28  : QToolButton( parent )
 
   29  , mShape( 
QgsStyle::defaultStyle()->defaultPatch( 
Qgis::SymbolType::Fill, QSizeF( 10, 5 ) ) )
 
   30  , mDialogTitle( dialogTitle.isEmpty() ? tr( 
"Legend Patch Shape" ) : dialogTitle )
 
   34  connect( 
this, &QAbstractButton::clicked, 
this, &QgsLegendPatchShapeButton::showSettingsDialog );
 
   37  mMenu = 
new QMenu( 
this );
 
   38  connect( mMenu, &QMenu::aboutToShow, 
this, &QgsLegendPatchShapeButton::prepareMenu );
 
   40  setPopupMode( QToolButton::MenuButtonPopup );
 
   43  QSize size = QToolButton::minimumSizeHint();
 
   45  mSizeHint = QSize( size.width(), std::max( size.height(), fontHeight ) );
 
 
   62  if ( mPreviewSymbol->type() != type )
 
 
   94  mPreviewSymbol.reset( symbol );
 
 
   98void QgsLegendPatchShapeButton::showSettingsDialog()
 
  150  mIsDefault = mShape.
isNull();
 
 
  178  if ( e->button() == Qt::RightButton )
 
  180    QToolButton::showMenu();
 
  183  QToolButton::mousePressEvent( e );
 
 
  186void QgsLegendPatchShapeButton::prepareMenu()
 
  190  QAction *configureAction = 
new QAction( tr( 
"Configure Patch…" ), 
this );
 
  191  mMenu->addAction( configureAction );
 
  192  connect( configureAction, &QAction::triggered, 
this, &QgsLegendPatchShapeButton::showSettingsDialog );
 
  194  QAction *defaultAction = 
new QAction( tr( 
"Reset to Default" ), 
this );
 
  195  mMenu->addAction( defaultAction );
 
  196  connect( defaultAction, &QAction::triggered, 
this, [ = ] { 
setToDefault(); emit 
changed(); } );
 
  198  mMenu->addSeparator();
 
  203  for ( 
const QString &name : std::as_const( patchNames ) )
 
  211        QAction *action = 
new QAction( name, 
this );
 
  212        action->setIcon( icon );
 
  213        connect( action, &QAction::triggered, 
this, [ = ] { loadPatchFromStyle( name ); } );
 
  214        mMenu->addAction( action );
 
  220void QgsLegendPatchShapeButton::loadPatchFromStyle( 
const QString &name )
 
  231  if ( e->type() == QEvent::EnabledChange )
 
  235  QToolButton::changeEvent( e );
 
 
  241  QToolButton::showEvent( e );
 
 
  246  QToolButton::resizeEvent( event );
 
 
  252void QgsLegendPatchShapeButton::updatePreview()
 
  254  QSize currentIconSize;
 
  258    if ( !mIconSize.isValid() )
 
  261      QStyleOptionToolButton opt;
 
  262      initStyleOption( &opt );
 
  263      QRect buttonSize = QApplication::style()->subControlRect( QStyle::CC_ToolButton, &opt, QStyle::SC_ToolButton,
 
  267      mIconSize = QSize( buttonSize.width() - 10, height() - 6 );
 
  269      mIconSize = QSize( buttonSize.width() - 10, height() - 12 );
 
  272    currentIconSize = mIconSize;
 
  278    currentIconSize = QSize( width() - 10, height() - 6 );
 
  280    currentIconSize = QSize( width() - 10, height() - 12 );
 
  284  if ( !currentIconSize.isValid() || currentIconSize.width() <= 0 || currentIconSize.height() <= 0 )
 
  291  setIconSize( currentIconSize );
 
  297  int width = 
static_cast< int >( 
Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 
'X' ) * 23 );
 
  298  int height = 
static_cast< int >( width / 1.61803398875 ); 
 
  302  QBuffer buffer( &data );
 
  303  pm.save( &buffer, 
"PNG", 100 );
 
  304  setToolTip( QStringLiteral( 
"<img src='data:image/png;base64, %3' width=\"%4\">" ).arg( QString( data.toBase64() ) ).arg( width ) );
 
  309  mDialogTitle = title;
 
 
The Qgis class provides global constants for use throughout the application.
 
static const double UI_SCALE_FACTOR
UI scaling factor.
 
static QgsFillSymbol * createSimple(const QVariantMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties.
 
Represents a patch shape for use in map legends.
 
bool isNull() const
Returns true if the patch shape is a null QgsLegendPatchShape, which indicates that the default legen...
 
Qgis::SymbolType symbolType() const
Returns the symbol type associated with this patch.
 
static QgsLineSymbol * createSimple(const QVariantMap &properties)
Create a line symbol with one symbol layer: SimpleLine with specified properties.
 
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.
 
Stores properties relating to a screen.
 
QgsLegendPatchShape defaultPatch(Qgis::SymbolType type, QSizeF size) const
Returns the default legend patch shape for the given symbol type.
 
@ LegendPatchShapeEntity
Legend patch shape (since QGIS 3.14)
 
static QgsStyle * defaultStyle(bool initialize=true)
Returns the default application-wide style.
 
QStringList symbolsOfFavorite(StyleEntity type) const
Returns the symbol names which are flagged as favorite.
 
QgsLegendPatchShape legendPatchShape(const QString &name) const
Returns the legend patch shape with the specified name.
 
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, const QgsScreenProperties &screen=QgsScreenProperties())
Returns a pixmap preview for a color ramp.
 
static QIcon symbolPreviewIcon(const QgsSymbol *symbol, QSize size, int padding=0, QgsLegendPatchShape *shape=nullptr, const QgsScreenProperties &screen=QgsScreenProperties())
Returns an icon preview for a color ramp.
 
Abstract base class for all rendered symbols.
 
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,...