All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BasicFillPropertyItem.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011-2012 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 "BasicFillPropertyItem.h"
28 
29 #include "../../../se/Fill.h"
30 #include "../../../color.h"
31 #include "../../../maptools/Utils.h"
32 
33 #include "../../../../../third-party/qt/propertybrowser/qtpropertybrowser.h"
34 
35 // STL
36 #include <cassert>
37 
38 
39 te::qt::widgets::BasicFillPropertyItem::BasicFillPropertyItem(QtTreePropertyBrowser* pb, QColor c) : te::qt::widgets::AbstractPropertyItem(pb, c),
40  m_fill(new te::se::Fill)
41 {
42  //build property browser basic fill
43  QtProperty* basicFillProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_groupManager->addProperty(tr("Basic Fill"));
44 
45  //color
46  m_colorProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_colorManager->addProperty(tr("Color"));
48  basicFillProperty->addSubProperty(m_colorProperty);
49 
50  //opacity
51  m_opacityProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_intSliderManager->addProperty(tr("Opacity"));
54  te::qt::widgets::AbstractPropertyManager::getInstance().m_intSliderManager->setMaximum(m_opacityProperty, 100);
55  te::qt::widgets::AbstractPropertyManager::getInstance().m_intSliderManager->setSingleStep(m_opacityProperty, 10);
56  basicFillProperty->addSubProperty(m_opacityProperty);
57 
58  addProperty(basicFillProperty, tr("Basic Fill"), QColor(255, 255, 175));
59 }
60 
62 {
63  delete m_fill;
64 }
65 
67 {
68  if(p == m_opacityProperty)
69  {
70  double opacity = value / 100.0;
71 
72  m_color.setAlpha(opacity * 255);
73  updateUiFillColor();
74 
75  // Updating fill opacity
76  m_fill->setOpacity(QString::number(opacity, 'g', 2).toStdString());
77  emit fillChanged();
78  }
79 }
80 
81 void te::qt::widgets::BasicFillPropertyItem::valueChanged(QtProperty *p, const QColor &value)
82 {
83  if(p == m_colorProperty)
84  {
85  // The new fill color
86  m_color.setRgb(value.red(), value.green(), value.blue(), m_color.alpha());
87 
88  updateUiFillColor();
89 
90  // Updating fill color
91  m_fill->setColor(m_color.name().toStdString());
92  emit fillChanged();
93  }
94 }
95 
97 {
98  assert(fill);
99 
100  // Verifying if this widget can deal with the given fill...
101  const te::se::Graphic* g = fill->getGraphicFill();
102  if(g != 0)
103  return false;
104 
105  delete m_fill;
106 
107  m_fill = fill->clone();
108 
109  updateUi();
110 
111  return true;
112 }
113 
115 {
116  return m_fill->clone();
117 }
118 
120 {
121  // Color
123  te::map::GetColor(m_fill, rgba);
124  m_color = QColor(rgba.getRgba());
125  m_color.setAlpha(rgba.getAlpha());
126 
127  te::qt::widgets::AbstractPropertyManager::getInstance().m_colorManager->setValue(m_colorProperty, m_color);
128 
129 
130  // Opacity
131  te::qt::widgets::AbstractPropertyManager::getInstance().m_intSliderManager->setValue(m_opacityProperty, m_color.alphaF() * 100);
132 }
133 
135 {
136  te::qt::widgets::AbstractPropertyManager::getInstance().m_colorManager->setValue(m_colorProperty, m_color);
137 }
TEMAPEXPORT void GetColor(const te::se::Stroke *stroke, te::color::RGBAColor &color)
Gets the RGBA color from Stroke element.
Definition: Utils.cpp:83
A Fill specifies the pattern for filling an area geometry.
Definition: Fill.h:59
void getRgba(int *r, int *g, int *b, int *a=0) const
It gets the color value.
Definition: RGBAColor.h:315
const Graphic * getGraphicFill() const
Gets the GraphicFill element associate to this Fill.
Definition: Fill.cpp:52
Fill * clone() const
It creates a new copy of this object.
Definition: Fill.cpp:86
bool setFill(const te::se::Fill *fill)
A widget used to define the basic fill se object.
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).
Definition: Config.h:79
#define TE_OPAQUE
For an RGBA color this is the value of the alpha-channel for totally opaque.
Definition: Config.h:39
void updateUiFillColor()
Updates the widget form element used to visualize the fill color.
A widget used to define the main property items that can be used to describe a se object...
BasicFillPropertyItem(QtTreePropertyBrowser *pb, QColor c=QColor())
Constructor.
void addProperty(QtProperty *property, const QString &id, QColor c)
static AbstractPropertyManager & getInstance()
It returns a reference to the singleton instance.
virtual void valueChanged(QtProperty *p, int value)
A Graphic is a graphic symbol with an inherent shape, color(s), and possibly size.
Definition: Graphic.h:66
int getAlpha() const
It returns the alpha component color value (a value from 0 to 255).
Definition: RGBAColor.h:310
void updateUi()
Updates the widget form based on internal fill element.