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