File: qwt_painter.h

package info (click to toggle)
libqwt 4.2.0-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 9,856 kB
  • ctags: 5,512
  • sloc: cpp: 22,973; ansic: 244; makefile: 59
file content (127 lines) | stat: -rw-r--r-- 4,001 bytes parent folder | download | duplicates (5)
1
2
3
4
5
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 * Qwt Widget Library
 * Copyright (C) 1997   Josef Wilgen
 * Copyright (C) 2002   Uwe Rathmann
 * 
 * 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 <qpointarray.h>
#include <qrect.h>
#include "qwt_global.h"
#include "qwt_layout_metrics.h"

class QPainter;

#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 QCOORD_MAX
#define QWT_COORD_MIN QCOORD_MIN
#endif

/*!
  \brief A collection of QPainter workarounds

  1) Clipping to coordinate system limits

  On X11 pixel coordinates are stored in shorts. Qt 
  produces overruns when mapping QCOORDS to shorts. 

  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
  remain device independend. To enable a device independent widget 
  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).

  3) Hide some Qt2/3 incompatibilities
*/

class QWT_EXPORT QwtPainter
{
public:
    /*!
      Indicates a method to work around a bug in the drawing of text using the
      XorROP raster operator on the X Window system. Has no effect on other
      platforms.

      \sa  QwtPainter::setTextXorRopMode
     */
    enum TextXorRopMode {
        XorRopTextNormal = 0,
        XorRopTextKeepFont = 1,
        XorRopTextKeepColor = 2
    };

    static void setMetricsMap(const QPaintDevice *layout,
        const QPaintDevice *device);
    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 &);

    static void drawText(QPainter *, int x, int y, 
        const QString &, int len = -1);
    static void drawText(QPainter *, const QPoint &, 
        const QString &, int len = -1);
    static void drawText(QPainter *, int x, int y, int w, int h, 
        int flags, const QString &, int len = -1);
    static void drawText(QPainter *, const QRect &, 
        int flags, const QString &, int len = -1);

#ifndef QT_NO_RICHTEXT
    static void drawSimpleRichText(QPainter *, const QRect &,
        int flags, QSimpleRichText &);
#endif

    static void drawRect(QPainter *, int x, int y, int w, int h);
    static void drawRect(QPainter *, const QRect &rect);
    static void fillRect(QPainter *, const QRect &, const QBrush &); 

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

    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 QPointArray &pa);
    static void drawPolyline(QPainter *, const QPointArray &pa);
    static void drawPoint(QPainter *, int x, int y);

    static void drawRoundFrame(QPainter *, const QRect &,
        int width, const QColorGroup &cg, bool sunken);

    static QPointArray clip(const QPointArray &);

    static int textXorRopMode();
    static int setTextXorRopMode(TextXorRopMode mode);

private:
    static const QRect &deviceClipRect();
    static void drawColoredArc(QPainter *, const QRect &,
        int peak, int arc, int intervall, const QColor &c1, const QColor &c2);

    static bool d_deviceClipping;
    static QwtMetricsMap d_metricsMap;
    static int d_textXorRopMode;
};

#endif

// Local Variables:
// mode: C++
// c-file-style: "stroustrup"
// indent-tabs-mode: nil
// End: