Main Page | Class Hierarchy | Alphabetical List | Class List | 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 "qwt_global.h"
    00015
    00016 class QPainter;
    00017 class QRect;
    00018 class QPoint;
    00019 class QPointArray;
    00020 class QString;
    00021 class QSimpleRichText;
    00022 class QPaintDeviceMetrics;
    00023
    00024 class QWT_EXPORT QwtMetricsMap
    00025 {
    00026 public:
    00027     QwtMetricsMap();
    00028
    00029     bool isIdentity() const;
    00030
    00031     void setMetrics(const QPaintDeviceMetrics &layoutMetrics,
    00032         const QPaintDeviceMetrics &deviceMetrics);
    00033
    00034     int layoutToDeviceX(int x) const;
    00035     int deviceToLayoutX(int x) const;
    00036     int screenToLayoutX(int x) const;
    00037     int layoutToScreenX(int x) const;
    00038
    00039     int layoutToDeviceY(int y) const;
    00040     int deviceToLayoutY(int y) const;
    00041     int screenToLayoutY(int y) const;
    00042     int layoutToScreenY(int y) const;
    00043
    00044     QPoint layoutToDevice(const QPoint &, const QPainter * = NULL) const;
    00045     QPoint deviceToLayout(const QPoint &, const QPainter * = NULL) const;
    00046     QPoint screenToLayout(const QPoint &) const;
    00047
    00048     QSize layoutToDevice(const QSize &) const;
    00049     QSize deviceToLayout(const QSize &) const;
    00050     QSize screenToLayout(const QSize &) const;
    00051
    00052     QRect layoutToDevice(const QRect &, const QPainter * = NULL) const;
    00053     QRect deviceToLayout(const QRect &, const QPainter * = NULL) const;
    00054     QRect screenToLayout(const QRect &) const;
    00055
    00056     QPointArray layoutToDevice(const QPointArray &,
    00057         const QPainter * = NULL) const;
    00058     QPointArray deviceToLayout(const QPointArray &,
    00059         const QPainter * = NULL) const;
    00060
    00061     static QRect translate(const QWMatrix &, const QRect &);
    00062     static QPointArray translate(const QWMatrix &, const QPointArray &);
    00063
    00064 private:
    00065     double d_screenToLayoutX;
    00066     double d_screenToLayoutY;
    00067
    00068     double d_deviceToLayoutX;
    00069     double d_deviceToLayoutY;
    00070 };
    00071
    00072
    00073 class QWT_EXPORT QwtLayoutMetrics
    00074 {
    00075 public:
    00076     QwtLayoutMetrics();
    00077     QwtLayoutMetrics(const QwtMetricsMap &);
    00078
    00079     void setMap(const QwtMetricsMap &);
    00080
    00081     QRect boundingRect(const QString &, int flags, QPainter *) const;
    00082     QRect boundingRect(const QString &, int flags, const QFontMetrics &) const;
    00083
    00084     int heightForWidth(const QString &,
    00085         int width, int flags, const QFontMetrics &) const;
    00086     int heightForWidth(const QString &,
    00087         int width, int flags, QPainter *) const;
    00088
    00089 #ifndef QT_NO_RICHTEXT
    00090     QRect boundingRect(const QSimpleRichText &,
    00091         int flags, QPainter * = NULL) const;
    00092     int heightForWidth(QSimpleRichText &, int width) const;
    00093 #endif
    00094
    00095 private:
    00096     QwtMetricsMap d_map;
    00097 };
    00098
    00099 inline bool QwtMetricsMap::isIdentity() const
    00100 {
    00101     return d_deviceToLayoutX == 1.0 && d_deviceToLayoutY == 1.0;
    00102 }
    00103
    00104 inline int QwtMetricsMap::layoutToDeviceX(int x) const
    00105 {
    00106     return qRound(x / d_deviceToLayoutX);
    00107 }
    00108
    00109 inline int QwtMetricsMap::deviceToLayoutX(int x) const
    00110 {
    00111     return qRound(x * d_deviceToLayoutX);
    00112 }
    00113
    00114 inline int QwtMetricsMap::screenToLayoutX(int x) const
    00115 {
    00116     return qRound(x * d_screenToLayoutX);
    00117 }
    00118
    00119 inline int QwtMetricsMap::layoutToScreenX(int x) const
    00120 {
    00121     return qRound(x / d_screenToLayoutX);
    00122 }
    00123
    00124 inline int QwtMetricsMap::layoutToDeviceY(int y) const
    00125 {
    00126     return qRound(y / d_deviceToLayoutY);
    00127 }
    00128
    00129 inline int QwtMetricsMap::deviceToLayoutY(int y) const
    00130 {
    00131     return qRound(y * d_deviceToLayoutY);
    00132 }
    00133
    00134 inline int QwtMetricsMap::screenToLayoutY(int y) const
    00135 {
    00136     return qRound(y * d_screenToLayoutY);
    00137 }
    00138
    00139 inline int QwtMetricsMap::layoutToScreenY(int y) const
    00140 {
    00141     return qRound(y / d_screenToLayoutY);
    00142 }
    00143
    00144 inline QSize QwtMetricsMap::layoutToDevice(const QSize &size) const
    00145 {
    00146     return QSize(layoutToDeviceX(size.width()),
    00147         layoutToDeviceY(size.height()));
    00148 }
    00149
    00150 inline QSize QwtMetricsMap::deviceToLayout(const QSize &size) const
    00151 {
    00152     return QSize(deviceToLayoutX(size.width()),
    00153         deviceToLayoutY(size.height()));
    00154 }
    00155
    00156 inline QSize QwtMetricsMap::screenToLayout(const QSize &size) const
    00157 {
    00158     return QSize(screenToLayoutX(size.width()),
    00159         screenToLayoutY(size.height()));
    00160 }
    00161
    00162 #endif