14 #include <qdrawutil.h> 16 #include <qstyleoption.h> 28 if ( state.state() & QPaintEngine::DirtyPen )
32 if ( state.state() & QPaintEngine::DirtyBrush )
36 if ( state.state() & QPaintEngine::DirtyBrushOrigin )
42 virtual void drawRects(
const QRectF *rects,
int count )
44 for (
int i = 0;
i < count;
i++ )
48 virtual void drawRects(
const QRect *rects,
int count )
50 for (
int i = 0;
i < count;
i++ )
54 virtual void drawPath(
const QPainterPath &path )
56 const QRectF rect( QPointF( 0.0, 0.0 ),
d_size );
57 if ( path.controlPointRect().contains( rect.center() ) )
74 QPointF pos( 0.0, 0.0 );
76 for (
int i = 0;
i < path.elementCount();
i++ )
78 QPainterPath::Element el = path.elementAt(
i);
81 case QPainterPath::MoveToElement:
82 case QPainterPath::LineToElement:
88 case QPainterPath::CurveToElement:
90 QRectF r( pos, QPointF( el.x, el.y ) );
98 case QPainterPath::CurveToDataElement:
104 qMin( r.left(), el.x ),
105 qMin( r.top(), el.y ),
106 qMax( r.right(), el.x ),
107 qMax( r.bottom(), el.y )
129 if ( r.center().x() < rect.center().x() )
130 r.setLeft( rect.left() );
132 r.setRight( rect.right() );
134 if ( r.center().y() < rect.center().y() )
135 r.setTop( rect.top() );
137 r.setBottom( rect.bottom() );
169 canvas->setContentsMargins( fw, fw, fw, fw );
176 QPainterPath borderClip;
178 ( void )QMetaObject::invokeMethod(
179 canvas,
"borderPath", Qt::DirectConnection,
180 Q_RETURN_ARG( QPainterPath, borderClip ), Q_ARG( QRect, canvas->rect() ) );
182 if ( !borderClip.isEmpty() )
183 painter->setClipPath( borderClip, Qt::IntersectClip );
185 const QBrush &brush =
186 canvas->palette().brush( canvas->backgroundRole() );
188 if ( brush.style() == Qt::TexturePattern )
190 QPixmap pm( canvas->size() );
192 painter->drawPixmap( 0, 0, pm );
194 else if ( brush.gradient() )
196 QVector<QRect> rects;
198 if ( brush.gradient()->coordinateMode() == QGradient::ObjectBoundingMode )
200 rects += canvas->rect();
204 rects = painter->clipRegion().rects();
208 bool useRaster =
false;
210 if ( painter->paintEngine()->type() == QPaintEngine::X11 )
223 QImage::Format
format = QImage::Format_RGB32;
225 const QGradientStops stops = brush.gradient()->stops();
226 for (
int i = 0;
i < stops.size();
i++ )
228 if ( stops[
i].second.alpha() != 255 )
234 format = QImage::Format_ARGB32;
239 QImage image( canvas->size(), format );
241 QPainter p( &image );
242 p.setPen( Qt::NoPen );
245 p.drawRects( rects );
249 painter->drawImage( 0, 0, image );
253 painter->setPen( Qt::NoPen );
254 painter->setBrush( brush );
256 painter->drawRects( rects );
261 painter->setPen( Qt::NoPen );
262 painter->setBrush( brush );
264 painter->drawRects( painter->clipRegion().rects() );
272 QWidget *w, QPainter *painter )
276 w->style()->drawPrimitive( QStyle::PE_Widget, &opt, painter, w);
281 if ( w->parentWidget() == NULL )
284 if ( w->autoFillBackground() )
286 const QBrush brush = w->palette().brush( w->backgroundRole() );
287 if ( brush.color().alpha() > 0 )
291 if ( w->testAttribute( Qt::WA_StyledBackground ) )
293 QImage image( 1, 1, QImage::Format_ARGB32 );
294 image.fill( Qt::transparent );
296 QPainter painter( &image );
297 painter.translate( -w->rect().center() );
301 if ( qAlpha( image.pixel( 0, 0 ) ) != 0 )
309 QWidget *widget,
const QVector<QRectF> &fillRects )
311 if ( fillRects.isEmpty() )
315 if ( painter->hasClipping() )
316 clipRegion = painter->transform().map( painter->clipRegion() );
318 clipRegion = widget->contentsRect();
325 for (
int i = 0;
i < fillRects.size();
i++ )
327 const QRect rect = fillRects[
i].toAlignedRect();
328 if ( clipRegion.intersects( rect ) )
330 QPixmap pm( rect.size() );
332 painter->drawPixmap( rect, pm );
339 QVector<QRectF> rects;
341 if ( canvas->testAttribute( Qt::WA_StyledBackground ) )
345 QPainter p( &recorder );
349 if ( recorder.background.brush.isOpaque() )
350 rects = recorder.clipRects;
352 rects += canvas->rect();
356 const double borderRadius = canvas->property(
"borderRadius" ).toDouble();
357 if ( borderRadius > 0.0 )
359 QSizeF sz( borderRadius, borderRadius );
361 const QRectF r = canvas->rect();
362 rects += QRectF( r.topLeft(), sz );
363 rects += QRectF( r.topRight() - QPointF( borderRadius, 0 ), sz );
364 rects += QRectF( r.bottomRight() - QPointF( borderRadius, borderRadius ), sz );
365 rects += QRectF( r.bottomLeft() - QPointF( 0, borderRadius ), sz );
374 if ( path.elementCount() == 4 )
376 QPainterPath::Element el0 = path.elementAt(0);
377 QPainterPath::Element el3 = path.elementAt(3);
379 path.setElementPositionAt( 0, el3.x, el3.y );
380 path.setElementPositionAt( 3, el0.x, el0.y );
385 const QList<QPainterPath> &
pathList )
387 if ( pathList.isEmpty() )
388 return QPainterPath();
390 QPainterPath ordered[8];
392 for (
int i = 0;
i < pathList.size();
i++ )
395 QPainterPath subPath = pathList[
i];
397 const QRectF br = pathList[
i].controlPointRect();
398 if ( br.center().x() < rect.center().x() )
400 if ( br.center().y() < rect.center().y() )
402 if ( qAbs( br.top() - rect.top() ) <
403 qAbs( br.left() - rect.left() ) )
414 if ( qAbs( br.bottom() - rect.bottom() ) <
415 qAbs( br.left() - rect.left() ) )
425 if ( subPath.currentPosition().y() > br.center().y() )
430 if ( br.center().y() < rect.center().y() )
432 if ( qAbs( br.top() - rect.top() ) <
433 qAbs( br.right() - rect.right() ) )
444 if ( qAbs( br.bottom() - rect.bottom() ) <
445 qAbs( br.right() - rect.right() ) )
454 if ( subPath.currentPosition().y() < br.center().y() )
457 ordered[index] = subPath;
460 for (
int i = 0;
i < 4;
i++ )
462 if ( ordered[ 2 *
i].isEmpty() != ordered[2 *
i + 1].isEmpty() )
465 return QPainterPath();
470 const QPolygonF corners( rect );
475 for (
int i = 0;
i < 4;
i++ )
477 if ( ordered[2 *
i].isEmpty() )
479 path.lineTo( corners[
i] );
483 path.connectPath( ordered[2 *
i] );
484 path.connectPath( ordered[2 * i + 1] );
491 return path.simplified();
497 static QPainterPath
qwtBorderPath(
const QWidget *canvas,
const QRect &rect )
499 if ( canvas->testAttribute(Qt::WA_StyledBackground ) )
503 QPainter painter( &recorder );
506 opt.initFrom( canvas );
508 canvas->style()->drawPrimitive( QStyle::PE_Widget, &opt, &painter, canvas );
512 if ( !recorder.background.path.isEmpty() )
513 return recorder.background.path;
515 if ( !recorder.border.rectList.isEmpty() )
520 const double borderRadius = canvas->property(
"borderRadius" ).toDouble();
522 if ( borderRadius > 0.0 )
524 double fw2 = canvas->property(
"frameWidth" ).toInt() * 0.5;
525 QRectF r = QRectF(rect).adjusted( fw2, fw2, -fw2, -fw2 );
528 path.addRoundedRect( r, borderRadius, borderRadius );
533 return QPainterPath();
540 focusIndicator( NoFocusIndicator ),
543 styleSheet.hasBorder =
false;
569 d_data->canvasWidget = canvasWidget;
572 canvasWidget->setCursor( Qt::CrossCursor );
575 canvasWidget->setAutoFillBackground(
true );
577 canvasWidget->setProperty(
"lineWidth", 2 );
578 canvasWidget->setProperty(
"frameShadow", QFrame::Sunken );
579 canvasWidget->setProperty(
"frameShape", QFrame::Panel );
590 return qobject_cast<
QwtPlot *>(
d_data->canvasWidget->parent() );
596 return qobject_cast<
const QwtPlot *>(
d_data->canvasWidget->parent() );
606 d_data->focusIndicator = focusIndicator;
616 return d_data->focusIndicator;
625 const int margin = 1;
627 QRect focusRect =
d_data->canvasWidget->contentsRect();
628 focusRect.setRect( focusRect.x() + margin, focusRect.y() + margin,
629 focusRect.width() - 2 * margin, focusRect.height() - 2 * margin );
642 d_data->borderRadius = qMax( 0.0, radius );
651 return d_data->borderRadius;
665 const QWidget *
w = canvasWidget();
667 if (
d_data->borderRadius > 0 )
669 const int frameWidth = w->property(
"frameWidth" ).toInt();
670 if ( frameWidth > 0 )
672 const int frameShape = w->property(
"frameShape" ).toInt();
673 const int frameShadow = w->property(
"frameShadow" ).toInt();
675 const QRectF frameRect = w->property(
"frameRect" ).toRect();
679 w->palette(), frameWidth, frameShape | frameShadow );
684 #if QT_VERSION >= 0x040500 685 const int frameShape = w->property(
"frameShape" ).toInt();
686 const int frameShadow = w->property(
"frameShadow" ).toInt();
688 #if QT_VERSION < 0x050000 689 QStyleOptionFrameV3 opt;
691 QStyleOptionFrame opt;
695 opt.frameShape = QFrame::Shape(
int( opt.frameShape ) | frameShape );
702 case QFrame::StyledPanel:
705 opt.lineWidth = w->property(
"lineWidth" ).toInt();
706 opt.midLineWidth = w->property(
"midLineWidth" ).toInt();
711 opt.lineWidth = w->property(
"frameWidth" ).toInt();
716 if ( frameShadow == QFrame::Sunken )
717 opt.state |= QStyle::State_Sunken;
718 else if ( frameShadow == QFrame::Raised )
719 opt.state |= QStyle::State_Raised;
721 w->style()->drawControl(QStyle::CE_ShapedFrame, &opt, painter, w );
740 fillBackground( painter );
742 QWidget *
w = canvasWidget();
744 if ( w->autoFillBackground() )
746 const QRect canvasRect = w->rect();
750 painter->setPen( Qt::NoPen );
751 painter->setBrush( w->palette().brush( w->backgroundRole() ) );
753 const QRect frameRect = w->property(
"frameRect" ).toRect();
754 if ( borderRadius() > 0.0 && ( canvasRect == frameRect ) )
756 const int frameWidth = w->property(
"frameWidth" ).toInt();
757 if ( frameWidth > 0 )
759 painter->setClipPath( borderPath2( canvasRect ) );
760 painter->drawRect( canvasRect );
764 painter->setRenderHint( QPainter::Antialiasing,
true );
765 painter->drawPath( borderPath2( canvasRect ) );
770 painter->drawRect( canvasRect );
776 drawCanvas( painter );
781 fillBackground( painter );
783 if ( hackStyledBackground )
797 if ( !
d_data->styleSheet.hasBorder ||
798 d_data->styleSheet.borderPath.isEmpty() )
801 hackStyledBackground =
false;
805 QWidget *
w = canvasWidget();
807 if ( hackStyledBackground )
812 painter->setPen( Qt::NoPen );
813 painter->setBrush(
d_data->styleSheet.background.brush );
814 painter->setBrushOrigin(
d_data->styleSheet.background.origin );
815 painter->setClipPath(
d_data->styleSheet.borderPath );
816 painter->drawRect( w->contentsRect() );
820 drawCanvas( painter );
823 QStyleOptionFrame opt;
825 w->style()->drawPrimitive( QStyle::PE_Frame, &opt, painter, w);
831 w->style()->drawPrimitive( QStyle::PE_Widget, &opt, painter, w );
833 drawCanvas( painter );
839 QWidget *
w = canvasWidget();
843 if ( !
d_data->styleSheet.borderPath.isEmpty() )
845 painter->setClipPath(
846 d_data->styleSheet.borderPath, Qt::IntersectClip );
850 if ( borderRadius() > 0.0 )
852 const QRect frameRect = w->property(
"frameRect" ).toRect();
853 painter->setClipPath( borderPath2( frameRect ), Qt::IntersectClip );
857 painter->setClipRect( w->contentsRect(), Qt::IntersectClip );
871 QWidget *
w = canvasWidget();
873 if ( !w->testAttribute( Qt::WA_StyledBackground ) )
878 QPainter painter( &recorder );
882 w->style()->drawPrimitive( QStyle::PE_Widget, &opt, &painter, w);
886 d_data->styleSheet.hasBorder = !recorder.border.rectList.isEmpty();
887 d_data->styleSheet.cornerRects = recorder.clipRects;
889 if ( recorder.background.path.isEmpty() )
891 if ( !recorder.border.rectList.isEmpty() )
893 d_data->styleSheet.borderPath =
899 d_data->styleSheet.borderPath = recorder.background.path;
900 d_data->styleSheet.background.brush = recorder.background.brush;
901 d_data->styleSheet.background.origin = recorder.background.origin;
907 return d_data->canvasWidget;
912 return d_data->canvasWidget;
919 frameStyle( QFrame::Panel | QFrame::Sunken),
1066 width = qMax( width, 0 );
1094 width = qMax( width, 0 );
1130 w->repaint( w->contentsRect() );
1132 w->update( w->contentsRect() );
1139 return canvasWidget()->contentsRect().adjusted( -fw, -fw, fw, fw );
1144 #if FIX_GL_TRANSLATION 1145 if ( painter->paintEngine()->type() == QPaintEngine::OpenGL2 )
1148 painter->translate( 1, 1 );
1152 if (
canvasWidget()->testAttribute( Qt::WA_StyledBackground ) )
QVector< QRectF > clipRects
virtual void clearBackingStore()=0
Paint double buffered reusing the content of the pixmap buffer when possible.
virtual void drawBackground(QPainter *)
static void fillPixmap(const QWidget *, QPixmap &, const QPoint &offset=QPoint())
QVector< QRectF > cornerRects
static void qwtRevertPath(QPainterPath &path)
void setPaintAttribute(PaintAttribute, bool on=true)
Changing the paint attributes.
static void drawFocusRect(QPainter *, const QWidget *)
Draw a focus rectangle on a widget using its style.
bool testPaintAttribute(PaintAttribute) const
void setBorderRadius(double)
void drawCanvas(QPainter *)
double borderRadius() const
QwtPlotAbstractGLCanvas::PaintAttributes paintAttributes
void drawUnstyled(QPainter *)
A null paint device doing nothing.
void setFrameStyle(int style)
FocusIndicator focusIndicator() const
static void qwtUpdateContentsRect(int fw, QWidget *canvas)
static void qwtDrawBackground(QPainter *painter, QWidget *canvas)
virtual void drawRects(const QRectF *rects, int count)
See QPaintEngine::drawRects()
void drawStyled(QPainter *, bool)
virtual ~QwtPlotAbstractGLCanvas()
FocusIndicator focusIndicator
virtual void drawPath(const QPainterPath &path)
See QPaintEngine::drawPath()
void setMidLineWidth(int)
virtual QSize sizeMetrics() const
static void drawRoundedFrame(QPainter *, const QRectF &, double xRadius, double yRadius, const QPalette &, int lineWidth, int frameStyle)
struct QwtStyleSheetRecorder::Background background
GraphId path[kMaxDeadlockPathLen]
void alignCornerRects(const QRectF &rect)
virtual void drawCanvas(QPainter *)
QFrame::Shape frameShape() const
virtual void drawRects(const QRect *rects, int count)
See QPaintEngine::drawRects()
static QPainterPath qwtBorderPath(const QWidget *canvas, const QRect &rect)
static QPainterPath qwtCombinePathList(const QRectF &rect, const QList< QPainterPath > &pathList)
QFrame::Shadow frameShadow() const
static void qwtDrawStyledBackground(QWidget *w, QPainter *painter)
std::string format(const std::string &, const time_point< seconds > &, const femtoseconds &, const time_zone &)
QwtPlotAbstractGLCanvas(QWidget *canvasWidget)
void setFrameShape(QFrame::Shape)
void setFocusIndicator(FocusIndicator)
virtual ~QwtPlotAbstractCanvas()
QPainterPath borderPath2(const QRect &rect) const
TFSIMD_FORCE_INLINE const tfScalar & w() const
virtual void drawBorder(QPainter *)
QFlags< PaintAttribute > PaintAttributes
Paint attributes.
FocusIndicator
Focus indicator The default setting is NoFocusIndicator.
QwtPlot * plot()
Return parent plot widget.
void setCornerRects(const QPainterPath &path)
static QWidget * qwtBackgroundWidget(QWidget *w)
QwtPlotAbstractCanvas(QWidget *canvasWidget)
void setFrameShadow(QFrame::Shadow)
virtual void drawFocusIndicator(QPainter *)
void fillBackground(QPainter *)
QwtStyleSheetRecorder(const QSize &size)
virtual void updateState(const QPaintEngineState &state)
See QPaintEngine::updateState()
void updateStyleSheetInfo()
Update the cached information about the current style sheet.
static void qwtFillBackground(QPainter *painter, QWidget *widget, const QVector< QRectF > &fillRects)
virtual void invalidateBackingStore()=0
PaintAttribute
Paint attributes.
struct QwtStyleSheetRecorder::Border border
QList< QPainterPath > pathList