QGIS API Documentation  2.14.11-Essen
qgscolorbuttonv2.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscolorbuttonv2.cpp - Button which displays a color
3  --------------------------------------
4  Date : 12-Dec-2006
5  Copyright : (C) 2006 by Tom Elwertowski
6  Email : telwertowski at users dot sourceforge dot net
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 
16 #include "qgscolorbuttonv2.h"
17 #include "qgscolordialog.h"
18 #include "qgsapplication.h"
19 #include "qgslogger.h"
20 #include "qgssymbollayerv2utils.h"
21 #include "qgscursors.h"
22 #include "qgscolorswatchgrid.h"
23 #include "qgscolorschemeregistry.h"
24 #include "qgscolorwidgets.h"
25 
26 #include <QPainter>
27 #include <QSettings>
28 #include <QTemporaryFile>
29 #include <QMouseEvent>
30 #include <QMenu>
31 #include <QClipboard>
32 #include <QDrag>
33 #include <QDesktopWidget>
34 #include <QStyle>
35 #include <QStyleOptionToolButton>
36 #include <QWidgetAction>
37 #include <QLabel>
38 #include <QGridLayout>
39 #include <QPushButton>
40 
42  : QToolButton( parent )
43  , mBehaviour( QgsColorButtonV2::ShowDialog )
44  , mColorDialogTitle( cdt.isEmpty() ? tr( "Select Color" ) : cdt )
45  , mColor( QColor() )
46  , mDefaultColor( QColor() ) //default to invalid color
47  , mAllowAlpha( false )
48  , mAcceptLiveUpdates( true )
49  , mColorSet( false )
50  , mShowNoColorOption( false )
51  , mNoColorString( tr( "No color" ) )
52  , mPickingColor( false )
53  , mMenu( nullptr )
54 
55 {
56  //if a color scheme registry was specified, use it, otherwise use the global instance
57  mColorSchemeRegistry = registry ? registry : QgsColorSchemeRegistry::instance();
58 
59  setAcceptDrops( true );
60  setMinimumSize( QSize( 24, 16 ) );
61  connect( this, SIGNAL( clicked() ), this, SLOT( buttonClicked() ) );
62 
63  //setup dropdown menu
64  mMenu = new QMenu( this );
65  connect( mMenu, SIGNAL( aboutToShow() ), this, SLOT( prepareMenu() ) );
66  setMenu( mMenu );
67  setPopupMode( QToolButton::MenuButtonPopup );
68 }
69 
71 {
72 }
73 
75 {
76  //make sure height of button looks good under different platforms
77 #ifdef Q_OS_WIN
78  return QSize( 120, 22 );
79 #else
80  return QSize( 120, 28 );
81 #endif
82 }
83 
85 {
86  static QPixmap transpBkgrd;
87 
88  if ( transpBkgrd.isNull() )
89  transpBkgrd = QgsApplication::getThemePixmap( "/transp-background_8x8.png" );
90 
91  return transpBkgrd;
92 }
93 
94 void QgsColorButtonV2::showColorDialog()
95 {
96  QColor newColor;
97  QSettings settings;
98 
99  //using native color dialogs?
100  bool useNative = settings.value( "/qgis/native_color_dialogs", false ).toBool();
101 
102  if ( useNative )
103  {
104  // use native o/s dialogs
105  if ( mAcceptLiveUpdates && settings.value( "/qgis/live_color_dialogs", false ).toBool() )
106  {
107  newColor = QgsColorDialog::getLiveColor(
108  color(), this, SLOT( setValidColor( const QColor& ) ),
109  this->parentWidget(), mColorDialogTitle, mAllowAlpha ? QColorDialog::ShowAlphaChannel : ( QColorDialog::ColorDialogOption )0 );
110  }
111  else
112  {
113  newColor = QColorDialog::getColor( color(), this->parentWidget(), mColorDialogTitle, mAllowAlpha ? QColorDialog::ShowAlphaChannel : ( QColorDialog::ColorDialogOption )0 );
114  }
115  }
116  else
117  {
118  //use QGIS style color dialogs
119  if ( mAcceptLiveUpdates && settings.value( "/qgis/live_color_dialogs", false ).toBool() )
120  {
122  color(), this, SLOT( setValidColor( const QColor& ) ),
123  this->parentWidget(), mColorDialogTitle, mAllowAlpha );
124  }
125  else
126  {
127  QgsColorDialogV2 dialog( this, nullptr, color() );
128  dialog.setTitle( mColorDialogTitle );
129  dialog.setAllowAlpha( mAllowAlpha );
130 
131  if ( dialog.exec() )
132  {
133  newColor = dialog.color();
134  }
135  }
136  }
137 
138  if ( newColor.isValid() )
139  {
140  setValidColor( newColor );
141  addRecentColor( newColor );
142  }
143 
144  // reactivate button's window
145  activateWindow();
146 }
147 
149 {
150  if ( !mDefaultColor.isValid() )
151  {
152  return;
153  }
154 
155  setColor( mDefaultColor );
156 }
157 
159 {
160  if ( mAllowAlpha )
161  {
162  QColor noColor = QColor( mColor );
163  noColor.setAlpha( 0 );
164  setColor( noColor );
165  }
166 }
167 
169 {
170  if ( mPickingColor )
171  {
172  //don't show dialog if in color picker mode
173  e->accept();
174  return;
175  }
176 
177  if ( e->button() == Qt::RightButton )
178  {
180  return;
181  }
182  else if ( e->button() == Qt::LeftButton )
183  {
184  mDragStartPosition = e->pos();
185  }
187 }
188 
189 bool QgsColorButtonV2::colorFromMimeData( const QMimeData * mimeData, QColor& resultColor )
190 {
191  bool hasAlpha = false;
192  QColor mimeColor = QgsSymbolLayerV2Utils::colorFromMimeData( mimeData, hasAlpha );
193 
194  if ( mimeColor.isValid() )
195  {
196  if ( !mAllowAlpha )
197  {
198  //remove alpha channel
199  mimeColor.setAlpha( 255 );
200  }
201  else if ( !hasAlpha )
202  {
203  //mime color has no explicit alpha component, so keep existing alpha
204  mimeColor.setAlpha( mColor.alpha() );
205  }
206  resultColor = mimeColor;
207  return true;
208  }
209 
210  //could not get color from mime data
211  return false;
212 }
213 
215 {
216  if ( mPickingColor )
217  {
218  //currently in color picker mode
219  if ( e->buttons() & Qt::LeftButton )
220  {
221  //if left button depressed, sample color under cursor and temporarily update button color
222  //to give feedback to user
223  QPixmap snappedPixmap = QPixmap::grabWindow( QApplication::desktop()->winId(), e->globalPos().x(), e->globalPos().y(), 1, 1 );
224  QImage snappedImage = snappedPixmap.toImage();
225  QColor hoverColor = snappedImage.pixel( 0, 0 );
226  setButtonBackground( hoverColor );
227  }
228  e->accept();
229  return;
230  }
231 
232  //handle dragging colors from button
233 
234  if ( !( e->buttons() & Qt::LeftButton ) || !mColor.isValid() )
235  {
236  //left button not depressed or no color set, so not a drag
238  return;
239  }
240 
241  if (( e->pos() - mDragStartPosition ).manhattanLength() < QApplication::startDragDistance() )
242  {
243  //mouse not moved, so not a drag
245  return;
246  }
247 
248  //user is dragging color
249  QDrag *drag = new QDrag( this );
251  drag->setPixmap( QgsColorWidget::createDragIcon( mColor ) );
252  drag->exec( Qt::CopyAction );
253  setDown( false );
254 }
255 
257 {
258  if ( mPickingColor )
259  {
260  //end color picking operation by sampling the color under cursor
261  stopPicking( e->globalPos() );
262  e->accept();
263  return;
264  }
265 
267 }
268 
269 void QgsColorButtonV2::stopPicking( QPointF eventPos, bool sampleColor )
270 {
271  //release mouse and keyboard, and reset cursor
272  releaseMouse();
273  releaseKeyboard();
274  unsetCursor();
275  mPickingColor = false;
276 
277  if ( !sampleColor )
278  {
279  //not sampling color, nothing more to do
280  return;
281  }
282 
283  //grab snapshot of pixel under mouse cursor
284  QPixmap snappedPixmap = QPixmap::grabWindow( QApplication::desktop()->winId(), eventPos.x(), eventPos.y(), 1, 1 );
285  QImage snappedImage = snappedPixmap.toImage();
286  //extract color from pixel and set color
287  setColor( snappedImage.pixel( 0, 0 ) );
288  addRecentColor( mColor );
289 }
290 
292 {
293  if ( !mPickingColor )
294  {
295  //if not picking a color, use default tool button behaviour
297  return;
298  }
299 
300  //cancel picking, sampling the color if space was pressed
301  stopPicking( QCursor::pos(), e->key() == Qt::Key_Space );
302 }
303 
305 {
306  //is dragged data valid color data?
307  QColor mimeColor;
308  if ( colorFromMimeData( e->mimeData(), mimeColor ) )
309  {
310  //if so, we accept the drag, and temporarily change the button's color
311  //to match the dragged color. This gives immediate feedback to the user
312  //that colors can be dropped here
314  setButtonBackground( mimeColor );
315  }
316 }
317 
319 {
320  Q_UNUSED( e );
321  //reset button color
322  setButtonBackground( mColor );
323 }
324 
326 {
327  //is dropped data valid color data?
328  QColor mimeColor;
329  if ( colorFromMimeData( e->mimeData(), mimeColor ) )
330  {
331  //accept drop and set new color
333  setColor( mimeColor );
334  addRecentColor( mimeColor );
335  }
336 }
337 
338 void QgsColorButtonV2::setValidColor( const QColor& newColor )
339 {
340  if ( newColor.isValid() )
341  {
342  setColor( newColor );
343  addRecentColor( newColor );
344  }
345 }
346 
347 QPixmap QgsColorButtonV2::createMenuIcon( const QColor &color, const bool showChecks )
348 {
349  //create an icon pixmap
350  QPixmap pixmap( 16, 16 );
351  pixmap.fill( Qt::transparent );
352 
353  QPainter p;
354  p.begin( &pixmap );
355 
356  //start with checkboard pattern
357  if ( showChecks )
358  {
359  QBrush checkBrush = QBrush( transparentBackground() );
360  p.setPen( Qt::NoPen );
361  p.setBrush( checkBrush );
362  p.drawRect( 0, 0, 15, 15 );
363  }
364 
365  //draw color over pattern
366  p.setBrush( QBrush( color ) );
367 
368  //draw border
369  p.setPen( QColor( 197, 197, 197 ) );
370  p.drawRect( 0, 0, 15, 15 );
371  p.end();
372  return pixmap;
373 }
374 
375 void QgsColorButtonV2::buttonClicked()
376 {
377  switch ( mBehaviour )
378  {
379  case ShowDialog:
380  showColorDialog();
381  return;
382  case SignalOnly:
383  emit colorClicked( mColor );
384  return;
385  }
386 }
387 
388 void QgsColorButtonV2::prepareMenu()
389 {
390  //we need to tear down and rebuild this menu every time it is shown. Otherwise the space allocated to any
391  //QgsColorSwatchGridAction is not recalculated by Qt and the swatch grid may not be the correct size
392  //for the number of colors shown in the grid. Note that we MUST refresh color swatch grids every time this
393  //menu is opened, otherwise color schemes like the recent color scheme grid are meaningless
394  mMenu->clear();
395 
396  //show default color option if set
397  if ( mDefaultColor.isValid() )
398  {
399  QAction* defaultColorAction = new QAction( tr( "Default color" ), this );
400  defaultColorAction->setIcon( createMenuIcon( mDefaultColor ) );
401  mMenu->addAction( defaultColorAction );
402  connect( defaultColorAction, SIGNAL( triggered() ), this, SLOT( setToDefaultColor() ) );
403  }
404 
405  if ( mShowNoColorOption && mAllowAlpha )
406  {
407  QAction* noColorAction = new QAction( mNoColorString, this );
408  noColorAction->setIcon( createMenuIcon( Qt::transparent, false ) );
409  mMenu->addAction( noColorAction );
410  connect( noColorAction, SIGNAL( triggered() ), this, SLOT( setToNoColor() ) );
411  }
412 
413  if ( mColorSchemeRegistry )
414  {
415  //get schemes with ShowInColorButtonMenu flag set
416  QList< QgsColorScheme* > schemeList = mColorSchemeRegistry->schemes( QgsColorScheme::ShowInColorButtonMenu );
417  QList< QgsColorScheme* >::iterator it = schemeList.begin();
418  for ( ; it != schemeList.end(); ++it )
419  {
420  QgsColorSwatchGridAction* colorAction = new QgsColorSwatchGridAction( *it, mMenu, mContext, this );
421  colorAction->setBaseColor( mColor );
422  mMenu->addAction( colorAction );
423  connect( colorAction, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setValidColor( const QColor& ) ) );
424  connect( colorAction, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( addRecentColor( const QColor& ) ) );
425  }
426  }
427 
428  mMenu->addSeparator();
429 
430  QAction* copyColorAction = new QAction( tr( "Copy color" ), this );
431  mMenu->addAction( copyColorAction );
432  connect( copyColorAction, SIGNAL( triggered() ), this, SLOT( copyColor() ) );
433 
434  QAction* pasteColorAction = new QAction( tr( "Paste color" ), this );
435  //enable or disable paste action based on current clipboard contents. We always show the paste
436  //action, even if it's disabled, to give hint to the user that pasting colors is possible
437  QColor clipColor;
438  if ( colorFromMimeData( QApplication::clipboard()->mimeData(), clipColor ) )
439  {
440  pasteColorAction->setIcon( createMenuIcon( clipColor ) );
441  }
442  else
443  {
444  pasteColorAction->setEnabled( false );
445  }
446  mMenu->addAction( pasteColorAction );
447  connect( pasteColorAction, SIGNAL( triggered() ), this, SLOT( pasteColor() ) );
448 
449 #ifndef Q_OS_MAC
450  //disabled for OSX, as it is impossible to grab the mouse under OSX
451  //see note for QWidget::grabMouse() re OSX Cocoa
452  //http://qt-project.org/doc/qt-4.8/qwidget.html#grabMouse
453  QAction* pickColorAction = new QAction( tr( "Pick color" ), this );
454  mMenu->addAction( pickColorAction );
455  connect( pickColorAction, SIGNAL( triggered() ), this, SLOT( activatePicker() ) );
456 #endif
457  QAction* chooseColorAction = new QAction( tr( "Choose color..." ), this );
458  mMenu->addAction( chooseColorAction );
459  connect( chooseColorAction, SIGNAL( triggered() ), this, SLOT( showColorDialog() ) );
460 }
461 
463 {
464  if ( e->type() == QEvent::EnabledChange )
465  {
467  }
469 }
470 
471 #if 0 // causes too many cyclical updates, but may be needed on some platforms
473 {
475 
476  if ( !mBackgroundSet )
477  {
479  }
480 }
481 #endif
482 
484 {
487 }
488 
490 {
491  QToolButton::resizeEvent( event );
492  //recalculate icon size and redraw icon
493  mIconSize = QSize();
494  setButtonBackground( mColor );
495 }
496 
497 void QgsColorButtonV2::setColor( const QColor &color )
498 {
499  QColor oldColor = mColor;
500  mColor = color;
501 
502  // handle when initially set color is same as default (Qt::black); consider it a color change
503  if ( oldColor != mColor || ( mColor == QColor( Qt::black ) && !mColorSet ) )
504  {
506  if ( isEnabled() )
507  {
508  // TODO: May be beneficial to have the option to set color without emitting this signal.
509  // Now done by blockSignals( bool ) where button is used
510  emit colorChanged( mColor );
511  }
512  }
513  mColorSet = true;
514 }
515 
516 void QgsColorButtonV2::addRecentColor( const QColor& color )
517 {
519 }
520 
522 {
523  QColor backgroundColor = color;
524 
525  if ( !color.isValid() )
526  {
527  backgroundColor = mColor;
528  }
529 
530  QSize currentIconSize;
531  //icon size is button size with a small margin
532  if ( menu() )
533  {
534  if ( !mIconSize.isValid() )
535  {
536  //calculate size of push button part of widget (ie, without the menu dropdown button part)
538  initStyleOption( &opt );
539  QRect buttonSize = QApplication::style()->subControlRect( QStyle::CC_ToolButton, &opt, QStyle::SC_ToolButton,
540  this );
541  //make sure height of icon looks good under different platforms
542 #ifdef Q_OS_WIN
543  mIconSize = QSize( buttonSize.width() - 10, height() - 6 );
544 #else
545  mIconSize = QSize( buttonSize.width() - 10, height() - 12 );
546 #endif
547  }
548  currentIconSize = mIconSize;
549  }
550  else
551  {
552  //no menu
553 #ifdef Q_OS_WIN
554  currentIconSize = QSize( width() - 10, height() - 6 );
555 #else
556  currentIconSize = QSize( width() - 10, height() - 12 );
557 #endif
558  }
559 
560  if ( !currentIconSize.isValid() || currentIconSize.width() <= 0 || currentIconSize.height() <= 0 )
561  {
562  return;
563  }
564 
565  //create an icon pixmap
566  QPixmap pixmap( currentIconSize );
567  pixmap.fill( Qt::transparent );
568 
569  if ( backgroundColor.isValid() )
570  {
571  QRect rect( 0, 0, currentIconSize.width(), currentIconSize.height() );
572  QPainter p;
573  p.begin( &pixmap );
574  p.setRenderHint( QPainter::Antialiasing );
575  p.setPen( Qt::NoPen );
576  if ( mAllowAlpha && backgroundColor.alpha() < 255 )
577  {
578  //start with checkboard pattern
579  QBrush checkBrush = QBrush( transparentBackground() );
580  p.setBrush( checkBrush );
581  p.drawRoundedRect( rect, 3, 3 );
582  }
583 
584  //draw semi-transparent color on top
585  p.setBrush( backgroundColor );
586  p.drawRoundedRect( rect, 3, 3 );
587  p.end();
588  }
589 
590  setIconSize( currentIconSize );
591  setIcon( pixmap );
592 }
593 
595 {
596  //copy color
598 }
599 
601 {
602  QColor clipColor;
603  if ( colorFromMimeData( QApplication::clipboard()->mimeData(), clipColor ) )
604  {
605  //paste color
606  setColor( clipColor );
607  addRecentColor( clipColor );
608  }
609 }
610 
612 {
613  //pick color
614  QPixmap samplerPixmap = QPixmap(( const char ** ) sampler_cursor );
615  setCursor( QCursor( samplerPixmap, 0, 0 ) );
616  grabMouse();
617  grabKeyboard();
618  mPickingColor = true;
619 }
620 
622 {
623  return mColor;
624 }
625 
627 {
628  mAllowAlpha = allowAlpha;
629 }
630 
632 {
633  mColorDialogTitle = title;
634 }
635 
637 {
638  return mColorDialogTitle;
639 }
640 
642 {
643  setMenu( showMenu ? mMenu : nullptr );
644  setPopupMode( showMenu ? QToolButton::MenuButtonPopup : QToolButton::DelayedPopup );
645  //force recalculation of icon size
646  mIconSize = QSize();
647  setButtonBackground( mColor );
648 }
649 
651 {
652  mBehaviour = behaviour;
653 }
654 
656 {
657  mDefaultColor = color;
658 }
659 
QColor color() const
Return the currently selected color.
bool showMenu() const
Returns whether the drop down menu is shown for the button.
void dragLeaveEvent(QDragLeaveEvent *e) override
Reimplemented to reset button appearance after drag leave.
void setDown(bool)
void releaseMouse()
void setColorDialogTitle(const QString &title)
Set the title for the color chooser dialog window.
bool isValid() const
void setMenu(QMenu *menu)
Type type() const
A cross platform button subclass for selecting colors.
void dropEvent(QDropEvent *e) override
Reimplemented to accept dropped colors.
int width() const
Registry of color schemes.
bool end()
void unsetCursor()
const QMimeData * mimeData() const
static QMimeData * colorToMimeData(const QColor &color)
Creates mime data from a color.
QColor color() const
Returns the current color for the dialog.
void activatePicker()
Activates the color picker tool, which allows for sampling a color from anywhere on the screen...
void fill(const QColor &color)
void setMimeData(QMimeData *data)
void setButtonBackground(const QColor &color=QColor())
Sets the background pixmap for the button based upon color and transparency.
A custom QGIS dialog for selecting a color.
void changeEvent(QEvent *e) override
void setPixmap(const QPixmap &pixmap)
void setIcon(const QIcon &icon)
virtual void mouseMoveEvent(QMouseEvent *e)
void addAction(QAction *action)
static QColor colorFromMimeData(const QMimeData *data, bool &hasAlpha)
Attempts to parse mime data as a color.
void mousePressEvent(QMouseEvent *e) override
Reimplemented to detect right mouse button clicks on the color button and allow dragging colors...
int exec()
void colorChanged(const QColor &color)
Is emitted whenever a new color is set for the button.
void setAlpha(int alpha)
QPixmap grabWindow(WId window, int x, int y, int width, int height)
virtual QRect subControlRect(ComplexControl control, const QStyleOptionComplex *option, SubControl subControl, const QWidget *widget) const=0
Qt::MouseButtons buttons() const
void acceptProposedAction()
void showEvent(QShowEvent *e) override
void triggered(QAction *action)
void setIcon(const QIcon &icon)
QString tr(const char *sourceText, const char *disambiguation, int n)
static QPixmap getThemePixmap(const QString &theName)
Helper to get a theme icon as a pixmap.
void setToDefaultColor()
Sets color to the button&#39;s default color, if set.
uint pixel(int screen) const
void initStyleOption(QStyleOptionToolButton *option) const
int x() const
int y() const
void mouseMoveEvent(QMouseEvent *e) override
Reimplemented to allow dragging colors from button.
int width() const
virtual QSize sizeHint() const override
void setDefaultColor(const QColor &color)
Sets the default color for the button, which is shown in the button&#39;s drop down menu for the "default...
Qt::DropAction exec(QFlags< Qt::DropAction > supportedActions)
void setAllowAlpha(const bool allowAlpha)
Sets whether alpha modification (transparency) is permitted for the color dialog. ...
void setMinimumSize(const QSize &)
void drawRect(const QRectF &rectangle)
void clear()
QList< QgsColorScheme * > schemes() const
Returns all color schemes in the registry.
bool isEnabled() const
virtual void showEvent(QShowEvent *event)
qreal x() const
qreal y() const
const QPoint & globalPos() const
virtual void mousePressEvent(QMouseEvent *e)
QClipboard * clipboard()
void setPen(const QColor &color)
void setIconSize(const QSize &size)
Qt::MouseButton button() const
Behaviour behaviour() const
Returns the behaviour for when the button is clicked.
virtual void paintEvent(QPaintEvent *event)
void clicked(bool checked)
virtual void mouseReleaseEvent(QMouseEvent *e)
void setTitle(const QString &title)
Sets the title for the color dialog.
void setBehaviour(const Behaviour behaviour)
Sets the behaviour for when the button is clicked.
void setBrush(const QBrush &brush)
void keyPressEvent(QKeyEvent *e) override
Reimplemented to allow cancelling color pick via keypress, and sample via space bar press...
virtual bool event(QEvent *event)
WId winId() const
QAction * addSeparator()
const QPixmap * pixmap() const
void pasteColor()
Pastes a color from the clipboard to the color button.
void setMimeData(QMimeData *src, Mode mode)
void setShowMenu(const bool showMenu)
Sets whether the drop down menu should be shown for the button.
int alpha() const
bool allowAlpha() const
Returns whether alpha modification (transparency) is permitted for the color.
virtual void changeEvent(QEvent *e)
void copyColor()
Copies the current color to the clipboard.
QRect rect() const
static void addRecentColor(const QColor &color)
Adds a color to the list of recent colors.
void setAcceptDrops(bool on)
iterator end()
int key() const
void setToNoColor()
Sets color to a totally transparent color.
void accept()
bool isNull() const
void setAllowAlpha(const bool allowAlpha)
Sets whether alpha modification (transparency) is permitted for the color.
QColor getColor(const QColor &initial, QWidget *parent, const QString &title, QFlags< QColorDialog::ColorDialogOption > options)
QMenu * menu() const
static QgsColorSchemeRegistry * instance()
Returns the global instance pointer, creating the object on the first call.
const char * sampler_cursor[]
Definition: qgscursors.cpp:183
void mouseReleaseEvent(QMouseEvent *e) override
Reimplemented to allow color picking.
QVariant value(const QString &key, const QVariant &defaultValue) const
void showMenu()
QString colorDialogTitle() const
Returns the title for the color chooser dialog window.
int width() const
QPoint pos()
void activateWindow()
virtual ~QgsColorButtonV2()
QStyle * style()
QDesktopWidget * desktop()
virtual void keyPressEvent(QKeyEvent *e)
void grabMouse()
void resizeEvent(QResizeEvent *event) override
void setColor(const QColor &color)
Sets the current color for the button.
QWidget * parentWidget() const
void releaseKeyboard()
void setPopupMode(ToolButtonPopupMode mode)
int height() const
QgsColorButtonV2(QWidget *parent=nullptr, const QString &cdt="", QgsColorSchemeRegistry *registry=nullptr)
Construct a new color button.
bool toBool() const
Behaviour
Specifies the behaviour when the button is clicked.
void colorClicked(const QColor &color)
Emitted when the button is clicked, if the button&#39;s behaviour is set to SignalOnly.
const QPoint & pos() const
void dragEnterEvent(QDragEnterEvent *e) override
Reimplemented to accept dragged colors.
QImage toImage() const
virtual void resizeEvent(QResizeEvent *event)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
static const QPixmap & transparentBackground()
Returns a checkboard pattern pixmap for use as a background to transparent colors.
bool begin(QPaintDevice *device)
static QPixmap createDragIcon(const QColor &color)
Create an icon for dragging colors.
void grabKeyboard()
static QColor getLiveColor(const QColor &initialColor, QObject *updateObject, const char *updateSlot, QWidget *parent=nullptr, const QString &title="", const QColorDialog::ColorDialogOptions &options=nullptr)
Return a color selection from a QColorDialog, with live updating of interim selections.
iterator begin()
void setEnabled(bool)
static QColor getLiveColor(const QColor &initialColor, QObject *updateObject, const char *updateSlot, QWidget *parent=nullptr, const QString &title=QString(), const bool allowAlpha=true)
Return a color selection from a color dialog, with live updating of interim selections.
int height() const
int startDragDistance()
bool isValid() const
void setBaseColor(const QColor &baseColor)
Sets the base color for the color grid.
#define tr(sourceText)