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.

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