qwt_painter.h 4.73 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 * Qwt Widget Library
 * Copyright (C) 1997   Josef Wilgen
 * Copyright (C) 2002   Uwe Rathmann
5
 *
pixhawk's avatar
pixhawk committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the Qwt License, Version 1.0
 *****************************************************************************/

#ifndef QWT_PAINTER_H
#define QWT_PAINTER_H

#include <qpoint.h>
#include <qrect.h>
#include "qwt_global.h"
#include "qwt_layout_metrics.h"
#include "qwt_polygon.h"

class QPainter;
class QBrush;
class QColor;
class QWidget;
class QwtScaleMap;
class QwtColorMap;
class QwtDoubleInterval;

#if QT_VERSION < 0x040000
class QColorGroup;
class QSimpleRichText;
#else
class QPalette;
class QTextDocument;
#endif

#if defined(Q_WS_X11)
// Warning: QCOORD_MIN, QCOORD_MAX are wrong on X11.
#define QWT_COORD_MAX 16384
#define QWT_COORD_MIN (-QWT_COORD_MAX - 1)
#else
#define QWT_COORD_MAX 2147483647
#define QWT_COORD_MIN -QWT_COORD_MAX - 1
#endif

/*!
  \brief A collection of QPainter workarounds

  1) Clipping to coordinate system limits (Qt3 only)

49 50
  On X11 pixel coordinates are stored in shorts. Qt
  produces overruns when mapping QCOORDS to shorts.
pixhawk's avatar
pixhawk committed
51 52 53 54 55

  2) Scaling to device metrics

  QPainter scales fonts, line and fill patterns to the metrics
  of the paint device. Other values like the geometries of rects, points
56
  remain device independend. To enable a device independent widget
pixhawk's avatar
pixhawk committed
57 58 59 60 61 62 63 64 65
  implementation, QwtPainter adds scaling of these geometries.
  (Unfortunately QPainter::scale scales both types of paintings,
   so the objects of the first type would be scaled twice).
*/

class QWT_EXPORT QwtPainter
{
public:
    static void setMetricsMap(const QPaintDevice *layout,
66
                              const QPaintDevice *device);
pixhawk's avatar
pixhawk committed
67 68 69 70 71 72 73 74 75
    static void setMetricsMap(const QwtMetricsMap &);
    static void resetMetricsMap();
    static const QwtMetricsMap &metricsMap();

    static void setDeviceClipping(bool);
    static bool deviceClipping();

    static void setClipRect(QPainter *, const QRect &);

76 77 78 79 80 81 82 83
    static void drawText(QPainter *, int x, int y,
                         const QString &);
    static void drawText(QPainter *, const QPoint &,
                         const QString &);
    static void drawText(QPainter *, int x, int y, int w, int h,
                         int flags, const QString &);
    static void drawText(QPainter *, const QRect &,
                         int flags, const QString &);
pixhawk's avatar
pixhawk committed
84 85 86 87

#ifndef QT_NO_RICHTEXT
#if QT_VERSION < 0x040000
    static void drawSimpleRichText(QPainter *, const QRect &,
88
                                   int flags, QSimpleRichText &);
pixhawk's avatar
pixhawk committed
89 90
#else
    static void drawSimpleRichText(QPainter *, const QRect &,
91
                                   int flags, QTextDocument &);
pixhawk's avatar
pixhawk committed
92 93 94 95 96
#endif
#endif

    static void drawRect(QPainter *, int x, int y, int w, int h);
    static void drawRect(QPainter *, const QRect &rect);
97
    static void fillRect(QPainter *, const QRect &, const QBrush &);
pixhawk's avatar
pixhawk committed
98 99 100 101 102 103 104 105 106 107 108 109

    static void drawEllipse(QPainter *, const QRect &);
    static void drawPie(QPainter *, const QRect & r, int a, int alen);

    static void drawLine(QPainter *, int x1, int y1, int x2, int y2);
    static void drawLine(QPainter *, const QPoint &p1, const QPoint &p2);
    static void drawPolygon(QPainter *, const QwtPolygon &pa);
    static void drawPolyline(QPainter *, const QwtPolygon &pa);
    static void drawPoint(QPainter *, int x, int y);

#if QT_VERSION < 0x040000
    static void drawRoundFrame(QPainter *, const QRect &,
110
                               int width, const QColorGroup &cg, bool sunken);
pixhawk's avatar
pixhawk committed
111 112
#else
    static void drawRoundFrame(QPainter *, const QRect &,
113
                               int width, const QPalette &, bool sunken);
pixhawk's avatar
pixhawk committed
114 115 116 117 118 119
#endif
    static void drawFocusRect(QPainter *, QWidget *);
    static void drawFocusRect(QPainter *, QWidget *, const QRect &);

    static QwtPolygon clip(const QwtPolygon &);

120 121 122
    static void drawColorBar(QPainter *painter,
                             const QwtColorMap &, const QwtDoubleInterval &,
                             const QwtScaleMap &, Qt::Orientation, const QRect &);
pixhawk's avatar
pixhawk committed
123 124 125 126 127 128 129 130

#if QT_VERSION < 0x040000
    static void setSVGMode(bool on);
    static bool isSVGMode();
#endif

private:
    static void drawColoredArc(QPainter *, const QRect &,
131
                               int peak, int arc, int intervall, const QColor &c1, const QColor &c2);
pixhawk's avatar
pixhawk committed
132 133 134 135 136 137 138 139 140 141 142 143

    static const QRect &deviceClipRect();

    static bool d_deviceClipping;
    static QwtMetricsMap d_metricsMap;
#if QT_VERSION < 0x040000
    static bool d_SVGMode;
#endif
};

//!  Wrapper for QPainter::drawLine()
inline void QwtPainter::drawLine(QPainter *painter,
144
                                 const QPoint &p1, const QPoint &p2)
pixhawk's avatar
pixhawk committed
145 146 147 148 149
{
    drawLine(painter, p1.x(), p1.y(), p2.x(), p2.y());
}

#endif