Fix crash with clap plugins without MIDI input
[carla.git] / source / theme / CarlaStyle.cpp
blob3f6a937605e8ef401f1a26b2da6aef320c98ea66
1 /*
2 * Carla Style, based on Qt5 fusion style
3 * Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies)
4 * Copyright (C) 2013-2019 Filipe Coelho <falktx@falktx.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
15 * For a full copy of the license see the doc/LGPL.txt file
18 #include "CarlaStylePrivate.hpp"
20 #include <QtCore/qmath.h>
21 #include <QtCore/QStringBuilder>
23 #if defined(__GNUC__) && __GNUC__ >= 8
24 # pragma GCC diagnostic ignored "-Wdeprecated-copy"
25 #endif
27 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
28 # include <QtGui/QPainter>
29 # include <QtGui/QPainterPath>
30 # include <QtGui/QPixmapCache>
31 # include <QtWidgets/qdrawutil.h>
32 # include <QtWidgets/QApplication>
33 # include <QtWidgets/QComboBox>
34 # include <QtWidgets/QGroupBox>
35 # include <QtWidgets/QMainWindow>
36 # include <QtWidgets/QProgressBar>
37 # include <QtWidgets/QPushButton>
38 # include <QtWidgets/QScrollBar>
39 # include <QtWidgets/QSlider>
40 # include <QtWidgets/QSpinBox>
41 # include <QtWidgets/QSplitter>
42 # include <QtWidgets/QWizard>
43 # define QStyleOptionFrameV3 QStyleOptionFrame
44 # define QStyleOptionProgressBarV2 QStyleOptionProgressBar
45 #else
46 # ifdef __clang__
47 # pragma clang diagnostic push
48 # pragma clang diagnostic ignored "-Wdeprecated-register"
49 # endif
50 # include <QtGui/QPainter>
51 # include <QtGui/QPainterPath>
52 # include <QtGui/QPixmapCache>
53 # include <QtGui/QApplication>
54 # include <QtGui/QComboBox>
55 # include <QtGui/QGroupBox>
56 # include <QtGui/QMainWindow>
57 # include <QtGui/QProgressBar>
58 # include <QtGui/QPushButton>
59 # include <QtGui/QScrollBar>
60 # include <QtGui/QSlider>
61 # include <QtGui/QSpinBox>
62 # include <QtGui/QSplitter>
63 # include <QtGui/QWizard>
64 # ifdef __clang__
65 # pragma clang diagnostic pop
66 # endif
67 #endif
69 #if defined(__GNUC__) && __GNUC__ >= 8
70 # pragma GCC diagnostic pop
71 #endif
73 #include <cstdio>
75 #if (QT_VERSION >= QT_VERSION_CHECK(5, 13, 0))
76 #define PIXMAPCACHE_VAR_PREFIX &
77 #else
78 #define PIXMAPCACHE_VAR_PREFIX
79 #endif
81 #define BEGIN_STYLE_PIXMAPCACHE(a) \
82 QRect rect = option->rect; \
83 QPixmap internalPixmapCache; \
84 QImage imageCache; \
85 QPainter *p = painter; \
86 QString unique = uniqueName((a), option, option->rect.size()); \
87 int txType = painter->deviceTransform().type() | painter->worldTransform().type(); \
88 bool doPixmapCache = txType <= QTransform::TxTranslate; \
89 if (doPixmapCache && QPixmapCache::find(unique, PIXMAPCACHE_VAR_PREFIX internalPixmapCache)) { \
90 painter->drawPixmap(option->rect.topLeft(), internalPixmapCache); \
91 } else { \
92 if (doPixmapCache) { \
93 rect.setRect(0, 0, option->rect.width(), option->rect.height()); \
94 imageCache = QImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied); \
95 imageCache.fill(0); \
96 p = new QPainter(&imageCache); \
99 #define END_STYLE_PIXMAPCACHE \
100 if (doPixmapCache) { \
101 p->end(); \
102 delete p; \
103 internalPixmapCache = QPixmap::fromImage(imageCache); \
104 painter->drawPixmap(option->rect.topLeft(), internalPixmapCache); \
105 QPixmapCache::insert(unique, internalPixmapCache); \
109 enum Direction {
110 TopDown,
111 FromLeft,
112 BottomUp,
113 FromRight
116 // from windows style
117 static const int windowsItemFrame = 2; // menu item frame width
118 static const int windowsItemHMargin = 3; // menu item hor text margin
119 static const int windowsItemVMargin = 8; // menu item ver text margin
120 static const int windowsRightBorder = 15; // right border on windows
122 static const int groupBoxBottomMargin = 0; // space below the groupbox
123 static const int groupBoxTopMargin = 3;
125 /* XPM */
126 static const char * const qt_titlebar_context_help[] = {
127 "10 10 3 1",
128 " c None",
129 "# c #000000",
130 "+ c #444444",
131 " +####+ ",
132 " ### ### ",
133 " ## ## ",
134 " +##+ ",
135 " +## ",
136 " ## ",
137 " ## ",
138 " ",
139 " ## ",
140 " ## "};
142 static const qreal Q_PI = qreal(3.14159265358979323846);
144 // internal helper. Converts an integer value to an unique string token
145 template <typename T>
146 struct HexString
148 HexString(const T t)
149 : val(t) {}
151 void write(QChar* &dest) const
153 const ushort hexChars[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
154 const char* c = reinterpret_cast<const char*>(&val);
156 for (uint i = 0; i < sizeof(T); ++i)
158 *dest++ = hexChars[*c & 0xf];
159 *dest++ = hexChars[(*c & 0xf0) >> 4];
160 ++c;
164 const T val;
167 // specialization to enable fast concatenating of our string tokens to a string
168 template <typename T>
169 struct QConcatenable<HexString<T> >
171 typedef HexString<T> type;
172 enum { ExactSize = true };
173 static int size(const HexString<T> &) { return sizeof(T) * 2; }
174 static inline void appendTo(const HexString<T> &str, QChar *&out) { str.write(out); }
175 typedef QString ConvertTo;
178 inline int qt_div_255(int x)
180 return (x + (x>>8) + 0x80) >> 8;
183 inline QPixmap styleCachePixmap(const QSize &size)
185 return QPixmap(size);
188 inline int fontMetricsHorizontalAdvance(const QFontMetrics& fm, const QString& s)
190 #if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
191 return fm.horizontalAdvance(s);
192 #else
193 return fm.width(s);
194 #endif
197 int calcBigLineSize(int radius)
199 int bigLineSize = radius / 6;
200 if (bigLineSize < 4)
201 bigLineSize = 4;
202 if (bigLineSize > radius / 2)
203 bigLineSize = radius / 2;
204 return bigLineSize;
207 static QPolygonF calcLines(const QStyleOptionSlider* dial)
209 QPolygonF poly;
210 int width = dial->rect.width();
211 int height = dial->rect.height();
212 qreal r = qMin(width, height) / 2;
213 int bigLineSize = calcBigLineSize(int(r));
215 qreal xc = width / 2 + 0.5;
216 qreal yc = height / 2 + 0.5;
217 const int ns = dial->tickInterval;
218 if (!ns) // Invalid values may be set by Qt Designer.
219 return poly;
220 int notches = (dial->maximum + ns - 1 - dial->minimum) / ns;
221 if (notches <= 0)
222 return poly;
223 if (dial->maximum < dial->minimum || dial->maximum - dial->minimum > 1000) {
224 int maximum = dial->minimum + 1000;
225 notches = (maximum + ns - 1 - dial->minimum) / ns;
228 poly.resize(2 + 2 * notches);
229 int smallLineSize = bigLineSize / 2;
230 for (int i = 0; i <= notches; ++i) {
231 qreal angle = dial->dialWrapping ? Q_PI * 3 / 2 - i * 2 * Q_PI / notches
232 : (Q_PI * 8 - i * 10 * Q_PI / notches) / 6;
233 qreal s = qSin(angle);
234 qreal c = qCos(angle);
235 if (i == 0 || (((ns * i) % (dial->pageStep ? dial->pageStep : 1)) == 0)) {
236 poly[2 * i] = QPointF(xc + (r - bigLineSize) * c,
237 yc - (r - bigLineSize) * s);
238 poly[2 * i + 1] = QPointF(xc + r * c, yc - r * s);
239 } else {
240 poly[2 * i] = QPointF(xc + (r - 1 - smallLineSize) * c,
241 yc - (r - 1 - smallLineSize) * s);
242 poly[2 * i + 1] = QPointF(xc + (r - 1) * c, yc -(r - 1) * s);
245 return poly;
248 static QPointF calcRadialPos(const QStyleOptionSlider *dial, qreal offset)
250 const int width = dial->rect.width();
251 const int height = dial->rect.height();
252 const int r = qMin(width, height) / 2;
253 const int currentSliderPosition = dial->upsideDown ? dial->sliderPosition : (dial->maximum - dial->sliderPosition);
254 qreal a = 0;
255 if (dial->maximum == dial->minimum)
256 a = Q_PI / 2;
257 else if (dial->dialWrapping)
258 a = Q_PI * 3 / 2 - (currentSliderPosition - dial->minimum) * 2 * Q_PI
259 / (dial->maximum - dial->minimum);
260 else
261 a = (Q_PI * 8 - (currentSliderPosition - dial->minimum) * 10 * Q_PI
262 / (dial->maximum - dial->minimum)) / 6;
263 qreal xc = width / 2.0;
264 qreal yc = height / 2.0;
265 qreal len = r - calcBigLineSize(r) - 3;
266 qreal back = offset * len;
267 QPointF pos(QPointF(xc + back * qCos(a), yc - back * qSin(a)));
268 return pos;
271 static QString uniqueName(const QString &key, const QStyleOption *option, const QSize &size)
273 const QStyleOptionComplex* complexOption = qstyleoption_cast<const QStyleOptionComplex *>(option);
274 QString tmp = key % HexString<uint>(option->state)
275 % HexString<uint>(option->direction)
276 % HexString<uint>(complexOption ? uint(complexOption->activeSubControls) : 0u)
277 % HexString<quint64>(option->palette.cacheKey())
278 % HexString<uint>(size.width())
279 % HexString<uint>(size.height());
281 #ifndef QT_NO_SPINBOX
282 if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
283 tmp = tmp % HexString<uint>(spinBox->buttonSymbols)
284 % HexString<uint>(spinBox->stepEnabled)
285 % QLatin1Char(spinBox->frame ? '1' : '0'); ;
287 #endif // QT_NO_SPINBOX
288 return tmp;
291 // This will draw a nice and shiny QDial for us. We don't want
292 // all the shinyness in QWindowsStyle, hence we place it here
294 static void drawDial(const QStyleOptionSlider* option, QPainter* painter)
296 QPalette pal = option->palette;
297 QColor buttonColor = pal.button().color();
298 const int width = option->rect.width();
299 const int height = option->rect.height();
300 const bool enabled = option->state & QStyle::State_Enabled;
301 qreal r = qMin(width, height) / 2;
302 r -= r/50;
303 const qreal penSize = r/20.0;
305 painter->save();
306 painter->setRenderHint(QPainter::Antialiasing);
308 // Draw notches
309 if (option->subControls & QStyle::SC_DialTickmarks) {
310 painter->setPen(option->palette.dark().color().darker(120));
311 painter->drawLines(calcLines(option));
314 // Cache dial background
315 BEGIN_STYLE_PIXMAPCACHE(QString::fromLatin1("qdial"));
316 p->setRenderHint(QPainter::Antialiasing);
318 const qreal d_ = r / 6;
319 const qreal dx = option->rect.x() + d_ + (width - 2 * r) / 2 + 1;
320 const qreal dy = option->rect.y() + d_ + (height - 2 * r) / 2 + 1;
322 QRectF br = QRectF(dx + 0.5, dy + 0.5,
323 int(r * 2 - 2 * d_ - 2),
324 int(r * 2 - 2 * d_ - 2));
325 buttonColor.setHsv(buttonColor .hue(),
326 qMin(140, buttonColor .saturation()),
327 qMax(180, buttonColor.value()));
328 QColor shadowColor(0, 0, 0, 20);
330 if (enabled) {
331 // Drop shadow
332 qreal shadowSize = qMax(1.0, penSize/2.0);
333 QRectF shadowRect= br.adjusted(-2*shadowSize, -2*shadowSize,
334 2*shadowSize, 2*shadowSize);
335 QRadialGradient shadowGradient(shadowRect.center().x(),
336 shadowRect.center().y(), shadowRect.width()/2.0,
337 shadowRect.center().x(), shadowRect.center().y());
338 shadowGradient.setColorAt(qreal(0.91), QColor(0, 0, 0, 40));
339 shadowGradient.setColorAt(qreal(1.0), Qt::transparent);
340 p->setBrush(shadowGradient);
341 p->setPen(Qt::NoPen);
342 p->translate(shadowSize, shadowSize);
343 p->drawEllipse(shadowRect);
344 p->translate(-shadowSize, -shadowSize);
346 // Main gradient
347 QRadialGradient gradient(br.center().x() - br.width()/3, dy,
348 br.width()*1.3, br.center().x(),
349 br.center().y() - br.height()/2);
350 gradient.setColorAt(0, buttonColor.lighter(110));
351 gradient.setColorAt(qreal(0.5), buttonColor);
352 gradient.setColorAt(qreal(0.501), buttonColor.darker(102));
353 gradient.setColorAt(1, buttonColor.darker(115));
354 p->setBrush(gradient);
355 } else {
356 p->setBrush(Qt::NoBrush);
359 p->setPen(QPen(buttonColor.darker(280)));
360 p->drawEllipse(br);
361 p->setBrush(Qt::NoBrush);
362 p->setPen(buttonColor.lighter(110));
363 p->drawEllipse(br.adjusted(1, 1, -1, -1));
365 if (option->state & QStyle::State_HasFocus) {
366 QColor highlight = pal.highlight().color();
367 highlight.setHsv(highlight.hue(),
368 qMin(160, highlight.saturation()),
369 qMax(230, highlight.value()));
370 highlight.setAlpha(127);
371 p->setPen(QPen(highlight, 2.0));
372 p->setBrush(Qt::NoBrush);
373 p->drawEllipse(br.adjusted(-1, -1, 1, 1));
376 END_STYLE_PIXMAPCACHE
378 QPointF dp = calcRadialPos(option, qreal(0.70));
379 buttonColor = buttonColor.lighter(104);
380 buttonColor.setAlphaF(qreal(0.8));
381 const qreal ds = r/qreal(7.0);
382 QRectF dialRect(dp.x() - ds, dp.y() - ds, 2*ds, 2*ds);
383 QRadialGradient dialGradient(dialRect.center().x() + dialRect.width()/2,
384 dialRect.center().y() + dialRect.width(),
385 dialRect.width()*2,
386 dialRect.center().x(), dialRect.center().y());
387 dialGradient.setColorAt(1, buttonColor.darker(140));
388 dialGradient.setColorAt(qreal(0.4), buttonColor.darker(120));
389 dialGradient.setColorAt(0, buttonColor.darker(110));
390 if (penSize > 3.0) {
391 painter->setPen(QPen(QColor(0, 0, 0, 25), penSize));
392 painter->drawLine(calcRadialPos(option, qreal(0.90)), calcRadialPos(option, qreal(0.96)));
395 painter->setBrush(dialGradient);
396 painter->setPen(QColor(255, 255, 255, 150));
397 painter->drawEllipse(dialRect.adjusted(-1, -1, 1, 1));
398 painter->setPen(QColor(0, 0, 0, 80));
399 painter->drawEllipse(dialRect);
400 painter->restore();
403 static QColor mergedColors(const QColor &colorA, const QColor &colorB, int factor = 50)
405 const int maxFactor = 100;
406 QColor tmp = colorA;
407 tmp.setRed((tmp.red() * factor) / maxFactor + (colorB.red() * (maxFactor - factor)) / maxFactor);
408 tmp.setGreen((tmp.green() * factor) / maxFactor + (colorB.green() * (maxFactor - factor)) / maxFactor);
409 tmp.setBlue((tmp.blue() * factor) / maxFactor + (colorB.blue() * (maxFactor - factor)) / maxFactor);
410 return tmp;
413 static QPixmap colorizedImage(const QString &fileName, const QColor &color, int rotation = 0)
415 QString pixmapName = QLatin1String("$qt_ia-") % fileName % HexString<uint>(color.rgba()) % QString::number(rotation);
416 QPixmap pixmap;
417 if (!QPixmapCache::find(pixmapName, PIXMAPCACHE_VAR_PREFIX pixmap)) {
418 QImage image(fileName);
420 if (image.format() != QImage::Format_ARGB32_Premultiplied)
421 image = image.convertToFormat( QImage::Format_ARGB32_Premultiplied);
423 int width = image.width();
424 int height = image.height();
425 int source = color.rgba();
427 unsigned char sourceRed = qRed(source);
428 unsigned char sourceGreen = qGreen(source);
429 unsigned char sourceBlue = qBlue(source);
431 for (int y = 0; y < height; ++y)
433 QRgb *data = (QRgb*) image.scanLine(y);
434 for (int x = 0 ; x < width ; ++x) {
435 QRgb col = data[x];
436 unsigned int colorDiff = (qBlue(col) - qRed(col));
437 unsigned char gray = qGreen(col);
438 unsigned char red = gray + qt_div_255(sourceRed * colorDiff);
439 unsigned char green = gray + qt_div_255(sourceGreen * colorDiff);
440 unsigned char blue = gray + qt_div_255(sourceBlue * colorDiff);
441 unsigned char alpha = qt_div_255(qAlpha(col) * qAlpha(source));
442 data[x] = qRgba(red, green, blue, alpha);
445 if (rotation != 0) {
446 QTransform transform;
447 transform.translate(-image.width()/2, -image.height()/2);
448 transform.rotate(rotation);
449 transform.translate(image.width()/2, image.height()/2);
450 image = image.transformed(transform);
453 pixmap = QPixmap::fromImage(image);
454 QPixmapCache::insert(pixmapName, pixmap);
456 return pixmap;
459 // The default button and handle gradient
460 static QLinearGradient qt_fusion_gradient(const QRect &rect, const QBrush &baseColor, Direction direction = TopDown)
462 int x = rect.center().x();
463 int y = rect.center().y();
464 QLinearGradient gradient;
465 switch (direction) {
466 case FromLeft:
467 gradient = QLinearGradient(rect.left(), y, rect.right(), y);
468 break;
469 case FromRight:
470 gradient = QLinearGradient(rect.right(), y, rect.left(), y);
471 break;
472 case BottomUp:
473 gradient = QLinearGradient(x, rect.bottom(), x, rect.top());
474 break;
475 case TopDown:
476 default:
477 gradient = QLinearGradient(x, rect.top(), x, rect.bottom());
478 break;
480 if (baseColor.gradient())
481 gradient.setStops(baseColor.gradient()->stops());
482 else {
483 QColor gradientStartColor = baseColor.color().lighter(124);
484 QColor gradientStopColor = baseColor.color().lighter(102);
485 gradient.setColorAt(0, gradientStartColor);
486 gradient.setColorAt(1, gradientStopColor);
487 // Uncomment for adding shiny shading
488 // QColor midColor1 = mergedColors(gradientStartColor, gradientStopColor, 55);
489 // QColor midColor2 = mergedColors(gradientStartColor, gradientStopColor, 45);
490 // gradient.setColorAt(0.5, midColor1);
491 // gradient.setColorAt(0.501, midColor2);
493 return gradient;
496 static void qt_fusion_draw_mdibutton(QPainter *painter, const QStyleOptionTitleBar *option, const QRect &tmp, bool hover, bool sunken)
498 QColor dark;
499 dark.setHsv(option->palette.button().color().hue(),
500 qMin(255, (int)(option->palette.button().color().saturation())),
501 qMin(255, (int)(option->palette.button().color().value()*0.7)));
503 QColor highlight = option->palette.highlight().color();
505 bool active = (option->titleBarState & QStyle::State_Active);
506 QColor titleBarHighlight(255, 255, 255, 60);
508 if (sunken)
509 painter->fillRect(tmp.adjusted(1, 1, -1, -1), option->palette.highlight().color().darker(120));
510 else if (hover)
511 painter->fillRect(tmp.adjusted(1, 1, -1, -1), QColor(255, 255, 255, 20));
513 QColor mdiButtonGradientStartColor;
514 QColor mdiButtonGradientStopColor;
516 mdiButtonGradientStartColor = QColor(0, 0, 0, 40);
517 mdiButtonGradientStopColor = QColor(255, 255, 255, 60);
519 if (sunken)
520 titleBarHighlight = highlight.darker(130);
522 QLinearGradient gradient(tmp.center().x(), tmp.top(), tmp.center().x(), tmp.bottom());
523 gradient.setColorAt(0, mdiButtonGradientStartColor);
524 gradient.setColorAt(1, mdiButtonGradientStopColor);
525 QColor mdiButtonBorderColor(active ? option->palette.highlight().color().darker(180): dark.darker(110));
527 painter->setPen(QPen(mdiButtonBorderColor, 1));
528 const QLine lines[4] = {
529 QLine(tmp.left() + 2, tmp.top(), tmp.right() - 2, tmp.top()),
530 QLine(tmp.left() + 2, tmp.bottom(), tmp.right() - 2, tmp.bottom()),
531 QLine(tmp.left(), tmp.top() + 2, tmp.left(), tmp.bottom() - 2),
532 QLine(tmp.right(), tmp.top() + 2, tmp.right(), tmp.bottom() - 2)
534 painter->drawLines(lines, 4);
535 const QPoint points[4] = {
536 QPoint(tmp.left() + 1, tmp.top() + 1),
537 QPoint(tmp.right() - 1, tmp.top() + 1),
538 QPoint(tmp.left() + 1, tmp.bottom() - 1),
539 QPoint(tmp.right() - 1, tmp.bottom() - 1)
541 painter->drawPoints(points, 4);
543 painter->setPen(titleBarHighlight);
544 painter->drawLine(tmp.left() + 2, tmp.top() + 1, tmp.right() - 2, tmp.top() + 1);
545 painter->drawLine(tmp.left() + 1, tmp.top() + 2, tmp.left() + 1, tmp.bottom() - 2);
547 painter->setPen(QPen(gradient, 1));
548 painter->drawLine(tmp.right() + 1, tmp.top() + 2, tmp.right() + 1, tmp.bottom() - 2);
549 painter->drawPoint(tmp.right() , tmp.top() + 1);
551 painter->drawLine(tmp.left() + 2, tmp.bottom() + 1, tmp.right() - 2, tmp.bottom() + 1);
552 painter->drawPoint(tmp.left() + 1, tmp.bottom());
553 painter->drawPoint(tmp.right() - 1, tmp.bottom());
554 painter->drawPoint(tmp.right() , tmp.bottom() - 1);
557 CarlaStyle::CarlaStyle()
558 : QCommonStyle(),
559 d(new CarlaStylePrivate(this))
561 setObjectName(QLatin1String("CarlaStyle"));
563 #if 0
564 fPalSystem = app->palette();
566 fPalBlack.setColor(QPalette::Disabled, QPalette::Window, QColor(14, 14, 14));
567 fPalBlack.setColor(QPalette::Active, QPalette::Window, QColor(17, 17, 17));
568 fPalBlack.setColor(QPalette::Inactive, QPalette::Window, QColor(17, 17, 17));
569 fPalBlack.setColor(QPalette::Disabled, QPalette::WindowText, QColor(83, 83, 83));
570 fPalBlack.setColor(QPalette::Active, QPalette::WindowText, QColor(240, 240, 240));
571 fPalBlack.setColor(QPalette::Inactive, QPalette::WindowText, QColor(240, 240, 240));
572 fPalBlack.setColor(QPalette::Disabled, QPalette::Base, QColor(6, 6, 6));
573 fPalBlack.setColor(QPalette::Active, QPalette::Base, QColor(7, 7, 7));
574 fPalBlack.setColor(QPalette::Inactive, QPalette::Base, QColor(7, 7, 7));
575 fPalBlack.setColor(QPalette::Disabled, QPalette::AlternateBase, QColor(12, 12, 12));
576 fPalBlack.setColor(QPalette::Active, QPalette::AlternateBase, QColor(14, 14, 14));
577 fPalBlack.setColor(QPalette::Inactive, QPalette::AlternateBase, QColor(14, 14, 14));
578 fPalBlack.setColor(QPalette::Disabled, QPalette::ToolTipBase, QColor(4, 4, 4));
579 fPalBlack.setColor(QPalette::Active, QPalette::ToolTipBase, QColor(4, 4, 4));
580 fPalBlack.setColor(QPalette::Inactive, QPalette::ToolTipBase, QColor(4, 4, 4));
581 fPalBlack.setColor(QPalette::Disabled, QPalette::ToolTipText, QColor(230, 230, 230));
582 fPalBlack.setColor(QPalette::Active, QPalette::ToolTipText, QColor(230, 230, 230));
583 fPalBlack.setColor(QPalette::Inactive, QPalette::ToolTipText, QColor(230, 230, 230));
584 fPalBlack.setColor(QPalette::Disabled, QPalette::Text, QColor(74, 74, 74));
585 fPalBlack.setColor(QPalette::Active, QPalette::Text, QColor(230, 230, 230));
586 fPalBlack.setColor(QPalette::Inactive, QPalette::Text, QColor(230, 230, 230));
587 fPalBlack.setColor(QPalette::Disabled, QPalette::Button, QColor(24, 24, 24));
588 fPalBlack.setColor(QPalette::Active, QPalette::Button, QColor(28, 28, 28));
589 fPalBlack.setColor(QPalette::Inactive, QPalette::Button, QColor(28, 28, 28));
590 fPalBlack.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(90, 90, 90));
591 fPalBlack.setColor(QPalette::Active, QPalette::ButtonText, QColor(240, 240, 240));
592 fPalBlack.setColor(QPalette::Inactive, QPalette::ButtonText, QColor(240, 240, 240));
593 fPalBlack.setColor(QPalette::Disabled, QPalette::BrightText, QColor(255, 255, 255));
594 fPalBlack.setColor(QPalette::Active, QPalette::BrightText, QColor(255, 255, 255));
595 fPalBlack.setColor(QPalette::Inactive, QPalette::BrightText, QColor(255, 255, 255));
596 fPalBlack.setColor(QPalette::Disabled, QPalette::Light, QColor(191, 191, 191));
597 fPalBlack.setColor(QPalette::Active, QPalette::Light, QColor(191, 191, 191));
598 fPalBlack.setColor(QPalette::Inactive, QPalette::Light, QColor(191, 191, 191));
599 fPalBlack.setColor(QPalette::Disabled, QPalette::Midlight, QColor(155, 155, 155));
600 fPalBlack.setColor(QPalette::Active, QPalette::Midlight, QColor(155, 155, 155));
601 fPalBlack.setColor(QPalette::Inactive, QPalette::Midlight, QColor(155, 155, 155));
602 fPalBlack.setColor(QPalette::Disabled, QPalette::Dark, QColor(129, 129, 129));
603 fPalBlack.setColor(QPalette::Active, QPalette::Dark, QColor(129, 129, 129));
604 fPalBlack.setColor(QPalette::Inactive, QPalette::Dark, QColor(129, 129, 129));
605 fPalBlack.setColor(QPalette::Disabled, QPalette::Mid, QColor(94, 94, 94));
606 fPalBlack.setColor(QPalette::Active, QPalette::Mid, QColor(94, 94, 94));
607 fPalBlack.setColor(QPalette::Inactive, QPalette::Mid, QColor(94, 94, 94));
608 fPalBlack.setColor(QPalette::Disabled, QPalette::Shadow, QColor(155, 155, 155));
609 fPalBlack.setColor(QPalette::Active, QPalette::Shadow, QColor(155, 155, 155));
610 fPalBlack.setColor(QPalette::Inactive, QPalette::Shadow, QColor(155, 155, 155));
611 fPalBlack.setColor(QPalette::Disabled, QPalette::Highlight, QColor(14, 14, 14));
612 fPalBlack.setColor(QPalette::Active, QPalette::Highlight, QColor(60, 60, 60));
613 fPalBlack.setColor(QPalette::Inactive, QPalette::Highlight, QColor(34, 34, 34));
614 fPalBlack.setColor(QPalette::Disabled, QPalette::HighlightedText, QColor(83, 83, 83));
615 fPalBlack.setColor(QPalette::Active, QPalette::HighlightedText, QColor(255, 255, 255));
616 fPalBlack.setColor(QPalette::Inactive, QPalette::HighlightedText, QColor(240, 240, 240));
617 fPalBlack.setColor(QPalette::Disabled, QPalette::Link, QColor(34, 34, 74));
618 fPalBlack.setColor(QPalette::Active, QPalette::Link, QColor(100, 100, 230));
619 fPalBlack.setColor(QPalette::Inactive, QPalette::Link, QColor(100, 100, 230));
620 fPalBlack.setColor(QPalette::Disabled, QPalette::LinkVisited, QColor(74, 34, 74));
621 fPalBlack.setColor(QPalette::Active, QPalette::LinkVisited, QColor(230, 100, 230));
622 fPalBlack.setColor(QPalette::Inactive, QPalette::LinkVisited, QColor(230, 100, 230));
624 fPalBlue.setColor(QPalette::Disabled, QPalette::Window, QColor(32, 35, 39));
625 fPalBlue.setColor(QPalette::Active, QPalette::Window, QColor(37, 40, 45));
626 fPalBlue.setColor(QPalette::Inactive, QPalette::Window, QColor(37, 40, 45));
627 fPalBlue.setColor(QPalette::Disabled, QPalette::WindowText, QColor(89, 95, 104));
628 fPalBlue.setColor(QPalette::Active, QPalette::WindowText, QColor(223, 237, 255));
629 fPalBlue.setColor(QPalette::Inactive, QPalette::WindowText, QColor(223, 237, 255));
630 fPalBlue.setColor(QPalette::Disabled, QPalette::Base, QColor(48, 53, 60));
631 fPalBlue.setColor(QPalette::Active, QPalette::Base, QColor(55, 61, 69));
632 fPalBlue.setColor(QPalette::Inactive, QPalette::Base, QColor(55, 61, 69));
633 fPalBlue.setColor(QPalette::Disabled, QPalette::AlternateBase, QColor(60, 64, 67));
634 fPalBlue.setColor(QPalette::Active, QPalette::AlternateBase, QColor(69, 73, 77));
635 fPalBlue.setColor(QPalette::Inactive, QPalette::AlternateBase, QColor(69, 73, 77));
636 fPalBlue.setColor(QPalette::Disabled, QPalette::ToolTipBase, QColor(182, 193, 208));
637 fPalBlue.setColor(QPalette::Active, QPalette::ToolTipBase, QColor(182, 193, 208));
638 fPalBlue.setColor(QPalette::Inactive, QPalette::ToolTipBase, QColor(182, 193, 208));
639 fPalBlue.setColor(QPalette::Disabled, QPalette::ToolTipText, QColor(42, 44, 48));
640 fPalBlue.setColor(QPalette::Active, QPalette::ToolTipText, QColor(42, 44, 48));
641 fPalBlue.setColor(QPalette::Inactive, QPalette::ToolTipText, QColor(42, 44, 48));
642 fPalBlue.setColor(QPalette::Disabled, QPalette::Text, QColor(96, 103, 113));
643 fPalBlue.setColor(QPalette::Active, QPalette::Text, QColor(210, 222, 240));
644 fPalBlue.setColor(QPalette::Inactive, QPalette::Text, QColor(210, 222, 240));
645 fPalBlue.setColor(QPalette::Disabled, QPalette::Button, QColor(51, 55, 62));
646 fPalBlue.setColor(QPalette::Active, QPalette::Button, QColor(59, 63, 71));
647 fPalBlue.setColor(QPalette::Inactive, QPalette::Button, QColor(59, 63, 71));
648 fPalBlue.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(98, 104, 114));
649 fPalBlue.setColor(QPalette::Active, QPalette::ButtonText, QColor(210, 222, 240));
650 fPalBlue.setColor(QPalette::Inactive, QPalette::ButtonText, QColor(210, 222, 240));
651 fPalBlue.setColor(QPalette::Disabled, QPalette::BrightText, QColor(255, 255, 255));
652 fPalBlue.setColor(QPalette::Active, QPalette::BrightText, QColor(255, 255, 255));
653 fPalBlue.setColor(QPalette::Inactive, QPalette::BrightText, QColor(255, 255, 255));
654 fPalBlue.setColor(QPalette::Disabled, QPalette::Light, QColor(59, 64, 72));
655 fPalBlue.setColor(QPalette::Active, QPalette::Light, QColor(63, 68, 76));
656 fPalBlue.setColor(QPalette::Inactive, QPalette::Light, QColor(63, 68, 76));
657 fPalBlue.setColor(QPalette::Disabled, QPalette::Midlight, QColor(48, 52, 59));
658 fPalBlue.setColor(QPalette::Active, QPalette::Midlight, QColor(51, 56, 63));
659 fPalBlue.setColor(QPalette::Inactive, QPalette::Midlight, QColor(51, 56, 63));
660 fPalBlue.setColor(QPalette::Disabled, QPalette::Dark, QColor(18, 19, 22));
661 fPalBlue.setColor(QPalette::Active, QPalette::Dark, QColor(20, 22, 25));
662 fPalBlue.setColor(QPalette::Inactive, QPalette::Dark, QColor(20, 22, 25));
663 fPalBlue.setColor(QPalette::Disabled, QPalette::Mid, QColor(28, 30, 34));
664 fPalBlue.setColor(QPalette::Active, QPalette::Mid, QColor(32, 35, 39));
665 fPalBlue.setColor(QPalette::Inactive, QPalette::Mid, QColor(32, 35, 39));
666 fPalBlue.setColor(QPalette::Disabled, QPalette::Shadow, QColor(13, 14, 16));
667 fPalBlue.setColor(QPalette::Active, QPalette::Shadow, QColor(15, 16, 18));
668 fPalBlue.setColor(QPalette::Inactive, QPalette::Shadow, QColor(15, 16, 18));
669 fPalBlue.setColor(QPalette::Disabled, QPalette::Highlight, QColor(32, 35, 39));
670 fPalBlue.setColor(QPalette::Active, QPalette::Highlight, QColor(14, 14, 17));
671 fPalBlue.setColor(QPalette::Inactive, QPalette::Highlight, QColor(27, 28, 33));
672 fPalBlue.setColor(QPalette::Disabled, QPalette::HighlightedText, QColor(89, 95, 104));
673 fPalBlue.setColor(QPalette::Active, QPalette::HighlightedText, QColor(217, 234, 253));
674 fPalBlue.setColor(QPalette::Inactive, QPalette::HighlightedText, QColor(223, 237, 255));
675 fPalBlue.setColor(QPalette::Disabled, QPalette::Link, QColor(79, 100, 118));
676 fPalBlue.setColor(QPalette::Active, QPalette::Link, QColor(156, 212, 255));
677 fPalBlue.setColor(QPalette::Inactive, QPalette::Link, QColor(156, 212, 255));
678 fPalBlue.setColor(QPalette::Disabled, QPalette::LinkVisited, QColor(51, 74, 118));
679 fPalBlue.setColor(QPalette::Active, QPalette::LinkVisited, QColor(64, 128, 255));
680 fPalBlue.setColor(QPalette::Inactive, QPalette::LinkVisited, QColor(64, 128, 255));
681 #endif
684 CarlaStyle::~CarlaStyle()
686 delete d;
689 void printPalette(const QPalette& pal)
691 #define PAL "fPalBlue"
693 #define PAL_PRINT(ROLE) \
695 QColor color1(pal.color(QPalette::Disabled, ROLE)); \
696 QColor color2(pal.color(QPalette::Active, ROLE)); \
697 QColor color3(pal.color(QPalette::Inactive, ROLE)); \
698 printf(PAL ".setColor(QPalette::Disabled, " #ROLE ", QColor(%i, %i, %i));\n", color1.red(), color1.green(), color1.blue()); \
699 printf(PAL ".setColor(QPalette::Active, " #ROLE ", QColor(%i, %i, %i));\n", color2.red(), color2.green(), color2.blue()); \
700 printf(PAL ".setColor(QPalette::Inactive, " #ROLE ", QColor(%i, %i, %i));\n", color3.red(), color3.green(), color3.blue()); \
703 PAL_PRINT(QPalette::Window)
704 PAL_PRINT(QPalette::WindowText)
705 PAL_PRINT(QPalette::Base)
706 PAL_PRINT(QPalette::AlternateBase)
707 PAL_PRINT(QPalette::ToolTipBase)
708 PAL_PRINT(QPalette::ToolTipText)
709 PAL_PRINT(QPalette::Text)
710 PAL_PRINT(QPalette::Button)
711 PAL_PRINT(QPalette::ButtonText)
712 PAL_PRINT(QPalette::BrightText)
713 PAL_PRINT(QPalette::Light)
714 PAL_PRINT(QPalette::Midlight)
715 PAL_PRINT(QPalette::Dark)
716 PAL_PRINT(QPalette::Mid)
717 PAL_PRINT(QPalette::Shadow)
718 PAL_PRINT(QPalette::Highlight)
719 PAL_PRINT(QPalette::HighlightedText)
720 PAL_PRINT(QPalette::Link)
721 PAL_PRINT(QPalette::LinkVisited)
723 #undef PAL
727 \fn void CarlaStyle::drawItemText(QPainter *painter, const QRect &rectangle, int alignment, const QPalette &palette,
728 bool enabled, const QString& text, QPalette::ColorRole textRole) const
730 Draws the given \a text in the specified \a rectangle using the
731 provided \a painter and \a palette.
733 Text is drawn using the painter's pen. If an explicit \a textRole
734 is specified, then the text is drawn using the \a palette's color
735 for the specified role. The \a enabled value indicates whether or
736 not the item is enabled; when reimplementing, this value should
737 influence how the item is drawn.
739 The text is aligned and wrapped according to the specified \a
740 alignment.
742 \sa Qt::Alignment
744 void CarlaStyle::drawItemText(QPainter *painter, const QRect &rect, int alignment, const QPalette &pal,
745 bool enabled, const QString& text, QPalette::ColorRole textRole) const
747 if (text.isEmpty())
748 return;
750 QPen savedPen = painter->pen();
751 if (textRole != QPalette::NoRole) {
752 painter->setPen(QPen(pal.brush(textRole), savedPen.widthF()));
754 if (!enabled) {
755 QPen pen = painter->pen();
756 painter->setPen(pen);
758 painter->drawText(rect, alignment, text);
759 painter->setPen(savedPen);
763 \reimp
765 void CarlaStyle::drawPrimitive(PrimitiveElement elem,
766 const QStyleOption *option,
767 QPainter *painter, const QWidget *widget) const
769 Q_ASSERT(option);
771 QRect rect = option->rect;
772 int state = option->state;
774 QColor outline = d->outline(option->palette);
775 QColor highlightedOutline = d->highlightedOutline(option->palette);
777 QColor tabFrameColor = d->tabFrameColor(option->palette);
779 switch (elem) {
781 // No frame drawn
782 case PE_FrameGroupBox:
784 QPixmap pixmap(QLatin1String(":/bitmaps/style/groupbox.png"));
785 int topMargin = qMax(pixelMetric(PM_ExclusiveIndicatorHeight), option->fontMetrics.height()) + groupBoxTopMargin;
786 QRect frame = option->rect.adjusted(0, topMargin, 0, 0);
787 qDrawBorderPixmap(painter, frame, QMargins(6, 6, 6, 6), pixmap);
788 break;
790 case PE_IndicatorBranch: {
791 if (!(option->state & State_Children))
792 break;
793 if (option->state & State_Open)
794 drawPrimitive(PE_IndicatorArrowDown, option, painter, widget);
795 else
796 drawPrimitive(PE_IndicatorArrowRight, option, painter, widget);
797 break;
799 case PE_FrameTabBarBase:
800 if (const QStyleOptionTabBarBase *tbb
801 = qstyleoption_cast<const QStyleOptionTabBarBase *>(option)) {
802 painter->save();
803 painter->setPen(QPen(outline.lighter(110), 0));
804 switch (tbb->shape) {
805 case QTabBar::RoundedNorth: {
806 QRegion region(tbb->rect);
807 region -= tbb->selectedTabRect;
808 painter->drawLine(tbb->rect.topLeft(), tbb->rect.topRight());
809 painter->setClipRegion(region);
810 painter->setPen(option->palette.light().color());
811 painter->drawLine(tbb->rect.topLeft() + QPoint(0, 1), tbb->rect.topRight() + QPoint(0, 1));
813 break;
814 case QTabBar::RoundedWest:
815 painter->drawLine(tbb->rect.left(), tbb->rect.top(), tbb->rect.left(), tbb->rect.bottom());
816 break;
817 case QTabBar::RoundedSouth:
818 painter->drawLine(tbb->rect.left(), tbb->rect.bottom(),
819 tbb->rect.right(), tbb->rect.bottom());
820 break;
821 case QTabBar::RoundedEast:
822 painter->drawLine(tbb->rect.topRight(), tbb->rect.bottomRight());
823 break;
824 case QTabBar::TriangularNorth:
825 case QTabBar::TriangularEast:
826 case QTabBar::TriangularWest:
827 case QTabBar::TriangularSouth:
828 painter->restore();
829 QCommonStyle::drawPrimitive(elem, option, painter, widget);
830 return;
832 painter->restore();
834 return;
835 case PE_PanelScrollAreaCorner: {
836 painter->save();
837 QColor alphaOutline = outline;
838 alphaOutline.setAlpha(180);
839 painter->setPen(alphaOutline);
840 painter->setBrush(option->palette.brush(QPalette::Window));
841 painter->drawRect(option->rect);
842 painter->restore();
843 } break;
844 case PE_IndicatorArrowUp:
845 case PE_IndicatorArrowDown:
846 case PE_IndicatorArrowRight:
847 case PE_IndicatorArrowLeft:
849 if (option->rect.width() <= 1 || option->rect.height() <= 1)
850 break;
851 QColor arrowColor = qt_palette_fg_color(option->palette);
852 QPixmap arrow;
853 int rotation = 0;
854 switch (elem) {
855 case PE_IndicatorArrowDown:
856 rotation = 180;
857 break;
858 case PE_IndicatorArrowRight:
859 rotation = 90;
860 break;
861 case PE_IndicatorArrowLeft:
862 rotation = -90;
863 break;
864 default:
865 break;
867 arrow = colorizedImage(QLatin1String(":/bitmaps/style/arrow.png"), arrowColor, rotation);
868 QRect rect = option->rect;
869 QRect arrowRect;
870 int imageMax = qMin(arrow.height(), arrow.width());
871 int rectMax = qMin(rect.height(), rect.width());
872 int size = qMin(imageMax, rectMax);
874 arrowRect.setWidth(size);
875 arrowRect.setHeight(size);
876 if (arrow.width() > arrow.height())
877 arrowRect.setHeight(arrow.height() * size / arrow.width());
878 else
879 arrowRect.setWidth(arrow.width() * size / arrow.height());
881 arrowRect.moveTopLeft(rect.center() - arrowRect.center());
882 painter->save();
883 painter->setRenderHint(QPainter::SmoothPixmapTransform);
884 painter->drawPixmap(arrowRect, arrow);
885 painter->restore();
887 break;
888 case PE_IndicatorViewItemCheck:
890 QStyleOptionButton button;
891 button.QStyleOption::operator=(*option);
892 button.state &= ~State_MouseOver;
893 proxy()->drawPrimitive(PE_IndicatorCheckBox, &button, painter, widget);
895 return;
896 case PE_IndicatorHeaderArrow:
897 if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
898 QRect r = header->rect;
899 QPixmap arrow;
900 QColor arrowColor = qt_palette_fg_color(header->palette);
901 QPoint offset = QPoint(0, -1);
903 if (header->sortIndicator & QStyleOptionHeader::SortUp) {
904 arrow = colorizedImage(QLatin1String(":/bitmaps/style/arrow.png"), arrowColor);
905 } else if (header->sortIndicator & QStyleOptionHeader::SortDown) {
906 arrow = colorizedImage(QLatin1String(":/bitmaps/style/arrow.png"), arrowColor, 180);
907 } if (!arrow.isNull()) {
908 r.setSize(QSize(arrow.width()/2, arrow.height()/2));
909 r.moveCenter(header->rect.center());
910 painter->drawPixmap(r.translated(offset), arrow);
913 break;
914 case PE_IndicatorButtonDropDown:
915 proxy()->drawPrimitive(PE_PanelButtonCommand, option, painter, widget);
916 break;
918 case PE_IndicatorToolBarSeparator:
920 QRect rect = option->rect;
921 const int margin = 6;
922 QColor separator_color = option->palette.text().color();
923 separator_color.setAlpha(50);
924 painter->setPen(QPen(separator_color));
925 if (option->state & State_Horizontal) {
926 const int offset = rect.width()/2;
928 painter->drawLine(rect.bottomLeft().x() + offset,
929 rect.bottomLeft().y() - margin,
930 rect.topLeft().x() + offset,
931 rect.topLeft().y() + margin);
932 painter->setPen(QPen(qt_palette_bg_color(option->palette).lighter(110)));
933 painter->drawLine(rect.bottomLeft().x() + offset + 1,
934 rect.bottomLeft().y() - margin,
935 rect.topLeft().x() + offset + 1,
936 rect.topLeft().y() + margin);
937 } else { //Draw vertical separator
938 const int offset = rect.height()/2;
939 painter->drawLine(rect.topLeft().x() + margin ,
940 rect.topLeft().y() + offset,
941 rect.topRight().x() - margin,
942 rect.topRight().y() + offset);
943 painter->setPen(QPen(qt_palette_bg_color(option->palette).lighter(110)));
944 painter->drawLine(rect.topLeft().x() + margin ,
945 rect.topLeft().y() + offset + 1,
946 rect.topRight().x() - margin,
947 rect.topRight().y() + offset + 1);
950 break;
951 case PE_Frame:
952 if (widget && widget->inherits("QComboBoxPrivateContainer")){
953 QStyleOption copy = *option;
954 copy.state |= State_Raised;
955 proxy()->drawPrimitive(PE_PanelMenu, &copy, painter, widget);
956 break;
958 painter->save();
959 painter->setPen(outline.lighter(108));
960 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
961 painter->restore();
962 break;
963 case PE_FrameMenu:
964 painter->save();
966 painter->setPen(QPen(outline, 1));
967 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
968 QColor frameLight = qt_palette_bg_color(option->palette).lighter(160);
969 QColor frameShadow = qt_palette_bg_color(option->palette).darker(110);
971 //paint beveleffect
972 QRect frame = option->rect.adjusted(1, 1, -1, -1);
973 painter->setPen(frameLight);
974 painter->drawLine(frame.topLeft(), frame.bottomLeft());
975 painter->drawLine(frame.topLeft(), frame.topRight());
977 painter->setPen(frameShadow);
978 painter->drawLine(frame.topRight(), frame.bottomRight());
979 painter->drawLine(frame.bottomLeft(), frame.bottomRight());
981 painter->restore();
982 break;
983 case PE_FrameDockWidget:
985 painter->save();
987 QColor softshadow = qt_palette_bg_color(option->palette).darker(120);
989 QRect rect= option->rect;
990 painter->setPen(softshadow);
991 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
992 painter->setPen(QPen(option->palette.light(), 0));
993 painter->drawLine(QPoint(rect.left() + 1, rect.top() + 1), QPoint(rect.left() + 1, rect.bottom() - 1));
994 painter->setPen(QPen(qt_palette_bg_color(option->palette).darker(120), 0));
995 painter->drawLine(QPoint(rect.left() + 1, rect.bottom() - 1), QPoint(rect.right() - 2, rect.bottom() - 1));
996 painter->drawLine(QPoint(rect.right() - 1, rect.top() + 1), QPoint(rect.right() - 1, rect.bottom() - 1));
999 painter->restore();
1000 break;
1001 case PE_PanelButtonTool:
1002 painter->save();
1003 if ((option->state & State_Enabled || option->state & State_On) || !(option->state & State_AutoRaise)) {
1004 if (widget && widget->inherits("QDockWidgetTitleButton")) {
1005 if (option->state & State_MouseOver)
1006 proxy()->drawPrimitive(PE_PanelButtonCommand, option, painter, widget);
1007 } else {
1008 proxy()->drawPrimitive(PE_PanelButtonCommand, option, painter, widget);
1011 painter->restore();
1012 break;
1013 case PE_IndicatorDockWidgetResizeHandle:
1015 QStyleOption dockWidgetHandle = *option;
1016 bool horizontal = option->state & State_Horizontal;
1017 if (horizontal)
1018 dockWidgetHandle.state &= ~State_Horizontal;
1019 else
1020 dockWidgetHandle.state |= State_Horizontal;
1021 proxy()->drawControl(CE_Splitter, &dockWidgetHandle, painter, widget);
1023 break;
1024 case PE_FrameWindow:
1025 painter->save();
1027 QRect rect= option->rect;
1028 painter->setPen(QPen(outline.darker(150), 0));
1029 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
1030 painter->setPen(QPen(option->palette.light(), 0));
1031 painter->drawLine(QPoint(rect.left() + 1, rect.top() + 1),
1032 QPoint(rect.left() + 1, rect.bottom() - 1));
1033 painter->setPen(QPen(qt_palette_bg_color(option->palette).darker(120), 0));
1034 painter->drawLine(QPoint(rect.left() + 1, rect.bottom() - 1),
1035 QPoint(rect.right() - 2, rect.bottom() - 1));
1036 painter->drawLine(QPoint(rect.right() - 1, rect.top() + 1),
1037 QPoint(rect.right() - 1, rect.bottom() - 1));
1039 painter->restore();
1040 break;
1041 case PE_FrameLineEdit:
1043 QRect r = rect;
1044 bool hasFocus = option->state & State_HasFocus;
1046 painter->save();
1048 painter->setRenderHint(QPainter::Antialiasing, true);
1049 // ### highdpi painter bug.
1050 painter->translate(0.5, 0.5);
1052 // Draw Outline
1053 painter->setPen( QPen(hasFocus ? highlightedOutline : highlightedOutline.darker(160), 0));
1054 painter->setBrush(option->palette.base());
1055 painter->drawRoundedRect(r.adjusted(0, 0, -1, -1), 2, 2);
1057 if (hasFocus) {
1058 QColor softHighlight = highlightedOutline;
1059 softHighlight.setAlpha(40);
1060 painter->setPen(softHighlight);
1061 painter->drawRoundedRect(r.adjusted(1, 1, -2, -2), 1.7, 1.7);
1063 // Draw inner shadow
1064 painter->setPen(d->topShadow());
1065 painter->drawLine(QPoint(r.left() + 2, r.top() + 1), QPoint(r.right() - 2, r.top() + 1));
1067 painter->restore();
1070 break;
1071 case PE_IndicatorCheckBox:
1072 painter->save();
1073 if (const QStyleOptionButton *checkbox = qstyleoption_cast<const QStyleOptionButton*>(option)) {
1074 painter->setRenderHint(QPainter::Antialiasing, true);
1075 painter->translate(0.5, 0.5);
1076 rect = rect.adjusted(0, 0, -1, -1);
1078 const QColor& baseColor = option->palette.base().color();
1080 QColor pressedColor = mergedColors(baseColor, qt_palette_fg_color(option->palette), 85);
1081 painter->setBrush(Qt::NoBrush);
1083 // Gradient fill
1084 QLinearGradient gradient(rect.topLeft(), rect.bottomLeft());
1086 if (state & State_Sunken)
1088 gradient.setColorAt(0, pressedColor);
1089 gradient.setColorAt(0.15, pressedColor);
1090 gradient.setColorAt(1, pressedColor);
1092 else
1094 gradient.setColorAt(0, baseColor.blackF() > 0.4 ? baseColor.lighter(115) : baseColor.darker(115));
1095 gradient.setColorAt(0.15, baseColor);
1096 gradient.setColorAt(1, baseColor);
1099 painter->setBrush((state & State_Sunken) ? QBrush(pressedColor) : gradient);
1101 if (option->state & State_HasFocus && option->state & State_KeyboardFocusChange)
1102 painter->setPen(QPen(highlightedOutline, 1));
1103 else
1104 painter->setPen(QPen(outline.lighter(110), 1));
1106 painter->drawRect(rect);
1108 QColor checkMarkColor = option->palette.text().color().darker(120);
1110 if (checkbox->state & State_NoChange) {
1111 gradient = QLinearGradient(rect.topLeft(), rect.bottomLeft());
1112 checkMarkColor.setAlpha(80);
1113 gradient.setColorAt(0, checkMarkColor);
1114 checkMarkColor.setAlpha(140);
1115 gradient.setColorAt(1, checkMarkColor);
1116 checkMarkColor.setAlpha(180);
1117 painter->setPen(QPen(checkMarkColor, 1));
1118 painter->setBrush(gradient);
1119 painter->drawRect(rect.adjusted(3, 3, -3, -3));
1121 } else if (checkbox->state & (State_On)) {
1122 QPen checkPen = QPen(checkMarkColor, 1.8);
1123 checkMarkColor.setAlpha(210);
1124 painter->translate(-1, 0.5);
1125 painter->setPen(checkPen);
1126 painter->setBrush(Qt::NoBrush);
1127 painter->translate(0.2, 0.0);
1129 // Draw checkmark
1130 QPainterPath path;
1131 path.moveTo(5, rect.height() / 2.0);
1132 path.lineTo(rect.width() / 2.0 - 0, rect.height() - 3);
1133 path.lineTo(rect.width() - 2.5, 3);
1134 painter->drawPath(path.translated(rect.topLeft()));
1137 painter->restore();
1138 break;
1139 case PE_IndicatorRadioButton:
1140 painter->save();
1142 QColor pressedColor = mergedColors(option->palette.base().color(), qt_palette_fg_color(option->palette), 85);
1143 painter->setBrush((state & State_Sunken) ? pressedColor : option->palette.base().color());
1144 painter->setRenderHint(QPainter::Antialiasing, true);
1145 QPainterPath circle;
1146 circle.addEllipse(rect.center() + QPoint(1.0, 1.0), 6.5, 6.5);
1147 painter->setPen(QPen(qt_palette_bg_color(option->palette).darker(150), 1));
1148 if (option->state & State_HasFocus && option->state & State_KeyboardFocusChange)
1149 painter->setPen(QPen(highlightedOutline, 1));
1150 painter->drawPath(circle);
1152 if (state & (State_On )) {
1153 circle = QPainterPath();
1154 circle.addEllipse(rect.center() + QPoint(1, 1), 2.8, 2.8);
1155 QColor checkMarkColor = option->palette.text().color().darker(120);
1156 checkMarkColor.setAlpha(200);
1157 painter->setPen(checkMarkColor);
1158 checkMarkColor.setAlpha(180);
1159 painter->setBrush(checkMarkColor);
1160 painter->drawPath(circle);
1163 painter->restore();
1164 break;
1165 case PE_IndicatorToolBarHandle:
1167 //draw grips
1168 if (option->state & State_Horizontal) {
1169 for (int i = -3 ; i < 2 ; i += 3) {
1170 for (int j = -8 ; j < 10 ; j += 3) {
1171 painter->fillRect(rect.center().x() + i, rect.center().y() + j, 2, 2, d->lightShade());
1172 painter->fillRect(rect.center().x() + i, rect.center().y() + j, 1, 1, d->darkShade());
1175 } else { //vertical toolbar
1176 for (int i = -6 ; i < 12 ; i += 3) {
1177 for (int j = -3 ; j < 2 ; j += 3) {
1178 painter->fillRect(rect.center().x() + i, rect.center().y() + j, 2, 2, d->lightShade());
1179 painter->fillRect(rect.center().x() + i, rect.center().y() + j, 1, 1, d->darkShade());
1183 break;
1185 case PE_FrameDefaultButton:
1186 break;
1187 case PE_FrameFocusRect:
1188 if (const QStyleOptionFocusRect *fropt = qstyleoption_cast<const QStyleOptionFocusRect *>(option)) {
1189 //### check for d->alt_down
1190 if (!(fropt->state & State_KeyboardFocusChange))
1191 return;
1192 QRect rect = option->rect;
1194 painter->save();
1195 painter->setRenderHint(QPainter::Antialiasing, true);
1196 painter->translate(0.5, 0.5);
1197 QColor fillcolor = highlightedOutline;
1198 fillcolor.setAlpha(80);
1199 painter->setPen(fillcolor.darker(120));
1200 fillcolor.setAlpha(30);
1201 QLinearGradient gradient(rect.topLeft(), rect.bottomLeft());
1202 gradient.setColorAt(0, fillcolor.lighter(160));
1203 gradient.setColorAt(1, fillcolor);
1204 painter->setBrush(gradient);
1205 painter->drawRoundedRect(option->rect.adjusted(0, 0, -1, -1), 1, 1);
1206 painter->restore();
1208 break;
1209 case PE_PanelButtonCommand:
1211 bool isDefault = false;
1212 bool isFlat = false;
1213 bool isDown = (option->state & State_Sunken) || (option->state & State_On);
1214 QRect r;
1216 if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton*>(option)) {
1217 isDefault = (button->features & QStyleOptionButton::DefaultButton) && (button->state & State_Enabled);
1218 isFlat = (button->features & QStyleOptionButton::Flat);
1221 if (isFlat && !isDown) {
1222 if (isDefault) {
1223 r = option->rect.adjusted(0, 1, 0, -1);
1224 painter->setPen(QPen(Qt::black, 0));
1225 const QLine lines[4] = {
1226 QLine(QPoint(r.left() + 2, r.top()),
1227 QPoint(r.right() - 2, r.top())),
1228 QLine(QPoint(r.left(), r.top() + 2),
1229 QPoint(r.left(), r.bottom() - 2)),
1230 QLine(QPoint(r.right(), r.top() + 2),
1231 QPoint(r.right(), r.bottom() - 2)),
1232 QLine(QPoint(r.left() + 2, r.bottom()),
1233 QPoint(r.right() - 2, r.bottom()))
1235 painter->drawLines(lines, 4);
1236 const QPoint points[4] = {
1237 QPoint(r.right() - 1, r.bottom() - 1),
1238 QPoint(r.right() - 1, r.top() + 1),
1239 QPoint(r.left() + 1, r.bottom() - 1),
1240 QPoint(r.left() + 1, r.top() + 1)
1242 painter->drawPoints(points, 4);
1244 return;
1247 BEGIN_STYLE_PIXMAPCACHE(QString::fromLatin1("pushbutton-%1").arg(isDefault))
1248 r = rect.adjusted(0, 1, -1, 0);
1250 bool isEnabled = option->state & State_Enabled;
1251 bool hasFocus = (option->state & State_HasFocus && option->state & State_KeyboardFocusChange);
1252 QColor buttonColor = d->buttonColor(option->palette);
1254 QColor darkOutline = outline;
1255 if (hasFocus || isDefault) {
1256 darkOutline = highlightedOutline;
1259 if (isDefault)
1260 buttonColor = mergedColors(buttonColor, highlightedOutline.lighter(130), 90);
1262 p->setRenderHint(QPainter::Antialiasing, true);
1263 p->translate(0.5, -0.5);
1265 QLinearGradient gradient = qt_fusion_gradient(rect, (isEnabled && option->state & State_MouseOver ) ? buttonColor : buttonColor.darker(104));
1266 p->setBrush(isDown ? QBrush(buttonColor.darker(110)) : gradient);
1267 p->setPen(QPen(p->brush(), 1));
1268 p->drawRoundedRect(r.adjusted(1,1,-1,-1), 1.8, 1.8);
1269 p->setBrush(Qt::NoBrush);
1271 // Outline
1272 p->setPen(!isEnabled ? QPen(darkOutline.lighter(115)) : QPen(darkOutline, 1));
1273 p->drawRoundedRect(r, 2.5, 2.5);
1275 p->setPen(d->innerContrastLine());
1276 p->drawRoundedRect(r.adjusted(1, 1, -1, -1), 1.8, 1.8);
1278 END_STYLE_PIXMAPCACHE
1280 break;
1281 case PE_FrameTabWidget:
1282 painter->save();
1283 painter->fillRect(option->rect.adjusted(0, 0, -1, -1), tabFrameColor);
1284 if (const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(option)) {
1285 QColor borderColor = outline.lighter(110);
1286 QRect rect = option->rect.adjusted(0, 0, -1, -1);
1288 // Shadow outline
1289 if (twf->shape != QTabBar::RoundedSouth) {
1290 rect.adjust(0, 0, 0, -1);
1291 QColor alphaShadow(Qt::black);
1292 alphaShadow.setAlpha(15);
1293 painter->setPen(alphaShadow);
1294 painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight()); painter->setPen(borderColor);
1297 // outline
1298 painter->setPen(outline);
1299 painter->drawRect(rect);
1301 // Inner frame highlight
1302 painter->setPen(d->innerContrastLine());
1303 painter->drawRect(rect.adjusted(1, 1, -1, -1));
1306 painter->restore();
1307 break ;
1309 case PE_FrameStatusBarItem:
1310 break;
1311 case PE_IndicatorTabClose:
1313 if (d->tabBarcloseButtonIcon.isNull())
1314 d->tabBarcloseButtonIcon = standardIcon(SP_DialogCloseButton, option, widget);
1315 if ((option->state & State_Enabled) && (option->state & State_MouseOver))
1316 proxy()->drawPrimitive(PE_PanelButtonCommand, option, painter, widget);
1317 QPixmap pixmap = d->tabBarcloseButtonIcon.pixmap(QSize(16, 16), QIcon::Normal, QIcon::On);
1318 proxy()->drawItemPixmap(painter, option->rect, Qt::AlignCenter, pixmap);
1320 break;
1321 case PE_PanelMenu: {
1322 painter->save();
1323 const QBrush menuBackground = option->palette.base().color().lighter(108);
1324 QColor borderColor(32, 32, 32);
1325 qDrawPlainRect(painter, option->rect, borderColor, 1, &menuBackground);
1326 painter->restore();
1328 break;
1330 default:
1331 QCommonStyle::drawPrimitive(elem, option, painter, widget);
1332 break;
1337 \reimp
1339 void CarlaStyle::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter,
1340 const QWidget *widget) const
1342 QRect rect = option->rect;
1343 QColor outline = d->outline(option->palette);
1344 QColor highlightedOutline = d->highlightedOutline(option->palette);
1345 QColor shadow = d->darkShade();
1347 switch (element) {
1348 case CE_ComboBoxLabel:
1349 if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
1350 QRect editRect = proxy()->subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, widget);
1351 painter->save();
1352 painter->setClipRect(editRect);
1353 if (!cb->currentIcon.isNull()) {
1354 QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal
1355 : QIcon::Disabled;
1356 QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, mode);
1357 QRect iconRect(editRect);
1358 iconRect.setWidth(cb->iconSize.width() + 4);
1359 iconRect = alignedRect(cb->direction,
1360 Qt::AlignLeft | Qt::AlignVCenter,
1361 iconRect.size(), editRect);
1362 if (cb->editable)
1363 painter->fillRect(iconRect, cb->palette.brush(QPalette::Base));
1364 proxy()->drawItemPixmap(painter, iconRect, Qt::AlignCenter, pixmap);
1366 if (cb->direction == Qt::RightToLeft)
1367 editRect.translate(-4 - cb->iconSize.width(), 0);
1368 else
1369 editRect.translate(cb->iconSize.width() + 4, 0);
1371 if (!cb->currentText.isEmpty() && !cb->editable) {
1372 proxy()->drawItemText(painter, editRect.adjusted(1, 0, -1, 0),
1373 visualAlignment(cb->direction, Qt::AlignLeft | Qt::AlignVCenter),
1374 cb->palette, cb->state & State_Enabled, cb->currentText,
1375 cb->editable ? QPalette::Text : QPalette::ButtonText);
1377 painter->restore();
1379 break;
1380 case CE_Splitter:
1382 // Don't draw handle for single pixel splitters
1383 if (option->rect.width() > 1 && option->rect.height() > 1) {
1384 //draw grips
1385 if (option->state & State_Horizontal) {
1386 for (int j = -6 ; j< 12 ; j += 3) {
1387 painter->fillRect(rect.center().x() + 1, rect.center().y() + j, 2, 2, d->lightShade());
1388 painter->fillRect(rect.center().x() + 1, rect.center().y() + j, 1, 1, d->darkShade());
1390 } else {
1391 for (int i = -6; i< 12 ; i += 3) {
1392 painter->fillRect(rect.center().x() + i, rect.center().y(), 2, 2, d->lightShade());
1393 painter->fillRect(rect.center().x() + i, rect.center().y(), 1, 1, d->darkShade());
1397 break;
1399 case CE_RubberBand:
1400 if (qstyleoption_cast<const QStyleOptionRubberBand *>(option)) {
1401 QColor highlight = option->palette.color(QPalette::Active, QPalette::Highlight);
1402 painter->save();
1403 QColor penColor = highlight.darker(120);
1404 penColor.setAlpha(180);
1405 painter->setPen(penColor);
1406 QColor dimHighlight(qMin(highlight.red()/2 + 110, 255),
1407 qMin(highlight.green()/2 + 110, 255),
1408 qMin(highlight.blue()/2 + 110, 255));
1409 dimHighlight.setAlpha(widget && widget->isTopLevel() ? 255 : 80);
1410 QLinearGradient gradient(rect.topLeft(), QPoint(rect.bottomLeft().x(), rect.bottomLeft().y()));
1411 gradient.setColorAt(0, dimHighlight.lighter(120));
1412 gradient.setColorAt(1, dimHighlight);
1413 painter->setRenderHint(QPainter::Antialiasing, true);
1414 painter->translate(0.5, 0.5);
1415 painter->setBrush(dimHighlight);
1416 painter->drawRoundedRect(option->rect.adjusted(0, 0, -1, -1), 1.3, 1.3);
1417 QColor innerLine = Qt::white;
1418 innerLine.setAlpha(40);
1419 painter->setPen(innerLine);
1420 painter->drawRoundedRect(option->rect.adjusted(1, 1, -2, -2), 0.7, 0.7);
1421 painter->restore();
1422 return;
1424 break;
1425 case CE_SizeGrip:
1426 painter->save();
1428 //draw grips
1429 for (int i = -6; i< 12 ; i += 3) {
1430 for (int j = -6 ; j< 12 ; j += 3) {
1431 if ((option->direction == Qt::LeftToRight && i > -j) || (option->direction == Qt::RightToLeft && j > i) ) {
1432 painter->fillRect(rect.center().x() + i, rect.center().y() + j, 2, 2, d->lightShade());
1433 painter->fillRect(rect.center().x() + i, rect.center().y() + j, 1, 1, d->darkShade());
1438 painter->restore();
1439 break;
1440 case CE_ToolBar:
1441 if (const QStyleOptionToolBar *toolBar = qstyleoption_cast<const QStyleOptionToolBar *>(option)) {
1442 // Reserve the beveled appearance only for mainwindow toolbars
1443 if (widget && !(qobject_cast<const QMainWindow*> (widget->parentWidget())))
1444 break;
1446 // Draws the light line above and the dark line below menu bars and
1447 // tool bars.
1448 QLinearGradient gradient(option->rect.topLeft(), option->rect.bottomLeft());
1449 if (!(option->state & State_Horizontal))
1450 gradient = QLinearGradient(rect.left(), rect.center().y(),
1451 rect.right(), rect.center().y());
1452 gradient.setColorAt(0, option->palette.window().color().lighter(104));
1453 gradient.setColorAt(1, option->palette.window().color());
1454 painter->fillRect(option->rect, gradient);
1456 QColor light = d->lightShade();
1457 QColor shadow = d->darkShade();
1459 QPen oldPen = painter->pen();
1460 if (toolBar->toolBarArea == Qt::TopToolBarArea) {
1461 if (toolBar->positionOfLine == QStyleOptionToolBar::End
1462 || toolBar->positionOfLine == QStyleOptionToolBar::OnlyOne) {
1463 // The end and onlyone top toolbar lines draw a double
1464 // line at the bottom to blend with the central
1465 // widget.
1466 painter->setPen(light);
1467 painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
1468 painter->setPen(shadow);
1469 painter->drawLine(option->rect.left(), option->rect.bottom() - 1,
1470 option->rect.right(), option->rect.bottom() - 1);
1471 } else {
1472 // All others draw a single dark line at the bottom.
1473 painter->setPen(shadow);
1474 painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
1476 // All top toolbar lines draw a light line at the top.
1477 painter->setPen(light);
1478 painter->drawLine(option->rect.topLeft(), option->rect.topRight());
1479 } else if (toolBar->toolBarArea == Qt::BottomToolBarArea) {
1480 if (toolBar->positionOfLine == QStyleOptionToolBar::End
1481 || toolBar->positionOfLine == QStyleOptionToolBar::Middle) {
1482 // The end and middle bottom tool bar lines draw a dark
1483 // line at the bottom.
1484 painter->setPen(shadow);
1485 painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
1487 if (toolBar->positionOfLine == QStyleOptionToolBar::Beginning
1488 || toolBar->positionOfLine == QStyleOptionToolBar::OnlyOne) {
1489 // The beginning and only one tool bar lines draw a
1490 // double line at the bottom to blend with the
1491 // status bar.
1492 // ### The styleoption could contain whether the
1493 // main window has a menu bar and a status bar, and
1494 // possibly dock widgets.
1495 painter->setPen(shadow);
1496 painter->drawLine(option->rect.left(), option->rect.bottom() - 1,
1497 option->rect.right(), option->rect.bottom() - 1);
1498 painter->setPen(light);
1499 painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
1501 if (toolBar->positionOfLine == QStyleOptionToolBar::End) {
1502 painter->setPen(shadow);
1503 painter->drawLine(option->rect.topLeft(), option->rect.topRight());
1504 painter->setPen(light);
1505 painter->drawLine(option->rect.left(), option->rect.top() + 1,
1506 option->rect.right(), option->rect.top() + 1);
1508 } else {
1509 // All other bottom toolbars draw a light line at the top.
1510 painter->setPen(light);
1511 painter->drawLine(option->rect.topLeft(), option->rect.topRight());
1514 if (toolBar->toolBarArea == Qt::LeftToolBarArea) {
1515 if (toolBar->positionOfLine == QStyleOptionToolBar::Middle
1516 || toolBar->positionOfLine == QStyleOptionToolBar::End) {
1517 // The middle and left end toolbar lines draw a light
1518 // line to the left.
1519 painter->setPen(light);
1520 painter->drawLine(option->rect.topLeft(), option->rect.bottomLeft());
1522 if (toolBar->positionOfLine == QStyleOptionToolBar::End) {
1523 // All other left toolbar lines draw a dark line to the right
1524 painter->setPen(shadow);
1525 painter->drawLine(option->rect.right() - 1, option->rect.top(),
1526 option->rect.right() - 1, option->rect.bottom());
1527 painter->setPen(light);
1528 painter->drawLine(option->rect.topRight(), option->rect.bottomRight());
1529 } else {
1530 // All other left toolbar lines draw a dark line to the right
1531 painter->setPen(shadow);
1532 painter->drawLine(option->rect.topRight(), option->rect.bottomRight());
1534 } else if (toolBar->toolBarArea == Qt::RightToolBarArea) {
1535 if (toolBar->positionOfLine == QStyleOptionToolBar::Middle
1536 || toolBar->positionOfLine == QStyleOptionToolBar::End) {
1537 // Right middle and end toolbar lines draw the dark right line
1538 painter->setPen(shadow);
1539 painter->drawLine(option->rect.topRight(), option->rect.bottomRight());
1541 if (toolBar->positionOfLine == QStyleOptionToolBar::End
1542 || toolBar->positionOfLine == QStyleOptionToolBar::OnlyOne) {
1543 // The right end and single toolbar draws the dark
1544 // line on its left edge
1545 painter->setPen(shadow);
1546 painter->drawLine(option->rect.topLeft(), option->rect.bottomLeft());
1547 // And a light line next to it
1548 painter->setPen(light);
1549 painter->drawLine(option->rect.left() + 1, option->rect.top(),
1550 option->rect.left() + 1, option->rect.bottom());
1551 } else {
1552 // Other right toolbars draw a light line on its left edge
1553 painter->setPen(light);
1554 painter->drawLine(option->rect.topLeft(), option->rect.bottomLeft());
1557 painter->setPen(oldPen);
1559 break;
1560 case CE_DockWidgetTitle:
1561 painter->save();
1562 if (const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<const QStyleOptionDockWidget *>(option)) {
1563 bool verticalTitleBar = false;
1565 QRect titleRect = subElementRect(SE_DockWidgetTitleBarText, option, widget);
1566 if (verticalTitleBar) {
1567 QRect rect = dwOpt->rect;
1568 QRect r = rect;
1569 QSize s = r.size();
1570 s.transpose();
1571 r.setSize(s);
1572 titleRect = QRect(r.left() + rect.bottom()
1573 - titleRect.bottom(),
1574 r.top() + titleRect.left() - rect.left(),
1575 titleRect.height(), titleRect.width());
1577 painter->translate(r.left(), r.top() + r.width());
1578 painter->rotate(-90);
1579 painter->translate(-r.left(), -r.top());
1582 if (!dwOpt->title.isEmpty()) {
1583 QString titleText
1584 = painter->fontMetrics().elidedText(dwOpt->title,
1585 Qt::ElideRight, titleRect.width());
1586 proxy()->drawItemText(painter,
1587 titleRect,
1588 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, dwOpt->palette,
1589 dwOpt->state & State_Enabled, titleText,
1590 QPalette::WindowText);
1593 painter->restore();
1594 break;
1595 case CE_HeaderSection:
1596 painter->save();
1597 // Draws the header in tables.
1598 if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
1599 QString pixmapName = uniqueName(QLatin1String("headersection"), option, option->rect.size());
1600 pixmapName += QString::number(- int(header->position));
1601 pixmapName += QString::number(- int(header->orientation));
1603 QPixmap cache;
1604 if (!QPixmapCache::find(pixmapName, PIXMAPCACHE_VAR_PREFIX cache)) {
1605 cache = styleCachePixmap(rect.size());
1606 cache.fill(Qt::transparent);
1607 QRect pixmapRect(0, 0, rect.width(), rect.height());
1608 QPainter cachePainter(&cache);
1609 QColor buttonColor = d->buttonColor(option->palette);
1610 QColor gradientStopColor;
1611 QColor gradientStartColor = buttonColor.lighter(104);
1612 gradientStopColor = buttonColor.darker(102);
1613 QLinearGradient gradient(pixmapRect.topLeft(), pixmapRect.bottomLeft());
1615 #if (QT_VERSION >= QT_VERSION_CHECK(5, 13, 0))
1616 const QGradient* gradientBrush = option->palette.window().gradient();
1617 #else
1618 const QGradient* gradientBrush = option->palette.background().gradient();
1619 #endif
1620 if (gradientBrush) {
1621 gradient.setStops(gradientBrush->stops());
1622 } else {
1623 QColor midColor1 = mergedColors(gradientStartColor, gradientStopColor, 60);
1624 QColor midColor2 = mergedColors(gradientStartColor, gradientStopColor, 40);
1625 gradient.setColorAt(0, gradientStartColor);
1626 gradient.setColorAt(0.5, midColor1);
1627 gradient.setColorAt(0.501, midColor2);
1628 gradient.setColorAt(0.92, gradientStopColor);
1629 gradient.setColorAt(1, gradientStopColor.darker(104));
1631 cachePainter.fillRect(pixmapRect, gradient);
1632 cachePainter.setPen(d->innerContrastLine());
1633 cachePainter.setBrush(Qt::NoBrush);
1634 cachePainter.drawLine(pixmapRect.topLeft(), pixmapRect.topRight());
1635 cachePainter.setPen(d->outline(option->palette));
1636 cachePainter.drawLine(pixmapRect.bottomLeft(), pixmapRect.bottomRight());
1638 if (header->orientation == Qt::Horizontal &&
1639 header->position != QStyleOptionHeader::End &&
1640 header->position != QStyleOptionHeader::OnlyOneSection) {
1641 cachePainter.setPen(QColor(0, 0, 0, 40));
1642 cachePainter.drawLine(pixmapRect.topRight(), pixmapRect.bottomRight() + QPoint(0, -1));
1643 cachePainter.setPen(d->innerContrastLine());
1644 cachePainter.drawLine(pixmapRect.topRight() + QPoint(-1, 0), pixmapRect.bottomRight() + QPoint(-1, -1));
1645 } else if (header->orientation == Qt::Vertical) {
1646 cachePainter.setPen(d->outline(option->palette));
1647 cachePainter.drawLine(pixmapRect.topRight(), pixmapRect.bottomRight());
1649 cachePainter.end();
1650 QPixmapCache::insert(pixmapName, cache);
1652 painter->drawPixmap(rect.topLeft(), cache);
1654 painter->restore();
1655 break;
1656 case CE_ProgressBarGroove:
1657 painter->save();
1659 painter->setRenderHint(QPainter::Antialiasing, true);
1660 painter->translate(0.5, 0.5);
1662 QColor shadowAlpha = Qt::black;
1663 shadowAlpha.setAlpha(16);
1664 painter->setPen(shadowAlpha);
1665 painter->drawLine(rect.topLeft() - QPoint(0, 1), rect.topRight() - QPoint(0, 1));
1667 painter->setBrush(Qt::NoBrush);
1668 painter->setPen(QPen(outline, 1));
1669 painter->drawRoundedRect(rect.adjusted(0, 0, -1, -1), 2.5, 2.5);
1670 painter->setBrush(option->palette.base());
1671 painter->setPen(QPen(option->palette.base(), 1));
1672 painter->drawRoundedRect(rect.adjusted(1, 1, -2, -2), 1.8, 1.8);
1674 // Inner shadow
1675 painter->setPen(d->topShadow());
1676 painter->drawLine(QPoint(rect.left() + 1, rect.top() + 1),
1677 QPoint(rect.right() - 1, rect.top() + 1));
1679 painter->restore();
1680 break;
1681 case CE_ProgressBarContents:
1682 painter->save();
1683 painter->setRenderHint(QPainter::Antialiasing, true);
1684 painter->translate(0.5, 0.5);
1685 if (const QStyleOptionProgressBarV2 *bar = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(option)) {
1686 bool vertical = false;
1687 bool inverted = false;
1688 bool indeterminate = (bar->minimum == 0 && bar->maximum == 0);
1689 bool complete = bar->progress == bar->maximum;
1691 // Get extra style options if version 2
1692 vertical = (bar->orientation == Qt::Vertical);
1693 inverted = bar->invertedAppearance;
1695 // If the orientation is vertical, we use a transform to rotate
1696 // the progress bar 90 degrees clockwise. This way we can use the
1697 // same rendering code for both orientations.
1698 if (vertical) {
1699 rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // flip width and height
1700 QTransform m = QTransform::fromTranslate(rect.height()-1, -1.0);
1701 m.rotate(90.0);
1702 painter->setTransform(m, true);
1705 int maxWidth = rect.width();
1706 int minWidth = 0;
1707 qreal progress = qMax(bar->progress, bar->minimum); // workaround for bug in QProgressBar
1708 int progressBarWidth = (progress - bar->minimum) * qreal(maxWidth) / qMax(qreal(1.0), qreal(bar->maximum) - bar->minimum);
1709 int width = indeterminate ? maxWidth : qMax(minWidth, progressBarWidth);
1711 bool reverse = (!vertical && (bar->direction == Qt::RightToLeft)) || vertical;
1712 if (inverted)
1713 reverse = !reverse;
1715 int step = 0;
1716 QRect progressBar;
1717 QColor highlight = d->highlight(option->palette);
1718 QColor highlightedoutline = highlight.darker(140);
1719 if (qGray(outline.rgb()) > qGray(highlightedoutline.rgb()))
1720 outline = highlightedoutline;
1722 if (!indeterminate) {
1723 QColor innerShadow(Qt::black);
1724 innerShadow.setAlpha(35);
1725 painter->setPen(innerShadow);
1726 if (!reverse) {
1727 progressBar.setRect(rect.left(), rect.top(), width - 1, rect.height() - 1);
1728 if (!complete) {
1729 painter->drawLine(progressBar.topRight() + QPoint(2, 1), progressBar.bottomRight() + QPoint(2, 0));
1730 painter->setPen(QPen(highlight.darker(140), 0));
1731 painter->drawLine(progressBar.topRight() + QPoint(1, 1), progressBar.bottomRight() + QPoint(1, 0));
1733 } else {
1734 progressBar.setRect(rect.right() - width - 1, rect.top(), width + 2, rect.height() - 1);
1735 if (!complete) {
1736 painter->drawLine(progressBar.topLeft() + QPoint(-2, 1), progressBar.bottomLeft() + QPoint(-2, 0));
1737 painter->setPen(QPen(highlight.darker(140), 0));
1738 painter->drawLine(progressBar.topLeft() + QPoint(-1, 1), progressBar.bottomLeft() + QPoint(-1, 0));
1741 } else {
1742 progressBar.setRect(rect.left(), rect.top(), rect.width() - 1, rect.height() - 1);
1745 if (indeterminate || bar->progress > bar->minimum) {
1747 QColor highlightedGradientStartColor = highlight.lighter(120);
1748 QColor highlightedGradientStopColor = highlight;
1749 QLinearGradient gradient(rect.topLeft(), QPoint(rect.bottomLeft().x(), rect.bottomLeft().y()));
1750 gradient.setColorAt(0, highlightedGradientStartColor);
1751 gradient.setColorAt(1, highlightedGradientStopColor);
1753 painter->setBrush(gradient);
1754 painter->setPen(QPen(painter->brush(), 1));
1756 painter->save();
1757 if (!complete && !indeterminate)
1758 painter->setClipRect(progressBar.adjusted(0, 0, -1, 0));
1759 QRect fillRect = progressBar.adjusted( indeterminate || complete || !reverse ? 1 : -1, 1,
1760 indeterminate || complete || reverse ? -1 : 1, -1);
1761 painter->drawRoundedRect(fillRect, 1.8, 1.8);
1762 painter->restore();
1764 painter->setBrush(Qt::NoBrush);
1765 painter->setPen(QColor(255, 255, 255, 50));
1766 painter->drawRoundedRect(progressBar.adjusted(1, 1, -1, -1), 1.8, 1.8);
1768 if (!indeterminate) {
1769 d->stopAnimation(widget);
1770 } else {
1771 highlightedGradientStartColor.setAlpha(120);
1772 painter->setPen(QPen(highlightedGradientStartColor, 9.0));
1773 painter->setClipRect(progressBar.adjusted(1, 1, -1, -1));
1774 #ifndef QT_NO_ANIMATION
1775 if (CarlaProgressStyleAnimation *animation = qobject_cast<CarlaProgressStyleAnimation*>(d->animation(widget)))
1776 step = animation->animationStep() % 22;
1777 else
1778 d->startAnimation(new CarlaProgressStyleAnimation(d->animationFps(), const_cast<QWidget*>(widget)));
1779 #endif
1780 for (int x = progressBar.left() - rect.height(); x < rect.right() ; x += 22)
1781 painter->drawLine(x + step, progressBar.bottom() + 1,
1782 x + rect.height() + step, progressBar.top() - 2);
1786 painter->restore();
1787 break;
1788 case CE_ProgressBarLabel:
1789 if (const QStyleOptionProgressBarV2 *bar = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(option)) {
1790 QRect leftRect;
1791 QRect rect = bar->rect;
1792 QColor textColor = option->palette.text().color();
1793 QColor alternateTextColor = d->highlightedText(option->palette);
1795 painter->save();
1796 bool vertical = false, inverted = false;
1797 vertical = (bar->orientation == Qt::Vertical);
1798 inverted = bar->invertedAppearance;
1799 if (vertical)
1800 rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // flip width and height
1801 const int progressIndicatorPos = (bar->progress - qreal(bar->minimum)) * rect.width() /
1802 qMax(qreal(1.0), qreal(bar->maximum) - bar->minimum);
1803 if (progressIndicatorPos >= 0 && progressIndicatorPos <= rect.width())
1804 leftRect = QRect(rect.left(), rect.top(), progressIndicatorPos, rect.height());
1805 if (vertical)
1806 leftRect.translate(rect.width() - progressIndicatorPos, 0);
1808 bool flip = (!vertical && (((bar->direction == Qt::RightToLeft) && !inverted) ||
1809 ((bar->direction == Qt::LeftToRight) && inverted)));
1811 QRegion rightRect = rect;
1812 rightRect = rightRect.subtracted(leftRect);
1813 painter->setClipRegion(rightRect);
1814 painter->setPen(flip ? alternateTextColor : textColor);
1815 painter->drawText(rect, bar->text, QTextOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter));
1816 if (!leftRect.isNull()) {
1817 painter->setPen(flip ? textColor : alternateTextColor);
1818 painter->setClipRect(leftRect);
1819 painter->drawText(rect, bar->text, QTextOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter));
1821 painter->restore();
1823 break;
1824 case CE_MenuBarItem:
1825 painter->save();
1826 if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option))
1828 QStyleOptionMenuItem item = *mbi;
1829 item.rect = mbi->rect.adjusted(0, 1, 0, -3);
1830 QColor highlightOutline = option->palette.highlight().color().darker(125);
1831 painter->fillRect(rect, option->palette.window());
1833 QCommonStyle::drawControl(element, &item, painter, widget);
1835 bool act = mbi->state & State_Selected && mbi->state & State_Sunken;
1836 bool dis = !(mbi->state & State_Enabled);
1838 QRect r = option->rect;
1839 if (act)
1841 painter->setBrush(option->palette.highlight().color());
1842 painter->setPen(QPen(highlightOutline, 0));
1843 painter->drawRect(r.adjusted(0, 5, -1, -1));
1844 painter->drawRoundedRect(r.adjusted(0, 0, -1, -1), 2, 2);
1846 //draw text
1847 QPalette::ColorRole textRole = dis ? QPalette::Text : QPalette::HighlightedText;
1848 uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
1849 if (!styleHint(SH_UnderlineShortcut, mbi, widget))
1850 alignment |= Qt::TextHideMnemonic;
1851 proxy()->drawItemText(painter, item.rect, alignment, mbi->palette, mbi->state & State_Enabled, mbi->text, textRole);
1853 else
1855 QColor shadow = mergedColors(qt_palette_bg_color(option->palette).darker(120),
1856 outline.lighter(140), 60);
1857 painter->setPen(QPen(shadow));
1858 painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
1861 painter->restore();
1862 break;
1863 case CE_MenuItem:
1864 painter->save();
1865 // Draws one item in a popup menu.
1866 if (const QStyleOptionMenuItem* menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
1867 QColor highlightOutline = highlightedOutline;
1868 QColor highlight = option->palette.highlight().color();
1869 if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) {
1870 int w = 0;
1871 if (!menuItem->text.isEmpty()) {
1872 painter->setFont(menuItem->font);
1873 proxy()->drawItemText(painter, menuItem->rect.adjusted(5, 0, -5, 0), Qt::AlignLeft | Qt::AlignVCenter,
1874 menuItem->palette, menuItem->state & State_Enabled, menuItem->text,
1875 QPalette::Text);
1876 w = fontMetricsHorizontalAdvance(menuItem->fontMetrics, menuItem->text) + 5;
1878 painter->setPen(highlight);
1879 bool reverse = menuItem->direction == Qt::RightToLeft;
1880 painter->drawLine(menuItem->rect.left() + 5 + (reverse ? 0 : w), menuItem->rect.center().y(),
1881 menuItem->rect.right() - 5 - (reverse ? w : 0), menuItem->rect.center().y());
1882 painter->restore();
1883 break;
1885 bool selected = menuItem->state & State_Selected && menuItem->state & State_Enabled;
1886 if (selected) {
1887 QRect r = option->rect;
1888 painter->fillRect(r, highlight);
1889 painter->setPen(QPen(highlightOutline, 0));
1890 painter->drawRect(QRectF(r).adjusted(0.5, 0.5, -0.5, -0.5));
1892 bool checkable = menuItem->checkType != QStyleOptionMenuItem::NotCheckable;
1893 bool checked = menuItem->checked;
1894 bool sunken = menuItem->state & State_Sunken;
1895 bool enabled = menuItem->state & State_Enabled;
1897 bool ignoreCheckMark = false;
1898 int checkcol = qMax(menuItem->maxIconWidth, 20);
1900 if (qobject_cast<const QComboBox*>(widget))
1901 ignoreCheckMark = true; //ignore the checkmarks provided by the QComboMenuDelegate
1903 if (!ignoreCheckMark) {
1904 // Check
1905 QRect checkRect(option->rect.left() + 7, option->rect.center().y() - 6, 14, 14);
1906 checkRect = visualRect(menuItem->direction, menuItem->rect, checkRect);
1907 if (checkable) {
1908 if (menuItem->checkType & QStyleOptionMenuItem::Exclusive) {
1909 // Radio button
1910 if (checked || sunken) {
1911 painter->setRenderHint(QPainter::Antialiasing);
1912 painter->setPen(Qt::NoPen);
1914 QPalette::ColorRole textRole = !enabled ? QPalette::Text:
1915 selected ? QPalette::HighlightedText : QPalette::ButtonText;
1916 painter->setBrush(option->palette.brush( option->palette.currentColorGroup(), textRole));
1917 painter->drawEllipse(checkRect.adjusted(4, 4, -4, -4));
1919 } else {
1920 // Check box
1921 if (menuItem->icon.isNull()) {
1922 QStyleOptionButton box;
1923 box.QStyleOption::operator=(*option);
1924 box.rect = checkRect;
1925 if (checked)
1926 box.state |= State_On;
1927 proxy()->drawPrimitive(PE_IndicatorCheckBox, &box, painter, widget);
1928 painter->setPen(QPen(highlight, 0));
1929 painter->drawRect(checkRect);
1933 } else { //ignore checkmark
1934 if (menuItem->icon.isNull())
1935 checkcol = 0;
1936 else
1937 checkcol = menuItem->maxIconWidth;
1940 // Text and icon, ripped from windows style
1941 bool dis = !(menuItem->state & State_Enabled);
1942 bool act = menuItem->state & State_Selected;
1943 const QStyleOption *opt = option;
1944 const QStyleOptionMenuItem *menuitem = menuItem;
1946 QPainter *p = painter;
1947 QRect vCheckRect = visualRect(opt->direction, menuitem->rect,
1948 QRect(menuitem->rect.x() + 4, menuitem->rect.y(),
1949 checkcol, menuitem->rect.height()));
1950 if (!menuItem->icon.isNull()) {
1951 QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
1952 if (act && !dis)
1953 mode = QIcon::Active;
1954 QPixmap pixmap;
1956 int smallIconSize = proxy()->pixelMetric(PM_SmallIconSize, option, widget);
1957 QSize iconSize(smallIconSize, smallIconSize);
1958 if (const QComboBox *combo = qobject_cast<const QComboBox*>(widget))
1959 iconSize = combo->iconSize();
1960 if (checked)
1961 pixmap = menuItem->icon.pixmap(iconSize, mode, QIcon::On);
1962 else
1963 pixmap = menuItem->icon.pixmap(iconSize, mode);
1965 #if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
1966 const int pixw = pixmap.width() / pixmap.devicePixelRatioF();
1967 const int pixh = pixmap.height() / pixmap.devicePixelRatioF();
1968 #else
1969 const int pixw = pixmap.width();
1970 const int pixh = pixmap.height();
1971 #endif
1973 QRect pmr(0, 0, pixw, pixh);
1974 pmr.moveCenter(vCheckRect.center());
1975 painter->setPen(menuItem->palette.text().color());
1976 if (checkable && checked) {
1977 QStyleOption opt = *option;
1978 if (act) {
1979 QColor activeColor = mergedColors(qt_palette_bg_color(option->palette),
1980 option->palette.highlight().color());
1981 opt.palette.setBrush(QPalette::Button, activeColor);
1983 opt.state |= State_Sunken;
1984 opt.rect = vCheckRect;
1985 proxy()->drawPrimitive(PE_PanelButtonCommand, &opt, painter, widget);
1987 painter->drawPixmap(pmr.topLeft(), pixmap);
1989 if (selected) {
1990 painter->setPen(menuItem->palette.highlightedText().color());
1991 } else {
1992 painter->setPen(menuItem->palette.text().color());
1994 int x, y, w, h;
1995 menuitem->rect.getRect(&x, &y, &w, &h);
1996 int tab = menuitem->tabWidth;
1997 QColor discol;
1998 if (dis) {
1999 discol = menuitem->palette.text().color();
2000 p->setPen(discol);
2002 int xm = windowsItemFrame + checkcol + windowsItemHMargin + 2;
2003 int xpos = menuitem->rect.x() + xm;
2005 QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
2006 QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
2007 QString s = menuitem->text;
2008 if (!s.isEmpty()) { // draw text
2009 p->save();
2010 int t = s.indexOf(QLatin1Char('\t'));
2011 int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
2012 if (!styleHint(SH_UnderlineShortcut, menuitem, widget))
2013 text_flags |= Qt::TextHideMnemonic;
2014 text_flags |= Qt::AlignLeft;
2015 if (t >= 0) {
2016 QRect vShortcutRect = visualRect(opt->direction, menuitem->rect,
2017 QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom())));
2018 if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, option, widget)) {
2019 p->setPen(menuitem->palette.light().color());
2020 p->drawText(vShortcutRect.adjusted(1, 1, 1, 1), text_flags, s.mid(t + 1));
2021 p->setPen(discol);
2023 p->drawText(vShortcutRect, text_flags, s.mid(t + 1));
2024 s = s.left(t);
2026 QFont font = menuitem->font;
2027 // font may not have any "hard" flags set. We override
2028 // the point size so that when it is resolved against the device, this font will win.
2029 // This is mainly to handle cases where someone sets the font on the window
2030 // and then the combo inherits it and passes it onward. At that point the resolve mask
2031 // is very, very weak. This makes it stonger.
2032 font.setPointSizeF(QFontInfo(menuItem->font).pointSizeF());
2034 if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
2035 font.setBold(true);
2037 p->setFont(font);
2038 if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, option, widget)) {
2039 p->setPen(menuitem->palette.light().color());
2040 p->drawText(vTextRect.adjusted(1, 1, 1, 1), text_flags, s.left(t));
2041 p->setPen(discol);
2043 p->drawText(vTextRect, text_flags, s.left(t));
2044 p->restore();
2047 // Arrow
2048 if (menuItem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow
2049 int dim = (menuItem->rect.height() - 4) / 2;
2050 PrimitiveElement arrow;
2051 arrow = option->direction == Qt::RightToLeft ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
2052 int xpos = menuItem->rect.left() + menuItem->rect.width() - 3 - dim;
2053 QRect vSubMenuRect = visualRect(option->direction, menuItem->rect,
2054 QRect(xpos, menuItem->rect.top() + menuItem->rect.height() / 2 - dim / 2, dim, dim));
2055 QStyleOptionMenuItem newMI = *menuItem;
2056 newMI.rect = vSubMenuRect;
2057 newMI.state = !enabled ? State_None : State_Enabled;
2058 if (selected)
2059 newMI.palette.setColor(QPalette::Foreground,
2060 newMI.palette.highlightedText().color());
2061 proxy()->drawPrimitive(arrow, &newMI, painter, widget);
2064 painter->restore();
2065 break;
2066 case CE_MenuHMargin:
2067 case CE_MenuVMargin:
2068 break;
2069 case CE_MenuEmptyArea:
2070 break;
2071 case CE_PushButton:
2072 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
2073 proxy()->drawControl(CE_PushButtonBevel, btn, painter, widget);
2074 QStyleOptionButton subopt = *btn;
2075 subopt.rect = subElementRect(SE_PushButtonContents, btn, widget);
2076 proxy()->drawControl(CE_PushButtonLabel, &subopt, painter, widget);
2078 break;
2079 case CE_PushButtonLabel:
2080 if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {
2081 QRect ir = button->rect;
2082 uint tf = Qt::AlignVCenter;
2083 if (styleHint(SH_UnderlineShortcut, button, widget))
2084 tf |= Qt::TextShowMnemonic;
2085 else
2086 tf |= Qt::TextHideMnemonic;
2088 if (!button->icon.isNull()) {
2089 //Center both icon and text
2090 QPoint point;
2092 QIcon::Mode mode = button->state & State_Enabled ? QIcon::Normal
2093 : QIcon::Disabled;
2094 if (mode == QIcon::Normal && button->state & State_HasFocus)
2095 mode = QIcon::Active;
2096 QIcon::State state = QIcon::Off;
2097 if (button->state & State_On)
2098 state = QIcon::On;
2100 QPixmap pixmap = button->icon.pixmap(button->iconSize, mode, state);
2101 #if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
2102 int w = pixmap.width() / pixmap.devicePixelRatio();
2103 int h = pixmap.height() / pixmap.devicePixelRatio();
2104 #else
2105 int w = pixmap.width();
2106 int h = pixmap.height();
2107 #endif
2109 if (!button->text.isEmpty())
2110 w += button->fontMetrics.boundingRect(option->rect, tf, button->text).width() + 2;
2112 point = QPoint(ir.x() + ir.width() / 2 - w / 2,
2113 ir.y() + ir.height() / 2 - h / 2);
2115 #if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
2116 w = pixmap.width() / pixmap.devicePixelRatio();
2117 #else
2118 w = pixmap.width();
2119 #endif
2121 if (button->direction == Qt::RightToLeft)
2122 point.rx() += w;
2124 painter->drawPixmap(visualPos(button->direction, button->rect, point), pixmap);
2126 if (button->direction == Qt::RightToLeft)
2127 ir.translate(-point.x() - 2, 0);
2128 else
2129 ir.translate(point.x() + w, 0);
2131 // left-align text if there is
2132 if (!button->text.isEmpty())
2133 tf |= Qt::AlignLeft;
2135 } else {
2136 tf |= Qt::AlignHCenter;
2139 if (button->features & QStyleOptionButton::HasMenu)
2140 ir = ir.adjusted(0, 0, -proxy()->pixelMetric(PM_MenuButtonIndicator, button, widget), 0);
2141 proxy()->drawItemText(painter, ir, tf, button->palette, (button->state & State_Enabled),
2142 button->text, QPalette::ButtonText);
2144 break;
2145 case CE_MenuBarEmptyArea:
2146 painter->save();
2148 painter->fillRect(rect, option->palette.window());
2149 if (widget && qobject_cast<const QMainWindow *>(widget->parentWidget())) {
2150 QColor shadow = mergedColors(qt_palette_bg_color(option->palette).darker(120),
2151 outline.lighter(140), 60);
2152 painter->setPen(QPen(shadow));
2153 painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
2156 painter->restore();
2157 break;
2158 case CE_TabBarTabShape:
2159 painter->save();
2160 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) {
2162 bool rtlHorTabs = (tab->direction == Qt::RightToLeft
2163 && (tab->shape == QTabBar::RoundedNorth
2164 || tab->shape == QTabBar::RoundedSouth));
2165 bool selected = tab->state & State_Selected;
2166 bool lastTab = ((!rtlHorTabs && tab->position == QStyleOptionTab::End)
2167 || (rtlHorTabs
2168 && tab->position == QStyleOptionTab::Beginning));
2169 bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab;
2170 int tabOverlap = pixelMetric(PM_TabBarTabOverlap, option, widget);
2171 rect = option->rect.adjusted(0, 0, (onlyOne || lastTab) ? 0 : tabOverlap, 0);
2173 #if 0
2174 QRect r2(rect);
2175 int x1 = r2.left();
2176 int x2 = r2.right();
2177 int y1 = r2.top();
2178 int y2 = r2.bottom();
2179 #endif
2181 painter->setPen(d->innerContrastLine());
2183 QTransform rotMatrix;
2184 bool flip = false;
2185 painter->setPen(shadow);
2187 switch (tab->shape) {
2188 case QTabBar::RoundedNorth:
2189 break;
2190 case QTabBar::RoundedSouth:
2191 rotMatrix.rotate(180);
2192 rotMatrix.translate(0, -rect.height() + 1);
2193 rotMatrix.scale(-1, 1);
2194 painter->setTransform(rotMatrix, true);
2195 break;
2196 case QTabBar::RoundedWest:
2197 rotMatrix.rotate(180 + 90);
2198 rotMatrix.scale(-1, 1);
2199 flip = true;
2200 painter->setTransform(rotMatrix, true);
2201 break;
2202 case QTabBar::RoundedEast:
2203 rotMatrix.rotate(90);
2204 rotMatrix.translate(0, - rect.width() + 1);
2205 flip = true;
2206 painter->setTransform(rotMatrix, true);
2207 break;
2208 default:
2209 painter->restore();
2210 QCommonStyle::drawControl(element, tab, painter, widget);
2211 return;
2214 if (flip) {
2215 QRect tmp = rect;
2216 rect = QRect(tmp.y(), tmp.x(), tmp.height(), tmp.width());
2217 #if 0
2218 int temp = x1;
2219 x1 = y1;
2220 y1 = temp;
2221 temp = x2;
2222 x2 = y2;
2223 y2 = temp;
2224 #endif
2227 painter->setRenderHint(QPainter::Antialiasing, true);
2228 painter->translate(0.5, 0.5);
2230 QColor tabFrameColor = d->tabFrameColor(option->palette);
2232 QLinearGradient fillGradient(rect.topLeft(), rect.bottomLeft());
2233 QLinearGradient outlineGradient(rect.topLeft(), rect.bottomLeft());
2234 QPen outlinePen = outline.lighter(110);
2235 if (selected) {
2236 fillGradient.setColorAt(0, tabFrameColor.lighter(104));
2237 // QColor highlight = option->palette.highlight().color();
2238 // if (option->state & State_HasFocus && option->state & State_KeyboardFocusChange) {
2239 // fillGradient.setColorAt(0, highlight.lighter(130));
2240 // outlineGradient.setColorAt(0, highlight.darker(130));
2241 // fillGradient.setColorAt(0.14, highlight);
2242 // outlineGradient.setColorAt(0.14, highlight.darker(130));
2243 // fillGradient.setColorAt(0.1401, tabFrameColor);
2244 // outlineGradient.setColorAt(0.1401, highlight.darker(130));
2245 // }
2246 fillGradient.setColorAt(1, tabFrameColor);
2247 outlineGradient.setColorAt(1, outline);
2248 outlinePen = QPen(outlineGradient, 1);
2249 } else {
2250 fillGradient.setColorAt(0, tabFrameColor.darker(108));
2251 fillGradient.setColorAt(0.85, tabFrameColor.darker(108));
2252 fillGradient.setColorAt(1, tabFrameColor.darker(116));
2255 QRect drawRect = rect.adjusted(0, selected ? 0 : 2, 0, 3);
2256 painter->setPen(outlinePen);
2257 painter->save();
2258 painter->setClipRect(rect.adjusted(-1, -1, 1, selected ? -2 : -3));
2259 painter->setBrush(Qt::NoBrush);
2260 painter->drawRoundedRect(drawRect.adjusted(0, 0, -1, -1), 2.5, 2.5);
2262 painter->setBrush(fillGradient);
2263 painter->setPen(QPen(QBrush(fillGradient), 1));
2264 drawRect.adjust(1, 1, -2, -1);
2265 painter->drawRoundedRect(drawRect, 1.8, 1.8);
2267 painter->setBrush(Qt::NoBrush);
2268 painter->setPen(d->innerContrastLine());
2269 painter->drawRoundedRect(drawRect, 1.8, 1.8);
2271 painter->restore();
2273 if (selected) {
2274 painter->fillRect(rect.left() + 1, rect.bottom() - 1, rect.width() - 2, rect.bottom() - 1, tabFrameColor);
2275 painter->fillRect(QRect(rect.bottomRight() + QPoint(-2, -1), QSize(1, 1)), d->innerContrastLine());
2276 painter->fillRect(QRect(rect.bottomLeft() + QPoint(0, -1), QSize(1, 1)), d->innerContrastLine());
2277 painter->fillRect(QRect(rect.bottomRight() + QPoint(-1, -1), QSize(1, 1)), d->innerContrastLine());
2280 painter->restore();
2281 break;
2282 default:
2283 QCommonStyle::drawControl(element,option,painter,widget);
2284 break;
2289 \reimp
2291 QPalette CarlaStyle::standardPalette () const
2293 QPalette palette = QCommonStyle::standardPalette();
2294 palette.setBrush(QPalette::Active, QPalette::Highlight, QColor(48, 140, 198));
2295 palette.setBrush(QPalette::Inactive, QPalette::Highlight, QColor(145, 141, 126));
2296 palette.setBrush(QPalette::Disabled, QPalette::Highlight, QColor(145, 141, 126));
2298 QColor backGround(239, 235, 231);
2300 QColor light = backGround.lighter(150);
2301 QColor base = Qt::white;
2302 QColor dark = QColor(170, 156, 143).darker(110);
2303 dark = backGround.darker(150);
2304 QColor darkDisabled = QColor(209, 200, 191).darker(110);
2306 //### Find the correct disabled text color
2307 palette.setBrush(QPalette::Disabled, QPalette::Text, QColor(190, 190, 190));
2309 palette.setBrush(QPalette::Window, backGround);
2310 palette.setBrush(QPalette::Mid, backGround.darker(130));
2311 palette.setBrush(QPalette::Light, light);
2313 palette.setBrush(QPalette::Active, QPalette::Base, base);
2314 palette.setBrush(QPalette::Inactive, QPalette::Base, base);
2315 palette.setBrush(QPalette::Disabled, QPalette::Base, backGround);
2317 palette.setBrush(QPalette::Midlight, palette.mid().color().lighter(110));
2319 palette.setBrush(QPalette::All, QPalette::Dark, dark);
2320 palette.setBrush(QPalette::Disabled, QPalette::Dark, darkDisabled);
2322 QColor button = backGround;
2324 palette.setBrush(QPalette::Button, button);
2326 QColor shadow = dark.darker(135);
2327 palette.setBrush(QPalette::Shadow, shadow);
2328 palette.setBrush(QPalette::Disabled, QPalette::Shadow, shadow.lighter(150));
2329 palette.setBrush(QPalette::HighlightedText, QColor(QRgb(0xffffffff)));
2331 return palette;
2335 \reimp
2337 void CarlaStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
2338 QPainter *painter, const QWidget *widget) const
2340 QColor buttonColor = d->buttonColor(option->palette);
2341 QColor gradientStartColor = buttonColor.lighter(118);
2342 QColor gradientStopColor = buttonColor;
2343 QColor outline = d->outline(option->palette);
2345 QColor alphaCornerColor;
2346 if (widget) {
2347 // ### backgroundrole/foregroundrole should be part of the style option
2348 alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), outline);
2349 } else {
2350 alphaCornerColor = mergedColors(qt_palette_bg_color(option->palette), outline);
2353 switch (control) {
2354 case CC_GroupBox:
2355 painter->save();
2356 if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
2357 // Draw frame
2358 QRect textRect = proxy()->subControlRect(CC_GroupBox, option, SC_GroupBoxLabel, widget);
2359 QRect checkBoxRect = proxy()->subControlRect(CC_GroupBox, option, SC_GroupBoxCheckBox, widget);
2361 if (groupBox->subControls & QStyle::SC_GroupBoxFrame) {
2362 QStyleOptionFrameV3 frame;
2363 frame.QStyleOption::operator=(*groupBox);
2364 frame.features = groupBox->features;
2365 frame.lineWidth = groupBox->lineWidth;
2366 frame.midLineWidth = groupBox->midLineWidth;
2367 frame.rect = proxy()->subControlRect(CC_GroupBox, option, SC_GroupBoxFrame, widget);
2368 proxy()->drawPrimitive(PE_FrameGroupBox, &frame, painter, widget);
2371 // Draw title
2372 if ((groupBox->subControls & QStyle::SC_GroupBoxLabel) && !groupBox->text.isEmpty()) {
2373 // groupBox->textColor gets the incorrect palette here
2374 painter->setPen(QPen(option->palette.windowText(), 1));
2375 int alignment = int(groupBox->textAlignment);
2376 if (!proxy()->styleHint(QStyle::SH_UnderlineShortcut, option, widget))
2377 alignment |= Qt::TextHideMnemonic;
2379 proxy()->drawItemText(painter, textRect, Qt::TextShowMnemonic | Qt::AlignLeft | alignment,
2380 groupBox->palette, groupBox->state & State_Enabled, groupBox->text, QPalette::NoRole);
2382 if (groupBox->state & State_HasFocus) {
2383 QStyleOptionFocusRect fropt;
2384 fropt.QStyleOption::operator=(*groupBox);
2385 fropt.rect = textRect.adjusted(-2, -1, 2, 1);
2386 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
2390 // Draw checkbox
2391 if (groupBox->subControls & SC_GroupBoxCheckBox) {
2392 QStyleOptionButton box;
2393 box.QStyleOption::operator=(*groupBox);
2394 box.rect = checkBoxRect;
2395 proxy()->drawPrimitive(PE_IndicatorCheckBox, &box, painter, widget);
2398 painter->restore();
2399 break;
2400 case CC_SpinBox:
2401 if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
2402 QPixmap cache;
2403 QString pixmapName = uniqueName(QLatin1String("spinbox"), spinBox, spinBox->rect.size());
2404 if (!QPixmapCache::find(pixmapName, PIXMAPCACHE_VAR_PREFIX cache)) {
2406 cache = styleCachePixmap(spinBox->rect.size());
2407 cache.fill(Qt::transparent);
2409 QRect pixmapRect(0, 0, spinBox->rect.width(), spinBox->rect.height());
2410 QRect rect = pixmapRect;
2411 QRect r = rect;
2412 QPainter cachePainter(&cache);
2413 QColor arrowColor = qt_palette_fg_color(spinBox->palette);
2414 arrowColor.setAlpha(220);
2416 const bool isEnabled = (spinBox->state & State_Enabled);
2417 const bool hover = isEnabled && (spinBox->state & State_MouseOver);
2418 const bool sunken = (spinBox->state & State_Sunken);
2419 const bool upIsActive = (spinBox->activeSubControls == SC_SpinBoxUp);
2420 const bool downIsActive = (spinBox->activeSubControls == SC_SpinBoxDown);
2421 const bool hasFocus = (option->state & State_HasFocus);
2423 QStyleOptionSpinBox spinBoxCopy = *spinBox;
2424 spinBoxCopy.rect = pixmapRect;
2425 QRect upRect = proxy()->subControlRect(CC_SpinBox, &spinBoxCopy, SC_SpinBoxUp, widget);
2426 QRect downRect = proxy()->subControlRect(CC_SpinBox, &spinBoxCopy, SC_SpinBoxDown, widget);
2428 const bool oddHeight = (1+upRect.bottom() != downRect.top());
2430 if (spinBox->frame) {
2431 // Button group outer bounds
2432 const int bty = upRect.top();
2433 const int bby = 1+downRect.bottom() - 1;
2434 const int brx = 1+upRect.right() - 1;
2436 cachePainter.save();
2437 cachePainter.setRenderHint(QPainter::Antialiasing, true);
2438 cachePainter.translate(0.5, 0.5);
2440 // Fill background
2441 const QBrush & brush = option->palette.base();
2442 cachePainter.setPen(brush.color());
2443 cachePainter.setBrush(brush);
2444 cachePainter.drawRoundedRect(r.adjusted(1, 1, -2, -2), 1.8, 1.8);
2446 // Draw inner shadow
2447 cachePainter.setPen(d->topShadow());
2448 cachePainter.drawLine(QPoint(r.left() + 2, r.top() + 1), QPoint(1+r.right() - 2, r.top() + 1));
2450 // Draw button gradient
2451 QColor buttonColor = d->buttonColor(option->palette);
2452 QRectF updownRect(upRect.topLeft(), downRect.bottomRight() + QPoint(1,1));
2453 updownRect.adjust(-0.5, -0.5, 0.5-1, 0.5-1);
2454 QLinearGradient gradient = qt_fusion_gradient(updownRect.toAlignedRect(), (isEnabled && option->state & State_MouseOver ) ? buttonColor : buttonColor.darker(104));
2456 // Draw button gradient
2457 cachePainter.setPen(QPen(gradient, 1));
2458 cachePainter.setBrush(gradient);
2460 cachePainter.save();
2461 cachePainter.setClipRect(updownRect);
2462 cachePainter.drawRoundedRect(QRect(0, bty, brx, bby-bty), 1.8, 1.8);
2463 cachePainter.setPen(QPen(d->innerContrastLine()));
2464 cachePainter.setBrush(Qt::NoBrush);
2465 cachePainter.drawRoundedRect(QRect(0, bty, brx, bby-bty), 1.8, 1.8);
2466 cachePainter.drawLine(upRect.left(), bty + 1, upRect.left(), bby - 1);
2467 if (hover) {
2468 const int y = oddHeight ? (downRect.top() - 1) : (upIsActive ? (1+upRect.bottom() - 1) : downRect.top());
2469 cachePainter.setOpacity(0.4);
2470 cachePainter.drawLine(downRect.left() + 1, y, brx - 1, y);
2471 cachePainter.setOpacity(1.0);
2473 cachePainter.restore();
2474 cachePainter.setPen(Qt::NoPen);
2476 // Buttons mouse over background
2477 if ((spinBox->stepEnabled & QAbstractSpinBox::StepUpEnabled) && upIsActive) {
2478 QPointF clipTLeft(0, upRect.top());
2479 QPointF clipBRight(1+downRect.right() - 1, 1+downRect.bottom() - 1);
2480 QRectF clipRect(clipTLeft, clipBRight);
2482 cachePainter.save();
2484 clipRect.adjust(-0.5,-0.5, 0.5, 0.5);
2485 QPainterPath clipPath;
2486 clipPath.addRoundedRect(clipRect, 2.0, 2.0);
2487 cachePainter.setClipPath(clipPath);
2489 const int cy_fix = oddHeight ? 0 : -1;
2490 if (sunken)
2491 cachePainter.fillRect(QRectF(upRect).adjusted(-0.5, -0.5, 0.5-1, 0.5+cy_fix), gradientStopColor.darker(110));
2492 else if (hover)
2493 cachePainter.fillRect(QRectF(upRect).adjusted(-0.5, -0.5, 0.5-1, 0.5+cy_fix), d->innerContrastLine());
2495 cachePainter.restore();
2498 if ((spinBox->stepEnabled & QAbstractSpinBox::StepDownEnabled) && downIsActive) {
2499 QPointF clipTLeft(0, upRect.top());
2500 QPointF clipBRight(1+downRect.right() - 1, 1+downRect.bottom() - 1);
2501 QRectF clipRect(clipTLeft, clipBRight);
2503 cachePainter.save();
2505 clipRect.adjust(-0.5,-0.5, 0.5, 0.5);
2506 QPainterPath clipPath;
2507 clipPath.addRoundedRect(clipRect, 2.0, 2.0);
2508 cachePainter.setClipPath(clipPath);
2510 const int cy_fix = oddHeight ? 0 : 1;
2511 if (sunken)
2512 cachePainter.fillRect(QRectF(downRect).adjusted(-0.5, -0.5-1+cy_fix, 0.5-1, 0.5-1-cy_fix), gradientStopColor.darker(110));
2513 else if (hover)
2514 cachePainter.fillRect(QRectF(downRect).adjusted(-0.5, -0.5-1+cy_fix, 0.5-1, 0.5-1-cy_fix), d->innerContrastLine());
2516 cachePainter.restore();
2519 // Common highlight border
2520 QColor highlightOutline = d->highlightedOutline(option->palette);
2521 cachePainter.setPen(hasFocus ? highlightOutline : highlightOutline.darker(160));
2522 cachePainter.setBrush(Qt::NoBrush);
2523 cachePainter.drawRoundedRect(r.adjusted(0, 0, -1, -1), 2.5, 2.5);
2524 if (hasFocus) {
2525 QColor softHighlight = option->palette.highlight().color();
2526 softHighlight.setAlpha(40);
2527 cachePainter.setPen(softHighlight);
2528 cachePainter.drawRoundedRect(r.adjusted(1, 1, -2, -2), 1.8, 1.8);
2530 cachePainter.restore();
2533 // outline the up/down buttons
2534 cachePainter.setPen(outline);
2535 if (spinBox->direction == Qt::RightToLeft) {
2536 cachePainter.drawLine(1+upRect.right() + 1, upRect.top(), 1+upRect.right() + 1, 1+downRect.bottom() - 1);
2537 } else {
2538 cachePainter.drawLine(upRect.left() - 1, upRect.top(), upRect.left() - 1, 1+downRect.bottom() - 1);
2541 if (upIsActive && sunken) {
2542 cachePainter.setPen(gradientStopColor.darker(130));
2543 const int left = upRect.left();
2544 const int right = 1+upRect.right() - 1;
2545 const int top = upRect.top();
2546 const int bottom = oddHeight ? (1+upRect.bottom()) : (1+upRect.bottom() - 1);
2547 const QPoint points[] = {QPoint(right,bottom), QPoint(left,bottom), QPoint(left,top), QPoint(right-1,top)};
2548 cachePainter.drawPolyline(points, 4);
2551 if (downIsActive && sunken) {
2552 cachePainter.setPen(gradientStopColor.darker(130));
2553 const int left = downRect.left();
2554 const int right = 1+downRect.right() - 1;
2555 const int top = oddHeight ? (downRect.top() - 1) : downRect.top();
2556 const int bottom = 1+downRect.bottom() - 1;
2557 const QPoint points[] = {QPoint(left,bottom), QPoint(left,top), QPoint(right,top)};
2558 cachePainter.drawPolyline(points, 3);
2561 QColor disabledColor = mergedColors(arrowColor, option->palette.button().color());
2562 if (spinBox->buttonSymbols == QAbstractSpinBox::PlusMinus) {
2563 // plus/minus
2564 int centerX, centerY;
2566 centerX = upRect.center().x();
2567 centerY = upRect.center().y();
2568 cachePainter.setPen((spinBox->stepEnabled & QAbstractSpinBox::StepUpEnabled) ? arrowColor : disabledColor);
2569 cachePainter.drawLine(centerX - 1, centerY, centerX + 3, centerY);
2570 cachePainter.drawLine(centerX + 1, centerY - 2, centerX + 1, centerY + 2);
2572 centerX = downRect.center().x();
2573 centerY = downRect.center().y();
2574 cachePainter.setPen((spinBox->stepEnabled & QAbstractSpinBox::StepDownEnabled) ? arrowColor : disabledColor);
2575 cachePainter.drawLine(centerX - 1, centerY, centerX + 3, centerY);
2577 } else if (spinBox->buttonSymbols == QAbstractSpinBox::UpDownArrows){
2578 // arrows
2579 painter->setRenderHint(QPainter::SmoothPixmapTransform);
2581 QPixmap upArrow = colorizedImage(QLatin1String(":/bitmaps/style/arrow.png"),
2582 (spinBox->stepEnabled & QAbstractSpinBox::StepUpEnabled) ? arrowColor : disabledColor);
2584 QPixmap downArrow = colorizedImage(QLatin1String(":/bitmaps/style/arrow.png"),
2585 (spinBox->stepEnabled & QAbstractSpinBox::StepDownEnabled) ? arrowColor : disabledColor, 180);
2587 int y1, y2;
2588 const int imgW = (upArrow.width() + downArrow.width()) / 2;
2589 const int imgH = (upArrow.height() + downArrow.height()) / 2;
2590 const float f = 1.0 / ceil(imgW / upRect.width() * 2);
2591 const int w = imgW * f;
2592 const int h = imgH * f;
2594 const int x = upRect.center().x() - w / 2;
2595 y1 = upRect.center().y();
2596 y2 = downRect.center().y();
2597 const int dy1 = 1+upRect.bottom() - y1;
2598 const int dy2 = y2 - downRect.top();
2599 const int dy = dy1 < dy2 ? dy1 : dy2;
2600 y1 = (1+upRect.bottom() - dy - 1) - ceil(h / 4.0);
2601 y2 = (downRect.top() + dy + 1) - floor(h / 4.0 * 3);
2603 cachePainter.drawPixmap(QRectF(x, y1, w, h), upArrow, upArrow.rect());
2604 cachePainter.drawPixmap(QRectF(x, y2, w, h), downArrow, downArrow.rect());
2607 cachePainter.end();
2608 QPixmapCache::insert(pixmapName, cache);
2610 painter->drawPixmap(spinBox->rect.topLeft(), cache);
2612 break;
2613 case CC_TitleBar:
2614 painter->save();
2615 if (const QStyleOptionTitleBar *titleBar = qstyleoption_cast<const QStyleOptionTitleBar *>(option)) {
2616 const int buttonMargin = 5;
2617 bool active = (titleBar->titleBarState & State_Active);
2618 QRect fullRect = titleBar->rect;
2619 QPalette palette = option->palette;
2620 QColor highlight = option->palette.highlight().color();
2622 QColor titleBarFrameBorder(active ? highlight.darker(180): outline.darker(110));
2623 QColor titleBarHighlight(active ? highlight.lighter(120): qt_palette_bg_color(palette).lighter(120));
2624 QColor textColor(active ? 0xffffff : 0xff000000);
2625 QColor textAlphaColor(active ? 0xffffff : 0xff000000 );
2628 // Fill title bar gradient
2629 QColor titlebarColor = QColor(active ? highlight: qt_palette_bg_color(palette));
2630 QLinearGradient gradient(option->rect.center().x(), option->rect.top(),
2631 option->rect.center().x(), option->rect.bottom());
2633 gradient.setColorAt(0, titlebarColor.lighter(114));
2634 gradient.setColorAt(0.5, titlebarColor.lighter(102));
2635 gradient.setColorAt(0.51, titlebarColor.darker(104));
2636 gradient.setColorAt(1, titlebarColor);
2637 painter->fillRect(option->rect.adjusted(1, 1, -1, 0), gradient);
2639 // Frame and rounded corners
2640 painter->setPen(titleBarFrameBorder);
2642 // top outline
2643 painter->drawLine(fullRect.left() + 5, fullRect.top(), fullRect.right() - 5, fullRect.top());
2644 painter->drawLine(fullRect.left(), fullRect.top() + 4, fullRect.left(), fullRect.bottom());
2645 const QPoint points[5] = {
2646 QPoint(fullRect.left() + 4, fullRect.top() + 1),
2647 QPoint(fullRect.left() + 3, fullRect.top() + 1),
2648 QPoint(fullRect.left() + 2, fullRect.top() + 2),
2649 QPoint(fullRect.left() + 1, fullRect.top() + 3),
2650 QPoint(fullRect.left() + 1, fullRect.top() + 4)
2652 painter->drawPoints(points, 5);
2654 painter->drawLine(fullRect.right(), fullRect.top() + 4, fullRect.right(), fullRect.bottom());
2655 const QPoint points2[5] = {
2656 QPoint(fullRect.right() - 3, fullRect.top() + 1),
2657 QPoint(fullRect.right() - 4, fullRect.top() + 1),
2658 QPoint(fullRect.right() - 2, fullRect.top() + 2),
2659 QPoint(fullRect.right() - 1, fullRect.top() + 3),
2660 QPoint(fullRect.right() - 1, fullRect.top() + 4)
2662 painter->drawPoints(points2, 5);
2664 // draw bottomline
2665 painter->drawLine(fullRect.right(), fullRect.bottom(), fullRect.left(), fullRect.bottom());
2667 // top highlight
2668 painter->setPen(titleBarHighlight);
2669 painter->drawLine(fullRect.left() + 6, fullRect.top() + 1, fullRect.right() - 6, fullRect.top() + 1);
2671 // draw title
2672 QRect textRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarLabel, widget);
2673 painter->setPen(active? (titleBar->palette.text().color().lighter(120)) :
2674 titleBar->palette.text().color() );
2675 // Note workspace also does elliding but it does not use the correct font
2676 QString title = painter->fontMetrics().elidedText(titleBar->text, Qt::ElideRight, textRect.width() - 14);
2677 painter->drawText(textRect.adjusted(1, 1, 1, 1), title, QTextOption(Qt::AlignHCenter | Qt::AlignVCenter));
2678 painter->setPen(Qt::white);
2679 if (active)
2680 painter->drawText(textRect, title, QTextOption(Qt::AlignHCenter | Qt::AlignVCenter));
2681 // min button
2682 if ((titleBar->subControls & SC_TitleBarMinButton) && (titleBar->titleBarFlags & Qt::WindowMinimizeButtonHint) &&
2683 !(titleBar->titleBarState& Qt::WindowMinimized)) {
2684 QRect minButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarMinButton, widget);
2685 if (minButtonRect.isValid()) {
2686 bool hover = (titleBar->activeSubControls & SC_TitleBarMinButton) && (titleBar->state & State_MouseOver);
2687 bool sunken = (titleBar->activeSubControls & SC_TitleBarMinButton) && (titleBar->state & State_Sunken);
2688 qt_fusion_draw_mdibutton(painter, titleBar, minButtonRect, hover, sunken);
2689 QRect minButtonIconRect = minButtonRect.adjusted(buttonMargin ,buttonMargin , -buttonMargin, -buttonMargin);
2690 painter->setPen(textColor);
2691 painter->drawLine(minButtonIconRect.center().x() - 2, minButtonIconRect.center().y() + 3,
2692 minButtonIconRect.center().x() + 3, minButtonIconRect.center().y() + 3);
2693 painter->drawLine(minButtonIconRect.center().x() - 2, minButtonIconRect.center().y() + 4,
2694 minButtonIconRect.center().x() + 3, minButtonIconRect.center().y() + 4);
2695 painter->setPen(textAlphaColor);
2696 painter->drawLine(minButtonIconRect.center().x() - 3, minButtonIconRect.center().y() + 3,
2697 minButtonIconRect.center().x() - 3, minButtonIconRect.center().y() + 4);
2698 painter->drawLine(minButtonIconRect.center().x() + 4, minButtonIconRect.center().y() + 3,
2699 minButtonIconRect.center().x() + 4, minButtonIconRect.center().y() + 4);
2702 // max button
2703 if ((titleBar->subControls & SC_TitleBarMaxButton) && (titleBar->titleBarFlags & Qt::WindowMaximizeButtonHint) &&
2704 !(titleBar->titleBarState & Qt::WindowMaximized)) {
2705 QRect maxButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarMaxButton, widget);
2706 if (maxButtonRect.isValid()) {
2707 bool hover = (titleBar->activeSubControls & SC_TitleBarMaxButton) && (titleBar->state & State_MouseOver);
2708 bool sunken = (titleBar->activeSubControls & SC_TitleBarMaxButton) && (titleBar->state & State_Sunken);
2709 qt_fusion_draw_mdibutton(painter, titleBar, maxButtonRect, hover, sunken);
2711 QRect maxButtonIconRect = maxButtonRect.adjusted(buttonMargin, buttonMargin, -buttonMargin, -buttonMargin);
2713 painter->setPen(textColor);
2714 painter->drawRect(maxButtonIconRect.adjusted(0, 0, -1, -1));
2715 painter->drawLine(maxButtonIconRect.left() + 1, maxButtonIconRect.top() + 1,
2716 maxButtonIconRect.right() - 1, maxButtonIconRect.top() + 1);
2717 painter->setPen(textAlphaColor);
2718 const QPoint points[4] = {
2719 maxButtonIconRect.topLeft(),
2720 maxButtonIconRect.topRight(),
2721 maxButtonIconRect.bottomLeft(),
2722 maxButtonIconRect.bottomRight()
2724 painter->drawPoints(points, 4);
2728 // close button
2729 if ((titleBar->subControls & SC_TitleBarCloseButton) && (titleBar->titleBarFlags & Qt::WindowSystemMenuHint)) {
2730 QRect closeButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarCloseButton, widget);
2731 if (closeButtonRect.isValid()) {
2732 bool hover = (titleBar->activeSubControls & SC_TitleBarCloseButton) && (titleBar->state & State_MouseOver);
2733 bool sunken = (titleBar->activeSubControls & SC_TitleBarCloseButton) && (titleBar->state & State_Sunken);
2734 qt_fusion_draw_mdibutton(painter, titleBar, closeButtonRect, hover, sunken);
2735 QRect closeIconRect = closeButtonRect.adjusted(buttonMargin, buttonMargin, -buttonMargin, -buttonMargin);
2736 painter->setPen(textAlphaColor);
2737 const QLine lines[4] = {
2738 QLine(closeIconRect.left() + 1, closeIconRect.top(),
2739 closeIconRect.right(), closeIconRect.bottom() - 1),
2740 QLine(closeIconRect.left(), closeIconRect.top() + 1,
2741 closeIconRect.right() - 1, closeIconRect.bottom()),
2742 QLine(closeIconRect.right() - 1, closeIconRect.top(),
2743 closeIconRect.left(), closeIconRect.bottom() - 1),
2744 QLine(closeIconRect.right(), closeIconRect.top() + 1,
2745 closeIconRect.left() + 1, closeIconRect.bottom())
2747 painter->drawLines(lines, 4);
2748 const QPoint points[4] = {
2749 closeIconRect.topLeft(),
2750 closeIconRect.topRight(),
2751 closeIconRect.bottomLeft(),
2752 closeIconRect.bottomRight()
2754 painter->drawPoints(points, 4);
2756 painter->setPen(textColor);
2757 painter->drawLine(closeIconRect.left() + 1, closeIconRect.top() + 1,
2758 closeIconRect.right() - 1, closeIconRect.bottom() - 1);
2759 painter->drawLine(closeIconRect.left() + 1, closeIconRect.bottom() - 1,
2760 closeIconRect.right() - 1, closeIconRect.top() + 1);
2764 // normalize button
2765 if ((titleBar->subControls & SC_TitleBarNormalButton) &&
2766 (((titleBar->titleBarFlags & Qt::WindowMinimizeButtonHint) &&
2767 (titleBar->titleBarState & Qt::WindowMinimized)) ||
2768 ((titleBar->titleBarFlags & Qt::WindowMaximizeButtonHint) &&
2769 (titleBar->titleBarState & Qt::WindowMaximized)))) {
2770 QRect normalButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarNormalButton, widget);
2771 if (normalButtonRect.isValid()) {
2773 bool hover = (titleBar->activeSubControls & SC_TitleBarNormalButton) && (titleBar->state & State_MouseOver);
2774 bool sunken = (titleBar->activeSubControls & SC_TitleBarNormalButton) && (titleBar->state & State_Sunken);
2775 QRect normalButtonIconRect = normalButtonRect.adjusted(buttonMargin, buttonMargin, -buttonMargin, -buttonMargin);
2776 qt_fusion_draw_mdibutton(painter, titleBar, normalButtonRect, hover, sunken);
2778 QRect frontWindowRect = normalButtonIconRect.adjusted(0, 3, -3, 0);
2779 painter->setPen(textColor);
2780 painter->drawRect(frontWindowRect.adjusted(0, 0, -1, -1));
2781 painter->drawLine(frontWindowRect.left() + 1, frontWindowRect.top() + 1,
2782 frontWindowRect.right() - 1, frontWindowRect.top() + 1);
2783 painter->setPen(textAlphaColor);
2784 const QPoint points[4] = {
2785 frontWindowRect.topLeft(),
2786 frontWindowRect.topRight(),
2787 frontWindowRect.bottomLeft(),
2788 frontWindowRect.bottomRight()
2790 painter->drawPoints(points, 4);
2792 QRect backWindowRect = normalButtonIconRect.adjusted(3, 0, 0, -3);
2793 QRegion clipRegion = backWindowRect;
2794 clipRegion -= frontWindowRect;
2795 painter->save();
2796 painter->setClipRegion(clipRegion);
2797 painter->setPen(textColor);
2798 painter->drawRect(backWindowRect.adjusted(0, 0, -1, -1));
2799 painter->drawLine(backWindowRect.left() + 1, backWindowRect.top() + 1,
2800 backWindowRect.right() - 1, backWindowRect.top() + 1);
2801 painter->setPen(textAlphaColor);
2802 const QPoint points2[4] = {
2803 backWindowRect.topLeft(),
2804 backWindowRect.topRight(),
2805 backWindowRect.bottomLeft(),
2806 backWindowRect.bottomRight()
2808 painter->drawPoints(points2, 4);
2809 painter->restore();
2813 // context help button
2814 if (titleBar->subControls & SC_TitleBarContextHelpButton
2815 && (titleBar->titleBarFlags & Qt::WindowContextHelpButtonHint)) {
2816 QRect contextHelpButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarContextHelpButton, widget);
2817 if (contextHelpButtonRect.isValid()) {
2818 bool hover = (titleBar->activeSubControls & SC_TitleBarContextHelpButton) && (titleBar->state & State_MouseOver);
2819 bool sunken = (titleBar->activeSubControls & SC_TitleBarContextHelpButton) && (titleBar->state & State_Sunken);
2820 qt_fusion_draw_mdibutton(painter, titleBar, contextHelpButtonRect, hover, sunken);
2821 QImage image(qt_titlebar_context_help);
2822 QColor alpha = textColor;
2823 alpha.setAlpha(128);
2824 image.setColor(1, textColor.rgba());
2825 image.setColor(2, alpha.rgba());
2826 painter->setRenderHint(QPainter::SmoothPixmapTransform);
2827 painter->drawImage(contextHelpButtonRect.adjusted(4, 4, -4, -4), image);
2831 // shade button
2832 if (titleBar->subControls & SC_TitleBarShadeButton && (titleBar->titleBarFlags & Qt::WindowShadeButtonHint)) {
2833 QRect shadeButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarShadeButton, widget);
2834 if (shadeButtonRect.isValid()) {
2835 bool hover = (titleBar->activeSubControls & SC_TitleBarShadeButton) && (titleBar->state & State_MouseOver);
2836 bool sunken = (titleBar->activeSubControls & SC_TitleBarShadeButton) && (titleBar->state & State_Sunken);
2837 qt_fusion_draw_mdibutton(painter, titleBar, shadeButtonRect, hover, sunken);
2838 QPixmap arrow = colorizedImage(QLatin1String(":/bitmaps/style/arrow.png"), textColor);
2839 painter->drawPixmap(shadeButtonRect.adjusted(5, 7, -5, -7), arrow);
2843 // unshade button
2844 if (titleBar->subControls & SC_TitleBarUnshadeButton && (titleBar->titleBarFlags & Qt::WindowShadeButtonHint)) {
2845 QRect unshadeButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarUnshadeButton, widget);
2846 if (unshadeButtonRect.isValid()) {
2847 bool hover = (titleBar->activeSubControls & SC_TitleBarUnshadeButton) && (titleBar->state & State_MouseOver);
2848 bool sunken = (titleBar->activeSubControls & SC_TitleBarUnshadeButton) && (titleBar->state & State_Sunken);
2849 qt_fusion_draw_mdibutton(painter, titleBar, unshadeButtonRect, hover, sunken);
2850 QPixmap arrow = colorizedImage(QLatin1String(":/bitmaps/style/arrow.png"), textColor, 180);
2851 painter->drawPixmap(unshadeButtonRect.adjusted(5, 7, -5, -7), arrow);
2855 if ((titleBar->subControls & SC_TitleBarSysMenu) && (titleBar->titleBarFlags & Qt::WindowSystemMenuHint)) {
2856 QRect iconRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarSysMenu, widget);
2857 if (iconRect.isValid()) {
2858 if (!titleBar->icon.isNull()) {
2859 titleBar->icon.paint(painter, iconRect);
2860 } else {
2861 QStyleOption tool(0);
2862 tool.palette = titleBar->palette;
2863 QPixmap pm = standardIcon(SP_TitleBarMenuButton, &tool, widget).pixmap(16, 16);
2864 tool.rect = iconRect;
2865 painter->save();
2866 proxy()->drawItemPixmap(painter, iconRect, Qt::AlignCenter, pm);
2867 painter->restore();
2872 painter->restore();
2873 break;
2874 case CC_ScrollBar:
2875 painter->save();
2876 if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
2877 bool horizontal = scrollBar->orientation == Qt::Horizontal;
2878 bool sunken = scrollBar->state & State_Sunken;
2880 QRect scrollBarSubLine = proxy()->subControlRect(control, scrollBar, SC_ScrollBarSubLine, widget);
2881 QRect scrollBarAddLine = proxy()->subControlRect(control, scrollBar, SC_ScrollBarAddLine, widget);
2882 QRect scrollBarSlider = proxy()->subControlRect(control, scrollBar, SC_ScrollBarSlider, widget);
2883 QRect scrollBarGroove = proxy()->subControlRect(control, scrollBar, SC_ScrollBarGroove, widget);
2885 QRect rect = option->rect;
2886 QColor alphaOutline = outline;
2887 alphaOutline.setAlpha(180);
2889 QColor arrowColor = qt_palette_fg_color(option->palette);
2890 arrowColor.setAlpha(220);
2892 // Paint groove
2893 if (scrollBar->subControls & SC_ScrollBarGroove) {
2894 QLinearGradient gradient(rect.center().x(), rect.top(),
2895 rect.center().x(), rect.bottom());
2896 if (!horizontal)
2897 gradient = QLinearGradient(rect.left(), rect.center().y(),
2898 rect.right(), rect.center().y());
2899 gradient.setColorAt(0, buttonColor.darker(107));
2900 gradient.setColorAt(0.1, buttonColor.darker(105));
2901 gradient.setColorAt(0.9, buttonColor.darker(105));
2902 gradient.setColorAt(1, buttonColor.darker(107));
2904 painter->fillRect(option->rect, gradient);
2905 painter->setPen(Qt::NoPen);
2906 painter->setPen(alphaOutline);
2907 if (horizontal)
2908 painter->drawLine(rect.topLeft(), rect.topRight());
2909 else
2910 painter->drawLine(rect.topLeft(), rect.bottomLeft());
2912 QColor subtleEdge = alphaOutline;
2913 subtleEdge.setAlpha(40);
2914 painter->setPen(subtleEdge);
2915 painter->setBrush(Qt::NoBrush);
2916 painter->save();
2917 painter->setClipRect(scrollBarGroove.adjusted(1, 0, -1, -3));
2918 painter->drawRect(scrollBarGroove.adjusted(1, 0, -1, -1));
2919 painter->restore();
2922 QRect pixmapRect = scrollBarSlider;
2923 QLinearGradient gradient(pixmapRect.center().x(), pixmapRect.top(),
2924 pixmapRect.center().x(), pixmapRect.bottom());
2925 if (!horizontal)
2926 gradient = QLinearGradient(pixmapRect.left(), pixmapRect.center().y(),
2927 pixmapRect.right(), pixmapRect.center().y());
2929 QLinearGradient highlightedGradient = gradient;
2931 QColor midColor2 = mergedColors(gradientStartColor, gradientStopColor, 40);
2932 gradient.setColorAt(0, d->buttonColor(option->palette).lighter(108));
2933 gradient.setColorAt(1, d->buttonColor(option->palette));
2935 highlightedGradient.setColorAt(0, gradientStartColor.darker(102));
2936 highlightedGradient.setColorAt(1, gradientStopColor.lighter(102));
2938 // Paint slider
2939 if (scrollBar->subControls & SC_ScrollBarSlider) {
2940 QRect pixmapRect = scrollBarSlider;
2941 painter->setPen(QPen(alphaOutline, 0));
2942 if (option->state & State_Sunken && scrollBar->activeSubControls & SC_ScrollBarSlider)
2943 painter->setBrush(midColor2);
2944 else if (option->state & State_MouseOver && scrollBar->activeSubControls & SC_ScrollBarSlider)
2945 painter->setBrush(highlightedGradient);
2946 else
2947 painter->setBrush(gradient);
2949 painter->drawRect(pixmapRect.adjusted(horizontal ? -1 : 0, horizontal ? 0 : -1, horizontal ? 0 : 1, horizontal ? 1 : 0));
2951 painter->setPen(d->innerContrastLine());
2952 painter->drawRect(scrollBarSlider.adjusted(horizontal ? 0 : 1, horizontal ? 1 : 0, -1, -1));
2954 // Outer shadow
2955 // painter->setPen(subtleEdge);
2956 // if (horizontal) {
2957 //// painter->drawLine(scrollBarSlider.topLeft() + QPoint(-2, 0), scrollBarSlider.bottomLeft() + QPoint(2, 0));
2958 //// painter->drawLine(scrollBarSlider.topRight() + QPoint(-2, 0), scrollBarSlider.bottomRight() + QPoint(2, 0));
2959 // } else {
2960 //// painter->drawLine(pixmapRect.topLeft() + QPoint(0, -2), pixmapRect.bottomLeft() + QPoint(0, -2));
2961 //// painter->drawLine(pixmapRect.topRight() + QPoint(0, 2), pixmapRect.bottomRight() + QPoint(0, 2));
2962 // }
2965 // The SubLine (up/left) buttons
2966 if (scrollBar->subControls & SC_ScrollBarSubLine) {
2967 if ((scrollBar->activeSubControls & SC_ScrollBarSubLine) && sunken)
2968 painter->setBrush(gradientStopColor);
2969 else if ((scrollBar->activeSubControls & SC_ScrollBarSubLine))
2970 painter->setBrush(highlightedGradient);
2971 else
2972 painter->setBrush(gradient);
2974 painter->setPen(Qt::NoPen);
2975 painter->drawRect(scrollBarSubLine.adjusted(horizontal ? 0 : 1, horizontal ? 1 : 0, 0, 0));
2976 painter->setPen(QPen(alphaOutline, 1));
2977 if (option->state & State_Horizontal) {
2978 if (option->direction == Qt::RightToLeft) {
2979 pixmapRect.setLeft(scrollBarSubLine.left());
2980 painter->drawLine(pixmapRect.topLeft(), pixmapRect.bottomLeft());
2981 } else {
2982 pixmapRect.setRight(scrollBarSubLine.right());
2983 painter->drawLine(pixmapRect.topRight(), pixmapRect.bottomRight());
2985 } else {
2986 pixmapRect.setBottom(scrollBarSubLine.bottom());
2987 painter->drawLine(pixmapRect.bottomLeft(), pixmapRect.bottomRight());
2990 painter->setBrush(Qt::NoBrush);
2991 painter->setPen(d->innerContrastLine());
2992 painter->drawRect(scrollBarSubLine.adjusted(horizontal ? 0 : 1, horizontal ? 1 : 0 , horizontal ? -2 : -1, horizontal ? -1 : -2));
2994 // Arrows
2995 int rotation = 0;
2996 if (option->state & State_Horizontal)
2997 rotation = option->direction == Qt::LeftToRight ? -90 : 90;
2998 QRect upRect = scrollBarSubLine.translated(horizontal ? -2 : -1, 0);
2999 QPixmap arrowPixmap = colorizedImage(QLatin1String(":/bitmaps/style/arrow.png"), arrowColor, rotation);
3000 painter->drawPixmap(QRect(upRect.center().x() - arrowPixmap.width() / 4 + 2,
3001 upRect.center().y() - arrowPixmap.height() / 4 + 1,
3002 arrowPixmap.width()/2, arrowPixmap.height()/2), arrowPixmap);
3005 // The AddLine (down/right) button
3006 if (scrollBar->subControls & SC_ScrollBarAddLine) {
3007 if ((scrollBar->activeSubControls & SC_ScrollBarAddLine) && sunken)
3008 painter->setBrush(gradientStopColor);
3009 else if ((scrollBar->activeSubControls & SC_ScrollBarAddLine))
3010 painter->setBrush(midColor2);
3011 else
3012 painter->setBrush(gradient);
3014 painter->setPen(Qt::NoPen);
3015 painter->drawRect(scrollBarAddLine.adjusted(horizontal ? 0 : 1, horizontal ? 1 : 0, 0, 0));
3016 painter->setPen(QPen(alphaOutline, 1));
3017 if (option->state & State_Horizontal) {
3018 if (option->direction == Qt::LeftToRight) {
3019 pixmapRect.setLeft(scrollBarAddLine.left());
3020 painter->drawLine(pixmapRect.topLeft(), pixmapRect.bottomLeft());
3021 } else {
3022 pixmapRect.setRight(scrollBarAddLine.right());
3023 painter->drawLine(pixmapRect.topRight(), pixmapRect.bottomRight());
3025 } else {
3026 pixmapRect.setTop(scrollBarAddLine.top());
3027 painter->drawLine(pixmapRect.topLeft(), pixmapRect.topRight());
3030 painter->setPen(d->innerContrastLine());
3031 painter->setBrush(Qt::NoBrush);
3032 painter->drawRect(scrollBarAddLine.adjusted(1, 1, -1, -1));
3034 int rotation = 180;
3035 if (option->state & State_Horizontal)
3036 rotation = option->direction == Qt::LeftToRight ? 90 : -90;
3037 QRect downRect = scrollBarAddLine.translated(-1, 1);
3038 QPixmap arrowPixmap = colorizedImage(QLatin1String(":/bitmaps/style/arrow.png"), arrowColor, rotation);
3039 painter->drawPixmap(QRect(downRect.center().x() - arrowPixmap.width() / 4 + 2,
3040 downRect.center().y() - arrowPixmap.height() / 4,
3041 arrowPixmap.width()/2, arrowPixmap.height()/2), arrowPixmap);
3045 painter->restore();
3046 break;;
3047 case CC_ComboBox:
3048 painter->save();
3049 if (const QStyleOptionComboBox *comboBox = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
3050 bool hasFocus = option->state & State_HasFocus && option->state & State_KeyboardFocusChange;
3051 bool sunken = comboBox->state & State_On; // play dead, if combobox has no items
3052 bool isEnabled = (comboBox->state & State_Enabled);
3053 QPixmap cache;
3054 QString pixmapName = uniqueName(QLatin1String("combobox"), option, comboBox->rect.size());
3055 if (sunken)
3056 pixmapName += QLatin1String("-sunken");
3057 if (comboBox->editable)
3058 pixmapName += QLatin1String("-editable");
3059 if (isEnabled)
3060 pixmapName += QLatin1String("-enabled");
3062 if (!QPixmapCache::find(pixmapName, PIXMAPCACHE_VAR_PREFIX cache)) {
3063 cache = styleCachePixmap(comboBox->rect.size());
3064 cache.fill(Qt::transparent);
3065 QPainter cachePainter(&cache);
3066 QRect pixmapRect(0, 0, comboBox->rect.width(), comboBox->rect.height());
3067 QStyleOptionComboBox comboBoxCopy = *comboBox;
3068 comboBoxCopy.rect = pixmapRect;
3070 QRect rect = pixmapRect;
3071 QRect downArrowRect = proxy()->subControlRect(CC_ComboBox, &comboBoxCopy,
3072 SC_ComboBoxArrow, widget);
3073 // Draw a line edit
3074 if (comboBox->editable) {
3075 QStyleOptionFrame buttonOption;
3076 buttonOption.QStyleOption::operator=(*comboBox);
3077 buttonOption.rect = rect;
3078 buttonOption.state = (comboBox->state & (State_Enabled | State_MouseOver | State_HasFocus))
3079 | State_KeyboardFocusChange; // Always show hig
3081 if (sunken) {
3082 buttonOption.state |= State_Sunken;
3083 buttonOption.state &= ~State_MouseOver;
3086 proxy()->drawPrimitive(PE_FrameLineEdit, &buttonOption, &cachePainter, widget);
3088 // Draw button clipped
3089 cachePainter.save();
3090 cachePainter.setClipRect(downArrowRect.adjusted(0, 0, 1, 0));
3091 buttonOption.rect.setLeft(comboBox->direction == Qt::LeftToRight ?
3092 downArrowRect.left() - 6: downArrowRect.right() + 6);
3093 proxy()->drawPrimitive(PE_PanelButtonCommand, &buttonOption, &cachePainter, widget);
3094 cachePainter.restore();
3095 cachePainter.setPen( QPen(hasFocus ? option->palette.highlight() : outline.lighter(110), 0));
3097 if (!sunken) {
3098 int borderSize = 1;
3099 if (comboBox->direction == Qt::RightToLeft) {
3100 cachePainter.drawLine(QPoint(downArrowRect.right() - 1, downArrowRect.top() + borderSize ),
3101 QPoint(downArrowRect.right() - 1, downArrowRect.bottom() - borderSize));
3102 } else {
3103 cachePainter.drawLine(QPoint(downArrowRect.left() , downArrowRect.top() + borderSize),
3104 QPoint(downArrowRect.left() , downArrowRect.bottom() - borderSize));
3106 } else {
3107 if (comboBox->direction == Qt::RightToLeft) {
3108 cachePainter.drawLine(QPoint(downArrowRect.right(), downArrowRect.top() + 2),
3109 QPoint(downArrowRect.right(), downArrowRect.bottom() - 2));
3111 } else {
3112 cachePainter.drawLine(QPoint(downArrowRect.left(), downArrowRect.top() + 2),
3113 QPoint(downArrowRect.left(), downArrowRect.bottom() - 2));
3116 } else {
3117 QStyleOptionButton buttonOption;
3118 buttonOption.QStyleOption::operator=(*comboBox);
3119 buttonOption.rect = rect;
3120 buttonOption.state = comboBox->state & (State_Enabled | State_MouseOver | State_HasFocus | State_KeyboardFocusChange);
3121 if (sunken) {
3122 buttonOption.state |= State_Sunken;
3123 buttonOption.state &= ~State_MouseOver;
3125 proxy()->drawPrimitive(PE_PanelButtonCommand, &buttonOption, &cachePainter, widget);
3127 if (comboBox->subControls & SC_ComboBoxArrow) {
3128 // Draw the up/down arrow
3129 QColor arrowColor = option->palette.buttonText().color();
3130 arrowColor.setAlpha(220);
3131 QPixmap downArrow = colorizedImage(QLatin1String(":/bitmaps/style/arrow.png"), arrowColor, 180);
3132 cachePainter.drawPixmap(QRect(downArrowRect.center().x() - downArrow.width() / 4 + 1,
3133 downArrowRect.center().y() - downArrow.height() / 4 + 1,
3134 downArrow.width()/2, downArrow.height()/2), downArrow);
3136 cachePainter.end();
3137 QPixmapCache::insert(pixmapName, cache);
3139 painter->drawPixmap(comboBox->rect.topLeft(), cache);
3141 painter->restore();
3142 break;
3143 case CC_Slider:
3144 if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
3145 QRect groove = proxy()->subControlRect(CC_Slider, option, SC_SliderGroove, widget);
3146 QRect handle = proxy()->subControlRect(CC_Slider, option, SC_SliderHandle, widget);
3148 bool horizontal = slider->orientation == Qt::Horizontal;
3149 bool ticksAbove = slider->tickPosition & QSlider::TicksAbove;
3150 bool ticksBelow = slider->tickPosition & QSlider::TicksBelow;
3151 QColor activeHighlight = d->highlight(option->palette);
3152 QPixmap cache;
3153 QBrush oldBrush = painter->brush();
3154 QPen oldPen = painter->pen();
3155 QColor shadowAlpha(Qt::black);
3156 shadowAlpha.setAlpha(10);
3157 if (option->state & State_HasFocus && option->state & State_KeyboardFocusChange)
3158 outline = d->highlightedOutline(option->palette);
3161 if ((option->subControls & SC_SliderGroove) && groove.isValid()) {
3162 QColor grooveColor;
3163 grooveColor.setHsv(buttonColor.hue(),
3164 qMin(255, (int)(buttonColor.saturation())),
3165 qMin(255, (int)(buttonColor.value()*0.9)));
3166 QString groovePixmapName = uniqueName(QLatin1String("slider_groove"), option, groove.size());
3167 QRect pixmapRect(0, 0, groove.width(), groove.height());
3169 // draw background groove
3170 if (!QPixmapCache::find(groovePixmapName, PIXMAPCACHE_VAR_PREFIX cache)) {
3171 cache = styleCachePixmap(pixmapRect.size());
3172 cache.fill(Qt::transparent);
3173 QPainter groovePainter(&cache);
3174 groovePainter.setRenderHint(QPainter::Antialiasing, true);
3175 groovePainter.translate(0.5, 0.5);
3176 QLinearGradient gradient;
3177 if (horizontal) {
3178 gradient.setStart(pixmapRect.center().x(), pixmapRect.top());
3179 gradient.setFinalStop(pixmapRect.center().x(), pixmapRect.bottom());
3181 else {
3182 gradient.setStart(pixmapRect.left(), pixmapRect.center().y());
3183 gradient.setFinalStop(pixmapRect.right(), pixmapRect.center().y());
3185 groovePainter.setPen(QPen(outline, 0));
3186 gradient.setColorAt(0, grooveColor.darker(110));
3187 gradient.setColorAt(1, grooveColor.lighter(110));//palette.button().color().darker(115));
3188 groovePainter.setBrush(gradient);
3189 groovePainter.drawRoundedRect(pixmapRect.adjusted(1, 1, -2, -2), 1, 1);
3190 groovePainter.end();
3191 QPixmapCache::insert(groovePixmapName, cache);
3193 painter->drawPixmap(groove.topLeft(), cache);
3195 // draw blue groove highlight
3196 QRect clipRect;
3197 groovePixmapName += QLatin1String("_blue");
3198 if (!QPixmapCache::find(groovePixmapName, PIXMAPCACHE_VAR_PREFIX cache)) {
3199 cache = styleCachePixmap(pixmapRect.size());
3200 cache.fill(Qt::transparent);
3201 QPainter groovePainter(&cache);
3202 QLinearGradient gradient;
3203 if (horizontal) {
3204 gradient.setStart(pixmapRect.center().x(), pixmapRect.top());
3205 gradient.setFinalStop(pixmapRect.center().x(), pixmapRect.bottom());
3207 else {
3208 gradient.setStart(pixmapRect.left(), pixmapRect.center().y());
3209 gradient.setFinalStop(pixmapRect.right(), pixmapRect.center().y());
3211 QColor highlight = d->highlight(option->palette);
3212 QColor highlightedoutline = highlight.darker(140);
3213 if (qGray(outline.rgb()) > qGray(highlightedoutline.rgb()))
3214 outline = highlightedoutline;
3217 groovePainter.setRenderHint(QPainter::Antialiasing, true);
3218 groovePainter.translate(0.5, 0.5);
3219 groovePainter.setPen(QPen(outline, 0));
3220 gradient.setColorAt(0, activeHighlight);
3221 gradient.setColorAt(1, activeHighlight.lighter(130));
3222 groovePainter.setBrush(gradient);
3223 groovePainter.drawRoundedRect(pixmapRect.adjusted(1, 1, -2, -2), 1, 1);
3224 groovePainter.setPen(d->innerContrastLine());
3225 groovePainter.setBrush(Qt::NoBrush);
3226 groovePainter.drawRoundedRect(pixmapRect.adjusted(2, 2, -3, -3), 1, 1);
3227 groovePainter.end();
3228 QPixmapCache::insert(groovePixmapName, cache);
3230 if (horizontal) {
3231 if (slider->upsideDown)
3232 clipRect = QRect(handle.right(), groove.top(), groove.right() - handle.right(), groove.height());
3233 else
3234 clipRect = QRect(groove.left(), groove.top(), handle.left(), groove.height());
3235 } else {
3236 if (slider->upsideDown)
3237 clipRect = QRect(groove.left(), handle.bottom(), groove.width(), groove.height() - handle.bottom());
3238 else
3239 clipRect = QRect(groove.left(), groove.top(), groove.width(), handle.top() - groove.top());
3241 painter->save();
3242 painter->setClipRect(clipRect.adjusted(0, 0, 1, 1));
3243 painter->drawPixmap(groove.topLeft(), cache);
3244 painter->restore();
3247 if (option->subControls & SC_SliderTickmarks) {
3248 painter->setPen(outline);
3249 int tickSize = proxy()->pixelMetric(PM_SliderTickmarkOffset, option, widget);
3250 int available = proxy()->pixelMetric(PM_SliderSpaceAvailable, slider, widget);
3251 int interval = slider->tickInterval;
3252 if (interval <= 0) {
3253 interval = slider->singleStep;
3254 if (QStyle::sliderPositionFromValue(slider->minimum, slider->maximum, interval,
3255 available)
3256 - QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
3257 0, available) < 3)
3258 interval = slider->pageStep;
3260 if (interval <= 0)
3261 interval = 1;
3263 int v = slider->minimum;
3264 int len = proxy()->pixelMetric(PM_SliderLength, slider, widget);
3265 while (v <= slider->maximum + 1) {
3266 if (v == slider->maximum + 1 && interval == 1)
3267 break;
3268 const int v_ = qMin(v, slider->maximum);
3269 int pos = sliderPositionFromValue(slider->minimum, slider->maximum,
3270 v_, (horizontal
3271 ? slider->rect.width()
3272 : slider->rect.height()) - len,
3273 slider->upsideDown) + len / 2;
3274 int extra = 2 - ((v_ == slider->minimum || v_ == slider->maximum) ? 1 : 0);
3276 if (horizontal) {
3277 if (ticksAbove) {
3278 painter->drawLine(pos, slider->rect.top() + extra,
3279 pos, slider->rect.top() + tickSize);
3281 if (ticksBelow) {
3282 painter->drawLine(pos, slider->rect.bottom() - extra,
3283 pos, slider->rect.bottom() - tickSize);
3285 } else {
3286 if (ticksAbove) {
3287 painter->drawLine(slider->rect.left() + extra, pos,
3288 slider->rect.left() + tickSize, pos);
3290 if (ticksBelow) {
3291 painter->drawLine(slider->rect.right() - extra, pos,
3292 slider->rect.right() - tickSize, pos);
3295 // in the case where maximum is max int
3296 int nextInterval = v + interval;
3297 if (nextInterval < v)
3298 break;
3299 v = nextInterval;
3303 // draw handle
3304 if ((option->subControls & SC_SliderHandle) ) {
3305 QString handlePixmapName = uniqueName(QLatin1String("slider_handle"), option, handle.size());
3306 if (!QPixmapCache::find(handlePixmapName, PIXMAPCACHE_VAR_PREFIX cache)) {
3307 cache = styleCachePixmap(handle.size());
3308 cache.fill(Qt::transparent);
3309 QRect pixmapRect(0, 0, handle.width(), handle.height());
3310 QPainter handlePainter(&cache);
3311 QRect gradRect = pixmapRect.adjusted(2, 2, -2, -2);
3313 // gradient fill
3314 QRect r = pixmapRect.adjusted(1, 1, -2, -2);
3315 QLinearGradient gradient = qt_fusion_gradient(gradRect, d->buttonColor(option->palette),horizontal ? TopDown : FromLeft);
3317 handlePainter.setRenderHint(QPainter::Antialiasing, true);
3318 handlePainter.translate(0.5, 0.5);
3320 handlePainter.setPen(Qt::NoPen);
3321 handlePainter.setBrush(QColor(0, 0, 0, 40));
3322 handlePainter.drawRect(r.adjusted(-1, 2, 1, -2));
3324 handlePainter.setPen(QPen(d->outline(option->palette), 1));
3325 if (option->state & State_HasFocus && option->state & State_KeyboardFocusChange)
3326 handlePainter.setPen(QPen(d->highlightedOutline(option->palette), 1));
3328 handlePainter.setBrush(gradient);
3329 handlePainter.drawRoundedRect(r, 2, 2);
3330 handlePainter.setBrush(Qt::NoBrush);
3331 handlePainter.setPen(d->innerContrastLine());
3332 handlePainter.drawRoundedRect(r.adjusted(1, 1, -1, -1), 2, 2);
3334 QColor cornerAlpha = outline.darker(120);
3335 cornerAlpha.setAlpha(80);
3337 //handle shadow
3338 handlePainter.setPen(shadowAlpha);
3339 handlePainter.drawLine(QPoint(r.left() + 2, r.bottom() + 1), QPoint(r.right() - 2, r.bottom() + 1));
3340 handlePainter.drawLine(QPoint(r.right() + 1, r.bottom() - 3), QPoint(r.right() + 1, r.top() + 4));
3341 handlePainter.drawLine(QPoint(r.right() - 1, r.bottom()), QPoint(r.right() + 1, r.bottom() - 2));
3343 handlePainter.end();
3344 QPixmapCache::insert(handlePixmapName, cache);
3347 painter->drawPixmap(handle.topLeft(), cache);
3350 painter->setBrush(oldBrush);
3351 painter->setPen(oldPen);
3353 break;
3354 case CC_Dial:
3355 if (const QStyleOptionSlider* dial = qstyleoption_cast<const QStyleOptionSlider *>(option))
3356 drawDial(dial, painter);
3357 break;
3358 default:
3359 QCommonStyle::drawComplexControl(control, option, painter, widget);
3360 break;
3365 \reimp
3367 int CarlaStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const
3369 switch (metric)
3371 case PM_SliderTickmarkOffset:
3372 return 4;
3373 case PM_HeaderMargin:
3374 return 2;
3375 case PM_ToolTipLabelFrameWidth:
3376 return 2;
3377 case PM_ButtonDefaultIndicator:
3378 return 0;
3379 case PM_ButtonShiftHorizontal:
3380 case PM_ButtonShiftVertical:
3381 return 0;
3382 case PM_MessageBoxIconSize:
3383 return 48;
3384 case PM_ListViewIconSize:
3385 return 24;
3386 case PM_DialogButtonsSeparator:
3387 case PM_ScrollBarSliderMin:
3388 return 26;
3389 case PM_TitleBarHeight:
3390 return 24;
3391 case PM_ScrollBarExtent:
3392 return 14;
3393 case PM_SliderThickness:
3394 return 15;
3395 case PM_SliderLength:
3396 return 15;
3397 case PM_DockWidgetTitleMargin:
3398 return 1;
3399 case PM_DefaultFrameWidth:
3400 return 1;
3401 case PM_SpinBoxFrameWidth:
3402 return 2;
3403 case PM_MenuVMargin:
3404 case PM_MenuHMargin:
3405 return 0;
3406 case PM_MenuPanelWidth:
3407 return 0;
3408 case PM_MenuBarItemSpacing:
3409 return 6;
3410 case PM_MenuBarVMargin:
3411 return 0;
3412 case PM_MenuBarHMargin:
3413 return 0;
3414 case PM_MenuBarPanelWidth:
3415 return 0;
3416 case PM_ToolBarHandleExtent:
3417 return 9;
3418 case PM_ToolBarItemSpacing:
3419 return 1;
3420 case PM_ToolBarFrameWidth:
3421 return 2;
3422 case PM_ToolBarItemMargin:
3423 return 2;
3424 case PM_SmallIconSize:
3425 return 16;
3426 case PM_ButtonIconSize:
3427 return 16;
3428 case PM_DockWidgetTitleBarButtonMargin:
3429 return 2;
3430 case PM_MaximumDragDistance:
3431 return -1;
3432 case PM_TabCloseIndicatorWidth:
3433 case PM_TabCloseIndicatorHeight:
3434 return 20;
3435 case PM_TabBarTabVSpace:
3436 return 12;
3437 case PM_TabBarTabOverlap:
3438 return 1;
3439 case PM_TabBarBaseOverlap:
3440 return 2;
3441 case PM_SubMenuOverlap:
3442 return -1;
3443 case PM_DockWidgetHandleExtent:
3444 case PM_SplitterWidth:
3445 return 4;
3446 case PM_IndicatorHeight:
3447 case PM_IndicatorWidth:
3448 case PM_ExclusiveIndicatorHeight:
3449 case PM_ExclusiveIndicatorWidth:
3450 return 14;
3451 case PM_ScrollView_ScrollBarSpacing:
3452 return 0;
3453 default:
3454 break;
3456 return QCommonStyle::pixelMetric(metric, option, widget);
3460 \reimp
3462 QSize CarlaStyle::sizeFromContents(ContentsType type, const QStyleOption* option,
3463 const QSize& size, const QWidget* widget) const
3465 QSize newSize = QCommonStyle::sizeFromContents(type, option, size, widget);
3467 switch (type)
3469 case CT_PushButton:
3470 if (const QStyleOptionButton* btn = qstyleoption_cast<const QStyleOptionButton *>(option))
3472 if (!btn->text.isEmpty() && newSize.width() < 80)
3473 newSize.setWidth(80);
3474 if (!btn->icon.isNull() && btn->iconSize.height() > 16)
3475 newSize -= QSize(0, 2);
3477 break;
3479 case CT_GroupBox:
3480 if (option)
3482 int topMargin = qMax(pixelMetric(PM_ExclusiveIndicatorHeight), option->fontMetrics.height()) + groupBoxTopMargin;
3483 newSize += QSize(10, topMargin); // Add some space below the groupbox
3485 break;
3487 case CT_RadioButton:
3488 case CT_CheckBox:
3489 newSize += QSize(0, 1);
3490 break;
3492 case CT_ToolButton:
3493 newSize += QSize(3, 3);
3494 break;
3496 case CT_SpinBox:
3497 newSize += QSize(0, -3);
3498 break;
3500 case CT_ComboBox:
3501 newSize += QSize(2, 4);
3502 break;
3504 case CT_LineEdit:
3505 newSize += QSize(0, 4);
3506 break;
3508 case CT_MenuBarItem:
3509 newSize += QSize(8, 5);
3510 break;
3512 case CT_MenuItem:
3513 if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option))
3515 int w = newSize.width();
3516 int maxpmw = menuItem->maxIconWidth;
3517 int tabSpacing = 20;
3518 if (menuItem->text.contains(QLatin1Char('\t')))
3519 w += tabSpacing;
3520 else if (menuItem->menuItemType == QStyleOptionMenuItem::SubMenu)
3521 w += 2 * CarlaStylePrivate::menuArrowHMargin;
3522 else if (menuItem->menuItemType == QStyleOptionMenuItem::DefaultItem) {
3523 QFontMetrics fm(menuItem->font);
3524 QFont fontBold = menuItem->font;
3525 fontBold.setBold(true);
3526 QFontMetrics fmBold(fontBold);
3527 w += fontMetricsHorizontalAdvance(fmBold, menuItem->text) - fontMetricsHorizontalAdvance(fm, menuItem->text);
3529 int checkcol = qMax<int>(maxpmw, CarlaStylePrivate::menuCheckMarkWidth); // Windows always shows a check column
3530 w += checkcol;
3531 w += int(CarlaStylePrivate::menuRightBorder) + 10;
3532 newSize.setWidth(w);
3533 if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) {
3534 if (!menuItem->text.isEmpty()) {
3535 newSize.setHeight(menuItem->fontMetrics.height());
3538 else if (!menuItem->icon.isNull())
3540 if (const QComboBox *combo = qobject_cast<const QComboBox*>(widget)) {
3541 newSize.setHeight(qMax(combo->iconSize().height() + 2, newSize.height()));
3544 newSize.setWidth(newSize.width() + 12);
3545 newSize.setWidth(qMax(newSize.width(), 120));
3547 break;
3549 case CT_SizeGrip:
3550 newSize += QSize(4, 4);
3551 break;
3553 case CT_MdiControls:
3554 if (const QStyleOptionComplex *styleOpt = qstyleoption_cast<const QStyleOptionComplex *>(option))
3556 int width = 0;
3557 if (styleOpt->subControls & SC_MdiMinButton)
3558 width += 19 + 1;
3559 if (styleOpt->subControls & SC_MdiNormalButton)
3560 width += 19 + 1;
3561 if (styleOpt->subControls & SC_MdiCloseButton)
3562 width += 19 + 1;
3563 newSize = QSize(width, 19);
3565 else
3567 newSize = QSize(60, 19);
3569 break;
3571 default:
3572 break;
3574 return newSize;
3577 void CarlaStyle::polish(QApplication* app)
3579 QCommonStyle::polish(app);
3582 void CarlaStyle::polish(QPalette& pal)
3584 QCommonStyle::polish(pal);
3588 \reimp
3590 void CarlaStyle::polish(QWidget *widget)
3592 QCommonStyle::polish(widget);
3593 if (qobject_cast<QAbstractButton*>(widget)
3594 || qobject_cast<QComboBox *>(widget)
3595 || qobject_cast<QProgressBar *>(widget)
3596 || qobject_cast<QScrollBar *>(widget)
3597 || qobject_cast<QSplitterHandle *>(widget)
3598 || qobject_cast<QAbstractSlider *>(widget)
3599 || qobject_cast<QAbstractSpinBox *>(widget)
3600 || (widget->inherits("QDockSeparator"))
3601 || (widget->inherits("QDockWidgetSeparator"))
3603 widget->setAttribute(Qt::WA_Hover, true);
3608 void CarlaStyle::unpolish(QApplication* app)
3610 QCommonStyle::unpolish(app);
3614 \reimp
3616 void CarlaStyle::unpolish(QWidget *widget)
3618 QCommonStyle::unpolish(widget);
3619 if (qobject_cast<QAbstractButton*>(widget)
3620 || qobject_cast<QComboBox *>(widget)
3621 || qobject_cast<QProgressBar *>(widget)
3622 || qobject_cast<QScrollBar *>(widget)
3623 || qobject_cast<QSplitterHandle *>(widget)
3624 || qobject_cast<QAbstractSlider *>(widget)
3625 || qobject_cast<QAbstractSpinBox *>(widget)
3626 || (widget->inherits("QDockSeparator"))
3627 || (widget->inherits("QDockWidgetSeparator"))
3629 widget->setAttribute(Qt::WA_Hover, false);
3634 \reimp
3636 QRect CarlaStyle::subControlRect(ComplexControl control, const QStyleOptionComplex *option,
3637 SubControl subControl, const QWidget *widget) const
3639 QRect rect = QCommonStyle::subControlRect(control, option, subControl, widget);
3641 switch (control) {
3642 case CC_Slider:
3643 if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
3644 int tickSize = proxy()->pixelMetric(PM_SliderTickmarkOffset, option, widget);
3645 switch (subControl) {
3646 case SC_SliderHandle: {
3647 if (slider->orientation == Qt::Horizontal) {
3648 rect.setHeight(proxy()->pixelMetric(PM_SliderThickness));
3649 rect.setWidth(proxy()->pixelMetric(PM_SliderLength));
3650 int centerY = slider->rect.center().y() - rect.height() / 2;
3651 if (slider->tickPosition & QSlider::TicksAbove)
3652 centerY += tickSize;
3653 if (slider->tickPosition & QSlider::TicksBelow)
3654 centerY -= tickSize;
3655 rect.moveTop(centerY);
3656 } else {
3657 rect.setWidth(proxy()->pixelMetric(PM_SliderThickness));
3658 rect.setHeight(proxy()->pixelMetric(PM_SliderLength));
3659 int centerX = slider->rect.center().x() - rect.width() / 2;
3660 if (slider->tickPosition & QSlider::TicksAbove)
3661 centerX += tickSize;
3662 if (slider->tickPosition & QSlider::TicksBelow)
3663 centerX -= tickSize;
3664 rect.moveLeft(centerX);
3667 break;
3668 case SC_SliderGroove: {
3669 QPoint grooveCenter = slider->rect.center();
3670 if (slider->orientation == Qt::Horizontal) {
3671 rect.setHeight(7);
3672 if (slider->tickPosition & QSlider::TicksAbove)
3673 grooveCenter.ry() += tickSize;
3674 if (slider->tickPosition & QSlider::TicksBelow)
3675 grooveCenter.ry() -= tickSize;
3676 } else {
3677 rect.setWidth(7);
3678 if (slider->tickPosition & QSlider::TicksAbove)
3679 grooveCenter.rx() += tickSize;
3680 if (slider->tickPosition & QSlider::TicksBelow)
3681 grooveCenter.rx() -= tickSize;
3683 rect.moveCenter(grooveCenter);
3684 break;
3686 default:
3687 break;
3690 break;
3691 case CC_SpinBox:
3692 if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
3693 QSize bs;
3694 const float center = spinbox->rect.height() / 2.0;
3695 const int fw = spinbox->frame ? proxy()->pixelMetric(PM_SpinBoxFrameWidth, spinbox, widget) : 0;
3696 const int y = 1;
3697 bs.setHeight(qMax(8, int(floor(center) - y)));
3698 bs.setWidth(14);
3699 int x, lx, rx;
3700 x = spinbox->rect.width() - y - bs.width();
3701 lx = fw;
3702 rx = x - fw;
3703 switch (subControl) {
3704 case SC_SpinBoxUp:
3705 if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons)
3706 return QRect();
3707 rect = QRect(x, y, bs.width(), bs.height());
3708 break;
3709 case SC_SpinBoxDown:
3710 if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons)
3711 return QRect();
3713 rect = QRect(x, ceil(center), bs.width(), bs.height());
3714 break;
3715 case SC_SpinBoxEditField:
3716 if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons) {
3717 rect = QRect(lx, fw, spinbox->rect.width() - 2*fw, spinbox->rect.height() - 2*fw);
3718 } else {
3719 rect = QRect(lx, fw, rx - qMax(fw - 1, 0), spinbox->rect.height() - 2*fw);
3721 break;
3722 case SC_SpinBoxFrame:
3723 rect = spinbox->rect;
3724 default:
3725 break;
3727 rect = visualRect(spinbox->direction, spinbox->rect, rect);
3729 break;
3731 case CC_GroupBox:
3732 if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
3733 rect = option->rect;
3734 if (subControl == SC_GroupBoxFrame)
3735 return rect.adjusted(0, 0, 0, 0);
3736 else if (subControl == SC_GroupBoxContents) {
3737 QRect frameRect = option->rect.adjusted(0, 0, 0, -groupBoxBottomMargin);
3738 int margin = 3;
3739 int leftMarginExtension = 0;
3740 int topMargin = qMax(pixelMetric(PM_ExclusiveIndicatorHeight), option->fontMetrics.height()) + groupBoxTopMargin;
3741 return frameRect.adjusted(leftMarginExtension + margin, margin + topMargin, -margin, -margin - groupBoxBottomMargin);
3744 QSize textSize = option->fontMetrics.boundingRect(groupBox->text).size() + QSize(2, 2);
3745 int indicatorWidth = proxy()->pixelMetric(PM_IndicatorWidth, option, widget);
3746 int indicatorHeight = proxy()->pixelMetric(PM_IndicatorHeight, option, widget);
3747 rect = QRect();
3748 if (subControl == SC_GroupBoxCheckBox) {
3749 rect.setWidth(indicatorWidth);
3750 rect.setHeight(indicatorHeight);
3751 rect.moveTop(textSize.height() > indicatorHeight ? (textSize.height() - indicatorHeight) / 2 : 0);
3752 rect.moveLeft(1);
3753 } else if (subControl == SC_GroupBoxLabel) {
3754 rect.setSize(textSize);
3755 rect.moveTop(1);
3756 if (option->subControls & QStyle::SC_GroupBoxCheckBox)
3757 rect.translate(indicatorWidth + 5, 0);
3759 return visualRect(option->direction, option->rect, rect);
3762 return rect;
3764 case CC_ComboBox:
3765 switch (subControl) {
3766 case SC_ComboBoxArrow:
3767 rect = visualRect(option->direction, option->rect, rect);
3768 rect.setRect(rect.right() - 18, rect.top() - 2,
3769 19, rect.height() + 4);
3770 rect = visualRect(option->direction, option->rect, rect);
3771 break;
3772 case SC_ComboBoxEditField: {
3773 int frameWidth = 2;
3774 rect = visualRect(option->direction, option->rect, rect);
3775 rect.setRect(option->rect.left() + frameWidth, option->rect.top() + frameWidth,
3776 option->rect.width() - 19 - 2 * frameWidth,
3777 option->rect.height() - 2 * frameWidth);
3778 if (const QStyleOptionComboBox *box = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
3779 if (!box->editable) {
3780 rect.adjust(2, 0, 0, 0);
3781 if (box->state & (State_Sunken | State_On))
3782 rect.translate(1, 1);
3785 rect = visualRect(option->direction, option->rect, rect);
3786 break;
3788 default:
3789 break;
3791 break;
3792 case CC_TitleBar:
3793 if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(option)) {
3794 SubControl sc = subControl;
3795 QRect &ret = rect;
3796 const int indent = 3;
3797 const int controlTopMargin = 3;
3798 const int controlBottomMargin = 3;
3799 const int controlWidthMargin = 2;
3800 const int controlHeight = tb->rect.height() - controlTopMargin - controlBottomMargin ;
3801 const int delta = controlHeight + controlWidthMargin;
3802 int offset = 0;
3804 bool isMinimized = tb->titleBarState & Qt::WindowMinimized;
3805 bool isMaximized = tb->titleBarState & Qt::WindowMaximized;
3807 switch (sc) {
3808 case SC_TitleBarLabel:
3809 if (tb->titleBarFlags & (Qt::WindowTitleHint | Qt::WindowSystemMenuHint)) {
3810 ret = tb->rect;
3811 if (tb->titleBarFlags & Qt::WindowSystemMenuHint)
3812 ret.adjust(delta, 0, -delta, 0);
3813 if (tb->titleBarFlags & Qt::WindowMinimizeButtonHint)
3814 ret.adjust(0, 0, -delta, 0);
3815 if (tb->titleBarFlags & Qt::WindowMaximizeButtonHint)
3816 ret.adjust(0, 0, -delta, 0);
3817 if (tb->titleBarFlags & Qt::WindowShadeButtonHint)
3818 ret.adjust(0, 0, -delta, 0);
3819 if (tb->titleBarFlags & Qt::WindowContextHelpButtonHint)
3820 ret.adjust(0, 0, -delta, 0);
3822 break;
3823 case SC_TitleBarContextHelpButton:
3824 if (tb->titleBarFlags & Qt::WindowContextHelpButtonHint)
3825 offset += delta;
3826 // fall through
3827 case SC_TitleBarMinButton:
3828 if (!isMinimized && (tb->titleBarFlags & Qt::WindowMinimizeButtonHint))
3829 offset += delta;
3830 else if (sc == SC_TitleBarMinButton)
3831 break;
3832 // fall through
3833 case SC_TitleBarNormalButton:
3834 if (isMinimized && (tb->titleBarFlags & Qt::WindowMinimizeButtonHint))
3835 offset += delta;
3836 else if (isMaximized && (tb->titleBarFlags & Qt::WindowMaximizeButtonHint))
3837 offset += delta;
3838 else if (sc == SC_TitleBarNormalButton)
3839 break;
3840 // fall through
3841 case SC_TitleBarMaxButton:
3842 if (!isMaximized && (tb->titleBarFlags & Qt::WindowMaximizeButtonHint))
3843 offset += delta;
3844 else if (sc == SC_TitleBarMaxButton)
3845 break;
3846 // fall through
3847 case SC_TitleBarShadeButton:
3848 if (!isMinimized && (tb->titleBarFlags & Qt::WindowShadeButtonHint))
3849 offset += delta;
3850 else if (sc == SC_TitleBarShadeButton)
3851 break;
3852 // fall through
3853 case SC_TitleBarUnshadeButton:
3854 if (isMinimized && (tb->titleBarFlags & Qt::WindowShadeButtonHint))
3855 offset += delta;
3856 else if (sc == SC_TitleBarUnshadeButton)
3857 break;
3858 // fall through
3859 case SC_TitleBarCloseButton:
3860 if (tb->titleBarFlags & Qt::WindowSystemMenuHint)
3861 offset += delta;
3862 else if (sc == SC_TitleBarCloseButton)
3863 break;
3864 ret.setRect(tb->rect.right() - indent - offset, tb->rect.top() + controlTopMargin,
3865 controlHeight, controlHeight);
3866 break;
3867 case SC_TitleBarSysMenu:
3868 if (tb->titleBarFlags & Qt::WindowSystemMenuHint) {
3869 ret.setRect(tb->rect.left() + controlWidthMargin + indent, tb->rect.top() + controlTopMargin,
3870 controlHeight, controlHeight);
3872 break;
3873 default:
3874 break;
3876 ret = visualRect(tb->direction, tb->rect, ret);
3878 break;
3879 default:
3880 break;
3883 return rect;
3887 \reimp
3889 QPixmap CarlaStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption* opt, const QWidget* widget) const
3891 #if 0 // ndef QT_NO_IMAGEFORMAT_XPM
3892 switch (standardPixmap) {
3893 case SP_TitleBarNormalButton:
3894 return QPixmap((const char **)dock_widget_restore_xpm);
3895 case SP_TitleBarMinButton:
3896 return QPixmap((const char **)workspace_minimize);
3897 case SP_TitleBarCloseButton:
3898 case SP_DockWidgetCloseButton:
3899 return QPixmap((const char **)dock_widget_close_xpm);
3900 default:
3901 break;
3903 #endif //QT_NO_IMAGEFORMAT_XPM
3905 QPixmap pixmap = QCommonStyle::standardPixmap(standardPixmap, opt, widget);
3907 if(!pixmap.isNull())
3908 return pixmap;
3910 #if 0 // ndef QT_NO_IMAGEFORMAT_XPM
3911 switch (standardPixmap) {
3912 case SP_TitleBarMenuButton:
3913 return QPixmap(qt_menu_xpm);
3914 case SP_TitleBarShadeButton:
3915 return QPixmap(qt_shade_xpm);
3916 case SP_TitleBarUnshadeButton:
3917 return QPixmap(qt_unshade_xpm);
3918 case SP_TitleBarMaxButton:
3919 return QPixmap(qt_maximize_xpm);
3920 case SP_TitleBarCloseButton:
3921 return QPixmap(qt_close_xpm);
3922 case SP_TitleBarContextHelpButton:
3923 return QPixmap(qt_help_xpm);
3924 case SP_MessageBoxInformation:
3925 return QPixmap(information_xpm);
3926 case SP_MessageBoxWarning:
3927 return QPixmap(warning_xpm);
3928 case SP_MessageBoxCritical:
3929 return QPixmap(critical_xpm);
3930 case SP_MessageBoxQuestion:
3931 return QPixmap(question_xpm);
3932 default:
3933 break;
3935 #endif //QT_NO_IMAGEFORMAT_XPM
3937 return QPixmap();
3941 \reimp
3943 int CarlaStyle::styleHint(StyleHint hint, const QStyleOption* option, const QWidget* widget,
3944 QStyleHintReturn* returnData) const
3946 switch (hint)
3948 case SH_Slider_SnapToValue:
3949 case SH_PrintDialog_RightAlignButtons:
3950 case SH_FontDialog_SelectAssociatedText:
3951 case SH_MenuBar_AltKeyNavigation:
3952 case SH_ComboBox_ListMouseTracking:
3953 case SH_ScrollBar_StopMouseOverSlider:
3954 case SH_ScrollBar_MiddleClickAbsolutePosition:
3955 case SH_TitleBar_AutoRaise:
3956 case SH_TitleBar_NoBorder:
3957 case SH_ItemView_ShowDecorationSelected:
3958 case SH_ItemView_ArrowKeysNavigateIntoChildren:
3959 case SH_ItemView_ChangeHighlightOnFocus:
3960 case SH_MenuBar_MouseTracking:
3961 case SH_Menu_MouseTracking:
3962 return 1;
3964 case SH_ComboBox_Popup:
3965 case SH_EtchDisabledText:
3966 case SH_ToolBox_SelectedPageTitleBold:
3967 case SH_ScrollView_FrameOnlyAroundContents:
3968 case SH_Menu_AllowActiveAndDisabled:
3969 case SH_MainWindow_SpaceBelowMenuBar:
3970 //case SH_DialogButtonBox_ButtonsHaveIcons:
3971 case SH_MessageBox_CenterButtons:
3972 case SH_RubberBand_Mask:
3973 case SH_UnderlineShortcut:
3974 return 0;
3976 case SH_Table_GridLineColor:
3977 return option ? qt_palette_bg_color(option->palette).darker(120).rgb() : 0;
3979 case SH_MessageBox_TextInteractionFlags:
3980 return Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse;
3982 case SH_WizardStyle:
3983 return QWizard::ClassicStyle;
3985 case SH_Menu_SubMenuPopupDelay:
3986 return 225; // default from GtkMenu
3988 case SH_WindowFrame_Mask:
3989 if (QStyleHintReturnMask* mask = qstyleoption_cast<QStyleHintReturnMask*>(returnData)) {
3990 //left rounded corner
3991 mask->region = option->rect;
3992 mask->region -= QRect(option->rect.left(), option->rect.top(), 5, 1);
3993 mask->region -= QRect(option->rect.left(), option->rect.top() + 1, 3, 1);
3994 mask->region -= QRect(option->rect.left(), option->rect.top() + 2, 2, 1);
3995 mask->region -= QRect(option->rect.left(), option->rect.top() + 3, 1, 2);
3997 //right rounded corner
3998 mask->region -= QRect(option->rect.right() - 4, option->rect.top(), 5, 1);
3999 mask->region -= QRect(option->rect.right() - 2, option->rect.top() + 1, 3, 1);
4000 mask->region -= QRect(option->rect.right() - 1, option->rect.top() + 2, 2, 1);
4001 mask->region -= QRect(option->rect.right() , option->rect.top() + 3, 1, 2);
4002 return 1;
4004 default:
4005 break;
4007 return QCommonStyle::styleHint(hint, option, widget, returnData);
4010 /*! \reimp */
4011 QRect CarlaStyle::subElementRect(SubElement sr, const QStyleOption *opt, const QWidget *w) const
4013 QRect r = QCommonStyle::subElementRect(sr, opt, w);
4014 switch (sr) {
4015 case SE_ProgressBarLabel:
4016 case SE_ProgressBarContents:
4017 case SE_ProgressBarGroove:
4018 return opt->rect;
4019 case SE_PushButtonFocusRect:
4020 r.adjust(0, 1, 0, -1);
4021 break;
4022 case SE_DockWidgetTitleBarText: {
4023 if (const QStyleOptionDockWidget *titlebar = qstyleoption_cast<const QStyleOptionDockWidget*>(opt)) {
4024 Q_UNUSED(titlebar);
4025 bool verticalTitleBar = false;
4026 if (verticalTitleBar) {
4027 r.adjust(0, 0, 0, -4);
4028 } else {
4029 if (opt->direction == Qt::LeftToRight)
4030 r.adjust(4, 0, 0, 0);
4031 else
4032 r.adjust(0, 0, -4, 0);
4036 break;
4038 default:
4039 break;
4041 return r;