File indexing completed on 2025-01-18 10:09:38
0001
0002
0003
0004 #ifndef QSTYLEPAINTER_H
0005 #define QSTYLEPAINTER_H
0006
0007 #include <QtWidgets/qtwidgetsglobal.h>
0008 #include <QtGui/qpainter.h>
0009 #include <QtWidgets/qstyle.h>
0010 #include <QtWidgets/qwidget.h>
0011
0012 QT_BEGIN_NAMESPACE
0013
0014
0015 class QStylePainter : public QPainter
0016 {
0017 public:
0018 inline QStylePainter() : QPainter(), widget(nullptr), wstyle(nullptr) {}
0019 inline explicit QStylePainter(QWidget *w) { begin(w, w); }
0020 inline QStylePainter(QPaintDevice *pd, QWidget *w) { begin(pd, w); }
0021 inline bool begin(QWidget *w) { return begin(w, w); }
0022 inline bool begin(QPaintDevice *pd, QWidget *w) {
0023 Q_ASSERT_X(w, "QStylePainter::QStylePainter", "Widget must be non-zero");
0024 widget = w;
0025 wstyle = w->style();
0026 const bool res = QPainter::begin(pd);
0027 setRenderHint(QPainter::SmoothPixmapTransform);
0028 return res;
0029 }
0030 inline void drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOption &opt);
0031 inline void drawControl(QStyle::ControlElement ce, const QStyleOption &opt);
0032 inline void drawComplexControl(QStyle::ComplexControl cc, const QStyleOptionComplex &opt);
0033 inline void drawItemText(const QRect &r, int flags, const QPalette &pal, bool enabled,
0034 const QString &text, QPalette::ColorRole textRole = QPalette::NoRole);
0035 inline void drawItemPixmap(const QRect &r, int flags, const QPixmap &pixmap);
0036 inline QStyle *style() const { return wstyle; }
0037
0038 private:
0039 QWidget *widget;
0040 QStyle *wstyle;
0041 Q_DISABLE_COPY(QStylePainter)
0042 };
0043
0044 void QStylePainter::drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOption &opt)
0045 {
0046 wstyle->drawPrimitive(pe, &opt, this, widget);
0047 }
0048
0049 void QStylePainter::drawControl(QStyle::ControlElement ce, const QStyleOption &opt)
0050 {
0051 wstyle->drawControl(ce, &opt, this, widget);
0052 }
0053
0054 void QStylePainter::drawComplexControl(QStyle::ComplexControl cc, const QStyleOptionComplex &opt)
0055 {
0056 wstyle->drawComplexControl(cc, &opt, this, widget);
0057 }
0058
0059 void QStylePainter::drawItemText(const QRect &r, int flags, const QPalette &pal, bool enabled,
0060 const QString &text, QPalette::ColorRole textRole)
0061 {
0062 wstyle->drawItemText(this, r, flags, pal, enabled, text, textRole);
0063 }
0064
0065 void QStylePainter::drawItemPixmap(const QRect &r, int flags, const QPixmap &pixmap)
0066 {
0067 wstyle->drawItemPixmap(this, r, flags, pixmap);
0068 }
0069
0070 QT_END_NAMESPACE
0071
0072 #endif