All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 "../../../se/Fill.h"
28 #include "../../../se/Utils.h"
29 #include "../propertybrowser/AbstractPropertyManager.h"
30 #include "BasicFillPropertyItem.h"
31 
32 // STL
33 #include <cassert>
34 
35 // QtPropertyBrowser
36 
37 
38 te::qt::widgets::BasicFillPropertyItem::BasicFillPropertyItem(QtTreePropertyBrowser* pb, QColor c) : te::qt::widgets::AbstractPropertyItem(pb, c),
39  m_fill(new te::se::Fill)
40 {
41  //build property browser basic fill
42  QtProperty* basicFillProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_groupManager->addProperty(tr("Basic Fill"));
43 
44  //color
45  m_colorProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_colorManager->addProperty(tr("Color"));
47  basicFillProperty->addSubProperty(m_colorProperty);
48 
49  //opacity
50  m_opacityProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_intSliderManager->addProperty(tr("Opacity"));
53  te::qt::widgets::AbstractPropertyManager::getInstance().m_intSliderManager->setMaximum(m_opacityProperty, 100);
54  te::qt::widgets::AbstractPropertyManager::getInstance().m_intSliderManager->setSingleStep(m_opacityProperty, 10);
55  basicFillProperty->addSubProperty(m_opacityProperty);
56 
57  addProperty(basicFillProperty, tr("Basic Fill"), QColor(255, 255, 175));
58 
59  m_update = true;
60 }
61 
63 {
64  delete m_fill;
65 }
66 
68 {
69  if(!m_update)
70  return;
71 
72  if(p == m_opacityProperty && m_update)
73  {
74  m_update = false;
75  double opacity = value / 100.0;
76 
77  m_color.setAlpha(opacity * 255);
78  updateUiFillColor();
79 
80  // Updating fill opacity
81  m_fill->setOpacity(QString::number(opacity, 'g', 2).toStdString());
82  emit fillChanged();
83  m_update = true;
84  }
85 }
86 
87 void te::qt::widgets::BasicFillPropertyItem::valueChanged(QtProperty *p, const QColor &value)
88 {
89  if(!m_update)
90  return;
91 
92  if(p == m_colorProperty)
93  {
94  m_update = false;
95  // The new fill color
96  m_color.setRgb(value.red(), value.green(), value.blue(), value.alpha());
97 
98  int opacity = (value.alpha() / 255.) * 100.;
99 
100  te::qt::widgets::AbstractPropertyManager::getInstance().m_intSliderManager->setValue(m_opacityProperty, opacity);
101 
102  updateUiFillColor();
103 
104  // Updating fill color
105  m_fill->setColor(m_color.name().toStdString());
106  m_fill->setOpacity(QString::number(opacity, 'g', 2).toStdString());
107  emit fillChanged();
108  m_update = true;
109  }
110 }
111 
113 {
114  assert(fill);
115 
116  // Verifying if this widget can deal with the given fill...
117  const te::se::Graphic* g = fill->getGraphicFill();
118  if(g != 0)
119  return false;
120 
121  delete m_fill;
122 
123  m_fill = fill->clone();
124 
125  updateUi();
126 
127  return true;
128 }
129 
131 {
132  return m_fill->clone();
133 }
134 
136 {
137  // Color
139  te::se::GetColor(m_fill, rgba);
140  m_color = QColor(rgba.getRgba());
141  m_color.setAlpha(rgba.getAlpha());
142 
143  te::qt::widgets::AbstractPropertyManager::getInstance().m_colorManager->setValue(m_colorProperty, m_color);
144 
145 
146  // Opacity
147  te::qt::widgets::AbstractPropertyManager::getInstance().m_intSliderManager->setValue(m_opacityProperty, m_color.alphaF() * 100);
148 }
149 
151 {
152  te::qt::widgets::AbstractPropertyManager::getInstance().m_colorManager->setValue(m_colorProperty, m_color);
153 }
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
A widget used to define the main property items that can be used to describe a se object...
void updateUiFillColor()
Updates the widget form element used to visualize the fill color.
void updateUi()
Updates the widget form based on internal fill element.
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.
#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
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
#define TE_SE_DEFAULT_FILL_BASIC_COLOR
It specifies the default color used by basic fill (solid colors).
Definition: Config.h:79
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
A widget used to define the basic fill se object.