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.

3841 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. case CE_SizeGrip:
  1250. painter->save();
  1251. {
  1252. //draw grips
  1253. for (int i = -6; i< 12 ; i += 3) {
  1254. for (int j = -6 ; j< 12 ; j += 3) {
  1255. if ((option->direction == Qt::LeftToRight && i > -j) || (option->direction == Qt::RightToLeft && j > i) ) {
  1256. painter->fillRect(rect.center().x() + i, rect.center().y() + j, 2, 2, d->lightShade());
  1257. painter->fillRect(rect.center().x() + i, rect.center().y() + j, 1, 1, d->darkShade());
  1258. }
  1259. }
  1260. }
  1261. }
  1262. painter->restore();
  1263. break;
  1264. case CE_ToolBar:
  1265. if (const QStyleOptionToolBar *toolBar = qstyleoption_cast<const QStyleOptionToolBar *>(option)) {
  1266. // Reserve the beveled appearance only for mainwindow toolbars
  1267. if (widget && !(qobject_cast<const QMainWindow*> (widget->parentWidget())))
  1268. break;
  1269. // Draws the light line above and the dark line below menu bars and
  1270. // tool bars.
  1271. QLinearGradient gradient(option->rect.topLeft(), option->rect.bottomLeft());
  1272. if (!(option->state & State_Horizontal))
  1273. gradient = QLinearGradient(rect.left(), rect.center().y(),
  1274. rect.right(), rect.center().y());
  1275. gradient.setColorAt(0, option->palette.window().color().lighter(104));
  1276. gradient.setColorAt(1, option->palette.window().color());
  1277. painter->fillRect(option->rect, gradient);
  1278. QColor light = d->lightShade();
  1279. QColor shadow = d->darkShade();
  1280. QPen oldPen = painter->pen();
  1281. if (toolBar->toolBarArea == Qt::TopToolBarArea) {
  1282. if (toolBar->positionOfLine == QStyleOptionToolBar::End
  1283. || toolBar->positionOfLine == QStyleOptionToolBar::OnlyOne) {
  1284. // The end and onlyone top toolbar lines draw a double
  1285. // line at the bottom to blend with the central
  1286. // widget.
  1287. painter->setPen(light);
  1288. painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
  1289. painter->setPen(shadow);
  1290. painter->drawLine(option->rect.left(), option->rect.bottom() - 1,
  1291. option->rect.right(), option->rect.bottom() - 1);
  1292. } else {
  1293. // All others draw a single dark line at the bottom.
  1294. painter->setPen(shadow);
  1295. painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
  1296. }
  1297. // All top toolbar lines draw a light line at the top.
  1298. painter->setPen(light);
  1299. painter->drawLine(option->rect.topLeft(), option->rect.topRight());
  1300. } else if (toolBar->toolBarArea == Qt::BottomToolBarArea) {
  1301. if (toolBar->positionOfLine == QStyleOptionToolBar::End
  1302. || toolBar->positionOfLine == QStyleOptionToolBar::Middle) {
  1303. // The end and middle bottom tool bar lines draw a dark
  1304. // line at the bottom.
  1305. painter->setPen(shadow);
  1306. painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
  1307. }
  1308. if (toolBar->positionOfLine == QStyleOptionToolBar::Beginning
  1309. || toolBar->positionOfLine == QStyleOptionToolBar::OnlyOne) {
  1310. // The beginning and only one tool bar lines draw a
  1311. // double line at the bottom to blend with the
  1312. // status bar.
  1313. // ### The styleoption could contain whether the
  1314. // main window has a menu bar and a status bar, and
  1315. // possibly dock widgets.
  1316. painter->setPen(shadow);
  1317. painter->drawLine(option->rect.left(), option->rect.bottom() - 1,
  1318. option->rect.right(), option->rect.bottom() - 1);
  1319. painter->setPen(light);
  1320. painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
  1321. }
  1322. if (toolBar->positionOfLine == QStyleOptionToolBar::End) {
  1323. painter->setPen(shadow);
  1324. painter->drawLine(option->rect.topLeft(), option->rect.topRight());
  1325. painter->setPen(light);
  1326. painter->drawLine(option->rect.left(), option->rect.top() + 1,
  1327. option->rect.right(), option->rect.top() + 1);
  1328. } else {
  1329. // All other bottom toolbars draw a light line at the top.
  1330. painter->setPen(light);
  1331. painter->drawLine(option->rect.topLeft(), option->rect.topRight());
  1332. }
  1333. }
  1334. if (toolBar->toolBarArea == Qt::LeftToolBarArea) {
  1335. if (toolBar->positionOfLine == QStyleOptionToolBar::Middle
  1336. || toolBar->positionOfLine == QStyleOptionToolBar::End) {
  1337. // The middle and left end toolbar lines draw a light
  1338. // line to the left.
  1339. painter->setPen(light);
  1340. painter->drawLine(option->rect.topLeft(), option->rect.bottomLeft());
  1341. }
  1342. if (toolBar->positionOfLine == QStyleOptionToolBar::End) {
  1343. // All other left toolbar lines draw a dark line to the right
  1344. painter->setPen(shadow);
  1345. painter->drawLine(option->rect.right() - 1, option->rect.top(),
  1346. option->rect.right() - 1, option->rect.bottom());
  1347. painter->setPen(light);
  1348. painter->drawLine(option->rect.topRight(), option->rect.bottomRight());
  1349. } else {
  1350. // All other left toolbar lines draw a dark line to the right
  1351. painter->setPen(shadow);
  1352. painter->drawLine(option->rect.topRight(), option->rect.bottomRight());
  1353. }
  1354. } else if (toolBar->toolBarArea == Qt::RightToolBarArea) {
  1355. if (toolBar->positionOfLine == QStyleOptionToolBar::Middle
  1356. || toolBar->positionOfLine == QStyleOptionToolBar::End) {
  1357. // Right middle and end toolbar lines draw the dark right line
  1358. painter->setPen(shadow);
  1359. painter->drawLine(option->rect.topRight(), option->rect.bottomRight());
  1360. }
  1361. if (toolBar->positionOfLine == QStyleOptionToolBar::End
  1362. || toolBar->positionOfLine == QStyleOptionToolBar::OnlyOne) {
  1363. // The right end and single toolbar draws the dark
  1364. // line on its left edge
  1365. painter->setPen(shadow);
  1366. painter->drawLine(option->rect.topLeft(), option->rect.bottomLeft());
  1367. // And a light line next to it
  1368. painter->setPen(light);
  1369. painter->drawLine(option->rect.left() + 1, option->rect.top(),
  1370. option->rect.left() + 1, option->rect.bottom());
  1371. } else {
  1372. // Other right toolbars draw a light line on its left edge
  1373. painter->setPen(light);
  1374. painter->drawLine(option->rect.topLeft(), option->rect.bottomLeft());
  1375. }
  1376. }
  1377. painter->setPen(oldPen);
  1378. }
  1379. break;
  1380. case CE_DockWidgetTitle:
  1381. painter->save();
  1382. if (const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<const QStyleOptionDockWidget *>(option)) {
  1383. bool verticalTitleBar = false;
  1384. QRect titleRect = subElementRect(SE_DockWidgetTitleBarText, option, widget);
  1385. if (verticalTitleBar) {
  1386. QRect rect = dwOpt->rect;
  1387. QRect r = rect;
  1388. QSize s = r.size();
  1389. s.transpose();
  1390. r.setSize(s);
  1391. titleRect = QRect(r.left() + rect.bottom()
  1392. - titleRect.bottom(),
  1393. r.top() + titleRect.left() - rect.left(),
  1394. titleRect.height(), titleRect.width());
  1395. painter->translate(r.left(), r.top() + r.width());
  1396. painter->rotate(-90);
  1397. painter->translate(-r.left(), -r.top());
  1398. }
  1399. if (!dwOpt->title.isEmpty()) {
  1400. QString titleText
  1401. = painter->fontMetrics().elidedText(dwOpt->title,
  1402. Qt::ElideRight, titleRect.width());
  1403. proxy()->drawItemText(painter,
  1404. titleRect,
  1405. Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, dwOpt->palette,
  1406. dwOpt->state & State_Enabled, titleText,
  1407. QPalette::WindowText);
  1408. }
  1409. }
  1410. painter->restore();
  1411. break;
  1412. case CE_HeaderSection:
  1413. painter->save();
  1414. // Draws the header in tables.
  1415. if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
  1416. QString pixmapName = uniqueName(QLatin1String("headersection"), option, option->rect.size());
  1417. pixmapName += QString::number(- int(header->position));
  1418. pixmapName += QString::number(- int(header->orientation));
  1419. QPixmap cache;
  1420. if (!QPixmapCache::find(pixmapName, cache)) {
  1421. cache = styleCachePixmap(rect.size());
  1422. cache.fill(Qt::transparent);
  1423. QRect pixmapRect(0, 0, rect.width(), rect.height());
  1424. QPainter cachePainter(&cache);
  1425. QColor buttonColor = d->buttonColor(option->palette);
  1426. QColor gradientStopColor;
  1427. QColor gradientStartColor = buttonColor.lighter(104);
  1428. gradientStopColor = buttonColor.darker(102);
  1429. QLinearGradient gradient(pixmapRect.topLeft(), pixmapRect.bottomLeft());
  1430. if (option->palette.background().gradient()) {
  1431. gradient.setStops(option->palette.background().gradient()->stops());
  1432. } else {
  1433. QColor midColor1 = mergedColors(gradientStartColor, gradientStopColor, 60);
  1434. QColor midColor2 = mergedColors(gradientStartColor, gradientStopColor, 40);
  1435. gradient.setColorAt(0, gradientStartColor);
  1436. gradient.setColorAt(0.5, midColor1);
  1437. gradient.setColorAt(0.501, midColor2);
  1438. gradient.setColorAt(0.92, gradientStopColor);
  1439. gradient.setColorAt(1, gradientStopColor.darker(104));
  1440. }
  1441. cachePainter.fillRect(pixmapRect, gradient);
  1442. cachePainter.setPen(d->innerContrastLine());
  1443. cachePainter.setBrush(Qt::NoBrush);
  1444. cachePainter.drawLine(pixmapRect.topLeft(), pixmapRect.topRight());
  1445. cachePainter.setPen(d->outline(option->palette));
  1446. cachePainter.drawLine(pixmapRect.bottomLeft(), pixmapRect.bottomRight());
  1447. if (header->orientation == Qt::Horizontal &&
  1448. header->position != QStyleOptionHeader::End &&
  1449. header->position != QStyleOptionHeader::OnlyOneSection) {
  1450. cachePainter.setPen(QColor(0, 0, 0, 40));
  1451. cachePainter.drawLine(pixmapRect.topRight(), pixmapRect.bottomRight() + QPoint(0, -1));
  1452. cachePainter.setPen(d->innerContrastLine());
  1453. cachePainter.drawLine(pixmapRect.topRight() + QPoint(-1, 0), pixmapRect.bottomRight() + QPoint(-1, -1));
  1454. } else if (header->orientation == Qt::Vertical) {
  1455. cachePainter.setPen(d->outline(option->palette));
  1456. cachePainter.drawLine(pixmapRect.topRight(), pixmapRect.bottomRight());
  1457. }
  1458. cachePainter.end();
  1459. QPixmapCache::insert(pixmapName, cache);
  1460. }
  1461. painter->drawPixmap(rect.topLeft(), cache);
  1462. }
  1463. painter->restore();
  1464. break;
  1465. case CE_ProgressBarGroove:
  1466. painter->save();
  1467. {
  1468. painter->setRenderHint(QPainter::Antialiasing, true);
  1469. painter->translate(0.5, 0.5);
  1470. QColor shadowAlpha = Qt::black;
  1471. shadowAlpha.setAlpha(16);
  1472. painter->setPen(shadowAlpha);
  1473. painter->drawLine(rect.topLeft() - QPoint(0, 1), rect.topRight() - QPoint(0, 1));
  1474. painter->setBrush(option->palette.base());
  1475. painter->setPen(QPen(outline, 0));
  1476. painter->drawRoundedRect(rect.adjusted(0, 0, -1, -1), 2, 2);
  1477. // Inner shadow
  1478. painter->setPen(d->topShadow());
  1479. painter->drawLine(QPoint(rect.left() + 1, rect.top() + 1),
  1480. QPoint(rect.right() - 1, rect.top() + 1));
  1481. }
  1482. painter->restore();
  1483. break;
  1484. case CE_ProgressBarContents:
  1485. painter->save();
  1486. painter->setRenderHint(QPainter::Antialiasing, true);
  1487. painter->translate(0.5, 0.5);
  1488. if (const QStyleOptionProgressBarV2 *bar = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(option)) {
  1489. bool vertical = false;
  1490. bool inverted = false;
  1491. bool indeterminate = (bar->minimum == 0 && bar->maximum == 0);
  1492. bool complete = bar->progress == bar->maximum;
  1493. // Get extra style options if version 2
  1494. vertical = (bar->orientation == Qt::Vertical);
  1495. inverted = bar->invertedAppearance;
  1496. // If the orientation is vertical, we use a transform to rotate
  1497. // the progress bar 90 degrees clockwise. This way we can use the
  1498. // same rendering code for both orientations.
  1499. if (vertical) {
  1500. rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // flip width and height
  1501. QTransform m = QTransform::fromTranslate(rect.height()-1, -1.0);
  1502. m.rotate(90.0);
  1503. painter->setTransform(m, true);
  1504. }
  1505. int maxWidth = rect.width();
  1506. int minWidth = 0;
  1507. qreal progress = qMax(bar->progress, bar->minimum); // workaround for bug in QProgressBar
  1508. int progressBarWidth = (progress - bar->minimum) * qreal(maxWidth) / qMax(qreal(1.0), qreal(bar->maximum) - bar->minimum);
  1509. int width = indeterminate ? maxWidth : qMax(minWidth, progressBarWidth);
  1510. bool reverse = (!vertical && (bar->direction == Qt::RightToLeft)) || vertical;
  1511. if (inverted)
  1512. reverse = !reverse;
  1513. int step = 0;
  1514. QRect progressBar;
  1515. QColor highlight = d->highlight(option->palette);
  1516. QColor highlightedoutline = highlight.darker(140);
  1517. if (qGray(outline.rgb()) > qGray(highlightedoutline.rgb()))
  1518. outline = highlightedoutline;
  1519. if (!indeterminate) {
  1520. QColor innerShadow(Qt::black);
  1521. innerShadow.setAlpha(35);
  1522. painter->setPen(innerShadow);
  1523. if (!reverse) {
  1524. progressBar.setRect(rect.left(), rect.top(), width - 1, rect.height() - 1);
  1525. if (!complete) {
  1526. painter->drawLine(progressBar.topRight() + QPoint(2, 1), progressBar.bottomRight() + QPoint(2, 0));
  1527. painter->setPen(QPen(highlight.darker(140), 0));
  1528. painter->drawLine(progressBar.topRight() + QPoint(1, 1), progressBar.bottomRight() + QPoint(1, 0));
  1529. }
  1530. } else {
  1531. progressBar.setRect(rect.right() - width - 1, rect.top(), width + 2, rect.height() - 1);
  1532. if (!complete) {
  1533. painter->drawLine(progressBar.topLeft() + QPoint(-2, 1), progressBar.bottomLeft() + QPoint(-2, 0));
  1534. painter->setPen(QPen(highlight.darker(140), 0));
  1535. painter->drawLine(progressBar.topLeft() + QPoint(-1, 1), progressBar.bottomLeft() + QPoint(-1, 0));
  1536. }
  1537. }
  1538. } else {
  1539. progressBar.setRect(rect.left(), rect.top(), rect.width() - 1, rect.height() - 1);
  1540. }
  1541. if (indeterminate || bar->progress > bar->minimum) {
  1542. painter->setPen(QPen(outline, 0));
  1543. QColor highlightedGradientStartColor = highlight.lighter(120);
  1544. QColor highlightedGradientStopColor = highlight;
  1545. QLinearGradient gradient(rect.topLeft(), QPoint(rect.bottomLeft().x(), rect.bottomLeft().y()));
  1546. gradient.setColorAt(0, highlightedGradientStartColor);
  1547. gradient.setColorAt(1, highlightedGradientStopColor);
  1548. painter->setBrush(gradient);
  1549. painter->save();
  1550. if (!complete && !indeterminate)
  1551. painter->setClipRect(progressBar.adjusted(-1, -1, -1, 1));
  1552. QRect fillRect = progressBar.adjusted( !indeterminate && !complete && reverse ? -2 : 0, 0,
  1553. indeterminate || complete || reverse ? 0 : 2, 0);
  1554. painter->drawRoundedRect(fillRect, 2, 2);
  1555. painter->restore();
  1556. painter->setBrush(Qt::NoBrush);
  1557. painter->setPen(QColor(255, 255, 255, 50));
  1558. painter->drawRoundedRect(progressBar.adjusted(1, 1, -1, -1), 1, 1);
  1559. if (!indeterminate) {
  1560. d->stopAnimation(widget);
  1561. } else {
  1562. highlightedGradientStartColor.setAlpha(120);
  1563. painter->setPen(QPen(highlightedGradientStartColor, 9.0));
  1564. painter->setClipRect(progressBar.adjusted(1, 1, -1, -1));
  1565. #ifndef QT_NO_ANIMATION
  1566. if (CarlaProgressStyleAnimation *animation = qobject_cast<CarlaProgressStyleAnimation*>(d->animation(widget)))
  1567. step = animation->animationStep() % 22;
  1568. else
  1569. d->startAnimation(new CarlaProgressStyleAnimation(d->animationFps(), const_cast<QWidget*>(widget)));
  1570. #endif
  1571. for (int x = progressBar.left() - rect.height(); x < rect.right() ; x += 22)
  1572. painter->drawLine(x + step, progressBar.bottom() + 1,
  1573. x + rect.height() + step, progressBar.top() - 2);
  1574. }
  1575. }
  1576. }
  1577. painter->restore();
  1578. break;
  1579. case CE_ProgressBarLabel:
  1580. if (const QStyleOptionProgressBarV2 *bar = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(option)) {
  1581. QRect leftRect;
  1582. QRect rect = bar->rect;
  1583. QColor textColor = option->palette.text().color();
  1584. QColor alternateTextColor = d->highlightedText(option->palette);
  1585. painter->save();
  1586. bool vertical = false, inverted = false;
  1587. vertical = (bar->orientation == Qt::Vertical);
  1588. inverted = bar->invertedAppearance;
  1589. if (vertical)
  1590. rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // flip width and height
  1591. const int progressIndicatorPos = (bar->progress - qreal(bar->minimum)) * rect.width() /
  1592. qMax(qreal(1.0), qreal(bar->maximum) - bar->minimum);
  1593. if (progressIndicatorPos >= 0 && progressIndicatorPos <= rect.width())
  1594. leftRect = QRect(rect.left(), rect.top(), progressIndicatorPos, rect.height());
  1595. if (vertical)
  1596. leftRect.translate(rect.width() - progressIndicatorPos, 0);
  1597. bool flip = (!vertical && (((bar->direction == Qt::RightToLeft) && !inverted) ||
  1598. ((bar->direction == Qt::LeftToRight) && inverted)));
  1599. QRegion rightRect = rect;
  1600. rightRect = rightRect.subtracted(leftRect);
  1601. painter->setClipRegion(rightRect);
  1602. painter->setPen(flip ? alternateTextColor : textColor);
  1603. painter->drawText(rect, bar->text, QTextOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter));
  1604. if (!leftRect.isNull()) {
  1605. painter->setPen(flip ? textColor : alternateTextColor);
  1606. painter->setClipRect(leftRect);
  1607. painter->drawText(rect, bar->text, QTextOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter));
  1608. }
  1609. painter->restore();
  1610. }
  1611. break;
  1612. case CE_MenuBarItem:
  1613. painter->save();
  1614. if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option))
  1615. {
  1616. QStyleOptionMenuItem item = *mbi;
  1617. item.rect = mbi->rect.adjusted(0, 1, 0, -3);
  1618. QColor highlightOutline = option->palette.highlight().color().darker(125);
  1619. painter->fillRect(rect, option->palette.window());
  1620. QCommonStyle::drawControl(element, &item, painter, widget);
  1621. bool act = mbi->state & State_Selected && mbi->state & State_Sunken;
  1622. bool dis = !(mbi->state & State_Enabled);
  1623. QRect r = option->rect;
  1624. if (act)
  1625. {
  1626. painter->setBrush(option->palette.highlight().color());
  1627. painter->setPen(QPen(highlightOutline, 0));
  1628. painter->drawRect(r.adjusted(0, 5, -1, -1));
  1629. painter->drawRoundedRect(r.adjusted(0, 0, -1, -1), 2, 2);
  1630. //draw text
  1631. QPalette::ColorRole textRole = dis ? QPalette::Text : QPalette::HighlightedText;
  1632. uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
  1633. if (!styleHint(SH_UnderlineShortcut, mbi, widget))
  1634. alignment |= Qt::TextHideMnemonic;
  1635. proxy()->drawItemText(painter, item.rect, alignment, mbi->palette, mbi->state & State_Enabled, mbi->text, textRole);
  1636. }
  1637. else
  1638. {
  1639. QColor shadow = mergedColors(option->palette.background().color().darker(120),
  1640. outline.lighter(140), 60);
  1641. painter->setPen(QPen(shadow));
  1642. painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
  1643. }
  1644. }
  1645. painter->restore();
  1646. break;
  1647. case CE_MenuItem:
  1648. painter->save();
  1649. // Draws one item in a popup menu.
  1650. if (const QStyleOptionMenuItem* menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
  1651. QColor highlightOutline = highlightedOutline;
  1652. QColor highlight = option->palette.highlight().color();
  1653. if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) {
  1654. int w = 0;
  1655. if (!menuItem->text.isEmpty()) {
  1656. painter->setFont(menuItem->font);
  1657. proxy()->drawItemText(painter, menuItem->rect.adjusted(5, 0, -5, 0), Qt::AlignLeft | Qt::AlignVCenter,
  1658. menuItem->palette, menuItem->state & State_Enabled, menuItem->text,
  1659. QPalette::Text);
  1660. w = menuItem->fontMetrics.width(menuItem->text) + 5;
  1661. }
  1662. painter->setPen(highlight);
  1663. bool reverse = menuItem->direction == Qt::RightToLeft;
  1664. painter->drawLine(menuItem->rect.left() + 5 + (reverse ? 0 : w), menuItem->rect.center().y(),
  1665. menuItem->rect.right() - 5 - (reverse ? w : 0), menuItem->rect.center().y());
  1666. painter->restore();
  1667. break;
  1668. }
  1669. bool selected = menuItem->state & State_Selected && menuItem->state & State_Enabled;
  1670. if (selected) {
  1671. QRect r = option->rect;
  1672. painter->fillRect(r, highlight);
  1673. painter->setPen(QPen(highlightOutline, 0));
  1674. const QLine lines[4] = {
  1675. QLine(QPoint(r.left() + 1, r.bottom()), QPoint(r.right() - 1, r.bottom())),
  1676. QLine(QPoint(r.left() + 1, r.top()), QPoint(r.right() - 1, r.top())),
  1677. QLine(QPoint(r.left(), r.top()), QPoint(r.left(), r.bottom())),
  1678. QLine(QPoint(r.right() , r.top()), QPoint(r.right(), r.bottom())),
  1679. };
  1680. painter->drawLines(lines, 4);
  1681. }
  1682. bool checkable = menuItem->checkType != QStyleOptionMenuItem::NotCheckable;
  1683. bool checked = menuItem->checked;
  1684. bool sunken = menuItem->state & State_Sunken;
  1685. bool enabled = menuItem->state & State_Enabled;
  1686. bool ignoreCheckMark = false;
  1687. int checkcol = qMax(menuItem->maxIconWidth, 20);
  1688. if (qobject_cast<const QComboBox*>(widget))
  1689. ignoreCheckMark = true; //ignore the checkmarks provided by the QComboMenuDelegate
  1690. if (!ignoreCheckMark) {
  1691. // Check
  1692. QRect checkRect(option->rect.left() + 7, option->rect.center().y() - 6, 14, 14);
  1693. checkRect = visualRect(menuItem->direction, menuItem->rect, checkRect);
  1694. if (checkable) {
  1695. if (menuItem->checkType & QStyleOptionMenuItem::Exclusive) {
  1696. // Radio button
  1697. if (checked || sunken) {
  1698. painter->setRenderHint(QPainter::Antialiasing);
  1699. painter->setPen(Qt::NoPen);
  1700. QPalette::ColorRole textRole = !enabled ? QPalette::Text:
  1701. selected ? QPalette::HighlightedText : QPalette::ButtonText;
  1702. painter->setBrush(option->palette.brush( option->palette.currentColorGroup(), textRole));
  1703. painter->drawEllipse(checkRect.adjusted(4, 4, -4, -4));
  1704. }
  1705. } else {
  1706. // Check box
  1707. if (menuItem->icon.isNull()) {
  1708. QStyleOptionButton box;
  1709. box.QStyleOption::operator=(*option);
  1710. box.rect = checkRect;
  1711. if (checked)
  1712. box.state |= State_On;
  1713. proxy()->drawPrimitive(PE_IndicatorCheckBox, &box, painter, widget);
  1714. painter->setPen(QPen(highlight, 0));
  1715. painter->drawRect(checkRect);
  1716. }
  1717. }
  1718. }
  1719. } else { //ignore checkmark
  1720. if (menuItem->icon.isNull())
  1721. checkcol = 0;
  1722. else
  1723. checkcol = menuItem->maxIconWidth;
  1724. }
  1725. // Text and icon, ripped from windows style
  1726. bool dis = !(menuItem->state & State_Enabled);
  1727. bool act = menuItem->state & State_Selected;
  1728. const QStyleOption *opt = option;
  1729. const QStyleOptionMenuItem *menuitem = menuItem;
  1730. QPainter *p = painter;
  1731. QRect vCheckRect = visualRect(opt->direction, menuitem->rect,
  1732. QRect(menuitem->rect.x() + 4, menuitem->rect.y(),
  1733. checkcol, menuitem->rect.height()));
  1734. if (!menuItem->icon.isNull()) {
  1735. QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
  1736. if (act && !dis)
  1737. mode = QIcon::Active;
  1738. QPixmap pixmap;
  1739. int smallIconSize = proxy()->pixelMetric(PM_SmallIconSize, option, widget);
  1740. QSize iconSize(smallIconSize, smallIconSize);
  1741. if (const QComboBox *combo = qobject_cast<const QComboBox*>(widget))
  1742. iconSize = combo->iconSize();
  1743. if (checked)
  1744. pixmap = menuItem->icon.pixmap(iconSize, mode, QIcon::On);
  1745. else
  1746. pixmap = menuItem->icon.pixmap(iconSize, mode);
  1747. int pixw = pixmap.width();
  1748. int pixh = pixmap.height();
  1749. QRect pmr(0, 0, pixw, pixh);
  1750. pmr.moveCenter(vCheckRect.center());
  1751. painter->setPen(menuItem->palette.text().color());
  1752. if (checkable && checked) {
  1753. QStyleOption opt = *option;
  1754. if (act) {
  1755. QColor activeColor = mergedColors(option->palette.background().color(),
  1756. option->palette.highlight().color());
  1757. opt.palette.setBrush(QPalette::Button, activeColor);
  1758. }
  1759. opt.state |= State_Sunken;
  1760. opt.rect = vCheckRect;
  1761. proxy()->drawPrimitive(PE_PanelButtonCommand, &opt, painter, widget);
  1762. }
  1763. painter->drawPixmap(pmr.topLeft(), pixmap);
  1764. }
  1765. if (selected) {
  1766. painter->setPen(menuItem->palette.highlightedText().color());
  1767. } else {
  1768. painter->setPen(menuItem->palette.text().color());
  1769. }
  1770. int x, y, w, h;
  1771. menuitem->rect.getRect(&x, &y, &w, &h);
  1772. int tab = menuitem->tabWidth;
  1773. QColor discol;
  1774. if (dis) {
  1775. discol = menuitem->palette.text().color();
  1776. p->setPen(discol);
  1777. }
  1778. int xm = windowsItemFrame + checkcol + windowsItemHMargin + 2;
  1779. int xpos = menuitem->rect.x() + xm;
  1780. QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
  1781. QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
  1782. QString s = menuitem->text;
  1783. if (!s.isEmpty()) { // draw text
  1784. p->save();
  1785. int t = s.indexOf(QLatin1Char('\t'));
  1786. int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
  1787. if (!styleHint(SH_UnderlineShortcut, menuitem, widget))
  1788. text_flags |= Qt::TextHideMnemonic;
  1789. text_flags |= Qt::AlignLeft;
  1790. if (t >= 0) {
  1791. QRect vShortcutRect = visualRect(opt->direction, menuitem->rect,
  1792. QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom())));
  1793. if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, option, widget)) {
  1794. p->setPen(menuitem->palette.light().color());
  1795. p->drawText(vShortcutRect.adjusted(1, 1, 1, 1), text_flags, s.mid(t + 1));
  1796. p->setPen(discol);
  1797. }
  1798. p->drawText(vShortcutRect, text_flags, s.mid(t + 1));
  1799. s = s.left(t);
  1800. }
  1801. QFont font = menuitem->font;
  1802. // font may not have any "hard" flags set. We override
  1803. // the point size so that when it is resolved against the device, this font will win.
  1804. // This is mainly to handle cases where someone sets the font on the window
  1805. // and then the combo inherits it and passes it onward. At that point the resolve mask
  1806. // is very, very weak. This makes it stonger.
  1807. font.setPointSizeF(QFontInfo(menuItem->font).pointSizeF());
  1808. if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
  1809. font.setBold(true);
  1810. p->setFont(font);
  1811. if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, option, widget)) {
  1812. p->setPen(menuitem->palette.light().color());
  1813. p->drawText(vTextRect.adjusted(1, 1, 1, 1), text_flags, s.left(t));
  1814. p->setPen(discol);
  1815. }
  1816. p->drawText(vTextRect, text_flags, s.left(t));
  1817. p->restore();
  1818. }
  1819. // Arrow
  1820. if (menuItem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow
  1821. int dim = (menuItem->rect.height() - 4) / 2;
  1822. PrimitiveElement arrow;
  1823. arrow = option->direction == Qt::RightToLeft ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
  1824. int xpos = menuItem->rect.left() + menuItem->rect.width() - 3 - dim;
  1825. QRect vSubMenuRect = visualRect(option->direction, menuItem->rect,
  1826. QRect(xpos, menuItem->rect.top() + menuItem->rect.height() / 2 - dim / 2, dim, dim));
  1827. QStyleOptionMenuItem newMI = *menuItem;
  1828. newMI.rect = vSubMenuRect;
  1829. newMI.state = !enabled ? State_None : State_Enabled;
  1830. if (selected)
  1831. newMI.palette.setColor(QPalette::Foreground,
  1832. newMI.palette.highlightedText().color());
  1833. proxy()->drawPrimitive(arrow, &newMI, painter, widget);
  1834. }
  1835. }
  1836. painter->restore();
  1837. break;
  1838. case CE_MenuHMargin:
  1839. case CE_MenuVMargin:
  1840. break;
  1841. case CE_MenuEmptyArea:
  1842. break;
  1843. case CE_PushButton:
  1844. if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
  1845. proxy()->drawControl(CE_PushButtonBevel, btn, painter, widget);
  1846. QStyleOptionButton subopt = *btn;
  1847. subopt.rect = subElementRect(SE_PushButtonContents, btn, widget);
  1848. proxy()->drawControl(CE_PushButtonLabel, &subopt, painter, widget);
  1849. }
  1850. break;
  1851. case CE_PushButtonLabel:
  1852. if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {
  1853. QRect ir = button->rect;
  1854. uint tf = Qt::AlignVCenter;
  1855. if (styleHint(SH_UnderlineShortcut, button, widget))
  1856. tf |= Qt::TextShowMnemonic;
  1857. else
  1858. tf |= Qt::TextHideMnemonic;
  1859. if (!button->icon.isNull()) {
  1860. //Center both icon and text
  1861. QPoint point;
  1862. QIcon::Mode mode = button->state & State_Enabled ? QIcon::Normal
  1863. : QIcon::Disabled;
  1864. if (mode == QIcon::Normal && button->state & State_HasFocus)
  1865. mode = QIcon::Active;
  1866. QIcon::State state = QIcon::Off;
  1867. if (button->state & State_On)
  1868. state = QIcon::On;
  1869. QPixmap pixmap = button->icon.pixmap(button->iconSize, mode, state);
  1870. int w = pixmap.width();
  1871. int h = pixmap.height();
  1872. if (!button->text.isEmpty())
  1873. w += button->fontMetrics.boundingRect(option->rect, tf, button->text).width() + 2;
  1874. point = QPoint(ir.x() + ir.width() / 2 - w / 2,
  1875. ir.y() + ir.height() / 2 - h / 2);
  1876. if (button->direction == Qt::RightToLeft)
  1877. point.rx() += pixmap.width();
  1878. painter->drawPixmap(visualPos(button->direction, button->rect, point), pixmap);
  1879. if (button->direction == Qt::RightToLeft)
  1880. ir.translate(-point.x() - 2, 0);
  1881. else
  1882. ir.translate(point.x() + pixmap.width(), 0);
  1883. // left-align text if there is
  1884. if (!button->text.isEmpty())
  1885. tf |= Qt::AlignLeft;
  1886. } else {
  1887. tf |= Qt::AlignHCenter;
  1888. }
  1889. if (button->features & QStyleOptionButton::HasMenu)
  1890. ir = ir.adjusted(0, 0, -proxy()->pixelMetric(PM_MenuButtonIndicator, button, widget), 0);
  1891. proxy()->drawItemText(painter, ir, tf, button->palette, (button->state & State_Enabled),
  1892. button->text, QPalette::ButtonText);
  1893. }
  1894. break;
  1895. case CE_MenuBarEmptyArea:
  1896. painter->save();
  1897. {
  1898. painter->fillRect(rect, option->palette.window());
  1899. if (widget && qobject_cast<const QMainWindow *>(widget->parentWidget())) {
  1900. QColor shadow = mergedColors(option->palette.background().color().darker(120),
  1901. outline.lighter(140), 60);
  1902. painter->setPen(QPen(shadow));
  1903. painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
  1904. }
  1905. }
  1906. painter->restore();
  1907. break;
  1908. case CE_TabBarTabShape:
  1909. painter->save();
  1910. if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) {
  1911. bool rtlHorTabs = (tab->direction == Qt::RightToLeft
  1912. && (tab->shape == QTabBar::RoundedNorth
  1913. || tab->shape == QTabBar::RoundedSouth));
  1914. bool selected = tab->state & State_Selected;
  1915. bool lastTab = ((!rtlHorTabs && tab->position == QStyleOptionTab::End)
  1916. || (rtlHorTabs
  1917. && tab->position == QStyleOptionTab::Beginning));
  1918. bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab;
  1919. int tabOverlap = pixelMetric(PM_TabBarTabOverlap, option, widget);
  1920. rect = option->rect.adjusted(0, 0, (onlyOne || lastTab) ? 0 : tabOverlap, 0);
  1921. QRect r2(rect);
  1922. int x1 = r2.left();
  1923. int x2 = r2.right();
  1924. int y1 = r2.top();
  1925. int y2 = r2.bottom();
  1926. painter->setPen(d->innerContrastLine());
  1927. QTransform rotMatrix;
  1928. bool flip = false;
  1929. painter->setPen(shadow);
  1930. switch (tab->shape) {
  1931. case QTabBar::RoundedNorth:
  1932. break;
  1933. case QTabBar::RoundedSouth:
  1934. rotMatrix.rotate(180);
  1935. rotMatrix.translate(0, -rect.height() + 1);
  1936. rotMatrix.scale(-1, 1);
  1937. painter->setTransform(rotMatrix, true);
  1938. break;
  1939. case QTabBar::RoundedWest:
  1940. rotMatrix.rotate(180 + 90);
  1941. rotMatrix.scale(-1, 1);
  1942. flip = true;
  1943. painter->setTransform(rotMatrix, true);
  1944. break;
  1945. case QTabBar::RoundedEast:
  1946. rotMatrix.rotate(90);
  1947. rotMatrix.translate(0, - rect.width() + 1);
  1948. flip = true;
  1949. painter->setTransform(rotMatrix, true);
  1950. break;
  1951. default:
  1952. painter->restore();
  1953. QCommonStyle::drawControl(element, tab, painter, widget);
  1954. return;
  1955. }
  1956. if (flip) {
  1957. QRect tmp = rect;
  1958. rect = QRect(tmp.y(), tmp.x(), tmp.height(), tmp.width());
  1959. int temp = x1;
  1960. x1 = y1;
  1961. y1 = temp;
  1962. temp = x2;
  1963. x2 = y2;
  1964. y2 = temp;
  1965. }
  1966. painter->setRenderHint(QPainter::Antialiasing, true);
  1967. painter->translate(0.5, 0.5);
  1968. QColor tabFrameColor = d->tabFrameColor(option->palette);
  1969. QLinearGradient fillGradient(rect.topLeft(), rect.bottomLeft());
  1970. QLinearGradient outlineGradient(rect.topLeft(), rect.bottomLeft());
  1971. QPen outlinePen = outline.lighter(110);
  1972. if (selected) {
  1973. fillGradient.setColorAt(0, tabFrameColor.lighter(104));
  1974. // QColor highlight = option->palette.highlight().color();
  1975. // if (option->state & State_HasFocus && option->state & State_KeyboardFocusChange) {
  1976. // fillGradient.setColorAt(0, highlight.lighter(130));
  1977. // outlineGradient.setColorAt(0, highlight.darker(130));
  1978. // fillGradient.setColorAt(0.14, highlight);
  1979. // outlineGradient.setColorAt(0.14, highlight.darker(130));
  1980. // fillGradient.setColorAt(0.1401, tabFrameColor);
  1981. // outlineGradient.setColorAt(0.1401, highlight.darker(130));
  1982. // }
  1983. fillGradient.setColorAt(1, tabFrameColor);
  1984. outlineGradient.setColorAt(1, outline);
  1985. outlinePen = QPen(outlineGradient, 1);
  1986. } else {
  1987. fillGradient.setColorAt(0, tabFrameColor.darker(108));
  1988. fillGradient.setColorAt(0.85, tabFrameColor.darker(108));
  1989. fillGradient.setColorAt(1, tabFrameColor.darker(116));
  1990. }
  1991. QRect drawRect = rect.adjusted(0, selected ? 0 : 2, 0, 3);
  1992. painter->setPen(outlinePen);
  1993. painter->save();
  1994. painter->setClipRect(rect.adjusted(-1, -1, 1, selected ? -2 : -3));
  1995. painter->setBrush(fillGradient);
  1996. painter->drawRoundedRect(drawRect.adjusted(0, 0, -1, -1), 2.0, 2.0);
  1997. painter->setBrush(Qt::NoBrush);
  1998. painter->setPen(d->innerContrastLine());
  1999. painter->drawRoundedRect(drawRect.adjusted(1, 1, -2, -1), 2.0, 2.0);
  2000. painter->restore();
  2001. if (selected) {
  2002. painter->fillRect(rect.left() + 1, rect.bottom() - 1, rect.width() - 2, rect.bottom() - 1, tabFrameColor);
  2003. painter->fillRect(QRect(rect.bottomRight() + QPoint(-2, -1), QSize(1, 1)), d->innerContrastLine());
  2004. painter->fillRect(QRect(rect.bottomLeft() + QPoint(0, -1), QSize(1, 1)), d->innerContrastLine());
  2005. painter->fillRect(QRect(rect.bottomRight() + QPoint(-1, -1), QSize(1, 1)), d->innerContrastLine());
  2006. }
  2007. }
  2008. painter->restore();
  2009. break;
  2010. default:
  2011. QCommonStyle::drawControl(element,option,painter,widget);
  2012. break;
  2013. }
  2014. }
  2015. /*!
  2016. \reimp
  2017. */
  2018. QPalette CarlaStyle::standardPalette () const
  2019. {
  2020. QPalette palette = QCommonStyle::standardPalette();
  2021. palette.setBrush(QPalette::Active, QPalette::Highlight, QColor(48, 140, 198));
  2022. palette.setBrush(QPalette::Inactive, QPalette::Highlight, QColor(145, 141, 126));
  2023. palette.setBrush(QPalette::Disabled, QPalette::Highlight, QColor(145, 141, 126));
  2024. QColor backGround(239, 235, 231);
  2025. QColor light = backGround.lighter(150);
  2026. QColor base = Qt::white;
  2027. QColor dark = QColor(170, 156, 143).darker(110);
  2028. dark = backGround.darker(150);
  2029. QColor darkDisabled = QColor(209, 200, 191).darker(110);
  2030. //### Find the correct disabled text color
  2031. palette.setBrush(QPalette::Disabled, QPalette::Text, QColor(190, 190, 190));
  2032. palette.setBrush(QPalette::Window, backGround);
  2033. palette.setBrush(QPalette::Mid, backGround.darker(130));
  2034. palette.setBrush(QPalette::Light, light);
  2035. palette.setBrush(QPalette::Active, QPalette::Base, base);
  2036. palette.setBrush(QPalette::Inactive, QPalette::Base, base);
  2037. palette.setBrush(QPalette::Disabled, QPalette::Base, backGround);
  2038. palette.setBrush(QPalette::Midlight, palette.mid().color().lighter(110));
  2039. palette.setBrush(QPalette::All, QPalette::Dark, dark);
  2040. palette.setBrush(QPalette::Disabled, QPalette::Dark, darkDisabled);
  2041. QColor button = backGround;
  2042. palette.setBrush(QPalette::Button, button);
  2043. QColor shadow = dark.darker(135);
  2044. palette.setBrush(QPalette::Shadow, shadow);
  2045. palette.setBrush(QPalette::Disabled, QPalette::Shadow, shadow.lighter(150));
  2046. palette.setBrush(QPalette::HighlightedText, QColor(QRgb(0xffffffff)));
  2047. return palette;
  2048. }
  2049. /*!
  2050. \reimp
  2051. */
  2052. void CarlaStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
  2053. QPainter *painter, const QWidget *widget) const
  2054. {
  2055. QColor buttonColor = d->buttonColor(option->palette);
  2056. QColor gradientStartColor = buttonColor.lighter(118);
  2057. QColor gradientStopColor = buttonColor;
  2058. QColor outline = d->outline(option->palette);
  2059. QColor alphaCornerColor;
  2060. if (widget) {
  2061. // ### backgroundrole/foregroundrole should be part of the style option
  2062. alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), outline);
  2063. } else {
  2064. alphaCornerColor = mergedColors(option->palette.background().color(), outline);
  2065. }
  2066. switch (control) {
  2067. case CC_GroupBox:
  2068. painter->save();
  2069. if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
  2070. // Draw frame
  2071. QRect textRect = proxy()->subControlRect(CC_GroupBox, option, SC_GroupBoxLabel, widget);
  2072. QRect checkBoxRect = proxy()->subControlRect(CC_GroupBox, option, SC_GroupBoxCheckBox, widget);
  2073. if (groupBox->subControls & QStyle::SC_GroupBoxFrame) {
  2074. QStyleOptionFrameV3 frame;
  2075. frame.QStyleOption::operator=(*groupBox);
  2076. frame.features = groupBox->features;
  2077. frame.lineWidth = groupBox->lineWidth;
  2078. frame.midLineWidth = groupBox->midLineWidth;
  2079. frame.rect = proxy()->subControlRect(CC_GroupBox, option, SC_GroupBoxFrame, widget);
  2080. proxy()->drawPrimitive(PE_FrameGroupBox, &frame, painter, widget);
  2081. }
  2082. // Draw title
  2083. if ((groupBox->subControls & QStyle::SC_GroupBoxLabel) && !groupBox->text.isEmpty()) {
  2084. // groupBox->textColor gets the incorrect palette here
  2085. painter->setPen(QPen(option->palette.windowText(), 1));
  2086. int alignment = int(groupBox->textAlignment);
  2087. if (!proxy()->styleHint(QStyle::SH_UnderlineShortcut, option, widget))
  2088. alignment |= Qt::TextHideMnemonic;
  2089. proxy()->drawItemText(painter, textRect, Qt::TextShowMnemonic | Qt::AlignLeft | alignment,
  2090. groupBox->palette, groupBox->state & State_Enabled, groupBox->text, QPalette::NoRole);
  2091. if (groupBox->state & State_HasFocus) {
  2092. QStyleOptionFocusRect fropt;
  2093. fropt.QStyleOption::operator=(*groupBox);
  2094. fropt.rect = textRect.adjusted(-2, -1, 2, 1);
  2095. proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
  2096. }
  2097. }
  2098. // Draw checkbox
  2099. if (groupBox->subControls & SC_GroupBoxCheckBox) {
  2100. QStyleOptionButton box;
  2101. box.QStyleOption::operator=(*groupBox);
  2102. box.rect = checkBoxRect;
  2103. proxy()->drawPrimitive(PE_IndicatorCheckBox, &box, painter, widget);
  2104. }
  2105. }
  2106. painter->restore();
  2107. break;
  2108. case CC_SpinBox:
  2109. if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
  2110. QPixmap cache;
  2111. QString pixmapName = uniqueName(QLatin1String("spinbox"), spinBox, spinBox->rect.size());
  2112. if (!QPixmapCache::find(pixmapName, cache)) {
  2113. cache = styleCachePixmap(spinBox->rect.size());
  2114. cache.fill(Qt::transparent);
  2115. QRect pixmapRect(0, 0, spinBox->rect.width(), spinBox->rect.height());
  2116. QRect rect = pixmapRect;
  2117. QRect r = rect.adjusted(0, 1, 0, -1);
  2118. QPainter cachePainter(&cache);
  2119. QColor arrowColor = spinBox->palette.foreground().color();
  2120. arrowColor.setAlpha(220);
  2121. bool isEnabled = (spinBox->state & State_Enabled);
  2122. bool hover = isEnabled && (spinBox->state & State_MouseOver);
  2123. bool sunken = (spinBox->state & State_Sunken);
  2124. bool upIsActive = (spinBox->activeSubControls == SC_SpinBoxUp);
  2125. bool downIsActive = (spinBox->activeSubControls == SC_SpinBoxDown);
  2126. bool hasFocus = (option->state & State_HasFocus);
  2127. QStyleOptionSpinBox spinBoxCopy = *spinBox;
  2128. spinBoxCopy.rect = pixmapRect;
  2129. QRect upRect = proxy()->subControlRect(CC_SpinBox, &spinBoxCopy, SC_SpinBoxUp, widget);
  2130. QRect downRect = proxy()->subControlRect(CC_SpinBox, &spinBoxCopy, SC_SpinBoxDown, widget);
  2131. if (spinBox->frame) {
  2132. cachePainter.save();
  2133. cachePainter.setRenderHint(QPainter::Antialiasing, true);
  2134. cachePainter.translate(0.5, 0.5);
  2135. // Fill background
  2136. cachePainter.setPen(Qt::NoPen);
  2137. cachePainter.setBrush(option->palette.base());
  2138. cachePainter.drawRoundedRect(r.adjusted(0, 0, -1, -1), 2, 2);
  2139. // Draw inner shadow
  2140. cachePainter.setPen(d->topShadow());
  2141. cachePainter.drawLine(QPoint(r.left() + 2, r.top() + 1), QPoint(r.right() - 2, r.top() + 1));
  2142. // Draw button gradient
  2143. QColor buttonColor = d->buttonColor(option->palette);
  2144. QRect updownRect = upRect.adjusted(0, -2, 0, downRect.height() + 2);
  2145. QLinearGradient gradient = qt_fusion_gradient(updownRect, (isEnabled && option->state & State_MouseOver ) ? buttonColor : buttonColor.darker(104));
  2146. // Draw button gradient
  2147. cachePainter.setPen(Qt::NoPen);
  2148. cachePainter.setBrush(gradient);
  2149. cachePainter.save();
  2150. cachePainter.setClipRect(updownRect);
  2151. cachePainter.drawRoundedRect(r.adjusted(0, 0, -1, -1), 2, 2);
  2152. cachePainter.setPen(QPen(d->innerContrastLine()));
  2153. cachePainter.setBrush(Qt::NoBrush);
  2154. cachePainter.drawRoundedRect(r.adjusted(1, 1, -2, -2), 2, 2);
  2155. cachePainter.restore();
  2156. if ((spinBox->stepEnabled & QAbstractSpinBox::StepUpEnabled) && upIsActive) {
  2157. if (sunken)
  2158. cachePainter.fillRect(upRect.adjusted(0, -1, 0, 0), gradientStopColor.darker(110));
  2159. else if (hover)
  2160. cachePainter.fillRect(upRect.adjusted(0, -1, 0, 0), d->innerContrastLine());
  2161. }
  2162. if ((spinBox->stepEnabled & QAbstractSpinBox::StepDownEnabled) && downIsActive) {
  2163. if (sunken)
  2164. cachePainter.fillRect(downRect.adjusted(0, 0, 0, 1), gradientStopColor.darker(110));
  2165. else if (hover)
  2166. cachePainter.fillRect(downRect.adjusted(0, 0, 0, 1), d->innerContrastLine());
  2167. }
  2168. QColor highlightOutline = d->highlightedOutline(option->palette);
  2169. cachePainter.setPen(hasFocus ? highlightOutline : highlightOutline.darker(160));
  2170. cachePainter.setBrush(Qt::NoBrush);
  2171. cachePainter.drawRoundedRect(r.adjusted(0, 0, -1, -1), 2, 2);
  2172. if (hasFocus) {
  2173. QColor softHighlight = option->palette.highlight().color();
  2174. softHighlight.setAlpha(40);
  2175. cachePainter.setPen(softHighlight);
  2176. cachePainter.drawRoundedRect(r.adjusted(1, 1, -2, -2), 1.7, 1.7);
  2177. }
  2178. cachePainter.restore();
  2179. }
  2180. // outline the up/down buttons
  2181. cachePainter.setPen(outline);
  2182. if (spinBox->direction == Qt::RightToLeft) {
  2183. cachePainter.drawLine(upRect.right(), upRect.top() - 1, upRect.right(), downRect.bottom() + 1);
  2184. } else {
  2185. cachePainter.drawLine(upRect.left(), upRect.top() - 1, upRect.left(), downRect.bottom() + 1);
  2186. }
  2187. if (upIsActive && sunken) {
  2188. cachePainter.setPen(gradientStopColor.darker(130));
  2189. cachePainter.drawLine(downRect.left() + 1, downRect.top(), downRect.right(), downRect.top());
  2190. cachePainter.drawLine(upRect.left() + 1, upRect.top(), upRect.left() + 1, upRect.bottom());
  2191. cachePainter.drawLine(upRect.left() + 1, upRect.top() - 1, upRect.right(), upRect.top() - 1);
  2192. }
  2193. if (downIsActive && sunken) {
  2194. cachePainter.setPen(gradientStopColor.darker(130));
  2195. cachePainter.drawLine(downRect.left() + 1, downRect.top(), downRect.left() + 1, downRect.bottom() + 1);
  2196. cachePainter.drawLine(downRect.left() + 1, downRect.top(), downRect.right(), downRect.top());
  2197. cachePainter.setPen(gradientStopColor.darker(110));
  2198. cachePainter.drawLine(downRect.left() + 1, downRect.bottom() + 1, downRect.right(), downRect.bottom() + 1);
  2199. }
  2200. QColor disabledColor = mergedColors(arrowColor, option->palette.button().color());
  2201. if (spinBox->buttonSymbols == QAbstractSpinBox::PlusMinus) {
  2202. int centerX = upRect.center().x();
  2203. int centerY = upRect.center().y();
  2204. // plus/minus
  2205. cachePainter.setPen((spinBox->stepEnabled & QAbstractSpinBox::StepUpEnabled) ? arrowColor : disabledColor);
  2206. cachePainter.drawLine(centerX - 1, centerY, centerX + 3, centerY);
  2207. cachePainter.drawLine(centerX + 1, centerY - 2, centerX + 1, centerY + 2);
  2208. centerX = downRect.center().x();
  2209. centerY = downRect.center().y();
  2210. cachePainter.setPen((spinBox->stepEnabled & QAbstractSpinBox::StepDownEnabled) ? arrowColor : disabledColor);
  2211. cachePainter.drawLine(centerX - 1, centerY, centerX + 3, centerY);
  2212. } else if (spinBox->buttonSymbols == QAbstractSpinBox::UpDownArrows){
  2213. // arrows
  2214. painter->setRenderHint(QPainter::SmoothPixmapTransform);
  2215. QPixmap upArrow = colorizedImage(QLatin1String(":/bitmaps/style/arrow.png"),
  2216. (spinBox->stepEnabled & QAbstractSpinBox::StepUpEnabled) ? arrowColor : disabledColor);
  2217. cachePainter.drawPixmap(QRect(upRect.center().x() - upArrow.width() / 4 + 1,
  2218. upRect.center().y() - upArrow.height() / 4 + 1,
  2219. upArrow.width()/2, upArrow.height()/2), upArrow);
  2220. QPixmap downArrow = colorizedImage(QLatin1String(":/bitmaps/style/arrow.png"),
  2221. (spinBox->stepEnabled & QAbstractSpinBox::StepDownEnabled) ? arrowColor : disabledColor, 180);
  2222. cachePainter.drawPixmap(QRect(downRect.center().x() - downArrow.width() / 4 + 1,
  2223. downRect.center().y() - downArrow.height() / 4 + 1,
  2224. downArrow.width()/2, downArrow.height()/2), downArrow);
  2225. }
  2226. cachePainter.end();
  2227. QPixmapCache::insert(pixmapName, cache);
  2228. }
  2229. painter->drawPixmap(spinBox->rect.topLeft(), cache);
  2230. }
  2231. break;
  2232. case CC_TitleBar:
  2233. painter->save();
  2234. if (const QStyleOptionTitleBar *titleBar = qstyleoption_cast<const QStyleOptionTitleBar *>(option)) {
  2235. const int buttonMargin = 5;
  2236. bool active = (titleBar->titleBarState & State_Active);
  2237. QRect fullRect = titleBar->rect;
  2238. QPalette palette = option->palette;
  2239. QColor highlight = option->palette.highlight().color();
  2240. QColor titleBarFrameBorder(active ? highlight.darker(180): outline.darker(110));
  2241. QColor titleBarHighlight(active ? highlight.lighter(120): palette.background().color().lighter(120));
  2242. QColor textColor(active ? 0xffffff : 0xff000000);
  2243. QColor textAlphaColor(active ? 0xffffff : 0xff000000 );
  2244. {
  2245. // Fill title bar gradient
  2246. QColor titlebarColor = QColor(active ? highlight: palette.background().color());
  2247. QLinearGradient gradient(option->rect.center().x(), option->rect.top(),
  2248. option->rect.center().x(), option->rect.bottom());
  2249. gradient.setColorAt(0, titlebarColor.lighter(114));
  2250. gradient.setColorAt(0.5, titlebarColor.lighter(102));
  2251. gradient.setColorAt(0.51, titlebarColor.darker(104));
  2252. gradient.setColorAt(1, titlebarColor);
  2253. painter->fillRect(option->rect.adjusted(1, 1, -1, 0), gradient);
  2254. // Frame and rounded corners
  2255. painter->setPen(titleBarFrameBorder);
  2256. // top outline
  2257. painter->drawLine(fullRect.left() + 5, fullRect.top(), fullRect.right() - 5, fullRect.top());
  2258. painter->drawLine(fullRect.left(), fullRect.top() + 4, fullRect.left(), fullRect.bottom());
  2259. const QPoint points[5] = {
  2260. QPoint(fullRect.left() + 4, fullRect.top() + 1),
  2261. QPoint(fullRect.left() + 3, fullRect.top() + 1),
  2262. QPoint(fullRect.left() + 2, fullRect.top() + 2),
  2263. QPoint(fullRect.left() + 1, fullRect.top() + 3),
  2264. QPoint(fullRect.left() + 1, fullRect.top() + 4)
  2265. };
  2266. painter->drawPoints(points, 5);
  2267. painter->drawLine(fullRect.right(), fullRect.top() + 4, fullRect.right(), fullRect.bottom());
  2268. const QPoint points2[5] = {
  2269. QPoint(fullRect.right() - 3, fullRect.top() + 1),
  2270. QPoint(fullRect.right() - 4, fullRect.top() + 1),
  2271. QPoint(fullRect.right() - 2, fullRect.top() + 2),
  2272. QPoint(fullRect.right() - 1, fullRect.top() + 3),
  2273. QPoint(fullRect.right() - 1, fullRect.top() + 4)
  2274. };
  2275. painter->drawPoints(points2, 5);
  2276. // draw bottomline
  2277. painter->drawLine(fullRect.right(), fullRect.bottom(), fullRect.left(), fullRect.bottom());
  2278. // top highlight
  2279. painter->setPen(titleBarHighlight);
  2280. painter->drawLine(fullRect.left() + 6, fullRect.top() + 1, fullRect.right() - 6, fullRect.top() + 1);
  2281. }
  2282. // draw title
  2283. QRect textRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarLabel, widget);
  2284. painter->setPen(active? (titleBar->palette.text().color().lighter(120)) :
  2285. titleBar->palette.text().color() );
  2286. // Note workspace also does elliding but it does not use the correct font
  2287. QString title = painter->fontMetrics().elidedText(titleBar->text, Qt::ElideRight, textRect.width() - 14);
  2288. painter->drawText(textRect.adjusted(1, 1, 1, 1), title, QTextOption(Qt::AlignHCenter | Qt::AlignVCenter));
  2289. painter->setPen(Qt::white);
  2290. if (active)
  2291. painter->drawText(textRect, title, QTextOption(Qt::AlignHCenter | Qt::AlignVCenter));
  2292. // min button
  2293. if ((titleBar->subControls & SC_TitleBarMinButton) && (titleBar->titleBarFlags & Qt::WindowMinimizeButtonHint) &&
  2294. !(titleBar->titleBarState& Qt::WindowMinimized)) {
  2295. QRect minButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarMinButton, widget);
  2296. if (minButtonRect.isValid()) {
  2297. bool hover = (titleBar->activeSubControls & SC_TitleBarMinButton) && (titleBar->state & State_MouseOver);
  2298. bool sunken = (titleBar->activeSubControls & SC_TitleBarMinButton) && (titleBar->state & State_Sunken);
  2299. qt_fusion_draw_mdibutton(painter, titleBar, minButtonRect, hover, sunken);
  2300. QRect minButtonIconRect = minButtonRect.adjusted(buttonMargin ,buttonMargin , -buttonMargin, -buttonMargin);
  2301. painter->setPen(textColor);
  2302. painter->drawLine(minButtonIconRect.center().x() - 2, minButtonIconRect.center().y() + 3,
  2303. minButtonIconRect.center().x() + 3, minButtonIconRect.center().y() + 3);
  2304. painter->drawLine(minButtonIconRect.center().x() - 2, minButtonIconRect.center().y() + 4,
  2305. minButtonIconRect.center().x() + 3, minButtonIconRect.center().y() + 4);
  2306. painter->setPen(textAlphaColor);
  2307. painter->drawLine(minButtonIconRect.center().x() - 3, minButtonIconRect.center().y() + 3,
  2308. minButtonIconRect.center().x() - 3, minButtonIconRect.center().y() + 4);
  2309. painter->drawLine(minButtonIconRect.center().x() + 4, minButtonIconRect.center().y() + 3,
  2310. minButtonIconRect.center().x() + 4, minButtonIconRect.center().y() + 4);
  2311. }
  2312. }
  2313. // max button
  2314. if ((titleBar->subControls & SC_TitleBarMaxButton) && (titleBar->titleBarFlags & Qt::WindowMaximizeButtonHint) &&
  2315. !(titleBar->titleBarState & Qt::WindowMaximized)) {
  2316. QRect maxButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarMaxButton, widget);
  2317. if (maxButtonRect.isValid()) {
  2318. bool hover = (titleBar->activeSubControls & SC_TitleBarMaxButton) && (titleBar->state & State_MouseOver);
  2319. bool sunken = (titleBar->activeSubControls & SC_TitleBarMaxButton) && (titleBar->state & State_Sunken);
  2320. qt_fusion_draw_mdibutton(painter, titleBar, maxButtonRect, hover, sunken);
  2321. QRect maxButtonIconRect = maxButtonRect.adjusted(buttonMargin, buttonMargin, -buttonMargin, -buttonMargin);
  2322. painter->setPen(textColor);
  2323. painter->drawRect(maxButtonIconRect.adjusted(0, 0, -1, -1));
  2324. painter->drawLine(maxButtonIconRect.left() + 1, maxButtonIconRect.top() + 1,
  2325. maxButtonIconRect.right() - 1, maxButtonIconRect.top() + 1);
  2326. painter->setPen(textAlphaColor);
  2327. const QPoint points[4] = {
  2328. maxButtonIconRect.topLeft(),
  2329. maxButtonIconRect.topRight(),
  2330. maxButtonIconRect.bottomLeft(),
  2331. maxButtonIconRect.bottomRight()
  2332. };
  2333. painter->drawPoints(points, 4);
  2334. }
  2335. }
  2336. // close button
  2337. if ((titleBar->subControls & SC_TitleBarCloseButton) && (titleBar->titleBarFlags & Qt::WindowSystemMenuHint)) {
  2338. QRect closeButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarCloseButton, widget);
  2339. if (closeButtonRect.isValid()) {
  2340. bool hover = (titleBar->activeSubControls & SC_TitleBarCloseButton) && (titleBar->state & State_MouseOver);
  2341. bool sunken = (titleBar->activeSubControls & SC_TitleBarCloseButton) && (titleBar->state & State_Sunken);
  2342. qt_fusion_draw_mdibutton(painter, titleBar, closeButtonRect, hover, sunken);
  2343. QRect closeIconRect = closeButtonRect.adjusted(buttonMargin, buttonMargin, -buttonMargin, -buttonMargin);
  2344. painter->setPen(textAlphaColor);
  2345. const QLine lines[4] = {
  2346. QLine(closeIconRect.left() + 1, closeIconRect.top(),
  2347. closeIconRect.right(), closeIconRect.bottom() - 1),
  2348. QLine(closeIconRect.left(), closeIconRect.top() + 1,
  2349. closeIconRect.right() - 1, closeIconRect.bottom()),
  2350. QLine(closeIconRect.right() - 1, closeIconRect.top(),
  2351. closeIconRect.left(), closeIconRect.bottom() - 1),
  2352. QLine(closeIconRect.right(), closeIconRect.top() + 1,
  2353. closeIconRect.left() + 1, closeIconRect.bottom())
  2354. };
  2355. painter->drawLines(lines, 4);
  2356. const QPoint points[4] = {
  2357. closeIconRect.topLeft(),
  2358. closeIconRect.topRight(),
  2359. closeIconRect.bottomLeft(),
  2360. closeIconRect.bottomRight()
  2361. };
  2362. painter->drawPoints(points, 4);
  2363. painter->setPen(textColor);
  2364. painter->drawLine(closeIconRect.left() + 1, closeIconRect.top() + 1,
  2365. closeIconRect.right() - 1, closeIconRect.bottom() - 1);
  2366. painter->drawLine(closeIconRect.left() + 1, closeIconRect.bottom() - 1,
  2367. closeIconRect.right() - 1, closeIconRect.top() + 1);
  2368. }
  2369. }
  2370. // normalize button
  2371. if ((titleBar->subControls & SC_TitleBarNormalButton) &&
  2372. (((titleBar->titleBarFlags & Qt::WindowMinimizeButtonHint) &&
  2373. (titleBar->titleBarState & Qt::WindowMinimized)) ||
  2374. ((titleBar->titleBarFlags & Qt::WindowMaximizeButtonHint) &&
  2375. (titleBar->titleBarState & Qt::WindowMaximized)))) {
  2376. QRect normalButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarNormalButton, widget);
  2377. if (normalButtonRect.isValid()) {
  2378. bool hover = (titleBar->activeSubControls & SC_TitleBarNormalButton) && (titleBar->state & State_MouseOver);
  2379. bool sunken = (titleBar->activeSubControls & SC_TitleBarNormalButton) && (titleBar->state & State_Sunken);
  2380. QRect normalButtonIconRect = normalButtonRect.adjusted(buttonMargin, buttonMargin, -buttonMargin, -buttonMargin);
  2381. qt_fusion_draw_mdibutton(painter, titleBar, normalButtonRect, hover, sunken);
  2382. QRect frontWindowRect = normalButtonIconRect.adjusted(0, 3, -3, 0);
  2383. painter->setPen(textColor);
  2384. painter->drawRect(frontWindowRect.adjusted(0, 0, -1, -1));
  2385. painter->drawLine(frontWindowRect.left() + 1, frontWindowRect.top() + 1,
  2386. frontWindowRect.right() - 1, frontWindowRect.top() + 1);
  2387. painter->setPen(textAlphaColor);
  2388. const QPoint points[4] = {
  2389. frontWindowRect.topLeft(),
  2390. frontWindowRect.topRight(),
  2391. frontWindowRect.bottomLeft(),
  2392. frontWindowRect.bottomRight()
  2393. };
  2394. painter->drawPoints(points, 4);
  2395. QRect backWindowRect = normalButtonIconRect.adjusted(3, 0, 0, -3);
  2396. QRegion clipRegion = backWindowRect;
  2397. clipRegion -= frontWindowRect;
  2398. painter->save();
  2399. painter->setClipRegion(clipRegion);
  2400. painter->setPen(textColor);
  2401. painter->drawRect(backWindowRect.adjusted(0, 0, -1, -1));
  2402. painter->drawLine(backWindowRect.left() + 1, backWindowRect.top() + 1,
  2403. backWindowRect.right() - 1, backWindowRect.top() + 1);
  2404. painter->setPen(textAlphaColor);
  2405. const QPoint points2[4] = {
  2406. backWindowRect.topLeft(),
  2407. backWindowRect.topRight(),
  2408. backWindowRect.bottomLeft(),
  2409. backWindowRect.bottomRight()
  2410. };
  2411. painter->drawPoints(points2, 4);
  2412. painter->restore();
  2413. }
  2414. }
  2415. // context help button
  2416. if (titleBar->subControls & SC_TitleBarContextHelpButton
  2417. && (titleBar->titleBarFlags & Qt::WindowContextHelpButtonHint)) {
  2418. QRect contextHelpButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarContextHelpButton, widget);
  2419. if (contextHelpButtonRect.isValid()) {
  2420. bool hover = (titleBar->activeSubControls & SC_TitleBarContextHelpButton) && (titleBar->state & State_MouseOver);
  2421. bool sunken = (titleBar->activeSubControls & SC_TitleBarContextHelpButton) && (titleBar->state & State_Sunken);
  2422. qt_fusion_draw_mdibutton(painter, titleBar, contextHelpButtonRect, hover, sunken);
  2423. QImage image(qt_titlebar_context_help);
  2424. QColor alpha = textColor;
  2425. alpha.setAlpha(128);
  2426. image.setColor(1, textColor.rgba());
  2427. image.setColor(2, alpha.rgba());
  2428. painter->setRenderHint(QPainter::SmoothPixmapTransform);
  2429. painter->drawImage(contextHelpButtonRect.adjusted(4, 4, -4, -4), image);
  2430. }
  2431. }
  2432. // shade button
  2433. if (titleBar->subControls & SC_TitleBarShadeButton && (titleBar->titleBarFlags & Qt::WindowShadeButtonHint)) {
  2434. QRect shadeButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarShadeButton, widget);
  2435. if (shadeButtonRect.isValid()) {
  2436. bool hover = (titleBar->activeSubControls & SC_TitleBarShadeButton) && (titleBar->state & State_MouseOver);
  2437. bool sunken = (titleBar->activeSubControls & SC_TitleBarShadeButton) && (titleBar->state & State_Sunken);
  2438. qt_fusion_draw_mdibutton(painter, titleBar, shadeButtonRect, hover, sunken);
  2439. QPixmap arrow = colorizedImage(QLatin1String(":/bitmaps/style/arrow.png"), textColor);
  2440. painter->drawPixmap(shadeButtonRect.adjusted(5, 7, -5, -7), arrow);
  2441. }
  2442. }
  2443. // unshade button
  2444. if (titleBar->subControls & SC_TitleBarUnshadeButton && (titleBar->titleBarFlags & Qt::WindowShadeButtonHint)) {
  2445. QRect unshadeButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarUnshadeButton, widget);
  2446. if (unshadeButtonRect.isValid()) {
  2447. bool hover = (titleBar->activeSubControls & SC_TitleBarUnshadeButton) && (titleBar->state & State_MouseOver);
  2448. bool sunken = (titleBar->activeSubControls & SC_TitleBarUnshadeButton) && (titleBar->state & State_Sunken);
  2449. qt_fusion_draw_mdibutton(painter, titleBar, unshadeButtonRect, hover, sunken);
  2450. QPixmap arrow = colorizedImage(QLatin1String(":/bitmaps/style/arrow.png"), textColor, 180);
  2451. painter->drawPixmap(unshadeButtonRect.adjusted(5, 7, -5, -7), arrow);
  2452. }
  2453. }
  2454. if ((titleBar->subControls & SC_TitleBarSysMenu) && (titleBar->titleBarFlags & Qt::WindowSystemMenuHint)) {
  2455. QRect iconRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarSysMenu, widget);
  2456. if (iconRect.isValid()) {
  2457. if (!titleBar->icon.isNull()) {
  2458. titleBar->icon.paint(painter, iconRect);
  2459. } else {
  2460. QStyleOption tool(0);
  2461. tool.palette = titleBar->palette;
  2462. QPixmap pm = standardIcon(SP_TitleBarMenuButton, &tool, widget).pixmap(16, 16);
  2463. tool.rect = iconRect;
  2464. painter->save();
  2465. proxy()->drawItemPixmap(painter, iconRect, Qt::AlignCenter, pm);
  2466. painter->restore();
  2467. }
  2468. }
  2469. }
  2470. }
  2471. painter->restore();
  2472. break;
  2473. case CC_ScrollBar:
  2474. painter->save();
  2475. if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
  2476. bool horizontal = scrollBar->orientation == Qt::Horizontal;
  2477. bool sunken = scrollBar->state & State_Sunken;
  2478. QRect scrollBarSubLine = proxy()->subControlRect(control, scrollBar, SC_ScrollBarSubLine, widget);
  2479. QRect scrollBarAddLine = proxy()->subControlRect(control, scrollBar, SC_ScrollBarAddLine, widget);
  2480. QRect scrollBarSlider = proxy()->subControlRect(control, scrollBar, SC_ScrollBarSlider, widget);
  2481. QRect scrollBarGroove = proxy()->subControlRect(control, scrollBar, SC_ScrollBarGroove, widget);
  2482. QRect rect = option->rect;
  2483. QColor alphaOutline = outline;
  2484. alphaOutline.setAlpha(180);
  2485. QColor arrowColor = option->palette.foreground().color();
  2486. arrowColor.setAlpha(220);
  2487. // Paint groove
  2488. if (scrollBar->subControls & SC_ScrollBarGroove) {
  2489. QLinearGradient gradient(rect.center().x(), rect.top(),
  2490. rect.center().x(), rect.bottom());
  2491. if (!horizontal)
  2492. gradient = QLinearGradient(rect.left(), rect.center().y(),
  2493. rect.right(), rect.center().y());
  2494. gradient.setColorAt(0, buttonColor.darker(107));
  2495. gradient.setColorAt(0.1, buttonColor.darker(105));
  2496. gradient.setColorAt(0.9, buttonColor.darker(105));
  2497. gradient.setColorAt(1, buttonColor.darker(107));
  2498. painter->fillRect(option->rect, gradient);
  2499. painter->setPen(Qt::NoPen);
  2500. painter->setPen(alphaOutline);
  2501. if (horizontal)
  2502. painter->drawLine(rect.topLeft(), rect.topRight());
  2503. else
  2504. painter->drawLine(rect.topLeft(), rect.bottomLeft());
  2505. QColor subtleEdge = alphaOutline;
  2506. subtleEdge.setAlpha(40);
  2507. painter->setPen(Qt::NoPen);
  2508. painter->setBrush(Qt::NoBrush);
  2509. painter->save();
  2510. painter->setClipRect(scrollBarGroove.adjusted(1, 0, -1, -3));
  2511. painter->drawRect(scrollBarGroove.adjusted(1, 0, -1, -1));
  2512. painter->restore();
  2513. }
  2514. QRect pixmapRect = scrollBarSlider;
  2515. QLinearGradient gradient(pixmapRect.center().x(), pixmapRect.top(),
  2516. pixmapRect.center().x(), pixmapRect.bottom());
  2517. if (!horizontal)
  2518. gradient = QLinearGradient(pixmapRect.left(), pixmapRect.center().y(),
  2519. pixmapRect.right(), pixmapRect.center().y());
  2520. QLinearGradient highlightedGradient = gradient;
  2521. QColor midColor2 = mergedColors(gradientStartColor, gradientStopColor, 40);
  2522. gradient.setColorAt(0, d->buttonColor(option->palette).lighter(108));
  2523. gradient.setColorAt(1, d->buttonColor(option->palette));
  2524. highlightedGradient.setColorAt(0, gradientStartColor.darker(102));
  2525. highlightedGradient.setColorAt(1, gradientStopColor.lighter(102));
  2526. // Paint slider
  2527. if (scrollBar->subControls & SC_ScrollBarSlider) {
  2528. QRect pixmapRect = scrollBarSlider;
  2529. painter->setPen(QPen(alphaOutline, 0));
  2530. if (option->state & State_Sunken && scrollBar->activeSubControls & SC_ScrollBarSlider)
  2531. painter->setBrush(midColor2);
  2532. else if (option->state & State_MouseOver && scrollBar->activeSubControls & SC_ScrollBarSlider)
  2533. painter->setBrush(highlightedGradient);
  2534. else
  2535. painter->setBrush(gradient);
  2536. painter->drawRect(pixmapRect.adjusted(horizontal ? -1 : 0, horizontal ? 0 : -1, horizontal ? 0 : 1, horizontal ? 1 : 0));
  2537. painter->setPen(d->innerContrastLine());
  2538. painter->drawRect(scrollBarSlider.adjusted(horizontal ? 0 : 1, horizontal ? 1 : 0, -1, -1));
  2539. // Outer shadow
  2540. // painter->setPen(subtleEdge);
  2541. // if (horizontal) {
  2542. //// painter->drawLine(scrollBarSlider.topLeft() + QPoint(-2, 0), scrollBarSlider.bottomLeft() + QPoint(2, 0));
  2543. //// painter->drawLine(scrollBarSlider.topRight() + QPoint(-2, 0), scrollBarSlider.bottomRight() + QPoint(2, 0));
  2544. // } else {
  2545. //// painter->drawLine(pixmapRect.topLeft() + QPoint(0, -2), pixmapRect.bottomLeft() + QPoint(0, -2));
  2546. //// painter->drawLine(pixmapRect.topRight() + QPoint(0, 2), pixmapRect.bottomRight() + QPoint(0, 2));
  2547. // }
  2548. }
  2549. // The SubLine (up/left) buttons
  2550. if (scrollBar->subControls & SC_ScrollBarSubLine) {
  2551. if ((scrollBar->activeSubControls & SC_ScrollBarSubLine) && sunken)
  2552. painter->setBrush(gradientStopColor);
  2553. else if ((scrollBar->activeSubControls & SC_ScrollBarSubLine))
  2554. painter->setBrush(highlightedGradient);
  2555. else
  2556. painter->setBrush(gradient);
  2557. painter->setPen(Qt::NoPen);
  2558. painter->drawRect(scrollBarSubLine.adjusted(horizontal ? 0 : 1, horizontal ? 1 : 0, 0, 0));
  2559. painter->setPen(QPen(alphaOutline, 1));
  2560. if (option->state & State_Horizontal) {
  2561. if (option->direction == Qt::RightToLeft) {
  2562. pixmapRect.setLeft(scrollBarSubLine.left());
  2563. painter->drawLine(pixmapRect.topLeft(), pixmapRect.bottomLeft());
  2564. } else {
  2565. pixmapRect.setRight(scrollBarSubLine.right());
  2566. painter->drawLine(pixmapRect.topRight(), pixmapRect.bottomRight());
  2567. }
  2568. } else {
  2569. pixmapRect.setBottom(scrollBarSubLine.bottom());
  2570. painter->drawLine(pixmapRect.bottomLeft(), pixmapRect.bottomRight());
  2571. }
  2572. painter->setBrush(Qt::NoBrush);
  2573. painter->setPen(d->innerContrastLine());
  2574. painter->drawRect(scrollBarSubLine.adjusted(horizontal ? 0 : 1, horizontal ? 1 : 0 , horizontal ? -2 : -1, horizontal ? -1 : -2));
  2575. // Arrows
  2576. int rotation = 0;
  2577. if (option->state & State_Horizontal)
  2578. rotation = option->direction == Qt::LeftToRight ? -90 : 90;
  2579. QRect upRect = scrollBarSubLine.translated(horizontal ? -2 : -1, 0);
  2580. QPixmap arrowPixmap = colorizedImage(QLatin1String(":/bitmaps/style/arrow.png"), arrowColor, rotation);
  2581. painter->drawPixmap(QRect(upRect.center().x() - arrowPixmap.width() / 4 + 2,
  2582. upRect.center().y() - arrowPixmap.height() / 4 + 1,
  2583. arrowPixmap.width()/2, arrowPixmap.height()/2), arrowPixmap);
  2584. }
  2585. // The AddLine (down/right) button
  2586. if (scrollBar->subControls & SC_ScrollBarAddLine) {
  2587. if ((scrollBar->activeSubControls & SC_ScrollBarAddLine) && sunken)
  2588. painter->setBrush(gradientStopColor);
  2589. else if ((scrollBar->activeSubControls & SC_ScrollBarAddLine))
  2590. painter->setBrush(midColor2);
  2591. else
  2592. painter->setBrush(gradient);
  2593. painter->setPen(Qt::NoPen);
  2594. painter->drawRect(scrollBarAddLine.adjusted(horizontal ? 0 : 1, horizontal ? 1 : 0, 0, 0));
  2595. painter->setPen(QPen(alphaOutline, 1));
  2596. if (option->state & State_Horizontal) {
  2597. if (option->direction == Qt::LeftToRight) {
  2598. pixmapRect.setLeft(scrollBarAddLine.left());
  2599. painter->drawLine(pixmapRect.topLeft(), pixmapRect.bottomLeft());
  2600. } else {
  2601. pixmapRect.setRight(scrollBarAddLine.right());
  2602. painter->drawLine(pixmapRect.topRight(), pixmapRect.bottomRight());
  2603. }
  2604. } else {
  2605. pixmapRect.setTop(scrollBarAddLine.top());
  2606. painter->drawLine(pixmapRect.topLeft(), pixmapRect.topRight());
  2607. }
  2608. painter->setPen(d->innerContrastLine());
  2609. painter->setBrush(Qt::NoBrush);
  2610. painter->drawRect(scrollBarAddLine.adjusted(1, 1, -1, -1));
  2611. int rotation = 180;
  2612. if (option->state & State_Horizontal)
  2613. rotation = option->direction == Qt::LeftToRight ? 90 : -90;
  2614. QRect downRect = scrollBarAddLine.translated(-1, 1);
  2615. QPixmap arrowPixmap = colorizedImage(QLatin1String(":/bitmaps/style/arrow.png"), arrowColor, rotation);
  2616. painter->drawPixmap(QRect(downRect.center().x() - arrowPixmap.width() / 4 + 2,
  2617. downRect.center().y() - arrowPixmap.height() / 4,
  2618. arrowPixmap.width()/2, arrowPixmap.height()/2), arrowPixmap);
  2619. }
  2620. }
  2621. painter->restore();
  2622. break;;
  2623. case CC_ComboBox:
  2624. painter->save();
  2625. if (const QStyleOptionComboBox *comboBox = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
  2626. bool hasFocus = option->state & State_HasFocus && option->state & State_KeyboardFocusChange;
  2627. bool sunken = comboBox->state & State_On; // play dead, if combobox has no items
  2628. bool isEnabled = (comboBox->state & State_Enabled);
  2629. QPixmap cache;
  2630. QString pixmapName = uniqueName(QLatin1String("combobox"), option, comboBox->rect.size());
  2631. if (sunken)
  2632. pixmapName += QLatin1String("-sunken");
  2633. if (comboBox->editable)
  2634. pixmapName += QLatin1String("-editable");
  2635. if (isEnabled)
  2636. pixmapName += QLatin1String("-enabled");
  2637. if (!QPixmapCache::find(pixmapName, cache)) {
  2638. cache = styleCachePixmap(comboBox->rect.size());
  2639. cache.fill(Qt::transparent);
  2640. QPainter cachePainter(&cache);
  2641. QRect pixmapRect(0, 0, comboBox->rect.width(), comboBox->rect.height());
  2642. QStyleOptionComboBox comboBoxCopy = *comboBox;
  2643. comboBoxCopy.rect = pixmapRect;
  2644. QRect rect = pixmapRect;
  2645. QRect downArrowRect = proxy()->subControlRect(CC_ComboBox, &comboBoxCopy,
  2646. SC_ComboBoxArrow, widget);
  2647. // Draw a line edit
  2648. if (comboBox->editable) {
  2649. QStyleOptionFrame buttonOption;
  2650. buttonOption.QStyleOption::operator=(*comboBox);
  2651. buttonOption.rect = rect;
  2652. buttonOption.state = (comboBox->state & (State_Enabled | State_MouseOver | State_HasFocus))
  2653. | State_KeyboardFocusChange; // Allways show hig
  2654. if (sunken) {
  2655. buttonOption.state |= State_Sunken;
  2656. buttonOption.state &= ~State_MouseOver;
  2657. }
  2658. proxy()->drawPrimitive(PE_FrameLineEdit, &buttonOption, &cachePainter, widget);
  2659. // Draw button clipped
  2660. cachePainter.save();
  2661. cachePainter.setClipRect(downArrowRect.adjusted(0, 0, 1, 0));
  2662. buttonOption.rect.setLeft(comboBox->direction == Qt::LeftToRight ?
  2663. downArrowRect.left() - 6: downArrowRect.right() + 6);
  2664. proxy()->drawPrimitive(PE_PanelButtonCommand, &buttonOption, &cachePainter, widget);
  2665. cachePainter.restore();
  2666. cachePainter.setPen( QPen(hasFocus ? option->palette.highlight() : outline.lighter(110), 0));
  2667. if (!sunken) {
  2668. int borderSize = 1;
  2669. if (comboBox->direction == Qt::RightToLeft) {
  2670. cachePainter.drawLine(QPoint(downArrowRect.right() - 1, downArrowRect.top() + borderSize ),
  2671. QPoint(downArrowRect.right() - 1, downArrowRect.bottom() - borderSize));
  2672. } else {
  2673. cachePainter.drawLine(QPoint(downArrowRect.left() , downArrowRect.top() + borderSize),
  2674. QPoint(downArrowRect.left() , downArrowRect.bottom() - borderSize));
  2675. }
  2676. } else {
  2677. if (comboBox->direction == Qt::RightToLeft) {
  2678. cachePainter.drawLine(QPoint(downArrowRect.right(), downArrowRect.top() + 2),
  2679. QPoint(downArrowRect.right(), downArrowRect.bottom() - 2));
  2680. } else {
  2681. cachePainter.drawLine(QPoint(downArrowRect.left(), downArrowRect.top() + 2),
  2682. QPoint(downArrowRect.left(), downArrowRect.bottom() - 2));
  2683. }
  2684. }
  2685. } else {
  2686. QStyleOptionButton buttonOption;
  2687. buttonOption.QStyleOption::operator=(*comboBox);
  2688. buttonOption.rect = rect;
  2689. buttonOption.state = comboBox->state & (State_Enabled | State_MouseOver | State_HasFocus | State_KeyboardFocusChange);
  2690. if (sunken) {
  2691. buttonOption.state |= State_Sunken;
  2692. buttonOption.state &= ~State_MouseOver;
  2693. }
  2694. proxy()->drawPrimitive(PE_PanelButtonCommand, &buttonOption, &cachePainter, widget);
  2695. }
  2696. if (comboBox->subControls & SC_ComboBoxArrow) {
  2697. // Draw the up/down arrow
  2698. QColor arrowColor = option->palette.buttonText().color();
  2699. arrowColor.setAlpha(220);
  2700. QPixmap downArrow = colorizedImage(QLatin1String(":/bitmaps/style/arrow.png"), arrowColor, 180);
  2701. cachePainter.drawPixmap(QRect(downArrowRect.center().x() - downArrow.width() / 4 + 1,
  2702. downArrowRect.center().y() - downArrow.height() / 4 + 1,
  2703. downArrow.width()/2, downArrow.height()/2), downArrow);
  2704. }
  2705. cachePainter.end();
  2706. QPixmapCache::insert(pixmapName, cache);
  2707. }
  2708. painter->drawPixmap(comboBox->rect.topLeft(), cache);
  2709. }
  2710. painter->restore();
  2711. break;
  2712. case CC_Slider:
  2713. if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
  2714. QRect groove = proxy()->subControlRect(CC_Slider, option, SC_SliderGroove, widget);
  2715. QRect handle = proxy()->subControlRect(CC_Slider, option, SC_SliderHandle, widget);
  2716. bool horizontal = slider->orientation == Qt::Horizontal;
  2717. bool ticksAbove = slider->tickPosition & QSlider::TicksAbove;
  2718. bool ticksBelow = slider->tickPosition & QSlider::TicksBelow;
  2719. QColor activeHighlight = d->highlight(option->palette);
  2720. QPixmap cache;
  2721. QBrush oldBrush = painter->brush();
  2722. QPen oldPen = painter->pen();
  2723. QColor shadowAlpha(Qt::black);
  2724. shadowAlpha.setAlpha(10);
  2725. if (option->state & State_HasFocus && option->state & State_KeyboardFocusChange)
  2726. outline = d->highlightedOutline(option->palette);
  2727. if ((option->subControls & SC_SliderGroove) && groove.isValid()) {
  2728. QColor grooveColor;
  2729. grooveColor.setHsv(buttonColor.hue(),
  2730. qMin(255, (int)(buttonColor.saturation())),
  2731. qMin(255, (int)(buttonColor.value()*0.9)));
  2732. QString groovePixmapName = uniqueName(QLatin1String("slider_groove"), option, groove.size());
  2733. QRect pixmapRect(0, 0, groove.width(), groove.height());
  2734. // draw background groove
  2735. if (!QPixmapCache::find(groovePixmapName, cache)) {
  2736. cache = styleCachePixmap(pixmapRect.size());
  2737. cache.fill(Qt::transparent);
  2738. QPainter groovePainter(&cache);
  2739. groovePainter.setRenderHint(QPainter::Antialiasing, true);
  2740. groovePainter.translate(0.5, 0.5);
  2741. QLinearGradient gradient;
  2742. if (horizontal) {
  2743. gradient.setStart(pixmapRect.center().x(), pixmapRect.top());
  2744. gradient.setFinalStop(pixmapRect.center().x(), pixmapRect.bottom());
  2745. }
  2746. else {
  2747. gradient.setStart(pixmapRect.left(), pixmapRect.center().y());
  2748. gradient.setFinalStop(pixmapRect.right(), pixmapRect.center().y());
  2749. }
  2750. groovePainter.setPen(QPen(outline, 0));
  2751. gradient.setColorAt(0, grooveColor.darker(110));
  2752. gradient.setColorAt(1, grooveColor.lighter(110));//palette.button().color().darker(115));
  2753. groovePainter.setBrush(gradient);
  2754. groovePainter.drawRoundedRect(pixmapRect.adjusted(1, 1, -2, -2), 1, 1);
  2755. groovePainter.end();
  2756. QPixmapCache::insert(groovePixmapName, cache);
  2757. }
  2758. painter->drawPixmap(groove.topLeft(), cache);
  2759. // draw blue groove highlight
  2760. QRect clipRect;
  2761. groovePixmapName += QLatin1String("_blue");
  2762. if (!QPixmapCache::find(groovePixmapName, cache)) {
  2763. cache = styleCachePixmap(pixmapRect.size());
  2764. cache.fill(Qt::transparent);
  2765. QPainter groovePainter(&cache);
  2766. QLinearGradient gradient;
  2767. if (horizontal) {
  2768. gradient.setStart(pixmapRect.center().x(), pixmapRect.top());
  2769. gradient.setFinalStop(pixmapRect.center().x(), pixmapRect.bottom());
  2770. }
  2771. else {
  2772. gradient.setStart(pixmapRect.left(), pixmapRect.center().y());
  2773. gradient.setFinalStop(pixmapRect.right(), pixmapRect.center().y());
  2774. }
  2775. QColor highlight = d->highlight(option->palette);
  2776. QColor highlightedoutline = highlight.darker(140);
  2777. if (qGray(outline.rgb()) > qGray(highlightedoutline.rgb()))
  2778. outline = highlightedoutline;
  2779. groovePainter.setRenderHint(QPainter::Antialiasing, true);
  2780. groovePainter.translate(0.5, 0.5);
  2781. groovePainter.setPen(QPen(outline, 0));
  2782. gradient.setColorAt(0, activeHighlight);
  2783. gradient.setColorAt(1, activeHighlight.lighter(130));
  2784. groovePainter.setBrush(gradient);
  2785. groovePainter.drawRoundedRect(pixmapRect.adjusted(1, 1, -2, -2), 1, 1);
  2786. groovePainter.setPen(d->innerContrastLine());
  2787. groovePainter.setBrush(Qt::NoBrush);
  2788. groovePainter.drawRoundedRect(pixmapRect.adjusted(2, 2, -3, -3), 1, 1);
  2789. groovePainter.end();
  2790. QPixmapCache::insert(groovePixmapName, cache);
  2791. }
  2792. if (horizontal) {
  2793. if (slider->upsideDown)
  2794. clipRect = QRect(handle.right(), groove.top(), groove.right() - handle.right(), groove.height());
  2795. else
  2796. clipRect = QRect(groove.left(), groove.top(), handle.left(), groove.height());
  2797. } else {
  2798. if (slider->upsideDown)
  2799. clipRect = QRect(groove.left(), handle.bottom(), groove.width(), groove.height() - handle.bottom());
  2800. else
  2801. clipRect = QRect(groove.left(), groove.top(), groove.width(), handle.top() - groove.top());
  2802. }
  2803. painter->save();
  2804. painter->setClipRect(clipRect.adjusted(0, 0, 1, 1));
  2805. painter->drawPixmap(groove.topLeft(), cache);
  2806. painter->restore();
  2807. }
  2808. if (option->subControls & SC_SliderTickmarks) {
  2809. painter->setPen(outline);
  2810. int tickSize = proxy()->pixelMetric(PM_SliderTickmarkOffset, option, widget);
  2811. int available = proxy()->pixelMetric(PM_SliderSpaceAvailable, slider, widget);
  2812. int interval = slider->tickInterval;
  2813. if (interval <= 0) {
  2814. interval = slider->singleStep;
  2815. if (QStyle::sliderPositionFromValue(slider->minimum, slider->maximum, interval,
  2816. available)
  2817. - QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
  2818. 0, available) < 3)
  2819. interval = slider->pageStep;
  2820. }
  2821. if (interval <= 0)
  2822. interval = 1;
  2823. int v = slider->minimum;
  2824. int len = proxy()->pixelMetric(PM_SliderLength, slider, widget);
  2825. while (v <= slider->maximum + 1) {
  2826. if (v == slider->maximum + 1 && interval == 1)
  2827. break;
  2828. const int v_ = qMin(v, slider->maximum);
  2829. int pos = sliderPositionFromValue(slider->minimum, slider->maximum,
  2830. v_, (horizontal
  2831. ? slider->rect.width()
  2832. : slider->rect.height()) - len,
  2833. slider->upsideDown) + len / 2;
  2834. int extra = 2 - ((v_ == slider->minimum || v_ == slider->maximum) ? 1 : 0);
  2835. if (horizontal) {
  2836. if (ticksAbove) {
  2837. painter->drawLine(pos, slider->rect.top() + extra,
  2838. pos, slider->rect.top() + tickSize);
  2839. }
  2840. if (ticksBelow) {
  2841. painter->drawLine(pos, slider->rect.bottom() - extra,
  2842. pos, slider->rect.bottom() - tickSize);
  2843. }
  2844. } else {
  2845. if (ticksAbove) {
  2846. painter->drawLine(slider->rect.left() + extra, pos,
  2847. slider->rect.left() + tickSize, pos);
  2848. }
  2849. if (ticksBelow) {
  2850. painter->drawLine(slider->rect.right() - extra, pos,
  2851. slider->rect.right() - tickSize, pos);
  2852. }
  2853. }
  2854. // in the case where maximum is max int
  2855. int nextInterval = v + interval;
  2856. if (nextInterval < v)
  2857. break;
  2858. v = nextInterval;
  2859. }
  2860. }
  2861. // draw handle
  2862. if ((option->subControls & SC_SliderHandle) ) {
  2863. QString handlePixmapName = uniqueName(QLatin1String("slider_handle"), option, handle.size());
  2864. if (!QPixmapCache::find(handlePixmapName, cache)) {
  2865. cache = styleCachePixmap(handle.size());
  2866. cache.fill(Qt::transparent);
  2867. QRect pixmapRect(0, 0, handle.width(), handle.height());
  2868. QPainter handlePainter(&cache);
  2869. QRect gradRect = pixmapRect.adjusted(2, 2, -2, -2);
  2870. // gradient fill
  2871. QRect r = pixmapRect.adjusted(1, 1, -2, -2);
  2872. QLinearGradient gradient = qt_fusion_gradient(gradRect, d->buttonColor(option->palette),horizontal ? TopDown : FromLeft);
  2873. handlePainter.setRenderHint(QPainter::Antialiasing, true);
  2874. handlePainter.translate(0.5, 0.5);
  2875. handlePainter.setPen(Qt::NoPen);
  2876. handlePainter.setBrush(QColor(0, 0, 0, 40));
  2877. handlePainter.drawRect(r.adjusted(-1, 2, 1, -2));
  2878. handlePainter.setPen(QPen(d->outline(option->palette), 1));
  2879. if (option->state & State_HasFocus && option->state & State_KeyboardFocusChange)
  2880. handlePainter.setPen(QPen(d->highlightedOutline(option->palette), 1));
  2881. handlePainter.setBrush(gradient);
  2882. handlePainter.drawRoundedRect(r, 2, 2);
  2883. handlePainter.setBrush(Qt::NoBrush);
  2884. handlePainter.setPen(d->innerContrastLine());
  2885. handlePainter.drawRoundedRect(r.adjusted(1, 1, -1, -1), 2, 2);
  2886. QColor cornerAlpha = outline.darker(120);
  2887. cornerAlpha.setAlpha(80);
  2888. //handle shadow
  2889. handlePainter.setPen(shadowAlpha);
  2890. handlePainter.drawLine(QPoint(r.left() + 2, r.bottom() + 1), QPoint(r.right() - 2, r.bottom() + 1));
  2891. handlePainter.drawLine(QPoint(r.right() + 1, r.bottom() - 3), QPoint(r.right() + 1, r.top() + 4));
  2892. handlePainter.drawLine(QPoint(r.right() - 1, r.bottom()), QPoint(r.right() + 1, r.bottom() - 2));
  2893. handlePainter.end();
  2894. QPixmapCache::insert(handlePixmapName, cache);
  2895. }
  2896. painter->drawPixmap(handle.topLeft(), cache);
  2897. }
  2898. painter->setBrush(oldBrush);
  2899. painter->setPen(oldPen);
  2900. }
  2901. break;
  2902. case CC_Dial:
  2903. if (const QStyleOptionSlider* dial = qstyleoption_cast<const QStyleOptionSlider *>(option))
  2904. drawDial(dial, painter);
  2905. break;
  2906. default:
  2907. QCommonStyle::drawComplexControl(control, option, painter, widget);
  2908. break;
  2909. }
  2910. }
  2911. /*!
  2912. \reimp
  2913. */
  2914. int CarlaStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const
  2915. {
  2916. switch (metric)
  2917. {
  2918. case PM_SliderTickmarkOffset:
  2919. return 4;
  2920. case PM_HeaderMargin:
  2921. return 2;
  2922. case PM_ToolTipLabelFrameWidth:
  2923. return 2;
  2924. case PM_ButtonDefaultIndicator:
  2925. return 0;
  2926. case PM_ButtonShiftHorizontal:
  2927. case PM_ButtonShiftVertical:
  2928. return 0;
  2929. case PM_MessageBoxIconSize:
  2930. return 48;
  2931. case PM_ListViewIconSize:
  2932. return 24;
  2933. case PM_DialogButtonsSeparator:
  2934. case PM_ScrollBarSliderMin:
  2935. return 26;
  2936. case PM_TitleBarHeight:
  2937. return 24;
  2938. case PM_ScrollBarExtent:
  2939. return 14;
  2940. case PM_SliderThickness:
  2941. return 15;
  2942. case PM_SliderLength:
  2943. return 15;
  2944. case PM_DockWidgetTitleMargin:
  2945. return 1;
  2946. case PM_DefaultFrameWidth:
  2947. return 1;
  2948. case PM_SpinBoxFrameWidth:
  2949. return 3;
  2950. case PM_MenuVMargin:
  2951. case PM_MenuHMargin:
  2952. return 0;
  2953. case PM_MenuPanelWidth:
  2954. return 0;
  2955. case PM_MenuBarItemSpacing:
  2956. return 6;
  2957. case PM_MenuBarVMargin:
  2958. return 0;
  2959. case PM_MenuBarHMargin:
  2960. return 0;
  2961. case PM_MenuBarPanelWidth:
  2962. return 0;
  2963. case PM_ToolBarHandleExtent:
  2964. return 9;
  2965. case PM_ToolBarItemSpacing:
  2966. return 1;
  2967. case PM_ToolBarFrameWidth:
  2968. return 2;
  2969. case PM_ToolBarItemMargin:
  2970. return 2;
  2971. case PM_SmallIconSize:
  2972. return 16;
  2973. case PM_ButtonIconSize:
  2974. return 16;
  2975. case PM_DockWidgetTitleBarButtonMargin:
  2976. return 2;
  2977. case PM_MaximumDragDistance:
  2978. return -1;
  2979. case PM_TabCloseIndicatorWidth:
  2980. case PM_TabCloseIndicatorHeight:
  2981. return 20;
  2982. case PM_TabBarTabVSpace:
  2983. return 12;
  2984. case PM_TabBarTabOverlap:
  2985. return 1;
  2986. case PM_TabBarBaseOverlap:
  2987. return 2;
  2988. case PM_SubMenuOverlap:
  2989. return -1;
  2990. case PM_DockWidgetHandleExtent:
  2991. case PM_SplitterWidth:
  2992. return 4;
  2993. case PM_IndicatorHeight:
  2994. case PM_IndicatorWidth:
  2995. case PM_ExclusiveIndicatorHeight:
  2996. case PM_ExclusiveIndicatorWidth:
  2997. return 14;
  2998. case PM_ScrollView_ScrollBarSpacing:
  2999. return 0;
  3000. default:
  3001. break;
  3002. }
  3003. return QCommonStyle::pixelMetric(metric, option, widget);
  3004. }
  3005. /*!
  3006. \reimp
  3007. */
  3008. QSize CarlaStyle::sizeFromContents(ContentsType type, const QStyleOption* option,
  3009. const QSize& size, const QWidget* widget) const
  3010. {
  3011. QSize newSize = QCommonStyle::sizeFromContents(type, option, size, widget);
  3012. switch (type)
  3013. {
  3014. case CT_PushButton:
  3015. if (const QStyleOptionButton* btn = qstyleoption_cast<const QStyleOptionButton *>(option))
  3016. {
  3017. if (!btn->text.isEmpty() && newSize.width() < 80)
  3018. newSize.setWidth(80);
  3019. if (!btn->icon.isNull() && btn->iconSize.height() > 16)
  3020. newSize -= QSize(0, 2);
  3021. }
  3022. break;
  3023. case CT_GroupBox:
  3024. if (option)
  3025. {
  3026. int topMargin = qMax(pixelMetric(PM_ExclusiveIndicatorHeight), option->fontMetrics.height()) + groupBoxTopMargin;
  3027. newSize += QSize(10, topMargin); // Add some space below the groupbox
  3028. }
  3029. break;
  3030. case CT_RadioButton:
  3031. case CT_CheckBox:
  3032. newSize += QSize(0, 1);
  3033. break;
  3034. case CT_ToolButton:
  3035. newSize += QSize(2, 2);
  3036. break;
  3037. case CT_SpinBox:
  3038. newSize += QSize(0, -3);
  3039. break;
  3040. case CT_ComboBox:
  3041. newSize += QSize(2, 4);
  3042. break;
  3043. case CT_LineEdit:
  3044. newSize += QSize(0, 4);
  3045. break;
  3046. case CT_MenuBarItem:
  3047. newSize += QSize(8, 5);
  3048. break;
  3049. case CT_MenuItem:
  3050. if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option))
  3051. {
  3052. int w = newSize.width();
  3053. int maxpmw = menuItem->maxIconWidth;
  3054. int tabSpacing = 20;
  3055. if (menuItem->text.contains(QLatin1Char('\t')))
  3056. w += tabSpacing;
  3057. else if (menuItem->menuItemType == QStyleOptionMenuItem::SubMenu)
  3058. w += 2 * CarlaStylePrivate::menuArrowHMargin;
  3059. else if (menuItem->menuItemType == QStyleOptionMenuItem::DefaultItem) {
  3060. QFontMetrics fm(menuItem->font);
  3061. QFont fontBold = menuItem->font;
  3062. fontBold.setBold(true);
  3063. QFontMetrics fmBold(fontBold);
  3064. w += fmBold.width(menuItem->text) - fm.width(menuItem->text);
  3065. }
  3066. int checkcol = qMax<int>(maxpmw, CarlaStylePrivate::menuCheckMarkWidth); // Windows always shows a check column
  3067. w += checkcol;
  3068. w += int(CarlaStylePrivate::menuRightBorder) + 10;
  3069. newSize.setWidth(w);
  3070. if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) {
  3071. if (!menuItem->text.isEmpty()) {
  3072. newSize.setHeight(menuItem->fontMetrics.height());
  3073. }
  3074. }
  3075. else if (!menuItem->icon.isNull())
  3076. {
  3077. if (const QComboBox *combo = qobject_cast<const QComboBox*>(widget)) {
  3078. newSize.setHeight(qMax(combo->iconSize().height() + 2, newSize.height()));
  3079. }
  3080. }
  3081. newSize.setWidth(newSize.width() + 12);
  3082. newSize.setWidth(qMax(newSize.width(), 120));
  3083. }
  3084. break;
  3085. case CT_SizeGrip:
  3086. newSize += QSize(4, 4);
  3087. break;
  3088. case CT_MdiControls:
  3089. if (const QStyleOptionComplex *styleOpt = qstyleoption_cast<const QStyleOptionComplex *>(option))
  3090. {
  3091. int width = 0;
  3092. if (styleOpt->subControls & SC_MdiMinButton)
  3093. width += 19 + 1;
  3094. if (styleOpt->subControls & SC_MdiNormalButton)
  3095. width += 19 + 1;
  3096. if (styleOpt->subControls & SC_MdiCloseButton)
  3097. width += 19 + 1;
  3098. newSize = QSize(width, 19);
  3099. }
  3100. else
  3101. {
  3102. newSize = QSize(60, 19);
  3103. }
  3104. break;
  3105. default:
  3106. break;
  3107. }
  3108. return newSize;
  3109. }
  3110. void CarlaStyle::polish(QApplication* app)
  3111. {
  3112. QCommonStyle::polish(app);
  3113. }
  3114. void CarlaStyle::polish(QPalette& pal)
  3115. {
  3116. QCommonStyle::polish(pal);
  3117. }
  3118. /*!
  3119. \reimp
  3120. */
  3121. void CarlaStyle::polish(QWidget *widget)
  3122. {
  3123. QCommonStyle::polish(widget);
  3124. if (qobject_cast<QAbstractButton*>(widget)
  3125. || qobject_cast<QComboBox *>(widget)
  3126. || qobject_cast<QProgressBar *>(widget)
  3127. || qobject_cast<QScrollBar *>(widget)
  3128. || qobject_cast<QSplitterHandle *>(widget)
  3129. || qobject_cast<QAbstractSlider *>(widget)
  3130. || qobject_cast<QAbstractSpinBox *>(widget)
  3131. || (widget->inherits("QDockSeparator"))
  3132. || (widget->inherits("QDockWidgetSeparator"))
  3133. ) {
  3134. widget->setAttribute(Qt::WA_Hover, true);
  3135. }
  3136. }
  3137. void CarlaStyle::unpolish(QApplication* app)
  3138. {
  3139. QCommonStyle::unpolish(app);
  3140. }
  3141. /*!
  3142. \reimp
  3143. */
  3144. void CarlaStyle::unpolish(QWidget *widget)
  3145. {
  3146. QCommonStyle::unpolish(widget);
  3147. if (qobject_cast<QAbstractButton*>(widget)
  3148. || qobject_cast<QComboBox *>(widget)
  3149. || qobject_cast<QProgressBar *>(widget)
  3150. || qobject_cast<QScrollBar *>(widget)
  3151. || qobject_cast<QSplitterHandle *>(widget)
  3152. || qobject_cast<QAbstractSlider *>(widget)
  3153. || qobject_cast<QAbstractSpinBox *>(widget)
  3154. || (widget->inherits("QDockSeparator"))
  3155. || (widget->inherits("QDockWidgetSeparator"))
  3156. ) {
  3157. widget->setAttribute(Qt::WA_Hover, false);
  3158. }
  3159. }
  3160. /*!
  3161. \reimp
  3162. */
  3163. QRect CarlaStyle::subControlRect(ComplexControl control, const QStyleOptionComplex *option,
  3164. SubControl subControl, const QWidget *widget) const
  3165. {
  3166. QRect rect = QCommonStyle::subControlRect(control, option, subControl, widget);
  3167. switch (control) {
  3168. case CC_Slider:
  3169. if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
  3170. int tickSize = proxy()->pixelMetric(PM_SliderTickmarkOffset, option, widget);
  3171. switch (subControl) {
  3172. case SC_SliderHandle: {
  3173. if (slider->orientation == Qt::Horizontal) {
  3174. rect.setHeight(proxy()->pixelMetric(PM_SliderThickness));
  3175. rect.setWidth(proxy()->pixelMetric(PM_SliderLength));
  3176. int centerY = slider->rect.center().y() - rect.height() / 2;
  3177. if (slider->tickPosition & QSlider::TicksAbove)
  3178. centerY += tickSize;
  3179. if (slider->tickPosition & QSlider::TicksBelow)
  3180. centerY -= tickSize;
  3181. rect.moveTop(centerY);
  3182. } else {
  3183. rect.setWidth(proxy()->pixelMetric(PM_SliderThickness));
  3184. rect.setHeight(proxy()->pixelMetric(PM_SliderLength));
  3185. int centerX = slider->rect.center().x() - rect.width() / 2;
  3186. if (slider->tickPosition & QSlider::TicksAbove)
  3187. centerX += tickSize;
  3188. if (slider->tickPosition & QSlider::TicksBelow)
  3189. centerX -= tickSize;
  3190. rect.moveLeft(centerX);
  3191. }
  3192. }
  3193. break;
  3194. case SC_SliderGroove: {
  3195. QPoint grooveCenter = slider->rect.center();
  3196. if (slider->orientation == Qt::Horizontal) {
  3197. rect.setHeight(7);
  3198. if (slider->tickPosition & QSlider::TicksAbove)
  3199. grooveCenter.ry() += tickSize;
  3200. if (slider->tickPosition & QSlider::TicksBelow)
  3201. grooveCenter.ry() -= tickSize;
  3202. } else {
  3203. rect.setWidth(7);
  3204. if (slider->tickPosition & QSlider::TicksAbove)
  3205. grooveCenter.rx() += tickSize;
  3206. if (slider->tickPosition & QSlider::TicksBelow)
  3207. grooveCenter.rx() -= tickSize;
  3208. }
  3209. rect.moveCenter(grooveCenter);
  3210. break;
  3211. }
  3212. default:
  3213. break;
  3214. }
  3215. }
  3216. break;
  3217. case CC_SpinBox:
  3218. if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
  3219. QSize bs;
  3220. int center = spinbox->rect.height() / 2;
  3221. int fw = spinbox->frame ? proxy()->pixelMetric(PM_SpinBoxFrameWidth, spinbox, widget) : 0;
  3222. int y = fw;
  3223. bs.setHeight(qMax(8, spinbox->rect.height()/2 - y));
  3224. bs.setWidth(14);
  3225. int x, lx, rx;
  3226. x = spinbox->rect.width() - y - bs.width() + 2;
  3227. lx = fw;
  3228. rx = x - fw;
  3229. switch (subControl) {
  3230. case SC_SpinBoxUp:
  3231. if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons)
  3232. return QRect();
  3233. rect = QRect(x, fw, bs.width(), center - fw);
  3234. break;
  3235. case SC_SpinBoxDown:
  3236. if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons)
  3237. return QRect();
  3238. rect = QRect(x, center, bs.width(), spinbox->rect.bottom() - center - fw + 1);
  3239. break;
  3240. case SC_SpinBoxEditField:
  3241. if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons) {
  3242. rect = QRect(lx, fw, spinbox->rect.width() - 2*fw, spinbox->rect.height() - 2*fw);
  3243. } else {
  3244. rect = QRect(lx, fw, rx - qMax(fw - 1, 0), spinbox->rect.height() - 2*fw);
  3245. }
  3246. break;
  3247. case SC_SpinBoxFrame:
  3248. rect = spinbox->rect;
  3249. default:
  3250. break;
  3251. }
  3252. rect = visualRect(spinbox->direction, spinbox->rect, rect);
  3253. }
  3254. break;
  3255. case CC_GroupBox:
  3256. if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
  3257. rect = option->rect;
  3258. if (subControl == SC_GroupBoxFrame)
  3259. return rect.adjusted(0, 0, 0, 0);
  3260. else if (subControl == SC_GroupBoxContents) {
  3261. QRect frameRect = option->rect.adjusted(0, 0, 0, -groupBoxBottomMargin);
  3262. int margin = 3;
  3263. int leftMarginExtension = 0;
  3264. int topMargin = qMax(pixelMetric(PM_ExclusiveIndicatorHeight), option->fontMetrics.height()) + groupBoxTopMargin;
  3265. return frameRect.adjusted(leftMarginExtension + margin, margin + topMargin, -margin, -margin - groupBoxBottomMargin);
  3266. }
  3267. QSize textSize = option->fontMetrics.boundingRect(groupBox->text).size() + QSize(2, 2);
  3268. int indicatorWidth = proxy()->pixelMetric(PM_IndicatorWidth, option, widget);
  3269. int indicatorHeight = proxy()->pixelMetric(PM_IndicatorHeight, option, widget);
  3270. rect = QRect();
  3271. if (subControl == SC_GroupBoxCheckBox) {
  3272. rect.setWidth(indicatorWidth);
  3273. rect.setHeight(indicatorHeight);
  3274. rect.moveTop(textSize.height() > indicatorHeight ? (textSize.height() - indicatorHeight) / 2 : 0);
  3275. rect.moveLeft(1);
  3276. } else if (subControl == SC_GroupBoxLabel) {
  3277. rect.setSize(textSize);
  3278. rect.moveTop(1);
  3279. if (option->subControls & QStyle::SC_GroupBoxCheckBox)
  3280. rect.translate(indicatorWidth + 5, 0);
  3281. }
  3282. return visualRect(option->direction, option->rect, rect);
  3283. }
  3284. return rect;
  3285. case CC_ComboBox:
  3286. switch (subControl) {
  3287. case SC_ComboBoxArrow:
  3288. rect = visualRect(option->direction, option->rect, rect);
  3289. rect.setRect(rect.right() - 18, rect.top() - 2,
  3290. 19, rect.height() + 4);
  3291. rect = visualRect(option->direction, option->rect, rect);
  3292. break;
  3293. case SC_ComboBoxEditField: {
  3294. int frameWidth = 2;
  3295. rect = visualRect(option->direction, option->rect, rect);
  3296. rect.setRect(option->rect.left() + frameWidth, option->rect.top() + frameWidth,
  3297. option->rect.width() - 19 - 2 * frameWidth,
  3298. option->rect.height() - 2 * frameWidth);
  3299. if (const QStyleOptionComboBox *box = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
  3300. if (!box->editable) {
  3301. rect.adjust(2, 0, 0, 0);
  3302. if (box->state & (State_Sunken | State_On))
  3303. rect.translate(1, 1);
  3304. }
  3305. }
  3306. rect = visualRect(option->direction, option->rect, rect);
  3307. break;
  3308. }
  3309. default:
  3310. break;
  3311. }
  3312. break;
  3313. case CC_TitleBar:
  3314. if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(option)) {
  3315. SubControl sc = subControl;
  3316. QRect &ret = rect;
  3317. const int indent = 3;
  3318. const int controlTopMargin = 3;
  3319. const int controlBottomMargin = 3;
  3320. const int controlWidthMargin = 2;
  3321. const int controlHeight = tb->rect.height() - controlTopMargin - controlBottomMargin ;
  3322. const int delta = controlHeight + controlWidthMargin;
  3323. int offset = 0;
  3324. bool isMinimized = tb->titleBarState & Qt::WindowMinimized;
  3325. bool isMaximized = tb->titleBarState & Qt::WindowMaximized;
  3326. switch (sc) {
  3327. case SC_TitleBarLabel:
  3328. if (tb->titleBarFlags & (Qt::WindowTitleHint | Qt::WindowSystemMenuHint)) {
  3329. ret = tb->rect;
  3330. if (tb->titleBarFlags & Qt::WindowSystemMenuHint)
  3331. ret.adjust(delta, 0, -delta, 0);
  3332. if (tb->titleBarFlags & Qt::WindowMinimizeButtonHint)
  3333. ret.adjust(0, 0, -delta, 0);
  3334. if (tb->titleBarFlags & Qt::WindowMaximizeButtonHint)
  3335. ret.adjust(0, 0, -delta, 0);
  3336. if (tb->titleBarFlags & Qt::WindowShadeButtonHint)
  3337. ret.adjust(0, 0, -delta, 0);
  3338. if (tb->titleBarFlags & Qt::WindowContextHelpButtonHint)
  3339. ret.adjust(0, 0, -delta, 0);
  3340. }
  3341. break;
  3342. case SC_TitleBarContextHelpButton:
  3343. if (tb->titleBarFlags & Qt::WindowContextHelpButtonHint)
  3344. offset += delta;
  3345. case SC_TitleBarMinButton:
  3346. if (!isMinimized && (tb->titleBarFlags & Qt::WindowMinimizeButtonHint))
  3347. offset += delta;
  3348. else if (sc == SC_TitleBarMinButton)
  3349. break;
  3350. case SC_TitleBarNormalButton:
  3351. if (isMinimized && (tb->titleBarFlags & Qt::WindowMinimizeButtonHint))
  3352. offset += delta;
  3353. else if (isMaximized && (tb->titleBarFlags & Qt::WindowMaximizeButtonHint))
  3354. offset += delta;
  3355. else if (sc == SC_TitleBarNormalButton)
  3356. break;
  3357. case SC_TitleBarMaxButton:
  3358. if (!isMaximized && (tb->titleBarFlags & Qt::WindowMaximizeButtonHint))
  3359. offset += delta;
  3360. else if (sc == SC_TitleBarMaxButton)
  3361. break;
  3362. case SC_TitleBarShadeButton:
  3363. if (!isMinimized && (tb->titleBarFlags & Qt::WindowShadeButtonHint))
  3364. offset += delta;
  3365. else if (sc == SC_TitleBarShadeButton)
  3366. break;
  3367. case SC_TitleBarUnshadeButton:
  3368. if (isMinimized && (tb->titleBarFlags & Qt::WindowShadeButtonHint))
  3369. offset += delta;
  3370. else if (sc == SC_TitleBarUnshadeButton)
  3371. break;
  3372. case SC_TitleBarCloseButton:
  3373. if (tb->titleBarFlags & Qt::WindowSystemMenuHint)
  3374. offset += delta;
  3375. else if (sc == SC_TitleBarCloseButton)
  3376. break;
  3377. ret.setRect(tb->rect.right() - indent - offset, tb->rect.top() + controlTopMargin,
  3378. controlHeight, controlHeight);
  3379. break;
  3380. case SC_TitleBarSysMenu:
  3381. if (tb->titleBarFlags & Qt::WindowSystemMenuHint) {
  3382. ret.setRect(tb->rect.left() + controlWidthMargin + indent, tb->rect.top() + controlTopMargin,
  3383. controlHeight, controlHeight);
  3384. }
  3385. break;
  3386. default:
  3387. break;
  3388. }
  3389. ret = visualRect(tb->direction, tb->rect, ret);
  3390. }
  3391. break;
  3392. default:
  3393. break;
  3394. }
  3395. return rect;
  3396. }
  3397. /*!
  3398. \reimp
  3399. */
  3400. int CarlaStyle::styleHint(StyleHint hint, const QStyleOption* option, const QWidget* widget,
  3401. QStyleHintReturn* returnData) const
  3402. {
  3403. switch (hint)
  3404. {
  3405. case SH_Slider_SnapToValue:
  3406. case SH_PrintDialog_RightAlignButtons:
  3407. case SH_FontDialog_SelectAssociatedText:
  3408. case SH_MenuBar_AltKeyNavigation:
  3409. case SH_ComboBox_ListMouseTracking:
  3410. case SH_ScrollBar_StopMouseOverSlider:
  3411. case SH_ScrollBar_MiddleClickAbsolutePosition:
  3412. case SH_TitleBar_AutoRaise:
  3413. case SH_TitleBar_NoBorder:
  3414. case SH_ItemView_ShowDecorationSelected:
  3415. case SH_ItemView_ArrowKeysNavigateIntoChildren:
  3416. case SH_ItemView_ChangeHighlightOnFocus:
  3417. case SH_MenuBar_MouseTracking:
  3418. case SH_Menu_MouseTracking:
  3419. return 1;
  3420. case SH_ComboBox_Popup:
  3421. case SH_EtchDisabledText:
  3422. case SH_ToolBox_SelectedPageTitleBold:
  3423. case SH_ScrollView_FrameOnlyAroundContents:
  3424. case SH_Menu_AllowActiveAndDisabled:
  3425. case SH_MainWindow_SpaceBelowMenuBar:
  3426. //case SH_DialogButtonBox_ButtonsHaveIcons:
  3427. case SH_MessageBox_CenterButtons:
  3428. case SH_RubberBand_Mask:
  3429. case SH_UnderlineShortcut:
  3430. return 0;
  3431. case SH_Table_GridLineColor:
  3432. return option ? option->palette.background().color().darker(120).rgb() : 0;
  3433. case SH_MessageBox_TextInteractionFlags:
  3434. return Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse;
  3435. case SH_WizardStyle:
  3436. return QWizard::ClassicStyle;
  3437. case SH_Menu_SubMenuPopupDelay:
  3438. return 225; // default from GtkMenu
  3439. case SH_WindowFrame_Mask:
  3440. if (QStyleHintReturnMask* mask = qstyleoption_cast<QStyleHintReturnMask*>(returnData)) {
  3441. //left rounded corner
  3442. mask->region = option->rect;
  3443. mask->region -= QRect(option->rect.left(), option->rect.top(), 5, 1);
  3444. mask->region -= QRect(option->rect.left(), option->rect.top() + 1, 3, 1);
  3445. mask->region -= QRect(option->rect.left(), option->rect.top() + 2, 2, 1);
  3446. mask->region -= QRect(option->rect.left(), option->rect.top() + 3, 1, 2);
  3447. //right rounded corner
  3448. mask->region -= QRect(option->rect.right() - 4, option->rect.top(), 5, 1);
  3449. mask->region -= QRect(option->rect.right() - 2, option->rect.top() + 1, 3, 1);
  3450. mask->region -= QRect(option->rect.right() - 1, option->rect.top() + 2, 2, 1);
  3451. mask->region -= QRect(option->rect.right() , option->rect.top() + 3, 1, 2);
  3452. return 1;
  3453. }
  3454. default:
  3455. break;
  3456. }
  3457. return QCommonStyle::styleHint(hint, option, widget, returnData);
  3458. }
  3459. /*! \reimp */
  3460. QRect CarlaStyle::subElementRect(SubElement sr, const QStyleOption *opt, const QWidget *w) const
  3461. {
  3462. QRect r = QCommonStyle::subElementRect(sr, opt, w);
  3463. switch (sr) {
  3464. case SE_ProgressBarLabel:
  3465. case SE_ProgressBarContents:
  3466. case SE_ProgressBarGroove:
  3467. return opt->rect;
  3468. case SE_PushButtonFocusRect:
  3469. r.adjust(0, 1, 0, -1);
  3470. break;
  3471. case SE_DockWidgetTitleBarText: {
  3472. if (const QStyleOptionDockWidget *titlebar = qstyleoption_cast<const QStyleOptionDockWidget*>(opt)) {
  3473. Q_UNUSED(titlebar);
  3474. bool verticalTitleBar = false;
  3475. if (verticalTitleBar) {
  3476. r.adjust(0, 0, 0, -4);
  3477. } else {
  3478. if (opt->direction == Qt::LeftToRight)
  3479. r.adjust(4, 0, 0, 0);
  3480. else
  3481. r.adjust(0, 0, -4, 0);
  3482. }
  3483. }
  3484. break;
  3485. }
  3486. default:
  3487. break;
  3488. }
  3489. return r;
  3490. }