File indexing completed on 2024-05-12 15:54:18
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 KCHARTMEASURE_H 0021 #define KCHARTMEASURE_H 0022 0023 #include <QDebug> 0024 #include <Qt> 0025 #include <QStack> 0026 #include "KChartGlobal.h" 0027 #include "KChartEnums.h" 0028 0029 /** \file KChartMeasure.h 0030 * \brief Declaring the class KChart::Measure. 0031 * 0032 * 0033 */ 0034 0035 QT_BEGIN_NAMESPACE 0036 class QObject; 0037 class QPaintDevice; 0038 QT_END_NAMESPACE 0039 0040 namespace KChart { 0041 0042 /** 0043 * \class Measure KChartMeasure.h KChartMeasure 0044 * \brief Measure is used to specify relative and absolute sizes in KChart, e.g. font sizes. 0045 * 0046 */ 0047 0048 class KCHART_EXPORT Measure 0049 { 0050 public: 0051 Measure(); 0052 /*implicit*/ Measure( qreal value, 0053 KChartEnums::MeasureCalculationMode mode = KChartEnums::MeasureCalculationModeAuto, 0054 KChartEnums::MeasureOrientation orientation = KChartEnums::MeasureOrientationAuto ); 0055 Measure( const Measure& ); 0056 Measure &operator= ( const Measure& ); 0057 0058 void setValue( qreal val ) { mValue = val; } 0059 qreal value() const { return mValue; } 0060 0061 void setCalculationMode( KChartEnums::MeasureCalculationMode mode ) { mMode = mode; } 0062 KChartEnums::MeasureCalculationMode calculationMode() const { return mMode; } 0063 0064 /** 0065 * The reference area must either be derived from AbstractArea 0066 * or from QWidget, so it can also be derived from AbstractAreaWidget. 0067 */ 0068 void setRelativeMode( const QObject * area, 0069 KChartEnums::MeasureOrientation orientation ) 0070 { 0071 mMode = KChartEnums::MeasureCalculationModeRelative; 0072 mArea = area; 0073 mOrientation = orientation; 0074 } 0075 0076 /** 0077 * \brief This is a convenience method for specifying a value, 0078 * implicitly setting the calculation mode to MeasureCalculationModeAbsolute. 0079 * 0080 * Calling setAbsoluteValue( value ) is the same as calling 0081 \verbatim 0082 setValue( value ); 0083 setCalculationMode( KChartEnums::MeasureCalculationModeAbsolute ); 0084 \endverbatim 0085 */ 0086 void setAbsoluteValue( qreal val ) 0087 { 0088 mMode = KChartEnums::MeasureCalculationModeAbsolute; 0089 mValue = val; 0090 } 0091 0092 /** 0093 * The reference area must either be derived from AbstractArea 0094 * or from QWidget, so it can also be derived from AbstractAreaWidget. 0095 */ 0096 void setReferenceArea( const QObject * area ) { mArea = area; } 0097 /** 0098 * The returned reference area will be derived from AbstractArea 0099 * or QWidget or both. 0100 */ 0101 const QObject * referenceArea() const { return mArea; } 0102 0103 void setReferenceOrientation( KChartEnums::MeasureOrientation orientation ) { mOrientation = orientation; } 0104 KChartEnums::MeasureOrientation referenceOrientation() const { return mOrientation; } 0105 0106 /** 0107 * The reference area must either be derived from AbstractArea 0108 * or from QWidget, so it can also be derived from AbstractAreaWidget. 0109 */ 0110 qreal calculatedValue( const QObject * autoArea, KChartEnums::MeasureOrientation autoOrientation ) const; 0111 qreal calculatedValue( const QSizeF& autoSize, KChartEnums::MeasureOrientation autoOrientation ) const; 0112 const QSizeF sizeOfArea( const QObject* area ) const; 0113 0114 bool operator==( const Measure& ) const; 0115 bool operator!=( const Measure& other ) const { return !operator==(other); } 0116 0117 private: 0118 qreal mValue; 0119 KChartEnums::MeasureCalculationMode mMode; 0120 const QObject* mArea; 0121 KChartEnums::MeasureOrientation mOrientation; 0122 }; // End of class Measure 0123 0124 0125 0126 /** 0127 * Auxiliary class used by the KChart::Measure and KChart::Chart class. 0128 * 0129 * Normally there should be no need to call any of these methods yourself. 0130 * 0131 * They are used by KChart::Chart::paint( QPainter*, const QRect& ) 0132 * to adjust all of the relative Measures according to the target 0133 * rectangle's size. 0134 * 0135 * Default factors are (1.0, 1.0) 0136 */ 0137 class GlobalMeasureScaling 0138 { 0139 public: 0140 static GlobalMeasureScaling* instance(); 0141 0142 GlobalMeasureScaling(); 0143 virtual ~GlobalMeasureScaling(); 0144 0145 public: 0146 /** 0147 * Set new factors to be used by all Measure objects from now on. 0148 * Previous values will be saved on a stack internally. 0149 */ 0150 static void setFactors(qreal factorX, qreal factorY); 0151 0152 /** 0153 * Restore factors to the values before the previous call to 0154 * setFactors. The current values are popped off a stack internally. 0155 */ 0156 static void resetFactors(); 0157 0158 /** 0159 * Return the currently active factors. 0160 */ 0161 static const QPair< qreal, qreal > currentFactors(); 0162 0163 /** 0164 * Set the paint device to use for calculating font metrics. 0165 */ 0166 static void setPaintDevice( QPaintDevice* paintDevice ); 0167 0168 /** 0169 * Return the paint device to use for calculating font metrics. 0170 */ 0171 static QPaintDevice* paintDevice(); 0172 0173 private: 0174 QStack< QPair< qreal, qreal > > mFactors; 0175 QPaintDevice* m_paintDevice; 0176 }; 0177 0178 } 0179 0180 #if !defined(QT_NO_DEBUG_STREAM) 0181 KCHART_EXPORT QDebug operator<<(QDebug, const KChart::Measure& ); 0182 #endif /* QT_NO_DEBUG_STREAM */ 0183 0184 #endif // KCHARTMEASURE_H