Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4073 lines
186KB

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