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.

3682 lines
171KB

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