Newer
Older
/* -*- 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
*****************************************************************************/
#include "qwt_painter.h"
#include "qwt_math.h"
#include "qwt_clipper.h"
#include "qwt_color_map.h"
#include "qwt_scale_map.h"
#include <qrect.h>
#include <qpainter.h>
#include <qpalette.h>
#include <qpaintdevice.h>
#include <qpixmap.h>
#include <qstyle.h>
#include <qtextdocument.h>
#include <qabstracttextdocumentlayout.h>
#include <qstyleoption.h>
#include <qpaintengine.h>
bool QwtPainter::d_polylineSplitting = true;
bool QwtPainter::d_roundingAlignment = true;
static inline bool qwtIsClippingNeeded(
const QPainter *painter, QRectF &clipRect )
bool doClipping = false;
const QPaintEngine *pe = painter->paintEngine();
if ( pe && pe->type() == QPaintEngine::SVG )
{
// The SVG paint engine ignores any clipping,
if ( painter->hasClipping() )
{
doClipping = true;
clipRect = painter->clipRegion().boundingRect();
}
}
template <class T>
static inline void qwtDrawPolyline( QPainter *painter,
const T *points, int pointCount, bool polylineSplitting )
bool doSplit = false;
if ( polylineSplitting )
{
const QPaintEngine *pe = painter->paintEngine();
if ( pe && pe->type() == QPaintEngine::Raster )
{
/*
The raster paint engine seems to use some algo with O(n*n).
( Qt 4.3 is better than Qt 4.2, but remains unacceptable)
To work around this problem, we have to split the polygon into
smaller pieces.
*/
doSplit = true;
}
}
if ( doSplit )
{
const int splitSize = 20;
for ( int i = 0; i < pointCount; i += splitSize )
{
const int n = qMin( splitSize + 1, pointCount - i );
painter->drawPolyline( points + i, n );
}
static QSize screenResolution;
if ( !screenResolution.isValid() )
{
QDesktopWidget *desktop = QApplication::desktop();
if ( desktop )
{
screenResolution.setWidth( desktop->logicalDpiX() );
screenResolution.setHeight( desktop->logicalDpiY() );
}
}
const QPaintDevice *pd = painter->device();
if ( pd->logicalDpiX() != screenResolution.width() ||
pd->logicalDpiY() != screenResolution.height() )
{
QFont pixelFont( painter->font(), QApplication::desktop() );
pixelFont.setPixelSize( QFontInfo( pixelFont ).pixelSize() );
Check is the application is running with the X11 graphics system
that has some special capabilities that can be used for incremental
painting to a widget.
static int onX11 = -1;
if ( onX11 < 0 )
{
QPixmap pm( 1, 1 );
QPainter painter( &pm );
onX11 = ( painter.paintEngine()->type() == QPaintEngine::X11 ) ? 1 : 0;
}
return onX11 == 1;
Check if the painter is using a paint engine, that aligns
coordinates to integers. Today these are all paint engines
beside QPaintEngine::Pdf and QPaintEngine::SVG.
If we have an integer based paint engine it is also
checked if the painter has a transformation matrix,
that rotates or scales.
\param painter Painter
\return true, when the painter is aligning
\sa setRoundingAlignment()
if ( painter && painter->isActive() )
{
switch ( painter->paintEngine()->type() )
{
case QPaintEngine::Pdf:
case QPaintEngine::SVG:
return false;
default:;
}
const QTransform tr = painter->transform();
if ( tr.isRotating() || tr.isScaling() )
{
// we might have to check translations too
return false;
}
}
return true;
Enable whether coordinates should be rounded, before they are painted
to a paint engine that floors to integer values. For other paint engines
this ( PDF, SVG ), this flag has no effect.
QwtPainter stores this flag only, the rounding itself is done in
the painting code ( f.e the plot items ).
The default setting is true.
\sa roundingAlignment(), isAligning()
\brief En/Disable line splitting for the raster paint engine
In some Qt versions the raster paint engine paints polylines of many points
much faster when they are split in smaller chunks: f.e all supported Qt versions
>= Qt 5.0 when drawing an antialiased polyline with a pen width >=2.
The default setting is true.
\sa polylineSplitting()
//! Wrapper for QPainter::drawPath()
void QwtPainter::drawPath( QPainter *painter, const QPainterPath &path )
//! Wrapper for QPainter::drawRect()
void QwtPainter::drawRect( QPainter *painter, double x, double y, double w, double h )
//! Wrapper for QPainter::drawRect()
void QwtPainter::drawRect( QPainter *painter, const QRectF &rect )
QRectF clipRect;
const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
if ( !clipRect.contains( r ) )
{
fillRect( painter, r & clipRect, painter->brush() );
painter->setBrush( Qt::NoBrush );
drawPolyline( painter, QPolygonF( r ) );
//! Wrapper for QPainter::fillRect()
void QwtPainter::fillRect( QPainter *painter,
const QRectF &rect, const QBrush &brush )
QRectF clipRect;
const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
Performance of Qt4 is horrible for a non trivial brush. Without
clipping expect minutes or hours for repainting large rectangles
if ( deviceClipping )
clipRect &= painter->window();
else
clipRect = painter->window();
if ( painter->hasClipping() )
clipRect &= painter->clipRegion().boundingRect();
QRectF r = rect;
if ( deviceClipping )
r = r.intersected( clipRect );
//! Wrapper for QPainter::drawPie()
void QwtPainter::drawPie( QPainter *painter, const QRectF &rect,
int a, int alen )
QRectF clipRect;
const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
if ( deviceClipping && !clipRect.contains( rect ) )
//! Wrapper for QPainter::drawEllipse()
void QwtPainter::drawEllipse( QPainter *painter, const QRectF &rect )
QRectF clipRect;
const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
//! Wrapper for QPainter::drawText()
void QwtPainter::drawText( QPainter *painter, double x, double y,
const QString &text )
//! Wrapper for QPainter::drawText()
void QwtPainter::drawText( QPainter *painter, const QPointF &pos,
const QString &text )
QRectF clipRect;
const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
painter->save();
qwtUnscaleFont( painter );
painter->drawText( pos, text );
painter->restore();
//! Wrapper for QPainter::drawText()
void QwtPainter::drawText( QPainter *painter,
double x, double y, double w, double h,
int flags, const QString &text )
//! Wrapper for QPainter::drawText()
void QwtPainter::drawText( QPainter *painter, const QRectF &rect,
int flags, const QString &text )
{
painter->save();
qwtUnscaleFont( painter );
painter->drawText( rect, flags, text );
painter->restore();
\param painter Painter
\param rect Traget rectangle
\param flags Alignments/Text flags, see QPainter::drawText()
\param text Text document
*/
void QwtPainter::drawSimpleRichText( QPainter *painter, const QRectF &rect,
int flags, const QTextDocument &text )
painter->setFont( txt->defaultFont() );
qwtUnscaleFont( painter );
txt->setDefaultFont( painter->font() );
txt->setPageSize( QSizeF( rect.width(), QWIDGETSIZE_MAX ) );
QAbstractTextDocumentLayout* layout = txt->documentLayout();
const double height = layout->documentSize().height();
double y = rect.y();
if ( flags & Qt::AlignBottom )
y += ( rect.height() - height );
else if ( flags & Qt::AlignVCenter )
y += ( rect.height() - height ) / 2;
context.palette.setColor( QPalette::Text, painter->pen().color() );
painter->translate( rect.x(), y );
layout->draw( painter, context );
//! Wrapper for QPainter::drawLine()
void QwtPainter::drawLine( QPainter *painter,
const QPointF &p1, const QPointF &p2 )
QRectF clipRect;
const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
!( clipRect.contains( p1 ) && clipRect.contains( p2 ) ) )
{
QPolygonF polygon;
polygon += p1;
polygon += p2;
drawPolyline( painter, polygon );
//! Wrapper for QPainter::drawPolygon()
void QwtPainter::drawPolygon( QPainter *painter, const QPolygonF &polygon )
{
QRectF clipRect;
const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
QPolygonF cpa = polygon;
if ( deviceClipping )
cpa = QwtClipper::clipPolygonF( clipRect, polygon );
//! Wrapper for QPainter::drawPolyline()
void QwtPainter::drawPolyline( QPainter *painter, const QPolygonF &polygon )
QRectF clipRect;
const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
QPolygonF cpa = polygon;
if ( deviceClipping )
cpa = QwtClipper::clipPolygonF( clipRect, cpa );
qwtDrawPolyline<QPointF>( painter,
cpa.constData(), cpa.size(), d_polylineSplitting );
//! Wrapper for QPainter::drawPolyline()
void QwtPainter::drawPolyline( QPainter *painter,
const QPointF *points, int pointCount )
QRectF clipRect;
const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
{
QPolygonF polygon( pointCount );
::memcpy( polygon.data(), points, pointCount * sizeof( QPointF ) );
polygon = QwtClipper::clipPolygonF( clipRect, polygon );
qwtDrawPolyline<QPointF>( painter,
polygon.constData(), polygon.size(), d_polylineSplitting );
else
{
qwtDrawPolyline<QPointF>( painter, points, pointCount, d_polylineSplitting );
}
}
//! Wrapper for QPainter::drawPolygon()
void QwtPainter::drawPolygon( QPainter *painter, const QPolygon &polygon )
{
QRectF clipRect;
const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
QPolygon cpa = polygon;
if ( deviceClipping )
cpa = QwtClipper::clipPolygon( clipRect, polygon );
painter->drawPolygon( cpa );
//! Wrapper for QPainter::drawPolyline()
void QwtPainter::drawPolyline( QPainter *painter, const QPolygon &polygon )
{
QRectF clipRect;
const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
QPolygon cpa = polygon;
if ( deviceClipping )
cpa = QwtClipper::clipPolygon( clipRect, cpa );
qwtDrawPolyline<QPoint>( painter,
cpa.constData(), cpa.size(), d_polylineSplitting );
}
//! Wrapper for QPainter::drawPolyline()
void QwtPainter::drawPolyline( QPainter *painter,
const QPoint *points, int pointCount )
QRectF clipRect;
const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
if ( deviceClipping )
{
QPolygon polygon( pointCount );
::memcpy( polygon.data(), points, pointCount * sizeof( QPoint ) );
polygon = QwtClipper::clipPolygon( clipRect, polygon );
qwtDrawPolyline<QPoint>( painter,
polygon.constData(), polygon.size(), d_polylineSplitting );
}
else
qwtDrawPolyline<QPoint>( painter, points, pointCount, d_polylineSplitting );
}
//! Wrapper for QPainter::drawPoint()
void QwtPainter::drawPoint( QPainter *painter, const QPointF &pos )
{
QRectF clipRect;
const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
//! Wrapper for QPainter::drawPoint()
void QwtPainter::drawPoint( QPainter *painter, const QPoint &pos )
QRectF clipRect;
const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
if ( deviceClipping )
{
const int minX = qCeil( clipRect.left() );
const int maxX = qFloor( clipRect.right() );
const int minY = qCeil( clipRect.top() );
const int maxY = qFloor( clipRect.bottom() );
if ( pos.x() < minX || pos.x() > maxX
|| pos.y() < minY || pos.y() > maxY )
{
return;
}
}
painter->drawPoint( pos );
}
//! Wrapper for QPainter::drawPoints()
void QwtPainter::drawPoints( QPainter *painter,
const QPoint *points, int pointCount )
{
QRectF clipRect;
const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
if ( deviceClipping )
{
const int minX = qCeil( clipRect.left() );
const int maxX = qFloor( clipRect.right() );
const int minY = qCeil( clipRect.top() );
const int maxY = qFloor( clipRect.bottom() );
QPolygon clippedPolygon( pointCount );
QPoint *clippedData = clippedPolygon.data();
int numClippedPoints = 0;
for ( int i = 0; i < pointCount; i++ )
{
if ( r.contains( points[i] ) )
clippedData[ numClippedPoints++ ] = points[i];
}
painter->drawPoints( clippedData, numClippedPoints );
}
else
{
painter->drawPoints( points, pointCount );
//! Wrapper for QPainter::drawPoints()
void QwtPainter::drawPoints( QPainter *painter,
const QPointF *points, int pointCount )
QRectF clipRect;
const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
if ( deviceClipping )
{
QPolygonF clippedPolygon( pointCount );
QPointF *clippedData = clippedPolygon.data();
int numClippedPoints = 0;
for ( int i = 0; i < pointCount; i++ )
{
if ( clipRect.contains( points[i] ) )
clippedData[ numClippedPoints++ ] = points[i];
}
painter->drawPoints( clippedData, numClippedPoints );
}
else
{
painter->drawPoints( points, pointCount );
}
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
//! Wrapper for QPainter::drawImage()
void QwtPainter::drawImage( QPainter *painter,
const QRectF &rect, const QImage &image )
{
const QRect alignedRect = rect.toAlignedRect();
if ( alignedRect != rect )
{
const QRectF clipRect = rect.adjusted( 0.0, 0.0, -1.0, -1.0 );
painter->save();
painter->setClipRect( clipRect, Qt::IntersectClip );
painter->drawImage( alignedRect, image );
painter->restore();
}
else
{
painter->drawImage( alignedRect, image );
}
}
//! Wrapper for QPainter::drawPixmap()
void QwtPainter::drawPixmap( QPainter *painter,
const QRectF &rect, const QPixmap &pixmap )
{
const QRect alignedRect = rect.toAlignedRect();
if ( alignedRect != rect )
{
const QRectF clipRect = rect.adjusted( 0.0, 0.0, -1.0, -1.0 );
painter->save();
painter->setClipRect( clipRect, Qt::IntersectClip );
painter->drawPixmap( alignedRect, pixmap );
painter->restore();
}
else
{
painter->drawPixmap( alignedRect, pixmap );
}
}
//! Draw a focus rectangle on a widget using its style.
void QwtPainter::drawFocusRect( QPainter *painter, const QWidget *widget )
{
drawFocusRect( painter, widget, widget->rect() );
}
//! Draw a focus rectangle on a widget using its style.
void QwtPainter::drawFocusRect( QPainter *painter, const QWidget *widget,
const QRect &rect )
opt.rect = rect;
opt.state |= QStyle::State_HasFocus;
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
widget->style()->drawPrimitive( QStyle::PE_FrameFocusRect,
&opt, painter, widget );
}
/*!
Draw a round frame
\param painter Painter
\param rect Frame rectangle
\param palette QPalette::WindowText is used for plain borders
QPalette::Dark and QPalette::Light for raised
or sunken borders
\param lineWidth Line width
\param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow
*/
void QwtPainter::drawRoundFrame( QPainter *painter,
const QRectF &rect, const QPalette &palette,
int lineWidth, int frameStyle )
{
enum Style
{
Plain,
Sunken,
Raised
};
Style style = Plain;
if ( (frameStyle & QFrame::Sunken) == QFrame::Sunken )
style = Sunken;
else if ( (frameStyle & QFrame::Raised) == QFrame::Raised )
style = Raised;
const double lw2 = 0.5 * lineWidth;
QRectF r = rect.adjusted( lw2, lw2, -lw2, -lw2 );
QBrush brush;
if ( style != Plain )
{
QColor c1 = palette.color( QPalette::Light );
QColor c2 = palette.color( QPalette::Dark );
if ( style == Sunken )
qSwap( c1, c2 );
QLinearGradient gradient( r.topLeft(), r.bottomRight() );
gradient.setColorAt( 0.0, c1 );
#if 0
gradient.setColorAt( 0.3, c1 );
gradient.setColorAt( 0.7, c2 );
gradient.setColorAt( 1.0, c2 );
brush = QBrush( gradient );
}
else // Plain
{
brush = palette.brush( QPalette::WindowText );
}
painter->save();
painter->setPen( QPen( brush, lineWidth ) );
painter->setBrush( Qt::NoBrush );
painter->drawEllipse( r );
/*!
Draw a rectangular frame
\param painter Painter
\param rect Frame rectangle
\param palette Palette
\param foregroundRole Foreground role used for QFrame::Plain
\param frameWidth Frame width
\param midLineWidth Used for QFrame::Box
\param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow
*/
void QwtPainter::drawFrame( QPainter *painter, const QRectF &rect,
const QPalette &palette, QPalette::ColorRole foregroundRole,
int frameWidth, int midLineWidth, int frameStyle )
const int shadow = frameStyle & QFrame::Shadow_Mask;
painter->save();
if ( shadow == QFrame::Plain )
{
const QRectF outerRect = rect.adjusted( 0.0, 0.0, -1.0, -1.0 );
const QRectF innerRect = outerRect.adjusted(
frameWidth, frameWidth, -frameWidth, -frameWidth );
QPainterPath path;
path.addRect( outerRect );
path.addRect( innerRect );
painter->setPen( Qt::NoPen );
painter->setBrush( palette.color( foregroundRole ) );
painter->drawPath( path );
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
else
{
const int shape = frameStyle & QFrame::Shape_Mask;
if ( shape == QFrame::Box )
{
const QRectF outerRect = rect.adjusted( 0.0, 0.0, -1.0, -1.0 );
const QRectF midRect1 = outerRect.adjusted(
frameWidth, frameWidth, -frameWidth, -frameWidth );
const QRectF midRect2 = midRect1.adjusted(
midLineWidth, midLineWidth, -midLineWidth, -midLineWidth );
const QRectF innerRect = midRect2.adjusted(
frameWidth, frameWidth, -frameWidth, -frameWidth );
QPainterPath path1;
path1.moveTo( outerRect.bottomLeft() );
path1.lineTo( outerRect.topLeft() );
path1.lineTo( outerRect.topRight() );
path1.lineTo( midRect1.topRight() );
path1.lineTo( midRect1.topLeft() );
path1.lineTo( midRect1.bottomLeft() );
QPainterPath path2;
path2.moveTo( outerRect.bottomLeft() );
path2.lineTo( outerRect.bottomRight() );
path2.lineTo( outerRect.topRight() );
path2.lineTo( midRect1.topRight() );
path2.lineTo( midRect1.bottomRight() );
path2.lineTo( midRect1.bottomLeft() );
QPainterPath path3;
path3.moveTo( midRect2.bottomLeft() );
path3.lineTo( midRect2.topLeft() );
path3.lineTo( midRect2.topRight() );
path3.lineTo( innerRect.topRight() );
path3.lineTo( innerRect.topLeft() );
path3.lineTo( innerRect.bottomLeft() );
QPainterPath path4;
path4.moveTo( midRect2.bottomLeft() );
path4.lineTo( midRect2.bottomRight() );
path4.lineTo( midRect2.topRight() );
path4.lineTo( innerRect.topRight() );
path4.lineTo( innerRect.bottomRight() );
path4.lineTo( innerRect.bottomLeft() );
QPainterPath path5;
path5.addRect( midRect1 );
path5.addRect( midRect2 );
painter->setPen( Qt::NoPen );
QBrush brush1 = palette.dark().color();
QBrush brush2 = palette.light().color();
if ( shadow == QFrame::Raised )
qSwap( brush1, brush2 );
painter->setBrush( brush1 );
painter->drawPath( path1 );
painter->drawPath( path4 );
painter->setBrush( brush2 );
painter->drawPath( path2 );
painter->drawPath( path3 );
painter->setBrush( palette.mid() );
painter->drawPath( path5 );
}
#if 0
// qDrawWinPanel doesn't result in something nice
// on a scalable document like PDF. Better draw a
// Panel.
else if ( shape == QFrame::WinPanel )
{
painter->setRenderHint( QPainter::NonCosmeticDefaultPen, true );
qDrawWinPanel ( painter, rect.toRect(), palette,
frameStyle & QFrame::Sunken );
}
else if ( shape == QFrame::StyledPanel )
{
}
else
{
const QRectF outerRect = rect.adjusted( 0.0, 0.0, -1.0, -1.0 );
const QRectF innerRect = outerRect.adjusted(
frameWidth - 1.0, frameWidth - 1.0,
-( frameWidth - 1.0 ), -( frameWidth - 1.0 ) );
QPainterPath path1;
path1.moveTo( outerRect.bottomLeft() );
path1.lineTo( outerRect.topLeft() );
path1.lineTo( outerRect.topRight() );
path1.lineTo( innerRect.topRight() );
path1.lineTo( innerRect.topLeft() );
path1.lineTo( innerRect.bottomLeft() );
QPainterPath path2;
path2.moveTo( outerRect.bottomLeft() );
path2.lineTo( outerRect.bottomRight() );
path2.lineTo( outerRect.topRight() );
path2.lineTo( innerRect.topRight() );
path2.lineTo( innerRect.bottomRight() );
path2.lineTo( innerRect.bottomLeft() );
painter->setPen( Qt::NoPen );
QBrush brush1 = palette.dark().color();
QBrush brush2 = palette.light().color();
if ( shadow == QFrame::Raised )
qSwap( brush1, brush2 );
painter->setBrush( brush1 );
painter->drawPath( path1 );
painter->setBrush( brush2 );
painter->drawPath( path2 );
}
}
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
Draw a rectangular frame with rounded borders
\param painter Painter
\param rect Frame rectangle
\param xRadius x-radius of the ellipses defining the corners
\param yRadius y-radius of the ellipses defining the corners
\param palette QPalette::WindowText is used for plain borders
QPalette::Dark and QPalette::Light for raised
or sunken borders
\param lineWidth Line width
\param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow
*/
void QwtPainter::drawRoundedFrame( QPainter *painter,
const QRectF &rect, double xRadius, double yRadius,
const QPalette &palette, int lineWidth, int frameStyle )
{
painter->save();
painter->setRenderHint( QPainter::Antialiasing, true );
painter->setBrush( Qt::NoBrush );
double lw2 = lineWidth * 0.5;
QRectF r = rect.adjusted( lw2, lw2, -lw2, -lw2 );
QPainterPath path;
path.addRoundedRect( r, xRadius, yRadius );
enum Style
{
Plain,
Sunken,
Raised
};
Style style = Plain;
if ( (frameStyle & QFrame::Sunken) == QFrame::Sunken )
style = Sunken;
else if ( (frameStyle & QFrame::Raised) == QFrame::Raised )
style = Raised;
if ( style != Plain && path.elementCount() == 17 )
{
// move + 4 * ( cubicTo + lineTo )
QPainterPath pathList[8];
for ( int i = 0; i < 4; i++ )
{
const int j = i * 4 + 1;
pathList[ 2 * i ].moveTo(
path.elementAt(j - 1).x, path.elementAt( j - 1 ).y
);
pathList[ 2 * i ].cubicTo(
path.elementAt(j + 0).x, path.elementAt(j + 0).y,
path.elementAt(j + 1).x, path.elementAt(j + 1).y,
path.elementAt(j + 2).x, path.elementAt(j + 2).y );
pathList[ 2 * i + 1 ].moveTo(
path.elementAt(j + 2).x, path.elementAt(j + 2).y
);
pathList[ 2 * i + 1 ].lineTo(
path.elementAt(j + 3).x, path.elementAt(j + 3).y
);
}
QColor c1( palette.color( QPalette::Dark ) );
QColor c2( palette.color( QPalette::Light ) );
if ( style == Raised )
qSwap( c1, c2 );
for ( int i = 0; i < 4; i++ )
{
QRectF r = pathList[2 * i].controlPointRect();
QPen arcPen;
arcPen.setCapStyle( Qt::FlatCap );
arcPen.setWidth( lineWidth );
QPen linePen;
linePen.setCapStyle( Qt::FlatCap );
linePen.setWidth( lineWidth );
switch( i )
{
case 0:
{
arcPen.setColor( c1 );
linePen.setColor( c1 );
break;
}
case 1:
{
QLinearGradient gradient;
gradient.setStart( r.topLeft() );
gradient.setFinalStop( r.bottomRight() );