QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgsfontbutton.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsfontbutton.h
3  ---------------
4  Date : May 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 "qgsfontbutton.h"
17 #include "qgstextformatwidget.h"
18 #include "qgssymbollayerutils.h"
19 #include "qgscolorscheme.h"
20 #include "qgsmapcanvas.h"
21 #include "qgscolorwidgets.h"
22 #include "qgscolorschemeregistry.h"
23 #include "qgscolorswatchgrid.h"
24 #include "qgsdoublespinbox.h"
25 #include "qgsunittypes.h"
26 #include "qgsmenuheader.h"
27 #include "qgsfontutils.h"
28 #include "qgsapplication.h"
30 #include "qgsvectorlayer.h"
31 #include "qgstextrenderer.h"
32 #include <QMenu>
33 #include <QClipboard>
34 #include <QDrag>
35 #include <QDesktopWidget>
36 #include <QToolTip>
37 
38 QgsFontButton::QgsFontButton( QWidget *parent, const QString &dialogTitle )
39  : QToolButton( parent )
40  , mDialogTitle( dialogTitle.isEmpty() ? tr( "Text Format" ) : dialogTitle )
41 
42 {
43  setText( tr( "Font" ) );
44 
45  setAcceptDrops( true );
46  connect( this, &QAbstractButton::clicked, this, &QgsFontButton::showSettingsDialog );
47 
48  //setup dropdown menu
49  mMenu = new QMenu( this );
50  connect( mMenu, &QMenu::aboutToShow, this, &QgsFontButton::prepareMenu );
51  setMenu( mMenu );
52  setPopupMode( QToolButton::MenuButtonPopup );
53 
54  //make sure height of button looks good under different platforms
55  QSize size = QToolButton::minimumSizeHint();
56  int fontHeight = Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 1.4;
57 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
58  int minWidth = Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 20;
59 #else
60  int minWidth = Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 20;
61 #endif
62  mSizeHint = QSize( std::max( minWidth, size.width() ), std::max( size.height(), fontHeight ) );
63 }
64 
66 {
67  return mSizeHint;
68 }
69 
71 {
72  return mSizeHint;
73 }
74 
75 void QgsFontButton::showSettingsDialog()
76 {
77  switch ( mMode )
78  {
79  case ModeTextRenderer:
80  {
81  QgsExpressionContext context;
82  if ( mExpressionContextGenerator )
83  context = mExpressionContextGenerator->createExpressionContext();
84  else
85  {
87  }
88 
89  QgsSymbolWidgetContext symbolContext;
90  symbolContext.setExpressionContext( &context );
91  symbolContext.setMapCanvas( mMapCanvas );
92  symbolContext.setMessageBar( mMessageBar );
93 
95  if ( panel && panel->dockMode() )
96  {
97  QgsTextFormatPanelWidget *formatWidget = new QgsTextFormatPanelWidget( mFormat, mMapCanvas, this, mLayer.data() );
98  formatWidget->setPanelTitle( mDialogTitle );
99  formatWidget->setContext( symbolContext );
100 
101  connect( formatWidget, &QgsTextFormatPanelWidget::widgetChanged, this, [ this, formatWidget ] { this->setTextFormat( formatWidget->format() ); } );
102  panel->openPanel( formatWidget );
103  return;
104  }
105 
106  QgsTextFormatDialog dialog( mFormat, mMapCanvas, this, QgsGuiUtils::ModalDialogFlags, mLayer.data() );
107  dialog.setWindowTitle( mDialogTitle );
108  dialog.setContext( symbolContext );
109  if ( dialog.exec() )
110  {
111  setTextFormat( dialog.format() );
112  QgsFontUtils::addRecentFontFamily( mFormat.font().family() );
113  }
114  break;
115  }
116 
117  case ModeQFont:
118  {
119  bool ok;
120  QFont newFont = QgsGuiUtils::getFont( ok, mFont, mDialogTitle );
121  if ( ok )
122  {
123  QgsFontUtils::addRecentFontFamily( newFont.family() );
124  setCurrentFont( newFont );
125  }
126  break;
127  }
128  }
129 
130  // reactivate button's window
131  activateWindow();
132  raise();
133 }
134 
136 {
137  return mMapCanvas;
138 }
139 
141 {
142  mMapCanvas = mapCanvas;
143 }
144 
146 {
147  mMessageBar = bar;
148 }
149 
151 {
152  return mMessageBar;
153 }
154 
156 {
157  mFormat = format;
158  updatePreview();
159  emit changed();
160 }
161 
162 void QgsFontButton::setColor( const QColor &color )
163 {
164  QColor opaque = color;
165  opaque.setAlphaF( 1.0 );
166 
167  if ( mFormat.color() != opaque )
168  {
169  mFormat.setColor( opaque );
170  updatePreview();
171  emit changed();
172  }
173 }
174 
176 {
177  switch ( mMode )
178  {
179  case ModeTextRenderer:
180  QApplication::clipboard()->setMimeData( mFormat.toMimeData() );
181  break;
182 
183  case ModeQFont:
184  QApplication::clipboard()->setMimeData( QgsFontUtils::toMimeData( mFont ) );
185  break;
186  }
187 }
188 
190 {
191  QgsTextFormat tempFormat;
192  QFont font;
193  if ( mMode == ModeTextRenderer && formatFromMimeData( QApplication::clipboard()->mimeData(), tempFormat ) )
194  {
195  setTextFormat( tempFormat );
196  QgsFontUtils::addRecentFontFamily( mFormat.font().family() );
197  }
198  else if ( mMode == ModeQFont && fontFromMimeData( QApplication::clipboard()->mimeData(), font ) )
199  {
200  QgsFontUtils::addRecentFontFamily( font.family() );
201  setCurrentFont( font );
202  }
203 }
204 
205 bool QgsFontButton::event( QEvent *e )
206 {
207  if ( e->type() == QEvent::ToolTip )
208  {
209  QHelpEvent *helpEvent = static_cast< QHelpEvent *>( e );
210  QString toolTip;
211  double fontSize = 0.0;
212  switch ( mMode )
213  {
214  case ModeTextRenderer:
215  fontSize = mFormat.size();
216  break;
217 
218  case ModeQFont:
219  fontSize = mFont.pointSizeF();
220  break;
221  }
222  toolTip = QStringLiteral( "<b>%1</b><br>%2<br>Size: %3" ).arg( text(), mMode == ModeTextRenderer ? mFormat.font().family() : mFont.family() ).arg( fontSize );
223  QToolTip::showText( helpEvent->globalPos(), toolTip );
224  }
225  return QToolButton::event( e );
226 }
227 
228 void QgsFontButton::mousePressEvent( QMouseEvent *e )
229 {
230  if ( e->button() == Qt::RightButton )
231  {
232  QToolButton::showMenu();
233  return;
234  }
235  else if ( e->button() == Qt::LeftButton )
236  {
237  mDragStartPosition = e->pos();
238  }
239  QToolButton::mousePressEvent( e );
240 }
241 
242 void QgsFontButton::mouseMoveEvent( QMouseEvent *e )
243 {
244  //handle dragging fonts from button
245 
246  if ( !( e->buttons() & Qt::LeftButton ) )
247  {
248  //left button not depressed, so not a drag
249  QToolButton::mouseMoveEvent( e );
250  return;
251  }
252 
253  if ( ( e->pos() - mDragStartPosition ).manhattanLength() < QApplication::startDragDistance() )
254  {
255  //mouse not moved, so not a drag
256  QToolButton::mouseMoveEvent( e );
257  return;
258  }
259 
260  //user is dragging font
261  QDrag *drag = new QDrag( this );
262  switch ( mMode )
263  {
264  case ModeTextRenderer:
265  drag->setMimeData( mFormat.toMimeData() );
266  break;
267 
268  case ModeQFont:
269  drag->setMimeData( QgsFontUtils::toMimeData( mFont ) );
270  break;
271  }
272  const int iconSize = QgsGuiUtils::scaleIconSize( 50 );
273  drag->setPixmap( createDragIcon( QSize( iconSize, iconSize ) ) );
274  drag->exec( Qt::CopyAction );
275  setDown( false );
276 }
277 
278 bool QgsFontButton::colorFromMimeData( const QMimeData *mimeData, QColor &resultColor, bool &hasAlpha )
279 {
280  hasAlpha = false;
281  QColor mimeColor = QgsSymbolLayerUtils::colorFromMimeData( mimeData, hasAlpha );
282 
283  if ( mimeColor.isValid() )
284  {
285  resultColor = mimeColor;
286  return true;
287  }
288 
289  //could not get color from mime data
290  return false;
291 }
292 
293 void QgsFontButton::dragEnterEvent( QDragEnterEvent *e )
294 {
295  //is dragged data valid font data?
296  QColor mimeColor;
297  QgsTextFormat format;
298  QFont font;
299  bool hasAlpha = false;
300 
301  if ( mMode == ModeTextRenderer && formatFromMimeData( e->mimeData(), format ) )
302  {
303  e->acceptProposedAction();
304  updatePreview( QColor(), &format );
305  }
306  else if ( mMode == ModeQFont && fontFromMimeData( e->mimeData(), font ) )
307  {
308  e->acceptProposedAction();
309  updatePreview( QColor(), nullptr, &font );
310  }
311  else if ( mMode == ModeTextRenderer && colorFromMimeData( e->mimeData(), mimeColor, hasAlpha ) )
312  {
313  //if so, we accept the drag, and temporarily change the button's color
314  //to match the dragged color. This gives immediate feedback to the user
315  //that colors can be dropped here
316  e->acceptProposedAction();
317  updatePreview( mimeColor );
318  }
319 }
320 
321 void QgsFontButton::dragLeaveEvent( QDragLeaveEvent *e )
322 {
323  Q_UNUSED( e )
324  //reset button color
325  updatePreview();
326 }
327 
328 void QgsFontButton::dropEvent( QDropEvent *e )
329 {
330  //is dropped data valid format data?
331  QColor mimeColor;
332  QgsTextFormat format;
333  QFont font;
334  bool hasAlpha = false;
335  if ( mMode == ModeTextRenderer && formatFromMimeData( e->mimeData(), format ) )
336  {
337  setTextFormat( format );
338  QgsFontUtils::addRecentFontFamily( mFormat.font().family() );
339  return;
340  }
341  else if ( mMode == ModeQFont && fontFromMimeData( e->mimeData(), font ) )
342  {
343  QgsFontUtils::addRecentFontFamily( font.family() );
344  setCurrentFont( font );
345  return;
346  }
347  else if ( mMode == ModeTextRenderer && colorFromMimeData( e->mimeData(), mimeColor, hasAlpha ) )
348  {
349  //accept drop and set new color
350  e->acceptProposedAction();
351 
352  if ( hasAlpha )
353  {
354  mFormat.setOpacity( mimeColor.alphaF() );
355  }
356  mimeColor.setAlphaF( 1.0 );
357  mFormat.setColor( mimeColor );
359  updatePreview();
360  emit changed();
361  }
362  updatePreview();
363 }
364 
365 void QgsFontButton::wheelEvent( QWheelEvent *event )
366 {
367  double size = 0;
368  switch ( mMode )
369  {
370  case ModeTextRenderer:
371  size = mFormat.size();
372  break;
373 
374  case ModeQFont:
375  size = mFont.pointSizeF();
376  break;
377  }
378 
379  double increment = ( event->modifiers() & Qt::ControlModifier ) ? 0.1 : 1;
380  if ( event->delta() > 0 )
381  {
382  size += increment;
383  }
384  else
385  {
386  size -= increment;
387  }
388  size = std::max( size, 1.0 );
389 
390  switch ( mMode )
391  {
392  case ModeTextRenderer:
393  {
394  QgsTextFormat newFormat = mFormat;
395  newFormat.setSize( size );
396  setTextFormat( newFormat );
397  break;
398  }
399 
400  case ModeQFont:
401  {
402  QFont newFont = mFont;
403  newFont.setPointSizeF( size );
404  setCurrentFont( newFont );
405  break;
406  }
407  }
408 
409  event->accept();
410 }
411 
412 QPixmap QgsFontButton::createColorIcon( const QColor &color ) const
413 {
414  //create an icon pixmap
415  const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
416  QPixmap pixmap( iconSize, iconSize );
417  pixmap.fill( Qt::transparent );
418 
419  QPainter p;
420  p.begin( &pixmap );
421 
422  //draw color over pattern
423  p.setBrush( QBrush( color ) );
424 
425  //draw border
426  p.setPen( QColor( 197, 197, 197 ) );
427  p.drawRect( 0, 0, iconSize - 1, iconSize - 1 );
428  p.end();
429  return pixmap;
430 }
431 
432 QPixmap QgsFontButton::createDragIcon( QSize size, const QgsTextFormat *tempFormat, const QFont *tempFont ) const
433 {
434  if ( !tempFormat )
435  tempFormat = &mFormat;
436  if ( !tempFont )
437  tempFont = &mFont;
438 
439  //create an icon pixmap
440  QPixmap pixmap( size.width(), size.height() );
441  pixmap.fill( Qt::transparent );
442  QPainter p;
443  p.begin( &pixmap );
444  p.setRenderHint( QPainter::Antialiasing );
445  QRect rect( 0, 0, size.width(), size.height() );
446 
447  if ( mMode == ModeQFont || tempFormat->color().lightnessF() < 0.7 )
448  {
449  p.setBrush( QBrush( QColor( 255, 255, 255 ) ) );
450  p.setPen( QPen( QColor( 150, 150, 150 ), 0 ) );
451  }
452  else
453  {
454  p.setBrush( QBrush( QColor( 0, 0, 0 ) ) );
455  p.setPen( QPen( QColor( 100, 100, 100 ), 0 ) );
456  }
457  p.drawRect( rect );
458  p.setBrush( Qt::NoBrush );
459  p.setPen( Qt::NoPen );
460 
461  switch ( mMode )
462  {
463  case ModeTextRenderer:
464  {
465  QgsRenderContext context;
466  QgsMapToPixel newCoordXForm;
467  newCoordXForm.setParameters( 1, 0, 0, 0, 0, 0 );
468  context.setMapToPixel( newCoordXForm );
469 
470  context.setScaleFactor( QgsApplication::desktop()->logicalDpiX() / 25.4 );
471  context.setUseAdvancedEffects( true );
472  context.setPainter( &p );
473 
474  // slightly inset text to account for buffer/background
475  double xtrans = 0;
476  if ( tempFormat->buffer().enabled() )
477  xtrans = context.convertToPainterUnits( tempFormat->buffer().size(), tempFormat->buffer().sizeUnit(), tempFormat->buffer().sizeMapUnitScale() );
478  if ( tempFormat->background().enabled() && tempFormat->background().sizeType() != QgsTextBackgroundSettings::SizeFixed )
479  xtrans = std::max( xtrans, context.convertToPainterUnits( tempFormat->background().size().width(), tempFormat->background().sizeUnit(), tempFormat->background().sizeMapUnitScale() ) );
480 
481  double ytrans = 0.0;
482  if ( tempFormat->buffer().enabled() )
483  ytrans = std::max( ytrans, context.convertToPainterUnits( tempFormat->buffer().size(), tempFormat->buffer().sizeUnit(), tempFormat->buffer().sizeMapUnitScale() ) );
484  if ( tempFormat->background().enabled() )
485  ytrans = std::max( ytrans, context.convertToPainterUnits( tempFormat->background().size().height(), tempFormat->background().sizeUnit(), tempFormat->background().sizeMapUnitScale() ) );
486 
487  QRectF textRect = rect;
488  textRect.setLeft( xtrans );
489  textRect.setWidth( textRect.width() - xtrans );
490  textRect.setTop( ytrans );
491  if ( textRect.height() > 300 )
492  textRect.setHeight( 300 );
493  if ( textRect.width() > 2000 )
494  textRect.setWidth( 2000 );
495 
496  QgsTextRenderer::drawText( textRect, 0, QgsTextRenderer::AlignCenter, QStringList() << tr( "Aa" ),
497  context, *tempFormat );
498  break;
499  }
500  case ModeQFont:
501  {
502  p.setBrush( Qt::NoBrush );
503  p.setPen( QColor( 0, 0, 0 ) );
504  p.setFont( *tempFont );
505  QRectF textRect = rect;
506  textRect.setLeft( 2 );
507  p.drawText( textRect, Qt::AlignVCenter, tr( "Aa" ) );
508  break;
509  }
510  }
511 
512  p.end();
513  return pixmap;
514 }
515 
516 void QgsFontButton::prepareMenu()
517 {
518  //we need to tear down and rebuild this menu every time it is shown. Otherwise the space allocated to any
519  //QgsColorSwatchGridAction is not recalculated by Qt and the swatch grid may not be the correct size
520  //for the number of colors shown in the grid. Note that we MUST refresh color swatch grids every time this
521  //menu is opened, otherwise color schemes like the recent color scheme grid are meaningless
522  mMenu->clear();
523 
524 
525  QWidgetAction *sizeAction = new QWidgetAction( mMenu );
526  QWidget *sizeWidget = new QWidget();
527  QVBoxLayout *sizeLayout = new QVBoxLayout();
528  sizeLayout->setMargin( 0 );
529  sizeLayout->setContentsMargins( 0, 0, 0, 3 );
530  sizeLayout->setSpacing( 2 );
531 
532  QString fontHeaderLabel;
533  switch ( mMode )
534  {
535  case ModeTextRenderer:
536  fontHeaderLabel = tr( "Font size (%1)" ).arg( QgsUnitTypes::toString( mFormat.sizeUnit() ) );
537  break;
538 
539  case ModeQFont:
540  fontHeaderLabel = tr( "Font size (pt)" );
541  break;
542  }
543 
544  QgsMenuHeader *sizeLabel = new QgsMenuHeader( fontHeaderLabel );
545  sizeLayout->addWidget( sizeLabel );
546 
547  QgsDoubleSpinBox *sizeSpin = new QgsDoubleSpinBox( nullptr );
548  sizeSpin->setDecimals( 4 );
549  sizeSpin->setMaximum( 1e+9 );
550  sizeSpin->setShowClearButton( false );
551  sizeSpin->setValue( mMode == ModeTextRenderer ? mFormat.size() : mFont.pointSizeF() );
552  connect( sizeSpin, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ),
553  this, [ = ]( double value )
554  {
555  switch ( mMode )
556  {
557  case ModeTextRenderer:
558  mFormat.setSize( value );
559  break;
560  case ModeQFont:
561  mFont.setPointSizeF( value );
562  break;
563  }
564  updatePreview();
565  emit changed();
566  } );
567  QHBoxLayout *spinLayout = new QHBoxLayout();
568  spinLayout->setMargin( 0 );
569  spinLayout->setContentsMargins( 4, 0, 4, 0 );
570  spinLayout->addWidget( sizeSpin );
571  sizeLayout->addLayout( spinLayout );
572  sizeWidget->setLayout( sizeLayout );
573  sizeAction->setDefaultWidget( sizeWidget );
574  sizeWidget->setFocusProxy( sizeSpin );
575  sizeWidget->setFocusPolicy( Qt::StrongFocus );
576  mMenu->addAction( sizeAction );
577 
578  QMenu *recentFontMenu = new QMenu( tr( "Recent Fonts" ), mMenu );
579  const auto recentFontFamilies { QgsFontUtils::recentFontFamilies() };
580  for ( const QString &family : recentFontFamilies )
581  {
582  QAction *fontAction = new QAction( family, recentFontMenu );
583  QFont f = fontAction->font();
584  f.setFamily( family );
585  fontAction->setFont( f );
586  fontAction->setToolTip( family );
587  recentFontMenu->addAction( fontAction );
588  if ( ( mMode == ModeTextRenderer && family == mFormat.font().family() )
589  || ( mMode == ModeQFont && family == mFont.family() ) )
590  {
591  fontAction->setCheckable( true );
592  fontAction->setChecked( true );
593  }
594  auto setFont = [this, family]
595  {
596  switch ( mMode )
597  {
598  case ModeTextRenderer:
599  {
600  QgsTextFormat newFormat = mFormat;
601  QFont f = newFormat.font();
602  f.setFamily( family );
603  newFormat.setFont( f );
604  setTextFormat( newFormat );
605  QgsFontUtils::addRecentFontFamily( mFormat.font().family() );
606  break;
607  }
608  case ModeQFont:
609  {
610  QFont font = mFont;
611  font.setFamily( family );
612  setCurrentFont( font );
614  break;
615  }
616  }
617  };
618  connect( fontAction, &QAction::triggered, this, setFont );
619  }
620  mMenu->addMenu( recentFontMenu );
621 
622  QAction *configureAction = new QAction( tr( "Configure Format…" ), this );
623  mMenu->addAction( configureAction );
624  connect( configureAction, &QAction::triggered, this, &QgsFontButton::showSettingsDialog );
625 
626  QAction *copyFormatAction = new QAction( tr( "Copy Format" ), this );
627  mMenu->addAction( copyFormatAction );
628  connect( copyFormatAction, &QAction::triggered, this, &QgsFontButton::copyFormat );
629  QAction *pasteFormatAction = new QAction( tr( "Paste Format" ), this );
630  //enable or disable paste action based on current clipboard contents. We always show the paste
631  //action, even if it's disabled, to give hint to the user that pasting colors is possible
632  QgsTextFormat tempFormat;
633  QFont tempFont;
634  const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
635  if ( mMode == ModeTextRenderer && formatFromMimeData( QApplication::clipboard()->mimeData(), tempFormat ) )
636  {
638  tempFormat.setSize( 14 );
639  pasteFormatAction->setIcon( createDragIcon( QSize( iconSize, iconSize ), &tempFormat ) );
640  }
641  else if ( mMode == ModeQFont && fontFromMimeData( QApplication::clipboard()->mimeData(), tempFont ) )
642  {
643  tempFont.setPointSize( 8 );
644  pasteFormatAction->setIcon( createDragIcon( QSize( iconSize, iconSize ), nullptr, &tempFont ) );
645  }
646  else
647  {
648  pasteFormatAction->setEnabled( false );
649  }
650  mMenu->addAction( pasteFormatAction );
651  connect( pasteFormatAction, &QAction::triggered, this, &QgsFontButton::pasteFormat );
652 
653  if ( mMode == ModeTextRenderer )
654  {
655  mMenu->addSeparator();
656 
657  QgsColorWheel *colorWheel = new QgsColorWheel( mMenu );
658  colorWheel->setColor( mFormat.color() );
659  QgsColorWidgetAction *colorAction = new QgsColorWidgetAction( colorWheel, mMenu, mMenu );
660  colorAction->setDismissOnColorSelection( false );
661  connect( colorAction, &QgsColorWidgetAction::colorChanged, this, &QgsFontButton::setColor );
662  mMenu->addAction( colorAction );
663 
665  QColor alphaColor = mFormat.color();
666  alphaColor.setAlphaF( mFormat.opacity() );
667  alphaRamp->setColor( alphaColor );
668  QgsColorWidgetAction *alphaAction = new QgsColorWidgetAction( alphaRamp, mMenu, mMenu );
669  alphaAction->setDismissOnColorSelection( false );
670  connect( alphaAction, &QgsColorWidgetAction::colorChanged, this, [ = ]( const QColor & color )
671  {
672  double opacity = color.alphaF();
673  mFormat.setOpacity( opacity );
674  updatePreview();
675  emit changed();
676  } );
677  connect( colorAction, &QgsColorWidgetAction::colorChanged, alphaRamp, [alphaRamp]( const QColor & color ) { alphaRamp->setColor( color, false ); }
678  );
679  mMenu->addAction( alphaAction );
680 
681  //get schemes with ShowInColorButtonMenu flag set
682  QList< QgsColorScheme * > schemeList = QgsApplication::colorSchemeRegistry()->schemes( QgsColorScheme::ShowInColorButtonMenu );
683  QList< QgsColorScheme * >::iterator it = schemeList.begin();
684  for ( ; it != schemeList.end(); ++it )
685  {
686  QgsColorSwatchGridAction *colorAction = new QgsColorSwatchGridAction( *it, mMenu, QStringLiteral( "labeling" ), this );
687  colorAction->setBaseColor( mFormat.color() );
688  mMenu->addAction( colorAction );
689  connect( colorAction, &QgsColorSwatchGridAction::colorChanged, this, &QgsFontButton::setColor );
690  connect( colorAction, &QgsColorSwatchGridAction::colorChanged, this, &QgsFontButton::addRecentColor );
691  }
692 
693  mMenu->addSeparator();
694 
695  QAction *copyColorAction = new QAction( tr( "Copy Color" ), this );
696  mMenu->addAction( copyColorAction );
697  connect( copyColorAction, &QAction::triggered, this, &QgsFontButton::copyColor );
698 
699  QAction *pasteColorAction = new QAction( tr( "Paste Color" ), this );
700  //enable or disable paste action based on current clipboard contents. We always show the paste
701  //action, even if it's disabled, to give hint to the user that pasting colors is possible
702  QColor clipColor;
703  bool hasAlpha = false;
704  if ( colorFromMimeData( QApplication::clipboard()->mimeData(), clipColor, hasAlpha ) )
705  {
706  pasteColorAction->setIcon( createColorIcon( clipColor ) );
707  }
708  else
709  {
710  pasteColorAction->setEnabled( false );
711  }
712  mMenu->addAction( pasteColorAction );
713  connect( pasteColorAction, &QAction::triggered, this, &QgsFontButton::pasteColor );
714  }
715 }
716 
717 void QgsFontButton::addRecentColor( const QColor &color )
718 {
720 }
721 
722 QFont QgsFontButton::currentFont() const
723 {
724  return mFont;
725 }
726 
728 {
729  return mLayer;
730 }
731 
733 {
734  mLayer = layer;
735 }
736 
738 {
739  mExpressionContextGenerator = generator;
740 }
741 
742 void QgsFontButton::setCurrentFont( const QFont &font )
743 {
744  mFont = font;
745  updatePreview();
746  emit changed();
747 }
748 
750 {
751  return mMode;
752 }
753 
755 {
756  mMode = mode;
757  updatePreview();
758 }
759 
760 bool QgsFontButton::formatFromMimeData( const QMimeData *mimeData, QgsTextFormat &resultFormat ) const
761 {
762  bool ok = false;
763  resultFormat = QgsTextFormat::fromMimeData( mimeData, &ok );
764  return ok;
765 }
766 
767 bool QgsFontButton::fontFromMimeData( const QMimeData *mimeData, QFont &resultFont ) const
768 {
769  bool ok = false;
770  resultFont = QgsFontUtils::fromMimeData( mimeData, &ok );
771  return ok;
772 }
773 
774 void QgsFontButton::changeEvent( QEvent *e )
775 {
776  if ( e->type() == QEvent::EnabledChange )
777  {
778  updatePreview();
779  }
780  QToolButton::changeEvent( e );
781 }
782 
783 void QgsFontButton::showEvent( QShowEvent *e )
784 {
785  updatePreview();
786  QToolButton::showEvent( e );
787 }
788 
789 void QgsFontButton::resizeEvent( QResizeEvent *event )
790 {
791  QToolButton::resizeEvent( event );
792  //recalculate icon size and redraw icon
793  mIconSize = QSize();
794  updatePreview();
795 }
796 
797 void QgsFontButton::updatePreview( const QColor &color, QgsTextFormat *format, QFont *font )
798 {
799  QgsTextFormat tempFormat;
800  QFont tempFont;
801 
802  if ( format )
803  tempFormat = *format;
804  else
805  tempFormat = mFormat;
806  if ( font )
807  tempFont = *font;
808  else
809  tempFont = mFont;
810 
811  if ( color.isValid() )
812  tempFormat.setColor( color );
813 
814  QSize currentIconSize;
815  //icon size is button size with a small margin
816  if ( menu() )
817  {
818  if ( !mIconSize.isValid() )
819  {
820  //calculate size of push button part of widget (ie, without the menu dropdown button part)
821  QStyleOptionToolButton opt;
822  initStyleOption( &opt );
823  QRect buttonSize = QApplication::style()->subControlRect( QStyle::CC_ToolButton, &opt, QStyle::SC_ToolButton,
824  this );
825  //make sure height of icon looks good under different platforms
826 #ifdef Q_OS_WIN
827  mIconSize = QSize( buttonSize.width() - 10, height() - 6 );
828 #elif defined(Q_OS_MAC)
829  mIconSize = QSize( buttonSize.width() - 10, height() - 2 );
830 #else
831  mIconSize = QSize( buttonSize.width() - 10, height() - 12 );
832 #endif
833  }
834  currentIconSize = mIconSize;
835  }
836  else
837  {
838  //no menu
839 #ifdef Q_OS_WIN
840  currentIconSize = QSize( width() - 10, height() - 6 );
841 #else
842  currentIconSize = QSize( width() - 10, height() - 12 );
843 #endif
844  }
845 
846  if ( !currentIconSize.isValid() || currentIconSize.width() <= 0 || currentIconSize.height() <= 0 )
847  {
848  return;
849  }
850 
851  //create an icon pixmap
852  QPixmap pixmap( currentIconSize );
853  pixmap.fill( Qt::transparent );
854  QPainter p;
855  p.begin( &pixmap );
856  p.setRenderHint( QPainter::Antialiasing );
857  QRect rect( 0, 0, currentIconSize.width(), currentIconSize.height() );
858 
859  switch ( mMode )
860  {
861  case ModeTextRenderer:
862  {
863  QgsRenderContext context;
864  QgsMapToPixel newCoordXForm;
865  newCoordXForm.setParameters( 1, 0, 0, 0, 0, 0 );
866  context.setMapToPixel( newCoordXForm );
867 
868  context.setScaleFactor( QgsApplication::desktop()->logicalDpiX() / 25.4 );
869  context.setUseAdvancedEffects( true );
870  context.setPainter( &p );
871 
872  // slightly inset text to account for buffer/background
873  double xtrans = 0;
874  if ( tempFormat.buffer().enabled() )
875  xtrans = context.convertToPainterUnits( tempFormat.buffer().size(), tempFormat.buffer().sizeUnit(), tempFormat.buffer().sizeMapUnitScale() );
876  if ( tempFormat.background().enabled() && tempFormat.background().sizeType() != QgsTextBackgroundSettings::SizeFixed )
877  xtrans = std::max( xtrans, context.convertToPainterUnits( tempFormat.background().size().width(), tempFormat.background().sizeUnit(), tempFormat.background().sizeMapUnitScale() ) );
878 
879  double ytrans = 0.0;
880  if ( tempFormat.buffer().enabled() )
881  ytrans = std::max( ytrans, context.convertToPainterUnits( tempFormat.buffer().size(), tempFormat.buffer().sizeUnit(), tempFormat.buffer().sizeMapUnitScale() ) );
882  if ( tempFormat.background().enabled() )
883  ytrans = std::max( ytrans, context.convertToPainterUnits( tempFormat.background().size().height(), tempFormat.background().sizeUnit(), tempFormat.background().sizeMapUnitScale() ) );
884 
885  QRectF textRect = rect;
886  textRect.setLeft( xtrans );
887  textRect.setWidth( textRect.width() - xtrans );
888  textRect.setTop( ytrans );
889  if ( textRect.height() > 300 )
890  textRect.setHeight( 300 );
891  if ( textRect.width() > 2000 )
892  textRect.setWidth( 2000 );
893 
894  QgsTextRenderer::drawText( textRect, 0, QgsTextRenderer::AlignLeft, QStringList() << text(),
895  context, tempFormat );
896  break;
897  }
898  case ModeQFont:
899  {
900  p.setBrush( Qt::NoBrush );
901  p.setPen( QColor( 0, 0, 0 ) );
902  p.setFont( tempFont );
903  QRectF textRect = rect;
904  textRect.setLeft( 2 );
905  p.drawText( textRect, Qt::AlignVCenter, text() );
906  break;
907  }
908 
909  }
910  p.end();
911  setIconSize( currentIconSize );
912  setIcon( pixmap );
913 }
914 
916 {
917  //copy color
918  QApplication::clipboard()->setMimeData( QgsSymbolLayerUtils::colorToMimeData( mFormat.color() ) );
919 }
920 
922 {
923  QColor clipColor;
924  bool hasAlpha = false;
925  if ( colorFromMimeData( QApplication::clipboard()->mimeData(), clipColor, hasAlpha ) )
926  {
927  //paste color
928  setColor( clipColor );
930  }
931 }
932 
933 void QgsFontButton::setDialogTitle( const QString &title )
934 {
935  mDialogTitle = title;
936 }
937 
938 QString QgsFontButton::dialogTitle() const
939 {
940  return mDialogTitle;
941 }
QgsFontButton::setDialogTitle
void setDialogTitle(const QString &title)
Sets the title for the text settings dialog window.
Definition: qgsfontbutton.cpp:933
QgsFontButton::dragLeaveEvent
void dragLeaveEvent(QDragLeaveEvent *e) override
Definition: qgsfontbutton.cpp:321
QgsFontButton::event
bool event(QEvent *e) override
Definition: qgsfontbutton.cpp:205
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:369
qgsexpressioncontextutils.h
QgsExpressionContext::appendScopes
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
Definition: qgsexpressioncontext.cpp:495
QgsTextFormat::buffer
QgsTextBufferSettings & buffer()
Returns a reference to the text buffer settings.
Definition: qgstextformat.h:66
QgsFontButton::changeEvent
void changeEvent(QEvent *e) override
Definition: qgsfontbutton.cpp:774
qgscolorscheme.h
QgsRenderContext::convertToPainterUnits
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
Definition: qgsrendercontext.cpp:287
QgsSymbolLayerUtils::colorToMimeData
static QMimeData * colorToMimeData(const QColor &color)
Creates mime data from a color.
Definition: qgssymbollayerutils.cpp:3250
QgsColorRampWidget::Horizontal
@ Horizontal
Horizontal ramp.
Definition: qgscolorwidgets.h:490
qgsdoublespinbox.h
QgsFontUtils::toMimeData
static QMimeData * toMimeData(const QFont &font)
Returns new mime data representing the specified font settings.
Definition: qgsfontutils.cpp:367
QgsTextFormat::setFont
void setFont(const QFont &font)
Sets the font used for rendering text.
Definition: qgstextformat.cpp:76
QgsTextBufferSettings::sizeMapUnitScale
QgsMapUnitScale sizeMapUnitScale() const
Returns the map unit scale object for the buffer size.
Definition: qgstextbuffersettings.cpp:77
QgsFontButton::resizeEvent
void resizeEvent(QResizeEvent *event) override
Definition: qgsfontbutton.cpp:789
QgsTextBackgroundSettings::enabled
bool enabled() const
Returns whether the background is enabled.
Definition: qgstextbackgroundsettings.cpp:47
QgsTextFormatPanelWidget::setContext
void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the widget is shown, e.g., the associated map canvas and expression context...
Definition: qgstextformatwidget.cpp:2055
qgsmapcanvas.h
qgstextrenderer.h
QgsMapToPixel::setParameters
void setParameters(double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation)
Set parameters for use in transforming coordinates.
Definition: qgsmaptopixel.cpp:163
QgsPanelWidget::findParentPanel
static QgsPanelWidget * findParentPanel(QWidget *widget)
Traces through the parents of a widget to find if it is contained within a QgsPanelWidget widget.
Definition: qgspanelwidget.cpp:49
QgsGuiUtils::getFont
QFont getFont(bool &ok, const QFont &initial, const QString &title)
Show font selection dialog.
Definition: qgsguiutils.cpp:208
QgsColorSwatchGridAction
Definition: qgscolorswatchgrid.h:189
qgscolorswatchgrid.h
QgsTextRenderer::AlignCenter
@ AlignCenter
Center align.
Definition: qgstextrenderer.h:61
QgsColorSwatchGridAction::setBaseColor
void setBaseColor(const QColor &baseColor)
Sets the base color for the color grid.
Definition: qgscolorswatchgrid.cpp:432
QgsFontButton::setTextFormat
void setTextFormat(const QgsTextFormat &format)
Sets the current text format to show in the widget.
Definition: qgsfontbutton.cpp:155
QgsRenderContext::setPainter
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
Definition: qgsrendercontext.h:475
qgssymbollayerutils.h
QgsFontButton::mode
Mode mode
Definition: qgsfontbutton.h:48
QgsFontUtils::fromMimeData
static QFont fromMimeData(const QMimeData *data, bool *ok=nullptr)
Attempts to parse the provided mime data as a QFont.
Definition: qgsfontutils.cpp:379
QgsSymbolWidgetContext
Definition: qgssymbolwidgetcontext.h:35
QgsMapCanvas
Definition: qgsmapcanvas.h:83
QgsPanelWidget::openPanel
void openPanel(QgsPanelWidget *panel)
Open a panel or dialog depending on dock mode setting If dock mode is true this method will emit the ...
Definition: qgspanelwidget.cpp:79
QgsTextFormat::sizeUnit
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units for the size of rendered text.
Definition: qgstextformat.cpp:96
QgsTextFormatDialog
Definition: qgstextformatwidget.h:323
QgsFontButton::showEvent
void showEvent(QShowEvent *e) override
Definition: qgsfontbutton.cpp:783
QgsRenderContext
Definition: qgsrendercontext.h:57
QgsApplication::colorSchemeRegistry
static QgsColorSchemeRegistry * colorSchemeRegistry()
Returns the application's color scheme registry, used for managing color schemes.
Definition: qgsapplication.cpp:2089
qgsunittypes.h
QgsExpressionContextUtils::globalProjectLayerScopes
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
Definition: qgsexpressioncontextutils.cpp:306
qgscolorwidgets.h
QgsColorRampWidget
Definition: qgscolorwidgets.h:479
QgsFontUtils::recentFontFamilies
static QStringList recentFontFamilies()
Returns a list of recently used font families.
Definition: qgsfontutils.cpp:542
qgsfontutils.h
QgsFontButton::dialogTitle
QString dialogTitle
Definition: qgsfontbutton.h:49
QgsSymbolLayerUtils::colorFromMimeData
static QColor colorFromMimeData(const QMimeData *data, bool &hasAlpha)
Attempts to parse mime data as a color.
Definition: qgssymbollayerutils.cpp:3260
QgsTextBackgroundSettings::sizeType
SizeType sizeType() const
Returns the method used to determine the size of the background shape (e.g., fixed size or buffer aro...
Definition: qgstextbackgroundsettings.cpp:87
QgsFontButton::copyColor
void copyColor()
Copies the current text color to the clipboard.
Definition: qgsfontbutton.cpp:915
QgsPanelWidget::dockMode
bool dockMode()
Returns the dock mode state.
Definition: qgspanelwidget.h:83
QgsGuiUtils::iconSize
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.
Definition: qgsguiutils.cpp:264
QgsSymbolWidgetContext::setMapCanvas
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
Definition: qgssymbolwidgetcontext.cpp:49
QgsColorScheme::ShowInColorButtonMenu
@ ShowInColorButtonMenu
Show scheme in color button drop-down menu.
Definition: qgscolorscheme.h:74
QgsTextFormat::color
QColor color() const
Returns the color that text will be rendered in.
Definition: qgstextformat.cpp:126
qgsapplication.h
QgsFontButton::pasteFormat
void pasteFormat()
Pastes a format from the clipboard.
Definition: qgsfontbutton.cpp:189
QgsTextRenderer::drawText
static void drawText(const QRectF &rect, double rotation, HAlignment alignment, const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, bool drawAsOutlines=true)
Draws text within a rectangle using the specified settings.
Definition: qgstextrenderer.cpp:45
QgsTextBackgroundSettings::sizeMapUnitScale
QgsMapUnitScale sizeMapUnitScale() const
Returns the map unit scale object for the shape size.
Definition: qgstextbackgroundsettings.cpp:117
QgsTextFormat
Definition: qgstextformat.h:38
QgsFontButton::setMapCanvas
void setMapCanvas(QgsMapCanvas *canvas)
Sets a map canvas to associate with the widget.
Definition: qgsfontbutton.cpp:140
QgsTextFormat::setColor
void setColor(const QColor &color)
Sets the color that text will be rendered in.
Definition: qgstextformat.cpp:131
QgsSymbolWidgetContext::setMessageBar
void setMessageBar(QgsMessageBar *bar)
Sets the message bar associated with the widget.
Definition: qgssymbolwidgetcontext.cpp:59
QgsTextBackgroundSettings::size
QSizeF size() const
Returns the size of the background shape.
Definition: qgstextbackgroundsettings.cpp:97
qgstextformatwidget.h
QgsColorWidget::setColor
virtual void setColor(const QColor &color, bool emitSignals=false)
Sets the color for the widget.
Definition: qgscolorwidgets.cpp:342
QgsPanelWidget
Base class for any widget that can be shown as a inline panel.
Definition: qgspanelwidget.h:29
QgsFontButton::dropEvent
void dropEvent(QDropEvent *e) override
Definition: qgsfontbutton.cpp:328
QgsColorWidgetAction::setDismissOnColorSelection
void setDismissOnColorSelection(bool dismiss)
Sets whether the parent menu should be dismissed and closed when a color is selected from the action'...
Definition: qgscolorwidgets.h:240
QgsFontButton::registerExpressionContextGenerator
void registerExpressionContextGenerator(QgsExpressionContextGenerator *generator)
Register an expression context generator class that will be used to retrieve an expression context fo...
Definition: qgsfontbutton.cpp:737
QgsFontButton::sizeHint
QSize sizeHint() const override
Definition: qgsfontbutton.cpp:70
QgsTextFormat::fromMimeData
static QgsTextFormat fromMimeData(const QMimeData *data, bool *ok=nullptr)
Attempts to parse the provided mime data as a QgsTextFormat.
Definition: qgstextformat.cpp:524
QgsUnitTypes::toString
static Q_INVOKABLE QString toString(QgsUnitTypes::DistanceUnit unit)
Returns a translated string representing a distance unit.
Definition: qgsunittypes.cpp:199
QgsFontButton::Mode
Mode
Available button modes.
Definition: qgsfontbutton.h:56
QgsFontButton::setColor
void setColor(const QColor &color)
Sets the current color for the text.
Definition: qgsfontbutton.cpp:162
QgsColorWheel
Definition: qgscolorwidgets.h:289
QgsFontButton::pasteColor
void pasteColor()
Pastes a color from the clipboard to the text format.
Definition: qgsfontbutton.cpp:921
QgsColorWidget::Alpha
@ Alpha
Alpha component (opacity) of color.
Definition: qgscolorwidgets.h:57
QgsMessageBar
Definition: qgsmessagebar.h:60
qgsmenuheader.h
QgsPanelWidget::widgetChanged
void widgetChanged()
Emitted when the widget state changes.
QgsRenderContext::setMapToPixel
void setMapToPixel(const QgsMapToPixel &mtp)
Sets the context's map to pixel transform, which transforms between map coordinates and device coordi...
Definition: qgsrendercontext.h:404
QgsTextRenderer::AlignLeft
@ AlignLeft
Left align.
Definition: qgstextrenderer.h:60
QgsColorWidgetAction
Definition: qgscolorwidgets.h:213
QgsExpressionContextGenerator::createExpressionContext
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QgsColorWheel::setColor
void setColor(const QColor &color, bool emitSignals=false) override
Definition: qgscolorwidgets.cpp:482
qgsfontbutton.h
QgsTextFormat::opacity
double opacity() const
Returns the text's opacity.
Definition: qgstextformat.cpp:136
Qgis::UI_SCALE_FACTOR
static const double UI_SCALE_FACTOR
UI scaling factor.
Definition: qgis.h:195
QgsFontButton::currentFont
QFont currentFont
Definition: qgsfontbutton.h:50
QgsDoubleSpinBox::setShowClearButton
void setShowClearButton(bool showClearButton)
Sets whether the widget will show a clear button.
Definition: qgsdoublespinbox.cpp:55
QgsTextBufferSettings::sizeUnit
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units for the buffer size.
Definition: qgstextbuffersettings.cpp:67
QgsPanelWidget::setPanelTitle
void setPanelTitle(const QString &panelTitle)
Set the title of the panel when shown in the interface.
Definition: qgspanelwidget.h:44
QgsFontButton::QgsFontButton
QgsFontButton(QWidget *parent=nullptr, const QString &dialogTitle=QString())
Construct a new font button.
Definition: qgsfontbutton.cpp:38
QgsTextFormatPanelWidget::format
QgsTextFormat format() const
Returns the current formatting settings defined by the widget.
Definition: qgstextformatwidget.cpp:2050
QgsFontButton::layer
QgsVectorLayer * layer() const
Returns the layer associated with the widget.
Definition: qgsfontbutton.cpp:727
QgsTextFormatPanelWidget
Definition: qgstextformatwidget.h:378
QgsFontButton::wheelEvent
void wheelEvent(QWheelEvent *event) override
Definition: qgsfontbutton.cpp:365
QgsTextBufferSettings::size
double size() const
Returns the size of the buffer.
Definition: qgstextbuffersettings.cpp:57
QgsUnitTypes::RenderPixels
@ RenderPixels
Pixels.
Definition: qgsunittypes.h:170
qgsvectorlayer.h
QgsTextFormat::size
double size() const
Returns the size for rendered text.
Definition: qgstextformat.cpp:116
QgsFontButton::ModeQFont
@ ModeQFont
Configure font settings for use with QFont objects.
Definition: qgsfontbutton.h:59
QgsTextBufferSettings::enabled
bool enabled() const
Returns whether the buffer is enabled.
Definition: qgstextbuffersettings.cpp:47
QgsTextFormat::toMimeData
QMimeData * toMimeData() const
Returns new mime data representing the text format settings.
Definition: qgstextformat.cpp:460
QgsFontButton::ModeTextRenderer
@ ModeTextRenderer
Configure font settings for use with QgsTextRenderer.
Definition: qgsfontbutton.h:58
QgsFontButton::mouseMoveEvent
void mouseMoveEvent(QMouseEvent *e) override
Definition: qgsfontbutton.cpp:242
QgsFontButton::mapCanvas
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
Definition: qgsfontbutton.cpp:135
QgsMapToPixel
Definition: qgsmaptopixel.h:37
QgsTextBackgroundSettings::SizeFixed
@ SizeFixed
Fixed size.
Definition: qgstextbackgroundsettings.h:68
QgsColorSchemeRegistry::schemes
QList< QgsColorScheme * > schemes() const
Returns all color schemes in the registry.
Definition: qgscolorschemeregistry.cpp:88
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsRecentColorScheme::addRecentColor
static void addRecentColor(const QColor &color)
Adds a color to the list of recent colors.
Definition: qgscolorscheme.cpp:66
QgsColorSwatchGridAction::colorChanged
void colorChanged(const QColor &color)
Emitted when a color has been selected from the widget.
QgsTextFormat::setOpacity
void setOpacity(double opacity)
Sets the text's opacity.
Definition: qgstextformat.cpp:141
QgsFontButton::mousePressEvent
void mousePressEvent(QMouseEvent *e) override
Definition: qgsfontbutton.cpp:228
QgsFontButton::setMessageBar
void setMessageBar(QgsMessageBar *bar)
Sets the message bar associated with the widget.
Definition: qgsfontbutton.cpp:145
qgscolorschemeregistry.h
QgsColorWidgetAction::colorChanged
void colorChanged(const QColor &color)
Emitted when a color has been selected from the widget.
QgsDoubleSpinBox
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value....
Definition: qgsdoublespinbox.h:42
QgsTextFormat::font
QFont font() const
Returns the font used for rendering text.
Definition: qgstextformat.cpp:62
QgsTextFormat::background
QgsTextBackgroundSettings & background()
Returns a reference to the text background settings.
Definition: qgstextformat.h:85
QgsTextFormat::setSizeUnit
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the size of rendered text.
Definition: qgstextformat.cpp:101
QgsFontButton::dragEnterEvent
void dragEnterEvent(QDragEnterEvent *e) override
Definition: qgsfontbutton.cpp:293
QgsTextBackgroundSettings::sizeUnit
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units used for the shape's size.
Definition: qgstextbackgroundsettings.cpp:107
QgsFontButton::setLayer
void setLayer(QgsVectorLayer *layer)
Sets a layer to associate with the widget.
Definition: qgsfontbutton.cpp:732
QgsMenuHeader
Definition: qgsmenuheader.h:32
QgsRenderContext::setUseAdvancedEffects
void setUseAdvancedEffects(bool enabled)
Used to enable or disable advanced effects such as blend modes.
Definition: qgsrendercontext.cpp:225
QgsFontUtils::addRecentFontFamily
static void addRecentFontFamily(const QString &family)
Adds a font family to the list of recently used font families.
Definition: qgsfontutils.cpp:520
QgsSymbolWidgetContext::setExpressionContext
void setExpressionContext(QgsExpressionContext *context)
Sets the optional expression context used for the widget.
Definition: qgssymbolwidgetcontext.cpp:69
QgsFontButton::setCurrentFont
void setCurrentFont(const QFont &font)
Sets the current text font to show in the widget.
Definition: qgsfontbutton.cpp:742
QgsTextFormat::setSize
void setSize(double size)
Sets the size for rendered text.
Definition: qgstextformat.cpp:121
QgsGuiUtils::scaleIconSize
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly,...
Definition: qgsguiutils.cpp:257
QgsFontButton::minimumSizeHint
QSize minimumSizeHint() const override
Definition: qgsfontbutton.cpp:65
QgsFontButton::copyFormat
void copyFormat()
Copies the current text format to the clipboard.
Definition: qgsfontbutton.cpp:175
QgsExpressionContextGenerator
Definition: qgsexpressioncontextgenerator.h:36
QgsFontButton::setMode
void setMode(Mode mode)
Sets the current button mode.
Definition: qgsfontbutton.cpp:754
QgsFontButton::messageBar
QgsMessageBar * messageBar() const
Returns the message bar associated with the widget.
Definition: qgsfontbutton.cpp:150
QgsRenderContext::setScaleFactor
void setScaleFactor(double factor)
Sets the scaling factor for the render to convert painter units to physical sizes.
Definition: qgsrendercontext.h:460
QgsFontButton::changed
void changed()
Emitted when the widget's text format settings are changed.