Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

qwt_layout_metrics.h

00001 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
00002  * Qwt Widget Library
00003  * Copyright (C) 1997   Josef Wilgen
00004  * Copyright (C) 2002   Uwe Rathmann
00005  * 
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the Qwt License, Version 1.0
00008  *****************************************************************************/
00009 
00010 #ifndef QWT_LAYOUT_METRICS_H
00011 #define QWT_LAYOUT_METRICS_H
00012 
00013 #include <qsize.h>
00014 #include <qrect.h>
00015 #if QT_VERSION < 0x040000
00016 #include <qpointarray.h>
00017 #else
00018 #include <qpolygon.h>
00019 #endif
00020 #include "qwt_global.h"
00021 
00022 class QPainter;
00023 class QString;
00024 class QFontMetrics;
00025 #if QT_VERSION < 0x040000
00026 class QWMatrix;
00027 #else
00028 class QMatrix;
00029 #endif
00030 class QPaintDevice;
00031 
00032 class QWT_EXPORT QwtMetricsMap
00033 {
00034 public:
00035     QwtMetricsMap();
00036 
00037     bool isIdentity() const;
00038 
00039     void setMetrics(const QPaintDevice *layoutMetrics,
00040         const QPaintDevice *deviceMetrics);
00041 
00042     int layoutToDeviceX(int x) const;
00043     int deviceToLayoutX(int x) const;
00044     int screenToLayoutX(int x) const;
00045     int layoutToScreenX(int x) const;
00046 
00047     int layoutToDeviceY(int y) const;
00048     int deviceToLayoutY(int y) const;
00049     int screenToLayoutY(int y) const;
00050     int layoutToScreenY(int y) const;
00051 
00052     QPoint layoutToDevice(const QPoint &, const QPainter * = NULL) const;
00053     QPoint deviceToLayout(const QPoint &, const QPainter * = NULL) const;
00054     QPoint screenToLayout(const QPoint &) const;
00055 
00056     QSize layoutToDevice(const QSize &) const;
00057     QSize deviceToLayout(const QSize &) const;
00058     QSize screenToLayout(const QSize &) const;
00059 
00060     QRect layoutToDevice(const QRect &, const QPainter * = NULL) const;
00061     QRect deviceToLayout(const QRect &, const QPainter * = NULL) const;
00062     QRect screenToLayout(const QRect &) const;
00063 
00064 #if QT_VERSION < 0x040000
00065     QPointArray layoutToDevice(const QPointArray &, 
00066         const QPainter * = NULL) const;
00067     QPointArray deviceToLayout(const QPointArray &, 
00068         const QPainter * = NULL) const;
00069 
00070     static QPointArray translate(const QWMatrix &, const QPointArray &);
00071     static QRect translate(const QWMatrix &, const QRect &);
00072 #else
00073     QPolygon layoutToDevice(const QPolygon &, 
00074         const QPainter * = NULL) const;
00075     QPolygon deviceToLayout(const QPolygon &, 
00076         const QPainter * = NULL) const;
00077 
00078     static QPolygon translate(const QMatrix &, const QPolygon &);
00079     static QRect translate(const QMatrix &, const QRect &);
00080 #endif
00081 
00082 private:
00083     double d_screenToLayoutX;
00084     double d_screenToLayoutY;
00085 
00086     double d_deviceToLayoutX;
00087     double d_deviceToLayoutY;
00088 };
00089 
00090 inline bool QwtMetricsMap::isIdentity() const
00091 {
00092     return d_deviceToLayoutX == 1.0 && d_deviceToLayoutY == 1.0;
00093 }
00094 
00095 inline int QwtMetricsMap::layoutToDeviceX(int x) const
00096 {
00097     return qRound(x / d_deviceToLayoutX);
00098 }
00099 
00100 inline int QwtMetricsMap::deviceToLayoutX(int x) const
00101 {
00102     return qRound(x * d_deviceToLayoutX);
00103 }
00104 
00105 inline int QwtMetricsMap::screenToLayoutX(int x) const
00106 {
00107     return qRound(x * d_screenToLayoutX);
00108 }
00109 
00110 inline int QwtMetricsMap::layoutToScreenX(int x) const
00111 {
00112     return qRound(x / d_screenToLayoutX);
00113 }
00114 
00115 inline int QwtMetricsMap::layoutToDeviceY(int y) const
00116 {
00117     return qRound(y / d_deviceToLayoutY);
00118 }
00119 
00120 inline int QwtMetricsMap::deviceToLayoutY(int y) const
00121 {
00122     return qRound(y * d_deviceToLayoutY);
00123 }
00124 
00125 inline int QwtMetricsMap::screenToLayoutY(int y) const
00126 {
00127     return qRound(y * d_screenToLayoutY);
00128 }
00129 
00130 inline int QwtMetricsMap::layoutToScreenY(int y) const
00131 {
00132     return qRound(y / d_screenToLayoutY);
00133 }
00134 
00135 inline QSize QwtMetricsMap::layoutToDevice(const QSize &size) const
00136 {
00137     return QSize(layoutToDeviceX(size.width()), 
00138         layoutToDeviceY(size.height()));
00139 }
00140 
00141 inline QSize QwtMetricsMap::deviceToLayout(const QSize &size) const
00142 {
00143     return QSize(deviceToLayoutX(size.width()), 
00144         deviceToLayoutY(size.height()));
00145 }
00146 
00147 inline QSize QwtMetricsMap::screenToLayout(const QSize &size) const
00148 {
00149     return QSize(screenToLayoutX(size.width()), 
00150         screenToLayoutY(size.height()));
00151 }
00152 
00153 #endif

Generated on Mon Jan 30 22:16:25 2006 for Qwt User's Guide by  doxygen 1.4.4