All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GlyphMarkWidget.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/GlyphMarkWidget.cpp
22 
23  \brief A widget used to build a mark element represented by a glyph.
24 */
25 
26 // TerraLib
27 #include "../../../se/Mark.h"
28 #include "BasicFillWidget.h"
29 #include "BasicStrokeWidget.h"
30 #include "CharMapWidget.h"
31 #include "GlyphMarkRenderer.h"
32 #include "GlyphMarkWidget.h"
33 #include "ui_GlyphMarkWidgetForm.h"
34 
35 // STL
36 #include <cassert>
37 
38 te::qt::widgets::GlyphMarkWidget::GlyphMarkWidget(QWidget* parent, Qt::WindowFlags f)
39  : QWidget(parent, f),
40  m_ui(new Ui::GlyphMarkWidgetForm),
41  m_mark(new te::se::Mark)
42 {
43  m_ui->setupUi(this);
44 
45  // Fill Widget
47 
48  // Adjusting...
49  QGridLayout* fillLayout = new QGridLayout(m_ui->m_fillFrame);
50  fillLayout->addWidget(m_fillWidget);
51 
52  // Char Map Widget
54  m_ui->m_charMapScrollArea->setWidget(m_charMapWidget);
55  m_ui->m_charMapScrollArea->setFixedWidth(m_charMapWidget->width() + 18);
56  m_ui->m_charMapScrollArea->setFixedHeight(m_charMapWidget->width() * 0.85);
57 
58  // Setups initial mark
61 
62  // Signals & slots
63  connect(m_ui->m_fontComboBox, SIGNAL(currentFontChanged(const QFont&)), m_charMapWidget, SLOT(updateFont(const QFont&)));
64  connect(m_ui->m_fontComboBox, SIGNAL(currentFontChanged(const QFont&)), SLOT(onCurrentFontChanged(const QFont&)));
65  connect(m_charMapWidget, SIGNAL(charSelected(const unsigned int&)), SLOT(onCharSelected(const unsigned int&)));
66  connect(m_fillWidget, SIGNAL(fillChanged()), SLOT(onFillChanged()));
67 }
68 
70 {
71  delete m_mark;
72 }
73 
75 {
76  assert(mark);
77 
78  delete m_mark;
79 
80  m_mark = mark->clone();
81 
82  updateUi();
83 }
84 
86 {
87  return m_mark->clone();
88 }
89 
91 {
92  const std::string* name = m_mark->getWellKnownName();
93  assert(name); // TODO: Exception?
94 
95  QString qName(name->c_str());
96  QString fontName;
97  QChar charCode;
98  try
99  {
100  te::qt::widgets::GlyphMarkRenderer::decode(qName, fontName, charCode);
101  }
102  catch(...)
103  {
104  }
105 
106  QFont font(fontName);
107  m_ui->m_fontComboBox->setCurrentFont(font);
108  // TODO: select the char on character map
109 
110  const te::se::Fill* fill = m_mark->getFill();
111  if(fill)
112  m_fillWidget->setFill(fill);
113 }
114 
116 {
117  QString name = te::qt::widgets::GlyphMarkRenderer::encode(m_ui->m_fontComboBox->currentFont().family(), m_charMapWidget->getCurrentChar());
118  m_mark->setWellKnownName(new std::string(name.toStdString()));
119  emit markChanged();
120 }
121 
123 {
124  updateMarkName();
125 }
126 
127 void te::qt::widgets::GlyphMarkWidget::onCharSelected(const unsigned int& /*charCode*/)
128 {
129  updateMarkName();
130 }
131 
133 {
134  m_mark->setFill(m_fillWidget->getFill());
135  emit markChanged();
136 }
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 build a basic fill element.
A Mark specifies a geometric shape and applies coloring to it.
Definition: Mark.h:84
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.
void updateMarkName()
Updates the mark well-known name enconding selected font and selected character.
void setFill(Fill *f)
Definition: Mark.cpp:108
static void decode(QString &name, QString &font, QChar &charCode)
Decodes the given name extracting the parameters known by this renderer.
A widget used to build a basic fill element.
te::qt::widgets::BasicFillWidget * m_fillWidget
Basic Fill Widget used to configure the mark fill element.
void onCharSelected(const unsigned int &charCode)
void setMark(const te::se::Mark *mark)
Sets a mark element to this widget.
A Fill specifies the pattern for filling an area geometry.
Definition: Fill.h:59
void updateUi()
Updates the widget form based on internal mark element.
void onCurrentFontChanged(const QFont &font)
Mark * clone() const
It creates a new copy of this object.
Definition: Mark.cpp:130
A widget used to build a mark element represented by a glyph.
A widget used to build a basic stroke element.
te::qt::widgets::CharMapWidget * m_charMapWidget
Character map widget.
std::auto_ptr< Ui::GlyphMarkWidgetForm > m_ui
Widget form.
GlyphMarkWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a glyph mark widget which is a child of parent, with widget flags set to f...
te::se::Fill * getFill() const
Gets the configured fill element.
te::se::Mark * m_mark
Mark element that will be configured by this widget.
te::se::Mark * getMark() const
Gets the configured mark element.