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-2014 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 
61 {
62  delete m_fill;
63 }
64 
66 {
67  if(p == m_opacityProperty)
68  {
69  double opacity = value / 100.0;
70 
71  m_color.setAlpha(opacity * 255);
72  updateUiFillColor();
73 
74  // Updating fill opacity
75  m_fill->setOpacity(QString::number(opacity, 'g', 2).toStdString());
76  emit fillChanged();
77  }
78 }
79 
80 void te::qt::widgets::BasicFillPropertyItem::valueChanged(QtProperty *p, const QColor &value)
81 {
82  if(p == m_colorProperty)
83  {
84  // The new fill color
85  m_color.setRgb(value.red(), value.green(), value.blue(), m_color.alpha());
86 
87  updateUiFillColor();
88 
89  // Updating fill color
90  m_fill->setColor(m_color.name().toStdString());
91  emit fillChanged();
92  }
93 }
94 
96 {
97  assert(fill);
98 
99  // Verifying if this widget can deal with the given fill...
100  const te::se::Graphic* g = fill->getGraphicFill();
101  if(g != 0)
102  return false;
103 
104  delete m_fill;
105 
106  m_fill = fill->clone();
107 
108  updateUi();
109 
110  return true;
111 }
112 
114 {
115  return m_fill->clone();
116 }
117 
119 {
120  // Color
122  te::se::GetColor(m_fill, rgba);
123  m_color = QColor(rgba.getRgba());
124  m_color.setAlpha(rgba.getAlpha());
125 
126  te::qt::widgets::AbstractPropertyManager::getInstance().m_colorManager->setValue(m_colorProperty, m_color);
127 
128 
129  // Opacity
130  te::qt::widgets::AbstractPropertyManager::getInstance().m_intSliderManager->setValue(m_opacityProperty, m_color.alphaF() * 100);
131 }
132 
134 {
135  te::qt::widgets::AbstractPropertyManager::getInstance().m_colorManager->setValue(m_colorProperty, m_color);
136 }
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
bool setFill(const te::se::Fill *fill)
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.