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