QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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 "qgsguiutils.h"
18#include <QGroupBox>
19
21
22QgsFormLabelFormatWidget::QgsFormLabelFormatWidget( QWidget *parent )
23 : QWidget( parent )
24{
25 setupUi( this );
26
27 mFontBoldBtn->setChecked( false );
28 mFontItalicBtn->setChecked( false );
29 mFontUnderlineBtn->setChecked( false );
30 mFontStrikethroughBtn->setChecked( false );
31
32 const int buttonSize = QgsGuiUtils::scaleIconSize( 24 );
33 mFontUnderlineBtn->setMinimumSize( buttonSize, buttonSize );
34 mFontUnderlineBtn->setMaximumSize( buttonSize, buttonSize );
35 mFontBoldBtn->setMinimumSize( buttonSize, buttonSize );
36 mFontBoldBtn->setMaximumSize( buttonSize, buttonSize );
37 mFontItalicBtn->setMinimumSize( buttonSize, buttonSize );
38 mFontItalicBtn->setMaximumSize( buttonSize, buttonSize );
39
40 mOverrideLabelColorGroupBox->setSaveCheckedState( false );
41 mOverrideLabelFontGroupBox->setSaveCheckedState( false );
42 mOverrideLabelColorGroupBox->setSaveCollapsedState( false );
43 mOverrideLabelFontGroupBox->setSaveCollapsedState( false );
44
45 btnTextColor->setAllowOpacity( true );
46 btnTextColor->setShowNull( true, tr( "Default color" ) );
47
48}
49
50void QgsFormLabelFormatWidget::setLabelStyle( const QgsAttributeEditorElement::LabelStyle &labelStyle )
51{
52 mFontFamilyCmbBx->setCurrentFont( labelStyle.font );
53 mFontUnderlineBtn->setChecked( labelStyle.font.underline() );
54 mFontItalicBtn->setChecked( labelStyle.font.italic() );
55 mFontBoldBtn->setChecked( labelStyle.font.bold() );
56 mFontStrikethroughBtn->setChecked( labelStyle.font.strikeOut() );
57 if ( labelStyle.color.isValid() )
58 {
59 btnTextColor->setColor( labelStyle.color );
60 }
61 else
62 {
63 btnTextColor->setToNull();
64 }
65 mOverrideLabelColorGroupBox->setChecked( labelStyle.overrideColor );
66 mOverrideLabelFontGroupBox->setChecked( labelStyle.overrideFont );
67 mOverrideLabelColorGroupBox->setCollapsed( ! labelStyle.overrideColor );
68 mOverrideLabelFontGroupBox->setCollapsed( ! labelStyle.overrideFont );
69}
70
71QgsAttributeEditorElement::LabelStyle QgsFormLabelFormatWidget::labelStyle() const
72{
74 style.color = btnTextColor->color();
75 QFont currentFont;
76 currentFont.setFamily( mFontFamilyCmbBx->currentFont().family() );
77 currentFont.setBold( mFontBoldBtn->isChecked() );
78 currentFont.setItalic( mFontItalicBtn->isChecked() );
79 currentFont.setUnderline( mFontUnderlineBtn->isChecked() );
80 currentFont.setStrikeOut( mFontStrikethroughBtn->isChecked() );
81 style.font = currentFont;
82 style.overrideColor = mOverrideLabelColorGroupBox->isChecked( );
83 style.overrideFont = mOverrideLabelFontGroupBox->isChecked( );
84 return style;
85}
86
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.