| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/styles/qstylehelper.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 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 <qstyleoption.h> | - | ||||||||||||||||||||||||||||||||||||
| 41 | #include <qpainter.h> | - | ||||||||||||||||||||||||||||||||||||
| 42 | #include <qpixmapcache.h> | - | ||||||||||||||||||||||||||||||||||||
| 43 | #include <private/qmath_p.h> | - | ||||||||||||||||||||||||||||||||||||
| 44 | #include <private/qstyle_p.h> | - | ||||||||||||||||||||||||||||||||||||
| 45 | #include <qmath.h> | - | ||||||||||||||||||||||||||||||||||||
| 46 | #include <qscrollbar.h> | - | ||||||||||||||||||||||||||||||||||||
| 47 | #include <qabstractscrollarea.h> | - | ||||||||||||||||||||||||||||||||||||
| 48 | #include <qwindow.h> | - | ||||||||||||||||||||||||||||||||||||
| 49 | - | |||||||||||||||||||||||||||||||||||||
| 50 | #include "qstylehelper_p.h" | - | ||||||||||||||||||||||||||||||||||||
| 51 | #include <qstringbuilder.h> | - | ||||||||||||||||||||||||||||||||||||
| 52 | #include <qdatastream.h> | - | ||||||||||||||||||||||||||||||||||||
| 53 | #include <qcryptographichash.h> | - | ||||||||||||||||||||||||||||||||||||
| 54 | - | |||||||||||||||||||||||||||||||||||||
| 55 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||||||||||||||
| 56 | - | |||||||||||||||||||||||||||||||||||||
| 57 | Q_GUI_EXPORT int qt_defaultDpiX(); | - | ||||||||||||||||||||||||||||||||||||
| 58 | - | |||||||||||||||||||||||||||||||||||||
| 59 | namespace QStyleHelper { | - | ||||||||||||||||||||||||||||||||||||
| 60 | - | |||||||||||||||||||||||||||||||||||||
| 61 | QString uniqueName(const QString &key, const QStyleOption *option, const QSize &size) | - | ||||||||||||||||||||||||||||||||||||
| 62 | { | - | ||||||||||||||||||||||||||||||||||||
| 63 | const QStyleOptionComplex *complexOption = qstyleoption_cast<const QStyleOptionComplex *>(option); | - | ||||||||||||||||||||||||||||||||||||
| 64 | QString tmp = key % HexString<uint>(option->state) | - | ||||||||||||||||||||||||||||||||||||
| 65 | % HexString<uint>(option->direction) | - | ||||||||||||||||||||||||||||||||||||
| 66 | % HexString<uint>(complexOption ? uint(complexOption->activeSubControls) : 0u) | - | ||||||||||||||||||||||||||||||||||||
| 67 | % HexString<uint>(size.width()) | - | ||||||||||||||||||||||||||||||||||||
| 68 | % HexString<uint>(size.height()); | - | ||||||||||||||||||||||||||||||||||||
| 69 | - | |||||||||||||||||||||||||||||||||||||
| 70 | #ifndef QT_NO_SPINBOX | - | ||||||||||||||||||||||||||||||||||||
| 71 | if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 72 | tmp = tmp % HexString<uint>(spinBox->buttonSymbols) | - | ||||||||||||||||||||||||||||||||||||
| 73 | % HexString<uint>(spinBox->stepEnabled) | - | ||||||||||||||||||||||||||||||||||||
| 74 | % QLatin1Char(spinBox->frame ? '1' : '0'); ; | - | ||||||||||||||||||||||||||||||||||||
| 75 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 76 | #endif // QT_NO_SPINBOX | - | ||||||||||||||||||||||||||||||||||||
| 77 | - | |||||||||||||||||||||||||||||||||||||
| 78 | // QTBUG-56743, try to create a palette cache key reflecting the value, | - | ||||||||||||||||||||||||||||||||||||
| 79 | // as leaks may occur in conjunction with QStyleSheetStyle/QRenderRule modifying | - | ||||||||||||||||||||||||||||||||||||
| 80 | // palettes when using QPalette::cacheKey() | - | ||||||||||||||||||||||||||||||||||||
| 81 | if (option->palette != QGuiApplication::palette()) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 82 | tmp.append(QLatin1Char('P')); | - | ||||||||||||||||||||||||||||||||||||
| 83 | #ifndef QT_NO_DATASTREAM | - | ||||||||||||||||||||||||||||||||||||
| 84 | QByteArray key; | - | ||||||||||||||||||||||||||||||||||||
| 85 | key.reserve(5120); // Observed 5040B for a serialized palette on 64bit | - | ||||||||||||||||||||||||||||||||||||
| 86 | { | - | ||||||||||||||||||||||||||||||||||||
| 87 | QDataStream str(&key, QIODevice::WriteOnly); | - | ||||||||||||||||||||||||||||||||||||
| 88 | str << option->palette; | - | ||||||||||||||||||||||||||||||||||||
| 89 | } | - | ||||||||||||||||||||||||||||||||||||
| 90 | const QByteArray sha1 = QCryptographicHash::hash(key, QCryptographicHash::Sha1).toHex(); | - | ||||||||||||||||||||||||||||||||||||
| 91 | tmp.append(QString::fromLatin1(sha1)); | - | ||||||||||||||||||||||||||||||||||||
| 92 | #else // QT_NO_DATASTREAM | - | ||||||||||||||||||||||||||||||||||||
| 93 | tmp.append(QString::number(option->palette.cacheKey(), 16)); | - | ||||||||||||||||||||||||||||||||||||
| 94 | #endif // !QT_NO_DATASTREAM | - | ||||||||||||||||||||||||||||||||||||
| 95 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 96 | return tmp; never executed: return tmp; | 0 | ||||||||||||||||||||||||||||||||||||
| 97 | } | - | ||||||||||||||||||||||||||||||||||||
| 98 | - | |||||||||||||||||||||||||||||||||||||
| 99 | qreal dpiScaled(qreal value) | - | ||||||||||||||||||||||||||||||||||||
| 100 | { | - | ||||||||||||||||||||||||||||||||||||
| 101 | #ifdef Q_OS_MAC | - | ||||||||||||||||||||||||||||||||||||
| 102 | // On mac the DPI is always 72 so we should not scale it | - | ||||||||||||||||||||||||||||||||||||
| 103 | return value; | - | ||||||||||||||||||||||||||||||||||||
| 104 | #else | - | ||||||||||||||||||||||||||||||||||||
| 105 | static const qreal scale = qreal(qt_defaultDpiX()) / 96.0; | - | ||||||||||||||||||||||||||||||||||||
| 106 | return value * scale; never executed: return value * scale; | 0 | ||||||||||||||||||||||||||||||||||||
| 107 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 108 | } | - | ||||||||||||||||||||||||||||||||||||
| 109 | - | |||||||||||||||||||||||||||||||||||||
| 110 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||||||||||||||
| 111 | bool isInstanceOf(QObject *obj, QAccessible::Role role) | - | ||||||||||||||||||||||||||||||||||||
| 112 | { | - | ||||||||||||||||||||||||||||||||||||
| 113 | bool match = false; | - | ||||||||||||||||||||||||||||||||||||
| 114 | QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(obj); | - | ||||||||||||||||||||||||||||||||||||
| 115 | match = iface && iface->role() == role;
| 0 | ||||||||||||||||||||||||||||||||||||
| 116 | return match; never executed: return match; | 0 | ||||||||||||||||||||||||||||||||||||
| 117 | } | - | ||||||||||||||||||||||||||||||||||||
| 118 | - | |||||||||||||||||||||||||||||||||||||
| 119 | // Searches for an ancestor of a particular accessible role | - | ||||||||||||||||||||||||||||||||||||
| 120 | bool hasAncestor(QObject *obj, QAccessible::Role role) | - | ||||||||||||||||||||||||||||||||||||
| 121 | { | - | ||||||||||||||||||||||||||||||||||||
| 122 | bool found = false; | - | ||||||||||||||||||||||||||||||||||||
| 123 | QObject *parent = obj ? obj->parent() : 0;
| 0 | ||||||||||||||||||||||||||||||||||||
| 124 | while (parent && !found) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 125 | if (isInstanceOf(parent, role))
| 0 | ||||||||||||||||||||||||||||||||||||
| 126 | found = true; never executed: found = true; | 0 | ||||||||||||||||||||||||||||||||||||
| 127 | parent = parent->parent(); | - | ||||||||||||||||||||||||||||||||||||
| 128 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 129 | return found; never executed: return found; | 0 | ||||||||||||||||||||||||||||||||||||
| 130 | } | - | ||||||||||||||||||||||||||||||||||||
| 131 | #endif // QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||||||||||||||
| 132 | - | |||||||||||||||||||||||||||||||||||||
| 133 | - | |||||||||||||||||||||||||||||||||||||
| 134 | #ifndef QT_NO_DIAL | - | ||||||||||||||||||||||||||||||||||||
| 135 | - | |||||||||||||||||||||||||||||||||||||
| 136 | int calcBigLineSize(int radius) | - | ||||||||||||||||||||||||||||||||||||
| 137 | { | - | ||||||||||||||||||||||||||||||||||||
| 138 | int bigLineSize = radius / 6; | - | ||||||||||||||||||||||||||||||||||||
| 139 | if (bigLineSize < 4)
| 0 | ||||||||||||||||||||||||||||||||||||
| 140 | bigLineSize = 4; never executed: bigLineSize = 4; | 0 | ||||||||||||||||||||||||||||||||||||
| 141 | if (bigLineSize > radius / 2)
| 0 | ||||||||||||||||||||||||||||||||||||
| 142 | bigLineSize = radius / 2; never executed: bigLineSize = radius / 2; | 0 | ||||||||||||||||||||||||||||||||||||
| 143 | return bigLineSize; never executed: return bigLineSize; | 0 | ||||||||||||||||||||||||||||||||||||
| 144 | } | - | ||||||||||||||||||||||||||||||||||||
| 145 | - | |||||||||||||||||||||||||||||||||||||
| 146 | static QPointF calcRadialPos(const QStyleOptionSlider *dial, qreal offset) | - | ||||||||||||||||||||||||||||||||||||
| 147 | { | - | ||||||||||||||||||||||||||||||||||||
| 148 | const int width = dial->rect.width(); | - | ||||||||||||||||||||||||||||||||||||
| 149 | const int height = dial->rect.height(); | - | ||||||||||||||||||||||||||||||||||||
| 150 | const int r = qMin(width, height) / 2; | - | ||||||||||||||||||||||||||||||||||||
| 151 | const int currentSliderPosition = dial->upsideDown ? dial->sliderPosition : (dial->maximum - dial->sliderPosition);
| 0 | ||||||||||||||||||||||||||||||||||||
| 152 | qreal a = 0; | - | ||||||||||||||||||||||||||||||||||||
| 153 | if (dial->maximum == dial->minimum)
| 0 | ||||||||||||||||||||||||||||||||||||
| 154 | a = Q_PI / 2; never executed: a = Q_PI / 2; | 0 | ||||||||||||||||||||||||||||||||||||
| 155 | else if (dial->dialWrapping)
| 0 | ||||||||||||||||||||||||||||||||||||
| 156 | a = Q_PI * 3 / 2 - (currentSliderPosition - dial->minimum) * 2 * Q_PI never executed: a = Q_PI * 3 / 2 - (currentSliderPosition - dial->minimum) * 2 * Q_PI / (dial->maximum - dial->minimum); | 0 | ||||||||||||||||||||||||||||||||||||
| 157 | / (dial->maximum - dial->minimum); never executed: a = Q_PI * 3 / 2 - (currentSliderPosition - dial->minimum) * 2 * Q_PI / (dial->maximum - dial->minimum); | 0 | ||||||||||||||||||||||||||||||||||||
| 158 | else | - | ||||||||||||||||||||||||||||||||||||
| 159 | a = (Q_PI * 8 - (currentSliderPosition - dial->minimum) * 10 * Q_PI never executed: a = (Q_PI * 8 - (currentSliderPosition - dial->minimum) * 10 * Q_PI / (dial->maximum - dial->minimum)) / 6; | 0 | ||||||||||||||||||||||||||||||||||||
| 160 | / (dial->maximum - dial->minimum)) / 6; never executed: a = (Q_PI * 8 - (currentSliderPosition - dial->minimum) * 10 * Q_PI / (dial->maximum - dial->minimum)) / 6; | 0 | ||||||||||||||||||||||||||||||||||||
| 161 | qreal xc = width / 2.0; | - | ||||||||||||||||||||||||||||||||||||
| 162 | qreal yc = height / 2.0; | - | ||||||||||||||||||||||||||||||||||||
| 163 | qreal len = r - QStyleHelper::calcBigLineSize(r) - 3; | - | ||||||||||||||||||||||||||||||||||||
| 164 | qreal back = offset * len; | - | ||||||||||||||||||||||||||||||||||||
| 165 | QPointF pos(QPointF(xc + back * qCos(a), yc - back * qSin(a))); | - | ||||||||||||||||||||||||||||||||||||
| 166 | return pos; never executed: return pos; | 0 | ||||||||||||||||||||||||||||||||||||
| 167 | } | - | ||||||||||||||||||||||||||||||||||||
| 168 | - | |||||||||||||||||||||||||||||||||||||
| 169 | qreal angle(const QPointF &p1, const QPointF &p2) | - | ||||||||||||||||||||||||||||||||||||
| 170 | { | - | ||||||||||||||||||||||||||||||||||||
| 171 | static const qreal rad_factor = 180 / Q_PI; | - | ||||||||||||||||||||||||||||||||||||
| 172 | qreal _angle = 0; | - | ||||||||||||||||||||||||||||||||||||
| 173 | - | |||||||||||||||||||||||||||||||||||||
| 174 | if (p1.x() == p2.x()) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 175 | if (p1.y() < p2.y())
| 0 | ||||||||||||||||||||||||||||||||||||
| 176 | _angle = 270; never executed: _angle = 270; | 0 | ||||||||||||||||||||||||||||||||||||
| 177 | else | - | ||||||||||||||||||||||||||||||||||||
| 178 | _angle = 90; never executed: _angle = 90; | 0 | ||||||||||||||||||||||||||||||||||||
| 179 | } else { | - | ||||||||||||||||||||||||||||||||||||
| 180 | qreal x1, x2, y1, y2; | - | ||||||||||||||||||||||||||||||||||||
| 181 | - | |||||||||||||||||||||||||||||||||||||
| 182 | if (p1.x() <= p2.x()) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 183 | x1 = p1.x(); y1 = p1.y(); | - | ||||||||||||||||||||||||||||||||||||
| 184 | x2 = p2.x(); y2 = p2.y(); | - | ||||||||||||||||||||||||||||||||||||
| 185 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 186 | x2 = p1.x(); y2 = p1.y(); | - | ||||||||||||||||||||||||||||||||||||
| 187 | x1 = p2.x(); y1 = p2.y(); | - | ||||||||||||||||||||||||||||||||||||
| 188 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 189 | - | |||||||||||||||||||||||||||||||||||||
| 190 | qreal m = -(y2 - y1) / (x2 - x1); | - | ||||||||||||||||||||||||||||||||||||
| 191 | _angle = qAtan(m) * rad_factor; | - | ||||||||||||||||||||||||||||||||||||
| 192 | - | |||||||||||||||||||||||||||||||||||||
| 193 | if (p1.x() < p2.x())
| 0 | ||||||||||||||||||||||||||||||||||||
| 194 | _angle = 180 - _angle; never executed: _angle = 180 - _angle; | 0 | ||||||||||||||||||||||||||||||||||||
| 195 | else | - | ||||||||||||||||||||||||||||||||||||
| 196 | _angle = -_angle; never executed: _angle = -_angle; | 0 | ||||||||||||||||||||||||||||||||||||
| 197 | } | - | ||||||||||||||||||||||||||||||||||||
| 198 | return _angle; never executed: return _angle; | 0 | ||||||||||||||||||||||||||||||||||||
| 199 | } | - | ||||||||||||||||||||||||||||||||||||
| 200 | - | |||||||||||||||||||||||||||||||||||||
| 201 | QPolygonF calcLines(const QStyleOptionSlider *dial) | - | ||||||||||||||||||||||||||||||||||||
| 202 | { | - | ||||||||||||||||||||||||||||||||||||
| 203 | QPolygonF poly; | - | ||||||||||||||||||||||||||||||||||||
| 204 | int width = dial->rect.width(); | - | ||||||||||||||||||||||||||||||||||||
| 205 | int height = dial->rect.height(); | - | ||||||||||||||||||||||||||||||||||||
| 206 | qreal r = qMin(width, height) / 2; | - | ||||||||||||||||||||||||||||||||||||
| 207 | int bigLineSize = calcBigLineSize(int(r)); | - | ||||||||||||||||||||||||||||||||||||
| 208 | - | |||||||||||||||||||||||||||||||||||||
| 209 | qreal xc = width / 2 + 0.5; | - | ||||||||||||||||||||||||||||||||||||
| 210 | qreal yc = height / 2 + 0.5; | - | ||||||||||||||||||||||||||||||||||||
| 211 | const int ns = dial->tickInterval; | - | ||||||||||||||||||||||||||||||||||||
| 212 | if (!ns) // Invalid values may be set by Qt Designer.
| 0 | ||||||||||||||||||||||||||||||||||||
| 213 | return poly; never executed: return poly; | 0 | ||||||||||||||||||||||||||||||||||||
| 214 | int notches = (dial->maximum + ns - 1 - dial->minimum) / ns; | - | ||||||||||||||||||||||||||||||||||||
| 215 | if (notches <= 0)
| 0 | ||||||||||||||||||||||||||||||||||||
| 216 | return poly; never executed: return poly; | 0 | ||||||||||||||||||||||||||||||||||||
| 217 | if (dial->maximum < dial->minimum || dial->maximum - dial->minimum > 1000) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 218 | int maximum = dial->minimum + 1000; | - | ||||||||||||||||||||||||||||||||||||
| 219 | notches = (maximum + ns - 1 - dial->minimum) / ns; | - | ||||||||||||||||||||||||||||||||||||
| 220 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 221 | - | |||||||||||||||||||||||||||||||||||||
| 222 | poly.resize(2 + 2 * notches); | - | ||||||||||||||||||||||||||||||||||||
| 223 | int smallLineSize = bigLineSize / 2; | - | ||||||||||||||||||||||||||||||||||||
| 224 | for (int i = 0; i <= notches; ++i) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 225 | qreal angle = dial->dialWrapping ? Q_PI * 3 / 2 - i * 2 * Q_PI / notches
| 0 | ||||||||||||||||||||||||||||||||||||
| 226 | : (Q_PI * 8 - i * 10 * Q_PI / notches) / 6; | - | ||||||||||||||||||||||||||||||||||||
| 227 | qreal s = qSin(angle); | - | ||||||||||||||||||||||||||||||||||||
| 228 | qreal c = qCos(angle); | - | ||||||||||||||||||||||||||||||||||||
| 229 | if (i == 0 || (((ns * i) % (dial->pageStep ? dial->pageStep : 1)) == 0)) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 230 | poly[2 * i] = QPointF(xc + (r - bigLineSize) * c, | - | ||||||||||||||||||||||||||||||||||||
| 231 | yc - (r - bigLineSize) * s); | - | ||||||||||||||||||||||||||||||||||||
| 232 | poly[2 * i + 1] = QPointF(xc + r * c, yc - r * s); | - | ||||||||||||||||||||||||||||||||||||
| 233 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 234 | poly[2 * i] = QPointF(xc + (r - 1 - smallLineSize) * c, | - | ||||||||||||||||||||||||||||||||||||
| 235 | yc - (r - 1 - smallLineSize) * s); | - | ||||||||||||||||||||||||||||||||||||
| 236 | poly[2 * i + 1] = QPointF(xc + (r - 1) * c, yc -(r - 1) * s); | - | ||||||||||||||||||||||||||||||||||||
| 237 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 238 | } | - | ||||||||||||||||||||||||||||||||||||
| 239 | return poly; never executed: return poly; | 0 | ||||||||||||||||||||||||||||||||||||
| 240 | } | - | ||||||||||||||||||||||||||||||||||||
| 241 | - | |||||||||||||||||||||||||||||||||||||
| 242 | // This will draw a nice and shiny QDial for us. We don't want | - | ||||||||||||||||||||||||||||||||||||
| 243 | // all the shinyness in QWindowsStyle, hence we place it here | - | ||||||||||||||||||||||||||||||||||||
| 244 | - | |||||||||||||||||||||||||||||||||||||
| 245 | void drawDial(const QStyleOptionSlider *option, QPainter *painter) | - | ||||||||||||||||||||||||||||||||||||
| 246 | { | - | ||||||||||||||||||||||||||||||||||||
| 247 | QPalette pal = option->palette; | - | ||||||||||||||||||||||||||||||||||||
| 248 | QColor buttonColor = pal.button().color(); | - | ||||||||||||||||||||||||||||||||||||
| 249 | const int width = option->rect.width(); | - | ||||||||||||||||||||||||||||||||||||
| 250 | const int height = option->rect.height(); | - | ||||||||||||||||||||||||||||||||||||
| 251 | const bool enabled = option->state & QStyle::State_Enabled; | - | ||||||||||||||||||||||||||||||||||||
| 252 | qreal r = qMin(width, height) / 2; | - | ||||||||||||||||||||||||||||||||||||
| 253 | r -= r/50; | - | ||||||||||||||||||||||||||||||||||||
| 254 | const qreal penSize = r/20.0; | - | ||||||||||||||||||||||||||||||||||||
| 255 | - | |||||||||||||||||||||||||||||||||||||
| 256 | painter->save(); | - | ||||||||||||||||||||||||||||||||||||
| 257 | painter->setRenderHint(QPainter::Antialiasing); | - | ||||||||||||||||||||||||||||||||||||
| 258 | - | |||||||||||||||||||||||||||||||||||||
| 259 | // Draw notches | - | ||||||||||||||||||||||||||||||||||||
| 260 | if (option->subControls & QStyle::SC_DialTickmarks) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 261 | painter->setPen(option->palette.dark().color().darker(120)); | - | ||||||||||||||||||||||||||||||||||||
| 262 | painter->drawLines(QStyleHelper::calcLines(option)); | - | ||||||||||||||||||||||||||||||||||||
| 263 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 264 | - | |||||||||||||||||||||||||||||||||||||
| 265 | // Cache dial background | - | ||||||||||||||||||||||||||||||||||||
| 266 | BEGIN_STYLE_PIXMAPCACHE(QString::fromLatin1("qdial")); never executed: end of blocknever executed: end of block
| 0 | ||||||||||||||||||||||||||||||||||||
| 267 | p->setRenderHint(QPainter::Antialiasing); | - | ||||||||||||||||||||||||||||||||||||
| 268 | - | |||||||||||||||||||||||||||||||||||||
| 269 | const qreal d_ = r / 6; | - | ||||||||||||||||||||||||||||||||||||
| 270 | const qreal dx = option->rect.x() + d_ + (width - 2 * r) / 2 + 1; | - | ||||||||||||||||||||||||||||||||||||
| 271 | const qreal dy = option->rect.y() + d_ + (height - 2 * r) / 2 + 1; | - | ||||||||||||||||||||||||||||||||||||
| 272 | - | |||||||||||||||||||||||||||||||||||||
| 273 | QRectF br = QRectF(dx + 0.5, dy + 0.5, | - | ||||||||||||||||||||||||||||||||||||
| 274 | int(r * 2 - 2 * d_ - 2), | - | ||||||||||||||||||||||||||||||||||||
| 275 | int(r * 2 - 2 * d_ - 2)); | - | ||||||||||||||||||||||||||||||||||||
| 276 | buttonColor.setHsv(buttonColor .hue(), | - | ||||||||||||||||||||||||||||||||||||
| 277 | qMin(140, buttonColor .saturation()), | - | ||||||||||||||||||||||||||||||||||||
| 278 | qMax(180, buttonColor.value())); | - | ||||||||||||||||||||||||||||||||||||
| 279 | QColor shadowColor(0, 0, 0, 20); | - | ||||||||||||||||||||||||||||||||||||
| 280 | - | |||||||||||||||||||||||||||||||||||||
| 281 | if (enabled) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 282 | // Drop shadow | - | ||||||||||||||||||||||||||||||||||||
| 283 | qreal shadowSize = qMax(1.0, penSize/2.0); | - | ||||||||||||||||||||||||||||||||||||
| 284 | QRectF shadowRect= br.adjusted(-2*shadowSize, -2*shadowSize, | - | ||||||||||||||||||||||||||||||||||||
| 285 | 2*shadowSize, 2*shadowSize); | - | ||||||||||||||||||||||||||||||||||||
| 286 | QRadialGradient shadowGradient(shadowRect.center().x(), | - | ||||||||||||||||||||||||||||||||||||
| 287 | shadowRect.center().y(), shadowRect.width()/2.0, | - | ||||||||||||||||||||||||||||||||||||
| 288 | shadowRect.center().x(), shadowRect.center().y()); | - | ||||||||||||||||||||||||||||||||||||
| 289 | shadowGradient.setColorAt(qreal(0.91), QColor(0, 0, 0, 40)); | - | ||||||||||||||||||||||||||||||||||||
| 290 | shadowGradient.setColorAt(qreal(1.0), Qt::transparent); | - | ||||||||||||||||||||||||||||||||||||
| 291 | p->setBrush(shadowGradient); | - | ||||||||||||||||||||||||||||||||||||
| 292 | p->setPen(Qt::NoPen); | - | ||||||||||||||||||||||||||||||||||||
| 293 | p->translate(shadowSize, shadowSize); | - | ||||||||||||||||||||||||||||||||||||
| 294 | p->drawEllipse(shadowRect); | - | ||||||||||||||||||||||||||||||||||||
| 295 | p->translate(-shadowSize, -shadowSize); | - | ||||||||||||||||||||||||||||||||||||
| 296 | - | |||||||||||||||||||||||||||||||||||||
| 297 | // Main gradient | - | ||||||||||||||||||||||||||||||||||||
| 298 | QRadialGradient gradient(br.center().x() - br.width()/3, dy, | - | ||||||||||||||||||||||||||||||||||||
| 299 | br.width()*1.3, br.center().x(), | - | ||||||||||||||||||||||||||||||||||||
| 300 | br.center().y() - br.height()/2); | - | ||||||||||||||||||||||||||||||||||||
| 301 | gradient.setColorAt(0, buttonColor.lighter(110)); | - | ||||||||||||||||||||||||||||||||||||
| 302 | gradient.setColorAt(qreal(0.5), buttonColor); | - | ||||||||||||||||||||||||||||||||||||
| 303 | gradient.setColorAt(qreal(0.501), buttonColor.darker(102)); | - | ||||||||||||||||||||||||||||||||||||
| 304 | gradient.setColorAt(1, buttonColor.darker(115)); | - | ||||||||||||||||||||||||||||||||||||
| 305 | p->setBrush(gradient); | - | ||||||||||||||||||||||||||||||||||||
| 306 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 307 | p->setBrush(Qt::NoBrush); | - | ||||||||||||||||||||||||||||||||||||
| 308 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 309 | - | |||||||||||||||||||||||||||||||||||||
| 310 | p->setPen(QPen(buttonColor.darker(280))); | - | ||||||||||||||||||||||||||||||||||||
| 311 | p->drawEllipse(br); | - | ||||||||||||||||||||||||||||||||||||
| 312 | p->setBrush(Qt::NoBrush); | - | ||||||||||||||||||||||||||||||||||||
| 313 | p->setPen(buttonColor.lighter(110)); | - | ||||||||||||||||||||||||||||||||||||
| 314 | p->drawEllipse(br.adjusted(1, 1, -1, -1)); | - | ||||||||||||||||||||||||||||||||||||
| 315 | - | |||||||||||||||||||||||||||||||||||||
| 316 | if (option->state & QStyle::State_HasFocus) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 317 | QColor highlight = pal.highlight().color(); | - | ||||||||||||||||||||||||||||||||||||
| 318 | highlight.setHsv(highlight.hue(), | - | ||||||||||||||||||||||||||||||||||||
| 319 | qMin(160, highlight.saturation()), | - | ||||||||||||||||||||||||||||||||||||
| 320 | qMax(230, highlight.value())); | - | ||||||||||||||||||||||||||||||||||||
| 321 | highlight.setAlpha(127); | - | ||||||||||||||||||||||||||||||||||||
| 322 | p->setPen(QPen(highlight, 2.0)); | - | ||||||||||||||||||||||||||||||||||||
| 323 | p->setBrush(Qt::NoBrush); | - | ||||||||||||||||||||||||||||||||||||
| 324 | p->drawEllipse(br.adjusted(-1, -1, 1, 1)); | - | ||||||||||||||||||||||||||||||||||||
| 325 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 326 | - | |||||||||||||||||||||||||||||||||||||
| 327 | END_STYLE_PIXMAPCACHE never executed: end of blocknever executed: end of block
| 0 | ||||||||||||||||||||||||||||||||||||
| 328 | - | |||||||||||||||||||||||||||||||||||||
| 329 | QPointF dp = calcRadialPos(option, qreal(0.70)); | - | ||||||||||||||||||||||||||||||||||||
| 330 | buttonColor = buttonColor.lighter(104); | - | ||||||||||||||||||||||||||||||||||||
| 331 | buttonColor.setAlphaF(qreal(0.8)); | - | ||||||||||||||||||||||||||||||||||||
| 332 | const qreal ds = r/qreal(7.0); | - | ||||||||||||||||||||||||||||||||||||
| 333 | QRectF dialRect(dp.x() - ds, dp.y() - ds, 2*ds, 2*ds); | - | ||||||||||||||||||||||||||||||||||||
| 334 | QRadialGradient dialGradient(dialRect.center().x() + dialRect.width()/2, | - | ||||||||||||||||||||||||||||||||||||
| 335 | dialRect.center().y() + dialRect.width(), | - | ||||||||||||||||||||||||||||||||||||
| 336 | dialRect.width()*2, | - | ||||||||||||||||||||||||||||||||||||
| 337 | dialRect.center().x(), dialRect.center().y()); | - | ||||||||||||||||||||||||||||||||||||
| 338 | dialGradient.setColorAt(1, buttonColor.darker(140)); | - | ||||||||||||||||||||||||||||||||||||
| 339 | dialGradient.setColorAt(qreal(0.4), buttonColor.darker(120)); | - | ||||||||||||||||||||||||||||||||||||
| 340 | dialGradient.setColorAt(0, buttonColor.darker(110)); | - | ||||||||||||||||||||||||||||||||||||
| 341 | if (penSize > 3.0) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 342 | painter->setPen(QPen(QColor(0, 0, 0, 25), penSize)); | - | ||||||||||||||||||||||||||||||||||||
| 343 | painter->drawLine(calcRadialPos(option, qreal(0.90)), calcRadialPos(option, qreal(0.96))); | - | ||||||||||||||||||||||||||||||||||||
| 344 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 345 | - | |||||||||||||||||||||||||||||||||||||
| 346 | painter->setBrush(dialGradient); | - | ||||||||||||||||||||||||||||||||||||
| 347 | painter->setPen(QColor(255, 255, 255, 150)); | - | ||||||||||||||||||||||||||||||||||||
| 348 | painter->drawEllipse(dialRect.adjusted(-1, -1, 1, 1)); | - | ||||||||||||||||||||||||||||||||||||
| 349 | painter->setPen(QColor(0, 0, 0, 80)); | - | ||||||||||||||||||||||||||||||||||||
| 350 | painter->drawEllipse(dialRect); | - | ||||||||||||||||||||||||||||||||||||
| 351 | painter->restore(); | - | ||||||||||||||||||||||||||||||||||||
| 352 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 353 | #endif //QT_NO_DIAL | - | ||||||||||||||||||||||||||||||||||||
| 354 | - | |||||||||||||||||||||||||||||||||||||
| 355 | void drawBorderPixmap(const QPixmap &pixmap, QPainter *painter, const QRect &rect, | - | ||||||||||||||||||||||||||||||||||||
| 356 | int left, int top, int right, | - | ||||||||||||||||||||||||||||||||||||
| 357 | int bottom) | - | ||||||||||||||||||||||||||||||||||||
| 358 | { | - | ||||||||||||||||||||||||||||||||||||
| 359 | QSize size = pixmap.size(); | - | ||||||||||||||||||||||||||||||||||||
| 360 | //painter->setRenderHint(QPainter::SmoothPixmapTransform); | - | ||||||||||||||||||||||||||||||||||||
| 361 | - | |||||||||||||||||||||||||||||||||||||
| 362 | //top | - | ||||||||||||||||||||||||||||||||||||
| 363 | if (top > 0) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 364 | painter->drawPixmap(QRect(rect.left() + left, rect.top(), rect.width() -right - left, top), pixmap, | - | ||||||||||||||||||||||||||||||||||||
| 365 | QRect(left, 0, size.width() -right - left, top)); | - | ||||||||||||||||||||||||||||||||||||
| 366 | - | |||||||||||||||||||||||||||||||||||||
| 367 | //top-left | - | ||||||||||||||||||||||||||||||||||||
| 368 | if(left > 0)
| 0 | ||||||||||||||||||||||||||||||||||||
| 369 | painter->drawPixmap(QRect(rect.left(), rect.top(), left, top), pixmap, never executed: painter->drawPixmap(QRect(rect.left(), rect.top(), left, top), pixmap, QRect(0, 0, left, top)); | 0 | ||||||||||||||||||||||||||||||||||||
| 370 | QRect(0, 0, left, top)); never executed: painter->drawPixmap(QRect(rect.left(), rect.top(), left, top), pixmap, QRect(0, 0, left, top)); | 0 | ||||||||||||||||||||||||||||||||||||
| 371 | - | |||||||||||||||||||||||||||||||||||||
| 372 | //top-right | - | ||||||||||||||||||||||||||||||||||||
| 373 | if (right > 0)
| 0 | ||||||||||||||||||||||||||||||||||||
| 374 | painter->drawPixmap(QRect(rect.left() + rect.width() - right, rect.top(), right, top), pixmap, never executed: painter->drawPixmap(QRect(rect.left() + rect.width() - right, rect.top(), right, top), pixmap, QRect(size.width() - right, 0, right, top)); | 0 | ||||||||||||||||||||||||||||||||||||
| 375 | QRect(size.width() - right, 0, right, top)); never executed: painter->drawPixmap(QRect(rect.left() + rect.width() - right, rect.top(), right, top), pixmap, QRect(size.width() - right, 0, right, top)); | 0 | ||||||||||||||||||||||||||||||||||||
| 376 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 377 | - | |||||||||||||||||||||||||||||||||||||
| 378 | //left | - | ||||||||||||||||||||||||||||||||||||
| 379 | if (left > 0)
| 0 | ||||||||||||||||||||||||||||||||||||
| 380 | painter->drawPixmap(QRect(rect.left(), rect.top()+top, left, rect.height() - top - bottom), pixmap, never executed: painter->drawPixmap(QRect(rect.left(), rect.top()+top, left, rect.height() - top - bottom), pixmap, QRect(0, top, left, size.height() - bottom - top)); | 0 | ||||||||||||||||||||||||||||||||||||
| 381 | QRect(0, top, left, size.height() - bottom - top)); never executed: painter->drawPixmap(QRect(rect.left(), rect.top()+top, left, rect.height() - top - bottom), pixmap, QRect(0, top, left, size.height() - bottom - top)); | 0 | ||||||||||||||||||||||||||||||||||||
| 382 | - | |||||||||||||||||||||||||||||||||||||
| 383 | //center | - | ||||||||||||||||||||||||||||||||||||
| 384 | painter->drawPixmap(QRect(rect.left() + left, rect.top()+top, rect.width() -right - left, | - | ||||||||||||||||||||||||||||||||||||
| 385 | rect.height() - bottom - top), pixmap, | - | ||||||||||||||||||||||||||||||||||||
| 386 | QRect(left, top, size.width() -right -left, | - | ||||||||||||||||||||||||||||||||||||
| 387 | size.height() - bottom - top)); | - | ||||||||||||||||||||||||||||||||||||
| 388 | //right | - | ||||||||||||||||||||||||||||||||||||
| 389 | if (right > 0)
| 0 | ||||||||||||||||||||||||||||||||||||
| 390 | painter->drawPixmap(QRect(rect.left() +rect.width() - right, rect.top()+top, right, rect.height() - top - bottom), pixmap, never executed: painter->drawPixmap(QRect(rect.left() +rect.width() - right, rect.top()+top, right, rect.height() - top - bottom), pixmap, QRect(size.width() - right, top, right, size.height() - bottom - top)); | 0 | ||||||||||||||||||||||||||||||||||||
| 391 | QRect(size.width() - right, top, right, size.height() - bottom - top)); never executed: painter->drawPixmap(QRect(rect.left() +rect.width() - right, rect.top()+top, right, rect.height() - top - bottom), pixmap, QRect(size.width() - right, top, right, size.height() - bottom - top)); | 0 | ||||||||||||||||||||||||||||||||||||
| 392 | - | |||||||||||||||||||||||||||||||||||||
| 393 | //bottom | - | ||||||||||||||||||||||||||||||||||||
| 394 | if (bottom > 0) {
| 0 | ||||||||||||||||||||||||||||||||||||
| 395 | painter->drawPixmap(QRect(rect.left() +left, rect.top() + rect.height() - bottom, | - | ||||||||||||||||||||||||||||||||||||
| 396 | rect.width() - right - left, bottom), pixmap, | - | ||||||||||||||||||||||||||||||||||||
| 397 | QRect(left, size.height() - bottom, | - | ||||||||||||||||||||||||||||||||||||
| 398 | size.width() - right - left, bottom)); | - | ||||||||||||||||||||||||||||||||||||
| 399 | //bottom-left | - | ||||||||||||||||||||||||||||||||||||
| 400 | if (left > 0)
| 0 | ||||||||||||||||||||||||||||||||||||
| 401 | painter->drawPixmap(QRect(rect.left(), rect.top() + rect.height() - bottom, left, bottom), pixmap, never executed: painter->drawPixmap(QRect(rect.left(), rect.top() + rect.height() - bottom, left, bottom), pixmap, QRect(0, size.height() - bottom, left, bottom)); | 0 | ||||||||||||||||||||||||||||||||||||
| 402 | QRect(0, size.height() - bottom, left, bottom)); never executed: painter->drawPixmap(QRect(rect.left(), rect.top() + rect.height() - bottom, left, bottom), pixmap, QRect(0, size.height() - bottom, left, bottom)); | 0 | ||||||||||||||||||||||||||||||||||||
| 403 | - | |||||||||||||||||||||||||||||||||||||
| 404 | //bottom-right | - | ||||||||||||||||||||||||||||||||||||
| 405 | if (right > 0)
| 0 | ||||||||||||||||||||||||||||||||||||
| 406 | painter->drawPixmap(QRect(rect.left() + rect.width() - right, rect.top() + rect.height() - bottom, right, bottom), pixmap, never executed: painter->drawPixmap(QRect(rect.left() + rect.width() - right, rect.top() + rect.height() - bottom, right, bottom), pixmap, QRect(size.width() - right, size.height() - bottom, right, bottom)); | 0 | ||||||||||||||||||||||||||||||||||||
| 407 | QRect(size.width() - right, size.height() - bottom, right, bottom)); never executed: painter->drawPixmap(QRect(rect.left() + rect.width() - right, rect.top() + rect.height() - bottom, right, bottom), pixmap, QRect(size.width() - right, size.height() - bottom, right, bottom)); | 0 | ||||||||||||||||||||||||||||||||||||
| 408 | - | |||||||||||||||||||||||||||||||||||||
| 409 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 410 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 411 | - | |||||||||||||||||||||||||||||||||||||
| 412 | QColor backgroundColor(const QPalette &pal, const QWidget* widget) | - | ||||||||||||||||||||||||||||||||||||
| 413 | { | - | ||||||||||||||||||||||||||||||||||||
| 414 | if (qobject_cast<const QScrollBar *>(widget) && widget->parent() &&
| 0 | ||||||||||||||||||||||||||||||||||||
| 415 | qobject_cast<const QAbstractScrollArea *>(widget->parent()->parent()))
| 0 | ||||||||||||||||||||||||||||||||||||
| 416 | return widget->parentWidget()->parentWidget()->palette().color(QPalette::Base); never executed: return widget->parentWidget()->parentWidget()->palette().color(QPalette::Base); | 0 | ||||||||||||||||||||||||||||||||||||
| 417 | return pal.color(QPalette::Base); never executed: return pal.color(QPalette::Base); | 0 | ||||||||||||||||||||||||||||||||||||
| 418 | } | - | ||||||||||||||||||||||||||||||||||||
| 419 | - | |||||||||||||||||||||||||||||||||||||
| 420 | QWindow *styleObjectWindow(QObject *so) | - | ||||||||||||||||||||||||||||||||||||
| 421 | { | - | ||||||||||||||||||||||||||||||||||||
| 422 | if (so)
| 0 | ||||||||||||||||||||||||||||||||||||
| 423 | return so->property("_q_styleObjectWindow").value<QWindow *>(); never executed: return so->property("_q_styleObjectWindow").value<QWindow *>(); | 0 | ||||||||||||||||||||||||||||||||||||
| 424 | - | |||||||||||||||||||||||||||||||||||||
| 425 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||
| 426 | } | - | ||||||||||||||||||||||||||||||||||||
| 427 | - | |||||||||||||||||||||||||||||||||||||
| 428 | } | - | ||||||||||||||||||||||||||||||||||||
| 429 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |