00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "qgscolorbutton.h"
00018 #include <QPainter>
00019
00035 QgsColorButton::QgsColorButton( QWidget *parent )
00036 : QToolButton( parent )
00037 {
00038 setToolButtonStyle( Qt::ToolButtonTextOnly );
00039 }
00040
00041 QgsColorButton::~QgsColorButton()
00042 {}
00043
00047 void QgsColorButton::paintEvent( QPaintEvent *e )
00048 {
00049 QToolButton::paintEvent( e );
00050 if (
00051 #ifdef Q_WS_MAC
00052
00053 isActiveWindow() &&
00054 #endif
00055 isEnabled() )
00056 {
00057 QPainter p( this );
00058 int margin = 2;
00059 QRect r = rect().adjusted( margin, margin, -margin, -margin );
00060 p.fillRect( r, mColor );
00061 }
00062 }
00063
00064 void QgsColorButton::setColor( const QColor &color )
00065 {
00066 mColor = color;
00067 update();
00068 }
00069
00070
00072
00073 QgsColorButtonV2::QgsColorButtonV2( QWidget* parent )
00074 : QPushButton( parent )
00075 {
00076 }
00077
00078 QgsColorButtonV2::QgsColorButtonV2( QString text, QWidget* parent )
00079 : QPushButton( text, parent )
00080 {
00081 }
00082
00083 void QgsColorButtonV2::setColor( const QColor &color )
00084 {
00085 mColor = color;
00086
00087 QPixmap pixmap( iconSize() );
00088 pixmap.fill( QColor( 0, 0, 0, 0 ) );
00089
00090 QRect rect( 1, 1, iconSize().width() - 2, iconSize().height() - 2 );
00091
00092
00093 QPainter p;
00094 p.begin( &pixmap );
00095 p.setPen( Qt::NoPen );
00096 p.setRenderHint( QPainter::Antialiasing );
00097 p.setBrush( color );
00098 p.drawRoundedRect( rect, 4, 4 );
00099 p.end();
00100
00101
00102 setIcon( QIcon( pixmap ) );
00103 }