File indexing completed on 2024-05-12 04:20:37
0001 /* 0002 * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved. 0003 * 0004 * This file is part of the KD Chart library. 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef KCHARTTEXTATTRIBUTES_H 0010 #define KCHARTTEXTATTRIBUTES_H 0011 0012 #include <QDebug> 0013 #include <QMetaType> 0014 #include "KChartGlobal.h" 0015 #include "KChartMeasure.h" 0016 0017 QT_BEGIN_NAMESPACE 0018 class QPen; 0019 class QFont; 0020 class QTextDocument; 0021 QT_END_NAMESPACE 0022 0023 namespace KChart { 0024 0025 /** 0026 * \brief A set of text attributes. 0027 * 0028 * TextAttributes encapsulates settings that have to do with 0029 * text. This includes font, fontsize, color, whether the text 0030 * is rotated, etc 0031 */ 0032 class KCHART_EXPORT TextAttributes 0033 { 0034 public: 0035 TextAttributes(); 0036 TextAttributes( const TextAttributes& ); 0037 TextAttributes &operator= ( const TextAttributes& ); 0038 bool operator==( const TextAttributes& ) const; 0039 inline bool operator!=( const TextAttributes& other ) const 0040 { return !operator==(other); } 0041 0042 ~TextAttributes(); 0043 0044 /** 0045 * Set whether the text is to be rendered at all. 0046 * \param visible Whether the text is visible. 0047 */ 0048 void setVisible( bool visible ); 0049 0050 /** 0051 * \return Whether the text is visible. 0052 */ 0053 bool isVisible() const; 0054 0055 /** 0056 * Set the font to be used for rendering the text. 0057 * 0058 * \note All of the font's attributes will be used - except of its size! 0059 * To specify the size please use setFontSize (or setMinimalFontSize, resp.) 0060 * 0061 * \param font The font to use. 0062 * 0063 * \sa setFontSize, setMinimalFontSize 0064 */ 0065 void setFont( const QFont& font ); 0066 0067 /** 0068 * \return The font that is used for rendering text. 0069 */ 0070 QFont font() const; 0071 0072 /** 0073 * Set the size of the font used for rendering text. 0074 * \param measure The measure to use. 0075 * \see Measure 0076 */ 0077 void setFontSize( const Measure & measure ); 0078 0079 /** 0080 * \return The measure used for the font size. 0081 */ 0082 Measure fontSize() const; 0083 0084 /** 0085 * Set the minimal size of the font used for rendering text. 0086 * \param measure The measure to use. 0087 * \see Measure 0088 */ 0089 void setMinimalFontSize( const Measure & measure ); 0090 0091 /** 0092 * \return The measure used for the minimal font size. 0093 */ 0094 Measure minimalFontSize() const; 0095 0096 /** 0097 * \brief Returns the font size that is used at drawing time. 0098 * 0099 * This method is called at drawing time. It returns the 0100 * font size as it is used for rendering text, taking into account 0101 * any measures that were set via setFontSize and/or setMinimalFontSize. 0102 */ 0103 qreal calculatedFontSize( const QSizeF &referenceSize, 0104 KChartEnums::MeasureOrientation autoReferenceOrientation ) const; 0105 0106 /** 0107 * \brief Returns the font size that is used at drawing time. 0108 * 0109 * This method is called at drawing time. It returns the 0110 * font size as it is used for rendering text, taking into account 0111 * any measures that were set via setFontSize and/or setMinimalFontSize. 0112 */ 0113 #if defined(Q_COMPILER_MANGLES_RETURN_TYPE) 0114 const qreal calculatedFontSize( 0115 #else 0116 qreal calculatedFontSize( 0117 #endif 0118 const QObject* autoReferenceArea, 0119 KChartEnums::MeasureOrientation autoReferenceOrientation ) const; 0120 0121 /** 0122 * \brief Returns the font in the size that is used at drawing time. 0123 * 0124 * This method is called at drawing time. It returns the 0125 * font as it is used for rendering text, taking into account 0126 * any measures that were set via setFontSize and/or setMinimalFontSize. 0127 */ 0128 const QFont calculatedFont( 0129 const QObject* autoReferenceArea, 0130 KChartEnums::MeasureOrientation autoReferenceOrientation ) const; 0131 0132 /** 0133 * \return Whether the text has an absolute font size set. 0134 */ 0135 bool hasAbsoluteFontSize() const; 0136 0137 /** 0138 * Set whether the text should be automatically rotated as 0139 * needed when space is tight. 0140 * \param autoRotate Whether text should be automatically rotated. 0141 */ 0142 void setAutoRotate( bool autoRotate ); 0143 0144 /** 0145 * \return Whether text is automatically rotated when space is 0146 * tight. 0147 */ 0148 bool autoRotate() const; 0149 0150 /** 0151 * Set whether the text should automatically be shrunk if 0152 * space is tight. 0153 * \param autoShrink Whether text should be auto-shrunk. 0154 */ 0155 void setAutoShrink( bool autoShrink ); 0156 0157 /** 0158 * \return Whether text is automatically shrunk if space is 0159 * tight. 0160 */ 0161 bool autoShrink() const; 0162 0163 /** 0164 * Set the rotation angle to use for the text. 0165 * 0166 * \note For axis titles the rotation angle can be set to one of the 0167 * following angles: 0, 90, 180, 270 0168 * Any other values specified will be replaced by the next smaller 0169 * one of the allowed values, so no matter what you set the rotation 0170 * will always be one of these four values. 0171 * 0172 * \param rotation The rotation angle. 0173 */ 0174 void setRotation( int rotation ); 0175 void resetRotation(); 0176 bool hasRotation() const; 0177 0178 /** 0179 * \return The rotation angle used for rendering the text. 0180 */ 0181 int rotation() const; 0182 0183 /** 0184 * Set the pen to use for rendering the text. 0185 * \param pen The pen to use. 0186 */ 0187 void setPen( const QPen& pen ); 0188 0189 /** 0190 * \return The pen used for rendering the text. 0191 */ 0192 QPen pen() const; 0193 0194 /** 0195 * \return The document used for the drawing the text or NULL if the 0196 * default document is used. 0197 */ 0198 QTextDocument* textDocument() const; 0199 0200 /** 0201 * Sets the document to use for the text. The previous document is deleted. 0202 */ 0203 void setTextDocument(QTextDocument* layout); 0204 0205 // FIXME KChartEnums::TextLayoutPolicy? 0206 0207 private: 0208 KCHART_DECLARE_PRIVATE_BASE_VALUE( TextAttributes ) 0209 0210 }; // End of class TextAttributes 0211 0212 } 0213 0214 #if !defined(QT_NO_DEBUG_STREAM) 0215 KCHART_EXPORT QDebug operator<<(QDebug, const KChart::TextAttributes& ); 0216 #endif /* QT_NO_DEBUG_STREAM */ 0217 0218 KCHART_DECLARE_SWAP_SPECIALISATION( KChart::TextAttributes ) 0219 0220 QT_BEGIN_NAMESPACE 0221 Q_DECLARE_TYPEINFO( KChart::TextAttributes, Q_MOVABLE_TYPE ); 0222 QT_END_NAMESPACE 0223 Q_DECLARE_METATYPE( KChart::TextAttributes ) 0224 0225 #endif // KCHARTTEXTATTRIBUTES_H