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