Public Member Functions | Static Public Member Functions

QwtMetricsMap Class Reference

A Map to translate between layout, screen and paint device metrics. More...

#include <qwt_layout_metrics.h>

List of all members.

Public Member Functions

 QwtMetricsMap ()
bool isIdentity () const
void setMetrics (const QPaintDevice *layoutMetrics, const QPaintDevice *deviceMetrics)
int layoutToDeviceX (int x) const
int deviceToLayoutX (int x) const
int screenToLayoutX (int x) const
int layoutToScreenX (int x) const
int layoutToDeviceY (int y) const
int deviceToLayoutY (int y) const
int screenToLayoutY (int y) const
int layoutToScreenY (int y) const
QPoint layoutToDevice (const QPoint &, const QPainter *=NULL) const
QPoint deviceToLayout (const QPoint &, const QPainter *=NULL) const
QPoint screenToLayout (const QPoint &) const
QPoint layoutToScreen (const QPoint &point) const
QSize layoutToDevice (const QSize &) const
QSize deviceToLayout (const QSize &) const
QSize screenToLayout (const QSize &) const
QSize layoutToScreen (const QSize &) const
QRect layoutToDevice (const QRect &, const QPainter *=NULL) const
QRect deviceToLayout (const QRect &, const QPainter *=NULL) const
QRect screenToLayout (const QRect &) const
QRect layoutToScreen (const QRect &) const
QwtPolygon layoutToDevice (const QwtPolygon &, const QPainter *=NULL) const
QwtPolygon deviceToLayout (const QwtPolygon &, const QPainter *=NULL) const

Static Public Member Functions

static QwtPolygon translate (const QWMatrix &, const QwtPolygon &)
static QRect translate (const QWMatrix &, const QRect &)

Detailed Description

A Map to translate between layout, screen and paint device metrics.

Qt3 supports painting in integer coordinates only. Therefore it is not possible to scale the layout in screen coordinates to layouts in higher resolutions ( f.e printing ) without losing the higher precision. QwtMetricsMap is used to incorporate the various widget attributes ( always in screen resolution ) into the layout/printing code of QwtPlot.

Qt4 is able to paint floating point based coordinates, what makes it possible always to render in screen coordinates ( with a common scale factor ). QwtMetricsMap will be obsolete as soon as Qt3 support has been dropped ( Qwt 6.x ).

Definition at line 43 of file qwt_layout_metrics.h.


Constructor & Destructor Documentation

QwtMetricsMap::QwtMetricsMap (  )

Definition at line 65 of file qwt_layout_metrics.cpp.

{
    d_screenToLayoutX = d_screenToLayoutY = 
        d_deviceToLayoutX = d_deviceToLayoutY = 1.0;
}

Member Function Documentation

QPoint QwtMetricsMap::deviceToLayout ( const QPoint &  point,
const QPainter *  painter = NULL 
) const

Definition at line 119 of file qwt_layout_metrics.cpp.

References invMatrix(), and matrix().

{
    if ( isIdentity() )
        return point;

    QPoint mappedPoint(point);

#ifndef QT_NO_TRANSFORMATIONS
    if ( painter )
        mappedPoint = matrix(painter).map(mappedPoint);
#endif

    mappedPoint.setX(deviceToLayoutX(mappedPoint.x()));
    mappedPoint.setY(deviceToLayoutY(mappedPoint.y()));

#ifndef QT_NO_TRANSFORMATIONS
    if ( painter )
        mappedPoint = invMatrix(painter).map(mappedPoint);
#endif

    return mappedPoint;
}
QSize QwtMetricsMap::deviceToLayout ( const QSize &  size ) const [inline]

Definition at line 151 of file qwt_layout_metrics.h.

References deviceToLayoutX(), and deviceToLayoutY().

{
    return QSize(deviceToLayoutX(size.width()), 
        deviceToLayoutY(size.height()));
}
QRect QwtMetricsMap::deviceToLayout ( const QRect &  rect,
const QPainter *  painter = NULL 
) const

Definition at line 207 of file qwt_layout_metrics.cpp.

References invMatrix(), and matrix().

{
    if ( isIdentity() )
        return rect;

    QRect mappedRect(rect);
#ifndef QT_NO_TRANSFORMATIONS
    if ( painter )
        mappedRect = translate(matrix(painter), mappedRect);
#endif

    mappedRect = QRect(
        deviceToLayout(mappedRect.topLeft()), 
        deviceToLayout(mappedRect.bottomRight())
    );

#ifndef QT_NO_TRANSFORMATIONS
    if ( painter )
        mappedRect = translate(invMatrix(painter), mappedRect);
#endif

    return mappedRect;
}
QwtPolygon QwtMetricsMap::deviceToLayout ( const QwtPolygon pa,
const QPainter *  painter = NULL 
) const

Definition at line 285 of file qwt_layout_metrics.cpp.

References invMatrix(), matrix(), and QwtMatrix.

{
    if ( isIdentity() )
        return pa;
    
    QwtPolygon mappedPa(pa);

#ifndef QT_NO_TRANSFORMATIONS
    if ( painter )
        mappedPa = translate(matrix(painter), mappedPa);
#endif

    QwtMatrix m;
    m.scale(d_deviceToLayoutX, d_deviceToLayoutY);
    mappedPa = translate(m, mappedPa);

#ifndef QT_NO_TRANSFORMATIONS
    if ( painter )
        mappedPa = translate(invMatrix(painter), mappedPa);
#endif

    return mappedPa;
}
int QwtMetricsMap::deviceToLayoutX ( int  x ) const [inline]

Definition at line 110 of file qwt_layout_metrics.h.

Referenced by deviceToLayout().

{
    return qRound(x * d_deviceToLayoutX);
}
int QwtMetricsMap::deviceToLayoutY ( int  y ) const [inline]

Definition at line 130 of file qwt_layout_metrics.h.

Referenced by deviceToLayout().

{
    return qRound(y * d_deviceToLayoutY);
}
bool QwtMetricsMap::isIdentity (  ) const [inline]

Definition at line 100 of file qwt_layout_metrics.h.

Referenced by QwtPainter::drawLine(), QwtScaleDraw::drawTick(), and QwtText::textSize().

{
    return d_deviceToLayoutX == 1.0 && d_deviceToLayoutY == 1.0;
}
QRect QwtMetricsMap::layoutToDevice ( const QRect &  rect,
const QPainter *  painter = NULL 
) const

Definition at line 164 of file qwt_layout_metrics.cpp.

References matrix().

{
    if ( isIdentity() )
        return rect;

    int dx = 0;
    int dy = 0;

    QRect mappedRect(rect);
#ifndef QT_NO_TRANSFORMATIONS
    if ( painter )
    {
        // only translations, but this code doesn't need to be perfect
        // as it used for printing of stuff only, that is not on the canvas.
        // Here we know we have translations only.
        // As soon as Qt3 support is dropped, Qwt will use a floating point
        // based layout and this class can die completely.

        dx = qRound(matrix(painter).dx());
        dy = qRound(matrix(painter).dy());

        mappedRect = QRect(mappedRect.x() + dx, mappedRect.y() + dy,
            mappedRect.width(), mappedRect.height() );
    }
#endif

    mappedRect = QRect(
        layoutToDevice(mappedRect.topLeft()), 
        layoutToDevice(mappedRect.bottomRight())
    );

    mappedRect = QRect(mappedRect.x() - dx, mappedRect.y() - dy,
        mappedRect.width(), mappedRect.height() );

    return mappedRect;
}
QPoint QwtMetricsMap::layoutToDevice ( const QPoint &  point,
const QPainter *  painter = NULL 
) const

Definition at line 90 of file qwt_layout_metrics.cpp.

References invMatrix(), and matrix().

Referenced by QwtPainter::drawColorBar(), QwtPainter::drawEllipse(), QwtScaleDraw::drawLabel(), QwtPainter::drawLine(), QwtPainter::drawPie(), QwtPainter::drawPoint(), QwtPainter::drawPolygon(), QwtPainter::drawPolyline(), QwtPainter::drawRect(), QwtPainter::drawSimpleRichText(), QwtPainter::drawText(), QwtScaleDraw::drawTick(), QwtScaleWidget::drawTitle(), QwtPainter::fillRect(), and QwtPainter::setClipRect().

{
    if ( isIdentity() )
        return point;

    QPoint mappedPoint(point);

#ifndef QT_NO_TRANSFORMATIONS
    if ( painter )
        mappedPoint = matrix(painter).map(mappedPoint);
#endif

    mappedPoint.setX(layoutToDeviceX(mappedPoint.x()));
    mappedPoint.setY(layoutToDeviceY(mappedPoint.y()));

#ifndef QT_NO_TRANSFORMATIONS
    if ( painter )
        mappedPoint = invMatrix(painter).map(mappedPoint);
#endif

    return mappedPoint;
}
QwtPolygon QwtMetricsMap::layoutToDevice ( const QwtPolygon pa,
const QPainter *  painter = NULL 
) const

Definition at line 255 of file qwt_layout_metrics.cpp.

References invMatrix(), matrix(), and QwtMatrix.

{
    if ( isIdentity() )
        return pa;
    
    QwtPolygon mappedPa(pa);

#ifndef QT_NO_TRANSFORMATIONS
    if ( painter )
        mappedPa = translate(matrix(painter), mappedPa);
#endif

    QwtMatrix m;
    m.scale(1.0 / d_deviceToLayoutX, 1.0 / d_deviceToLayoutY);
    mappedPa = translate(m, mappedPa);

#ifndef QT_NO_TRANSFORMATIONS
    if ( painter )
        mappedPa = translate(invMatrix(painter), mappedPa);
#endif

    return mappedPa;
}
QSize QwtMetricsMap::layoutToDevice ( const QSize &  size ) const [inline]

Definition at line 145 of file qwt_layout_metrics.h.

References layoutToDeviceX(), and layoutToDeviceY().

{
    return QSize(layoutToDeviceX(size.width()), 
        layoutToDeviceY(size.height()));
}
int QwtMetricsMap::layoutToDeviceX ( int  x ) const [inline]

Definition at line 105 of file qwt_layout_metrics.h.

Referenced by QwtScaleDraw::drawTick(), and layoutToDevice().

{
    return qRound(x / d_deviceToLayoutX);
}
int QwtMetricsMap::layoutToDeviceY ( int  y ) const [inline]

Definition at line 125 of file qwt_layout_metrics.h.

Referenced by QwtScaleDraw::drawTick(), and layoutToDevice().

{
    return qRound(y / d_deviceToLayoutY);
}
QSize QwtMetricsMap::layoutToScreen ( const QSize &  size ) const [inline]

Definition at line 163 of file qwt_layout_metrics.h.

References layoutToScreenX(), and layoutToScreenY().

{
    return QSize(layoutToScreenX(size.width()), 
        layoutToScreenY(size.height()));
}
QRect QwtMetricsMap::layoutToScreen ( const QRect &  rect ) const

Definition at line 245 of file qwt_layout_metrics.cpp.

References layoutToScreenX(), and layoutToScreenY().

{
    if ( d_screenToLayoutX == 1.0 && d_screenToLayoutY == 1.0 )
        return rect;

    return QRect(layoutToScreenX(rect.x()), layoutToScreenY(rect.y()),
        layoutToScreenX(rect.width()), layoutToScreenY(rect.height()));
}
QPoint QwtMetricsMap::layoutToScreen ( const QPoint &  point ) const

Definition at line 155 of file qwt_layout_metrics.cpp.

References layoutToScreenX(), and layoutToScreenY().

Referenced by QwtPlot::printScale().

{
    if ( d_screenToLayoutX == 1.0 && d_screenToLayoutY == 1.0 )
        return point;

    return QPoint(layoutToScreenX(point.x()), layoutToScreenY(point.y()));
}
int QwtMetricsMap::layoutToScreenX ( int  x ) const [inline]

Definition at line 120 of file qwt_layout_metrics.h.

Referenced by QwtText::heightForWidth(), and layoutToScreen().

{
    return qRound(x / d_screenToLayoutX);
}
int QwtMetricsMap::layoutToScreenY ( int  y ) const [inline]

Definition at line 140 of file qwt_layout_metrics.h.

Referenced by layoutToScreen().

{
    return qRound(y / d_screenToLayoutY);
}
QSize QwtMetricsMap::screenToLayout ( const QSize &  size ) const [inline]

Definition at line 157 of file qwt_layout_metrics.h.

References screenToLayoutX(), and screenToLayoutY().

{
    return QSize(screenToLayoutX(size.width()), 
        screenToLayoutY(size.height()));
}
QRect QwtMetricsMap::screenToLayout ( const QRect &  rect ) const

Definition at line 236 of file qwt_layout_metrics.cpp.

References screenToLayoutX(), and screenToLayoutY().

{
    if ( d_screenToLayoutX == 1.0 && d_screenToLayoutY == 1.0 )
        return rect;

    return QRect(screenToLayoutX(rect.x()), screenToLayoutY(rect.y()),
        screenToLayoutX(rect.width()), screenToLayoutY(rect.height()));
}
QPoint QwtMetricsMap::screenToLayout ( const QPoint &  point ) const

Definition at line 147 of file qwt_layout_metrics.cpp.

References screenToLayoutX(), and screenToLayoutY().

Referenced by QwtLegendItem::drawIdentifier(), QwtPlotCurve::drawSymbols(), and QwtText::textSize().

{
    if ( d_screenToLayoutX == 1.0 && d_screenToLayoutY == 1.0 )
        return point;

    return QPoint(screenToLayoutX(point.x()), screenToLayoutY(point.y()));
}
int QwtMetricsMap::screenToLayoutX ( int  x ) const [inline]

Definition at line 115 of file qwt_layout_metrics.h.

Referenced by QwtText::draw(), QwtLegendItem::drawItem(), QwtPlot::printScale(), and screenToLayout().

{
    return qRound(x * d_screenToLayoutX);
}
int QwtMetricsMap::screenToLayoutY ( int  y ) const [inline]

Definition at line 135 of file qwt_layout_metrics.h.

Referenced by QwtText::draw(), QwtText::heightForWidth(), QwtPlot::printScale(), and screenToLayout().

{
    return qRound(y * d_screenToLayoutY);
}
void QwtMetricsMap::setMetrics ( const QPaintDevice *  layoutMetrics,
const QPaintDevice *  deviceMetrics 
)

Definition at line 71 of file qwt_layout_metrics.cpp.

References deviceDpi().

Referenced by QwtPainter::setMetricsMap().

{
    const QSize screenDpi = deviceDpi(QApplication::desktop());
    const QSize layoutDpi = deviceDpi(layoutDevice);
    const QSize paintDpi = deviceDpi(paintDevice);

    d_screenToLayoutX = double(layoutDpi.width()) / 
        double(screenDpi.width());
    d_screenToLayoutY = double(layoutDpi.height()) / 
        double(screenDpi.height());

    d_deviceToLayoutX = double(layoutDpi.width()) / 
        double(paintDpi.width());
    d_deviceToLayoutY = double(layoutDpi.height()) / 
        double(paintDpi.height());
}
QwtPolygon QwtMetricsMap::translate ( const QWMatrix &  m,
const QwtPolygon pa 
) [static]

Wrapper for QMatrix::map.

Parameters:
mMatrix
paPolygon to translate
Returns:
Translated polygon

Definition at line 335 of file qwt_layout_metrics.cpp.

Referenced by QwtScaleDraw::labelRect().

{
    return m.map(pa);
}
QRect QwtMetricsMap::translate ( const QWMatrix &  m,
const QRect &  rect 
) [static]

Wrapper for QMatrix::mapRect.

Parameters:
mMatrix
rectRectangle to translate
Returns:
Translated rectangle

Definition at line 322 of file qwt_layout_metrics.cpp.

{
    return m.mapRect(rect);
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines