23 #include <QTemporaryFile>
42 : QPushButton( parent )
43 , mColorDialogTitle( cdt.isEmpty() ?
tr(
"Select Color" ) : cdt )
45 , mColorDialogOptions( cdo )
46 , mAcceptLiveUpdates( true )
63 if ( transpBkgrd.isNull() )
74 if (
mAcceptLiveUpdates && settings.value(
"/qgis/live_color_dialogs",
false ).toBool() )
92 if ( newColor.isValid() )
100 if ( e->type() == QEvent::EnabledChange )
107 #if 0 // causes too many cyclical updates, but may be needed on some platforms
108 void QgsColorButton::paintEvent( QPaintEvent* e )
110 QPushButton::paintEvent( e );
112 if ( !mBackgroundSet )
127 if ( !color.isValid() )
150 if ( !text().isEmpty() )
156 pixmap = QPixmap( iconSize() );
157 pixmap.fill( QColor( 0, 0, 0, 0 ) );
159 int iconW = iconSize().width();
160 int iconH = iconSize().height();
161 QRect rect( 0, 0, iconW, iconH );
164 QPainterPath roundRect;
167 roundRect.moveTo( chamfer, inset );
168 roundRect.lineTo( iconW - chamfer, inset );
169 roundRect.lineTo( iconW - inset, chamfer );
170 roundRect.lineTo( iconW - inset, iconH - chamfer );
171 roundRect.lineTo( iconW - chamfer, iconH - inset );
172 roundRect.lineTo( chamfer, iconH - inset );
173 roundRect.lineTo( inset, iconH - chamfer );
174 roundRect.lineTo( inset, chamfer );
175 roundRect.closeSubpath();
179 p.setRenderHint( QPainter::Antialiasing );
180 p.setClipPath( roundRect );
181 p.setPen( Qt::NoPen );
182 if (
mColor.alpha() < 255 )
191 setIcon( QIcon( pixmap ) );
203 QString margin = QString(
"%1px %2px %3px %4px" ).arg( 0 ).arg( 0 ).arg( 0 ).arg( 0 );
207 QString bkgrd = QString(
" background-color: rgba(%1,%2,%3,%4);" )
211 .arg( useAlpha ?
mColor.alpha() : 255 );
213 if ( useAlpha &&
mColor.alpha() < 255 )
216 QRect rect( 0, 0, pixmap.width(), pixmap.height() );
220 p.setRenderHint( QPainter::Antialiasing );
221 p.setPen( Qt::NoPen );
229 pixmap.save(
mTempPNG.fileName(),
"PNG" );
233 bkgrd = QString(
" background-image: url(%1);" ).arg(
mTempPNG.fileName() );
239 setStyleSheet( QString(
"QgsColorButton{"
241 " background-position: top left;"
242 " background-origin: content;"
243 " background-clip: content;"
248 " border-width: 1px;"
249 " border-color: rgb(%3,%3,%3);"
250 " border-radius: 3px;} "
251 "QgsColorButton:pressed{"
253 " background-position: top left;"
254 " background-origin: content;"
255 " background-clip: content;"
259 " border-style: inset;"
260 " border-width: 2px;"
261 " border-color: rgb(128,128,128);"
262 " border-radius: 4px;} " )
265 .arg( isEnabled() ?
"128" :
"110" )
266 .arg( isEnabled() ?
"outset" :
"dotted" ) );