QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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  , mShowNull( false )
53  , mPickingColor( false )
54  , mMenu( nullptr )
55 
56 {
57  //if a color scheme registry was specified, use it, otherwise use the global instance
58  mColorSchemeRegistry = registry ? registry : QgsColorSchemeRegistry::instance();
59 
60  setAcceptDrops( true );
61  setMinimumSize( QSize( 24, 16 ) );
62  connect( this, SIGNAL( clicked() ), this, SLOT( buttonClicked() ) );
63 
64  //setup dropdown menu
65  mMenu = new QMenu( this );
66  connect( mMenu, SIGNAL( aboutToShow() ), this, SLOT( prepareMenu() ) );
67  setMenu( mMenu );
68  setPopupMode( QToolButton::MenuButtonPopup );
69 }
70 
72 {
73 }
74 
76 {
77  //make sure height of button looks good under different platforms
78 #ifdef Q_OS_WIN
79  return QSize( 120, 22 );
80 #else
81  return QSize( 120, 28 );
82 #endif
83 }
84 
86 {
87  static QPixmap transpBkgrd;
88 
89  if ( transpBkgrd.isNull() )
90  transpBkgrd = QgsApplication::getThemePixmap( "/transp-background_8x8.png" );
91 
92  return transpBkgrd;
93 }
94 
95 void QgsColorButtonV2::showColorDialog()
96 {
97  QColor currentColor = color();
98  if ( QgsPanelWidget* panel = QgsPanelWidget::findParentPanel( this ) )
99  {
100  QgsCompoundColorWidget* colorWidget = new QgsCompoundColorWidget( panel, currentColor, panel->dockMode() ? QgsCompoundColorWidget::LayoutVertical :
102  colorWidget->setPanelTitle( mColorDialogTitle );
103  colorWidget->setAllowAlpha( mAllowAlpha );
104 
105  if ( currentColor.isValid() )
106  {
107  colorWidget->setPreviousColor( currentColor );
108  }
109 
110  connect( colorWidget, SIGNAL( currentColorChanged( QColor ) ), this, SLOT( setValidTemporaryColor( QColor ) ) );
111  connect( colorWidget, SIGNAL( panelAccepted( QgsPanelWidget* ) ), this, SLOT( panelAccepted( QgsPanelWidget* ) ) );
112  panel->openPanel( colorWidget );
113  return;
114  }
115 
116  QColor newColor;
117  QSettings settings;
118 
119  //using native color dialogs?
120  bool useNative = settings.value( "/qgis/native_color_dialogs", false ).toBool();
121 
122  if ( useNative )
123  {
124  // use native o/s dialogs
125  if ( mAcceptLiveUpdates && settings.value( "/qgis/live_color_dialogs", false ).toBool() )
126  {
127  newColor = QgsColorDialog::getLiveColor(
128  color(), this, SLOT( setValidColor( const QColor& ) ),
129  this->parentWidget(), mColorDialogTitle, mAllowAlpha ? QColorDialog::ShowAlphaChannel : ( QColorDialog::ColorDialogOption )0 );
130  }
131  else
132  {
133  newColor = QColorDialog::getColor( color(), this->parentWidget(), mColorDialogTitle, mAllowAlpha ? QColorDialog::ShowAlphaChannel : ( QColorDialog::ColorDialogOption )0 );
134  }
135  }
136  else
137  {
138  //use QGIS style color dialogs
139  if ( mAcceptLiveUpdates && settings.value( "/qgis/live_color_dialogs", false ).toBool() )
140  {
142  color(), this, SLOT( setValidColor( const QColor& ) ),
143  this->parentWidget(), mColorDialogTitle, mAllowAlpha );
144  }
145  else
146  {
147  QgsColorDialogV2 dialog( this, nullptr, color() );
148  dialog.setTitle( mColorDialogTitle );
149  dialog.setAllowAlpha( mAllowAlpha );
150 
151  if ( dialog.exec() )
152  {
153  newColor = dialog.color();
154  }
155  }
156  }
157 
158  if ( newColor.isValid() )
159  {
160  setValidColor( newColor );
161  addRecentColor( newColor );
162  }
163 
164  // reactivate button's window
165  activateWindow();
166 }
167 
169 {
170  if ( !mDefaultColor.isValid() )
171  {
172  return;
173  }
174 
175  setColor( mDefaultColor );
176 }
177 
179 {
180  setColor( QColor() );
181 }
182 
184 {
185  if ( e->type() == QEvent::ToolTip )
186  {
187  QString name = this->color().name();
188  int hue = this->color().hue();
189  int value = this->color().value();
190  int saturation = this->color().saturation();
191  QString info = QString( "HEX: %1 \n"
192  "RGB: %2 \n"
193  "HSV: %3,%4,%5" ).arg( name )
195  .arg( hue ).arg( saturation ).arg( value );
196  setToolTip( info );
197  }
198  return QToolButton::event( e );
199 }
200 
202 {
203  if ( mAllowAlpha )
204  {
205  QColor noColor = QColor( mColor );
206  noColor.setAlpha( 0 );
207  setColor( noColor );
208  }
209 }
210 
212 {
213  if ( mPickingColor )
214  {
215  //don't show dialog if in color picker mode
216  e->accept();
217  return;
218  }
219 
220  if ( e->button() == Qt::RightButton )
221  {
223  return;
224  }
225  else if ( e->button() == Qt::LeftButton )
226  {
227  mDragStartPosition = e->pos();
228  }
230 }
231 
232 bool QgsColorButtonV2::colorFromMimeData( const QMimeData * mimeData, QColor& resultColor )
233 {
234  bool hasAlpha = false;
235  QColor mimeColor = QgsSymbolLayerV2Utils::colorFromMimeData( mimeData, hasAlpha );
236 
237  if ( mimeColor.isValid() )
238  {
239  if ( !mAllowAlpha )
240  {
241  //remove alpha channel
242  mimeColor.setAlpha( 255 );
243  }
244  else if ( !hasAlpha )
245  {
246  //mime color has no explicit alpha component, so keep existing alpha
247  mimeColor.setAlpha( mColor.alpha() );
248  }
249  resultColor = mimeColor;
250  return true;
251  }
252 
253  //could not get color from mime data
254  return false;
255 }
256 
258 {
259  if ( mPickingColor )
260  {
261  //currently in color picker mode
262  if ( e->buttons() & Qt::LeftButton )
263  {
264  //if left button depressed, sample color under cursor and temporarily update button color
265  //to give feedback to user
266  QPixmap snappedPixmap = QPixmap::grabWindow( QApplication::desktop()->winId(), e->globalPos().x(), e->globalPos().y(), 1, 1 );
267  QImage snappedImage = snappedPixmap.toImage();
268  QColor hoverColor = snappedImage.pixel( 0, 0 );
269  setButtonBackground( hoverColor );
270  }
271  e->accept();
272  return;
273  }
274 
275  //handle dragging colors from button
276 
277  if ( !( e->buttons() & Qt::LeftButton ) || !mColor.isValid() )
278  {
279  //left button not depressed or no color set, so not a drag
281  return;
282  }
283 
284  if (( e->pos() - mDragStartPosition ).manhattanLength() < QApplication::startDragDistance() )
285  {
286  //mouse not moved, so not a drag
288  return;
289  }
290 
291  //user is dragging color
292  QDrag *drag = new QDrag( this );
294  drag->setPixmap( QgsColorWidget::createDragIcon( mColor ) );
295  drag->exec( Qt::CopyAction );
296  setDown( false );
297 }
298 
300 {
301  if ( mPickingColor )
302  {
303  //end color picking operation by sampling the color under cursor
304  stopPicking( e->globalPos() );
305  e->accept();
306  return;
307  }
308 
310 }
311 
312 void QgsColorButtonV2::stopPicking( QPointF eventPos, bool sampleColor )
313 {
314  //release mouse and keyboard, and reset cursor
315  releaseMouse();
316  releaseKeyboard();
317  unsetCursor();
318  mPickingColor = false;
319 
320  if ( !sampleColor )
321  {
322  //not sampling color, nothing more to do
323  return;
324  }
325 
326  //grab snapshot of pixel under mouse cursor
327  QPixmap snappedPixmap = QPixmap::grabWindow( QApplication::desktop()->winId(), eventPos.x(), eventPos.y(), 1, 1 );
328  QImage snappedImage = snappedPixmap.toImage();
329  //extract color from pixel and set color
330  setColor( snappedImage.pixel( 0, 0 ) );
331  addRecentColor( mColor );
332 }
333 
335 {
336  if ( !mPickingColor )
337  {
338  //if not picking a color, use default tool button behaviour
340  return;
341  }
342 
343  //cancel picking, sampling the color if space was pressed
344  stopPicking( QCursor::pos(), e->key() == Qt::Key_Space );
345 }
346 
348 {
349  //is dragged data valid color data?
350  QColor mimeColor;
351  if ( colorFromMimeData( e->mimeData(), mimeColor ) )
352  {
353  //if so, we accept the drag, and temporarily change the button's color
354  //to match the dragged color. This gives immediate feedback to the user
355  //that colors can be dropped here
357  setButtonBackground( mimeColor );
358  }
359 }
360 
362 {
363  Q_UNUSED( e );
364  //reset button color
365  setButtonBackground( mColor );
366 }
367 
369 {
370  //is dropped data valid color data?
371  QColor mimeColor;
372  if ( colorFromMimeData( e->mimeData(), mimeColor ) )
373  {
374  //accept drop and set new color
376  setColor( mimeColor );
377  addRecentColor( mimeColor );
378  }
379 }
380 
381 void QgsColorButtonV2::setValidColor( const QColor& newColor )
382 {
383  if ( newColor.isValid() )
384  {
385  setColor( newColor );
386  addRecentColor( newColor );
387  }
388 }
389 
390 void QgsColorButtonV2::setValidTemporaryColor( const QColor& newColor )
391 {
392  if ( newColor.isValid() )
393  {
394  setColor( newColor );
395  }
396 }
397 
398 void QgsColorButtonV2::panelAccepted( QgsPanelWidget* widget )
399 {
400  if ( QgsCompoundColorWidget* colorWidget = qobject_cast< QgsCompoundColorWidget* >( widget ) )
401  {
402  addRecentColor( colorWidget->color() );
403  colorWidget->deleteLater();
404  }
405 }
406 
407 QPixmap QgsColorButtonV2::createMenuIcon( const QColor &color, const bool showChecks )
408 {
409  //create an icon pixmap
410  QPixmap pixmap( 16, 16 );
411  pixmap.fill( Qt::transparent );
412 
413  QPainter p;
414  p.begin( &pixmap );
415 
416  //start with checkboard pattern
417  if ( showChecks )
418  {
419  QBrush checkBrush = QBrush( transparentBackground() );
420  p.setPen( Qt::NoPen );
421  p.setBrush( checkBrush );
422  p.drawRect( 0, 0, 15, 15 );
423  }
424 
425  //draw color over pattern
426  p.setBrush( QBrush( color ) );
427 
428  //draw border
429  p.setPen( QColor( 197, 197, 197 ) );
430  p.drawRect( 0, 0, 15, 15 );
431  p.end();
432  return pixmap;
433 }
434 
435 void QgsColorButtonV2::buttonClicked()
436 {
437  switch ( mBehaviour )
438  {
439  case ShowDialog:
440  showColorDialog();
441  return;
442  case SignalOnly:
443  emit colorClicked( mColor );
444  return;
445  }
446 }
447 
448 void QgsColorButtonV2::prepareMenu()
449 {
450  //we need to tear down and rebuild this menu every time it is shown. Otherwise the space allocated to any
451  //QgsColorSwatchGridAction is not recalculated by Qt and the swatch grid may not be the correct size
452  //for the number of colors shown in the grid. Note that we MUST refresh color swatch grids every time this
453  //menu is opened, otherwise color schemes like the recent color scheme grid are meaningless
454  mMenu->clear();
455 
456  if ( mShowNull )
457  {
458  QAction* nullAction = new QAction( tr( "Clear color" ), this );
459  nullAction->setIcon( createMenuIcon( Qt::transparent, false ) );
460  mMenu->addAction( nullAction );
461  connect( nullAction, SIGNAL( triggered() ), this, SLOT( setToNull() ) );
462  }
463 
464  //show default color option if set
465  if ( mDefaultColor.isValid() )
466  {
467  QAction* defaultColorAction = new QAction( tr( "Default color" ), this );
468  defaultColorAction->setIcon( createMenuIcon( mDefaultColor ) );
469  mMenu->addAction( defaultColorAction );
470  connect( defaultColorAction, SIGNAL( triggered() ), this, SLOT( setToDefaultColor() ) );
471  }
472 
473  if ( mShowNoColorOption && mAllowAlpha )
474  {
475  QAction* noColorAction = new QAction( mNoColorString, this );
476  noColorAction->setIcon( createMenuIcon( Qt::transparent, false ) );
477  mMenu->addAction( noColorAction );
478  connect( noColorAction, SIGNAL( triggered() ), this, SLOT( setToNoColor() ) );
479  }
480 
481  mMenu->addSeparator();
482  QgsColorWheel* colorWheel = new QgsColorWheel( mMenu );
483  colorWheel->setColor( color() );
484  QgsColorWidgetAction* colorAction = new QgsColorWidgetAction( colorWheel, mMenu, mMenu );
485  colorAction->setDismissOnColorSelection( false );
486  connect( colorAction, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor( const QColor& ) ) );
487  mMenu->addAction( colorAction );
488 
489 
490  if ( mColorSchemeRegistry )
491  {
492  //get schemes with ShowInColorButtonMenu flag set
493  QList< QgsColorScheme* > schemeList = mColorSchemeRegistry->schemes( QgsColorScheme::ShowInColorButtonMenu );
494  QList< QgsColorScheme* >::iterator it = schemeList.begin();
495  for ( ; it != schemeList.end(); ++it )
496  {
497  QgsColorSwatchGridAction* colorAction = new QgsColorSwatchGridAction( *it, mMenu, mContext, this );
498  colorAction->setBaseColor( mColor );
499  mMenu->addAction( colorAction );
500  connect( colorAction, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setValidColor( const QColor& ) ) );
501  connect( colorAction, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( addRecentColor( const QColor& ) ) );
502  }
503  }
504 
505  mMenu->addSeparator();
506 
507  QAction* copyColorAction = new QAction( tr( "Copy color" ), this );
508  mMenu->addAction( copyColorAction );
509  connect( copyColorAction, SIGNAL( triggered() ), this, SLOT( copyColor() ) );
510 
511  QAction* pasteColorAction = new QAction( tr( "Paste color" ), this );
512  //enable or disable paste action based on current clipboard contents. We always show the paste
513  //action, even if it's disabled, to give hint to the user that pasting colors is possible
514  QColor clipColor;
515  if ( colorFromMimeData( QApplication::clipboard()->mimeData(), clipColor ) )
516  {
517  pasteColorAction->setIcon( createMenuIcon( clipColor ) );
518  }
519  else
520  {
521  pasteColorAction->setEnabled( false );
522  }
523  mMenu->addAction( pasteColorAction );
524  connect( pasteColorAction, SIGNAL( triggered() ), this, SLOT( pasteColor() ) );
525 
526 #ifndef Q_OS_MAC
527  //disabled for OSX, as it is impossible to grab the mouse under OSX
528  //see note for QWidget::grabMouse() re OSX Cocoa
529  //http://qt-project.org/doc/qt-4.8/qwidget.html#grabMouse
530  QAction* pickColorAction = new QAction( tr( "Pick color" ), this );
531  mMenu->addAction( pickColorAction );
532  connect( pickColorAction, SIGNAL( triggered() ), this, SLOT( activatePicker() ) );
533 #endif
534  QAction* chooseColorAction = new QAction( tr( "Choose color..." ), this );
535  mMenu->addAction( chooseColorAction );
536  connect( chooseColorAction, SIGNAL( triggered() ), this, SLOT( showColorDialog() ) );
537 }
538 
540 {
541  if ( e->type() == QEvent::EnabledChange )
542  {
544  }
546 }
547 
548 #if 0 // causes too many cyclical updates, but may be needed on some platforms
550 {
552 
553  if ( !mBackgroundSet )
554  {
556  }
557 }
558 #endif
559 
561 {
564 }
565 
567 {
568  QToolButton::resizeEvent( event );
569  //recalculate icon size and redraw icon
570  mIconSize = QSize();
571  setButtonBackground( mColor );
572 }
573 
574 void QgsColorButtonV2::setColor( const QColor &color )
575 {
576  QColor oldColor = mColor;
577  mColor = color;
578 
579  // handle when initially set color is same as default (Qt::black); consider it a color change
580  if ( oldColor != mColor || ( mColor == QColor( Qt::black ) && !mColorSet ) )
581  {
583  if ( isEnabled() )
584  {
585  // TODO: May be beneficial to have the option to set color without emitting this signal.
586  // Now done by blockSignals( bool ) where button is used
587  emit colorChanged( mColor );
588  }
589  }
590  mColorSet = true;
591 }
592 
593 void QgsColorButtonV2::addRecentColor( const QColor& color )
594 {
596 }
597 
599 {
600  QColor backgroundColor = color;
601 
602  if ( !color.isValid() )
603  {
604  backgroundColor = mColor;
605  }
606 
607  QSize currentIconSize;
608  //icon size is button size with a small margin
609  if ( menu() )
610  {
611  if ( !mIconSize.isValid() )
612  {
613  //calculate size of push button part of widget (ie, without the menu dropdown button part)
615  initStyleOption( &opt );
616  QRect buttonSize = QApplication::style()->subControlRect( QStyle::CC_ToolButton, &opt, QStyle::SC_ToolButton,
617  this );
618  //make sure height of icon looks good under different platforms
619 #ifdef Q_OS_WIN
620  mIconSize = QSize( buttonSize.width() - 10, height() - 6 );
621 #else
622  mIconSize = QSize( buttonSize.width() - 10, height() - 12 );
623 #endif
624  }
625  currentIconSize = mIconSize;
626  }
627  else
628  {
629  //no menu
630 #ifdef Q_OS_WIN
631  currentIconSize = QSize( width() - 10, height() - 6 );
632 #else
633  currentIconSize = QSize( width() - 10, height() - 12 );
634 #endif
635  }
636 
637  if ( !currentIconSize.isValid() || currentIconSize.width() <= 0 || currentIconSize.height() <= 0 )
638  {
639  return;
640  }
641 
642  //create an icon pixmap
643  QPixmap pixmap( currentIconSize );
644  pixmap.fill( Qt::transparent );
645 
646  if ( backgroundColor.isValid() )
647  {
648  QRect rect( 0, 0, currentIconSize.width(), currentIconSize.height() );
649  QPainter p;
650  p.begin( &pixmap );
651  p.setRenderHint( QPainter::Antialiasing );
652  p.setPen( Qt::NoPen );
653  if ( mAllowAlpha && backgroundColor.alpha() < 255 )
654  {
655  //start with checkboard pattern
656  QBrush checkBrush = QBrush( transparentBackground() );
657  p.setBrush( checkBrush );
658  p.drawRoundedRect( rect, 3, 3 );
659  }
660 
661  //draw semi-transparent color on top
662  p.setBrush( backgroundColor );
663  p.drawRoundedRect( rect, 3, 3 );
664  p.end();
665  }
666 
667  setIconSize( currentIconSize );
668  setIcon( pixmap );
669 }
670 
672 {
673  //copy color
675 }
676 
678 {
679  QColor clipColor;
680  if ( colorFromMimeData( QApplication::clipboard()->mimeData(), clipColor ) )
681  {
682  //paste color
683  setColor( clipColor );
684  addRecentColor( clipColor );
685  }
686 }
687 
689 {
690  //pick color
691  QPixmap samplerPixmap = QPixmap(( const char ** ) sampler_cursor );
692  setCursor( QCursor( samplerPixmap, 0, 0 ) );
693  grabMouse();
694  grabKeyboard();
695  mPickingColor = true;
696 }
697 
699 {
700  return mColor;
701 }
702 
704 {
705  mAllowAlpha = allowAlpha;
706 }
707 
709 {
710  mColorDialogTitle = title;
711 }
712 
714 {
715  return mColorDialogTitle;
716 }
717 
719 {
720  setMenu( showMenu ? mMenu : nullptr );
721  setPopupMode( showMenu ? QToolButton::MenuButtonPopup : QToolButton::DelayedPopup );
722  //force recalculation of icon size
723  mIconSize = QSize();
724  setButtonBackground( mColor );
725 }
726 
728 {
729  mBehaviour = behaviour;
730 }
731 
733 {
734  mDefaultColor = color;
735 }
736 
738 {
739  mShowNull = showNull;
740 }
741 
743 {
744  return mShowNull;
745 }
746 
748 {
749  return !mColor.isValid();
750 }
751 
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()
A color swatch grid which can be embedded into a menu.
void setColorDialogTitle(const QString &title)
Set the title for the color chooser dialog window.
bool isValid() const
bool isNull() const
Returns true if the current color is null.
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.
QString name() const
A custom QGIS dialog for selecting a color.
void changeEvent(QEvent *e) override
static QString encodeColor(const QColor &color)
void setShowNull(bool showNull)
Sets whether a set to null (clear) option is shown in the button&#39;s drop down menu.
int value() const
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)
Base class for any widget that can be shown as a inline panel.
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)
int hue() const
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()
const char * name() const
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
A color wheel widget.
virtual void mousePressEvent(QMouseEvent *e)
QClipboard * clipboard()
static QgsPanelWidget * findParentPanel(QWidget *widget)
Traces through the parents of a widget to find if it is contained within a QgsPanelWidget widget...
void setPen(const QColor &color)
A custom QGIS widget for selecting a color, including options for selecting colors via hue wheel...
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)
bool event(QEvent *e) override
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 setAllowAlpha(const bool allowAlpha)
Sets whether alpha modification (transparency) is permitted for the color dialog. ...
void setToNoColor()
Sets color to a totally transparent color.
void accept()
bool showNull() const
Returns whether the set to null (clear) option is shown in the button&#39;s drop down menu...
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
void setPreviousColor(const QColor &color)
Sets the color to show in an optional "previous color" section.
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()
void setPanelTitle(QString panelTitle)
Set the title of the panel when shown in the interface.
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.
An action containing a color widget, which can be embedded into a menu.
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
virtual void setColor(const QColor &color, const bool emitSignals=false) override
Behaviour
Specifies the behaviour when the button is clicked.
int saturation() const
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.
void setToolTip(const QString &)
QImage toImage() const
virtual void resizeEvent(QResizeEvent *event)
void setDismissOnColorSelection(bool dismiss)
Sets whether the parent menu should be dismissed and closed when a color is selected from the action&#39;...
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.
void setToNull()
Sets color to null.
bool begin(QPaintDevice *device)
static QPixmap createDragIcon(const QColor &color)
Create an icon for dragging colors.
void grabKeyboard()
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
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.