23 #include <QTemporaryFile>
42 : QPushButton( parent )
43 , mColorDialogTitle( cdt.isEmpty() ?
tr(
"Select Color" ) : cdt )
45 , mColorDialogOptions( cdo )
46 , mAcceptLiveUpdates( true )
62 if ( transpBkgrd.isNull() )
72 #if QT_VERSION >= 0x040500
74 if (
mAcceptLiveUpdates && settings.value(
"/qgis/live_color_dialogs",
false ).toBool() )
85 newColor = QColorDialog::getColor(
color(), this->parentWidget() );
95 if ( newColor.isValid() )
103 if ( e->type() == QEvent::EnabledChange )
110 #if 0 // causes too many cyclical updates, but may be needed on some platforms
111 void QgsColorButton::paintEvent( QPaintEvent* e )
113 QPushButton::paintEvent( e );
115 if ( !mBackgroundSet )
130 if ( !color.isValid() )
151 if ( !text().isEmpty() )
157 pixmap = QPixmap( iconSize() );
158 pixmap.fill( QColor( 0, 0, 0, 0 ) );
160 int iconW = iconSize().width();
161 int iconH = iconSize().height();
162 QRect rect( 0, 0, iconW, iconH );
165 QPainterPath roundRect;
168 roundRect.moveTo( chamfer, inset );
169 roundRect.lineTo( iconW - chamfer, inset );
170 roundRect.lineTo( iconW - inset, chamfer );
171 roundRect.lineTo( iconW - inset, iconH - chamfer );
172 roundRect.lineTo( iconW - chamfer, iconH - inset );
173 roundRect.lineTo( chamfer, iconH - inset );
174 roundRect.lineTo( inset, iconH - chamfer );
175 roundRect.lineTo( inset, chamfer );
176 roundRect.closeSubpath();
180 p.setRenderHint( QPainter::Antialiasing );
181 p.setClipPath( roundRect );
182 p.setPen( Qt::NoPen );
183 if (
mColor.alpha() < 255 )
192 setIcon( QIcon( pixmap ) );
204 QString margin = QString(
"%1px %2px %3px %4px" ).arg( 0 ).arg( 0 ).arg( 0 ).arg( 0 );
208 QString bkgrd = QString(
" background-color: rgba(%1,%2,%3,%4);" )
212 .arg( useAlpha ?
mColor.alpha() : 255 );
214 if ( useAlpha &&
mColor.alpha() < 255 )
217 QRect rect( 0, 0, pixmap.width(), pixmap.height() );
221 p.setRenderHint( QPainter::Antialiasing );
222 p.setPen( Qt::NoPen );
230 pixmap.save(
mTempPNG.fileName(),
"PNG" );
234 bkgrd = QString(
" background-image: url(%1);" ).arg(
mTempPNG.fileName() );
240 setStyleSheet( QString(
"QgsColorButton{"
242 " background-position: top left;"
243 " background-origin: content;"
244 " background-clip: content;"
249 " border-width: 1px;"
250 " border-color: rgb(%3,%3,%3);"
251 " border-radius: 3px;} "
252 "QgsColorButton:pressed{"
254 " background-position: top left;"
255 " background-origin: content;"
256 " background-clip: content;"
260 " border-style: inset;"
261 " border-width: 2px;"
262 " border-color: rgb(128,128,128);"
263 " border-radius: 4px;} " )
266 .arg( isEnabled() ?
"128" :
"110" )
267 .arg( isEnabled() ?
"outset" :
"dotted" ) );