~ubuntu-branches/ubuntu/oneiric/qwt/oneiric-proposed

« back to all changes in this revision

Viewing changes to src/qwt_painter.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2011-06-10 11:22:47 UTC
  • mfrom: (1.1.6 upstream) (2.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20110610112247-0i1019vvmzaq6p86
Tags: 6.0.0-1
* New upstream release (Closes: #624107):
  - drop Qt3 support. (Closes: #604379, #626868)
* Register documentation with doc-base. (Closes: #626567)
* Drop patches:
  - 01_makefiles.diff
  - 02_add_missing_warnings.diff
  - 03_qwt_branch_pull_r544.diff
* Add qwt_install_paths.patch to fix the hardcoded installation paths.
* Update debian/control:
  - drop libqt3-mt-dev build dependency.
  - bump Standards-Version to 3.9.2 (no changes).
  - drop Qt3 related packages.
  - due to bump soname (and as we dropper Qt3 support):
    - libqwt5-qt4-dev -> libqwt-dev
    - libqwt5-qt4 -> libqwt6
    - libqwt5-doc -> libqwt-doc
* Update debian/copyright file.
* Update debian/rules: drop Qt3 packages support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 
2
 * Qwt Widget Library
 
3
 * Copyright (C) 1997   Josef Wilgen
 
4
 * Copyright (C) 2002   Uwe Rathmann
 
5
 *
 
6
 * This library is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the Qwt License, Version 1.0
 
8
 *****************************************************************************/
 
9
 
 
10
#include "qwt_painter.h"
 
11
#include "qwt_math.h"
 
12
#include "qwt_clipper.h"
 
13
#include "qwt_color_map.h"
 
14
#include "qwt_scale_map.h"
 
15
#include <qwindowdefs.h>
 
16
#include <qwidget.h>
 
17
#include <qrect.h>
 
18
#include <qpainter.h>
 
19
#include <qpalette.h>
 
20
#include <qpaintdevice.h>
 
21
#include <qpixmap.h>
 
22
#include <qstyle.h>
 
23
#include <qtextdocument.h>
 
24
#include <qabstracttextdocumentlayout.h>
 
25
#include <qstyleoption.h>
 
26
#include <qpaintengine.h>
 
27
#include <qapplication.h>
 
28
#include <qdesktopwidget.h>
 
29
 
 
30
bool QwtPainter::d_polylineSplitting = true;
 
31
bool QwtPainter::d_roundingAlignment = true;
 
32
 
 
33
static inline bool isClippingNeeded( const QPainter *painter, QRectF &clipRect )
 
34
{
 
35
    bool doClipping = false;
 
36
    const QPaintEngine *pe = painter->paintEngine();
 
37
    if ( pe && pe->type() == QPaintEngine::SVG )
 
38
    {
 
39
        // The SVG paint engine ignores any clipping,
 
40
 
 
41
        if ( painter->hasClipping() )
 
42
        {
 
43
            doClipping = true;
 
44
            clipRect = painter->clipRegion().boundingRect();
 
45
        }
 
46
    }
 
47
 
 
48
    return doClipping;
 
49
}
 
50
 
 
51
static inline void drawPolyline( QPainter *painter,
 
52
    const QPointF *points, int pointCount, bool polylineSplitting )
 
53
{
 
54
    bool doSplit = false;
 
55
    if ( polylineSplitting )
 
56
    {
 
57
        const QPaintEngine *pe = painter->paintEngine();
 
58
        if ( pe && pe->type() == QPaintEngine::Raster )
 
59
        {
 
60
            /*
 
61
                The raster paint engine seems to use some algo with O(n*n).
 
62
                ( Qt 4.3 is better than Qt 4.2, but remains unacceptable)
 
63
                To work around this problem, we have to split the polygon into
 
64
                smaller pieces.
 
65
             */
 
66
            doSplit = true;
 
67
        }
 
68
    }
 
69
 
 
70
    if ( doSplit )
 
71
    {
 
72
        const int splitSize = 20;
 
73
        for ( int i = 0; i < pointCount; i += splitSize )
 
74
        {
 
75
            const int n = qMin( splitSize + 1, pointCount - i );
 
76
            painter->drawPolyline( points + i, n );
 
77
        }
 
78
    }
 
79
    else
 
80
        painter->drawPolyline( points, pointCount );
 
81
}
 
82
 
 
83
static inline void unscaleFont( QPainter *painter )
 
84
{
 
85
    if ( painter->font().pixelSize() >= 0 )
 
86
        return;
 
87
 
 
88
    static QSize screenResolution;
 
89
    if ( !screenResolution.isValid() )
 
90
    {
 
91
        QDesktopWidget *desktop = QApplication::desktop();
 
92
        if ( desktop )
 
93
        {
 
94
            screenResolution.setWidth( desktop->logicalDpiX() );
 
95
            screenResolution.setHeight( desktop->logicalDpiY() );
 
96
        }
 
97
    }
 
98
 
 
99
    const QPaintDevice *pd = painter->device();
 
100
    if ( pd->logicalDpiX() != screenResolution.width() ||
 
101
        pd->logicalDpiY() != screenResolution.height() )
 
102
    {
 
103
        QFont pixelFont( painter->font(), QApplication::desktop() );
 
104
        pixelFont.setPixelSize( QFontInfo( pixelFont ).pixelSize() );
 
105
 
 
106
        painter->setFont( pixelFont );
 
107
    }
 
108
}
 
109
 
 
110
/*!
 
111
  Check if the painter is using a paint engine, that aligns
 
112
  coordinates to integers. Today these are all paint engines
 
113
  beside QPaintEngine::Pdf and QPaintEngine::SVG.
 
114
 
 
115
  \param  painter Painter
 
116
  \return true, when the paint engine is aligning
 
117
 
 
118
  \sa setRoundingAlignment()
 
119
*/
 
120
bool QwtPainter::isAligning( QPainter *painter )
 
121
{
 
122
    if ( painter && painter->isActive() )
 
123
    {
 
124
        switch ( painter->paintEngine()->type() )
 
125
        {
 
126
            case QPaintEngine::Pdf:
 
127
            case QPaintEngine::SVG:
 
128
                return false;
 
129
 
 
130
            default:;
 
131
        }
 
132
    }
 
133
 
 
134
    return true;
 
135
}
 
136
 
 
137
/*!
 
138
  Enable whether coordinates should be rounded, before they are painted
 
139
  to a paint engine that floors to integer values. For other paint engines
 
140
  this ( Pdf, SVG ), this flag has no effect.
 
141
  QwtPainter stores this flag only, the rounding itsself is done in 
 
142
  the painting code ( f.e the plot items ).
 
143
 
 
144
  The default setting is true. 
 
145
 
 
146
  \sa roundingAlignment(), isAligning()
 
147
*/
 
148
void QwtPainter::setRoundingAlignment( bool enable )
 
149
{
 
150
    d_roundingAlignment = enable;
 
151
}
 
152
 
 
153
/*!
 
154
  \brief En/Disable line splitting for the raster paint engine
 
155
 
 
156
  The raster paint engine paints polylines of many points
 
157
  much faster when they are splitted in smaller chunks.
 
158
 
 
159
  \sa polylineSplitting()
 
160
*/
 
161
void QwtPainter::setPolylineSplitting( bool enable )
 
162
{
 
163
    d_polylineSplitting = enable;
 
164
}
 
165
 
 
166
//! Wrapper for QPainter::drawPath()
 
167
void QwtPainter::drawPath( QPainter *painter, const QPainterPath &path )
 
168
{
 
169
    painter->drawPath( path );
 
170
}
 
171
 
 
172
//! Wrapper for QPainter::drawRect()
 
173
void QwtPainter::drawRect( QPainter *painter, double x, double y, double w, double h )
 
174
{
 
175
    drawRect( painter, QRectF( x, y, w, h ) );
 
176
}
 
177
 
 
178
//! Wrapper for QPainter::drawRect()
 
179
void QwtPainter::drawRect( QPainter *painter, const QRectF &rect )
 
180
{
 
181
    const QRectF r = rect;
 
182
 
 
183
    QRectF clipRect;
 
184
    const bool deviceClipping = isClippingNeeded( painter, clipRect );
 
185
 
 
186
    if ( deviceClipping )
 
187
    {
 
188
        if ( !clipRect.intersects( r ) )
 
189
            return;
 
190
 
 
191
        if ( !clipRect.contains( r ) )
 
192
        {
 
193
            fillRect( painter, r & clipRect, painter->brush() );
 
194
 
 
195
            painter->save();
 
196
            painter->setBrush( Qt::NoBrush );
 
197
            drawPolyline( painter, QPolygonF( r ) );
 
198
            painter->restore();
 
199
 
 
200
            return;
 
201
        }
 
202
    }
 
203
 
 
204
    painter->drawRect( r );
 
205
}
 
206
 
 
207
//! Wrapper for QPainter::fillRect()
 
208
void QwtPainter::fillRect( QPainter *painter,
 
209
    const QRectF &rect, const QBrush &brush )
 
210
{
 
211
    if ( !rect.isValid() )
 
212
        return;
 
213
 
 
214
    QRectF clipRect;
 
215
    const bool deviceClipping = isClippingNeeded( painter, clipRect );
 
216
 
 
217
    /*
 
218
      Performance of Qt4 is horrible for non trivial brushs. Without
 
219
      clipping expect minutes or hours for repainting large rects
 
220
      (might result from zooming)
 
221
    */
 
222
 
 
223
    if ( deviceClipping )
 
224
        clipRect &= painter->window();
 
225
    else
 
226
        clipRect = painter->window();
 
227
 
 
228
    if ( painter->hasClipping() )
 
229
        clipRect &= painter->clipRegion().boundingRect();
 
230
 
 
231
    QRectF r = rect;
 
232
    if ( deviceClipping )
 
233
        r = r.intersect( clipRect );
 
234
 
 
235
    if ( r.isValid() )
 
236
        painter->fillRect( r, brush );
 
237
}
 
238
 
 
239
//! Wrapper for QPainter::drawPie()
 
240
void QwtPainter::drawPie( QPainter *painter, const QRectF &rect,
 
241
    int a, int alen )
 
242
{
 
243
    QRectF clipRect;
 
244
    const bool deviceClipping = isClippingNeeded( painter, clipRect );
 
245
    if ( deviceClipping && !clipRect.contains( rect ) )
 
246
        return;
 
247
 
 
248
    painter->drawPie( rect, a, alen );
 
249
}
 
250
 
 
251
//! Wrapper for QPainter::drawEllipse()
 
252
void QwtPainter::drawEllipse( QPainter *painter, const QRectF &rect )
 
253
{
 
254
    QRectF clipRect;
 
255
    const bool deviceClipping = isClippingNeeded( painter, clipRect );
 
256
 
 
257
    if ( deviceClipping && !clipRect.contains( rect ) )
 
258
        return;
 
259
 
 
260
    painter->drawEllipse( rect );
 
261
}
 
262
 
 
263
//! Wrapper for QPainter::drawText()
 
264
void QwtPainter::drawText( QPainter *painter, double x, double y,
 
265
        const QString &text )
 
266
{
 
267
    drawText( painter, QPointF( x, y ), text );
 
268
}
 
269
 
 
270
//! Wrapper for QPainter::drawText()
 
271
void QwtPainter::drawText( QPainter *painter, const QPointF &pos,
 
272
        const QString &text )
 
273
{
 
274
    QRectF clipRect;
 
275
    const bool deviceClipping = isClippingNeeded( painter, clipRect );
 
276
 
 
277
    if ( deviceClipping && !clipRect.contains( pos ) )
 
278
        return;
 
279
 
 
280
 
 
281
    painter->save();
 
282
    unscaleFont( painter );
 
283
    painter->drawText( pos, text );
 
284
    painter->restore();
 
285
}
 
286
 
 
287
//! Wrapper for QPainter::drawText()
 
288
void QwtPainter::drawText( QPainter *painter,
 
289
    double x, double y, double w, double h,
 
290
    int flags, const QString &text )
 
291
{
 
292
    drawText( painter, QRectF( x, y, w, h ), flags, text );
 
293
}
 
294
 
 
295
//! Wrapper for QPainter::drawText()
 
296
void QwtPainter::drawText( QPainter *painter, const QRectF &rect,
 
297
        int flags, const QString &text )
 
298
{
 
299
    painter->save();
 
300
    unscaleFont( painter );
 
301
    painter->drawText( rect, flags, text );
 
302
    painter->restore();
 
303
}
 
304
 
 
305
#ifndef QT_NO_RICHTEXT
 
306
 
 
307
/*!
 
308
  Draw a text document into a rectangle
 
309
 
 
310
  \param painter Painter
 
311
  \param rect Traget rectangle
 
312
  \param flags Alignments/Text flags, see QPainter::drawText()
 
313
  \param text Text document
 
314
*/
 
315
void QwtPainter::drawSimpleRichText( QPainter *painter, const QRectF &rect,
 
316
    int flags, const QTextDocument &text )
 
317
{
 
318
    QTextDocument *txt = text.clone();
 
319
 
 
320
    painter->save();
 
321
 
 
322
    painter->setFont( txt->defaultFont() );
 
323
    unscaleFont( painter );
 
324
 
 
325
    txt->setDefaultFont( painter->font() );
 
326
    txt->setPageSize( QSizeF( rect.width(), QWIDGETSIZE_MAX ) );
 
327
 
 
328
    QAbstractTextDocumentLayout* layout = txt->documentLayout();
 
329
 
 
330
    const double height = layout->documentSize().height();
 
331
    double y = rect.y();
 
332
    if ( flags & Qt::AlignBottom )
 
333
        y += ( rect.height() - height );
 
334
    else if ( flags & Qt::AlignVCenter )
 
335
        y += ( rect.height() - height ) / 2;
 
336
 
 
337
    QAbstractTextDocumentLayout::PaintContext context;
 
338
    context.palette.setColor( QPalette::Text, painter->pen().color() );
 
339
 
 
340
    painter->translate( rect.x(), y );
 
341
    layout->draw( painter, context );
 
342
 
 
343
    painter->restore();
 
344
    delete txt;
 
345
}
 
346
 
 
347
#endif // !QT_NO_RICHTEXT
 
348
 
 
349
 
 
350
//! Wrapper for QPainter::drawLine()
 
351
void QwtPainter::drawLine( QPainter *painter,
 
352
    const QPointF &p1, const QPointF &p2 )
 
353
{
 
354
    QRectF clipRect;
 
355
    const bool deviceClipping = isClippingNeeded( painter, clipRect );
 
356
 
 
357
    if ( deviceClipping &&
 
358
        !( clipRect.contains( p1 ) && clipRect.contains( p2 ) ) )
 
359
    {
 
360
        QPolygonF polygon;
 
361
        polygon += p1;
 
362
        polygon += p2;
 
363
        drawPolyline( painter, polygon );
 
364
        return;
 
365
    }
 
366
 
 
367
    painter->drawLine( p1, p2 );
 
368
}
 
369
 
 
370
//! Wrapper for QPainter::drawPolygon()
 
371
void QwtPainter::drawPolygon( QPainter *painter, const QPolygonF &polygon )
 
372
{
 
373
    QRectF clipRect;
 
374
    const bool deviceClipping = isClippingNeeded( painter, clipRect );
 
375
 
 
376
    QPolygonF cpa = polygon;
 
377
    if ( deviceClipping )
 
378
        cpa = QwtClipper::clipPolygonF( clipRect, polygon );
 
379
 
 
380
    painter->drawPolygon( cpa );
 
381
}
 
382
 
 
383
//! Wrapper for QPainter::drawPolyline()
 
384
void QwtPainter::drawPolyline( QPainter *painter, const QPolygonF &polygon )
 
385
{
 
386
    QRectF clipRect;
 
387
    const bool deviceClipping = isClippingNeeded( painter, clipRect );
 
388
 
 
389
    QPolygonF cpa = polygon;
 
390
    if ( deviceClipping )
 
391
        cpa = QwtClipper::clipPolygonF( clipRect, cpa );
 
392
 
 
393
    ::drawPolyline( painter,
 
394
        cpa.constData(), cpa.size(), d_polylineSplitting );
 
395
}
 
396
 
 
397
//! Wrapper for QPainter::drawPolyline()
 
398
void QwtPainter::drawPolyline( QPainter *painter,
 
399
    const QPointF *points, int pointCount )
 
400
{
 
401
    QRectF clipRect;
 
402
    const bool deviceClipping = isClippingNeeded( painter, clipRect );
 
403
 
 
404
    if ( deviceClipping )
 
405
    {
 
406
        QPolygonF polygon( pointCount );
 
407
        qMemCopy( polygon.data(), points, pointCount * sizeof( QPointF ) );
 
408
 
 
409
        polygon = QwtClipper::clipPolygonF( clipRect, polygon );
 
410
        ::drawPolyline( painter,
 
411
            polygon.constData(), polygon.size(), d_polylineSplitting );
 
412
    }
 
413
    else
 
414
        ::drawPolyline( painter, points, pointCount, d_polylineSplitting );
 
415
}
 
416
 
 
417
//! Wrapper for QPainter::drawPoint()
 
418
void QwtPainter::drawPoint( QPainter *painter, const QPointF &pos )
 
419
{
 
420
    QRectF clipRect;
 
421
    const bool deviceClipping = isClippingNeeded( painter, clipRect );
 
422
 
 
423
    if ( deviceClipping && !clipRect.contains( pos ) )
 
424
        return;
 
425
 
 
426
    painter->drawPoint( pos );
 
427
}
 
428
 
 
429
//! Wrapper for QPainter::drawImage()
 
430
void QwtPainter::drawImage( QPainter *painter,
 
431
    const QRectF &rect, const QImage &image )
 
432
{
 
433
    const QRect alignedRect = rect.toAlignedRect();
 
434
 
 
435
    if ( alignedRect != rect )
 
436
    {
 
437
        const QRectF clipRect = rect.adjusted( 0.0, 0.0, -1.0, -1.0 );
 
438
 
 
439
        painter->save();
 
440
        painter->setClipRect( clipRect, Qt::IntersectClip );
 
441
        painter->drawImage( alignedRect, image );
 
442
        painter->restore();
 
443
    }
 
444
    else
 
445
    {
 
446
        painter->drawImage( alignedRect, image );
 
447
    }
 
448
}
 
449
 
 
450
//! Wrapper for QPainter::drawPixmap()
 
451
void QwtPainter::drawPixmap( QPainter *painter,
 
452
    const QRectF &rect, const QPixmap &pixmap )
 
453
{
 
454
    const QRect alignedRect = rect.toAlignedRect();
 
455
 
 
456
    if ( alignedRect != rect )
 
457
    {
 
458
        const QRectF clipRect = rect.adjusted( 0.0, 0.0, -1.0, -1.0 );
 
459
 
 
460
        painter->save();
 
461
        painter->setClipRect( clipRect, Qt::IntersectClip );
 
462
        painter->drawPixmap( alignedRect, pixmap );
 
463
        painter->restore();
 
464
    }
 
465
    else
 
466
    {
 
467
        painter->drawPixmap( alignedRect, pixmap );
 
468
    }
 
469
}
 
470
 
 
471
//! Draw a focus rectangle on a widget using its style.
 
472
void QwtPainter::drawFocusRect( QPainter *painter, QWidget *widget )
 
473
{
 
474
    drawFocusRect( painter, widget, widget->rect() );
 
475
}
 
476
 
 
477
//! Draw a focus rectangle on a widget using its style.
 
478
void QwtPainter::drawFocusRect( QPainter *painter, QWidget *widget,
 
479
    const QRect &rect )
 
480
{
 
481
    QStyleOptionFocusRect opt;
 
482
    opt.init( widget );
 
483
    opt.rect = rect;
 
484
    opt.state |= QStyle::State_HasFocus;
 
485
 
 
486
    widget->style()->drawPrimitive( QStyle::PE_FrameFocusRect,
 
487
        &opt, painter, widget );
 
488
}
 
489
 
 
490
/*!
 
491
  Draw a frame with rounded borders
 
492
 
 
493
  \param painter Painter
 
494
  \param rect Frame rectangle
 
495
  \param xRadius x-radius of the ellipses defining the corners
 
496
  \param yRadius y-radius of the ellipses defining the corners
 
497
  \param palette QPalette::WindowText is used for plain borders
 
498
                 QPalette::Dark and QPalette::Light for raised
 
499
                 or sunken borders
 
500
  \param lineWidth Line width
 
501
  \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow
 
502
*/
 
503
 
 
504
void QwtPainter::drawRoundedFrame( QPainter *painter, 
 
505
    const QRectF &rect, double xRadius, double yRadius, 
 
506
    const QPalette &palette, int lineWidth, int frameStyle )
 
507
{
 
508
    painter->save();
 
509
    painter->setRenderHint( QPainter::Antialiasing, true );
 
510
    painter->setBrush( Qt::NoBrush );
 
511
 
 
512
    double lw2 = lineWidth * 0.5;
 
513
    QRectF r = rect.adjusted( lw2, lw2, -lw2, -lw2 );
 
514
 
 
515
    QPainterPath path;
 
516
    path.addRoundedRect( r, xRadius, yRadius );
 
517
 
 
518
    enum Style
 
519
    {
 
520
        Plain,
 
521
        Sunken,
 
522
        Raised
 
523
    };
 
524
 
 
525
    Style style = Plain;
 
526
    if ( (frameStyle & QFrame::Sunken) == QFrame::Sunken )
 
527
        style = Sunken;
 
528
    else if ( (frameStyle & QFrame::Raised) == QFrame::Raised )
 
529
        style = Raised;
 
530
 
 
531
    if ( style != Plain && path.elementCount() == 17 )
 
532
    {
 
533
        // move + 4 * ( cubicTo + lineTo )
 
534
        QPainterPath pathList[8];
 
535
        
 
536
        for ( int i = 0; i < 4; i++ )
 
537
        {
 
538
            const int j = i * 4 + 1;
 
539
            
 
540
            pathList[ 2 * i ].moveTo(
 
541
                path.elementAt(j - 1).x, path.elementAt( j - 1 ).y
 
542
            );  
 
543
            
 
544
            pathList[ 2 * i ].cubicTo(
 
545
                path.elementAt(j + 0).x, path.elementAt(j + 0).y,
 
546
                path.elementAt(j + 1).x, path.elementAt(j + 1).y,
 
547
                path.elementAt(j + 2).x, path.elementAt(j + 2).y );
 
548
                
 
549
            pathList[ 2 * i + 1 ].moveTo(
 
550
                path.elementAt(j + 2).x, path.elementAt(j + 2).y
 
551
            );  
 
552
            pathList[ 2 * i + 1 ].lineTo(
 
553
                path.elementAt(j + 3).x, path.elementAt(j + 3).y
 
554
            );  
 
555
        }   
 
556
 
 
557
        QColor c1( palette.color( QPalette::Dark ) );
 
558
        QColor c2( palette.color( QPalette::Light ) );
 
559
 
 
560
        if ( style == Raised )
 
561
            qSwap( c1, c2 );
 
562
 
 
563
        for ( int i = 0; i < 4; i++ )
 
564
        {
 
565
            QRectF r = pathList[2 * i].controlPointRect();
 
566
 
 
567
            QPen arcPen;
 
568
            arcPen.setWidth( lineWidth );
 
569
 
 
570
            QPen linePen;
 
571
            linePen.setWidth( lineWidth );
 
572
 
 
573
            switch( i )
 
574
            {
 
575
                case 0:
 
576
                {
 
577
                    arcPen.setColor( c1 );
 
578
                    linePen.setColor( c1 );
 
579
                    break;
 
580
                }
 
581
                case 1:
 
582
                {
 
583
                    QLinearGradient gradient;
 
584
                    gradient.setStart( r.topLeft() );
 
585
                    gradient.setFinalStop( r.bottomRight() );
 
586
                    gradient.setColorAt( 0.0, c1 );
 
587
                    gradient.setColorAt( 1.0, c2 );
 
588
 
 
589
                    arcPen.setBrush( gradient );
 
590
                    linePen.setColor( c2 );
 
591
                    break;
 
592
                }
 
593
                case 2:
 
594
                {
 
595
                    arcPen.setColor( c2 );
 
596
                    linePen.setColor( c2 );
 
597
                    break;
 
598
                }
 
599
                case 3:
 
600
                {
 
601
                    QLinearGradient gradient;
 
602
 
 
603
                    gradient.setStart( r.bottomRight() );
 
604
                    gradient.setFinalStop( r.topLeft() );
 
605
                    gradient.setColorAt( 0.0, c2 );
 
606
                    gradient.setColorAt( 1.0, c1 );
 
607
 
 
608
                    arcPen.setBrush( gradient );
 
609
                    linePen.setColor( c1 );
 
610
                    break;
 
611
                }
 
612
            }
 
613
 
 
614
 
 
615
            painter->setPen( arcPen );
 
616
            painter->drawPath( pathList[ 2 * i] );
 
617
 
 
618
            painter->setPen( linePen );
 
619
            painter->drawPath( pathList[ 2 * i + 1] );
 
620
        }
 
621
    }
 
622
    else
 
623
    {
 
624
        QPen pen( palette.color( QPalette::WindowText ), lineWidth );
 
625
        painter->setPen( pen );
 
626
        painter->drawPath( path );
 
627
    }
 
628
 
 
629
    painter->restore();
 
630
}
 
631
 
 
632
/*!
 
633
  Draw a color bar into a rectangle
 
634
 
 
635
  \param painter Painter
 
636
  \param colorMap Color map
 
637
  \param interval Value range
 
638
  \param scaleMap Scale map
 
639
  \param orientation Orientation
 
640
  \param rect Traget rectangle
 
641
*/
 
642
void QwtPainter::drawColorBar( QPainter *painter,
 
643
        const QwtColorMap &colorMap, const QwtInterval &interval,
 
644
        const QwtScaleMap &scaleMap, Qt::Orientation orientation,
 
645
        const QRectF &rect )
 
646
{
 
647
    QVector<QRgb> colorTable;
 
648
    if ( colorMap.format() == QwtColorMap::Indexed )
 
649
        colorTable = colorMap.colorTable( interval );
 
650
 
 
651
    QColor c;
 
652
 
 
653
    const QRect devRect = rect.toAlignedRect();
 
654
 
 
655
    /*
 
656
      We paint to a pixmap first to have something scalable for printing
 
657
      ( f.e. in a Pdf document )
 
658
     */
 
659
 
 
660
    QPixmap pixmap( devRect.size() );
 
661
    QPainter pmPainter( &pixmap );
 
662
    pmPainter.translate( -devRect.x(), -devRect.y() );
 
663
 
 
664
    if ( orientation == Qt::Horizontal )
 
665
    {
 
666
        QwtScaleMap sMap = scaleMap;
 
667
        sMap.setPaintInterval( rect.left(), rect.right() );
 
668
 
 
669
        for ( int x = devRect.left(); x <= devRect.right(); x++ )
 
670
        {
 
671
            const double value = sMap.invTransform( x );
 
672
 
 
673
            if ( colorMap.format() == QwtColorMap::RGB )
 
674
                c.setRgb( colorMap.rgb( interval, value ) );
 
675
            else
 
676
                c = colorTable[colorMap.colorIndex( interval, value )];
 
677
 
 
678
            pmPainter.setPen( c );
 
679
            pmPainter.drawLine( x, devRect.top(), x, devRect.bottom() );
 
680
        }
 
681
    }
 
682
    else // Vertical
 
683
    {
 
684
        QwtScaleMap sMap = scaleMap;
 
685
        sMap.setPaintInterval( rect.bottom(), rect.top() );
 
686
 
 
687
        for ( int y = devRect.top(); y <= devRect.bottom(); y++ )
 
688
        {
 
689
            const double value = sMap.invTransform( y );
 
690
 
 
691
            if ( colorMap.format() == QwtColorMap::RGB )
 
692
                c.setRgb( colorMap.rgb( interval, value ) );
 
693
            else
 
694
                c = colorTable[colorMap.colorIndex( interval, value )];
 
695
 
 
696
            pmPainter.setPen( c );
 
697
            pmPainter.drawLine( devRect.left(), y, devRect.right(), y );
 
698
        }
 
699
    }
 
700
    pmPainter.end();
 
701
 
 
702
    drawPixmap( painter, rect, pixmap );
 
703
}