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.

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