1
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
3
* Copyright (C) 1997 Josef Wilgen
4
* Copyright (C) 2002 Uwe Rathmann
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
*****************************************************************************/
10
#ifndef QWT_LAYOUT_METRICS_H
11
#define QWT_LAYOUT_METRICS_H
15
#include "qwt_polygon.h"
16
#include "qwt_global.h"
21
#if QT_VERSION < 0x040000
29
\brief A Map to translate between layout, screen and paint device metrics
31
class QWT_EXPORT QwtMetricsMap
36
bool isIdentity() const;
38
void setMetrics(const QPaintDevice *layoutMetrics,
39
const QPaintDevice *deviceMetrics);
41
int layoutToDeviceX(int x) const;
42
int deviceToLayoutX(int x) const;
43
int screenToLayoutX(int x) const;
44
int layoutToScreenX(int x) const;
46
int layoutToDeviceY(int y) const;
47
int deviceToLayoutY(int y) const;
48
int screenToLayoutY(int y) const;
49
int layoutToScreenY(int y) const;
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;
57
QSize layoutToDevice(const QSize &) const;
58
QSize deviceToLayout(const QSize &) const;
59
QSize screenToLayout(const QSize &) const;
60
QSize layoutToScreen(const QSize &) const;
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;
67
QwtPolygon layoutToDevice(const QwtPolygon &,
68
const QPainter * = NULL) const;
69
QwtPolygon deviceToLayout(const QwtPolygon &,
70
const QPainter * = NULL) const;
72
#if QT_VERSION < 0x040000
73
static QwtPolygon translate(const QWMatrix &, const QwtPolygon &);
74
static QRect translate(const QWMatrix &, const QRect &);
76
static QwtPolygon translate(const QMatrix &, const QwtPolygon &);
77
static QRect translate(const QMatrix &, const QRect &);
81
double d_screenToLayoutX;
82
double d_screenToLayoutY;
84
double d_deviceToLayoutX;
85
double d_deviceToLayoutY;
88
inline bool QwtMetricsMap::isIdentity() const
90
return d_deviceToLayoutX == 1.0 && d_deviceToLayoutY == 1.0;
93
inline int QwtMetricsMap::layoutToDeviceX(int x) const
95
return qRound(x / d_deviceToLayoutX);
98
inline int QwtMetricsMap::deviceToLayoutX(int x) const
100
return qRound(x * d_deviceToLayoutX);
103
inline int QwtMetricsMap::screenToLayoutX(int x) const
105
return qRound(x * d_screenToLayoutX);
108
inline int QwtMetricsMap::layoutToScreenX(int x) const
110
return qRound(x / d_screenToLayoutX);
113
inline int QwtMetricsMap::layoutToDeviceY(int y) const
115
return qRound(y / d_deviceToLayoutY);
118
inline int QwtMetricsMap::deviceToLayoutY(int y) const
120
return qRound(y * d_deviceToLayoutY);
123
inline int QwtMetricsMap::screenToLayoutY(int y) const
125
return qRound(y * d_screenToLayoutY);
128
inline int QwtMetricsMap::layoutToScreenY(int y) const
130
return qRound(y / d_screenToLayoutY);
133
inline QSize QwtMetricsMap::layoutToDevice(const QSize &size) const
135
return QSize(layoutToDeviceX(size.width()),
136
layoutToDeviceY(size.height()));
139
inline QSize QwtMetricsMap::deviceToLayout(const QSize &size) const
141
return QSize(deviceToLayoutX(size.width()),
142
deviceToLayoutY(size.height()));
145
inline QSize QwtMetricsMap::screenToLayout(const QSize &size) const
147
return QSize(screenToLayoutX(size.width()),
148
screenToLayoutY(size.height()));
151
inline QSize QwtMetricsMap::layoutToScreen(const QSize &size) const
153
return QSize(layoutToScreenX(size.width()),
154
layoutToScreenY(size.height()));