BasicFillPropertyItem.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/BasicFillPropertyItem.cpp
22 
23  \brief A widget used to define the basic fill se object.
24 */
25 
26 #include "../../../color.h"
27 #include "../../../raster/Utils.h"
28 #include "../../../se/Fill.h"
29 #include "../../../se/SvgParameter.h"
30 #include "../../../se/Utils.h"
31 #include "../propertybrowser/AbstractPropertyManager.h"
32 #include "BasicFillPropertyItem.h"
33 
34 // STL
35 #include <cassert>
36 
37 // QtPropertyBrowser
38 
39 
40 te::qt::widgets::BasicFillPropertyItem::BasicFillPropertyItem(QtTreePropertyBrowser* pb, QColor c) : te::qt::widgets::AbstractPropertyItem(pb, c),
41  m_fill(new te::se::Fill)
42 {
43  //build property browser basic fill
44  QtProperty* basicFillProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_groupManager->addProperty(tr("Basic Fill"));
45 
46  //color
47  m_colorProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_colorManager->addProperty(tr("Color"));
49  basicFillProperty->addSubProperty(m_colorProperty);
50 
51  //opacity
52  m_opacityProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_intSliderManager->addProperty(tr("Opacity"));
55  te::qt::widgets::AbstractPropertyManager::getInstance().m_intSliderManager->setMaximum(m_opacityProperty, 255);
56  te::qt::widgets::AbstractPropertyManager::getInstance().m_intSliderManager->setSingleStep(m_opacityProperty, 10);
57  basicFillProperty->addSubProperty(m_opacityProperty);
58 
59  addProperty(basicFillProperty, tr("Basic Fill"), QColor(255, 255, 175));
60 
61  m_update = true;
62 }
63 
65 {
66  delete m_fill;
67 }
68 
70 {
71  if(!m_update)
72  return;
73 
74  if(p == m_opacityProperty && m_update)
75  {
76  m_update = false;
77 
78  m_color.setAlpha(value);
79 
80  double opacity = value / 255.;
81 
82  // Updating fill opacity
83  m_fill->setOpacity(QString::number(opacity, 'g', 2).toUtf8().data());
84 
85  updateUi();
86 
87  emit fillChanged();
88  m_update = true;
89  }
90 }
91 
92 void te::qt::widgets::BasicFillPropertyItem::valueChanged(QtProperty *p, const QColor &value)
93 {
94  if(!m_update)
95  return;
96 
97  if(p == m_colorProperty)
98  {
99  m_update = false;
100  // The new fill color
101  m_color.setRgb(value.red(), value.green(), value.blue(), value.alpha());
102 
103  double alpha = value.alpha() / 255.;
104 
105  // Updating fill color
106  m_fill->setColor(m_color.name().toUtf8().data());
107  m_fill->setOpacity(QString::number(alpha, 'g', 2).toUtf8().data());
108 
109  updateUi();
110 
111  emit fillChanged();
112  m_update = true;
113  }
114 }
115 
117 {
118  assert(fill);
119 
120  // Verifying if this widget can deal with the given fill...
121  const te::se::Graphic* g = fill->getGraphicFill();
122  if(g != nullptr)
123  return false;
124 
125  delete m_fill;
126 
127  m_fill = fill->clone();
128 
129  updateUi();
130 
131  return true;
132 }
133 
135 {
136  return m_fill->clone();
137 }
138 
140 {
141  // Color
143  te::se::GetColor(m_fill, rgba);
144  QColor c = QColor(rgba.getRgba());
145 
146  int alpha = 255;
147 
148  if (m_fill->getOpacity())
150 
151  c.setAlpha(alpha);
152 
154 
155  // Opacity
156  te::qt::widgets::AbstractPropertyManager::getInstance().m_intSliderManager->setValue(m_opacityProperty, alpha);
157 }
158 
void getRgba(int *r, int *g, int *b, int *a=0) const
It gets the color value.
Definition: RGBAColor.h:327
TESEEXPORT void GetColor(const te::se::Stroke *stroke, te::color::RGBAColor &color)
It gets the RGBA color from the Stroke element.
A widget used to define the main property items that can be used to describe a se object...
void updateUi()
Updates the widget form based on internal fill element.
void setColor(const std::string &color)
Definition: Fill.cpp:66
#define TE_OPAQUE
For an RGBA color this is the value of the alpha-channel for totally opaque.
TESEEXPORT double GetDouble(const te::se::ParameterValue *param)
It gets the parameter value as a double.
A Graphic is a graphic symbol with an inherent shape, color(s), and possibly size.
Definition: Graphic.h:66
BasicFillPropertyItem(QtTreePropertyBrowser *pb, QColor c=QColor())
Constructor.
virtual void valueChanged(QtProperty *p, int value)
static AbstractPropertyManager & getInstance()
It returns a reference to the singleton instance.
const Graphic * getGraphicFill() const
Gets the GraphicFill element associate to this Fill.
Definition: Fill.cpp:52
URI C++ Library.
Definition: Attributes.h:37
te::se::Fill * m_fill
Fill element that will be configured by this widget.
TERASTEREXPORT int Round(double val)
Round a double value to a integer value.
te::gm::Polygon * p
void setOpacity(const std::string &opacity)
Definition: Fill.cpp:71
A Fill specifies the pattern for filling an area geometry.
Definition: Fill.h:59
void addProperty(QtProperty *property, const QString &id, QColor c)
Fill * clone() const
It creates a new copy of this object.
Definition: Fill.cpp:86
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
#define TE_SE_DEFAULT_FILL_BASIC_COLOR
It specifies the default color used by basic fill (solid colors).
A widget used to define the basic fill se object.
const SvgParameter * getOpacity() const
Definition: Fill.cpp:81