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.

3866 lines
178KB

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