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.

CarlaStyle.cpp 178KB

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