QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgstextcharacterformat.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgstextcharacterformat.cpp
3  -----------------
4  begin : May 2020
5  copyright : (C) 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 "qgstextcharacterformat.h"
17 
18 #include <QTextCharFormat>
19 
20 QgsTextCharacterFormat::QgsTextCharacterFormat( const QTextCharFormat &format )
21  : mTextColor( format.hasProperty( QTextFormat::ForegroundBrush ) ? format.foreground().color() : QColor() )
22 #if 0 // settings which affect font metrics are disabled for now
23  , mFontWeight( format.hasProperty( QTextFormat::FontWeight ) ? format.fontWeight() : -1 )
24  , mItalic( format.hasProperty( QTextFormat::FontItalic ) ? ( format.fontItalic() ? BooleanValue::SetTrue : BooleanValue::SetFalse ) : BooleanValue::NotSet )
25  , mFontPointSize( format.hasProperty( QTextFormat::FontPointSize ) ? format.fontPointSize() : - 1 )
26  , mFontFamily( format.hasProperty( QTextFormat::FontFamily ) ? format.fontFamily() : QString() )
27 #endif
28  , mStrikethrough( format.hasProperty( QTextFormat::FontStrikeOut ) ? ( format.fontStrikeOut() ? BooleanValue::SetTrue : BooleanValue::SetFalse ) : BooleanValue::NotSet )
29  , mUnderline( format.hasProperty( QTextFormat::FontUnderline ) ? ( format.fontUnderline() ? BooleanValue::SetTrue : BooleanValue::SetFalse ) : BooleanValue::NotSet )
30  , mOverline( format.hasProperty( QTextFormat::FontOverline ) ? ( format.fontOverline() ? BooleanValue::SetTrue : BooleanValue::SetFalse ) : BooleanValue::NotSet )
31 {
32 
33 }
34 
36 {
37  return mTextColor;
38 }
39 
40 void QgsTextCharacterFormat::setTextColor( const QColor &textColor )
41 {
42  mTextColor = textColor;
43 }
44 
46 {
47  return mStrikethrough;
48 }
49 
51 {
52  mStrikethrough = strikethrough;
53 }
54 
56 {
57  return mUnderline;
58 }
59 
61 {
62  mUnderline = underline;
63 }
64 
66 {
67  return mOverline;
68 }
69 
71 {
72  mOverline = enabled;
73 }
74 
76 {
77 #if 0 // settings which affect font metrics are disabled for now
79  font.setItalic( mItalic == QgsTextCharacterFormat::BooleanValue::SetTrue );
80  if ( mFontWeight != -1 )
81  font.setWeight( mFontWeight );
82  if ( !mFontFamily.isEmpty() )
83  font.setFamily( mFontFamily );
84  if ( mFontPointSize != -1 )
85  font.setPointSizeF( mFontPointSize );
86 #endif
87 
88  if ( mUnderline != BooleanValue::NotSet )
89  font.setUnderline( mUnderline == QgsTextCharacterFormat::BooleanValue::SetTrue );
90  if ( mOverline != BooleanValue::NotSet )
91  font.setOverline( mOverline == QgsTextCharacterFormat::BooleanValue::SetTrue );
92  if ( mStrikethrough != QgsTextCharacterFormat::BooleanValue::NotSet )
93  font.setStrikeOut( mStrikethrough == QgsTextCharacterFormat::BooleanValue::SetTrue );
94 }
95 
96 #if 0 // settings which affect font metrics are disabled for now
97 QgsTextCharacterFormat::BooleanValue QgsTextCharacterFormat::italic() const
98 {
99  return mItalic;
100 }
101 
102 void QgsTextCharacterFormat::setItalic( QgsTextCharacterFormat::BooleanValue enabled )
103 {
104  mItalic = enabled;
105 }
106 
107 int QgsTextCharacterFormat::fontWeight() const
108 {
109  return mFontWeight;
110 }
111 
112 void QgsTextCharacterFormat::setFontWeight( int fontWeight )
113 {
114  mFontWeight = fontWeight;
115 }
116 #endif
QgsTextCharacterFormat::BooleanValue::NotSet
@ NotSet
Property is not set.
QgsTextCharacterFormat::BooleanValue::SetTrue
@ SetTrue
Property is set and true.
QgsTextCharacterFormat::textColor
QColor textColor() const
Returns the character's text color, or an invalid color if no color override is set and the default f...
Definition: qgstextcharacterformat.cpp:35
QgsTextCharacterFormat::overline
BooleanValue overline() const
Returns whether the format has overline enabled.
Definition: qgstextcharacterformat.cpp:65
QgsTextCharacterFormat::BooleanValue
BooleanValue
Status values for boolean format properties.
Definition: qgstextcharacterformat.h:54
QgsTextCharacterFormat::setUnderline
void setUnderline(BooleanValue enabled)
Sets whether the format has underline enabled.
Definition: qgstextcharacterformat.cpp:60
QgsTextCharacterFormat::setStrikeOut
void setStrikeOut(BooleanValue enabled)
Sets whether the format has strikethrough enabled.
Definition: qgstextcharacterformat.cpp:50
qgstextcharacterformat.h
QgsTextCharacterFormat::updateFontForFormat
void updateFontForFormat(QFont &font) const
Updates the specified font in place, applying character formatting options which are applicable on a ...
Definition: qgstextcharacterformat.cpp:75
QgsTextCharacterFormat::setOverline
void setOverline(BooleanValue enabled)
Sets whether the format has overline enabled.
Definition: qgstextcharacterformat.cpp:70
QgsTextCharacterFormat::underline
BooleanValue underline() const
Returns whether the format has underline enabled.
Definition: qgstextcharacterformat.cpp:55
QgsTextCharacterFormat::strikeOut
BooleanValue strikeOut() const
Returns whether the format has strikethrough enabled.
Definition: qgstextcharacterformat.cpp:45
QgsTextCharacterFormat::setTextColor
void setTextColor(const QColor &textColor)
Sets the character's text color.
Definition: qgstextcharacterformat.cpp:40
QgsTextCharacterFormat::QgsTextCharacterFormat
QgsTextCharacterFormat()=default
Constructor for QgsTextCharacterFormat.