All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GlyphMarkPropertyItem.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/qt/widgets/se/GlyphMarkPropertyItem.cpp
22 
23  \brief A widget used to define a glyph object.
24 */
25 
26 // TerraLib
27 #include "../../../se/Config.h"
28 #include "../../../se/Mark.h"
29 #include "../propertybrowser/AbstractPropertyManager.h"
30 #include "BasicFillPropertyItem.h"
31 #include "CharMapWidget.h"
32 #include "GlyphMarkPropertyItem.h"
33 #include "GlyphMarkRenderer.h"
34 
35 // Qt
36 #include <QDialog>
37 #include <QGridLayout>
38 #include <QScrollArea>
39 #include <QPushButton>
40 
41 // QtPropertyBrowser
42 #include <QtPropertyBrowser/QtTreePropertyBrowser>
43 #include <QtPropertyBrowser/QtVariantPropertyManager>
44 
45 // STL
46 #include <cassert>
47 
48 
49 te::qt::widgets::GlyphMarkPropertyItem::GlyphMarkPropertyItem(QtTreePropertyBrowser* pb, QColor c) : te::qt::widgets::AbstractPropertyItem(pb, c) ,
50  m_mark(new te::se::Mark), m_update(false)
51 {
52  //build property browser basic fill
53  QtProperty* glyphProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_groupManager->addProperty(tr("Glyph Mark"));
54 
55  //font
56  m_fontProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_fontManager->addProperty(tr("Font"));
57  glyphProperty->addSubProperty(m_fontProperty);
58 
59  //char
60  m_charProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_strDlgManager->addProperty(tr("Char"));
61  te::qt::widgets::AbstractPropertyManager::getInstance().m_strDlgManager->setValue(m_charProperty, QString("0"));
62  connect(te::qt::widgets::AbstractPropertyManager::getInstance().m_dlgFactory, SIGNAL(internalDlg(QWidget *, QtProperty *)), this, SLOT(setDlg(QWidget *, QtProperty *)));
63  glyphProperty->addSubProperty(m_charProperty);
64 
65  addProperty(glyphProperty, tr("Glyph Mark"), QColor(175, 175, 255));
66 
67  m_basicFill = new te::qt::widgets::BasicFillPropertyItem(pb, QColor(175, 175, 255));
68 
69  connect(m_basicFill, SIGNAL(fillChanged()), SLOT(onFillChanged()));
70 
73 }
74 
76 {
77 }
78 
80 {
81  assert(mark);
82 
83  delete m_mark;
84 
85  m_mark = mark->clone();
86 
87  updateUi();
88 }
89 
91 {
92  return m_mark->clone();
93 }
94 
96 {
97  const std::string* name = m_mark->getWellKnownName();
98  assert(name); // TODO: Exception?
99 
100  QString qName(name->c_str());
101  QString fontName;
102  QChar charCode;
103 
104  try
105  {
106  te::qt::widgets::GlyphMarkRenderer::decode(qName, fontName, charCode);
107  }
108  catch(...)
109  {
110  }
111 
112  QFont font(fontName);
113 
114  int intCharCode = charCode.unicode();
115  QString strCharCode;
116  strCharCode.setNum(intCharCode);
117 
118  m_update = true;
119 
120  te::qt::widgets::AbstractPropertyManager::getInstance().m_strDlgManager->setValue(m_charProperty, strCharCode);
122 
123  m_update = false;
124 
125  const te::se::Fill* fill = m_mark->getFill();
126  if(fill)
127  m_basicFill->setFill(fill);
128 }
129 
131 {
132  QFont f = te::qt::widgets::AbstractPropertyManager::getInstance().m_fontManager->value(m_fontProperty);
133 
134  QString valStr = te::qt::widgets::AbstractPropertyManager::getInstance().m_strDlgManager->value(m_charProperty);
135 
136  QString name = te::qt::widgets::GlyphMarkRenderer::encode(f.family(), valStr.toInt());
137 
138  m_mark->setWellKnownName(new std::string(name.toStdString()));
139 
140  if(!m_update)
141  emit markChanged();
142 }
143 
144 void te::qt::widgets::GlyphMarkPropertyItem::valueChanged(QtProperty* p, const QFont &value)
145 {
146  if(m_fontProperty == p )
147  updateMarkName();
148 }
149 
150 void te::qt::widgets::GlyphMarkPropertyItem::valueChanged(QtProperty* p, const QString &value)
151 {
152  if(m_charProperty == p)
153  updateMarkName();
154 }
155 
156 void te::qt::widgets::GlyphMarkPropertyItem::setDlg(QWidget *parent, QtProperty * prop)
157 {
158  if(prop == m_charProperty)
159  {
160  m_charDlg = parent;
161 
162  connect(m_charDlg, SIGNAL(showDlg()), this, SLOT(showCharMapDlg()));
163  }
164 }
165 
167 {
168  QFont f = te::qt::widgets::AbstractPropertyManager::getInstance().m_fontManager->value(m_fontProperty);
169 
170  //build form
171  QDialog d;
172 
173  QGridLayout* l = new QGridLayout(&d);
174  l->setObjectName("mainLayout");
175  QScrollArea* sa = new QScrollArea(&d);
176  sa->setFixedSize(300, 200);
177  QGridLayout* lsa = new QGridLayout(&d);
178  lsa->setObjectName("scrollAreaLayout");
179  sa->setLayout(lsa);
180 
182  lsa->addWidget(cmw);
183  l->addWidget(sa,0, 0, 1, 2);
184  connect(cmw, SIGNAL(charSelected(const unsigned int&)), this, SLOT(charMapSelected(const unsigned int&)));
185  cmw->setFont(f);
186  sa->setWidget(cmw);
187 
188  QSpacerItem* spacer = new QSpacerItem(16, 16, QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
189  l->addItem(spacer, 1, 0);
190  QPushButton* pb = new QPushButton(tr("Close"), &d);
191  connect(pb, SIGNAL(clicked()), &d, SLOT(close()));
192  l->addWidget(pb, 1, 1);
193  l->setSizeConstraint(QLayout::SetFixedSize);
194 
195  d.setLayout(l);
196  d.setWindowTitle(tr("Char Map"));
197  d.setWindowFlags(Qt::Tool);
198  d.exec();
199 
200 
201  //if(m_charMapWidget->isVisible())
202  //{
203  // m_charMapWidget->close();
204  //}
205 
206  //
207 
208  //m_charMapWidget->setFont(f);
209 
210  //m_charMapWidget->show();
211 }
212 
214 {
215  QString str;
216  str.setNum(charCode);
217 
219 
220  updateMarkName();
221 }
222 
224 {
225  m_mark->setFill(m_basicFill->getFill());
226  emit markChanged();
227 }
static QString encode(const QString &font, const int &charCode)
Encodes the given parameters to a format known by this renderer.
A concrete renderer based on Qt4 for conversion of Symbology Enconding Mark elements to an image patt...
A widget used to define the main property items that can be used to describe a se object...
A Mark specifies a geometric shape and applies coloring to it.
Definition: Mark.h:84
void setDlg(QWidget *parent, QtProperty *prop)
A widget used to show the set of characters of a specified font.
Definition: CharMapWidget.h:46
A widget used to show the set of characters of a specified font.
te::se::Mark * getMark() const
Gets the configured mark element.
GlyphMarkPropertyItem(QtTreePropertyBrowser *pb, QColor c=QColor())
Constructor.
void setFill(Fill *f)
Definition: Mark.cpp:108
void updateUi()
Updates the widget form based on internal mark element.
static void decode(QString &name, QString &font, QChar &charCode)
Decodes the given name extracting the parameters known by this renderer.
te::qt::widgets::BasicFillPropertyItem * m_basicFill
A widget used to define a glyph object.
void charMapSelected(const unsigned int &charCode)
static AbstractPropertyManager & getInstance()
It returns a reference to the singleton instance.
void updateMarkName()
Updates the mark well-known name enconding selected font and selected character.
A Fill specifies the pattern for filling an area geometry.
Definition: Fill.h:59
te::se::Mark * m_mark
Mark element that will be configured by this widget.
void addProperty(QtProperty *property, const QString &id, QColor c)
Mark * clone() const
It creates a new copy of this object.
Definition: Mark.cpp:130
A widget used to define the basic fill se object.
virtual void valueChanged(QtProperty *p, const QFont &value)
A widget used to define the basic fill se object.
void setMark(const te::se::Mark *mark)
Sets a mark element to this widget.