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.

3478 lines
159KB

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