TDE core libraries
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.

kthemestyle.cpp 99KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459
  1. /*
  2. $Id$
  3. This file is part of the KDE libraries
  4. Copyright (C) 1999 Daniel M. Duley <mosfet@kde.org>
  5. KDE3 port (C) 2001-2002 Maksim Orlovich <mo002j@mail.rochester.edu>
  6. Port version 0.9.7
  7. Includes code portions from the dotNET style, and the KDE HighColor style.
  8. dotNET Style
  9. Copyright (C) 2001, Chris Lee <lee@azsites.com>
  10. Carsten Pfeiffer <pfeiffer@kde.org>
  11. KDE3 HighColor Style
  12. Copyright (C) 2001 Karol Szwed <gallium@kde.org>
  13. (C) 2001 Fredrik H�glund <fredrik@kde.org>
  14. Drawing routines adapted from the KDE2 HCStyle,
  15. Copyright (C) 2000 Daniel M. Duley <mosfet@kde.org>
  16. (C) 2000 Dirk Mueller <mueller@kde.org>
  17. (C) 2001 Martijn Klingens <klingens@kde.org>
  18. This library is free software; you can redistribute it and/or
  19. modify it under the terms of the GNU Library General Public
  20. License version 2 as published by the Free Software Foundation.
  21. This library is distributed in the hope that it will be useful,
  22. but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  24. Library General Public License for more details.
  25. You should have received a copy of the GNU Library General Public License
  26. along with this library; see the file COPYING.LIB. If not, write to
  27. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  28. Boston, MA 02110-1301, USA.
  29. */
  30. #include "kthemestyle.h"
  31. #include "kthemebase.h"
  32. #include <tqstyleplugin.h>
  33. #include <tqstylefactory.h>
  34. #include <kimageeffect.h>
  35. #include <tqbitmap.h>
  36. #include <tqcheckbox.h>
  37. #include <tqlabel.h>
  38. #define INCLUDE_MENUITEM_DEF
  39. #include <tqmenudata.h>
  40. #include <tqpopupmenu.h>
  41. #include <tqpalette.h>
  42. #include <tqtabbar.h>
  43. #include <tqtoolbutton.h>
  44. #include <tdeglobalsettings.h>
  45. #include <kdrawutil.h>
  46. #include <tqdrawutil.h>
  47. #include <tqprogressbar.h>
  48. #include <tqdir.h>
  49. #include <tqapplication.h>
  50. #include <tqmenubar.h>
  51. #include <tqrangecontrol.h>
  52. #include <tqslider.h>
  53. #include <tqtooltip.h>
  54. #include <tqobjectlist.h>
  55. #include <tqradiobutton.h>
  56. #include <tqstatusbar.h>
  57. #include "kstyledirs.h"
  58. #include <tqimage.h>
  59. #include <limits.h>
  60. #ifdef __GLIBC__
  61. #include <dlfcn.h>
  62. #endif
  63. static const TQCOORD u_arrow[] = { -1, -3, 0, -3, -2, -2, 1, -2, -3, -1, 2, -1, -4, 0, 3, 0, -4, 1, 3, 1};
  64. static const TQCOORD d_arrow[] = { -4, -2, 3, -2, -4, -1, 3, -1, -3, 0, 2, 0, -2, 1, 1, 1, -1, 2, 0, 2};
  65. static const TQCOORD l_arrow[] = { -3, -1, -3, 0, -2, -2, -2, 1, -1, -3, -1, 2, 0, -4, 0, 3, 1, -4, 1, 3};
  66. static const TQCOORD r_arrow[] = { -2, -4, -2, 3, -1, -4, -1, 3, 0, -3, 0, 2, 1, -2, 1, 1, 2, -1, 2, 0};
  67. const TQCOORD win_style_u_arrow[] = { 0, -2, 0, -2, -1, -1, 1, -1, -2, 0, 2, 0, -3, 1, 3, 1 };
  68. const TQCOORD win_style_d_arrow[] = { -3, -2, 3, -2, -2, -1, 2, -1, -1, 0, 1, 0, 0, 1, 0, 1 };
  69. const TQCOORD win_style_l_arrow[] = { 1, -3, 1, -3, 0, -2, 1, -2, -1, -1, 1, -1, -2, 0, 1, 0, -1, 1, 1, 1, 0, 2, 1, 2, 1, 3, 1, 3 };
  70. const TQCOORD win_style_r_arrow[] = { -2, -3, -2, -3, -2, -2, -1, -2, -2, -1, 0, -1, -2, 0, 1, 0, -2, 1, 0, 1, -2, 2, -1, 2, -2, 3, -2, 3 };
  71. #define TQCOORDARRLEN(x) sizeof(x)/(sizeof(TQCOORD)*2)
  72. static const int itemFrame = 2;
  73. static const int itemHMargin = 3;
  74. static const int itemVMargin = 1;
  75. static const int arrowHMargin = 6;
  76. static const int rightBorder = 12;
  77. /*
  78. BUGS:
  79. Sliders flash a bit -- anything else?
  80. TODO:
  81. Nicer disabled buttons.
  82. Sliders are not disabled properly
  83. */
  84. class KThemeStylePlugin : public TQStylePlugin
  85. {
  86. public:
  87. KThemeStylePlugin()
  88. {
  89. #ifdef __GLIBC__
  90. dlopen("kthemestyle.so",RTLD_LAZY);
  91. //####### Keep reference count up so tdecore w. fast-malloc doesn't get unloaded
  92. //####### (Fixes exit crashes with qt-only apps that occur on Linux)
  93. //####### This should be rethought after 3.0,
  94. //####### as it relies on the implementation-specific behavior
  95. //####### of the glibc libdl (finding already loaded libraries based on the
  96. //####### soname)
  97. #endif
  98. }
  99. ~KThemeStylePlugin()
  100. {}
  101. TQStringList keys() const
  102. {
  103. TQSettings cfg;
  104. TDEStyleDirs::dirs()->addToSearch( "config", cfg );
  105. TQStringList keys;
  106. bool ok;
  107. keys = cfg.readListEntry( "/kthemestyle/themes", &ok);
  108. if ( !ok )
  109. tqWarning( "KThemeStyle cache seems corrupt!\n" ); //Too bad one can't i18n this :-(
  110. return keys;
  111. }
  112. TQStyle* create( const TQString& key )
  113. {
  114. TQSettings cfg;
  115. TDEStyleDirs::dirs()->addToSearch( "config", cfg );
  116. TQString file = cfg.readEntry( "/kthemestyle/" + key + "/file" );
  117. if ( !key.isEmpty() )
  118. {
  119. TQFileInfo fi( file );
  120. return new KThemeStyle( fi.dirPath(), fi.fileName() );
  121. }
  122. return 0;
  123. }
  124. };
  125. KDE_Q_EXPORT_PLUGIN( KThemeStylePlugin )
  126. void kDrawWindowsArrow ( TQPainter *p, const TQStyleControlElementData &ceData, const TQStyle::ControlElementFlags elementFlags, const TQStyle* style, TQStyle::PrimitiveElement pe, bool down,
  127. int x, int y, int w, int h,
  128. const TQColorGroup &cg, bool enabled )
  129. {
  130. TQPointArray a;
  131. switch ( pe )
  132. {
  133. case TQStyle::PE_ArrowUp:
  134. a.setPoints( TQCOORDARRLEN( win_style_u_arrow ), win_style_u_arrow );
  135. break;
  136. case TQStyle::PE_ArrowDown:
  137. a.setPoints( TQCOORDARRLEN( win_style_d_arrow ), win_style_d_arrow );
  138. break;
  139. case TQStyle::PE_ArrowLeft:
  140. a.setPoints( TQCOORDARRLEN( win_style_l_arrow ), win_style_l_arrow );
  141. break;
  142. default:
  143. a.setPoints( TQCOORDARRLEN( win_style_r_arrow ), win_style_r_arrow );
  144. }
  145. p->save();
  146. if ( down )
  147. {
  148. p->translate( style->pixelMetric( TQStyle::PM_ButtonShiftHorizontal, ceData, elementFlags ),
  149. style->pixelMetric( TQStyle::PM_ButtonShiftVertical, ceData, elementFlags ) );
  150. }
  151. if ( enabled )
  152. {
  153. a.translate( x + w / 2, y + h / 2 );
  154. p->setPen( cg.buttonText() );
  155. p->drawLineSegments( a );
  156. }
  157. else
  158. {
  159. a.translate( x + w / 2 + 1, y + h / 2 + 1 );
  160. p->setPen( cg.light() );
  161. p->drawLineSegments( a );
  162. a.translate( -1, -1 );
  163. p->setPen( cg.mid() );
  164. p->drawLineSegments( a );
  165. }
  166. p->restore();
  167. }
  168. TQSize KThemeStyle::sizeFromContents( ContentsType contents,
  169. const TQStyleControlElementData &ceData,
  170. ControlElementFlags elementFlags,
  171. const TQSize &contentSize,
  172. const TQStyleOption& opt,
  173. const TQWidget* widget ) const
  174. {
  175. switch ( contents )
  176. {
  177. // PUSHBUTTON SIZE
  178. // ------------------------------------------------------------------
  179. case CT_PushButton:
  180. {
  181. const TQPushButton * button = ( const TQPushButton* ) widget;
  182. int w = contentSize.width();
  183. int h = contentSize.height();
  184. int bm = pixelMetric( PM_ButtonMargin, ceData, elementFlags, widget );
  185. int fw = pixelMetric( PM_DefaultFrameWidth, ceData, elementFlags, widget ) * 2;
  186. w += bm + fw + 6; // ### Add 6 to make way for bold font.
  187. h += bm + fw;
  188. // Ensure we stick to standard width and heights.
  189. if ( button->isDefault() || button->autoDefault() )
  190. {
  191. if ( w < 80 && !button->text().isEmpty() )
  192. w = 80;
  193. }
  194. if ( h < 22 )
  195. h = 22;
  196. return TQSize( w, h );
  197. }
  198. // POPUPMENU ITEM SIZE
  199. // -----------------------------------------------------------------
  200. case CT_PopupMenuItem:
  201. {
  202. if ( ! widget || opt.isDefault() )
  203. return contentSize;
  204. const TQPopupMenu *popup = ( const TQPopupMenu * ) widget;
  205. bool checkable = popup->isCheckable();
  206. TQMenuItem *mi = opt.menuItem();
  207. int maxpmw = opt.maxIconWidth();
  208. int w = contentSize.width(), h = contentSize.height();
  209. if ( mi->custom() )
  210. {
  211. w = mi->custom() ->sizeHint().width();
  212. h = mi->custom() ->sizeHint().height();
  213. if ( ! mi->custom() ->fullSpan() )
  214. h += 2 * itemVMargin + 2 * itemFrame;
  215. }
  216. else if ( mi->widget() )
  217. {}
  218. else if ( mi->isSeparator() )
  219. {
  220. w = 10; // Arbitrary
  221. h = 2;
  222. }
  223. else
  224. {
  225. if ( mi->pixmap() )
  226. h = QMAX( h, mi->pixmap() ->height() + 2 * itemFrame );
  227. else
  228. h = QMAX( h, popup->fontMetrics().height()
  229. + 2 * itemVMargin + 2 * itemFrame );
  230. if ( mi->iconSet() )
  231. h = QMAX( h, mi->iconSet() ->pixmap(
  232. TQIconSet::Small, TQIconSet::Normal ).height() +
  233. 2 * itemFrame );
  234. }
  235. if ( ! mi->text().isNull() && mi->text().find( '\t' ) >= 0 )
  236. w += 12;
  237. else if ( mi->popup() )
  238. w += 2 * arrowHMargin;
  239. if ( maxpmw )
  240. w += maxpmw + 6;
  241. if ( checkable && maxpmw < 20 )
  242. w += 20 - maxpmw;
  243. if ( checkable || maxpmw > 0 )
  244. w += 12;
  245. w += rightBorder;
  246. return TQSize( w, h );
  247. }
  248. default:
  249. return KThemeBase::sizeFromContents( contents, ceData, elementFlags, contentSize, opt, widget );
  250. }
  251. }
  252. TQRect KThemeStyle::subRect(SubRect sr, const TQStyleControlElementData &ceData, const ControlElementFlags elementFlags, const TQWidget* widget) const
  253. {
  254. if (sr == SR_CheckBoxFocusRect)
  255. {
  256. const TQCheckBox* cb = static_cast<const TQCheckBox*>(widget);
  257. //Only checkbox, no label
  258. if (cb->text().isEmpty() && (cb->pixmap() == 0) )
  259. {
  260. TQRect bounding = cb->rect();
  261. int cw = pixelMetric(PM_IndicatorWidth, ceData, elementFlags, widget);
  262. int ch = pixelMetric(PM_IndicatorHeight, ceData, elementFlags, widget);
  263. TQRect checkbox(bounding.x() + 2, bounding.y() + 2 + (bounding.height() - ch)/2, cw - 4, ch - 4);
  264. return checkbox;
  265. }
  266. }
  267. return TDEStyle::subRect(sr, ceData, elementFlags, widget);
  268. }
  269. int KThemeStyle::pixelMetric ( PixelMetric metric, const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, const TQWidget * widget ) const
  270. {
  271. switch ( metric )
  272. {
  273. case PM_MenuBarFrameWidth:
  274. return 1;
  275. case PM_DefaultFrameWidth:
  276. return ( frameWidth() );
  277. case PM_ButtonMargin:
  278. return decoWidth( PushButton ) > decoWidth( PushButtonDown ) ?
  279. 3 + decoWidth( PushButton ) : 3 + decoWidth( PushButtonDown );
  280. case PM_ScrollBarExtent:
  281. case PM_SliderThickness: //Should this be 16 always?
  282. return getSBExtent();
  283. case PM_ButtonDefaultIndicator:
  284. return 0;
  285. case PM_ButtonShiftHorizontal:
  286. return buttonXShift();
  287. case PM_ButtonShiftVertical:
  288. return buttonYShift();
  289. case PM_ExclusiveIndicatorWidth:
  290. if ( isPixmap( ExIndicatorOn ) )
  291. return ( uncached( ExIndicatorOn ) ->size().width() );
  292. else
  293. return KThemeBase::pixelMetric ( metric, ceData, elementFlags, widget );
  294. case PM_ExclusiveIndicatorHeight:
  295. if ( isPixmap( ExIndicatorOn ) )
  296. return ( uncached( ExIndicatorOn ) ->size().height() );
  297. else
  298. return KThemeBase::pixelMetric ( metric, ceData, elementFlags, widget );
  299. case PM_IndicatorWidth:
  300. if ( isPixmap( IndicatorOn ) )
  301. return ( uncached( IndicatorOn ) ->size().width() );
  302. else
  303. return KThemeBase::pixelMetric ( metric, ceData, elementFlags, widget );
  304. case PM_IndicatorHeight:
  305. if ( isPixmap( IndicatorOn ) )
  306. return ( uncached( IndicatorOn ) ->size().height() );
  307. else
  308. return KThemeBase::pixelMetric ( metric, ceData, elementFlags, widget );
  309. case PM_SliderLength:
  310. return ( sliderButtonLength() );
  311. case PM_SplitterWidth:
  312. return ( splitWidth() );
  313. case PM_MenuIndicatorFrameHBorder:
  314. case PM_MenuIndicatorFrameVBorder:
  315. case PM_MenuIconIndicatorFrameHBorder:
  316. case PM_MenuIconIndicatorFrameVBorder:
  317. return 0;
  318. default:
  319. return KThemeBase::pixelMetric ( metric, ceData, elementFlags, widget );
  320. }
  321. }
  322. KThemeStyle::KThemeStyle( const TQString& configDir, const TQString &configFile )
  323. : KThemeBase( configDir, configFile ), paletteSaved( false ), polishLock( false ), menuCache( 0 ), vsliderCache( 0 ),
  324. brushHandle( 0 ), brushHandleSet( false ), kickerMode( false )
  325. {
  326. mtfstyle = TQStyleFactory::create( "Motif" );
  327. if ( !mtfstyle )
  328. mtfstyle = TQStyleFactory::create( *( TQStyleFactory::keys().begin() ) );
  329. }
  330. KThemeStyle::~KThemeStyle()
  331. {
  332. delete vsliderCache;
  333. delete menuCache;
  334. }
  335. void KThemeStyle::applicationPolish( const TQStyleControlElementData &ceData, ControlElementFlags, void *ptr )
  336. {
  337. if (ceData.widgetObjectTypes.contains(TQAPPLICATION_OBJECT_NAME_STRING)) {
  338. TQApplication *app = reinterpret_cast<TQApplication*>(ptr);
  339. if (!qstrcmp(app->argv()[0], "kicker")) {
  340. kickerMode = true;
  341. }
  342. }
  343. }
  344. void KThemeStyle::polish( TQPalette &p )
  345. {
  346. if ( polishLock )
  347. {
  348. return ; //Palette polishing disabled ...
  349. }
  350. if ( !paletteSaved )
  351. {
  352. oldPalette = p;
  353. paletteSaved = true;
  354. }
  355. p = overridePalette( p );
  356. if ( isPixmap( Background ) )
  357. {
  358. TQBrush bgBrush( p.color( TQPalette::Normal,
  359. TQColorGroup::Background ),
  360. *uncached( Background ) );
  361. brushHandle = uncached( Background )->handle();
  362. brushHandleSet = true;
  363. p.setBrush( TQColorGroup::Background, bgBrush );
  364. }
  365. }
  366. void KThemeStyle::paletteChanged()
  367. {
  368. TQPalette p = TQApplication::palette();
  369. polish( p );
  370. TQApplication::setPalette( p );
  371. }
  372. void KThemeStyle::applicationUnPolish( const TQStyleControlElementData &ceData, ControlElementFlags, void *ptr )
  373. {
  374. if (ceData.widgetObjectTypes.contains(TQAPPLICATION_OBJECT_NAME_STRING)) {
  375. TQApplication *app = reinterpret_cast<TQApplication*>(ptr);
  376. app->setPalette( oldPalette, true );
  377. }
  378. }
  379. bool KThemeStyle::objectEventHandler( const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, void* source, TQEvent *event )
  380. {
  381. if (ceData.widgetObjectTypes.contains(TQOBJECT_OBJECT_NAME_STRING)) {
  382. TQObject* object = reinterpret_cast<TQObject*>(source);
  383. if( object->inherits("KActiveLabel"))
  384. {
  385. if(event->type() == TQEvent::Move || event->type() == TQEvent::Resize ||
  386. event->type() == TQEvent::Show)
  387. {
  388. TQWidget *w = TQT_TQWIDGET(object);
  389. TQPoint pos(0, 0);
  390. pos = w->mapTo(w->topLevelWidget(), pos);
  391. TQPixmap pix(uncached( Background )->size());
  392. TQPainter p;
  393. p.begin(&pix);
  394. p.drawTiledPixmap(0, 0,
  395. uncached( Background )->width(),
  396. uncached( Background )->height() ,
  397. *uncached( Background ),
  398. pos.x(), pos.y());
  399. p.end();
  400. TQPalette pal(w->palette());
  401. TQBrush brush( pal.color( TQPalette::Normal,
  402. TQColorGroup::Background),
  403. pix );
  404. pal.setBrush(TQColorGroup::Base, brush);
  405. w->setPalette(pal);
  406. }
  407. }
  408. if (!qstrcmp(object->name(), "kde toolbar widget") && object->inherits(TQLABEL_OBJECT_NAME_STRING))
  409. {
  410. TQWidget* lb = TQT_TQWIDGET(object);
  411. if (lb->backgroundMode() == TQt::PaletteButton)
  412. lb->setBackgroundMode(TQt::PaletteBackground);
  413. removeObjectEventHandler(ceData, elementFlags, source, this);
  414. }
  415. }
  416. return TDEStyle::objectEventHandler(ceData, elementFlags, source, event);
  417. }
  418. void KThemeStyle::polish( const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, void *ptr )
  419. {
  420. if (ceData.widgetObjectTypes.contains(TQWIDGET_OBJECT_NAME_STRING)) {
  421. TQWidget *w = reinterpret_cast<TQWidget*>(ptr);
  422. if (::tqqt_cast<TQStatusBar*>(w))
  423. w->setPaletteBackgroundColor(TQApplication::palette().color(TQPalette::Normal, TQColorGroup::Background));
  424. if (::tqqt_cast<TQLabel*>(w) && !qstrcmp(w->name(), "kde toolbar widget"))
  425. installObjectEventHandler(ceData, elementFlags, ptr, this);
  426. if (w->backgroundPixmap() && !w->isTopLevel() &&
  427. (!kickerMode ||
  428. (!w->inherits("TaskBar") && !w->inherits("TaskBarContainer") && !w->inherits("TaskbarApplet") && !w->inherits("ContainerArea") && !w->inherits("AppletHandle"))))
  429. {
  430. //The brushHandle check verifies that the bg pixmap is actually the brush..
  431. if (!brushHandleSet || brushHandle == w->backgroundPixmap()->handle())
  432. {
  433. w->setBackgroundOrigin( TQWidget::WindowOrigin );
  434. }
  435. }
  436. if (w->inherits("KActiveLabel"))
  437. {
  438. if (uncached( Background ))
  439. installObjectEventHandler(ceData, elementFlags, ptr, this);
  440. }
  441. if ( w->inherits( "QTipLabel" ) )
  442. {
  443. polishLock = true;
  444. TQColorGroup clrGroup( Qt::black, TQColor( 255, 255, 220 ),
  445. TQColor( 96, 96, 96 ), Qt::black, Qt::black,
  446. Qt::black, TQColor( 255, 255, 220 ) );
  447. TQPalette toolTip ( clrGroup, clrGroup, clrGroup );
  448. TQToolTip::setPalette( toolTip );
  449. polishLock = false;
  450. }
  451. if ( w->inherits( "KonqIconViewWidget" ) ) //Konqueror background hack/workaround
  452. {
  453. w->setPalette( oldPalette );
  454. return ;
  455. }
  456. if ( ::tqqt_cast<TQMenuBar*>(w) )
  457. {
  458. w->setBackgroundMode( TQWidget::NoBackground );
  459. }
  460. else if ( w->inherits( "TDEToolBarSeparator" ) || w->inherits( "QToolBarSeparator" ) )
  461. {
  462. w->setBackgroundMode( TQWidget::PaletteBackground );
  463. }
  464. else if ( ::tqqt_cast<TQPopupMenu*>(w) )
  465. {
  466. popupPalette = w->palette();
  467. if ( isColor( MenuItem ) || isColor( MenuItemDown ) )
  468. {
  469. TQPalette newPal( w->palette() );
  470. if ( isColor( MenuItem ) )
  471. {
  472. newPal.setActive( *colorGroup( newPal.active(), MenuItem ) );
  473. newPal.setDisabled( *colorGroup( newPal.active(), MenuItem ) );
  474. }
  475. if ( isColor( MenuItemDown ) )
  476. {
  477. newPal.setActive( *colorGroup( newPal.active(), MenuItemDown ) );
  478. }
  479. w->setPalette( newPal );
  480. }
  481. w->setBackgroundMode( TQWidget::NoBackground );
  482. }
  483. else if ( ::tqqt_cast<TQCheckBox*>(w) )
  484. {
  485. if ( isColor( IndicatorOff ) || isColor( IndicatorOn ) )
  486. {
  487. TQPalette newPal( w->palette() );
  488. if ( isColor( IndicatorOff ) )
  489. {
  490. newPal.setActive( *colorGroup( newPal.active(), IndicatorOff ) );
  491. newPal.setDisabled( *colorGroup( newPal.active(), IndicatorOff ) );
  492. }
  493. if ( isColor( IndicatorOn ) )
  494. newPal.setActive( *colorGroup( newPal.active(), IndicatorOn ) );
  495. w->setPalette( newPal );
  496. }
  497. }
  498. else if ( ::tqqt_cast<TQRadioButton*>(w) )
  499. {
  500. if ( isColor( ExIndicatorOff ) || isColor( ExIndicatorOn ) )
  501. {
  502. TQPalette newPal( w->palette() );
  503. if ( isColor( ExIndicatorOff ) )
  504. {
  505. newPal.setActive( *colorGroup( newPal.active(), ExIndicatorOff ) );
  506. newPal.setDisabled( *colorGroup( newPal.active(),
  507. ExIndicatorOff ) );
  508. }
  509. if ( isColor( ExIndicatorOn ) )
  510. newPal.setActive( *colorGroup( newPal.active(), ExIndicatorOn ) );
  511. w->setPalette( newPal );
  512. }
  513. }
  514. }
  515. TDEStyle::polish( ceData, elementFlags, ptr );
  516. }
  517. void KThemeStyle::unPolish( const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, void *ptr )
  518. {
  519. if (ceData.widgetObjectTypes.contains(TQWIDGET_OBJECT_NAME_STRING)) {
  520. TQWidget *w = reinterpret_cast<TQWidget*>(ptr);
  521. if (w->backgroundPixmap() && !w->isTopLevel())
  522. {
  523. //The brushHandle check verifies that the bg pixmap is actually the brush..
  524. if (!brushHandleSet || brushHandle ==w->backgroundPixmap()->handle())
  525. {
  526. w->setBackgroundOrigin( TQWidget::WidgetOrigin );
  527. }
  528. }
  529. //Toolbar labels should nornally be PaletteButton
  530. if ( ::tqqt_cast<TQLabel*>(w) && !qstrcmp(w->name(), "kde toolbar widget"))
  531. w->setBackgroundMode( TQWidget::PaletteButton );
  532. //The same for menu bars, popup menus
  533. else if ( ::tqqt_cast<TQMenuBar*>(w) || ::tqqt_cast<TQPopupMenu*>(w) )
  534. w->setBackgroundMode( TQWidget::PaletteButton );
  535. //For toolbar internal separators, return to button, too (can't use tqqt_cast here since don't have access to the class)
  536. else if ( w->inherits( "TDEToolBarSeparator" ) || w->inherits( "QToolBarSeparator" ) )
  537. w->setBackgroundMode( TQWidget::PaletteButton );
  538. //For scrollbars, we don't do much, since the widget queries the style on the switch
  539. //Drop some custom palettes. ### this really should check the serial number to be 100% correct.
  540. if ( ::tqqt_cast<TQPopupMenu*>(w) || ::tqqt_cast<TQCheckBox*>(w) || ::tqqt_cast<TQRadioButton*>(w) || ::tqqt_cast<TQStatusBar*>(w) )
  541. w->unsetPalette();
  542. }
  543. TDEStyle::unPolish( ceData, elementFlags, ptr );
  544. }
  545. void KThemeStyle::drawBaseButton( TQPainter *p, int x, int y, int w, int h,
  546. const TQColorGroup &g, bool sunken, bool
  547. rounded, WidgetType type ) const
  548. {
  549. int offset = borderPixmap( type ) ? 0 : decoWidth( type ) ; //##### This is wrong, but the code relies on it..
  550. TQPen oldPen = p->pen();
  551. // handle reverse bevel here since it uses decowidth differently
  552. if ( gradientHint( type ) == GrReverseBevel )
  553. {
  554. int i;
  555. bitBlt( p->device(), x, y, TQT_TQPAINTDEVICE(scalePixmap( w, h, type )), 0, 0, w, h,
  556. TQt::CopyROP, true );
  557. p->setPen( g.text() );
  558. for ( i = 0; i < borderWidth( type ); ++i, ++x, ++y, w -= 2, h -= 2 )
  559. p->drawRect( x, y, w, h );
  560. }
  561. // same with KDE style borders
  562. else if ( !borderPixmap( type ) && shade() == KDE )
  563. {
  564. kDrawBeButton( p, x, y, w, h, g, sunken );
  565. if ( isPixmap( type ) )
  566. p->drawTiledPixmap( x + 4, y + 4, w - 6, h - 6,
  567. *scalePixmap( w - 6, h - 6,
  568. type ) );
  569. else
  570. p->fillRect( x + 4, y + 4, w - 6, h - offset * 6,
  571. g.brush( TQColorGroup::Button ) );
  572. }
  573. else
  574. {
  575. if ( ( w - offset * 2 ) > 0 && ( h - offset * 2 ) > 0 )
  576. {
  577. if ( isPixmap( type ) )
  578. if ( rounded )
  579. p->drawTiledPixmap( x, y, w, h, *scalePixmap( w, h, type ) );
  580. else
  581. p->drawTiledPixmap( x + offset, y + offset, w - offset * 2,
  582. h - offset * 2,
  583. *scalePixmap( w - offset * 2, h - offset * 2,
  584. type ) );
  585. else if ( 1 ) //##### TODO - Get this optimization working... !borderPixmap( type ) || (( w - decoWidth(type) * 2 ) > 0 && ( h - decoWidth(type) * 2 ) > 0) )
  586. //Sometimes border covers the whole thing - in that case, avoid drawing the base.
  587. {
  588. p->fillRect( x + offset, y + offset, w - offset * 2, h - offset * 2,
  589. g.brush( TQColorGroup::Button ) );
  590. }
  591. }
  592. if ( borderPixmap( type ) )
  593. {
  594. bitBlt( p->device(), x, y, TQT_TQPAINTDEVICE(scaleBorder( w, h, type )), 0, 0, w, h,
  595. TQt::CopyROP, false );
  596. }
  597. else
  598. drawShade( p, x, y, w, h, g, sunken, rounded,
  599. highlightWidth( type ), borderWidth( type ), shade() );
  600. }
  601. p->setPen( oldPen );
  602. }
  603. void KThemeStyle::drawPrimitive ( PrimitiveElement pe, TQPainter * p, const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, const TQRect & r, const TQColorGroup & g_base,
  604. SFlags flags, const TQStyleOption & opt ) const
  605. {
  606. bool handled = false;
  607. int x, y, w, h;
  608. r.rect( &x, &y, &w, &h );
  609. bool sunken = ( flags & Style_Sunken );
  610. bool enabled = ( flags & Style_Enabled );
  611. bool down = ( flags & Style_Down );
  612. bool on = flags & Style_On;
  613. bool active = flags & Style_Active;
  614. TQColorGroup g = g_base;
  615. switch ( pe )
  616. {
  617. case PE_ArrowUp:
  618. case PE_ArrowDown:
  619. case PE_ArrowRight:
  620. case PE_ArrowLeft:
  621. {
  622. TQRect r( x, y, w, h );
  623. if ( r.width() > 12 )
  624. {
  625. r.setRect( r.x() + ( r.width() - 12 ) / 2, r.y(), 12, r.height() );
  626. }
  627. if ( r.height() > 12 )
  628. {
  629. r.setRect( r.x(), r.y() + ( r.height() - 12 ) / 2, r.width(), 12 );
  630. }
  631. r.rect( &x, &y, &w, &h );
  632. // Handles pixmapped arrows. A little inefficient because you can specify
  633. // some as pixmaps and some as default types.
  634. WidgetType widget;
  635. switch ( pe )
  636. {
  637. case PE_ArrowUp:
  638. widget = enabled ? down ? SunkenArrowUp : ArrowUp : DisArrowUp;
  639. break;
  640. case PE_ArrowDown:
  641. widget = enabled ? down ? SunkenArrowDown : ArrowDown : DisArrowDown;
  642. break;
  643. case PE_ArrowLeft:
  644. widget = enabled ? down ? SunkenArrowLeft : ArrowLeft : DisArrowLeft;
  645. break;
  646. case PE_ArrowRight:
  647. default:
  648. widget = enabled ? down ? SunkenArrowRight : ArrowRight : DisArrowRight;
  649. break;
  650. }
  651. if ( isPixmap( widget ) )
  652. {
  653. bitBlt( p->device(), x + ( w - uncached( widget ) ->width() ) / 2,
  654. y + ( h - uncached( widget ) ->height() ) / 2,
  655. uncached( widget ) );
  656. return ;
  657. }
  658. const TQColorGroup *cg = colorGroup( g, widget );
  659. // Standard arrow types
  660. if ( arrowType() == MotifArrow )
  661. {
  662. mtfstyle->drawPrimitive( pe, p, ceData, elementFlags, r, g, flags, opt );
  663. handled = true;
  664. }
  665. else if ( arrowType() == SmallArrow )
  666. {
  667. // #### FIXME: This should be like the Platinum style - uses HighColor look for now
  668. TQPointArray a;
  669. switch ( pe )
  670. {
  671. case PE_ArrowUp:
  672. a.setPoints( TQCOORDARRLEN( u_arrow ), u_arrow );
  673. break;
  674. case PE_ArrowDown:
  675. a.setPoints( TQCOORDARRLEN( d_arrow ), d_arrow );
  676. break;
  677. case PE_ArrowLeft:
  678. a.setPoints( TQCOORDARRLEN( l_arrow ), l_arrow );
  679. break;
  680. default:
  681. a.setPoints( TQCOORDARRLEN( r_arrow ), r_arrow );
  682. }
  683. p->save();
  684. if ( flags & Style_Down )
  685. p->translate( pixelMetric( PM_ButtonShiftHorizontal, ceData, elementFlags ),
  686. pixelMetric( PM_ButtonShiftVertical, ceData, elementFlags ) );
  687. if ( flags & Style_Enabled )
  688. {
  689. a.translate( r.x() + r.width() / 2, r.y() + r.height() / 2 );
  690. p->setPen( cg->buttonText() );
  691. p->drawLineSegments( a );
  692. }
  693. else
  694. {
  695. a.translate( r.x() + r.width() / 2 + 1, r.y() + r.height() / 2 + 1 );
  696. p->setPen( cg->mid() );
  697. p->drawLineSegments( a );
  698. }
  699. p->restore();
  700. }
  701. else
  702. {
  703. TQPointArray a;
  704. int x2 = x + w - 1, y2 = y + h - 1;
  705. switch ( pe )
  706. {
  707. case PE_ArrowUp:
  708. a.setPoints( 4, x, y2, x2, y2, x + w / 2, y, x, y2 );
  709. break;
  710. case PE_ArrowDown:
  711. a.setPoints( 4, x, y, x2, y, x + w / 2, y2, x, y );
  712. break;
  713. case PE_ArrowLeft:
  714. a.setPoints( 4, x2, y, x2, y2, x, y + h / 2, x2, y );
  715. break;
  716. default:
  717. a.setPoints( 4, x, y, x, y2, x2, y + h / 2, x, y );
  718. break;
  719. }
  720. TQBrush oldBrush = p->brush();
  721. TQPen oldPen = p->pen();
  722. p->setBrush( cg->brush( TQColorGroup::Shadow ) );
  723. p->setPen( cg->shadow() );
  724. p->drawPolygon( a );
  725. p->setBrush( oldBrush );
  726. p->setPen( oldPen );
  727. handled = true;
  728. }
  729. break;
  730. }
  731. case PE_HeaderSectionMenu:
  732. case PE_HeaderSection:
  733. {
  734. sunken = false; //Never mind this one
  735. }
  736. case PE_ButtonBevel:
  737. {
  738. WidgetType type = ( sunken || on || down ) ? BevelDown : Bevel;
  739. drawBaseButton( p, x, y, w, h, *colorGroup( g, type ), ( sunken || on || down ), false, type );
  740. handled = true;
  741. break;
  742. }
  743. case PE_ButtonCommand:
  744. {
  745. drawBaseButton( p, x, y, w, h, g, ( sunken || on || down ), roundButton(), ( sunken || on || down ) ?
  746. PushButtonDown : PushButton );
  747. handled = true;
  748. break;
  749. }
  750. case PE_PanelDockWindow:
  751. {
  752. drawBaseButton( p, x, y, w, h, *colorGroup( g, ToolBar ), false, false,
  753. ToolBar );
  754. handled = true;
  755. break;
  756. }
  757. case PE_CheckMark:
  758. {
  759. if ( isPixmap( CheckMark ) )
  760. {
  761. if ( flags & Style_Enabled || flags & Style_On )
  762. bitBlt( p->device(), x + ( w - uncached( CheckMark ) ->width() ) / 2,
  763. y + ( h - uncached( CheckMark ) ->height() ) / 2,
  764. uncached( CheckMark ) );
  765. handled = true;
  766. }
  767. else //Small hack to ensure the checkmark gets painter proper color..
  768. {
  769. g.setColor( TQColorGroup::Text, g.buttonText() );
  770. }
  771. break;
  772. }
  773. case PE_ExclusiveIndicator:
  774. {
  775. if ( isPixmap( ( flags & Style_On || flags & Style_Down ) ? ExIndicatorOn : ExIndicatorOff ) )
  776. {
  777. p->drawPixmap( x, y, *uncached( ( flags & Style_On || flags & Style_Down ) ? ExIndicatorOn :
  778. ExIndicatorOff ) );
  779. handled = true;
  780. }
  781. break;
  782. }
  783. case PE_ExclusiveIndicatorMask:
  784. {
  785. if ( isPixmap( ( flags & Style_On || flags & Style_Down ) ? ExIndicatorOn : ExIndicatorOff ) )
  786. {
  787. const TQBitmap * mask = uncached( ( flags & Style_On || flags & Style_Down ) ? ExIndicatorOn : ExIndicatorOff ) ->mask();
  788. if ( mask )
  789. {
  790. p->setPen( Qt::color1 );
  791. p->drawPixmap( x, y, *mask );
  792. }
  793. else
  794. p->fillRect( x, y, w, h, TQBrush( color1, SolidPattern ) );
  795. handled = true;
  796. }
  797. break;
  798. }
  799. case PE_IndicatorMask:
  800. {
  801. if ( isPixmap( ( flags & Style_On ) ? IndicatorOn : IndicatorOff ) )
  802. {
  803. const TQBitmap * mask = uncached( ( flags & Style_On ) ? IndicatorOn :
  804. IndicatorOff ) ->mask();
  805. if ( mask )
  806. {
  807. p->setPen( Qt::color1 );
  808. p->drawPixmap( x, y, *mask );
  809. }
  810. else
  811. p->fillRect( x, y, w, h, TQBrush( color1, SolidPattern ) );
  812. handled = true;
  813. }
  814. break;
  815. }
  816. case PE_Indicator:
  817. {
  818. if ( isPixmap( ( flags & Style_On || flags & Style_Down ) ?
  819. IndicatorOn : IndicatorOff ) )
  820. {
  821. p->drawPixmap( x, y, *uncached( ( flags & Style_On || flags & Style_Down ) ?
  822. IndicatorOn : IndicatorOff ) );
  823. handled = true;
  824. }
  825. break;
  826. }
  827. case PE_Splitter:
  828. {
  829. drawBaseButton( p, x, y, w, h, *colorGroup( g, Splitter ), false, false,
  830. Splitter );
  831. handled = true;
  832. break;
  833. }
  834. case PE_FocusRect:
  835. {
  836. if ( is3DFocus() )
  837. {
  838. p->setPen( g.dark() );
  839. int i = focusOffset();
  840. p->drawLine( r.x() + i, r.y() + 1 + i, r.x() + i, r.bottom() - 1 - i );
  841. p->drawLine( r.x() + 1 + i, r.y() + i, r.right() - 1 - i, r.y() + i );
  842. p->setPen( g.light() );
  843. p->drawLine( r.right() - i, r.y() + 1 + i, r.right() - i, r.bottom() - 1 - i );
  844. p->drawLine( r.x() + 1 + i, r.bottom() - i, r.right() - 1 - i, r.bottom() - i );
  845. handled = true;
  846. }
  847. else
  848. {
  849. handled = true;
  850. p->drawWinFocusRect(r);
  851. }
  852. break;
  853. }
  854. case PE_PanelMenuBar:
  855. {
  856. TQPixmap* cache = makeMenuBarCache(w, h);
  857. p->drawPixmap( x, y, *cache);
  858. handled = true;
  859. break;
  860. }
  861. case PE_ScrollBarAddPage:
  862. case PE_ScrollBarSubPage:
  863. {
  864. WidgetType widget = ( flags & Style_Horizontal ) ? HScrollGroove : VScrollGroove;
  865. if ( !isPixmap( widget ) )
  866. {
  867. p->fillRect( r, colorGroup( g, widget ) ->brush( TQColorGroup::Background ) );
  868. // Do the borders and frame
  869. drawShade( p, r.x(), r.y(), r.width(),
  870. r.height(), *colorGroup( g, widget ), true, false,
  871. highlightWidth( widget ), borderWidth( widget ), shade() );
  872. }
  873. else
  874. {
  875. // If the groove is pixmapped we make a full-sized image (it gets
  876. // cached) then bitBlt it to the appropriate rect.
  877. p->drawTiledPixmap( r.x(), r.y(), r.width(), r.height(),
  878. *scalePixmap( r.width(), r.height(),
  879. widget ) );
  880. drawShade( p, r.x(), r.y(), r.width(),
  881. r.height(), *colorGroup( g, widget ), true, false,
  882. highlightWidth( widget ), borderWidth( widget ), shade() );
  883. }
  884. handled = true;
  885. break;
  886. }
  887. case PE_ScrollBarAddLine:
  888. {
  889. bool horizontal = ( flags & Style_Horizontal );
  890. drawBaseButton( p, r.x(), r.y(), r.width(), r.height(),
  891. *colorGroup( g, down ? ScrollButtonDown : ScrollButton ),
  892. down, false, down ? ScrollButtonDown : ScrollButton );
  893. drawPrimitive( ( horizontal ) ? PE_ArrowRight : PE_ArrowDown, p, ceData, elementFlags ,
  894. TQRect( r.x() + 3, r.y() + 3, r.width() - 6, r.height() - 6 ),
  895. *colorGroup( g, down ? ScrollButtonDown : ScrollButton ),
  896. flags );
  897. handled = true;
  898. break;
  899. }
  900. case PE_ScrollBarSubLine:
  901. {
  902. bool horizontal = ( flags & Style_Horizontal );
  903. drawBaseButton( p, r.x(), r.y(), r.width(), r.height(),
  904. *colorGroup( g, down ? ScrollButtonDown : ScrollButton ),
  905. down, false, down ? ScrollButtonDown : ScrollButton );
  906. drawPrimitive( ( horizontal ) ? PE_ArrowLeft : PE_ArrowUp, p, ceData, elementFlags ,
  907. TQRect( r.x() + 3, r.y() + 3, r.width() - 6, r.height() - 6 ),
  908. *colorGroup( g, down ? ScrollButtonDown : ScrollButton ),
  909. flags );
  910. handled = true;
  911. break;
  912. }
  913. case PE_ScrollBarSlider:
  914. {
  915. bool active = ( flags & Style_Active ) || ( flags & Style_Down ); //activeControl == TQStyle::AddLine;
  916. bool horizontal = ( flags & Style_Horizontal );
  917. int offsetH = horizontal ? 0: decoWidth(VScrollGroove) ;
  918. int offsetV = horizontal ? decoWidth(HScrollGroove):0;
  919. WidgetType widget = horizontal ?
  920. active ? HScrollBarSliderDown : HScrollBarSlider :
  921. active ? VScrollBarSliderDown : VScrollBarSlider;
  922. drawBaseButton( p, r.x()+offsetH, r.y()+offsetV, r.width()-2*offsetH,
  923. r.height()-2*offsetV, *colorGroup( g, widget ), active, false,
  924. widget );
  925. int spaceW = horizontal ? r.width() - decoWidth( widget ) - 4 :
  926. r.width();
  927. int spaceH = horizontal ? r.height() :
  928. r.height() - decoWidth( widget ) - 4;
  929. widget = active ? horizontal ? HScrollDecoDown : VScrollDecoDown :
  930. horizontal ? HScrollDeco : VScrollDeco;
  931. if ( isPixmap( widget ) )
  932. {
  933. if ( spaceW >= uncached( widget ) ->width() &&
  934. spaceH >= uncached( widget ) ->height() )
  935. {
  936. bitBlt( p->device(),
  937. r.x() + ( r.width() - uncached( widget ) ->width() ) / 2,
  938. r.y() + ( r.height() - uncached( widget ) ->height() ) / 2,
  939. uncached( widget ) );
  940. }
  941. }
  942. handled = true;
  943. break;
  944. }
  945. case PE_MenuItemIndicatorFrame:
  946. {
  947. // Draw nothing
  948. break;
  949. }
  950. case PE_MenuItemIndicatorIconFrame:
  951. {
  952. int x, y, w, h;
  953. r.rect( &x, &y, &w, &h );
  954. int checkcol = styleHint(SH_MenuIndicatorColumnWidth, ceData, elementFlags, opt, NULL, NULL);
  955. bool reverse = TQApplication::reverseLayout();
  956. int cx = reverse ? x + w - checkcol : x;
  957. TQRect cr = visualRect( TQRect( x, y, checkcol, h ), r );
  958. const TQColorGroup& cg_ours = *colorGroup( g_base, active ? MenuItemDown : MenuItem );
  959. drawBaseButton( p, cr.x(), cr.y(), cr.width(), cr.height(), *colorGroup( cg_ours, BevelDown ), true, false, BevelDown );
  960. break;
  961. }
  962. case PE_MenuItemIndicatorCheck:
  963. {
  964. int x, y, w, h;
  965. r.rect( &x, &y, &w, &h );
  966. int checkcol = styleHint(SH_MenuIndicatorColumnWidth, ceData, elementFlags, opt, NULL, NULL);
  967. bool reverse = TQApplication::reverseLayout();
  968. int cx = reverse ? x + w - checkcol : x;
  969. TQRect cr = visualRect( TQRect( x, y, checkcol, h ), r );
  970. const TQColorGroup& cg_ours = *colorGroup( g_base, active ? MenuItemDown : MenuItem );
  971. SFlags cflags = Style_Default;
  972. cflags |= active ? Style_Enabled : Style_On;
  973. drawPrimitive( PE_CheckMark, p, ceData, elementFlags, TQRect( x + itemFrame, y + itemFrame, checkcol - itemFrame * 2, h - itemFrame * 2 ), cg_ours, cflags );
  974. break;
  975. }
  976. default:
  977. handled = false;
  978. }
  979. if ( !handled )
  980. KThemeBase::drawPrimitive ( pe, p, ceData, elementFlags, r, g,
  981. flags, opt );
  982. }
  983. TQPixmap* KThemeStyle::makeMenuBarCache(int w, int h) const
  984. {
  985. if (menuCache)
  986. {
  987. if (menuCache->width() != w || menuCache->height() != h )
  988. {
  989. delete menuCache;
  990. }
  991. else
  992. return menuCache;
  993. }
  994. const TQColorGroup *g = colorGroup( TQApplication::palette().active(), MenuBar);
  995. menuCache = new TQPixmap ( w, h );
  996. TQPainter p(menuCache);
  997. drawBaseButton( &p, 0, 0, w, h, *g, false, false, MenuBar );
  998. p.end();
  999. return menuCache;
  1000. }
  1001. void KThemeStyle::drawControl( ControlElement element,
  1002. TQPainter *p,
  1003. const TQStyleControlElementData &ceData,
  1004. ControlElementFlags elementFlags,
  1005. const TQRect &r,
  1006. const TQColorGroup &cg,
  1007. SFlags how ,
  1008. const TQStyleOption& opt,
  1009. const TQWidget *widget ) const
  1010. {
  1011. bool handled = false;
  1012. int x, y, w, h;
  1013. r.rect( &x, &y, &w, &h );
  1014. switch ( element )
  1015. {
  1016. case CE_PushButton:
  1017. {
  1018. const TQPushButton * btn = ( const TQPushButton* ) widget;
  1019. bool sunken = btn->isOn() || btn->isDown();
  1020. int diw = pixelMetric( PM_ButtonDefaultIndicator, ceData, elementFlags, btn );
  1021. drawBaseButton( p, diw, diw, w - 2 * diw, h - 2 * diw,
  1022. *colorGroup( btn->colorGroup(), sunken ? PushButtonDown :
  1023. PushButton ), sunken, roundButton(),
  1024. sunken ? PushButtonDown : PushButton );
  1025. // TODO if diw, draw fancy default button indicator
  1026. handled = true;
  1027. break;
  1028. }
  1029. case CE_PushButtonLabel:
  1030. {
  1031. const TQPushButton* button = ( const TQPushButton* ) widget;
  1032. bool active = button->isOn() || button->isDown();
  1033. int x, y, w, h;
  1034. r.rect( &x, &y, &w, &h );
  1035. // Shift button contents if pushed.
  1036. if ( active )
  1037. {
  1038. x += pixelMetric( PM_ButtonShiftHorizontal, ceData, elementFlags, widget );
  1039. y += pixelMetric( PM_ButtonShiftVertical, ceData, elementFlags, widget );
  1040. how |= Style_Sunken;
  1041. }
  1042. // Does the button have a popup menu?
  1043. if ( button->isMenuButton() )
  1044. {
  1045. int dx = pixelMetric( PM_MenuButtonIndicator, ceData, elementFlags, widget );
  1046. drawPrimitive( PE_ArrowDown, p, ceData, elementFlags, TQRect( x + w - dx - 2, y + 2, dx, h - 4 ),
  1047. cg, how, opt );
  1048. w -= dx;
  1049. }
  1050. // Draw the icon if there is one
  1051. if ( button->iconSet() && !button->iconSet() ->isNull() )
  1052. {
  1053. TQIconSet::Mode mode = TQIconSet::Disabled;
  1054. TQIconSet::State state = TQIconSet::Off;
  1055. if ( button->isEnabled() )
  1056. mode = button->hasFocus() ? TQIconSet::Active : TQIconSet::Normal;
  1057. if ( button->isToggleButton() && button->isOn() )
  1058. state = TQIconSet::On;
  1059. TQPixmap pixmap = button->iconSet() ->pixmap( TQIconSet::Small, mode, state );
  1060. // Center the iconset if there's no text or pixmap
  1061. if (button->text().isEmpty() && !button->pixmap())
  1062. p->drawPixmap( x + (w - pixmap.width()) / 2,
  1063. y + (h - pixmap.height()) / 2, pixmap );
  1064. else
  1065. p->drawPixmap( x + 4, y + (h - pixmap.height()) / 2, pixmap );
  1066. int pw = pixmap.width();
  1067. x += pw + 4;
  1068. w -= pw + 4;
  1069. }
  1070. // Make the label indicate if the button is a default button or not
  1071. if ( active || button->isDefault() && button->isEnabled() )
  1072. {
  1073. // Draw "fake" bold text - this enables the font metrics to remain
  1074. // the same as computed in TQPushButton::sizeHint(), but gives
  1075. // a reasonable bold effect.
  1076. int i;
  1077. // Text shadow
  1078. for ( i = 0; i < 2; i++ )
  1079. drawItem( p, TQRect( x + i + 1, y + 1, w, h ), AlignCenter | ShowPrefix,
  1080. button->colorGroup(), button->isEnabled(), NULL,
  1081. button->text(), -1,
  1082. active ? &button->colorGroup().dark() : &button->colorGroup().mid() );
  1083. // Normal Text
  1084. for ( i = 0; i < 2; i++ )
  1085. drawItem( p, TQRect( x + i, y, w, h ), AlignCenter | ShowPrefix,
  1086. button->colorGroup(), true, i == 0 ? button->pixmap() : NULL,
  1087. button->text(), -1,
  1088. active ? &button->colorGroup().light() : &button->colorGroup().buttonText() );
  1089. }
  1090. else
  1091. {
  1092. if ( button->isEnabled() )
  1093. {
  1094. drawItem( p, TQRect( x, y, w, h ), AlignCenter | ShowPrefix, button->colorGroup(),
  1095. true, button->pixmap(), button->text(), -1,
  1096. active ? &button->colorGroup().light() : &button->colorGroup().buttonText() );
  1097. }
  1098. else
  1099. {
  1100. //TODO: Handle reversed
  1101. drawItem( p, TQRect( x + 1, y + 1, w, h ), AlignCenter | ShowPrefix, button->colorGroup(),
  1102. true, button->pixmap(), button->text(), -1,
  1103. &button->colorGroup().light() );
  1104. drawItem( p, TQRect( x, y, w, h ), AlignCenter | ShowPrefix, button->colorGroup(),
  1105. true, button->pixmap(), button->text(), -1,
  1106. &button->colorGroup().buttonText() );
  1107. }
  1108. }
  1109. // Draw a focus rect if the button has focus
  1110. if ( how & Style_HasFocus )
  1111. drawPrimitive( PE_FocusRect, p, ceData, elementFlags,
  1112. TQStyle::visualRect( subRect( SR_PushButtonFocusRect, ceData, elementFlags, widget ), ceData, elementFlags ),
  1113. cg, how );
  1114. handled = true;
  1115. break;
  1116. }
  1117. case CE_MenuBarEmptyArea:
  1118. {
  1119. //Expand to cover entire region
  1120. drawPrimitive(PE_PanelMenuBar, p, ceData, elementFlags,
  1121. TQRect(0,0,r.width()+r.x()*2, r.height()+r.y()*2),
  1122. cg, Style_Default);
  1123. handled = true;
  1124. break;
  1125. }
  1126. case CE_TabBarTab:
  1127. {
  1128. TQTabBar::Shape tbs = ceData.tabBarData.shape;
  1129. bool selected = how & Style_Selected;
  1130. WidgetType widget = selected ? ActiveTab : InactiveTab;
  1131. const TQColorGroup *cg = colorGroup( ceData.colorGroup, widget );
  1132. int i;
  1133. int x2 = x + w - 1, y2 = y + h - 1;
  1134. int bWidth = borderWidth( widget );
  1135. int hWidth = highlightWidth( widget );
  1136. handled = true;
  1137. if ( tbs == TQTabBar::RoundedAbove || tbs == TQTabBar::TriangularAbove )
  1138. {
  1139. if ( !selected )
  1140. {
  1141. p->fillRect( x, y, x2 - x + 1, 2,
  1142. ceData.palette.active().brush( TQColorGroup::Background ) );
  1143. y += 2;
  1144. }
  1145. p->setPen( cg->text() );
  1146. i = 0;
  1147. if ( i < bWidth )
  1148. {
  1149. p->drawLine( x, y + 1, x, y2 );
  1150. p->drawLine( x2, y + 1, x2, y2 );
  1151. p->drawLine( x + 1, y, x2 - 1, y );
  1152. if ( selected ? activeTabLine() : inactiveTabLine() )
  1153. {
  1154. p->drawLine( x, y2, x2, y2 );
  1155. --y2;
  1156. }
  1157. ++i, ++x, ++y, --x2;
  1158. }
  1159. for ( ; i < bWidth; ++i, ++x, ++y, --x2 )
  1160. {
  1161. p->drawLine( x, y, x, y2 );
  1162. p->drawLine( x2, y, x2, y2 );
  1163. p->drawLine( x, y, x2, y );
  1164. if ( selected ? activeTabLine() : inactiveTabLine() )
  1165. {
  1166. p->drawLine( x, y2, x2, y2 );
  1167. --y2;
  1168. }
  1169. }
  1170. i = 0;
  1171. if ( i < hWidth && bWidth == 0 )
  1172. {
  1173. p->setPen( cg->light() );
  1174. p->drawLine( x, y + 1, x, y2 );
  1175. p->drawLine( x + 1, y, x2 - 1, y );
  1176. p->setPen( cg->dark() );
  1177. p->drawLine( x2, y + 1, x2, y2 );
  1178. if ( selected ? activeTabLine() : inactiveTabLine() )
  1179. {
  1180. p->drawLine( x, y2, x2, y2 );
  1181. --y2;
  1182. }
  1183. ++i, ++x, ++y, --x2;
  1184. }
  1185. for ( ; i < hWidth; ++i, ++x, ++y, --x2 )
  1186. {
  1187. p->setPen( cg->light() );
  1188. p->drawLine( x, y, x, y2 );
  1189. p->drawLine( x, y, x2, y );
  1190. p->setPen( cg->dark() );
  1191. p->drawLine( x2, y + 1, x2, y2 );
  1192. if ( selected ? activeTabLine() : inactiveTabLine() )
  1193. {
  1194. p->drawLine( x, y2, x2, y2 );
  1195. --y2;
  1196. }
  1197. }
  1198. if ( isPixmap( widget ) )
  1199. p->drawTiledPixmap( x, y, x2 - x + 1, y2 - y + 1,
  1200. *scalePixmap( x2 - x + 1, y2 - y + 1, widget ) );
  1201. else
  1202. p->fillRect( x, y, x2 - x + 1, y2 - y + 1, cg->background() );
  1203. }
  1204. else if ( ceData.tabBarData.shape == TQTabBar::RoundedBelow ||
  1205. ceData.tabBarData.shape == TQTabBar::TriangularBelow )
  1206. {
  1207. if ( widget == ActiveTab )
  1208. widget = RotActiveTab;
  1209. else
  1210. widget = RotInactiveTab;
  1211. if ( !selected )
  1212. {
  1213. p->fillRect( x, y2 - 2, x2 - x + 1, 2,
  1214. ceData.palette.active().brush( TQColorGroup::Background ) );
  1215. y2 -= 2;
  1216. }
  1217. p->setPen( cg->text() );
  1218. i = 0;
  1219. if ( i < bWidth )
  1220. {
  1221. p->drawLine( x, y, x, y2 - 1 );
  1222. p->drawLine( x2, y, x2, y2 - 1 );
  1223. p->drawLine( x + 1, y2, x2 - 1, y2 );
  1224. if ( selected ? activeTabLine() : inactiveTabLine() )
  1225. {
  1226. p->drawLine( x, y, x2, y );
  1227. ++y;
  1228. }
  1229. }
  1230. for ( ; i < bWidth; ++i, ++x, --x2, --y2 )
  1231. {
  1232. p->drawLine( x, y, x, y2 );
  1233. p->drawLine( x2, y, x2, y2 );
  1234. p->drawLine( x, y2, x2, y2 );
  1235. if ( selected ? activeTabLine() : inactiveTabLine() )
  1236. {
  1237. p->drawLine( x, y, x2, y );
  1238. ++y;
  1239. }
  1240. }
  1241. i = 0;
  1242. if ( i < hWidth && bWidth == 0 )
  1243. {
  1244. p->setPen( cg->dark() );
  1245. p->drawLine( x + 1, y2, x2 - 1, y2 );
  1246. p->drawLine( x2, y, x2, y2 - 1 );
  1247. p->setPen( cg->light() );
  1248. p->drawLine( x, y, x, y2 - 1 );
  1249. if ( selected ? activeTabLine() : inactiveTabLine() )
  1250. {
  1251. p->drawLine( x, y, x2, y );
  1252. ++y;
  1253. }
  1254. ++i, ++x, --x2, --y2;
  1255. }
  1256. for ( ; i < hWidth; ++i, ++x, --x2, --y2 )
  1257. {
  1258. p->setPen( cg->dark() );
  1259. p->drawLine( x, y2, x2, y2 );
  1260. p->drawLine( x2, y, x2, y2 );
  1261. p->setPen( cg->light() );
  1262. p->drawLine( x, y, x, y2 );
  1263. if ( selected ? activeTabLine() : inactiveTabLine() )
  1264. {
  1265. p->drawLine( x, y, x2, y );
  1266. ++y;
  1267. }
  1268. }
  1269. if ( isPixmap( widget ) )
  1270. p->drawTiledPixmap( x, y, x2 - x + 1, y2 - y + 1,
  1271. *scalePixmap( x2 - x + 1, y2 - y + 1, widget ) );
  1272. else
  1273. p->fillRect( x, y, x2 - x + 1, y2 - y + 1, cg->background() );
  1274. }
  1275. break;
  1276. }
  1277. case CE_MenuBarItem:
  1278. {
  1279. r.rect( &x, &y, &w, &h );
  1280. TQMenuItem *mi = opt.menuItem();
  1281. TQMenuBar *mb = ( TQMenuBar* ) widget;
  1282. TQRect pr = mb->rect();
  1283. bool active = how & Style_Active;
  1284. //bool focused = how & Style_HasFocus;
  1285. const TQColorGroup *g = colorGroup( cg, active ? MenuBarItem : MenuBar );
  1286. TQColor btext = g->buttonText();
  1287. TQPixmap* cache = makeMenuBarCache(pr.width(), pr.height());
  1288. TQPixmap buf( w, pr.height() );
  1289. bitBlt(&buf, 0, 0, cache, x, y, w, pr.height());
  1290. TQPainter p2( &buf );
  1291. if ( active )
  1292. {
  1293. drawBaseButton( &p2, 0, 0, w, h, *g, false, false, MenuBarItem );
  1294. }
  1295. p2.end();
  1296. p->drawPixmap( x, y, buf, 0, 0, w, h );
  1297. drawItem( p, TQRect(x,y,w,h), AlignCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine,
  1298. *g, mi->isEnabled(), mi->pixmap(), mi->text(),
  1299. -1, &btext );
  1300. handled = true;
  1301. break;
  1302. }
  1303. case CE_PopupMenuItem:
  1304. {
  1305. bool separator = false;
  1306. int x, y, w, h;
  1307. r.rect( &x, &y, &w, &h );
  1308. TQMenuItem *mi = opt.menuItem();
  1309. if ( mi )
  1310. {
  1311. separator = mi->isSeparator();
  1312. }
  1313. int tab = opt.tabWidth();
  1314. int checkcol = opt.maxIconWidth();
  1315. bool enabled = (mi? mi->isEnabled():true);
  1316. bool checkable = (elementFlags & CEF_IsCheckable);
  1317. bool active = how & Style_Active;
  1318. bool etchtext = styleHint( SH_EtchDisabledText, ceData, elementFlags, TQStyleOption::Default, 0, 0 );
  1319. bool reverse = TQApplication::reverseLayout();
  1320. const TQColorGroup& cg_ours = *colorGroup( cg, active ? MenuItemDown : MenuItem );
  1321. //TQColor btext = cg_ours.buttonText();
  1322. if ( checkable )
  1323. checkcol = QMAX( checkcol, 20 );
  1324. // Are we a menu item separator?
  1325. if ( separator )
  1326. {
  1327. p->setPen( cg_ours.dark() );
  1328. p->drawLine( x, y, x + w, y );
  1329. p->setPen( cg_ours.light() );
  1330. p->drawLine( x, y + 1, x + w, y + 1 );
  1331. break;
  1332. }
  1333. // Draw the menu item background
  1334. if ( active )
  1335. drawBaseButton( p, x, y, w, h, cg_ours, true, false, MenuItemDown );
  1336. else
  1337. {
  1338. drawShade( p, x, y, w, h, *colorGroup( cg_ours, MenuItem ), false, false,
  1339. highlightWidth( MenuItem ), borderWidth( MenuItem ),
  1340. shade() );
  1341. int dw = decoWidth( MenuItem );
  1342. if ( !isPixmap( MenuItem ) )
  1343. {
  1344. p->fillRect(
  1345. x + dw, y + dw, w - dw * 2, h - dw * 2,
  1346. cg_ours.brush( TQColorGroup::Background ) );
  1347. //cg.brush( TQColorGroup::Background ));
  1348. //colorGroup( cg_ours, MenuItem ) ->brush( TQColorGroup::Background ) );
  1349. }
  1350. else
  1351. {
  1352. // process inactive item pixmaps as one large item
  1353. p->drawTiledPixmap( x + dw, y + dw, w - dw * 2, h - dw * 2, *scalePixmap
  1354. ( w, p->window().height(), MenuItem ),
  1355. x, y );
  1356. }
  1357. }
  1358. if (!mi)
  1359. break;
  1360. // Do we have an icon?
  1361. if ( mi->iconSet() )
  1362. {
  1363. TQIconSet::Mode mode;
  1364. TQRect cr = visualRect( TQRect( x, y, checkcol, h ), r );
  1365. // Select the correct icon from the iconset
  1366. if ( active )
  1367. mode = enabled ? TQIconSet::Active : TQIconSet::Disabled;
  1368. else
  1369. mode = enabled ? TQIconSet::Normal : TQIconSet::Disabled;
  1370. // Do we have an icon and are checked at the same time?
  1371. // Then draw a "pressed" background behind the icon
  1372. if ( checkable && mi->isChecked() ) //!active && -- ??
  1373. drawPrimitive(PE_MenuItemIndicatorIconFrame, p, ceData, elementFlags, r, cg, how, opt);
  1374. // Draw the icon
  1375. TQPixmap pixmap = mi->iconSet() ->pixmap( TQIconSet::Small, mode );
  1376. int pixw = pixmap.width();
  1377. int pixh = pixmap.height();
  1378. TQRect pmr( 0, 0, pixw, pixh );
  1379. pmr.moveCenter( cr.center() );
  1380. p->setPen( cg_ours.highlightedText() );
  1381. p->drawPixmap( pmr.topLeft(), pixmap );
  1382. }
  1383. // Are we checked? (This time without an icon)
  1384. else if ( checkable && mi->isChecked() )
  1385. {
  1386. // We only have to draw the background if the menu item is inactive -
  1387. // if it's active the "pressed" background is already drawn
  1388. //if ( ! active )
  1389. // qDrawShadePanel( p, cx, y, checkcol, h, cg_ours, true, 1,
  1390. // &cg_ours.brush(TQColorGroup::Midlight) );
  1391. // Draw the checkmark
  1392. drawPrimitive(PE_MenuItemIndicatorCheck, p, ceData, elementFlags, r, cg, how, opt);
  1393. }
  1394. // Time to draw the menu item label...
  1395. int xm = itemFrame + checkcol + itemHMargin; // X position margin
  1396. int xp = reverse ? // X position
  1397. x + tab + rightBorder + itemHMargin + itemFrame - 1 :
  1398. x + xm;
  1399. int offset = reverse ? -1 : 1; // Shadow offset for etched text
  1400. // Label width (minus the width of the accelerator portion)
  1401. int tw = w - xm - tab - arrowHMargin - itemHMargin * 3 - itemFrame + 1;
  1402. // Set the color for enabled and disabled text
  1403. // (used for both active and inactive menu items)
  1404. p->setPen( enabled ? cg_ours.buttonText() : cg_ours.mid() );
  1405. // This color will be used instead of the above if the menu item
  1406. // is active and disabled at the same time. (etched text)
  1407. TQColor discol = cg_ours.mid();
  1408. // Does the menu item draw it's own label?
  1409. if ( mi->custom() )
  1410. {
  1411. int m = itemVMargin;
  1412. // Save the painter state in case the custom
  1413. // paint method changes it in some way
  1414. p->save();
  1415. // Draw etched text if we're inactive and the menu item is disabled
  1416. if ( etchtext && !enabled && !active )
  1417. {
  1418. p->setPen( cg_ours.light() );
  1419. mi->custom() ->paint( p, cg_ours, active, enabled, xp + offset, y + m + 1, tw, h - 2 * m );
  1420. p->setPen( discol );
  1421. }
  1422. mi->custom() ->paint( p, cg_ours, active, enabled, xp, y + m, tw, h - 2 * m );
  1423. p->restore();
  1424. }
  1425. else
  1426. {
  1427. // The menu item doesn't draw it's own label
  1428. TQString s = mi->text();
  1429. // Does the menu item have a text label?
  1430. if ( !s.isNull() )
  1431. {
  1432. int t = s.find( '\t' );
  1433. int m = itemVMargin;
  1434. int text_flags = AlignVCenter | ShowPrefix | DontClip | SingleLine;
  1435. text_flags |= reverse ? AlignRight : AlignLeft;
  1436. // Does the menu item have a tabstop? (for the accelerator text)
  1437. if ( t >= 0 )
  1438. {
  1439. int tabx = reverse ? x + rightBorder + itemHMargin + itemFrame :
  1440. x + w - tab - rightBorder - itemHMargin - itemFrame;
  1441. // Draw the right part of the label (accelerator text)
  1442. if ( etchtext && !enabled && !active )
  1443. {
  1444. // Draw etched text if we're inactive and the menu item is disabled
  1445. p->setPen( cg_ours.light() );
  1446. p->drawText( tabx + offset, y + m + 1, tab, h - 2 * m, text_flags, s.mid( t + 1 ) );
  1447. p->setPen( discol );
  1448. }
  1449. p->drawText( tabx, y + m, tab, h - 2 * m, text_flags, s.mid( t + 1 ) );
  1450. s = s.left( t );
  1451. }
  1452. // Draw the left part of the label (or the whole label
  1453. // if there's no accelerator)
  1454. if ( etchtext && !enabled && !active )
  1455. {
  1456. // Etched text again for inactive disabled menu items...
  1457. p->setPen( cg_ours.light() );
  1458. p->drawText( xp + offset, y + m + 1, tw, h - 2 * m, text_flags, s, t );
  1459. p->setPen( discol );
  1460. }
  1461. p->drawText( xp, y + m, tw, h - 2 * m, text_flags, s, t );
  1462. }
  1463. // The menu item doesn't have a text label
  1464. // Check if it has a pixmap instead
  1465. else if ( mi->pixmap() )
  1466. {
  1467. TQPixmap * pixmap = mi->pixmap();
  1468. // Draw the pixmap
  1469. if ( pixmap->depth() == 1 )
  1470. p->setBackgroundMode( Qt::OpaqueMode );
  1471. int diffw = ( ( w - pixmap->width() ) / 2 )
  1472. + ( ( w - pixmap->width() ) % 2 );
  1473. p->drawPixmap( x + diffw, y + itemFrame, *pixmap );
  1474. if ( pixmap->depth() == 1 )
  1475. p->setBackgroundMode( Qt::TransparentMode );
  1476. }
  1477. }
  1478. // Does the menu item have a submenu?
  1479. if ( mi->popup() )
  1480. {
  1481. PrimitiveElement arrow = reverse ? PE_ArrowLeft : PE_ArrowRight;
  1482. int dim = 10 - itemFrame; //We're not very useful to inherit off, so just hardcode..
  1483. TQRect vr = visualRect( TQRect( x + w - arrowHMargin - itemFrame - dim,
  1484. y + h / 2 - dim / 2, dim, dim ), r );
  1485. // Draw an arrow at the far end of the menu item
  1486. if ( active )
  1487. {
  1488. if ( enabled )
  1489. discol = cg_ours.buttonText();
  1490. TQColorGroup g2( discol, cg_ours.highlight(), white, white,
  1491. enabled ? white : discol, discol, white );
  1492. drawPrimitive( arrow, p, ceData, elementFlags, vr, g2, Style_Enabled | Style_Down );
  1493. }
  1494. else
  1495. drawPrimitive( arrow, p, ceData, elementFlags, vr, cg_ours,
  1496. enabled ? Style_Enabled : Style_Default );
  1497. }
  1498. handled = true;
  1499. break;
  1500. }
  1501. case CE_ProgressBarGroove:
  1502. {
  1503. TQBrush bg;
  1504. const TQColorGroup * cg2 = colorGroup( cg, ProgressBg );
  1505. qDrawWinPanel( p, r, *cg2, true );
  1506. bg.setColor( cg2->color( TQColorGroup::Background ) );
  1507. if ( isPixmap( ProgressBg ) )
  1508. bg.setPixmap( *uncached( ProgressBg ) );
  1509. p->fillRect( x + 2, y + 2, w - 4, h - 4, bg );
  1510. handled = true;
  1511. break;
  1512. }
  1513. case CE_ProgressBarContents:
  1514. {
  1515. const TQProgressBar* pb = (const TQProgressBar*)widget;
  1516. TQRect cr = subRect(SR_ProgressBarContents, ceData, elementFlags, widget);
  1517. double progress = pb->progress();
  1518. bool reverse = TQApplication::reverseLayout();
  1519. int steps = pb->totalSteps();
  1520. int pstep = 0;
  1521. if (!cr.isValid())
  1522. return;
  1523. // Draw progress bar
  1524. if (progress > 0 || steps == 0)
  1525. {
  1526. double pg = (steps == 0) ? 0.1 : progress / steps;
  1527. int width = QMIN(cr.width(), (int)(pg * cr.width()));
  1528. if (steps == 0)
  1529. { //Busy indicator
  1530. if (width < 1) width = 1; //A busy indicator with width 0 is kind of useless
  1531. int remWidth = cr.width() - width; //Never disappear completely
  1532. if (remWidth <= 0) remWidth = 1; //Do something non-crashy when too small...
  1533. pstep = int(progress) % ( 2 * remWidth );
  1534. if ( pstep > remWidth )
  1535. {
  1536. //Bounce about.. We're remWidth + some delta, we want to be remWidth - delta...
  1537. // - ( (remWidth + some delta) - 2* remWidth ) = - (some deleta - remWidth) = remWidth - some delta..
  1538. pstep = - (pstep - 2 * remWidth );
  1539. }
  1540. }
  1541. if ( !reverse )
  1542. drawBaseButton( p, x + pstep, y, width, h, *colorGroup( cg, ProgressBar ), false, false, ProgressBar );
  1543. else
  1544. {
  1545. //TODO:Optimize
  1546. TQPixmap buf( width, h );
  1547. TQPainter p2( &buf );
  1548. drawBaseButton( &p2, 0, 0, width, h, *colorGroup( cg, ProgressBar ), false, false, ProgressBar );
  1549. p2.end();
  1550. TQPixmap mirroredPix = TQPixmap( TQImage(buf.convertToImage()).mirror( true, false ) );
  1551. bitBlt( p->device(), x + w - width - pstep, y, &mirroredPix );
  1552. }
  1553. }
  1554. handled = true;
  1555. break;
  1556. }
  1557. default:
  1558. handled = false;
  1559. };
  1560. if ( !handled )
  1561. KThemeBase::drawControl( element,
  1562. p, ceData, elementFlags, r, cg, how, opt, widget );
  1563. }
  1564. void KThemeStyle::drawControlMask( ControlElement element,
  1565. TQPainter *p,
  1566. const TQStyleControlElementData &ceData,
  1567. ControlElementFlags elementFlags,
  1568. const TQRect &r,
  1569. const TQStyleOption& opt,
  1570. const TQWidget *widget ) const
  1571. {
  1572. bool handled = false;
  1573. int x, y, w, h;
  1574. r.rect( &x, &y, &w, &h );
  1575. switch ( element )
  1576. {
  1577. case CE_PushButton:
  1578. {
  1579. //Is this correct?
  1580. drawBaseMask( p, x, y, w, h, roundButton() );
  1581. handled = true;
  1582. break;
  1583. }
  1584. default:
  1585. handled = false;
  1586. };
  1587. if ( !handled )
  1588. KThemeBase::drawControlMask( element,
  1589. p, ceData, elementFlags, r, opt, widget );
  1590. }
  1591. void KThemeStyle::drawTDEStylePrimitive( TDEStylePrimitive kpe,
  1592. TQPainter* p,
  1593. const TQStyleControlElementData &ceData,
  1594. ControlElementFlags elementFlags,
  1595. const TQRect &r,
  1596. const TQColorGroup &cg,
  1597. SFlags flags,
  1598. const TQStyleOption& opt,
  1599. const TQWidget* widget ) const
  1600. {
  1601. bool handled = false;
  1602. int x, y, w, h;
  1603. r.rect( &x, &y, &w, &h );
  1604. switch ( kpe )
  1605. {
  1606. case KPE_SliderGroove:
  1607. {
  1608. if ( !roundSlider() )
  1609. {
  1610. const TQSlider * slider = ( const TQSlider* ) widget;
  1611. bool horizontal = slider->orientation() == Qt::Horizontal;
  1612. if ( horizontal )
  1613. {
  1614. drawBaseButton( p, x, y, w, h, *colorGroup( cg, SliderGroove ), true,
  1615. false, SliderGroove );
  1616. }
  1617. else
  1618. {
  1619. drawBaseButton( p, x, y, w, h, *colorGroup( cg, RotSliderGroove ), true,
  1620. false, RotSliderGroove );
  1621. }
  1622. }
  1623. else
  1624. {
  1625. //This code is from HighColorDefault..
  1626. const TQSlider* slider = ( const TQSlider* ) widget;
  1627. bool horizontal = slider->orientation() == Qt::Horizontal;
  1628. int gcenter = ( horizontal ? r.height() : r.width() ) / 2;
  1629. TQRect gr;
  1630. if ( horizontal )
  1631. gr = TQRect( r.x(), r.y() + gcenter - 3, r.width(), 7 );
  1632. else
  1633. gr = TQRect( r.x() + gcenter - 3, r.y(), 7, r.height() );
  1634. int x, y, w, h;
  1635. gr.rect( &x, &y, &w, &h );
  1636. int x2 = x + w - 1;
  1637. int y2 = y + h - 1;
  1638. // Draw the slider groove.
  1639. p->setPen( cg.dark() );
  1640. p->drawLine( x + 2, y, x2 - 2, y );
  1641. p->drawLine( x, y + 2, x, y2 - 2 );
  1642. p->fillRect( x + 2, y + 2, w - 4, h - 4,
  1643. slider->isEnabled() ? cg.dark() : cg.mid() );
  1644. p->setPen( cg.shadow() );
  1645. p->drawRect( x + 1, y + 1, w - 2, h - 2 );
  1646. p->setPen( cg.light() );
  1647. p->drawPoint( x + 1, y2 - 1 );
  1648. p->drawPoint( x2 - 1, y2 - 1 );
  1649. p->drawLine( x2, y + 2, x2, y2 - 2 );
  1650. p->drawLine( x + 2, y2, x2 - 2, y2 );
  1651. }
  1652. handled = true;
  1653. break;
  1654. }
  1655. case KPE_SliderHandle:
  1656. {
  1657. if ( isPixmap( Slider ) )
  1658. {
  1659. const TQSlider * slider = ( const TQSlider* ) widget;
  1660. bool horizontal = slider->orientation() == Qt::Horizontal;
  1661. if ( horizontal )
  1662. {
  1663. bitBlt( p->device(), x, y + ( h - uncached( Slider ) ->height() ) / 2,
  1664. uncached( Slider ) );
  1665. }
  1666. else
  1667. {
  1668. if ( !vsliderCache )
  1669. {
  1670. TQWMatrix r270;
  1671. r270.rotate( 270 );
  1672. vsliderCache = new TQPixmap( uncached( Slider ) ->xForm( r270 ) );
  1673. if ( uncached( Slider ) ->mask() )
  1674. vsliderCache->setMask( uncached( Slider ) ->mask() ->xForm( r270 ) );
  1675. }
  1676. bitBlt( p->device(), x + ( w - vsliderCache->width() ) / 2, y,
  1677. vsliderCache );
  1678. }
  1679. }
  1680. else
  1681. {
  1682. //This code again from HighColor..
  1683. //...except sans the gradient..
  1684. const TQSlider* slider = ( const TQSlider* ) widget;
  1685. bool horizontal = slider->orientation() == Qt::Horizontal;
  1686. int x, y, w, h;
  1687. r.rect( &x, &y, &w, &h );
  1688. int x2 = x + w - 1;
  1689. int y2 = y + h - 1;
  1690. p->setPen( cg.mid() );
  1691. p->drawLine( x + 1, y, x2 - 1, y );
  1692. p->drawLine( x, y + 1, x, y2 - 1 );
  1693. p->setPen( cg.shadow() );
  1694. p->drawLine( x + 1, y2, x2 - 1, y2 );
  1695. p->drawLine( x2, y + 1, x2, y2 - 1 );
  1696. p->setPen( cg.light() );
  1697. p->drawLine( x + 1, y + 1, x2 - 1, y + 1 );
  1698. p->drawLine( x + 1, y + 1, x + 1, y2 - 1 );
  1699. p->setPen( cg.dark() );
  1700. p->drawLine( x + 2, y2 - 1, x2 - 1, y2 - 1 );
  1701. p->drawLine( x2 - 1, y + 2, x2 - 1, y2 - 1 );
  1702. p->setPen( cg.midlight() );
  1703. p->drawLine( x + 2, y + 2, x2 - 2, y + 2 );
  1704. p->drawLine( x + 2, y + 2, x + 2, y2 - 2 );
  1705. p->setPen( cg.mid() );
  1706. p->drawLine( x + 3, y2 - 2, x2 - 2, y2 - 2 );
  1707. p->drawLine( x2 - 2, y + 3, x2 - 2, y2 - 2 );
  1708. p->fillRect( TQRect( x + 3, y + 3, w - 6, h - 6 ),
  1709. cg.button() );
  1710. // Paint riffles
  1711. if ( horizontal )
  1712. {
  1713. p->setPen( cg.light() );
  1714. p->drawLine( x + 5, y + 4, x + 5, y2 - 4 );
  1715. p->drawLine( x + 8, y + 4, x + 8, y2 - 4 );
  1716. p->drawLine( x + 11, y + 4, x + 11, y2 - 4 );
  1717. p->setPen( slider->isEnabled() ? cg.shadow() : cg.mid() );
  1718. p->drawLine( x + 6, y + 4, x + 6, y2 - 4 );
  1719. p->drawLine( x + 9, y + 4, x + 9, y2 - 4 );
  1720. p->drawLine( x + 12, y + 4, x + 12, y2 - 4 );
  1721. }
  1722. else
  1723. {
  1724. p->setPen( cg.light() );
  1725. p->drawLine( x + 4, y + 5, x2 - 4, y + 5 );
  1726. p->drawLine( x + 4, y + 8, x2 - 4, y + 8 );
  1727. p->drawLine( x + 4, y + 11, x2 - 4, y + 11 );
  1728. p->setPen( slider->isEnabled() ? cg.shadow() : cg.mid() );
  1729. p->drawLine( x + 4, y + 6, x2 - 4, y + 6 );
  1730. p->drawLine( x + 4, y + 9, x2 - 4, y + 9 );
  1731. p->drawLine( x + 4, y + 12, x2 - 4, y + 12 );
  1732. }
  1733. }
  1734. handled = true;
  1735. break;
  1736. }
  1737. //case KPE_DockWindowHandle:
  1738. case KPE_ToolBarHandle:
  1739. case KPE_GeneralHandle:
  1740. {
  1741. if ( w > h )
  1742. drawBaseButton( p, x, y, w, h, *colorGroup( cg, HBarHandle ), false, false,
  1743. HBarHandle );
  1744. else
  1745. drawBaseButton( p, x, y, w, h, *colorGroup( cg, VBarHandle ), false, false,
  1746. VBarHandle );
  1747. handled = true;
  1748. break;
  1749. }
  1750. default:
  1751. handled = false;
  1752. }
  1753. if ( !handled )
  1754. {
  1755. KThemeBase::drawTDEStylePrimitive( kpe, p, ceData, elementFlags,
  1756. r, cg, flags, opt, widget );
  1757. }
  1758. }
  1759. void KThemeStyle::drawComplexControl ( TQ_ComplexControl control, TQPainter * p, const TQStyleControlElementData &ceData, ControlElementFlags elementFlags,
  1760. const TQRect & r, const TQColorGroup & g, SFlags how ,
  1761. SCFlags controls, SCFlags active,
  1762. const TQStyleOption & opt, const TQWidget * widget ) const
  1763. {
  1764. bool handled = false;
  1765. int x, y, w, h;
  1766. r.rect( &x, &y, &w, &h );
  1767. bool down = how & Style_Down;
  1768. bool on = how & Style_On;
  1769. // bool enabled = ( how & Style_Enabled );
  1770. switch ( control )
  1771. {
  1772. case CC_ToolButton:
  1773. {
  1774. const TQToolButton * toolbutton = ( const TQToolButton * ) widget;
  1775. TQRect button, menu;
  1776. button = querySubControlMetrics( control, ceData, elementFlags, SC_ToolButton, opt, widget );
  1777. menu = querySubControlMetrics( control, ceData, elementFlags, SC_ToolButtonMenu, opt, widget );
  1778. if ( controls & SC_ToolButton )
  1779. {
  1780. WidgetType widget = ( down || on ) ? ToolButtonDown : ToolButton;
  1781. drawBaseButton( p, button.x(), button.y(), button.width(), button.height(), *colorGroup( g, widget ), down || on, false,
  1782. widget );
  1783. // int m = decoWidth( widget );
  1784. }
  1785. if ( controls & SC_ToolButtonMenu )
  1786. {
  1787. drawPrimitive( PE_ArrowDown, p, ceData, elementFlags, menu, g, how );
  1788. /* if ( enabled )
  1789. kDrawWindowsArrow(p, ceData, elementFlags, this, PE_ArrowDown, false, menu.x(), menu.y(), menu.width(), menu.height(),
  1790. g, true );
  1791. else
  1792. kDrawWindowsArrow(p, ceData, elementFlags, this, PE_ArrowDown, false, menu.x(), menu.y(), menu.width(), menu.height(),
  1793. g, false );*/
  1794. }
  1795. if ( toolbutton->hasFocus() && !toolbutton->focusProxy() )
  1796. {
  1797. TQRect fr = toolbutton->rect();
  1798. fr.addCoords( 3, 3, -3, -3 );
  1799. drawPrimitive( PE_FocusRect, p, ceData, elementFlags, fr, g );
  1800. }
  1801. handled = true;
  1802. break;
  1803. }
  1804. case CC_ComboBox:
  1805. {
  1806. if ( controls & SC_ComboBoxFrame )
  1807. {
  1808. //TODO: Anyway of detecting when the popup is there -- would look nicer if sunken then too..
  1809. bool sunken = ( active == SC_ComboBoxArrow );
  1810. //No frame, edit box and button for now?
  1811. WidgetType widget = sunken ? ComboBoxDown : ComboBox;
  1812. drawBaseButton( p, x, y, w, h, *colorGroup( g, widget ), sunken,
  1813. roundComboBox(), widget );
  1814. controls ^= SC_ComboBoxFrame;
  1815. }
  1816. if ( controls & SC_ComboBoxArrow )
  1817. {
  1818. bool sunken = ( active == SC_ComboBoxArrow );
  1819. TQRect ar = TQStyle::visualRect(
  1820. querySubControlMetrics( CC_ComboBox, ceData, elementFlags, SC_ComboBoxArrow, TQStyleOption::Default, widget ),
  1821. ceData, elementFlags );
  1822. ar.rect( &x, &y, &w, &h );
  1823. WidgetType widget = sunken ? ComboBoxDown : ComboBox;
  1824. if ( !sunken && isPixmap( ComboDeco ) )
  1825. bitBlt( p->device(),
  1826. x + ( w - uncached( ComboDeco ) ->width() - decoWidth( ComboBox ) / 2 ),
  1827. y + ( h - uncached( ComboDeco ) ->height() ) / 2,
  1828. uncached( ComboDeco ) );
  1829. else if ( sunken && isPixmap( ComboDecoDown ) )
  1830. bitBlt( p->device(),
  1831. x + ( w - uncached( ComboDecoDown ) ->width() - decoWidth( ComboBoxDown ) ) / 2,
  1832. y + ( h - uncached( ComboDecoDown ) ->height() ) / 2,
  1833. uncached( ComboDecoDown ) );
  1834. else
  1835. {
  1836. mtfstyle->drawPrimitive( PE_ArrowDown, p, ceData, elementFlags, TQRect( x, y, w, h ), *colorGroup( g, widget ), sunken ? ( how | Style_Sunken ) : how, opt );
  1837. qDrawShadeRect( p, x, y, w, h, *colorGroup( g, widget ) ); //w-14, y+7+(h-15), 10, 3,
  1838. }
  1839. controls ^= SC_ComboBoxArrow;
  1840. }
  1841. break;
  1842. }
  1843. case CC_ScrollBar:
  1844. {
  1845. const TQScrollBar *sb = ( const TQScrollBar* ) widget;
  1846. bool maxedOut = ( sb->minValue() == sb->maxValue() );
  1847. bool horizontal = ( sb->orientation() == Qt::Horizontal );
  1848. SFlags sflags = ( ( horizontal ? Style_Horizontal : Style_Default ) |
  1849. ( maxedOut ? Style_Default : Style_Enabled ) );
  1850. //Here, we don't do add page, subpage, etc.,
  1851. TQRect addline, subline, subline2, groove, slider;
  1852. subline = querySubControlMetrics( control, ceData, elementFlags, SC_ScrollBarSubLine, opt, widget );
  1853. addline = querySubControlMetrics( control, ceData, elementFlags, SC_ScrollBarAddLine, opt, widget );
  1854. groove = querySubControlMetrics( control, ceData, elementFlags, SC_ScrollBarGroove, opt, widget );
  1855. slider = querySubControlMetrics( control, ceData, elementFlags, SC_ScrollBarSlider, opt, widget );
  1856. subline2 = addline;
  1857. TQPixmap buf( sb->width(), sb->height() );
  1858. TQPainter p2( &buf );
  1859. if ( groove.isValid() )
  1860. {
  1861. p2.fillRect( groove, TQColor( 255, 0, 0 ) );
  1862. drawPrimitive( PE_ScrollBarSubPage, &p2, ceData, elementFlags, groove, g,
  1863. sflags | ( ( active == SC_ScrollBarSubPage ) ?
  1864. Style_Down : Style_Default ) );
  1865. }
  1866. // Draw the up/left button set
  1867. if ( subline.isValid() )
  1868. {
  1869. drawPrimitive( PE_ScrollBarSubLine, &p2, ceData, elementFlags, subline, g,
  1870. sflags | ( active == SC_ScrollBarSubLine ?
  1871. Style_Down : Style_Default ) );
  1872. }
  1873. if ( addline.isValid() )
  1874. drawPrimitive( PE_ScrollBarAddLine, &p2, ceData, elementFlags, addline, g,
  1875. sflags | ( ( active == SC_ScrollBarAddLine ) ?
  1876. Style_Down : Style_Default ) );
  1877. if ( slider.isValid() )
  1878. { //(controls & SC_ScrollBarSlider) &&
  1879. drawPrimitive( PE_ScrollBarSlider, &p2, ceData, elementFlags, slider, g,
  1880. sflags | ( ( active == SC_ScrollBarSlider ) ?
  1881. Style_Down : Style_Default ) );
  1882. // Draw focus rect
  1883. if ( sb->hasFocus() )
  1884. {
  1885. TQRect fr( slider.x() + 2, slider.y() + 2,
  1886. slider.width() - 5, slider.height() - 5 );
  1887. drawPrimitive( PE_FocusRect, &p2, ceData, elementFlags, fr, g, Style_Default );
  1888. }
  1889. p2.end();
  1890. bitBlt( p->device(), x, y, &buf );
  1891. handled = true;
  1892. }
  1893. break;
  1894. }
  1895. default:
  1896. handled = false;
  1897. }
  1898. if ( !handled )
  1899. {
  1900. KThemeBase::drawComplexControl ( control, p, ceData, elementFlags,
  1901. r, g, how ,
  1902. controls, active,
  1903. opt, widget );
  1904. }
  1905. }
  1906. void KThemeStyle::drawBaseMask( TQPainter *p, int x, int y, int w, int h,
  1907. bool round ) const
  1908. {
  1909. // round edge fills
  1910. static const TQCOORD btm_left_fill[] =
  1911. {
  1912. 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1,
  1913. 1, 2, 2, 2, 3, 2, 4, 2, 2, 3, 3, 3, 4, 3, 3, 4, 4, 4
  1914. };
  1915. static const TQCOORD btm_right_fill[] =
  1916. {
  1917. 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 0, 1, 1, 1, 2, 1, 3, 1, 4,
  1918. 1, 0, 2, 1, 2, 2, 2, 3, 2, 0, 3, 1, 3, 2, 3, 0, 4, 1, 4
  1919. };
  1920. static const TQCOORD top_left_fill[] =
  1921. {
  1922. 3, 0, 4, 0, 2, 1, 3, 1, 4, 1, 1, 2, 2, 2, 3, 2, 4, 2, 0, 3,
  1923. 1, 3, 2, 3, 3, 3, 4, 3, 0, 4, 1, 4, 2, 4, 3, 4, 4, 4
  1924. };
  1925. static const TQCOORD top_right_fill[] =
  1926. {
  1927. 0, 0, 1, 0, 0, 1, 1, 1, 2, 1, 0, 2, 1, 2, 2, 2, 3, 2, 0,
  1928. 3, 1, 3, 2, 3, 3, 3, 4, 3, 0, 4, 1, 4, 2, 4, 3, 4, 4, 4
  1929. };
  1930. TQBrush fillBrush( color1, SolidPattern );
  1931. p->setPen( color1 );
  1932. if ( round && w > 19 && h > 19 )
  1933. {
  1934. int x2 = x + w - 1;
  1935. int y2 = y + h - 1;
  1936. TQPointArray a( TQCOORDARRLEN( top_left_fill ), top_left_fill );
  1937. a.translate( 1, 1 );
  1938. p->drawPoints( a );
  1939. a.setPoints( TQCOORDARRLEN( btm_left_fill ), btm_left_fill );
  1940. a.translate( 1, h - 6 );
  1941. p->drawPoints( a );
  1942. a.setPoints( TQCOORDARRLEN( top_right_fill ), top_right_fill );
  1943. a.translate( w - 6, 1 );
  1944. p->drawPoints( a );
  1945. a.setPoints( TQCOORDARRLEN( btm_right_fill ), btm_right_fill );
  1946. a.translate( w - 6, h - 6 );
  1947. p->drawPoints( a );
  1948. p->fillRect( x + 6, y, w - 12, h, fillBrush );
  1949. p->fillRect( x, y + 6, x + 6, h - 12, fillBrush );
  1950. p->fillRect( x2 - 6, y + 6, x2, h - 12, fillBrush );
  1951. p->drawLine( x + 6, y, x2 - 6, y );
  1952. p->drawLine( x + 6, y2, x2 - 6, y2 );
  1953. p->drawLine( x, y + 6, x, y2 - 6 );
  1954. p->drawLine( x2, y + 6, x2, y2 - 6 );
  1955. }
  1956. else
  1957. p->fillRect( x, y, w, h, fillBrush );
  1958. }
  1959. int KThemeStyle::styleHint( StyleHint sh, const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, const TQStyleOption &opt, TQStyleHintReturn *shr, const TQWidget *w ) const
  1960. {
  1961. switch ( sh )
  1962. {
  1963. case SH_EtchDisabledText:
  1964. case SH_Slider_SnapToValue:
  1965. case SH_PrintDialog_RightAlignButtons:
  1966. case SH_FontDialog_SelectAssociatedText:
  1967. case SH_PopupMenu_AllowActiveAndDisabled:
  1968. case SH_MenuBar_AltKeyNavigation:
  1969. case SH_MenuBar_MouseTracking:
  1970. case SH_PopupMenu_MouseTracking:
  1971. case SH_ComboBox_ListMouseTracking:
  1972. return 1;
  1973. case SH_GUIStyle:
  1974. return WindowsStyle;
  1975. case SH_ScrollBar_BackgroundMode:
  1976. return NoBackground;
  1977. case SH_MenuIndicatorColumnWidth:
  1978. {
  1979. int checkcol = opt.maxIconWidth();
  1980. bool checkable = (elementFlags & CEF_IsCheckable);
  1981. if ( checkable )
  1982. checkcol = QMAX( checkcol, 20 );
  1983. return checkcol;
  1984. break;
  1985. }
  1986. default:
  1987. return KThemeBase::styleHint( sh, ceData, elementFlags, opt, shr, w );
  1988. };
  1989. }
  1990. /* This is where we draw the borders and highlights. The new round button
  1991. * code is a pain in the arse. We don't want to be calculating arcs so
  1992. * use a whole lotta QPointArray's ;-) The code is made a lot more complex
  1993. * because you can have variable width border and highlights...
  1994. * I may want to cache this if round buttons are used, but am concerned
  1995. * about excessive cache misses. This is a memory/speed tradeoff that I
  1996. * have to test.
  1997. */
  1998. void KThemeStyle::drawShade( TQPainter *p, int x, int y, int w, int h,
  1999. const TQColorGroup &g, bool sunken, bool rounded,
  2000. int hWidth, int bWidth, ShadeStyle style ) const
  2001. {
  2002. int i, sc, bc, x2, y2;
  2003. TQPen highPen, lowPen;
  2004. if ( style == Motif )
  2005. {
  2006. highPen.setColor( sunken ? g.dark() : g.light() );
  2007. lowPen.setColor( sunken ? g.light() : g.dark() );
  2008. }
  2009. else
  2010. {
  2011. highPen.setColor( sunken ? g.shadow() : g.light() );
  2012. lowPen.setColor( sunken ? g.light() : g.shadow() );
  2013. }
  2014. // Advanced round buttons
  2015. if ( rounded && w > 19 && h > 19 )
  2016. {
  2017. x2 = x + w - 1, y2 = y + h - 1;
  2018. TQPointArray bPntArray, hPntArray, lPntArray;
  2019. TQPointArray bLineArray, hLineArray, lLineArray;
  2020. // borders
  2021. for ( i = 0, bc = 0; i < bWidth; ++i )
  2022. {
  2023. bPntArray.putPoints( bc, 24, x + 4, y + 1, x + 5, y + 1, x + 3, y + 2, x + 2, y + 3,
  2024. x + 1, y + 4, x + 1, y + 5, x + 1, y2 - 5, x + 1, y2 - 4, x + 2, y2 - 3,
  2025. x2 - 5, y + 1, x2 - 4, y + 1, x2 - 3, y + 2, x2 - 5, y2 - 1,
  2026. x2 - 4, y2 - 1, x2 - 3, y2 - 2, x2 - 2, y2 - 3, x2 - 1, y2 - 5,
  2027. x2 - 1, y2 - 4, x + 3, y2 - 2, x + 4, y2 - 1, x + 5, y2 - 1,
  2028. x2 - 2, y + 3, x2 - 1, y + 4, x2 - 1, y + 5 );
  2029. bc += 24;
  2030. // ellispe edges don't match exactly, so fill in blanks
  2031. if ( i < bWidth - 1 || hWidth != 0 )
  2032. {
  2033. bPntArray.putPoints( bc, 20, x + 6, y + 1, x + 4, y + 2, x + 3, y + 3,
  2034. x + 2, y + 4, x + 1, y + 6, x2 - 6, y + 1, x2 - 4, y + 2,
  2035. x2 - 3, y + 3, x + 2, y2 - 4, x + 1, y2 - 6, x2 - 6, y2 - 1,
  2036. x2 - 4, y2 - 2, x2 - 3, y2 - 3, x2 - 2, y2 - 4, x2 - 1, y2 - 6,
  2037. x + 6, y2 - 1, x + 4, y2 - 2, x + 3, y2 - 3, x2 - 1, y + 6,
  2038. x2 - 2, y + 4 );
  2039. bc += 20;
  2040. }
  2041. bLineArray.putPoints( i * 8, 8, x + 6, y, x2 - 6, y, x, y + 6, x, y2 - 6,
  2042. x + 6, y2, x2 - 6, y2, x2, y + 6, x2, y2 - 6 );
  2043. ++x, ++y;
  2044. --x2, --y2;
  2045. }
  2046. // highlights
  2047. for ( i = 0, sc = 0; i < hWidth; ++i )
  2048. {
  2049. hPntArray.putPoints( sc, 12, x + 4, y + 1, x + 5, y + 1, // top left
  2050. x + 3, y + 2, x + 2, y + 3, x + 1, y + 4, x + 1, y + 5,
  2051. x + 1, y2 - 5, x + 1, y2 - 4, x + 2, y2 - 3, // half corners
  2052. x2 - 5, y + 1, x2 - 4, y + 1, x2 - 3, y + 2 );
  2053. lPntArray.putPoints( sc, 12, x2 - 5, y2 - 1, x2 - 4, y2 - 1, // btm right
  2054. x2 - 3, y2 - 2, x2 - 2, y2 - 3, x2 - 1, y2 - 5, x2 - 1, y2 - 4,
  2055. x + 3, y2 - 2, x + 4, y2 - 1, x + 5, y2 - 1, //half corners
  2056. x2 - 2, y + 3, x2 - 1, y + 4, x2 - 1, y + 5 );
  2057. sc += 12;
  2058. if ( i < hWidth - 1 )
  2059. {
  2060. hPntArray.putPoints( sc, 10, x + 6, y + 1, x + 4, y + 2, // top left
  2061. x + 3, y + 3, x + 2, y + 4, x + 1, y + 6,
  2062. x2 - 6, y + 1, x2 - 4, y + 2, // half corners
  2063. x2 - 3, y + 3, x + 2, y2 - 4, x + 1, y2 - 6 );
  2064. lPntArray.putPoints( sc, 10, x2 - 6, y2 - 1, x2 - 4, y2 - 2, // btm right
  2065. x2 - 3, y2 - 3, x2 - 2, y2 - 4, x2 - 1, y2 - 6,
  2066. x + 6, y2 - 1, x + 4, y2 - 2, // half corners
  2067. x + 3, y2 - 3, x2 - 1, y + 6, x2 - 2, y + 4 );
  2068. sc += 10;
  2069. }
  2070. hLineArray.putPoints( i * 4, 4, x + 6, y, x2 - 6, y, x, y + 6, x, y2 - 6 );
  2071. lLineArray.putPoints( i * 4, 4, x + 6, y2, x2 - 6, y2, x2, y + 6, x2, y2 - 6 );
  2072. ++x, ++y;
  2073. --x2, --y2;
  2074. }
  2075. p->setPen( Qt::black );
  2076. p->drawPoints( bPntArray );
  2077. p->drawLineSegments( bLineArray );
  2078. p->setPen( highPen );
  2079. p->drawPoints( hPntArray );
  2080. p->drawLineSegments( hLineArray );
  2081. p->setPen( lowPen );
  2082. p->drawPoints( lPntArray );
  2083. p->drawLineSegments( lLineArray );
  2084. }
  2085. // Rectangular buttons
  2086. else
  2087. {
  2088. TQPointArray highShade( hWidth * 4 );
  2089. TQPointArray lowShade( hWidth * 4 );
  2090. p->setPen( g.shadow() );
  2091. for ( i = 0; i < bWidth && w > 2 && h > 2; ++i, ++x, ++y, w -= 2, h -= 2 )
  2092. p->drawRect( x, y , w, h );
  2093. if ( !hWidth )
  2094. return ;
  2095. x2 = x + w - 1, y2 = y + h - 1;
  2096. for ( i = 0; i < hWidth; ++i, ++x, ++y, --x2, --y2 )
  2097. {
  2098. highShade.putPoints( i * 4, 4, x, y, x2, y, x, y, x, y2 );
  2099. lowShade.putPoints( i * 4, 4, x, y2, x2, y2, x2, y, x2, y2 );
  2100. }
  2101. if ( style == Windows && hWidth > 1 )
  2102. {
  2103. p->setPen( highPen );
  2104. p->drawLineSegments( highShade, 0, 2 );
  2105. p->setPen( lowPen );
  2106. p->drawLineSegments( lowShade, 0, 2 );
  2107. p->setPen( ( sunken ) ? g.dark() : g.mid() );
  2108. p->drawLineSegments( highShade, 4 );
  2109. p->setPen( ( sunken ) ? g.mid() : g.dark() );
  2110. p->drawLineSegments( lowShade, 4 );
  2111. }
  2112. else
  2113. {
  2114. p->setPen( ( sunken ) ? g.dark() : g.light() );
  2115. p->drawLineSegments( highShade );
  2116. p->setPen( ( sunken ) ? g.light() : g.dark() );
  2117. p->drawLineSegments( lowShade );
  2118. }
  2119. }
  2120. }
  2121. int KThemeStyle::popupMenuItemHeight( bool /*checkable*/, TQMenuItem *mi,
  2122. const TQFontMetrics &fm )
  2123. {
  2124. int h2, h = 0;
  2125. int offset = QMAX( decoWidth( MenuItemDown ), decoWidth( MenuItem ) ) + 4;
  2126. if ( mi->isSeparator() )
  2127. return ( 2 );
  2128. if ( mi->isChecked() )
  2129. h = isPixmap( CheckMark ) ? uncached( CheckMark ) ->height() + offset :
  2130. offset + 16;
  2131. if ( mi->pixmap() )
  2132. {
  2133. h2 = mi->pixmap() ->height() + offset;
  2134. h = h2 > h ? h2 : h;
  2135. }
  2136. if ( mi->iconSet() )
  2137. {
  2138. h2 = mi->iconSet() ->
  2139. pixmap( TQIconSet::Small, TQIconSet::Normal ).height() + offset;
  2140. h = h2 > h ? h2 : h;
  2141. }
  2142. h2 = fm.height() + offset;
  2143. h = h2 > h ? h2 : h;
  2144. return ( h );
  2145. }
  2146. #include "kthemestyle.moc"
  2147. // kate: indent-width 4; replace-tabs off; tab-width 4; space-indent on;