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