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.

3862 lines
178KB

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