• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.14
  • kdeedu
  • marble
  • src
  • plugins
  • render
  • annotate
EditPolygonDialog.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2014 Calin-Cristian Cruceru <crucerucalincristian@gmail.com>
9 //
10 
11 // Self
12 #include "EditPolygonDialog.h"
13 #include "ui_EditPolygonDialog.h"
14 
15 // Marble
16 #include "GeoDataStyle.h"
17 
18 // Qt
19 #include <QColorDialog>
20 
21 namespace Marble {
22 
23 class EditPolygonDialog::Private : public Ui::UiEditPolygonDialog
24 {
25 public:
26  Private( GeoDataPlacemark *placemark );
27  ~Private();
28 
29  GeoDataPlacemark *m_placemark;
30 
31  QColorDialog *m_linesDialog;
32  QColorDialog *m_polyDialog;
33 };
34 
35 EditPolygonDialog::Private::Private( GeoDataPlacemark *placemark ) :
36  Ui::UiEditPolygonDialog(),
37  m_placemark( placemark ),
38  m_linesDialog( 0 ),
39  m_polyDialog( 0 )
40 {
41  // nothing to do
42 }
43 
44 EditPolygonDialog::Private::~Private()
45 {
46  // nothig to do
47 }
48 
49 EditPolygonDialog::EditPolygonDialog( GeoDataPlacemark *placemark, QWidget *parent ) :
50  QDialog( parent ),
51  d( new Private( placemark ) )
52 {
53  d->setupUi( this );
54 
55  d->m_name->setText( placemark->name() );
56  d->m_description->setText( placemark->description() );
57  d->m_linesWidth->setRange( 0.1, 5.0 );
58 
59  // Get the current style properties.
60  const GeoDataLineStyle lineStyle = placemark->style()->lineStyle();
61  const GeoDataPolyStyle polyStyle = placemark->style()->polyStyle();
62 
63  // Adjust the "Filled"/"Not Filled" option according to its current fill.
64  d->m_linesWidth->setValue( lineStyle.width() );
65  if ( polyStyle.fill() ) {
66  d->m_filledColor->setCurrentIndex( 0 );
67  } else {
68  d->m_filledColor->setCurrentIndex( 1 );
69  }
70 
71  // Adjust the color buttons' icons to the current lines and polygon colors.
72  QPixmap linesPixmap( d->m_linesColorButton->iconSize().width(),
73  d->m_linesColorButton->iconSize().height() );
74  linesPixmap.fill( lineStyle.color() );
75  d->m_linesColorButton->setIcon( QIcon( linesPixmap ) );
76 
77  QPixmap polyPixmap( d->m_polyColorButton->iconSize().width(),
78  d->m_polyColorButton->iconSize().height() );
79  polyPixmap.fill( polyStyle.color() );
80  d->m_polyColorButton->setIcon( QIcon( polyPixmap ) );
81 
82  // Setup the color dialogs.
83  d->m_linesDialog = new QColorDialog( this );
84  d->m_linesDialog->setOption( QColorDialog::ShowAlphaChannel );
85  d->m_linesDialog->setCurrentColor( lineStyle.color() );
86  connect( d->m_linesColorButton, SIGNAL(clicked()), d->m_linesDialog, SLOT(exec()) );
87  connect( d->m_linesDialog, SIGNAL(colorSelected(QColor)), this, SLOT(updateLinesDialog(const QColor&)) );
88 
89  d->m_polyDialog = new QColorDialog( this );
90  d->m_polyDialog->setOption( QColorDialog::ShowAlphaChannel );
91  d->m_polyDialog->setCurrentColor( polyStyle.color() );
92  connect( d->m_polyColorButton, SIGNAL(clicked()), d->m_polyDialog, SLOT(exec()) );
93  connect( d->m_polyDialog, SIGNAL(colorSelected(QColor)), this, SLOT(updatePolyDialog(const QColor&)) );
94 
95 
96  // Promote "Apply" button to default button and connect it to updatePolygon() slot.
97  QPushButton *applyButton = d->buttonBox->button( QDialogButtonBox::Apply );
98  d->buttonBox->button( QDialogButtonBox::Apply )->setDefault( true );
99  connect( applyButton, SIGNAL(clicked()), this, SLOT(updatePolygon()) );
100 
101  // Make sure pressing "OK" will also update the polygon.
102  connect( d->buttonBox, SIGNAL(accepted()), this, SLOT(updatePolygon()) );
103 
104  // Ensure that the dialog gets deleted when closing it (either when clicking OK or
105  // Close).
106  connect( this, SIGNAL(finished(int)), SLOT(deleteLater()) );
107 }
108 
109 EditPolygonDialog::~EditPolygonDialog()
110 {
111  // nothing to do
112 }
113 
114 void EditPolygonDialog::updatePolygon()
115 {
116  GeoDataStyle *style = new GeoDataStyle( *d->m_placemark->style() );
117 
118  d->m_placemark->setName( d->m_name->text() );
119  d->m_placemark->setDescription( d->m_description->toPlainText() );
120 
121  style->lineStyle().setWidth( d->m_linesWidth->value() );
122  // 0 corresponds to "Filled" and 1 corresponds to "Not Filled".
123  style->polyStyle().setFill( !d->m_filledColor->currentIndex() );
124 
125 
126  // Adjust the lines/polygon colors.
127  // QColorDialog::currentColor() also works even if the color dialog
128  // has not been exec'ed, while QColorDialog::selectedColor() does not.
129  style->lineStyle().setColor( d->m_linesDialog->currentColor() );
130  style->polyStyle().setColor( d->m_polyDialog->currentColor() );
131 
132 
133  d->m_placemark->setStyle( style );
134  emit polygonUpdated( d->m_placemark );
135 }
136 
137 void EditPolygonDialog::updateLinesDialog( const QColor &color )
138 {
139  QPixmap linesPixmap( d->m_linesColorButton->iconSize().width(),
140  d->m_linesColorButton->iconSize().height() );
141  linesPixmap.fill( color );
142  d->m_linesColorButton->setIcon( QIcon( linesPixmap ) );
143 }
144 
145 void EditPolygonDialog::updatePolyDialog( const QColor &color )
146 {
147  QPixmap polyPixmap( d->m_polyColorButton->iconSize().width(),
148  d->m_polyColorButton->iconSize().height() );
149  polyPixmap.fill( color );
150  d->m_polyColorButton->setIcon( QIcon( polyPixmap ) );
151 }
152 
153 }
154 
155 #include "EditPolygonDialog.moc"
Marble::GeoDataLineStyle
specifies the style how lines are drawn
Definition: GeoDataLineStyle.h:36
QWidget
Marble::GeoDataPolyStyle::fill
bool fill() const
Return true if polygons get filled.
Definition: GeoDataPolyStyle.cpp:95
EditPolygonDialog.h
QPixmap::fill
void fill(const QColor &color)
QWidget::style
QStyle * style() const
Marble::GeoDataStyle::polyStyle
GeoDataPolyStyle & polyStyle()
Return the label style of this style.
Definition: GeoDataStyle.cpp:153
Marble::GeoDataColorStyle::setColor
void setColor(const QColor &value)
Set a new color.
Definition: GeoDataColorStyle.cpp:84
GeoDataStyle.h
QDialog::accepted
void accepted()
QDialog::exec
int exec()
Marble::GeoDataFeature::description
QString description() const
Return the text description of the feature.
Definition: GeoDataFeature.cpp:588
Marble::GeoDataFeature::style
const GeoDataStyle * style() const
Return the style assigned to the placemark, or a default style if none has been set.
Definition: GeoDataFeature.cpp:709
Marble::GeoDataStyle::lineStyle
GeoDataLineStyle & lineStyle()
Return the label style of this style.
Definition: GeoDataStyle.cpp:143
Marble::EditPolygonDialog::~EditPolygonDialog
~EditPolygonDialog()
Definition: EditPolygonDialog.cpp:109
Marble::GeoDataLineStyle::width
float width() const
Return the current width of the line.
Definition: GeoDataLineStyle.cpp:100
QDialog::finished
void finished(int result)
Marble::GeoDataStyle
an addressable style group
Definition: GeoDataStyle.h:55
Marble::EditPolygonDialog::EditPolygonDialog
EditPolygonDialog(GeoDataPlacemark *placemark, QWidget *parent=0)
Definition: EditPolygonDialog.cpp:49
Marble::GeoDataLineStyle::setWidth
void setWidth(const float &width)
Set the width of the line.
Definition: GeoDataLineStyle.cpp:95
Marble::GeoDataPolyStyle::setFill
void setFill(const bool &fill)
Set whether to fill the polygon.
Definition: GeoDataPolyStyle.cpp:90
QColorDialog
QObject::deleteLater
void deleteLater()
QColor
QPixmap
Marble::GeoDataFeature::name
QString name() const
The name of the feature.
Definition: GeoDataFeature.cpp:544
Marble::GeoDataColorStyle::color
QColor color() const
Return the color component.
Definition: GeoDataColorStyle.cpp:98
QDialog
QPushButton
Marble::EditPolygonDialog::polygonUpdated
void polygonUpdated(GeoDataFeature *feature)
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Marble::GeoDataPolyStyle
specifies the style how polygons are drawn
Definition: GeoDataPolyStyle.h:34
Marble::GeoDataPlacemark
a class representing a point of interest on the map
Definition: GeoDataPlacemark.h:54
QIcon
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:39 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal