• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDEUI

  • sources
  • kde-4.14
  • kdelibs
  • kdeui
  • kernel
kstyle.cpp
Go to the documentation of this file.
1 
46 #include "kstyle.h"
47 #include "kstyle.moc"
48 
49 #include <QtCore/qalgorithms.h>
50 #include <QtCore/QCache>
51 #include <QtCore/QEvent>
52 #include <QtCore/QVariant>
53 #include <QtGui/QAbstractItemView>
54 #include <QtGui/QApplication>
55 #include <QtGui/QDialogButtonBox>
56 #include <QtGui/QFormLayout>
57 #include <QtGui/QIcon>
58 #include <QtGui/QLabel>
59 #include <QtGui/QKeyEvent>
60 #include <QtGui/QPainter>
61 #include <QtGui/QScrollBar>
62 #include <QtGui/QStyleOption>
63 
64 #include <kcomponentdata.h>
65 #include <kglobal.h>
66 #include <kconfiggroup.h>
67 #include <kdebug.h>
68 #include <kicon.h>
69 #include <kiconloader.h>
70 
71 #include "kglobalsettings.h"
72 
73 //### FIXME: Who to credit these to?
74 static const qint32 u_arrow[]={-1,-3, 0,-3, -2,-2, 1,-2, -3,-1, 2,-1, -4,0, 3,0, -4,1, 3,1};
75 static const qint32 d_arrow[]={-4,-2, 3,-2, -4,-1, 3,-1, -3,0, 2,0, -2,1, 1,1, -1,2, 0,2};
76 static const qint32 l_arrow[]={-3,-1, -3,0, -2,-2, -2,1, -1,-3, -1,2, 0,-4, 0,3, 1,-4, 1,3};
77 static const qint32 r_arrow[]={-2,-4, -2,3, -1,-4, -1,3, 0,-3, 0,2, 1,-2, 1,1, 2,-1, 2,0};
78 #define QCOORDARRLEN(x) sizeof(x)/(sizeof(qint32)*2)
79 
80 
89 // ----------------------------------------------------------------------------
90 
91 
92 // For item view selections
93 struct SelectionTiles
94 {
95  QPixmap left, center, right;
96 };
97 
98 
99 // ----------------------------------------------------------------------------
100 
101 static const QStyle::StyleHint SH_KCustomStyleElement = (QStyle::StyleHint)0xff000001;
102 static const int X_KdeBase = 0xff000000;
103 
104 class KStylePrivate
105 {
106 public:
107  KStylePrivate();
108  QCache<quint64, SelectionTiles> selectionCache;
109  KComponentData m_componentData;
110 
111  QHash<QString, int> styleElements;
112  int hintCounter, controlCounter, subElementCounter;
113 };
114 
115 KStylePrivate::KStylePrivate() : m_componentData()
116 {
117  if(KGlobal::hasMainComponent())
118  {
119  m_componentData = KGlobal::mainComponent();
120  } else
121  {
122  QString name(QApplication::applicationName());
123 
124  if(name.isEmpty())
125  name=qAppName();
126 
127  if(name.isEmpty())
128  name="KStyle";
129 
130  m_componentData = KComponentData(name.toLatin1(), name.toLatin1(), KComponentData::SkipMainComponentRegistration);
131  }
132  selectionCache.setMaxCost(10);
133  controlCounter = subElementCounter = X_KdeBase;
134  hintCounter = X_KdeBase+1; //sic! X_KdeBase is covered by SH_KCustomStyleElement
135 }
136 
137 
138 // ----------------------------------------------------------------------------
139 
140 
141 KStyle::KStyle() : clickedLabel(0), d(new KStylePrivate)
142 {
143  //Set up some default metrics...
144  setWidgetLayoutProp(WT_Generic, Generic::DefaultFrameWidth, 2);
145  setWidgetLayoutProp(WT_Generic, Generic::DefaultLayoutSpacing, 6);
146  setWidgetLayoutProp(WT_Generic, Generic::DefaultLayoutMargin, 9);
147 
148  setWidgetLayoutProp(WT_PushButton, PushButton::ContentsMargin, 5);
149  setWidgetLayoutProp(WT_PushButton, PushButton::FocusMargin, 3);
150  setWidgetLayoutProp(WT_PushButton, PushButton::PressedShiftHorizontal, 2);
151  setWidgetLayoutProp(WT_PushButton, PushButton::PressedShiftVertical, 2);
152  setWidgetLayoutProp(WT_PushButton, PushButton::MenuIndicatorSize, 8);
153  setWidgetLayoutProp(WT_PushButton, PushButton::TextToIconSpace, 6);
154 
155  setWidgetLayoutProp(WT_Splitter, Splitter::Width, 6); //As KStyle in KDE3
156 
157  setWidgetLayoutProp(WT_CheckBox, CheckBox::Size, 16);
158  setWidgetLayoutProp(WT_CheckBox, CheckBox::BoxTextSpace, 6);
159  setWidgetLayoutProp(WT_CheckBox, CheckBox::NoLabelFocusMargin, 1);
160 
161  setWidgetLayoutProp(WT_RadioButton, RadioButton::Size, 16);
162  setWidgetLayoutProp(WT_RadioButton, RadioButton::BoxTextSpace, 6);
163 
164  setWidgetLayoutProp(WT_DockWidget, DockWidget::TitleTextColor,
165  ColorMode(QPalette::HighlightedText));
166  setWidgetLayoutProp(WT_DockWidget, DockWidget::TitleMargin, 2);
167  setWidgetLayoutProp(WT_DockWidget, DockWidget::FrameWidth, 3);
168  setWidgetLayoutProp(WT_DockWidget, DockWidget::SeparatorExtent, 6);
169 
170  setWidgetLayoutProp(WT_ProgressBar, ProgressBar::GrooveMargin, 2);
171  setWidgetLayoutProp(WT_ProgressBar, ProgressBar::SideTextSpace, 3); //(Matches QCommonStyle)
172  setWidgetLayoutProp(WT_ProgressBar, ProgressBar::MaxBusyIndicatorSize, 10000);
173  setWidgetLayoutProp(WT_ProgressBar, ProgressBar::BusyIndicatorSize, 10);
174  setWidgetLayoutProp(WT_ProgressBar, ProgressBar::Precision, 1);
175 
176  setWidgetLayoutProp(WT_MenuBar, MenuBar::ItemSpacing, 14);
177  setWidgetLayoutProp(WT_MenuBar, MenuBar::Margin, 2);
178  setWidgetLayoutProp(WT_MenuBar, MenuBar::Margin + Left, 4);
179  setWidgetLayoutProp(WT_MenuBar, MenuBar::Margin + Right, 4);
180 
181  setWidgetLayoutProp(WT_MenuBarItem, MenuBarItem::Margin, 1);
182 
183  setWidgetLayoutProp(WT_Menu, Menu::FrameWidth, 1);
184  setWidgetLayoutProp(WT_Menu, Menu::Margin, 3);
185  setWidgetLayoutProp(WT_Menu, Menu::ScrollerHeight, 10);
186  setWidgetLayoutProp(WT_Menu, Menu::TearOffHeight, 10);
187 
188  setWidgetLayoutProp(WT_MenuItem, MenuItem::CheckWidth, 12);
189  setWidgetLayoutProp(WT_MenuItem, MenuItem::CheckSpace, 3);
190  setWidgetLayoutProp(WT_MenuItem, MenuItem::IconWidth, 12);
191  setWidgetLayoutProp(WT_MenuItem, MenuItem::IconSpace, 3);
192  setWidgetLayoutProp(WT_MenuItem, MenuItem::ArrowWidth, 11);
193  setWidgetLayoutProp(WT_MenuItem, MenuItem::ArrowSpace, 3);
194  setWidgetLayoutProp(WT_MenuItem, MenuItem::Margin, 2);
195  setWidgetLayoutProp(WT_MenuItem, MenuItem::SeparatorHeight, 0); //the margins give enough rooms
196  setWidgetLayoutProp(WT_MenuItem, MenuItem::MinHeight, 16);
197  setWidgetLayoutProp(WT_MenuItem, MenuItem::TextColor, ColorMode(QPalette::Text));
198  setWidgetLayoutProp(WT_MenuItem, MenuItem::ActiveTextColor, ColorMode(QPalette::HighlightedText));
199  setWidgetLayoutProp(WT_MenuItem, MenuItem::DisabledTextColor, ColorMode(QPalette::Text));
200  setWidgetLayoutProp(WT_MenuItem, MenuItem::ActiveDisabledTextColor, ColorMode(QPalette::Text));
201  setWidgetLayoutProp(WT_MenuItem, MenuItem::AccelSpace, 16);
202 
203  //KDE default is single top button, double bottom one
204  setWidgetLayoutProp(WT_ScrollBar, ScrollBar::DoubleTopButton, 0);
205  setWidgetLayoutProp(WT_ScrollBar, ScrollBar::DoubleBotButton, 1);
206  setWidgetLayoutProp(WT_ScrollBar, ScrollBar::SingleButtonHeight, 16);
207  setWidgetLayoutProp(WT_ScrollBar, ScrollBar::DoubleButtonHeight, 32);
208  setWidgetLayoutProp(WT_ScrollBar, ScrollBar::BarWidth, 16);
209  setWidgetLayoutProp(WT_ScrollBar, ScrollBar::ArrowColor,
210  ColorMode(ColorMode::BWAutoContrastMode, QPalette::Button));
211  setWidgetLayoutProp(WT_ScrollBar, ScrollBar::ActiveArrowColor,
212  ColorMode(ColorMode::BWAutoContrastMode, QPalette::ButtonText));
213 
214  setWidgetLayoutProp(WT_TabBar, TabBar::TabContentsMargin, 6);
215  setWidgetLayoutProp(WT_TabBar, TabBar::TabFocusMargin, 3);
216  setWidgetLayoutProp(WT_TabBar, TabBar::TabOverlap, 0);
217  setWidgetLayoutProp(WT_TabBar, TabBar::BaseHeight, 2);
218  setWidgetLayoutProp(WT_TabBar, TabBar::BaseOverlap, 2);
219  setWidgetLayoutProp(WT_TabBar, TabBar::ScrollButtonWidth, 10);
220  setWidgetLayoutProp(WT_TabBar, TabBar::TabTextToIconSpace, 6);
221 
222  setWidgetLayoutProp(WT_TabWidget, TabWidget::ContentsMargin, 2);
223 
224  setWidgetLayoutProp(WT_Tree, Tree::MaxExpanderSize, 9);
225 
226  setWidgetLayoutProp(WT_Slider, Slider::HandleThickness, 20);
227  setWidgetLayoutProp(WT_Slider, Slider::HandleLength, 16);
228 
229  setWidgetLayoutProp(WT_SpinBox, SpinBox::FrameWidth, 1);
230  setWidgetLayoutProp(WT_SpinBox, SpinBox::ButtonWidth, 16);
231  setWidgetLayoutProp(WT_SpinBox, SpinBox::ButtonSpacing, 1);
232  setWidgetLayoutProp(WT_SpinBox, SpinBox::ButtonMargin+Right, 1);
233  setWidgetLayoutProp(WT_SpinBox, SpinBox::ButtonMargin+Top, 1);
234  setWidgetLayoutProp(WT_SpinBox, SpinBox::ButtonMargin+Bot, 1);
235 
236  setWidgetLayoutProp(WT_ComboBox, ComboBox::FrameWidth, 1);
237  setWidgetLayoutProp(WT_ComboBox, ComboBox::ButtonWidth, 16);
238  setWidgetLayoutProp(WT_ComboBox, ComboBox::ButtonMargin+Right, 1);
239  setWidgetLayoutProp(WT_ComboBox, ComboBox::ButtonMargin+Top, 1);
240  setWidgetLayoutProp(WT_ComboBox, ComboBox::ButtonMargin+Bot, 1);
241  setWidgetLayoutProp(WT_ComboBox, ComboBox::FocusMargin, 1);
242 
243  setWidgetLayoutProp(WT_Header, Header::ContentsMargin, 3);
244  setWidgetLayoutProp(WT_Header, Header::TextToIconSpace, 3);
245  setWidgetLayoutProp(WT_Header, Header::MarkSize, 9);
246 
247  setWidgetLayoutProp(WT_GroupBox, GroupBox::FrameWidth, 2);
248  setWidgetLayoutProp(WT_GroupBox, GroupBox::TextAlignTop, false);
249  setWidgetLayoutProp(WT_GroupBox, GroupBox::TitleTextColor, ColorMode(QPalette::Text));
250 
251  setWidgetLayoutProp(WT_ToolBar, ToolBar::HandleExtent, 6);
252  setWidgetLayoutProp(WT_ToolBar, ToolBar::SeparatorExtent, 6);
253  setWidgetLayoutProp(WT_ToolBar, ToolBar::ExtensionExtent, 10);
254  setWidgetLayoutProp(WT_ToolBar, ToolBar::FrameWidth, 2);
255  setWidgetLayoutProp(WT_ToolBar, ToolBar::ItemSpacing, 3);
256  setWidgetLayoutProp(WT_ToolBar, ToolBar::ItemMargin, 1);
257 
258  setWidgetLayoutProp(WT_ToolButton, ToolButton::ContentsMargin, 5);
259  setWidgetLayoutProp(WT_ToolButton, ToolButton::FocusMargin, 3);
260  setWidgetLayoutProp(WT_ToolButton, ToolButton::MenuIndicatorSize, 11);
261 
262  setWidgetLayoutProp(WT_ToolBoxTab, ToolBoxTab::Margin, 0);
263 
264  setWidgetLayoutProp(WT_Window, Window::TitleTextColor, ColorMode(QPalette::HighlightedText));
265  setWidgetLayoutProp(WT_Window, Window::TitleHeight, 20);
266  setWidgetLayoutProp(WT_Window, Window::TitleMargin, 2);
267  setWidgetLayoutProp(WT_Window, Window::NoTitleFrame, 0);
268  setWidgetLayoutProp(WT_Window, Window::ButtonWidth, 16);
269  setWidgetLayoutProp(WT_Window, Window::ButtonSpace, 2);
270  setWidgetLayoutProp(WT_Window, Window::ButtonToTextSpace, 3);
271 }
272 
273 KStyle::~KStyle()
274 {
275  // this is just for stupid msvc compiler to force the creation of
276  // DoubleButtonOption::defaultOption() inside kstyle lib
277  // hope the optimizer won't throw it away
278  const DoubleButtonOption* bOpt = extractOption<const DoubleButtonOption*>(NULL);
279  Q_UNUSED(bOpt)
280 #ifdef __GNUC__
281 #warning "mem leak: need to delete bOpt"
282 #endif
283  delete d;
284 }
285 
286 
287 /*
288  Custom Style Element runtime extension:
289  We reserve one StyleHint to let the effective style inform widgets whether it supports certain
290  string based style elements.
291  As this could lead to number conflicts (i.e. an app utilizing one of the hints itself for other
292  purposes) there're various safety mechanisms to rule out such interference.
293 
294  1) It's most unlikely that a widget in some 3rd party app will accidentally call a general
295  QStyle/KStyle styleHint() or draw*() and (unconditionally) expect a valid return, however:
296  a. The StyleHint is not directly above Qt's custom base, assuming most 3rd party apps would
297  - in case - make use of such
298  b. In order to be accepted, the StyleHint query must pass a widget with a perfectly matching
299  name, containing the typical element prefix ("CE_", etc.) and being supported by the current style
300  c. Instead using Qt's fragile qstyleoption_cast on the QStyleOption provided to the StyleHint
301  query, try to dump out a string and hope for the best, we now manipulate the widgets objectName().
302  Plain Qt dependent widgets can do that themselves and if a widget uses KStyle's convenience access
303  functions, it won't notice this at all
304 
305  2) The key problem is that a common KDE widget will run into an apps custom style which will then
306  falsely respond to the styleHint() call with an invalid value.
307  To prevent this, supporting styles *must* set a Q_CLASSINFO "X-KDE-CustomElements".
308 
309  3) If any of the above traps snaps, the returned id is 0 - the QStyle default, indicating
310  that this element is not supported by the current style.
311 
312  Obviously, this contains the "diminished clean" action to (temporarily) manipulate the
313  objectName() of a const QWidget* - but this happens completely inside KStyle or the widget, if
314  it does not make use of KStyles static convenience functions.
315  My biggest worry here would be, that in a multithreaded environment a thread (usually not being
316  owner of the widget) does something crucially relying on the widgets name property...
317  This however would also have to happen during the widget construction or stylechanges, when
318  the functions in doubt will typically be called.
319  So this is imho unlikely causing any trouble, ever.
320 */
321 
322 /*
323  The functions called by the real style implementation to add support for a certain element.
324  Checks for well-formed string (containing the element prefix) and returns 0 otherwise.
325  Checks whether the element is already supported or inserts it otherwise; Returns the proper id
326  NOTICE: We could check for "X-KDE-CustomElements", but this would bloat style start up times
327  (if they e.g. register 100 elements or so)
328 */
329 
330 
331 static inline int newStyleElement(const QString &element, const char *check, int &counter, QHash<QString, int> *elements)
332 {
333  if (!element.contains(check))
334  return 0;
335  int id = elements->value(element, 0);
336  if (!id) {
337  ++counter;
338  id = counter;
339  elements->insert(element, id);
340  }
341  return id;
342 }
343 
344 QStyle::StyleHint KStyle::newStyleHint(const QString &element)
345 {
346  return (StyleHint)newStyleElement(element, "SH_", d->hintCounter, &d->styleElements);
347 }
348 
349 QStyle::ControlElement KStyle::newControlElement(const QString &element)
350 {
351  return (ControlElement)newStyleElement(element, "CE_", d->controlCounter, &d->styleElements);
352 }
353 
354 KStyle::SubElement KStyle::newSubElement(const QString &element)
355 {
356  return (SubElement)newStyleElement(element, "SE_", d->subElementCounter, &d->styleElements);
357 }
358 
359 
360 QString KStyle::defaultStyle()
361 {
362 #if defined(Q_WS_X11) && !defined(Q_WS_MAEMO_5) || defined(Q_WS_WIN)
363  return QString("oxygen");
364 #else
365  return QString(); // native style
366 #endif
367 }
368 
369 /*
370  The functions called by widgets that request custom element support, passed to the effective style.
371  Collected in a static inline function due to similarity.
372 */
373 
374 static inline int customStyleElement(QStyle::StyleHint type, const QString &element, QWidget *widget)
375 {
376  if (!widget || widget->style()->metaObject()->indexOfClassInfo("X-KDE-CustomElements") < 0)
377  return 0;
378 
379  const QString originalName = widget->objectName();
380  widget->setObjectName(element);
381  const int id = widget->style()->styleHint(type, 0, widget);
382  widget->setObjectName(originalName);
383  return id;
384 }
385 
386 QStyle::StyleHint KStyle::customStyleHint(const QString &element, const QWidget *widget)
387 {
388  return (StyleHint) customStyleElement(SH_KCustomStyleElement, element, const_cast<QWidget*>(widget));
389 }
390 
391 QStyle::ControlElement KStyle::customControlElement(const QString &element, const QWidget *widget)
392 {
393  return (ControlElement) customStyleElement(SH_KCustomStyleElement, element, const_cast<QWidget*>(widget));
394 }
395 
396 QStyle::SubElement KStyle::customSubElement(const QString &element, const QWidget *widget)
397 {
398  return (SubElement) customStyleElement(SH_KCustomStyleElement, element, const_cast<QWidget*>(widget));
399 }
400 
401 void KStyle::polish(QWidget *w)
402 {
403  if (qobject_cast<QLabel*>(w) ) {
404  w->installEventFilter(this);
405  }
406 
407  // Enable hover effects in all itemviews
408  if (QAbstractItemView *itemView = qobject_cast<QAbstractItemView*>(w) ) {
409  itemView->viewport()->setAttribute(Qt::WA_Hover);
410  }
411 
412  QCommonStyle::polish(w);
413 }
414 void KStyle::unpolish(QWidget *w)
415 {
416  if (qobject_cast<QLabel*>(w) ) {
417  w->removeEventFilter(this);
418  }
419 
420  QCommonStyle::unpolish(w);
421 }
422 void KStyle::polish(QApplication *a)
423 {
424  QCommonStyle::polish(a);
425 }
426 void KStyle::unpolish(QApplication *a)
427 {
428  QCommonStyle::unpolish(a);
429 }
430 void KStyle::polish(QPalette &pal)
431 {
432  QCommonStyle::polish(pal);
433 }
434 QRect KStyle::itemTextRect(const QFontMetrics &fm, const QRect &r,
435  int flags, bool enabled,
436  const QString &text) const
437 {
438  return QCommonStyle::itemTextRect(fm, r, flags, enabled, text);
439 }
440 QRect KStyle::itemPixmapRect(const QRect &r, int flags, const QPixmap &pixmap) const
441 {
442  return QCommonStyle::itemPixmapRect(r, flags, pixmap);
443 }
444 void KStyle::drawItemText(QPainter *painter, const QRect &rect,
445  int flags, const QPalette &pal, bool enabled,
446  const QString &text, QPalette::ColorRole textRole) const
447 {
448  QCommonStyle::drawItemText(painter, rect, flags, pal, enabled,
449  text, textRole);
450 }
451 void KStyle::drawItemPixmap(QPainter *painter, const QRect &rect,
452  int alignment, const QPixmap &pixmap) const
453 {
454  QCommonStyle::drawItemPixmap(painter, rect, alignment, pixmap);
455 }
456 QPalette KStyle::standardPalette() const
457 {
458  return KGlobalSettings::createApplicationPalette(
459  KSharedConfig::openConfig(d->m_componentData));
460 }
461 
462 QIcon KStyle::standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *option,
463  const QWidget *widget) const
464 {
465  switch (standardIcon) {
466  case QStyle::SP_DesktopIcon:
467  return KIcon("user-desktop");
468  case QStyle::SP_TrashIcon:
469  return KIcon("user-trash");
470  case QStyle::SP_ComputerIcon:
471  return KIcon("computer");
472  case QStyle::SP_DriveFDIcon:
473  return KIcon("media-floppy");
474  case QStyle::SP_DriveHDIcon:
475  return KIcon("drive-harddisk");
476  case QStyle::SP_DriveCDIcon:
477  case QStyle::SP_DriveDVDIcon:
478  return KIcon("drive-optical");
479  case QStyle::SP_DriveNetIcon:
480  return KIcon("folder-remote");
481  case QStyle::SP_DirHomeIcon:
482  return KIcon("user-home");
483  case QStyle::SP_DirOpenIcon:
484  return KIcon("document-open-folder");
485  case QStyle::SP_DirClosedIcon:
486  return KIcon("folder");
487  case QStyle::SP_DirIcon:
488  return KIcon("folder");
489  case QStyle::SP_DirLinkIcon:
490  return KIcon("folder"); //TODO: generate (!?) folder with link emblem
491  case QStyle::SP_FileIcon:
492  return KIcon("text-plain"); //TODO: look for a better icon
493  case QStyle::SP_FileLinkIcon:
494  return KIcon("text-plain"); //TODO: generate (!?) file with link emblem
495  case QStyle::SP_FileDialogStart:
496  return KIcon("media-playback-start"); //TODO: find correct icon
497  case QStyle::SP_FileDialogEnd:
498  return KIcon("media-playback-stop"); //TODO: find correct icon
499  case QStyle::SP_FileDialogToParent:
500  return KIcon("go-up");
501  case QStyle::SP_FileDialogNewFolder:
502  return KIcon("folder-new");
503  case QStyle::SP_FileDialogDetailedView:
504  return KIcon("view-list-details");
505  case QStyle::SP_FileDialogInfoView:
506  return KIcon("document-properties");
507  case QStyle::SP_FileDialogContentsView:
508  return KIcon("view-list-icons");
509  case QStyle::SP_FileDialogListView:
510  return KIcon("view-list-text");
511  case QStyle::SP_FileDialogBack:
512  return KIcon("go-previous");
513  case QStyle::SP_MessageBoxInformation:
514  return KIcon("dialog-information");
515  case QStyle::SP_MessageBoxWarning:
516  return KIcon("dialog-warning");
517  case QStyle::SP_MessageBoxCritical:
518  return KIcon("dialog-error");
519  case QStyle::SP_MessageBoxQuestion:
520  return KIcon("dialog-information");
521  case QStyle::SP_DialogOkButton:
522  return KIcon("dialog-ok");
523  case QStyle::SP_DialogCancelButton:
524  return KIcon("dialog-cancel");
525  case QStyle::SP_DialogHelpButton:
526  return KIcon("help-contents");
527  case QStyle::SP_DialogOpenButton:
528  return KIcon("document-open");
529  case QStyle::SP_DialogSaveButton:
530  return KIcon("document-save");
531  case QStyle::SP_DialogCloseButton:
532  return KIcon("dialog-close");
533  case QStyle::SP_DialogApplyButton:
534  return KIcon("dialog-ok-apply");
535  case QStyle::SP_DialogResetButton:
536  return KIcon("document-revert");
537  case QStyle::SP_DialogDiscardButton:
538  return KIcon("dialog-cancel");
539  case QStyle::SP_DialogYesButton:
540  return KIcon("dialog-ok-apply");
541  case QStyle::SP_DialogNoButton:
542  return KIcon("dialog-cancel");
543  case QStyle::SP_ArrowUp:
544  return KIcon("go-up");
545  case QStyle::SP_ArrowDown:
546  return KIcon("go-down");
547  case QStyle::SP_ArrowLeft:
548  return KIcon("go-previous-view");
549  case QStyle::SP_ArrowRight:
550  return KIcon("go-next-view");
551  case QStyle::SP_ArrowBack:
552  return KIcon("go-previous");
553  case QStyle::SP_ArrowForward:
554  return KIcon("go-next");
555  case QStyle::SP_BrowserReload:
556  return KIcon("view-refresh");
557  case QStyle::SP_BrowserStop:
558  return KIcon("process-stop");
559  case QStyle::SP_MediaPlay:
560  return KIcon("media-playback-start");
561  case QStyle::SP_MediaStop:
562  return KIcon("media-playback-stop");
563  case QStyle::SP_MediaPause:
564  return KIcon("media-playback-pause");
565  case QStyle::SP_MediaSkipForward:
566  return KIcon("media-skip-forward");
567  case QStyle::SP_MediaSkipBackward:
568  return KIcon("media-skip-backward");
569  case QStyle::SP_MediaSeekForward:
570  return KIcon("media-seek-forward");
571  case QStyle::SP_MediaSeekBackward:
572  return KIcon("media-seek-backward");
573  case QStyle::SP_MediaVolume:
574  return KIcon("audio-volume-medium");
575  case QStyle::SP_MediaVolumeMuted:
576  return KIcon("audio-volume-muted");
577 
578  default:
579  return QStyle::standardIconImplementation(standardIcon, option, widget);
580  }
581 }
582 
583 QPixmap KStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt,
584  const QWidget *widget) const
585 {
586  return QCommonStyle::standardPixmap(standardPixmap, opt, widget);
587 }
588 QPixmap KStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap,
589  const QStyleOption *opt) const
590 {
591  return QCommonStyle::generatedIconPixmap(iconMode, pixmap, opt);
592 }
593 
594 void KStyle::drawInsideRect(QPainter* p, const QRect& r) const
595 {
596  p->drawRect(r.x(), r.y(), r.width() - 1, r.height() - 1);
597 }
598 
599 QRect KStyle::centerRect(const QRect &in, int w, int h) const
600 {
601  return QRect(in.x() + (in.width() - w)/2, in.y() + (in.height() - h)/2, w, h);
602 }
603 
604 QRect KStyle::centerRect(const QRect &in, const QSize &size) const
605 {
606  return centerRect(in, size.width(), size.height());
607 }
608 
609 
610 
611 void KStyle::drawKStylePrimitive(WidgetType widgetType, int primitive,
612  const QStyleOption* opt,
613  const QRect &r, const QPalette &pal,
614  State flags, QPainter* p,
615  const QWidget* widget,
616  KStyle::Option* kOpt) const
617 {
618  switch (widgetType)
619  {
620  case WT_Tree:
621  {
622  switch (primitive)
623  {
624  case Tree::VerticalBranch:
625  case Tree::HorizontalBranch:
626  //### FIXME: set sane color.
627  p->fillRect(r, QBrush(Qt::Dense4Pattern));
628  return;
629  case Tree::ExpanderOpen:
630  case Tree::ExpanderClosed:
631  {
632  p->setPen(pal.text().color());
633  drawInsideRect(p, r); //the border.
634  int signLineSize = r.width()/4;
635  p->drawLine(r.center().x() - signLineSize, r.center().y(),
636  r.center().x() + signLineSize, r.center().y()); //-
637  if (primitive == Tree::ExpanderClosed) //vertical line of +
638  p->drawLine(r.center().x(), r.center().y() - signLineSize,
639  r.center().x(), r.center().y() + signLineSize);
640  return;
641  }
642  default:
643  break;
644  }
645 
646  break;
647  }
648 
649  case WT_SpinBox:
650  {
651  switch (primitive)
652  {
653  case SpinBox::PlusSymbol:
654  case SpinBox::MinusSymbol:
655  {
656  p->setPen( pal.buttonText().color() );
657 
658  int l = qMin( r.width()-2, r.height()-2 );
659  QPoint c = r.center();
660 
661  p->drawLine( c.x()-l/2, c.y(), c.x()+l/2, c.y() );
662  if (primitive == SpinBox::PlusSymbol ) {
663  p->drawLine( c.x(), c.y()-l/2, c.x(), c.y()+l/2 );
664  }
665 
666  return;
667  }
668  default:
669  break;
670  }
671 
672  break;
673  }
674 
675  case WT_GroupBox:
676  {
677  if (primitive == GroupBox::FlatFrame) {
678  QPen oldPen = p->pen();
679  p->setPen(pal.color(QPalette::WindowText) );
680  p->drawLine(r.topLeft(), r.topRight() );
681  p->setPen(oldPen);
682  }
683 
684  break;
685  }
686 
687  case WT_ToolBoxTab:
688  {
689  if (primitive == ToolBoxTab::Panel) {
690  drawKStylePrimitive(WT_ToolButton, ToolButton::Panel, opt, r, pal, flags, p, widget);
691  }
692 
693  break;
694  }
695 
696  case WT_DockWidget:
697  {
698  switch (primitive)
699  {
700  case DockWidget::TitlePanel:
701  p->fillRect(r, pal.color(QPalette::Highlight) );
702  return;
703 
704  case DockWidget::SeparatorHandle:
705  return;
706 
707  default:
708  break;
709  }
710 
711  break;
712  }
713 
714  case WT_Window:
715  {
716  switch (primitive)
717  {
718  case Window::TitlePanel:
719  p->fillRect(r, pal.color(QPalette::Highlight) );
720  return;
721 
722  case Window::ButtonMenu:
723  {
724  KStyle::TitleButtonOption* tbkOpts =
725  extractOption<KStyle::TitleButtonOption*>(kOpt);
726  if (!tbkOpts->icon.isNull()) {
727  tbkOpts->icon.paint(p, r);
728  } else {
729  QStyleOption tool(0);
730  tool.palette = pal;
731  // TODO: give it a nice KDE logo.
732  QPixmap pm = standardPixmap(SP_TitleBarMenuButton, &tool, widget);
733  tool.rect = r;
734  p->save();
735  drawItemPixmap(p, r, Qt::AlignCenter, pm);
736  p->restore();
737  }
738  return;
739  }
740 
741  case Window::ButtonMin:
742  case Window::ButtonMax:
743  case Window::ButtonRestore:
744  case Window::ButtonClose:
745  case Window::ButtonShade:
746  case Window::ButtonUnshade:
747  case Window::ButtonHelp:
748  {
749  KStyle::TitleButtonOption* tbkOpts =
750  extractOption<KStyle::TitleButtonOption*>(kOpt);
751  State bflags = flags;
752  bflags &= ~State_Sunken;
753  if (tbkOpts->active)
754  bflags |= State_Sunken;
755  drawKStylePrimitive(WT_ToolButton, ToolButton::Panel, opt, r, pal, bflags, p, widget);
756  return;
757  }
758  }
759 
760  break;
761  }
762 
763  case WT_TabBar:
764  {
765  // For vertical text fallback, provide the generic text implementation
766  // a transformed rotated painter, with rect swizzled appropriately
767  if (primitive == TabBar::EastText || primitive == TabBar::WestText)
768  {
769  QTransform tr;
770 
771  if (primitive == TabBar::WestText)
772  {
773  tr.translate(r.x(), r.height() + r.y());
774  tr.rotate(-90);
775  }
776  else
777  {
778  tr.translate(r.width() + r.x(), r.y());
779  tr.rotate(90);
780  }
781 
782  p->save();
783  p->setTransform(tr, true);
784  drawKStylePrimitive(WT_TabBar, Generic::Text, opt,
785  QRect(0, 0, r.height(), r.width()), pal, flags, p, widget, kOpt);
786  p->restore();
787  }
788  break;
789  }
790 
791  default:
792  break;
793  }
794 
795  if (primitive == Generic::Text)
796  {
797  KStyle::TextOption* textOpts = extractOption<KStyle::TextOption*>(kOpt);
798 
799  //### debug
800  //p->setPen(Qt::green);
801  //drawInsideRect(p, r);
802 
803  QColor col = textOpts->color.color(pal);
804  QPen old = p->pen();
805  p->setPen(col);
806  drawItemText(p, r, Qt::AlignVCenter | Qt::TextShowMnemonic | textOpts->hAlign, pal, flags & State_Enabled,
807  textOpts->text);
808  p->setPen(old);
809  }
810  else if (primitive == Generic::Icon)
811  {
812  KStyle::IconOption* iconOpts = extractOption<KStyle::IconOption*>(kOpt);
813  QIcon::Mode mode;
814  QIcon::State iconState;
815 
816  // Select the correct icon from the iconset
817  if (flags & State_Enabled)
818  if (iconOpts->active)
819  mode = QIcon::Active;
820  else
821  mode = QIcon::Normal;
822  else
823  mode = QIcon::Disabled;
824 
825  if( (flags & State_On) || (flags & State_Sunken) )
826  iconState = QIcon::On;
827  else
828  iconState = QIcon::Off;
829 
830  QSize size = iconOpts->size;
831  if(!size.isValid())
832  size = QSize(pixelMetric(PM_SmallIconSize), pixelMetric(PM_SmallIconSize));
833  QPixmap icon = iconOpts->icon.pixmap(size, mode, iconState);
834  p->drawPixmap(centerRect(r, icon.size()), icon);
835  }
836  else if (primitive == Generic::FocusIndicator)
837  {
838  QPen pen;
839  pen.setWidth(0);
840  pen.setStyle(Qt::DotLine);
841  p->setPen(pen);
842  drawInsideRect(p, r);
843  }
844  else if (primitive >= Generic::ArrowUp && primitive <= Generic::ArrowLeft)
845  {
846  //### FIXME: Helper for these sorts of things, as Keramik has virtually
847  //identical code!
848  KStyle::ColorOption* colorOpt = extractOption<KStyle::ColorOption*>(kOpt);
849  QColor arrowColor = colorOpt->color.color(pal);
850 
851  QPolygon poly;
852 
853  switch (primitive)
854  {
855  case Generic::ArrowUp:
856  poly.setPoints(QCOORDARRLEN(u_arrow), u_arrow);
857  break;
858 
859  case Generic::ArrowDown:
860  poly.setPoints(QCOORDARRLEN(d_arrow), d_arrow);
861  break;
862 
863  case Generic::ArrowLeft:
864  poly.setPoints(QCOORDARRLEN(l_arrow), l_arrow);
865  break;
866 
867  default:
868  poly.setPoints(QCOORDARRLEN(r_arrow), r_arrow);
869  }
870 
871  if ( flags & State_Enabled )
872  {
873  //CHECKME: Why is the -1 needed?
874  poly.translate(r.x() + r.width()/2 - 1, r.y() + r.height()/2);
875 
876  p->setPen(arrowColor);
877  p->drawPolygon(poly);
878  }
879  else
880  {
881  //Disabled ones ignore color parameter
882  poly.translate(r.x() + r.width()/2, r.y() + r.height()/2 + 1);
883  p->setPen( pal.color( QPalette::Light ) );
884  p->drawPolygon(poly);
885  poly.translate(-1,-1);
886  p->setPen(pal.mid().color());
887  p->drawPolygon(poly);
888  }
889 
890  }
891 #if 0 //Reenable if you need a debug aid
892  else
893  {
894  p->setPen(Qt::red);
895  drawInsideRect(p, r);
896  }
897 #endif
898 }
899 
900 
901 void KStyle::setWidgetLayoutProp(WidgetType widget, int metric, int value)
902 {
903  if (metrics.size() <= widget)
904  metrics.resize(widget + 1);
905 
906  QVector<int>& widgetMetrics = metrics[widget];
907  if (widgetMetrics.size() <= metric)
908  widgetMetrics.resize(metric + 1);
909 
910  widgetMetrics[metric] = value;
911 }
912 
913 int KStyle::widgetLayoutProp(WidgetType widget, int metric,
914  const QStyleOption* opt,
915  const QWidget* w ) const
916 {
917  Q_UNUSED(opt)
918  Q_UNUSED(w)
919 
920  if (metrics.size() <= widget)
921  return 0;
922 
923  const QVector<int>& widgetMetrics = metrics[widget];
924  if (widgetMetrics.size() <= metric)
925  return 0;
926 
927  return widgetMetrics[metric];
928 }
929 
930 QSize KStyle::expandDim(const QSize& orig, WidgetType wt, int baseMarginMetric,
931  const QStyleOption* opt, const QWidget* w, bool rotated) const
932 {
933  int addWidth = 2*widgetLayoutProp(wt, baseMarginMetric + MainMargin, opt, w) +
934  widgetLayoutProp(wt, baseMarginMetric + Left, opt, w) +
935  widgetLayoutProp(wt, baseMarginMetric + Right, opt, w);
936 
937  int addHeight = 2*widgetLayoutProp(wt, baseMarginMetric + MainMargin, opt, w) +
938  widgetLayoutProp(wt, baseMarginMetric + Top, opt, w) +
939  widgetLayoutProp(wt, baseMarginMetric + Bot, opt, w);
940 
941  return QSize(orig.width() + (rotated? addHeight: addWidth),
942  orig.height() + (rotated? addWidth: addHeight));
943 }
944 
945 QRect KStyle::insideMargin(const QRect &orig, WidgetType wt,
946  int baseMarginMetric,
947  const QStyleOption* opt, const QWidget* w) const
948 {
949  int x1 = orig.topLeft().x();
950  int y1 = orig.topLeft().y();
951  int x2 = orig.bottomRight().x();
952  int y2 = orig.bottomRight().y();
953 
954  x1 += widgetLayoutProp(wt, baseMarginMetric + MainMargin, opt, w);
955  x1 += widgetLayoutProp(wt, baseMarginMetric + Left, opt, w);
956 
957  y1 += widgetLayoutProp(wt, baseMarginMetric + MainMargin, opt, w);
958  y1 += widgetLayoutProp(wt, baseMarginMetric + Top, opt, w);
959 
960  x2 -= widgetLayoutProp(wt, baseMarginMetric + MainMargin, opt, w);
961  x2 -= widgetLayoutProp(wt, baseMarginMetric + Right, opt, w);
962 
963  y2 -= widgetLayoutProp(wt, baseMarginMetric + MainMargin, opt, w);
964  y2 -= widgetLayoutProp(wt, baseMarginMetric + Bot, opt, w);
965 
966  return QRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
967 }
968 
969 QRect KStyle::handleRTL(const QStyleOption* opt, const QRect& subRect) const
970 {
971  return visualRect(opt->direction, opt->rect, subRect);
972 }
973 
974 QPoint KStyle::handleRTL(const QStyleOption* opt, const QPoint& pos) const
975 {
976  return visualPos(opt->direction, opt->rect, pos);
977 }
978 
979 void KStyle::drawPrimitive(PrimitiveElement elem, const QStyleOption* option, QPainter* painter, const QWidget* widget) const
980 {
981  //Extract the stuff we need out of the option
982  State flags = option->state;
983  QRect r = option->rect;
984  QPalette pal = option->palette;
985 
986  switch (elem)
987  {
988  case PE_FrameFocusRect:
989  drawKStylePrimitive(WT_Generic, Generic::FocusIndicator, option, r, pal, flags, painter, widget);
990  return;
991  case PE_IndicatorArrowUp:
992  drawKStylePrimitive(WT_Generic, Generic::ArrowUp, option, r, pal, flags, painter, widget);
993  return;
994  case PE_IndicatorArrowDown:
995  drawKStylePrimitive(WT_Generic, Generic::ArrowDown, option, r, pal, flags, painter, widget);
996  return;
997  case PE_IndicatorArrowLeft:
998  drawKStylePrimitive(WT_Generic, Generic::ArrowLeft, option, r, pal, flags, painter, widget);
999  return;
1000  case PE_IndicatorArrowRight:
1001  drawKStylePrimitive(WT_Generic, Generic::ArrowRight, option, r, pal, flags, painter, widget);
1002  return;
1003  case PE_IndicatorMenuCheckMark:
1004  //### check flags
1005  drawKStylePrimitive(WT_MenuItem, MenuItem::CheckOn, option, r, pal, flags, painter, widget);
1006  return;
1007  case PE_IndicatorCheckBox:
1008  if (flags & State_NoChange)
1009  drawKStylePrimitive(WT_CheckBox, CheckBox::CheckTriState, option, r, pal, flags, painter, widget);
1010  else if (flags & State_On)
1011  drawKStylePrimitive(WT_CheckBox, CheckBox::CheckOn, option, r, pal, flags, painter, widget);
1012  else
1013  drawKStylePrimitive(WT_CheckBox, CheckBox::CheckOff, option, r, pal, flags, painter, widget);
1014  return;
1015  case PE_IndicatorRadioButton:
1016  if (flags & State_On)
1017  drawKStylePrimitive(WT_RadioButton, RadioButton::RadioOn, option, r, pal, flags, painter, widget);
1018  else
1019  drawKStylePrimitive(WT_RadioButton, RadioButton::RadioOff, option, r, pal, flags, painter, widget);
1020  return;
1021  case PE_IndicatorBranch:
1022  {
1023  int centerX = r.x() + r.width()/2;
1024  int centerY = r.y() + r.height()/2;
1025 
1026  int expanderAdjust = 0;
1027  //First, determine whether we need to draw an expander.
1028  if (flags & State_Children)
1029  {
1030  //How large should we make it?
1031  int sizeLimit = qMin(qMin(r.width(), r.height()),
1032  widgetLayoutProp(WT_Tree, Tree::MaxExpanderSize, option, widget));
1033  if ((sizeLimit & 1) == 0)
1034  --sizeLimit;
1035 
1036  expanderAdjust = sizeLimit/2 + 1;
1037 
1038  QRect expanderRect = QRect(centerX - sizeLimit/2, centerY - sizeLimit/2,
1039  sizeLimit, sizeLimit);
1040 
1041  drawKStylePrimitive(WT_Tree, flags & State_Open ? Tree::ExpanderOpen : Tree::ExpanderClosed,
1042  option, expanderRect, pal, flags, painter, widget);
1043  }
1044 
1045  //Now, draw the branches. The top line gets drawn unless we're completely
1046  //w/o any indication of a neightbor
1047  if (flags & (State_Item | State_Children | State_Sibling))
1048  {
1049  QRect topLine = QRect(QPoint(centerX, r.y()), QPoint(centerX, centerY - expanderAdjust));
1050  drawKStylePrimitive(WT_Tree, Tree::VerticalBranch, option, topLine, pal, flags, painter, widget);
1051  }
1052 
1053  //The right/left (depending on dir) line gets drawn if we have an item
1054  if (flags & State_Item)
1055  {
1056  QRect horLine;
1057  if (option->direction == Qt::LeftToRight)
1058  horLine = QRect(QPoint(centerX + expanderAdjust, centerY),
1059  QPoint(r.right(), centerY));
1060  else
1061  horLine = QRect(QPoint(r.left(), centerY),
1062  QPoint(centerX - expanderAdjust, centerY));
1063  drawKStylePrimitive(WT_Tree, Tree::HorizontalBranch, option, horLine, pal, flags, painter, widget);
1064  }
1065 
1066  //The bottom if we have a sibling
1067  if (flags & State_Sibling)
1068  {
1069  QRect botLine = QRect(QPoint(centerX, centerY + expanderAdjust),
1070  QPoint(centerX, r.bottom()));
1071  drawKStylePrimitive(WT_Tree, Tree::VerticalBranch, option, botLine, pal, flags, painter, widget);
1072  }
1073  return;
1074  }
1075  case PE_FrameMenu:
1076  drawKStylePrimitive(WT_Menu, Generic::Frame, option, r, pal, flags, painter, widget);
1077  return;
1078  case PE_IndicatorHeaderArrow:
1079  {
1080  const QStyleOptionHeader *hOpt = qstyleoption_cast<const QStyleOptionHeader *>(option);
1081  int primitive = 0;
1082  if (flags&State_UpArrow || (hOpt && hOpt->sortIndicator==QStyleOptionHeader::SortUp))
1083  primitive = Generic::ArrowUp;
1084  else if (flags&State_DownArrow || (hOpt && hOpt->sortIndicator==QStyleOptionHeader::SortDown))
1085  primitive = Generic::ArrowDown;
1086  if (primitive != 0)
1087  drawKStylePrimitive(WT_Header, primitive, option, r, pal, flags, painter, widget);
1088  return;
1089  }
1090  case PE_FrameTabBarBase:
1091  {
1092  drawKStylePrimitive(WT_TabBar, TabBar::BaseFrame,option,r,pal,flags,painter,widget);
1093  return;
1094  }
1095  case PE_IndicatorTabTear:
1096  {
1097  drawKStylePrimitive(WT_TabBar, TabBar::IndicatorTear,option,r,pal,flags,painter,widget);
1098  return;
1099  }
1100  case PE_FrameTabWidget:
1101  {
1102  drawKStylePrimitive(WT_TabWidget, Generic::Frame,option,r,pal,flags,painter,widget);
1103  return;
1104  }
1105 
1106  case PE_PanelLineEdit:
1107  {
1108  drawKStylePrimitive(WT_LineEdit, LineEdit::Panel,option,r,pal,flags,painter,widget);
1109  return;
1110  }
1111 
1112  case PE_FrameLineEdit:
1113  {
1114  drawKStylePrimitive(WT_LineEdit, Generic::Frame,option,r,pal,flags,painter,widget);
1115  return;
1116  }
1117 
1118  case PE_FrameGroupBox:
1119  {
1120  if (const QStyleOptionFrame *fOpt =
1121  qstyleoption_cast<const QStyleOptionFrame *>(option))
1122  {
1123  QStyleOptionFrameV2 fOpt2(*fOpt);
1124 
1125  if (fOpt2.features & QStyleOptionFrameV2::Flat) {
1126  drawKStylePrimitive(WT_GroupBox, GroupBox::FlatFrame,option,r,pal,flags,painter,widget);
1127  } else {
1128  drawKStylePrimitive(WT_GroupBox, Generic::Frame,option,r,pal,flags,painter,widget);
1129  }
1130  }
1131  return;
1132  }
1133 
1134  case PE_FrameStatusBar:
1135  {
1136  drawKStylePrimitive(WT_StatusBar, Generic::Frame,option,r,pal,flags,painter,widget);
1137  return;
1138  }
1139 
1140  case PE_FrameDockWidget:
1141  {
1142  drawKStylePrimitive(WT_DockWidget, Generic::Frame,option,r,pal,flags,painter,widget);
1143  return;
1144  }
1145 
1146  case PE_IndicatorDockWidgetResizeHandle:
1147  {
1148  drawKStylePrimitive(WT_DockWidget, DockWidget::SeparatorHandle, option, r, pal, flags,
1149  painter, widget);
1150  return;
1151  }
1152 
1153  case PE_FrameWindow:
1154  {
1155  drawKStylePrimitive(WT_Window, Generic::Frame,option,r,pal,flags,painter,widget);
1156  return;
1157  }
1158 
1159  case PE_Frame:
1160  {
1161  drawKStylePrimitive(WT_Generic, Generic::Frame,option,r,pal,flags,painter,widget);
1162  return;
1163  }
1164 
1165  case PE_IndicatorToolBarHandle:
1166  {
1167  if (flags & State_Horizontal)
1168  drawKStylePrimitive(WT_ToolBar, ToolBar::HandleHor,
1169  option,r,pal,flags,painter,widget);
1170  else
1171  drawKStylePrimitive(WT_ToolBar, ToolBar::HandleVert,
1172  option,r,pal,flags,painter,widget);
1173  return;
1174  }
1175 
1176  case PE_IndicatorToolBarSeparator:
1177  drawKStylePrimitive(WT_ToolBar, ToolBar::Separator,option,r,pal,flags,painter,widget);
1178  return;
1179 
1180  case PE_PanelButtonCommand:
1181  //case PE_PanelButtonBevel: // ### CHECKME
1182  drawKStylePrimitive(WT_PushButton, PushButton::Panel, option, r, pal, flags, painter, widget);
1183  return;
1184  case PE_FrameDefaultButton:
1185  drawKStylePrimitive(WT_PushButton, PushButton::DefaultButtonFrame, option, r, pal, flags, painter, widget);
1186  return;
1187 
1188  case PE_PanelButtonTool:
1189  drawKStylePrimitive(WT_ToolButton, ToolButton::Panel,option,r,pal,flags,painter,widget);
1190  return;
1191 
1192  case PE_IndicatorButtonDropDown:
1193  drawKStylePrimitive(WT_ToolButton, Generic::ArrowDown, option, r, pal, flags, painter, widget);
1194  return;
1195 
1196  case PE_PanelItemViewItem: {
1197 
1198  const QStyleOptionViewItemV4 *opt = qstyleoption_cast<const QStyleOptionViewItemV4*>(option);
1199  const QAbstractItemView *view = qobject_cast<const QAbstractItemView *>(widget);
1200  bool hover = (option->state & State_MouseOver) && (!view ||
1201  view->selectionMode() != QAbstractItemView::NoSelection);
1202 
1203  bool hasCustomBackground = opt->backgroundBrush.style() != Qt::NoBrush &&
1204  !(option->state & State_Selected);
1205  bool hasSolidBackground = !hasCustomBackground || opt->backgroundBrush.style() == Qt::SolidPattern;
1206 
1207  const qreal rounding = 2.5;
1208 
1209  if (!hover && !(option->state & State_Selected) && !hasCustomBackground &&
1210  !(opt->features & QStyleOptionViewItemV2::Alternate))
1211  return;
1212 
1213  QPalette::ColorGroup cg;
1214  if (option->state & State_Enabled)
1215  cg = (option->state & State_Active) ? QPalette::Normal : QPalette::Inactive;
1216  else
1217  cg = QPalette::Disabled;
1218 
1219  QColor color;
1220 
1221  if (hasCustomBackground && hasSolidBackground)
1222  color = opt->backgroundBrush.color();
1223  else
1224  color = option->palette.color(cg, QPalette::Highlight);
1225 
1226  if (hover && !hasCustomBackground) {
1227  if (!(option->state & State_Selected))
1228  color.setAlphaF(.20);
1229  else
1230  color = color.lighter(110);
1231  }
1232 
1233  if (opt && (opt->features & QStyleOptionViewItemV2::Alternate))
1234  painter->fillRect(option->rect, option->palette.brush(cg, QPalette::AlternateBase));
1235 
1236  if (!hover && !(option->state & State_Selected) && !hasCustomBackground)
1237  return;
1238 
1239  quint64 key = quint64(option->rect.height()) << 32 | color.rgba();
1240  SelectionTiles* tiles = d->selectionCache.object(key);
1241  if (!tiles && hasSolidBackground)
1242  {
1243  QImage image(32 + 16, option->rect.height(), QImage::Format_ARGB32_Premultiplied);
1244  image.fill(0);
1245 
1246  QRect r = image.rect().adjusted(0, 0, -1, -1);
1247 
1248  QPainterPath path1, path2;
1249  path1.addRoundedRect(r, rounding, rounding);
1250  path2.addRoundedRect(r.adjusted(1, 1, -1, -1), rounding - 1, rounding - 1);
1251 
1252  // items with custom background brushes always have their background drawn
1253  // regardless of whether they are hovered or selected or neither so
1254  // the gradient effect needs to be more subtle
1255  int lightenAmount = hasCustomBackground ? 110 : 130;
1256  QLinearGradient gradient(0, 0, 0, r.bottom());
1257  gradient.setColorAt(0, color.lighter(lightenAmount));
1258  gradient.setColorAt(1, color);
1259 
1260  QPainter p(&image);
1261  p.setRenderHint(QPainter::Antialiasing);
1262  p.translate(.5, .5);
1263  p.setPen(QPen(color, 1));
1264  p.setBrush(gradient);
1265  p.drawPath(path1);
1266  p.strokePath(path2, QPen(QColor(255, 255, 255, 64), 1));
1267  p.end();
1268 
1269  QPixmap pixmap = QPixmap::fromImage(image);
1270 
1271  tiles = new SelectionTiles;
1272  tiles->left = pixmap.copy(0, 0, 8, image.height());
1273  tiles->center = pixmap.copy(8, 0, 32, image.height());
1274  tiles->right = pixmap.copy(40, 0, 8, image.height());
1275 
1276  d->selectionCache.insert(key, tiles);
1277  }
1278  else if (hasCustomBackground && !hasSolidBackground)
1279  {
1280  const QPointF oldBrushOrigin = painter->brushOrigin();
1281  painter->setBrushOrigin(opt->rect.topLeft());
1282  painter->setBrush(opt->backgroundBrush);
1283  painter->setPen(Qt::NoPen);
1284  painter->drawRect(opt->rect);
1285  painter->setBrushOrigin(oldBrushOrigin);
1286  return;
1287  }
1288 
1289  bool roundedLeft = false;
1290  bool roundedRight = false;
1291  if (opt) {
1292  roundedLeft = (opt->viewItemPosition == QStyleOptionViewItemV4::Beginning);
1293  roundedRight = (opt->viewItemPosition == QStyleOptionViewItemV4::End);
1294  if (opt->viewItemPosition == QStyleOptionViewItemV4::OnlyOne ||
1295  opt->viewItemPosition == QStyleOptionViewItemV4::Invalid ||
1296  (view && view->selectionBehavior() != QAbstractItemView::SelectRows))
1297  {
1298  roundedLeft = true;
1299  roundedRight = true;
1300  }
1301  }
1302 
1303  QRect r = option->rect;
1304  bool reverseLayout = option->direction == Qt::RightToLeft;
1305 
1306  if (!reverseLayout ? roundedLeft : roundedRight) {
1307  painter->drawPixmap(r.topLeft(), tiles->left);
1308  r.adjust(8, 0, 0, 0);
1309  }
1310  if (!reverseLayout ? roundedRight : roundedLeft) {
1311  painter->drawPixmap(r.right() - 8 + 1, r.top(), tiles->right);
1312  r.adjust(0, 0, -8, 0);
1313  }
1314  if (r.isValid())
1315  painter->drawTiledPixmap(r, tiles->center);
1316 
1317  return;
1318  }
1319 
1320  default:
1321  break;
1322  }
1323 
1324  QCommonStyle::drawPrimitive(elem, option, painter, widget);
1325 }
1326 
1327 void KStyle::drawControl(ControlElement element, const QStyleOption* option, QPainter* p, const QWidget* widget) const
1328 {
1329  //Extract the stuff we need out of the option
1330  State flags = option->state;
1331  QRect r = option->rect;
1332  QPalette pal = option->palette;
1333 
1334  switch (element)
1335  {
1336  case CE_PushButton:
1337  {
1338  const QStyleOptionButton* bOpt = qstyleoption_cast<const QStyleOptionButton*>(option);
1339  if (!bOpt) return;
1340 
1341  //Draw the bevel outside
1342  drawControl(CE_PushButtonBevel, option, p, widget);
1343 
1344  //Now, draw the label...
1345  QRect labelRect = r;
1346 
1347  //Move inside of default indicator margin if need be
1348  if ((bOpt->features & QStyleOptionButton::DefaultButton) || (bOpt->features & QStyleOptionButton::AutoDefaultButton))
1349  labelRect = insideMargin(labelRect, WT_PushButton, PushButton::DefaultIndicatorMargin, option, widget);
1350 
1351  //now get the contents area
1352  labelRect = insideMargin(labelRect, WT_PushButton, PushButton::ContentsMargin, option, widget);
1353 
1354  //### do we do anything for RTL here?
1355 
1356  QStyleOptionButton bOptTmp = *bOpt;
1357  bOptTmp.rect = labelRect;
1358  drawControl(CE_PushButtonLabel, &bOptTmp, p, widget);
1359 
1360  //Finally, renderer the focus indicator if need be
1361  if (flags & State_HasFocus)
1362  {
1363  QRect focusRect = insideMargin(r, WT_PushButton, PushButton::FocusMargin, option, widget);
1364 
1365  QStyleOptionFocusRect foOpts;
1366  foOpts.palette = pal;
1367  foOpts.rect = focusRect;
1368  foOpts.state = flags;
1369 
1370  drawKStylePrimitive(WT_PushButton, Generic::FocusIndicator, &foOpts, focusRect, pal, flags, p, widget);
1371  }
1372 
1373  return;
1374  }
1375 
1376  case CE_PushButtonBevel:
1377  {
1378  const QStyleOptionButton* bOpt = qstyleoption_cast<const QStyleOptionButton*>(option);
1379  if (!bOpt) return;
1380 
1381  //Check whether we should draw default indicator.
1382  if (bOpt->features & QStyleOptionButton::DefaultButton)
1383  drawPrimitive(PE_FrameDefaultButton, option, p, widget);
1384 
1385  QRect bevelRect = r;
1386  //Exclude the margin if default or auto-default
1387  if ((bOpt->features & QStyleOptionButton::DefaultButton) || (bOpt->features & QStyleOptionButton::AutoDefaultButton))
1388  bevelRect = insideMargin(r, WT_PushButton, PushButton::DefaultIndicatorMargin, option, widget);
1389 
1390  //Now draw the bevel itself.
1391  QStyleOptionButton bOptTmp = *bOpt;
1392  bOptTmp.rect = bevelRect;
1393  drawPrimitive(PE_PanelButtonCommand, &bOptTmp, p, widget);
1394 
1395  return;
1396  }
1397 
1398  case CE_PushButtonLabel:
1399  {
1400  const QStyleOptionButton* bOpt = qstyleoption_cast<const QStyleOptionButton*>(option);
1401  if (!bOpt) return;
1402 
1403  //Extract out coordinates for easier manipulation
1404  //(OK, OK, for easier stealing of code from Keramik)
1405  int x, y, w, h;
1406  r.getRect(&x, &y, &w, &h);
1407 
1408  //Are we active? If so, shift contents
1409  bool active = (flags & State_On) || (flags & State_Sunken);
1410  if (active)
1411  {
1412  x += widgetLayoutProp(WT_PushButton, PushButton::PressedShiftHorizontal, option, widget);
1413  y += widgetLayoutProp(WT_PushButton, PushButton::PressedShiftVertical, option, widget);
1414  }
1415 
1416  //Layout the stuff.
1417  if (bOpt->features & QStyleOptionButton::HasMenu)
1418  {
1419  int indicatorWidth = widgetLayoutProp(WT_PushButton, PushButton::MenuIndicatorSize, option, widget);
1420  int indicatorSpacing = widgetLayoutProp(WT_PushButton, PushButton::TextToIconSpace, option, widget);
1421  w -= indicatorWidth + indicatorSpacing;
1422 
1423  //Draw the arrow...
1424  drawKStylePrimitive(WT_PushButton, Generic::ArrowDown, option,
1425  handleRTL(bOpt, QRect(x + w + indicatorSpacing, y, indicatorWidth, h)),
1426  pal, flags, p, widget);
1427  }
1428 
1429  // Draw the icon if there is one
1430  if (!bOpt->icon.isNull())
1431  {
1432  IconOption icoOpt;
1433  icoOpt.icon = bOpt->icon;
1434  icoOpt.size = bOpt->iconSize;
1435  icoOpt.active = flags & State_HasFocus;
1436 
1437  if (!bOpt->text.isEmpty())
1438  {
1439  int margin = widgetLayoutProp(WT_PushButton, PushButton::TextToIconSpace, option, widget);
1440  //Center text + icon w/margin in between..
1441 
1442  //Calculate length of both.
1443  int length = bOpt->iconSize.width() + margin
1444  + p->fontMetrics().size(Qt::TextShowMnemonic, bOpt->text).width();
1445 
1446  //Calculate offset.
1447  int offset = (w - length)/2;
1448 
1449  //draw icon
1450  QRect rect = QRect(QPoint(x + offset, y + h/2 - bOpt->iconSize.height()/2), bOpt->iconSize);
1451  drawKStylePrimitive(WT_PushButton, Generic::Icon, option,
1452  handleRTL(bOpt, rect),
1453  pal, flags, p, widget, &icoOpt);
1454 
1455  //new bounding rect for the text
1456  x += offset + bOpt->iconSize.width() + margin;
1457  w = length - bOpt->iconSize.width() - margin;
1458  }
1459  else
1460  {
1461  //Icon only. Center it. (Thankfully, they killed the icon + pixmap insanity in Qt4. Whee!
1462  //(no need to do anything for RTL here, it's symmetric)
1463  drawKStylePrimitive(WT_PushButton, Generic::Icon, option,
1464  QRect(x, y, w, h),
1465  pal, flags, p, widget, &icoOpt);
1466  }
1467  }
1468  else
1469  {
1470  //Center the text
1471  int textW = p->fontMetrics().size(Qt::TextShowMnemonic, bOpt->text).width();
1472  x += (w - textW)/2;
1473  w = textW;
1474  }
1475 
1476  TextOption lbOpt(bOpt->text);
1477  drawKStylePrimitive(WT_PushButton, Generic::Text, option, handleRTL(bOpt, QRect(x, y, w, h)),
1478  pal, flags, p, widget, &lbOpt);
1479 
1480  return;
1481  }
1482 
1483  case CE_DockWidgetTitle:
1484  {
1485  const QStyleOptionDockWidget* dwOpt = ::qstyleoption_cast<const QStyleOptionDockWidget*>(option);
1486  if (!dwOpt) return;
1487 
1488  QRect textRect = insideMargin(r, WT_DockWidget, DockWidget::TitleMargin, option, widget);
1489  drawKStylePrimitive(WT_DockWidget, DockWidget::TitlePanel, option, r, pal, flags, p, widget);
1490 
1491  TextOption lbOpt(dwOpt->title);
1492  lbOpt.color = widgetLayoutProp(WT_DockWidget, DockWidget::TitleTextColor,
1493  option, widget);
1494  drawKStylePrimitive(WT_DockWidget, Generic::Text, option, textRect, pal, flags, p, widget, &lbOpt);
1495  return;
1496  }
1497 
1498  case CE_ToolBoxTabShape:
1499  {
1500  drawKStylePrimitive(WT_ToolBoxTab, ToolBoxTab::Panel, option, r, pal, flags, p, widget);
1501  return;
1502  }
1503 /*
1504  case CE_ToolBoxTabLabel:
1505  {
1506  drawKStylePrimitive(WT_ToolBoxTab, Generic::Text, option, r, pal, flags, p, widget);
1507  return;
1508  }
1509 */
1510  case CE_CheckBox:
1511  {
1512  const QStyleOptionButton* bOpt = qstyleoption_cast<const QStyleOptionButton*>(option);
1513  if (!bOpt) return;
1514 
1515  //Draw the checkbox
1516  QRect checkBox = subElementRect(SE_CheckBoxIndicator, option, widget);
1517  QStyleOptionButton bOptTmp = *bOpt;
1518  bOptTmp.rect = checkBox;
1519  drawPrimitive(PE_IndicatorCheckBox, &bOptTmp, p, widget);
1520 
1521  // pixmap and text label...
1522  bOptTmp.rect = subElementRect(SE_CheckBoxContents, option, widget);
1523  drawControl(CE_CheckBoxLabel, &bOptTmp, p, widget);
1524 
1525  //Draw the focus rect...
1526  if (flags & State_HasFocus)
1527  {
1528  QRect focusRect = subElementRect(SE_CheckBoxFocusRect, option, widget);
1529  drawKStylePrimitive(WT_CheckBox, Generic::FocusIndicator, option, focusRect,
1530  pal, flags, p, widget);
1531  }
1532  return;
1533  }
1534 
1535  case CE_CheckBoxLabel:
1536  {
1537  const QStyleOptionButton* bOpt = qstyleoption_cast<const QStyleOptionButton*>(option);
1538  if (!bOpt) return;
1539 
1540  int textShift = 0; // shift text in case there is a label pixmap
1541  // draw the pixmap, if there is one
1542  if (!bOpt->icon.isNull())
1543  {
1544  IconOption icoOpt;
1545  icoOpt.icon = bOpt->icon;
1546  icoOpt.size = bOpt->iconSize;
1547  icoOpt.active = flags & State_HasFocus;
1548 
1549  QRect iconRect(r.x(), r.y() + (r.height()-bOpt->iconSize.height())/2,
1550  bOpt->iconSize.width(), bOpt->iconSize.height());
1551  drawKStylePrimitive(WT_CheckBox, Generic::Icon, option,
1552  handleRTL(bOpt, iconRect),
1553  pal, flags, p, widget, &icoOpt);
1554 
1555  textShift = bOpt->iconSize.width() +
1556  widgetLayoutProp(WT_RadioButton, RadioButton::BoxTextSpace, option, widget);
1557  }
1558 
1559 
1560  if (!bOpt->text.isEmpty() ) {
1561  TextOption lbOpt(bOpt->text);
1562  drawKStylePrimitive(WT_CheckBox, Generic::Text, option,
1563  handleRTL(bOpt, r.adjusted(textShift,0,0,0)),
1564  pal, flags, p, widget, &lbOpt);
1565  }
1566 
1567  return;
1568  }
1569 
1570  case CE_RadioButton:
1571  {
1572  const QStyleOptionButton* bOpt = qstyleoption_cast<const QStyleOptionButton*>(option);
1573  if (!bOpt) return;
1574 
1575  //Draw the indicator
1576  QRect indicator = subElementRect(SE_RadioButtonIndicator, option, widget);
1577  QStyleOptionButton bOptTmp = *bOpt;
1578  bOptTmp.rect = indicator;
1579  drawPrimitive(PE_IndicatorRadioButton, &bOptTmp, p, widget);
1580 
1581  // pixmap and text label...
1582  bOptTmp.rect = subElementRect(SE_RadioButtonContents, option, widget);
1583  drawControl(CE_RadioButtonLabel, &bOptTmp, p, widget);
1584 
1585  //Draw the focus rect...
1586  if (flags & State_HasFocus)
1587  {
1588  QRect focusRect = subElementRect(SE_RadioButtonFocusRect, option, widget);
1589  drawKStylePrimitive(WT_RadioButton, Generic::FocusIndicator, option, focusRect,
1590  pal, flags, p, widget);
1591  }
1592  return;
1593  }
1594 
1595  case CE_RadioButtonLabel:
1596  {
1597  const QStyleOptionButton* bOpt = qstyleoption_cast<const QStyleOptionButton*>(option);
1598  if (!bOpt) return;
1599 
1600  int textShift = 0; // shift text in case there is a label pixmap
1601  // draw the pixmap, if there is one
1602  if (!bOpt->icon.isNull())
1603  {
1604  IconOption icoOpt;
1605  icoOpt.icon = bOpt->icon;
1606  icoOpt.active = flags & State_HasFocus;
1607  icoOpt.size = bOpt->iconSize;
1608 
1609  QRect iconRect(r.x(), r.y() + (r.height()-bOpt->iconSize.height())/2,
1610  bOpt->iconSize.width(), bOpt->iconSize.height());
1611  drawKStylePrimitive(WT_RadioButton, Generic::Icon, option,
1612  handleRTL(bOpt, iconRect),
1613  pal, flags, p, widget, &icoOpt);
1614 
1615  textShift = bOpt->iconSize.width() +
1616  widgetLayoutProp(WT_RadioButton, RadioButton::BoxTextSpace, option, widget);
1617  }
1618 
1619  TextOption lbOpt(bOpt->text);
1620  drawKStylePrimitive(WT_RadioButton, Generic::Text, option,
1621  handleRTL(bOpt, r.adjusted(textShift,0,0,0)),
1622  pal, flags, p, widget, &lbOpt);
1623  return;
1624  }
1625 
1626  //The CE_ProgressBar implementation inside QCommonStyle is acceptible.
1627  //We just implement the subElementRect's it uses
1628 
1629  case CE_ProgressBarGroove:
1630  {
1631  drawKStylePrimitive(WT_ProgressBar, ProgressBar::Groove, option, r,
1632  pal, flags, p, widget);
1633  return;
1634  }
1635 
1636  case CE_ProgressBarContents:
1637  {
1638  const QStyleOptionProgressBar* pbOpt = qstyleoption_cast<const QStyleOptionProgressBar*>(option);
1639  const QStyleOptionProgressBarV2* pbOpt2 = qstyleoption_cast<const QStyleOptionProgressBarV2*>(option);
1640  if (!pbOpt) return;
1641 
1642  //We layout as if LTR, relying on visualRect to fix it up
1643  double progress = pbOpt->progress - pbOpt->minimum;
1644  int steps = qMax(pbOpt->maximum - pbOpt->minimum, 1);
1645  bool busyIndicator = (pbOpt->minimum == 0 && pbOpt->maximum == 0);
1646  bool horizontal = !pbOpt2 || pbOpt2->orientation == Qt::Horizontal;
1647 
1648  //Do we have to draw anything?
1649  if (!progress && ! busyIndicator)
1650  return;
1651 
1652  //Calculate width fraction
1653  double widthFrac;
1654  if (busyIndicator)
1655  widthFrac = widgetLayoutProp(WT_ProgressBar, ProgressBar::BusyIndicatorSize, option, widget) / 100.0;
1656  else
1657  widthFrac = progress / steps;
1658 
1659  //And now the pixel width
1660  int width = qMin(r.width(), (int)(widthFrac * double(r.width())));
1661  int height = qMin(r.height(), (int)(widthFrac * r.height()));
1662 
1663  if (busyIndicator)
1664  {
1665  int size = width;
1666  if (!horizontal)
1667  size = height;
1668  //Clamp to upper width limit
1669  if (size > widgetLayoutProp(WT_ProgressBar, ProgressBar::MaxBusyIndicatorSize, option, widget))
1670  size = widgetLayoutProp(WT_ProgressBar, ProgressBar::MaxBusyIndicatorSize, option, widget);
1671 
1672  //A busy indicator with width 0 is kind of useless
1673  if (size < 1) size = 1;
1674 
1675 
1676  int remSize = (horizontal ? r.width() : r.height()) - size; //The space around which we move around...
1677  if (remSize <= 0) remSize = 1; //Do something non-crashy when too small...
1678 
1679  int pstep = int(progress)%(2*remSize);
1680 
1681  if (pstep > remSize)
1682  {
1683  //Bounce about.. We're remWidth + some delta, we want to be remWidth - delta...
1684  // - ( (remWidth + some delta) - 2* remWidth ) = - (some deleta - remWidth) = remWidth - some delta..
1685  pstep = -(pstep - 2*remSize);
1686  }
1687 
1688  QRect indicatorRect;
1689  if (horizontal)
1690  indicatorRect = QRect(r.x() + pstep, r.y(), size, r.height());
1691  else
1692  indicatorRect = QRect(r.x(), r.y() + pstep, r.width(), size);
1693  drawKStylePrimitive(WT_ProgressBar, ProgressBar::BusyIndicator, option, handleRTL(option, indicatorRect),
1694  pal, flags, p, widget);
1695  }
1696  else
1697  {
1698  QRect indicatorRect;
1699  if (horizontal)
1700  indicatorRect = QRect(r.x(), r.y(), width, r.height());
1701  else
1702  indicatorRect = QRect(r.x(), r.bottom()-height+1, r.width(), height);
1703  drawKStylePrimitive(WT_ProgressBar, ProgressBar::Indicator, option, handleRTL(option, indicatorRect),
1704  pal, flags, p, widget);
1705  }
1706  return;
1707  }
1708 
1709  case CE_ProgressBarLabel:
1710  {
1711  const QStyleOptionProgressBar* pbOpt = qstyleoption_cast<const QStyleOptionProgressBar*>(option);
1712  const QStyleOptionProgressBarV2* pbOpt2 = qstyleoption_cast<const QStyleOptionProgressBarV2*>(option);
1713  if (pbOpt)
1714  {
1715  TextOption lbOpt(pbOpt->text);
1716  bool horizontal = !pbOpt2 || pbOpt2->orientation == Qt::Horizontal;
1717  bool reverseLayout = option->direction == Qt::RightToLeft;
1718 
1719  p->save();
1720 
1721  // rotate label for vertical layout
1722  if (!horizontal && !reverseLayout)
1723  {
1724  p->translate(r.topRight());
1725  p->rotate(90.0);
1726  }
1727  else if (!horizontal)
1728  {
1729  p->translate(r.bottomLeft());
1730  p->rotate(-90.0);
1731  }
1732 
1733  if (useSideText(pbOpt))
1734  {
1735  lbOpt.color = QPalette::ButtonText;
1736 
1737  //### or other way around?
1738  if (option->direction == Qt::LeftToRight)
1739  lbOpt.hAlign = Qt::AlignRight;
1740  else
1741  lbOpt.hAlign = Qt::AlignLeft;
1742 
1743  //Handle side margin.
1744  int marWidth = widgetLayoutProp(WT_ProgressBar, ProgressBar::SideTextSpace, option, widget);
1745 
1746  drawKStylePrimitive(WT_ProgressBar, Generic::Text, option,
1747  horizontal? r.adjusted(0, marWidth, 0, -marWidth) : QRect(0, marWidth, r.height(), r.width()-marWidth),
1748  pal, flags, p, widget, &lbOpt);
1749  }
1750  else
1751  {
1752  if (pbOpt->textAlignment == Qt::AlignLeft) //TODO: Check BIDI?
1753  lbOpt.hAlign = Qt::AlignHCenter;
1754  else
1755  lbOpt.hAlign = pbOpt->textAlignment;
1756 
1757  //Now, we need to figure out the geometry of the indicator.
1758  QRect progressRect;
1759  double progress = pbOpt->progress - pbOpt->minimum;
1760  int steps = qMax(pbOpt->maximum - pbOpt->minimum, 1);
1761  bool busyIndicator = (steps <= 1);
1762 
1763  int width;
1764  int height;
1765  if (busyIndicator)
1766  {
1767  //how did this happen? handle as 0%
1768  width = 0;
1769  height = 0;
1770  }
1771  else
1772  {
1773  double widthFrac = progress / steps;;
1774  width = qMin(r.width(), (int)(widthFrac * r.width()));
1775  height = qMin(r.height(), (int)(widthFrac * r.height()));
1776  }
1777 
1778  //If there is any indicator, we do two paths, with different
1779  //clipping rects, for the two colors.
1780  if (width || height)
1781  {
1782  if (horizontal)
1783  p->setClipRect(handleRTL(option, QRect(r.x(), r.y(), width, r.height())));
1784  else if (!reverseLayout)
1785  p->setClipRect(QRect(r.height()-height, 0, r.height(), r.width()));
1786  else
1787  p->setClipRect(QRect(0, 0, height, r.width()));
1788  lbOpt.color = QPalette::HighlightedText;
1789  drawKStylePrimitive(WT_ProgressBar, Generic::Text, option,
1790  horizontal? r: QRect(0,0,r.height(),r.width()),
1791  pal, flags, p, widget, &lbOpt);
1792 
1793  if (horizontal)
1794  p->setClipRect(handleRTL(option, QRect(r.x() + width, r.y(), r.width() - width, r.height())));
1795  else if (!reverseLayout)
1796  p->setClipRect(QRect(0, 0, r.height()-height, r.width()));
1797  else
1798  p->setClipRect(QRect(height, 0, r.height()-height, r.width()));
1799  lbOpt.color = QPalette::ButtonText;
1800  drawKStylePrimitive(WT_ProgressBar, Generic::Text, option,
1801  horizontal? r: QRect(0,0,r.height(),r.width()),
1802  pal, flags, p, widget, &lbOpt);
1803  p->setClipping(false);
1804  }
1805  else
1806  {
1807  lbOpt.color = QPalette::ButtonText;
1808  drawKStylePrimitive(WT_ProgressBar, Generic::Text, option,
1809  horizontal? r: QRect(0,0,r.height(),r.width()),
1810  pal, flags, p, widget, &lbOpt);
1811  }
1812  }
1813  p->restore();
1814  }
1815  return;
1816  }
1817 
1818  case CE_MenuBarItem:
1819  {
1820  const QStyleOptionMenuItem* mOpt = ::qstyleoption_cast<const QStyleOptionMenuItem*>(option);
1821  if (!mOpt) return;
1822 
1823  //Bevel...
1824  drawKStylePrimitive(WT_MenuBarItem, MenuBarItem::Panel, option, r,
1825  pal, flags, p, widget);
1826 
1827  //Text...
1828  QRect textRect = insideMargin(r, WT_MenuBarItem, MenuBarItem::Margin, option, widget);
1829 
1830 
1831  TextOption lbOpt(mOpt->text);
1832  drawKStylePrimitive(WT_MenuBarItem, Generic::Text, option, textRect,
1833  pal, flags, p, widget, &lbOpt);
1834 
1835  return;
1836  }
1837 
1838  case CE_MenuBarEmptyArea:
1839  {
1840  drawKStylePrimitive(WT_MenuBar, MenuBar::EmptyArea, option, r,
1841  pal, flags, p, widget);
1842  return;
1843  }
1844 
1845  case CE_MenuEmptyArea:
1846  case CE_MenuVMargin:
1847  case CE_MenuHMargin:
1848  {
1849  drawKStylePrimitive(WT_Menu, Menu::Background, option, r,
1850  pal, flags, p, widget);
1851  return;
1852  }
1853 
1854  case CE_MenuItem:
1855  {
1856 
1857  //First of all,render the background.
1858  drawKStylePrimitive(WT_Menu, Menu::Background, option, r,
1859  pal, flags, p, widget);
1860 
1861  const QStyleOptionMenuItem* miOpt = ::qstyleoption_cast<const QStyleOptionMenuItem*>(option);
1862  if (!miOpt || miOpt->menuItemType == QStyleOptionMenuItem::EmptyArea) return;
1863 
1864  //Remove the margin (for everything but the column background)
1865  QRect ir = insideMargin(r, WT_MenuItem, MenuItem::Margin, option, widget);
1866 
1867 
1868  //First, figure out the left column width. When CheckAlongsideIcon is disabled it's just
1869  // the icon column width. Otherwise it consists of CheckWidth+CheckSpace+icon column width.
1870  int iconColW = miOpt->maxIconWidth;
1871  iconColW = qMax(iconColW, widgetLayoutProp(WT_MenuItem, MenuItem::IconWidth, option, widget));
1872  int checkColW = widgetLayoutProp(WT_MenuItem, MenuItem::CheckWidth, option, widget);
1873  int checkSpace = widgetLayoutProp(WT_MenuItem, MenuItem::CheckSpace, option, widget);
1874 
1875  int leftColW = iconColW;
1876  // only use the additional check row if the menu has checkable menuItems.
1877  bool checkAlongsideIcon = (miOpt->menuHasCheckableItems &&
1878  widgetLayoutProp(WT_MenuItem, MenuItem::CheckAlongsideIcon, option, widget) );
1879  if (checkAlongsideIcon)
1880  {
1881  leftColW = checkColW + checkSpace + iconColW;
1882  }
1883 
1884  //And the right arrow column...
1885  int rightColW = widgetLayoutProp(WT_MenuItem, MenuItem::ArrowSpace, option, widget) +
1886  widgetLayoutProp(WT_MenuItem, MenuItem::ArrowWidth, option, widget);
1887 
1888  //Render left column background. This is a bit tricky, since we don't use the V margin.
1889  QRect leftColRect(ir.x(), r.y(), leftColW, r.height());
1890  drawKStylePrimitive(WT_MenuItem, MenuItem::CheckColumn, option, handleRTL(option, leftColRect),
1891  pal, flags, p, widget);
1892 
1893  //Separators: done with the bg, can paint them and bail them out.
1894  if (miOpt->menuItemType == QStyleOptionMenuItem::Separator)
1895  {
1896  drawKStylePrimitive(WT_MenuItem, MenuItem::Separator, option, ir, pal, flags, p, widget);
1897  return;
1898  }
1899 
1900  //Now paint the active indicator --- other stuff goes on top of it
1901  bool active = (flags & State_Selected);
1902 
1903  //Active indicator...
1904  if (active)
1905  drawKStylePrimitive(WT_MenuItem, MenuItem::ItemIndicator, option, handleRTL(option, r), pal, flags, p, widget);
1906 
1907 
1908  ColorMode textColor = (flags & State_Enabled) ? (widgetLayoutProp(WT_MenuItem, active ?
1909  MenuItem::ActiveTextColor :
1910  MenuItem::TextColor, option, widget))
1911  : (widgetLayoutProp(WT_MenuItem, active ?
1912  MenuItem::ActiveDisabledTextColor:
1913  MenuItem::DisabledTextColor, option, widget));
1914 
1915  //Readjust the column rectangle back to proper height
1916  leftColRect = QRect(ir.x(), ir.y(), leftColW, ir.height());
1917  // Paint checkbox, etc.
1918  if (!checkAlongsideIcon && !miOpt->icon.isNull() )
1919  {
1920  // there is an icon and the item is checked, so paint a CheckIcon
1921  if (miOpt->checked)
1922  {
1923  drawKStylePrimitive(WT_MenuItem, MenuItem::CheckIcon,
1924  option, handleRTL(option, leftColRect), pal, flags,
1925  p, widget);
1926  }
1927  }
1928  else
1929  {
1930  // paint a normal check- resp. radiomark.
1931  QRect checkColRect;
1932  if (checkAlongsideIcon)
1933  {
1934  checkColRect = QRect(leftColRect.x(), leftColRect.y(),
1935  checkColW, leftColRect.height() );
1936  }
1937  else
1938  {
1939  checkColRect = leftColRect;
1940  }
1941 
1942  bool checked = miOpt->checked;
1943  if (miOpt->checkType == QStyleOptionMenuItem::NonExclusive)
1944  {
1945  drawKStylePrimitive(WT_MenuItem, checked ? MenuItem::CheckOn : MenuItem::CheckOff,
1946  option, handleRTL(option, checkColRect), pal, flags,
1947  p, widget);
1948  }
1949  else if (miOpt->checkType == QStyleOptionMenuItem::Exclusive)
1950  {
1951  drawKStylePrimitive(WT_MenuItem, checked ? MenuItem::RadioOn : MenuItem::RadioOff,
1952  option, handleRTL(option, checkColRect), pal, flags,
1953  p, widget);
1954  }
1955  }
1956  // Paint the menu icon.
1957  if (!miOpt->icon.isNull())
1958  {
1959  int iconSize = pixelMetric(PM_SmallIconSize);
1960 
1961  QRect iconColRect;
1962  if (checkAlongsideIcon)
1963  {
1964  iconColRect = QRect(leftColRect.x()+checkColW+checkSpace, leftColRect.y(),
1965  leftColRect.width()-(checkColW+checkSpace), leftColRect.height() );
1966  }
1967  else
1968  {
1969  iconColRect = leftColRect;
1970  }
1971  IconOption icoOpt;
1972  icoOpt.icon = miOpt->icon;
1973  icoOpt.active = flags & State_Selected;
1974  drawKStylePrimitive(WT_MenuItem, Generic::Icon, option,
1975  handleRTL(option, centerRect(iconColRect, iconSize, iconSize)),
1976  pal, flags, p, widget, &icoOpt);
1977  }
1978 
1979  //Now include the spacing when calculating the next columns
1980  leftColW += widgetLayoutProp(WT_MenuItem, MenuItem::IconSpace, option, widget);
1981 
1982  //Render the text, including any accel.
1983  QString text = miOpt->text;
1984  QRect textRect = QRect(ir.x() + leftColW, ir.y(), ir.width() - leftColW - rightColW, ir.height());
1985  QFont font = miOpt->font;
1986  const QFont oldFont = p->font();
1987 
1988  p->setFont(font);
1989  int tabPos = miOpt->text.indexOf(QLatin1Char('\t'));
1990  if (tabPos != -1)
1991  {
1992  text = miOpt->text.left(tabPos);
1993  QString accl = miOpt->text.mid (tabPos + 1);
1994 
1995  //Draw the accel.
1996  TextOption lbOpt(accl);
1997  lbOpt.color = textColor;
1998  lbOpt.hAlign = Qt::AlignRight;
1999  drawKStylePrimitive(WT_MenuItem, Generic::Text, option, handleRTL(option, textRect),
2000  pal, flags, p, widget, &lbOpt);
2001  }
2002 
2003  //Draw the text.
2004  TextOption lbOpt(text);
2005  lbOpt.color = textColor;
2006  drawKStylePrimitive(WT_MenuItem, Generic::Text, option, handleRTL(option, textRect),
2007  pal, flags, p, widget, &lbOpt);
2008 
2009  p->setFont(oldFont);
2010 
2011  //Render arrow, if need be.
2012  if (miOpt->menuItemType == QStyleOptionMenuItem::SubMenu)
2013  {
2014  ColorOption arrowColor;
2015  arrowColor.color = textColor;
2016 
2017  int aw = widgetLayoutProp(WT_MenuItem, MenuItem::ArrowWidth, option, widget);
2018 
2019  QRect arrowRect(ir.x() + ir.width() - aw, ir.y(), aw, ir.height());
2020  drawKStylePrimitive(WT_MenuItem, option->direction == Qt::LeftToRight ?
2021  Generic::ArrowRight : Generic::ArrowLeft,
2022  option, handleRTL(option, arrowRect), pal, flags, p, widget, &arrowColor);
2023  }
2024 
2025  return;
2026  }
2027 
2028  case CE_ScrollBarAddLine:
2029  case CE_ScrollBarSubLine:
2030  {
2031  const QStyleOptionSlider* slOpt = ::qstyleoption_cast<const QStyleOptionSlider*>(option);
2032  if (!slOpt) return;
2033 
2034  //Fix up the rectangle to be what we want
2035  r = internalSubControlRect(CC_ScrollBar, slOpt,
2036  element == CE_ScrollBarAddLine ? SC_ScrollBarAddLine : SC_ScrollBarSubLine, widget);
2037  const_cast<QStyleOption*>(option)->rect = r;
2038 
2039 
2040  bool doubleButton = false;
2041 
2042  //See whether we're a double-button...
2043  if (element == CE_ScrollBarAddLine && widgetLayoutProp(WT_ScrollBar, ScrollBar::DoubleBotButton, option, widget))
2044  doubleButton = true;
2045  if (element == CE_ScrollBarSubLine && widgetLayoutProp(WT_ScrollBar, ScrollBar::DoubleTopButton, option, widget))
2046  doubleButton = true;
2047 
2048  if (doubleButton)
2049  {
2050  if (flags & State_Horizontal)
2051  {
2052  DoubleButtonOption::ActiveButton ab = DoubleButtonOption::None;
2053 
2054  //Depending on RTL direction, the one on the left is either up or down.
2055  bool leftAdds, rightAdds;
2056  if (slOpt->direction == Qt::LeftToRight)
2057  {
2058  leftAdds = false;
2059  rightAdds = true;
2060  }
2061  else
2062  {
2063  leftAdds = true;
2064  rightAdds = false;
2065  }
2066 
2067  //Determine whether any of the buttons is active
2068  if (flags & State_Sunken)
2069  {
2070  if (((slOpt->activeSubControls & SC_ScrollBarAddLine) && leftAdds) ||
2071  ((slOpt->activeSubControls & SC_ScrollBarSubLine) && !leftAdds))
2072  ab = DoubleButtonOption::Left;
2073 
2074  if (((slOpt->activeSubControls & SC_ScrollBarAddLine) && rightAdds) ||
2075  ((slOpt->activeSubControls & SC_ScrollBarSubLine) && !rightAdds))
2076  ab = DoubleButtonOption::Right;
2077  }
2078 
2079  DoubleButtonOption bOpt(ab);
2080  drawKStylePrimitive(WT_ScrollBar, ScrollBar::DoubleButtonHor,
2081  option, r, pal, flags, p, widget, &bOpt);
2082 
2083  //Draw the left arrow..
2084  QRect leftSubButton = QRect(r.x(), r.y(), r.width()/2, r.height());
2085 
2086  ColorOption colOpt;
2087  colOpt.color = widgetLayoutProp(WT_ScrollBar, ScrollBar::ArrowColor, option, widget);
2088  if (ab == DoubleButtonOption::Left)
2089  colOpt.color = widgetLayoutProp(WT_ScrollBar, ScrollBar::ActiveArrowColor, option, widget);
2090 
2091  drawKStylePrimitive(WT_ScrollBar, Generic::ArrowLeft, option, leftSubButton, pal,
2092  flags, p, widget, &colOpt);
2093 
2094  //Right half..
2095  QRect rightSubButton;
2096  rightSubButton.setBottomRight(r.bottomRight());
2097  rightSubButton.setLeft (leftSubButton.right() + 1);
2098  rightSubButton.setTop (r.top());
2099 
2100  //Chose proper color
2101  colOpt.color = widgetLayoutProp(WT_ScrollBar, ScrollBar::ArrowColor, option, widget);
2102  if (ab == DoubleButtonOption::Right)
2103  colOpt.color = widgetLayoutProp(WT_ScrollBar, ScrollBar::ActiveArrowColor, option, widget);
2104 
2105  drawKStylePrimitive(WT_ScrollBar, Generic::ArrowRight, option, rightSubButton, pal,
2106  flags, p, widget, &colOpt);
2107  }
2108  else
2109  {
2110  DoubleButtonOption::ActiveButton ab = DoubleButtonOption::None;
2111 
2112  //Determine whether any of the buttons is active
2113  //Qt sets both sunken and activeSubControls for active,
2114  //just activeSubControls for hover.
2115  if (flags & State_Sunken)
2116  {
2117  if (slOpt->activeSubControls & SC_ScrollBarSubLine)
2118  ab = DoubleButtonOption::Top;
2119 
2120  if (slOpt->activeSubControls & SC_ScrollBarAddLine)
2121  ab = DoubleButtonOption::Bottom;
2122  }
2123 
2124  //Paint the bevel
2125  DoubleButtonOption bOpt(ab);
2126  drawKStylePrimitive(WT_ScrollBar, ScrollBar::DoubleButtonVert,
2127  option, r, pal, flags, p, widget, &bOpt);
2128 
2129  //Paint top button.
2130  ColorOption colOpt;
2131  colOpt.color = widgetLayoutProp(WT_ScrollBar, ScrollBar::ArrowColor, option, widget);
2132 
2133  if (ab == DoubleButtonOption::Top)
2134  colOpt.color = widgetLayoutProp(WT_ScrollBar, ScrollBar::ActiveArrowColor, option, widget);
2135 
2136 
2137  QRect topSubButton = QRect(r.x(), r.y(), r.width(), r.height()/2);
2138  drawKStylePrimitive(WT_ScrollBar, Generic::ArrowUp, option, topSubButton, pal,
2139  flags, p, widget, &colOpt);
2140 
2141  //Paint bot button
2142  QRect botSubButton;
2143  botSubButton.setBottomRight(r.bottomRight());
2144  botSubButton.setLeft (r.left());
2145  botSubButton.setTop (topSubButton.bottom() + 1);
2146 
2147  colOpt.color = widgetLayoutProp(WT_ScrollBar, ScrollBar::ArrowColor, option, widget);
2148 
2149  if (ab == DoubleButtonOption::Bottom)
2150  colOpt.color = widgetLayoutProp(WT_ScrollBar, ScrollBar::ActiveArrowColor, option, widget);
2151 
2152  drawKStylePrimitive(WT_ScrollBar, Generic::ArrowDown, option, botSubButton, pal,
2153  flags, p, widget, &colOpt);
2154  }
2155  }
2156  else
2157  { // Single button
2158  if (flags & State_Horizontal)
2159  {
2160  drawKStylePrimitive(WT_ScrollBar, ScrollBar::SingleButtonHor,
2161  option, r, pal, flags, p, widget);
2162 
2163  int primitive;
2164  bool active = false;
2165 
2166  if (element == CE_ScrollBarAddLine)
2167  {
2168  if (slOpt->direction == Qt::LeftToRight)
2169  primitive = Generic::ArrowRight;
2170  else
2171  primitive = Generic::ArrowLeft;
2172 
2173  if ((slOpt->activeSubControls & SC_ScrollBarAddLine) && (flags & State_Sunken))
2174  active = true;
2175  }
2176  else
2177  {
2178  if (slOpt->direction == Qt::LeftToRight)
2179  primitive = Generic::ArrowLeft;
2180  else
2181  primitive = Generic::ArrowRight;
2182 
2183  if ((slOpt->activeSubControls & SC_ScrollBarSubLine) && (flags & State_Sunken))
2184  active = true;
2185  }
2186 
2187  ColorOption colOpt;
2188  colOpt.color = widgetLayoutProp(WT_ScrollBar, ScrollBar::ArrowColor, option, widget);
2189  if (active)
2190  colOpt.color = widgetLayoutProp(WT_ScrollBar, ScrollBar::ActiveArrowColor, option, widget);
2191 
2192  drawKStylePrimitive(WT_ScrollBar, primitive, option, r, pal,
2193  flags, p, widget, &colOpt);
2194  }
2195  else
2196  {
2197  drawKStylePrimitive(WT_ScrollBar, ScrollBar::SingleButtonVert,
2198  option, r, pal, flags, p, widget);
2199 
2200  int primitive;
2201  bool active = false;
2202 
2203  if (element == CE_ScrollBarAddLine)
2204  {
2205  primitive = Generic::ArrowDown;
2206  if ((slOpt->activeSubControls & SC_ScrollBarAddLine) && (flags & State_Sunken))
2207  active = true;
2208  }
2209  else
2210  {
2211  primitive = Generic::ArrowUp;
2212  if ((slOpt->activeSubControls & SC_ScrollBarSubLine) && (flags & State_Sunken))
2213  active = true;
2214  }
2215 
2216  ColorOption colOpt;
2217  colOpt.color = widgetLayoutProp(WT_ScrollBar, ScrollBar::ArrowColor, option, widget);
2218  if (active)
2219  colOpt.color = widgetLayoutProp(WT_ScrollBar, ScrollBar::ActiveArrowColor, option, widget);
2220 
2221  drawKStylePrimitive(WT_ScrollBar, primitive, option, r, pal,
2222  flags, p, widget, &colOpt);
2223  }
2224  }
2225  return;
2226  }
2227 
2228 // TODO: what about CE_ScrollBarFirst, CE_ScrollBarLast...?
2229 // case CE_ScrollBarFirst:
2230 // case CE_ScrollBarLast:
2231 
2232  case CE_ScrollBarSlider:
2233  {
2234  drawKStylePrimitive(WT_ScrollBar,
2235  (flags & State_Horizontal) ? ScrollBar::SliderHor :
2236  ScrollBar::SliderVert,
2237  option, r, pal, flags, p, widget);
2238  return;
2239  }
2240 
2241  case CE_ScrollBarAddPage:
2242  {
2243  const QStyleOptionSlider* slOpt = ::qstyleoption_cast<const QStyleOptionSlider*>(option);
2244  if (!slOpt) return;
2245 
2246  if (flags & State_Horizontal)
2247  drawKStylePrimitive(WT_ScrollBar,
2248  (slOpt->direction == Qt::LeftToRight) ? ScrollBar::GrooveAreaHorRight :
2249  ScrollBar::GrooveAreaHorLeft,
2250  option, r, pal, flags, p, widget);
2251  else
2252  drawKStylePrimitive(WT_ScrollBar, ScrollBar::GrooveAreaVertBottom,
2253  option, r, pal, flags, p, widget);
2254  return;
2255  }
2256 
2257  case CE_ScrollBarSubPage:
2258  {
2259  const QStyleOptionSlider* slOpt = ::qstyleoption_cast<const QStyleOptionSlider*>(option);
2260  if (!slOpt) return;
2261 
2262  if (flags & State_Horizontal)
2263  drawKStylePrimitive(WT_ScrollBar,
2264  (slOpt->direction == Qt::LeftToRight) ? ScrollBar::GrooveAreaHorLeft :
2265  ScrollBar::GrooveAreaHorRight,
2266  option, r, pal, flags, p, widget);
2267  else
2268  drawKStylePrimitive(WT_ScrollBar, ScrollBar::GrooveAreaVertTop,
2269  option, r, pal, flags, p, widget);
2270  return;
2271  }
2272 
2273  //QCS's CE_TabBarTab is perfectly fine, so we just handle the subbits
2274 
2275  case CE_TabBarTabShape:
2276  {
2277  const QStyleOptionTab* tabOpt = qstyleoption_cast<const QStyleOptionTab*>(option);
2278  if (!tabOpt) return;
2279 
2280  // TabOverlap handling
2281  int tabOverlap = pixelMetric(PM_TabBarTabOverlap, option, widget);
2282  bool beginning = tabOpt->position == QStyleOptionTab::Beginning;
2283  bool onlyOne = tabOpt->position == QStyleOptionTab::OnlyOneTab;
2284  if (!beginning && !onlyOne) {
2285  switch (tabSide(tabOpt)) {
2286  case North:
2287  case South:
2288  if (option->direction == Qt::LeftToRight)
2289  r.adjust(-tabOverlap, 0, 0, 0);
2290  else
2291  r.adjust(0, 0, tabOverlap, 0);
2292  break;
2293  case East:
2294  case West:
2295  r.adjust(0, -tabOverlap, 0, 0);
2296  default:
2297  break;
2298  }
2299  }
2300 
2301  int prim;
2302  switch (tabSide(tabOpt))
2303  {
2304  case North:
2305  prim = TabBar::NorthTab; break;
2306  case South:
2307  prim = TabBar::SouthTab; break;
2308  case East:
2309  prim = TabBar::EastTab; break;
2310  default:
2311  prim = TabBar::WestTab; break;
2312  }
2313 
2314  drawKStylePrimitive(WT_TabBar, prim, option, r, pal, flags, p, widget);
2315 
2316  return;
2317  }
2318 
2319  case CE_TabBarTabLabel:
2320  {
2321  const QStyleOptionTab* tabOpt = qstyleoption_cast<const QStyleOptionTab*>(option);
2322  if (!tabOpt) return;
2323 
2324  //First, we get our content region.
2325  QRect labelRect = subElementRect(SE_TabBarTabText, option, widget);
2326 
2327  Side tabSd = tabSide(tabOpt);
2328 
2329  //Now, what we do, depends on rotation, LTR vs. RTL, and text/icon combinations.
2330  //First, figure out if we have to deal with icons, and place them if need be.
2331  if (!tabOpt->icon.isNull())
2332  {
2333  QStyleOptionTabV3 tabV3(*tabOpt);
2334  QSize iconSize = tabV3.iconSize;
2335  if (!iconSize.isValid()) {
2336  int iconExtent = pixelMetric(PM_SmallIconSize);
2337  iconSize = QSize(iconExtent, iconExtent);
2338  }
2339 
2340  IconOption icoOpt;
2341  icoOpt.icon = tabOpt->icon;
2342  icoOpt.active = flags & State_Selected;
2343  icoOpt.size = iconSize;
2344 
2345  if (tabOpt->text.isNull())
2346  {
2347  //Icon only. Easy.
2348  drawKStylePrimitive(WT_TabBar, Generic::Icon, option, labelRect,
2349  pal, flags, p, widget, &icoOpt);
2350  return;
2351  }
2352 
2353  //OK, we have to stuff both icon and text. So we figure out where to stick the icon.
2354  QRect iconRect;
2355 
2356  if (tabSd == North || tabSd == South)
2357  {
2358  //OK, this is simple affair, we just pick a side for the icon
2359  //based on layout direction. (Actually, I guess text
2360  //would be more accurate, but I am -so- not doing BIDI here)
2361  if (tabOpt->direction == Qt::LeftToRight)
2362  {
2363  //We place icon on the left.
2364  iconRect = QRect(labelRect.x(), labelRect.y() + (labelRect.height() - iconSize.height() + 1) / 2,
2365  iconSize.width(), iconSize.height());
2366 
2367  //Adjust the text rect.
2368  labelRect.setLeft(labelRect.x() + iconSize.width() +
2369  widgetLayoutProp(WT_TabBar, TabBar::TabTextToIconSpace, option, widget));
2370  }
2371  else
2372  {
2373  //We place icon on the right
2374  iconRect = QRect(labelRect.x() + labelRect.width() - iconSize.width(),
2375  labelRect.y() + (labelRect.height() - iconSize.height() + 1) / 2, iconSize.width(), iconSize.height());
2376  //Adjust the text rect
2377  labelRect.setWidth(labelRect.width() - iconSize.width() -
2378  widgetLayoutProp(WT_TabBar, TabBar::TabTextToIconSpace, option, widget));
2379  }
2380  }
2381  else
2382  {
2383  bool aboveIcon = false;
2384  if (tabSd == West && tabOpt->direction == Qt::RightToLeft)
2385  aboveIcon = true;
2386  if (tabSd == East && tabOpt->direction == Qt::LeftToRight)
2387  aboveIcon = true;
2388 
2389  if (aboveIcon)
2390  {
2391  iconRect = QRect(labelRect.x() + (labelRect.width() - iconSize.width() + 1) / 2, labelRect.y(),
2392  iconSize.width(), iconSize.height());
2393  labelRect.setTop(labelRect.y() + iconSize.height() +
2394  widgetLayoutProp(WT_TabBar, TabBar::TabTextToIconSpace, option, widget));
2395  }
2396  else
2397  {
2398  iconRect = QRect(labelRect.x() + (labelRect.width() - iconSize.width() + 1) / 2,
2399  labelRect.y() + labelRect.height() - iconSize.height(),
2400  iconSize.width(), iconSize.height());
2401  labelRect.setHeight(labelRect.height() - iconSize.height() -
2402  widgetLayoutProp(WT_TabBar, TabBar::TabTextToIconSpace, option, widget));
2403  }
2404  }
2405 
2406  //Draw the thing
2407  drawKStylePrimitive(WT_TabBar, Generic::Icon, option, iconRect,
2408  pal, flags, p, widget, &icoOpt);
2409  } //if have icon.
2410 
2411  //Draw text
2412  if (!tabOpt->text.isNull())
2413  {
2414  TextOption lbOpt(tabOpt->text);
2415  if (widget)
2416  lbOpt.color = widget->foregroundRole();
2417 
2418  int primitive = Generic::Text; // For horizontal tabs
2419 
2420  if (tabSd == East)
2421  primitive = TabBar::EastText;
2422  else if (tabSd == West)
2423  primitive = TabBar::WestText;
2424 
2425  drawKStylePrimitive(WT_TabBar, primitive, option, labelRect,
2426  pal, flags, p, widget, &lbOpt);
2427  }
2428 
2429  //If need be, draw focus rect
2430  if (tabOpt->state & State_HasFocus)
2431  {
2432  QRect focusRect = marginAdjustedTab(tabOpt, TabBar::TabFocusMargin);
2433  drawKStylePrimitive(WT_TabBar, Generic::FocusIndicator, option, focusRect,
2434  pal, flags, p, widget);
2435  }
2436  return;
2437  }
2438 
2439  case CE_ToolBar:
2440  {
2441  if (flags & State_Horizontal)
2442  drawKStylePrimitive(WT_ToolBar, ToolBar::PanelHor,option,r,pal,flags,p,widget);
2443  else
2444  drawKStylePrimitive(WT_ToolBar, ToolBar::PanelVert,option,r,pal,flags,p,widget);
2445 
2446  return;
2447  }
2448 
2449  case CE_HeaderSection:
2450  {
2451  if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
2452  drawKStylePrimitive(WT_Header, (header->orientation==Qt::Horizontal)?Header::SectionHor:Header::SectionVert,
2453  option, r, pal, flags, p, widget);
2454  return;
2455  }
2456  }
2457 
2458  case CE_HeaderLabel:
2459  {
2460  if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
2461  QRect textRect = r;
2462  if (!header->icon.isNull()) {
2463  bool enabled = flags & State_Enabled;
2464  QPixmap pm = header->icon.pixmap(pixelMetric(PM_SmallIconSize), enabled?QIcon::Normal:QIcon::Disabled);
2465 
2466  // TODO: respect header->iconAlignment.
2467  bool reverseLayout = header->direction == Qt::RightToLeft;
2468  int iy = r.top()+(r.height()-pm.height())/2;
2469  int ix = reverseLayout ? r.right()-pm.width() : r.left();
2470  QRect iconRect = QRect(ix, iy, pm.width(), pm.height() );
2471 
2472  IconOption iconOpt;
2473  iconOpt.icon = pm;
2474  drawKStylePrimitive(WT_Header, Generic::Icon, option, iconRect, pal, flags, p, widget, &iconOpt);
2475 
2476  // adjust the rect for the text...
2477  int spacing = widgetLayoutProp(WT_Header, Header::TextToIconSpace, option, widget);
2478  if (reverseLayout)
2479  {
2480  textRect.setRight(r.right()-iconRect.width()-spacing );
2481  }
2482  else
2483  {
2484  textRect.setLeft(r.x()+iconRect.width()+spacing );
2485  }
2486  }
2487 
2488  TextOption lbOpt(header->text);
2489  lbOpt.hAlign = header->textAlignment;
2490  drawKStylePrimitive(WT_Header, Generic::Text, option, textRect, pal, flags, p, widget, &lbOpt);
2491  }
2492  return;
2493  }
2494 
2495  case CE_Splitter:
2496  {
2497  if (flags&State_Horizontal)
2498  drawKStylePrimitive(WT_Splitter, Splitter::HandleHor, option, r, pal, flags, p, widget);
2499  else
2500  drawKStylePrimitive(WT_Splitter, Splitter::HandleVert, option, r, pal, flags, p, widget);
2501  return;
2502  }
2503 
2504  default:
2505  break;
2506  }
2507 
2508  QCommonStyle::drawControl(element, option, p, widget);
2509 }
2510 
2511 
2512 int KStyle::styleHint (StyleHint hint, const QStyleOption* option, const QWidget* widget, QStyleHintReturn* returnData) const
2513 {
2514  switch (hint)
2515  {
2516  case SH_ComboBox_ListMouseTracking:
2517  return true;
2518 
2519  case SH_MenuBar_MouseTracking:
2520  case SH_Menu_MouseTracking:
2521  return true;
2522 
2523  case SH_Menu_SubMenuPopupDelay:
2524  return 96; // Motif-like delay...
2525 
2526  case SH_TitleBar_NoBorder:
2527  return widgetLayoutProp(WT_Window, Window::NoTitleFrame, option, widget);
2528 
2529  case SH_GroupBox_TextLabelVerticalAlignment:
2530  if (widgetLayoutProp(WT_GroupBox, GroupBox::TextAlignTop, option, widget) )
2531  return Qt::AlignTop;
2532  else
2533  return Qt::AlignVCenter;
2534 
2535  case SH_GroupBox_TextLabelColor:
2536  {
2537  ColorMode cm( widgetLayoutProp(WT_GroupBox, GroupBox::TitleTextColor,
2538  option, widget) );
2539  return cm.color(option ? option->palette : qApp->palette()).rgba();
2540  }
2541 
2542  case SH_DialogButtonLayout:
2543  return QDialogButtonBox::KdeLayout;
2544 
2545  case SH_ScrollBar_MiddleClickAbsolutePosition:
2546  return true;
2547 
2548  // Don't draw the branch as selected in tree views
2549  case SH_ItemView_ShowDecorationSelected:
2550  return false;
2551 
2552  case SH_ItemView_ActivateItemOnSingleClick:
2553  return d->m_componentData.config()->group("KDE").readEntry("SingleClick", KDE_DEFAULT_SINGLECLICK );
2554  case SH_KCustomStyleElement:
2555  if (!widget)
2556  return 0;
2557  return d->styleElements.value(widget->objectName(), 0);
2558 
2559  // per HIG, align the contents in a form layout to the left
2560  case SH_FormLayoutFormAlignment:
2561  return Qt::AlignLeft | Qt::AlignTop;
2562 
2563  // per HIG, align the labels in a form layout to the right
2564  case SH_FormLayoutLabelAlignment:
2565  return Qt::AlignRight;
2566 
2567  case SH_FormLayoutFieldGrowthPolicy:
2568  return QFormLayout::ExpandingFieldsGrow;
2569 
2570  case SH_FormLayoutWrapPolicy:
2571  return QFormLayout::DontWrapRows;
2572 
2573  case SH_MessageBox_TextInteractionFlags:
2574  return true;
2575 
2576  case SH_DialogButtonBox_ButtonsHaveIcons:
2577  return KGlobalSettings::showIconsOnPushButtons();
2578 
2579  case SH_ItemView_ArrowKeysNavigateIntoChildren:
2580  return true;
2581 
2582  default:
2583  break;
2584  };
2585 
2586  return QCommonStyle::styleHint(hint, option, widget, returnData);
2587 }
2588 
2589 int KStyle::pixelMetric(PixelMetric metric, const QStyleOption* option, const QWidget* widget) const
2590 {
2591  switch (metric)
2592  {
2593  case PM_SmallIconSize:
2594  case PM_ButtonIconSize:
2595  return KIconLoader::global()->currentSize(KIconLoader::Small);
2596  case PM_ToolBarIconSize:
2597  return KIconLoader::global()->currentSize(KIconLoader::Toolbar);
2598  case PM_LargeIconSize:
2599  return KIconLoader::global()->currentSize(KIconLoader::Dialog);
2600  case PM_MessageBoxIconSize:
2601  // TODO return KIconLoader::global()->currentSize(KIconLoader::MessageBox);
2602  return KIconLoader::SizeHuge;
2603 
2604  case PM_DefaultFrameWidth:
2605  if (qstyleoption_cast<const QStyleOptionGroupBox *>(option) )
2606  return widgetLayoutProp(WT_GroupBox, GroupBox::FrameWidth, option, widget);
2607  else
2608  return widgetLayoutProp(WT_Generic, Generic::DefaultFrameWidth, option, widget);
2609 
2610  case PM_DefaultChildMargin:
2611  case PM_DefaultTopLevelMargin:
2612  return widgetLayoutProp(WT_Generic, Generic::DefaultLayoutMargin, option, widget);
2613 
2614  case PM_LayoutHorizontalSpacing:
2615  case PM_LayoutVerticalSpacing:
2616  // use layoutSpacingImplementation
2617  return -1;
2618 
2619  case PM_DefaultLayoutSpacing:
2620  return widgetLayoutProp(WT_Generic, Generic::DefaultLayoutSpacing, option, widget);
2621 
2622  case PM_LayoutLeftMargin:
2623  case PM_LayoutTopMargin:
2624  case PM_LayoutRightMargin:
2625  case PM_LayoutBottomMargin:
2626  {
2627  PixelMetric marginMetric;
2628  if ((option && (option->state & QStyle::State_Window))
2629  || (widget && widget->isWindow())) {
2630  marginMetric = PM_DefaultTopLevelMargin;
2631  } else {
2632  marginMetric = PM_DefaultChildMargin;
2633  }
2634  return pixelMetric(marginMetric, option, widget);
2635  }
2636 
2637  case PM_ButtonMargin:
2638  return 0; //Better not return anything here since we already
2639  //incorporated this into SE_PushButtonContents
2640  case PM_ButtonDefaultIndicator:
2641  // PushButton::DefaultIndicatorMargin is used throughout KStyle button
2642  // implementation code, so this probably is not necessary.
2643  // return it in case Apps rely on this metric, though.
2644  return widgetLayoutProp(WT_PushButton, PushButton::DefaultIndicatorMargin, option, widget);
2645  case PM_ButtonShiftHorizontal:
2646  return widgetLayoutProp(WT_PushButton, PushButton::PressedShiftHorizontal, option, widget);
2647  case PM_ButtonShiftVertical:
2648  return widgetLayoutProp(WT_PushButton, PushButton::PressedShiftVertical, option, widget);
2649  case PM_MenuButtonIndicator:
2650  if (qstyleoption_cast<const QStyleOptionToolButton*>(option))
2651  return widgetLayoutProp(WT_ToolButton, ToolButton::MenuIndicatorSize, option, widget);
2652  else
2653  return widgetLayoutProp(WT_PushButton, PushButton::MenuIndicatorSize, option, widget);
2654 
2655  case PM_SplitterWidth:
2656  return widgetLayoutProp(WT_Splitter, Splitter::Width, option, widget);
2657 
2658  case PM_IndicatorWidth:
2659  case PM_IndicatorHeight:
2660  return widgetLayoutProp(WT_CheckBox, CheckBox::Size, option, widget);
2661 
2662  case PM_ExclusiveIndicatorWidth:
2663  case PM_ExclusiveIndicatorHeight:
2664  return widgetLayoutProp(WT_RadioButton, RadioButton::Size, option, widget);
2665 
2666  case PM_CheckListControllerSize:
2667  case PM_CheckListButtonSize:
2668  {
2669  int checkBoxSize = widgetLayoutProp(WT_CheckBox, CheckBox::Size, option, widget);
2670  int radioButtonSize = widgetLayoutProp(WT_RadioButton, RadioButton::Size, option, widget);
2671  return qMax(checkBoxSize, radioButtonSize);
2672  }
2673 
2674  case PM_DockWidgetFrameWidth:
2675  return widgetLayoutProp(WT_DockWidget, DockWidget::FrameWidth, option, widget);
2676 
2677  case PM_DockWidgetSeparatorExtent:
2678  return widgetLayoutProp(WT_DockWidget, DockWidget::SeparatorExtent, option, widget);
2679 
2680  // handle extent only used somewhere in Qt3support, don't care.
2681  // case PM_DockWidgetHandleExtent:
2682 
2683  case PM_DockWidgetTitleMargin:
2684  return widgetLayoutProp(WT_DockWidget, DockWidget::TitleMargin, option, widget);
2685 
2686  case PM_ProgressBarChunkWidth:
2687  return widgetLayoutProp(WT_ProgressBar, ProgressBar::Precision, option, widget);
2688 
2689  case PM_MenuBarPanelWidth:
2690  return 0; //Simplification: just one primitive is used and it includes the border
2691 
2692  case PM_MenuBarHMargin:
2693  {
2694  //Calculate how much extra space we need besides the frame size. We use the left margin
2695  //here, and adjust the total rect by the difference between it and the right margin
2696  int spaceL = widgetLayoutProp(WT_MenuBar, MenuBar::Margin, option, widget) + widgetLayoutProp(WT_MenuBar, MenuBar::Margin + Left, option, widget);
2697 
2698  return spaceL;
2699  }
2700 
2701  case PM_MenuBarVMargin:
2702  {
2703  //As above, we return the top one, and fudge the total size for the bottom.
2704  int spaceT = widgetLayoutProp(WT_MenuBar, MenuBar::Margin, option, widget) + widgetLayoutProp(WT_MenuBar, MenuBar::Margin + Top, option, widget);
2705  return spaceT;
2706  }
2707 
2708  case PM_MenuBarItemSpacing:
2709  return widgetLayoutProp(WT_MenuBar, MenuBar::ItemSpacing, option, widget);
2710 
2711  case PM_MenuDesktopFrameWidth:
2712  return 0; //### CHECKME
2713 
2714  case PM_MenuPanelWidth:
2715  return widgetLayoutProp(WT_Menu, Menu::FrameWidth, option, widget);
2716 
2717  /* ### seems to trigger Qt bug. So we loose the margins for now
2718  case PM_MenuHMargin:
2719  {
2720  //Calculate how much extra space we need besides the frame size. We use the left margin
2721  //here, and adjust the total rect by the difference between it and the right margin
2722  int spaceL = widgetLayoutProp(WT_Menu, Menu::Margin, option, widget) + widgetLayoutProp(WT_Menu, Menu::Margin + Left, option, widget) -
2723  widgetLayoutProp(WT_Menu, Menu::FrameWidth, option, widget);
2724 
2725  return spaceL;
2726  }
2727 
2728  case PM_MenuVMargin:
2729  {
2730  //As above, we return the top one, and fudge the total size for the bottom.
2731  int spaceT = widgetLayoutProp(WT_Menu, Menu::Margin, option, widget) + widgetLayoutProp(WT_Menu, Menu::Margin + Top, option, widget) -
2732  widgetLayoutProp(WT_Menu, Menu::FrameWidth, option, widget);
2733  return spaceT;
2734  } */
2735 
2736  case PM_MenuScrollerHeight:
2737  return widgetLayoutProp(WT_Menu, Menu::ScrollerHeight, option, widget);
2738 
2739  case PM_MenuTearoffHeight:
2740  return widgetLayoutProp(WT_Menu, Menu::TearOffHeight, option, widget);
2741 
2742  case PM_TabBarTabHSpace:
2743  {
2744  const QStyleOptionTab* tabOpt = qstyleoption_cast<const QStyleOptionTab*>(option);
2745  if (tabOpt)
2746  {
2747  //Perhaps we can avoid the extra margin...
2748  if (tabOpt->text.isNull() && !tabOpt->icon.isNull())
2749  return 0;
2750  if (tabOpt->icon.isNull() && !tabOpt->text.isNull())
2751  return 0;
2752  }
2753 
2754  return widgetLayoutProp(WT_TabBar, TabBar::TabTextToIconSpace, option, widget);
2755  }
2756 
2757  case PM_TabBarTabVSpace:
2758  return 0;
2759 
2760  case PM_TabBarBaseHeight:
2761  return widgetLayoutProp(WT_TabBar, TabBar::BaseHeight, option, widget);
2762 
2763  case PM_TabBarBaseOverlap:
2764  return widgetLayoutProp(WT_TabBar, TabBar::BaseOverlap, option, widget);
2765 
2766  case PM_TabBarTabOverlap:
2767  return widgetLayoutProp(WT_TabBar, TabBar::TabOverlap, option, widget);
2768 
2769  case PM_TabBarScrollButtonWidth:
2770  return widgetLayoutProp(WT_TabBar, TabBar::ScrollButtonWidth, option, widget);
2771 
2772  case PM_TabBarTabShiftVertical:
2773  return 1;
2774 
2775  case PM_TabBarTabShiftHorizontal:
2776  return 0;
2777 
2778  case PM_SliderControlThickness:
2779  return widgetLayoutProp(WT_Slider, Slider::HandleThickness, option, widget);
2780 
2781  case PM_SliderLength:
2782  return widgetLayoutProp(WT_Slider, Slider::HandleLength, option, widget);
2783 
2784  case PM_SliderThickness:
2785  {
2786  // not sure what the difference to PM_SliderControlThickness actually is
2787  return widgetLayoutProp(WT_Slider, Slider::HandleThickness, option, widget);
2788  }
2789 
2790  case PM_SpinBoxFrameWidth:
2791  return widgetLayoutProp(WT_SpinBox, SpinBox::FrameWidth, option, widget);
2792 
2793  case PM_ComboBoxFrameWidth:
2794  return widgetLayoutProp(WT_ComboBox, ComboBox::FrameWidth, option, widget);
2795 
2796  case PM_HeaderMarkSize:
2797  return widgetLayoutProp(WT_Header, Header::MarkSize, option, widget);
2798 
2799  case PM_HeaderMargin:
2800  return widgetLayoutProp(WT_Header, Header::TextToIconSpace, option, widget);
2801 
2802  case PM_ToolBarFrameWidth:
2803  return widgetLayoutProp(WT_ToolBar, ToolBar::FrameWidth, option, widget);
2804 
2805  case PM_ToolBarHandleExtent:
2806  return widgetLayoutProp(WT_ToolBar, ToolBar::HandleExtent, option, widget);
2807 
2808  case PM_ToolBarSeparatorExtent:
2809  return widgetLayoutProp(WT_ToolBar, ToolBar::SeparatorExtent, option, widget);
2810 
2811  case PM_ToolBarExtensionExtent:
2812  return widgetLayoutProp(WT_ToolBar, ToolBar::ExtensionExtent, option, widget);
2813 
2814  case PM_ToolBarItemMargin:
2815  return widgetLayoutProp(WT_ToolBar, ToolBar::ItemMargin, option, widget);
2816 
2817  case PM_ToolBarItemSpacing:
2818  return widgetLayoutProp(WT_ToolBar, ToolBar::ItemSpacing, option, widget);
2819 
2820  case PM_ScrollBarExtent:
2821  return widgetLayoutProp(WT_ScrollBar, ScrollBar::BarWidth, option, widget);
2822 
2823  case PM_TitleBarHeight:
2824  return widgetLayoutProp(WT_Window, Window::TitleHeight, option, widget);
2825 
2826  default:
2827  break;
2828  }
2829 
2830  return QCommonStyle::pixelMetric(metric, option, widget);
2831 }
2832 
2833 int KStyle::layoutSpacingImplementation(QSizePolicy::ControlType control1, QSizePolicy::ControlType control2, Qt::Orientation orientation, const QStyleOption *option, const QWidget *widget) const
2834 {
2835  Q_UNUSED(control1); Q_UNUSED(control2); Q_UNUSED(orientation);
2836 
2837  return pixelMetric(PM_DefaultLayoutSpacing, option, widget);
2838 }
2839 
2840 
2841 bool KStyle::isVerticalTab(const QStyleOptionTab* tbOpt) const
2842 {
2843  switch (tbOpt->shape)
2844  {
2845  case QTabBar::RoundedWest:
2846  case QTabBar::RoundedEast:
2847  case QTabBar::TriangularWest:
2848  case QTabBar::TriangularEast:
2849  return true;
2850  default:
2851  return false;
2852  }
2853 }
2854 
2855 bool KStyle::isReflectedTab(const QStyleOptionTab* tbOpt) const
2856 {
2857  switch (tbOpt->shape)
2858  {
2859  case QTabBar::RoundedEast:
2860  case QTabBar::TriangularEast:
2861  case QTabBar::RoundedSouth:
2862  case QTabBar::TriangularSouth:
2863  return true;
2864  default:
2865  return false;
2866  }
2867 }
2868 
2869 KStyle::Side KStyle::tabSide(const QStyleOptionTab* tbOpt) const
2870 {
2871  switch (tbOpt->shape)
2872  {
2873  case QTabBar::RoundedEast:
2874  case QTabBar::TriangularEast:
2875  return East;
2876  case QTabBar::RoundedWest:
2877  case QTabBar::TriangularWest:
2878  return West;
2879  case QTabBar::RoundedNorth:
2880  case QTabBar::TriangularNorth:
2881  return North;
2882  default:
2883  return South;
2884  }
2885 }
2886 
2887 QRect KStyle::marginAdjustedTab(const QStyleOptionTab* tabOpt, int property) const
2888 {
2889  QRect r = tabOpt->rect;
2890 
2891  //For region, we first figure out the geometry if it was normal, and adjust.
2892  //this takes some rotating
2893  bool vertical = isVerticalTab (tabOpt);
2894  bool flip = isReflectedTab(tabOpt);
2895 
2896  QRect idializedGeometry = vertical ? QRect(0, 0, r.height(), r.width())
2897  : QRect(0, 0, r.width(), r.height());
2898 
2899  QRect contentArea = insideMargin(idializedGeometry, WT_TabBar, property, tabOpt, 0);
2900 
2901  int leftMargin = contentArea.x();
2902  int rightMargin = idializedGeometry.width() - 1 - contentArea.right();
2903  int topMargin = contentArea.y();
2904  int botMargin = idializedGeometry.height() - 1 - contentArea.bottom();
2905 
2906  if (vertical)
2907  {
2908  int t = rightMargin;
2909  rightMargin = topMargin;
2910  topMargin = leftMargin;
2911  leftMargin = botMargin;
2912  botMargin = t;
2913 
2914  if (!flip)
2915  qSwap(leftMargin, rightMargin);
2916  }
2917  else if (flip)
2918  {
2919  qSwap(topMargin, botMargin);
2920  //For horizontal tabs, we also want to reverse stuff for RTL!
2921  if (tabOpt->direction == Qt::RightToLeft)
2922  qSwap(leftMargin, rightMargin);
2923  }
2924 
2925  QRect geom =
2926  QRect(QPoint(leftMargin, topMargin),
2927  QPoint(r.width() - 1 - rightMargin,
2928  r.height() - 1 - botMargin));
2929  geom.translate(r.topLeft());
2930  return geom;
2931 }
2932 
2933 bool KStyle::useSideText(const QStyleOptionProgressBar* pbOpt) const
2934 {
2935  if (widgetLayoutProp(WT_ProgressBar, ProgressBar::SideText) == 0)
2936  return false;
2937 
2938  if (!pbOpt) return false; //Paranoia
2939 
2940  if (!pbOpt->textVisible) return false; //Don't allocate side margin if text display is off...
2941 
2942  if (pbOpt->textAlignment & Qt::AlignHCenter) return false; //### do we want this? we don't
2943  //force indicator to the side outside
2944  //the main otherwise.
2945 
2946  if (pbOpt->minimum == pbOpt->maximum) return false;
2947 
2948  int widthAlloc = pbOpt->fontMetrics.width(QLatin1String("100%"));
2949 
2950  if (pbOpt->fontMetrics.width(pbOpt->text) > widthAlloc)
2951  return false; //Doesn't fit!
2952 
2953  return true;
2954 }
2955 
2956 int KStyle::sideTextWidth(const QStyleOptionProgressBar* pbOpt) const
2957 {
2958  return pbOpt->fontMetrics.width(QLatin1String("100%")) +
2959  2*widgetLayoutProp(WT_ProgressBar, ProgressBar::SideTextSpace);
2960 }
2961 
2962 QRect KStyle::subElementRect(SubElement sr, const QStyleOption* option, const QWidget* widget) const
2963 {
2964  QRect r = option->rect;
2965 
2966  switch (sr)
2967  {
2968  case SE_PushButtonContents:
2969  {
2970  const QStyleOptionButton* bOpt = qstyleoption_cast<const QStyleOptionButton*>(option);
2971  if (!bOpt) return r;
2972 
2973  if ((bOpt->features & QStyleOptionButton::DefaultButton) || (bOpt->features & QStyleOptionButton::AutoDefaultButton))
2974  r = insideMargin(r, WT_PushButton, PushButton::DefaultIndicatorMargin, option, widget);
2975 
2976  return insideMargin(r, WT_PushButton, PushButton::ContentsMargin, option, widget);
2977  }
2978 
2979  case SE_PushButtonFocusRect:
2980  {
2981  const QStyleOptionButton* bOpt = qstyleoption_cast<const QStyleOptionButton*>(option);
2982  if (!bOpt) return r;
2983 
2984  if ((bOpt->features & QStyleOptionButton::DefaultButton) || (bOpt->features & QStyleOptionButton::AutoDefaultButton))
2985  r = insideMargin(r, WT_PushButton, PushButton::DefaultIndicatorMargin, option, widget);
2986 
2987  return insideMargin(r, WT_PushButton, PushButton::FocusMargin, option, widget);
2988  }
2989 
2990  case SE_ToolBoxTabContents:
2991  {
2992  return insideMargin(r, WT_ToolBoxTab, ToolBoxTab::Margin, option, widget);
2993  }
2994 
2995  case SE_CheckBoxContents:
2996  {
2997  r.setX(r.x() + widgetLayoutProp(WT_CheckBox, CheckBox::Size, option, widget) +
2998  widgetLayoutProp(WT_CheckBox, CheckBox::BoxTextSpace, option, widget));
2999  return handleRTL(option, r);
3000  }
3001 
3002  case SE_RadioButtonContents:
3003  {
3004  r.setX(r.x() + widgetLayoutProp(WT_RadioButton, RadioButton::Size, option, widget) +
3005  widgetLayoutProp(WT_RadioButton, RadioButton::BoxTextSpace, option, widget));
3006  return handleRTL(option, r);
3007  }
3008 
3009  case SE_CheckBoxFocusRect:
3010  {
3011  const QStyleOptionButton* bOpt = qstyleoption_cast<const QStyleOptionButton*>(option);
3012  if (!bOpt) return r;
3013 
3014  QRect ret;
3015 
3016  if (bOpt->text.isEmpty())
3017  {
3018  // first convert, so we can deal with logical coords
3019  QRect checkRect =
3020  handleRTL(option, subElementRect(SE_CheckBoxIndicator, option, widget) );
3021  ret = insideMargin(checkRect, WT_CheckBox, CheckBox::NoLabelFocusMargin, option, widget);
3022  }
3023  else
3024  {
3025  // first convert, so we can deal with logical coords
3026  QRect contentsRect =
3027  handleRTL(option, subElementRect(SE_CheckBoxContents, option, widget) );
3028  ret = insideMargin(contentsRect, WT_CheckBox, CheckBox::FocusMargin, option, widget);
3029  }
3030  // convert back to screen coords
3031  return handleRTL(option, ret);
3032  }
3033 
3034  case SE_RadioButtonFocusRect:
3035  {
3036  // first convert it back to logical coords
3037  QRect contentsRect =
3038  handleRTL(option, subElementRect(SE_RadioButtonContents, option, widget) );
3039 
3040  // modify the rect and convert back to screen coords
3041  return handleRTL(option,
3042  insideMargin(contentsRect, WT_RadioButton,
3043  RadioButton::FocusMargin, option, widget) );
3044  }
3045 
3046  case SE_ProgressBarGroove:
3047  {
3048  const QStyleOptionProgressBar* pbOpt = ::qstyleoption_cast<const QStyleOptionProgressBar*>(option);
3049  if (useSideText(pbOpt))
3050  {
3051  r.setWidth(r.width() - sideTextWidth(pbOpt));
3052  return r;
3053  }
3054 
3055  //Centering mode --- could be forced or side... so the groove area is everything
3056  return r;
3057  }
3058 
3059  case SE_ProgressBarContents:
3060  {
3061  QRect grooveRect = subElementRect(SE_ProgressBarGroove, option, widget);
3062  return insideMargin(grooveRect, WT_ProgressBar, ProgressBar::GrooveMargin, option, widget);
3063  }
3064 
3065  case SE_ProgressBarLabel:
3066  {
3067  const QStyleOptionProgressBar* pbOpt = ::qstyleoption_cast<const QStyleOptionProgressBar*>(option);
3068  if (useSideText(pbOpt))
3069  {
3070  int width = sideTextWidth(pbOpt);
3071  return QRect(r.x() + r.width() - width, r.y(), width, r.height());
3072  }
3073 
3074  //The same as the contents area..
3075  return subElementRect(SE_PushButtonContents, option, widget);
3076  }
3077 
3078  // SE_TabWidgetTabPane implementation in QCommonStyle is perfectly fine.
3079  case SE_TabWidgetTabContents:
3080  {
3081  const QStyleOptionTabWidgetFrame* tabOpt = qstyleoption_cast<const QStyleOptionTabWidgetFrame*>(option);
3082  if (!tabOpt) break;
3083 
3084  // Don't apply the custom margin when documentMode is enabled.
3085  if (tabOpt->lineWidth == 0) break;
3086 
3087  // use QCommonStyle's SE_TabWidgetTabPane, and adjust the result
3088  // according to the custom frame width.
3089  QRect pane = QCommonStyle::subElementRect(SE_TabWidgetTabPane, option, widget);
3090  int m = widgetLayoutProp(WT_TabWidget, TabWidget::ContentsMargin, option, widget);
3091  int top = m+widgetLayoutProp(WT_TabWidget, TabWidget::ContentsMargin+Top,
3092  option, widget);
3093  int bot = m+widgetLayoutProp(WT_TabWidget, TabWidget::ContentsMargin+Bot,
3094  option, widget);
3095  int left = m+widgetLayoutProp(WT_TabWidget, TabWidget::ContentsMargin+Left,
3096  option, widget);
3097  int right = m+widgetLayoutProp(WT_TabWidget, TabWidget::ContentsMargin+Right,
3098  option, widget);
3099 
3100  switch (tabOpt->shape) {
3101  case QTabBar::RoundedNorth:
3102  case QTabBar::TriangularNorth:
3103  return pane.adjusted(left,top,-right,-bot);
3104  case QTabBar::RoundedEast:
3105  case QTabBar::TriangularEast:
3106  return pane.adjusted(bot,left, -top,-right);
3107  case QTabBar::RoundedSouth:
3108  case QTabBar::TriangularSouth:
3109  return pane.adjusted(right,bot, -left,-top);
3110  case QTabBar::RoundedWest:
3111  case QTabBar::TriangularWest:
3112  return pane.adjusted(top,right, -bot,-left);
3113  }
3114  }
3115 
3116  case SE_TabBarTabText:
3117  {
3118  const QStyleOptionTab* tabOpt = qstyleoption_cast<const QStyleOptionTab*>(option);
3119  if (!tabOpt) return QRect();
3120 
3121  QRect r = marginAdjustedTab(tabOpt, TabBar::TabContentsMargin);
3122  QStyleOptionTabV3 tov3(*tabOpt);
3123 
3124  switch (tov3.shape)
3125  {
3126  case QTabBar::RoundedNorth:
3127  case QTabBar::TriangularNorth:
3128  case QTabBar::RoundedSouth:
3129  case QTabBar::TriangularSouth:
3130  if (tov3.direction == Qt::LeftToRight)
3131  r.adjust(tov3.leftButtonSize.width(), 0, -tov3.rightButtonSize.width(), 0);
3132  else
3133  r.adjust(tov3.rightButtonSize.width(), 0, -tov3.leftButtonSize.width(), 0);
3134  break;
3135  case QTabBar::RoundedEast:
3136  case QTabBar::TriangularEast:
3137  r.adjust(0, tov3.leftButtonSize.width(), 0, -tov3.rightButtonSize.width());
3138  break;
3139  case QTabBar::RoundedWest:
3140  case QTabBar::TriangularWest:
3141  r.adjust(0, tov3.rightButtonSize.width(), 0, -tov3.leftButtonSize.width());
3142  break;
3143  }
3144 
3145  return r;
3146  }
3147 
3148  default:
3149  break;
3150  }
3151 
3152  return QCommonStyle::subElementRect(sr, option, widget);
3153 }
3154 
3155 void KStyle::drawComplexControl (ComplexControl cc, const QStyleOptionComplex* opt,
3156  QPainter *p, const QWidget* w) const
3157 {
3158  //Extract the stuff we need out of the option
3159  State flags = opt->state;
3160  QRect r = opt->rect;
3161  QPalette pal = opt->palette;
3162 
3163  switch (cc)
3164  {
3165  case CC_ScrollBar:
3166  {
3167  QStyleOptionComplex* mutableOpt = const_cast<QStyleOptionComplex*>(opt);
3168  if ((mutableOpt->subControls & SC_ScrollBarSubLine) || (mutableOpt->subControls & SC_ScrollBarAddLine))
3169  {
3170  //If we paint one of the buttons, must paint both!
3171  mutableOpt->subControls |= SC_ScrollBarSubPage | SC_ScrollBarAddLine;
3172  }
3173  //Note: we falldown to the base intentionally
3174  }
3175  break;
3176 
3177  case CC_Q3ListView:
3178  {
3179  const QStyleOptionQ3ListView* lvOpt = qstyleoption_cast<const QStyleOptionQ3ListView*>(opt);
3180  Q_ASSERT (lvOpt);
3181 
3182  if (lvOpt->subControls & SC_Q3ListView)
3183  QCommonStyle::drawComplexControl(cc, opt, p, w);
3184 
3185  if (lvOpt->items.isEmpty())
3186  return;
3187 
3188  // If we have a branch or are expanded...
3189  if (lvOpt->subControls & (SC_Q3ListViewBranch | SC_Q3ListViewExpand))
3190  {
3191  QStyleOptionQ3ListViewItem item = lvOpt->items.at(0);
3192 
3193  int y = r.y();
3194 
3195  QStyleOption opt; //For painting
3196  opt.palette = lvOpt->palette;
3197  opt.direction = Qt::LeftToRight;
3198 
3199  //Remap the painter so (0,0) corresponds to the origin
3200  //of the widget, to help out the line align code.
3201  //Extract the paint offset. Here be dragons
3202  //(and not the cute green Patron of the project, either)
3203  int cX = w ? w->property("contentsX").toInt() : 0;
3204  int cY = w ? w->property("contentsY").toInt() : 0;
3205 
3206  QPoint adjustCoords = p->matrix().map(QPoint(0,0)) + QPoint(cX, cY);
3207  p->translate(-adjustCoords);
3208 
3209  if (lvOpt->activeSubControls == SC_All && (lvOpt->subControls & SC_Q3ListViewExpand)) {
3210  //### CHECKME: this is from KStyle3, and needs to be re-checked/tested
3211  // We only need to draw a vertical line
3212  //Route through the Qt4 style-call.
3213  QStyleOption opt;
3214  opt.rect = QRect(r.topLeft() + adjustCoords, r.size());
3215  opt.state = State_Sibling;
3216  drawPrimitive(PE_IndicatorBranch, &opt, p, 0);
3217  } else {
3218  int childPos = 1;
3219 
3220  // Draw all the expand/close boxes, and nearby branches
3221  while (childPos < lvOpt->items.size() && y < r.height())
3222  {
3223  const QStyleOptionQ3ListViewItem& child = lvOpt->items.at(childPos);
3224  if (!(child.features & QStyleOptionQ3ListViewItem::Visible))
3225  {
3226  childPos++;
3227  continue;
3228  }
3229 
3230  //Route through the Qt4 style-call.
3231  opt.rect = QRect(r.x() + adjustCoords.x(), y + adjustCoords.y(),
3232  r.width(), child.height);
3233  opt.state = State_Item;
3234 
3235  if (child.features & QStyleOptionQ3ListViewItem::Expandable || child.childCount)
3236  {
3237  opt.state |= State_Children;
3238  opt.state |= (child.state & State_Open);
3239  }
3240 
3241  //See if we have a visible sibling
3242  int siblingPos = 0;
3243  for (siblingPos = childPos + 1; siblingPos < lvOpt->items.size(); ++siblingPos)
3244  {
3245  if (lvOpt->items.at(siblingPos).features & QStyleOptionQ3ListViewItem::Visible)
3246  {
3247  opt.state |= State_Sibling;
3248  break;
3249  }
3250  }
3251 
3252  //If on screen, paint it
3253  if (y + child.height > 0)
3254  drawPrimitive(PE_IndicatorBranch, &opt, p, 0);
3255 
3256  if (!siblingPos)
3257  break;
3258 
3259  //If we have a sibling, and an expander, also have to draw
3260  //a line for below the immediate area
3261  if ((opt.state & State_Children) && (opt.state & State_Sibling))
3262  {
3263  opt.state = State_Sibling;
3264  opt.rect = QRect(r.x() + adjustCoords.x(),
3265  y + adjustCoords.y() + child.height,
3266  r.width(), child.totalHeight - child.height);
3267  if (opt.rect.height())
3268  drawPrimitive(PE_IndicatorBranch, &opt, p, 0);
3269  }
3270 
3271  y += child.totalHeight;
3272  childPos = siblingPos;
3273  } //loop through items
3274  } //complex case
3275 
3276  p->translate(adjustCoords);
3277  } //if have branch or expander
3278  } //CC_Q3ListView
3279  break;
3280 
3281  case CC_Slider:
3282  {
3283  if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt))
3284  {
3285  QRect groove = subControlRect(CC_Slider, slider, SC_SliderGroove, w);
3286  QRect handle = subControlRect(CC_Slider, slider, SC_SliderHandle, w);
3287  bool hor = slider->orientation == Qt::Horizontal;
3288 
3289  if (slider->subControls & SC_SliderTickmarks)
3290  {
3291  // TODO: make tickmarks customizable with Slider::Tickmark-primitives?
3292  QStyleOptionSlider tmpSlider = *slider;
3293  tmpSlider.subControls = SC_SliderTickmarks;
3294  QCommonStyle::drawComplexControl(cc, &tmpSlider, p, w);
3295  }
3296 
3297  if ((slider->subControls & SC_SliderGroove) && groove.isValid())
3298  {
3299  drawKStylePrimitive(WT_Slider, hor ? Slider::GrooveHor : Slider::GrooveVert, opt, groove, pal, flags, p, w);
3300  }
3301 
3302  if (slider->subControls & SC_SliderHandle)
3303  {
3304  drawKStylePrimitive(WT_Slider, hor ? Slider::HandleHor : Slider::HandleVert, opt, handle, pal, flags, p, w);
3305 
3306  if (slider->state & State_HasFocus) {
3307  QRect focus = subElementRect(SE_SliderFocusRect, slider, w);
3308  drawKStylePrimitive(WT_Slider, Generic::FocusIndicator, opt, focus, pal, flags, p, w, 0);
3309  }
3310  }
3311  } //option OK
3312  return;
3313  } //CC_Slider
3314 
3315  case CC_SpinBox:
3316  {
3317  if (const QStyleOptionSpinBox *sb = qstyleoption_cast<const QStyleOptionSpinBox *>(opt) )
3318  {
3319  bool activeSbUp = sb->activeSubControls&SC_SpinBoxUp && (flags & State_Sunken);
3320  bool activeSbDown = sb->activeSubControls&SC_SpinBoxDown && (flags & State_Sunken);
3321 
3322  if (sb->subControls & SC_SpinBoxFrame)
3323  {
3324  drawKStylePrimitive(WT_SpinBox, Generic::Frame, opt, r, pal, flags, p, w);
3325  }
3326 
3327  if (sb->subControls & SC_SpinBoxEditField)
3328  {
3329  QRect editField = subControlRect(CC_SpinBox, opt, SC_SpinBoxEditField, w);
3330  drawKStylePrimitive(WT_SpinBox, SpinBox::EditField, opt, editField, pal, flags, p, w);
3331  }
3332 
3333  QRect upRect, downRect;
3334  if (sb->subControls & (SC_SpinBoxUp | SC_SpinBoxDown))
3335  {
3336  upRect = subControlRect(CC_SpinBox, opt, SC_SpinBoxUp, w);
3337  downRect = subControlRect(CC_SpinBox, opt, SC_SpinBoxDown, w);
3338  QRect buttonAreaRect = upRect | downRect;
3339  drawKStylePrimitive(WT_SpinBox, SpinBox::ButtonArea, opt, buttonAreaRect, pal, flags, p, w);
3340  }
3341 
3342  if (sb->subControls & SC_SpinBoxUp)
3343  {
3344  // adjust the sunken state flag...
3345  State upFlags = flags;
3346  if (activeSbUp)
3347  upFlags |= State_Sunken;
3348  else
3349  upFlags &= ~State_Sunken;
3350 
3351  drawKStylePrimitive(WT_SpinBox, SpinBox::UpButton, opt, upRect, pal, upFlags, p, w);
3352 
3353  // draw symbol...
3354  int primitive;
3355  if (sb->buttonSymbols == QAbstractSpinBox::PlusMinus)
3356  primitive = SpinBox::PlusSymbol;
3357  else
3358  primitive = Generic::ArrowUp;
3359  drawKStylePrimitive(WT_SpinBox, primitive, opt, upRect, pal, upFlags, p, w);
3360  }
3361 
3362  if (sb->subControls & SC_SpinBoxDown)
3363  {
3364  // adjust the sunken state flag...
3365  State downFlags = flags;
3366  if (activeSbDown)
3367  downFlags |= State_Sunken;
3368  else
3369  downFlags &= ~State_Sunken;
3370 
3371  drawKStylePrimitive(WT_SpinBox, SpinBox::DownButton, opt, downRect, pal, downFlags, p, w);
3372 
3373  // draw symbol...
3374  int primitive;
3375  if (sb->buttonSymbols == QAbstractSpinBox::PlusMinus)
3376  primitive = SpinBox::MinusSymbol;
3377  else
3378  primitive = Generic::ArrowDown;
3379  drawKStylePrimitive(WT_SpinBox, primitive, opt, downRect, pal, downFlags, p, w);
3380  }
3381 
3382  return;
3383  } //option OK
3384  } //CC_SpinBox
3385 
3386  case CC_ComboBox:
3387  {
3388  if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt) )
3389  {
3390  if (cb->subControls & SC_ComboBoxFrame)
3391  {
3392  drawKStylePrimitive(WT_ComboBox, Generic::Frame, opt, r, pal, flags, p, w);
3393 
3394  // focus indicator
3395  if (cb->state & State_HasFocus) {
3396  QRect editField = subControlRect(CC_ComboBox, opt, SC_ComboBoxEditField, w);
3397  QRect focusRect = insideMargin(editField, WT_ComboBox, ComboBox::FocusMargin, opt, w);
3398  drawKStylePrimitive(WT_ComboBox, Generic::FocusIndicator, opt, focusRect, pal, flags, p, w, 0);
3399  }
3400  }
3401 
3402  if (cb->subControls & SC_ComboBoxEditField)
3403  {
3404  QRect editField = subControlRect(CC_ComboBox, opt, SC_ComboBoxEditField, w);
3405  drawKStylePrimitive(WT_ComboBox, ComboBox::EditField, opt, editField, pal, flags, p, w);
3406  }
3407 
3408  if (cb->subControls & SC_ComboBoxArrow)
3409  {
3410  QRect buttonRect = subControlRect(CC_ComboBox, opt, SC_ComboBoxArrow, w);
3411  drawKStylePrimitive(WT_ComboBox, ComboBox::Button, opt, buttonRect, pal, flags, p, w);
3412 
3413  // draw symbol...
3414  drawKStylePrimitive(WT_ComboBox, Generic::ArrowDown, opt, buttonRect, pal, flags, p, w);
3415  }
3416 
3417  return;
3418  } //option OK
3419  break;
3420  } //CC_Combo
3421 
3422  case CC_ToolButton:
3423  {
3424  if (const QStyleOptionToolButton *tool = qstyleoption_cast<const QStyleOptionToolButton *>(opt)) {
3425  QRect buttonRect = subControlRect(cc, tool, SC_ToolButton, w);
3426  QRect menuRect = subControlRect(cc, tool, SC_ToolButtonMenu, w);
3427 
3428  // State_AutoRaise: only draw button when State_MouseOver
3429  State bflags = tool->state;
3430  if (bflags & State_AutoRaise) {
3431  if (!(bflags & State_MouseOver)) {
3432  bflags &= ~State_Raised;
3433  }
3434  }
3435  State mflags = bflags;
3436 
3437  QStyleOption tOpt(0);
3438  tOpt.palette = pal;
3439 
3440  if (tool->subControls & SC_ToolButton) {
3441  if (bflags & (State_Sunken | State_On | State_Raised)) {
3442  tOpt.rect = buttonRect;
3443  tOpt.state = bflags;
3444  drawPrimitive(PE_PanelButtonTool, &tOpt, p, w);
3445  }
3446  }
3447 
3448  if (tool->subControls & SC_ToolButtonMenu) {
3449  tOpt.rect = menuRect;
3450  tOpt.state = mflags;
3451  drawPrimitive(PE_IndicatorButtonDropDown, &tOpt, p, w);
3452  } else if (tool->features & QStyleOptionToolButton::HasMenu) {
3453  // This is requesting KDE3-style arrow indicator, per Qt 4.4 behavior. Qt 4.3 prefers to hide
3454  // the fact of the menu's existence. Whee! Since we don't know how to paint this right,
3455  // though, we have to have some metrics set for it to look nice.
3456  int size = widgetLayoutProp(WT_ToolButton, ToolButton::InlineMenuIndicatorSize, opt, w);
3457 
3458  if (size) {
3459  int xOff = widgetLayoutProp(WT_ToolButton, ToolButton::InlineMenuIndicatorXOff, opt, w);
3460  int yOff = widgetLayoutProp(WT_ToolButton, ToolButton::InlineMenuIndicatorYOff, opt, w);
3461 
3462  QRect r = QRect(buttonRect.right() + xOff, buttonRect.bottom() + yOff, size, size);
3463  tOpt.rect = r;
3464  tOpt.state = bflags;
3465  drawPrimitive(PE_IndicatorButtonDropDown, &tOpt, p, w);
3466  }
3467  }
3468 
3469  if (flags & State_HasFocus) {
3470  QRect focusRect = insideMargin(r, WT_ToolButton, ToolButton::FocusMargin, opt, w);
3471  tOpt.rect = focusRect;
3472  tOpt.state = bflags;
3473  drawKStylePrimitive(WT_ToolButton, Generic::FocusIndicator, &tOpt, focusRect, pal, bflags, p, w);
3474  }
3475 
3476  // CE_ToolButtonLabel expects a readjusted rect, for the button area proper
3477  QStyleOptionToolButton labelOpt = *tool;
3478  labelOpt.rect = buttonRect;
3479  drawControl(CE_ToolButtonLabel, &labelOpt, p, w);
3480 
3481  return;
3482  }
3483  break;
3484  } //CC_ToolButton
3485 
3486  case CC_TitleBar:
3487  {
3488  const QStyleOptionTitleBar *tb =
3489  qstyleoption_cast<const QStyleOptionTitleBar *>(opt);
3490  if (!tb)
3491  break;
3492 
3493  // title bar
3494  drawKStylePrimitive(WT_Window, Window::TitlePanel, opt, r, pal, flags, p, w);
3495 
3496  // TODO: different color depending on Active/inactive state
3497  // draw title text
3498  QRect textRect = subControlRect(CC_TitleBar, tb, SC_TitleBarLabel, w);
3499  TextOption textOpt(tb->text);
3500  textOpt.color = widgetLayoutProp(WT_Window, Window::TitleTextColor, opt, w);
3501  drawKStylePrimitive(WT_Window, Generic::Text, opt, textRect,
3502  pal, flags, p, w, &textOpt);
3503 
3504  TitleButtonOption buttonKOpt;
3505  buttonKOpt.icon = tb->icon;
3506 
3507  if ((tb->subControls & SC_TitleBarSysMenu) &&
3508  (tb->titleBarFlags & Qt::WindowSystemMenuHint))
3509  {
3510  buttonKOpt.active = (tb->activeSubControls & SC_TitleBarSysMenu)
3511  && (tb->state & State_Sunken);
3512  QRect br = subControlRect(CC_TitleBar, tb, SC_TitleBarSysMenu, w);
3513  drawKStylePrimitive(WT_Window, Window::ButtonMenu, opt, br, pal, flags, p, w,
3514  &buttonKOpt);
3515  }
3516 
3517  if ((tb->subControls & SC_TitleBarMinButton) &&
3518  (tb->titleBarFlags & Qt::WindowMinimizeButtonHint))
3519  {
3520  buttonKOpt.active = (tb->activeSubControls & SC_TitleBarMinButton)
3521  && (tb->state & State_Sunken);
3522  QRect br = subControlRect(CC_TitleBar, tb, SC_TitleBarMinButton, w);
3523  drawKStylePrimitive(WT_Window, Window::ButtonMin, opt, br, pal, flags, p, w,
3524  &buttonKOpt);
3525  }
3526 
3527  if ((tb->subControls & SC_TitleBarMaxButton) &&
3528  (tb->titleBarFlags & Qt::WindowMaximizeButtonHint))
3529  {
3530  buttonKOpt.active = (tb->activeSubControls & SC_TitleBarMaxButton)
3531  && (tb->state & State_Sunken);
3532  QRect br = subControlRect(CC_TitleBar, tb, SC_TitleBarMaxButton, w);
3533  drawKStylePrimitive(WT_Window, Window::ButtonMax, opt, br, pal, flags, p, w,
3534  &buttonKOpt);
3535  }
3536 
3537  if ((tb->subControls & SC_TitleBarCloseButton) &&
3538  (tb->titleBarFlags & Qt::WindowSystemMenuHint))
3539  {
3540 // bool hover = (tb->activeSubControls & SC_TitleBarCloseButton)
3541 // && (tb->state & State_MouseOver);
3542  buttonKOpt.active = (tb->activeSubControls & SC_TitleBarCloseButton)
3543  && (tb->state & State_Sunken);
3544  QRect br = subControlRect(CC_TitleBar, tb, SC_TitleBarCloseButton, w);
3545  drawKStylePrimitive(WT_Window, Window::ButtonClose, opt, br, pal, flags, p, w,
3546  &buttonKOpt);
3547  }
3548 
3549  if ((tb->subControls & SC_TitleBarNormalButton) &&
3550  (((tb->titleBarFlags & Qt::WindowMinimizeButtonHint) &&
3551  (tb->titleBarState & Qt::WindowMinimized)) ||
3552  ((tb->titleBarFlags & Qt::WindowMaximizeButtonHint) &&
3553  (tb->titleBarState & Qt::WindowMaximized))))
3554  {
3555  buttonKOpt.active = (tb->activeSubControls & SC_TitleBarNormalButton)
3556  && (tb->state & State_Sunken);
3557  QRect br = subControlRect(CC_TitleBar, tb, SC_TitleBarNormalButton, w);
3558  drawKStylePrimitive(WT_Window, Window::ButtonRestore, opt, br, pal, flags, p, w,
3559  &buttonKOpt);
3560  }
3561 
3562  if (tb->subControls & SC_TitleBarShadeButton)
3563  {
3564  buttonKOpt.active = (tb->activeSubControls & SC_TitleBarShadeButton)
3565  && (tb->state & State_Sunken);
3566  QRect br = subControlRect(CC_TitleBar, tb, SC_TitleBarShadeButton, w);
3567  drawKStylePrimitive(WT_Window, Window::ButtonShade, opt, br, pal, flags, p, w,
3568  &buttonKOpt);
3569  }
3570 
3571  if (tb->subControls & SC_TitleBarUnshadeButton)
3572  {
3573  buttonKOpt.active = (tb->activeSubControls & SC_TitleBarUnshadeButton)
3574  && (tb->state & State_Sunken);
3575  QRect br = subControlRect(CC_TitleBar, tb, SC_TitleBarUnshadeButton, w);
3576  drawKStylePrimitive(WT_Window, Window::ButtonUnshade, opt, br, pal, flags, p, w,
3577  &buttonKOpt);
3578  }
3579 
3580  if ((tb->subControls & SC_TitleBarContextHelpButton)
3581  && (tb->titleBarFlags & Qt::WindowContextHelpButtonHint))
3582  {
3583  buttonKOpt.active = (tb->activeSubControls & SC_TitleBarContextHelpButton)
3584  && (tb->state & State_Sunken);
3585  QRect br = subControlRect(CC_TitleBar, tb, SC_TitleBarContextHelpButton, w);
3586  drawKStylePrimitive(WT_Window, Window::ButtonHelp, opt, br, pal, flags, p, w,
3587  &buttonKOpt);
3588  }
3589 
3590  return;
3591  } // CC_TitleBar
3592 
3593  default:
3594  break;
3595  } //switch
3596 
3597  QCommonStyle::drawComplexControl(cc, opt, p, w);
3598 }
3599 
3600 
3601 QRect KStyle::internalSubControlRect (ComplexControl control, const QStyleOptionComplex* option,
3602  SubControl subControl, const QWidget* widget) const
3603 {
3604  QRect r = option->rect;
3605 
3606  if (control == CC_ScrollBar)
3607  {
3608  switch (subControl)
3609  {
3610  //The "top" arrow
3611  case SC_ScrollBarSubLine:
3612  {
3613  int majorSize;
3614  if (widgetLayoutProp(WT_ScrollBar, ScrollBar::DoubleTopButton, option, widget))
3615  majorSize = widgetLayoutProp(WT_ScrollBar, ScrollBar::DoubleButtonHeight, option, widget);
3616  else
3617  majorSize = widgetLayoutProp(WT_ScrollBar, ScrollBar::SingleButtonHeight, option, widget);
3618 
3619  if (option->state & State_Horizontal)
3620  return handleRTL(option, QRect(r.x(), r.y(), majorSize, r.height()));
3621  else
3622  return handleRTL(option, QRect(r.x(), r.y(), r.width(), majorSize));
3623 
3624  }
3625 
3626  //The "bottom" arrow
3627  case SC_ScrollBarAddLine:
3628  {
3629  int majorSize;
3630  if (widgetLayoutProp(WT_ScrollBar, ScrollBar::DoubleBotButton, option, widget))
3631  majorSize = widgetLayoutProp(WT_ScrollBar, ScrollBar::DoubleButtonHeight, option, widget);
3632  else
3633  majorSize = widgetLayoutProp(WT_ScrollBar, ScrollBar::SingleButtonHeight, option, widget);
3634 
3635  if (option->state & State_Horizontal)
3636  return handleRTL(option, QRect(r.right() - majorSize + 1, r.y(), majorSize, r.height()));
3637  else
3638  return handleRTL(option, QRect(r.x(), r.bottom() - majorSize + 1, r.width(), majorSize));
3639  }
3640 
3641  default:
3642  break;
3643  }
3644  }
3645 
3646  return QRect();
3647 }
3648 
3649 
3650 QRect KStyle::subControlRect(ComplexControl control, const QStyleOptionComplex* option,
3651  SubControl subControl, const QWidget* widget) const
3652 {
3653  QRect r = option->rect;
3654 
3655  switch (control)
3656  {
3657  case CC_ScrollBar:
3658  {
3659  switch (subControl)
3660  {
3661  //For both arrows, we return -everything-,
3662  //to get stuff to repaint right. See internalSubControlRect
3663  //for the real thing
3664  case SC_ScrollBarSubLine:
3665  case SC_ScrollBarAddLine:
3666  return r;
3667 
3668  //The main groove area. This is used to compute the others...
3669  case SC_ScrollBarGroove:
3670  {
3671  QRect top = handleRTL(option, internalSubControlRect(control, option, SC_ScrollBarSubLine, widget));
3672  QRect bot = handleRTL(option, internalSubControlRect(control, option, SC_ScrollBarAddLine, widget));
3673 
3674  QPoint topLeftCorner, botRightCorner;
3675  if (option->state & State_Horizontal)
3676  {
3677  topLeftCorner = QPoint(top.right() + 1, top.top());
3678  botRightCorner = QPoint(bot.left() - 1, top.bottom());
3679  }
3680  else
3681  {
3682  topLeftCorner = QPoint(top.left(), top.bottom() + 1);
3683  botRightCorner = QPoint(top.right(), bot.top() - 1);
3684  }
3685 
3686  return handleRTL(option, QRect(topLeftCorner, botRightCorner));
3687  }
3688 
3689  case SC_ScrollBarFirst:
3690  case SC_ScrollBarLast:
3691  return QRect();
3692 
3693  case SC_ScrollBarSlider:
3694  {
3695  const QStyleOptionSlider* slOpt = ::qstyleoption_cast<const QStyleOptionSlider*>(option);
3696 
3697  //We do handleRTL here to unreflect things if need be
3698  QRect groove = handleRTL(option, subControlRect(control, option, SC_ScrollBarGroove, widget));
3699  Q_ASSERT (slOpt);
3700 
3701  if (slOpt->minimum == slOpt->maximum)
3702  return groove;
3703 
3704  //Figure out how much room we have..
3705  int space;
3706  if (option->state & State_Horizontal)
3707  space = groove.width();
3708  else
3709  space = groove.height();
3710 
3711  //Calculate the portion of this space that the slider should take up.
3712  int sliderSize = int(space * float(slOpt->pageStep) /
3713  (slOpt->maximum - slOpt->minimum + slOpt->pageStep));
3714 
3715  if (sliderSize < widgetLayoutProp(WT_ScrollBar, ScrollBar::MinimumSliderHeight, option, widget))
3716  sliderSize = widgetLayoutProp(WT_ScrollBar, ScrollBar::MinimumSliderHeight, option, widget);
3717 
3718  if (sliderSize > space)
3719  sliderSize = space;
3720 
3721  //What do we have remaining?
3722  space = space - sliderSize;
3723 
3724  //uhm, yeah, nothing much
3725  if (space <= 0)
3726  return groove;
3727 
3728  int pos = qRound(float(slOpt->sliderPosition - slOpt->minimum)/
3729  (slOpt->maximum - slOpt->minimum)*space);
3730  if (option->state & State_Horizontal)
3731  return handleRTL(option, QRect(groove.x() + pos, groove.y(), sliderSize, groove.height()));
3732  else
3733  return handleRTL(option, QRect(groove.x(), groove.y() + pos, groove.width(), sliderSize));
3734  }
3735 
3736  case SC_ScrollBarSubPage:
3737  {
3738  //We do handleRTL here to unreflect things if need be
3739  QRect slider = handleRTL(option, subControlRect(control, option, SC_ScrollBarSlider, widget));
3740  QRect groove = handleRTL(option, subControlRect(control, option, SC_ScrollBarGroove, widget));
3741 
3742  //We're above the slider in the groove.
3743  if (option->state & State_Horizontal)
3744  return handleRTL(option, QRect(groove.x(), groove.y(), slider.x() - groove.x(), groove.height()));
3745  else
3746  return handleRTL(option, QRect(groove.x(), groove.y(), groove.width(), slider.y() - groove.y()));
3747  }
3748 
3749  case SC_ScrollBarAddPage:
3750  {
3751  //We do handleRTL here to unreflect things if need be
3752  QRect slider = handleRTL(option, subControlRect(control, option, SC_ScrollBarSlider, widget));
3753  QRect groove = handleRTL(option, subControlRect(control, option, SC_ScrollBarGroove, widget));
3754 
3755  //We're below the slider in the groove.
3756  if (option->state & State_Horizontal)
3757  return handleRTL(option,
3758  QRect(slider.right() + 1, groove.y(), groove.right() - slider.right(), groove.height()));
3759  else
3760  return handleRTL(option,
3761  QRect(groove.x(), slider.bottom() + 1, groove.width(), groove.bottom() - slider.bottom()));
3762  }
3763 
3764  default:
3765  break;
3766  }
3767  } //CC_ScrollBar
3768 
3769  case CC_SpinBox:
3770  {
3771  if (const QStyleOptionSpinBox *sb = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
3772 
3773  int fw = widgetLayoutProp(WT_SpinBox, SpinBox::FrameWidth, option, widget);
3774  int bw = widgetLayoutProp(WT_SpinBox, SpinBox::ButtonWidth, option, widget);
3775  int bm = widgetLayoutProp(WT_SpinBox, SpinBox::ButtonMargin, option, widget);
3776  int bml = bm + widgetLayoutProp(WT_SpinBox, SpinBox::ButtonMargin + Left, option, widget);
3777  int bmr = bm + widgetLayoutProp(WT_SpinBox, SpinBox::ButtonMargin + Right, option, widget);
3778  int bmt = bm + widgetLayoutProp(WT_SpinBox, SpinBox::ButtonMargin + Top, option, widget);
3779  int bmb = bm + widgetLayoutProp(WT_SpinBox, SpinBox::ButtonMargin + Bot, option, widget);
3780  int bs = widgetLayoutProp(WT_SpinBox, SpinBox::ButtonSpacing, option, widget);
3781  bool symmButtons = widgetLayoutProp(WT_SpinBox, SpinBox::SymmetricButtons, option, widget);
3782  bool supportFrameless = widgetLayoutProp(WT_SpinBox, SpinBox::SupportFrameless, option, widget);
3783 
3784  // SpinBox without a frame, set the corresponding layout values to 0, reduce button width.
3785  if (supportFrameless && !sb->frame)
3786  {
3787  bw = bw - bmr; // reduce button with as the right button margin will be ignored.
3788  fw = 0;
3789  bmt = bmb = bmr = 0;
3790  }
3791 
3792  const int buttonsWidth = bw-bml-bmr;
3793  const int buttonsLeft = r.right()-bw+bml+1;
3794 
3795  // compute the height of each button...
3796  int availableButtonHeight = r.height()-bmt-bmb - bs;
3797  if (symmButtons)
3798  {
3799  // make sure the availableButtonHeight is even by reducing the
3800  // button spacing by 1 if necessary. Results in both buttons
3801  // of the same height...
3802  if (availableButtonHeight%2 != 0)
3803  {
3804  --bs;
3805 
3806  // recalculate...
3807  availableButtonHeight = r.height()-bmt-bmb - bs;
3808  }
3809  }
3810  int heightUp = availableButtonHeight / 2;
3811  int heightDown = availableButtonHeight - heightUp;
3812 
3813 
3814  switch (subControl) {
3815  case SC_SpinBoxUp:
3816  return handleRTL(option,
3817  QRect(buttonsLeft, r.top()+bmt, buttonsWidth, heightUp) );
3818  case SC_SpinBoxDown:
3819  return handleRTL(option,
3820  QRect(buttonsLeft, r.bottom()-bmb-heightDown+1, buttonsWidth, heightDown) );
3821  case SC_SpinBoxEditField:
3822  {
3823  QRect labelRect(r.left()+fw, r.top()+fw, r.width()-fw-bw, r.height()-2*fw);
3824  labelRect = insideMargin(labelRect, WT_SpinBox, SpinBox::ContentsMargin, option, widget);
3825  return handleRTL(option, labelRect );
3826  }
3827  case SC_SpinBoxFrame:
3828  return (sb->frame || !supportFrameless) ? r : QRect();
3829  default:
3830  break;
3831  }
3832  } //option ok
3833  } //CC_SpinBox
3834 
3835  case CC_ComboBox:
3836  {
3837  if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
3838 
3839  int fw = widgetLayoutProp(WT_ComboBox, ComboBox::FrameWidth, option, widget);
3840  int bw = widgetLayoutProp(WT_ComboBox, ComboBox::ButtonWidth, option, widget);
3841  int bm = widgetLayoutProp(WT_ComboBox, ComboBox::ButtonMargin, option, widget);
3842  int bml = bm + widgetLayoutProp(WT_ComboBox, ComboBox::ButtonMargin + Left, option, widget);
3843  int bmr = bm + widgetLayoutProp(WT_ComboBox, ComboBox::ButtonMargin + Right, option, widget);
3844  int bmt = bm + widgetLayoutProp(WT_ComboBox, ComboBox::ButtonMargin + Top, option, widget);
3845  int bmb = bm + widgetLayoutProp(WT_ComboBox, ComboBox::ButtonMargin + Bot, option, widget);
3846  bool supportFrameless = widgetLayoutProp(WT_ComboBox, ComboBox::SupportFrameless, option, widget);
3847 
3848  // ComboBox without a frame, set the corresponding layout values to 0, reduce button width.
3849  if (supportFrameless && !cb->frame)
3850  {
3851  bw = bw - bmr; // reduce button with as the right button margin will be ignored.
3852  fw = 0;
3853  bmt = bmb = bmr = 0;
3854  }
3855 
3856  switch (subControl) {
3857  case SC_ComboBoxFrame:
3858  return (cb->frame || !supportFrameless) ? r : QRect();
3859  case SC_ComboBoxArrow:
3860  return handleRTL(option,
3861  QRect(r.right()-bw+bml+1, r.top()+bmt, bw-bml-bmr, r.height()-bmt-bmb) );
3862  case SC_ComboBoxEditField:
3863  {
3864  QRect labelRect(r.left()+fw, r.top()+fw, r.width()-fw-bw, r.height()-2*fw);
3865  labelRect = insideMargin(labelRect, WT_ComboBox, ComboBox::ContentsMargin, option, widget);
3866  return handleRTL(option, labelRect );
3867  }
3868  case SC_ComboBoxListBoxPopup:
3869  // TODO: need to add layoutProps to control the popup rect?
3870 // return cb->popupRect;
3871  // popupRect seems to be empty, so use QStyleOption::rect as Qt's styles do
3872  return r;
3873  default:
3874  break;
3875  }
3876  } //option ok
3877  } //CC_ComboBox
3878 
3879  case CC_TitleBar:
3880  {
3881  const QStyleOptionTitleBar *tbOpt =
3882  qstyleoption_cast<const QStyleOptionTitleBar *>(option);
3883  if (!tbOpt)
3884  break;
3885 
3886  QRect ret = insideMargin(r, WT_Window, Window::TitleMargin, option, widget);
3887 
3888  const int btnHeight = ret.height();
3889  const int btnWidth = widgetLayoutProp(WT_Window, Window::ButtonWidth, option, widget);
3890  const int btnSpace = widgetLayoutProp(WT_Window, Window::ButtonSpace, option, widget);
3891  const int titleSpace = widgetLayoutProp(WT_Window, Window::ButtonToTextSpace, option, widget);
3892 
3893  bool isMinimized = tbOpt->titleBarState & Qt::WindowMinimized;
3894  bool isMaximized = tbOpt->titleBarState & Qt::WindowMaximized;
3895 
3896  // button layout: menu -title- help,shade,min,max,close
3897 
3898  bool menuCloseBtn = tbOpt->titleBarFlags & Qt::WindowSystemMenuHint;
3899  bool minBtn = !isMinimized &&
3900  (tbOpt->titleBarFlags & Qt::WindowMinimizeButtonHint);
3901  bool maxBtn = !isMaximized &&
3902  (tbOpt->titleBarFlags & Qt::WindowMaximizeButtonHint);
3903  bool restoreBtn =
3904  (isMinimized && (tbOpt->titleBarFlags & Qt::WindowMinimizeButtonHint)) ||
3905  (isMaximized && (tbOpt->titleBarFlags & Qt::WindowMaximizeButtonHint));
3906  bool shadeBtn = tbOpt->titleBarFlags & Qt::WindowShadeButtonHint;
3907  bool helpBtn = tbOpt->titleBarFlags & Qt::WindowContextHelpButtonHint;
3908 
3909 
3910  int btnOffsetCount = 0; // for button rects; count the position in the button bar
3911 
3912  switch (subControl) {
3913  case SC_TitleBarLabel:
3914  {
3915  if (tbOpt->titleBarFlags & Qt::WindowTitleHint)
3916  {
3917  int cLeft = 0; // count buttons in the button bar
3918  int cRight = 0;
3919 
3920  if (menuCloseBtn) {
3921  // menu and close button
3922  ++cLeft;
3923  ++cRight;
3924  }
3925  if (minBtn) ++cRight;
3926  if (restoreBtn) ++cRight;
3927  if (maxBtn) ++cRight;
3928  if (shadeBtn) ++cRight;
3929  if (helpBtn) ++cRight;
3930 
3931  ret.adjust( cLeft*btnWidth+(cLeft-1)*btnSpace+titleSpace, 0,
3932  -(titleSpace+cRight*btnWidth+(cRight-1)*btnSpace), 0 );
3933  }
3934  break;
3935  }
3936 
3937  case SC_TitleBarSysMenu:
3938  {
3939  if (tbOpt->titleBarFlags & Qt::WindowSystemMenuHint) {
3940  ret.setRect(ret.left(), ret.top(), btnWidth, btnHeight);
3941  }
3942  break;
3943  }
3944 
3945  case SC_TitleBarContextHelpButton:
3946  if (helpBtn)
3947  ++btnOffsetCount;
3948  case SC_TitleBarMinButton:
3949  if (minBtn)
3950  ++btnOffsetCount;
3951  else if (subControl == SC_TitleBarMinButton)
3952  return QRect();
3953  case SC_TitleBarNormalButton:
3954  if (restoreBtn)
3955  ++btnOffsetCount;
3956  else if (subControl == SC_TitleBarNormalButton)
3957  return QRect();
3958  case SC_TitleBarMaxButton:
3959  if (maxBtn)
3960  ++btnOffsetCount;
3961  else if (subControl == SC_TitleBarMaxButton)
3962  return QRect();
3963  case SC_TitleBarShadeButton:
3964  if (!isMinimized && shadeBtn)
3965  ++btnOffsetCount;
3966  else if (subControl == SC_TitleBarShadeButton)
3967  return QRect();
3968  case SC_TitleBarUnshadeButton:
3969  if (isMinimized && shadeBtn)
3970  ++btnOffsetCount;
3971  else if (subControl == SC_TitleBarUnshadeButton)
3972  return QRect();
3973  case SC_TitleBarCloseButton:
3974  {
3975  if (menuCloseBtn)
3976  ++btnOffsetCount;
3977  else if (subControl == SC_TitleBarCloseButton)
3978  return QRect();
3979  // set the rect for all buttons that fell through:
3980  ret.setRect(ret.right()-btnOffsetCount*btnWidth-(btnOffsetCount-1)*btnSpace,
3981  ret.top(), btnWidth, btnHeight);
3982  break;
3983  }
3984 
3985  default:
3986  return QRect();
3987  }
3988 
3989  return visualRect(tbOpt->direction, tbOpt->rect, ret);
3990 
3991  } // CC_TitleBar
3992 
3993  default:
3994  break;
3995  }
3996 
3997  return QCommonStyle::subControlRect(control, option, subControl, widget);
3998 }
3999 
4000 /*
4001  Checks whether the point is before the bound rect for
4002  bound of given orientation
4003 */
4004 static bool preceeds(const QPoint &pt, const QRect &bound,
4005  const QStyleOption* opt)
4006 {
4007  if (opt->state & QStyle::State_Horizontal)
4008  {
4009  //What's earlier depends on RTL or not
4010  if (opt->direction == Qt::LeftToRight)
4011  return pt.x() < bound.right();
4012  else
4013  return pt.x() > bound.x();
4014  }
4015  else
4016  {
4017  return pt.y() < bound.y();
4018  }
4019 }
4020 
4021 static QStyle::SubControl buttonPortion(const QRect &totalRect,
4022  const QPoint &pt,
4023  const QStyleOption* opt)
4024 {
4025  if (opt->state & QStyle::State_Horizontal)
4026  {
4027  //What's earlier depends on RTL or not
4028  if (opt->direction == Qt::LeftToRight)
4029  return pt.x() < totalRect.center().x() ? QStyle::SC_ScrollBarSubLine : QStyle::SC_ScrollBarAddLine;
4030  else
4031  return pt.x() > totalRect.center().x() ? QStyle::SC_ScrollBarSubLine : QStyle::SC_ScrollBarAddLine;
4032  }
4033  else
4034  {
4035  return pt.y() < totalRect.center().y() ? QStyle::SC_ScrollBarSubLine : QStyle::SC_ScrollBarAddLine;
4036  }
4037 }
4038 
4039 QStyle::SubControl KStyle::hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex* opt,
4040  const QPoint& pt, const QWidget* w) const
4041 {
4042  if (cc == CC_ScrollBar)
4043  {
4044  //First, check whether we're inside the groove or not...
4045  QRect groove = subControlRect(CC_ScrollBar, opt, SC_ScrollBarGroove, w);
4046 
4047  if (groove.contains(pt))
4048  {
4049  //Must be either page up/page down, or just click on the slider.
4050  //Grab the slider to compare
4051  QRect slider = subControlRect(CC_ScrollBar, opt, SC_ScrollBarSlider, w);
4052 
4053  if (slider.contains(pt))
4054  return SC_ScrollBarSlider;
4055  else if (preceeds(pt, slider, opt))
4056  return SC_ScrollBarSubPage;
4057  else
4058  return SC_ScrollBarAddPage;
4059  }
4060  else
4061  {
4062  //This is one of the up/down buttons. First, decide which one it is.
4063  if (preceeds(pt, groove, opt))
4064  {
4065  //"Upper" button
4066  if (widgetLayoutProp(WT_ScrollBar, ScrollBar::DoubleTopButton, 0, w))
4067  {
4068  QRect buttonRect = internalSubControlRect(CC_ScrollBar, opt, SC_ScrollBarSubLine, w);
4069  return buttonPortion(buttonRect, pt, opt);
4070  }
4071  else
4072  return SC_ScrollBarSubLine; //Easy one!
4073  }
4074  else
4075  {
4076  //"Bottom" button
4077  if (widgetLayoutProp(WT_ScrollBar, ScrollBar::DoubleBotButton, 0, w))
4078  {
4079  QRect buttonRect = internalSubControlRect(CC_ScrollBar, opt, SC_ScrollBarAddLine, w);
4080  return buttonPortion(buttonRect, pt, opt);
4081  }
4082  else
4083  return SC_ScrollBarAddLine; //Easy one!
4084  }
4085  }
4086  }
4087 
4088  return QCommonStyle::hitTestComplexControl(cc, opt, pt, w);
4089 }
4090 
4091 
4092 QSize KStyle::sizeFromContents(ContentsType type, const QStyleOption* option, const QSize& contentsSize, const QWidget* widget) const
4093 {
4094  switch (type)
4095  {
4096  case CT_PushButton:
4097  {
4098  const QStyleOptionButton* bOpt = qstyleoption_cast<const QStyleOptionButton*>(option);
4099  if (!bOpt) return contentsSize;
4100 
4101  QSize size = contentsSize;
4102 
4103  if ((bOpt->features & QStyleOptionButton::DefaultButton) || (bOpt->features & QStyleOptionButton::AutoDefaultButton))
4104  size = expandDim(size, WT_PushButton, PushButton::DefaultIndicatorMargin, option, widget);
4105 
4106  //### TODO: Handle minimum size limits, extra spacing as in current styles ??
4107  size = expandDim(size, WT_PushButton, PushButton::ContentsMargin, option, widget);
4108 
4109  if (bOpt->features & QStyleOptionButton::HasMenu) {
4110  size.setWidth(size.width() + widgetLayoutProp(WT_PushButton, PushButton::TextToIconSpace, option, widget));
4111  }
4112 
4113  if (!bOpt->text.isEmpty() && !bOpt->icon.isNull()) {
4114  // Incorporate the spacing between the icon and text. Qt sticks 4 there,
4115  // but we use PushButton::TextToIconSpace.
4116  size.setWidth(size.width() - 4 + widgetLayoutProp(WT_PushButton, PushButton::TextToIconSpace, option, widget));
4117  }
4118  return size;
4119  }
4120 
4121  case CT_ToolButton:
4122  {
4123  // We want to avoid super-skiny buttons, for things like "up" when icons + text
4124  // For this, we would like to make width >= height.
4125  // However, once we get here, QToolButton may have already put in the menu area
4126  // (PM_MenuButtonIndicator) into the width. So we may have to take it out, fix things
4127  // up, and add it back in. So much for class-independent rendering...
4128  QSize size = contentsSize;
4129  int menuAreaWidth = 0;
4130  if (const QStyleOptionToolButton* tbOpt = qstyleoption_cast<const QStyleOptionToolButton*>(option)) {
4131  if (tbOpt->features & QStyleOptionToolButton::MenuButtonPopup)
4132  menuAreaWidth = pixelMetric(QStyle::PM_MenuButtonIndicator, option, widget);
4133  else if (tbOpt->features & QStyleOptionToolButton::HasMenu)
4134  size.setWidth(size.width() + widgetLayoutProp(WT_ToolButton, ToolButton::InlineMenuIndicatorSize, tbOpt, widget));
4135  }
4136 
4137  size.setWidth(size.width() - menuAreaWidth);
4138  if (size.width() < size.height())
4139  size.setWidth(size.height());
4140  size.setWidth(size.width() + menuAreaWidth);
4141 
4142  return expandDim(size, WT_ToolButton, ToolButton::ContentsMargin, option, widget);
4143  }
4144 
4145  case CT_CheckBox:
4146  {
4147  //Add size for indicator ### handle empty case differently?
4148  int indicator = widgetLayoutProp(WT_CheckBox, CheckBox::Size, option, widget);
4149  int spacer = widgetLayoutProp(WT_CheckBox, CheckBox::BoxTextSpace, option, widget);
4150 
4151  //Make sure we include space for the focus rect margin
4152  QSize size = expandDim(contentsSize, WT_CheckBox, CheckBox::FocusMargin, option, widget);
4153 
4154  //Make sure we can fit the indicator (### an extra margin around that?)
4155  size.setHeight(qMax(size.height(), indicator));
4156 
4157  //Add space for the indicator and the icon
4158  size.setWidth(size.width() + indicator + spacer);
4159 
4160  return size;
4161  }
4162 
4163  case CT_RadioButton:
4164  {
4165  //Add size for indicator
4166  int indicator = widgetLayoutProp(WT_RadioButton, RadioButton::Size, option, widget);
4167  int spacer = widgetLayoutProp(WT_RadioButton, RadioButton::BoxTextSpace, option, widget);
4168 
4169  //Make sure we include space for the focus rect margin
4170  QSize size = expandDim(contentsSize, WT_RadioButton, RadioButton::FocusMargin, option, widget);
4171 
4172  //Make sure we can fit the indicator (### an extra margin around that?)
4173  size.setHeight(qMax(size.height(), indicator));
4174 
4175  //Add space for the indicator and the icon
4176  size.setWidth(size.width() + indicator + spacer);
4177 
4178  return size;
4179  }
4180 
4181  case CT_ProgressBar:
4182  {
4183  QSize size = contentsSize;
4184 
4185  const QStyleOptionProgressBar* pbOpt = ::qstyleoption_cast<const QStyleOptionProgressBar*>(option);
4186  if (useSideText(pbOpt))
4187  {
4188  //Allocate extra room for side text
4189  size.setWidth(size.width() + sideTextWidth(pbOpt));
4190  }
4191 
4192  return size;
4193  }
4194 
4195 
4196  case CT_MenuBar:
4197  {
4198  int extraW = widgetLayoutProp(WT_MenuBar, MenuBar::Margin + Right, option, widget) -
4199  widgetLayoutProp(WT_MenuBar, MenuBar::Margin + Left, option, widget);
4200 
4201  int extraH = widgetLayoutProp(WT_MenuBar, MenuBar::Margin + Bot, option, widget) -
4202  widgetLayoutProp(WT_MenuBar, MenuBar::Margin + Top, option, widget);
4203 
4204  return QSize(contentsSize.width() + extraW, contentsSize.height() + extraH);
4205  }
4206 
4207  case CT_Menu:
4208  {
4209  int extraW = widgetLayoutProp(WT_Menu, Menu::Margin + Right, option, widget) -
4210  widgetLayoutProp(WT_Menu, Menu::Margin + Left, option, widget);
4211 
4212  int extraH = widgetLayoutProp(WT_Menu, Menu::Margin + Bot, option, widget) -
4213  widgetLayoutProp(WT_Menu, Menu::Margin + Top, option, widget);
4214 
4215  return QSize(contentsSize.width() + extraW, contentsSize.height() + extraH);
4216  }
4217 
4218  case CT_MenuItem:
4219  {
4220  const QStyleOptionMenuItem* miOpt = ::qstyleoption_cast<const QStyleOptionMenuItem*>(option);
4221  if (!miOpt) return contentsSize; //Someone is asking for trouble..
4222 
4223  //First, we calculate the intrinsic size of the item..
4224  QSize insideSize;
4225 
4226  switch (miOpt->menuItemType)
4227  {
4228  case QStyleOptionMenuItem::Normal:
4229  case QStyleOptionMenuItem::DefaultItem: //huh?
4230  case QStyleOptionMenuItem::SubMenu:
4231  {
4232  int iconColW = miOpt->maxIconWidth;
4233  iconColW = qMax(iconColW, widgetLayoutProp(WT_MenuItem, MenuItem::IconWidth, option, widget));
4234 
4235  int leftColW = iconColW;
4236  if (miOpt->menuHasCheckableItems &&
4237  widgetLayoutProp(WT_MenuItem, MenuItem::CheckAlongsideIcon, option, widget) )
4238  {
4239  leftColW = widgetLayoutProp(WT_MenuItem, MenuItem::CheckWidth, option, widget) +
4240  widgetLayoutProp(WT_MenuItem, MenuItem::CheckSpace, option, widget) +
4241  iconColW;
4242  }
4243 
4244  leftColW += widgetLayoutProp(WT_MenuItem, MenuItem::IconSpace, option, widget);
4245 
4246  int rightColW = widgetLayoutProp(WT_MenuItem, MenuItem::ArrowSpace, option, widget) +
4247  widgetLayoutProp(WT_MenuItem, MenuItem::ArrowWidth, option, widget);
4248 
4249  QFontMetrics fm(miOpt->font);
4250 
4251  int textW;
4252  int tabPos = miOpt->text.indexOf(QLatin1Char('\t'));
4253  if (tabPos == -1)
4254  {
4255  //No accel..
4256  textW = contentsSize.width();
4257  }
4258  else
4259  {
4260  // The width of the accelerator is not included here since
4261  // Qt will add that on separately after obtaining the
4262  // sizeFromContents() for each menu item in the menu to be shown
4263  // ( see QMenuPrivate::calcActionRects() )
4264  textW = contentsSize.width() +
4265  widgetLayoutProp(WT_MenuItem,MenuItem::AccelSpace,option,widget);
4266  }
4267 
4268  int h = qMax(contentsSize.height(), widgetLayoutProp(WT_MenuItem, MenuItem::MinHeight, option, widget));
4269  insideSize = QSize(leftColW + textW + rightColW, h);
4270  break;
4271  }
4272 
4273  case QStyleOptionMenuItem::Separator:
4274  {
4275  insideSize = QSize(10, widgetLayoutProp(WT_MenuItem, MenuItem::SeparatorHeight, option, widget));
4276  }
4277  break;
4278 
4279 
4280  //Double huh if we get those.
4281  case QStyleOptionMenuItem::Scroller:
4282  case QStyleOptionMenuItem::TearOff:
4283  case QStyleOptionMenuItem::Margin:
4284  case QStyleOptionMenuItem::EmptyArea:
4285  return contentsSize;
4286  }
4287 
4288  //...now apply the outermost margin.
4289  return expandDim(insideSize, WT_MenuItem, MenuItem::Margin, option, widget);
4290  }
4291 
4292  case CT_MenuBarItem:
4293  return expandDim(contentsSize, WT_MenuBarItem, MenuBarItem::Margin, option, widget);
4294 
4295  case CT_TabBarTab:
4296  {
4297  //With our PM_TabBarTabHSpace/VSpace, Qt should give us what we want for
4298  //contentsSize, so we just expand that. Qt also takes care of
4299  //the vertical thing.
4300 
4301  bool rotated = false; // indicates whether the tab is rotated by 90 degrees
4302  if (const QStyleOptionTab *tabOpt = qstyleoption_cast<const QStyleOptionTab*>(option)) {
4303  rotated = isVerticalTab(tabOpt);
4304  }
4305 
4306  return expandDim(contentsSize, WT_TabBar, TabBar::TabContentsMargin, option, widget, rotated);
4307  }
4308 
4309  case CT_TabWidget:
4310  {
4311  const QStyleOptionTabWidgetFrame* tabOpt = qstyleoption_cast<const QStyleOptionTabWidgetFrame*>(option);
4312  if (!tabOpt) break;
4313 
4314  int m = widgetLayoutProp(WT_TabWidget, TabWidget::ContentsMargin, option, widget);
4315  int vert = 2*m +
4316  widgetLayoutProp(WT_TabWidget, TabWidget::ContentsMargin+Top, option, widget) +
4317  widgetLayoutProp(WT_TabWidget, TabWidget::ContentsMargin+Bot, option, widget);
4318  int hor = 2*m +
4319  widgetLayoutProp(WT_TabWidget, TabWidget::ContentsMargin+Left, option, widget) +
4320  widgetLayoutProp(WT_TabWidget, TabWidget::ContentsMargin+Right, option, widget);
4321 
4322  switch (tabOpt->shape) {
4323  case QTabBar::RoundedNorth:
4324  case QTabBar::TriangularNorth:
4325  case QTabBar::RoundedWest:
4326  case QTabBar::TriangularWest:
4327  return contentsSize + QSize(hor, vert);
4328  case QTabBar::RoundedSouth:
4329  case QTabBar::TriangularSouth:
4330  case QTabBar::RoundedEast:
4331  case QTabBar::TriangularEast:
4332  return contentsSize + QSize(vert,hor);
4333  }
4334  }
4335 
4336  case CT_HeaderSection:
4337  {
4338  if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
4339  QSize iconSize = header->icon.isNull() ? QSize(0,0) : QSize(22,22);
4340  QSize textSize = header->fontMetrics.size(0, header->text);
4341  int iconSpacing = widgetLayoutProp(WT_Header, Header::TextToIconSpace, option, widget);
4342  int w = iconSize.width() + iconSpacing + textSize.width();
4343  int h = qMax(iconSize.height(), textSize.height() );
4344 
4345  return expandDim(QSize(w, h), WT_Header, Header::ContentsMargin, option, widget);
4346  }
4347  }
4348 
4349  case CT_ComboBox:
4350  {
4351  // TODO: Figure out what to do with the button margins
4352  QSize size = contentsSize;
4353 
4354  // Add the contents margin
4355  size = expandDim(size, WT_ComboBox, ComboBox::ContentsMargin, option, widget);
4356 
4357  // Add the button width
4358  size.rwidth() += widgetLayoutProp(WT_ComboBox, ComboBox::ButtonWidth, option, widget);
4359 
4360  // Add the frame width
4361  size.rwidth() += widgetLayoutProp(WT_ComboBox, ComboBox::FrameWidth, option, widget) * 2;
4362  size.rheight() += widgetLayoutProp(WT_ComboBox, ComboBox::FrameWidth, option, widget) * 2;
4363 
4364  return size;
4365  }
4366 
4367  default:
4368  break;
4369  }
4370 
4371  return QCommonStyle::sizeFromContents(type, option, contentsSize, widget);
4372 }
4373 
4374 bool KStyle::eventFilter(QObject *obj, QEvent *ev)
4375 {
4376  if (QCommonStyle::eventFilter(obj, ev) )
4377  return true;
4378 
4379  if (QLabel *lbl = qobject_cast<QLabel*>(obj) ) {
4380  QWidget *buddy = lbl->buddy();
4381  if (buddy) {
4382  switch (ev->type() ) {
4383  case QEvent::MouseButtonPress:
4384  {
4385  QMouseEvent *mev = dynamic_cast<QMouseEvent*>(ev);
4386  if (!mev) break;
4387 
4388  if (lbl->rect().contains(mev->pos() ) ) {
4389  clickedLabel = obj;
4390  lbl->repaint();
4391  }
4392  break;
4393  }
4394  case QEvent::MouseButtonRelease:
4395  {
4396  QMouseEvent *mev = dynamic_cast<QMouseEvent*>(ev);
4397  if (!mev) break;
4398 
4399  if (clickedLabel) {
4400  clickedLabel = 0;
4401  lbl->update();
4402  }
4403 
4404  // set focus to the buddy...
4405  if (lbl->rect().contains(mev->pos() ) ) {
4406  buddy->setFocus(Qt::ShortcutFocusReason);
4407  }
4408  break;
4409  }
4410  case QEvent::Paint:
4411  if (obj == clickedLabel && buddy->isEnabled()) {
4412  // paint focus rect
4413  QPainter p(lbl);
4414  QStyleOptionFocusRect foOpts;
4415  QRect foRect(0,0,lbl->width(),lbl->height());
4416  foOpts.palette = lbl->palette();
4417  foOpts.rect = foRect;
4418  drawKStylePrimitive(WT_Generic, Generic::FocusIndicator, &foOpts,
4419  foRect, lbl->palette(), 0, &p, lbl);
4420  }
4421  break;
4422 
4423  default:
4424  break;
4425  }
4426  }
4427  }
4428 
4429  return false;
4430 }
4431 
4432 KStyle::ColorMode::ColorMode(QPalette::ColorRole _role):
4433  mode(PaletteEntryMode),
4434  role(_role)
4435 {}
4436 
4437 KStyle::ColorMode::ColorMode(Mode _mode, QPalette::ColorRole _role):
4438  mode(_mode),
4439  role(_role)
4440 {}
4441 
4442 KStyle::ColorMode::operator int() const
4443 {
4444  return int(role) | int(mode);
4445 }
4446 
4447 KStyle::ColorMode::ColorMode(int encoded)
4448 {
4449  mode = (encoded & BWAutoContrastMode) ? BWAutoContrastMode : PaletteEntryMode;
4450  role = QPalette::ColorRole(encoded & (~BWAutoContrastMode));
4451 }
4452 
4453 QColor KStyle::ColorMode::color(const QPalette& palette)
4454 {
4455  QColor palColor = palette.color(role);
4456 
4457  if (mode == BWAutoContrastMode) {
4458  if (qGray(palColor.rgb()) > 128) { //### CHECKME
4459  palColor = Qt::black;
4460  } else {
4461  palColor = Qt::white;
4462  }
4463  }
4464  return palColor;
4465 }
4466 
4467 KStyle::TextOption::TextOption()
4468 {
4469  init();
4470 }
4471 
4472 KStyle::TextOption::TextOption(const QString& _text):
4473  text(_text)
4474 {
4475  init();
4476 }
4477 
4478 void KStyle::TextOption::init()
4479 {
4480  hAlign = Qt::AlignLeft; //NOTE: Check BIDI?
4481 }
4482 
4483 // kate: indent-width 4; replace-tabs on; tab-width 4; space-indent on;
KStyle::Generic::DefaultLayoutSpacing
The spacing used by layouts, unless the style implements layoutSpacingImplementation(), default is 6 [sets QStyle::PM_DefaultLayoutSpacing].
Definition: kstyle.h:468
QObject::child
QObject * child(const char *objName, const char *inheritsClass, bool recursiveSearch) const
KStyle::Window::ButtonRestore
restore button, passes TitleButtonOption
Definition: kstyle.h:1473
KStyle::ProgressBar::MaxBusyIndicatorSize
(10000) size limit on the busy indicator size
Definition: kstyle.h:698
KStyle::PushButton::TextToIconSpace
(6) space between the icon and the text if both exist
Definition: kstyle.h:519
KStyle::ComboBox::SupportFrameless
(0)
Definition: kstyle.h:1181
KStyle::Slider::HandleVert
A vertical slider handle.
Definition: kstyle.h:1045
KStyle::ProgressBar::BusyIndicatorSize
(10) The busy indicator size, in percent of area size.
Definition: kstyle.h:697
QTransform
KStyle::ToolBar::HandleVert
handle of a toolbar, vertical
Definition: kstyle.h:1341
QPainter::setTransform
void setTransform(const QTransform &transform, bool combine)
KStyle::SpinBox::SupportFrameless
(0) Set to non-zero to indicate that you are able to handle frame-less SpinBoxes. ...
Definition: kstyle.h:1125
KStyle::ScrollBar::SliderVert
scrollbar slider, vertical. Flags: State_On&&State_Sunken for pressed state
Definition: kstyle.h:926
QEvent
QPixmap::size
QSize size() const
QWidget
KStyle::standardPixmap
QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt, const QWidget *widget=0) const
Definition: kstyle.cpp:583
QSize::isValid
bool isValid() const
QStyleOptionSpinBox
KStyle::MenuItem::TextColor
(ColorMode(QPalette::Text)) color for inactive text and arrow
Definition: kstyle.h:851
QSize::setHeight
void setHeight(int height)
KStyle::SpinBox::EditField
the text contents area, painted after Generic::Frame
Definition: kstyle.h:1141
KStyle::ToolBar::PanelHor
the actual toolbar, horizontal
Definition: kstyle.h:1343
QPen::setStyle
void setStyle(Qt::PenStyle style)
QRect::size
QSize size() const
QEvent::type
Type type() const
KStyle::CheckBox::NoLabelFocusMargin
(1) rectangle to apply to the checkbox rectangle to get where to paint the focus rectangle in case of...
Definition: kstyle.h:583
QHash::insert
iterator insert(const Key &key, const T &value)
KStyle::MenuItem::CheckSpace
(3) Space between the checkmark column and the icon column (CheckAlongsideButton enabled).
Definition: kstyle.h:841
header
const char header[]
KStyle::subElementRect
QRect subElementRect(SubElement subRect, const QStyleOption *opt, const QWidget *w) const
Definition: kstyle.cpp:2962
KStyle::ScrollBar::DoubleButtonVert
Used to draw a 2-button bevel, vertical.
Definition: kstyle.h:918
KIconLoader::currentSize
int currentSize(KIconLoader::Group group) const
Returns the current size of the icon group.
Definition: kiconloader.cpp:1370
KStyle::MenuItem::Margin
(2) margin for each entry
Definition: kstyle.h:835
KStyle::Left
Apply an additional left margin.
Definition: kstyle.h:447
KStyle::subControlRect
QRect subControlRect(ComplexControl control, const QStyleOptionComplex *opt, SubControl subControl, const QWidget *w) const
Definition: kstyle.cpp:3650
QRect::topRight
QPoint topRight() const
KStyle::Generic::ArrowLeft
Left arrow.
Definition: kstyle.h:488
KStyle::ScrollBar::ArrowColor
(ColorMode(ColorMode::BWAutoContrastMode, QPalette::Button)) color mode of a button arrow ...
Definition: kstyle.h:900
KStyle::DockWidget::TitlePanel
the panel/background of the title bar
Definition: kstyle.h:674
KStyle::DoubleButtonOption::Right
Horizontal scrollbar: The right button is active.
Definition: kstyle.h:322
QSize::width
int width() const
KStyle::SpinBox::SymmetricButtons
(0) Set to non-zero to make sure both buttons are always of the same height.
Definition: kstyle.h:1120
KStyle::ToolButton::Panel
the toolbutton panel [implements QStyle::PE_PanelButtonTool]
Definition: kstyle.h:1425
QPalette::text
const QBrush & text() const
QPixmap::width
int width() const
QPainter::end
bool end()
kdebug.h
KStyle::Window::ButtonHelp
context help button, passes TitleButtonOption
Definition: kstyle.h:1477
QAbstractItemView
QPainter::fillRect
void fillRect(const QRectF &rectangle, const QBrush &brush)
KStyle::newStyleHint
StyleHint newStyleHint(const QString &element)
Runtime element extension, allows inheriting styles to add support custom elements merges supporting ...
Definition: kstyle.cpp:344
QRect::setBottomRight
void setBottomRight(const QPoint &position)
KStyle::TabBar::BaseFrame
[implements QStyle::PE_FrameTabBarBase]
Definition: kstyle.h:984
QPixmap::copy
QPixmap copy(int x, int y, int width, int height) const
QCommonStyle::polish
virtual void polish(QPalette &pal)
KStyle::Splitter::HandleVert
The splitter handle, vertical.
Definition: kstyle.h:565
QPainter::setRenderHint
void setRenderHint(RenderHint hint, bool on)
QPainter::strokePath
void strokePath(const QPainterPath &path, const QPen &pen)
KStyle::Slider::HandleLength
(16) The width of a slider handle [sets QStyle::PM_SliderLength]
Definition: kstyle.h:1034
KStyle::MenuItem::IconWidth
(12) minimum size of the icon column
Definition: kstyle.h:843
KStyle::MenuItem::RadioOn
The checkmark of exclusive actions - selected.
Definition: kstyle.h:868
QRect::right
int right() const
KStyle::Header::TextToIconSpace
(3) space that is allocated between icon and text if both exist [sets QStyle::PM_HeaderMargin] ...
Definition: kstyle.h:1217
KIconLoader::global
static KIconLoader * global()
Returns the global icon loader initialized with the global KComponentData.
kglobalsettings.h
QCommonStyle::standardPixmap
virtual QPixmap standardPixmap(StandardPixmap sp, const QStyleOption *option, const QWidget *widget) const
KStyle::unpolish
void unpolish(QWidget *)
Definition: kstyle.cpp:414
QCommonStyle::unpolish
virtual void unpolish(QWidget *widget)
KStyle::Right
Apply an additional right margin.
Definition: kstyle.h:448
KStyle::customStyleHint
static StyleHint customStyleHint(const QString &element, const QWidget *widget)
Runtime element extension This is just convenience and does /not/ require the using widgets style to ...
Definition: kstyle.cpp:386
KStyle::WT_CheckBox
Definition: kstyle.h:406
KStyle::ToolBar::SeparatorExtent
(6) the width/height of a ToolBar separator [sets QStyle::PM_ToolBarSeparatorExtent] ...
Definition: kstyle.h:1324
QGradient::setColorAt
void setColorAt(qreal position, const QColor &color)
KStyle::DoubleButtonOption::Bottom
Vertical scrollbar: The lower button is active.
Definition: kstyle.h:323
newStyleElement
static int newStyleElement(const QString &element, const char *check, int &counter, QHash< QString, int > *elements)
Definition: kstyle.cpp:331
customStyleElement
static int customStyleElement(QStyle::StyleHint type, const QString &element, QWidget *widget)
Definition: kstyle.cpp:374
QPainter::font
const QFont & font() const
KStyle::sizeFromContents
QSize sizeFromContents(ContentsType type, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w) const
Definition: kstyle.cpp:4092
KStyle::ProgressBar::SideText
(false) set this to true to have the text positionned to the side
Definition: kstyle.h:694
KStyle::WT_Generic
Definition: kstyle.h:403
KStyle::Menu::TearOffHeight
(10) Height of the TearOff area. [sets QStyle::PM_MenuTearoffHeight]
Definition: kstyle.h:791
KDE_DEFAULT_SINGLECLICK
#define KDE_DEFAULT_SINGLECLICK
Definition: kglobalsettings.h:27
QFont
KStyle::SpinBox::ButtonMargin
(MainMargin 0, Right Top Bot 1) Where the up/down buttons are located, measured from right of the edi...
Definition: kstyle.h:1115
QCommonStyle::drawComplexControl
virtual void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *widget) const
QWidget::style
QStyle * style() const
KStyle::WidgetType
WidgetType
This enum is used to represent KStyle's concept of a widget, and to associate drawing requests and me...
Definition: kstyle.h:401
KStyle::Bot
Apply an additional bottom margin.
Definition: kstyle.h:446
KStyle::drawInsideRect
void drawInsideRect(QPainter *p, const QRect &r) const
Draws inside the rectangle using a thinkness 0 pen.
Definition: kstyle.cpp:594
KStyle::ScrollBar::SingleButtonVert
used to draw a 1-button bevel, vertical
Definition: kstyle.h:916
QPainter::setClipping
void setClipping(bool enable)
X_KdeBase
static const int X_KdeBase
Definition: kstyle.cpp:102
KStyle::ScrollBar::SingleButtonHor
used to draw a 1-button bevel, horizontal
Definition: kstyle.h:917
KStyle::WT_MenuBarItem
Definition: kstyle.h:411
QPalette::color
const QColor & color(ColorGroup group, ColorRole role) const
KStyle::ToolBar::Separator
[implements QStyle::PE_IndicatorToolBarSeparator]
Definition: kstyle.h:1342
QSize::rwidth
int & rwidth()
QPainterPath::addRoundedRect
void addRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode)
QStyleOptionProgressBar
KStyle::IconOption::icon
QIcon icon
Icon drawn by this option.
Definition: kstyle.h:300
KStyle::polish
void polish(QWidget *)
Definition: kstyle.cpp:401
QApplication
QRect::bottomRight
QPoint bottomRight() const
KStyle::customControlElement
static ControlElement customControlElement(const QString &element, const QWidget *widget)
Definition: kstyle.cpp:391
KStyle::defaultStyle
static QString defaultStyle()
Returns the default widget style.
Definition: kstyle.cpp:360
KStyle::SpinBox::ContentsMargin
(5) space between the bevel and the spinbox contents
Definition: kstyle.h:1129
KStyle::RadioButton::RadioOn
radiobutton which is checked
Definition: kstyle.h:639
QRect::translate
void translate(int dx, int dy)
QPainter::save
void save()
KStandardAction::name
const char * name(StandardAction id)
This will return the internal name of a given standard action.
Definition: kstandardaction.cpp:223
KStyle::ToolButton::InlineMenuIndicatorXOff
Horizontal offset off the bottom-right corner to place the arrow if it's incorporated directly...
Definition: kstyle.h:1405
KStyle::PushButton::PressedShiftVertical
(2) vertical contents shift for pressed buttons [sets QStyle::PM_ButtonShiftVertical] ...
Definition: kstyle.h:517
QRect::bottomLeft
QPoint bottomLeft() const
QObject::metaObject
virtual const QMetaObject * metaObject() const
KStyle::ScrollBar::GrooveAreaVertBottom
scrollbar groove area, vertical. An interesting flag is State_Sunken for pressed state ...
Definition: kstyle.h:922
KStyle::TabBar::TabFocusMargin
(3) where the tab focus rect is placed, measured from the tab sides (?)
Definition: kstyle.h:954
QPainter::drawPolygon
void drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule)
QPixmap::fromImage
QPixmap fromImage(const QImage &image, QFlags< Qt::ImageConversionFlag > flags)
KStyle::Generic::Text
Passes in TextOption.
Definition: kstyle.h:479
KStyle::DoubleButtonOption::ActiveButton
ActiveButton
List of active button possibilities.
Definition: kstyle.h:317
KStyle::CheckBox::CheckOff
checkbox which is not checked
Definition: kstyle.h:604
KStyle::ToolButton::MenuIndicatorSize
(11) Size for the separate menu arrows on tool buttons [sets QStyle::PM_MenuButtonIndicator wheen a t...
Definition: kstyle.h:1400
KStyle::TabWidget::ContentsMargin
(2) Width of the frame around a tab widget.
Definition: kstyle.h:1007
KStyle::MenuItem::Separator
Definition: kstyle.h:871
QPainter::drawTiledPixmap
void drawTiledPixmap(const QRectF &rectangle, const QPixmap &pixmap, const QPointF &position)
QRect::height
int height() const
KStyle::Window::ButtonShade
shade button, passes TitleButtonOption
Definition: kstyle.h:1475
QBrush
KStyle::CheckBox::BoxTextSpace
(6) space to leave between checkbox and text (and icon between them in case there is one) ...
Definition: kstyle.h:582
KStyle::DockWidget::SeparatorHandle
the splitter between dockwidgets
Definition: kstyle.h:675
QStyle::State
typedef State
QStyleOptionToolButton
QRect::x
int x() const
QRect::y
int y() const
kiconloader.h
KStyle::ColorOption
Option representing the color of the thing to draw.
Definition: kstyle.h:284
QStyle::itemTextRect
virtual QRect itemTextRect(const QFontMetrics &metrics, const QRect &rectangle, int alignment, bool enabled, const QString &text) const
KStyle::ComboBox::ButtonMargin
(MainMargin 0, Right Top Bot 1)
Definition: kstyle.h:1176
KStyle::GroupBox::FrameWidth
(2) width of a groupbox frame
Definition: kstyle.h:1277
KStyle::ComboBox::ButtonWidth
(16)
Definition: kstyle.h:1175
QPoint
KStyle::ToolBar::HandleHor
handle of a toolbar, horizontal
Definition: kstyle.h:1340
QFontMetrics
QMouseEvent
KStyle::IconOption::active
bool active
Is the icon active?
Definition: kstyle.h:299
KStyle::WT_TabWidget
Definition: kstyle.h:416
KStyle::TextOption::init
void init()
Called by the constructor to set the default value of hAlign.
Definition: kstyle.cpp:4478
KStyle::TextOption
Option representing text drawing info. For Generic::Text.
Definition: kstyle.h:369
QPainter::rotate
void rotate(qreal angle)
KStyle::Header::MarkSize
(9) size of the sort indicator in a header [sets QStyle::PM_HeaderMarkSize]
Definition: kstyle.h:1221
KStyle::MenuItem::ActiveDisabledTextColor
(ColorMode(QPalette::Text)) color for active + disabled text and arrow
Definition: kstyle.h:853
QPainter::drawLine
void drawLine(const QLineF &line)
KStyle::CheckBox::Size
(16) size of the checkbox [sets PM_IndicatorWidth, PM_IndicatorHeight]
Definition: kstyle.h:581
KStyle::PushButton::DefaultButtonFrame
frame indicating a default button, painted before the button Panel [implements QStyle::PE_FrameDefaul...
Definition: kstyle.h:536
KStyle::Menu::Margin
(3) The margin of the menu.
Definition: kstyle.h:789
QLinearGradient
KStyle::ToolBoxTab::Panel
the panel of a toolbox tab, KStyles default implementation paints WT_ToolButton/ToolButton::Panel [im...
Definition: kstyle.h:1371
KStyle::TabBar::BaseOverlap
(2) the number of pixels the tabs overlap with the base (i.e. tabWidget frame) [sets QStyle::PM_TabBa...
Definition: kstyle.h:965
KStyle::Slider::GrooveVert
A vertical slider groove.
Definition: kstyle.h:1047
KStyle::Tree::HorizontalBranch
A horizontal tree line.
Definition: kstyle.h:1082
KStyle::Generic::DefaultLayoutMargin
The margin used by layouts, default is 9 [sets QStyle::PM_DefaultChildMargin and QStyle::PM_DefaultTo...
Definition: kstyle.h:469
KStyle::WT_Slider
Definition: kstyle.h:417
KStyle::~KStyle
~KStyle()
Definition: kstyle.cpp:273
KStyle::DoubleButtonOption::Top
Vertical scrollbar: The upper button is active.
Definition: kstyle.h:320
KStyle::TitleButtonOption::icon
QIcon icon
window Icon
Definition: kstyle.h:352
QObject::tr
QString tr(const char *sourceText, const char *disambiguation, int n)
QWidget::foregroundRole
QPalette::ColorRole foregroundRole() const
KStyle::standardIconImplementation
QIcon standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *option=0, const QWidget *widget=0) const
Definition: kstyle.cpp:462
KStyle::GroupBox::TitleTextColor
(ColorMode(QPalette::Text)) color of the title text label
Definition: kstyle.h:1281
KStyle::ToolButton::ContentsMargin
(5) Margin reserved around the contents size of a toolbutton.
Definition: kstyle.h:1395
KStyle::Menu::FrameWidth
(1) The width of the frame, note that this does not affect the layout.
Definition: kstyle.h:788
KStyle::PushButton::DefaultIndicatorMargin
(0 ?) Default indicator between the very outside and the bevel. KStyle may reserve this for auto-defa...
Definition: kstyle.h:515
QPainter::setBrushOrigin
void setBrushOrigin(int x, int y)
metric
float metric(float dx, float dy)
Definition: kgesture.cpp:26
KStyle::Generic::DefaultFrameWidth
The FrameWidth used by LineEdit, etc..., default is 2 [sets QStyle::PM_DefaultFrameWidth].
Definition: kstyle.h:467
QPoint::x
int x() const
QPoint::y
int y() const
QCommonStyle::subControlRect
virtual QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget) const
QStyleOptionComplex
QPolygon
QStyleOptionButton
KStyle::MenuItem::ArrowWidth
(11) space to reserve for the menu arrow column
Definition: kstyle.h:847
QIcon::pixmap
QPixmap pixmap(const QSize &size, Mode mode, State state) const
QSize::rheight
int & rheight()
KStyle::layoutSpacingImplementation
int layoutSpacingImplementation(QSizePolicy::ControlType control1, QSizePolicy::ControlType control2, Qt::Orientation orientation, const QStyleOption *option, const QWidget *widget) const
Definition: kstyle.cpp:2833
QPointF
KStyle::Window::TitlePanel
whole titlebar panel/background, by KStyle default it's filled with plain highlight color ...
Definition: kstyle.h:1469
KStyle::ComboBox::ContentsMargin
(5) space between the bevel and the combobox contents
Definition: kstyle.h:1184
KStyle::DockWidget::TitleMargin
(2) Margin around title contents: Note that the symmetric margin (MainMargin) is used to size the tit...
Definition: kstyle.h:658
KStyle::Generic::ArrowDown
Down arrow.
Definition: kstyle.h:486
KStyle::Header::ContentsMargin
(3) margin around contents used to size the header.
Definition: kstyle.h:1216
QBrush::color
const QColor & color() const
KStyle::Slider::HandleHor
A horizontal slider handle.
Definition: kstyle.h:1046
KStyle::Window::ButtonUnshade
button to remove the shade state, passes TitleButtonOption
Definition: kstyle.h:1476
KStyle::MenuItem::CheckAlongsideIcon
(0) Set to non-zero to have checkmarks painted separate from icons.
Definition: kstyle.h:836
QPainter::drawRect
void drawRect(const QRectF &rectangle)
QStyleOption
QStyleOptionTitleBar
KStyle::MenuItem::ItemIndicator
Definition: kstyle.h:872
KStyle::Splitter::HandleHor
The splitter handle, horizontal.
Definition: kstyle.h:564
QRect
KStyle::Generic::Icon
Passes in IconOption.
Definition: kstyle.h:480
QPainter::setFont
void setFont(const QFont &font)
KStyle::MenuItem::CheckWidth
(12) size of the checkmark column (CheckAlongsideButton enabled).
Definition: kstyle.h:839
kglobal.h
QTransform::translate
QTransform & translate(qreal dx, qreal dy)
KStyle::Generic::Frame
Frame around widget.
Definition: kstyle.h:482
KStyle::RadioButton::Size
[sets QStyle::PM_ExclusiveIndicatorWidth, QStyle::PM_ExclusiveIndicatorHeight]
Definition: kstyle.h:619
KStyle::drawItemText
void drawItemText(QPainter *painter, const QRect &rect, int flags, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole=QPalette::NoRole) const
Definition: kstyle.cpp:444
QWidget::isEnabled
bool isEnabled() const
KStyle::ScrollBar::SingleButtonHeight
(16) height of a single button
Definition: kstyle.h:894
KStyle::TabBar::SouthTab
Definition: kstyle.h:983
KStyle::KStyle
KStyle()
Definition: kstyle.cpp:141
KStyle::centerRect
QRect centerRect(const QRect &in, int w, int h) const
Returns a w x h QRect center inside the 'in' rectangle.
Definition: kstyle.cpp:599
KStyle::DockWidget::SeparatorExtent
(6) width of the area which separates the (docked) dock window from the window contents [sets QStyle:...
Definition: kstyle.h:660
KStandardShortcut::End
Definition: kstandardshortcut.h:69
KStyle::Window::NoTitleFrame
(0) if set to non-zero, the frame primitive is not expected to paint around the titlebar area [sets Q...
Definition: kstyle.h:1447
QStyleOptionTabV3
KStyle::CheckBox::CheckOn
checkbox which is checked
Definition: kstyle.h:603
KStyle::TabBar::TabTextToIconSpace
(0 ?) space between icon and text if the tab contains both
Definition: kstyle.h:957
QCommonStyle::pixelMetric
virtual int pixelMetric(PixelMetric m, const QStyleOption *opt, const QWidget *widget) const
QVector::resize
void resize(int size)
QObject::property
QVariant property(const char *name) const
QObject::installEventFilter
void installEventFilter(QObject *filterObj)
KStyle::ScrollBar::ActiveArrowColor
(ColorMode(ColorMode::BWAutoContrastMode, QPalette::ButtonText)) color mode of a pressed button arrow...
Definition: kstyle.h:902
QVariant::toInt
int toInt(bool *ok) const
KStyle::TabBar::TabContentsMargin
(6) margin around the tab contents, used to size the tab
Definition: kstyle.h:953
KStyle::ProgressBar::Indicator
The actual bar indicating the progress...
Definition: kstyle.h:711
KStyle::LineEdit::Panel
the panel for a QLineEdit (including frame...) [implements QStyle::PE_PanelLineEdit] ...
Definition: kstyle.h:1254
KGlobalSettings::createApplicationPalette
static QPalette createApplicationPalette(const KSharedConfigPtr &config=KSharedConfigPtr())
Used to obtain the QPalette that will be used to set the application palette.
Definition: kglobalsettings.cpp:975
QImage::fill
void fill(uint pixelValue)
KStyle::ProgressBar::BusyIndicator
Used to indicate business, for example when no progress is known (minimum and maximum values both set...
Definition: kstyle.h:712
QCommonStyle::generatedIconPixmap
virtual QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const
KIconLoader::Small
Small icons, e.g. for buttons.
Definition: kiconloader.h:139
KStyle::MainMargin
The main margin is applied equally on each side.
Definition: kstyle.h:442
KStyle::newSubElement
SubElement newSubElement(const QString &element)
Definition: kstyle.cpp:354
QHash< QString, int >
KStyle::MenuItem::CheckIcon
When CheckAlongsideIcon is disabled and item is checked: checkmark Indicator painted below the icon...
Definition: kstyle.h:870
KStyle::ToolBar::PanelVert
the actual toolbar, vertical
Definition: kstyle.h:1344
QRect::top
int top() const
QColor::rgb
QRgb rgb() const
KStyle::PushButton::PressedShiftHorizontal
(2) horizontal contents shift for pressed buttons [sets QStyle::PM_ButtonShiftHorizontal] ...
Definition: kstyle.h:516
r_arrow
static const qint32 r_arrow[]
Definition: kstyle.cpp:77
QObject
QPainter::setPen
void setPen(const QColor &color)
KStyle::WT_StatusBar
Definition: kstyle.h:424
KStyle::MenuItem::RadioOff
The checkmark of exclusive actions - not selected.
Definition: kstyle.h:869
KStyle::Splitter::Width
(6) size of the splitter handle [sets QStyle::PM_SplitterWidth]
Definition: kstyle.h:554
QWidget::setFocus
void setFocus()
QRect::setTop
void setTop(int y)
KStyle::drawControl
void drawControl(ControlElement elem, const QStyleOption *opt, QPainter *p, const QWidget *w) const
Definition: kstyle.cpp:1327
KStyle::Tree::ExpanderOpen
An opened tree expander, usually drawn as '-' KStyle has a default implementation.
Definition: kstyle.h:1081
QRect::left
int left() const
KStyle::ColorMode::BWAutoContrastMode
Definition: kstyle.h:204
KStyle::styleHint
int styleHint(StyleHint hint, const QStyleOption *opt, const QWidget *w, QStyleHintReturn *returnData) const
Definition: kstyle.cpp:2512
QPainter::drawPixmap
void drawPixmap(const QRectF &target, const QPixmap &pixmap, const QRectF &source)
QSize::setWidth
void setWidth(int width)
KStyle::pixelMetric
int pixelMetric(PixelMetric metric, const QStyleOption *opt=0, const QWidget *w=0) const
Definition: kstyle.cpp:2589
QPainter
KStyle::MenuItem::IconSpace
(3) space between the icon column and text column
Definition: kstyle.h:844
QObject::objectName
objectName
KStyle::MenuBar::EmptyArea
Empty area of a menu bar, e.g.
Definition: kstyle.h:741
QRect::setWidth
void setWidth(int width)
QStyle::styleHint
virtual int styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget, QStyleHintReturn *returnData) const =0
KStyle::ToolBar::ExtensionExtent
(10) the width/height of a ToolBar extender, when there is not enough room for toolbar buttons [sets ...
Definition: kstyle.h:1325
KStyle::ScrollBar::DoubleButtonHor
Definition: kstyle.h:921
KStyle::TabBar::EastTab
Definition: kstyle.h:981
QCommonStyle::subElementRect
virtual QRect subElementRect(SubElement sr, const QStyleOption *opt, const QWidget *widget) const
KStyle::WT_ProgressBar
Definition: kstyle.h:409
KStyle::WT_MenuBar
Definition: kstyle.h:410
QCOORDARRLEN
#define QCOORDARRLEN(x)
Definition: kstyle.cpp:78
KStyle::TabBar::BaseHeight
(2) the height of the tabBar's base, usually the frame width [sets QStyle::PM_TabBarBaseHeight] ...
Definition: kstyle.h:964
KStyle::generatedIconPixmap
QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const
Definition: kstyle.cpp:588
KIcon
A wrapper around QIcon that provides KDE icon features.
Definition: kicon.h:40
KStyle::WT_ScrollBar
Definition: kstyle.h:414
KStyle::Menu::ScrollerHeight
(10) Height of a menu scroller. [sets QStyle::PM_MenuScrollerHeight]
Definition: kstyle.h:790
QPainter::setBrush
void setBrush(const QBrush &brush)
KStyle::SpinBox::ButtonSpacing
(1) spacing between up/down buttons
Definition: kstyle.h:1119
KStyle::ScrollBar::MinimumSliderHeight
(0 ?) the minimum slider height
Definition: kstyle.h:897
KStyle::MenuItem::CheckOn
The checkmark - checked.
Definition: kstyle.h:866
KStyle::drawComplexControl
void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *w) const
Definition: kstyle.cpp:3155
KStyle::MenuItem::SeparatorHeight
(0) heigh of separator
Definition: kstyle.h:848
KStyle::TextOption::hAlign
Qt::Alignment hAlign
The horizontal alignment, default is Qt::AlignLeft.
Definition: kstyle.h:371
QRect::center
QPoint center() const
d_arrow
static const qint32 d_arrow[]
Definition: kstyle.cpp:75
u_arrow
static const qint32 u_arrow[]
KStyle for KDE4 Copyright (C) 2004-2005 Maksim Orlovich maksim@kde.org Copyright (C) 2005...
Definition: kstyle.cpp:74
KStyle::GroupBox::FlatFrame
For groupboxes which are set to be 'flat' (usually a divider line from top left to top right)...
Definition: kstyle.h:1288
KStyle::Window::ButtonSpace
(2) space between titlebar buttons
Definition: kstyle.h:1454
KStyle::RadioButton::RadioOff
radiobutton which is not checked
Definition: kstyle.h:640
QStyleOptionTabWidgetFrame
QObject::eventFilter
virtual bool eventFilter(QObject *watched, QEvent *event)
KIconLoader::Dialog
Icons for use in dialog titles, page lists, etc.
Definition: kiconloader.h:143
QStyle::drawItemText
virtual void drawItemText(QPainter *painter, const QRect &rectangle, int alignment, const QPalette &palette, bool enabled, const QString &text, QPalette::ColorRole textRole) const
QRect::contains
bool contains(const QPoint &point, bool proper) const
KStyle::GroupBox::TextAlignTop
(0) set to non-zero, the title will be aligned above the groupbox frame, not vertically centered [set...
Definition: kstyle.h:1278
KStyle::RadioButton::BoxTextSpace
Definition: kstyle.h:622
KStyle::MenuItem::CheckColumn
Background of the checkmark/icon column.
Definition: kstyle.h:865
QPainter::brushOrigin
QPoint brushOrigin() const
preceeds
static bool preceeds(const QPoint &pt, const QRect &bound, const QStyleOption *opt)
Definition: kstyle.cpp:4004
QString
QColor
KStyle::WT_Window
Definition: kstyle.h:428
KStyle::WT_ToolBar
Definition: kstyle.h:425
KStyle::Generic::ArrowRight
Right arrow.
Definition: kstyle.h:487
QMetaObject::indexOfClassInfo
int indexOfClassInfo(const char *name) const
QCommonStyle::sizeFromContents
virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &csz, const QWidget *widget) const
KStyle::TextOption::TextOption
TextOption()
Definition: kstyle.cpp:4467
KStyle::ColorMode::Mode
Mode
KStyle understands two kinds of colors:Palette entries.
Definition: kstyle.h:201
KStyle::ScrollBar::DoubleBotButton
(1) set to non-zero to have two buttons on bottom
Definition: kstyle.h:893
KStyle::ToolBar::ItemSpacing
(3) [sets QStyle::PM_ToolBarItemSpacing]
Definition: kstyle.h:1329
KStyle::PushButton::ContentsMargin
(5) space between the bevel and the button contents
Definition: kstyle.h:513
QIcon::paint
void paint(QPainter *painter, const QRect &rect, QFlags< Qt::AlignmentFlag > alignment, Mode mode, State state) const
KStyle::IconOption::size
QSize size
Definition: kstyle.h:301
KStyle::hitTestComplexControl
SubControl hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, const QPoint &pt, const QWidget *w) const
Definition: kstyle.cpp:4039
QCache< quint64, SelectionTiles >
QWidget::isWindow
bool isWindow() const
KStyle::Generic::FocusIndicator
Indication that this widget has focus.
Definition: kstyle.h:481
QPixmap
KStyle::ComboBox::EditField
Definition: kstyle.h:1199
QRect::adjusted
QRect adjusted(int dx1, int dy1, int dx2, int dy2) const
KStyle::Tree::MaxExpanderSize
(9)
Definition: kstyle.h:1069
KStyle::MenuBar::ItemSpacing
(14) Space between items [sets QStyle::PM_MenuBarItemSpacing]
Definition: kstyle.h:733
QStyleOptionFocusRect
KStyle::TabBar::TabOverlap
(0) Amount of pixels tabs should overlap.
Definition: kstyle.h:959
QHash::value
const T value(const Key &key) const
KStyle::Option
Base for our own option classes.
Definition: kstyle.h:239
KStyle::SpinBox::DownButton
Panel of the spinbox button which decreases the value.
Definition: kstyle.h:1145
KGlobalSettings::showIconsOnPushButtons
static bool showIconsOnPushButtons()
This function determines if the user wishes to see icons on the push buttons.
Definition: kglobalsettings.cpp:768
KStyle::ScrollBar::GrooveAreaVertTop
scrollbar groove area, vertical. An interesting flag is State_Sunken for pressed state ...
Definition: kstyle.h:924
KStyle::MenuBarItem::Margin
(1) Margin rectangle to allocate for any bevel, etc.
Definition: kstyle.h:761
KStyle::Generic::ArrowUp
Up arrow (pointing up)
Definition: kstyle.h:485
KStyle::SpinBox::PlusSymbol
Plus symbol painted on top of the up button, centering primitive.
Definition: kstyle.h:1149
buttonPortion
static QStyle::SubControl buttonPortion(const QRect &totalRect, const QPoint &pt, const QStyleOption *opt)
Definition: kstyle.cpp:4021
KStyle::itemPixmapRect
QRect itemPixmapRect(const QRect &r, int flags, const QPixmap &pixmap) const
Definition: kstyle.cpp:440
QString::contains
bool contains(QChar ch, Qt::CaseSensitivity cs) const
QSize
KStyle::ColorOption::color
ColorMode color
Color to use for the drawing.
Definition: kstyle.h:287
QStyleOptionQ3ListViewItem
KStyle::WT_DockWidget
Definition: kstyle.h:408
QLatin1Char
QPalette::mid
const QBrush & mid() const
QPixmap::height
int height() const
KStyle::TabBar::NorthTab
Definition: kstyle.h:980
QStyle::drawItemPixmap
virtual void drawItemPixmap(QPainter *painter, const QRect &rectangle, int alignment, const QPixmap &pixmap) const
KStyle::DockWidget::FrameWidth
(3) width of the frame around floating dockwidgets [sets QStyle::PM_DockWidgetFrameWidth] ...
Definition: kstyle.h:659
KStyle::newControlElement
ControlElement newControlElement(const QString &element)
Definition: kstyle.cpp:349
QColor::lighter
QColor lighter(int factor) const
QRect::isValid
bool isValid() const
QImage
KStyle::WT_SpinBox
Definition: kstyle.h:419
KStyle::SpinBox::MinusSymbol
Minus symbol painted on top of the down button, centering primitive.
Definition: kstyle.h:1151
KStyle::DoubleButtonOption::Left
Horizontal scrollbar: The left button is active.
Definition: kstyle.h:321
l_arrow
static const qint32 l_arrow[]
Definition: kstyle.cpp:76
KStyle::CheckBox::CheckTriState
tristate checkbox (neither off nor on)
Definition: kstyle.h:605
KIconLoader::SizeHuge
huge sized icons for iconviews
Definition: kiconloader.h:163
KStyle::Top
Apply an additional top margin.
Definition: kstyle.h:445
SH_KCustomStyleElement
static const QStyle::StyleHint SH_KCustomStyleElement
Definition: kstyle.cpp:101
KStyle::ToolButton::InlineMenuIndicatorSize
(0) Size of arrow when it's incorporated into the button directly.
Definition: kstyle.h:1402
KStyle::WT_PushButton
Definition: kstyle.h:404
QPainter::restore
void restore()
KStyle::WT_Tree
Definition: kstyle.h:418
QTransform::rotate
QTransform & rotate(qreal angle, Qt::Axis axis)
KStyle::ToolButton::InlineMenuIndicatorYOff
Vertical offset off the bottom-right corner to place the arrow if it's incorporated directly...
Definition: kstyle.h:1408
KStyle::WT_LineEdit
Definition: kstyle.h:422
KStyle::TabBar::IndicatorTear
painted in the left edge of a tabbar when the left tab is scrolled out [implements PE_IndicatorTabTea...
Definition: kstyle.h:985
KStyle::MenuItem::ActiveTextColor
(ColorMode(QPalette::HighlightedText)) color for active text and arrow
Definition: kstyle.h:850
QRect::setRight
void setRight(int x)
KStyle::ComboBox::Button
The button panel of the combobox.
Definition: kstyle.h:1200
QStyleOptionHeader
KStyle::WT_Menu
Definition: kstyle.h:412
KStyle::Slider::HandleThickness
(20) The height of a slider handle
Definition: kstyle.h:1033
KStyle::WT_TabBar
Definition: kstyle.h:415
KStyle::Tree::ExpanderClosed
A closed tree expander, usually drawn as '+'. KStyle has a default implementation (Windows-like look)...
Definition: kstyle.h:1080
KStyle::MenuItem::AccelSpace
(0 ?) space between text and keyboard accelerator label
Definition: kstyle.h:845
QStyleOptionMenuItem
QPainterPath
KStyle::PushButton::MenuIndicatorSize
(8) Space inside the content area, which is allocated to the down arrow if there is a popup menu [set...
Definition: kstyle.h:518
KStyle::drawKStylePrimitive
virtual void drawKStylePrimitive(WidgetType widgetType, int primitive, const QStyleOption *opt, const QRect &r, const QPalette &pal, State flags, QPainter *p, const QWidget *widget=0, Option *kOpt=0) const
Draws primitives which are used inside KStyle.
Definition: kstyle.cpp:611
KIconLoader::Toolbar
Toolbar icons.
Definition: kiconloader.h:135
KStyle::Window::ButtonClose
close button, passes TitleButtonOption
Definition: kstyle.h:1474
QRect::width
int width() const
KStyle::Window::ButtonToTextSpace
(3) space between buttons and the title text
Definition: kstyle.h:1455
QPainter::setClipRect
void setClipRect(const QRectF &rectangle, Qt::ClipOperation operation)
QPainter::drawPath
void drawPath(const QPainterPath &path)
KStyle::MenuItem::MinHeight
(16) limit on the size of item content
Definition: kstyle.h:849
QVector< int >
KStyle::MenuItem::CheckOff
The checkmark - not checked.
Definition: kstyle.h:867
QPalette::buttonText
const QBrush & buttonText() const
QPen::setWidth
void setWidth(int width)
KStyle::itemTextRect
QRect itemTextRect(const QFontMetrics &fm, const QRect &r, int flags, bool enabled, const QString &text) const
Definition: kstyle.cpp:434
KStyle::Slider::GrooveHor
A horizontal slider groove.
Definition: kstyle.h:1048
QLatin1String
KStyle::DockWidget::TitleTextColor
(ColorMode(QPalette::HighlightedText)) color mode of the title text
Definition: kstyle.h:657
QRect::setX
void setX(int x)
KStyle::SpinBox::FrameWidth
(1) Space reserved left, top, bottom of the SpinBox [sets QStyle::PM_SpinBoxFrameWidth] ...
Definition: kstyle.h:1112
KStyle::ProgressBar::SideTextSpace
(3) Extra space besides that needed for text to allocate to side indicator (on both sides)...
Definition: kstyle.h:695
KStyle::CheckBox::FocusMargin
(0) margin around the checkbox contents reserved for the focus rect
Definition: kstyle.h:586
QRect::setRect
void setRect(int x, int y, int width, int height)
QIcon::isNull
bool isNull() const
KStyle::SpinBox::ButtonArea
Can be used in addition or instead of KPE_SpinBox_UpButton and KPE_SpinBox_DownButton.
Definition: kstyle.h:1146
QPainter::fontMetrics
QFontMetrics fontMetrics() const
QRect::setHeight
void setHeight(int height)
QStyleHintReturn
KStyle::TabBar::WestText
Definition: kstyle.h:979
quint64
KComponentData::SkipMainComponentRegistration
KStyle::WT_Splitter
Definition: kstyle.h:405
KStyle::IconOption
Option for drawing icons: represents whether the icon should be active or not.
Definition: kstyle.h:297
KStyle::ToolBar::FrameWidth
(2) width of the frame around toolbars [sets QStyle::PM_ToolBarFrameWidth]
Definition: kstyle.h:1326
QStyle::visualRect
QRect visualRect(Qt::LayoutDirection direction, const QRect &boundingRectangle, const QRect &logicalRectangle)
KStyle::eventFilter
bool eventFilter(QObject *, QEvent *)
Definition: kstyle.cpp:4374
KStyle::ToolBar::ItemMargin
(1) [sets QStyle::PM_ToolBarItemMargin]
Definition: kstyle.h:1328
KStyle::ProgressBar::GrooveMargin
(2) Margin to allocate for the groove. Content area will be inside of it.
Definition: kstyle.h:693
KStyle::WT_GroupBox
Definition: kstyle.h:423
QStyleOptionQ3ListView
QSize::height
int height() const
QPolygon::translate
void translate(int dx, int dy)
KStyle::MenuBar::Margin
(MainMargin 2, Left 4, Right 4) Margin rectangle for the contents.
Definition: kstyle.h:731
QRect::adjust
void adjust(int dx1, int dy1, int dx2, int dy2)
KStyle::TitleButtonOption::active
bool active
whether the button is pressed
Definition: kstyle.h:351
KStyle::Window::TitleMargin
(2) margin around titlebar contents (buttons, text label), used to position them and determine the he...
Definition: kstyle.h:1450
QRect::bottom
int bottom() const
QRect::topLeft
QPoint topLeft() const
KGlobal::mainComponent
const KComponentData & mainComponent()
KGlobal::hasMainComponent
bool hasMainComponent()
QPainter::translate
void translate(const QPointF &offset)
KStyle::Window::ButtonMenu
system menu button, passes TitleButtonOption
Definition: kstyle.h:1470
KStyle::Header::SectionHor
header section, horizontal
Definition: kstyle.h:1234
QStyleOptionComboBox
KStyle::Window::ButtonWidth
(16) width of a titlebar button
Definition: kstyle.h:1453
QCommonStyle::hitTestComplexControl
virtual SubControl hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, const QPoint &pt, const QWidget *widget) const
KStyle::TitleButtonOption
Option for drawing WT_Window titlebar buttons, indicating whether the button is pressed, and containing the window icon.
Definition: kstyle.h:349
qint32
KStyle::RadioButton::FocusMargin
Definition: kstyle.h:623
KStyle::WT_MenuItem
Definition: kstyle.h:413
KStyle::Window::ButtonMin
minimize button, passes TitleButtonOption
Definition: kstyle.h:1471
QPen
QColor::setAlphaF
void setAlphaF(qreal alpha)
KStyle::drawPrimitive
void drawPrimitive(PrimitiveElement elem, const QStyleOption *opt, QPainter *p, const QWidget *w) const
Definition: kstyle.cpp:979
KStyle::DoubleButtonOption
Option for drawing double scrollbar buttons, indicating whether a button should be drawn active or no...
Definition: kstyle.h:312
KStyle::TabBar::WestTab
Definition: kstyle.h:982
QFontMetrics::size
QSize size(int flags, const QString &text, int tabStops, int *tabArray) const
KStyle::standardPalette
QPalette standardPalette() const
Definition: kstyle.cpp:456
QStyle::itemPixmapRect
virtual QRect itemPixmapRect(const QRect &rectangle, int alignment, const QPixmap &pixmap) const
KStyle::PushButton::FocusMargin
(3) Used to calculate the area of the focus indicator. Measured from the bevel.
Definition: kstyle.h:514
KStyle::WT_ToolBoxTab
Definition: kstyle.h:427
QCommonStyle::styleHint
virtual int styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *widget, QStyleHintReturn *hret) const
KStyle::SpinBox::ButtonWidth
(16) Space reserved for the widget, right of the EditField
Definition: kstyle.h:1114
QCommonStyle::drawControl
virtual void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *widget) const
KStyle::ToolButton::FocusMargin
(3) Where the focus rect will be drawn, measured from the widget sides
Definition: kstyle.h:1397
QMouseEvent::pos
const QPoint & pos() const
QStyleOptionViewItemV4
KStyle::Window::ButtonMax
maximize button, passes TitleButtonOption
Definition: kstyle.h:1472
QStyle::standardIconImplementation
QIcon standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget) const
KStyle::ColorMode
A representation for colors for use as a widget layout property.
Definition: kstyle.h:191
KStyle::ScrollBar::DoubleTopButton
(0) set to non-zero to have two buttons on top
Definition: kstyle.h:892
KStyle::ScrollBar::BarWidth
(16) width of a scrollbar [sets QStyle::PM_ScrollBarExtent]
Definition: kstyle.h:896
KStyle::MenuItem::DisabledTextColor
(ColorMode(QPalette::Text)) color for inactive + disabled text and arrow
Definition: kstyle.h:852
KStyle::widgetLayoutProp
virtual int widgetLayoutProp(WidgetType widgetType, int metric, const QStyleOption *opt=0, const QWidget *w=0) const
Used to obtain information about KStyle layout properties and metrics.
Definition: kstyle.cpp:913
KStyle::ColorMode::ColorMode
ColorMode(QPalette::ColorRole _role)
Constructor, using a the given palette role _role and a default mode.
Definition: kstyle.cpp:4432
QPolygon::setPoints
void setPoints(int nPoints, const int *points)
kcomponentdata.h
KSharedConfig::openConfig
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, const char *resourceType="config")
kicon.h
KStyle::WT_Header
Definition: kstyle.h:421
KStyle::Window::TitleTextColor
(ColorMode(QPalette::HighlightedText)) color mode of the titlebar text
Definition: kstyle.h:1445
QStyle::visualPos
QPoint visualPos(Qt::LayoutDirection direction, const QRect &boundingRectangle, const QPoint &logicalPosition)
QLabel
QMatrix::map
void map(int x, int y, int *tx, int *ty) const
KStyle::drawItemPixmap
void drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, const QPixmap &pixmap) const
Definition: kstyle.cpp:451
QVector::size
int size() const
QStyleOptionDockWidget
KStyle::ScrollBar::SliderHor
scrollbar slider, horizontal. Flags: State_On&&State_Sunken for pressed state
Definition: kstyle.h:927
QStyleOptionFrame
KStyle::setWidgetLayoutProp
void setWidgetLayoutProp(WidgetType widget, int metric, int value)
Interface for the style to configure various metrics that KStyle has customizable.
Definition: kstyle.cpp:901
KStyle::ColorMode::color
QColor color(const QPalette &palette)
Return the color corresponding to our role from the palette, automatically compensating for the contr...
Definition: kstyle.cpp:4453
QPainter::pen
const QPen & pen() const
QStyleOptionFrameV2
KStyle::WT_ToolButton
Definition: kstyle.h:426
KStyle::Header::SectionVert
header section, vertical
Definition: kstyle.h:1235
KStyle::Window::TitleHeight
(20) height of the titlebar [sets QStyle::PM_TitleBarHeight]
Definition: kstyle.h:1446
QRect::setLeft
void setLeft(int x)
QCommonStyle::drawPrimitive
virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *widget) const
QStyleOptionProgressBarV2
KStyle::ProgressBar::Groove
the progressbar groove, drawn before the progress Indicator [implements QStyle::CE_ProgressBarGroove]...
Definition: kstyle.h:709
QRect::getRect
void getRect(int *x, int *y, int *width, int *height) const
KStyle::WT_ComboBox
Definition: kstyle.h:420
KStyle::Tree::VerticalBranch
Definition: kstyle.h:1086
KStyle::TextOption::text
QString text
The text to draw.
Definition: kstyle.h:372
KComponentData
QPalette
QObject::removeEventFilter
void removeEventFilter(QObject *obj)
KStyle::SpinBox::UpButton
Panel of the spinbox button which increases the value.
Definition: kstyle.h:1144
KStyle::ComboBox::FocusMargin
(1) Focus margin for ComboBoxes that aren't editable, measured from the EditField rect ...
Definition: kstyle.h:1178
KStyle::Menu::Background
Menu and MenuItem background.
Definition: kstyle.h:802
kstyle.h
QStyleOptionTab
QPainter::matrix
const QMatrix & matrix() const
KStyle::WT_RadioButton
Definition: kstyle.h:407
kconfiggroup.h
KStyle::TabBar::ScrollButtonWidth
(10) buttons which are shown when there's not enough space for tabs (A ToolButton is used for this) [...
Definition: kstyle.h:966
QIcon
KStyle::ProgressBar::Precision
(1) The indicator size will always be a multiple of this (modulo busy indicator size clamping)...
Definition: kstyle.h:696
QCoreApplication::applicationName
QString applicationName()
KStyle::DoubleButtonOption::None
No button is active.
Definition: kstyle.h:319
QStyleOptionSlider
QColor::rgba
QRgb rgba() const
KStyle::MenuBarItem::Panel
The panel/background of a menubar item. Interesting flags: State_Selected && State_HasFocus for mouse...
Definition: kstyle.h:772
KStyle::ToolBar::HandleExtent
(6) the width(hor)/height(vert) of a ToolBar handle [sets QStyle::PM_ToolBarHandleExtent] ...
Definition: kstyle.h:1323
KStyle::ComboBox::FrameWidth
(1)
Definition: kstyle.h:1174
KStyle::customSubElement
static SubElement customSubElement(const QString &element, const QWidget *widget)
Definition: kstyle.cpp:396
KStyle::ToolBoxTab::Margin
(0) used to specify the position of the tab contents, doesn't influence the tab size [sets QStyle::SE...
Definition: kstyle.h:1361
KStyle::MenuItem::ArrowSpace
(3) space between the text column and arrow column (indicating sub menus)
Definition: kstyle.h:846
KStyle::TabBar::EastText
Special rotated text for east tabs.
Definition: kstyle.h:978
KStyle::ScrollBar::DoubleButtonHeight
(32) height of a double button
Definition: kstyle.h:895
KStyle::PushButton::Panel
the pushbutton panel [implements QStyle::PE_PanelButtonCommand]
Definition: kstyle.h:534
KStyle::ScrollBar::GrooveAreaHorLeft
scrollbar groove area, horizontal. Flags: State_Sunken for pressed state
Definition: kstyle.h:925
QRect::rect
void rect(int *x, int *y, int *width, int *height) const
KStyle::ScrollBar::GrooveAreaHorRight
scrollbar groove area, horizontal. Flags: State_Sunken for pressed state
Definition: kstyle.h:923
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:24:00 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal