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.

3680 lines
171KB

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