~ubuntu-branches/ubuntu/oneiric/qwt/oneiric-proposed

« back to all changes in this revision

Viewing changes to qwt-5.0.2/src/qwt_layout_metrics.h

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2007-10-05 15:20:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071005152041-qmybqh4fj9jejyo2
Tags: 5.0.2-2
* Handle nostrip build option. (Closes: #437877)
* Build libqwt5-doc package in binary-indep target. (Closes: #443110)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 
2
 * Qwt Widget Library
 
3
 * Copyright (C) 1997   Josef Wilgen
 
4
 * Copyright (C) 2002   Uwe Rathmann
 
5
 * 
 
6
 * This library is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the Qwt License, Version 1.0
 
8
 *****************************************************************************/
 
9
 
 
10
#ifndef QWT_LAYOUT_METRICS_H
 
11
#define QWT_LAYOUT_METRICS_H
 
12
 
 
13
#include <qsize.h>
 
14
#include <qrect.h>
 
15
#include "qwt_polygon.h"
 
16
#include "qwt_global.h"
 
17
 
 
18
class QPainter;
 
19
class QString;
 
20
class QFontMetrics;
 
21
#if QT_VERSION < 0x040000
 
22
class QWMatrix;
 
23
#else
 
24
class QMatrix;
 
25
#endif
 
26
class QPaintDevice;
 
27
 
 
28
/*!
 
29
  \brief A Map to translate between layout, screen and paint device metrics
 
30
*/
 
31
class QWT_EXPORT QwtMetricsMap
 
32
{
 
33
public:
 
34
    QwtMetricsMap();
 
35
 
 
36
    bool isIdentity() const;
 
37
 
 
38
    void setMetrics(const QPaintDevice *layoutMetrics,
 
39
        const QPaintDevice *deviceMetrics);
 
40
 
 
41
    int layoutToDeviceX(int x) const;
 
42
    int deviceToLayoutX(int x) const;
 
43
    int screenToLayoutX(int x) const;
 
44
    int layoutToScreenX(int x) const;
 
45
 
 
46
    int layoutToDeviceY(int y) const;
 
47
    int deviceToLayoutY(int y) const;
 
48
    int screenToLayoutY(int y) const;
 
49
    int layoutToScreenY(int y) const;
 
50
 
 
51
    QPoint layoutToDevice(const QPoint &, const QPainter * = NULL) const;
 
52
    QPoint deviceToLayout(const QPoint &, const QPainter * = NULL) const;
 
53
    QPoint screenToLayout(const QPoint &) const;
 
54
    QPoint layoutToScreen(const QPoint &point) const;
 
55
 
 
56
 
 
57
    QSize layoutToDevice(const QSize &) const;
 
58
    QSize deviceToLayout(const QSize &) const;
 
59
    QSize screenToLayout(const QSize &) const;
 
60
    QSize layoutToScreen(const QSize &) const;
 
61
 
 
62
    QRect layoutToDevice(const QRect &, const QPainter * = NULL) const;
 
63
    QRect deviceToLayout(const QRect &, const QPainter * = NULL) const;
 
64
    QRect screenToLayout(const QRect &) const;
 
65
    QRect layoutToScreen(const QRect &) const;
 
66
 
 
67
    QwtPolygon layoutToDevice(const QwtPolygon &, 
 
68
        const QPainter * = NULL) const;
 
69
    QwtPolygon deviceToLayout(const QwtPolygon &, 
 
70
        const QPainter * = NULL) const;
 
71
 
 
72
#if QT_VERSION < 0x040000
 
73
    static QwtPolygon translate(const QWMatrix &, const QwtPolygon &);
 
74
    static QRect translate(const QWMatrix &, const QRect &);
 
75
#else
 
76
    static QwtPolygon translate(const QMatrix &, const QwtPolygon &);
 
77
    static QRect translate(const QMatrix &, const QRect &);
 
78
#endif
 
79
 
 
80
private:
 
81
    double d_screenToLayoutX;
 
82
    double d_screenToLayoutY;
 
83
 
 
84
    double d_deviceToLayoutX;
 
85
    double d_deviceToLayoutY;
 
86
};
 
87
 
 
88
inline bool QwtMetricsMap::isIdentity() const
 
89
{
 
90
    return d_deviceToLayoutX == 1.0 && d_deviceToLayoutY == 1.0;
 
91
}
 
92
 
 
93
inline int QwtMetricsMap::layoutToDeviceX(int x) const
 
94
{
 
95
    return qRound(x / d_deviceToLayoutX);
 
96
}
 
97
 
 
98
inline int QwtMetricsMap::deviceToLayoutX(int x) const
 
99
{
 
100
    return qRound(x * d_deviceToLayoutX);
 
101
}
 
102
 
 
103
inline int QwtMetricsMap::screenToLayoutX(int x) const
 
104
{
 
105
    return qRound(x * d_screenToLayoutX);
 
106
}
 
107
 
 
108
inline int QwtMetricsMap::layoutToScreenX(int x) const
 
109
{
 
110
    return qRound(x / d_screenToLayoutX);
 
111
}
 
112
 
 
113
inline int QwtMetricsMap::layoutToDeviceY(int y) const
 
114
{
 
115
    return qRound(y / d_deviceToLayoutY);
 
116
}
 
117
 
 
118
inline int QwtMetricsMap::deviceToLayoutY(int y) const
 
119
{
 
120
    return qRound(y * d_deviceToLayoutY);
 
121
}
 
122
 
 
123
inline int QwtMetricsMap::screenToLayoutY(int y) const
 
124
{
 
125
    return qRound(y * d_screenToLayoutY);
 
126
}
 
127
 
 
128
inline int QwtMetricsMap::layoutToScreenY(int y) const
 
129
{
 
130
    return qRound(y / d_screenToLayoutY);
 
131
}
 
132
 
 
133
inline QSize QwtMetricsMap::layoutToDevice(const QSize &size) const
 
134
{
 
135
    return QSize(layoutToDeviceX(size.width()), 
 
136
        layoutToDeviceY(size.height()));
 
137
}
 
138
 
 
139
inline QSize QwtMetricsMap::deviceToLayout(const QSize &size) const
 
140
{
 
141
    return QSize(deviceToLayoutX(size.width()), 
 
142
        deviceToLayoutY(size.height()));
 
143
}
 
144
 
 
145
inline QSize QwtMetricsMap::screenToLayout(const QSize &size) const
 
146
{
 
147
    return QSize(screenToLayoutX(size.width()), 
 
148
        screenToLayoutY(size.height()));
 
149
}
 
150
 
 
151
inline QSize QwtMetricsMap::layoutToScreen(const QSize &size) const
 
152
{
 
153
    return QSize(layoutToScreenX(size.width()), 
 
154
        layoutToScreenY(size.height()));
 
155
}
 
156
 
 
157
#endif