All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
BasicFillWidget.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/BasicFillWidget.cpp
22 
23  \brief A widget used to build a basic fill element.
24 */
25 
26 // TerraLib
27 #include "../../../se/Fill.h"
28 #include "../../../se/Utils.h"
29 #include "../utils/ColorPickerToolButton.h"
30 #include "BasicFillWidget.h"
31 #include "ui_BasicFillWidgetForm.h"
32 
33 // STL
34 #include <cassert>
35 
36 te::qt::widgets::BasicFillWidget::BasicFillWidget(QWidget* parent, Qt::WindowFlags f)
37  : AbstractFillWidget(parent, f),
38  m_ui(new Ui::BasicFillWidgetForm),
39  m_fill(new te::se::Fill)
40 {
41  m_ui->setupUi(this);
42 
43  // Color Picker
45  m_colorPicker->setFixedSize(70, 24);
46 
47  // Adjusting...
48  QGridLayout* layout = new QGridLayout(m_ui->m_colorPickerFrame);
49  layout->setContentsMargins(0, 0, 0, 0);
50  layout->setSizeConstraint(QLayout::SetFixedSize);
51  layout->addWidget(m_colorPicker);
52 
53  initialize();
54 
55  // Signals & slots
56  connect(m_colorPicker, SIGNAL(colorChanged(const QColor&)), SLOT(onColorChanged(const QColor&)));
57  connect(m_ui->m_fillOpacitySlider, SIGNAL(valueChanged(int)), SLOT(onFillOpacitySliderValueChanged(int)));
58 }
59 
61 {
62  delete m_fill;
63 }
64 
66 {
67  assert(fill);
68 
69  // Verifying if this widget can deal with the given fill...
70  const te::se::Graphic* g = fill->getGraphicFill();
71  if(g != 0)
72  return false;
73 
74  delete m_fill;
75 
76  m_fill = fill->clone();
77 
78  updateUi();
79 
80  return true;
81 }
82 
84 {
85  return m_fill->clone();
86 }
87 
89 {
90  return tr("Basic Fill");
91 }
92 
94 {
95  // Default fill color
96  m_color = QColor(TE_SE_DEFAULT_FILL_BASIC_COLOR);
97  updateUiFillColor();
98 }
99 
101 {
102  // Color
104  te::se::GetColor(m_fill, rgba);
105  m_color = QColor(rgba.getRgba());
106  m_color.setAlpha(rgba.getAlpha());
107  updateUiFillColor();
108 
109  // Opacity
110  m_ui->m_fillOpacitySlider->setValue(m_color.alphaF() * 100);
111 }
112 
114 {
115  m_colorPicker->setColor(m_color);
116 }
117 
119 {
120  // The new fill color
121  m_color.setRgb(color.red(), color.green(), color.blue(), m_color.alpha());
122 
123  updateUiFillColor();
124 
125  // Updating fill color
126  m_fill->setColor(m_color.name().toStdString());
127  emit fillChanged();
128 }
129 
131 {
132  double opacity = value / 100.0;
133 
134  m_color.setAlpha(opacity * 255);
135  updateUiFillColor();
136 
137  // Updating fill opacity
138  m_fill->setOpacity(QString::number(opacity, 'g', 2).toStdString());
139  emit fillChanged();
140 }
void updateUi()
Updates the widget form based on internal fill element.
void getRgba(int *r, int *g, int *b, int *a=0) const
It gets the color value.
Definition: RGBAColor.h:315
TESEEXPORT void GetColor(const te::se::Stroke *stroke, te::color::RGBAColor &color)
It gets the RGBA color from the Stroke element.
Definition: Utils.cpp:404
Abstract class that represents a widget that can be used to build a fill element. ...
ColorPickerToolButton * m_colorPicker
Widget used to pick a color.
A Graphic is a graphic symbol with an inherent shape, color(s), and possibly size.
Definition: Graphic.h:66
A widget used to build a basic fill element.
void initialize()
Internal method to initialize the widget (e.g.: color, combos, icons, etc.)
Custom tool button used to pick a color.
#define TE_OPAQUE
For an RGBA color this is the value of the alpha-channel for totally opaque.
Definition: Config.h:39
const Graphic * getGraphicFill() const
Gets the GraphicFill element associate to this Fill.
Definition: Fill.cpp:52
int getAlpha() const
It returns the alpha component color value (a value from 0 to 255).
Definition: RGBAColor.h:310
QString getFillType() const
Pure virtual method that should return a "user friendly" string that informs the fill type that can b...
A Fill specifies the pattern for filling an area geometry.
Definition: Fill.h:59
bool setFill(const te::se::Fill *fill)
Sets a fill element to this widget.
std::auto_ptr< Ui::BasicFillWidgetForm > m_ui
Widget form.
Fill * clone() const
It creates a new copy of this object.
Definition: Fill.cpp:86
void onFillOpacitySliderValueChanged(int value)
#define TE_SE_DEFAULT_FILL_BASIC_COLOR
It specifies the default color used by basic fill (solid colors).
Definition: Config.h:79
void onColorChanged(const QColor &color)
void updateUiFillColor()
Updates the widget form element used to visualize the fill color.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
te::se::Fill * getFill() const
Gets the configured fill element.
BasicFillWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a basic fill widget which is a child of parent, with widget flags set to f...