QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgsformlabelformatwidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsformlabelformatwidget.cpp - QgsFormLabelFormatWidget
3
4 ---------------------
5 begin : 22.4.2022
6 copyright : (C) 2022 by Alessandro Pasotti
7 email : elpaso at itopen dot it
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
17#include "moc_qgsformlabelformatwidget.cpp"
18#include "qgsguiutils.h"
19#include "qgsfontutils.h"
20
21#include <QGroupBox>
22
24
25QgsFormLabelFormatWidget::QgsFormLabelFormatWidget( QWidget *parent )
26 : QWidget( parent )
27{
28 setupUi( this );
29
30 mFontBoldBtn->setChecked( false );
31 mFontItalicBtn->setChecked( false );
32 mFontUnderlineBtn->setChecked( false );
33 mFontStrikethroughBtn->setChecked( false );
34
35 const int buttonSize = QgsGuiUtils::scaleIconSize( 24 );
36 mFontUnderlineBtn->setMinimumSize( buttonSize, buttonSize );
37 mFontUnderlineBtn->setMaximumSize( buttonSize, buttonSize );
38 mFontBoldBtn->setMinimumSize( buttonSize, buttonSize );
39 mFontBoldBtn->setMaximumSize( buttonSize, buttonSize );
40 mFontItalicBtn->setMinimumSize( buttonSize, buttonSize );
41 mFontItalicBtn->setMaximumSize( buttonSize, buttonSize );
42
43 mOverrideLabelColorGroupBox->setSaveCheckedState( false );
44 mOverrideLabelFontGroupBox->setSaveCheckedState( false );
45 mOverrideLabelColorGroupBox->setSaveCollapsedState( false );
46 mOverrideLabelFontGroupBox->setSaveCollapsedState( false );
47
48 btnTextColor->setAllowOpacity( true );
49 btnTextColor->setShowNull( true, tr( "Default color" ) );
50
51}
52
53void QgsFormLabelFormatWidget::setLabelStyle( const QgsAttributeEditorElement::LabelStyle &labelStyle )
54{
55 mFontFamilyCmbBx->setCurrentFont( labelStyle.font );
56 mFontUnderlineBtn->setChecked( labelStyle.font.underline() );
57 mFontItalicBtn->setChecked( labelStyle.font.italic() );
58 mFontBoldBtn->setChecked( labelStyle.font.bold() );
59 mFontStrikethroughBtn->setChecked( labelStyle.font.strikeOut() );
60 if ( labelStyle.color.isValid() )
61 {
62 btnTextColor->setColor( labelStyle.color );
63 }
64 else
65 {
66 btnTextColor->setToNull();
67 }
68 mOverrideLabelColorGroupBox->setChecked( labelStyle.overrideColor );
69 mOverrideLabelFontGroupBox->setChecked( labelStyle.overrideFont );
70 mOverrideLabelColorGroupBox->setCollapsed( ! labelStyle.overrideColor );
71 mOverrideLabelFontGroupBox->setCollapsed( ! labelStyle.overrideFont );
72}
73
74QgsAttributeEditorElement::LabelStyle QgsFormLabelFormatWidget::labelStyle() const
75{
77 style.color = btnTextColor->color();
78 QFont currentFont;
79 QgsFontUtils::setFontFamily( currentFont, mFontFamilyCmbBx->currentFont().family() );
80 currentFont.setBold( mFontBoldBtn->isChecked() );
81 currentFont.setItalic( mFontItalicBtn->isChecked() );
82 currentFont.setUnderline( mFontUnderlineBtn->isChecked() );
83 currentFont.setStrikeOut( mFontStrikethroughBtn->isChecked() );
84 style.font = currentFont;
85 style.overrideColor = mOverrideLabelColorGroupBox->isChecked( );
86 style.overrideFont = mOverrideLabelFontGroupBox->isChecked( );
87 return style;
88}
89
static void setFontFamily(QFont &font, const QString &family)
Sets the family for a font object.
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly,...
The TabStyle struct defines color and font overrides for form fields, tabs and groups labels.