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