QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
qgsbrushstylecombobox.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsbrushstylecombobox.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
17#include "qgsguiutils.h"
18
19#include <QList>
20#include <QPair>
21
22#include <QBrush>
23#include <QPainter>
24#include <QPen>
25
27 : QComboBox( parent )
28{
29 QList < QPair<Qt::BrushStyle, QString> > styles;
30 styles << qMakePair( Qt::SolidPattern, tr( "Solid" ) )
31 << qMakePair( Qt::NoBrush, tr( "No Brush" ) )
32 << qMakePair( Qt::HorPattern, tr( "Horizontal" ) )
33 << qMakePair( Qt::VerPattern, tr( "Vertical" ) )
34 << qMakePair( Qt::CrossPattern, tr( "Cross" ) )
35 << qMakePair( Qt::BDiagPattern, tr( "BDiagonal" ) )
36 << qMakePair( Qt::FDiagPattern, tr( "FDiagonal" ) )
37 << qMakePair( Qt::DiagCrossPattern, tr( "Diagonal X" ) )
38 << qMakePair( Qt::Dense1Pattern, tr( "Dense 1" ) )
39 << qMakePair( Qt::Dense2Pattern, tr( "Dense 2" ) )
40 << qMakePair( Qt::Dense3Pattern, tr( "Dense 3" ) )
41 << qMakePair( Qt::Dense4Pattern, tr( "Dense 4" ) )
42 << qMakePair( Qt::Dense5Pattern, tr( "Dense 5" ) )
43 << qMakePair( Qt::Dense6Pattern, tr( "Dense 6" ) )
44 << qMakePair( Qt::Dense7Pattern, tr( "Dense 7" ) );
45
46 const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
47 setIconSize( QSize( iconSize * 2, iconSize ) );
48
49 for ( int i = 0; i < styles.count(); i++ )
50 {
51 const Qt::BrushStyle style = styles.at( i ).first;
52 const QString name = styles.at( i ).second;
53 addItem( iconForBrush( style ), name, QVariant( static_cast<int>( style ) ) );
54 }
55
56 setCurrentIndex( 1 );
57
58}
59
60
62{
63 return ( Qt::BrushStyle ) currentData().toInt();
64}
65
66void QgsBrushStyleComboBox::setBrushStyle( Qt::BrushStyle style )
67{
68 const int idx = findData( QVariant( static_cast<int>( style ) ) );
69 setCurrentIndex( idx == -1 ? 0 : idx );
70}
71
72QIcon QgsBrushStyleComboBox::iconForBrush( Qt::BrushStyle style )
73{
74 QPixmap pix( iconSize() );
75 QPainter p;
76 pix.fill( Qt::transparent );
77
78 p.begin( &pix );
79 const QBrush brush( QColor( 100, 100, 100 ), style );
80 p.setBrush( brush );
81 const QPen pen( Qt::NoPen );
82 p.setPen( pen );
83 p.drawRect( QRect( QPoint( 0, 0 ), iconSize() ) );
84 p.end();
85
86 return QIcon( pix );
87}
Qt::BrushStyle brushStyle() const
QIcon iconForBrush(Qt::BrushStyle style)
QgsBrushStyleComboBox(QWidget *parent=nullptr)
void setBrushStyle(Qt::BrushStyle style)
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly,...