00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef QWT_LAYOUT_METRICS_H
00011 #define QWT_LAYOUT_METRICS_H
00012
00013 #include <qsize.h>
00014 #include "qwt_global.h"
00015
00016 class QPainter;
00017 class QRect;
00018 class QPoint;
00019 class QString;
00020 class QFontMetrics;
00021 #if QT_VERSION < 0x040000
00022 class QSimpleRichText;
00023 class QWMatrix;
00024 #else
00025 class QTextDocument;
00026 class QMatrix;
00027 #endif
00028 class QPaintDevice;
00029
00030 class QWT_EXPORT QwtMetricsMap
00031 {
00032 public:
00033 QwtMetricsMap();
00034
00035 bool isIdentity() const;
00036
00037 void setMetrics(const QPaintDevice *layoutMetrics,
00038 const QPaintDevice *deviceMetrics);
00039
00040 int layoutToDeviceX(int x) const;
00041 int deviceToLayoutX(int x) const;
00042 int screenToLayoutX(int x) const;
00043 int layoutToScreenX(int x) const;
00044
00045 int layoutToDeviceY(int y) const;
00046 int deviceToLayoutY(int y) const;
00047 int screenToLayoutY(int y) const;
00048 int layoutToScreenY(int y) const;
00049
00050 QPoint layoutToDevice(const QPoint &, const QPainter * = NULL) const;
00051 QPoint deviceToLayout(const QPoint &, const QPainter * = NULL) const;
00052 QPoint screenToLayout(const QPoint &) const;
00053
00054 QSize layoutToDevice(const QSize &) const;
00055 QSize deviceToLayout(const QSize &) const;
00056 QSize screenToLayout(const QSize &) const;
00057
00058 QRect layoutToDevice(const QRect &, const QPainter * = NULL) const;
00059 QRect deviceToLayout(const QRect &, const QPainter * = NULL) const;
00060 QRect screenToLayout(const QRect &) const;
00061
00062 #if QT_VERSION < 0x040000
00063 QPointArray layoutToDevice(const QPointArray &,
00064 const QPainter * = NULL) const;
00065 QPointArray deviceToLayout(const QPointArray &,
00066 const QPainter * = NULL) const;
00067
00068 static QPointArray translate(const QWMatrix &, const QPointArray &);
00069 static QRect translate(const QWMatrix &, const QRect &);
00070 #else
00071 QPolygon layoutToDevice(const QPolygon &,
00072 const QPainter * = NULL) const;
00073 QPolygon deviceToLayout(const QPolygon &,
00074 const QPainter * = NULL) const;
00075
00076 static QPolygon translate(const QMatrix &, const QPolygon &);
00077 static QRect translate(const QMatrix &, const QRect &);
00078 #endif
00079
00080 private:
00081 double d_screenToLayoutX;
00082 double d_screenToLayoutY;
00083
00084 double d_deviceToLayoutX;
00085 double d_deviceToLayoutY;
00086 };
00087
00088
00089 class QWT_EXPORT QwtLayoutMetrics
00090 {
00091 public:
00092 QwtLayoutMetrics();
00093 QwtLayoutMetrics(const QwtMetricsMap &);
00094
00095 void setMap(const QwtMetricsMap &);
00096
00097 QRect boundingRect(const QString &, int flags, QPainter *) const;
00098 QRect boundingRect(const QString &, int flags, const QFontMetrics &) const;
00099
00100 int heightForWidth(const QString &,
00101 int width, int flags, const QFontMetrics &) const;
00102 int heightForWidth(const QString &,
00103 int width, int flags, QPainter *) const;
00104
00105 #ifndef QT_NO_RICHTEXT
00106 #if QT_VERSION < 0x040000
00107 QRect boundingRect( const QSimpleRichText &,
00108 int flags, QPainter * = NULL) const;
00109 int heightForWidth(QSimpleRichText &, int width) const;
00110 #else
00111 QRect boundingRect(const QString &,
00112 QTextDocument &, int flags) const;
00113 int heightForWidth(QTextDocument &, int width) const;
00114 #endif
00115 #endif
00116
00117 private:
00118 QwtMetricsMap d_map;
00119 };
00120
00121 inline bool QwtMetricsMap::isIdentity() const
00122 {
00123 return d_deviceToLayoutX == 1.0 && d_deviceToLayoutY == 1.0;
00124 }
00125
00126 inline int QwtMetricsMap::layoutToDeviceX(int x) const
00127 {
00128 return qRound(x / d_deviceToLayoutX);
00129 }
00130
00131 inline int QwtMetricsMap::deviceToLayoutX(int x) const
00132 {
00133 return qRound(x * d_deviceToLayoutX);
00134 }
00135
00136 inline int QwtMetricsMap::screenToLayoutX(int x) const
00137 {
00138 return qRound(x * d_screenToLayoutX);
00139 }
00140
00141 inline int QwtMetricsMap::layoutToScreenX(int x) const
00142 {
00143 return qRound(x / d_screenToLayoutX);
00144 }
00145
00146 inline int QwtMetricsMap::layoutToDeviceY(int y) const
00147 {
00148 return qRound(y / d_deviceToLayoutY);
00149 }
00150
00151 inline int QwtMetricsMap::deviceToLayoutY(int y) const
00152 {
00153 return qRound(y * d_deviceToLayoutY);
00154 }
00155
00156 inline int QwtMetricsMap::screenToLayoutY(int y) const
00157 {
00158 return qRound(y * d_screenToLayoutY);
00159 }
00160
00161 inline int QwtMetricsMap::layoutToScreenY(int y) const
00162 {
00163 return qRound(y / d_screenToLayoutY);
00164 }
00165
00166 inline QSize QwtMetricsMap::layoutToDevice(const QSize &size) const
00167 {
00168 return QSize(layoutToDeviceX(size.width()),
00169 layoutToDeviceY(size.height()));
00170 }
00171
00172 inline QSize QwtMetricsMap::deviceToLayout(const QSize &size) const
00173 {
00174 return QSize(deviceToLayoutX(size.width()),
00175 deviceToLayoutY(size.height()));
00176 }
00177
00178 inline QSize QwtMetricsMap::screenToLayout(const QSize &size) const
00179 {
00180 return QSize(screenToLayoutX(size.width()),
00181 screenToLayoutY(size.height()));
00182 }
00183
00184 #endif