QGIS API Documentation  2.14.0-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  setColor( QColor( 0, 0, 0, 0 ) );
163  }
164 }
165 
167 {
168  if ( mPickingColor )
169  {
170  //don't show dialog if in color picker mode
171  e->accept();
172  return;
173  }
174 
175  if ( e->button() == Qt::RightButton )
176  {
178  return;
179  }
180  else if ( e->button() == Qt::LeftButton )
181  {
182  mDragStartPosition = e->pos();
183  }
185 }
186 
187 bool QgsColorButtonV2::colorFromMimeData( const QMimeData * mimeData, QColor& resultColor )
188 {
189  bool hasAlpha = false;
190  QColor mimeColor = QgsSymbolLayerV2Utils::colorFromMimeData( mimeData, hasAlpha );
191 
192  if ( mimeColor.isValid() )
193  {
194  if ( !mAllowAlpha )
195  {
196  //remove alpha channel
197  mimeColor.setAlpha( 255 );
198  }
199  else if ( !hasAlpha )
200  {
201  //mime color has no explicit alpha component, so keep existing alpha
202  mimeColor.setAlpha( mColor.alpha() );
203  }
204  resultColor = mimeColor;
205  return true;
206  }
207 
208  //could not get color from mime data
209  return false;
210 }
211 
213 {
214  if ( mPickingColor )
215  {
216  //currently in color picker mode
217  if ( e->buttons() & Qt::LeftButton )
218  {
219  //if left button depressed, sample color under cursor and temporarily update button color
220  //to give feedback to user
221  QPixmap snappedPixmap = QPixmap::grabWindow( QApplication::desktop()->winId(), e->globalPos().x(), e->globalPos().y(), 1, 1 );
222  QImage snappedImage = snappedPixmap.toImage();
223  QColor hoverColor = snappedImage.pixel( 0, 0 );
224  setButtonBackground( hoverColor );
225  }
226  e->accept();
227  return;
228  }
229 
230  //handle dragging colors from button
231 
232  if ( !( e->buttons() & Qt::LeftButton ) || !mColor.isValid() )
233  {
234  //left button not depressed or no color set, so not a drag
236  return;
237  }
238 
239  if (( e->pos() - mDragStartPosition ).manhattanLength() < QApplication::startDragDistance() )
240  {
241  //mouse not moved, so not a drag
243  return;
244  }
245 
246  //user is dragging color
247  QDrag *drag = new QDrag( this );
249  drag->setPixmap( QgsColorWidget::createDragIcon( mColor ) );
250  drag->exec( Qt::CopyAction );
251  setDown( false );
252 }
253 
255 {
256  if ( mPickingColor )
257  {
258  //end color picking operation by sampling the color under cursor
259  stopPicking( e->globalPos() );
260  e->accept();
261  return;
262  }
263 
265 }
266 
267 void QgsColorButtonV2::stopPicking( QPointF eventPos, bool sampleColor )
268 {
269  //release mouse and keyboard, and reset cursor
270  releaseMouse();
271  releaseKeyboard();
272  unsetCursor();
273  mPickingColor = false;
274 
275  if ( !sampleColor )
276  {
277  //not sampling color, nothing more to do
278  return;
279  }
280 
281  //grab snapshot of pixel under mouse cursor
282  QPixmap snappedPixmap = QPixmap::grabWindow( QApplication::desktop()->winId(), eventPos.x(), eventPos.y(), 1, 1 );
283  QImage snappedImage = snappedPixmap.toImage();
284  //extract color from pixel and set color
285  setColor( snappedImage.pixel( 0, 0 ) );
286  addRecentColor( mColor );
287 }
288 
290 {
291  if ( !mPickingColor )
292  {
293  //if not picking a color, use default tool button behaviour
295  return;
296  }
297 
298  //cancel picking, sampling the color if space was pressed
299  stopPicking( QCursor::pos(), e->key() == Qt::Key_Space );
300 }
301 
303 {
304  //is dragged data valid color data?
305  QColor mimeColor;
306  if ( colorFromMimeData( e->mimeData(), mimeColor ) )
307  {
308  //if so, we accept the drag, and temporarily change the button's color
309  //to match the dragged color. This gives immediate feedback to the user
310  //that colors can be dropped here
312  setButtonBackground( mimeColor );
313  }
314 }
315 
317 {
318  Q_UNUSED( e );
319  //reset button color
320  setButtonBackground( mColor );
321 }
322 
324 {
325  //is dropped data valid color data?
326  QColor mimeColor;
327  if ( colorFromMimeData( e->mimeData(), mimeColor ) )
328  {
329  //accept drop and set new color
331  setColor( mimeColor );
332  addRecentColor( mimeColor );
333  }
334 }
335 
336 void QgsColorButtonV2::setValidColor( const QColor& newColor )
337 {
338  if ( newColor.isValid() )
339  {
340  setColor( newColor );
341  addRecentColor( newColor );
342  }
343 }
344 
345 QPixmap QgsColorButtonV2::createMenuIcon( const QColor &color, const bool showChecks )
346 {
347  //create an icon pixmap
348  QPixmap pixmap( 16, 16 );
349  pixmap.fill( Qt::transparent );
350 
351  QPainter p;
352  p.begin( &pixmap );
353 
354  //start with checkboard pattern
355  if ( showChecks )
356  {
357  QBrush checkBrush = QBrush( transparentBackground() );
358  p.setPen( Qt::NoPen );
359  p.setBrush( checkBrush );
360  p.drawRect( 0, 0, 15, 15 );
361  }
362 
363  //draw color over pattern
364  p.setBrush( QBrush( color ) );
365 
366  //draw border
367  p.setPen( QColor( 197, 197, 197 ) );
368  p.drawRect( 0, 0, 15, 15 );
369  p.end();
370  return pixmap;
371 }
372 
373 void QgsColorButtonV2::buttonClicked()
374 {
375  switch ( mBehaviour )
376  {
377  case ShowDialog:
378  showColorDialog();
379  return;
380  case SignalOnly:
381  emit colorClicked( mColor );
382  return;
383  }
384 }
385 
386 void QgsColorButtonV2::prepareMenu()
387 {
388  //we need to tear down and rebuild this menu every time it is shown. Otherwise the space allocated to any
389  //QgsColorSwatchGridAction is not recalculated by Qt and the swatch grid may not be the correct size
390  //for the number of colors shown in the grid. Note that we MUST refresh color swatch grids every time this
391  //menu is opened, otherwise color schemes like the recent color scheme grid are meaningless
392  mMenu->clear();
393 
394  //show default color option if set
395  if ( mDefaultColor.isValid() )
396  {
397  QAction* defaultColorAction = new QAction( tr( "Default color" ), this );
398  defaultColorAction->setIcon( createMenuIcon( mDefaultColor ) );
399  mMenu->addAction( defaultColorAction );
400  connect( defaultColorAction, SIGNAL( triggered() ), this, SLOT( setToDefaultColor() ) );
401  }
402 
403  if ( mShowNoColorOption && mAllowAlpha )
404  {
405  QAction* noColorAction = new QAction( mNoColorString, this );
406  noColorAction->setIcon( createMenuIcon( Qt::transparent, false ) );
407  mMenu->addAction( noColorAction );
408  connect( noColorAction, SIGNAL( triggered() ), this, SLOT( setToNoColor() ) );
409  }
410 
411  if ( mColorSchemeRegistry )
412  {
413  //get schemes with ShowInColorButtonMenu flag set
414  QList< QgsColorScheme* > schemeList = mColorSchemeRegistry->schemes( QgsColorScheme::ShowInColorButtonMenu );
415  QList< QgsColorScheme* >::iterator it = schemeList.begin();
416  for ( ; it != schemeList.end(); ++it )
417  {
418  QgsColorSwatchGridAction* colorAction = new QgsColorSwatchGridAction( *it, mMenu, mContext, this );
419  colorAction->setBaseColor( mColor );
420  mMenu->addAction( colorAction );
421  connect( colorAction, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setValidColor( const QColor& ) ) );
422  connect( colorAction, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( addRecentColor( const QColor& ) ) );
423  }
424  }
425 
426  mMenu->addSeparator();
427 
428  QAction* copyColorAction = new QAction( tr( "Copy color" ), this );
429  mMenu->addAction( copyColorAction );
430  connect( copyColorAction, SIGNAL( triggered() ), this, SLOT( copyColor() ) );
431 
432  QAction* pasteColorAction = new QAction( tr( "Paste color" ), this );
433  //enable or disable paste action based on current clipboard contents. We always show the paste
434  //action, even if it's disabled, to give hint to the user that pasting colors is possible
435  QColor clipColor;
436  if ( colorFromMimeData( QApplication::clipboard()->mimeData(), clipColor ) )
437  {
438  pasteColorAction->setIcon( createMenuIcon( clipColor ) );
439  }
440  else
441  {
442  pasteColorAction->setEnabled( false );
443  }
444  mMenu->addAction( pasteColorAction );
445  connect( pasteColorAction, SIGNAL( triggered() ), this, SLOT( pasteColor() ) );
446 
447 #ifndef Q_OS_MAC
448  //disabled for OSX, as it is impossible to grab the mouse under OSX
449  //see note for QWidget::grabMouse() re OSX Cocoa
450  //http://qt-project.org/doc/qt-4.8/qwidget.html#grabMouse
451  QAction* pickColorAction = new QAction( tr( "Pick color" ), this );
452  mMenu->addAction( pickColorAction );
453  connect( pickColorAction, SIGNAL( triggered() ), this, SLOT( activatePicker() ) );
454 #endif
455  QAction* chooseColorAction = new QAction( tr( "Choose color..." ), this );
456  mMenu->addAction( chooseColorAction );
457  connect( chooseColorAction, SIGNAL( triggered() ), this, SLOT( showColorDialog() ) );
458 }
459 
461 {
462  if ( e->type() == QEvent::EnabledChange )
463  {
465  }
467 }
468 
469 #if 0 // causes too many cyclical updates, but may be needed on some platforms
471 {
473 
474  if ( !mBackgroundSet )
475  {
477  }
478 }
479 #endif
480 
482 {
485 }
486 
488 {
489  QToolButton::resizeEvent( event );
490  //recalculate icon size and redraw icon
491  mIconSize = QSize();
492  setButtonBackground( mColor );
493 }
494 
495 void QgsColorButtonV2::setColor( const QColor &color )
496 {
497  QColor oldColor = mColor;
498  mColor = color;
499 
500  // handle when initially set color is same as default (Qt::black); consider it a color change
501  if ( oldColor != mColor || ( mColor == QColor( Qt::black ) && !mColorSet ) )
502  {
504  if ( isEnabled() )
505  {
506  // TODO: May be beneficial to have the option to set color without emitting this signal.
507  // Now done by blockSignals( bool ) where button is used
508  emit colorChanged( mColor );
509  }
510  }
511  mColorSet = true;
512 }
513 
514 void QgsColorButtonV2::addRecentColor( const QColor& color )
515 {
517 }
518 
520 {
521  QColor backgroundColor = color;
522 
523  if ( !color.isValid() )
524  {
525  backgroundColor = mColor;
526  }
527 
528  QSize currentIconSize;
529  //icon size is button size with a small margin
530  if ( menu() )
531  {
532  if ( !mIconSize.isValid() )
533  {
534  //calculate size of push button part of widget (ie, without the menu dropdown button part)
536  initStyleOption( &opt );
537  QRect buttonSize = QApplication::style()->subControlRect( QStyle::CC_ToolButton, &opt, QStyle::SC_ToolButton,
538  this );
539  //make sure height of icon looks good under different platforms
540 #ifdef Q_OS_WIN
541  mIconSize = QSize( buttonSize.width() - 10, height() - 6 );
542 #else
543  mIconSize = QSize( buttonSize.width() - 10, height() - 12 );
544 #endif
545  }
546  currentIconSize = mIconSize;
547  }
548  else
549  {
550  //no menu
551 #ifdef Q_OS_WIN
552  currentIconSize = QSize( width() - 10, height() - 6 );
553 #else
554  currentIconSize = QSize( width() - 10, height() - 12 );
555 #endif
556  }
557 
558  if ( !currentIconSize.isValid() || currentIconSize.width() <= 0 || currentIconSize.height() <= 0 )
559  {
560  return;
561  }
562 
563  //create an icon pixmap
564  QPixmap pixmap( currentIconSize );
565  pixmap.fill( Qt::transparent );
566 
567  if ( backgroundColor.isValid() )
568  {
569  QRect rect( 0, 0, currentIconSize.width(), currentIconSize.height() );
570  QPainter p;
571  p.begin( &pixmap );
572  p.setRenderHint( QPainter::Antialiasing );
573  p.setPen( Qt::NoPen );
574  if ( mAllowAlpha && backgroundColor.alpha() < 255 )
575  {
576  //start with checkboard pattern
577  QBrush checkBrush = QBrush( transparentBackground() );
578  p.setBrush( checkBrush );
579  p.drawRoundedRect( rect, 3, 3 );
580  }
581 
582  //draw semi-transparent color on top
583  p.setBrush( backgroundColor );
584  p.drawRoundedRect( rect, 3, 3 );
585  p.end();
586  }
587 
588  setIconSize( currentIconSize );
589  setIcon( pixmap );
590 }
591 
593 {
594  //copy color
596 }
597 
599 {
600  QColor clipColor;
601  if ( colorFromMimeData( QApplication::clipboard()->mimeData(), clipColor ) )
602  {
603  //paste color
604  setColor( clipColor );
605  addRecentColor( clipColor );
606  }
607 }
608 
610 {
611  //pick color
612  QPixmap samplerPixmap = QPixmap(( const char ** ) sampler_cursor );
613  setCursor( QCursor( samplerPixmap, 0, 0 ) );
614  grabMouse();
615  grabKeyboard();
616  mPickingColor = true;
617 }
618 
620 {
621  return mColor;
622 }
623 
625 {
626  mAllowAlpha = allowAlpha;
627 }
628 
630 {
631  mColorDialogTitle = title;
632 }
633 
635 {
636  return mColorDialogTitle;
637 }
638 
640 {
641  setMenu( showMenu ? mMenu : nullptr );
642  setPopupMode( showMenu ? QToolButton::MenuButtonPopup : QToolButton::DelayedPopup );
643  //force recalculation of icon size
644  mIconSize = QSize();
645  setButtonBackground( mColor );
646 }
647 
649 {
650  mBehaviour = behaviour;
651 }
652 
654 {
655  mDefaultColor = color;
656 }
657 
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.
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
bool allowAlpha() const
Returns whether alpha modification (transparency) is permitted for the color.
void setPixmap(const QPixmap &pixmap)
void setIcon(const QIcon &icon)
virtual void mouseMoveEvent(QMouseEvent *e)
bool showMenu() const
Returns whether the drop down menu is shown for the button.
void addAction(QAction *action)
QColor color() const
Return the currently selected color.
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()
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()
QColor color() const
Returns the current color for the dialog.
void setPen(const QColor &color)
void setIconSize(const QSize &size)
Qt::MouseButton button() const
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
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
QString colorDialogTitle() const
Returns the title for the color chooser dialog window.
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()
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 behaviour() const
Returns the behaviour for when the button is clicked.
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()
QList< QgsColorScheme * > schemes() const
Returns all color schemes in the registry.
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)