Lipstik widget style for TDE
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.

4109 lines
164KB

  1. /* Lipstik widget style for KDE 3
  2. Copyright (C) 2004-2007 Patrice Tremblay <poplixos@gmail.com>
  3. http://www.poplix.info/lipstik
  4. based on Plastik:
  5. Copyright (C) 2003 Sandro Giessl <ceebx@users.sourceforge.net>
  6. based on the KDE style "dotNET":
  7. Copyright (C) 2001-2002, Chris Lee <clee@kde.org>
  8. Carsten Pfeiffer <pfeiffer@kde.org>
  9. Karol Szwed <gallium@kde.org>
  10. Drawing routines completely reimplemented from KDE3 HighColor, which was
  11. originally based on some stuff from the KDE2 HighColor.
  12. based on drawing routines of the style "Keramik":
  13. Copyright (c) 2002 Malte Starostik <malte@kde.org>
  14. (c) 2002,2003 Maksim Orlovich <mo002j@mail.rochester.edu>
  15. based on the KDE3 HighColor Style
  16. Copyright (C) 2001-2002 Karol Szwed <gallium@kde.org>
  17. (C) 2001-2002 Fredrik H�glund <fredrik@kde.org>
  18. Drawing routines adapted from the KDE2 HCStyle,
  19. Copyright (C) 2000 Daniel M. Duley <mosfet@kde.org>
  20. (C) 2000 Dirk Mueller <mueller@kde.org>
  21. (C) 2001 Martijn Klingens <klingens@kde.org>
  22. Progressbar code based on KStyle,
  23. Copyright (C) 2001-2002 Karol Szwed <gallium@kde.org>
  24. ...also based on plastikq, krisp, comix, motifplus, polyester, qtcurve...
  25. This library is free software; you can redistribute it and/or
  26. modify it under the terms of the GNU Library General Public
  27. License version 2 as published by the Free Software Foundation.
  28. This library is distributed in the hope that it will be useful,
  29. but WITHOUT ANY WARRANTY; without even the implied warranty of
  30. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  31. Library General Public License for more details.
  32. You should have received a copy of the GNU Library General Public License
  33. along with this library; see the file COPYING.LIB. If not, write to
  34. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  35. Boston, MA 02110-1301, USA.
  36. */
  37. #include <tqimage.h>
  38. #include <tqstylefactory.h>
  39. #include <tqpointarray.h>
  40. #include <tqpainter.h>
  41. #include <tqtabbar.h>
  42. #include <tqprogressbar.h>
  43. #include <tqcheckbox.h>
  44. #include <tqcombobox.h>
  45. #include <tqcleanuphandler.h>
  46. #include <tqheader.h>
  47. #include <tqlineedit.h>
  48. #include <tqlistbox.h>
  49. #include <tqscrollbar.h>
  50. #include <tqstyleplugin.h>
  51. #include <tqpushbutton.h>
  52. #include <tqtabwidget.h>
  53. #include <tqtimer.h>
  54. #include <tqtoolbutton.h>
  55. #include <tqtoolbar.h>
  56. #include <tqmenubar.h>
  57. #include <tqpopupmenu.h>
  58. #include <tqdrawutil.h>
  59. #include <tqapplication.h>
  60. #include <tqvariant.h>
  61. #include <tqradiobutton.h>
  62. #include <tqregion.h>
  63. #include <tqslider.h>
  64. #include <tqsettings.h>
  65. #include <kpixmap.h>
  66. #include "lipstik.h"
  67. #include "lipstik.moc"
  68. #include "misc.h"
  69. // some bitmaps for the radio button so it's easier to handle the circle stuff...
  70. // 13x13
  71. static const unsigned char radiobutton_mask_bits[] = {
  72. 0xf8, 0x03, 0xfc, 0x07, 0xfe, 0x0f, 0xff, 0x1f, 0xff, 0x1f, 0xff, 0x1f,
  73. 0xff, 0x1f, 0xff, 0x1f, 0xff, 0x1f, 0xff, 0x1f, 0xfe, 0x0f, 0xfc, 0x07,
  74. 0xf8, 0x03};
  75. static const unsigned char radiobutton_contour_bits[] = {
  76. 0xf0, 0x01, 0x0c, 0x06, 0x02, 0x08, 0x02, 0x08, 0x01, 0x10, 0x01, 0x10,
  77. 0x01, 0x10, 0x01, 0x10, 0x01, 0x10, 0x02, 0x08, 0x02, 0x08, 0x0c, 0x06,
  78. 0xf0, 0x01};
  79. static const unsigned char radiobutton_aa_inside_bits[] = {
  80. 0x00, 0x00, 0x10, 0x01, 0x04, 0x04, 0x00, 0x00, 0x02, 0x08, 0x00, 0x00,
  81. 0x00, 0x00, 0x00, 0x00, 0x02, 0x08, 0x00, 0x00, 0x04, 0x04, 0x10, 0x01,
  82. 0x00, 0x00};
  83. static const unsigned char radiobutton_aa_outside_bits[] = {
  84. 0x08, 0x02, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00,
  85. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00,
  86. 0x08, 0x02};
  87. static const unsigned char radiobutton_highlight1_bits[] = {
  88. 0x00, 0x00, 0xf0, 0x01, 0x1c, 0x07, 0x04, 0x04, 0x06, 0x0c, 0x02, 0x08,
  89. 0x02, 0x08, 0x02, 0x08, 0x06, 0x0c, 0x04, 0x04, 0x1c, 0x07, 0xf0, 0x01,
  90. 0x00, 0x00};
  91. static const unsigned char radiobutton_highlight2_bits[] = {
  92. 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x18, 0x03, 0x08, 0x02, 0x04, 0x04,
  93. 0x04, 0x04, 0x04, 0x04, 0x08, 0x02, 0x18, 0x03, 0xe0, 0x00, 0x00, 0x00,
  94. 0x00, 0x00};
  95. // check mark
  96. const uint CHECKMARKSIZE = 9; // 9x9
  97. static const unsigned char checkmark_aa_bits[] = {
  98. 0x45, 0x01, 0x28, 0x00, 0x11, 0x01, 0x82, 0x00, 0x44, 0x00, 0x82, 0x00,
  99. 0x11, 0x01, 0x28, 0x00, 0x45, 0x01};
  100. static const unsigned char checkmark_dark_bits[] = {
  101. 0x82, 0x00, 0x45, 0x01, 0xaa, 0x00, 0x54, 0x00, 0x28, 0x00, 0x74, 0x00,
  102. 0xea, 0x00, 0xc5, 0x01, 0x82, 0x00};
  103. static const unsigned char checkmark_light_bits[] = {
  104. 0x00, 0xfe, 0x82, 0xfe, 0x44, 0xfe, 0x28, 0xfe, 0x10, 0xfe, 0x08, 0xfe,
  105. 0x04, 0xfe, 0x02, 0xfe, 0x00, 0xfe};
  106. static const unsigned char checkmark_tristate_bits[] = {
  107. 0x00, 0x00, 0xff, 0x01, 0x00, 0x00, 0xff, 0x01, 0x00, 0x00, 0xff, 0x01,
  108. 0x00, 0x00, 0xff, 0x01, 0x00, 0x00};
  109. // radio mark
  110. const uint RADIOMARKSIZE = 9; // 9x9
  111. static const unsigned char radiomark_aa_bits[] = {
  112. 0x00, 0x00, 0x44, 0x00, 0x82, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  113. 0x82, 0x00, 0x44, 0x00, 0x00, 0x00};
  114. static const unsigned char radiomark_dark_bits[] = {
  115. 0x00, 0x00, 0x38, 0x00, 0x44, 0x00, 0xf2, 0x00, 0xfa, 0x00, 0xfa, 0x00,
  116. 0x7c, 0x00, 0x38, 0x00, 0x00, 0x00};
  117. static const unsigned char radiomark_light_bits[] = {
  118. 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x0c, 0x00, 0x04, 0x00, 0x04, 0x00,
  119. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  120. // popupmenu item constants...
  121. static const int itemHMargin = 6;
  122. static const int itemFrame = 2;
  123. static const int arrowHMargin = 6;
  124. static const int rightBorder = 12;
  125. // -- Style Plugin Interface -------------------------
  126. class LipstikStylePlugin : public TQStylePlugin
  127. {
  128. public:
  129. LipstikStylePlugin() {}
  130. ~LipstikStylePlugin() {}
  131. TQStringList keys() const {
  132. return TQStringList() << "Lipstik";
  133. }
  134. TQStyle* create( const TQString& key ) {
  135. if (key.lower() == "lipstik")
  136. return new LipstikStyle;
  137. return 0;
  138. }
  139. };
  140. TQ_EXPORT_PLUGIN( LipstikStylePlugin )
  141. // -- end --
  142. LipstikStyle::LipstikStyle() : KStyle( AllowMenuTransparency, ThreeButtonScrollBar),
  143. kickerMode(false),
  144. kornMode(false),
  145. flatMode(false)
  146. {
  147. hoverWidget = 0;
  148. hoverTab = 0;
  149. horizontalDots = 0;
  150. verticalDots = 0;
  151. horizontalLine = 0;
  152. verticalLine = 0;
  153. TQSettings settings;
  154. _contrast = settings.readNumEntry("/TQt/KDE/contrast", 6);
  155. _defaultMenuStripeColor.setNamedColor( settings.readEntry("/TQt/KWinPalette/activeBackground", "black") );
  156. settings.beginGroup("/lipstikstyle/Settings");
  157. _animateProgressBar = settings.readBoolEntry("/animateProgressBar", false);
  158. _drawToolBarSeparator = settings.readBoolEntry("/drawToolBarSeparator", true);
  159. _drawToolBarGradient = settings.readBoolEntry("/drawToolBarGradient", false);
  160. _invertBarGrad = settings.readBoolEntry("/invertBarGrad", true);
  161. _drawToolBarItemSeparator = settings.readBoolEntry("/drawToolBarItemSeparator", true);
  162. _drawFocusRect = settings.readBoolEntry("/drawFocusRect", true);
  163. _drawTriangularExpander = settings.readBoolEntry("/drawTriangularExpander", false);
  164. _inputFocusHighlight = settings.readBoolEntry("/inputFocusHighlight", true);
  165. _customOverHighlightColor = settings.readBoolEntry("/customOverHighlightColor", false);
  166. _overHighlightColor.setNamedColor( settings.readEntry("/overHighlightColor", "black") );
  167. _customFocusHighlightColor = settings.readBoolEntry("/customFocusHighlightColor", false);
  168. _focusHighlightColor.setNamedColor( settings.readEntry("/focusHighlightColor", "black") );
  169. _customCheckMarkColor = settings.readBoolEntry("/customCheckMarkColor", false);
  170. _checkMarkColor.setNamedColor( settings.readEntry("/checkMarkColor", "black") );
  171. _customTabHighlightColor = settings.readBoolEntry("/customTabHighlightColor", false);
  172. _tabHighlightColor.setNamedColor( settings.readEntry("/tabHighlightColor", "black") );
  173. _menuSpacing = settings.readNumEntry("/menuSpacing", 5);
  174. _toolBarSpacing = settings.readNumEntry("/toolBarSpacing", 0);
  175. _drawStatusBarFrame = settings.readBoolEntry("/drawStatusBarFrame", false);
  176. _scrollBarStyle = settings.readEntry("/scrollBarStyle", "WindowsStyleScrollBar");
  177. _scrollBarWidth = settings.readEntry("/scrollBarWidth", "Small");
  178. _paintGroove = settings.readBoolEntry("/paintGroove", true);
  179. _flatHeaders = settings.readBoolEntry("/flatHeaders", true);
  180. _sliderStyle = settings.readEntry("/sliderStyle", "sliderLipstikStyle");
  181. _reverseGradients = settings.readBoolEntry("/reverseGradients", false);
  182. _drawTabHighlight = settings.readBoolEntry("/drawTabHighlight", true);
  183. _drawToolBarHandle = settings.readBoolEntry("/drawToolBarHandle", true);
  184. _coloredMenuBar = settings.readBoolEntry("/coloredMenuBar", false);
  185. _menuLeftSideBar = settings.readBoolEntry("/menuLeftSideBar", true);
  186. _flatStripe = settings.readBoolEntry("/flatStripe", false);
  187. _customMenuStripeColor = settings.readBoolEntry("/customMenuStripeColor", false);
  188. _menuStripeColor.setNamedColor( settings.readEntry("/menuStripeColor", "black") );
  189. _alterMenuGradients = settings.readBoolEntry("/alterMenuGradients", true);
  190. _sharperMenuGradient = settings.readBoolEntry("/sharperMenuGradient", false);
  191. _comboboxColored = settings.readBoolEntry("/comboboxColored", false);
  192. _tickCheckMark = settings.readBoolEntry("/tickCheckMark", true);
  193. //(Keep the following around for later, I cant make it work now.)
  194. //_customArrowColor = settings.readBoolEntry("/customArrowColor", false);
  195. //_arrowColor.setNamedColor( settings.readEntry("/arrowColor", "black") );
  196. settings.endGroup();
  197. if( !strcmp(_scrollBarStyle,"WindowsStyleScrollBar" ) )
  198. this->setScrollBarType(KStyle::WindowsStyleScrollBar);
  199. else if( !strcmp(_scrollBarStyle,"PlatinumStyleScrollBar" ) )
  200. this->setScrollBarType(KStyle::PlatinumStyleScrollBar);
  201. else if( !strcmp(_scrollBarStyle,"NextStyleScrollBar" ) )
  202. this->setScrollBarType(KStyle::NextStyleScrollBar);
  203. // setup pixmap cache...
  204. pixmapCache = new TQIntCache<CacheEntry>(150000, 499);
  205. pixmapCache->setAutoDelete(true);
  206. if ( _animateProgressBar )
  207. {
  208. animationTimer = new TQTimer( this );
  209. connect( animationTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(updateProgressPos()) );
  210. }
  211. }
  212. void LipstikStyle::updateProgressPos()
  213. {
  214. TQProgressBar* pb;
  215. //Update the registered progressbars.
  216. TQMap<TQWidget*, int>::iterator iter;
  217. bool visible = false;
  218. for (iter = progAnimWidgets.begin(); iter != progAnimWidgets.end(); ++iter)
  219. {
  220. if ( !::tqqt_cast<TQProgressBar*>(iter.key()) )
  221. continue;
  222. pb = dynamic_cast<TQProgressBar*>(iter.key());
  223. if ( iter.key() -> isEnabled() &&
  224. pb -> progress() != pb->totalSteps() )
  225. {
  226. // update animation Offset of the current Widget
  227. iter.data() = (iter.data() + 1) % 20;
  228. iter.key()->update();
  229. }
  230. if (iter.key()->isVisible())
  231. visible = true;
  232. }
  233. if (!visible)
  234. animationTimer->stop();
  235. }
  236. LipstikStyle::~LipstikStyle()
  237. {
  238. delete pixmapCache;
  239. delete horizontalDots;
  240. delete verticalDots;
  241. delete horizontalLine;
  242. delete verticalLine;
  243. }
  244. void LipstikStyle::polish(TQApplication* app)
  245. {
  246. if (!qstrcmp(app->argv()[0], "kicker"))
  247. kickerMode = true;
  248. else if (!qstrcmp(app->argv()[0], "korn"))
  249. kornMode = true;
  250. }
  251. void LipstikStyle::polish(TQWidget* widget)
  252. {
  253. if( !strcmp(widget->name(), "__khtml") ) { // is it a khtml widget...?
  254. khtmlWidgets[widget] = true;
  255. connect(widget, TQT_SIGNAL(destroyed(TQObject*)), this, TQT_SLOT(khtmlWidgetDestroyed(TQObject*)));
  256. }
  257. // use qt_cast where possible to check if the widget inheits one of the classes. might improve
  258. // performance compared to TQObject::inherits()
  259. if ( ::tqqt_cast<TQPushButton*>(widget) || ::tqqt_cast<TQComboBox*>(widget) ||
  260. ::tqqt_cast<TQSpinWidget*>(widget) || ::tqqt_cast<TQSlider*>(widget) ||
  261. ::tqqt_cast<TQCheckBox*>(widget) || ::tqqt_cast<TQRadioButton*>(widget) ||
  262. ::tqqt_cast<TQToolButton*>(widget)
  263. )
  264. {
  265. widget->installEventFilter(this);
  266. } else if (::tqqt_cast<TQTabBar*>(widget)) {
  267. widget->setMouseTracking(true);
  268. widget->installEventFilter(this);
  269. } else if (::tqqt_cast<TQPopupMenu*>(widget)) {
  270. widget->setBackgroundMode( NoBackground );
  271. } else if(::tqqt_cast<TQScrollBar*>(widget)) {
  272. widget->setMouseTracking(true);
  273. widget->installEventFilter(this);
  274. } else if (widget->inherits(TQSPLITTERHANDLE_OBJECT_NAME_STRING) || widget->inherits(TQDOCKWINDOWHANDLE_OBJECT_NAME_STRING) ) {
  275. widget->installEventFilter(this);
  276. } else if (::tqqt_cast<TQLineEdit*>(widget)) {
  277. widget->installEventFilter(this);
  278. } else if ( !qstrcmp(widget->name(), "kde toolbar widget") ) {
  279. widget->installEventFilter(this);
  280. }
  281. if( _animateProgressBar && ::tqqt_cast<TQProgressBar*>(widget) ) {
  282. widget->installEventFilter(this);
  283. progAnimWidgets[widget] = 0;
  284. connect(widget, TQT_SIGNAL(destroyed(TQObject*)), this, TQT_SLOT(progressBarDestroyed(TQObject*)));
  285. if (!animationTimer->isActive())
  286. animationTimer->start( 50, false );
  287. } else if( !qstrcmp(widget->className(), "KonqFrameStatusBar") ) {
  288. // This disables the white background of the KonquerorFrameStatusBar.
  289. // When the green led is shown the background is set to
  290. // applications cg.midlight() so we override it to standard background.
  291. // Thanks Comix! (because this was ugly from day one!)
  292. // NOTE: Check if we can set it earlier (before painting), cause
  293. // on slow machines we can see the repainting of the bar (from white to background...)
  294. TQPalette kPalette = TQApplication::palette();
  295. kPalette.setColor( TQColorGroup::Midlight,kPalette.active().background() );
  296. TQApplication::setPalette( kPalette );
  297. }
  298. KStyle::polish(widget);
  299. }
  300. void LipstikStyle::unPolish(TQWidget* widget)
  301. {
  302. if( !strcmp(widget->name(), "__khtml") ) { // is it a khtml widget...?
  303. khtmlWidgets.remove(widget);
  304. }
  305. // use qt_cast to check if the widget inheits one of the classes.
  306. if ( ::tqqt_cast<TQPushButton*>(widget) || ::tqqt_cast<TQComboBox*>(widget) ||
  307. ::tqqt_cast<TQSpinWidget*>(widget) || ::tqqt_cast<TQSlider*>(widget) ||
  308. ::tqqt_cast<TQCheckBox*>(widget) || ::tqqt_cast<TQRadioButton*>(widget) ||
  309. ::tqqt_cast<TQToolButton*>(widget) || ::tqqt_cast<TQLineEdit*>(widget) ||
  310. widget->inherits(TQSPLITTERHANDLE_OBJECT_NAME_STRING) )
  311. {
  312. widget->removeEventFilter(this);
  313. }
  314. else if (::tqqt_cast<TQTabBar*>(widget)) {
  315. widget->setMouseTracking(false);
  316. widget->removeEventFilter(this);
  317. } else if (::tqqt_cast<TQScrollBar*>(widget)) {
  318. widget->setMouseTracking(false);
  319. widget->removeEventFilter(this);
  320. } else if (::tqqt_cast<TQPopupMenu*>(widget)) {
  321. widget->setBackgroundMode( PaletteBackground );
  322. } else if ( !qstrcmp(widget->name(), "kde toolbar widget") ) {
  323. widget->removeEventFilter(this);
  324. }
  325. if ( ::tqqt_cast<TQProgressBar*>(widget) ) {
  326. progAnimWidgets.remove(widget);
  327. } else if( widget->inherits("KonqFrameStatusBar") ) {
  328. widget->removeEventFilter(this);
  329. }
  330. KStyle::unPolish(widget);
  331. }
  332. void LipstikStyle::khtmlWidgetDestroyed(TQObject* obj)
  333. {
  334. khtmlWidgets.remove(TQT_TQWIDGET(obj));
  335. }
  336. void LipstikStyle::progressBarDestroyed(TQObject* obj)
  337. {
  338. progAnimWidgets.remove(TQT_TQWIDGET(obj));
  339. }
  340. void LipstikStyle::renderContour(TQPainter *p,
  341. const TQRect &r,
  342. const TQColor &backgroundColor,
  343. const TQColor &contour,
  344. const uint flags) const
  345. {
  346. if((r.width() <= 0)||(r.height() <= 0))
  347. return;
  348. const bool drawLeft = flags&Draw_Left;
  349. const bool drawRight = flags&Draw_Right;
  350. const bool drawTop = flags&Draw_Top;
  351. const bool drawBottom = flags&Draw_Bottom;
  352. const bool disabled = flags&Is_Disabled;
  353. const bool alphaBlend = flags&Draw_AlphaBlend;
  354. TQColor contourColor;
  355. if (disabled) {
  356. contourColor = backgroundColor.dark(150);
  357. } else {
  358. contourColor = contour;
  359. }
  360. // sides
  361. p->setPen( alphaBlendColors(backgroundColor, contourColor, 50) );
  362. if(drawLeft)
  363. p->drawLine(r.left(), drawTop?r.top()+2:r.top(), r.left(), drawBottom?r.bottom()-2:r.bottom());
  364. if(drawRight)
  365. p->drawLine(r.right(), drawTop?r.top()+2:r.top(), r.right(), drawBottom?r.bottom()-2:r.bottom());
  366. if(drawTop)
  367. p->drawLine(drawLeft?r.left()+2:r.left(), r.top(), drawRight?r.right()-2:r.right(), r.top());
  368. if(drawBottom)
  369. p->drawLine(drawLeft?r.left()+2:r.left(), r.bottom(), drawRight?r.right()-2:r.right(), r.bottom());
  370. // edges
  371. const int alphaAA = 110; // the alpha value for anti-aliasing...
  372. // first part...
  373. p->setPen(alphaBlendColors(backgroundColor, contourColor, 50) );
  374. if(drawLeft && drawTop) {
  375. switch(flags&Round_UpperLeft) {
  376. case false:
  377. p->drawPoint(r.left()+1, r.top());
  378. p->drawPoint(r.left(), r.top()+1);
  379. break;
  380. default:
  381. p->drawPoint(r.left()+1, r.top()+1);
  382. }
  383. }
  384. if(drawLeft && drawBottom) {
  385. switch(flags&Round_BottomLeft) {
  386. case false:
  387. p->drawPoint(r.left()+1, r.bottom());
  388. p->drawPoint(r.left(), r.bottom()-1);
  389. break;
  390. default:
  391. p->drawPoint(r.left()+1, r.bottom()-1);
  392. }
  393. }
  394. if(drawRight && drawTop) {
  395. switch(flags&Round_UpperRight) {
  396. case false:
  397. p->drawPoint(r.right()-1, r.top());
  398. p->drawPoint(r.right(), r.top()+1);
  399. break;
  400. default:
  401. p->drawPoint(r.right()-1, r.top()+1);
  402. }
  403. }
  404. if(drawRight && drawBottom) {
  405. switch(flags&Round_BottomRight) {
  406. case false:
  407. p->drawPoint(r.right()-1, r.bottom());
  408. p->drawPoint(r.right(), r.bottom()-1);
  409. break;
  410. default:
  411. p->drawPoint(r.right()-1, r.bottom()-1);
  412. }
  413. }
  414. // second part... fill edges in case we don't paint alpha-blended
  415. p->setPen( backgroundColor );
  416. if (!alphaBlend) {
  417. if(flags&Round_UpperLeft && drawLeft && drawTop) {
  418. p->drawPoint( r.x(), r.y() );
  419. }
  420. if(flags&Round_BottomLeft && drawLeft && drawBottom) {
  421. p->drawPoint( r.x(), r.bottom() );
  422. }
  423. if(flags&Round_UpperRight && drawRight && drawTop) {
  424. p->drawPoint( r.right(), r.y() );
  425. }
  426. if(flags&Round_BottomRight && drawRight && drawBottom) {
  427. p->drawPoint( r.right(), r.bottom() );
  428. }
  429. }
  430. // third part... anti-aliasing...
  431. if(drawLeft && drawTop) {
  432. switch(flags&Round_UpperLeft) {
  433. case false:
  434. renderPixel(p,TQPoint(r.left(),r.top()),alphaAA,contourColor,backgroundColor,alphaBlend);
  435. break;
  436. default:
  437. renderPixel(p,TQPoint(r.left()+1,r.top()),alphaAA,contourColor,backgroundColor,alphaBlend);
  438. renderPixel(p,TQPoint(r.left(),r.top()+1),alphaAA,contourColor,backgroundColor,alphaBlend);
  439. }
  440. }
  441. if(drawLeft && drawBottom) {
  442. switch(flags&Round_BottomLeft) {
  443. case false:
  444. renderPixel(p,TQPoint(r.left(),r.bottom()),alphaAA,contourColor,backgroundColor,alphaBlend);
  445. break;
  446. default:
  447. renderPixel(p,TQPoint(r.left()+1,r.bottom()),alphaAA,contourColor,backgroundColor,alphaBlend);
  448. renderPixel(p,TQPoint(r.left(),r.bottom()-1),alphaAA,contourColor,backgroundColor,alphaBlend);
  449. }
  450. }
  451. if(drawRight && drawTop) {
  452. switch(flags&Round_UpperRight) {
  453. case false:
  454. renderPixel(p,TQPoint(r.right(),r.top()),alphaAA,contourColor,backgroundColor,alphaBlend);
  455. break;
  456. default:
  457. renderPixel(p,TQPoint(r.right()-1,r.top()),alphaAA,contourColor,backgroundColor,alphaBlend);
  458. renderPixel(p,TQPoint(r.right(),r.top()+1),alphaAA,contourColor,backgroundColor,alphaBlend);
  459. }
  460. }
  461. if(drawRight && drawBottom) {
  462. switch(flags&Round_BottomRight) {
  463. case false:
  464. renderPixel(p,TQPoint(r.right(),r.bottom()),alphaAA,contourColor,backgroundColor,alphaBlend);
  465. break;
  466. default:
  467. renderPixel(p,TQPoint(r.right()-1,r.bottom()),alphaAA,contourColor,backgroundColor,alphaBlend);
  468. renderPixel(p,TQPoint(r.right(),r.bottom()-1),alphaAA,contourColor,backgroundColor,alphaBlend);
  469. }
  470. }
  471. }
  472. void LipstikStyle::renderMask(TQPainter *p,
  473. const TQRect &r,
  474. const TQColor &color,
  475. const uint flags) const
  476. {
  477. if((r.width() <= 0)||(r.height() <= 0))
  478. return;
  479. const bool roundUpperLeft = flags&Round_UpperLeft;
  480. const bool roundUpperRight = flags&Round_UpperRight;
  481. const bool roundBottomLeft = flags&Round_BottomLeft;
  482. const bool roundBottomRight = flags&Round_BottomRight;
  483. p->fillRect (TQRect(r.x()+1, r.y()+1, r.width()-2, r.height()-2) , color);
  484. p->setPen(color);
  485. // sides
  486. p->drawLine(roundUpperLeft?r.x()+1:r.x(), r.y(),
  487. roundUpperRight?r.right()-1:r.right(), r.y() );
  488. p->drawLine(roundBottomLeft?r.x()+1:r.x(), r.bottom(),
  489. roundBottomRight?r.right()-1:r.right(), r.bottom() );
  490. p->drawLine(r.x(), roundUpperLeft?r.y()+1:r.y(),
  491. r.x(), roundBottomLeft?r.bottom()-1:r.bottom() );
  492. p->drawLine(r.right(), roundUpperLeft?r.y()+1:r.y(),
  493. r.right(), roundBottomLeft?r.bottom()-1:r.bottom() );
  494. }
  495. void LipstikStyle::renderSurface(TQPainter *p,
  496. const TQRect &r,
  497. const TQColor &backgroundColor,
  498. const TQColor &buttonColor,
  499. const TQColor &highlightColor,
  500. int intensity,
  501. const uint flags) const
  502. {
  503. if((r.width() <= 0)||(r.height() <= 0))
  504. return;
  505. const bool disabled = flags&Is_Disabled;
  506. const bool drawLeft = flags&Draw_Left;
  507. const bool drawRight = flags&Draw_Right;
  508. const bool drawTop = flags&Draw_Top;
  509. const bool drawBottom = flags&Draw_Bottom;
  510. const bool roundUpperLeft = flags&Round_UpperLeft;
  511. const bool roundUpperRight = flags&Round_UpperRight;
  512. const bool roundBottomLeft = flags&Round_BottomLeft;
  513. const bool roundBottomRight = flags&Round_BottomRight;
  514. const bool sunken = flags&Is_Sunken;
  515. const bool horizontal = flags&Is_Horizontal;
  516. bool highlight = false,
  517. highlightLeft = false,
  518. highlightRight = false,
  519. highlightTop = false,
  520. highlightBottom = false;
  521. // only highlight if not sunken & not disabled...
  522. if(!sunken && !disabled) {
  523. highlight = (flags&Is_Highlight);
  524. highlightLeft = (flags&Highlight_Left);
  525. highlightRight = (flags&Highlight_Right);
  526. highlightTop = (flags&Highlight_Top);
  527. highlightBottom = (flags&Highlight_Bottom);
  528. }
  529. TQColor baseColor = alphaBlendColors(backgroundColor, disabled?backgroundColor:buttonColor, 10);
  530. if (disabled) {
  531. intensity = 2;
  532. } else if (highlight) {
  533. // blend this _slightly_ with the background
  534. baseColor = alphaBlendColors(baseColor, highlightColor, 240);
  535. } else if (sunken) {
  536. // enforce a common sunken-style...
  537. baseColor = baseColor.dark(110+intensity);
  538. intensity = _contrast/2;
  539. }
  540. // some often needed colors...
  541. // 1 more intensive than 2 and 3.
  542. const TQColor colorTop1 = alphaBlendColors(baseColor,
  543. sunken?baseColor.dark(100+intensity*2):baseColor.light(100+intensity*2), 80);
  544. const TQColor colorTop2 = alphaBlendColors(baseColor,
  545. sunken?baseColor.dark(100+intensity):baseColor.light(100+intensity), 80);
  546. const TQColor colorBottom1 = alphaBlendColors(baseColor,
  547. sunken?baseColor.light(100+intensity*2):baseColor.dark(100+intensity*2), 80);
  548. const TQColor colorBottom2 = alphaBlendColors(baseColor,
  549. sunken?baseColor.light(100+intensity):baseColor.dark(100+intensity), 80);
  550. // sides
  551. if (drawLeft) {
  552. if (horizontal) {
  553. int height = r.height();
  554. if (roundUpperLeft || !drawTop) height--;
  555. if (roundBottomLeft || !drawBottom) height--;
  556. renderGradient(p, TQRect(r.left(), (roundUpperLeft&&drawTop)?r.top()+1:r.top(), 1, height),
  557. colorTop1, baseColor);
  558. } else {
  559. p->setPen(colorTop1 );
  560. p->drawLine(r.left(), (roundUpperLeft&&drawTop)?r.top()+1:r.top(),
  561. r.left(), (roundBottomLeft&&drawBottom)?r.bottom()-1:r.bottom() );
  562. }
  563. }
  564. if (drawRight) {
  565. if (horizontal) {
  566. int height = r.height();
  567. // TODO: there's still a bogus in it: when edge4 is Thick
  568. // and we don't whant to draw the Top, we have a unpainted area
  569. if (roundUpperRight || !drawTop) height--;
  570. if (roundBottomRight || !drawBottom) height--;
  571. renderGradient(p, TQRect(r.right(), (roundUpperRight&&drawTop)?r.top()+1:r.top(), 1, height),
  572. baseColor, colorBottom1);
  573. } else {
  574. p->setPen(colorBottom1 );
  575. p->drawLine(r.right(), (roundUpperRight&&drawTop)?r.top()+1:r.top(),
  576. r.right(), (roundBottomRight&&drawBottom)?r.bottom()-1:r.bottom() );
  577. }
  578. }
  579. if (drawTop) {
  580. if (horizontal) {
  581. p->setPen(colorTop1 );
  582. p->drawLine((roundUpperLeft&&drawLeft)?r.left()+1:r.left(), r.top(),
  583. (roundUpperRight&&drawRight)?r.right()-1:r.right(), r.top() );
  584. } else {
  585. int width = r.width();
  586. if (roundUpperLeft || !drawLeft) width--;
  587. if (roundUpperRight || !drawRight) width--;
  588. renderGradient(p, TQRect((roundUpperLeft&&drawLeft)?r.left()+1:r.left(), r.top(), width, 1),
  589. colorTop1, colorTop2);
  590. }
  591. }
  592. if (drawBottom) {
  593. if (horizontal) {
  594. p->setPen(colorBottom1 );
  595. p->drawLine((roundBottomLeft&&drawLeft)?r.left()+1:r.left(), r.bottom(),
  596. (roundBottomRight&&drawRight)?r.right()-1:r.right(), r.bottom() );
  597. } else {
  598. int width = r.width();
  599. if (roundBottomLeft || !drawLeft) width--;
  600. if (roundBottomRight || !drawRight) width--;
  601. renderGradient(p, TQRect((roundBottomLeft&&drawLeft)?r.left()+1:r.left(), r.bottom(), width, 1),
  602. colorBottom2, colorBottom1);
  603. }
  604. }
  605. // button area...
  606. int width = r.width();
  607. int height = r.height();
  608. if (drawLeft) width--;
  609. if (drawRight) width--;
  610. if (drawTop) height--;
  611. if (drawBottom) height--;
  612. renderGradient(p, TQRect(drawLeft?r.left()+1:r.left(), drawTop?r.top()+1:r.top(), width, height),
  613. colorTop2, colorBottom2, horizontal);
  614. // highlighting...
  615. if(highlightTop) {
  616. p->setPen(alphaBlendColors(colorTop1 , highlightColor, 80) );
  617. p->drawLine((roundUpperLeft&&drawLeft)?r.left()+1:r.left(), r.top(),
  618. (roundUpperRight&&drawRight)?r.right()-1:r.right(), r.top() );
  619. p->setPen(alphaBlendColors(colorTop2 , highlightColor, 150) );
  620. p->drawLine(highlightLeft?r.left()+1:r.left(), r.top()+1,
  621. highlightRight?r.right()-1:r.right(), r.top()+1 );
  622. }
  623. if(highlightBottom) {
  624. p->setPen(alphaBlendColors(colorBottom1 , highlightColor, 80) );
  625. p->drawLine((roundBottomLeft&&drawLeft)?r.left()+1:r.left(), r.bottom(),
  626. (roundBottomRight&&drawRight)?r.right()-1:r.right(), r.bottom() );
  627. p->setPen(alphaBlendColors(colorBottom2 , highlightColor, 150) );
  628. p->drawLine(highlightLeft?r.left()+1:r.left(), r.bottom()-1,
  629. highlightRight?r.right()-1:r.right(), r.bottom()-1 );
  630. }
  631. if(highlightLeft) {
  632. p->setPen(alphaBlendColors(colorTop1 , highlightColor, 80) );
  633. p->drawLine(r.left(), (roundUpperLeft&&drawTop)?r.top()+1:r.top(),
  634. r.left(), (roundBottomLeft&&drawBottom)?r.bottom()-1:r.bottom() );
  635. p->setPen(alphaBlendColors(colorTop2 , highlightColor, 150) );
  636. p->drawLine(r.left()+1, highlightTop?r.top()+1:r.top(),
  637. r.left()+1, highlightBottom?r.bottom()-1:r.bottom() );
  638. }
  639. if(highlightRight) {
  640. p->setPen(alphaBlendColors(colorBottom1 , highlightColor, 80) );
  641. p->drawLine(r.right(), (roundUpperRight&&drawTop)?r.top()+1:r.top(),
  642. r.right(), (roundBottomRight&&drawBottom)?r.bottom()-1:r.bottom() );
  643. p->setPen(alphaBlendColors(colorBottom2 , highlightColor, 150) );
  644. p->drawLine(r.right()-1, highlightTop?r.top()+1:r.top(),
  645. r.right()-1, highlightBottom?r.bottom()-1:r.bottom() );
  646. }
  647. }
  648. void LipstikStyle::renderPixel(TQPainter *p,
  649. const TQPoint &pos,
  650. const int alpha,
  651. const TQColor &color,
  652. const TQColor &background,
  653. bool fullAlphaBlend) const
  654. {
  655. if(fullAlphaBlend)
  656. // full alpha blend: paint into an image with alpha buffer and convert to a pixmap ...
  657. {
  658. TQRgb rgb = color.rgb();
  659. // generate a quite unique key -- use the unused width field to store the alpha value.
  660. CacheEntry search(cAlphaDot, alpha, 0, rgb);
  661. int key = search.key();
  662. CacheEntry *cacheEntry;
  663. if( (cacheEntry = pixmapCache->find(key)) ) {
  664. if( search == *cacheEntry ) { // match! we can draw now...
  665. if(cacheEntry->pixmap)
  666. p->drawPixmap(pos, *(cacheEntry->pixmap) );
  667. return;
  668. } else { //Remove old entry in case of a conflict!
  669. pixmapCache->remove( key );
  670. }
  671. }
  672. TQImage aImg(1,1,32); // 1x1
  673. aImg.setAlphaBuffer(true);
  674. aImg.setPixel(0,0,tqRgba(tqRed(rgb),tqGreen(rgb),tqBlue(rgb),alpha));
  675. TQPixmap *result = new TQPixmap(aImg);
  676. p->drawPixmap(pos, *result);
  677. // add to the cache...
  678. CacheEntry *toAdd = new CacheEntry(search);
  679. toAdd->pixmap = result;
  680. bool insertOk = pixmapCache->insert( key, toAdd, result->depth()/8);
  681. if(!insertOk)
  682. delete result;
  683. } else
  684. // don't use an alpha buffer: calculate the resulting color from the alpha value, the fg- and the bg-color.
  685. {
  686. TQRgb rgb_a = color.rgb();
  687. TQRgb rgb_b = background.rgb();
  688. int a = alpha;
  689. if(a>255) a = 255;
  690. if(a<0) a = 0;
  691. int a_inv = 255 - a;
  692. TQColor res = TQColor( tqRgb(tqRed(rgb_b)*a_inv/255 + tqRed(rgb_a)*a/255,
  693. tqGreen(rgb_b)*a_inv/255 + tqGreen(rgb_a)*a/255,
  694. tqBlue(rgb_b)*a_inv/255 + tqBlue(rgb_a)*a/255) );
  695. p->setPen(res);
  696. p->drawPoint(pos);
  697. }
  698. }
  699. void LipstikStyle::renderButton(TQPainter *p,
  700. const TQRect &r,
  701. const TQColorGroup &g,
  702. bool sunken,
  703. bool mouseOver,
  704. bool horizontal,
  705. bool enabled,
  706. bool khtmlMode) const
  707. {
  708. // small fix for the kicker buttons...
  709. if(kickerMode) enabled = true;
  710. const TQPen oldPen( p->pen() );
  711. uint contourFlags = Draw_Left|Draw_Right|Draw_Top|Draw_Bottom;
  712. if(!enabled) contourFlags|=Is_Disabled;
  713. if(khtmlMode) contourFlags|=Draw_AlphaBlend;
  714. uint surfaceFlags = Draw_Left|Draw_Right|Draw_Top|Draw_Bottom;
  715. if(horizontal) surfaceFlags|=Is_Horizontal;
  716. if(!enabled) surfaceFlags|=Is_Disabled;
  717. else {
  718. if(sunken) surfaceFlags|=Is_Sunken;
  719. else {
  720. if(mouseOver) {
  721. surfaceFlags|=Is_Highlight;
  722. surfaceFlags|=Highlight_Top;
  723. surfaceFlags|=Highlight_Bottom;
  724. surfaceFlags|=Highlight_Right;
  725. surfaceFlags|=Highlight_Left;
  726. }
  727. }
  728. }
  729. if (!flatMode) {
  730. contourFlags |= Round_UpperLeft|Round_UpperRight|Round_BottomLeft|Round_BottomRight;
  731. surfaceFlags |= Round_UpperLeft|Round_UpperRight|Round_BottomLeft|Round_BottomRight;
  732. renderContour(p, r, g.background(), getColor(g,ButtonContour),
  733. contourFlags);
  734. renderSurface(p, TQRect(r.left()+1, r.top()+1, r.width()-2, r.height()-2),
  735. g.background(), g.button(), getColor(g,MouseOverHighlight), _contrast, surfaceFlags);
  736. } else {
  737. renderContour(p, r, g.background(), g.button().dark(105+_contrast*3),
  738. contourFlags);
  739. renderSurface(p, TQRect(r.left()+1, r.top()+1, r.width()-2, r.height()-2),
  740. g.background(), g.button(), getColor(g,MouseOverHighlight), _contrast/2, surfaceFlags);
  741. flatMode = false;
  742. }
  743. p->setPen(oldPen);
  744. }
  745. void LipstikStyle::renderDot(TQPainter *p,
  746. const TQPoint &point,
  747. const TQColor &baseColor,
  748. const bool thick,
  749. const bool sunken) const
  750. {
  751. const TQColor topColor = alphaBlendColors(baseColor, sunken?baseColor.dark(130):baseColor.light(150), 70);
  752. const TQColor bottomColor = alphaBlendColors(baseColor, sunken?baseColor.light(150):baseColor.dark(130), 70);
  753. p->setPen(topColor );
  754. p->drawLine(point.x(), point.y(), point.x()+1, point.y());
  755. p->drawPoint(point.x(), point.y()+1);
  756. p->setPen(bottomColor );
  757. if(thick) {
  758. p->drawLine(point.x()+1, point.y()+2, point.x()+2, point.y()+2);
  759. p->drawPoint(point.x()+2, point.y()+1);
  760. } else {
  761. p->drawPoint(point.x()+1, point.y()+1);
  762. }
  763. }
  764. void LipstikStyle::renderGradient(TQPainter *painter,
  765. const TQRect &rect,
  766. const TQColor &c1,
  767. const TQColor &c2,
  768. bool horizontal) const
  769. {
  770. if((rect.width() <= 0)||(rect.height() <= 0))
  771. return;
  772. // generate a quite unique key for this surface.
  773. CacheEntry search(cGradientTile,
  774. horizontal ? 0 : rect.width(),
  775. horizontal ? rect.height() : 0,
  776. c1.rgb(), c2.rgb(), horizontal );
  777. int key = search.key();
  778. CacheEntry *cacheEntry;
  779. if( (cacheEntry = pixmapCache->find(key)) ) {
  780. if( search == *cacheEntry ) { // match! we can draw now...
  781. if(cacheEntry->pixmap) {
  782. painter->drawTiledPixmap(rect, *(cacheEntry->pixmap) );
  783. }
  784. return;
  785. } else {
  786. // Remove old entry in case of a conflict!
  787. // This shouldn't happen very often, see comment in CacheEntry.
  788. pixmapCache->remove(key);
  789. }
  790. }
  791. // there wasn't anything matching in the cache, create the pixmap now...
  792. TQPixmap *result = new TQPixmap(horizontal ? 10 : rect.width(),
  793. horizontal ? rect.height() : 10);
  794. TQPainter p(result);
  795. int r_w = result->rect().width();
  796. int r_h = result->rect().height();
  797. int r_x, r_y, r_x2, r_y2;
  798. TQT_TQRECT_OBJECT(result->rect()).coords(&r_x, &r_y, &r_x2, &r_y2);
  799. int rDiff, gDiff, bDiff;
  800. int rc, gc, bc;
  801. register int x, y;
  802. if( _reverseGradients ) {
  803. rDiff = ( c2.red()) - (rc = c1.red());
  804. gDiff = ( c2.green()) - (gc = c1.green());
  805. bDiff = ( c2.blue()) - (bc = c1.blue());
  806. } else {
  807. rDiff = ( c1.red()) - (rc = c2.red());
  808. gDiff = ( c1.green()) - (gc = c2.green());
  809. bDiff = ( c1.blue()) - (bc = c2.blue());
  810. }
  811. register int rl = rc << 16;
  812. register int gl = gc << 16;
  813. register int bl = bc << 16;
  814. int rdelta = ((1<<16) / (horizontal ? r_h : r_w)) * rDiff;
  815. int gdelta = ((1<<16) / (horizontal ? r_h : r_w)) * gDiff;
  816. int bdelta = ((1<<16) / (horizontal ? r_h : r_w)) * bDiff;
  817. // these for-loops could be merged, but the if's in the inner loop
  818. // would make it slow
  819. if(horizontal) {
  820. for ( y = 0; y < r_h; y++ ) {
  821. rl += rdelta;
  822. gl += gdelta;
  823. bl += bdelta;
  824. p.setPen(TQColor(rl>>16, gl>>16, bl>>16));
  825. p.drawLine(r_x, r_y+y, r_x2, r_y+y);
  826. }
  827. } else {
  828. for( x = 0; x < r_w; x++) {
  829. rl += rdelta;
  830. gl += gdelta;
  831. bl += bdelta;
  832. p.setPen(TQColor(rl>>16, gl>>16, bl>>16));
  833. p.drawLine(r_x+x, r_y, r_x+x, r_y2);
  834. }
  835. }
  836. p.end();
  837. // draw the result...
  838. painter->drawTiledPixmap(rect, *result);
  839. // insert into cache using the previously created key.
  840. CacheEntry *toAdd = new CacheEntry(search);
  841. toAdd->pixmap = result;
  842. bool insertOk = pixmapCache->insert( key, toAdd, result->width()*result->height()*result->depth()/8 );
  843. if(!insertOk)
  844. delete result;
  845. }
  846. void LipstikStyle::renderPanel(TQPainter *p,
  847. const TQRect &r,
  848. const TQColorGroup &g,
  849. const bool pseudo3d,
  850. const bool sunken) const
  851. {
  852. int x, x2, y, y2, w, h;
  853. r.rect(&x,&y,&w,&h);
  854. r.coords(&x, &y, &x2, &y2);
  855. if (kickerMode &&
  856. p->device() && p->device()->devType() == TQInternal::Widget &&
  857. TQCString(TQT_TQWIDGET(static_cast<QWidget*>(p->device()))->className()) == "FittsLawFrame") {
  858. // Stolen wholesale from Keramik. I don't like it, but oh well.
  859. if (sunken) {
  860. const TQCOORD corners[] = { x2, y, x2, y2, x, y2, x, y };
  861. p->setPen(g.mid());
  862. p->drawConvexPolygon(TQPointArray(4, corners));
  863. p->setPen(g.mid());
  864. p->tqdrawPolyline(TQPointArray(4, corners), 0, 3);
  865. } else {
  866. const TQCOORD corners[] = { x, y2, x, y, x2, y, x2, y2 };
  867. p->setPen(g.background().dark());
  868. p->drawPolygon(TQPointArray(4, corners));
  869. p->setPen(g.background().light());
  870. p->tqdrawPolyline(TQPointArray(4, corners), 0, 3);
  871. }
  872. } else {
  873. renderContour(p, r, g.background(), getColor(g, PanelContour) );
  874. if(pseudo3d) {
  875. if (sunken) {
  876. p->setPen(getColor(g, PanelDark) );
  877. } else {
  878. p->setPen(getColor(g, PanelLight) );
  879. }
  880. p->drawLine(r.left()+2, r.top()+1, r.right()-2, r.top()+1);
  881. p->drawLine(r.left()+1, r.top()+2, r.left()+1, r.bottom()-2);
  882. if (sunken) {
  883. p->setPen(getColor(g, PanelLight) );
  884. } else {
  885. p->setPen(getColor(g, PanelDark) );
  886. }
  887. p->drawLine(r.left()+2, r.bottom()-1, r.right()-2, r.bottom()-1);
  888. p->drawLine(r.right()-1, r.top()+2, r.right()-1, r.bottom()-2);
  889. }
  890. }
  891. }
  892. void LipstikStyle::renderMenuBlendPixmap( KPixmap &pix, const TQColorGroup &cg,
  893. const TQPopupMenu* /* popup */ ) const
  894. {
  895. pix.fill( cg.background().light(105) );
  896. }
  897. void LipstikStyle::renderTab(TQPainter *p,
  898. const TQRect &r,
  899. const TQColorGroup &g,
  900. bool mouseOver,
  901. const bool selected,
  902. const bool bottom,
  903. const TabPosition pos,
  904. const bool triangular,
  905. const bool cornerWidget) const
  906. {
  907. const bool reverseLayout = TQApplication::reverseLayout();
  908. const bool isFirst = (pos == First) || (pos == Single);
  909. const bool isLast = (pos == Last);
  910. const bool isSingle = (pos == Single);
  911. if (selected) {
  912. // is selected
  913. // the top part of the tab which is nearly the same for all positions
  914. TQRect Rc; // contour
  915. if (!bottom) {
  916. if (isFirst && !cornerWidget && !reverseLayout) {
  917. Rc = TQRect(r.x(), r.y(), r.width()-1, r.height()-3);
  918. } else if (isFirst && !cornerWidget && reverseLayout) {
  919. Rc = TQRect(r.x()+1, r.y(), r.width()-1, r.height()-3);
  920. } else {
  921. Rc = TQRect(r.x()+1, r.y(), r.width()-2, r.height()-3);
  922. }
  923. } else {
  924. if (isFirst && !cornerWidget && !reverseLayout) {
  925. Rc = TQRect(r.x(), r.y()+3, r.width()-1, r.height()-3);
  926. } else if (isFirst && !cornerWidget && reverseLayout) {
  927. Rc = TQRect(r.x()+1, r.y()+3, r.width()-1, r.height()-3);
  928. } else {
  929. Rc = TQRect(r.x()+1, r.y()+3, r.width()-2, r.height()-3);
  930. }
  931. }
  932. const TQRect Rs(Rc.x()+1, bottom?Rc.y():Rc.y()+1, Rc.width()-2, Rc.height()-1); // the resulting surface
  933. // the area where the fake border shoudl appear
  934. const TQRect Rb(r.x(), bottom?r.top():Rc.bottom()+1, r.width(), r.height()-Rc.height() );
  935. uint contourFlags = Draw_Left|Draw_Right;
  936. if(!bottom) {
  937. contourFlags |= Draw_Top|Round_UpperLeft|Round_UpperRight;
  938. } else {
  939. contourFlags |= Draw_Bottom|Round_BottomLeft|Round_BottomRight;
  940. }
  941. renderContour(p, Rc,
  942. g.background(), getColor(g,PanelContour),
  943. contourFlags);
  944. // surface
  945. if(!bottom) {
  946. p->setPen(getColor(g,PanelLight) );
  947. p->drawLine(Rs.x()+1, Rs.y(), Rs.right()-1, Rs.y() );
  948. renderGradient(p, TQRect(Rs.x(), Rs.y()+1, 1, Rs.height()-1),
  949. getColor(g,PanelLight), getColor(g,PanelLight2));
  950. renderGradient(p, TQRect(Rs.right(), Rs.y()+1, 1, Rs.height()-1),
  951. getColor(g,PanelDark), getColor(g,PanelDark2));
  952. if(_drawTabHighlight) {
  953. if(_customTabHighlightColor) {
  954. p->setPen( alphaBlendColors(getColor(g,TabHighlight), getColor(g,PanelLight), 180) );
  955. p->drawLine( Rs.x()+1, Rs.y(), Rs.right()-1, Rs.y() );
  956. p->setPen( alphaBlendColors(getColor(g,TabHighlight), getColor(g,PanelLight), 110) );
  957. p->drawLine( Rs.x(), Rs.y()+1, Rs.right(), Rs.y()+1 );
  958. } else {
  959. p->setPen( alphaBlendColors(g.highlight(), getColor(g,PanelLight), 180) );
  960. p->drawLine( Rs.x()+1, Rs.y(), Rs.right()-1, Rs.y() );
  961. p->setPen( alphaBlendColors(g.highlight(), getColor(g,PanelLight), 110) );
  962. p->drawLine( Rs.x(), Rs.y()+1, Rs.right(), Rs.y()+1 );
  963. }
  964. }
  965. } else {
  966. p->setPen(alphaBlendColors(g.background(), g.background().dark(160), 100) );
  967. p->drawLine(Rs.x()+1, Rs.bottom(), Rs.right()-1, Rs.bottom() );
  968. renderGradient(p, TQRect(Rs.x(), Rs.y(), 1, Rs.height()-1),
  969. getColor(g,PanelLight), getColor(g,PanelLight2));
  970. renderGradient(p, TQRect(Rs.right(), Rs.y(), 1, Rs.height()-1),
  971. getColor(g,PanelDark), getColor(g,PanelDark2));
  972. if(_drawTabHighlight) {
  973. p->setPen( alphaBlendColors(g.highlight(), getColor(g,PanelLight), 180) );
  974. //p->setPen(getColor(g,MouseOverHighlight) );
  975. p->drawLine( Rs.x()+1, Rs.bottom(), Rs.right()-1, Rs.bottom() );
  976. p->setPen( alphaBlendColors(g.highlight(), getColor(g,PanelLight), 110) );
  977. p->drawLine( Rs.x(), Rs.bottom()-1, Rs.right(), Rs.bottom()-1 );
  978. }
  979. }
  980. // some "position specific" paintings...
  981. // draw parts of the inactive tabs around...
  982. if(!isSingle) {
  983. p->setPen(alphaBlendColors(g.background(), getColor(g, ButtonContour), 50) );
  984. if( (!isFirst&&!reverseLayout) || (!isLast&&reverseLayout) ) {
  985. p->drawPoint(r.left(), bottom?(triangular?r.bottom()-2:r.bottom()-3):(triangular?r.top()+2:r.top()+3) );
  986. renderSurface(p, TQRect(r.left(), bottom?r.top()+3:(triangular?r.top()+3:r.top()+4), 1, (triangular?r.height()-6:r.height()-7) ),
  987. g.background(), g.button(), getColor(g,MouseOverHighlight), _contrast,
  988. Draw_Top|Draw_Bottom|Is_Horizontal);
  989. }
  990. if( (!isLast&&!reverseLayout) || (!isFirst&&reverseLayout) ) {
  991. p->drawPoint(r.right(), bottom?(triangular?r.bottom()-2:r.bottom()-3):(triangular?r.top()+2:r.top()+3) );
  992. renderSurface(p, TQRect(r.right(), bottom?r.top()+3:(triangular?r.top()+3:r.top()+4), 1, (triangular?r.height()-6:r.height()-7) ),
  993. g.background(), g.button(), getColor(g,MouseOverHighlight), _contrast,
  994. Draw_Top|Draw_Bottom|Is_Horizontal);
  995. }
  996. }
  997. // left connection from the panel border to the tab. :)
  998. if(isFirst && !reverseLayout && !cornerWidget) {
  999. p->setPen(alphaBlendColors(g.background(), getColor(g,PanelContour), 50) );
  1000. p->drawLine(Rb.x(), Rb.y(), Rb.x(), Rb.bottom() );
  1001. p->setPen(getColor(g,PanelLight) );
  1002. p->drawLine(Rb.x()+1, Rb.y(), Rb.x()+1, Rb.bottom() );
  1003. } else if(isFirst && reverseLayout && !cornerWidget) {
  1004. p->setPen(alphaBlendColors(g.background(), getColor(g,PanelContour), 50) );
  1005. p->drawLine(Rb.right(), Rb.y(), Rb.right(), Rb.bottom() );
  1006. p->setPen(getColor(g,PanelDark) );
  1007. p->drawLine(Rb.right()-1, Rb.y(), Rb.right()-1, Rb.bottom() );
  1008. }
  1009. // rounded connections to the panel...
  1010. if(!bottom) {
  1011. // left
  1012. if( (!isFirst && !reverseLayout) || (reverseLayout) || (isFirst && !reverseLayout && cornerWidget) ) {
  1013. p->setPen( alphaBlendColors(g.background(), getColor(g,PanelContour), 50) );
  1014. p->drawPoint(Rb.x(), Rb.y());
  1015. p->setPen( alphaBlendColors(g.background(), getColor(g,PanelContour), 150) );
  1016. p->drawPoint(Rb.x(), Rb.y()+1);
  1017. p->drawPoint(Rb.x()+1, Rb.y());
  1018. }
  1019. // right
  1020. if( (!reverseLayout) || (!isFirst && reverseLayout) || (isFirst && reverseLayout && cornerWidget) ) {
  1021. p->setPen( alphaBlendColors(g.background(), getColor(g,PanelContour), 50) );
  1022. p->drawPoint(Rb.right(), Rb.y());
  1023. p->setPen( alphaBlendColors(g.background(), getColor(g,PanelContour), 150) );
  1024. p->drawPoint(Rb.right(), Rb.y()+1);
  1025. p->drawPoint(Rb.right()-1, Rb.y());
  1026. }
  1027. } else {
  1028. // left
  1029. if( (!isFirst && !reverseLayout) || (reverseLayout) || (isFirst && !reverseLayout && cornerWidget) ) {
  1030. p->setPen( alphaBlendColors(g.background(), getColor(g,PanelContour), 50) );
  1031. p->drawPoint(Rb.x(), Rb.bottom());
  1032. p->setPen( alphaBlendColors(g.background(), getColor(g,PanelContour), 150) );
  1033. p->drawPoint(Rb.x(), Rb.bottom()-1);
  1034. p->drawPoint(Rb.x()+1, Rb.bottom());
  1035. }
  1036. // right
  1037. if( (!reverseLayout) || (!isFirst && reverseLayout) || (isFirst && reverseLayout && cornerWidget) ) {
  1038. p->setPen( alphaBlendColors(g.background(), getColor(g,PanelContour), 50) );
  1039. p->drawPoint(Rb.right(), Rb.bottom());
  1040. p->setPen( alphaBlendColors(g.background(), getColor(g,PanelContour), 150) );
  1041. p->drawPoint(Rb.right(), Rb.bottom()-1);
  1042. p->drawPoint(Rb.right()-1, Rb.bottom());
  1043. }
  1044. }
  1045. } else {
  1046. // inactive tabs
  1047. // the top part of the tab which is nearly the same for all positions
  1048. TQRect Rc; // contour
  1049. if (isFirst&&reverseLayout ) {
  1050. Rc = TQRect(r.x()+1, (bottom?r.y()+2:(triangular?r.y()+2:r.y()+3)), r.width()-2, (triangular?r.height()-4:r.height()-5) );
  1051. } else {
  1052. Rc = TQRect(r.x()+1, (bottom?r.y()+2:(triangular?r.y()+2:r.y()+3)), r.width()-1, (triangular?r.height()-4:r.height()-5) );
  1053. }
  1054. TQRect Rs; // the resulting surface
  1055. if ( (isFirst&&!reverseLayout) || (isLast&&reverseLayout) ) {
  1056. Rs = TQRect(Rc.x()+1, bottom?Rc.y():Rc.y()+1, Rc.width()-2, Rc.height()-1);
  1057. } else {
  1058. Rs = TQRect(Rc.x(), bottom?Rc.y():Rc.y()+1, Rc.width()-1, Rc.height()-1);
  1059. }
  1060. // the area where the fake border shoudl appear
  1061. const TQRect Rb(r.x(), bottom?r.y():Rc.bottom()+1, r.width(), 2 );
  1062. uint contourFlags;
  1063. if(!bottom) {
  1064. if ( (isFirst&&!reverseLayout) || (isLast&&reverseLayout) ) {
  1065. contourFlags = Draw_Left|Draw_Right|Draw_Top|Round_UpperLeft;
  1066. } else if ( (isLast&&!reverseLayout) || (isFirst&&reverseLayout) ) {
  1067. contourFlags = Draw_Right|Draw_Top|Round_UpperRight;
  1068. } else {
  1069. contourFlags = Draw_Right|Draw_Top;
  1070. }
  1071. } else {
  1072. if ( (isFirst&&!reverseLayout) || (isLast&&reverseLayout) ) {
  1073. contourFlags = Draw_Left|Draw_Right|Draw_Bottom|Round_BottomLeft;
  1074. } else if ( (isLast&&!reverseLayout) || (isFirst&&reverseLayout) ) {
  1075. contourFlags = Draw_Right|Draw_Bottom|Round_BottomRight;
  1076. } else {
  1077. contourFlags = Draw_Right|Draw_Bottom;
  1078. }
  1079. }
  1080. renderContour(p, Rc,
  1081. g.background(), getColor(g, ButtonContour),
  1082. contourFlags);
  1083. uint surfaceFlags = Is_Horizontal;
  1084. if(mouseOver) {
  1085. surfaceFlags |= (bottom?Highlight_Bottom:Highlight_Top);
  1086. surfaceFlags |= Is_Highlight;
  1087. }
  1088. if ( (isFirst&&!reverseLayout) || (isLast&&reverseLayout) ) {
  1089. if(!bottom)
  1090. surfaceFlags |= Draw_Left|Draw_Top|Draw_Bottom|Round_UpperLeft;
  1091. else
  1092. surfaceFlags |= Draw_Left|Draw_Top|Draw_Bottom|Round_BottomLeft;
  1093. } else if ( (isLast&&!reverseLayout) || (isFirst&&reverseLayout) ) {
  1094. if(!bottom)
  1095. surfaceFlags |= Draw_Right|Draw_Top|Draw_Bottom|Round_UpperRight;
  1096. else
  1097. surfaceFlags |= Draw_Right|Draw_Top|Draw_Bottom|Round_BottomRight;
  1098. } else {
  1099. surfaceFlags |= Draw_Top|Draw_Bottom;
  1100. }
  1101. renderSurface(p, Rs,
  1102. g.background(), g.button(), getColor(g,MouseOverHighlight), _contrast,
  1103. surfaceFlags);
  1104. // some "position specific" paintings...
  1105. // fake parts of the panel border
  1106. if(!bottom) {
  1107. p->setPen(alphaBlendColors(g.background(), getColor(g,PanelContour), 50) );
  1108. p->drawLine(Rb.x(), Rb.y(), ((isLast&&!reverseLayout)||(isFirst&&reverseLayout&&cornerWidget))?Rb.right():Rb.right()-1, Rb.y());
  1109. p->setPen(getColor(g,PanelLight) );
  1110. p->drawLine(Rb.x(), Rb.y()+1, ((isLast&&!reverseLayout)||(isFirst&&reverseLayout&&cornerWidget))?Rb.right():Rb.right()-1, Rb.y()+1 );
  1111. } else {
  1112. p->setPen(alphaBlendColors(g.background(), getColor(g,PanelContour), 50) );
  1113. p->drawLine(Rb.x(), Rb.bottom(), ((isLast&&!reverseLayout)||(isFirst&&reverseLayout&&cornerWidget))?Rb.right():Rb.right()-1, Rb.bottom());
  1114. p->setPen(getColor(g,PanelDark) );
  1115. p->drawLine(Rb.x(), Rb.bottom()-1, ((isLast&&!reverseLayout)||(isFirst&&reverseLayout&&cornerWidget))?Rb.right():Rb.right()-1, Rb.bottom()-1 );
  1116. }
  1117. // fake the panel border edge for tabs which are aligned left-most
  1118. // (i.e. only if there is no widget in the corner of the tabwidget!)
  1119. if(isFirst&&!reverseLayout&&!cornerWidget)
  1120. // normal tqlayout
  1121. {
  1122. if (!bottom) {
  1123. p->setPen(alphaBlendColors(g.background(), getColor(g,PanelContour), 50) );
  1124. p->drawPoint(Rb.x()+1, Rb.y()+1 );
  1125. p->setPen(alphaBlendColors(g.background(), getColor(g,PanelContour), 150) );
  1126. p->drawPoint(Rb.x(), Rb.y()+1 );
  1127. p->setPen(g.background() );
  1128. p->drawPoint(Rb.x(), Rb.y() );
  1129. p->setPen(alphaBlendColors( alphaBlendColors(g.background(), getColor(g, ButtonContour), 50), getColor(g,PanelContour), 150) );
  1130. p->drawPoint(Rb.x()+1, Rb.y() );
  1131. } else {
  1132. p->setPen(alphaBlendColors(g.background(), getColor(g,PanelContour), 50) );
  1133. p->drawPoint(Rb.x()+1, Rb.bottom()-1 );
  1134. p->setPen(alphaBlendColors(g.background(), getColor(g,PanelContour), 150) );
  1135. p->drawPoint(Rb.x(), Rb.bottom()-1 );
  1136. p->setPen(g.background() );
  1137. p->drawPoint(Rb.x(), Rb.bottom() );
  1138. p->setPen(alphaBlendColors( alphaBlendColors(g.background(), getColor(g, ButtonContour), 50), getColor(g,PanelContour), 150) );
  1139. p->drawPoint(Rb.x()+1, Rb.bottom() );
  1140. }
  1141. } else if(isFirst&&reverseLayout&&!cornerWidget)
  1142. // reverse tqlayout
  1143. {
  1144. if (!bottom) {
  1145. p->setPen(alphaBlendColors(g.background(), getColor(g,PanelContour), 50) );
  1146. p->drawPoint(Rb.right()-1, Rb.y()+1 );
  1147. p->setPen(alphaBlendColors(g.background(), getColor(g,PanelContour), 150) );
  1148. p->drawPoint(Rb.right(), Rb.y()+1 );
  1149. p->setPen(g.background() );
  1150. p->drawPoint(Rb.right(), Rb.y() );
  1151. p->setPen(alphaBlendColors( alphaBlendColors(g.background(), getColor(g, ButtonContour), 50), getColor(g,PanelContour), 150) );
  1152. p->drawPoint(Rb.right()-1, Rb.y() );
  1153. } else {
  1154. p->setPen(alphaBlendColors(g.background(), getColor(g,PanelContour), 50) );
  1155. p->drawPoint(Rb.right()-1, Rb.bottom()-1 );
  1156. p->setPen(alphaBlendColors(g.background(), getColor(g,PanelContour), 150) );
  1157. p->drawPoint(Rb.right(), Rb.bottom()-1 );
  1158. p->setPen(g.background() );
  1159. p->drawPoint(Rb.right(), Rb.bottom() );
  1160. p->setPen(alphaBlendColors( alphaBlendColors(g.background(), getColor(g, ButtonContour), 50), getColor(g,PanelContour), 150) );
  1161. p->drawPoint(Rb.right()-1, Rb.bottom() );
  1162. }
  1163. }
  1164. }
  1165. }
  1166. void LipstikStyle::drawKStylePrimitive(KStylePrimitive kpe,
  1167. TQPainter *p,
  1168. const TQWidget* widget,
  1169. const TQRect &r,
  1170. const TQColorGroup &cg,
  1171. SFlags flags,
  1172. const TQStyleOption& opt) const
  1173. {
  1174. // some "global" vars...
  1175. const bool enabled = (flags & Style_Enabled);
  1176. // SLIDER
  1177. // ------
  1178. switch( kpe ) {
  1179. case KPE_SliderGroove: {
  1180. const TQSlider* slider = (const TQSlider*)widget;
  1181. bool horizontal = slider->orientation() ==Qt::Horizontal;
  1182. if (horizontal) {
  1183. int center = r.y()+r.height()/2;
  1184. renderContour(p, TQRect(r.left(), center-2, r.width(), 4),
  1185. cg.background(), cg.background().dark(enabled?150:130),
  1186. Draw_Left|Draw_Right|Draw_Top|Draw_Bottom);
  1187. } else {
  1188. int center = r.x()+r.width()/2;
  1189. renderContour(p, TQRect(center-2, r.top(), 4, r.height()),
  1190. cg.background(), cg.background().dark(enabled?150:130),
  1191. Draw_Left|Draw_Right|Draw_Top|Draw_Bottom);
  1192. }
  1193. break;
  1194. }
  1195. case KPE_SliderHandle: {
  1196. const TQSlider* slider = (const TQSlider*)widget;
  1197. bool horizontal = slider->orientation() ==Qt::Horizontal;
  1198. const bool pressed = (flags&Style_Active);
  1199. const WidgetState s = enabled?(pressed?IsPressed:IsEnabled):IsDisabled;
  1200. const TQColor contour = getColor(cg,DragButtonContour,s),
  1201. surface = getColor(cg,DragButtonSurface,s);
  1202. int xcenter = (r.left()+r.right()) / 2;
  1203. int ycenter = (r.top()+r.bottom()) / 2;
  1204. if (_sliderStyle == "sliderLipstikStyle") {
  1205. if (horizontal) {
  1206. renderContour(p, TQRect(xcenter-9, ycenter-7, 20, 15), cg.background(), contour,
  1207. Draw_Left|Draw_Right|Draw_Top|Round_UpperLeft|Round_UpperRight|
  1208. Draw_Bottom|Round_BottomLeft|Round_BottomRight);
  1209. TQRegion mask(xcenter-8, ycenter-6, 18, 13);
  1210. p->setClipRegion(mask);
  1211. uint surfaceFlags = Draw_Left|Draw_Right|Draw_Top|Round_UpperLeft|Round_UpperRight|
  1212. Is_Horizontal;
  1213. if(!enabled)
  1214. surfaceFlags |= Is_Disabled;
  1215. else if(hoverWidget == widget) {
  1216. surfaceFlags |= Highlight_Right|Highlight_Left;
  1217. }
  1218. renderSurface(p, TQRect(xcenter-8, ycenter-6, 18, 13),
  1219. cg.background(), surface, getColor(cg,MouseOverHighlight),
  1220. _contrast+3, surfaceFlags);
  1221. renderDot(p, TQPoint(xcenter-2, ycenter), surface, true, true );
  1222. renderDot(p, TQPoint(xcenter+2, ycenter), surface, true, true );
  1223. p->setClipping(false);
  1224. } else {
  1225. renderContour(p, TQRect(xcenter-7, ycenter-9, 16, 20), cg.background(), contour,
  1226. Draw_Left|Draw_Right|Draw_Top|Round_UpperLeft|Round_UpperRight|
  1227. Draw_Bottom|Round_BottomLeft|Round_BottomRight);
  1228. TQRegion mask(xcenter-6, ycenter-8, 13, 18);
  1229. p->setClipRegion(mask);
  1230. uint surfaceFlags = Draw_Left|Draw_Top|Draw_Bottom|Round_UpperLeft|Round_BottomLeft|
  1231. Round_UpperRight|Is_Horizontal;
  1232. if(!enabled)
  1233. surfaceFlags |= Is_Disabled;
  1234. else if(hoverWidget == widget)
  1235. surfaceFlags |= Highlight_Top|Highlight_Bottom;
  1236. renderSurface(p, TQRect(xcenter-6, ycenter-8, 13, 18),
  1237. cg.background(), surface, getColor(cg,MouseOverHighlight),
  1238. _contrast+3, surfaceFlags);
  1239. renderDot(p, TQPoint(xcenter, ycenter-2), surface, true, true );
  1240. renderDot(p, TQPoint(xcenter, ycenter+2), surface, true, true );
  1241. p->setClipping(false);
  1242. }
  1243. } else if (_sliderStyle == "sliderPlastikStyle") {
  1244. if (horizontal) {
  1245. renderContour(p, TQRect(xcenter-5, ycenter-6, 11, 10),
  1246. cg.background(), contour,
  1247. Draw_Left|Draw_Right|Draw_Top|Round_UpperLeft|Round_UpperRight);
  1248. // manual contour: vertex
  1249. p->setPen(alphaBlendColors(cg.background(), contour, 50) );
  1250. p->drawPoint(xcenter-5+1, ycenter+4);
  1251. p->drawPoint(xcenter+5-1, ycenter+4);
  1252. p->drawPoint(xcenter-5+2, ycenter+5);
  1253. p->drawPoint(xcenter+5-2, ycenter+5);
  1254. p->drawPoint(xcenter-5+3, ycenter+6);
  1255. p->drawPoint(xcenter+5-3, ycenter+6);
  1256. p->drawPoint(xcenter-5+4, ycenter+7);
  1257. p->drawPoint(xcenter+5-4, ycenter+7);
  1258. // anti-aliasing of the contour... sort of. :)
  1259. p->setPen(alphaBlendColors(cg.background(), contour, 80) );
  1260. p->drawPoint(xcenter, ycenter+8);
  1261. p->setPen(alphaBlendColors(cg.background(), contour, 150) );
  1262. p->drawPoint(xcenter-5, ycenter+4);
  1263. p->drawPoint(xcenter+5, ycenter+4);
  1264. p->drawPoint(xcenter-5+1, ycenter+5);
  1265. p->drawPoint(xcenter+5-1, ycenter+5);
  1266. p->drawPoint(xcenter-5+2, ycenter+6);
  1267. p->drawPoint(xcenter+5-2, ycenter+6);
  1268. p->drawPoint(xcenter-5+3, ycenter+7);
  1269. p->drawPoint(xcenter+5-3, ycenter+7);
  1270. p->setPen(alphaBlendColors(cg.background(), contour, 190) );
  1271. p->drawPoint(xcenter-5+4, ycenter+8);
  1272. p->drawPoint(xcenter+5-4, ycenter+8);
  1273. TQRegion mask(xcenter-4, ycenter-5, 9, 13);
  1274. mask -= TQRegion(xcenter-4, ycenter+4, 1, 4);
  1275. mask -= TQRegion(xcenter-3, ycenter+5, 1, 3);
  1276. mask -= TQRegion(xcenter-2, ycenter+6, 1, 2);
  1277. mask -= TQRegion(xcenter-1, ycenter+7, 1, 1);
  1278. mask -= TQRegion(xcenter+1, ycenter+7, 1, 1);
  1279. mask -= TQRegion(xcenter+2, ycenter+6, 1, 2);
  1280. mask -= TQRegion(xcenter+3, ycenter+5, 1, 3);
  1281. mask -= TQRegion(xcenter+4, ycenter+4, 1, 4);
  1282. p->setClipRegion(mask);
  1283. uint surfaceFlags = Draw_Left|Draw_Right|Draw_Top|Round_UpperLeft|Round_UpperRight|Is_Horizontal;
  1284. if(!enabled)
  1285. surfaceFlags |= Is_Disabled;
  1286. renderSurface(p, TQRect(xcenter-4, ycenter-5, 9, 13),
  1287. cg.background(), surface, getColor(cg,MouseOverHighlight),
  1288. _contrast+3, surfaceFlags);
  1289. renderDot(p, TQPoint(xcenter-3, ycenter-3), surface, false, true );
  1290. renderDot(p, TQPoint(xcenter+2, ycenter-3), surface, false, true );
  1291. p->setClipping(false);
  1292. } else {
  1293. renderContour(p, TQRect(xcenter-6, ycenter-5, 10, 11),
  1294. cg.background(), contour,
  1295. Draw_Left|Draw_Top|Draw_Bottom|Round_UpperLeft|Round_BottomLeft);
  1296. // manual contour: vertex
  1297. p->setPen(alphaBlendColors(cg.background(), contour, 50) );
  1298. p->drawPoint(xcenter+4, ycenter-5+1);
  1299. p->drawPoint(xcenter+4, ycenter+5-1);
  1300. p->drawPoint(xcenter+5, ycenter-5+2);
  1301. p->drawPoint(xcenter+5, ycenter+5-2);
  1302. p->drawPoint(xcenter+6, ycenter-5+3);
  1303. p->drawPoint(xcenter+6, ycenter+5-3);
  1304. p->drawPoint(xcenter+7, ycenter-5+4);
  1305. p->drawPoint(xcenter+7, ycenter+5-4);
  1306. // anti-aliasing. ...sort of :)
  1307. p->setPen(alphaBlendColors(cg.background(), contour, 80) );
  1308. p->drawPoint(xcenter+8, ycenter);
  1309. p->setPen(alphaBlendColors(cg.background(), contour, 150) );
  1310. p->drawPoint(xcenter+4, ycenter-5);
  1311. p->drawPoint(xcenter+4, ycenter+5);
  1312. p->drawPoint(xcenter+5, ycenter-5+1);
  1313. p->drawPoint(xcenter+5, ycenter+5-1);
  1314. p->drawPoint(xcenter+6, ycenter-5+2);
  1315. p->drawPoint(xcenter+6, ycenter+5-2);
  1316. p->drawPoint(xcenter+7, ycenter-5+3);
  1317. p->drawPoint(xcenter+7, ycenter+5-3);
  1318. p->setPen(alphaBlendColors(cg.background(), contour, 190) );
  1319. p->drawPoint(xcenter+8, ycenter-5+4);
  1320. p->drawPoint(xcenter+8, ycenter+5-4);
  1321. TQRegion mask(xcenter-5, ycenter-4, 13, 9);
  1322. mask -= TQRegion(xcenter+4, ycenter-4, 4, 1);
  1323. mask -= TQRegion(xcenter+5, ycenter-3, 3, 1);
  1324. mask -= TQRegion(xcenter+6, ycenter-2, 2, 1);
  1325. mask -= TQRegion(xcenter+7, ycenter-1, 1, 1);
  1326. mask -= TQRegion(xcenter+7, ycenter+1, 1, 1);
  1327. mask -= TQRegion(xcenter+6, ycenter+2, 2, 1);
  1328. mask -= TQRegion(xcenter+5, ycenter+3, 3, 1);
  1329. mask -= TQRegion(xcenter+4, ycenter+4, 4, 1);
  1330. p->setClipRegion(mask);
  1331. uint surfaceFlags = Draw_Left|Draw_Top|Draw_Bottom|Round_UpperLeft|Round_BottomLeft|
  1332. Round_UpperRight|Is_Horizontal;
  1333. if(!enabled)
  1334. surfaceFlags |= Is_Disabled;
  1335. renderSurface(p, TQRect(xcenter-5, ycenter-4, 13, 9),
  1336. cg.background(), surface, getColor(cg,MouseOverHighlight),
  1337. _contrast+3, surfaceFlags);
  1338. renderDot(p, TQPoint(xcenter-3, ycenter-3), surface, false, true );
  1339. renderDot(p, TQPoint(xcenter-3, ycenter+2), surface, false, true );
  1340. p->setClipping(false);
  1341. }
  1342. } else {
  1343. if (horizontal) {
  1344. renderContour(p, TQRect(xcenter-16, ycenter-7, 33, 15), cg.background(), contour,
  1345. Draw_Left|Draw_Right|Draw_Top|Round_UpperLeft|Round_UpperRight|
  1346. Draw_Bottom|Round_BottomLeft|Round_BottomRight);
  1347. TQRegion mask(xcenter-15, ycenter-6, 31, 13);
  1348. p->setClipRegion(mask);
  1349. uint surfaceFlags = Draw_Left|Draw_Right|Draw_Top|Round_UpperLeft|Round_UpperRight|
  1350. Is_Horizontal;
  1351. if(!enabled)
  1352. surfaceFlags |= Is_Disabled;
  1353. else if(hoverWidget == widget) {
  1354. surfaceFlags |= Highlight_Right|Highlight_Left;
  1355. }
  1356. renderSurface(p, TQRect(xcenter-15, ycenter-6, 31, 13),
  1357. cg.background(), surface, getColor(cg,MouseOverHighlight),
  1358. _contrast+3, surfaceFlags);
  1359. renderDot(p, TQPoint(xcenter-4, ycenter), surface, true, true );
  1360. renderDot(p, TQPoint(xcenter, ycenter), surface, true, true );
  1361. renderDot(p, TQPoint(xcenter+4, ycenter), surface, true, true );
  1362. p->setClipping(false);
  1363. } else {
  1364. renderContour(p, TQRect(xcenter-7, ycenter-16, 16, 33), cg.background(), contour,
  1365. Draw_Left|Draw_Right|Draw_Top|Round_UpperLeft|Round_UpperRight|Draw_Bottom|Round_BottomLeft|Round_BottomRight);
  1366. TQRegion mask(xcenter-6, ycenter-15, 13, 31);
  1367. p->setClipRegion(mask);
  1368. uint surfaceFlags = Draw_Left|Draw_Top|Draw_Bottom|Round_UpperLeft|Round_BottomLeft|
  1369. Round_UpperRight|Is_Horizontal;
  1370. if(!enabled)
  1371. surfaceFlags |= Is_Disabled;
  1372. else if(hoverWidget == widget)
  1373. surfaceFlags |= Highlight_Top|Highlight_Bottom;
  1374. renderSurface(p, TQRect(xcenter-6, ycenter-15, 13, 31),
  1375. cg.background(), surface, getColor(cg,MouseOverHighlight),
  1376. _contrast+3, surfaceFlags);
  1377. renderDot(p, TQPoint(xcenter, ycenter-4), surface, true, true );
  1378. renderDot(p, TQPoint(xcenter, ycenter), surface, true, true );
  1379. renderDot(p, TQPoint(xcenter, ycenter+4), surface, true, true );
  1380. p->setClipping(false);
  1381. }
  1382. }
  1383. break;
  1384. }
  1385. case KPE_ListViewExpander: {
  1386. int radius = (r.width() - 4) / 2;
  1387. int centerx = r.x() + r.width()/2;
  1388. int centery = r.y() + r.height()/2;
  1389. renderContour(p, r, cg.base(), cg.dark(), Draw_Left|Draw_Right|Draw_Top|Draw_Bottom|Round_UpperLeft|Round_UpperRight|Round_BottomLeft|Round_BottomRight );
  1390. p->setPen( cg.text() );
  1391. if(!_drawTriangularExpander)
  1392. {
  1393. // plus or minus
  1394. p->drawLine( centerx - radius, centery, centerx + radius, centery );
  1395. if ( flags & Style_On ) // Collapsed = On
  1396. p->drawLine( centerx, centery - radius, centerx, centery + radius );
  1397. } else if(_drawTriangularExpander) {
  1398. if( flags & Style_On )
  1399. tqdrawPrimitive(PE_ArrowRight, p, TQRect(r.x()+1,r.y()+1,r.width(),r.height()), cg,ButtonContour, flags);
  1400. if( flags & Style_Off )
  1401. tqdrawPrimitive(PE_ArrowDown, p, TQRect(r.x()+1,r.y()+1,r.width(),r.height()), cg,ButtonContour, flags);
  1402. }
  1403. break;
  1404. }
  1405. // copied and slightly modified from KStyle.
  1406. case KPE_ListViewBranch: {
  1407. // Typical Windows style listview branch element (dotted line).
  1408. // Create the dotline pixmaps if not already created
  1409. if ( !verticalLine )
  1410. {
  1411. // make 128*1 and 1*128 bitmaps that can be used for
  1412. // drawing the right sort of lines.
  1413. verticalLine = new TQBitmap( 1, 129, true );
  1414. horizontalLine = new TQBitmap( 128, 1, true );
  1415. TQPointArray a( 64 );
  1416. TQPainter p2;
  1417. p2.begin( verticalLine );
  1418. int i;
  1419. for( i=0; i < 64; i++ )
  1420. a.setPoint( i, 0, i*2+1 );
  1421. p2.setPen( color1 );
  1422. p2.drawPoints( a );
  1423. p2.end();
  1424. TQApplication::flushX();
  1425. verticalLine->setMask( *verticalLine );
  1426. p2.begin( horizontalLine );
  1427. for( i=0; i < 64; i++ )
  1428. a.setPoint( i, i*2+1, 0 );
  1429. p2.setPen( color1 );
  1430. p2.drawPoints( a );
  1431. p2.end();
  1432. TQApplication::flushX();
  1433. horizontalLine->setMask( *horizontalLine );
  1434. }
  1435. p->setPen( cg.mid() );
  1436. if (flags & Style_Horizontal)
  1437. {
  1438. int point = r.x();
  1439. int other = r.y();
  1440. int end = r.x()+r.width();
  1441. int thickness = r.height();
  1442. while( point < end )
  1443. {
  1444. int i = 128;
  1445. if ( i+point > end )
  1446. i = end-point;
  1447. p->drawPixmap( point, other, *horizontalLine, 0, 0, i, thickness );
  1448. point += i;
  1449. }
  1450. } else {
  1451. int point = r.y();
  1452. int other = r.x();
  1453. int end = r.y()+r.height();
  1454. int thickness = r.width();
  1455. int pixmapoffset = (flags & Style_NoChange) ? 0 : 1; // ### Hackish
  1456. while( point < end )
  1457. {
  1458. int i = 128;
  1459. if ( i+point > end )
  1460. i = end-point;
  1461. p->drawPixmap( other, point, *verticalLine, 0, pixmapoffset, thickness, i );
  1462. point += i;
  1463. }
  1464. }
  1465. break;
  1466. }
  1467. default:
  1468. KStyle::drawKStylePrimitive(kpe, p, widget, r, cg, flags, opt);
  1469. }
  1470. }
  1471. void LipstikStyle::tqdrawPrimitive(PrimitiveElement pe,
  1472. TQPainter *p,
  1473. const TQRect &r,
  1474. const TQColorGroup &cg,
  1475. SFlags flags,
  1476. const TQStyleOption &opt ) const
  1477. {
  1478. bool down = flags & Style_Down;
  1479. bool on = flags & Style_On;
  1480. bool sunken = flags & Style_Sunken;
  1481. bool horiz = flags & Style_Horizontal;
  1482. const bool enabled = flags & Style_Enabled;
  1483. const bool mouseOver = flags & Style_MouseOver;
  1484. bool hasFocus = flags & Style_HasFocus;
  1485. int x = r.x();
  1486. int y = r.y();
  1487. int w = r.width();
  1488. int h = r.height();
  1489. int x2, y2;
  1490. r.coords(&x, &y, &x2, &y2);
  1491. switch(pe) {
  1492. // BUTTONS
  1493. // -------
  1494. case PE_FocusRect: {
  1495. if(_drawFocusRect)
  1496. {
  1497. TQPen old = p->pen();
  1498. p->setPen( alphaBlendColors(cg.highlight(), getColor(cg,PanelLight), 120) );
  1499. p->drawRect( TQRect(r.topLeft(), r.bottomRight()));
  1500. p->setPen(old);
  1501. }
  1502. else
  1503. {
  1504. p->drawWinFocusRect( r );
  1505. }
  1506. break;
  1507. }
  1508. case PE_HeaderSectionMenu:
  1509. case PE_HeaderSection: {
  1510. // the taskbar buttons seems to be painted with PE_HeaderSection but I
  1511. // want them look like normal buttons (at least for now. :) )
  1512. if(!kickerMode) {
  1513. // Pat: Here I add another header painting method to
  1514. // optionnally give headers a "flat" look.
  1515. if(_flatHeaders) {
  1516. p->fillRect( r.left(), r.top(), r.width(), r.height(), cg.background() );
  1517. p->setPen( cg.background().dark(110) );
  1518. p->drawLine( r.left(), r.bottom(), r.right(), r.bottom() );
  1519. p->drawLine( r.right(), r.bottom(), r.right(), r.top() );
  1520. break;
  1521. } else {
  1522. // detect if this is the left most header item
  1523. bool isFirst = false;
  1524. TQHeader *header = dynamic_cast<TQHeader*>(p->device() );
  1525. if (header) {
  1526. isFirst = header->mapToIndex(header->sectionAt(r.x() ) ) == 0;
  1527. }
  1528. uint contourFlags = Draw_Right|Draw_Top|Draw_Bottom;
  1529. if (isFirst)
  1530. contourFlags |= Draw_Left;
  1531. if(!enabled) contourFlags|=Is_Disabled;
  1532. renderContour(p, r, cg.background(), getColor(cg,ButtonContour),
  1533. contourFlags);
  1534. uint surfaceFlags = Draw_Left|Draw_Right|Draw_Top|Draw_Bottom|Is_Horizontal;
  1535. if(!enabled) surfaceFlags|=Is_Disabled;
  1536. else {
  1537. if(on||down) surfaceFlags|=Is_Sunken;
  1538. else {
  1539. if(mouseOver) {
  1540. surfaceFlags|=Is_Highlight|Highlight_Top|Highlight_Bottom;
  1541. }
  1542. }
  1543. }
  1544. renderSurface(p, TQRect(isFirst?r.left()+1:r.left(), r.top()+1, isFirst?r.width()-2:r.width()-1, r.height()-2),
  1545. cg.background(), cg.button(), getColor(cg,MouseOverHighlight), _contrast,
  1546. surfaceFlags);
  1547. break;
  1548. }
  1549. }
  1550. }
  1551. case PE_ButtonBevel:
  1552. case PE_ButtonTool:
  1553. case PE_ButtonDropDown:
  1554. case PE_ButtonCommand: {
  1555. bool khtmlMode = opt.isDefault() ? false : khtmlWidgets.contains(opt.widget());
  1556. renderButton(p, r, cg, (on||down), mouseOver, true, enabled, khtmlMode );
  1557. break;
  1558. }
  1559. case PE_ButtonDefault: {
  1560. uint contourFlags = Draw_Left|Draw_Right|Draw_Top|Draw_Bottom|
  1561. Round_UpperLeft|Round_UpperRight|Round_BottomLeft|Round_BottomRight;
  1562. if(!enabled) contourFlags|=Is_Disabled;
  1563. renderContour(p, r, cg.background(), cg.highlight(), contourFlags);
  1564. break;
  1565. }
  1566. case PE_SpinWidgetPlus:
  1567. case PE_SpinWidgetMinus: {
  1568. p->setPen( cg.buttonText() );
  1569. int l = TQMIN( w-2, h-2 );
  1570. // make the length even so that we get a nice symmetric plus...
  1571. if(l%2 != 0)
  1572. --l;
  1573. TQPoint c = r.center();
  1574. p->drawLine( c.x()-l/2, c.y(), c.x()+l/2, c.y() );
  1575. if ( pe == PE_SpinWidgetPlus ) {
  1576. p->drawLine( c.x(), c.y()-l/2, c.x(), c.y()+l/2 );
  1577. }
  1578. break;
  1579. }
  1580. case PE_ScrollBarSlider: {
  1581. const WidgetState s = enabled?(down?IsPressed:IsEnabled):IsDisabled;
  1582. const TQColor surface = getColor(cg, DragButtonSurface, s);
  1583. bool scrollbarHighlighted = false;
  1584. uint contourFlags = Draw_Left|Draw_Right|Draw_Top|Draw_Bottom;
  1585. if(!enabled) contourFlags|=Is_Disabled;
  1586. renderContour(p, r, cg.background(), getColor(cg, DragButtonContour, s),
  1587. contourFlags);
  1588. uint surfaceFlags = Draw_Left|Draw_Right|Draw_Top|Draw_Bottom|Is_Horizontal;
  1589. if(hoverWidget == p->device())
  1590. {
  1591. scrollbarHighlighted = true;
  1592. if(horiz)
  1593. surfaceFlags |= Highlight_Right|Highlight_Left;
  1594. else
  1595. surfaceFlags |= Highlight_Top|Highlight_Bottom;
  1596. }
  1597. if(!enabled) surfaceFlags|=Is_Disabled;
  1598. if(r.height() >= 4)
  1599. renderSurface(p, TQRect(r.left()+1, r.top()+1, r.width()-2, r.height()-2),
  1600. cg.background(), surface, scrollbarHighlighted?cg.highlight():cg.background(),
  1601. _contrast+3, surfaceFlags);
  1602. //Now draw the dots.
  1603. p->setPen(alphaBlendColors(cg.background(), surface.dark(enabled?140:120), 50) );
  1604. int xPos = r.center().x();
  1605. int yPos = r.center().y();
  1606. if(horiz)
  1607. {
  1608. renderDot(p, TQPoint(xPos-6, yPos), surface, true, true );
  1609. renderDot(p, TQPoint(xPos-2, yPos), surface, true, true );
  1610. renderDot(p, TQPoint(xPos+2, yPos), surface, true, true );
  1611. renderDot(p, TQPoint(xPos+6, yPos), surface, true, true );
  1612. }
  1613. else
  1614. {
  1615. //--xPos;
  1616. renderDot(p, TQPoint(xPos, yPos-6), surface, true, true );
  1617. renderDot(p, TQPoint(xPos, yPos-2), surface, true, true );
  1618. renderDot(p, TQPoint(xPos, yPos+2), surface, true, true );
  1619. renderDot(p, TQPoint(xPos, yPos+6), surface, true, true );
  1620. }
  1621. break;
  1622. }
  1623. case PE_ScrollBarAddPage:
  1624. case PE_ScrollBarSubPage: {
  1625. // draw double buffered to avoid flicker...
  1626. TQPixmap buffer;
  1627. if(flags & Style_Horizontal) {
  1628. buffer.resize(2, r.height() );
  1629. } else {
  1630. buffer.resize(r.width(), 2 );
  1631. }
  1632. TQRect br(buffer.rect() );
  1633. TQPainter bp(&buffer);
  1634. if (on || down) {
  1635. bp.fillRect(br, TQBrush(cg.mid().dark()));
  1636. } else {
  1637. if(flags & Style_Horizontal) {
  1638. bp.setPen(cg.background().dark(106));
  1639. bp.drawLine(br.left(), br.top(), br.right(), br.top());
  1640. bp.setPen(cg.background().light(106));
  1641. bp.drawLine(br.left(), br.bottom(), br.right(), br.bottom());
  1642. bp.fillRect(br.left(), br.top()+1, br.width(), br.height()-2,cg.background());
  1643. } else {
  1644. bp.setPen(cg.background().dark(106));
  1645. bp.drawLine(br.left(), br.top(), br.left(), br.bottom());
  1646. bp.setPen(cg.background().light(106));
  1647. bp.drawLine(br.right(), br.top(), br.right(), br.bottom());
  1648. bp.fillRect(br.left()+1, br.top(), br.width()-2, br.height(),cg.background());
  1649. }
  1650. }
  1651. bp.fillRect(br, TQBrush(cg.background().light(), _paintGroove?Dense4Pattern:SolidPattern));
  1652. bp.end();
  1653. p->drawTiledPixmap(r, buffer, TQPoint(0, r.top()%2) );
  1654. break;
  1655. }
  1656. // SCROLLBAR BUTTONS
  1657. // -----------------
  1658. case PE_ScrollBarSubLine: {
  1659. uint contourFlags = Draw_Left|Draw_Right|Draw_Top|Draw_Bottom;
  1660. uint surfaceFlags = Draw_Left|Draw_Right|Draw_Top|Draw_Bottom;
  1661. if(down) surfaceFlags|=Is_Sunken;
  1662. if(!enabled) {
  1663. contourFlags|=Is_Disabled;
  1664. surfaceFlags|=Is_Disabled;
  1665. }
  1666. if(horiz) {
  1667. contourFlags |= Round_UpperLeft|Round_BottomLeft|Is_Horizontal;
  1668. surfaceFlags |= Round_UpperLeft|Round_BottomLeft|Is_Horizontal;
  1669. } else {
  1670. contourFlags |= Round_UpperLeft|Round_UpperRight|Is_Horizontal;
  1671. surfaceFlags |= Round_UpperLeft|Round_UpperRight|Is_Horizontal;
  1672. }
  1673. renderContour(p, r, cg.background(), getColor(cg, ButtonContour),
  1674. contourFlags);
  1675. renderSurface(p, TQRect(r.left()+1, r.top()+1, r.width()-2, r.height()-2),
  1676. cg.background(), cg.button(), getColor(cg,MouseOverHighlight), _contrast+3,
  1677. surfaceFlags);
  1678. p->setPen(cg.foreground());
  1679. tqdrawPrimitive((horiz ? PE_ArrowLeft : PE_ArrowUp), p, r, cg, flags);
  1680. break;
  1681. }
  1682. case PE_ScrollBarAddLine: {
  1683. uint contourFlags = Draw_Left|Draw_Right|Draw_Top|Draw_Bottom;
  1684. uint surfaceFlags = Draw_Left|Draw_Right|Draw_Top|Draw_Bottom;
  1685. if(down) surfaceFlags|=Is_Sunken;
  1686. if(!enabled) {
  1687. contourFlags|=Is_Disabled;
  1688. surfaceFlags|=Is_Disabled;
  1689. }
  1690. if(horiz) {
  1691. contourFlags |= Round_UpperRight|Round_BottomRight|Is_Horizontal;
  1692. surfaceFlags |= Round_UpperRight|Round_BottomRight|Is_Horizontal;
  1693. } else {
  1694. contourFlags |= Round_BottomLeft|Round_BottomRight|Is_Horizontal;
  1695. surfaceFlags |= Round_BottomLeft|Round_BottomRight|Is_Horizontal;
  1696. }
  1697. renderContour(p, r, cg.background(), getColor(cg, ButtonContour),
  1698. contourFlags);
  1699. renderSurface(p, TQRect(r.left()+1, r.top()+1, r.width()-2, r.height()-2),
  1700. cg.background(), cg.button(), getColor(cg,MouseOverHighlight), _contrast+3,
  1701. surfaceFlags);
  1702. p->setPen(cg.foreground());
  1703. tqdrawPrimitive((horiz ? PE_ArrowRight : PE_ArrowDown), p, r, cg, flags);
  1704. break;
  1705. }
  1706. // CHECKBOXES
  1707. // ----------
  1708. case PE_Indicator: {
  1709. TQColor contentColor = enabled?cg.base():cg.background();
  1710. uint contourFlags = Draw_Left|Draw_Right|Draw_Top|Draw_Bottom;
  1711. if(!enabled) {
  1712. contourFlags |= Is_Disabled;
  1713. }
  1714. renderContour(p, r, cg.background(), getColor(cg, ButtonContour),
  1715. contourFlags);
  1716. // surface
  1717. uint surfaceFlags = Draw_Left|Draw_Right|Draw_Top|Draw_Bottom|Is_Horizontal;
  1718. if(!enabled) {
  1719. surfaceFlags |= Is_Disabled;
  1720. } else if(mouseOver) {
  1721. contentColor = alphaBlendColors(contentColor, getColor(cg,MouseOverHighlight), 240);
  1722. surfaceFlags |= Is_Highlight;
  1723. surfaceFlags |= Highlight_Left|Highlight_Right|
  1724. Highlight_Top|Highlight_Bottom;
  1725. }
  1726. renderSurface(p, TQRect(r.x()+1, r.y()+1, r.width()-2, r.height()-2),
  1727. cg.background(), contentColor, getColor(cg,MouseOverHighlight), enabled?_contrast+3:(_contrast/2), surfaceFlags);
  1728. tqdrawPrimitive(PE_CheckMark, p, r, cg, flags);
  1729. break;
  1730. }
  1731. case PE_IndicatorMask: {
  1732. p->fillRect (r, color1);
  1733. break;
  1734. }
  1735. // RADIOBUTTONS
  1736. // ------------
  1737. case PE_ExclusiveIndicator: {
  1738. const TQColor contourColor = getColor(cg, ButtonContour, enabled);
  1739. TQColor contentColor = enabled?cg.base():cg.background();
  1740. TQBitmap bmp;
  1741. bmp = TQBitmap(13, 13, radiobutton_mask_bits, true);
  1742. // first the surface...
  1743. uint surfaceFlags = Draw_Left|Draw_Right|Draw_Top|Draw_Bottom|Is_Horizontal;
  1744. if(!enabled) {
  1745. surfaceFlags |= Is_Disabled;
  1746. } else if (mouseOver) {
  1747. contentColor = alphaBlendColors(contentColor, getColor(cg,MouseOverHighlight), 240);
  1748. }
  1749. p->setClipRegion(bmp);
  1750. renderSurface(p, r,
  1751. cg.background(), contentColor, getColor(cg,MouseOverHighlight), enabled?_contrast+3:(_contrast/2), surfaceFlags);
  1752. p->setClipping(false);
  1753. // ...then contour, anti-alias, mouseOver...
  1754. // contour
  1755. bmp = TQBitmap(13, 13, radiobutton_contour_bits, true);
  1756. bmp.setMask(bmp);
  1757. p->setPen(alphaBlendColors(cg.background(), contourColor, 50) );
  1758. p->drawPixmap(x, y, bmp);
  1759. // anti-alias outside
  1760. bmp = TQBitmap(13, 13, radiobutton_aa_outside_bits, true);
  1761. bmp.setMask(bmp);
  1762. p->setPen(alphaBlendColors(cg.background(), contourColor, 150) );
  1763. p->drawPixmap(x, y, bmp);
  1764. // highlighting...
  1765. if(mouseOver) {
  1766. bmp = TQBitmap(13, 13, radiobutton_highlight1_bits, true);
  1767. bmp.setMask(bmp);
  1768. p->setPen(alphaBlendColors(contentColor, getColor(cg,MouseOverHighlight), 80) );
  1769. p->drawPixmap(x, y, bmp);
  1770. bmp = TQBitmap(13, 13, radiobutton_highlight2_bits, true);
  1771. bmp.setMask(bmp);
  1772. p->setPen(alphaBlendColors(contentColor, getColor(cg,MouseOverHighlight), 150) );
  1773. p->drawPixmap(x, y, bmp);
  1774. }
  1775. // anti-alias inside, "above" the higlighting!
  1776. bmp = TQBitmap(13, 13, radiobutton_aa_inside_bits, true);
  1777. bmp.setMask(bmp);
  1778. if(mouseOver) {
  1779. p->setPen(alphaBlendColors(getColor(cg,MouseOverHighlight), contourColor, 180) );
  1780. } else {
  1781. p->setPen(alphaBlendColors(contentColor, contourColor, 180) );
  1782. }
  1783. p->drawPixmap(x, y, bmp);
  1784. TQColor checkmarkColor = enabled?getColor(cg,CheckMark):cg.background();
  1785. if(flags & Style_Down) {
  1786. checkmarkColor = alphaBlendColors(contentColor, checkmarkColor, 150);
  1787. }
  1788. // draw the radio mark
  1789. if (flags & Style_On || flags & Style_Down) {
  1790. bmp = TQBitmap(CHECKMARKSIZE, CHECKMARKSIZE, radiomark_dark_bits, true);
  1791. bmp.setMask(bmp);
  1792. p->setPen(alphaBlendColors(contentColor, checkmarkColor.dark(150), 50) );
  1793. p->drawPixmap(x+2, y+2, bmp);
  1794. bmp = TQBitmap(CHECKMARKSIZE, CHECKMARKSIZE, radiomark_light_bits, true);
  1795. bmp.setMask(bmp);
  1796. p->setPen(alphaBlendColors(contentColor, checkmarkColor.dark(125), 50) );
  1797. p->drawPixmap(x+2, y+2, bmp);
  1798. bmp = TQBitmap(CHECKMARKSIZE, CHECKMARKSIZE, radiomark_aa_bits, true);
  1799. bmp.setMask(bmp);
  1800. p->setPen(alphaBlendColors(contentColor, checkmarkColor.dark(150), 150) );
  1801. p->drawPixmap(x+2, y+2, bmp);
  1802. }
  1803. break;
  1804. }
  1805. case PE_ExclusiveIndicatorMask: {
  1806. p->fillRect(r, color0);
  1807. TQBitmap bmp;
  1808. bmp = TQBitmap(13, 13, radiobutton_mask_bits, true);
  1809. bmp.setMask(bmp);
  1810. p->setPen(color1);
  1811. p->drawPixmap(x, y, bmp);
  1812. break;
  1813. }
  1814. // GENERAL PANELS
  1815. // --------------
  1816. case PE_Splitter: {
  1817. // highlight on mouse over
  1818. TQColor color = (hoverWidget == p->device())?cg.highlight():cg.background();
  1819. //p->fillRect(r, color);
  1820. if (w > h) {
  1821. if (h > 4) {
  1822. int ycenter = r.height()/2;
  1823. for(int k = 2*r.width()/10; k < 8*r.width()/10; k+=5) {
  1824. renderDot(p, TQPoint(k, ycenter-1), color, false, true);
  1825. }
  1826. }
  1827. } else {
  1828. if (w > 4) {
  1829. int xcenter = r.width()/2;
  1830. for(int k = 2*r.height()/10; k < 8*r.height()/10; k+=5) {
  1831. renderDot(p, TQPoint(xcenter-1, k), color, false, true);
  1832. }
  1833. }
  1834. }
  1835. break;
  1836. }
  1837. case PE_PanelGroupBox:
  1838. case PE_GroupBoxFrame: {
  1839. if ( opt.isDefault() || opt.lineWidth() <= 0 )
  1840. break;
  1841. renderPanel(p, r, cg, false);
  1842. break;
  1843. }
  1844. case PE_WindowFrame:
  1845. case PE_Panel: {
  1846. if ( opt.isDefault() || opt.lineWidth() <= 0 )
  1847. break;
  1848. renderPanel(p, r, cg, true, sunken);
  1849. break;
  1850. }
  1851. case PE_PanelLineEdit: {
  1852. bool isReadOnly = false;
  1853. bool isEnabled = true;
  1854. // panel is highlighted by default if it has focus, but if we have access to the
  1855. // widget itself we can try to avoid highlighting in case it's readOnly or disabled.
  1856. if (p->device() && dynamic_cast<TQLineEdit*>(p->device()))
  1857. {
  1858. TQLineEdit* lineEdit = dynamic_cast<TQLineEdit*>(p->device());
  1859. isReadOnly = lineEdit->isReadOnly();
  1860. isEnabled = lineEdit->isEnabled();
  1861. }
  1862. uint contourFlags = Draw_Left|Draw_Right|Draw_Top|Draw_Bottom|
  1863. Round_UpperLeft|Round_UpperRight|Round_BottomLeft|Round_BottomRight;
  1864. // HACK!!
  1865. //
  1866. // In order to draw nice edges in khtml, we need to paint alpha-blended.
  1867. // On the other hand, we can't paint alpha-blended in normal widgets.
  1868. //
  1869. // In this place there is no reliable way to detect if we are in khtml; the
  1870. // only thing we know is that khtml buffers its widgets into a pixmap. So
  1871. // when the paint device is a TQPixmap, chances are high that we are in khtml.
  1872. // It's possible that this breaks other things, so let's see how it works...
  1873. if (p->device() && dynamic_cast<TQPixmap*>(p->device() ) ) {
  1874. contourFlags += Draw_AlphaBlend;
  1875. }
  1876. if ( _inputFocusHighlight && hasFocus && !isReadOnly && isEnabled)
  1877. {
  1878. renderContour(p, r, cg.background(),
  1879. getColor(cg,FocusHighlight,enabled), contourFlags );
  1880. }
  1881. else
  1882. {
  1883. renderContour(p, r, cg.background(),
  1884. getColor(cg, ButtonContour, enabled), contourFlags );
  1885. }
  1886. const TQColor contentColor = enabled?cg.base():cg.background();
  1887. if (_inputFocusHighlight && hasFocus && !isReadOnly && isEnabled)
  1888. {
  1889. p->setPen( getColor(cg,FocusHighlight).dark(130) );
  1890. }
  1891. else
  1892. {
  1893. p->setPen(contentColor.dark(130) );
  1894. }
  1895. p->drawLine(r.left()+1, r.top()+2, r.left()+1, r.bottom()-2 );
  1896. p->drawLine(r.left()+2, r.top()+1, r.right()-2, r.top()+1 );
  1897. if (_inputFocusHighlight && hasFocus && !isReadOnly && isEnabled)
  1898. {
  1899. p->setPen( getColor(cg,FocusHighlight).light(130) );
  1900. }
  1901. else
  1902. {
  1903. p->setPen(contentColor.light(130) );
  1904. }
  1905. p->drawLine(r.left()+2, r.bottom()-1, r.right()-2, r.bottom()-1 );
  1906. p->drawLine(r.right()-1, r.top()+2, r.right()-1, r.bottom()-2 );
  1907. break;
  1908. }
  1909. case PE_StatusBarSection:
  1910. {
  1911. if(_drawStatusBarFrame)
  1912. {
  1913. // renderButton(p, r, cg, true, false, true, true, false );
  1914. renderContour(p, r, cg.background(), cg.background().dark(130), Draw_Left|Draw_Right|Draw_Top|Draw_Bottom);
  1915. }
  1916. break;
  1917. }
  1918. case PE_TabBarBase: // Still not sure what this one does
  1919. case PE_PanelTabWidget: {
  1920. renderPanel(p, r, cg, true, sunken);
  1921. break;
  1922. }
  1923. case PE_PanelPopup: {
  1924. renderContour(p, r, cg.background(), cg.background().dark(200),
  1925. Draw_Left|Draw_Right|Draw_Top|Draw_Bottom);
  1926. break;
  1927. }
  1928. // MENU / TOOLBAR PANEL
  1929. // --------------------
  1930. case PE_PanelMenuBar:
  1931. case PE_PanelDockWindow: {
  1932. // fix for toolbar lag (from Mosfet Liquid)
  1933. TQWidget* w = dynamic_cast<TQWidget*>(p->device());
  1934. if(w && w->backgroundMode() == PaletteButton)
  1935. w->setBackgroundMode(PaletteBackground);
  1936. bool horizontal=false;
  1937. if ( r.width() > r.height() ) {
  1938. horizontal=true;
  1939. }
  1940. if (_drawToolBarGradient) {
  1941. if (_invertBarGrad) {
  1942. renderGradient(p, r, cg.background().dark(105), cg.background(), horizontal);
  1943. } else {
  1944. renderGradient(p, r, cg.background(), cg.background().dark(105), horizontal);
  1945. }
  1946. } else {
  1947. p->fillRect(r, cg.background());
  1948. }
  1949. if (_drawToolBarSeparator) {
  1950. p->setPen( getColor(cg, PanelLight) );
  1951. p->drawLine( r.left(), r.top(), r.right(), r.top() );
  1952. p->setPen( getColor(cg, PanelDark) );
  1953. p->drawLine( r.left(), r.bottom(), r.right(), r.bottom() );
  1954. } else {
  1955. p->fillRect(r, cg.background());
  1956. }
  1957. break;
  1958. }
  1959. // TOOLBAR/DOCK WINDOW HANDLE
  1960. // --------------------------
  1961. case PE_DockWindowResizeHandle: {
  1962. renderButton(p, r, cg);
  1963. break;
  1964. }
  1965. case PE_DockWindowHandle: {
  1966. // In all cases, fill the background.
  1967. TQColor handleDotColor=cg.background();
  1968. //bool horiz=false;
  1969. //if ( r.width() > r.height() ) {
  1970. //horiz=true;
  1971. //}
  1972. if (_drawToolBarGradient) {
  1973. if (_invertBarGrad) {
  1974. renderGradient(p, r, cg.background().dark(105), cg.background(), horiz);
  1975. } else {
  1976. renderGradient(p, r, cg.background(), cg.background().dark(105), horiz);
  1977. }
  1978. } else {
  1979. p->fillRect(r, cg.background());
  1980. }
  1981. if(_drawToolBarHandle) {
  1982. if (horiz) {
  1983. int center = r.left() + (r.width()/2) - 2 ;
  1984. if(hoverWidget == p->device())
  1985. handleDotColor = cg.highlight();
  1986. for(int j = kickerMode?r.top()+1:r.top()+4; j <= r.bottom()-2; j+=4)
  1987. {
  1988. renderDot(p, TQPoint(center, j), handleDotColor, kickerMode?true:false, true);
  1989. }
  1990. } else {
  1991. int center = r.top() + (r.height()/2) - 2 ;
  1992. if(hoverWidget == p->device())
  1993. handleDotColor = cg.highlight();
  1994. for(int j = kickerMode?r.left()+1:r.left()+4; j <= r.right()-2; j+=5)
  1995. {
  1996. renderDot(p, TQPoint(j, center+1), handleDotColor, kickerMode?true:false, true);
  1997. }
  1998. }
  1999. }
  2000. break;
  2001. }
  2002. // TOOLBAR SEPARATOR
  2003. // -----------------
  2004. case PE_DockWindowSeparator: {
  2005. if (_drawToolBarGradient) {
  2006. if (_invertBarGrad) {
  2007. renderGradient(p, r, cg.background().dark(105), cg.background(), horiz);
  2008. } else {
  2009. renderGradient(p, r, cg.background(), cg.background().dark(105), horiz);
  2010. }
  2011. } else {
  2012. p->fillRect(r, cg.background());
  2013. }
  2014. if (_drawToolBarItemSeparator) {
  2015. if(horiz) {
  2016. int center = r.left()+r.width()/2;
  2017. p->setPen( getColor(cg, PanelDark) );
  2018. p->drawLine( center-1, r.top()+3, center-1, r.bottom()-3 );
  2019. //p->setPen( getColor(cg, PanelLight) );
  2020. //p->drawLine( center, r.top()+3, center, r.bottom()-3 );
  2021. } else {
  2022. int center = r.top()+r.height()/2;
  2023. p->setPen( getColor(cg, PanelDark) );
  2024. p->drawLine( r.x()+3, center-1, r.right()-3, center-1 );
  2025. //p->setPen( getColor(cg, PanelLight) );
  2026. //p->drawLine( r.x()+3, center, r.right()-3, center );
  2027. }
  2028. }
  2029. break;
  2030. }
  2031. case PE_CheckMark: {
  2032. // PaT: Complicated by the tick thing.
  2033. if(_tickCheckMark) {
  2034. const int markW = r.width() > 7 ? 7 : r.width();
  2035. const int markH = markW;
  2036. int posX = r.x() + ( r.width() - markW )/2;
  2037. int posY = r.y() + ( r.height() - markH )/2-1;
  2038. TQColor contentColor = enabled?cg.base():cg.background();
  2039. // Could do with some optimizing/caching...
  2040. TQPointArray a( markH*2 );
  2041. int i, xx, yy;
  2042. xx = posX;
  2043. yy = 3 + posY;
  2044. for ( i=0; i<markW/2; i++ ) {
  2045. a.setPoint( 2*i, xx, yy );
  2046. a.setPoint( 2*i+1, xx, yy+2 );
  2047. xx++; yy++;
  2048. }
  2049. yy -= 2;
  2050. for ( ; i<markH; i++ ) {
  2051. a.setPoint( 2*i, xx, yy );
  2052. a.setPoint( 2*i+1, xx, yy+2 );
  2053. xx++; yy--;
  2054. }
  2055. if (flags & Style_On) {
  2056. int pnt;
  2057. TQColor checkmarkColor;
  2058. if(enabled) {
  2059. checkmarkColor = getColor(cg,CheckMark);
  2060. } else {
  2061. checkmarkColor = cg.mid();
  2062. }
  2063. p->setPen( checkmarkColor );
  2064. TQPoint offset(1,1);
  2065. for ( pnt = 0; pnt < (int)a.size(); pnt++ )
  2066. a[pnt];
  2067. p->drawLineSegments( a );
  2068. for ( pnt = 0; pnt < (int)a.size(); pnt++ )
  2069. a[pnt];
  2070. } else if(flags & Style_Down) {
  2071. int pnt;
  2072. TQColor checkmarkColor = alphaBlendColors(contentColor, checkmarkColor, 150);
  2073. p->setPen( checkmarkColor );
  2074. TQPoint offset(1,1);
  2075. for ( pnt = 0; pnt < (int)a.size(); pnt++ )
  2076. a[pnt];
  2077. p->drawLineSegments( a );
  2078. for ( pnt = 0; pnt < (int)a.size(); pnt++ )
  2079. a[pnt];
  2080. } else if(flags & Style_Off) {
  2081. //Dont move yer ass.
  2082. } else {
  2083. int pnt;
  2084. p->setPen( cg.mid() );
  2085. TQPoint offset(1,1);
  2086. for ( pnt = 0; pnt < (int)a.size(); pnt++ )
  2087. a[pnt];
  2088. p->drawLineSegments( a );
  2089. for ( pnt = 0; pnt < (int)a.size(); pnt++ )
  2090. a[pnt];
  2091. }
  2092. } else {
  2093. const TQColor contentColor = enabled?cg.base():cg.background();
  2094. TQColor checkmarkColor = enabled?getColor(cg,CheckMark):cg.background();
  2095. if(flags & Style_Down) {
  2096. checkmarkColor = alphaBlendColors(contentColor, checkmarkColor, 150);
  2097. }
  2098. int x = r.center().x() - 4, y = r.center().y() - 4;
  2099. TQBitmap bmp;
  2100. if( flags & Style_On ) {
  2101. bmp = TQBitmap(CHECKMARKSIZE, CHECKMARKSIZE, checkmark_dark_bits, true);
  2102. bmp.setMask(bmp);
  2103. p->setPen(alphaBlendColors(contentColor, checkmarkColor.dark(150), 50) );
  2104. p->drawPixmap(x, y, bmp);
  2105. bmp = TQBitmap(CHECKMARKSIZE, CHECKMARKSIZE, checkmark_light_bits, true);
  2106. bmp.setMask(bmp);
  2107. p->setPen(alphaBlendColors(contentColor, checkmarkColor.dark(125), 50) );
  2108. p->drawPixmap(x, y, bmp);
  2109. bmp = TQBitmap(CHECKMARKSIZE, CHECKMARKSIZE, checkmark_aa_bits, true);
  2110. bmp.setMask(bmp);
  2111. p->setPen(alphaBlendColors(contentColor, checkmarkColor.dark(150), 150) );
  2112. p->drawPixmap(x, y, bmp);
  2113. } else if ( flags & Style_Off ) {
  2114. // empty
  2115. } else { // tristate
  2116. bmp = TQBitmap(CHECKMARKSIZE, CHECKMARKSIZE, checkmark_tristate_bits, true);
  2117. bmp.setMask(bmp);
  2118. p->setPen(alphaBlendColors(contentColor, checkmarkColor.dark(150), 50) );
  2119. p->drawPixmap(x, y, bmp);
  2120. }
  2121. }
  2122. break;
  2123. }
  2124. case PE_SpinWidgetUp:
  2125. case PE_SpinWidgetDown:
  2126. case PE_HeaderArrow:
  2127. case PE_ArrowUp:
  2128. case PE_ArrowDown:
  2129. case PE_ArrowLeft:
  2130. case PE_ArrowRight: {
  2131. TQPointArray a;
  2132. switch (pe) {
  2133. case PE_SpinWidgetUp:
  2134. case PE_ArrowUp: {
  2135. a.setPoints(7, u_arrow);
  2136. break;
  2137. }
  2138. case PE_SpinWidgetDown:
  2139. case PE_ArrowDown: {
  2140. a.setPoints(7, d_arrow);
  2141. break;
  2142. }
  2143. case PE_ArrowLeft: {
  2144. a.setPoints(7, l_arrow);
  2145. break;
  2146. }
  2147. case PE_ArrowRight: {
  2148. a.setPoints(7, r_arrow);
  2149. break;
  2150. }
  2151. default: {
  2152. if (flags & Style_Up) {
  2153. a.setPoints(7, u_arrow);
  2154. } else {
  2155. a.setPoints(7, d_arrow);
  2156. }
  2157. }
  2158. }
  2159. const TQWMatrix oldMatrix( p->tqworldMatrix() );
  2160. if (flags & Style_Down) {
  2161. p->translate(tqpixelMetric(PM_ButtonShiftHorizontal),
  2162. tqpixelMetric(PM_ButtonShiftVertical));
  2163. }
  2164. a.translate((r.x()+r.width()/2), (r.y()+r.height()/2));
  2165. // extra-pixel-shift, correcting some visual tics...
  2166. switch(pe) {
  2167. case PE_ArrowLeft:
  2168. case PE_ArrowRight:
  2169. a.translate(0, -1);
  2170. break;
  2171. case PE_SpinWidgetUp:
  2172. case PE_SpinWidgetDown:
  2173. a.translate(+1, 0);
  2174. break;
  2175. default:
  2176. a.translate(0, 0);
  2177. }
  2178. if (p->pen() == TQPen(TQPen::NoPen)) {
  2179. if (flags & Style_Enabled) {
  2180. p->setPen(cg.buttonText());
  2181. } else {
  2182. p->setPen(cg.highlightedText());
  2183. }
  2184. }
  2185. p->drawLineSegments(a, 0, 3);
  2186. p->drawPoint(a[6]);
  2187. p->setWorldMatrix( oldMatrix );
  2188. break;
  2189. }
  2190. default: {
  2191. return KStyle::tqdrawPrimitive(pe, p, r, cg, flags, opt);
  2192. }
  2193. }
  2194. }
  2195. void LipstikStyle::tqdrawControl(ControlElement element,
  2196. TQPainter *p,
  2197. const TQWidget *widget,
  2198. const TQRect &r,
  2199. const TQColorGroup &cg,
  2200. SFlags flags,
  2201. const TQStyleOption& opt) const
  2202. {
  2203. const bool reverseLayout = TQApplication::reverseLayout();
  2204. const bool enabled = (flags & Style_Enabled);
  2205. switch (element) {
  2206. // PROGRESSBAR
  2207. // -----------
  2208. case CE_ProgressBarGroove: {
  2209. const TQColor content = enabled?cg.base():cg.background();
  2210. renderContour(p, r, cg.background(), getColor(cg, ButtonContour, enabled) );
  2211. p->setPen(content.dark(105) );
  2212. p->drawLine(r.left()+2, r.top()+1, r.right()-2, r.top()+1 );
  2213. p->drawLine(r.left()+1, r.top()+2, r.left()+1, r.bottom()-2);
  2214. p->setPen(content.light(105) );
  2215. p->drawLine(r.left()+2, r.bottom()-1, r.right()-2, r.bottom()-1 );
  2216. p->drawLine(r.right()-1, r.top()+2, r.right()-1, r.bottom()-2);
  2217. break;
  2218. }
  2219. case CE_ProgressBarContents: {
  2220. const TQProgressBar *pb = dynamic_cast<const TQProgressBar*>(widget);
  2221. int steps = pb->totalSteps();
  2222. const TQColor bg = enabled?cg.base():cg.background(); // background
  2223. const TQColor fg = enabled?cg.highlight():TQColor(cg.background().dark(110)); // foreground
  2224. if( steps == 0 ) { // Busy indicator
  2225. static const int barWidth = 10;
  2226. int progress = pb->progress() % (2*(r.width()-barWidth));
  2227. if( progress < 0)
  2228. progress = 0;
  2229. if( progress > r.width()-barWidth )
  2230. progress = (r.width()-barWidth)-(progress-(r.width()-barWidth));
  2231. p->fillRect( TQRect( r.x(), r.y(), r.width(), r.height() ), bg );
  2232. renderContour( p, TQRect( r.x()+progress, r.y(), barWidth, r.height() ),
  2233. bg, fg.dark(160),
  2234. Draw_Left|Draw_Right|Draw_Top|Draw_Bottom|Round_UpperRight|
  2235. Round_BottomRight|Round_UpperLeft|Round_BottomLeft );
  2236. renderSurface(p, TQRect( r.x()+progress+1, r.y()+1, barWidth-2, r.height()-2 ),
  2237. bg, fg, cg.highlight(),
  2238. 2*(_contrast/3),
  2239. Draw_Right|Draw_Left|Draw_Top|Draw_Bottom|
  2240. Round_UpperRight|Round_BottomRight|
  2241. Round_UpperLeft|Round_BottomLeft|Is_Horizontal);
  2242. } else {
  2243. double percent = static_cast<double>(pb->progress()) / static_cast<double>(steps);
  2244. int w = static_cast<int>(r.width() * percent);
  2245. // renderContour/renderSurface handle small sizes not very well, so set a minimal
  2246. // progressbar width...
  2247. if(w<4) w = 4;
  2248. int w2 = r.width()-(r.width()-w);
  2249. TQRect Rempty(reverseLayout?r.left():r.left()+w-1, r.top(), r.width()-w+1, r.height() );
  2250. TQRect Rcontour(reverseLayout?r.right()-w2+1:r.left(), r.top(), w2, r.height() );
  2251. TQRect Rsurface(Rcontour.left()+1, Rcontour.top()+1, w2-2, Rcontour.height()-2);
  2252. p->fillRect(Rempty, bg);
  2253. renderContour(p, Rcontour,
  2254. bg, fg.dark(160),
  2255. reverseLayout ? Draw_Left|Draw_Right|Draw_Top|Draw_Bottom|Round_UpperLeft|Round_BottomLeft
  2256. : Draw_Left|Draw_Right|Draw_Top|Draw_Bottom|Round_UpperRight|Round_BottomRight);
  2257. TQRegion mask(Rsurface);
  2258. if(reverseLayout) {
  2259. mask -= TQRegion(Rsurface.left(), Rsurface.top(), 1, 1);
  2260. mask -= TQRegion(Rsurface.left(), Rsurface.bottom(), 1, 1);
  2261. } else {
  2262. mask -= TQRegion(Rsurface.right(), Rsurface.top(), 1, 1);
  2263. mask -= TQRegion(Rsurface.right(), Rsurface.bottom(), 1, 1);
  2264. }
  2265. p->setClipRegion(mask);
  2266. int counter = 0;
  2267. TQPixmap surfaceTile(21, r.height()-2);
  2268. TQPainter surfacePainter(&surfaceTile);
  2269. // - 21 pixel -
  2270. // __________
  2271. // | ` `| <- 3
  2272. // | 1 | 2 |
  2273. // |____,____,| <- 3
  2274. // 1 = light, 11 pixel, 1 pixel overlapping with 2
  2275. // 2 = dark, 11 pixel, 1 pixel overlapping with 3
  2276. // 3 = light edges
  2277. const int tileHeight = surfaceTile.height();
  2278. // 3
  2279. renderSurface(&surfacePainter,
  2280. TQRect(20, 0, 11, tileHeight),
  2281. fg.light(105), fg, cg.highlight(), 2*(_contrast/3),
  2282. reverseLayout ? Draw_Right|Draw_Left|Draw_Top|Draw_Bottom|
  2283. Round_UpperLeft|Round_BottomLeft|Is_Horizontal
  2284. : Draw_Right|Draw_Left|Draw_Top|Draw_Bottom|
  2285. Round_UpperRight|Round_BottomRight|Is_Horizontal);
  2286. // 2
  2287. renderSurface(&surfacePainter,
  2288. TQRect(10, 0, 11, tileHeight),
  2289. fg, fg.light(105), cg.highlight(), 2*(_contrast/3),
  2290. reverseLayout ? Draw_Right|Draw_Left|Draw_Top|Draw_Bottom|
  2291. Round_UpperLeft|Round_BottomLeft|Is_Horizontal
  2292. : Draw_Right|Draw_Left|Draw_Top|Draw_Bottom|
  2293. Round_UpperRight|Round_BottomRight|Is_Horizontal);
  2294. // 1
  2295. renderSurface(&surfacePainter,
  2296. TQRect(0, 0, 11, tileHeight),
  2297. fg.light(105), fg, cg.highlight(), 2*(_contrast/3),
  2298. reverseLayout ? Draw_Right|Draw_Left|Draw_Top|Draw_Bottom|
  2299. Round_UpperLeft|Round_BottomLeft|Is_Horizontal
  2300. : Draw_Right|Draw_Left|Draw_Top|Draw_Bottom|
  2301. Round_UpperRight|Round_BottomRight|Is_Horizontal);
  2302. surfacePainter.end();
  2303. int staticShift = 0;
  2304. int animShift = 0;
  2305. if (!_animateProgressBar) {
  2306. staticShift = (reverseLayout ? Rsurface.left() : Rsurface.right()) % 40 - 40;
  2307. } else {
  2308. // find the animation Offset for the current Widget
  2309. TQWidget* nonConstWidget = const_cast<TQWidget*>(widget);
  2310. TQMapConstIterator<TQWidget*, int> iter = progAnimWidgets.find(nonConstWidget);
  2311. if (iter != progAnimWidgets.end())
  2312. animShift = iter.data();
  2313. }
  2314. while((counter*10) < (Rsurface.width()+20)) {
  2315. counter++;
  2316. if (reverseLayout) {
  2317. // from right to left, overlap 1 pixel with the previously drawn tile
  2318. p->drawPixmap(Rsurface.right()-counter*20-animShift+40+staticShift, r.top()+1,
  2319. surfaceTile);
  2320. } else {
  2321. // from left to right, overlap 1 pixel with the previously drawn tile
  2322. p->drawPixmap(Rsurface.left()+counter*20+animShift-40+staticShift, r.top()+1,
  2323. surfaceTile);
  2324. }
  2325. }
  2326. p->setClipping(false);
  2327. }
  2328. break;
  2329. }
  2330. // TABS
  2331. // ----
  2332. case CE_TabBarTab: {
  2333. const TQTabBar * tb = (const TQTabBar *) widget;
  2334. bool cornerWidget = false;
  2335. if( ::tqqt_cast<TQTabWidget*>(tb->parent()) ) {
  2336. const TQTabWidget *tw = (const TQTabWidget*)tb->parent();
  2337. // is there a corner widget in the (top) left edge?
  2338. TQWidget *cw = tw->cornerWidget(TQt::TopLeft);
  2339. if(cw)
  2340. cornerWidget = true;
  2341. }
  2342. TQTabBar::Shape tbs = tb->tqshape();
  2343. bool selected = false;
  2344. if (flags & Style_Selected) selected = true;
  2345. TabPosition pos;
  2346. if (tb->count() == 1) {
  2347. pos = Single;
  2348. } else if ((tb->indexOf(opt.tab()->identifier()) == 0)) {
  2349. pos = First;
  2350. } else if (tb->indexOf(opt.tab()->identifier()) == tb->count() - 1) {
  2351. pos = Last;
  2352. } else {
  2353. pos = Middle;
  2354. }
  2355. bool mouseOver = false;
  2356. if (opt.tab() == hoverTab) {
  2357. mouseOver = true;
  2358. flags |= Style_MouseOver;
  2359. }
  2360. switch (tbs) {
  2361. case TQTabBar::TriangularAbove:
  2362. // renderTriangularTab(p, r, cg, (flags & Style_MouseOver), selected, false, pos);
  2363. renderTab(p, r, cg, mouseOver, selected, false, pos, true, cornerWidget);
  2364. break;
  2365. case TQTabBar::RoundedAbove:
  2366. renderTab(p, r, cg, mouseOver, selected, false, pos, false, cornerWidget);
  2367. break;
  2368. case TQTabBar::TriangularBelow:
  2369. // renderTriangularTab(p, r, cg, (flags & Style_MouseOver), selected, true, pos);
  2370. renderTab(p, r, cg, mouseOver, selected, true, pos, true, cornerWidget);
  2371. break;
  2372. case TQTabBar::RoundedBelow:
  2373. renderTab(p, r, cg, mouseOver, selected, true, pos, false, cornerWidget);
  2374. break;
  2375. default:
  2376. KStyle::tqdrawControl(element, p, widget, r, cg, flags, opt);
  2377. }
  2378. break;
  2379. }
  2380. case CE_PushButton: {
  2381. TQPushButton *button = (TQPushButton *)widget;
  2382. const bool isDefault = enabled && button->isDefault();
  2383. if (button->isFlat() )
  2384. flatMode = true;
  2385. if (widget == hoverWidget)
  2386. flags |= Style_MouseOver;
  2387. TQColorGroup g2 = cg;
  2388. if (isDefault)
  2389. g2.setColor(TQColorGroup::Background, cg.background().dark(120) );
  2390. tqdrawPrimitive(PE_ButtonBevel, p,
  2391. isDefault?TQRect(r.x()+1,r.y()+1,r.width()-2,r.height()-2):r,
  2392. g2, flags, TQStyleOption(button) );
  2393. if (isDefault ) {
  2394. tqdrawPrimitive(PE_ButtonDefault, p, r, cg, flags);
  2395. }
  2396. break;
  2397. }
  2398. case CE_PushButtonLabel:
  2399. {
  2400. int x, y, w, h;
  2401. r.rect( &x, &y, &w, &h );
  2402. const TQPushButton* button = static_cast<const TQPushButton *>( widget );
  2403. bool active = button->isOn() || button->isDown();
  2404. bool cornArrow = false;
  2405. // Shift button contents if pushed.
  2406. if ( active )
  2407. {
  2408. x += tqpixelMetric(PM_ButtonShiftHorizontal, widget);
  2409. y += tqpixelMetric(PM_ButtonShiftVertical, widget);
  2410. flags |= Style_Sunken;
  2411. }
  2412. // Does the button have a popup menu?
  2413. if ( button->isMenuButton() )
  2414. {
  2415. int dx = tqpixelMetric( PM_MenuButtonIndicator, widget );
  2416. if ( button->iconSet() && !button->iconSet()->isNull() &&
  2417. (dx + button->iconSet()->pixmap (TQIconSet::Small, TQIconSet::Normal, TQIconSet::Off ).width()) >= w )
  2418. {
  2419. cornArrow = true; //To little room. Draw the arrow in the corner, don't adjust the widget
  2420. }
  2421. else
  2422. {
  2423. p->setPen(cg.buttonText());
  2424. tqdrawPrimitive( PE_ArrowDown, p, tqvisualRect( TQRect(x + w - dx - 8, y + 2, dx, h - 4), r ),
  2425. cg, flags, opt );
  2426. w -= dx;
  2427. }
  2428. }
  2429. // Draw the icon if there is one
  2430. if ( button->iconSet() && !button->iconSet()->isNull() )
  2431. {
  2432. TQIconSet::Mode mode = TQIconSet::Disabled;
  2433. TQIconSet::State state = TQIconSet::Off;
  2434. if (button->isEnabled())
  2435. mode = button->hasFocus() ? TQIconSet::Active : TQIconSet::Normal;
  2436. if (button->isToggleButton() && button->isOn())
  2437. state = TQIconSet::On;
  2438. TQPixmap pixmap = button->iconSet()->pixmap( TQIconSet::Small, mode, state );
  2439. if (button->text().isEmpty() && !button->pixmap())
  2440. p->drawPixmap( x + w/2 - pixmap.width()/2, y + h / 2 - pixmap.height() / 2,
  2441. pixmap );
  2442. else
  2443. p->drawPixmap( x + 4, y + h / 2 - pixmap.height() / 2, pixmap );
  2444. if (cornArrow) //Draw over the icon
  2445. tqdrawPrimitive( PE_ArrowDown, p, tqvisualRect( TQRect(x + w - 6, x + h - 6, 7, 7), r ),
  2446. cg, flags, opt );
  2447. int pw = pixmap.width();
  2448. x += pw + 4;
  2449. w -= pw + 4;
  2450. }
  2451. // Make the label indicate if the button is a default button or not
  2452. drawItem( p, TQRect(x, y, w, h), AlignCenter|ShowPrefix, button->tqcolorGroup(),
  2453. button->isEnabled(), button->pixmap(), button->text(), -1,
  2454. &button->tqcolorGroup().buttonText() );
  2455. if ( flags & Style_HasFocus )
  2456. tqdrawPrimitive( PE_FocusRect, p,
  2457. tqvisualRect( subRect( SR_PushButtonFocusRect, widget ), widget ),
  2458. cg, flags );
  2459. break;
  2460. }
  2461. // MENUBAR ITEM (sunken panel on mouse over)
  2462. // -----------------------------------------
  2463. case CE_MenuBarItem: {
  2464. TQMenuItem *mi = opt.menuItem();
  2465. bool active = flags & Style_Active;
  2466. bool focused = flags & Style_HasFocus;
  2467. bool down = flags & Style_Down;
  2468. const int text_flags =
  2469. AlignVCenter | AlignHCenter | ShowPrefix | DontClip | SingleLine;
  2470. if (active && focused) {
  2471. if(_coloredMenuBar) {
  2472. if(_alterMenuGradients) {
  2473. uint contourFlags = Draw_Left|Draw_Right|Draw_Top|Draw_Bottom|
  2474. Round_UpperLeft|Round_UpperRight|Round_BottomLeft|Round_BottomRight;
  2475. uint surfaceFlags = Draw_Left|Draw_Right|Draw_Top|Draw_Bottom|
  2476. Round_UpperLeft|Round_UpperRight|Round_BottomLeft|Round_BottomRight|
  2477. Is_Horizontal;
  2478. renderContour(p,
  2479. r,
  2480. alphaBlendColors(getColor(cg,MenuStripeColor),
  2481. cg.background().light( 105 ),
  2482. 50),
  2483. cg.highlight().dark(200),
  2484. contourFlags);
  2485. renderSurface(p,
  2486. TQRect(r.left()+1, r.top()+1, r.width()-2, r.height()-2),
  2487. alphaBlendColors(getColor(cg,MenuStripeColor),
  2488. cg.background().light( 105 ),
  2489. 50),
  2490. cg.highlight(),
  2491. getColor(cg,MouseOverHighlight),
  2492. _sharperMenuGradient?_contrast+10:_contrast,
  2493. surfaceFlags);
  2494. } else {
  2495. renderSurface(p, r, cg.background(), cg.highlight(), cg.highlight(),
  2496. _sharperMenuGradient?_contrast+30:_contrast+3, Draw_Top|Draw_Bottom|Is_Horizontal);
  2497. }
  2498. p->setPen(cg.highlightedText() );
  2499. p->drawText(r, text_flags, mi->text());
  2500. } else {
  2501. if (down) {
  2502. tqdrawPrimitive(PE_ButtonTool, p, r, cg, flags|Style_Down, opt);
  2503. } else {
  2504. tqdrawPrimitive(PE_ButtonTool, p, r, cg, flags, opt);
  2505. }
  2506. p->setPen(cg.buttonText() );
  2507. p->drawText(r, text_flags, mi->text());
  2508. }
  2509. } else {
  2510. p->setPen(cg.buttonText() );
  2511. p->drawText(r, text_flags, mi->text());
  2512. }
  2513. break;
  2514. }
  2515. // POPUPMENU ITEM (highlighted on mouseover)
  2516. // ------------------------------------------
  2517. case CE_PopupMenuItem: {
  2518. const TQPopupMenu *popupmenu = static_cast< const TQPopupMenu * >( widget );
  2519. TQMenuItem *mi = opt.menuItem();
  2520. if ( !mi )
  2521. {
  2522. // Don't leave blank holes if we set NoBackground for the TQPopupMenu.
  2523. // This only happens when the popupMenu spans more than one column.
  2524. if (! ( widget->erasePixmap() && !widget->erasePixmap()->isNull() ) )
  2525. p->fillRect( r, cg.background().light( 105 ) );
  2526. break;
  2527. }
  2528. int tab = opt.tabWidth();
  2529. int checkcol = opt.maxIconWidth();
  2530. bool enabled = mi->isEnabled();
  2531. bool checkable = popupmenu->isCheckable();
  2532. bool active = flags & Style_Active;
  2533. bool etchtext = tqstyleHint( SH_EtchDisabledText );
  2534. bool reverse = TQApplication::reverseLayout();
  2535. if ( checkable )
  2536. checkcol = TQMAX( checkcol, 20 );
  2537. // Draw the menu item background
  2538. if (active) {
  2539. if (enabled) {
  2540. if(_alterMenuGradients) {
  2541. uint contourFlags = Draw_Left|Draw_Right|Draw_Top|Draw_Bottom|
  2542. Round_UpperLeft|Round_UpperRight|Round_BottomLeft|Round_BottomRight;
  2543. uint surfaceFlags = Draw_Left|Draw_Right|Draw_Top|Draw_Bottom|
  2544. Round_UpperLeft|Round_UpperRight|Round_BottomLeft|Round_BottomRight|
  2545. Is_Horizontal;
  2546. renderContour(p,
  2547. r,
  2548. alphaBlendColors(getColor(cg,MenuStripeColor),
  2549. cg.background().light( 105 ),
  2550. 50),
  2551. cg.highlight().dark(250),
  2552. contourFlags);
  2553. renderSurface(p,
  2554. TQRect(r.left()+1, r.top()+1, r.width()-2, r.height()-2),
  2555. alphaBlendColors(getColor(cg,MenuStripeColor),
  2556. cg.background().light( 105 ),
  2557. 50),
  2558. cg.highlight(),
  2559. getColor(cg,MouseOverHighlight),
  2560. _sharperMenuGradient?_contrast+10:_contrast,
  2561. surfaceFlags);
  2562. if(_menuLeftSideBar) {
  2563. p->setPen(getColor(cg,MenuStripeColor));
  2564. p->drawPoint(r.left(), r.top());
  2565. p->drawPoint(r.left(), r.bottom());
  2566. }
  2567. } else {
  2568. renderSurface(p, r, cg.background(), cg.highlight(), cg.highlight(),
  2569. _sharperMenuGradient?_contrast+30:_contrast+3, Draw_Top|Draw_Bottom|Is_Horizontal);
  2570. }
  2571. } else {
  2572. if(_drawFocusRect) {
  2573. p->setPen(TQPen(cg.highlight().dark(130), 1));
  2574. p->drawRect(TQRect(r.left(), r.top(), r.width(), r.height()));
  2575. } else {
  2576. p->drawWinFocusRect( r );
  2577. }
  2578. }
  2579. } else if ( widget->erasePixmap() && !widget->erasePixmap()->isNull() ) {
  2580. // Draw the transparency pixmap
  2581. // Transparency in KDE3/TQt3 is an EVIL hack! Beware!
  2582. p->drawPixmap( r.topLeft(), *widget->erasePixmap(), r );
  2583. } else {
  2584. // Draw a solid background
  2585. p->fillRect( r, cg.background().light( 105 ) );
  2586. //add a pretty bar on the left side of the menu, now looks good too!
  2587. if(_menuLeftSideBar && !active) {
  2588. if(_flatStripe) {
  2589. p->fillRect( TQRect(r.left(),r.top(), checkcol+4,r.bottom()-r.top()+1), getColor(cg, MenuStripeColor) );
  2590. } else {
  2591. if(_reverseGradients) {
  2592. renderGradient(p, TQRect(r.left(),r.top(), checkcol+4,r.bottom()-r.top()+1), getColor(cg, MenuStripeColor), cg.background().light( 105 ), false);
  2593. } else {
  2594. renderGradient(p, TQRect(r.left(),r.top(), checkcol+4,r.bottom()-r.top()+1),cg.background().light( 105 ), getColor(cg, MenuStripeColor), false);
  2595. }
  2596. }
  2597. }
  2598. }
  2599. // Are we a menu item separator?
  2600. if ( mi->isSeparator() ) {
  2601. if(_menuLeftSideBar) {
  2602. p->setPen( cg.mid() );
  2603. p->drawLine( r.x()+5+checkcol+4, r.y() + 1, r.right()-5-checkcol-4, r.y() + 1 );
  2604. //p->setPen( cg.light() );
  2605. //p->drawLine( r.x()+5, r.y() + 2, r.right()-5 , r.y() + 2 );
  2606. } else {
  2607. p->setPen( cg.mid() );
  2608. p->drawLine( r.x()+5, r.y() + 1, r.right()-5, r.y() + 1 );
  2609. //p->setPen( cg.light() );
  2610. //p->drawLine( r.x()+5, r.y() + 2, r.right()-5 , r.y() + 2 );
  2611. }
  2612. break;
  2613. }
  2614. TQRect cr = tqvisualRect( TQRect( r.x() + 2, r.y() + 2, checkcol - 1, r.height() - 4 ), r );
  2615. // Do we have an icon?
  2616. if ( mi->iconSet() ) {
  2617. TQIconSet::Mode mode;
  2618. // Select the correct icon from the iconset
  2619. if (active)
  2620. mode = enabled?TQIconSet::Active:TQIconSet::Disabled;
  2621. else
  2622. mode = enabled?TQIconSet::Normal:TQIconSet::Disabled;
  2623. TQPixmap pixmap = mi->iconSet()->pixmap(TQIconSet::Small, mode);
  2624. TQRect pmr( 0, 0, pixmap.width(), pixmap.height() );
  2625. pmr.moveCenter( cr.center() );
  2626. p->drawPixmap( pmr.topLeft(), pixmap );
  2627. // Do we have an icon and are checked at the same time?
  2628. // Then dont draw the icon, only the check. I believe its more
  2629. // apparent its checked, compared to an almost invisible pressed background only.
  2630. if ( checkable && /*!active &&*/ mi->isChecked() ) {
  2631. qDrawShadePanel( p, cr.x(), cr.y(), cr.width(), cr.height(), cg, true, 1,
  2632. &cg.brush(TQColorGroup::Midlight) );
  2633. // Draw the checkmark
  2634. SFlags cflags = Style_On;
  2635. if (enabled)
  2636. cflags |= Style_Enabled;
  2637. tqdrawPrimitive( PE_CheckMark, p, cr, cg, cflags );
  2638. }
  2639. }
  2640. // Are we checked? (This time without an icon)
  2641. else if ( checkable && mi->isChecked() )
  2642. {
  2643. // We only have to draw the background if the menu item is inactive -
  2644. // if it's active the "pressed" background is already drawn
  2645. // if ( ! active )
  2646. qDrawShadePanel( p, cr.x(), cr.y(), cr.width(), cr.height(), cg, true, 1,
  2647. &cg.brush(TQColorGroup::Midlight) );
  2648. // Draw the checkmark
  2649. SFlags cflags = Style_On;
  2650. if (enabled)
  2651. cflags |= Style_Enabled;
  2652. tqdrawPrimitive( PE_CheckMark, p, cr, cg, cflags );
  2653. }
  2654. // Time to draw the menu item label...
  2655. int xm = 2 + checkcol + 2; // X position margin
  2656. if(_menuLeftSideBar) {
  2657. xm = 2 + checkcol + 2 + 3; // X position margin
  2658. }
  2659. int xp = reverse ? // X position
  2660. r.x() + tab + rightBorder + itemHMargin + itemFrame - 1 :
  2661. r.x() + xm;
  2662. int offset = reverse ? -1 : 1; // Shadow offset for etched text
  2663. // Label width (minus the width of the accelerator portion)
  2664. int tw = r.width() - xm - tab - arrowHMargin - itemHMargin * 3 - itemFrame + 1;
  2665. // Set the color for enabled and disabled text
  2666. // (used for both active and inactive menu items)
  2667. p->setPen( enabled ? cg.buttonText() : cg.mid() );
  2668. // This color will be used instead of the above if the menu item
  2669. // is active and disabled at the same time. (etched text)
  2670. TQColor discol = cg.mid();
  2671. // Does the menu item draw it's own label?
  2672. if ( mi->custom() ) {
  2673. int m = 2;
  2674. // Save the painter state in case the custom
  2675. // paint method changes it in some way
  2676. p->save();
  2677. // Draw etched text if we're inactive and the menu item is disabled
  2678. if ( etchtext && !enabled && !active ) {
  2679. p->setPen( cg.light() );
  2680. mi->custom()->paint( p, cg, active, enabled, xp+offset, r.y()+m+1, tw, r.height()-2*m );
  2681. p->setPen( discol );
  2682. }
  2683. mi->custom()->paint( p, cg, active, enabled, xp, r.y()+m, tw, r.height()-2*m );
  2684. p->restore();
  2685. }
  2686. else {
  2687. // The menu item doesn't draw it's own label
  2688. TQString s = mi->text();
  2689. // Does the menu item have a text label?
  2690. if ( !s.isNull() ) {
  2691. int t = s.find( '\t' );
  2692. int m = 2;
  2693. int text_flags = AlignVCenter | ShowPrefix | DontClip | SingleLine;
  2694. text_flags |= reverse ? AlignRight : AlignLeft;
  2695. //TQColor draw = cg.text();
  2696. TQColor draw = (active && enabled) ? cg.highlightedText () : cg.foreground();
  2697. p->setPen(draw);
  2698. // Does the menu item have a tabstop? (for the accelerator text)
  2699. if ( t >= 0 ) {
  2700. int tabx = reverse ? r.x() + rightBorder + itemHMargin + itemFrame :
  2701. r.x() + r.width() - tab - rightBorder - itemHMargin - itemFrame;
  2702. // Draw the right part of the label (accelerator text)
  2703. if ( etchtext && !enabled ) {
  2704. // Draw etched text if we're inactive and the menu item is disabled
  2705. p->setPen( cg.light() );
  2706. p->drawText( tabx+offset, r.y()+m+1, tab, r.height()-2*m, text_flags, s.mid( t+1 ) );
  2707. p->setPen( discol );
  2708. }
  2709. p->drawText( tabx, r.y()+m, tab, r.height()-2*m, text_flags, s.mid( t+1 ) );
  2710. s = s.left( t );
  2711. }
  2712. // Draw the left part of the label (or the whole label
  2713. // if there's no accelerator)
  2714. if ( etchtext && !enabled ) {
  2715. // Etched text again for inactive disabled menu items...
  2716. p->setPen( cg.light() );
  2717. p->drawText( xp+offset, r.y()+m+1, tw, r.height()-2*m, text_flags, s, t );
  2718. p->setPen( discol );
  2719. }
  2720. p->drawText( xp, r.y()+m, tw, r.height()-2*m, text_flags, s, t );
  2721. p->setPen(cg.text());
  2722. }
  2723. // The menu item doesn't have a text label
  2724. // Check if it has a pixmap instead
  2725. else if ( mi->pixmap() ) {
  2726. TQPixmap *pixmap = mi->pixmap();
  2727. // Draw the pixmap
  2728. if ( pixmap->depth() == 1 )
  2729. p->setBackgroundMode( Qt::OpaqueMode );
  2730. int diffw = ( ( r.width() - pixmap->width() ) / 2 )
  2731. + ( ( r.width() - pixmap->width() ) % 2 );
  2732. p->drawPixmap( r.x()+diffw, r.y()+1, *pixmap );
  2733. if ( pixmap->depth() == 1 )
  2734. p->setBackgroundMode( Qt::TransparentMode );
  2735. }
  2736. }
  2737. // Does the menu item have a submenu?
  2738. if ( mi->popup() ) {
  2739. PrimitiveElement arrow = reverse ? PE_ArrowLeft : PE_ArrowRight;
  2740. int dim = tqpixelMetric(PM_MenuButtonIndicator) - 1;
  2741. TQRect vr = tqvisualRect( TQRect( r.x() + r.width() - 5 - 1 - dim,
  2742. r.y() + r.height() / 2 - dim / 2, dim, dim), r );
  2743. // Draw an arrow at the far end of the menu item
  2744. if ( active )
  2745. {
  2746. if ( enabled )
  2747. p->setPen(cg.highlightedText());
  2748. else
  2749. p->setPen(cg.buttonText());
  2750. tqdrawPrimitive( arrow, p, vr, cg, Style_Enabled );
  2751. }
  2752. else
  2753. {
  2754. p->setPen(cg.buttonText());
  2755. tqdrawPrimitive( arrow, p, vr, cg, enabled? Style_Enabled : Style_Default );
  2756. }
  2757. }
  2758. break;
  2759. }
  2760. // Menu and doctwindow empty space
  2761. //
  2762. case CE_DockWindowEmptyArea:
  2763. if (_drawToolBarGradient) {
  2764. TQDockWindow *wind = (TQDockWindow*)widget;
  2765. bool horizontal=false;
  2766. if ( Qt::Horizontal==wind->orientation() ) {
  2767. horizontal=true;
  2768. }
  2769. if (_invertBarGrad) {
  2770. renderGradient(p, r, cg.background().dark(105), cg.background(), horizontal);
  2771. } else {
  2772. renderGradient(p, r, cg.background(), cg.background().dark(105), horizontal);
  2773. }
  2774. } else {
  2775. p->fillRect(r, cg.background());
  2776. }
  2777. break;
  2778. case CE_MenuBarEmptyArea:
  2779. p->fillRect(r, cg.background());
  2780. break;
  2781. default:
  2782. KStyle::tqdrawControl(element, p, widget, r, cg, flags, opt);
  2783. }
  2784. }
  2785. void LipstikStyle::tqdrawControlMask(ControlElement element,
  2786. TQPainter *p,
  2787. const TQWidget *w,
  2788. const TQRect &r,
  2789. const TQStyleOption &opt) const
  2790. {
  2791. switch (element) {
  2792. case CE_PushButton: {
  2793. p->fillRect (r, color0);
  2794. renderMask(p, r, color1,
  2795. Round_UpperLeft|Round_UpperRight|Round_BottomLeft|Round_BottomRight);
  2796. break;
  2797. }
  2798. default: {
  2799. KStyle::tqdrawControlMask (element, p, w, r, opt);
  2800. }
  2801. }
  2802. }
  2803. void LipstikStyle::tqdrawComplexControlMask(ComplexControl c,
  2804. TQPainter *p,
  2805. const TQWidget *w,
  2806. const TQRect &r,
  2807. const TQStyleOption &o) const
  2808. {
  2809. switch (c) {
  2810. case CC_SpinWidget:
  2811. case CC_ListView:
  2812. case CC_ComboBox: {
  2813. p->fillRect (r, color0);
  2814. renderMask(p, r, color1,
  2815. Round_UpperLeft|Round_UpperRight|Round_BottomLeft|Round_BottomRight);
  2816. break;
  2817. }
  2818. default: {
  2819. KStyle::tqdrawComplexControlMask (c, p, w, r, o);
  2820. }
  2821. }
  2822. }
  2823. void LipstikStyle::tqdrawComplexControl(ComplexControl control,
  2824. TQPainter *p,
  2825. const TQWidget *widget,
  2826. const TQRect &r,
  2827. const TQColorGroup &cg,
  2828. SFlags flags,
  2829. SCFlags controls,
  2830. SCFlags active,
  2831. const TQStyleOption& opt) const
  2832. {
  2833. const bool reverseLayout = TQApplication::reverseLayout();
  2834. const bool enabled = (flags & Style_Enabled);
  2835. switch(control) {
  2836. // COMBOBOX
  2837. // --------
  2838. case CC_ComboBox: {
  2839. static const unsigned int handleWidth = 15;
  2840. const TQComboBox *cb = dynamic_cast<const TQComboBox *>(widget);
  2841. // at the moment cb is only needed to check if the combo box is editable or not.
  2842. // if cb doesn't exist, just assume false and the app (gideon! ;) ) at least doesn't crash.
  2843. bool editable = false;
  2844. bool hasFocus = false;
  2845. if (cb) {
  2846. editable = cb->editable();
  2847. hasFocus = cb->hasFocus();
  2848. }
  2849. const TQColor buttonColor = enabled?cg.button():cg.background();
  2850. const TQColor inputColor = enabled?(editable?cg.base():cg.button())
  2851. :cg.background();
  2852. uint contourFlags = 0;
  2853. if( khtmlWidgets.contains(cb) )
  2854. contourFlags |= Draw_AlphaBlend;
  2855. if (_inputFocusHighlight && hasFocus && editable && enabled)
  2856. {
  2857. TQRect editField = querySubControlMetrics(control, widget, SC_ComboBoxEditField);
  2858. TQRect editFrame = r;
  2859. TQRect buttonFrame = r;
  2860. uint editFlags = contourFlags;
  2861. uint buttonFlags = contourFlags;
  2862. // Hightlight only the part of the contour next to the control button
  2863. if (reverseLayout)
  2864. {
  2865. // querySubControlMetrics doesn't work right for reverse Layout
  2866. int dx = r.right() - editField.right();
  2867. editFrame.setLeft(editFrame.left() + dx);
  2868. buttonFrame.setRight(editFrame.left() - 1);
  2869. editFlags |= Draw_Right|Draw_Top|Draw_Bottom|Round_UpperRight|Round_BottomRight;
  2870. buttonFlags |= Draw_Left|Draw_Top|Draw_Bottom|Round_UpperLeft|Round_BottomLeft;
  2871. }
  2872. else
  2873. {
  2874. editFrame.setRight(editField.right());
  2875. buttonFrame.setLeft(editField.right() + 1);
  2876. editFlags |= Draw_Left|Draw_Top|Draw_Bottom|Round_UpperLeft|Round_BottomLeft;
  2877. buttonFlags |= Draw_Right|Draw_Top|Draw_Bottom|Round_UpperRight|Round_BottomRight;
  2878. }
  2879. renderContour(p, editFrame, cg.background(), getColor(cg,FocusHighlight,enabled), editFlags);
  2880. renderContour(p, buttonFrame, cg.background(),
  2881. getColor(cg, ButtonContour, enabled), buttonFlags);
  2882. }
  2883. else
  2884. {
  2885. contourFlags |= Draw_Left|Draw_Right|Draw_Top|Draw_Bottom|
  2886. Round_UpperLeft|Round_UpperRight|Round_BottomLeft|Round_BottomRight;
  2887. renderContour(p, r, cg.background(), getColor(cg, ButtonContour, enabled), contourFlags);
  2888. }
  2889. //extend the contour: between input and handler...
  2890. p->setPen(alphaBlendColors(cg.background(), getColor(cg, ButtonContour, enabled), 50) );
  2891. if(reverseLayout) {
  2892. p->drawLine(r.left()+1+handleWidth, r.top()+1, r.left()+1+handleWidth, r.bottom()-1);
  2893. } else {
  2894. p->drawLine(r.right()-handleWidth-1, r.top()+1, r.right()-handleWidth-1, r.bottom()-1);
  2895. }
  2896. const TQRect RbuttonSurface(reverseLayout?r.left()+1:r.right()-handleWidth, r.top()+1,
  2897. handleWidth, r.height()-2);
  2898. const TQRect RcontentSurface(reverseLayout?r.left()+1+handleWidth+1:r.left()+1, r.top()+1,
  2899. r.width()-handleWidth-3, r.height()-2);
  2900. // handler
  2901. uint surfaceFlags = Draw_Left|Draw_Right|Draw_Top|Draw_Bottom|Is_Horizontal;
  2902. if(reverseLayout) {
  2903. surfaceFlags |= Round_UpperLeft|Round_BottomLeft;
  2904. } else {
  2905. surfaceFlags |= Round_UpperRight|Round_BottomRight;
  2906. }
  2907. if ((widget == hoverWidget) || (flags & Style_MouseOver)) {
  2908. surfaceFlags |= Is_Highlight;
  2909. if(editable) surfaceFlags |= Highlight_Left|Highlight_Right;
  2910. surfaceFlags |= Highlight_Top|Highlight_Bottom;
  2911. }
  2912. if(_comboboxColored) {
  2913. renderSurface(p, RbuttonSurface,
  2914. cg.background(), getColor(cg,MouseOverHighlight), getColor(cg,MouseOverHighlight), enabled?_contrast+3:(_contrast/2),
  2915. surfaceFlags);
  2916. } else {
  2917. renderSurface(p, RbuttonSurface,
  2918. cg.background(), buttonColor, getColor(cg,MouseOverHighlight), enabled?_contrast+3:(_contrast/2),
  2919. surfaceFlags);
  2920. }
  2921. if(!editable) {
  2922. surfaceFlags = Draw_Left|Draw_Right|Draw_Top|Draw_Bottom|Is_Horizontal;
  2923. if(reverseLayout) {
  2924. surfaceFlags |= Round_UpperRight|Round_BottomRight;
  2925. } else {
  2926. surfaceFlags |= Round_UpperLeft|Round_BottomLeft;
  2927. }
  2928. if ((widget == hoverWidget) || (flags & Style_MouseOver)) {
  2929. surfaceFlags |= Is_Highlight;
  2930. surfaceFlags |= Highlight_Top|Highlight_Bottom;
  2931. }
  2932. renderSurface(p, RcontentSurface,
  2933. cg.background(), buttonColor, getColor(cg,MouseOverHighlight), enabled?_contrast+3:(_contrast/2),
  2934. surfaceFlags);
  2935. if (hasFocus) {
  2936. tqdrawPrimitive(PE_FocusRect, p,
  2937. TQRect(RcontentSurface.x() + 2,
  2938. RcontentSurface.y() + 2,
  2939. RcontentSurface.width() - 4,
  2940. RcontentSurface.height() - 4), cg);
  2941. }
  2942. } else {
  2943. // thin frame around the input area
  2944. if (_inputFocusHighlight && hasFocus && editable && enabled)
  2945. {
  2946. p->setPen( getColor(cg,FocusHighlight).dark(130) );
  2947. }
  2948. else
  2949. {
  2950. p->setPen(inputColor.dark(130) );
  2951. }
  2952. p->drawLine(RcontentSurface.x(), reverseLayout?RcontentSurface.y():RcontentSurface.y()+1,
  2953. RcontentSurface.x(), reverseLayout?RcontentSurface.bottom():RcontentSurface.bottom()-1);
  2954. p->drawLine(RcontentSurface.x()+1, RcontentSurface.y(),
  2955. reverseLayout?RcontentSurface.right()-1:RcontentSurface.right(), RcontentSurface.y() );
  2956. if (_inputFocusHighlight && hasFocus && editable && enabled)
  2957. {
  2958. p->setPen( getColor(cg,FocusHighlight).light(130) );
  2959. }
  2960. else
  2961. {
  2962. p->setPen(inputColor.light(130) );
  2963. }
  2964. p->drawLine(reverseLayout?RcontentSurface.x():RcontentSurface.x()+1, RcontentSurface.bottom(),
  2965. reverseLayout?RcontentSurface.right()-1:RcontentSurface.right(), RcontentSurface.bottom() );
  2966. p->drawLine(RcontentSurface.right(), RcontentSurface.top()+1,
  2967. RcontentSurface.right(), RcontentSurface.bottom()-1 );
  2968. // input area
  2969. p->fillRect(RcontentSurface.x()+1, RcontentSurface.y()+1,
  2970. RcontentSurface.width()-2, RcontentSurface.height()-2, inputColor );
  2971. }
  2972. if(_comboboxColored) {
  2973. p->setPen(cg.highlightedText());
  2974. } else {
  2975. p->setPen(cg.foreground());
  2976. }
  2977. tqdrawPrimitive(PE_SpinWidgetDown, p, RbuttonSurface, cg, Style_Default|Style_Enabled|Style_Raised);
  2978. // TQComboBox draws the text using cg.text(), we can override this
  2979. // from here
  2980. p->setPen( cg.buttonText() );
  2981. p->setBackgroundColor( cg.button() );
  2982. break;
  2983. }
  2984. // TOOLBUTTON
  2985. // ----------
  2986. case CC_ToolButton: {
  2987. const TQToolButton *tb = (const TQToolButton *) widget;
  2988. TQRect button, menuarea;
  2989. button = querySubControlMetrics(control, widget, SC_ToolButton, opt);
  2990. menuarea = querySubControlMetrics(control, widget, SC_ToolButtonMenu, opt);
  2991. SFlags bflags = flags,
  2992. mflags = flags;
  2993. if (kornMode)
  2994. {
  2995. tqdrawPrimitive(PE_ButtonTool, p, button, cg, bflags, opt);
  2996. break;
  2997. }
  2998. else
  2999. {
  3000. // Tricky... (I'm lucky TQtCurve has already gone there... thanks Craig!)
  3001. if (_drawToolBarGradient) {
  3002. const TQToolBar *tbar=widget->parentWidget() ? ::tqqt_cast<const TQToolBar *>(widget->parentWidget()) : NULL;
  3003. bool horizontal=false;
  3004. if ( tbar != NULL ) {
  3005. if ( Qt::Horizontal==tbar->orientation() ) {
  3006. horizontal=true;
  3007. }
  3008. }
  3009. if (_invertBarGrad) {
  3010. renderGradient(p, r, cg.background().dark(105), cg.background(), horizontal);
  3011. } else {
  3012. renderGradient(p, r, cg.background(), cg.background().dark(105), horizontal);
  3013. }
  3014. } else {
  3015. p->fillRect(r, cg.background());
  3016. }
  3017. bflags &= ~Style_MouseOver;
  3018. }
  3019. if (active & SC_ToolButton)
  3020. bflags |= Style_Down;
  3021. if (active & SC_ToolButtonMenu)
  3022. mflags |= Style_Down;
  3023. //PaT: Added Mouse Hover FX for TabBar Buttons... Now that
  3024. // was damn tricky... My proudest achievement! :)
  3025. // Its not highly efficient, but im fu***ng tired...
  3026. if (controls & SC_ToolButton) {
  3027. // If we're pressed, on, or raised...
  3028. if (bflags & (Style_Down | Style_On | Style_Raised) || widget==hoverWidget) {
  3029. if ( widget == hoverWidget && tb->parentWidget()->inherits( "KTabWidget" )) {
  3030. renderButton(p, r, cg, false, true, false, true, false );
  3031. } else {
  3032. tqdrawPrimitive(PE_ButtonTool, p, button, cg, bflags, opt);
  3033. }
  3034. } else if (tb->parentWidget() &&
  3035. tb->parentWidget()->backgroundPixmap() &&
  3036. !tb->parentWidget()->backgroundPixmap()->isNull()) {
  3037. TQPixmap pixmap = *(tb->parentWidget()->backgroundPixmap());
  3038. p->drawTiledPixmap( r, pixmap, tb->pos() );
  3039. }
  3040. }
  3041. // Draw a toolbutton menu indicator if required
  3042. if (controls & SC_ToolButtonMenu) {
  3043. if (mflags & (Style_Down | Style_On | Style_Raised)) {
  3044. tqdrawPrimitive(PE_ButtonDropDown, p, menuarea, cg, mflags, opt);
  3045. }
  3046. tqdrawPrimitive(PE_ArrowDown, p, menuarea, cg, mflags, opt);
  3047. }
  3048. if (tb->hasFocus() && !tb->focusProxy()) {
  3049. TQRect fr = tb->rect();
  3050. fr.addCoords(2, 2, -2, -2);
  3051. tqdrawPrimitive(PE_FocusRect, p, fr, cg);
  3052. }
  3053. // Set the color for the ToolButton menu indicator
  3054. p->setPen(cg.buttonText() );
  3055. break;
  3056. }
  3057. // SPINWIDGETS
  3058. // -----------
  3059. case CC_SpinWidget: {
  3060. static const unsigned int handleWidth = 15;
  3061. const TQSpinWidget *sw = dynamic_cast<const TQSpinWidget *>(widget);
  3062. SFlags sflags = flags;
  3063. PrimitiveElement pe;
  3064. bool hasFocus = false;
  3065. if (sw)
  3066. hasFocus = sw->hasFocus();
  3067. const TQColor buttonColor = enabled?cg.button():cg.background();
  3068. const TQColor inputColor = enabled?cg.base():cg.background();
  3069. // contour
  3070. const bool heightDividable = ((r.height()%2) == 0);
  3071. if (_inputFocusHighlight && hasFocus && enabled)
  3072. {
  3073. TQRect editField = querySubControlMetrics(control, widget, SC_SpinWidgetEditField);
  3074. TQRect editFrame = r;
  3075. TQRect buttonFrame = r;
  3076. uint editFlags = 0;
  3077. uint buttonFlags = 0;
  3078. // Hightlight only the part of the contour next to the control buttons
  3079. if (reverseLayout)
  3080. {
  3081. // querySubControlMetrics doesn't work right for reverse Layout
  3082. int dx = r.right() - editField.right();
  3083. editFrame.setLeft(editFrame.left() + dx);
  3084. buttonFrame.setRight(editFrame.left() - 1);
  3085. editFlags |= Draw_Right|Draw_Top|Draw_Bottom|Round_UpperRight|Round_BottomRight;
  3086. buttonFlags |= Draw_Left|Draw_Top|Draw_Bottom|Round_UpperLeft|Round_BottomLeft;
  3087. }
  3088. else
  3089. {
  3090. editFrame.setRight(editField.right());
  3091. buttonFrame.setLeft(editField.right() + 1);
  3092. editFlags |= Draw_Left|Draw_Top|Draw_Bottom|Round_UpperLeft|Round_BottomLeft;
  3093. buttonFlags |= Draw_Right|Draw_Top|Draw_Bottom|Round_UpperRight|Round_BottomRight;
  3094. }
  3095. renderContour(p, editFrame, cg.background(), cg.highlight(), editFlags);
  3096. renderContour(p, buttonFrame, cg.background(),
  3097. getColor(cg, ButtonContour, enabled), buttonFlags);
  3098. }
  3099. else
  3100. {
  3101. renderContour(p, querySubControlMetrics(control, widget, SC_SpinWidgetFrame),
  3102. cg.background(), getColor(cg, ButtonContour, enabled) );
  3103. }
  3104. p->setPen(alphaBlendColors(cg.background(), getColor(cg, ButtonContour, enabled), 50) );
  3105. p->drawLine(reverseLayout?r.left()+1+handleWidth:r.right()-handleWidth-1, r.top()+1,
  3106. reverseLayout?r.left()+1+handleWidth:r.right()-handleWidth-1, r.bottom()-1);
  3107. p->drawLine(reverseLayout?r.left()+1:r.right()-handleWidth, r.top()+1+(r.height()-2)/2,
  3108. reverseLayout?r.left()+handleWidth:r.right()-1, r.top()+1+(r.height()-2)/2);
  3109. if(heightDividable)
  3110. p->drawLine(reverseLayout?r.left()+1:r.right()-handleWidth, r.top()+1+(r.height()-2)/2-1,
  3111. reverseLayout?r.left()+handleWidth:r.right()-1, r.top()+1+(r.height()-2)/2-1);
  3112. // surface
  3113. TQRect upRect = TQRect(reverseLayout?r.left()+1:r.right()-handleWidth, r.top()+1,
  3114. handleWidth, (r.height()-2)/2);
  3115. TQRect downRect = TQRect(reverseLayout?r.left()+1:r.right()-handleWidth,
  3116. heightDividable?r.top()+1+((r.height()-2)/2):r.top()+1+((r.height()-2)/2)+1,
  3117. handleWidth, ((r.height()-2)/2) );
  3118. if(heightDividable) {
  3119. upRect = TQRect(upRect.left(), upRect.top(), upRect.width(), upRect.height()-1 );
  3120. downRect = TQRect(downRect.left(), downRect.top()+1, downRect.width(), downRect.height()-1 );
  3121. }
  3122. uint surfaceFlags = Draw_Left|Draw_Right|Draw_Top|Draw_Bottom|Is_Horizontal;
  3123. if(reverseLayout) {
  3124. surfaceFlags |= Round_UpperLeft;
  3125. } else {
  3126. surfaceFlags |= Round_UpperRight;
  3127. }
  3128. if ((widget == hoverWidget) || (sflags & Style_MouseOver)) {
  3129. surfaceFlags |= Is_Highlight;
  3130. surfaceFlags |= Highlight_Top|Highlight_Left|Highlight_Right;
  3131. }
  3132. if (active==SC_SpinWidgetUp) surfaceFlags|=Is_Sunken;
  3133. if(!enabled) surfaceFlags|=Is_Disabled;
  3134. renderSurface(p, upRect, cg.background(), buttonColor, getColor(cg,MouseOverHighlight),
  3135. _contrast, surfaceFlags);
  3136. surfaceFlags = Draw_Left|Draw_Right|Draw_Top|Draw_Bottom|Is_Horizontal;
  3137. if(reverseLayout) {
  3138. surfaceFlags |= Round_BottomLeft;
  3139. } else {
  3140. surfaceFlags |= Round_BottomRight;
  3141. }
  3142. if ((widget == hoverWidget) || (sflags & Style_MouseOver)) {
  3143. surfaceFlags |= Is_Highlight;
  3144. surfaceFlags |= Highlight_Bottom|Highlight_Left|Highlight_Right;
  3145. }
  3146. if (active==SC_SpinWidgetDown) surfaceFlags|=Is_Sunken;
  3147. if(!enabled) surfaceFlags|=Is_Disabled;
  3148. renderSurface(p, downRect, cg.background(), buttonColor, getColor(cg,MouseOverHighlight),
  3149. _contrast, surfaceFlags);
  3150. // icons...
  3151. sflags = Style_Default | Style_Enabled;
  3152. if (active == SC_SpinWidgetUp) {
  3153. sflags |= Style_On;
  3154. sflags |= Style_Sunken;
  3155. } else
  3156. sflags |= Style_Raised;
  3157. if (sw->buttonSymbols() == TQSpinWidget::PlusMinus)
  3158. pe = PE_SpinWidgetPlus;
  3159. else
  3160. pe = PE_SpinWidgetUp;
  3161. p->setPen(cg.foreground());
  3162. tqdrawPrimitive(pe, p, upRect, cg, sflags);
  3163. sflags = Style_Default | Style_Enabled;
  3164. if (active == SC_SpinWidgetDown) {
  3165. sflags |= Style_On;
  3166. sflags |= Style_Sunken;
  3167. } else
  3168. sflags |= Style_Raised;
  3169. if (sw->buttonSymbols() == TQSpinWidget::PlusMinus)
  3170. pe = PE_SpinWidgetMinus;
  3171. else
  3172. pe = PE_SpinWidgetDown;
  3173. p->setPen(cg.foreground());
  3174. tqdrawPrimitive(pe, p, downRect, cg, sflags);
  3175. // thin frame around the input area
  3176. const TQRect Rcontent = TQRect(reverseLayout?r.left()+1+handleWidth+1:r.left()+1, r.top()+1,
  3177. r.width()-1-2-handleWidth, r.height()-2);
  3178. if (_inputFocusHighlight && hasFocus && enabled)
  3179. {
  3180. p->setPen( getColor(cg,FocusHighlight).dark(130) );
  3181. }
  3182. else
  3183. {
  3184. p->setPen(inputColor.dark(130) );
  3185. }
  3186. p->drawLine(Rcontent.left(), reverseLayout?Rcontent.top():Rcontent.top()+1,
  3187. Rcontent.left(), reverseLayout?Rcontent.bottom():Rcontent.bottom()-1 );
  3188. p->drawLine(Rcontent.left()+1, Rcontent.top(),
  3189. reverseLayout?Rcontent.right()-1:Rcontent.right(), Rcontent.top() );
  3190. if (_inputFocusHighlight && hasFocus && enabled)
  3191. {
  3192. p->setPen( getColor(cg,FocusHighlight).light(130) );
  3193. }
  3194. else
  3195. {
  3196. p->setPen(inputColor.light(130) );
  3197. }
  3198. p->drawLine(Rcontent.left()+1, Rcontent.bottom(), Rcontent.right()-1, Rcontent.bottom() );
  3199. p->drawLine(Rcontent.right(), Rcontent.top()+1,
  3200. Rcontent.right(), reverseLayout?Rcontent.bottom()-1:Rcontent.bottom() );
  3201. break;
  3202. }
  3203. default:
  3204. KStyle::tqdrawComplexControl(control, p, widget,
  3205. r, cg, flags, controls,
  3206. active, opt);
  3207. break;
  3208. }
  3209. }
  3210. TQRect LipstikStyle::subRect(SubRect r, const TQWidget *widget) const
  3211. {
  3212. switch (r) {
  3213. case SR_ComboBoxFocusRect: {
  3214. return querySubControlMetrics( CC_ComboBox, widget, SC_ComboBoxEditField );
  3215. }
  3216. // Don't use KStyles progressbar subrect
  3217. // TODO:
  3218. case SR_ProgressBarGroove: {
  3219. return TQRect(widget->rect());
  3220. }
  3221. case SR_ProgressBarContents:
  3222. case SR_ProgressBarLabel: {
  3223. TQRect rw = widget->rect();
  3224. return TQRect(rw.left()+2, rw.top()+2, rw.width()-4, rw.height()-4 );
  3225. }
  3226. default: {
  3227. return KStyle::subRect(r, widget);
  3228. }
  3229. }
  3230. }
  3231. TQRect LipstikStyle::querySubControlMetrics(ComplexControl control,
  3232. const TQWidget *widget,
  3233. SubControl subcontrol,
  3234. const TQStyleOption &opt) const
  3235. {
  3236. if (!widget) {
  3237. return TQRect();
  3238. }
  3239. TQRect r(widget->rect());
  3240. switch (control) {
  3241. case CC_ComboBox: {
  3242. switch (subcontrol) {
  3243. case SC_ComboBoxEditField: {
  3244. // TODO: is the handler width in pixelmetric?
  3245. return TQRect(r.left()+2, r.top()+2, r.width()-4-15-1, r.height()-4);
  3246. }
  3247. default: {
  3248. return KStyle::querySubControlMetrics(control, widget, subcontrol, opt);
  3249. }
  3250. }
  3251. break;
  3252. }
  3253. case CC_SpinWidget: {
  3254. const int fw = 2; // Frame width...
  3255. const bool heightDividable = ((r.height()%2) == 0);
  3256. TQSize bs;
  3257. if(heightDividable) {
  3258. bs.setHeight(TQMAX(8, (r.height()-2)/2));
  3259. } else {
  3260. bs.setHeight(TQMAX(8, (r.height()-2-1)/2));
  3261. }
  3262. bs.setWidth(15);
  3263. const int buttonsLeft = /*reverseLayout?r.left()+1:*/r.right()-bs.width();
  3264. switch (subcontrol) {
  3265. case SC_SpinWidgetUp: {
  3266. return TQRect(buttonsLeft, r.top()+1, bs.width(), bs.height() );
  3267. }
  3268. case SC_SpinWidgetDown: {
  3269. if(heightDividable) {
  3270. return TQRect(buttonsLeft, r.top()+1+bs.height(),
  3271. bs.width(), r.height()-(bs.height()+2) );
  3272. } else {
  3273. return TQRect(buttonsLeft, r.top()+1+bs.height()+1,
  3274. bs.width(), r.height()-(bs.height()+2+1) );
  3275. }
  3276. }
  3277. case SC_SpinWidgetFrame: {
  3278. return TQRect(r.left(), r.top(), r.width(), r.height() );
  3279. }
  3280. case SC_SpinWidgetEditField: {
  3281. return TQRect(r.left()+fw, r.top()+fw,
  3282. r.width()-(bs.width()+1+2*fw), r.height()-2*fw);
  3283. }
  3284. case SC_SpinWidgetButtonField: {
  3285. return TQRect(buttonsLeft, r.top()+1, bs.width(), r.height()-2);
  3286. }
  3287. default: {
  3288. return KStyle::querySubControlMetrics(control, widget, subcontrol, opt);
  3289. }
  3290. }
  3291. break;
  3292. }
  3293. default: {
  3294. return KStyle::querySubControlMetrics(control, widget, subcontrol, opt);
  3295. }
  3296. }
  3297. }
  3298. int LipstikStyle::tqpixelMetric(PixelMetric m, const TQWidget *widget) const
  3299. {
  3300. switch(m) {
  3301. // TABS
  3302. // ----
  3303. case PM_TabBarTabVSpace: {
  3304. const TQTabBar * tb = (const TQTabBar *) widget;
  3305. if (tb->tqshape() == TQTabBar::RoundedAbove ||
  3306. tb->tqshape() == TQTabBar::RoundedBelow)
  3307. return 12;
  3308. else
  3309. return 4;
  3310. }
  3311. case PM_TabBarTabOverlap: {
  3312. return 1;
  3313. }
  3314. // extra space between menubar items
  3315. case PM_MenuBarItemSpacing: {
  3316. return 3 + _menuSpacing;
  3317. }
  3318. // // extra space between toolbar items
  3319. // // causes weird bugs...
  3320. // case PM_ToolBarItemSpacing: {
  3321. // return 4;
  3322. // }
  3323. // SCROLL BAR
  3324. case PM_ScrollBarSliderMin: {
  3325. return 26;
  3326. }
  3327. case PM_ScrollBarExtent: {
  3328. if (_scrollBarWidth == "Small" ) {
  3329. return 14;
  3330. } else if (_scrollBarWidth == "Normal" ) {
  3331. return 16;
  3332. } else {
  3333. return 18;
  3334. }
  3335. }
  3336. case PM_DockWindowSeparatorExtent:
  3337. return 6;
  3338. // SPLITTERS
  3339. // ---------
  3340. case PM_SplitterWidth: {
  3341. return 6;
  3342. }
  3343. // PROGRESSBARS
  3344. // ------------
  3345. case PM_ProgressBarChunkWidth:
  3346. return 10;
  3347. // SLIDER
  3348. // ------
  3349. case PM_SliderLength:
  3350. {
  3351. if (_sliderStyle == "sliderLipstikStyle" ) {
  3352. return 20;
  3353. } else if (_sliderStyle == "sliderPlastikStyle" ) {
  3354. return 11;
  3355. } else {
  3356. return 33;
  3357. }
  3358. }
  3359. // MENU INDICATOR
  3360. // --------------
  3361. case PM_MenuButtonIndicator:
  3362. return 8;
  3363. // CHECKBOXES / RADIO BUTTONS
  3364. // --------------------------
  3365. case PM_ExclusiveIndicatorWidth: // Radiobutton size
  3366. case PM_ExclusiveIndicatorHeight: // 13x13
  3367. case PM_IndicatorWidth: // Checkbox size
  3368. case PM_IndicatorHeight: // 13x13
  3369. return 13;
  3370. // FRAMES
  3371. // ------
  3372. case PM_SpinBoxFrameWidth:
  3373. return 1;
  3374. case PM_MenuBarFrameWidth:
  3375. return 1;
  3376. case PM_DefaultFrameWidth: {
  3377. if(widget && ::tqqt_cast<TQPopupMenu*>(widget))
  3378. return 1;
  3379. else
  3380. return 2;
  3381. }
  3382. case PM_ButtonDefaultIndicator: {
  3383. return 0;
  3384. }
  3385. case PM_ButtonMargin: {
  3386. return 2;
  3387. }
  3388. case PM_ButtonShiftVertical:
  3389. case PM_ButtonShiftHorizontal: {
  3390. return 1;
  3391. }
  3392. default:
  3393. return KStyle::tqpixelMetric(m, widget);
  3394. }
  3395. }
  3396. TQSize LipstikStyle::tqsizeFromContents(ContentsType t,
  3397. const TQWidget *widget,
  3398. const TQSize &s,
  3399. const TQStyleOption &opt) const
  3400. {
  3401. switch (t) {
  3402. case CT_PopupMenuItem: {
  3403. if (!widget || opt.isDefault())
  3404. return s;
  3405. const TQPopupMenu *popup = dynamic_cast<const TQPopupMenu *>(widget);
  3406. TQMenuItem *mi = opt.menuItem();
  3407. int maxpmw = opt.maxIconWidth();
  3408. int w = s.width(), h = s.height() + _menuSpacing;
  3409. bool checkable = popup->isCheckable();
  3410. if (mi->custom()) {
  3411. w = mi->custom()->tqsizeHint().width();
  3412. h = mi->custom()->tqsizeHint().height();
  3413. if (!mi->custom()->fullSpan() )
  3414. h += 4;
  3415. } else if (mi->widget()) {
  3416. h = h - _menuSpacing;
  3417. } else if (mi->isSeparator()) {
  3418. w = 20;
  3419. h = 2;
  3420. } else {
  3421. if (mi->pixmap()) {
  3422. h = TQMAX(h, mi->pixmap()->height() + 2);
  3423. } else {
  3424. h = TQMAX(h, 16 + 2);
  3425. h = TQMAX(h, popup->fontMetrics().height() + 4 );
  3426. }
  3427. if (mi->iconSet()) {
  3428. h = TQMAX(h, mi->iconSet()->pixmap(TQIconSet::Small, TQIconSet::Normal).height() + 2);
  3429. }
  3430. }
  3431. if (!mi->text().isNull() && (mi->text().find('\t') >= 0)) {
  3432. w += itemHMargin + itemFrame*2 + 7;
  3433. } else if (mi->popup()) {
  3434. w += 2 * arrowHMargin;
  3435. }
  3436. if (maxpmw) {
  3437. w += maxpmw + 6;
  3438. }
  3439. if (checkable && maxpmw < 20) {
  3440. w += 20 - maxpmw;
  3441. }
  3442. if (checkable || maxpmw > 0) {
  3443. w += 12;
  3444. }
  3445. w += rightBorder;
  3446. return TQSize(w, h);
  3447. }
  3448. case CT_PushButton:
  3449. {
  3450. const TQPushButton* btn = static_cast<const TQPushButton*>(widget);
  3451. int w = s.width() + 2 * tqpixelMetric(PM_ButtonMargin, widget);
  3452. int h = s.height() + 2 * tqpixelMetric(PM_ButtonMargin, widget);
  3453. if ( btn->text().isEmpty() && s.width() < 32 ) return TQSize(w, h);
  3454. return TQSize( w+25, h+5 );
  3455. }
  3456. case CT_ToolButton:
  3457. {
  3458. if(widget->parent() && ::tqqt_cast<TQToolBar*>(widget->parent()) )
  3459. return TQSize( s.width()+2*4+_toolBarSpacing, s.height()+2*4 );
  3460. else
  3461. return KStyle::tqsizeFromContents (t, widget, s, opt);
  3462. }
  3463. default:
  3464. return KStyle::tqsizeFromContents (t, widget, s, opt);
  3465. }
  3466. return KStyle::tqsizeFromContents (t, widget, s, opt);
  3467. }
  3468. int LipstikStyle::tqstyleHint( StyleHint stylehint,
  3469. const TQWidget *widget,
  3470. const TQStyleOption &option,
  3471. TQStyleHintReturn* returnData ) const
  3472. {
  3473. switch (stylehint) {
  3474. case SH_PopupMenu_SubMenuPopupDelay:
  3475. return 96; // Motif-like delay...
  3476. default:
  3477. return KStyle::tqstyleHint(stylehint, widget, option, returnData);
  3478. }
  3479. }
  3480. bool LipstikStyle::eventFilter(TQObject *obj, TQEvent *ev)
  3481. {
  3482. if (KStyle::eventFilter(obj, ev) )
  3483. return true;
  3484. if (!obj->isWidgetType() ) return false;
  3485. // focus highlight
  3486. if ( ::tqqt_cast<TQLineEdit*>(obj) ) {
  3487. TQWidget* widget = TQT_TQWIDGET(obj);
  3488. if ( ::tqqt_cast<TQSpinWidget*>(widget->parentWidget()) )
  3489. {
  3490. TQWidget* spinbox = widget->parentWidget();
  3491. if ((ev->type() == TQEvent::FocusIn) || (ev->type() == TQEvent::FocusOut))
  3492. {
  3493. spinbox->tqrepaint(false);
  3494. }
  3495. return false;
  3496. }
  3497. if ((ev->type() == TQEvent::FocusIn) || (ev->type() == TQEvent::FocusOut))
  3498. {
  3499. widget->tqrepaint(false);
  3500. }
  3501. return false;
  3502. }
  3503. //Hover highlight... use qt_cast to check if the widget inheits one of the classes.
  3504. if ( ::tqqt_cast<TQPushButton*>(obj) || ::tqqt_cast<TQComboBox*>(obj) ||
  3505. ::tqqt_cast<TQSpinWidget*>(obj) || ::tqqt_cast<TQCheckBox*>(obj) ||
  3506. ::tqqt_cast<TQRadioButton*>(obj) || ::tqqt_cast<TQToolButton*>(obj) ||
  3507. ::tqqt_cast<TQSlider*>(obj) || ::tqqt_cast<TQScrollBar*>(obj) ||
  3508. obj->inherits(TQDOCKWINDOWHANDLE_OBJECT_NAME_STRING) || obj->inherits(TQSPLITTERHANDLE_OBJECT_NAME_STRING) )
  3509. {
  3510. if ((ev->type() == TQEvent::Enter) && TQT_TQWIDGET(obj)->isEnabled())
  3511. {
  3512. TQWidget* button = TQT_TQWIDGET(obj);
  3513. hoverWidget = button;
  3514. button->tqrepaint(false);
  3515. }
  3516. else if ((ev->type() == TQEvent::Leave) && (TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(hoverWidget)) )
  3517. {
  3518. TQWidget* button = TQT_TQWIDGET(obj);
  3519. hoverWidget = 0;
  3520. button->tqrepaint(false);
  3521. }
  3522. return false;
  3523. }
  3524. if ( ::tqqt_cast<TQTabBar*>(obj) ) {
  3525. if ((ev->type() == TQEvent::Enter) && TQT_TQWIDGET(obj)->isEnabled())
  3526. {
  3527. TQWidget* tabbar = TQT_TQWIDGET(obj);
  3528. hoverWidget = tabbar;
  3529. hoverTab = 0;
  3530. tabbar->tqrepaint(false);
  3531. }
  3532. else if (ev->type() == TQEvent::MouseMove)
  3533. {
  3534. TQTabBar *tabbar = dynamic_cast<TQTabBar*>(obj);
  3535. TQMouseEvent *me = dynamic_cast<TQMouseEvent*>(ev);
  3536. if (tabbar && me) {
  3537. // avoid unnecessary repaints (which otherwise would occour on every
  3538. // MouseMove event causing high cpu load).
  3539. bool tqrepaint = true;
  3540. TQTab *tab = tabbar->selectTab(me->pos() );
  3541. if (hoverTab == tab)
  3542. tqrepaint = false;
  3543. hoverTab = tab;
  3544. if (tqrepaint)
  3545. tabbar->tqrepaint(false);
  3546. }
  3547. }
  3548. else if (ev->type() == TQEvent::Leave)
  3549. {
  3550. TQWidget* tabbar = TQT_TQWIDGET(obj);
  3551. hoverWidget = 0;
  3552. hoverTab = 0;
  3553. tabbar->tqrepaint(false);
  3554. }
  3555. return false;
  3556. }
  3557. // Track show events for progress bars
  3558. if ( _animateProgressBar && ::tqqt_cast<TQProgressBar*>(obj) )
  3559. {
  3560. if ((ev->type() == TQEvent::Show) && !animationTimer->isActive())
  3561. {
  3562. animationTimer->start( 50, false );
  3563. }
  3564. }
  3565. if ( !qstrcmp(obj->name(), "kde toolbar widget") )
  3566. {
  3567. TQWidget* lb = TQT_TQWIDGET(obj);
  3568. if (lb->backgroundMode() == TQt::PaletteButton)
  3569. lb->setBackgroundMode(TQt::PaletteBackground);
  3570. lb->removeEventFilter(this);
  3571. }
  3572. return false;
  3573. }
  3574. TQColor LipstikStyle::getColor(const TQColorGroup &cg, const ColorType t, const bool enabled)const
  3575. {
  3576. return getColor(cg, t, enabled?IsEnabled:IsDisabled);
  3577. }
  3578. TQColor LipstikStyle::getColor(const TQColorGroup &cg, const ColorType t, const WidgetState s)const
  3579. {
  3580. const bool enabled = (s != IsDisabled) &&
  3581. ((s == IsEnabled) || (s == IsPressed) || (s == IsHighlighted));
  3582. const bool pressed = (s == IsPressed);
  3583. const bool highlighted = (s == IsHighlighted);
  3584. switch(t) {
  3585. case ButtonContour:
  3586. return enabled ? cg.button().dark(130+_contrast*8)
  3587. : cg.background().dark(120+_contrast*8);
  3588. case DragButtonContour: {
  3589. if(enabled) {
  3590. if(pressed)
  3591. return cg.button().dark(130+_contrast*6); // bright
  3592. else if(highlighted)
  3593. return cg.button().dark(130+_contrast*9); // dark
  3594. else
  3595. return cg.button().dark(130+_contrast*8); // normal
  3596. } else {
  3597. return cg.background().dark(120+_contrast*8);
  3598. }
  3599. }
  3600. case DragButtonSurface: {
  3601. if(enabled) {
  3602. if(pressed)
  3603. return cg.button().dark(100-_contrast); // bright
  3604. else if(highlighted)
  3605. return cg.button().light(100+_contrast); // dark
  3606. else
  3607. return cg.button(); // normal
  3608. } else {
  3609. return cg.background();
  3610. }
  3611. }
  3612. case PanelContour:
  3613. return cg.background().dark(130+_contrast*8);
  3614. case PanelDark:
  3615. return alphaBlendColors(cg.background(), cg.background().dark(100+_contrast*5), 110);
  3616. case PanelDark2:
  3617. return alphaBlendColors(cg.background(), cg.background().dark(90+_contrast*5), 110);
  3618. case PanelLight:
  3619. return alphaBlendColors(cg.background(), cg.background().light(100+_contrast*5), 110);
  3620. case PanelLight2:
  3621. return alphaBlendColors(cg.background(), cg.background().light(90+_contrast*5), 110);
  3622. case MouseOverHighlight:
  3623. if( _customOverHighlightColor )
  3624. return _overHighlightColor;
  3625. else
  3626. return cg.highlight();
  3627. case MenuStripeColor:
  3628. if( _customMenuStripeColor )
  3629. return _menuStripeColor;
  3630. else
  3631. return alphaBlendColors(_defaultMenuStripeColor, cg.background().light(110), 110);
  3632. case FocusHighlight:
  3633. if( _customFocusHighlightColor )
  3634. return _focusHighlightColor;
  3635. else
  3636. return cg.highlight();
  3637. case CheckMark:
  3638. if( _customCheckMarkColor )
  3639. return _checkMarkColor;
  3640. else
  3641. return cg.highlight().dark(130);
  3642. case TabHighlight:
  3643. if( _customTabHighlightColor )
  3644. return _tabHighlightColor;
  3645. else
  3646. return cg.highlight();
  3647. // case Arrows:
  3648. // if( _customArrowColor )
  3649. // return _arrowColor;
  3650. // else
  3651. // return cg.buttonText();
  3652. default:
  3653. return cg.background();
  3654. }
  3655. }