27 #include "../../../maptools/Utils.h"
28 #include "../../../maptools/Enums.h"
29 #include "../../../se/Stroke.h"
30 #include "../../../se/SvgParameter.h"
31 #include "../utils/ColorPickerToolButton.h"
33 #include "ui_BasicStrokeWidgetForm.h"
36 #include <QtGui/QPainter>
43 m_ui(new Ui::BasicStrokeWidgetForm),
44 m_stroke(new te::se::Stroke)
53 QGridLayout* layout =
new QGridLayout(
m_ui->m_colorPickerFrame);
54 layout->setContentsMargins(0, 0, 0, 0);
55 layout->setSizeConstraint(QLayout::SetFixedSize);
80 m_stroke = stroke->
clone();
87 return m_stroke->
clone();
93 m_dashes.push_back(
"");
94 m_dashes.push_back(
"1 2");
95 m_dashes.push_back(
"4 2");
96 m_dashes.push_back(
"4 2 1 2");
97 m_dashes.push_back(
"4 2 1 2 1 2");
102 updateUiStrokeColor();
105 fillStrokeDashStyleComboBox();
108 m_strokeJoinStyleButtonGroup =
new QButtonGroup(
this);
109 m_strokeJoinStyleButtonGroup->addButton(m_ui->m_miterJoinPushButton,
te::map::MiterJoin);
110 m_strokeJoinStyleButtonGroup->addButton(m_ui->m_roundJoinPushButton,
te::map::RoundJoin);
111 m_strokeJoinStyleButtonGroup->addButton(m_ui->m_bevelJoinPushButton,
te::map::BevelJoin);
114 m_strokeCapStyleButtonGroup =
new QButtonGroup(
this);
115 m_strokeCapStyleButtonGroup->addButton(m_ui->m_buttCapPushButton,
te::map::ButtCap);
116 m_strokeCapStyleButtonGroup->addButton(m_ui->m_roundCapPushButton,
te::map::RoundCap);
117 m_strokeCapStyleButtonGroup->addButton(m_ui->m_squareCapPushButton,
te::map::SquareCap);
120 m_ui->m_miterJoinPushButton->setIcon(QIcon::fromTheme(
"stroke-join-miter"));
121 m_ui->m_roundJoinPushButton->setIcon(QIcon::fromTheme(
"stroke-join-round"));
122 m_ui->m_bevelJoinPushButton->setIcon(QIcon::fromTheme(
"stroke-join-bevel"));
124 m_ui->m_buttCapPushButton->setIcon(QIcon::fromTheme(
"stroke-cap-butt"));
125 m_ui->m_roundCapPushButton->setIcon(QIcon::fromTheme(
"stroke-cap-round"));
126 m_ui->m_squareCapPushButton->setIcon(QIcon::fromTheme(
"stroke-cap-square"));
134 m_color = QColor(rgba.
getRgba());
136 updateUiStrokeColor();
139 m_ui->m_strokeOpacitySlider->setValue(m_color.alphaF() * 100);
164 m_colorPicker->setColor(m_color);
170 std::vector<std::string>::iterator it;
171 for(it = m_dashes.begin(); it != m_dashes.end(); ++it)
175 m_ui->m_strokeDashComboBox->setCurrentIndex(i);
181 if(it == m_dashes.end())
183 m_dashes.push_back(pattern);
184 fillStrokeDashStyleComboBox();
185 m_ui->m_strokeDashComboBox->setCurrentIndex(i);
193 m_ui->m_roundJoinPushButton->setChecked(
true);
195 m_ui->m_bevelJoinPushButton->setChecked(
true);
202 m_ui->m_roundCapPushButton->setChecked(
true);
204 m_ui->m_squareCapPushButton->setChecked(
true);
210 m_ui->m_strokeDashComboBox->clear();
216 m_ui->m_strokeDashComboBox->setIconSize(size);
219 QLine line(0, size.height() * 0.5, size.width(), size.height() * 0.5);
226 std::vector<std::string>::iterator it = m_dashes.begin();
227 for(it = m_dashes.begin(); it != m_dashes.end(); ++it)
229 QPixmap pixmap(size);
230 pixmap.fill(Qt::transparent);
232 QPainter painter(&pixmap);
234 std::string pattern = *it;
235 std::vector<double> dasharray;
238 QVector<qreal> qdasharray = QVector<qreal>::fromStdVector(dasharray);
240 pen.setDashPattern(qdasharray);
242 painter.drawLine(line);
244 m_ui->m_strokeDashComboBox->addItem(pixmap,
"");
251 m_color.setRgb(color.red(), color.green(), color.blue(), m_color.alpha());
253 updateUiStrokeColor();
256 m_stroke->setColor(m_color.name().toStdString());
257 emit strokeChanged();
262 double opacity = value / 100.0;
264 m_color.setAlpha(opacity * 255);
265 updateUiStrokeColor();
268 m_stroke->setOpacity(QString::number(opacity,
'g', 2).toStdString());
269 emit strokeChanged();
274 m_stroke->setWidth(text.toStdString());
275 emit strokeChanged();
283 std::string pattern = m_dashes[index];
284 m_stroke->setDashArray(pattern);
285 emit strokeChanged();
305 emit strokeChanged();
325 emit strokeChanged();
void onColorChanged(const QColor &color)
TEMAPEXPORT void GetColor(const te::se::Stroke *stroke, te::color::RGBAColor &color)
Gets the RGBA color from Stroke element.
A widget used to build a basic stroke element.
#define TE_SE_ROUND_CAP
It specifies the value "round" for stroke-linecap parameter.
#define TE_SE_ROUND_JOIN
It specifies the value "round" for stroke-linejoin parameter.
void getRgba(int *r, int *g, int *b, int *a=0) const
It gets the color value.
#define TE_SE_BUTT_CAP
It specifies the value "butt" for stroke-linecap parameter.
void fillStrokeDashStyleComboBox()
Fills the widget form element used to visualize the stroke cap style.
void onStrokeWidthDoubleSpinBoxValueChanged(const QString &text)
te::se::Stroke * getStroke() const
Gets the configured stroke element.
ColorPickerToolButton * m_colorPicker
Widget used to pick a color.
A Stroke specifies the appearance of a linear geometry.
TEMAPEXPORT double GetDouble(const te::se::ParameterValue *param)
Gets the parameter value as double.
Stroke * clone() const
It creates a new copy of this object.
QButtonGroup * m_strokeJoinStyleButtonGroup
Button group used to control the join styles.
void setStroke(const te::se::Stroke *stroke)
Sets a stroke element to this widget.
TEMAPEXPORT void GetDashStyle(const std::string &dasharray, std::vector< double > &style)
Converts a dasharray pattern coded by a string to a vector of double.
void updateUiStrokeColor()
Updates the widget form element used to visualize the stroke color.
void onStrokeOpacitySliderValueChanged(int value)
BasicStrokeWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a basic stroke widget which is a child of parent, with widget flags set to f...
#define TE_SE_SQUARE_CAP
It specifies the value "square" for stroke-linecap parameter.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
TEMAPEXPORT std::string GetString(const te::se::ParameterValue *param)
Gets the parameter value as string.
~BasicStrokeWidget()
Destructor.
#define TE_SE_DEFAULT_STROKE_BASIC_COLOR
It specifies the default color used by stroke basic (solid colors).
#define TE_SE_BEVEL_JOIN
It specifies the value "bevel" for stroke-linejoin parameter.
#define TE_SE_MITRE_JOIN
It specifies the value "mitre" for stroke-linejoin parameter.
void onStrokeDashComboBoxCurrentIndexChanged(int index)
#define TE_OPAQUE
For an RGBA color this is the value of the alpha-channel for totally opaque.
void initialize()
Internal method to initialize the widget (e.g.: color, combos, icons, etc.)
void updateUiDashStyle(const std::string &pattern)
Updates the widget form element used to visualize the stroke dash style.
std::auto_ptr< Ui::BasicStrokeWidgetForm > m_ui
Widget form.
Custom tool button used to pick a color.
void onStrokeJoinStyleChanged(int style)
void onStrokeCapStyleChanged(int style)
void updateUiJoinStyle(const std::string &style)
Updates the widget form element used to visualize the stroke join style.
void updateUiCapStyle(const std::string &style)
Updates the widget form element used to visualize the stroke cap style.
void updateUi()
Updates the widget form based on internal stroke element.
A SvgParameter refers to an SVG/CSS graphical-formatting parameter.
int getAlpha() const
It returns the alpha component color value (a value from 0 to 255).
QButtonGroup * m_strokeCapStyleButtonGroup
Button group used to control the cap styles.