• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdefx
 

tdefx

  • tdefx
tdestyle.cpp
1 /*
2  *
3  * TDEStyle
4  * Copyright (C) 2001-2002 Karol Szwed <gallium@kde.org>
5  *
6  * TQWindowsStyle CC_ListView and style images were kindly donated by TrollTech,
7  * Copyright (C) 1998-2000 TrollTech AS.
8  *
9  * Many thanks to Bradley T. Hughes for the 3 button scrollbar code.
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License version 2 as published by the Free Software Foundation.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public License
21  * along with this library; see the file COPYING.LIB. If not, write to
22  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23  * Boston, MA 02110-1301, USA.
24  */
25 
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29 
30 #include "tdestyle.h"
31 
32 #include <tqapplication.h>
33 #include <tqbitmap.h>
34 #include <tqmetaobject.h>
35 #include <tqcleanuphandler.h>
36 #include <tqmap.h>
37 #include <tqimage.h>
38 #include <tqlistview.h>
39 #include <tqmenubar.h>
40 #include <tqpainter.h>
41 #include <tqpixmap.h>
42 #include <tqpopupmenu.h>
43 #include <tqprogressbar.h>
44 #include <tqscrollbar.h>
45 #include <tqsettings.h>
46 #include <tqslider.h>
47 #include <tqstylefactory.h>
48 #include <tqtabbar.h>
49 #include <tqtoolbar.h>
50 #include <tqframe.h>
51 
52 #include <kpixmap.h>
53 #include <kpixmapeffect.h>
54 #include <kimageeffect.h>
55 
56 #ifdef Q_WS_X11
57 # include <X11/Xlib.h>
58 # ifdef HAVE_XRENDER
59 # include <X11/extensions/Xrender.h> // schroder
60  extern bool tqt_use_xrender;
61 # endif
62 #else
63 #undef HAVE_XRENDER
64 #endif
65 
66 #ifdef HAVE_XCOMPOSITE
67 #include <X11/extensions/Xrender.h>
68 #include <X11/extensions/Xcomposite.h>
69 #include <dlfcn.h>
70 #endif
71 
72 #include <limits.h>
73 
74 namespace
75 {
76  // INTERNAL
77  enum TransparencyEngine {
78  Disabled = 0,
79  SoftwareTint,
80  SoftwareBlend,
81  XRender
82  };
83 
84  // Drop Shadow
85  struct ShadowElements {
86  TQWidget* w1;
87  TQWidget* w2;
88  };
89  typedef TQMap<const TQWidget*,ShadowElements> ShadowMap;
90  static ShadowMap *_shadowMap = 0;
91  TQSingleCleanupHandler<ShadowMap> cleanupShadowMap;
92  ShadowMap &shadowMap() {
93  if ( !_shadowMap ) {
94  _shadowMap = new ShadowMap;
95  cleanupShadowMap.set( &_shadowMap );
96  }
97  return *_shadowMap;
98  }
99 
100 
101  // DO NOT ASK ME HOW I MADE THESE TABLES!
102  // (I probably won't remember anyway ;)
103  const double top_right_corner[16] =
104  { 0.949, 0.965, 0.980, 0.992,
105  0.851, 0.890, 0.945, 0.980,
106  0.706, 0.780, 0.890, 0.960,
107  0.608, 0.706, 0.851, 0.949 };
108 
109  const double bottom_right_corner[16] =
110  { 0.608, 0.706, 0.851, 0.949,
111  0.706, 0.780, 0.890, 0.960,
112  0.851, 0.890, 0.945, 0.980,
113  0.949, 0.965, 0.980, 0.992 };
114 
115  const double bottom_left_corner[16] =
116  { 0.949, 0.851, 0.706, 0.608,
117  0.965, 0.890, 0.780, 0.706,
118  0.980, 0.945, 0.890, 0.851,
119  0.992, 0.980, 0.960, 0.949 };
120 
121  const double shadow_strip[4] =
122  { 0.565, 0.675, 0.835, 0.945 };
123 
124  static bool useDropShadow(TQWidget* w)
125  {
126  return w && w->metaObject() &&
127  w->metaObject()->findProperty("TDEStyleMenuDropShadow") != -1;
128  }
129 }
130 
131 namespace
132 {
133 class TransparencyHandler : public TQObject
134 {
135  public:
136  TransparencyHandler(TDEStyle* style, TransparencyEngine tEngine,
137  float menuOpacity, bool useDropShadow);
138  ~TransparencyHandler();
139  bool eventFilter(TQObject* object, TQEvent* event);
140 
141  protected:
142  void blendToColor(const TQColor &col);
143  void blendToPixmap(const TQColorGroup &cg, const TQWidget* p);
144 #ifdef HAVE_XRENDER
145  void XRenderBlendToPixmap(const TQWidget* p);
146 #endif
147  bool haveX11RGBASupport();
148  TQImage handleRealAlpha(TQImage);
149  void createShadowWindows(const TQWidget* p);
150  void removeShadowWindows(const TQWidget* p);
151  void rightShadow(TQImage& dst);
152  void bottomShadow(TQImage& dst);
153  private:
154  bool dropShadow;
155  float opacity;
156  TQPixmap pix;
157  TDEStyle* kstyle;
158  TransparencyEngine te;
159 };
160 } // namespace
161 
162 struct TDEStylePrivate
163 {
164  bool highcolor : 1;
165  bool useFilledFrameWorkaround : 1;
166  bool etchDisabledText : 1;
167  bool scrollablePopupmenus : 1;
168  bool autoHideAccelerators : 1;
169  bool menuAltKeyNavigation : 1;
170  bool menuDropShadow : 1;
171  bool sloppySubMenus : 1;
172  bool semiTransparentRubberband : 1;
173  int popupMenuDelay;
174  float menuOpacity;
175 
176  TransparencyEngine transparencyEngine;
177  TDEStyle::TDEStyleScrollBarType scrollbarType;
178  TransparencyHandler* menuHandler;
179  TDEStyle::TDEStyleFlags flags;
180 
181  //For KPE_ListViewBranch
182  TQBitmap *verticalLine;
183  TQBitmap *horizontalLine;
184 };
185 
186 // -----------------------------------------------------------------------------
187 
188 
189 TDEStyle::TDEStyle( TDEStyleFlags flags, TDEStyleScrollBarType sbtype )
190  : TQCommonStyle(), d(new TDEStylePrivate)
191 {
192  d->flags = flags;
193  bool useMenuTransparency = (flags & AllowMenuTransparency);
194  d->useFilledFrameWorkaround = (flags & FilledFrameWorkaround);
195  d->scrollbarType = sbtype;
196  d->highcolor = TQPixmap::defaultDepth() > 8;
197 
198  // Read style settings
199  TQSettings settings;
200  d->popupMenuDelay = settings.readNumEntry ("/TDEStyle/Settings/PopupMenuDelay", 250);
201  d->sloppySubMenus = settings.readBoolEntry("/TDEStyle/Settings/SloppySubMenus", false);
202  d->etchDisabledText = settings.readBoolEntry("/TDEStyle/Settings/EtchDisabledText", true);
203  d->menuAltKeyNavigation = settings.readBoolEntry("/TDEStyle/Settings/MenuAltKeyNavigation", true);
204  d->scrollablePopupmenus = settings.readBoolEntry("/TDEStyle/Settings/ScrollablePopupMenus", false);
205  d->autoHideAccelerators = settings.readBoolEntry("/TDEStyle/Settings/AutoHideAccelerators", false);
206  d->menuDropShadow = settings.readBoolEntry("/TDEStyle/Settings/MenuDropShadow", false);
207  d->semiTransparentRubberband = settings.readBoolEntry("/TDEStyle/Settings/SemiTransparentRubberband", false);
208  d->menuHandler = NULL;
209 
210  if (useMenuTransparency) {
211  TQString effectEngine = settings.readEntry("/TDEStyle/Settings/MenuTransparencyEngine", "Disabled");
212 
213 #ifdef HAVE_XRENDER
214  if (effectEngine == "XRender")
215  d->transparencyEngine = XRender;
216 #else
217  if (effectEngine == "XRender")
218  d->transparencyEngine = SoftwareBlend;
219 #endif
220  else if (effectEngine == "SoftwareBlend")
221  d->transparencyEngine = SoftwareBlend;
222  else if (effectEngine == "SoftwareTint")
223  d->transparencyEngine = SoftwareTint;
224  else
225  d->transparencyEngine = Disabled;
226 
227  if (d->transparencyEngine != Disabled) {
228  // Create an instance of the menu transparency handler
229  d->menuOpacity = settings.readDoubleEntry("/TDEStyle/Settings/MenuOpacity", 0.90);
230  d->menuHandler = new TransparencyHandler(this, d->transparencyEngine,
231  d->menuOpacity, d->menuDropShadow);
232  }
233  }
234 
235  d->verticalLine = 0;
236  d->horizontalLine = 0;
237 
238  // Create a transparency handler if only drop shadows are enabled.
239  if (!d->menuHandler && d->menuDropShadow)
240  d->menuHandler = new TransparencyHandler(this, Disabled, 1.0, d->menuDropShadow);
241 }
242 
243 
244 TDEStyle::~TDEStyle()
245 {
246  delete d->verticalLine;
247  delete d->horizontalLine;
248 
249  delete d->menuHandler;
250 
251  d->menuHandler = NULL;
252  delete d;
253 }
254 
255 
256 TQString TDEStyle::defaultStyle()
257 {
258  if (TQPixmap::defaultDepth() > 8)
259  return TQString("plastik");
260  else
261  return TQString("light, 3rd revision");
262 }
263 
264 void TDEStyle::polish( const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, void *ptr )
265 {
266  if (ceData.widgetObjectTypes.contains(TQWIDGET_OBJECT_NAME_STRING)) {
267  TQWidget* widget = reinterpret_cast<TQWidget*>(ptr);
268  if ( d->useFilledFrameWorkaround )
269  {
270  if ( TQFrame *frame = ::tqqt_cast< TQFrame* >( widget ) ) {
271  TQFrame::Shape shape = frame->frameShape();
272  if (shape == TQFrame::ToolBarPanel || shape == TQFrame::MenuBarPanel)
273  widget->installEventFilter(this);
274  }
275  }
276  if (widget->isTopLevel())
277  {
278  if (!d->menuHandler && useDropShadow(widget))
279  d->menuHandler = new TransparencyHandler(this, Disabled, 1.0, false);
280 
281  if (d->menuHandler && useDropShadow(widget))
282  widget->installEventFilter(d->menuHandler);
283  }
284  }
285 }
286 
287 
288 void TDEStyle::unPolish( const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, void *ptr )
289 {
290  if (ceData.widgetObjectTypes.contains(TQWIDGET_OBJECT_NAME_STRING)) {
291  TQWidget* widget = reinterpret_cast<TQWidget*>(ptr);
292  if ( d->useFilledFrameWorkaround )
293  {
294  if ( TQFrame *frame = ::tqqt_cast< TQFrame* >( widget ) ) {
295  TQFrame::Shape shape = frame->frameShape();
296  if (shape == TQFrame::ToolBarPanel || shape == TQFrame::MenuBarPanel)
297  widget->removeEventFilter(this);
298  }
299  }
300  if (widget->isTopLevel() && d->menuHandler && useDropShadow(widget))
301  widget->removeEventFilter(d->menuHandler);
302  }
303 }
304 
305 
306 // Style changes (should) always re-polish popups.
307 void TDEStyle::polishPopupMenu( const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, void *ptr )
308 {
309  if ( !(ceData.windowState & WState_Polished ) ) {
310  widgetActionRequest(ceData, elementFlags, ptr, WAR_SetCheckable);
311  }
312 
313  if (ceData.widgetObjectTypes.contains(TQWIDGET_OBJECT_NAME_STRING)) {
314  TQWidget* widget = reinterpret_cast<TQWidget*>(ptr);
315  TQPopupMenu *p = dynamic_cast<TQPopupMenu*>(widget);
316  if (p) {
317  // Install transparency handler if the effect is enabled.
318  if ( d->menuHandler && (strcmp(p->name(), "tear off menu") != 0)) {
319  p->installEventFilter(d->menuHandler);
320  }
321  }
322  }
323 }
324 
325 
326 // -----------------------------------------------------------------------------
327 // TDEStyle extensions
328 // -----------------------------------------------------------------------------
329 
330 void TDEStyle::setScrollBarType(TDEStyleScrollBarType sbtype)
331 {
332  d->scrollbarType = sbtype;
333 }
334 
335 TDEStyle::TDEStyleFlags TDEStyle::styleFlags() const
336 {
337  return d->flags;
338 }
339 
340 void TDEStyle::renderMenuBlendPixmap( KPixmap &pix, const TQColorGroup &cg,
341  const TQPopupMenu* /* popup */ ) const
342 {
343  pix.fill(cg.button()); // Just tint as the default behavior
344 }
345 
346 void TDEStyle::drawTDEStylePrimitive( TDEStylePrimitive kpe,
347  TQPainter* p,
348  const TQWidget* widget,
349  const TQRect &r,
350  const TQColorGroup &cg,
351  SFlags flags,
352  const TQStyleOption &opt ) const
353 {
354  TQStyleControlElementData ceData = populateControlElementDataFromWidget(widget, TQStyleOption());
355  drawTDEStylePrimitive(kpe, p, ceData, getControlElementFlagsForObject(widget, ceData.widgetObjectTypes, TQStyleOption()), r, cg, flags, opt);
356 }
357 
358 void TDEStyle::drawTDEStylePrimitive( TDEStylePrimitive kpe,
359  TQPainter* p,
360  const TQStyleControlElementData &ceData,
361  ControlElementFlags elementFlags,
362  const TQRect &r,
363  const TQColorGroup &cg,
364  SFlags flags,
365  const TQStyleOption&, /* opt */
366  const TQWidget* widget ) const
367 {
368  switch( kpe )
369  {
370  // Dock / Toolbar / General handles.
371  // ---------------------------------
372 
373  case KPE_DockWindowHandle: {
374 
375  // Draws a nice DockWindow handle including the dock title.
376  TQWidget* wid = const_cast<TQWidget*>(widget);
377  bool horizontal = flags & Style_Horizontal;
378  int x,y,w,h,x2,y2;
379 
380  r.rect( &x, &y, &w, &h );
381  if ((w <= 2) || (h <= 2)) {
382  p->fillRect(r, cg.highlight());
383  return;
384  }
385 
386 
387  x2 = x + w - 1;
388  y2 = y + h - 1;
389 
390  TQFont fnt;
391  fnt = TQApplication::font(wid);
392  fnt.setPointSize( fnt.pointSize()-2 );
393 
394  // Draw the item on an off-screen pixmap
395  // to preserve Xft antialiasing for
396  // vertically oriented handles.
397  TQPixmap pix;
398  if (horizontal)
399  pix.resize( h-2, w-2 );
400  else
401  pix.resize( w-2, h-2 );
402 
403  TQString title = wid->parentWidget()->caption();
404  TQPainter p2;
405  p2.begin(&pix);
406  p2.fillRect(pix.rect(), cg.brush(TQColorGroup::Highlight));
407  p2.setPen(cg.highlightedText());
408  p2.setFont(fnt);
409  p2.drawText(pix.rect(), AlignCenter, title);
410  p2.end();
411 
412  // Draw a sunken bevel
413  p->setPen(cg.dark());
414  p->drawLine(x, y, x2, y);
415  p->drawLine(x, y, x, y2);
416  p->setPen(cg.light());
417  p->drawLine(x+1, y2, x2, y2);
418  p->drawLine(x2, y+1, x2, y2);
419 
420  if (horizontal) {
421  TQWMatrix m;
422  m.rotate(-90.0);
423  TQPixmap vpix = pix.xForm(m);
424  bitBlt(wid, r.x()+1, r.y()+1, &vpix);
425  } else
426  bitBlt(wid, r.x()+1, r.y()+1, &pix);
427 
428  break;
429  }
430 
431 
432  /*
433  * KPE_ListViewExpander and KPE_ListViewBranch are based on code from
434  * QWindowStyle's CC_ListView, kindly donated by TrollTech.
435  * CC_ListView code is Copyright (C) 1998-2000 TrollTech AS.
436  */
437 
438  case KPE_ListViewExpander: {
439  // Typical Windows style expand/collapse element.
440  int radius = (r.width() - 4) / 2;
441  int centerx = r.x() + r.width()/2;
442  int centery = r.y() + r.height()/2;
443 
444  // Outer box
445  p->setPen( cg.mid() );
446  p->drawRect( r );
447 
448  // plus or minus
449  p->setPen( cg.text() );
450  p->drawLine( centerx - radius, centery, centerx + radius, centery );
451  if ( flags & Style_On ) // Collapsed = On
452  p->drawLine( centerx, centery - radius, centerx, centery + radius );
453  break;
454  }
455 
456  case KPE_ListViewBranch: {
457  // Typical Windows style listview branch element (dotted line).
458 
459  // Create the dotline pixmaps if not already created
460  if ( !d->verticalLine )
461  {
462  // make 128*1 and 1*128 bitmaps that can be used for
463  // drawing the right sort of lines.
464  d->verticalLine = new TQBitmap( 1, 129, true );
465  d->horizontalLine = new TQBitmap( 128, 1, true );
466  TQPointArray a( 64 );
467  TQPainter p2;
468  p2.begin( d->verticalLine );
469 
470  int i;
471  for( i=0; i < 64; i++ )
472  a.setPoint( i, 0, i*2+1 );
473  p2.setPen( color1 );
474  p2.drawPoints( a );
475  p2.end();
476  TQApplication::flushX();
477  d->verticalLine->setMask( *d->verticalLine );
478 
479  p2.begin( d->horizontalLine );
480  for( i=0; i < 64; i++ )
481  a.setPoint( i, i*2+1, 0 );
482  p2.setPen( color1 );
483  p2.drawPoints( a );
484  p2.end();
485  TQApplication::flushX();
486  d->horizontalLine->setMask( *d->horizontalLine );
487  }
488 
489  p->setPen( cg.text() ); // cg.dark() is bad for dark color schemes.
490 
491  if (flags & Style_Horizontal)
492  {
493  int point = r.x();
494  int other = r.y();
495  int end = r.x()+r.width();
496  int thickness = r.height();
497 
498  while( point < end )
499  {
500  int i = 128;
501  if ( i+point > end )
502  i = end-point;
503  p->drawPixmap( point, other, *d->horizontalLine, 0, 0, i, thickness );
504  point += i;
505  }
506 
507  } else {
508  int point = r.y();
509  int other = r.x();
510  int end = r.y()+r.height();
511  int thickness = r.width();
512  int pixmapoffset = (flags & Style_NoChange) ? 0 : 1; // ### Hackish
513 
514  while( point < end )
515  {
516  int i = 128;
517  if ( i+point > end )
518  i = end-point;
519  p->drawPixmap( other, point, *d->verticalLine, 0, pixmapoffset, thickness, i );
520  point += i;
521  }
522  }
523 
524  break;
525  }
526 
527  // Reimplement the other primitives in your styles.
528  // The current implementation just paints something visibly different.
529  case KPE_ToolBarHandle:
530  case KPE_GeneralHandle:
531  case KPE_SliderHandle:
532  p->fillRect(r, cg.light());
533  break;
534 
535  case KPE_SliderGroove:
536  p->fillRect(r, cg.dark());
537  break;
538 
539  default:
540  p->fillRect(r, Qt::yellow); // Something really bad happened - highlight.
541  break;
542  }
543 }
544 
545 
546 int TDEStyle::kPixelMetric( TDEStylePixelMetric kpm, const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, const TQWidget* /* widget */) const
547 {
548  int value;
549  switch(kpm)
550  {
551  case KPM_ListViewBranchThickness:
552  value = 1;
553  break;
554 
555  case KPM_MenuItemSeparatorHeight:
556  case KPM_MenuItemHMargin:
557  case KPM_MenuItemVMargin:
558  case KPM_MenuItemHFrame:
559  case KPM_MenuItemVFrame:
560  case KPM_MenuItemCheckMarkHMargin:
561  case KPM_MenuItemArrowHMargin:
562  case KPM_MenuItemTabSpacing:
563  default:
564  value = 0;
565  }
566 
567  return value;
568 }
569 
570 // -----------------------------------------------------------------------------
571 
572 // #ifdef USE_QT4 // tdebindings / smoke needs this function declaration available at all times. Furthermore I don't think it would hurt to have the declaration available at all times...so leave these commented out for now
573 
574 //void TDEStyle::drawPrimitive( TQ_ControlElement pe,
575 // TQPainter* p,
576 // const TQStyleControlElementData &ceData,
577 // ControlElementFlags elementFlags,
578 // const TQRect &r,
579 // const TQColorGroup &cg,
580 // SFlags flags,
581 // const TQStyleOption& opt ) const
582 //{
583 // // FIXME:
584 // // What should "widget" be in actuality? How should I get it? From where?
585 // // Almost certainly it should not be null!
586 // TQWidget *widget = 0;
587 // drawControl(pe, p, ceData, elementFlags, r, cg, flags, opt, widget);
588 //}
589 
590 // #endif // USE_QT4
591 
592 // -----------------------------------------------------------------------------
593 
594 void TDEStyle::drawPrimitive( TQ_PrimitiveElement pe,
595  TQPainter* p,
596  const TQStyleControlElementData &ceData,
597  ControlElementFlags elementFlags,
598  const TQRect &r,
599  const TQColorGroup &cg,
600  SFlags flags,
601  const TQStyleOption& opt ) const
602 {
603  // TOOLBAR/DOCK WINDOW HANDLE
604  // ------------------------------------------------------------------------
605  if (pe == PE_DockWindowHandle)
606  {
607  // Wild workarounds are here. Beware.
608  TQWidget *widget, *parent;
609 
610  if (p && p->device()->devType() == TQInternal::Widget) {
611  widget = static_cast<TQWidget*>(p->device());
612  parent = widget->parentWidget();
613  } else
614  return; // Don't paint on non-widgets
615 
616  // Check if we are a normal toolbar or a hidden dockwidget.
617  if ( parent &&
618  (parent->inherits(TQTOOLBAR_OBJECT_NAME_STRING) || // Normal toolbar
619  (parent->inherits(TQMAINWINDOW_OBJECT_NAME_STRING)) )) // Collapsed dock
620 
621  // Draw a toolbar handle
622  drawTDEStylePrimitive( KPE_ToolBarHandle, p, ceData, elementFlags, r, cg, flags, opt, widget );
623 
624  else if (ceData.widgetObjectTypes.contains(TQDOCKWINDOWHANDLE_OBJECT_NAME_STRING))
625 
626  // Draw a dock window handle
627  drawTDEStylePrimitive( KPE_DockWindowHandle, p, ceData, elementFlags, r, cg, flags, opt, widget );
628 
629  else
630  // General handle, probably a kicker applet handle.
631  drawTDEStylePrimitive( KPE_GeneralHandle, p, ceData, elementFlags, r, cg, flags, opt, widget );
632 #if TQT_VERSION >= 0x030300
633 #ifdef HAVE_XRENDER
634  } else if ( d->semiTransparentRubberband && pe == TQStyle::PE_RubberBand ) {
635  TQRect rect = r.normalize();
636  TQPoint point;
637  point = p->xForm( point );
638 
639  static XRenderColor clr = { 0, 0, 0, 0 };
640  static unsigned long fillColor = 0;
641  if ( fillColor != cg.highlight().rgb() ) {
642  fillColor = cg.highlight().rgb();
643 
644  unsigned long color = fillColor << 8 | 0x40;
645 
646  int red = (color >> 24) & 0xff;
647  int green = (color >> 16) & 0xff;
648  int blue = (color >> 8) & 0xff;
649  int alpha = (color >> 0) & 0xff;
650 
651  red = red * alpha / 255;
652  green = green * alpha / 255;
653  blue = blue * alpha / 255;
654 
655  clr.red = (red << 8) + red;
656  clr.green = (green << 8) + green;
657  clr.blue = (blue << 8) + blue;
658  clr.alpha = (alpha << 8) + alpha;
659  }
660 
661  XRenderFillRectangle(
662  p->device()->x11Display(),
663  PictOpOver,
664  p->device()->x11RenderHandle(),
665  &clr,
666  rect.x() + point.x(),
667  rect.y() + point.y(),
668  rect.width(),
669  rect.height() );
670 
671  p->save();
672  p->setRasterOp( TQt::CopyROP );
673  p->setPen( TQPen( cg.highlight().dark( 160 ), 1 ) );
674  p->setBrush( NoBrush );
675  p->drawRect(
676  rect.x() + point.x(),
677  rect.y() + point.y(),
678  rect.width(),
679  rect.height() );
680  p->restore();
681 #endif
682 #endif
683  } else
684  TQCommonStyle::drawPrimitive( pe, p, ceData, elementFlags, r, cg, flags, opt );
685 }
686 
687 
688 
689 void TDEStyle::drawControl( TQ_ControlElement element,
690  TQPainter* p,
691  const TQStyleControlElementData &ceData,
692  ControlElementFlags elementFlags,
693  const TQRect &r,
694  const TQColorGroup &cg,
695  SFlags flags,
696  const TQStyleOption &opt,
697  const TQWidget* widget ) const
698 {
699  switch (element)
700  {
701  // TABS
702  // ------------------------------------------------------------------------
703  case CE_TabBarTab: {
704  TQTabBar::Shape tbs = ceData.tabBarData.shape;
705  bool selected = flags & Style_Selected;
706  int x = r.x(), y=r.y(), bottom=r.bottom(), right=r.right();
707 
708  switch (tbs) {
709 
710  case TQTabBar::RoundedAbove: {
711  if (!selected)
712  p->translate(0,1);
713  p->setPen(selected ? cg.light() : cg.shadow());
714  p->drawLine(x, y+4, x, bottom);
715  p->drawLine(x, y+4, x+4, y);
716  p->drawLine(x+4, y, right-1, y);
717  if (selected)
718  p->setPen(cg.shadow());
719  p->drawLine(right, y+1, right, bottom);
720 
721  p->setPen(cg.midlight());
722  p->drawLine(x+1, y+4, x+1, bottom);
723  p->drawLine(x+1, y+4, x+4, y+1);
724  p->drawLine(x+5, y+1, right-2, y+1);
725 
726  if (selected) {
727  p->setPen(cg.mid());
728  p->drawLine(right-1, y+1, right-1, bottom);
729  } else {
730  p->setPen(cg.mid());
731  p->drawPoint(right-1, y+1);
732  p->drawLine(x+4, y+2, right-1, y+2);
733  p->drawLine(x+3, y+3, right-1, y+3);
734  p->fillRect(x+2, y+4, r.width()-3, r.height()-6, cg.mid());
735 
736  p->setPen(cg.light());
737  p->drawLine(x, bottom-1, right, bottom-1);
738  p->translate(0,-1);
739  }
740  break;
741  }
742 
743  case TQTabBar::RoundedBelow: {
744  if (!selected)
745  p->translate(0,-1);
746  p->setPen(selected ? cg.light() : cg.shadow());
747  p->drawLine(x, bottom-4, x, y);
748  if (selected)
749  p->setPen(cg.mid());
750  p->drawLine(x, bottom-4, x+4, bottom);
751  if (selected)
752  p->setPen(cg.shadow());
753  p->drawLine(x+4, bottom, right-1, bottom);
754  p->drawLine(right, bottom-1, right, y);
755 
756  p->setPen(cg.midlight());
757  p->drawLine(x+1, bottom-4, x+1, y);
758  p->drawLine(x+1, bottom-4, x+4, bottom-1);
759  p->drawLine(x+5, bottom-1, right-2, bottom-1);
760 
761  if (selected) {
762  p->setPen(cg.mid());
763  p->drawLine(right-1, y, right-1, bottom-1);
764  } else {
765  p->setPen(cg.mid());
766  p->drawPoint(right-1, bottom-1);
767  p->drawLine(x+4, bottom-2, right-1, bottom-2);
768  p->drawLine(x+3, bottom-3, right-1, bottom-3);
769  p->fillRect(x+2, y+2, r.width()-3, r.height()-6, cg.mid());
770  p->translate(0,1);
771  p->setPen(cg.dark());
772  p->drawLine(x, y, right, y);
773  }
774  break;
775  }
776 
777  case TQTabBar::TriangularAbove: {
778  if (!selected)
779  p->translate(0,1);
780  p->setPen(selected ? cg.light() : cg.shadow());
781  p->drawLine(x, bottom, x, y+6);
782  p->drawLine(x, y+6, x+6, y);
783  p->drawLine(x+6, y, right-6, y);
784  if (selected)
785  p->setPen(cg.mid());
786  p->drawLine(right-5, y+1, right-1, y+5);
787  p->setPen(cg.shadow());
788  p->drawLine(right, y+6, right, bottom);
789 
790  p->setPen(cg.midlight());
791  p->drawLine(x+1, bottom, x+1, y+6);
792  p->drawLine(x+1, y+6, x+6, y+1);
793  p->drawLine(x+6, y+1, right-6, y+1);
794  p->drawLine(right-5, y+2, right-2, y+5);
795  p->setPen(cg.mid());
796  p->drawLine(right-1, y+6, right-1, bottom);
797 
798  TQPointArray a(6);
799  a.setPoint(0, x+2, bottom);
800  a.setPoint(1, x+2, y+7);
801  a.setPoint(2, x+7, y+2);
802  a.setPoint(3, right-7, y+2);
803  a.setPoint(4, right-2, y+7);
804  a.setPoint(5, right-2, bottom);
805  p->setPen (selected ? cg.background() : cg.mid());
806  p->setBrush(selected ? cg.background() : cg.mid());
807  p->drawPolygon(a);
808  p->setBrush(NoBrush);
809  if (!selected) {
810  p->translate(0,-1);
811  p->setPen(cg.light());
812  p->drawLine(x, bottom, right, bottom);
813  }
814  break;
815  }
816 
817  default: { // TQTabBar::TriangularBelow
818  if (!selected)
819  p->translate(0,-1);
820  p->setPen(selected ? cg.light() : cg.shadow());
821  p->drawLine(x, y, x, bottom-6);
822  if (selected)
823  p->setPen(cg.mid());
824  p->drawLine(x, bottom-6, x+6, bottom);
825  if (selected)
826  p->setPen(cg.shadow());
827  p->drawLine(x+6, bottom, right-6, bottom);
828  p->drawLine(right-5, bottom-1, right-1, bottom-5);
829  if (!selected)
830  p->setPen(cg.shadow());
831  p->drawLine(right, bottom-6, right, y);
832 
833  p->setPen(cg.midlight());
834  p->drawLine(x+1, y, x+1, bottom-6);
835  p->drawLine(x+1, bottom-6, x+6, bottom-1);
836  p->drawLine(x+6, bottom-1, right-6, bottom-1);
837  p->drawLine(right-5, bottom-2, right-2, bottom-5);
838  p->setPen(cg.mid());
839  p->drawLine(right-1, bottom-6, right-1, y);
840 
841  TQPointArray a(6);
842  a.setPoint(0, x+2, y);
843  a.setPoint(1, x+2, bottom-7);
844  a.setPoint(2, x+7, bottom-2);
845  a.setPoint(3, right-7, bottom-2);
846  a.setPoint(4, right-2, bottom-7);
847  a.setPoint(5, right-2, y);
848  p->setPen (selected ? cg.background() : cg.mid());
849  p->setBrush(selected ? cg.background() : cg.mid());
850  p->drawPolygon(a);
851  p->setBrush(NoBrush);
852  if (!selected) {
853  p->translate(0,1);
854  p->setPen(cg.dark());
855  p->drawLine(x, y, right, y);
856  }
857  break;
858  }
859  };
860 
861  break;
862  }
863 
864  // Popup menu scroller
865  // ------------------------------------------------------------------------
866  case CE_PopupMenuScroller: {
867  p->fillRect(r, cg.background());
868  drawPrimitive(PE_ButtonTool, p, ceData, elementFlags, r, cg, Style_Enabled);
869  drawPrimitive((flags & Style_Up) ? PE_ArrowUp : PE_ArrowDown, p, ceData, elementFlags, r, cg, Style_Enabled);
870  break;
871  }
872 
873 
874  // PROGRESSBAR
875  // ------------------------------------------------------------------------
876  case CE_ProgressBarGroove: {
877  TQRect fr = subRect(SR_ProgressBarGroove, ceData, elementFlags, widget);
878  drawPrimitive(PE_Panel, p, ceData, elementFlags, fr, cg, Style_Sunken, TQStyleOption::SO_Default);
879  break;
880  }
881 
882  case CE_ProgressBarContents: {
883  // ### Take into account totalSteps() for busy indicator
884  TQRect cr = subRect(SR_ProgressBarContents, ceData, elementFlags, widget);
885  double progress = ceData.currentStep;
886  bool reverse = TQApplication::reverseLayout();
887  int steps = ceData.totalSteps;
888 
889  if (!cr.isValid())
890  return;
891 
892  // Draw progress bar
893  if (progress > 0 || steps == 0) {
894  double pg = (steps == 0) ? 0.1 : progress / steps;
895  int width = QMIN(cr.width(), (int)(pg * cr.width()));
896  if (steps == 0) { //Busy indicator
897 
898  if (width < 1) width = 1; //A busy indicator with width 0 is kind of useless
899 
900  int remWidth = cr.width() - width; //Never disappear completely
901  if (remWidth <= 0) remWidth = 1; //Do something non-crashy when too small...
902 
903  int pstep = int(progress) % ( 2 * remWidth );
904 
905  if ( pstep > remWidth ) {
906  //Bounce about.. We're remWidth + some delta, we want to be remWidth - delta...
907  // - ( (remWidth + some delta) - 2* remWidth ) = - (some deleta - remWidth) = remWidth - some delta..
908  pstep = - (pstep - 2 * remWidth );
909  }
910 
911  if (reverse)
912  p->fillRect(cr.x() + cr.width() - width - pstep, cr.y(), width, cr.height(),
913  cg.brush(TQColorGroup::Highlight));
914  else
915  p->fillRect(cr.x() + pstep, cr.y(), width, cr.height(),
916  cg.brush(TQColorGroup::Highlight));
917 
918  return;
919  }
920 
921 
922  // Do fancy gradient for highcolor displays
923  if (d->highcolor) {
924  TQColor c(cg.highlight());
925  KPixmap pix;
926  pix.resize(cr.width(), cr.height());
927  KPixmapEffect::gradient(pix, reverse ? c.light(150) : c.dark(150),
928  reverse ? c.dark(150) : c.light(150),
929  KPixmapEffect::HorizontalGradient);
930  if (reverse)
931  p->drawPixmap(cr.x()+(cr.width()-width), cr.y(), pix,
932  cr.width()-width, 0, width, cr.height());
933  else
934  p->drawPixmap(cr.x(), cr.y(), pix, 0, 0, width, cr.height());
935  } else
936  if (reverse)
937  p->fillRect(cr.x()+(cr.width()-width), cr.y(), width, cr.height(),
938  cg.brush(TQColorGroup::Highlight));
939  else
940  p->fillRect(cr.x(), cr.y(), width, cr.height(),
941  cg.brush(TQColorGroup::Highlight));
942  }
943  break;
944  }
945 
946  case CE_ProgressBarLabel: {
947  TQRect cr = subRect(SR_ProgressBarContents, ceData, elementFlags, widget);
948  double progress = ceData.currentStep;
949  bool reverse = TQApplication::reverseLayout();
950  int steps = ceData.totalSteps;
951 
952  if (!cr.isValid())
953  return;
954 
955  TQFont font = p->font();
956  font.setBold(true);
957  p->setFont(font);
958 
959  // Draw label
960  if (progress > 0 || steps == 0) {
961  double pg = (steps == 0) ? 1.0 : progress / steps;
962  int width = QMIN(cr.width(), (int)(pg * cr.width()));
963  TQRect crect;
964  if (reverse)
965  crect.setRect(cr.x()+(cr.width()-width), cr.y(), cr.width(), cr.height());
966  else
967  crect.setRect(cr.x()+width, cr.y(), cr.width(), cr.height());
968 
969  p->save();
970  p->setPen((elementFlags & CEF_IsEnabled) ? (reverse ? cg.text() : cg.highlightedText()) : cg.text());
971  p->drawText(r, AlignCenter, ceData.progressText);
972  p->setClipRect(crect);
973  p->setPen(reverse ? cg.highlightedText() : cg.text());
974  p->drawText(r, AlignCenter, ceData.progressText);
975  p->restore();
976 
977  } else {
978  p->setPen(cg.text());
979  p->drawText(r, AlignCenter, ceData.progressText);
980  }
981 
982  break;
983  }
984 
985  default:
986  TQCommonStyle::drawControl(element, p, ceData, elementFlags, r, cg, flags, opt, widget);
987  }
988 }
989 
990 
991 TQRect TDEStyle::subRect(SubRect r, const TQStyleControlElementData &ceData, const ControlElementFlags elementFlags, const TQWidget* widget) const
992 {
993  switch(r)
994  {
995  // KDE2 look smooth progress bar
996  // ------------------------------------------------------------------------
997  case SR_ProgressBarGroove:
998  return ceData.rect;
999 
1000  case SR_ProgressBarContents:
1001  case SR_ProgressBarLabel: {
1002  // ### take into account indicatorFollowsStyle()
1003  TQRect rt = ceData.rect;
1004  return TQRect(rt.x()+2, rt.y()+2, rt.width()-4, rt.height()-4);
1005  }
1006 
1007  default:
1008  return TQCommonStyle::subRect(r, ceData, elementFlags, widget);
1009  }
1010 }
1011 
1012 
1013 int TDEStyle::pixelMetric(PixelMetric m, const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, const TQWidget* widget) const
1014 {
1015  switch(m)
1016  {
1017  // BUTTONS
1018  // ------------------------------------------------------------------------
1019  case PM_ButtonShiftHorizontal: // Offset by 1
1020  case PM_ButtonShiftVertical: // ### Make configurable
1021  return 1;
1022 
1023  case PM_DockWindowHandleExtent:
1024  {
1025  TQWidget* parent = 0;
1026  // Check that we are not a normal toolbar or a hidden dockwidget,
1027  // in which case we need to adjust the height for font size
1028  if (widget
1029  && !(ceData.parentWidgetData.widgetObjectTypes.contains(TQTOOLBAR_OBJECT_NAME_STRING))
1030  && !(ceData.parentWidgetData.widgetObjectTypes.contains(TQMAINWINDOW_OBJECT_NAME_STRING))
1031  && (ceData.widgetObjectTypes.contains(TQDOCKWINDOWHANDLE_OBJECT_NAME_STRING)) )
1032  return widget->fontMetrics().lineSpacing();
1033  else
1034  return TQCommonStyle::pixelMetric(m, ceData, elementFlags, widget);
1035  }
1036 
1037  // TABS
1038  // ------------------------------------------------------------------------
1039  case PM_TabBarTabHSpace:
1040  return 24;
1041 
1042  case PM_TabBarTabVSpace: {
1043  if ( ceData.tabBarData.shape == TQTabBar::RoundedAbove ||
1044  ceData.tabBarData.shape == TQTabBar::RoundedBelow )
1045  return 10;
1046  else
1047  return 4;
1048  }
1049 
1050  case PM_TabBarTabOverlap: {
1051  TQTabBar::Shape tbs = ceData.tabBarData.shape;
1052 
1053  if ( (tbs == TQTabBar::RoundedAbove) ||
1054  (tbs == TQTabBar::RoundedBelow) )
1055  return 0;
1056  else
1057  return 2;
1058  }
1059 
1060  // SLIDER
1061  // ------------------------------------------------------------------------
1062  case PM_SliderLength:
1063  return 18;
1064 
1065  case PM_SliderThickness:
1066  return 24;
1067 
1068  // Determines how much space to leave for the actual non-tickmark
1069  // portion of the slider.
1070  case PM_SliderControlThickness: {
1071  TQSlider::TickSetting ts = (TQSlider::TickSetting)ceData.tickMarkSetting;
1072  int thickness = (ceData.orientation == TQt::Horizontal) ?
1073  ceData.rect.height() : ceData.rect.width();
1074  switch (ts) {
1075  case TQSlider::NoMarks: // Use total area.
1076  break;
1077  case TQSlider::Both:
1078  thickness = (thickness/2) + 3; // Use approx. 1/2 of area.
1079  break;
1080  default: // Use approx. 2/3 of area
1081  thickness = ((thickness*2)/3) + 3;
1082  break;
1083  };
1084  return thickness;
1085  }
1086 
1087  // SPLITTER
1088  // ------------------------------------------------------------------------
1089  case PM_SplitterWidth:
1090  if (ceData.widgetObjectTypes.contains(TQDOCKWINDOWRESIZEHANDLE_OBJECT_NAME_STRING))
1091  return 8; // ### why do we need 2pix extra?
1092  else
1093  return 6;
1094 
1095  // FRAMES
1096  // ------------------------------------------------------------------------
1097  case PM_MenuBarFrameWidth:
1098  return 1;
1099 
1100  case PM_DockWindowFrameWidth:
1101  return 1;
1102 
1103  // GENERAL
1104  // ------------------------------------------------------------------------
1105  case PM_MaximumDragDistance:
1106  return -1;
1107 
1108  case PM_MenuBarItemSpacing:
1109  return 5;
1110 
1111  case PM_ToolBarItemSpacing:
1112  return 0;
1113 
1114  case PM_PopupMenuScrollerHeight:
1115  return pixelMetric( PM_ScrollBarExtent, ceData, elementFlags, 0);
1116 
1117  default:
1118  return TQCommonStyle::pixelMetric( m, ceData, elementFlags, widget );
1119  }
1120 }
1121 
1122 //Helper to find the next sibling that's not hidden
1123 static TQListViewItem* nextVisibleSibling(TQListViewItem* item)
1124 {
1125  TQListViewItem* sibling = item;
1126  do
1127  {
1128  sibling = sibling->nextSibling();
1129  }
1130  while (sibling && !sibling->isVisible());
1131 
1132  return sibling;
1133 }
1134 
1135 void TDEStyle::drawComplexControl( TQ_ComplexControl control,
1136  TQPainter* p,
1137  const TQStyleControlElementData &ceData,
1138  ControlElementFlags elementFlags,
1139  const TQRect &r,
1140  const TQColorGroup &cg,
1141  SFlags flags,
1142  SCFlags controls,
1143  SCFlags active,
1144  const TQStyleOption &opt,
1145  const TQWidget* widget ) const
1146 {
1147  switch(control)
1148  {
1149  // 3 BUTTON SCROLLBAR
1150  // ------------------------------------------------------------------------
1151  case CC_ScrollBar: {
1152  // Many thanks to Brad Hughes for contributing this code.
1153  bool useThreeButtonScrollBar = (d->scrollbarType & ThreeButtonScrollBar);
1154 
1155  bool maxedOut = (ceData.minSteps == ceData.maxSteps);
1156  bool horizontal = (ceData.orientation == TQt::Horizontal);
1157  SFlags sflags = ((horizontal ? Style_Horizontal : Style_Default) |
1158  (maxedOut ? Style_Default : Style_Enabled));
1159 
1160  TQRect addline, subline, subline2, addpage, subpage, slider, first, last;
1161  subline = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarSubLine, opt, widget);
1162  addline = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarAddLine, opt, widget);
1163  subpage = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarSubPage, opt, widget);
1164  addpage = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarAddPage, opt, widget);
1165  slider = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarSlider, opt, widget);
1166  first = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarFirst, opt, widget);
1167  last = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarLast, opt, widget);
1168  subline2 = addline;
1169 
1170  if ( useThreeButtonScrollBar ) {
1171  if (horizontal) {
1172  subline2.moveBy(-addline.width(), 0);
1173  }
1174  else {
1175  subline2.moveBy(0, -addline.height());
1176  }
1177  }
1178 
1179  // Draw the up/left button set
1180  if ((controls & SC_ScrollBarSubLine) && subline.isValid()) {
1181  drawPrimitive(PE_ScrollBarSubLine, p, ceData, elementFlags, subline, cg,
1182  sflags | (active == SC_ScrollBarSubLine ?
1183  Style_Down : Style_Default));
1184 
1185  if (useThreeButtonScrollBar && subline2.isValid())
1186  drawPrimitive(PE_ScrollBarSubLine, p, ceData, elementFlags, subline2, cg,
1187  sflags | (active == SC_ScrollBarSubLine ?
1188  Style_Down : Style_Default));
1189  }
1190 
1191  if ((controls & SC_ScrollBarAddLine) && addline.isValid())
1192  drawPrimitive(PE_ScrollBarAddLine, p, ceData, elementFlags, addline, cg,
1193  sflags | ((active == SC_ScrollBarAddLine) ?
1194  Style_Down : Style_Default));
1195 
1196  if ((controls & SC_ScrollBarSubPage) && subpage.isValid())
1197  drawPrimitive(PE_ScrollBarSubPage, p, ceData, elementFlags, subpage, cg,
1198  sflags | ((active == SC_ScrollBarSubPage) ?
1199  Style_Down : Style_Default));
1200 
1201  if ((controls & SC_ScrollBarAddPage) && addpage.isValid())
1202  drawPrimitive(PE_ScrollBarAddPage, p, ceData, elementFlags, addpage, cg,
1203  sflags | ((active == SC_ScrollBarAddPage) ?
1204  Style_Down : Style_Default));
1205 
1206  if ((controls & SC_ScrollBarFirst) && first.isValid())
1207  drawPrimitive(PE_ScrollBarFirst, p, ceData, elementFlags, first, cg,
1208  sflags | ((active == SC_ScrollBarFirst) ?
1209  Style_Down : Style_Default));
1210 
1211  if ((controls & SC_ScrollBarLast) && last.isValid())
1212  drawPrimitive(PE_ScrollBarLast, p, ceData, elementFlags, last, cg,
1213  sflags | ((active == SC_ScrollBarLast) ?
1214  Style_Down : Style_Default));
1215 
1216  if ((controls & SC_ScrollBarSlider) && slider.isValid()) {
1217  drawPrimitive(PE_ScrollBarSlider, p, ceData, elementFlags, slider, cg,
1218  sflags | ((active == SC_ScrollBarSlider) ?
1219  Style_Down : Style_Default));
1220  // Draw focus rect
1221  if (elementFlags & CEF_HasFocus) {
1222  TQRect fr(slider.x() + 2, slider.y() + 2,
1223  slider.width() - 5, slider.height() - 5);
1224  drawPrimitive(PE_FocusRect, p, ceData, elementFlags, fr, cg, Style_Default);
1225  }
1226  }
1227  break;
1228  }
1229 
1230 
1231  // SLIDER
1232  // -------------------------------------------------------------------
1233  case CC_Slider: {
1234  TQRect groove = querySubControlMetrics(CC_Slider, ceData, elementFlags, SC_SliderGroove, opt, widget);
1235  TQRect handle = querySubControlMetrics(CC_Slider, ceData, elementFlags, SC_SliderHandle, opt, widget);
1236 
1237  // Double-buffer slider for no flicker
1238  TQPixmap pix(ceData.rect.size());
1239  TQPainter p2;
1240  p2.begin(&pix);
1241 
1242  if ( (elementFlags & CEF_HasParentWidget) &&
1243  !ceData.parentWidgetData.bgPixmap.isNull() ) {
1244  TQPixmap pixmap = ceData.parentWidgetData.bgPixmap;
1245  p2.drawTiledPixmap(r, pixmap, ceData.pos);
1246  } else
1247  pix.fill(cg.background());
1248 
1249  // Draw slider groove
1250  if ((controls & SC_SliderGroove) && groove.isValid()) {
1251  drawTDEStylePrimitive( KPE_SliderGroove, &p2, ceData, elementFlags, groove, cg, flags, opt, widget );
1252 
1253  // Draw the focus rect around the groove
1254  if (elementFlags & CEF_HasFocus) {
1255  drawPrimitive(PE_FocusRect, &p2, ceData, elementFlags, groove, cg);
1256  }
1257  }
1258 
1259  // Draw the tickmarks
1260  if (controls & SC_SliderTickmarks)
1261  TQCommonStyle::drawComplexControl(control, &p2, ceData, elementFlags,
1262  r, cg, flags, SC_SliderTickmarks, active, opt, widget);
1263 
1264  // Draw the slider handle
1265  if ((controls & SC_SliderHandle) && handle.isValid()) {
1266  if (active == SC_SliderHandle)
1267  flags |= Style_Active;
1268  drawTDEStylePrimitive( KPE_SliderHandle, &p2, ceData, elementFlags, handle, cg, flags, opt, widget );
1269  }
1270 
1271  p2.end();
1272 
1273  TQPaintDevice* ppd = p->device();
1274  if (ppd->isExtDev()) {
1275  p->drawPixmap(0, 0, pix);
1276  }
1277  else {
1278  bitBlt((TQWidget*)widget, r.x(), r.y(), &pix);
1279  }
1280  break;
1281  }
1282 
1283  // LISTVIEW
1284  // -------------------------------------------------------------------
1285  case CC_ListView: {
1286 
1287  /*
1288  * Many thanks to TrollTech AS for donating CC_ListView from TQWindowsStyle.
1289  * CC_ListView code is Copyright (C) 1998-2000 TrollTech AS.
1290  */
1291 
1292  // Paint the icon and text.
1293  if ( controls & SC_ListView )
1294  TQCommonStyle::drawComplexControl( control, p, ceData, elementFlags, r, cg, flags, controls, active, opt, widget );
1295 
1296  // If we're have a branch or are expanded...
1297  if ( controls & (SC_ListViewBranch | SC_ListViewExpand) )
1298  {
1299  // If no list view item was supplied, break
1300  if (opt.isDefault())
1301  break;
1302 
1303  TQListViewItem *item = opt.listViewItem();
1304  TQListViewItem *child = item->firstChild();
1305 
1306  int y = r.y();
1307  int c; // dotline vertice count
1308  int dotoffset = 0;
1309  TQPointArray dotlines;
1310 
1311  if ( active == SC_All && controls == SC_ListViewExpand ) {
1312  // We only need to draw a vertical line
1313  c = 2;
1314  dotlines.resize(2);
1315  dotlines[0] = TQPoint( r.right(), r.top() );
1316  dotlines[1] = TQPoint( r.right(), r.bottom() );
1317 
1318  } else {
1319 
1320  int linetop = 0, linebot = 0;
1321  // each branch needs at most two lines, ie. four end points
1322  dotoffset = (item->itemPos() + item->height() - y) % 2;
1323  dotlines.resize( item->childCount() * 4 );
1324  c = 0;
1325 
1326  // skip the stuff above the exposed rectangle
1327  while ( child && y + child->height() <= 0 )
1328  {
1329  y += child->totalHeight();
1330  child = nextVisibleSibling(child);
1331  }
1332 
1333  int bx = r.width() / 2;
1334 
1335  // paint stuff in the magical area
1336  TQListView* v = item->listView();
1337  int lh = QMAX( p->fontMetrics().height() + 2 * v->itemMargin(),
1338  TQApplication::globalStrut().height() );
1339  if ( lh % 2 > 0 )
1340  lh++;
1341 
1342  // Draw all the expand/close boxes...
1343  TQRect boxrect;
1344  TQStyle::StyleFlags boxflags;
1345  while ( child && y < r.height() )
1346  {
1347  linebot = y + lh/2;
1348  if ( (child->isExpandable() || child->childCount()) &&
1349  (child->height() > 0) )
1350  {
1351  // The primitive requires a rect.
1352  boxrect = TQRect( bx-4, linebot-4, 9, 9 );
1353  boxflags = child->isOpen() ? TQStyle::Style_Off : TQStyle::Style_On;
1354 
1355  // TDEStyle extension: Draw the box and expand/collapse indicator
1356  drawTDEStylePrimitive( KPE_ListViewExpander, p, ceData, elementFlags, boxrect, cg, boxflags, opt, NULL );
1357 
1358  // dotlinery
1359  p->setPen( cg.mid() );
1360  dotlines[c++] = TQPoint( bx, linetop );
1361  dotlines[c++] = TQPoint( bx, linebot - 5 );
1362  dotlines[c++] = TQPoint( bx + 5, linebot );
1363  dotlines[c++] = TQPoint( r.width(), linebot );
1364  linetop = linebot + 5;
1365  } else {
1366  // just dotlinery
1367  dotlines[c++] = TQPoint( bx+1, linebot );
1368  dotlines[c++] = TQPoint( r.width(), linebot );
1369  }
1370 
1371  y += child->totalHeight();
1372  child = nextVisibleSibling(child);
1373  }
1374 
1375  if ( child ) // there's a child to draw, so move linebot to edge of rectangle
1376  linebot = r.height();
1377 
1378  if ( linetop < linebot )
1379  {
1380  dotlines[c++] = TQPoint( bx, linetop );
1381  dotlines[c++] = TQPoint( bx, linebot );
1382  }
1383  }
1384 
1385  // Draw all the branches...
1386  static int thickness = kPixelMetric( KPM_ListViewBranchThickness, ceData, elementFlags );
1387  int line; // index into dotlines
1388  TQRect branchrect;
1389  TQStyle::StyleFlags branchflags;
1390  for( line = 0; line < c; line += 2 )
1391  {
1392  // assumptions here: lines are horizontal or vertical.
1393  // lines always start with the numerically lowest
1394  // coordinate.
1395 
1396  // point ... relevant coordinate of current point
1397  // end ..... same coordinate of the end of the current line
1398  // other ... the other coordinate of the current point/line
1399  if ( dotlines[line].y() == dotlines[line+1].y() )
1400  {
1401  // Horizontal branch
1402  int end = dotlines[line+1].x();
1403  int point = dotlines[line].x();
1404  int other = dotlines[line].y();
1405 
1406  branchrect = TQRect( point, other-(thickness/2), end-point, thickness );
1407  branchflags = TQStyle::Style_Horizontal;
1408 
1409  // TDEStyle extension: Draw the horizontal branch
1410  drawTDEStylePrimitive( KPE_ListViewBranch, p, ceData, elementFlags, branchrect, cg, branchflags, opt, NULL );
1411 
1412  } else {
1413  // Vertical branch
1414  int end = dotlines[line+1].y();
1415  int point = dotlines[line].y();
1416  int other = dotlines[line].x();
1417  int pixmapoffset = ((point & 1) != dotoffset ) ? 1 : 0;
1418 
1419  branchrect = TQRect( other-(thickness/2), point, thickness, end-point );
1420  if (!pixmapoffset) // ### Hackish - used to hint the offset
1421  branchflags = TQStyle::Style_NoChange;
1422  else
1423  branchflags = TQStyle::Style_Default;
1424 
1425  // TDEStyle extension: Draw the vertical branch
1426  drawTDEStylePrimitive( KPE_ListViewBranch, p, ceData, elementFlags, branchrect, cg, branchflags, opt, NULL );
1427  }
1428  }
1429  }
1430  break;
1431  }
1432 
1433  default:
1434  TQCommonStyle::drawComplexControl( control, p, ceData, elementFlags, r, cg,
1435  flags, controls, active, opt, widget );
1436  break;
1437  }
1438 }
1439 
1440 
1441 TQStyle::SubControl TDEStyle::querySubControl( TQ_ComplexControl control,
1442  const TQStyleControlElementData &ceData,
1443  ControlElementFlags elementFlags,
1444  const TQPoint &pos,
1445  const TQStyleOption &opt,
1446  const TQWidget* widget ) const
1447 {
1448  TQStyle::SubControl ret = TQCommonStyle::querySubControl(control, ceData, elementFlags, pos, opt, widget);
1449 
1450  if (d->scrollbarType == ThreeButtonScrollBar) {
1451  // Enable third button
1452  if (control == CC_ScrollBar && ret == SC_None)
1453  ret = SC_ScrollBarSubLine;
1454  }
1455  return ret;
1456 }
1457 
1458 
1459 TQRect TDEStyle::querySubControlMetrics( TQ_ComplexControl control,
1460  const TQStyleControlElementData &ceData,
1461  ControlElementFlags elementFlags,
1462  SubControl sc,
1463  const TQStyleOption &opt,
1464  const TQWidget* widget ) const
1465 {
1466  TQRect ret;
1467 
1468  if (control == CC_ScrollBar)
1469  {
1470  bool threeButtonScrollBar = d->scrollbarType & ThreeButtonScrollBar;
1471  bool platinumScrollBar = d->scrollbarType & PlatinumStyleScrollBar;
1472  bool nextScrollBar = d->scrollbarType & NextStyleScrollBar;
1473 
1474  bool horizontal = ceData.orientation == TQt::Horizontal;
1475  int sliderstart = ceData.startStep;
1476  int sbextent = pixelMetric(PM_ScrollBarExtent, ceData, elementFlags, widget);
1477  int maxlen = (horizontal ? ceData.rect.width() : ceData.rect.height())
1478  - (sbextent * (threeButtonScrollBar ? 3 : 2));
1479  int sliderlen;
1480 
1481  // calculate slider length
1482  if (ceData.maxSteps != ceData.minSteps)
1483  {
1484  uint range = ceData.maxSteps - ceData.minSteps;
1485  sliderlen = (ceData.pageStep * maxlen) / (range + ceData.pageStep);
1486 
1487  int slidermin = pixelMetric( PM_ScrollBarSliderMin, ceData, elementFlags, widget );
1488  if ( sliderlen < slidermin || range > INT_MAX / 2 )
1489  sliderlen = slidermin;
1490  if ( sliderlen > maxlen )
1491  sliderlen = maxlen;
1492  } else
1493  sliderlen = maxlen;
1494 
1495  // Subcontrols
1496  switch (sc)
1497  {
1498  case SC_ScrollBarSubLine: {
1499  // top/left button
1500  if (platinumScrollBar) {
1501  if (horizontal)
1502  ret.setRect(ceData.rect.width() - 2 * sbextent, 0, sbextent, sbextent);
1503  else
1504  ret.setRect(0, ceData.rect.height() - 2 * sbextent, sbextent, sbextent);
1505  } else
1506  ret.setRect(0, 0, sbextent, sbextent);
1507  break;
1508  }
1509 
1510  case SC_ScrollBarAddLine: {
1511  // bottom/right button
1512  if (nextScrollBar) {
1513  if (horizontal)
1514  ret.setRect(sbextent, 0, sbextent, sbextent);
1515  else
1516  ret.setRect(0, sbextent, sbextent, sbextent);
1517  } else {
1518  if (horizontal)
1519  ret.setRect(ceData.rect.width() - sbextent, 0, sbextent, sbextent);
1520  else
1521  ret.setRect(0, ceData.rect.height() - sbextent, sbextent, sbextent);
1522  }
1523  break;
1524  }
1525 
1526  case SC_ScrollBarSubPage: {
1527  // between top/left button and slider
1528  if (platinumScrollBar) {
1529  if (horizontal)
1530  ret.setRect(0, 0, sliderstart, sbextent);
1531  else
1532  ret.setRect(0, 0, sbextent, sliderstart);
1533  } else if (nextScrollBar) {
1534  if (horizontal)
1535  ret.setRect(sbextent*2, 0, sliderstart-2*sbextent, sbextent);
1536  else
1537  ret.setRect(0, sbextent*2, sbextent, sliderstart-2*sbextent);
1538  } else {
1539  if (horizontal)
1540  ret.setRect(sbextent, 0, sliderstart - sbextent, sbextent);
1541  else
1542  ret.setRect(0, sbextent, sbextent, sliderstart - sbextent);
1543  }
1544  break;
1545  }
1546 
1547  case SC_ScrollBarAddPage: {
1548  // between bottom/right button and slider
1549  int fudge;
1550 
1551  if (platinumScrollBar)
1552  fudge = 0;
1553  else if (nextScrollBar)
1554  fudge = 2*sbextent;
1555  else
1556  fudge = sbextent;
1557 
1558  if (horizontal)
1559  ret.setRect(sliderstart + sliderlen, 0,
1560  maxlen - sliderstart - sliderlen + fudge, sbextent);
1561  else
1562  ret.setRect(0, sliderstart + sliderlen, sbextent,
1563  maxlen - sliderstart - sliderlen + fudge);
1564  break;
1565  }
1566 
1567  case SC_ScrollBarGroove: {
1568  int multi = threeButtonScrollBar ? 3 : 2;
1569  int fudge;
1570 
1571  if (platinumScrollBar)
1572  fudge = 0;
1573  else if (nextScrollBar)
1574  fudge = 2*sbextent;
1575  else
1576  fudge = sbextent;
1577 
1578  if (horizontal)
1579  ret.setRect(fudge, 0, ceData.rect.width() - sbextent * multi, ceData.rect.height());
1580  else
1581  ret.setRect(0, fudge, ceData.rect.width(), ceData.rect.height() - sbextent * multi);
1582  break;
1583  }
1584 
1585  case SC_ScrollBarSlider: {
1586  if (horizontal)
1587  ret.setRect(sliderstart, 0, sliderlen, sbextent);
1588  else
1589  ret.setRect(0, sliderstart, sbextent, sliderlen);
1590  break;
1591  }
1592 
1593  default:
1594  ret = TQCommonStyle::querySubControlMetrics(control, ceData, elementFlags, sc, opt, widget);
1595  break;
1596  }
1597  } else
1598  ret = TQCommonStyle::querySubControlMetrics(control, ceData, elementFlags, sc, opt, widget);
1599 
1600  return ret;
1601 }
1602 
1603 static const char * const kstyle_close_xpm[] = {
1604 "12 12 2 1",
1605 "# c #000000",
1606 ". c None",
1607 "............",
1608 "............",
1609 "..##....##..",
1610 "...##..##...",
1611 "....####....",
1612 ".....##.....",
1613 "....####....",
1614 "...##..##...",
1615 "..##....##..",
1616 "............",
1617 "............",
1618 "............"};
1619 
1620 static const char * const kstyle_maximize_xpm[]={
1621 "12 12 2 1",
1622 "# c #000000",
1623 ". c None",
1624 "............",
1625 "............",
1626 ".##########.",
1627 ".##########.",
1628 ".#........#.",
1629 ".#........#.",
1630 ".#........#.",
1631 ".#........#.",
1632 ".#........#.",
1633 ".#........#.",
1634 ".##########.",
1635 "............"};
1636 
1637 
1638 static const char * const kstyle_minimize_xpm[] = {
1639 "12 12 2 1",
1640 "# c #000000",
1641 ". c None",
1642 "............",
1643 "............",
1644 "............",
1645 "............",
1646 "............",
1647 "............",
1648 "............",
1649 "...######...",
1650 "...######...",
1651 "............",
1652 "............",
1653 "............"};
1654 
1655 static const char * const kstyle_normalizeup_xpm[] = {
1656 "12 12 2 1",
1657 "# c #000000",
1658 ". c None",
1659 "............",
1660 "...#######..",
1661 "...#######..",
1662 "...#.....#..",
1663 ".#######.#..",
1664 ".#######.#..",
1665 ".#.....#.#..",
1666 ".#.....###..",
1667 ".#.....#....",
1668 ".#.....#....",
1669 ".#######....",
1670 "............"};
1671 
1672 
1673 static const char * const kstyle_shade_xpm[] = {
1674 "12 12 2 1",
1675 "# c #000000",
1676 ". c None",
1677 "............",
1678 "............",
1679 "............",
1680 "............",
1681 "............",
1682 ".....#......",
1683 "....###.....",
1684 "...#####....",
1685 "..#######...",
1686 "............",
1687 "............",
1688 "............"};
1689 
1690 static const char * const kstyle_unshade_xpm[] = {
1691 "12 12 2 1",
1692 "# c #000000",
1693 ". c None",
1694 "............",
1695 "............",
1696 "............",
1697 "............",
1698 "..#######...",
1699 "...#####....",
1700 "....###.....",
1701 ".....#......",
1702 "............",
1703 "............",
1704 "............",
1705 "............"};
1706 
1707 static const char * const dock_window_close_xpm[] = {
1708 "8 8 2 1",
1709 "# c #000000",
1710 ". c None",
1711 "##....##",
1712 ".##..##.",
1713 "..####..",
1714 "...##...",
1715 "..####..",
1716 ".##..##.",
1717 "##....##",
1718 "........"};
1719 
1720 // Message box icons, from page 210 of the Windows style guide.
1721 
1722 // Hand-drawn to resemble Microsoft's icons, but in the Mac/Netscape
1723 // palette. The "question mark" icon, which Microsoft recommends not
1724 // using but a lot of people still use, is left out.
1725 
1726 /* XPM */
1727 static const char * const information_xpm[]={
1728 "32 32 5 1",
1729 ". c None",
1730 "c c #000000",
1731 "* c #999999",
1732 "a c #ffffff",
1733 "b c #0000ff",
1734 "...........********.............",
1735 "........***aaaaaaaa***..........",
1736 "......**aaaaaaaaaaaaaa**........",
1737 ".....*aaaaaaaaaaaaaaaaaa*.......",
1738 "....*aaaaaaaabbbbaaaaaaaac......",
1739 "...*aaaaaaaabbbbbbaaaaaaaac.....",
1740 "..*aaaaaaaaabbbbbbaaaaaaaaac....",
1741 ".*aaaaaaaaaaabbbbaaaaaaaaaaac...",
1742 ".*aaaaaaaaaaaaaaaaaaaaaaaaaac*..",
1743 "*aaaaaaaaaaaaaaaaaaaaaaaaaaaac*.",
1744 "*aaaaaaaaaabbbbbbbaaaaaaaaaaac*.",
1745 "*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
1746 "*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
1747 "*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
1748 "*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
1749 "*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
1750 ".*aaaaaaaaaaabbbbbaaaaaaaaaac***",
1751 ".*aaaaaaaaaaabbbbbaaaaaaaaaac***",
1752 "..*aaaaaaaaaabbbbbaaaaaaaaac***.",
1753 "...caaaaaaabbbbbbbbbaaaaaac****.",
1754 "....caaaaaaaaaaaaaaaaaaaac****..",
1755 ".....caaaaaaaaaaaaaaaaaac****...",
1756 "......ccaaaaaaaaaaaaaacc****....",
1757 ".......*cccaaaaaaaaccc*****.....",
1758 "........***cccaaaac*******......",
1759 "..........****caaac*****........",
1760 ".............*caaac**...........",
1761 "...............caac**...........",
1762 "................cac**...........",
1763 ".................cc**...........",
1764 "..................***...........",
1765 "...................**..........."};
1766 /* XPM */
1767 static const char* const warning_xpm[]={
1768 "32 32 4 1",
1769 ". c None",
1770 "a c #ffff00",
1771 "* c #000000",
1772 "b c #999999",
1773 ".............***................",
1774 "............*aaa*...............",
1775 "...........*aaaaa*b.............",
1776 "...........*aaaaa*bb............",
1777 "..........*aaaaaaa*bb...........",
1778 "..........*aaaaaaa*bb...........",
1779 ".........*aaaaaaaaa*bb..........",
1780 ".........*aaaaaaaaa*bb..........",
1781 "........*aaaaaaaaaaa*bb.........",
1782 "........*aaaa***aaaa*bb.........",
1783 ".......*aaaa*****aaaa*bb........",
1784 ".......*aaaa*****aaaa*bb........",
1785 "......*aaaaa*****aaaaa*bb.......",
1786 "......*aaaaa*****aaaaa*bb.......",
1787 ".....*aaaaaa*****aaaaaa*bb......",
1788 ".....*aaaaaa*****aaaaaa*bb......",
1789 "....*aaaaaaaa***aaaaaaaa*bb.....",
1790 "....*aaaaaaaa***aaaaaaaa*bb.....",
1791 "...*aaaaaaaaa***aaaaaaaaa*bb....",
1792 "...*aaaaaaaaaa*aaaaaaaaaa*bb....",
1793 "..*aaaaaaaaaaa*aaaaaaaaaaa*bb...",
1794 "..*aaaaaaaaaaaaaaaaaaaaaaa*bb...",
1795 ".*aaaaaaaaaaaa**aaaaaaaaaaa*bb..",
1796 ".*aaaaaaaaaaa****aaaaaaaaaa*bb..",
1797 "*aaaaaaaaaaaa****aaaaaaaaaaa*bb.",
1798 "*aaaaaaaaaaaaa**aaaaaaaaaaaa*bb.",
1799 "*aaaaaaaaaaaaaaaaaaaaaaaaaaa*bbb",
1800 "*aaaaaaaaaaaaaaaaaaaaaaaaaaa*bbb",
1801 ".*aaaaaaaaaaaaaaaaaaaaaaaaa*bbbb",
1802 "..*************************bbbbb",
1803 "....bbbbbbbbbbbbbbbbbbbbbbbbbbb.",
1804 ".....bbbbbbbbbbbbbbbbbbbbbbbbb.."};
1805 /* XPM */
1806 static const char* const critical_xpm[]={
1807 "32 32 4 1",
1808 ". c None",
1809 "a c #999999",
1810 "* c #ff0000",
1811 "b c #ffffff",
1812 "...........********.............",
1813 ".........************...........",
1814 ".......****************.........",
1815 "......******************........",
1816 ".....********************a......",
1817 "....**********************a.....",
1818 "...************************a....",
1819 "..*******b**********b*******a...",
1820 "..******bbb********bbb******a...",
1821 ".******bbbbb******bbbbb******a..",
1822 ".*******bbbbb****bbbbb*******a..",
1823 "*********bbbbb**bbbbb*********a.",
1824 "**********bbbbbbbbbb**********a.",
1825 "***********bbbbbbbb***********aa",
1826 "************bbbbbb************aa",
1827 "************bbbbbb************aa",
1828 "***********bbbbbbbb***********aa",
1829 "**********bbbbbbbbbb**********aa",
1830 "*********bbbbb**bbbbb*********aa",
1831 ".*******bbbbb****bbbbb*******aa.",
1832 ".******bbbbb******bbbbb******aa.",
1833 "..******bbb********bbb******aaa.",
1834 "..*******b**********b*******aa..",
1835 "...************************aaa..",
1836 "....**********************aaa...",
1837 "....a********************aaa....",
1838 ".....a******************aaa.....",
1839 "......a****************aaa......",
1840 ".......aa************aaaa.......",
1841 ".........aa********aaaaa........",
1842 "...........aaaaaaaaaaa..........",
1843 ".............aaaaaaa............"};
1844 
1845 TQPixmap TDEStyle::stylePixmap( StylePixmap stylepixmap,
1846  const TQStyleControlElementData &ceData,
1847  ControlElementFlags elementFlags,
1848  const TQStyleOption& opt,
1849  const TQWidget* widget) const
1850 {
1851  switch (stylepixmap) {
1852  case SP_TitleBarShadeButton:
1853  return TQPixmap(const_cast<const char**>(kstyle_shade_xpm));
1854  case SP_TitleBarUnshadeButton:
1855  return TQPixmap(const_cast<const char**>(kstyle_unshade_xpm));
1856  case SP_TitleBarNormalButton:
1857  return TQPixmap(const_cast<const char**>(kstyle_normalizeup_xpm));
1858  case SP_TitleBarMinButton:
1859  return TQPixmap(const_cast<const char**>(kstyle_minimize_xpm));
1860  case SP_TitleBarMaxButton:
1861  return TQPixmap(const_cast<const char**>(kstyle_maximize_xpm));
1862  case SP_TitleBarCloseButton:
1863  return TQPixmap(const_cast<const char**>(kstyle_close_xpm));
1864  case SP_DockWindowCloseButton:
1865  return TQPixmap(const_cast<const char**>(dock_window_close_xpm ));
1866  case SP_MessageBoxInformation:
1867  return TQPixmap(const_cast<const char**>(information_xpm));
1868  case SP_MessageBoxWarning:
1869  return TQPixmap(const_cast<const char**>(warning_xpm));
1870  case SP_MessageBoxCritical:
1871  return TQPixmap(const_cast<const char**>(critical_xpm));
1872  default:
1873  break;
1874  }
1875  return TQCommonStyle::stylePixmap(stylepixmap, ceData, elementFlags, opt, widget);
1876 }
1877 
1878 
1879 int TDEStyle::styleHint( TQ_StyleHint sh, const TQStyleControlElementData &ceData, ControlElementFlags elementFlags,
1880  const TQStyleOption &opt, TQStyleHintReturn* shr, const TQWidget* w) const
1881 {
1882  switch (sh)
1883  {
1884  case SH_EtchDisabledText:
1885  return d->etchDisabledText ? 1 : 0;
1886 
1887  case SH_PopupMenu_Scrollable:
1888  return d->scrollablePopupmenus ? 1 : 0;
1889 
1890  case SH_HideUnderlineAcceleratorWhenAltUp:
1891  return d->autoHideAccelerators ? 1 : 0;
1892 
1893  case SH_MenuBar_AltKeyNavigation:
1894  return d->menuAltKeyNavigation ? 1 : 0;
1895 
1896  case SH_PopupMenu_SubMenuPopupDelay:
1897  if ( styleHint( SH_PopupMenu_SloppySubMenus, ceData, elementFlags, TQStyleOption::Default, 0, w ) )
1898  return QMIN( 100, d->popupMenuDelay );
1899  else
1900  return d->popupMenuDelay;
1901 
1902  case SH_PopupMenu_SloppySubMenus:
1903  return d->sloppySubMenus;
1904 
1905  case SH_ItemView_ChangeHighlightOnFocus:
1906  case SH_Slider_SloppyKeyEvents:
1907  case SH_MainWindow_SpaceBelowMenuBar:
1908  case SH_PopupMenu_AllowActiveAndDisabled:
1909  return 0;
1910 
1911  case SH_Slider_SnapToValue:
1912  case SH_PrintDialog_RightAlignButtons:
1913  case SH_FontDialog_SelectAssociatedText:
1914  case SH_MenuBar_MouseTracking:
1915  case SH_PopupMenu_MouseTracking:
1916  case SH_ComboBox_ListMouseTracking:
1917  case SH_ScrollBar_MiddleClickAbsolutePosition:
1918  return 1;
1919  case SH_LineEdit_PasswordCharacter:
1920  {
1921  if (w) {
1922  const TQFontMetrics &fm = w->fontMetrics();
1923  if (fm.inFont(TQChar(0x25CF))) {
1924  return 0x25CF;
1925  } else if (fm.inFont(TQChar(0x2022))) {
1926  return 0x2022;
1927  }
1928  }
1929  return '*';
1930  }
1931 
1932  default:
1933  return TQCommonStyle::styleHint(sh, ceData, elementFlags, opt, shr, w);
1934  }
1935 }
1936 
1937 
1938 bool TDEStyle::objectEventHandler( const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, void* source, TQEvent *event )
1939 {
1940  if (ceData.widgetObjectTypes.contains(TQOBJECT_OBJECT_NAME_STRING)) {
1941  TQObject* object = reinterpret_cast<TQObject*>(source);
1942  if ( d->useFilledFrameWorkaround )
1943  {
1944  // Make the QMenuBar/TQToolBar paintEvent() cover a larger area to
1945  // ensure that the filled frame contents are properly painted.
1946  // We essentially modify the paintEvent's rect to include the
1947  // panel border, which also paints the widget's interior.
1948  // This is nasty, but I see no other way to properly repaint
1949  // filled frames in all QMenuBars and QToolBars.
1950  // -- Karol.
1951  TQFrame *frame = 0;
1952  if ( event->type() == TQEvent::Paint
1953  && (frame = ::tqqt_cast<TQFrame*>(object)) )
1954  {
1955  if (frame->frameShape() != TQFrame::ToolBarPanel && frame->frameShape() != TQFrame::MenuBarPanel)
1956  return false;
1957 
1958  bool horizontal = true;
1959  TQPaintEvent* pe = (TQPaintEvent*)event;
1960  TQToolBar *toolbar = ::tqqt_cast< TQToolBar *>( frame );
1961  TQRect r = pe->rect();
1962 
1963  if (toolbar && toolbar->orientation() == Qt::Vertical)
1964  horizontal = false;
1965 
1966  if (horizontal) {
1967  if ( r.height() == frame->height() )
1968  return false; // Let TQFrame handle the painting now.
1969 
1970  // Else, send a new paint event with an updated paint rect.
1971  TQPaintEvent dummyPE( TQRect( r.x(), 0, r.width(), frame->height()) );
1972  TQApplication::sendEvent( frame, &dummyPE );
1973  }
1974  else { // Vertical
1975  if ( r.width() == frame->width() )
1976  return false;
1977 
1978  TQPaintEvent dummyPE( TQRect( 0, r.y(), frame->width(), r.height()) );
1979  TQApplication::sendEvent( frame, &dummyPE );
1980  }
1981 
1982  // Discard this event as we sent a new paintEvent.
1983  return true;
1984  }
1985  }
1986  }
1987 
1988  return false;
1989 }
1990 
1991 
1992 // -----------------------------------------------------------------------------
1993 // I N T E R N A L - TDEStyle menu transparency handler
1994 // -----------------------------------------------------------------------------
1995 
1996 TransparencyHandler::TransparencyHandler( TDEStyle* style,
1997  TransparencyEngine tEngine, float menuOpacity, bool useDropShadow )
1998  : TQObject()
1999 {
2000  te = tEngine;
2001  kstyle = style;
2002  opacity = menuOpacity;
2003  dropShadow = useDropShadow;
2004  pix.setOptimization(TQPixmap::BestOptim);
2005 }
2006 
2007 TransparencyHandler::~TransparencyHandler()
2008 {
2009 }
2010 
2011 bool TransparencyHandler::haveX11RGBASupport()
2012 {
2013  // Simple way to determine if we have ARGB support
2014  if (TQPaintDevice::x11AppDepth() == 32) {
2015  return true;
2016  }
2017  else {
2018  return false;
2019  }
2020 }
2021 
2022 #define REAL_ALPHA_STRENGTH 255.0
2023 
2024 // This is meant to be ugly but fast.
2025 void TransparencyHandler::rightShadow(TQImage& dst)
2026 {
2027  bool have_composite = haveX11RGBASupport();
2028 
2029  if (dst.depth() != 32)
2030  dst = dst.convertDepth(32);
2031 
2032  // blend top-right corner.
2033  int pixels = dst.width() * dst.height();
2034 #ifdef WORDS_BIGENDIAN
2035  register unsigned char* data = dst.bits() + 1; // Skip alpha
2036 #else
2037  register unsigned char* data = dst.bits(); // Skip alpha
2038 #endif
2039  for(register int i = 0; i < 16; i++) {
2040  if (have_composite) {
2041  data++;
2042  data++;
2043  data++;
2044  *data = (unsigned char)(REAL_ALPHA_STRENGTH*(1.0-top_right_corner[i])); data++;
2045  }
2046  else {
2047  *data = (unsigned char)((*data)*top_right_corner[i]); data++;
2048  *data = (unsigned char)((*data)*top_right_corner[i]); data++;
2049  *data = (unsigned char)((*data)*top_right_corner[i]); data++;
2050  data++; // skip alpha
2051  }
2052  }
2053 
2054  pixels -= 32; // tint right strip without rounded edges.
2055  register int c = 0;
2056  for(register int i = 0; i < pixels; i++) {
2057  if (have_composite) {
2058  data++;
2059  data++;
2060  data++;;
2061  *data = (unsigned char)(REAL_ALPHA_STRENGTH*(1.0-shadow_strip[c])); data++;
2062  }
2063  else {
2064  *data = (unsigned char)((*data)*shadow_strip[c]); data++;
2065  *data = (unsigned char)((*data)*shadow_strip[c]); data++;
2066  *data = (unsigned char)((*data)*shadow_strip[c]); data++;
2067  data++; // skip alpha
2068  }
2069  ++c;
2070  c %= 4;
2071  }
2072 
2073  // tint bottom edge
2074  for(register int i = 0; i < 16; i++) {
2075  if (have_composite) {
2076  data++;
2077  data++;
2078  data++;
2079  *data = (unsigned char)(REAL_ALPHA_STRENGTH*(1.0-bottom_right_corner[i])); data++;
2080  }
2081  else {
2082  *data = (unsigned char)((*data)*bottom_right_corner[i]); data++;
2083  *data = (unsigned char)((*data)*bottom_right_corner[i]); data++;
2084  *data = (unsigned char)((*data)*bottom_right_corner[i]); data++;
2085  data++; // skip alpha
2086  }
2087  }
2088 }
2089 
2090 void TransparencyHandler::bottomShadow(TQImage& dst)
2091 {
2092  bool have_composite = haveX11RGBASupport();
2093 
2094  if (dst.depth() != 32)
2095  dst = dst.convertDepth(32);
2096 
2097  int line = 0;
2098  int width = dst.width() - 4;
2099  double strip_data = shadow_strip[0];
2100  double* corner = const_cast<double*>(bottom_left_corner);
2101 
2102 #ifdef WORDS_BIGENDIAN
2103  register unsigned char* data = dst.bits() + 1; // Skip alpha
2104 #else
2105  register unsigned char* data = dst.bits(); // Skip alpha
2106 #endif
2107 
2108  for(int y = 0; y < 4; y++)
2109  {
2110  // Bottom-left Corner
2111  for(register int x = 0; x < 4; x++) {
2112  if (have_composite) {
2113  data++;
2114  data++;
2115  data++;
2116  *data = (unsigned char)(REAL_ALPHA_STRENGTH*(1.0-(*corner))); data++;
2117  }
2118  else {
2119  *data = (unsigned char)((*data)*(*corner)); data++;
2120  *data = (unsigned char)((*data)*(*corner)); data++;
2121  *data = (unsigned char)((*data)*(*corner)); data++;
2122  data++; // skip alpha
2123  }
2124  corner++;
2125  }
2126 
2127  // Scanline
2128  for(register int x = 0; x < width; x++) {
2129  if (have_composite) {
2130  data++;
2131  data++;
2132  data++;
2133  *data = (unsigned char)(REAL_ALPHA_STRENGTH*(1.0-strip_data)); data++;
2134  }
2135  else {
2136  *data = (unsigned char)((*data)*strip_data); data++;
2137  *data = (unsigned char)((*data)*strip_data); data++;
2138  *data = (unsigned char)((*data)*strip_data); data++;
2139  data++; // skip alpha
2140  }
2141  }
2142 
2143  strip_data = shadow_strip[++line];
2144  }
2145 }
2146 
2147 TQImage TransparencyHandler::handleRealAlpha(TQImage img) {
2148  TQImage clearImage = img.convertDepth(32);
2149  clearImage.setAlphaBuffer(true);
2150 
2151  int w = clearImage.width();
2152  int h = clearImage.height();
2153 
2154  for (int y = 0; y < h; ++y) {
2155  TQRgb *ls = (TQRgb *)clearImage.scanLine( y );
2156  for (int x = 0; x < w; ++x) {
2157  ls[x] = tqRgba( 0, 0, 0, 0 );
2158  }
2159  }
2160 
2161  return clearImage;
2162 }
2163 
2164 // Create a shadow of thickness 4.
2165 void TransparencyHandler::createShadowWindows(const TQWidget* p)
2166 {
2167 #ifdef Q_WS_X11
2168  int x2 = p->x()+p->width();
2169  int y2 = p->y()+p->height();
2170  TQRect shadow1(x2, p->y() + 4, 4, p->height());
2171  TQRect shadow2(p->x() + 4, y2, p->width() - 4, 4);
2172 
2173  bool have_composite = haveX11RGBASupport();
2174 
2175  // Create a fake drop-down shadow effect via blended Xwindows
2176  ShadowElements se;
2177  se.w1 = new TQWidget(0, 0, (WFlags)(WStyle_Customize | WType_Popup | WX11BypassWM) );
2178  se.w2 = new TQWidget(0, 0, (WFlags)(WStyle_Customize | WType_Popup | WX11BypassWM) );
2179  se.w1->setGeometry(shadow1);
2180  se.w2->setGeometry(shadow2);
2181  XSelectInput(tqt_xdisplay(), se.w1->winId(), StructureNotifyMask );
2182  XSelectInput(tqt_xdisplay(), se.w2->winId(), StructureNotifyMask );
2183 
2184  // Insert a new ShadowMap entry
2185  shadowMap()[p] = se;
2186 
2187  // Some hocus-pocus here to create the drop-shadow.
2188  TQPixmap pix_shadow1;
2189  TQPixmap pix_shadow2;
2190  if (have_composite) {
2191  pix_shadow1 = TQPixmap(shadow1.width(), shadow1.height());
2192  pix_shadow2 = TQPixmap(shadow2.width(), shadow2.height());
2193  }
2194  else {
2195  pix_shadow1 = TQPixmap::grabWindow(tqt_xrootwin(),
2196  shadow1.x(), shadow1.y(), shadow1.width(), shadow1.height());
2197  pix_shadow2 = TQPixmap::grabWindow(tqt_xrootwin(),
2198  shadow2.x(), shadow2.y(), shadow2.width(), shadow2.height());
2199  }
2200 
2201  TQImage img;
2202  img = pix_shadow1.convertToImage();
2203  if (have_composite) img = handleRealAlpha(img);
2204  rightShadow(img);
2205  pix_shadow1.convertFromImage(img);
2206  img = pix_shadow2.convertToImage();
2207  if (have_composite) img = handleRealAlpha(img);
2208  bottomShadow(img);
2209  pix_shadow2.convertFromImage(img);
2210 
2211  // Set the background pixmaps
2212  se.w1->setErasePixmap(pix_shadow1);
2213  se.w2->setErasePixmap(pix_shadow2);
2214 
2215  // Show the 'shadow' just before showing the popup menu window
2216  // Don't use TQWidget::show() so we don't confuse QEffects, thus causing broken focus.
2217  XMapWindow(tqt_xdisplay(), se.w1->winId());
2218  XMapWindow(tqt_xdisplay(), se.w2->winId());
2219 #else
2220  Q_UNUSED( p )
2221 #endif
2222 }
2223 
2224 void TransparencyHandler::removeShadowWindows(const TQWidget* p)
2225 {
2226 #ifdef Q_WS_X11
2227  ShadowMap::iterator it = shadowMap().find(p);
2228  if (it != shadowMap().end())
2229  {
2230  ShadowElements se = it.data();
2231  XUnmapWindow(tqt_xdisplay(), se.w1->winId()); // hide
2232  XUnmapWindow(tqt_xdisplay(), se.w2->winId());
2233  XFlush(tqt_xdisplay()); // try to hide faster
2234  delete se.w1;
2235  delete se.w2;
2236  shadowMap().erase(it);
2237  }
2238 #else
2239  Q_UNUSED( p )
2240 #endif
2241 }
2242 
2243 bool TransparencyHandler::eventFilter( TQObject* object, TQEvent* event )
2244 {
2245 #if !defined Q_WS_MAC && !defined Q_WS_WIN
2246  // Transparency idea was borrowed from KDE2's "MegaGradient" Style,
2247  // Copyright (C) 2000 Daniel M. Duley <mosfet@kde.org>
2248 
2249  // Added 'fake' menu shadows <04-Jul-2002> -- Karol
2250  TQWidget* p = (TQWidget*)object;
2251  TQEvent::Type et = event->type();
2252 
2253  if (et == TQEvent::Show)
2254  {
2255  // Handle translucency
2256  if (te != Disabled)
2257  {
2258  pix = TQPixmap::grabWindow(tqt_xrootwin(),
2259  p->x(), p->y(), p->width(), p->height());
2260 
2261  switch (te) {
2262 #ifdef HAVE_XRENDER
2263  case XRender:
2264  if (tqt_use_xrender) {
2265  XRenderBlendToPixmap(p);
2266  break;
2267  }
2268  // Fall through intended
2269 #else
2270  case XRender:
2271 #endif
2272  case SoftwareBlend:
2273  blendToPixmap(p->colorGroup(), p);
2274  break;
2275 
2276  case SoftwareTint:
2277  default:
2278  blendToColor(p->colorGroup().button());
2279  };
2280 
2281  p->setErasePixmap(pix);
2282  }
2283 
2284  // Handle drop shadow
2285  // * FIXME : !shadowMap().contains(p) is a workaround for leftover
2286  // * shadows after duplicate show events.
2287  // * TODO : determine real cause for duplicate events
2288  // * till 20021005
2289  if ((dropShadow || useDropShadow(p))
2290  && p->width() > 16 && p->height() > 16 && !shadowMap().contains( p ))
2291  createShadowWindows(p);
2292  }
2293  else if (et == TQEvent::Resize && p->isShown() && p->isTopLevel())
2294  {
2295  // Handle drop shadow
2296  if (dropShadow || useDropShadow(p))
2297  {
2298  removeShadowWindows(p);
2299  createShadowWindows(p);
2300  }
2301  }
2302  else if (et == TQEvent::Hide)
2303  {
2304  // Handle drop shadow
2305  if (dropShadow || useDropShadow(p))
2306  removeShadowWindows(p);
2307 
2308  // Handle translucency
2309  if (te != Disabled)
2310  p->setErasePixmap(TQPixmap());
2311  }
2312 
2313 #endif
2314  return false;
2315 }
2316 
2317 
2318 // Blends a TQImage to a predefined color, with a given opacity.
2319 void TransparencyHandler::blendToColor(const TQColor &col)
2320 {
2321  if (opacity < 0.0 || opacity > 1.0)
2322  return;
2323 
2324  TQImage img = pix.convertToImage();
2325  KImageEffect::blend(col, img, opacity);
2326  pix.convertFromImage(img);
2327 }
2328 
2329 
2330 void TransparencyHandler::blendToPixmap(const TQColorGroup &cg, const TQWidget* p)
2331 {
2332  if (opacity < 0.0 || opacity > 1.0)
2333  return;
2334 
2335  KPixmap blendPix;
2336  blendPix.resize( pix.width(), pix.height() );
2337 
2338  if (blendPix.width() != pix.width() ||
2339  blendPix.height() != pix.height())
2340  return;
2341 
2342  // Allow styles to define the blend pixmap - allows for some interesting effects.
2343  if (::tqqt_cast<TQPopupMenu*>(p))
2344  kstyle->renderMenuBlendPixmap( blendPix, cg, ::tqqt_cast<TQPopupMenu*>(p) );
2345  else
2346  blendPix.fill(cg.button()); // Just tint as the default behavior
2347 
2348  TQImage blendImg = blendPix.convertToImage();
2349  TQImage backImg = pix.convertToImage();
2350  KImageEffect::blend(blendImg, backImg, opacity);
2351  pix.convertFromImage(backImg);
2352 }
2353 
2354 
2355 #ifdef HAVE_XRENDER
2356 // Here we go, use XRender in all its glory.
2357 // NOTE: This is actually a bit slower than the above routines
2358 // on non-accelerated displays. -- Karol.
2359 void TransparencyHandler::XRenderBlendToPixmap(const TQWidget* p)
2360 {
2361  KPixmap renderPix;
2362  renderPix.resize( pix.width(), pix.height() );
2363 
2364  // Allow styles to define the blend pixmap - allows for some interesting effects.
2365  if (::tqqt_cast<TQPopupMenu*>(p))
2366  kstyle->renderMenuBlendPixmap( renderPix, p->colorGroup(),
2367  ::tqqt_cast<TQPopupMenu*>(p) );
2368  else
2369  renderPix.fill(p->colorGroup().button()); // Just tint as the default behavior
2370 
2371  Display* dpy = tqt_xdisplay();
2372  Pixmap alphaPixmap;
2373  Picture alphaPicture;
2374  XRenderPictFormat Rpf;
2375  XRenderPictureAttributes Rpa;
2376  XRenderColor clr;
2377  clr.alpha = ((unsigned short)(255*opacity) << 8);
2378 
2379  Rpf.type = PictTypeDirect;
2380  Rpf.depth = 8;
2381  Rpf.direct.alphaMask = 0xff;
2382  Rpa.repeat = True; // Tile
2383 
2384  XRenderPictFormat* xformat = XRenderFindFormat(dpy,
2385  PictFormatType | PictFormatDepth | PictFormatAlphaMask, &Rpf, 0);
2386 
2387  alphaPixmap = XCreatePixmap(dpy, p->handle(), 1, 1, 8);
2388  alphaPicture = XRenderCreatePicture(dpy, alphaPixmap, xformat, CPRepeat, &Rpa);
2389 
2390  XRenderFillRectangle(dpy, PictOpSrc, alphaPicture, &clr, 0, 0, 1, 1);
2391 
2392  XRenderComposite(dpy, PictOpOver,
2393  renderPix.x11RenderHandle(), alphaPicture, pix.x11RenderHandle(), // src, mask, dst
2394  0, 0, // srcx, srcy
2395  0, 0, // maskx, masky
2396  0, 0, // dstx, dsty
2397  pix.width(), pix.height());
2398 
2399  XRenderFreePicture(dpy, alphaPicture);
2400  XFreePixmap(dpy, alphaPixmap);
2401 }
2402 #endif
2403 
2404 void TDEStyle::virtual_hook( int, void* )
2405 { /*BASE::virtual_hook( id, data );*/ }
2406 
2407 // HACK for gtk-qt-engine
2408 
2409 extern "C" KDE_EXPORT
2410 void kde_kstyle_set_scrollbar_type_windows( void* style )
2411 {
2412  ((TDEStyle*)style)->setScrollBarType( TDEStyle::WindowsStyleScrollBar );
2413 }
2414 
2415 // vim: set noet ts=4 sw=4:
2416 // kate: indent-width 4; replace-tabs off; tab-width 4; space-indent off;
2417 
2418 #include "tdestyle.moc"

tdefx

Skip menu "tdefx"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members

tdefx

Skip menu "tdefx"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • knewstuff
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdefx by doxygen 1.8.3.1
This website is maintained by Timothy Pearson.