QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 
75 void QgsTextCharacterFormat::updateFontForFormat( QFont &font, const double scaleFactor ) const
76 {
77  Q_UNUSED( scaleFactor );
78 #if 0 // settings which affect font metrics are disabled for now
80  font.setItalic( mItalic == QgsTextCharacterFormat::BooleanValue::SetTrue );
81  if ( mFontWeight != -1 )
82  font.setWeight( mFontWeight );
83  if ( !mFontFamily.isEmpty() )
84  font.setFamily( mFontFamily );
85  if ( mFontPointSize != -1 )
86  font.setPointSizeF( mFontPointSize );
87 #endif
88 
89  if ( mUnderline != BooleanValue::NotSet )
90  font.setUnderline( mUnderline == QgsTextCharacterFormat::BooleanValue::SetTrue );
91  if ( mOverline != BooleanValue::NotSet )
92  font.setOverline( mOverline == QgsTextCharacterFormat::BooleanValue::SetTrue );
93  if ( mStrikethrough != QgsTextCharacterFormat::BooleanValue::NotSet )
94  font.setStrikeOut( mStrikethrough == QgsTextCharacterFormat::BooleanValue::SetTrue );
95 }
96 
97 #if 0 // settings which affect font metrics are disabled for now
98 QgsTextCharacterFormat::BooleanValue QgsTextCharacterFormat::italic() const
99 {
100  return mItalic;
101 }
102 
103 void QgsTextCharacterFormat::setItalic( QgsTextCharacterFormat::BooleanValue enabled )
104 {
105  mItalic = enabled;
106 }
107 
108 int QgsTextCharacterFormat::fontWeight() const
109 {
110  return mFontWeight;
111 }
112 
113 void QgsTextCharacterFormat::setFontWeight( int fontWeight )
114 {
115  mFontWeight = fontWeight;
116 }
117 #endif
QColor textColor() const
Returns the character's text color, or an invalid color if no color override is set and the default f...
QgsTextCharacterFormat()=default
Constructor for QgsTextCharacterFormat.
void setStrikeOut(BooleanValue enabled)
Sets whether the format has strikethrough enabled.
void setOverline(BooleanValue enabled)
Sets whether the format has overline enabled.
BooleanValue
Status values for boolean format properties.
@ SetTrue
Property is set and true.
BooleanValue strikeOut() const
Returns whether the format has strikethrough enabled.
BooleanValue underline() const
Returns whether the format has underline enabled.
void setTextColor(const QColor &textColor)
Sets the character's text color.
void setUnderline(BooleanValue enabled)
Sets whether the format has underline enabled.
BooleanValue overline() const
Returns whether the format has overline enabled.
void updateFontForFormat(QFont &font, double scaleFactor=1.0) const
Updates the specified font in place, applying character formatting options which are applicable on a ...