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

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