| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtWidgets module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #include "qstylepainter.h" |
| 41 | |
| 42 | QT_BEGIN_NAMESPACE |
| 43 | |
| 44 | /*! |
| 45 | \class QStylePainter |
| 46 | |
| 47 | \brief The QStylePainter class is a convenience class for drawing QStyle |
| 48 | elements inside a widget. |
| 49 | |
| 50 | \ingroup appearance |
| 51 | \ingroup painting |
| 52 | \inmodule QtWidgets |
| 53 | |
| 54 | QStylePainter extends QPainter with a set of high-level \c |
| 55 | draw...() functions implemented on top of QStyle's API. The |
| 56 | advantage of using QStylePainter is that the parameter lists get |
| 57 | considerably shorter. Whereas a QStyle object must be able to |
| 58 | draw on any widget using any painter (because the application |
| 59 | normally has one QStyle object shared by all widget), a |
| 60 | QStylePainter is initialized with a widget, eliminating the need |
| 61 | to specify the QWidget, the QPainter, and the QStyle for every |
| 62 | function call. |
| 63 | |
| 64 | Example using QStyle directly: |
| 65 | |
| 66 | \snippet styles/styles.cpp 1 |
| 67 | |
| 68 | Example using QStylePainter: |
| 69 | |
| 70 | \snippet styles/styles.cpp 0 |
| 71 | \snippet styles/styles.cpp 4 |
| 72 | \snippet styles/styles.cpp 6 |
| 73 | |
| 74 | \sa QStyle, QStyleOption |
| 75 | */ |
| 76 | |
| 77 | /*! |
| 78 | \fn QStylePainter::QStylePainter() |
| 79 | |
| 80 | Constructs a QStylePainter. |
| 81 | */ |
| 82 | |
| 83 | /*! |
| 84 | \fn QStylePainter::QStylePainter(QWidget *widget) |
| 85 | |
| 86 | Construct a QStylePainter using widget \a widget for its paint device. |
| 87 | */ |
| 88 | |
| 89 | /*! |
| 90 | \fn QStylePainter::QStylePainter(QPaintDevice *pd, QWidget *widget) |
| 91 | |
| 92 | Construct a QStylePainter using \a pd for its paint device, and |
| 93 | attributes from \a widget. |
| 94 | */ |
| 95 | |
| 96 | |
| 97 | /*! |
| 98 | \fn bool QStylePainter::begin(QWidget *widget) |
| 99 | |
| 100 | Begin painting operations on the specified \a widget. |
| 101 | Returns \c true if the painter is ready to use; otherwise returns \c false. |
| 102 | |
| 103 | This is automatically called by the constructor that takes a QWidget. |
| 104 | */ |
| 105 | |
| 106 | /*! |
| 107 | \fn bool QStylePainter::begin(QPaintDevice *pd, QWidget *widget) |
| 108 | \overload |
| 109 | |
| 110 | Begin painting operations on paint device \a pd as if it was \a |
| 111 | widget. |
| 112 | |
| 113 | This is automatically called by the constructor that |
| 114 | takes a QPaintDevice and a QWidget. |
| 115 | */ |
| 116 | |
| 117 | |
| 118 | /*! |
| 119 | \fn void QStylePainter::drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOption &option) |
| 120 | |
| 121 | Use the widget's style to draw a primitive element \a pe specified by QStyleOption \a option. |
| 122 | |
| 123 | \sa QStyle::drawPrimitive() |
| 124 | */ |
| 125 | |
| 126 | /*! |
| 127 | \fn void QStylePainter::drawControl(QStyle::ControlElement ce, const QStyleOption &option) |
| 128 | |
| 129 | Use the widget's style to draw a control element \a ce specified by QStyleOption \a option. |
| 130 | |
| 131 | \sa QStyle::drawControl() |
| 132 | */ |
| 133 | |
| 134 | /*! |
| 135 | \fn void QStylePainter::drawComplexControl(QStyle::ComplexControl cc, |
| 136 | const QStyleOptionComplex &option) |
| 137 | |
| 138 | Use the widget's style to draw a complex control \a cc specified by the |
| 139 | QStyleOptionComplex \a option. |
| 140 | |
| 141 | \sa QStyle::drawComplexControl() |
| 142 | */ |
| 143 | |
| 144 | /*! |
| 145 | \fn void QStylePainter::drawItemText(const QRect &rect, int flags, const QPalette &pal, |
| 146 | bool enabled, const QString &text, |
| 147 | QPalette::ColorRole textRole = QPalette::NoRole) |
| 148 | |
| 149 | Draws the \a text in rectangle \a rect and palette \a pal. |
| 150 | The text is aligned and wrapped according to \a |
| 151 | flags. |
| 152 | |
| 153 | The pen color is specified with \a textRole. The \a enabled bool |
| 154 | indicates whether or not the item is enabled; when reimplementing |
| 155 | this bool should influence how the item is drawn. |
| 156 | |
| 157 | \sa QStyle::drawItemText(), Qt::Alignment |
| 158 | */ |
| 159 | |
| 160 | /*! |
| 161 | \fn void QStylePainter::drawItemPixmap(const QRect &rect, int flags, const QPixmap &pixmap) |
| 162 | |
| 163 | Draws the \a pixmap in rectangle \a rect. |
| 164 | The pixmap is aligned according to \a flags. |
| 165 | |
| 166 | \sa QStyle::drawItemPixmap(), Qt::Alignment |
| 167 | */ |
| 168 | |
| 169 | /*! |
| 170 | \fn QStyle *QStylePainter::style() const |
| 171 | |
| 172 | Return the current style used by the QStylePainter. |
| 173 | */ |
| 174 | |
| 175 | QT_END_NAMESPACE |
| 176 | |