All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Utils.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2001-2009 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/Utils.cpp
22 
23  \brief This file contains utility functions for dealing with Symbology Enconding and Qt concepts.
24  */
25 
26 // TerraLib
27 #include "../../../color/RGBAColor.h"
28 #include "../../../maptools/Utils.h"
29 #include "../../../se/Stroke.h"
30 #include "../../../se/SvgParameter.h"
31 #include "Utils.h"
32 
33 // Qt
34 #include <QtCore/QVector>
35 #include <QtGui/QBrush>
36 #include <QtGui/QPen>
37 
38 void te::qt::widgets::Config(QPen& pen, const te::se::Stroke* stroke)
39 {
40  if(stroke == 0)
41  {
42  pen.setColor(Qt::transparent);
43  return;
44  }
45 
46  // Color
48  te::map::GetColor(stroke, rgba);
49  QColor qrgba(rgba.getRgba());
50  qrgba.setAlpha(rgba.getAlpha());
51  pen.setColor(qrgba);
52 
53  // Width
54  const te::se::SvgParameter* width = stroke->getWidth();
55  if(width)
56  pen.setWidth(te::map::GetInt(width));
57 
58  // Cap Style
59  const te::se::SvgParameter* linecap = stroke->getLineCap();
60  if(linecap)
61  {
62  std::string capValue = te::map::GetString(linecap);
63 
64  Qt::PenCapStyle capStyle = Qt::FlatCap;
65  capValue == TE_SE_ROUND_CAP ? capStyle = Qt::RoundCap : capStyle = Qt::SquareCap;
66 
67  pen.setCapStyle(capStyle);
68  }
69 
70  // Join Style
71  const te::se::SvgParameter* linejoin = stroke->getLineJoin();
72  if(linejoin)
73  {
74  std::string joinValue = te::map::GetString(linejoin);
75 
76  Qt::PenJoinStyle joinStyle = Qt::MiterJoin;
77  joinValue == TE_SE_ROUND_JOIN ? joinStyle = Qt::RoundJoin : joinStyle = Qt::BevelJoin;
78 
79  pen.setJoinStyle(joinStyle);
80  }
81 
82  // Dash Style
83  const te::se::SvgParameter* dasharray = stroke->getDashArray();
84  if(dasharray)
85  {
86  std::string value = te::map::GetString(dasharray);
87 
88  std::vector<double> pattern;
89  te::map::GetDashStyle(value, pattern);
90 
91  pen.setDashPattern(QVector<qreal>::fromStdVector(pattern));
92  }
93 
94  /* TODO: Is necessary verify stroke-dashoffset, <GraphicStroke>, and <GraphicFill> elements here ?! */
95 }
96 
97 void te::qt::widgets::Config(QBrush& brush, const te::se::Fill* fill)
98 {
99  if(fill == 0)
100  {
101  brush.setColor(Qt::transparent);
102  return;
103  }
104 
106  te::map::GetColor(fill, rgba);
107  QColor qrgba(rgba.getRgba());
108  qrgba.setAlpha(rgba.getAlpha());
109  brush.setColor(qrgba);
110 
111  /* TODO: Is necessary verify <GraphicFill> element here ?! */
112 }
const SvgParameter * getLineJoin() const
Definition: Stroke.cpp:138
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
TEMAPEXPORT int GetInt(const te::se::ParameterValue *param)
Gets the parameter value as integer.
Definition: Utils.cpp:122
#define TE_SE_ROUND_CAP
It specifies the value &quot;round&quot; for stroke-linecap parameter.
Definition: Config.h:128
#define TE_SE_ROUND_JOIN
It specifies the value &quot;round&quot; for stroke-linejoin parameter.
Definition: Config.h:149
const SvgParameter * getWidth() const
Definition: Stroke.cpp:133
void Config(QPen &pen, const te::se::Stroke *stroke)
It configs the given pen based on Symbology Enconding Stroke element.
Definition: Utils.cpp:38
void getRgba(int *r, int *g, int *b, int *a=0) const
It gets the color value.
Definition: RGBAColor.h:315
const SvgParameter * getLineCap() const
Definition: Stroke.cpp:143
Utility functions for MapTools module.
A Stroke specifies the appearance of a linear geometry.
Definition: Stroke.h:67
const SvgParameter * getDashArray() const
Definition: Stroke.cpp:148
TEMAPEXPORT void GetDashStyle(const std::string &dasharray, std::vector< double > &style)
Converts a dasharray pattern coded by a string to a vector of double.
Definition: Utils.cpp:227
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
TEMAPEXPORT std::string GetString(const te::se::ParameterValue *param)
Gets the parameter value as string.
Definition: Utils.cpp:132
#define TE_SE_DEFAULT_STROKE_BASIC_COLOR
It specifies the default color used by stroke basic (solid colors).
Definition: Config.h:86
#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
A SvgParameter refers to an SVG/CSS graphical-formatting parameter.
Definition: SvgParameter.h:48
int getAlpha() const
It returns the alpha component color value (a value from 0 to 255).
Definition: RGBAColor.h:310