~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to kchart/kdchart/src/KDChartMeasure.h

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-27 17:52:57 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101027175257-s04zqqk5bs8ckm9o
Tags: 1:2.2.83-0ubuntu1
* Merge with Debian git remaining changes:
 - Add build-deps on librcps-dev, opengtl-dev, libqtgtl-dev, freetds-dev,
   create-resources, libspnav-dev
 - Remove needless build-dep on libwv2-dev
 - koffice-libs recommends create-resources
 - krita recommends pstoedit
 - Keep our patches
* New upstream release 2.3 beta 3
  - Remove debian/patches fixed by upstream
  - Update install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C++ -*-
2
 
   KDChart - a multi-platform charting engine
3
 
   */
4
 
 
5
 
/****************************************************************************
6
 
 ** Copyright (C) 2005-2007 Klarälvdalens Datakonsult AB.  All rights reserved.
7
 
 **
8
 
 ** This file is part of the KD Chart library.
9
 
 **
10
 
 ** This file may be used under the terms of the GNU General Public
11
 
 ** License versions 2.0 or 3.0 as published by the Free Software
12
 
 ** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
13
 
 ** included in the packaging of this file.  Alternatively you may (at
14
 
 ** your option) use any later version of the GNU General Public
15
 
 ** License if such license has been publicly approved by
16
 
 ** Klarälvdalens Datakonsult AB (or its successors, if any).
17
 
 ** 
18
 
 ** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
19
 
 ** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
20
 
 ** A PARTICULAR PURPOSE. Klarälvdalens Datakonsult AB reserves all rights
21
 
 ** not expressly granted herein.
22
 
 ** 
23
 
 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
24
 
 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
25
 
 **
26
 
 **********************************************************************/
27
 
 
28
 
#ifndef KDCHARTMEASURE_H
29
 
#define KDCHARTMEASURE_H
30
 
 
31
 
#include <QDebug>
32
 
#include <Qt>
33
 
#include <QStack>
34
 
#include "KDChartGlobal.h"
35
 
#include "KDChartEnums.h"
36
 
 
37
 
/** \file KDChartMeasure.h
38
 
 *  \brief Declaring the class KDChart::Measure.
39
 
 *
40
 
 *
41
 
 */
42
 
 
43
 
 
44
 
class QObject;
45
 
class QPaintDevice;
46
 
 
47
 
namespace KDChart {
48
 
 
49
 
/**
50
 
  * \class Measure KDChartMeasure.h KDChartMeasure
51
 
  * \brief  Measure is used to specify all relative and/or absolute measures in KDChart, e.g. font sizes.
52
 
  *
53
 
  */
54
 
 
55
 
class KDCHART_EXPORT Measure
56
 
{
57
 
public:
58
 
    Measure();
59
 
    /*implicit*/ Measure( qreal value,
60
 
                          KDChartEnums::MeasureCalculationMode mode = KDChartEnums::MeasureCalculationModeAuto,
61
 
                          KDChartEnums::MeasureOrientation orientation = KDChartEnums::MeasureOrientationAuto );
62
 
    Measure( const Measure& );
63
 
    Measure &operator= ( const Measure& );
64
 
 
65
 
    void setValue( qreal val ){ mValue = val; }
66
 
    qreal value() const { return mValue; }
67
 
 
68
 
    void setCalculationMode( KDChartEnums::MeasureCalculationMode mode ){ mMode = mode; }
69
 
    KDChartEnums::MeasureCalculationMode calculationMode() const { return mMode; }
70
 
 
71
 
    /**
72
 
      * The reference area must either be derived from AbstractArea
73
 
      * or be derived from QWidget, so e.g. it could be derived from
74
 
      * AbstractAreaWidget too.
75
 
      */
76
 
    void setRelativeMode( const QObject * area,
77
 
                          KDChartEnums::MeasureOrientation orientation )
78
 
    {
79
 
        mMode = KDChartEnums::MeasureCalculationModeRelative;
80
 
        mArea = area;
81
 
        mOrientation = orientation;
82
 
    }
83
 
 
84
 
    /**
85
 
     * \brief This is a convenience method for specifying a value,
86
 
     * with implicitely setting the calculation mode to MeasureCalculationModeAbsolute
87
 
     *
88
 
     * Calling setAbsoluteValue( value ) is the same as calling
89
 
\verbatim
90
 
    setValue( value );
91
 
    setCalculationMode( KDChartEnums::MeasureCalculationModeAbsolute );
92
 
\endverbatim
93
 
     */
94
 
    void setAbsoluteValue( qreal val )
95
 
    {
96
 
        mMode = KDChartEnums::MeasureCalculationModeAbsolute;
97
 
        mValue = val;
98
 
    }
99
 
 
100
 
    /**
101
 
      * The reference area must either be derived from AbstractArea
102
 
      * or be derived from QWidget, so e.g. it could be derived from
103
 
      * AbstractAreaWidget too.
104
 
      */
105
 
    void setReferenceArea( const QObject * area ){ mArea = area; }
106
 
    /**
107
 
      * The returned reference area will either be derived from AbstractArea
108
 
      * or be derived from QWidget.
109
 
      */
110
 
    const QObject * referenceArea() const { return mArea; }
111
 
 
112
 
    void setReferenceOrientation( KDChartEnums::MeasureOrientation orientation ){ mOrientation = orientation; }
113
 
    KDChartEnums::MeasureOrientation referenceOrientation() const { return mOrientation; }
114
 
 
115
 
    /**
116
 
      * The reference area must either be derived from AbstractArea
117
 
      * or be derived from QWidget, so e.g. it could be derived from
118
 
      * AbstractAreaWidget too.
119
 
      */
120
 
    qreal calculatedValue( const QObject * autoArea, KDChartEnums::MeasureOrientation autoOrientation ) const;
121
 
    qreal calculatedValue( const QSizeF& autoSize, KDChartEnums::MeasureOrientation autoOrientation ) const;
122
 
    const QSizeF sizeOfArea( const QObject* area ) const;
123
 
 
124
 
    bool operator==( const Measure& ) const;
125
 
    bool operator!=( const Measure& other ) const { return !operator==(other); }
126
 
 
127
 
private:
128
 
    qreal mValue;
129
 
    KDChartEnums::MeasureCalculationMode mMode;
130
 
    const QObject* mArea;
131
 
    KDChartEnums::MeasureOrientation mOrientation;
132
 
}; // End of class Measure
133
 
 
134
 
 
135
 
 
136
 
/**
137
 
 * Auxiliary class used by the KDChart::Measure and KDChart::Chart class.
138
 
 *
139
 
 * Normally there should be no need to call any of these methods yourself.
140
 
 * 
141
 
 * They are used by KDChart::Chart::paint( QPainter*, const QRect& )
142
 
 * to adjust all of the relative Measures according to the target
143
 
 * rectangle's size.
144
 
 *
145
 
 * Default factors are (1.0, 1.0)
146
 
 */
147
 
class GlobalMeasureScaling
148
 
{
149
 
public:
150
 
    static GlobalMeasureScaling* instance();
151
 
 
152
 
    GlobalMeasureScaling();
153
 
    virtual ~GlobalMeasureScaling();
154
 
 
155
 
public:
156
 
    /**
157
 
     * Set new factors to be used by all Measure objects from now on.
158
 
     * Previous values will be stored.
159
 
     */
160
 
    static void setFactors(qreal factorX, qreal factorY);
161
 
 
162
 
    /**
163
 
     * Reset factors to the values active before the previous call of
164
 
     * setFactors.
165
 
     * This works on a stack, so recursive calls works fine, like:
166
 
     * setFactors, setFactors, unserFactors, unsetFactors
167
 
     */
168
 
    static void resetFactors();
169
 
 
170
 
    /**
171
 
     * Returns the currently active factors.
172
 
     */
173
 
    static const QPair< qreal, qreal > currentFactors();
174
 
 
175
 
    /**
176
 
     * Sets the paint device usable for calculating fort metrics.
177
 
     */
178
 
    static void setPaintDevice( QPaintDevice* paintDevice );
179
 
 
180
 
    /**
181
 
     * Returns the paint device usable for calculating fort metrics.
182
 
     */
183
 
    static QPaintDevice* paintDevice();
184
 
 
185
 
private:
186
 
    QStack< QPair< qreal, qreal > > mFactors;
187
 
    QPaintDevice* m_paintDevice;
188
 
};
189
 
 
190
 
}
191
 
 
192
 
#if !defined(QT_NO_DEBUG_STREAM)
193
 
KDCHART_EXPORT QDebug operator<<(QDebug, const KDChart::Measure& );
194
 
#endif /* QT_NO_DEBUG_STREAM */
195
 
 
196
 
#endif // KDCHARTMEASURE_H