~ubuntu-branches/ubuntu/vivid/goldencheetah/vivid-proposed

« back to all changes in this revision

Viewing changes to qwt/src/qwt_painter.cpp

  • Committer: Package Import Robot
  • Author(s): Bhavani Shankar
  • Date: 2014-11-16 14:54:01 UTC
  • mfrom: (16.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20141116145401-89v8lm2rayldamnr
Tags: 3.1.0-1ubuntu1
* Resync on debian unstable. Remaining changes:
  + Use libgcrypt11-dev than libgcrypt-dev as it no longer exists.
    (Closes: #769754)

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include <qapplication.h>
29
29
#include <qdesktopwidget.h>
30
30
 
 
31
#if QT_VERSION >= 0x050000
 
32
#include <qwindow.h>
 
33
#endif
 
34
 
 
35
#if QT_VERSION < 0x050000 
 
36
 
 
37
#ifdef Q_WS_X11
 
38
#include <qx11info_x11.h>
 
39
#endif
 
40
 
 
41
#endif
 
42
 
31
43
bool QwtPainter::d_polylineSplitting = true;
32
44
bool QwtPainter::d_roundingAlignment = true;
33
45
 
34
 
static inline bool isClippingNeeded( const QPainter *painter, QRectF &clipRect )
 
46
static inline bool qwtIsClippingNeeded( 
 
47
    const QPainter *painter, QRectF &clipRect )
35
48
{
36
49
    bool doClipping = false;
37
50
    const QPaintEngine *pe = painter->paintEngine();
49
62
    return doClipping;
50
63
}
51
64
 
52
 
static inline void drawPolyline( QPainter *painter,
53
 
    const QPointF *points, int pointCount, bool polylineSplitting )
 
65
template <class T>
 
66
static inline void qwtDrawPolyline( QPainter *painter,
 
67
    const T *points, int pointCount, bool polylineSplitting )
54
68
{
55
69
    bool doSplit = false;
56
70
    if ( polylineSplitting )
81
95
        painter->drawPolyline( points, pointCount );
82
96
}
83
97
 
84
 
static inline void unscaleFont( QPainter *painter )
 
98
static inline void qwtUnscaleFont( QPainter *painter )
85
99
{
86
100
    if ( painter->font().pixelSize() >= 0 )
87
101
        return;
109
123
}
110
124
 
111
125
/*!
 
126
  Check is the application is running with the X11 graphics system
 
127
  that has some special capabilities that can be used for incremental
 
128
  painting to a widget.
 
129
 
 
130
  \return True, when the graphics system is X11
 
131
*/
 
132
bool QwtPainter::isX11GraphicsSystem()
 
133
{
 
134
    static int onX11 = -1;
 
135
    if ( onX11 < 0 )
 
136
    {
 
137
        QPixmap pm( 1, 1 );
 
138
        QPainter painter( &pm );
 
139
 
 
140
        onX11 = ( painter.paintEngine()->type() == QPaintEngine::X11 ) ? 1 : 0;
 
141
    }
 
142
 
 
143
    return onX11 == 1;
 
144
}
 
145
 
 
146
/*!
112
147
  Check if the painter is using a paint engine, that aligns
113
148
  coordinates to integers. Today these are all paint engines
114
149
  beside QPaintEngine::Pdf and QPaintEngine::SVG.
115
150
 
 
151
  If we have an integer based paint engine it is also
 
152
  checked if the painter has a transformation matrix,
 
153
  that rotates or scales.
 
154
 
116
155
  \param  painter Painter
117
 
  \return true, when the paint engine is aligning
 
156
  \return true, when the painter is aligning
118
157
 
119
158
  \sa setRoundingAlignment()
120
159
*/
130
169
 
131
170
            default:;
132
171
        }
 
172
 
 
173
        const QTransform tr = painter->transform();
 
174
        if ( tr.isRotating() || tr.isScaling() )
 
175
        {
 
176
            // we might have to check translations too
 
177
            return false;
 
178
        }
133
179
    }
134
180
 
135
181
    return true;
138
184
/*!
139
185
  Enable whether coordinates should be rounded, before they are painted
140
186
  to a paint engine that floors to integer values. For other paint engines
141
 
  this ( Pdf, SVG ), this flag has no effect.
142
 
  QwtPainter stores this flag only, the rounding itsself is done in
 
187
  this ( PDF, SVG ), this flag has no effect.
 
188
  QwtPainter stores this flag only, the rounding itself is done in 
143
189
  the painting code ( f.e the plot items ).
144
190
 
145
 
  The default setting is true.
 
191
  The default setting is true. 
146
192
 
147
193
  \sa roundingAlignment(), isAligning()
148
194
*/
154
200
/*!
155
201
  \brief En/Disable line splitting for the raster paint engine
156
202
 
157
 
  The raster paint engine paints polylines of many points
158
 
  much faster when they are splitted in smaller chunks.
 
203
  In some Qt versions the raster paint engine paints polylines of many points
 
204
  much faster when they are split in smaller chunks: f.e all supported Qt versions
 
205
  >= Qt 5.0 when drawing an antialiased polyline with a pen width >=2.
 
206
 
 
207
  The default setting is true.
159
208
 
160
209
  \sa polylineSplitting()
161
210
*/
182
231
    const QRectF r = rect;
183
232
 
184
233
    QRectF clipRect;
185
 
    const bool deviceClipping = isClippingNeeded( painter, clipRect );
 
234
    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
186
235
 
187
236
    if ( deviceClipping )
188
237
    {
213
262
        return;
214
263
 
215
264
    QRectF clipRect;
216
 
    const bool deviceClipping = isClippingNeeded( painter, clipRect );
 
265
    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
217
266
 
218
267
    /*
219
 
      Performance of Qt4 is horrible for non trivial brushs. Without
220
 
      clipping expect minutes or hours for repainting large rects
 
268
      Performance of Qt4 is horrible for a non trivial brush. Without
 
269
      clipping expect minutes or hours for repainting large rectangles
221
270
      (might result from zooming)
222
271
    */
223
272
 
231
280
 
232
281
    QRectF r = rect;
233
282
    if ( deviceClipping )
234
 
        r = r.intersect( clipRect );
 
283
        r = r.intersected( clipRect );
235
284
 
236
285
    if ( r.isValid() )
237
286
        painter->fillRect( r, brush );
242
291
    int a, int alen )
243
292
{
244
293
    QRectF clipRect;
245
 
    const bool deviceClipping = isClippingNeeded( painter, clipRect );
 
294
    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
246
295
    if ( deviceClipping && !clipRect.contains( rect ) )
247
296
        return;
248
297
 
253
302
void QwtPainter::drawEllipse( QPainter *painter, const QRectF &rect )
254
303
{
255
304
    QRectF clipRect;
256
 
    const bool deviceClipping = isClippingNeeded( painter, clipRect );
 
305
    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
257
306
 
258
307
    if ( deviceClipping && !clipRect.contains( rect ) )
259
308
        return;
273
322
        const QString &text )
274
323
{
275
324
    QRectF clipRect;
276
 
    const bool deviceClipping = isClippingNeeded( painter, clipRect );
 
325
    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
277
326
 
278
327
    if ( deviceClipping && !clipRect.contains( pos ) )
279
328
        return;
280
329
 
281
330
 
282
331
    painter->save();
283
 
    unscaleFont( painter );
 
332
    qwtUnscaleFont( painter );
284
333
    painter->drawText( pos, text );
285
334
    painter->restore();
286
335
}
298
347
        int flags, const QString &text )
299
348
{
300
349
    painter->save();
301
 
    unscaleFont( painter );
 
350
    qwtUnscaleFont( painter );
302
351
    painter->drawText( rect, flags, text );
303
352
    painter->restore();
304
353
}
321
370
    painter->save();
322
371
 
323
372
    painter->setFont( txt->defaultFont() );
324
 
    unscaleFont( painter );
 
373
    qwtUnscaleFont( painter );
325
374
 
326
375
    txt->setDefaultFont( painter->font() );
327
376
    txt->setPageSize( QSizeF( rect.width(), QWIDGETSIZE_MAX ) );
353
402
    const QPointF &p1, const QPointF &p2 )
354
403
{
355
404
    QRectF clipRect;
356
 
    const bool deviceClipping = isClippingNeeded( painter, clipRect );
 
405
    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
357
406
 
358
407
    if ( deviceClipping &&
359
408
        !( clipRect.contains( p1 ) && clipRect.contains( p2 ) ) )
372
421
void QwtPainter::drawPolygon( QPainter *painter, const QPolygonF &polygon )
373
422
{
374
423
    QRectF clipRect;
375
 
    const bool deviceClipping = isClippingNeeded( painter, clipRect );
 
424
    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
376
425
 
377
426
    QPolygonF cpa = polygon;
378
427
    if ( deviceClipping )
385
434
void QwtPainter::drawPolyline( QPainter *painter, const QPolygonF &polygon )
386
435
{
387
436
    QRectF clipRect;
388
 
    const bool deviceClipping = isClippingNeeded( painter, clipRect );
 
437
    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
389
438
 
390
439
    QPolygonF cpa = polygon;
391
440
    if ( deviceClipping )
392
441
        cpa = QwtClipper::clipPolygonF( clipRect, cpa );
393
442
 
394
 
    ::drawPolyline( painter,
 
443
    qwtDrawPolyline<QPointF>( painter,
395
444
        cpa.constData(), cpa.size(), d_polylineSplitting );
396
445
}
397
446
 
400
449
    const QPointF *points, int pointCount )
401
450
{
402
451
    QRectF clipRect;
403
 
    const bool deviceClipping = isClippingNeeded( painter, clipRect );
 
452
    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
404
453
 
405
454
    if ( deviceClipping )
406
455
    {
407
456
        QPolygonF polygon( pointCount );
408
 
        qMemCopy( polygon.data(), points, pointCount * sizeof( QPointF ) );
 
457
        ::memcpy( polygon.data(), points, pointCount * sizeof( QPointF ) );
409
458
 
410
459
        polygon = QwtClipper::clipPolygonF( clipRect, polygon );
411
 
        ::drawPolyline( painter,
412
 
            polygon.constData(), polygon.size(), d_polylineSplitting );
413
 
    }
414
 
    else
415
 
        ::drawPolyline( painter, points, pointCount, d_polylineSplitting );
 
460
        qwtDrawPolyline<QPointF>( painter,
 
461
            polygon.constData(), polygon.size(), d_polylineSplitting );
 
462
    }
 
463
    else
 
464
    {
 
465
        qwtDrawPolyline<QPointF>( painter, points, pointCount, d_polylineSplitting );
 
466
    }
 
467
}
 
468
 
 
469
//! Wrapper for QPainter::drawPolygon()
 
470
void QwtPainter::drawPolygon( QPainter *painter, const QPolygon &polygon )
 
471
{
 
472
    QRectF clipRect;
 
473
    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
 
474
 
 
475
    QPolygon cpa = polygon;
 
476
    if ( deviceClipping )
 
477
        cpa = QwtClipper::clipPolygon( clipRect, polygon );
 
478
 
 
479
    painter->drawPolygon( cpa );
 
480
}
 
481
 
 
482
//! Wrapper for QPainter::drawPolyline()
 
483
void QwtPainter::drawPolyline( QPainter *painter, const QPolygon &polygon )
 
484
{
 
485
    QRectF clipRect;
 
486
    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
 
487
 
 
488
    QPolygon cpa = polygon;
 
489
    if ( deviceClipping )
 
490
        cpa = QwtClipper::clipPolygon( clipRect, cpa );
 
491
 
 
492
    qwtDrawPolyline<QPoint>( painter,
 
493
        cpa.constData(), cpa.size(), d_polylineSplitting );
 
494
}
 
495
 
 
496
//! Wrapper for QPainter::drawPolyline()
 
497
void QwtPainter::drawPolyline( QPainter *painter,
 
498
    const QPoint *points, int pointCount )
 
499
{
 
500
    QRectF clipRect;
 
501
    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
 
502
 
 
503
    if ( deviceClipping )
 
504
    {
 
505
        QPolygon polygon( pointCount );
 
506
        ::memcpy( polygon.data(), points, pointCount * sizeof( QPoint ) );
 
507
 
 
508
        polygon = QwtClipper::clipPolygon( clipRect, polygon );
 
509
        qwtDrawPolyline<QPoint>( painter,
 
510
            polygon.constData(), polygon.size(), d_polylineSplitting );
 
511
    }
 
512
    else
 
513
        qwtDrawPolyline<QPoint>( painter, points, pointCount, d_polylineSplitting );
416
514
}
417
515
 
418
516
//! Wrapper for QPainter::drawPoint()
419
517
void QwtPainter::drawPoint( QPainter *painter, const QPointF &pos )
420
518
{
421
519
    QRectF clipRect;
422
 
    const bool deviceClipping = isClippingNeeded( painter, clipRect );
 
520
    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
423
521
 
424
522
    if ( deviceClipping && !clipRect.contains( pos ) )
425
523
        return;
427
525
    painter->drawPoint( pos );
428
526
}
429
527
 
 
528
//! Wrapper for QPainter::drawPoint()
 
529
void QwtPainter::drawPoint( QPainter *painter, const QPoint &pos )
 
530
{
 
531
    QRectF clipRect;
 
532
    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
 
533
 
 
534
    if ( deviceClipping )
 
535
    {
 
536
        const int minX = qCeil( clipRect.left() );
 
537
        const int maxX = qFloor( clipRect.right() );
 
538
        const int minY = qCeil( clipRect.top() );
 
539
        const int maxY = qFloor( clipRect.bottom() );
 
540
 
 
541
        if ( pos.x() < minX || pos.x() > maxX 
 
542
            || pos.y() < minY || pos.y() > maxY )
 
543
        {
 
544
            return;
 
545
        }
 
546
    }
 
547
 
 
548
    painter->drawPoint( pos );
 
549
}
 
550
 
 
551
//! Wrapper for QPainter::drawPoints()
 
552
void QwtPainter::drawPoints( QPainter *painter, 
 
553
    const QPoint *points, int pointCount )
 
554
{
 
555
    QRectF clipRect;
 
556
    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
 
557
 
 
558
    if ( deviceClipping )
 
559
    {
 
560
        const int minX = qCeil( clipRect.left() );
 
561
        const int maxX = qFloor( clipRect.right() );
 
562
        const int minY = qCeil( clipRect.top() );
 
563
        const int maxY = qFloor( clipRect.bottom() );
 
564
 
 
565
        const QRect r( minX, minY, maxX - minX, maxY - minY );
 
566
 
 
567
        QPolygon clippedPolygon( pointCount );
 
568
        QPoint *clippedData = clippedPolygon.data();
 
569
 
 
570
        int numClippedPoints = 0;
 
571
        for ( int i = 0; i < pointCount; i++ )
 
572
        {
 
573
            if ( r.contains( points[i] ) )
 
574
                clippedData[ numClippedPoints++ ] = points[i];
 
575
        }
 
576
        painter->drawPoints( clippedData, numClippedPoints );
 
577
    }
 
578
    else
 
579
    {
 
580
        painter->drawPoints( points, pointCount );
 
581
    }
 
582
}
 
583
 
 
584
//! Wrapper for QPainter::drawPoints()
 
585
void QwtPainter::drawPoints( QPainter *painter, 
 
586
    const QPointF *points, int pointCount )
 
587
{
 
588
    QRectF clipRect;
 
589
    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
 
590
 
 
591
    if ( deviceClipping )
 
592
    {
 
593
        QPolygonF clippedPolygon( pointCount );
 
594
        QPointF *clippedData = clippedPolygon.data();
 
595
 
 
596
        int numClippedPoints = 0;
 
597
        for ( int i = 0; i < pointCount; i++ )
 
598
        {
 
599
            if ( clipRect.contains( points[i] ) )
 
600
                clippedData[ numClippedPoints++ ] = points[i];
 
601
        }
 
602
        painter->drawPoints( clippedData, numClippedPoints );
 
603
    }
 
604
    else
 
605
    {
 
606
        painter->drawPoints( points, pointCount );
 
607
    }
 
608
}
 
609
 
430
610
//! Wrapper for QPainter::drawImage()
431
611
void QwtPainter::drawImage( QPainter *painter,
432
612
    const QRectF &rect, const QImage &image )
470
650
}
471
651
 
472
652
//! Draw a focus rectangle on a widget using its style.
473
 
void QwtPainter::drawFocusRect( QPainter *painter, QWidget *widget )
 
653
void QwtPainter::drawFocusRect( QPainter *painter, const QWidget *widget )
474
654
{
475
655
    drawFocusRect( painter, widget, widget->rect() );
476
656
}
477
657
 
478
658
//! Draw a focus rectangle on a widget using its style.
479
 
void QwtPainter::drawFocusRect( QPainter *painter, QWidget *widget,
 
659
void QwtPainter::drawFocusRect( QPainter *painter, const QWidget *widget,
480
660
    const QRect &rect )
481
661
{
482
662
    QStyleOptionFocusRect opt;
489
669
}
490
670
 
491
671
/*!
492
 
  Draw a frame with rounded borders
 
672
  Draw a round frame 
 
673
 
 
674
  \param painter Painter
 
675
  \param rect Frame rectangle
 
676
  \param palette QPalette::WindowText is used for plain borders
 
677
                 QPalette::Dark and QPalette::Light for raised
 
678
                 or sunken borders
 
679
  \param lineWidth Line width
 
680
  \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow
 
681
*/
 
682
void QwtPainter::drawRoundFrame( QPainter *painter,
 
683
    const QRectF &rect, const QPalette &palette, 
 
684
    int lineWidth, int frameStyle )
 
685
{
 
686
    enum Style
 
687
    {
 
688
        Plain,
 
689
        Sunken,
 
690
        Raised
 
691
    };
 
692
 
 
693
    Style style = Plain;
 
694
    if ( (frameStyle & QFrame::Sunken) == QFrame::Sunken )
 
695
        style = Sunken;
 
696
    else if ( (frameStyle & QFrame::Raised) == QFrame::Raised )
 
697
        style = Raised;
 
698
 
 
699
    const double lw2 = 0.5 * lineWidth;
 
700
    QRectF r = rect.adjusted( lw2, lw2, -lw2, -lw2 );
 
701
 
 
702
    QBrush brush;
 
703
 
 
704
    if ( style != Plain )
 
705
    {
 
706
        QColor c1 = palette.color( QPalette::Light );
 
707
        QColor c2 = palette.color( QPalette::Dark );
 
708
 
 
709
        if ( style == Sunken )
 
710
            qSwap( c1, c2 );
 
711
 
 
712
        QLinearGradient gradient( r.topLeft(), r.bottomRight() );
 
713
        gradient.setColorAt( 0.0, c1 );
 
714
#if 0
 
715
        gradient.setColorAt( 0.3, c1 );
 
716
        gradient.setColorAt( 0.7, c2 );
 
717
#endif
 
718
        gradient.setColorAt( 1.0, c2 );
 
719
 
 
720
        brush = QBrush( gradient );
 
721
    }
 
722
    else // Plain
 
723
    {
 
724
        brush = palette.brush( QPalette::WindowText );
 
725
    }
 
726
 
 
727
    painter->save();
 
728
 
 
729
    painter->setPen( QPen( brush, lineWidth ) );
 
730
    painter->setBrush( Qt::NoBrush );
 
731
 
 
732
    painter->drawEllipse( r );
 
733
 
 
734
    painter->restore();
 
735
}
 
736
 
 
737
/*!
 
738
  Draw a rectangular frame
 
739
 
 
740
  \param painter Painter
 
741
  \param rect Frame rectangle
 
742
  \param palette Palette
 
743
  \param foregroundRole Foreground role used for QFrame::Plain
 
744
  \param frameWidth Frame width
 
745
  \param midLineWidth Used for QFrame::Box
 
746
  \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow
 
747
*/
 
748
void QwtPainter::drawFrame( QPainter *painter, const QRectF &rect,
 
749
    const QPalette &palette, QPalette::ColorRole foregroundRole,
 
750
    int frameWidth, int midLineWidth, int frameStyle )
 
751
{
 
752
    if ( frameWidth <= 0 || rect.isEmpty() )
 
753
        return;
 
754
 
 
755
    const int shadow = frameStyle & QFrame::Shadow_Mask;
 
756
 
 
757
    painter->save();
 
758
 
 
759
    if ( shadow == QFrame::Plain )
 
760
    {
 
761
        const QRectF outerRect = rect.adjusted( 0.0, 0.0, -1.0, -1.0 );
 
762
        const QRectF innerRect = outerRect.adjusted( 
 
763
            frameWidth, frameWidth, -frameWidth, -frameWidth );
 
764
 
 
765
        QPainterPath path;
 
766
        path.addRect( outerRect );
 
767
        path.addRect( innerRect );
 
768
 
 
769
        painter->setPen( Qt::NoPen );
 
770
        painter->setBrush( palette.color( foregroundRole ) );
 
771
 
 
772
        painter->drawPath( path );
 
773
    }
 
774
    else
 
775
    {
 
776
        const int shape = frameStyle & QFrame::Shape_Mask;
 
777
 
 
778
        if ( shape == QFrame::Box )
 
779
        {
 
780
            const QRectF outerRect = rect.adjusted( 0.0, 0.0, -1.0, -1.0 );
 
781
            const QRectF midRect1 = outerRect.adjusted( 
 
782
                frameWidth, frameWidth, -frameWidth, -frameWidth );
 
783
            const QRectF midRect2 = midRect1.adjusted( 
 
784
                midLineWidth, midLineWidth, -midLineWidth, -midLineWidth );
 
785
 
 
786
            const QRectF innerRect = midRect2.adjusted( 
 
787
                frameWidth, frameWidth, -frameWidth, -frameWidth );
 
788
 
 
789
            QPainterPath path1;
 
790
            path1.moveTo( outerRect.bottomLeft() );
 
791
            path1.lineTo( outerRect.topLeft() );
 
792
            path1.lineTo( outerRect.topRight() );
 
793
            path1.lineTo( midRect1.topRight() );
 
794
            path1.lineTo( midRect1.topLeft() );
 
795
            path1.lineTo( midRect1.bottomLeft() );
 
796
 
 
797
            QPainterPath path2;
 
798
            path2.moveTo( outerRect.bottomLeft() );
 
799
            path2.lineTo( outerRect.bottomRight() );
 
800
            path2.lineTo( outerRect.topRight() );
 
801
            path2.lineTo( midRect1.topRight() );
 
802
            path2.lineTo( midRect1.bottomRight() );
 
803
            path2.lineTo( midRect1.bottomLeft() );
 
804
 
 
805
            QPainterPath path3;
 
806
            path3.moveTo( midRect2.bottomLeft() );
 
807
            path3.lineTo( midRect2.topLeft() );
 
808
            path3.lineTo( midRect2.topRight() );
 
809
            path3.lineTo( innerRect.topRight() );
 
810
            path3.lineTo( innerRect.topLeft() );
 
811
            path3.lineTo( innerRect.bottomLeft() );
 
812
 
 
813
            QPainterPath path4;
 
814
            path4.moveTo( midRect2.bottomLeft() );
 
815
            path4.lineTo( midRect2.bottomRight() );
 
816
            path4.lineTo( midRect2.topRight() );
 
817
            path4.lineTo( innerRect.topRight() );
 
818
            path4.lineTo( innerRect.bottomRight() );
 
819
            path4.lineTo( innerRect.bottomLeft() );
 
820
 
 
821
            QPainterPath path5;
 
822
            path5.addRect( midRect1 );
 
823
            path5.addRect( midRect2 );
 
824
 
 
825
            painter->setPen( Qt::NoPen );
 
826
 
 
827
            QBrush brush1 = palette.dark().color();
 
828
            QBrush brush2 = palette.light().color();
 
829
 
 
830
            if ( shadow == QFrame::Raised )
 
831
                qSwap( brush1, brush2 );
 
832
 
 
833
            painter->setBrush( brush1 );
 
834
            painter->drawPath( path1 );
 
835
            painter->drawPath( path4 );
 
836
 
 
837
            painter->setBrush( brush2 );
 
838
            painter->drawPath( path2 );
 
839
            painter->drawPath( path3 );
 
840
 
 
841
            painter->setBrush( palette.mid() );
 
842
            painter->drawPath( path5 );
 
843
        }
 
844
#if 0
 
845
        // qDrawWinPanel doesn't result in something nice
 
846
        // on a scalable document like PDF. Better draw a
 
847
        // Panel.
 
848
 
 
849
        else if ( shape == QFrame::WinPanel )
 
850
        {
 
851
            painter->setRenderHint( QPainter::NonCosmeticDefaultPen, true );
 
852
            qDrawWinPanel ( painter, rect.toRect(), palette,
 
853
                frameStyle & QFrame::Sunken );
 
854
        }
 
855
        else if ( shape == QFrame::StyledPanel )
 
856
        {
 
857
        }
 
858
#endif
 
859
        else
 
860
        {
 
861
            const QRectF outerRect = rect.adjusted( 0.0, 0.0, -1.0, -1.0 );
 
862
            const QRectF innerRect = outerRect.adjusted( 
 
863
                frameWidth - 1.0, frameWidth - 1.0, 
 
864
                -( frameWidth - 1.0 ), -( frameWidth - 1.0 ) );
 
865
 
 
866
            QPainterPath path1;
 
867
            path1.moveTo( outerRect.bottomLeft() );
 
868
            path1.lineTo( outerRect.topLeft() );
 
869
            path1.lineTo( outerRect.topRight() );
 
870
            path1.lineTo( innerRect.topRight() );
 
871
            path1.lineTo( innerRect.topLeft() );
 
872
            path1.lineTo( innerRect.bottomLeft() );
 
873
 
 
874
 
 
875
            QPainterPath path2;
 
876
            path2.moveTo( outerRect.bottomLeft() );
 
877
            path2.lineTo( outerRect.bottomRight() );
 
878
            path2.lineTo( outerRect.topRight() );
 
879
            path2.lineTo( innerRect.topRight() );
 
880
            path2.lineTo( innerRect.bottomRight() );
 
881
            path2.lineTo( innerRect.bottomLeft() );
 
882
 
 
883
            painter->setPen( Qt::NoPen );
 
884
 
 
885
            QBrush brush1 = palette.dark().color();
 
886
            QBrush brush2 = palette.light().color();
 
887
 
 
888
            if ( shadow == QFrame::Raised )
 
889
                qSwap( brush1, brush2 );
 
890
 
 
891
            painter->setBrush( brush1 );
 
892
            painter->drawPath( path1 );
 
893
 
 
894
            painter->setBrush( brush2 );
 
895
            painter->drawPath( path2 );
 
896
        }
 
897
 
 
898
    }
 
899
 
 
900
    painter->restore();
 
901
}
 
902
 
 
903
/*!
 
904
  Draw a rectangular frame with rounded borders
493
905
 
494
906
  \param painter Painter
495
907
  \param rect Frame rectangle
502
914
  \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow
503
915
*/
504
916
 
505
 
void QwtPainter::drawRoundedFrame( QPainter *painter,
506
 
    const QRectF &rect, double xRadius, double yRadius,
 
917
void QwtPainter::drawRoundedFrame( QPainter *painter, 
 
918
    const QRectF &rect, double xRadius, double yRadius, 
507
919
    const QPalette &palette, int lineWidth, int frameStyle )
508
920
{
509
921
    painter->save();
533
945
    {
534
946
        // move + 4 * ( cubicTo + lineTo )
535
947
        QPainterPath pathList[8];
536
 
 
 
948
        
537
949
        for ( int i = 0; i < 4; i++ )
538
950
        {
539
951
            const int j = i * 4 + 1;
540
 
 
 
952
            
541
953
            pathList[ 2 * i ].moveTo(
542
954
                path.elementAt(j - 1).x, path.elementAt( j - 1 ).y
543
 
            );
544
 
 
 
955
            );  
 
956
            
545
957
            pathList[ 2 * i ].cubicTo(
546
958
                path.elementAt(j + 0).x, path.elementAt(j + 0).y,
547
959
                path.elementAt(j + 1).x, path.elementAt(j + 1).y,
548
960
                path.elementAt(j + 2).x, path.elementAt(j + 2).y );
549
 
 
 
961
                
550
962
            pathList[ 2 * i + 1 ].moveTo(
551
963
                path.elementAt(j + 2).x, path.elementAt(j + 2).y
552
 
            );
 
964
            );  
553
965
            pathList[ 2 * i + 1 ].lineTo(
554
966
                path.elementAt(j + 3).x, path.elementAt(j + 3).y
555
 
            );
556
 
        }
 
967
            );  
 
968
        }   
557
969
 
558
970
        QColor c1( palette.color( QPalette::Dark ) );
559
971
        QColor c2( palette.color( QPalette::Light ) );
566
978
            QRectF r = pathList[2 * i].controlPointRect();
567
979
 
568
980
            QPen arcPen;
 
981
            arcPen.setCapStyle( Qt::FlatCap );
569
982
            arcPen.setWidth( lineWidth );
570
983
 
571
984
            QPen linePen;
 
985
            linePen.setCapStyle( Qt::FlatCap );
572
986
            linePen.setWidth( lineWidth );
573
987
 
574
988
            switch( i )
672
1086
            const double value = sMap.invTransform( x );
673
1087
 
674
1088
            if ( colorMap.format() == QwtColorMap::RGB )
675
 
                c.setRgb( colorMap.rgb( interval, value ) );
 
1089
                c.setRgba( colorMap.rgb( interval, value ) );
676
1090
            else
677
1091
                c = colorTable[colorMap.colorIndex( interval, value )];
678
1092
 
702
1116
 
703
1117
    drawPixmap( painter, rect, pixmap );
704
1118
}
 
1119
 
 
1120
static inline void qwtFillRect( const QWidget *widget, QPainter *painter, 
 
1121
    const QRect &rect, const QBrush &brush)
 
1122
{
 
1123
    if ( brush.style() == Qt::TexturePattern ) 
 
1124
    {
 
1125
        painter->save();
 
1126
 
 
1127
        painter->setClipRect( rect );
 
1128
        painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft());
 
1129
 
 
1130
        painter->restore();
 
1131
    } 
 
1132
    else if ( brush.gradient() )
 
1133
    {
 
1134
        painter->save();
 
1135
 
 
1136
        painter->setClipRect( rect );
 
1137
        painter->fillRect(0, 0, widget->width(), 
 
1138
            widget->height(), brush);
 
1139
 
 
1140
        painter->restore();
 
1141
    } 
 
1142
    else 
 
1143
    {
 
1144
        painter->fillRect(rect, brush);
 
1145
    }
 
1146
}
 
1147
 
 
1148
/*!
 
1149
  Fill a pixmap with the content of a widget
 
1150
 
 
1151
  In Qt >= 5.0 QPixmap::fill() is a nop, in Qt 4.x it is buggy
 
1152
  for backgrounds with gradients. Thus fillPixmap() offers 
 
1153
  an alternative implementation.
 
1154
 
 
1155
  \param widget Widget
 
1156
  \param pixmap Pixmap to be filled
 
1157
  \param offset Offset 
 
1158
 
 
1159
  \sa QPixmap::fill()
 
1160
 */
 
1161
void QwtPainter::fillPixmap( const QWidget *widget, 
 
1162
    QPixmap &pixmap, const QPoint &offset )
 
1163
{
 
1164
    const QRect rect( offset, pixmap.size() );
 
1165
 
 
1166
    QPainter painter( &pixmap );
 
1167
    painter.translate( -offset );
 
1168
 
 
1169
    const QBrush autoFillBrush = 
 
1170
        widget->palette().brush( widget->backgroundRole() );
 
1171
 
 
1172
    if ( !( widget->autoFillBackground() && autoFillBrush.isOpaque() ) ) 
 
1173
    {
 
1174
        const QBrush bg = widget->palette().brush( QPalette::Window );
 
1175
        qwtFillRect( widget, &painter, rect, bg);
 
1176
    }
 
1177
 
 
1178
    if ( widget->autoFillBackground() )
 
1179
        qwtFillRect( widget, &painter, rect, autoFillBrush);
 
1180
 
 
1181
    if ( widget->testAttribute(Qt::WA_StyledBackground) ) 
 
1182
    {
 
1183
        painter.setClipRegion( rect );
 
1184
 
 
1185
        QStyleOption opt;
 
1186
        opt.initFrom( widget );
 
1187
        widget->style()->drawPrimitive( QStyle::PE_Widget, 
 
1188
            &opt, &painter, widget );
 
1189
    }
 
1190
}
 
1191
 
 
1192
/*!
 
1193
  Fill rect with the background of a widget
 
1194
 
 
1195
  \param painter Painter
 
1196
  \param rect Rectangle to be filled
 
1197
  \param widget Widget
 
1198
 
 
1199
  \sa QStyle::PE_Widget, QWidget::backgroundRole()
 
1200
 */
 
1201
void QwtPainter::drawBackgound( QPainter *painter,
 
1202
    const QRectF &rect, const QWidget *widget )
 
1203
{
 
1204
    if ( widget->testAttribute( Qt::WA_StyledBackground ) )
 
1205
    {
 
1206
        QStyleOption opt;
 
1207
        opt.initFrom( widget );
 
1208
        opt.rect = rect.toAlignedRect();
 
1209
 
 
1210
        widget->style()->drawPrimitive(
 
1211
            QStyle::PE_Widget, &opt, painter, widget);
 
1212
    }
 
1213
    else
 
1214
    {
 
1215
        const QBrush brush =
 
1216
            widget->palette().brush( widget->backgroundRole() );
 
1217
 
 
1218
        painter->fillRect( rect, brush );
 
1219
    }
 
1220
}
 
1221
 
 
1222
/*!
 
1223
  \return A pixmap that can be used as backing store
 
1224
 
 
1225
  \param widget Widget, for which the backinstore is intended
 
1226
  \param size Size of the pixmap
 
1227
 */
 
1228
QPixmap QwtPainter::backingStore( QWidget *widget, const QSize &size )
 
1229
{
 
1230
    QPixmap pm;
 
1231
 
 
1232
#define QWT_HIGH_DPI 1
 
1233
 
 
1234
#if QT_VERSION >= 0x050000 && QWT_HIGH_DPI
 
1235
    qreal pixelRatio = 1.0;
 
1236
 
 
1237
    if ( widget && widget->windowHandle() )
 
1238
    {
 
1239
        pixelRatio = widget->windowHandle()->devicePixelRatio();
 
1240
    }
 
1241
    else
 
1242
    {
 
1243
        if ( qApp )
 
1244
            pixelRatio = qApp->devicePixelRatio();
 
1245
    }
 
1246
 
 
1247
    pm = QPixmap( size * pixelRatio );
 
1248
    pm.setDevicePixelRatio( pixelRatio );
 
1249
#else
 
1250
    Q_UNUSED( widget )
 
1251
    pm = QPixmap( size );
 
1252
#endif
 
1253
 
 
1254
#if QT_VERSION < 0x050000 
 
1255
#ifdef Q_WS_X11
 
1256
    if ( widget && isX11GraphicsSystem() )
 
1257
    {
 
1258
        if ( pm.x11Info().screen() != widget->x11Info().screen() )
 
1259
            pm.x11SetScreen( widget->x11Info().screen() );
 
1260
    }
 
1261
#endif
 
1262
#endif
 
1263
 
 
1264
    return pm;
 
1265
}
 
1266