qwt_painter.h 5.99 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
 * 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

Bryant's avatar
Bryant committed
13 14
#include "qwt_global.h"

pixhawk's avatar
pixhawk committed
15 16
#include <qpoint.h>
#include <qrect.h>
Bryant's avatar
Bryant committed
17 18 19
#include <qpen.h>
#include <qline.h>
#include <qpalette.h>
pixhawk's avatar
pixhawk committed
20 21 22 23 24

class QPainter;
class QBrush;
class QColor;
class QWidget;
Bryant's avatar
Bryant committed
25 26 27 28
class QPolygonF;
class QRectF;
class QImage;
class QPixmap;
pixhawk's avatar
pixhawk committed
29 30
class QwtScaleMap;
class QwtColorMap;
Bryant's avatar
Bryant committed
31
class QwtInterval;
pixhawk's avatar
pixhawk committed
32 33

class QTextDocument;
Bryant's avatar
Bryant committed
34
class QPainterPath;
pixhawk's avatar
pixhawk committed
35 36 37 38 39 40 41

/*!
  \brief A collection of QPainter workarounds
*/
class QWT_EXPORT QwtPainter
{
public:
Bryant's avatar
Bryant committed
42 43 44 45 46 47 48 49 50 51 52 53 54
    static void setPolylineSplitting( bool );
    static bool polylineSplitting();

    static void setRoundingAlignment( bool );
    static bool roundingAlignment();
    static bool roundingAlignment(QPainter *);

    static void drawText( QPainter *, double x, double y, const QString & );
    static void drawText( QPainter *, const QPointF &, const QString & );
    static void drawText( QPainter *, double x, double y, double w, double h,
        int flags, const QString & );
    static void drawText( QPainter *, const QRectF &, 
        int flags, const QString & );
pixhawk's avatar
pixhawk committed
55 56

#ifndef QT_NO_RICHTEXT
Bryant's avatar
Bryant committed
57 58
    static void drawSimpleRichText( QPainter *, const QRectF &,
        int flags, const QTextDocument & );
pixhawk's avatar
pixhawk committed
59 60
#endif

Bryant's avatar
Bryant committed
61 62 63
    static void drawRect( QPainter *, double x, double y, double w, double h );
    static void drawRect( QPainter *, const QRectF &rect );
    static void fillRect( QPainter *, const QRectF &, const QBrush & );
pixhawk's avatar
pixhawk committed
64

Bryant's avatar
Bryant committed
65 66
    static void drawEllipse( QPainter *, const QRectF & );
    static void drawPie( QPainter *, const QRectF & r, int a, int alen );
pixhawk's avatar
pixhawk committed
67

Bryant's avatar
Bryant committed
68 69 70
    static void drawLine( QPainter *, double x1, double y1, double x2, double y2 );
    static void drawLine( QPainter *, const QPointF &p1, const QPointF &p2 );
    static void drawLine( QPainter *, const QLineF & );
pixhawk's avatar
pixhawk committed
71

Bryant's avatar
Bryant committed
72 73 74
    static void drawPolygon( QPainter *, const QPolygonF & );
    static void drawPolyline( QPainter *, const QPolygonF & );
    static void drawPolyline( QPainter *, const QPointF *, int pointCount );
pixhawk's avatar
pixhawk committed
75

Bryant's avatar
Bryant committed
76 77 78
    static void drawPolygon( QPainter *, const QPolygon & );
    static void drawPolyline( QPainter *, const QPolygon & );
    static void drawPolyline( QPainter *, const QPoint *, int pointCount );
pixhawk's avatar
pixhawk committed
79

Bryant's avatar
Bryant committed
80 81 82
    static void drawPoint( QPainter *, const QPoint & );
    static void drawPoints( QPainter *, const QPolygon & );
    static void drawPoints( QPainter *, const QPoint *, int pointCount );
pixhawk's avatar
pixhawk committed
83

Bryant's avatar
Bryant committed
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
    static void drawPoint( QPainter *, double x, double y );
    static void drawPoint( QPainter *, const QPointF & );
    static void drawPoints( QPainter *, const QPolygonF & );
    static void drawPoints( QPainter *, const QPointF *, int pointCount );

    static void drawPath( QPainter *, const QPainterPath & );
    static void drawImage( QPainter *, const QRectF &, const QImage & );
    static void drawPixmap( QPainter *, const QRectF &, const QPixmap & );

    static void drawRoundFrame( QPainter *,
        const QRectF &, const QPalette &, int lineWidth, int frameStyle );

    static void drawRoundedFrame( QPainter *, 
        const QRectF &, double xRadius, double yRadius,
        const QPalette &, int lineWidth, int frameStyle );

    static void drawFrame( QPainter *, const QRectF &rect,
        const QPalette &palette, QPalette::ColorRole foregroundRole,
        int lineWidth, int midLineWidth, int frameStyle ); 

    static void drawFocusRect( QPainter *, const QWidget * );
    static void drawFocusRect( QPainter *, const QWidget *, const QRect & );

    static void drawColorBar( QPainter *painter,
        const QwtColorMap &, const QwtInterval &,
        const QwtScaleMap &, Qt::Orientation, const QRectF & );

    static bool isAligning( QPainter *painter );
    static bool isX11GraphicsSystem();

    static void fillPixmap( const QWidget *, 
        QPixmap &, const QPoint &offset = QPoint() );

    static void drawBackgound( QPainter *painter,
        const QRectF &rect, const QWidget *widget );

    static QPixmap backingStore( QWidget *, const QSize & );

private:
    static bool d_polylineSplitting;
    static bool d_roundingAlignment;
pixhawk's avatar
pixhawk committed
125 126
};

Bryant's avatar
Bryant committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
//!  Wrapper for QPainter::drawPoint()
inline void QwtPainter::drawPoint( QPainter *painter, double x, double y )
{
    QwtPainter::drawPoint( painter, QPointF( x, y ) );
}

//! Wrapper for QPainter::drawPoints()
inline void QwtPainter::drawPoints( QPainter *painter, const QPolygon &polygon )
{
    drawPoints( painter, polygon.data(), polygon.size() );
}

//! Wrapper for QPainter::drawPoints()
inline void QwtPainter::drawPoints( QPainter *painter, const QPolygonF &polygon )
{
    drawPoints( painter, polygon.data(), polygon.size() );
}

pixhawk's avatar
pixhawk committed
145
//!  Wrapper for QPainter::drawLine()
Bryant's avatar
Bryant committed
146 147
inline void QwtPainter::drawLine( QPainter *painter,
    double x1, double y1, double x2, double y2 )
pixhawk's avatar
pixhawk committed
148
{
Bryant's avatar
Bryant committed
149
    QwtPainter::drawLine( painter, QPointF( x1, y1 ), QPointF( x2, y2 ) );
pixhawk's avatar
pixhawk committed
150 151
}

Bryant's avatar
Bryant committed
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
//!  Wrapper for QPainter::drawLine()
inline void QwtPainter::drawLine( QPainter *painter, const QLineF &line )
{
    QwtPainter::drawLine( painter, line.p1(), line.p2() );
}

/*!
  \return True, when line splitting for the raster paint engine is enabled.
  \sa setPolylineSplitting()
*/
inline bool QwtPainter::polylineSplitting()
{
    return d_polylineSplitting;
}

/*!
  Check whether coordinates should be rounded, before they are painted
  to a paint engine that rounds to integer values. For other paint engines
  ( PDF, SVG ), this flag has no effect.

  \return True, when rounding is enabled
  \sa setRoundingAlignment(), isAligning()
*/
inline bool QwtPainter::roundingAlignment()
{
    return d_roundingAlignment;
}

/*!
  \return roundingAlignment() && isAligning(painter);
  \param painter Painter
*/
inline bool QwtPainter::roundingAlignment(QPainter *painter)
{
    return d_roundingAlignment && isAligning(painter);
}
pixhawk's avatar
pixhawk committed
188
#endif