QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
qgssymbolbutton.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgssymbolbutton.h
3  -----------------
4  Date : July 2017
5  Copyright : (C) 2017 by Nyall Dawson
6  Email : nyall dot dawson at gmail dot com
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 "qgssymbolbutton.h"
17 #include "qgspanelwidget.h"
18 #include "qgsexpressioncontext.h"
20 #include "qgsvectorlayer.h"
22 #include "qgsstyle.h"
23 #include "qgscolorwidgets.h"
24 #include "qgscolorschemeregistry.h"
25 #include "qgscolorswatchgrid.h"
26 #include "qgssymbollayerutils.h"
27 #include "qgsapplication.h"
28 #include "qgsguiutils.h"
30 #include "qgsgui.h"
31 #include "qgscolordialog.h"
32 
33 #include <QMenu>
34 #include <QClipboard>
35 #include <QDrag>
36 
37 QgsSymbolButton::QgsSymbolButton( QWidget *parent, const QString &dialogTitle )
38  : QToolButton( parent )
39  , mDialogTitle( dialogTitle.isEmpty() ? tr( "Symbol Settings" ) : dialogTitle )
40 {
41  mSymbol.reset( QgsFillSymbol::createSimple( QgsStringMap() ) );
42 
43  setAcceptDrops( true );
44  connect( this, &QAbstractButton::clicked, this, &QgsSymbolButton::showSettingsDialog );
45 
46  //setup dropdown menu
47  mMenu = new QMenu( this );
48  connect( mMenu, &QMenu::aboutToShow, this, &QgsSymbolButton::prepareMenu );
49  setMenu( mMenu );
50  setPopupMode( QToolButton::MenuButtonPopup );
51 
52  //make sure height of button looks good under different platforms
53  QSize size = QToolButton::minimumSizeHint();
54  int fontHeight = static_cast< int >( Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 1.4 );
55  mSizeHint = QSize( size.width(), std::max( size.height(), fontHeight ) );
56 }
57 
59 {
60 
61  return mSizeHint;
62 }
63 
65 {
66  return mSizeHint;
67 }
68 
70 {
71  if ( type != mType )
72  {
73  switch ( type )
74  {
75  case QgsSymbol::Marker:
76  mSymbol.reset( QgsMarkerSymbol::createSimple( QgsStringMap() ) );
77  break;
78 
79  case QgsSymbol::Line:
80  mSymbol.reset( QgsLineSymbol::createSimple( QgsStringMap() ) );
81  break;
82 
83  case QgsSymbol::Fill:
84  mSymbol.reset( QgsFillSymbol::createSimple( QgsStringMap() ) );
85  break;
86 
87  case QgsSymbol::Hybrid:
88  break;
89  }
90  }
91  updatePreview();
92  mType = type;
93 }
94 
95 void QgsSymbolButton::showSettingsDialog()
96 {
97  QgsExpressionContext context;
98  if ( mExpressionContextGenerator )
99  context = mExpressionContextGenerator->createExpressionContext();
100  else
101  {
103  }
104  QgsSymbol *newSymbol = mSymbol->clone();
105 
106  QgsSymbolWidgetContext symbolContext;
107  symbolContext.setExpressionContext( &context );
108  symbolContext.setMapCanvas( mMapCanvas );
109  symbolContext.setMessageBar( mMessageBar );
110 
112  if ( panel && panel->dockMode() )
113  {
114  QgsSymbolSelectorWidget *d = new QgsSymbolSelectorWidget( newSymbol, QgsStyle::defaultStyle(), mLayer, nullptr );
115  d->setPanelTitle( mDialogTitle );
116  d->setContext( symbolContext );
117  connect( d, &QgsPanelWidget::widgetChanged, this, &QgsSymbolButton::updateSymbolFromWidget );
118  connect( d, &QgsPanelWidget::panelAccepted, this, &QgsSymbolButton::cleanUpSymbolSelector );
119  panel->openPanel( d );
120  }
121  else
122  {
123  QgsSymbolSelectorDialog dialog( newSymbol, QgsStyle::defaultStyle(), mLayer, nullptr );
124  dialog.setWindowTitle( mDialogTitle );
125  dialog.setContext( symbolContext );
126  if ( dialog.exec() )
127  {
128  setSymbol( newSymbol );
129  }
130  else
131  {
132  delete newSymbol;
133  }
134 
135  // reactivate button's window
136  activateWindow();
137  }
138 }
139 
140 void QgsSymbolButton::updateSymbolFromWidget()
141 {
142  if ( QgsSymbolSelectorWidget *w = qobject_cast<QgsSymbolSelectorWidget *>( sender() ) )
143  setSymbol( w->symbol()->clone() );
144 }
145 
146 void QgsSymbolButton::cleanUpSymbolSelector( QgsPanelWidget *container )
147 {
148  QgsSymbolSelectorWidget *w = qobject_cast<QgsSymbolSelectorWidget *>( container );
149  if ( !w )
150  return;
151 
152  delete w->symbol();
153 }
154 
156 {
157  return mMapCanvas;
158 }
159 
161 {
162  mMapCanvas = mapCanvas;
163 }
164 
166 {
167  mMessageBar = bar;
168 }
169 
171 {
172  return mMessageBar;
173 }
174 
176 {
177  return mLayer;
178 }
179 
181 {
182  mLayer = layer;
183 }
184 
186 {
187  mExpressionContextGenerator = generator;
188 }
189 
191 {
192  mSymbol.reset( symbol );
193  updatePreview();
194  emit changed();
195 }
196 
197 void QgsSymbolButton::setColor( const QColor &color )
198 {
199  QColor opaque = color;
200  opaque.setAlphaF( 1.0 );
201 
202  if ( opaque == mSymbol->color() )
203  return;
204 
205  mSymbol->setColor( opaque );
206  updatePreview();
207  emit changed();
208 }
209 
211 {
212  QApplication::clipboard()->setMimeData( QgsSymbolLayerUtils::symbolToMimeData( mSymbol.get() ) );
213 }
214 
216 {
217  std::unique_ptr< QgsSymbol > symbol( QgsSymbolLayerUtils::symbolFromMimeData( QApplication::clipboard()->mimeData() ) );
218  if ( symbol && symbol->type() == mType )
219  setSymbol( symbol.release() );
220 }
221 
223 {
224  QApplication::clipboard()->setMimeData( QgsSymbolLayerUtils::colorToMimeData( mSymbol->color() ) );
225 }
226 
228 {
229  QColor clipColor;
230  bool hasAlpha = false;
231  if ( colorFromMimeData( QApplication::clipboard()->mimeData(), clipColor, hasAlpha ) )
232  {
233  //paste color
234  setColor( clipColor );
236  }
237 }
238 
239 void QgsSymbolButton::mousePressEvent( QMouseEvent *e )
240 {
241  if ( mPickingColor )
242  {
243  //don't show dialog if in color picker mode
244  e->accept();
245  return;
246  }
247 
248  if ( e->button() == Qt::RightButton )
249  {
250  QToolButton::showMenu();
251  return;
252  }
253  else if ( e->button() == Qt::LeftButton )
254  {
255  mDragStartPosition = e->pos();
256  }
257  QToolButton::mousePressEvent( e );
258 }
259 
260 void QgsSymbolButton::mouseMoveEvent( QMouseEvent *e )
261 {
262  if ( mPickingColor )
263  {
264  updatePreview( QgsGui::sampleColor( e->globalPos() ) );
265  e->accept();
266  return;
267  }
268 
269  //handle dragging colors/symbols from button
270 
271  if ( !( e->buttons() & Qt::LeftButton ) )
272  {
273  //left button not depressed, so not a drag
274  QToolButton::mouseMoveEvent( e );
275  return;
276  }
277 
278  if ( ( e->pos() - mDragStartPosition ).manhattanLength() < QApplication::startDragDistance() )
279  {
280  //mouse not moved, so not a drag
281  QToolButton::mouseMoveEvent( e );
282  return;
283  }
284 
285  //user is dragging
286  QDrag *drag = new QDrag( this );
287  drag->setMimeData( QgsSymbolLayerUtils::colorToMimeData( mSymbol->color() ) );
288  drag->setPixmap( QgsColorWidget::createDragIcon( mSymbol->color() ) );
289  drag->exec( Qt::CopyAction );
290  setDown( false );
291 }
292 
294 {
295  if ( mPickingColor )
296  {
297  //end color picking operation by sampling the color under cursor
298  stopPicking( e->globalPos() );
299  e->accept();
300  return;
301  }
302 
303  QToolButton::mouseReleaseEvent( e );
304 }
305 
306 void QgsSymbolButton::keyPressEvent( QKeyEvent *e )
307 {
308  if ( !mPickingColor )
309  {
310  //if not picking a color, use default tool button behavior
311  QToolButton::keyPressEvent( e );
312  return;
313  }
314 
315  //cancel picking, sampling the color if space was pressed
316  stopPicking( QCursor::pos(), e->key() == Qt::Key_Space );
317 }
318 
319 void QgsSymbolButton::dragEnterEvent( QDragEnterEvent *e )
320 {
321  //is dragged data valid color data?
322  QColor mimeColor;
323  bool hasAlpha = false;
324 
325  if ( colorFromMimeData( e->mimeData(), mimeColor, hasAlpha ) )
326  {
327  //if so, we accept the drag, and temporarily change the button's color
328  //to match the dragged color. This gives immediate feedback to the user
329  //that colors can be dropped here
330  e->acceptProposedAction();
331  updatePreview( mimeColor );
332  }
333 }
334 
335 void QgsSymbolButton::dragLeaveEvent( QDragLeaveEvent *e )
336 {
337  Q_UNUSED( e )
338  //reset button color
339  updatePreview();
340 }
341 
342 void QgsSymbolButton::dropEvent( QDropEvent *e )
343 {
344  //is dropped data valid format data?
345  QColor mimeColor;
346  bool hasAlpha = false;
347  if ( colorFromMimeData( e->mimeData(), mimeColor, hasAlpha ) )
348  {
349  //accept drop and set new color
350  e->acceptProposedAction();
351  mimeColor.setAlphaF( 1.0 );
352  mSymbol->setColor( mimeColor );
354  updatePreview();
355  emit changed();
356  }
357  updatePreview();
358 }
359 
360 void QgsSymbolButton::prepareMenu()
361 {
362  //we need to tear down and rebuild this menu every time it is shown. Otherwise the space allocated to any
363  //QgsColorSwatchGridAction is not recalculated by Qt and the swatch grid may not be the correct size
364  //for the number of colors shown in the grid. Note that we MUST refresh color swatch grids every time this
365  //menu is opened, otherwise color schemes like the recent color scheme grid are meaningless
366  mMenu->clear();
367 
368  QAction *configureAction = new QAction( tr( "Configure Symbol…" ), this );
369  mMenu->addAction( configureAction );
370  connect( configureAction, &QAction::triggered, this, &QgsSymbolButton::showSettingsDialog );
371 
372  QAction *copySymbolAction = new QAction( tr( "Copy Symbol" ), this );
373  mMenu->addAction( copySymbolAction );
374  connect( copySymbolAction, &QAction::triggered, this, &QgsSymbolButton::copySymbol );
375  QAction *pasteSymbolAction = new QAction( tr( "Paste Symbol" ), this );
376  //enable or disable paste action based on current clipboard contents. We always show the paste
377  //action, even if it's disabled, to give hint to the user that pasting symbols is possible
378  std::unique_ptr< QgsSymbol > tempSymbol( QgsSymbolLayerUtils::symbolFromMimeData( QApplication::clipboard()->mimeData() ) );
379  if ( tempSymbol && tempSymbol->type() == mType )
380  {
381  const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
382  pasteSymbolAction->setIcon( QgsSymbolLayerUtils::symbolPreviewIcon( tempSymbol.get(), QSize( iconSize, iconSize ), 1 ) );
383  }
384  else
385  {
386  pasteSymbolAction->setEnabled( false );
387  }
388  mMenu->addAction( pasteSymbolAction );
389  connect( pasteSymbolAction, &QAction::triggered, this, &QgsSymbolButton::pasteSymbol );
390 
391  mMenu->addSeparator();
392 
393  QgsColorWheel *colorWheel = new QgsColorWheel( mMenu );
394  colorWheel->setColor( mSymbol->color() );
395  QgsColorWidgetAction *colorAction = new QgsColorWidgetAction( colorWheel, mMenu, mMenu );
396  colorAction->setDismissOnColorSelection( false );
397  connect( colorAction, &QgsColorWidgetAction::colorChanged, this, &QgsSymbolButton::setColor );
398  mMenu->addAction( colorAction );
399 
401  QColor alphaColor = mSymbol->color();
402  alphaColor.setAlphaF( mSymbol->opacity() );
403  alphaRamp->setColor( alphaColor );
404  QgsColorWidgetAction *alphaAction = new QgsColorWidgetAction( alphaRamp, mMenu, mMenu );
405  alphaAction->setDismissOnColorSelection( false );
406  connect( alphaAction, &QgsColorWidgetAction::colorChanged, this, [ = ]( const QColor & color )
407  {
408  double opacity = color.alphaF();
409  mSymbol->setOpacity( opacity );
410  updatePreview();
411  emit changed();
412  } );
413  connect( colorAction, &QgsColorWidgetAction::colorChanged, alphaRamp, [alphaRamp]( const QColor & color ) { alphaRamp->setColor( color, false ); }
414  );
415  mMenu->addAction( alphaAction );
416 
417  //get schemes with ShowInColorButtonMenu flag set
418  QList< QgsColorScheme * > schemeList = QgsApplication::colorSchemeRegistry()->schemes( QgsColorScheme::ShowInColorButtonMenu );
419  QList< QgsColorScheme * >::iterator it = schemeList.begin();
420  for ( ; it != schemeList.end(); ++it )
421  {
422  QgsColorSwatchGridAction *colorAction = new QgsColorSwatchGridAction( *it, mMenu, QStringLiteral( "symbology" ), this );
423  colorAction->setBaseColor( mSymbol->color() );
424  mMenu->addAction( colorAction );
425  connect( colorAction, &QgsColorSwatchGridAction::colorChanged, this, &QgsSymbolButton::setColor );
426  connect( colorAction, &QgsColorSwatchGridAction::colorChanged, this, &QgsSymbolButton::addRecentColor );
427  }
428 
429  mMenu->addSeparator();
430 
431  QAction *copyColorAction = new QAction( tr( "Copy Color" ), this );
432  mMenu->addAction( copyColorAction );
433  connect( copyColorAction, &QAction::triggered, this, &QgsSymbolButton::copyColor );
434 
435  QAction *pasteColorAction = new QAction( tr( "Paste Color" ), this );
436  //enable or disable paste action based on current clipboard contents. We always show the paste
437  //action, even if it's disabled, to give hint to the user that pasting colors is possible
438  QColor clipColor;
439  bool hasAlpha = false;
440  if ( colorFromMimeData( QApplication::clipboard()->mimeData(), clipColor, hasAlpha ) )
441  {
442  pasteColorAction->setIcon( createColorIcon( clipColor ) );
443  }
444  else
445  {
446  pasteColorAction->setEnabled( false );
447  }
448  mMenu->addAction( pasteColorAction );
449  connect( pasteColorAction, &QAction::triggered, this, &QgsSymbolButton::pasteColor );
450 
451  QAction *pickColorAction = new QAction( tr( "Pick Color" ), this );
452  mMenu->addAction( pickColorAction );
453  connect( pickColorAction, &QAction::triggered, this, &QgsSymbolButton::activatePicker );
454 
455  QAction *chooseColorAction = new QAction( tr( "Choose Color…" ), this );
456  mMenu->addAction( chooseColorAction );
457  connect( chooseColorAction, &QAction::triggered, this, &QgsSymbolButton::showColorDialog );
458 }
459 
460 void QgsSymbolButton::addRecentColor( const QColor &color )
461 {
463 }
464 
465 void QgsSymbolButton::activatePicker()
466 {
467  //activate picker color
468  QApplication::setOverrideCursor( QgsApplication::getThemeCursor( QgsApplication::Cursor::Sampler ) );
469  grabMouse();
470  grabKeyboard();
471  mPickingColor = true;
472  setMouseTracking( true );
473 }
474 
475 
477 {
478  if ( e->type() == QEvent::EnabledChange )
479  {
480  updatePreview();
481  }
482  QToolButton::changeEvent( e );
483 }
484 
485 void QgsSymbolButton::showEvent( QShowEvent *e )
486 {
487  updatePreview();
488  QToolButton::showEvent( e );
489 }
490 
491 void QgsSymbolButton::resizeEvent( QResizeEvent *event )
492 {
493  QToolButton::resizeEvent( event );
494  //recalculate icon size and redraw icon
495  mIconSize = QSize();
496  updatePreview();
497 }
498 
499 void QgsSymbolButton::updatePreview( const QColor &color, QgsSymbol *tempSymbol )
500 {
501  std::unique_ptr< QgsSymbol > previewSymbol;
502 
503  if ( tempSymbol )
504  previewSymbol.reset( tempSymbol->clone() );
505  else
506  previewSymbol.reset( mSymbol->clone() );
507 
508  if ( color.isValid() )
509  previewSymbol->setColor( color );
510 
511  QSize currentIconSize;
512  //icon size is button size with a small margin
513  if ( menu() )
514  {
515  if ( !mIconSize.isValid() )
516  {
517  //calculate size of push button part of widget (ie, without the menu dropdown button part)
518  QStyleOptionToolButton opt;
519  initStyleOption( &opt );
520  QRect buttonSize = QApplication::style()->subControlRect( QStyle::CC_ToolButton, &opt, QStyle::SC_ToolButton,
521  this );
522  //make sure height of icon looks good under different platforms
523 #ifdef Q_OS_WIN
524  mIconSize = QSize( buttonSize.width() - 10, height() - 6 );
525 #else
526  mIconSize = QSize( buttonSize.width() - 10, height() - 12 );
527 #endif
528  }
529  currentIconSize = mIconSize;
530  }
531  else
532  {
533  //no menu
534 #ifdef Q_OS_WIN
535  currentIconSize = QSize( width() - 10, height() - 6 );
536 #else
537  currentIconSize = QSize( width() - 10, height() - 12 );
538 #endif
539  }
540 
541  if ( !currentIconSize.isValid() || currentIconSize.width() <= 0 || currentIconSize.height() <= 0 )
542  {
543  return;
544  }
545 
546  //create an icon pixmap
547  QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( previewSymbol.get(), currentIconSize );
548  setIconSize( currentIconSize );
549  setIcon( icon );
550 
551  // set tooltip
552  // create very large preview image
553  int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 23 );
554  int height = static_cast< int >( width / 1.61803398875 ); // golden ratio
555 
556  QPixmap pm = QgsSymbolLayerUtils::symbolPreviewPixmap( previewSymbol.get(), QSize( width, height ), height / 20 );
557  QByteArray data;
558  QBuffer buffer( &data );
559  pm.save( &buffer, "PNG", 100 );
560  setToolTip( QStringLiteral( "<img src='data:image/png;base64, %3'>" ).arg( QString( data.toBase64() ) ) );
561 }
562 
563 bool QgsSymbolButton::colorFromMimeData( const QMimeData *mimeData, QColor &resultColor, bool &hasAlpha )
564 {
565  hasAlpha = false;
566  QColor mimeColor = QgsSymbolLayerUtils::colorFromMimeData( mimeData, hasAlpha );
567 
568  if ( mimeColor.isValid() )
569  {
570  resultColor = mimeColor;
571  return true;
572  }
573 
574  //could not get color from mime data
575  return false;
576 }
577 
578 QPixmap QgsSymbolButton::createColorIcon( const QColor &color ) const
579 {
580  //create an icon pixmap
581  const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
582  QPixmap pixmap( iconSize, iconSize );
583  pixmap.fill( Qt::transparent );
584 
585  QPainter p;
586  p.begin( &pixmap );
587 
588  //draw color over pattern
589  p.setBrush( QBrush( color ) );
590 
591  //draw border
592  p.setPen( QColor( 197, 197, 197 ) );
593  p.drawRect( 0, 0, iconSize - 1, iconSize - 1 );
594  p.end();
595  return pixmap;
596 }
597 
598 void QgsSymbolButton::stopPicking( QPoint eventPos, bool samplingColor )
599 {
600  //release mouse and keyboard, and reset cursor
601  releaseMouse();
602  releaseKeyboard();
603  QgsApplication::restoreOverrideCursor();
604  setMouseTracking( false );
605  mPickingColor = false;
606 
607  if ( !samplingColor )
608  {
609  //not sampling color, restore old icon
610  updatePreview();
611  return;
612  }
613 
614  const QColor newColor = QgsGui::sampleColor( eventPos );
615  setColor( newColor );
616  addRecentColor( newColor );
617 }
618 
619 void QgsSymbolButton::showColorDialog()
620 {
622  if ( panel && panel->dockMode() )
623  {
624  QColor currentColor = mSymbol->color();
626  colorWidget->setPanelTitle( tr( "Symbol Color" ) );
627  colorWidget->setAllowOpacity( true );
628 
629  if ( currentColor.isValid() )
630  {
631  colorWidget->setPreviousColor( currentColor );
632  }
633 
634  connect( colorWidget, &QgsCompoundColorWidget::currentColorChanged, this, [ = ]( const QColor & newColor )
635  {
636  if ( newColor.isValid() )
637  {
638  setColor( newColor );
639  }
640  } );
641  panel->openPanel( colorWidget );
642  return;
643  }
644 
645  QColor newColor;
646 
647  QgsColorDialog dialog( this, nullptr, mSymbol->color() );
648  dialog.setTitle( tr( "Symbol Color" ) );
649  dialog.setAllowOpacity( true );
650 
651  if ( dialog.exec() && dialog.color().isValid() )
652  {
653  setColor( dialog.color() );
654  }
655 
656  // reactivate button's window
657  activateWindow();
658 }
659 
660 void QgsSymbolButton::setDialogTitle( const QString &title )
661 {
662  mDialogTitle = title;
663 }
664 
665 QString QgsSymbolButton::dialogTitle() const
666 {
667  return mDialogTitle;
668 }
669 
671 {
672  return mSymbol.get();
673 }
void openPanel(QgsPanelWidget *panel)
Open a panel or dialog depending on dock mode setting If dock mode is true this method will emit the ...
A color swatch grid which can be embedded into a menu.
static QgsSymbol * symbolFromMimeData(const QMimeData *data)
Attempts to parse mime data as a symbol.
void setMessageBar(QgsMessageBar *bar)
Sets the message bar associated with the widget.
void registerExpressionContextGenerator(QgsExpressionContextGenerator *generator)
Register an expression context generator class that will be used to retrieve an expression context fo...
QSize minimumSizeHint() const override
bool dockMode()
Returns the dock mode state.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:61
void copyColor()
Copies the current symbol color to the clipboard.
static const double UI_SCALE_FACTOR
UI scaling factor.
Definition: qgis.h:154
QgsSymbol * symbol()
Returns the symbol that is currently active in the widget.
void mousePressEvent(QMouseEvent *e) override
virtual void setColor(const QColor &color, bool emitSignals=false)
Sets the color for the widget.
static QgsLineSymbol * createSimple(const QgsStringMap &properties)
Create a line symbol with one symbol layer: SimpleLine with specified properties. ...
Definition: qgssymbol.cpp:1240
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly...
void setDialogTitle(const QString &title)
Sets the title for the symbol settings dialog window.
static QgsFillSymbol * createSimple(const QgsStringMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties. ...
Definition: qgssymbol.cpp:1251
void showEvent(QShowEvent *e) override
static QIcon symbolPreviewIcon(const QgsSymbol *symbol, QSize size, int padding=0)
Returns an icon preview for a color ramp.
void changed()
Emitted when the symbol&#39;s settings are changed.
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:45
void colorChanged(const QColor &color)
Emitted when a color has been selected from the widget.
Base class for any widget that can be shown as a inline panel.
Line symbol.
Definition: qgssymbol.h:86
Show scheme in color button drop-down menu.
void panelAccepted(QgsPanelWidget *panel)
Emitted when the panel is accepted by the user.
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
QMap< QString, QString > QgsStringMap
Definition: qgis.h:612
void pasteSymbol()
Pastes a symbol from the clipboard.
void pasteColor()
Pastes a color from the clipboard to the symbol.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:75
static QgsStyle * defaultStyle()
Returns default application-wide style.
Definition: qgsstyle.cpp:74
void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the symbol widget is shown, e.g., the associated map canvas and expression ...
void setMessageBar(QgsMessageBar *bar)
Sets the message bar associated with the widget.
SymbolType
Type of the symbol.
Definition: qgssymbol.h:83
QList< QgsColorScheme * > schemes() const
Returns all color schemes in the registry.
void setTitle(const QString &title)
Sets the title for the color dialog.
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
void resizeEvent(QResizeEvent *event) override
A color wheel widget.
QgsSymbolButton(QWidget *parent=nullptr, const QString &dialogTitle=QString())
Construct a new symbol button.
static QgsPanelWidget * findParentPanel(QWidget *widget)
Traces through the parents of a widget to find if it is contained within a QgsPanelWidget widget...
Contains settings which reflect the context in which a symbol (or renderer) widget is shown...
A custom QGIS widget for selecting a color, including options for selecting colors via hue wheel...
Alpha component (opacity) of color.
static QMimeData * symbolToMimeData(const QgsSymbol *symbol)
Creates new mime data from a symbol.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
A color ramp widget.
void mouseMoveEvent(QMouseEvent *e) override
void setColor(const QColor &color, bool emitSignals=false) override
void mouseReleaseEvent(QMouseEvent *e) override
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer&#39;s project and layer.
Symbol selector widget that can be used to select and build a symbol.
void setColor(const QColor &color)
Sets the current color for the symbol.
QString dialogTitle() const
Returns the title for the symbol settings dialog window.
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window&#39;s toolbar icons.
static void addRecentColor(const QColor &color)
Adds a color to the list of recent colors.
void widgetChanged()
Emitted when the widget state changes.
void changeEvent(QEvent *e) override
void setExpressionContext(QgsExpressionContext *context)
Sets the optional expression context used for the widget.
Abstract interface for generating an expression context.
QgsVectorLayer * layer() const
Returns the layer associated with the widget.
void setAllowOpacity(bool allowOpacity)
Sets whether opacity modification (transparency) is permitted for the color dialog.
void keyPressEvent(QKeyEvent *e) override
void setPreviousColor(const QColor &color)
Sets the color to show in an optional "previous color" section.
A custom QGIS dialog for selecting a color.
Marker symbol.
Definition: qgssymbol.h:85
static QgsColorSchemeRegistry * colorSchemeRegistry()
Returns the application&#39;s color scheme registry, used for managing color schemes. ...
Fill symbol.
Definition: qgssymbol.h:87
void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the symbol widget is shown, e.g., the associated map canvas and expression ...
void setLayer(QgsVectorLayer *layer)
Sets a layer to associate with the widget.
void currentColorChanged(const QColor &color)
Emitted when the dialog&#39;s color changes.
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
An action containing a color widget, which can be embedded into a menu.
void dropEvent(QDropEvent *e) override
static QMimeData * colorToMimeData(const QColor &color)
Creates mime data from a color.
void dragLeaveEvent(QDragLeaveEvent *e) override
static QPixmap symbolPreviewPixmap(const QgsSymbol *symbol, QSize size, int padding=0, QgsRenderContext *customContext=nullptr, bool selected=false, const QgsExpressionContext *expressionContext=nullptr)
Returns a pixmap preview for a color ramp.
QSize sizeHint() const override
void setMapCanvas(QgsMapCanvas *canvas)
Sets a map canvas to associate with the widget.
void setSymbol(QgsSymbol *symbol)
Sets the symbol for the button.
static QCursor getThemeCursor(Cursor cursor)
Helper to get a theme cursor.
void appendScopes(const QList< QgsExpressionContextScope *> &scopes)
Appends a list of scopes to the end of the context.
static QgsMarkerSymbol * createSimple(const QgsStringMap &properties)
Create a marker symbol with one symbol layer: SimpleMarker with specified properties.
Definition: qgssymbol.cpp:1229
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
void copySymbol()
Copies the current symbol to the clipboard.
void setDismissOnColorSelection(bool dismiss)
Sets whether the parent menu should be dismissed and closed when a color is selected from the action&#39;...
Represents a vector layer which manages a vector based data sets.
void setSymbolType(QgsSymbol::SymbolType type)
Sets the symbol type which the button requires.
static QPixmap createDragIcon(const QColor &color)
Create an icon for dragging colors.
void setPanelTitle(const QString &panelTitle)
Set the title of the panel when shown in the interface.
static QColor sampleColor(QPoint point)
Samples the color on screen at the specified global point (pixel).
Definition: qgsgui.cpp:176
void dragEnterEvent(QDragEnterEvent *e) override
QgsSymbol * symbol()
Returns the current symbol defined by the button.
Hybrid symbol.
Definition: qgssymbol.h:88
Use a narrower, vertically stacked layout.
static QColor colorFromMimeData(const QMimeData *data, bool &hasAlpha)
Attempts to parse mime data as a color.
QgsMessageBar * messageBar() const
Returns the message bar associated with the widget.
void colorChanged(const QColor &color)
Emitted when a color has been selected from the widget.
void setBaseColor(const QColor &baseColor)
Sets the base color for the color grid.