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