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

« back to all changes in this revision

Viewing changes to qwt/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
 
// vim: expandtab
11
 
 
12
 
#include <qwindowdefs.h>
13
 
#include <qwidget.h>
14
 
#include <qrect.h>
15
 
#include <qpainter.h>
16
 
#include <qpalette.h>
17
 
#include <qpaintdevice.h>
18
 
#include <qpixmap.h>
19
 
#include <qstyle.h>
20
 
#if QT_VERSION < 0x040000
21
 
#include <qsimplerichtext.h>
22
 
#else
23
 
#include <qtextdocument.h>
24
 
#include <qabstracttextdocumentlayout.h>
25
 
#include <qstyleoption.h>
26
 
#include <qpaintengine.h>
27
 
#endif
28
 
 
29
 
#include "qwt_math.h"
30
 
#include "qwt_clipper.h"
31
 
#include "qwt_color_map.h"
32
 
#include "qwt_scale_map.h"
33
 
#include "qwt_painter.h"
34
 
 
35
 
QwtMetricsMap QwtPainter::d_metricsMap;
36
 
 
37
 
#if defined(Q_WS_X11)
38
 
bool QwtPainter::d_deviceClipping = true;
39
 
#else
40
 
bool QwtPainter::d_deviceClipping = false;
41
 
#endif
42
 
 
43
 
#if QT_VERSION < 0x040000
44
 
bool QwtPainter::d_SVGMode = false;
45
 
#endif
46
 
 
47
 
static inline bool isClippingNeeded(const QPainter *painter, QRect &clipRect)
48
 
{
49
 
    bool doClipping = false;
50
 
#if QT_VERSION >= 0x040000
51
 
    const QPaintEngine *pe = painter->paintEngine();
52
 
    if ( pe && pe->type() == QPaintEngine::SVG )
53
 
#else
54
 
    if ( painter->device()->devType() == QInternal::Picture )
55
 
#endif
56
 
    {
57
 
        // The SVG paint engine ignores any clipping,
58
 
 
59
 
        if ( painter->hasClipping() )
60
 
        {
61
 
            doClipping = true;
62
 
            clipRect = painter->clipRegion().boundingRect();
63
 
        }
64
 
    }
65
 
 
66
 
    if ( QwtPainter::deviceClipping() )
67
 
    {
68
 
        if (painter->device()->devType() == QInternal::Widget ||
69
 
          painter->device()->devType() == QInternal::Pixmap )
70
 
        {
71
 
            if ( doClipping )
72
 
            {
73
 
                clipRect &= QwtPainter::deviceClipRect();
74
 
            }
75
 
            else
76
 
            {
77
 
                doClipping = true;
78
 
                clipRect = QwtPainter::deviceClipRect();
79
 
            }
80
 
        }
81
 
    }
82
 
 
83
 
    return doClipping;
84
 
}
85
 
 
86
 
/*!
87
 
  \brief En/Disable device clipping. 
88
 
 
89
 
  On X11 the default for device clipping is enabled, 
90
 
  otherwise it is disabled.
91
 
  \sa QwtPainter::deviceClipping()
92
 
*/
93
 
void QwtPainter::setDeviceClipping(bool enable)
94
 
{
95
 
    d_deviceClipping = enable;
96
 
}
97
 
 
98
 
/*!
99
 
  Returns rect for device clipping
100
 
  \sa QwtPainter::setDeviceClipping()
101
 
*/
102
 
const QRect &QwtPainter::deviceClipRect()
103
 
{
104
 
    static QRect clip;
105
 
 
106
 
    if ( !clip.isValid() )
107
 
    {
108
 
        clip.setCoords(QWT_COORD_MIN, QWT_COORD_MIN,
109
 
            QWT_COORD_MAX, QWT_COORD_MAX);
110
 
    }
111
 
    return clip;
112
 
}
113
 
 
114
 
#if QT_VERSION < 0x040000 
115
 
 
116
 
/*!
117
 
  \brief En/Disable SVG mode. 
118
 
 
119
 
  When saving a QPicture to a SVG some texts are misaligned.
120
 
  In SVGMode QwtPainter tries to fix them. 
121
 
 
122
 
  \sa QwtPainter::isSVGMode()
123
 
  \note A QPicture that is created in SVG mode and saved to the
124
 
        native format, will be misaligned. Also it is not possible to
125
 
        reload and play a SVG document, that was created in SVG mode.
126
 
*/
127
 
void QwtPainter::setSVGMode(bool on)
128
 
{
129
 
    d_SVGMode = on;
130
 
}
131
 
 
132
 
bool QwtPainter::isSVGMode()
133
 
{
134
 
    return d_SVGMode;
135
 
}
136
 
 
137
 
#endif // QT_VERSION < 0x040000
138
 
 
139
 
/*!
140
 
  Scale all QwtPainter drawing operations using the ratio
141
 
  QwtPaintMetrics(from).logicalDpiX() / QwtPaintMetrics(to).logicalDpiX()
142
 
  and QwtPaintMetrics(from).logicalDpiY() / QwtPaintMetrics(to).logicalDpiY()
143
 
 
144
 
  \sa QwtPainter::resetScaleMetrics(), QwtPainter::scaleMetricsX(),
145
 
        QwtPainter::scaleMetricsY()
146
 
*/
147
 
void QwtPainter::setMetricsMap(const QPaintDevice *layout,
148
 
    const QPaintDevice *device)
149
 
{
150
 
    d_metricsMap.setMetrics(layout, device);
151
 
}
152
 
 
153
 
/*! 
154
 
  Change the metrics map 
155
 
  \sa QwtPainter::resetMetricsMap(), QwtPainter::metricsMap()
156
 
*/
157
 
void QwtPainter::setMetricsMap(const QwtMetricsMap &map)
158
 
{
159
 
    d_metricsMap = map;
160
 
}
161
 
 
162
 
/*! 
163
 
   Reset the metrics map to the ratio 1:1
164
 
   \sa QwtPainter::setMetricsMap(), QwtPainter::resetMetricsMap()
165
 
*/
166
 
void QwtPainter::resetMetricsMap()
167
 
{
168
 
    d_metricsMap = QwtMetricsMap();
169
 
}
170
 
 
171
 
/*!
172
 
  \return Metrics map
173
 
*/
174
 
const QwtMetricsMap &QwtPainter::metricsMap()
175
 
{
176
 
    return d_metricsMap;
177
 
}
178
 
 
179
 
/*!
180
 
    Wrapper for QPainter::setClipRect()
181
 
*/
182
 
void QwtPainter::setClipRect(QPainter *painter, const QRect &rect)
183
 
{
184
 
    painter->setClipRect(d_metricsMap.layoutToDevice(rect, painter));
185
 
}
186
 
 
187
 
/*!
188
 
    Wrapper for QPainter::drawRect()
189
 
*/
190
 
void QwtPainter::drawRect(QPainter *painter, int x, int y, int w, int h) 
191
 
{
192
 
    drawRect(painter, QRect(x, y, w, h));
193
 
}
194
 
 
195
 
/*!
196
 
    Wrapper for QPainter::drawRect()
197
 
*/
198
 
void QwtPainter::drawRect(QPainter *painter, const QRect &rect) 
199
 
{
200
 
    const QRect r = d_metricsMap.layoutToDevice(rect, painter);
201
 
 
202
 
    QRect clipRect;
203
 
    const bool deviceClipping = isClippingNeeded(painter, clipRect);
204
 
 
205
 
    if ( deviceClipping )
206
 
    {
207
 
        if ( !clipRect.intersects(r) )
208
 
            return;
209
 
 
210
 
        if ( !clipRect.contains(r) )
211
 
        {
212
 
            fillRect(painter, r & clipRect, painter->brush());
213
 
 
214
 
            int pw = painter->pen().width();
215
 
            pw = pw % 2 + pw / 2;
216
 
 
217
 
            QwtPolygon pa(5);
218
 
            pa.setPoint(0, r.left(), r.top());
219
 
            pa.setPoint(1, r.right() - pw, r.top());
220
 
            pa.setPoint(2, r.right() - pw, r.bottom() - pw);
221
 
            pa.setPoint(3, r.left(), r.bottom() - pw);
222
 
            pa.setPoint(4, r.left(), r.top());
223
 
 
224
 
            painter->save();
225
 
            painter->setBrush(Qt::NoBrush);
226
 
            drawPolyline(painter, pa);
227
 
            painter->restore();
228
 
 
229
 
            return;
230
 
        }
231
 
    }
232
 
 
233
 
    painter->drawRect(r);
234
 
}
235
 
 
236
 
/*!
237
 
    Wrapper for QPainter::fillRect()
238
 
*/
239
 
void QwtPainter::fillRect(QPainter *painter, 
240
 
    const QRect &rect, const QBrush &brush)
241
 
{
242
 
    if ( !rect.isValid() )
243
 
        return;
244
 
 
245
 
    QRect clipRect;
246
 
    const bool deviceClipping = isClippingNeeded(painter, clipRect);
247
 
 
248
 
#if QT_VERSION >= 0x040000
249
 
    /*
250
 
      Performance of Qt4 is horrible for non trivial brushs. Without
251
 
      clipping expect minutes or hours for repainting large rects
252
 
      (might result from zooming)
253
 
    */
254
 
 
255
 
    if ( deviceClipping )
256
 
        clipRect &= painter->window();
257
 
    else
258
 
        clipRect = painter->window();
259
 
 
260
 
    if ( painter->hasClipping() )
261
 
        clipRect &= painter->clipRegion().boundingRect();
262
 
#endif
263
 
 
264
 
    QRect r = d_metricsMap.layoutToDevice(rect, painter);
265
 
    if ( deviceClipping )
266
 
        r = r.intersect(clipRect);
267
 
 
268
 
    if ( r.isValid() )
269
 
        painter->fillRect(r, brush);
270
 
}
271
 
 
272
 
/*!
273
 
    Wrapper for QPainter::drawPie()
274
 
*/
275
 
void QwtPainter::drawPie(QPainter *painter, const QRect &rect, 
276
 
    int a, int alen)
277
 
{
278
 
    const QRect r = d_metricsMap.layoutToDevice(rect, painter);
279
 
 
280
 
    QRect clipRect;
281
 
    const bool deviceClipping = isClippingNeeded(painter, clipRect);
282
 
    if ( deviceClipping && !clipRect.contains(r) )
283
 
        return;
284
 
 
285
 
    painter->drawPie(r, a, alen);
286
 
}
287
 
 
288
 
/*!
289
 
    Wrapper for QPainter::drawEllipse()
290
 
*/
291
 
void QwtPainter::drawEllipse(QPainter *painter, const QRect &rect)
292
 
{
293
 
    QRect r = d_metricsMap.layoutToDevice(rect, painter);
294
 
 
295
 
    QRect clipRect;
296
 
    const bool deviceClipping = isClippingNeeded(painter, clipRect);
297
 
 
298
 
    if ( deviceClipping && !clipRect.contains(r) )
299
 
        return;
300
 
 
301
 
#if QT_VERSION >= 0x040000
302
 
    if ( painter->pen().style() != Qt::NoPen &&
303
 
        painter->pen().color().isValid() )
304
 
    {
305
 
        // Qt4 adds the pen to the rect, Qt3 not.
306
 
        int pw = painter->pen().width();
307
 
        if ( pw == 0 )
308
 
            pw = 1;
309
 
 
310
 
        r.setWidth(r.width() - pw);
311
 
        r.setHeight(r.height() - pw);
312
 
    }
313
 
#endif
314
 
 
315
 
    painter->drawEllipse(r);
316
 
}
317
 
 
318
 
/*!
319
 
    Wrapper for QPainter::drawText()
320
 
*/
321
 
void QwtPainter::drawText(QPainter *painter, int x, int y, 
322
 
        const QString &text)
323
 
{
324
 
    drawText(painter, QPoint(x, y), text);
325
 
}
326
 
 
327
 
/*!
328
 
    Wrapper for QPainter::drawText()
329
 
*/
330
 
void QwtPainter::drawText(QPainter *painter, const QPoint &pos, 
331
 
        const QString &text)
332
 
{
333
 
    const QPoint p = d_metricsMap.layoutToDevice(pos, painter);
334
 
 
335
 
    QRect clipRect;
336
 
    const bool deviceClipping = isClippingNeeded(painter, clipRect);
337
 
 
338
 
    if ( deviceClipping && !clipRect.contains(p) )
339
 
        return;
340
 
 
341
 
    painter->drawText(p, text);
342
 
}
343
 
 
344
 
/*!
345
 
    Wrapper for QPainter::drawText()
346
 
*/
347
 
void QwtPainter::drawText(QPainter *painter, int x, int y, int w, int h, 
348
 
        int flags, const QString &text)
349
 
{
350
 
    drawText(painter, QRect(x, y, w, h), flags, text);
351
 
}
352
 
 
353
 
/*!
354
 
    Wrapper for QPainter::drawText()
355
 
*/
356
 
void QwtPainter::drawText(QPainter *painter, const QRect &rect, 
357
 
        int flags, const QString &text)
358
 
{
359
 
    QRect textRect = d_metricsMap.layoutToDevice(rect, painter);
360
 
#if QT_VERSION < 0x040000
361
 
    if ( d_SVGMode &&
362
 
        ( flags == 0 || flags & Qt::AlignVCenter ) 
363
 
        && painter->device()->devType() == QInternal::Picture )
364
 
    {
365
 
        /*
366
 
            Qt3 misalignes texts, when saving a text
367
 
            to a SVG image. 
368
 
         */
369
 
        textRect.setY(textRect.y() - painter->fontMetrics().height() / 4);
370
 
    }
371
 
#endif
372
 
    painter->drawText(textRect, flags, text);
373
 
}
374
 
 
375
 
#ifndef QT_NO_RICHTEXT
376
 
 
377
 
/*!
378
 
  Wrapper for QSimpleRichText::draw()
379
 
*/
380
 
#if QT_VERSION < 0x040000
381
 
 
382
 
void QwtPainter::drawSimpleRichText(QPainter *painter, const QRect &rect,
383
 
    int flags, QSimpleRichText &text)
384
 
{
385
 
    QColorGroup cg;
386
 
    cg.setColor(QColorGroup::Text, painter->pen().color());
387
 
 
388
 
    const QRect scaledRect = d_metricsMap.layoutToDevice(rect, painter);
389
 
 
390
 
    text.setWidth(painter, scaledRect.width());
391
 
 
392
 
    // QSimpleRichText is Qt::AlignTop by default
393
 
 
394
 
    int y = scaledRect.y();
395
 
    if (flags & Qt::AlignBottom)
396
 
        y += (scaledRect.height() - text.height());
397
 
    else if (flags & Qt::AlignVCenter)
398
 
        y += (scaledRect.height() - text.height())/2;
399
 
 
400
 
    text.draw(painter, scaledRect.x(), y, scaledRect, cg);
401
 
}
402
 
#else
403
 
void QwtPainter::drawSimpleRichText(QPainter *painter, const QRect &rect,
404
 
    int flags, QTextDocument &text)
405
 
{
406
 
    const QRect scaledRect = d_metricsMap.layoutToDevice(rect, painter);
407
 
    text.setPageSize(QSize(scaledRect.width(), QWIDGETSIZE_MAX));
408
 
 
409
 
    QAbstractTextDocumentLayout* layout = text.documentLayout();
410
 
 
411
 
    const int height = qRound(layout->documentSize().height());
412
 
    int y = scaledRect.y();
413
 
    if (flags & Qt::AlignBottom)
414
 
        y += (scaledRect.height() - height);
415
 
    else if (flags & Qt::AlignVCenter)
416
 
        y += (scaledRect.height() - height)/2;
417
 
 
418
 
    QAbstractTextDocumentLayout::PaintContext context;
419
 
    context.palette.setColor(QPalette::Text, painter->pen().color());
420
 
 
421
 
    painter->save();
422
 
 
423
 
    painter->translate(scaledRect.x(), y);
424
 
    layout->draw(painter, context);
425
 
 
426
 
    painter->restore();
427
 
}
428
 
#endif
429
 
 
430
 
#endif // !QT_NO_RICHTEXT
431
 
 
432
 
 
433
 
/*!
434
 
  Wrapper for QPainter::drawLine()
435
 
*/
436
 
void QwtPainter::drawLine(QPainter *painter, int x1, int y1, int x2, int y2)
437
 
{
438
 
    QRect clipRect;
439
 
    const bool deviceClipping = isClippingNeeded(painter, clipRect);
440
 
 
441
 
    if ( deviceClipping && 
442
 
        !(clipRect.contains(x1, y1) && clipRect.contains(x2, y2)) )
443
 
    {
444
 
        QwtPolygon pa(2);
445
 
        pa.setPoint(0, x1, y1);
446
 
        pa.setPoint(1, x2, y2);
447
 
        drawPolyline(painter, pa);
448
 
        return;
449
 
    }
450
 
 
451
 
    if ( d_metricsMap.isIdentity() )
452
 
    {
453
 
#if QT_VERSION >= 0x030200 && QT_VERSION < 0x040000
454
 
        if ( !painter->device()->isExtDev() )
455
 
#endif
456
 
        {
457
 
            painter->drawLine(x1, y1, x2, y2);
458
 
            return;
459
 
        }
460
 
    }
461
 
 
462
 
    const QPoint p1 = d_metricsMap.layoutToDevice(QPoint(x1, y1));
463
 
    const QPoint p2 = d_metricsMap.layoutToDevice(QPoint(x2, y2));
464
 
 
465
 
#if QT_VERSION >= 0x030200 && QT_VERSION < 0x040000
466
 
    if ( painter->device()->isExtDev() )
467
 
    {
468
 
        // Strange: the postscript driver of QPrinter adds an offset 
469
 
        // of 0.5 to the start/endpoint when using drawLine, but not
470
 
        // for lines painted with drawLineSegments.
471
 
 
472
 
        QwtPolygon pa(2);
473
 
        pa.setPoint(0, p1);
474
 
        pa.setPoint(1, p2);
475
 
        painter->drawLineSegments(pa);
476
 
    }
477
 
    else
478
 
        painter->drawLine(p1, p2);
479
 
#else
480
 
    painter->drawLine(p1, p2);
481
 
#endif
482
 
}
483
 
 
484
 
/*!
485
 
  Wrapper for QPainter::drawPolygon()
486
 
*/
487
 
void QwtPainter::drawPolygon(QPainter *painter, const QwtPolygon &pa)
488
 
{
489
 
    QRect clipRect;
490
 
    const bool deviceClipping = isClippingNeeded(painter, clipRect);
491
 
 
492
 
    QwtPolygon cpa = d_metricsMap.layoutToDevice(pa);
493
 
    if ( deviceClipping )
494
 
    {
495
 
#ifdef __GNUC__
496
 
#endif
497
 
        cpa = QwtClipper::clipPolygon(clipRect, cpa);
498
 
    }
499
 
    painter->drawPolygon(cpa);
500
 
}
501
 
 
502
 
/*!
503
 
    Wrapper for QPainter::drawPolyline()
504
 
*/
505
 
void QwtPainter::drawPolyline(QPainter *painter, const QwtPolygon &pa)
506
 
{
507
 
    QRect clipRect;
508
 
    const bool deviceClipping = isClippingNeeded(painter, clipRect);
509
 
 
510
 
    QwtPolygon cpa = d_metricsMap.layoutToDevice(pa);
511
 
    if ( deviceClipping )
512
 
        cpa = QwtClipper::clipPolygon(clipRect, cpa);
513
 
 
514
 
#if QT_VERSION >= 0x040000 && QT_VERSION < 0x040400
515
 
    bool doSplit = false;
516
 
 
517
 
    const QPaintEngine *pe = painter->paintEngine();
518
 
    if ( pe && pe->type() == QPaintEngine::Raster &&
519
 
        painter->pen().width() >= 2 )
520
 
    {
521
 
        /*
522
 
            The raster paint engine seems to use some algo with O(n*n).
523
 
            ( Qt 4.3 is better than Qt 4.2, but remains unacceptable)
524
 
            To work around this problem, we have to split the polygon into
525
 
            smaller pieces.
526
 
         */
527
 
        doSplit = true;
528
 
    }
529
 
 
530
 
    if ( doSplit )
531
 
    {
532
 
        const int numPoints = cpa.size();
533
 
        const QPoint *points = cpa.data();
534
 
 
535
 
        const int splitSize = 20;
536
 
        for ( int i = 0; i < numPoints; i += splitSize )
537
 
        {
538
 
            const int n = qwtMin(splitSize + 1, cpa.size() - i);
539
 
            painter->drawPolyline(points + i, n);
540
 
        }
541
 
    }
542
 
    else
543
 
#endif
544
 
        painter->drawPolyline(cpa);
545
 
}
546
 
 
547
 
/*!
548
 
    Wrapper for QPainter::drawPoint()
549
 
*/
550
 
 
551
 
void QwtPainter::drawPoint(QPainter *painter, int x, int y)
552
 
{
553
 
    QRect clipRect;
554
 
    const bool deviceClipping = isClippingNeeded(painter, clipRect);
555
 
 
556
 
    const QPoint pos = d_metricsMap.layoutToDevice(QPoint(x, y));
557
 
 
558
 
    if ( deviceClipping && !clipRect.contains(pos) )
559
 
        return;
560
 
 
561
 
    painter->drawPoint(pos);
562
 
}
563
 
 
564
 
void QwtPainter::drawColoredArc(QPainter *painter, const QRect &rect, 
565
 
    int peak, int arc, int interval, const QColor &c1, const QColor &c2)
566
 
{
567
 
    int h1, s1, v1;
568
 
    int h2, s2, v2;
569
 
 
570
 
#if QT_VERSION < 0x040000
571
 
    c1.hsv(&h1, &s1, &v1);
572
 
    c2.hsv(&h2, &s2, &v2);
573
 
#else
574
 
    c1.getHsv(&h1, &s1, &v1);
575
 
    c2.getHsv(&h2, &s2, &v2);
576
 
#endif
577
 
    
578
 
    arc /= 2;
579
 
    for ( int angle = -arc; angle < arc; angle += interval)
580
 
    {
581
 
        double ratio;
582
 
        if ( angle >= 0 )
583
 
            ratio = 1.0 - angle / double(arc);
584
 
        else
585
 
            ratio = 1.0 + angle / double(arc);
586
 
            
587
 
 
588
 
        QColor c;
589
 
        c.setHsv( h1 + qRound(ratio * (h2 - h1)),
590
 
            s1 + qRound(ratio * (s2 - s1)),
591
 
            v1 + qRound(ratio * (v2 - v1)) );
592
 
 
593
 
        painter->setPen(QPen(c, painter->pen().width()));
594
 
        painter->drawArc(rect, (peak + angle) * 16, interval * 16);
595
 
    }
596
 
}
597
 
 
598
 
void QwtPainter::drawFocusRect(QPainter *painter, QWidget *widget)
599
 
{
600
 
    drawFocusRect(painter, widget, widget->rect());
601
 
}
602
 
 
603
 
void QwtPainter::drawFocusRect(QPainter *painter, QWidget *widget,
604
 
    const QRect &rect)
605
 
{
606
 
#if QT_VERSION < 0x040000
607
 
        widget->style().drawPrimitive(QStyle::PE_FocusRect, painter,
608
 
            rect, widget->colorGroup());
609
 
#else
610
 
        QStyleOptionFocusRect opt;
611
 
        opt.init(widget);
612
 
        opt.rect = rect;
613
 
        opt.state |= QStyle::State_HasFocus;
614
 
 
615
 
        widget->style()->drawPrimitive(QStyle::PE_FrameFocusRect, 
616
 
            &opt, painter, widget);
617
 
#endif
618
 
 
619
 
}
620
 
 
621
 
//!  Draw a round frame
622
 
#if QT_VERSION < 0x040000
623
 
void QwtPainter::drawRoundFrame(QPainter *painter, const QRect &rect,
624
 
    int width, const QColorGroup &cg, bool sunken)
625
 
#else
626
 
void QwtPainter::drawRoundFrame(QPainter *painter, const QRect &rect,
627
 
    int width, const QPalette &palette, bool sunken)
628
 
#endif
629
 
{
630
 
 
631
 
#if QT_VERSION < 0x040000
632
 
    QColor c0 = cg.mid();
633
 
    QColor c1, c2;
634
 
    if ( sunken )
635
 
    {
636
 
        c1 = cg.dark();
637
 
        c2 = cg.light();
638
 
    }
639
 
    else
640
 
    {
641
 
        c1 = cg.light();
642
 
        c2 = cg.dark();
643
 
    }
644
 
#else
645
 
    QColor c0 = palette.color(QPalette::Mid);
646
 
    QColor c1, c2;
647
 
    if ( sunken )
648
 
    {
649
 
        c1 = palette.color(QPalette::Dark);
650
 
        c2 = palette.color(QPalette::Light);
651
 
    }
652
 
    else
653
 
    {
654
 
        c1 = palette.color(QPalette::Light);
655
 
        c2 = palette.color(QPalette::Dark);
656
 
    }
657
 
#endif
658
 
 
659
 
    painter->setPen(QPen(c0, width));
660
 
    painter->drawArc(rect, 0, 360 * 16); // full
661
 
 
662
 
    const int peak = 150;
663
 
    const int interval = 2;
664
 
 
665
 
    if ( c0 != c1 )
666
 
        drawColoredArc(painter, rect, peak, 160, interval, c0, c1);
667
 
    if ( c0 != c2 )
668
 
        drawColoredArc(painter, rect, peak + 180, 120, interval, c0, c2);
669
 
}
670
 
 
671
 
void QwtPainter::drawColorBar(QPainter *painter,
672
 
        const QwtColorMap &colorMap, const QwtDoubleInterval &interval,
673
 
        const QwtScaleMap &scaleMap, Qt::Orientation orientation,
674
 
        const QRect &rect)
675
 
{
676
 
#if QT_VERSION < 0x040000
677
 
    QValueVector<QRgb> colorTable;
678
 
#else
679
 
    QVector<QRgb> colorTable;
680
 
#endif
681
 
    if ( colorMap.format() == QwtColorMap::Indexed )
682
 
        colorTable = colorMap.colorTable(interval);
683
 
 
684
 
    QColor c;
685
 
 
686
 
    const QRect devRect = d_metricsMap.layoutToDevice(rect);
687
 
 
688
 
    /*
689
 
      We paint to a pixmap first to have something scalable for printing
690
 
      ( f.e. in a Pdf document )
691
 
     */
692
 
      
693
 
    QPixmap pixmap(devRect.size());
694
 
    QPainter pmPainter(&pixmap);
695
 
    pmPainter.translate(-devRect.x(), -devRect.y());
696
 
 
697
 
    if ( orientation == Qt::Horizontal )
698
 
    {
699
 
        QwtScaleMap sMap = scaleMap;
700
 
        sMap.setPaintInterval(devRect.left(), devRect.right());
701
 
 
702
 
        for ( int x = devRect.left(); x <= devRect.right(); x++ )
703
 
        {
704
 
            const double value = sMap.invTransform(x);
705
 
 
706
 
            if ( colorMap.format() == QwtColorMap::RGB )
707
 
                c.setRgb(colorMap.rgb(interval, value));
708
 
            else
709
 
                c = colorTable[colorMap.colorIndex(interval, value)];
710
 
 
711
 
            pmPainter.setPen(c);
712
 
            pmPainter.drawLine(x, devRect.top(), x, devRect.bottom());
713
 
        }
714
 
    }
715
 
    else // Vertical
716
 
    {
717
 
        QwtScaleMap sMap = scaleMap;
718
 
        sMap.setPaintInterval(devRect.bottom(), devRect.top());
719
 
 
720
 
        for ( int y = devRect.top(); y <= devRect.bottom(); y++ )
721
 
        {
722
 
            const double value = sMap.invTransform(y);
723
 
 
724
 
            if ( colorMap.format() == QwtColorMap::RGB )
725
 
                c.setRgb(colorMap.rgb(interval, value));
726
 
            else
727
 
                c = colorTable[colorMap.colorIndex(interval, value)];
728
 
 
729
 
            pmPainter.setPen(c);
730
 
            pmPainter.drawLine(devRect.left(), y, devRect.right(), y);
731
 
        }
732
 
    }
733
 
    pmPainter.end();
734
 
    painter->drawPixmap(devRect, pixmap);
735
 
}
736
 
 
737
 
/*!
738
 
  \brief Scale a pen according to the layout metrics
739
 
    
740
 
  The width of non cosmetic pens is scaled from screen to layout metrics, 
741
 
  so that they look similar on paint devices with different resolutions.
742
 
 
743
 
  \param pen Unscaled pen
744
 
  \return Scaled pen
745
 
*/
746
 
 
747
 
QPen QwtPainter::scaledPen(const QPen &pen)
748
 
{
749
 
#if QT_VERSION < 0x040000
750
 
    return pen;
751
 
#else
752
 
    QPen sPen = pen;
753
 
 
754
 
    if ( !pen.isCosmetic() )
755
 
    {
756
 
        int pw = pen.width();
757
 
        if ( pw == 0 )
758
 
            pw = 1;
759
 
 
760
 
        sPen.setWidth(QwtPainter::metricsMap().screenToLayoutX(pw));
761
 
        sPen.setCosmetic(true);
762
 
    }
763
 
 
764
 
    return sPen;
765
 
#endif
766
 
}
767