|
QGIS API Documentation
master-59fd5e0
|
00001 /*************************************************************************** 00002 qgsbrushstylecombobox.cpp 00003 --------------------- 00004 begin : November 2009 00005 copyright : (C) 2009 by Martin Dobias 00006 email : wonder dot sk at gmail dot com 00007 *************************************************************************** 00008 * * 00009 * This program is free software; you can redistribute it and/or modify * 00010 * it under the terms of the GNU General Public License as published by * 00011 * the Free Software Foundation; either version 2 of the License, or * 00012 * (at your option) any later version. * 00013 * * 00014 ***************************************************************************/ 00015 00016 #include "qgsbrushstylecombobox.h" 00017 00018 #include <QList> 00019 #include <QPair> 00020 00021 #include <QBrush> 00022 #include <QPainter> 00023 #include <QPen> 00024 00025 QgsBrushStyleComboBox::QgsBrushStyleComboBox( QWidget* parent ) 00026 : QComboBox( parent ) 00027 { 00028 QList < QPair<Qt::BrushStyle, QString> > styles; 00029 styles << qMakePair( Qt::SolidPattern, tr( "Solid" ) ) 00030 << qMakePair( Qt::NoBrush, tr( "No Brush" ) ) 00031 << qMakePair( Qt::HorPattern, tr( "Horizontal" ) ) 00032 << qMakePair( Qt::VerPattern, tr( "Vertical" ) ) 00033 << qMakePair( Qt::CrossPattern, tr( "Cross" ) ) 00034 << qMakePair( Qt::BDiagPattern, tr( "BDiagonal" ) ) 00035 << qMakePair( Qt::FDiagPattern, tr( "FDiagonal" ) ) 00036 << qMakePair( Qt::DiagCrossPattern, tr( "Diagonal X" ) ) 00037 << qMakePair( Qt::Dense1Pattern, tr( "Dense 1" ) ) 00038 << qMakePair( Qt::Dense2Pattern, tr( "Dense 2" ) ) 00039 << qMakePair( Qt::Dense3Pattern, tr( "Dense 3" ) ) 00040 << qMakePair( Qt::Dense4Pattern, tr( "Dense 4" ) ) 00041 << qMakePair( Qt::Dense5Pattern, tr( "Dense 5" ) ) 00042 << qMakePair( Qt::Dense6Pattern, tr( "Dense 6" ) ) 00043 << qMakePair( Qt::Dense7Pattern, tr( "Dense 7" ) ); 00044 00045 setIconSize( QSize( 32, 16 ) ); 00046 00047 for ( int i = 0; i < styles.count(); i++ ) 00048 { 00049 Qt::BrushStyle style = styles.at( i ).first; 00050 QString name = styles.at( i ).second; 00051 addItem( iconForBrush( style ), name, QVariant( style ) ); 00052 } 00053 00054 setCurrentIndex( 1 ); 00055 00056 } 00057 00058 00059 Qt::BrushStyle QgsBrushStyleComboBox::brushStyle() const 00060 { 00061 return ( Qt::BrushStyle ) itemData( currentIndex() ).toInt(); 00062 } 00063 00064 void QgsBrushStyleComboBox::setBrushStyle( Qt::BrushStyle style ) 00065 { 00066 int idx = findData( QVariant( style ) ); 00067 setCurrentIndex( idx == -1 ? 0 : idx ); 00068 } 00069 00070 QIcon QgsBrushStyleComboBox::iconForBrush( Qt::BrushStyle style ) 00071 { 00072 QPixmap pix( iconSize() ); 00073 QPainter p; 00074 pix.fill( Qt::transparent ); 00075 00076 p.begin( &pix ); 00077 QBrush brush( QColor( 100, 100, 100 ), style ); 00078 p.setBrush( brush ); 00079 QPen pen( Qt::NoPen ); 00080 p.setPen( pen ); 00081 p.drawRect( QRect( QPoint( 0, 0 ), iconSize() ) ); 00082 p.end(); 00083 00084 return QIcon( pix ); 00085 }