QGIS API Documentation  2.11.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
qgspenstylecombobox.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgspenstylecombobox.cpp
3  ---------------------
4  begin : November 2009
5  copyright : (C) 2009 by Martin Dobias
6  email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgspenstylecombobox.h"
17 
18 #include "qgsapplication.h"
19 
20 #include <QList>
21 #include <QPair>
22 
23 #include <QPainter>
24 #include <QPen>
25 
27  : QComboBox( parent )
28 {
30  styles << qMakePair( Qt::SolidLine, tr( "Solid Line" ) )
31  << qMakePair( Qt::NoPen, tr( "No Pen" ) )
32  << qMakePair( Qt::DashLine, tr( "Dash Line" ) )
33  << qMakePair( Qt::DotLine, tr( "Dot Line" ) )
34  << qMakePair( Qt::DashDotLine, tr( "Dash Dot Line" ) )
35  << qMakePair( Qt::DashDotDotLine, tr( "Dash Dot Dot Line" ) );
36 
37  setIconSize( QSize( 32, 12 ) );
38 
39  for ( int i = 0; i < styles.count(); i++ )
40  {
41  Qt::PenStyle style = styles.at( i ).first;
42  QString name = styles.at( i ).second;
43  addItem( iconForPen( style ), name, QVariant(( int ) style ) );
44  }
45 }
46 
47 Qt::PenStyle QgsPenStyleComboBox::penStyle() const
48 {
49  return ( Qt::PenStyle ) itemData( currentIndex() ).toInt();
50 }
51 
52 void QgsPenStyleComboBox::setPenStyle( Qt::PenStyle style )
53 {
54  int idx = findData( QVariant(( int ) style ) );
55  setCurrentIndex( idx == -1 ? 0 : idx );
56 }
57 
59 {
60  QPixmap pix( iconSize() );
61  QPainter p;
62  pix.fill( Qt::transparent );
63 
64  p.begin( &pix );
65  QPen pen( style );
66  pen.setWidth( 2 );
67  p.setPen( pen );
68  double mid = iconSize().height() / 2.0;
69  p.drawLine( 0, mid, iconSize().width(), mid );
70  p.end();
71 
72  return QIcon( pix );
73 }
74 
75 
77 // join
78 
80  : QComboBox( parent )
81 {
83  addItem( QIcon( path + "/join_bevel.png" ), tr( "Bevel" ), QVariant( Qt::BevelJoin ) );
84  addItem( QIcon( path + "/join_miter.png" ), tr( "Miter" ), QVariant( Qt::MiterJoin ) );
85  addItem( QIcon( path + "/join_round.png" ), tr( "Round" ), QVariant( Qt::RoundJoin ) );
86 }
87 
88 Qt::PenJoinStyle QgsPenJoinStyleComboBox::penJoinStyle() const
89 {
90  return ( Qt::PenJoinStyle ) itemData( currentIndex() ).toInt();
91 }
92 
93 void QgsPenJoinStyleComboBox::setPenJoinStyle( Qt::PenJoinStyle style )
94 {
95  int idx = findData( QVariant( style ) );
96  setCurrentIndex( idx == -1 ? 0 : idx );
97 }
98 
99 
101 // cap
102 
104  : QComboBox( parent )
105 {
107  addItem( QIcon( path + "/cap_square.png" ), tr( "Square" ), QVariant( Qt::SquareCap ) );
108  addItem( QIcon( path + "/cap_flat.png" ), tr( "Flat" ), QVariant( Qt::FlatCap ) );
109  addItem( QIcon( path + "/cap_round.png" ), tr( "Round" ), QVariant( Qt::RoundCap ) );
110 }
111 
112 Qt::PenCapStyle QgsPenCapStyleComboBox::penCapStyle() const
113 {
114  return ( Qt::PenCapStyle ) itemData( currentIndex() ).toInt();
115 }
116 
117 void QgsPenCapStyleComboBox::setPenCapStyle( Qt::PenCapStyle style )
118 {
119  int idx = findData( QVariant( style ) );
120  setCurrentIndex( idx == -1 ? 0 : idx );
121 }
QgsPenStyleComboBox(QWidget *parent=NULL)
bool end()
void setPenStyle(Qt::PenStyle style)
void fill(const QColor &color)
QStyle * style() const
void setPenCapStyle(Qt::PenCapStyle style)
const T & at(int i) const
void setIconSize(const QSize &size)
QgsPenJoinStyleComboBox(QWidget *parent=NULL)
QgsPenCapStyleComboBox(QWidget *parent=NULL)
void drawLine(const QLineF &line)
QString tr(const char *sourceText, const char *disambiguation, int n)
void addItem(const QString &text, const QVariant &userData)
int width() const
const char * name() const
int count(const T &value) const
int toInt(bool *ok) const
void setPen(const QColor &color)
Qt::PenCapStyle penCapStyle() const
static const QString defaultThemePath()
Returns the path to the default theme directory.
Qt::PenJoinStyle penJoinStyle() const
void setPenJoinStyle(Qt::PenJoinStyle style)
QVariant itemData(int index, int role) const
QIcon iconForPen(Qt::PenStyle style)
Qt::PenStyle penStyle() const
int findData(const QVariant &data, int role, QFlags< Qt::MatchFlag > flags) const
void setWidth(int width)
int height() const
int currentIndex() const
bool begin(QPaintDevice *device)