QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
Loading...
Searching...
No Matches
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#include "qgsguiutils.h"
20
21#include <QAbstractItemView>
22#include <QList>
23#include <QPainter>
24#include <QPair>
25#include <QPen>
26
27#include "moc_qgspenstylecombobox.cpp"
28
30 : QComboBox( parent )
31{
32 QList<QPair<Qt::PenStyle, QString>> styles;
33 styles
34 << qMakePair( Qt::SolidLine, tr( "Solid Line" ) )
35 << qMakePair( Qt::NoPen, tr( "No Line" ) )
36 << qMakePair( Qt::DashLine, tr( "Dash Line" ) )
37 << qMakePair( Qt::DotLine, tr( "Dot Line" ) )
38 << qMakePair( Qt::DashDotLine, tr( "Dash Dot Line" ) )
39 << qMakePair( Qt::DashDotDotLine, tr( "Dash Dot Dot Line" ) );
40
41 const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
42 setIconSize( QSize( iconSize * 2, iconSize ) );
43
44 for ( int i = 0; i < styles.count(); i++ )
45 {
46 const Qt::PenStyle style = styles.at( i ).first;
47 const QString name = styles.at( i ).second;
48 addItem( iconForPen( style ), name, QVariant( ( int ) style ) );
49 }
50}
51
53{
54 return ( Qt::PenStyle ) currentData().toInt();
55}
56
57void QgsPenStyleComboBox::setPenStyle( Qt::PenStyle style )
58{
59 const int idx = findData( QVariant( ( int ) style ) );
60 setCurrentIndex( idx == -1 ? 0 : idx );
61}
62
63QIcon QgsPenStyleComboBox::iconForPen( Qt::PenStyle style )
64{
65 QPixmap pix( iconSize() );
66 QPainter p;
67 pix.fill( Qt::transparent );
68
69 p.begin( &pix );
70 QPen pen( style );
71 pen.setWidth( 2 );
72 pen.setColor( view()->palette().color( QPalette::Text ) );
73
74 p.setPen( pen );
75 const double mid = iconSize().height() / 2.0;
76 p.drawLine( 0, mid, iconSize().width(), mid );
77 p.end();
78
79 return QIcon( pix );
80}
81
82
84// join
85
87 : QComboBox( parent )
88{
89 const QString path = QgsApplication::defaultThemePath();
90 addItem( QIcon( path + "/join_bevel.svg" ), tr( "Bevel" ), QVariant( Qt::BevelJoin ) );
91 addItem( QIcon( path + "/join_miter.svg" ), tr( "Miter" ), QVariant( Qt::MiterJoin ) );
92 addItem( QIcon( path + "/join_round.svg" ), tr( "Round" ), QVariant( Qt::RoundJoin ) );
93}
94
96{
97 return ( Qt::PenJoinStyle ) currentData().toInt();
98}
99
100void QgsPenJoinStyleComboBox::setPenJoinStyle( Qt::PenJoinStyle style )
101{
102 const int idx = findData( QVariant( style ) );
103 setCurrentIndex( idx == -1 ? 0 : idx );
104}
105
106
108// cap
109
111 : QComboBox( parent )
112{
113 const QString path = QgsApplication::defaultThemePath();
114 addItem( QIcon( path + "/cap_square.svg" ), tr( "Square" ), QVariant( Qt::SquareCap ) );
115 addItem( QIcon( path + "/cap_flat.svg" ), tr( "Flat" ), QVariant( Qt::FlatCap ) );
116 addItem( QIcon( path + "/cap_round.svg" ), tr( "Round" ), QVariant( Qt::RoundCap ) );
117}
118
120{
121 return ( Qt::PenCapStyle ) currentData().toInt();
122}
123
124void QgsPenCapStyleComboBox::setPenCapStyle( Qt::PenCapStyle style )
125{
126 const int idx = findData( QVariant( style ) );
127 setCurrentIndex( idx == -1 ? 0 : idx );
128}
static QString defaultThemePath()
Returns the path to the default theme directory.
void setPenCapStyle(Qt::PenCapStyle style)
Qt::PenCapStyle penCapStyle() const
QgsPenCapStyleComboBox(QWidget *parent=nullptr)
Qt::PenJoinStyle penJoinStyle() const
QgsPenJoinStyleComboBox(QWidget *parent=nullptr)
void setPenJoinStyle(Qt::PenJoinStyle style)
void setPenStyle(Qt::PenStyle style)
QIcon iconForPen(Qt::PenStyle style)
Qt::PenStyle penStyle() const
QgsPenStyleComboBox(QWidget *parent=nullptr)
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly,...