KChart

KChartTextAttributes.h
1 /*
2  * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3  *
4  * This file is part of the KD Chart library.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef KCHARTTEXTATTRIBUTES_H
21 #define KCHARTTEXTATTRIBUTES_H
22 
23 #include <QDebug>
24 #include <QMetaType>
25 #include "KChartGlobal.h"
26 #include "KChartMeasure.h"
27 
28 QT_BEGIN_NAMESPACE
29 class QPen;
30 class QFont;
31 class QTextDocument;
32 QT_END_NAMESPACE
33 
34 namespace KChart {
35 
36  /**
37  * \brief A set of text attributes.
38  *
39  * TextAttributes encapsulates settings that have to do with
40  * text. This includes font, fontsize, color, whether the text
41  * is rotated, etc
42  */
43 class KCHART_EXPORT TextAttributes
44 {
45 public:
48  TextAttributes &operator= ( const TextAttributes& );
49  bool operator==( const TextAttributes& ) const;
50  inline bool operator!=( const TextAttributes& other ) const
51  { return !operator==(other); }
52 
53  ~TextAttributes();
54 
55  /**
56  * Set whether the text is to be rendered at all.
57  * \param visible Whether the text is visible.
58  */
59  void setVisible( bool visible );
60 
61  /**
62  * \return Whether the text is visible.
63  */
64  bool isVisible() const;
65 
66  /**
67  * Set the font to be used for rendering the text.
68  *
69  * \note All of the font's attributes will be used - except of its size!
70  * To specify the size please use setFontSize (or setMinimalFontSize, resp.)
71  *
72  * \param font The font to use.
73  *
74  * \sa setFontSize, setMinimalFontSize
75  */
76  void setFont( const QFont& font );
77 
78  /**
79  * \return The font that is used for rendering text.
80  */
81  QFont font() const;
82 
83  /**
84  * Set the size of the font used for rendering text.
85  * \param measure The measure to use.
86  * \see Measure
87  */
88  void setFontSize( const Measure & measure );
89 
90  /**
91  * \return The measure used for the font size.
92  */
93  Measure fontSize() const;
94 
95  /**
96  * Set the minimal size of the font used for rendering text.
97  * \param measure The measure to use.
98  * \see Measure
99  */
100  void setMinimalFontSize( const Measure & measure );
101 
102  /**
103  * \return The measure used for the minimal font size.
104  */
105  Measure minimalFontSize() const;
106 
107  /**
108  * \brief Returns the font size that is used at drawing time.
109  *
110  * This method is called at drawing time. It returns the
111  * font size as it is used for rendering text, taking into account
112  * any measures that were set via setFontSize and/or setMinimalFontSize.
113  */
114  qreal calculatedFontSize( const QSizeF &referenceSize,
115  KChartEnums::MeasureOrientation autoReferenceOrientation ) const;
116 
117  /**
118  * \brief Returns the font size that is used at drawing time.
119  *
120  * This method is called at drawing time. It returns the
121  * font size as it is used for rendering text, taking into account
122  * any measures that were set via setFontSize and/or setMinimalFontSize.
123  */
124 #if defined(Q_COMPILER_MANGLES_RETURN_TYPE)
125  const qreal calculatedFontSize(
126 #else
127  qreal calculatedFontSize(
128 #endif
129  const QObject* autoReferenceArea,
130  KChartEnums::MeasureOrientation autoReferenceOrientation ) const;
131 
132  /**
133  * \brief Returns the font in the size that is used at drawing time.
134  *
135  * This method is called at drawing time. It returns the
136  * font as it is used for rendering text, taking into account
137  * any measures that were set via setFontSize and/or setMinimalFontSize.
138  */
139  const QFont calculatedFont(
140  const QObject* autoReferenceArea,
141  KChartEnums::MeasureOrientation autoReferenceOrientation ) const;
142 
143  /**
144  * \return Whether the text has an absolute font size set.
145  */
146  bool hasAbsoluteFontSize() const;
147 
148  /**
149  * Set whether the text should be automatically rotated as
150  * needed when space is tight.
151  * \param autoRotate Whether text should be automatically rotated.
152  */
153  void setAutoRotate( bool autoRotate );
154 
155  /**
156  * \return Whether text is automatically rotated when space is
157  * tight.
158  */
159  bool autoRotate() const;
160 
161  /**
162  * Set whether the text should automatically be shrunk if
163  * space is tight.
164  * \param autoShrink Whether text should be auto-shrunk.
165  */
166  void setAutoShrink( bool autoShrink );
167 
168  /**
169  * \return Whether text is automatically shrunk if space is
170  * tight.
171  */
172  bool autoShrink() const;
173 
174  /**
175  * Set the rotation angle to use for the text.
176  *
177  * \note For axis titles the rotation angle can be set to one of the
178  * following angles: 0, 90, 180, 270
179  * Any other values specified will be replaced by the next smaller
180  * one of the allowed values, so no matter what you set the rotation
181  * will always be one of these four values.
182  *
183  * \param rotation The rotation angle.
184  */
185  void setRotation( int rotation );
186  void resetRotation();
187  bool hasRotation() const;
188 
189  /**
190  * \return The rotation angle used for rendering the text.
191  */
192  int rotation() const;
193 
194  /**
195  * Set the pen to use for rendering the text.
196  * \param pen The pen to use.
197  */
198  void setPen( const QPen& pen );
199 
200  /**
201  * \return The pen used for rendering the text.
202  */
203  QPen pen() const;
204 
205  /**
206  * \return The document used for the drawing the text or NULL if the
207  * default document is used.
208  */
209  QTextDocument* textDocument() const;
210 
211  /**
212  * Sets the document to use for the text. The previous document is deleted.
213  */
214  void setTextDocument(QTextDocument* layout);
215 
216  // FIXME KChartEnums::TextLayoutPolicy?
217 
218 private:
219  KCHART_DECLARE_PRIVATE_BASE_VALUE( TextAttributes )
220 
221 }; // End of class TextAttributes
222 
223 }
224 
225 #if !defined(QT_NO_DEBUG_STREAM)
226 KCHART_EXPORT QDebug operator<<(QDebug, const KChart::TextAttributes& );
227 #endif /* QT_NO_DEBUG_STREAM */
228 
229 KCHART_DECLARE_SWAP_SPECIALISATION( KChart::TextAttributes )
230 
231 QT_BEGIN_NAMESPACE
232 Q_DECLARE_TYPEINFO( KChart::TextAttributes, Q_MOVABLE_TYPE );
233 QT_END_NAMESPACE
234 Q_DECLARE_METATYPE( KChart::TextAttributes )
235 
236 #endif // KCHARTTEXTATTRIBUTES_H
Declaring the class KChart::Measure.
Class only listed here to document inheritance of some KChart classes.
Contains KChart macros.
MeasureOrientation
Measure orientation mode: the way how the absolute value of a KChart::Measure is determined during KC...
Definition: KChartEnums.h:293
QDataStream & operator<<(QDataStream &out, const KDateTime::Spec &spec)
Class only listed here to document inheritance of some KChart classes.
A set of text attributes.
Global namespace.
Measure is used to specify relative and absolute sizes in KChart, e.g.
Definition: KChartMeasure.h:48
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Mar 2 2021 23:33:14 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.