42   : QToolButton( parent )
 
   43   , mDialogTitle( dialogTitle.isEmpty() ? tr( 
"Symbol Settings" ) : dialogTitle )
 
   47   setAcceptDrops( 
true );
 
   48   connect( 
this, &QAbstractButton::clicked, 
this, &QgsSymbolButton::showSettingsDialog );
 
   51   mMenu = 
new QMenu( 
this );
 
   52   connect( mMenu, &QMenu::aboutToShow, 
this, &QgsSymbolButton::prepareMenu );
 
   54   setPopupMode( QToolButton::MenuButtonPopup );
 
   57   QSize size = QToolButton::minimumSizeHint();
 
   59   mSizeHint = QSize( size.width(), std::max( size.height(), fontHeight ) );
 
  101 void QgsSymbolButton::showSettingsDialog()
 
  104   if ( mExpressionContextGenerator )
 
  130     dialog.setWindowTitle( mDialogTitle );
 
  131     dialog.setContext( symbolContext );
 
  146 void QgsSymbolButton::updateSymbolFromWidget()
 
  152 void QgsSymbolButton::cleanUpSymbolSelector( 
QgsPanelWidget *container )
 
  193   mExpressionContextGenerator = generator;
 
  205   QColor opaque = color;
 
  206   opaque.setAlphaF( 1.0 );
 
  208   if ( opaque == mSymbol->color() )
 
  211   mSymbol->setColor( opaque );
 
  236   bool hasAlpha = 
false;
 
  237   if ( colorFromMimeData( QApplication::clipboard()->mimeData(), clipColor, hasAlpha ) )
 
  254   if ( e->button() == Qt::RightButton )
 
  256     QToolButton::showMenu();
 
  259   else if ( e->button() == Qt::LeftButton )
 
  261     mDragStartPosition = e->pos();
 
  263   QToolButton::mousePressEvent( e );
 
  277   if ( !( e->buttons() & Qt::LeftButton ) )
 
  280     QToolButton::mouseMoveEvent( e );
 
  284   if ( ( e->pos() - mDragStartPosition ).manhattanLength() < QApplication::startDragDistance() )
 
  287     QToolButton::mouseMoveEvent( e );
 
  292   QDrag *drag = 
new QDrag( 
this );
 
  295   drag->exec( Qt::CopyAction );
 
  304     stopPicking( e->globalPos() );
 
  309   QToolButton::mouseReleaseEvent( e );
 
  314   if ( !mPickingColor )
 
  317     QToolButton::keyPressEvent( e );
 
  322   stopPicking( QCursor::pos(), e->key() == Qt::Key_Space );
 
  329   bool hasAlpha = 
false;
 
  331   if ( colorFromMimeData( e->mimeData(), mimeColor, hasAlpha ) )
 
  336     e->acceptProposedAction();
 
  337     updatePreview( mimeColor );
 
  352   bool hasAlpha = 
false;
 
  353   if ( colorFromMimeData( e->mimeData(), mimeColor, hasAlpha ) )
 
  356     e->acceptProposedAction();
 
  357     mimeColor.setAlphaF( 1.0 );
 
  358     mSymbol->setColor( mimeColor );
 
  366 void QgsSymbolButton::prepareMenu()
 
  374   QAction *configureAction = 
new QAction( tr( 
"Configure Symbol…" ), 
this );
 
  375   mMenu->addAction( configureAction );
 
  376   connect( configureAction, &QAction::triggered, 
this, &QgsSymbolButton::showSettingsDialog );
 
  378   QAction *copySymbolAction = 
new QAction( tr( 
"Copy Symbol" ), 
this );
 
  379   mMenu->addAction( copySymbolAction );
 
  381   QAction *pasteSymbolAction = 
new QAction( tr( 
"Paste Symbol" ), 
this );
 
  385   if ( tempSymbol && tempSymbol->type() == mType )
 
  392     pasteSymbolAction->setEnabled( 
false );
 
  394   mMenu->addAction( pasteSymbolAction );
 
  397   mMenu->addSeparator();
 
  400   colorWheel->
setColor( mSymbol->color() );
 
  404   mMenu->addAction( colorAction );
 
  407   QColor alphaColor = mSymbol->color();
 
  408   alphaColor.setAlphaF( mSymbol->opacity() );
 
  414     double opacity = color.alphaF();
 
  415     mSymbol->setOpacity( opacity );
 
  421   mMenu->addAction( alphaAction );
 
  425   QList< QgsColorScheme * >::iterator it = schemeList.begin();
 
  426   for ( ; it != schemeList.end(); ++it )
 
  430     mMenu->addAction( colorAction );
 
  435   mMenu->addSeparator();
 
  437   QAction *copyColorAction = 
new QAction( tr( 
"Copy Color" ), 
this );
 
  438   mMenu->addAction( copyColorAction );
 
  441   QAction *pasteColorAction = 
new QAction( tr( 
"Paste Color" ), 
this );
 
  445   bool hasAlpha = 
false;
 
  446   if ( colorFromMimeData( QApplication::clipboard()->mimeData(), clipColor, hasAlpha ) )
 
  448     pasteColorAction->setIcon( createColorIcon( clipColor ) );
 
  452     pasteColorAction->setEnabled( 
false );
 
  454   mMenu->addAction( pasteColorAction );
 
  457   QAction *pickColorAction = 
new QAction( tr( 
"Pick Color" ), 
this );
 
  458   mMenu->addAction( pickColorAction );
 
  459   connect( pickColorAction, &QAction::triggered, 
this, &QgsSymbolButton::activatePicker );
 
  461   QAction *chooseColorAction = 
new QAction( tr( 
"Choose Color…" ), 
this );
 
  462   mMenu->addAction( chooseColorAction );
 
  463   connect( chooseColorAction, &QAction::triggered, 
this, &QgsSymbolButton::showColorDialog );
 
  466 void QgsSymbolButton::addRecentColor( 
const QColor &color )
 
  471 void QgsSymbolButton::activatePicker()
 
  477   mPickingColor = 
true;
 
  478   setMouseTracking( 
true );
 
  484   if ( e->type() == QEvent::EnabledChange )
 
  488   QToolButton::changeEvent( e );
 
  494   QToolButton::showEvent( e );
 
  499   QToolButton::resizeEvent( event );
 
  505 void QgsSymbolButton::updatePreview( 
const QColor &color, 
QgsSymbol *tempSymbol )
 
  507   std::unique_ptr< QgsSymbol > previewSymbol;
 
  510     previewSymbol.reset( tempSymbol->
clone() );
 
  512     previewSymbol.reset( mSymbol->clone() );
 
  514   if ( color.isValid() )
 
  515     previewSymbol->setColor( color );
 
  517   QSize currentIconSize;
 
  521     if ( !mIconSize.isValid() )
 
  524       QStyleOptionToolButton opt;
 
  525       initStyleOption( &opt );
 
  526       QRect buttonSize = QApplication::style()->subControlRect( QStyle::CC_ToolButton, &opt, QStyle::SC_ToolButton,
 
  530       mIconSize = QSize( buttonSize.width() - 10, height() - 6 );
 
  532       mIconSize = QSize( buttonSize.width() - 10, height() - 12 );
 
  535     currentIconSize = mIconSize;
 
  541     currentIconSize = QSize( width() - 10, height() - 6 );
 
  543     currentIconSize = QSize( width() - 10, height() - 12 );
 
  547   if ( !currentIconSize.isValid() || currentIconSize.width() <= 0 || currentIconSize.height() <= 0 )
 
  554   setIconSize( currentIconSize );
 
  560   int width = 
static_cast< int >( 
Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 
'X' ) * 23 );
 
  561   int height = 
static_cast< int >( width / 1.61803398875 ); 
 
  565   QBuffer buffer( &data );
 
  566   pm.save( &buffer, 
"PNG", 100 );
 
  567   setToolTip( QStringLiteral( 
"<img src='data:image/png;base64, %3'>" ).arg( QString( data.toBase64() ) ) );
 
  570 bool QgsSymbolButton::colorFromMimeData( 
const QMimeData *mimeData, QColor &resultColor, 
bool &hasAlpha )
 
  575   if ( mimeColor.isValid() )
 
  577     resultColor = mimeColor;
 
  585 QPixmap QgsSymbolButton::createColorIcon( 
const QColor &color )
 const 
  590   pixmap.fill( Qt::transparent );
 
  596   p.setBrush( QBrush( color ) );
 
  599   p.setPen( QColor( 197, 197, 197 ) );
 
  605 void QgsSymbolButton::stopPicking( QPoint eventPos, 
bool samplingColor )
 
  610   QgsApplication::restoreOverrideCursor();
 
  611   setMouseTracking( 
false );
 
  612   mPickingColor = 
false;
 
  614   if ( !samplingColor )
 
  623   addRecentColor( newColor );
 
  626 void QgsSymbolButton::showColorDialog()
 
  631     QColor currentColor = mSymbol->color();
 
  636     if ( currentColor.isValid() )
 
  643       if ( newColor.isValid() )
 
  645         setColor( newColor );
 
  652   QgsColorDialog dialog( 
this, Qt::WindowFlags(), mSymbol->color() );
 
  653   dialog.setTitle( tr( 
"Symbol Color" ) );
 
  654   dialog.setAllowOpacity( 
true );
 
  656   if ( dialog.exec() && dialog.color().isValid() )
 
  667   mDialogTitle = title;
 
  677   return mSymbol.get();
 
static const double UI_SCALE_FACTOR
UI scaling factor.
static QCursor getThemeCursor(Cursor cursor)
Helper to get a theme cursor.
static QgsColorSchemeRegistry * colorSchemeRegistry()
Returns the application's color scheme registry, used for managing color schemes.
A custom QGIS dialog for selecting a color.
QList< QgsColorScheme * > schemes() const
Returns all color schemes in the registry.
@ ShowInColorButtonMenu
Show scheme in color button drop-down menu.
A color swatch grid which can be embedded into a menu.
void setBaseColor(const QColor &baseColor)
Sets the base color for the color grid.
void colorChanged(const QColor &color)
Emitted when a color has been selected from the widget.
void setColor(const QColor &color, bool emitSignals=false) override
Abstract interface for generating an expression context.
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
static QgsFillSymbol * createSimple(const QVariantMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties.
static QColor sampleColor(QPoint point)
Samples the color on screen at the specified global point (pixel).
static QgsLineSymbol * createSimple(const QVariantMap &properties)
Create a line symbol with one symbol layer: SimpleLine with specified properties.
Map canvas is a class for displaying all GIS data types on a canvas.
static QgsMarkerSymbol * createSimple(const QVariantMap &properties)
Create a marker symbol with one symbol layer: SimpleMarker with specified properties.
A bar for displaying non-blocking messages to the user.
static void addRecentColor(const QColor &color)
Adds a color to the list of recent colors.
static QgsStyle * defaultStyle()
Returns default application-wide style.
static QgsSymbol * symbolFromMimeData(const QMimeData *data)
Attempts to parse mime data as a symbol.
static QPixmap symbolPreviewPixmap(const QgsSymbol *symbol, QSize size, int padding=0, QgsRenderContext *customContext=nullptr, bool selected=false, const QgsExpressionContext *expressionContext=nullptr, const QgsLegendPatchShape *shape=nullptr)
Returns a pixmap preview for a color ramp.
static QMimeData * symbolToMimeData(const QgsSymbol *symbol)
Creates new mime data from a symbol.
static QColor colorFromMimeData(const QMimeData *data, bool &hasAlpha)
Attempts to parse mime data as a color.
static QIcon symbolPreviewIcon(const QgsSymbol *symbol, QSize size, int padding=0, QgsLegendPatchShape *shape=nullptr)
Returns an icon preview for a color ramp.
static QMimeData * colorToMimeData(const QColor &color)
Creates mime data from a color.
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
void setMessageBar(QgsMessageBar *bar)
Sets the message bar associated with the widget.
void setExpressionContext(QgsExpressionContext *context)
Sets the optional expression context used for the widget.
Abstract base class for all rendered symbols.
Qgis::SymbolType type() const
Returns the symbol's type.
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
Represents a vector layer which manages a vector based data sets.
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly,...