00001
00046 #include "kstyle.h"
00047 #include "kstyle.moc"
00048
00049 #include <QtCore/qalgorithms.h>
00050 #include <QtCore/QCache>
00051 #include <QtCore/QEvent>
00052 #include <QtCore/QVariant>
00053 #include <QtGui/QAbstractItemView>
00054 #include <QtGui/QApplication>
00055 #include <QtGui/QDialogButtonBox>
00056 #include <QtGui/QFormLayout>
00057 #include <QtGui/QIcon>
00058 #include <QtGui/QLabel>
00059 #include <QtGui/QKeyEvent>
00060 #include <QtGui/QPainter>
00061 #include <QtGui/QScrollBar>
00062 #include <QtGui/QStyleOption>
00063
00064 #include <kcomponentdata.h>
00065 #include <kglobal.h>
00066 #include <kconfiggroup.h>
00067 #include <kdebug.h>
00068 #include <kicon.h>
00069
00070 #include "kglobalsettings.h"
00071
00072
00073 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};
00074 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};
00075 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};
00076 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};
00077 #define QCOORDARRLEN(x) sizeof(x)/(sizeof(qint32)*2)
00078
00079
00088
00089
00090
00091
00092 struct SelectionTiles
00093 {
00094 QPixmap left, center, right;
00095 };
00096
00097
00098
00099
00100 static const QStyle::StyleHint SH_KCustomStyleElement = (QStyle::StyleHint)0xff000001;
00101 static const int X_KdeBase = 0xff000000;
00102
00103 class KStylePrivate
00104 {
00105 public:
00106 KStylePrivate();
00107 QCache<quint64, SelectionTiles> selectionCache;
00108 KComponentData m_componentData;
00109
00110 QHash<QString, int> styleElements;
00111 int hintCounter, controlCounter, subElementCounter;
00112 };
00113
00114 KStylePrivate::KStylePrivate() : m_componentData()
00115 {
00116 if(KGlobal::hasMainComponent())
00117 {
00118 m_componentData = KGlobal::mainComponent();
00119 } else
00120 {
00121 QString name(QApplication::applicationName());
00122
00123 if(name.isEmpty())
00124 name=qAppName();
00125
00126 if(name.isEmpty())
00127 name="KStyle";
00128
00129 m_componentData = KComponentData(name.toLatin1(), name.toLatin1(), KComponentData::SkipMainComponentRegistration);
00130 }
00131 selectionCache.setMaxCost(10);
00132 controlCounter = subElementCounter = X_KdeBase;
00133 hintCounter = X_KdeBase+1;
00134 }
00135
00136
00137
00138
00139
00140 KStyle::KStyle() : clickedLabel(0), d(new KStylePrivate)
00141 {
00142
00143 setWidgetLayoutProp(WT_Generic, Generic::DefaultFrameWidth, 2);
00144 setWidgetLayoutProp(WT_Generic, Generic::DefaultLayoutSpacing, 6);
00145 setWidgetLayoutProp(WT_Generic, Generic::DefaultLayoutMargin, 9);
00146
00147 setWidgetLayoutProp(WT_PushButton, PushButton::ContentsMargin, 5);
00148 setWidgetLayoutProp(WT_PushButton, PushButton::FocusMargin, 3);
00149 setWidgetLayoutProp(WT_PushButton, PushButton::PressedShiftHorizontal, 2);
00150 setWidgetLayoutProp(WT_PushButton, PushButton::PressedShiftVertical, 2);
00151 setWidgetLayoutProp(WT_PushButton, PushButton::MenuIndicatorSize, 8);
00152 setWidgetLayoutProp(WT_PushButton, PushButton::TextToIconSpace, 6);
00153
00154 setWidgetLayoutProp(WT_Splitter, Splitter::Width, 6);
00155
00156 setWidgetLayoutProp(WT_CheckBox, CheckBox::Size, 16);
00157 setWidgetLayoutProp(WT_CheckBox, CheckBox::BoxTextSpace, 6);
00158 setWidgetLayoutProp(WT_CheckBox, CheckBox::NoLabelFocusMargin, 1);
00159
00160 setWidgetLayoutProp(WT_RadioButton, RadioButton::Size, 16);
00161 setWidgetLayoutProp(WT_RadioButton, RadioButton::BoxTextSpace, 6);
00162
00163 setWidgetLayoutProp(WT_DockWidget, DockWidget::TitleTextColor,
00164 ColorMode(QPalette::HighlightedText));
00165 setWidgetLayoutProp(WT_DockWidget, DockWidget::TitleMargin, 2);
00166 setWidgetLayoutProp(WT_DockWidget, DockWidget::FrameWidth, 3);
00167 setWidgetLayoutProp(WT_DockWidget, DockWidget::SeparatorExtent, 6);
00168
00169 setWidgetLayoutProp(WT_ProgressBar, ProgressBar::GrooveMargin, 2);
00170 setWidgetLayoutProp(WT_ProgressBar, ProgressBar::SideTextSpace, 3);
00171 setWidgetLayoutProp(WT_ProgressBar, ProgressBar::MaxBusyIndicatorSize, 10000);
00172 setWidgetLayoutProp(WT_ProgressBar, ProgressBar::BusyIndicatorSize, 10);
00173 setWidgetLayoutProp(WT_ProgressBar, ProgressBar::Precision, 1);
00174
00175 setWidgetLayoutProp(WT_MenuBar, MenuBar::ItemSpacing, 14);
00176 setWidgetLayoutProp(WT_MenuBar, MenuBar::Margin, 2);
00177 setWidgetLayoutProp(WT_MenuBar, MenuBar::Margin + Left, 4);
00178 setWidgetLayoutProp(WT_MenuBar, MenuBar::Margin + Right, 4);
00179
00180 setWidgetLayoutProp(WT_MenuBarItem, MenuBarItem::Margin, 1);
00181
00182 setWidgetLayoutProp(WT_Menu, Menu::FrameWidth, 1);
00183 setWidgetLayoutProp(WT_Menu, Menu::Margin, 3);
00184 setWidgetLayoutProp(WT_Menu, Menu::ScrollerHeight, 10);
00185 setWidgetLayoutProp(WT_Menu, Menu::TearOffHeight, 10);
00186
00187 setWidgetLayoutProp(WT_MenuItem, MenuItem::CheckWidth, 12);
00188 setWidgetLayoutProp(WT_MenuItem, MenuItem::CheckSpace, 3);
00189 setWidgetLayoutProp(WT_MenuItem, MenuItem::IconWidth, 12);
00190 setWidgetLayoutProp(WT_MenuItem, MenuItem::IconSpace, 3);
00191 setWidgetLayoutProp(WT_MenuItem, MenuItem::ArrowWidth, 11);
00192 setWidgetLayoutProp(WT_MenuItem, MenuItem::ArrowSpace, 3);
00193 setWidgetLayoutProp(WT_MenuItem, MenuItem::Margin, 2);
00194 setWidgetLayoutProp(WT_MenuItem, MenuItem::SeparatorHeight, 0);
00195 setWidgetLayoutProp(WT_MenuItem, MenuItem::MinHeight, 16);
00196 setWidgetLayoutProp(WT_MenuItem, MenuItem::TextColor, ColorMode(QPalette::Text));
00197 setWidgetLayoutProp(WT_MenuItem, MenuItem::ActiveTextColor, ColorMode(QPalette::HighlightedText));
00198 setWidgetLayoutProp(WT_MenuItem, MenuItem::DisabledTextColor, ColorMode(QPalette::Text));
00199 setWidgetLayoutProp(WT_MenuItem, MenuItem::ActiveDisabledTextColor, ColorMode(QPalette::Text));
00200 setWidgetLayoutProp(WT_MenuItem, MenuItem::AccelSpace, 16);
00201
00202
00203 setWidgetLayoutProp(WT_ScrollBar, ScrollBar::DoubleTopButton, 0);
00204 setWidgetLayoutProp(WT_ScrollBar, ScrollBar::DoubleBotButton, 1);
00205 setWidgetLayoutProp(WT_ScrollBar, ScrollBar::SingleButtonHeight, 16);
00206 setWidgetLayoutProp(WT_ScrollBar, ScrollBar::DoubleButtonHeight, 32);
00207 setWidgetLayoutProp(WT_ScrollBar, ScrollBar::BarWidth, 16);
00208 setWidgetLayoutProp(WT_ScrollBar, ScrollBar::ArrowColor,
00209 ColorMode(ColorMode::BWAutoContrastMode, QPalette::Button));
00210 setWidgetLayoutProp(WT_ScrollBar, ScrollBar::ActiveArrowColor,
00211 ColorMode(ColorMode::BWAutoContrastMode, QPalette::ButtonText));
00212
00213 setWidgetLayoutProp(WT_TabBar, TabBar::TabContentsMargin, 6);
00214 setWidgetLayoutProp(WT_TabBar, TabBar::TabFocusMargin, 3);
00215 setWidgetLayoutProp(WT_TabBar, TabBar::TabOverlap, 0);
00216 setWidgetLayoutProp(WT_TabBar, TabBar::BaseHeight, 2);
00217 setWidgetLayoutProp(WT_TabBar, TabBar::BaseOverlap, 2);
00218 setWidgetLayoutProp(WT_TabBar, TabBar::ScrollButtonWidth, 10);
00219 setWidgetLayoutProp(WT_TabBar, TabBar::TabTextToIconSpace, 6);
00220
00221 setWidgetLayoutProp(WT_TabWidget, TabWidget::ContentsMargin, 2);
00222
00223 setWidgetLayoutProp(WT_Tree, Tree::MaxExpanderSize, 9);
00224
00225 setWidgetLayoutProp(WT_Slider, Slider::HandleThickness, 20);
00226 setWidgetLayoutProp(WT_Slider, Slider::HandleLength, 16);
00227
00228 setWidgetLayoutProp(WT_SpinBox, SpinBox::FrameWidth, 1);
00229 setWidgetLayoutProp(WT_SpinBox, SpinBox::ButtonWidth, 16);
00230 setWidgetLayoutProp(WT_SpinBox, SpinBox::ButtonSpacing, 1);
00231 setWidgetLayoutProp(WT_SpinBox, SpinBox::ButtonMargin+Right, 1);
00232 setWidgetLayoutProp(WT_SpinBox, SpinBox::ButtonMargin+Top, 1);
00233 setWidgetLayoutProp(WT_SpinBox, SpinBox::ButtonMargin+Bot, 1);
00234
00235 setWidgetLayoutProp(WT_ComboBox, ComboBox::FrameWidth, 1);
00236 setWidgetLayoutProp(WT_ComboBox, ComboBox::ButtonWidth, 16);
00237 setWidgetLayoutProp(WT_ComboBox, ComboBox::ButtonMargin+Right, 1);
00238 setWidgetLayoutProp(WT_ComboBox, ComboBox::ButtonMargin+Top, 1);
00239 setWidgetLayoutProp(WT_ComboBox, ComboBox::ButtonMargin+Bot, 1);
00240 setWidgetLayoutProp(WT_ComboBox, ComboBox::FocusMargin, 1);
00241
00242 setWidgetLayoutProp(WT_Header, Header::ContentsMargin, 3);
00243 setWidgetLayoutProp(WT_Header, Header::TextToIconSpace, 3);
00244 setWidgetLayoutProp(WT_Header, Header::MarkSize, 9);
00245
00246 setWidgetLayoutProp(WT_GroupBox, GroupBox::FrameWidth, 2);
00247 setWidgetLayoutProp(WT_GroupBox, GroupBox::TextAlignTop, false);
00248 setWidgetLayoutProp(WT_GroupBox, GroupBox::TitleTextColor, ColorMode(QPalette::Text));
00249
00250 setWidgetLayoutProp(WT_ToolBar, ToolBar::HandleExtent, 6);
00251 setWidgetLayoutProp(WT_ToolBar, ToolBar::SeparatorExtent, 6);
00252 setWidgetLayoutProp(WT_ToolBar, ToolBar::ExtensionExtent, 10);
00253 setWidgetLayoutProp(WT_ToolBar, ToolBar::FrameWidth, 2);
00254 setWidgetLayoutProp(WT_ToolBar, ToolBar::ItemSpacing, 3);
00255 setWidgetLayoutProp(WT_ToolBar, ToolBar::ItemMargin, 1);
00256
00257 setWidgetLayoutProp(WT_ToolButton, ToolButton::ContentsMargin, 5);
00258 setWidgetLayoutProp(WT_ToolButton, ToolButton::FocusMargin, 3);
00259 setWidgetLayoutProp(WT_ToolButton, ToolButton::MenuIndicatorSize, 11);
00260
00261 setWidgetLayoutProp(WT_ToolBoxTab, ToolBoxTab::Margin, 0);
00262
00263 setWidgetLayoutProp(WT_Window, Window::TitleTextColor, ColorMode(QPalette::HighlightedText));
00264 setWidgetLayoutProp(WT_Window, Window::TitleHeight, 20);
00265 setWidgetLayoutProp(WT_Window, Window::TitleMargin, 2);
00266 setWidgetLayoutProp(WT_Window, Window::NoTitleFrame, 0);
00267 setWidgetLayoutProp(WT_Window, Window::ButtonWidth, 16);
00268 setWidgetLayoutProp(WT_Window, Window::ButtonSpace, 2);
00269 setWidgetLayoutProp(WT_Window, Window::ButtonToTextSpace, 3);
00270 }
00271
00272 KStyle::~KStyle()
00273 {
00274
00275
00276
00277 const DoubleButtonOption* bOpt = extractOption<const DoubleButtonOption*>(NULL);
00278 Q_UNUSED(bOpt)
00279 #ifdef __GNUC__
00280 #warning "mem leak: need to delete bOpt"
00281 #endif
00282 delete d;
00283 }
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330 static inline int newStyleElement(const QString &element, const char *check, int &counter, QHash<QString, int> *elements)
00331 {
00332 if (!element.contains(check))
00333 return 0;
00334 int id = elements->value(element, 0);
00335 if (!id) {
00336 ++counter;
00337 id = counter;
00338 elements->insert(element, id);
00339 }
00340 return id;
00341 }
00342
00343 QStyle::StyleHint KStyle::newStyleHint(const QString &element)
00344 {
00345 return (StyleHint)newStyleElement(element, "SH_", d->hintCounter, &d->styleElements);
00346 }
00347
00348 QStyle::ControlElement KStyle::newControlElement(const QString &element)
00349 {
00350 return (ControlElement)newStyleElement(element, "CE_", d->controlCounter, &d->styleElements);
00351 }
00352
00353 KStyle::SubElement KStyle::newSubElement(const QString &element)
00354 {
00355 return (SubElement)newStyleElement(element, "SE_", d->subElementCounter, &d->styleElements);
00356 }
00357
00358
00359 QString KStyle::defaultStyle()
00360 {
00361 #ifdef Q_WS_X11
00362 return QString("oxygen");
00363 #else
00364 return QString();
00365 #endif
00366 }
00367
00368
00369
00370
00371
00372
00373 static inline int customStyleElement(QStyle::StyleHint type, const QString &element, QWidget *widget)
00374 {
00375 if (!widget || widget->style()->metaObject()->indexOfClassInfo("X-KDE-CustomElements") < 0)
00376 return 0;
00377
00378 const QString originalName = widget->objectName();
00379 widget->setObjectName(element);
00380 const int id = widget->style()->styleHint(type, 0, widget);
00381 widget->setObjectName(originalName);
00382 return id;
00383 }
00384
00385 QStyle::StyleHint KStyle::customStyleHint(const QString &element, const QWidget *widget)
00386 {
00387 return (StyleHint) customStyleElement(SH_KCustomStyleElement, element, const_cast<QWidget*>(widget));
00388 }
00389
00390 QStyle::ControlElement KStyle::customControlElement(const QString &element, const QWidget *widget)
00391 {
00392 return (ControlElement) customStyleElement(SH_KCustomStyleElement, element, const_cast<QWidget*>(widget));
00393 }
00394
00395 QStyle::SubElement KStyle::customSubElement(const QString &element, const QWidget *widget)
00396 {
00397 return (SubElement) customStyleElement(SH_KCustomStyleElement, element, const_cast<QWidget*>(widget));
00398 }
00399
00400 void KStyle::polish(QWidget *w)
00401 {
00402 if (qobject_cast<QLabel*>(w) ) {
00403 w->installEventFilter(this);
00404 }
00405
00406
00407 if (QAbstractItemView *itemView = qobject_cast<QAbstractItemView*>(w) ) {
00408 itemView->viewport()->setAttribute(Qt::WA_Hover);
00409 }
00410
00411 QCommonStyle::polish(w);
00412 }
00413 void KStyle::unpolish(QWidget *w)
00414 {
00415 if (qobject_cast<QLabel*>(w) ) {
00416 w->removeEventFilter(this);
00417 }
00418
00419 QCommonStyle::unpolish(w);
00420 }
00421 void KStyle::polish(QApplication *a)
00422 {
00423 QCommonStyle::polish(a);
00424 }
00425 void KStyle::unpolish(QApplication *a)
00426 {
00427 QCommonStyle::unpolish(a);
00428 }
00429 void KStyle::polish(QPalette &pal)
00430 {
00431 QCommonStyle::polish(pal);
00432 }
00433 QRect KStyle::itemTextRect(const QFontMetrics &fm, const QRect &r,
00434 int flags, bool enabled,
00435 const QString &text) const
00436 {
00437 return QCommonStyle::itemTextRect(fm, r, flags, enabled, text);
00438 }
00439 QRect KStyle::itemPixmapRect(const QRect &r, int flags, const QPixmap &pixmap) const
00440 {
00441 return QCommonStyle::itemPixmapRect(r, flags, pixmap);
00442 }
00443 void KStyle::drawItemText(QPainter *painter, const QRect &rect,
00444 int flags, const QPalette &pal, bool enabled,
00445 const QString &text, QPalette::ColorRole textRole) const
00446 {
00447 QCommonStyle::drawItemText(painter, rect, flags, pal, enabled,
00448 text, textRole);
00449 }
00450 void KStyle::drawItemPixmap(QPainter *painter, const QRect &rect,
00451 int alignment, const QPixmap &pixmap) const
00452 {
00453 QCommonStyle::drawItemPixmap(painter, rect, alignment, pixmap);
00454 }
00455 QPalette KStyle::standardPalette() const
00456 {
00457 return KGlobalSettings::createApplicationPalette(
00458 KSharedConfig::openConfig(d->m_componentData));
00459 }
00460
00461 QIcon KStyle::standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *option,
00462 const QWidget *widget) const
00463 {
00464 switch (standardIcon) {
00465 case QStyle::SP_DesktopIcon:
00466 return KIcon("user-desktop");
00467 case QStyle::SP_TrashIcon:
00468 return KIcon("user-trash");
00469 case QStyle::SP_ComputerIcon:
00470 return KIcon("computer");
00471 case QStyle::SP_DriveFDIcon:
00472 return KIcon("media-floppy");
00473 case QStyle::SP_DriveHDIcon:
00474 return KIcon("drive-harddisk");
00475 case QStyle::SP_DriveCDIcon:
00476 case QStyle::SP_DriveDVDIcon:
00477 return KIcon("drive-optical");
00478 case QStyle::SP_DriveNetIcon:
00479 return KIcon("folder-remote");
00480 case QStyle::SP_DirHomeIcon:
00481 return KIcon("user-home");
00482 case QStyle::SP_DirOpenIcon:
00483 return KIcon("document-open-folder");
00484 case QStyle::SP_DirClosedIcon:
00485 return KIcon("folder");
00486 case QStyle::SP_DirIcon:
00487 return KIcon("folder");
00488 case QStyle::SP_DirLinkIcon:
00489 return KIcon("folder");
00490 case QStyle::SP_FileIcon:
00491 return KIcon("text-plain");
00492 case QStyle::SP_FileLinkIcon:
00493 return KIcon("text-plain");
00494 case QStyle::SP_FileDialogStart:
00495 return KIcon("media-playback-start");
00496 case QStyle::SP_FileDialogEnd:
00497 return KIcon("media-playback-stop");
00498 case QStyle::SP_FileDialogToParent:
00499 return KIcon("go-up");
00500 case QStyle::SP_FileDialogNewFolder:
00501 return KIcon("folder-new");
00502 case QStyle::SP_FileDialogDetailedView:
00503 return KIcon("view-list-details");
00504 case QStyle::SP_FileDialogInfoView:
00505 return KIcon("document-properties");
00506 case QStyle::SP_FileDialogContentsView:
00507 return KIcon("view-list-icons");
00508 case QStyle::SP_FileDialogListView:
00509 return KIcon("view-list-text");
00510 case QStyle::SP_FileDialogBack:
00511 return KIcon("go-previous");
00512 case QStyle::SP_MessageBoxInformation:
00513 return KIcon("dialog-information");
00514 case QStyle::SP_MessageBoxWarning:
00515 return KIcon("dialog-warning");
00516 case QStyle::SP_MessageBoxCritical:
00517 return KIcon("dialog-error");
00518 case QStyle::SP_MessageBoxQuestion:
00519 return KIcon("dialog-information");
00520 case QStyle::SP_DialogOkButton:
00521 return KIcon("dialog-ok");
00522 case QStyle::SP_DialogCancelButton:
00523 return KIcon("dialog-cancel");
00524 case QStyle::SP_DialogHelpButton:
00525 return KIcon("help-contents");
00526 case QStyle::SP_DialogOpenButton:
00527 return KIcon("document-open");
00528 case QStyle::SP_DialogSaveButton:
00529 return KIcon("document-save");
00530 case QStyle::SP_DialogCloseButton:
00531 return KIcon("dialog-close");
00532 case QStyle::SP_DialogApplyButton:
00533 return KIcon("dialog-ok-apply");
00534 case QStyle::SP_DialogResetButton:
00535 return KIcon("document-revert");
00536 case QStyle::SP_DialogDiscardButton:
00537 return KIcon("dialog-cancel");
00538 case QStyle::SP_DialogYesButton:
00539 return KIcon("dialog-ok-apply");
00540 case QStyle::SP_DialogNoButton:
00541 return KIcon("dialog-cancel");
00542 case QStyle::SP_ArrowUp:
00543 return KIcon("go-up");
00544 case QStyle::SP_ArrowDown:
00545 return KIcon("go-down");
00546 case QStyle::SP_ArrowLeft:
00547 return KIcon("go-previous-view");
00548 case QStyle::SP_ArrowRight:
00549 return KIcon("go-next-view");
00550 case QStyle::SP_ArrowBack:
00551 return KIcon("go-previous");
00552 case QStyle::SP_ArrowForward:
00553 return KIcon("go-next");
00554 case QStyle::SP_BrowserReload:
00555 return KIcon("view-refresh");
00556 case QStyle::SP_BrowserStop:
00557 return KIcon("process-stop");
00558 case QStyle::SP_MediaPlay:
00559 return KIcon("media-playback-start");
00560 case QStyle::SP_MediaStop:
00561 return KIcon("media-playback-stop");
00562 case QStyle::SP_MediaPause:
00563 return KIcon("media-playback-pause");
00564 case QStyle::SP_MediaSkipForward:
00565 return KIcon("media-skip-forward");
00566 case QStyle::SP_MediaSkipBackward:
00567 return KIcon("media-skip-backward");
00568 case QStyle::SP_MediaSeekForward:
00569 return KIcon("media-seek-forward");
00570 case QStyle::SP_MediaSeekBackward:
00571 return KIcon("media-seek-backward");
00572 case QStyle::SP_MediaVolume:
00573 return KIcon("audio-volume-medium");
00574 case QStyle::SP_MediaVolumeMuted:
00575 return KIcon("audio-volume-muted");
00576
00577 default:
00578 return QStyle::standardIconImplementation(standardIcon, option, widget);
00579 }
00580 }
00581
00582 QPixmap KStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt,
00583 const QWidget *widget) const
00584 {
00585 return QCommonStyle::standardPixmap(standardPixmap, opt, widget);
00586 }
00587 QPixmap KStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap,
00588 const QStyleOption *opt) const
00589 {
00590 return QCommonStyle::generatedIconPixmap(iconMode, pixmap, opt);
00591 }
00592
00593 void KStyle::drawInsideRect(QPainter* p, const QRect& r) const
00594 {
00595 p->drawRect(r.x(), r.y(), r.width() - 1, r.height() - 1);
00596 }
00597
00598 QRect KStyle::centerRect(const QRect &in, int w, int h) const
00599 {
00600 return QRect(in.x() + (in.width() - w)/2, in.y() + (in.height() - h)/2, w, h);
00601 }
00602
00603 QRect KStyle::centerRect(const QRect &in, const QSize &size) const
00604 {
00605 return centerRect(in, size.width(), size.height());
00606 }
00607
00608
00609
00610 void KStyle::drawKStylePrimitive(WidgetType widgetType, int primitive,
00611 const QStyleOption* opt,
00612 const QRect &r, const QPalette &pal,
00613 State flags, QPainter* p,
00614 const QWidget* widget,
00615 KStyle::Option* kOpt) const
00616 {
00617 switch (widgetType)
00618 {
00619 case WT_Tree:
00620 {
00621 switch (primitive)
00622 {
00623 case Tree::VerticalBranch:
00624 case Tree::HorizontalBranch:
00625
00626 p->fillRect(r, QBrush(Qt::Dense4Pattern));
00627 return;
00628 case Tree::ExpanderOpen:
00629 case Tree::ExpanderClosed:
00630 {
00631 p->setPen(pal.text().color());
00632 drawInsideRect(p, r);
00633 int signLineSize = r.width()/4;
00634 p->drawLine(r.center().x() - signLineSize, r.center().y(),
00635 r.center().x() + signLineSize, r.center().y());
00636 if (primitive == Tree::ExpanderClosed)
00637 p->drawLine(r.center().x(), r.center().y() - signLineSize,
00638 r.center().x(), r.center().y() + signLineSize);
00639 return;
00640 }
00641 default:
00642 break;
00643 }
00644
00645 break;
00646 }
00647
00648 case WT_SpinBox:
00649 {
00650 switch (primitive)
00651 {
00652 case SpinBox::PlusSymbol:
00653 case SpinBox::MinusSymbol:
00654 {
00655 p->setPen( pal.buttonText().color() );
00656
00657 int l = qMin( r.width()-2, r.height()-2 );
00658 QPoint c = r.center();
00659
00660 p->drawLine( c.x()-l/2, c.y(), c.x()+l/2, c.y() );
00661 if (primitive == SpinBox::PlusSymbol ) {
00662 p->drawLine( c.x(), c.y()-l/2, c.x(), c.y()+l/2 );
00663 }
00664
00665 return;
00666 }
00667 default:
00668 break;
00669 }
00670
00671 break;
00672 }
00673
00674 case WT_GroupBox:
00675 {
00676 if (primitive == GroupBox::FlatFrame) {
00677 QPen oldPen = p->pen();
00678 p->setPen(pal.color(QPalette::WindowText) );
00679 p->drawLine(r.topLeft(), r.topRight() );
00680 p->setPen(oldPen);
00681 }
00682
00683 break;
00684 }
00685
00686 case WT_ToolBoxTab:
00687 {
00688 if (primitive == ToolBoxTab::Panel) {
00689 drawKStylePrimitive(WT_ToolButton, ToolButton::Panel, opt, r, pal, flags, p, widget);
00690 }
00691
00692 break;
00693 }
00694
00695 case WT_DockWidget:
00696 {
00697 switch (primitive)
00698 {
00699 case DockWidget::TitlePanel:
00700 p->fillRect(r, pal.color(QPalette::Highlight) );
00701 return;
00702
00703 case DockWidget::SeparatorHandle:
00704 return;
00705
00706 default:
00707 break;
00708 }
00709
00710 break;
00711 }
00712
00713 case WT_Window:
00714 {
00715 switch (primitive)
00716 {
00717 case Window::TitlePanel:
00718 p->fillRect(r, pal.color(QPalette::Highlight) );
00719 return;
00720
00721 case Window::ButtonMenu:
00722 {
00723 KStyle::TitleButtonOption* tbkOpts =
00724 extractOption<KStyle::TitleButtonOption*>(kOpt);
00725 if (!tbkOpts->icon.isNull()) {
00726 tbkOpts->icon.paint(p, r);
00727 } else {
00728 QStyleOption tool(0);
00729 tool.palette = pal;
00730
00731 QPixmap pm = standardPixmap(SP_TitleBarMenuButton, &tool, widget);
00732 tool.rect = r;
00733 p->save();
00734 drawItemPixmap(p, r, Qt::AlignCenter, pm);
00735 p->restore();
00736 }
00737 return;
00738 }
00739
00740 case Window::ButtonMin:
00741 case Window::ButtonMax:
00742 case Window::ButtonRestore:
00743 case Window::ButtonClose:
00744 case Window::ButtonShade:
00745 case Window::ButtonUnshade:
00746 case Window::ButtonHelp:
00747 {
00748 KStyle::TitleButtonOption* tbkOpts =
00749 extractOption<KStyle::TitleButtonOption*>(kOpt);
00750 State bflags = flags;
00751 bflags &= ~State_Sunken;
00752 if (tbkOpts->active)
00753 bflags |= State_Sunken;
00754 drawKStylePrimitive(WT_ToolButton, ToolButton::Panel, opt, r, pal, bflags, p, widget);
00755 return;
00756 }
00757 }
00758
00759 break;
00760 }
00761
00762 case WT_TabBar:
00763 {
00764
00765
00766 if (primitive == TabBar::EastText || primitive == TabBar::WestText)
00767 {
00768 QTransform tr;
00769
00770 if (primitive == TabBar::WestText)
00771 {
00772 tr.translate(r.x(), r.height() + r.y());
00773 tr.rotate(-90);
00774 }
00775 else
00776 {
00777 tr.translate(r.width() + r.x(), r.y());
00778 tr.rotate(90);
00779 }
00780
00781 p->save();
00782 p->setTransform(tr, true);
00783 drawKStylePrimitive(WT_TabBar, Generic::Text, opt,
00784 QRect(0, 0, r.height(), r.width()), pal, flags, p, widget, kOpt);
00785 p->restore();
00786 }
00787 break;
00788 }
00789
00790 default:
00791 break;
00792 }
00793
00794 if (primitive == Generic::Text)
00795 {
00796 KStyle::TextOption* textOpts = extractOption<KStyle::TextOption*>(kOpt);
00797
00798
00799
00800
00801
00802 QColor col = textOpts->color.color(pal);
00803 QPen old = p->pen();
00804 p->setPen(col);
00805 drawItemText(p, r, Qt::AlignVCenter | Qt::TextShowMnemonic | textOpts->hAlign, pal, flags & State_Enabled,
00806 textOpts->text);
00807 p->setPen(old);
00808 }
00809 else if (primitive == Generic::Icon)
00810 {
00811 KStyle::IconOption* iconOpts = extractOption<KStyle::IconOption*>(kOpt);
00812 QIcon::Mode mode;
00813
00814
00815 if (flags & State_Enabled)
00816 if (iconOpts->active)
00817 mode = QIcon::Active;
00818 else
00819 mode = QIcon::Normal;
00820 else
00821 mode = QIcon::Disabled;
00822
00823 QSize size = iconOpts->size;
00824 if(!size.isValid())
00825 size = QSize(pixelMetric(PM_SmallIconSize), pixelMetric(PM_SmallIconSize));
00826 QPixmap icon = iconOpts->icon.pixmap(size, mode);
00827 p->drawPixmap(centerRect(r, icon.size()), icon);
00828 }
00829 else if (primitive == Generic::FocusIndicator)
00830 {
00831 QPen pen;
00832 pen.setWidth(0);
00833 pen.setStyle(Qt::DotLine);
00834 p->setPen(pen);
00835 drawInsideRect(p, r);
00836 }
00837 else if (primitive >= Generic::ArrowUp && primitive <= Generic::ArrowLeft)
00838 {
00839
00840
00841 KStyle::ColorOption* colorOpt = extractOption<KStyle::ColorOption*>(kOpt);
00842 QColor arrowColor = colorOpt->color.color(pal);
00843
00844 QPolygon poly;
00845
00846 switch (primitive)
00847 {
00848 case Generic::ArrowUp:
00849 poly.setPoints(QCOORDARRLEN(u_arrow), u_arrow);
00850 break;
00851
00852 case Generic::ArrowDown:
00853 poly.setPoints(QCOORDARRLEN(d_arrow), d_arrow);
00854 break;
00855
00856 case Generic::ArrowLeft:
00857 poly.setPoints(QCOORDARRLEN(l_arrow), l_arrow);
00858 break;
00859
00860 default:
00861 poly.setPoints(QCOORDARRLEN(r_arrow), r_arrow);
00862 }
00863
00864 if ( flags & State_Enabled )
00865 {
00866
00867 poly.translate(r.x() + r.width()/2 - 1, r.y() + r.height()/2);
00868
00869 p->setPen(arrowColor);
00870 p->drawPolygon(poly);
00871 }
00872 else
00873 {
00874
00875 poly.translate(r.x() + r.width()/2, r.y() + r.height()/2 + 1);
00876 p->setPen( pal.color( QPalette::Light ) );
00877 p->drawPolygon(poly);
00878 poly.translate(-1,-1);
00879 p->setPen(pal.mid().color());
00880 p->drawPolygon(poly);
00881 }
00882
00883 }
00884 #if 0 //Reenable if you need a debug aid
00885 else
00886 {
00887 p->setPen(Qt::red);
00888 drawInsideRect(p, r);
00889 }
00890 #endif
00891 }
00892
00893
00894 void KStyle::setWidgetLayoutProp(WidgetType widget, int metric, int value)
00895 {
00896 if (metrics.size() <= widget)
00897 metrics.resize(widget + 1);
00898
00899 QVector<int>& widgetMetrics = metrics[widget];
00900 if (widgetMetrics.size() <= metric)
00901 widgetMetrics.resize(metric + 1);
00902
00903 widgetMetrics[metric] = value;
00904 }
00905
00906 int KStyle::widgetLayoutProp(WidgetType widget, int metric,
00907 const QStyleOption* opt,
00908 const QWidget* w ) const
00909 {
00910 Q_UNUSED(opt)
00911 Q_UNUSED(w)
00912
00913 if (metrics.size() <= widget)
00914 return 0;
00915
00916 const QVector<int>& widgetMetrics = metrics[widget];
00917 if (widgetMetrics.size() <= metric)
00918 return 0;
00919
00920 return widgetMetrics[metric];
00921 }
00922
00923 QSize KStyle::expandDim(const QSize& orig, WidgetType wt, int baseMarginMetric,
00924 const QStyleOption* opt, const QWidget* w, bool rotated) const
00925 {
00926 int addWidth = 2*widgetLayoutProp(wt, baseMarginMetric + MainMargin, opt, w) +
00927 widgetLayoutProp(wt, baseMarginMetric + Left, opt, w) +
00928 widgetLayoutProp(wt, baseMarginMetric + Right, opt, w);
00929
00930 int addHeight = 2*widgetLayoutProp(wt, baseMarginMetric + MainMargin, opt, w) +
00931 widgetLayoutProp(wt, baseMarginMetric + Top, opt, w) +
00932 widgetLayoutProp(wt, baseMarginMetric + Bot, opt, w);
00933
00934 return QSize(orig.width() + (rotated? addHeight: addWidth),
00935 orig.height() + (rotated? addWidth: addHeight));
00936 }
00937
00938 QRect KStyle::insideMargin(const QRect &orig, WidgetType wt,
00939 int baseMarginMetric,
00940 const QStyleOption* opt, const QWidget* w) const
00941 {
00942 int x1 = orig.topLeft().x();
00943 int y1 = orig.topLeft().y();
00944 int x2 = orig.bottomRight().x();
00945 int y2 = orig.bottomRight().y();
00946
00947 x1 += widgetLayoutProp(wt, baseMarginMetric + MainMargin, opt, w);
00948 x1 += widgetLayoutProp(wt, baseMarginMetric + Left, opt, w);
00949
00950 y1 += widgetLayoutProp(wt, baseMarginMetric + MainMargin, opt, w);
00951 y1 += widgetLayoutProp(wt, baseMarginMetric + Top, opt, w);
00952
00953 x2 -= widgetLayoutProp(wt, baseMarginMetric + MainMargin, opt, w);
00954 x2 -= widgetLayoutProp(wt, baseMarginMetric + Right, opt, w);
00955
00956 y2 -= widgetLayoutProp(wt, baseMarginMetric + MainMargin, opt, w);
00957 y2 -= widgetLayoutProp(wt, baseMarginMetric + Bot, opt, w);
00958
00959 return QRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
00960 }
00961
00962 QRect KStyle::handleRTL(const QStyleOption* opt, const QRect& subRect) const
00963 {
00964 return visualRect(opt->direction, opt->rect, subRect);
00965 }
00966
00967 QPoint KStyle::handleRTL(const QStyleOption* opt, const QPoint& pos) const
00968 {
00969 return visualPos(opt->direction, opt->rect, pos);
00970 }
00971
00972 void KStyle::drawPrimitive(PrimitiveElement elem, const QStyleOption* option, QPainter* painter, const QWidget* widget) const
00973 {
00974
00975 State flags = option->state;
00976 QRect r = option->rect;
00977 QPalette pal = option->palette;
00978
00979 switch (elem)
00980 {
00981 case PE_FrameFocusRect:
00982 drawKStylePrimitive(WT_Generic, Generic::FocusIndicator, option, r, pal, flags, painter, widget);
00983 return;
00984 case PE_IndicatorArrowUp:
00985 drawKStylePrimitive(WT_Generic, Generic::ArrowUp, option, r, pal, flags, painter, widget);
00986 return;
00987 case PE_IndicatorArrowDown:
00988 drawKStylePrimitive(WT_Generic, Generic::ArrowDown, option, r, pal, flags, painter, widget);
00989 return;
00990 case PE_IndicatorArrowLeft:
00991 drawKStylePrimitive(WT_Generic, Generic::ArrowLeft, option, r, pal, flags, painter, widget);
00992 return;
00993 case PE_IndicatorArrowRight:
00994 drawKStylePrimitive(WT_Generic, Generic::ArrowRight, option, r, pal, flags, painter, widget);
00995 return;
00996 case PE_IndicatorMenuCheckMark:
00997
00998 drawKStylePrimitive(WT_MenuItem, MenuItem::CheckOn, option, r, pal, flags, painter, widget);
00999 return;
01000 case PE_IndicatorCheckBox:
01001 if (flags & State_NoChange)
01002 drawKStylePrimitive(WT_CheckBox, CheckBox::CheckTriState, option, r, pal, flags, painter, widget);
01003 else if (flags & State_On)
01004 drawKStylePrimitive(WT_CheckBox, CheckBox::CheckOn, option, r, pal, flags, painter, widget);
01005 else
01006 drawKStylePrimitive(WT_CheckBox, CheckBox::CheckOff, option, r, pal, flags, painter, widget);
01007 return;
01008 case PE_IndicatorRadioButton:
01009 if (flags & State_On)
01010 drawKStylePrimitive(WT_RadioButton, RadioButton::RadioOn, option, r, pal, flags, painter, widget);
01011 else
01012 drawKStylePrimitive(WT_RadioButton, RadioButton::RadioOff, option, r, pal, flags, painter, widget);
01013 return;
01014 case PE_IndicatorBranch:
01015 {
01016 int centerX = r.x() + r.width()/2;
01017 int centerY = r.y() + r.height()/2;
01018
01019 int expanderAdjust = 0;
01020
01021 if (flags & State_Children)
01022 {
01023
01024 int sizeLimit = qMin(qMin(r.width(), r.height()),
01025 widgetLayoutProp(WT_Tree, Tree::MaxExpanderSize, option, widget));
01026 if ((sizeLimit & 1) == 0)
01027 --sizeLimit;
01028
01029 expanderAdjust = sizeLimit/2 + 1;
01030
01031 QRect expanderRect = QRect(centerX - sizeLimit/2, centerY - sizeLimit/2,
01032 sizeLimit, sizeLimit);
01033
01034 drawKStylePrimitive(WT_Tree, flags & State_Open ? Tree::ExpanderOpen : Tree::ExpanderClosed,
01035 option, expanderRect, pal, flags, painter, widget);
01036 }
01037
01038
01039
01040 if (flags & (State_Item | State_Children | State_Sibling))
01041 {
01042 QRect topLine = QRect(QPoint(centerX, r.y()), QPoint(centerX, centerY - expanderAdjust));
01043 drawKStylePrimitive(WT_Tree, Tree::VerticalBranch, option, topLine, pal, flags, painter, widget);
01044 }
01045
01046
01047 if (flags & State_Item)
01048 {
01049 QRect horLine;
01050 if (option->direction == Qt::LeftToRight)
01051 horLine = QRect(QPoint(centerX + expanderAdjust, centerY),
01052 QPoint(r.right(), centerY));
01053 else
01054 horLine = QRect(QPoint(r.left(), centerY),
01055 QPoint(centerX - expanderAdjust, centerY));
01056 drawKStylePrimitive(WT_Tree, Tree::HorizontalBranch, option, horLine, pal, flags, painter, widget);
01057 }
01058
01059
01060 if (flags & State_Sibling)
01061 {
01062 QRect botLine = QRect(QPoint(centerX, centerY + expanderAdjust),
01063 QPoint(centerX, r.bottom()));
01064 drawKStylePrimitive(WT_Tree, Tree::VerticalBranch, option, botLine, pal, flags, painter, widget);
01065 }
01066 return;
01067 }
01068 case PE_FrameMenu:
01069 drawKStylePrimitive(WT_Menu, Generic::Frame, option, r, pal, flags, painter, widget);
01070 return;
01071 case PE_IndicatorHeaderArrow:
01072 {
01073 const QStyleOptionHeader *hOpt = qstyleoption_cast<const QStyleOptionHeader *>(option);
01074 int primitive = 0;
01075 if (flags&State_UpArrow || (hOpt && hOpt->sortIndicator==QStyleOptionHeader::SortUp))
01076 primitive = Generic::ArrowUp;
01077 else if (flags&State_DownArrow || (hOpt && hOpt->sortIndicator==QStyleOptionHeader::SortDown))
01078 primitive = Generic::ArrowDown;
01079 if (primitive != 0)
01080 drawKStylePrimitive(WT_Header, primitive, option, r, pal, flags, painter, widget);
01081 return;
01082 }
01083 case PE_FrameTabBarBase:
01084 {
01085 drawKStylePrimitive(WT_TabBar, TabBar::BaseFrame,option,r,pal,flags,painter,widget);
01086 return;
01087 }
01088 case PE_IndicatorTabTear:
01089 {
01090 drawKStylePrimitive(WT_TabBar, TabBar::IndicatorTear,option,r,pal,flags,painter,widget);
01091 return;
01092 }
01093 case PE_FrameTabWidget:
01094 {
01095 drawKStylePrimitive(WT_TabWidget, Generic::Frame,option,r,pal,flags,painter,widget);
01096 return;
01097 }
01098
01099 case PE_PanelLineEdit:
01100 {
01101 drawKStylePrimitive(WT_LineEdit, LineEdit::Panel,option,r,pal,flags,painter,widget);
01102 return;
01103 }
01104
01105 case PE_FrameLineEdit:
01106 {
01107 drawKStylePrimitive(WT_LineEdit, Generic::Frame,option,r,pal,flags,painter,widget);
01108 return;
01109 }
01110
01111 case PE_FrameGroupBox:
01112 {
01113 if (const QStyleOptionFrame *fOpt =
01114 qstyleoption_cast<const QStyleOptionFrame *>(option))
01115 {
01116 QStyleOptionFrameV2 fOpt2(*fOpt);
01117
01118 if (fOpt2.features & QStyleOptionFrameV2::Flat) {
01119 drawKStylePrimitive(WT_GroupBox, GroupBox::FlatFrame,option,r,pal,flags,painter,widget);
01120 } else {
01121 drawKStylePrimitive(WT_GroupBox, Generic::Frame,option,r,pal,flags,painter,widget);
01122 }
01123 }
01124 return;
01125 }
01126
01127 case PE_FrameStatusBar:
01128 {
01129 drawKStylePrimitive(WT_StatusBar, Generic::Frame,option,r,pal,flags,painter,widget);
01130 return;
01131 }
01132
01133 case PE_FrameDockWidget:
01134 {
01135 drawKStylePrimitive(WT_DockWidget, Generic::Frame,option,r,pal,flags,painter,widget);
01136 return;
01137 }
01138
01139 case PE_IndicatorDockWidgetResizeHandle:
01140 {
01141 drawKStylePrimitive(WT_DockWidget, DockWidget::SeparatorHandle, option, r, pal, flags,
01142 painter, widget);
01143 return;
01144 }
01145
01146 case PE_FrameWindow:
01147 {
01148 drawKStylePrimitive(WT_Window, Generic::Frame,option,r,pal,flags,painter,widget);
01149 return;
01150 }
01151
01152 case PE_Frame:
01153 {
01154 drawKStylePrimitive(WT_Generic, Generic::Frame,option,r,pal,flags,painter,widget);
01155 return;
01156 }
01157
01158 case PE_IndicatorToolBarHandle:
01159 {
01160 if (flags & State_Horizontal)
01161 drawKStylePrimitive(WT_ToolBar, ToolBar::HandleHor,
01162 option,r,pal,flags,painter,widget);
01163 else
01164 drawKStylePrimitive(WT_ToolBar, ToolBar::HandleVert,
01165 option,r,pal,flags,painter,widget);
01166 return;
01167 }
01168
01169 case PE_IndicatorToolBarSeparator:
01170 drawKStylePrimitive(WT_ToolBar, ToolBar::Separator,option,r,pal,flags,painter,widget);
01171 return;
01172
01173 case PE_PanelButtonCommand:
01174
01175 drawKStylePrimitive(WT_PushButton, PushButton::Panel, option, r, pal, flags, painter, widget);
01176 return;
01177 case PE_FrameDefaultButton:
01178 drawKStylePrimitive(WT_PushButton, PushButton::DefaultButtonFrame, option, r, pal, flags, painter, widget);
01179 return;
01180
01181 case PE_PanelButtonTool:
01182 drawKStylePrimitive(WT_ToolButton, ToolButton::Panel,option,r,pal,flags,painter,widget);
01183 return;
01184
01185 case PE_IndicatorButtonDropDown:
01186 drawKStylePrimitive(WT_ToolButton, Generic::ArrowDown, option, r, pal, flags, painter, widget);
01187 return;
01188
01189 case PE_PanelItemViewItem: {
01190
01191 const QStyleOptionViewItemV4 *opt = qstyleoption_cast<const QStyleOptionViewItemV4*>(option);
01192 const QAbstractItemView *view = qobject_cast<const QAbstractItemView *>(widget);
01193 bool hover = (option->state & State_MouseOver) && (!view ||
01194 view->selectionMode() != QAbstractItemView::NoSelection);
01195
01196 bool hasCustomBackground = opt->backgroundBrush.style() != Qt::NoBrush &&
01197 !(option->state & State_Selected);
01198 bool hasSolidBackground = !hasCustomBackground || opt->backgroundBrush.style() == Qt::SolidPattern;
01199
01200 const qreal rounding = 2.5;
01201
01202 if (!hover && !(option->state & State_Selected) && !hasCustomBackground &&
01203 !(opt->features & QStyleOptionViewItemV2::Alternate))
01204 return;
01205
01206 QPalette::ColorGroup cg;
01207 if (option->state & State_Enabled)
01208 cg = (option->state & State_Active) ? QPalette::Normal : QPalette::Inactive;
01209 else
01210 cg = QPalette::Disabled;
01211
01212 QColor color;
01213
01214 if (hasCustomBackground && hasSolidBackground)
01215 color = opt->backgroundBrush.color();
01216 else
01217 color = option->palette.color(cg, QPalette::Highlight);
01218
01219 if (hover && !hasCustomBackground) {
01220 if (!(option->state & State_Selected))
01221 color.setAlphaF(.20);
01222 else
01223 color = color.lighter(110);
01224 }
01225
01226 if (opt && (opt->features & QStyleOptionViewItemV2::Alternate))
01227 painter->fillRect(option->rect, option->palette.brush(cg, QPalette::AlternateBase));
01228
01229 if (!hover && !(option->state & State_Selected) && !hasCustomBackground)
01230 return;
01231
01232 quint64 key = quint64(option->rect.height()) << 32 | color.rgba();
01233 SelectionTiles* tiles = d->selectionCache.object(key);
01234 if (!tiles && hasSolidBackground)
01235 {
01236 QImage image(32 + 16, option->rect.height(), QImage::Format_ARGB32_Premultiplied);
01237 image.fill(0);
01238
01239 QRect r = image.rect().adjusted(0, 0, -1, -1);
01240
01241 QPainterPath path1, path2;
01242 path1.addRoundedRect(r, rounding, rounding);
01243 path2.addRoundedRect(r.adjusted(1, 1, -1, -1), rounding - 1, rounding - 1);
01244
01245
01246
01247
01248 int lightenAmount = hasCustomBackground ? 110 : 130;
01249 QLinearGradient gradient(0, 0, 0, r.bottom());
01250 gradient.setColorAt(0, color.lighter(lightenAmount));
01251 gradient.setColorAt(1, color);
01252
01253 QPainter p(&image);
01254 p.setRenderHint(QPainter::Antialiasing);
01255 p.translate(.5, .5);
01256 p.setPen(QPen(color, 1));
01257 p.setBrush(gradient);
01258 p.drawPath(path1);
01259 p.strokePath(path2, QPen(QColor(255, 255, 255, 64), 1));
01260 p.end();
01261
01262 QPixmap pixmap = QPixmap::fromImage(image);
01263
01264 tiles = new SelectionTiles;
01265 tiles->left = pixmap.copy(0, 0, 8, image.height());
01266 tiles->center = pixmap.copy(8, 0, 32, image.height());
01267 tiles->right = pixmap.copy(40, 0, 8, image.height());
01268
01269 d->selectionCache.insert(key, tiles);
01270 }
01271 else if (hasCustomBackground && !hasSolidBackground)
01272 {
01273 const QPointF oldBrushOrigin = painter->brushOrigin();
01274 painter->setBrushOrigin(opt->rect.topLeft());
01275 painter->setBrush(opt->backgroundBrush);
01276 painter->setPen(Qt::NoPen);
01277 painter->drawRect(opt->rect);
01278 painter->setBrushOrigin(oldBrushOrigin);
01279 return;
01280 }
01281
01282 bool roundedLeft = false;
01283 bool roundedRight = false;
01284 if (opt) {
01285 roundedLeft = (opt->viewItemPosition == QStyleOptionViewItemV4::Beginning);
01286 roundedRight = (opt->viewItemPosition == QStyleOptionViewItemV4::End);
01287 if (opt->viewItemPosition == QStyleOptionViewItemV4::OnlyOne ||
01288 opt->viewItemPosition == QStyleOptionViewItemV4::Invalid ||
01289 (view && view->selectionBehavior() != QAbstractItemView::SelectRows))
01290 {
01291 roundedLeft = true;
01292 roundedRight = true;
01293 }
01294 }
01295
01296 QRect r = option->rect;
01297 bool reverseLayout = option->direction == Qt::RightToLeft;
01298
01299 if (!reverseLayout ? roundedLeft : roundedRight) {
01300 painter->drawPixmap(r.topLeft(), tiles->left);
01301 r.adjust(8, 0, 0, 0);
01302 }
01303 if (!reverseLayout ? roundedRight : roundedLeft) {
01304 painter->drawPixmap(r.right() - 8 + 1, r.top(), tiles->right);
01305 r.adjust(0, 0, -8, 0);
01306 }
01307 if (r.isValid())
01308 painter->drawTiledPixmap(r, tiles->center);
01309
01310 return;
01311 }
01312
01313 default:
01314 break;
01315 }
01316
01317 QCommonStyle::drawPrimitive(elem, option, painter, widget);
01318 }
01319
01320 void KStyle::drawControl(ControlElement element, const QStyleOption* option, QPainter* p, const QWidget* widget) const
01321 {
01322
01323 State flags = option->state;
01324 QRect r = option->rect;
01325 QPalette pal = option->palette;
01326
01327 switch (element)
01328 {
01329 case CE_PushButton:
01330 {
01331 const QStyleOptionButton* bOpt = qstyleoption_cast<const QStyleOptionButton*>(option);
01332 if (!bOpt) return;
01333
01334
01335 drawControl(CE_PushButtonBevel, option, p, widget);
01336
01337
01338 QRect labelRect = r;
01339
01340
01341 if ((bOpt->features & QStyleOptionButton::DefaultButton) || (bOpt->features & QStyleOptionButton::AutoDefaultButton))
01342 labelRect = insideMargin(labelRect, WT_PushButton, PushButton::DefaultIndicatorMargin, option, widget);
01343
01344
01345 labelRect = insideMargin(labelRect, WT_PushButton, PushButton::ContentsMargin, option, widget);
01346
01347
01348
01349 QStyleOptionButton bOptTmp = *bOpt;
01350 bOptTmp.rect = labelRect;
01351 drawControl(CE_PushButtonLabel, &bOptTmp, p, widget);
01352
01353
01354 if (flags & State_HasFocus)
01355 {
01356 QRect focusRect = insideMargin(r, WT_PushButton, PushButton::FocusMargin, option, widget);
01357
01358 QStyleOptionFocusRect foOpts;
01359 foOpts.palette = pal;
01360 foOpts.rect = focusRect;
01361 foOpts.state = flags;
01362
01363 drawKStylePrimitive(WT_PushButton, Generic::FocusIndicator, &foOpts, focusRect, pal, flags, p, widget);
01364 }
01365
01366 return;
01367 }
01368
01369 case CE_PushButtonBevel:
01370 {
01371 const QStyleOptionButton* bOpt = qstyleoption_cast<const QStyleOptionButton*>(option);
01372 if (!bOpt) return;
01373
01374
01375 if (bOpt->features & QStyleOptionButton::DefaultButton)
01376 drawPrimitive(PE_FrameDefaultButton, option, p, widget);
01377
01378 QRect bevelRect = r;
01379
01380 if ((bOpt->features & QStyleOptionButton::DefaultButton) || (bOpt->features & QStyleOptionButton::AutoDefaultButton))
01381 bevelRect = insideMargin(r, WT_PushButton, PushButton::DefaultIndicatorMargin, option, widget);
01382
01383
01384 QStyleOptionButton bOptTmp = *bOpt;
01385 bOptTmp.rect = bevelRect;
01386 drawPrimitive(PE_PanelButtonCommand, &bOptTmp, p, widget);
01387
01388 return;
01389 }
01390
01391 case CE_PushButtonLabel:
01392 {
01393 const QStyleOptionButton* bOpt = qstyleoption_cast<const QStyleOptionButton*>(option);
01394 if (!bOpt) return;
01395
01396
01397
01398 int x, y, w, h;
01399 r.getRect(&x, &y, &w, &h);
01400
01401
01402 bool active = (flags & State_On) || (flags & State_Sunken);
01403 if (active)
01404 {
01405 x += widgetLayoutProp(WT_PushButton, PushButton::PressedShiftHorizontal, option, widget);
01406 y += widgetLayoutProp(WT_PushButton, PushButton::PressedShiftVertical, option, widget);
01407 }
01408
01409
01410 if (bOpt->features & QStyleOptionButton::HasMenu)
01411 {
01412 int indicatorWidth = widgetLayoutProp(WT_PushButton, PushButton::MenuIndicatorSize, option, widget);
01413 int indicatorSpacing = widgetLayoutProp(WT_PushButton, PushButton::TextToIconSpace, option, widget);
01414 w -= indicatorWidth + indicatorSpacing;
01415
01416
01417 drawKStylePrimitive(WT_PushButton, Generic::ArrowDown, option,
01418 handleRTL(bOpt, QRect(x + w + indicatorSpacing, y, indicatorWidth, h)),
01419 pal, flags, p, widget);
01420 }
01421
01422
01423 if (!bOpt->icon.isNull())
01424 {
01425 IconOption icoOpt;
01426 icoOpt.icon = bOpt->icon;
01427 icoOpt.size = bOpt->iconSize;
01428 icoOpt.active = flags & State_HasFocus;
01429
01430 if (!bOpt->text.isEmpty())
01431 {
01432 int margin = widgetLayoutProp(WT_PushButton, PushButton::TextToIconSpace, option, widget);
01433
01434
01435
01436 int length = bOpt->iconSize.width() + margin
01437 + p->fontMetrics().size(Qt::TextShowMnemonic, bOpt->text).width();
01438
01439
01440 int offset = (w - length)/2;
01441
01442
01443 QRect rect = QRect(QPoint(x + offset, y + h/2 - bOpt->iconSize.height()/2), bOpt->iconSize);
01444 drawKStylePrimitive(WT_PushButton, Generic::Icon, option,
01445 handleRTL(bOpt, rect),
01446 pal, flags, p, widget, &icoOpt);
01447
01448
01449 x += offset + bOpt->iconSize.width() + margin;
01450 w = length - bOpt->iconSize.width() - margin;
01451 }
01452 else
01453 {
01454
01455
01456 drawKStylePrimitive(WT_PushButton, Generic::Icon, option,
01457 QRect(x, y, w, h),
01458 pal, flags, p, widget, &icoOpt);
01459 }
01460 }
01461 else
01462 {
01463
01464 int textW = p->fontMetrics().size(Qt::TextShowMnemonic, bOpt->text).width();
01465 x += (w - textW)/2;
01466 w = textW;
01467 }
01468
01469 TextOption lbOpt(bOpt->text);
01470 drawKStylePrimitive(WT_PushButton, Generic::Text, option, handleRTL(bOpt, QRect(x, y, w, h)),
01471 pal, flags, p, widget, &lbOpt);
01472
01473 return;
01474 }
01475
01476 case CE_DockWidgetTitle:
01477 {
01478 const QStyleOptionDockWidget* dwOpt = ::qstyleoption_cast<const QStyleOptionDockWidget*>(option);
01479 if (!dwOpt) return;
01480
01481 QRect textRect = insideMargin(r, WT_DockWidget, DockWidget::TitleMargin, option, widget);
01482 drawKStylePrimitive(WT_DockWidget, DockWidget::TitlePanel, option, r, pal, flags, p, widget);
01483
01484 TextOption lbOpt(dwOpt->title);
01485 lbOpt.color = widgetLayoutProp(WT_DockWidget, DockWidget::TitleTextColor,
01486 option, widget);
01487 drawKStylePrimitive(WT_DockWidget, Generic::Text, option, textRect, pal, flags, p, widget, &lbOpt);
01488 return;
01489 }
01490
01491 case CE_ToolBoxTabShape:
01492 {
01493 drawKStylePrimitive(WT_ToolBoxTab, ToolBoxTab::Panel, option, r, pal, flags, p, widget);
01494 return;
01495 }
01496
01497
01498
01499
01500
01501
01502
01503 case CE_CheckBox:
01504 {
01505 const QStyleOptionButton* bOpt = qstyleoption_cast<const QStyleOptionButton*>(option);
01506 if (!bOpt) return;
01507
01508
01509 QRect checkBox = subElementRect(SE_CheckBoxIndicator, option, widget);
01510 QStyleOptionButton bOptTmp = *bOpt;
01511 bOptTmp.rect = checkBox;
01512 drawPrimitive(PE_IndicatorCheckBox, &bOptTmp, p, widget);
01513
01514
01515 bOptTmp.rect = subElementRect(SE_CheckBoxContents, option, widget);
01516 drawControl(CE_CheckBoxLabel, &bOptTmp, p, widget);
01517
01518
01519 if (flags & State_HasFocus)
01520 {
01521 QRect focusRect = subElementRect(SE_CheckBoxFocusRect, option, widget);
01522 drawKStylePrimitive(WT_CheckBox, Generic::FocusIndicator, option, focusRect,
01523 pal, flags, p, widget);
01524 }
01525 return;
01526 }
01527
01528 case CE_CheckBoxLabel:
01529 {
01530 const QStyleOptionButton* bOpt = qstyleoption_cast<const QStyleOptionButton*>(option);
01531 if (!bOpt) return;
01532
01533 int textShift = 0;
01534
01535 if (!bOpt->icon.isNull())
01536 {
01537 IconOption icoOpt;
01538 icoOpt.icon = bOpt->icon;
01539 icoOpt.size = bOpt->iconSize;
01540 icoOpt.active = flags & State_HasFocus;
01541
01542 QRect iconRect(r.x(), r.y() + (r.height()-bOpt->iconSize.height())/2,
01543 bOpt->iconSize.width(), bOpt->iconSize.height());
01544 drawKStylePrimitive(WT_CheckBox, Generic::Icon, option,
01545 handleRTL(bOpt, iconRect),
01546 pal, flags, p, widget, &icoOpt);
01547
01548 textShift = bOpt->iconSize.width() +
01549 widgetLayoutProp(WT_RadioButton, RadioButton::BoxTextSpace, option, widget);
01550 }
01551
01552
01553 if (!bOpt->text.isEmpty() ) {
01554 TextOption lbOpt(bOpt->text);
01555 drawKStylePrimitive(WT_CheckBox, Generic::Text, option,
01556 handleRTL(bOpt, r.adjusted(textShift,0,0,0)),
01557 pal, flags, p, widget, &lbOpt);
01558 }
01559
01560 return;
01561 }
01562
01563 case CE_RadioButton:
01564 {
01565 const QStyleOptionButton* bOpt = qstyleoption_cast<const QStyleOptionButton*>(option);
01566 if (!bOpt) return;
01567
01568
01569 QRect indicator = subElementRect(SE_RadioButtonIndicator, option, widget);
01570 QStyleOptionButton bOptTmp = *bOpt;
01571 bOptTmp.rect = indicator;
01572 drawPrimitive(PE_IndicatorRadioButton, &bOptTmp, p, widget);
01573
01574
01575 bOptTmp.rect = subElementRect(SE_RadioButtonContents, option, widget);
01576 drawControl(CE_RadioButtonLabel, &bOptTmp, p, widget);
01577
01578
01579 if (flags & State_HasFocus)
01580 {
01581 QRect focusRect = subElementRect(SE_RadioButtonFocusRect, option, widget);
01582 drawKStylePrimitive(WT_RadioButton, Generic::FocusIndicator, option, focusRect,
01583 pal, flags, p, widget);
01584 }
01585 return;
01586 }
01587
01588 case CE_RadioButtonLabel:
01589 {
01590 const QStyleOptionButton* bOpt = qstyleoption_cast<const QStyleOptionButton*>(option);
01591 if (!bOpt) return;
01592
01593 int textShift = 0;
01594
01595 if (!bOpt->icon.isNull())
01596 {
01597 IconOption icoOpt;
01598 icoOpt.icon = bOpt->icon;
01599 icoOpt.active = flags & State_HasFocus;
01600 icoOpt.size = bOpt->iconSize;
01601
01602 QRect iconRect(r.x(), r.y() + (r.height()-bOpt->iconSize.height())/2,
01603 bOpt->iconSize.width(), bOpt->iconSize.height());
01604 drawKStylePrimitive(WT_RadioButton, Generic::Icon, option,
01605 handleRTL(bOpt, iconRect),
01606 pal, flags, p, widget, &icoOpt);
01607
01608 textShift = bOpt->iconSize.width() +
01609 widgetLayoutProp(WT_RadioButton, RadioButton::BoxTextSpace, option, widget);
01610 }
01611
01612 TextOption lbOpt(bOpt->text);
01613 drawKStylePrimitive(WT_RadioButton, Generic::Text, option,
01614 handleRTL(bOpt, r.adjusted(textShift,0,0,0)),
01615 pal, flags, p, widget, &lbOpt);
01616 return;
01617 }
01618
01619
01620
01621
01622 case CE_ProgressBarGroove:
01623 {
01624 drawKStylePrimitive(WT_ProgressBar, ProgressBar::Groove, option, r,
01625 pal, flags, p, widget);
01626 return;
01627 }
01628
01629 case CE_ProgressBarContents:
01630 {
01631 const QStyleOptionProgressBar* pbOpt = qstyleoption_cast<const QStyleOptionProgressBar*>(option);
01632 const QStyleOptionProgressBarV2* pbOpt2 = qstyleoption_cast<const QStyleOptionProgressBarV2*>(option);
01633 if (!pbOpt) return;
01634
01635
01636 double progress = pbOpt->progress - pbOpt->minimum;
01637 int steps = qMax(pbOpt->maximum - pbOpt->minimum, 1);
01638 bool busyIndicator = (pbOpt->minimum == 0 && pbOpt->maximum == 0);
01639 bool horizontal = !pbOpt2 || pbOpt2->orientation == Qt::Horizontal;
01640
01641
01642 if (!progress && ! busyIndicator)
01643 return;
01644
01645
01646 double widthFrac;
01647 if (busyIndicator)
01648 widthFrac = widgetLayoutProp(WT_ProgressBar, ProgressBar::BusyIndicatorSize, option, widget) / 100.0;
01649 else
01650 widthFrac = progress / steps;
01651
01652
01653 int width = qMin(r.width(), (int)(widthFrac * double(r.width())));
01654 int height = qMin(r.height(), (int)(widthFrac * r.height()));
01655
01656 if (busyIndicator)
01657 {
01658 int size = width;
01659 if (!horizontal)
01660 size = height;
01661
01662 if (size > widgetLayoutProp(WT_ProgressBar, ProgressBar::MaxBusyIndicatorSize, option, widget))
01663 size = widgetLayoutProp(WT_ProgressBar, ProgressBar::MaxBusyIndicatorSize, option, widget);
01664
01665
01666 if (size < 1) size = 1;
01667
01668
01669 int remSize = (horizontal ? r.width() : r.height()) - size;
01670 if (remSize <= 0) remSize = 1;
01671
01672 int pstep = int(progress)%(2*remSize);
01673
01674 if (pstep > remSize)
01675 {
01676
01677
01678 pstep = -(pstep - 2*remSize);
01679 }
01680
01681 QRect indicatorRect;
01682 if (horizontal)
01683 indicatorRect = QRect(r.x() + pstep, r.y(), size, r.height());
01684 else
01685 indicatorRect = QRect(r.x(), r.y() + pstep, r.width(), size);
01686 drawKStylePrimitive(WT_ProgressBar, ProgressBar::BusyIndicator, option, handleRTL(option, indicatorRect),
01687 pal, flags, p, widget);
01688 }
01689 else
01690 {
01691 QRect indicatorRect;
01692 if (horizontal)
01693 indicatorRect = QRect(r.x(), r.y(), width, r.height());
01694 else
01695 indicatorRect = QRect(r.x(), r.bottom()-height+1, r.width(), height);
01696 drawKStylePrimitive(WT_ProgressBar, ProgressBar::Indicator, option, handleRTL(option, indicatorRect),
01697 pal, flags, p, widget);
01698 }
01699 return;
01700 }
01701
01702 case CE_ProgressBarLabel:
01703 {
01704 const QStyleOptionProgressBar* pbOpt = qstyleoption_cast<const QStyleOptionProgressBar*>(option);
01705 const QStyleOptionProgressBarV2* pbOpt2 = qstyleoption_cast<const QStyleOptionProgressBarV2*>(option);
01706 if (pbOpt)
01707 {
01708 TextOption lbOpt(pbOpt->text);
01709 bool horizontal = !pbOpt2 || pbOpt2->orientation == Qt::Horizontal;
01710 bool reverseLayout = option->direction == Qt::RightToLeft;
01711
01712 p->save();
01713
01714
01715 if (!horizontal && !reverseLayout)
01716 {
01717 p->translate(r.topRight());
01718 p->rotate(90.0);
01719 }
01720 else if (!horizontal)
01721 {
01722 p->translate(r.bottomLeft());
01723 p->rotate(-90.0);
01724 }
01725
01726 if (useSideText(pbOpt))
01727 {
01728 lbOpt.color = QPalette::ButtonText;
01729
01730
01731 if (option->direction == Qt::LeftToRight)
01732 lbOpt.hAlign = Qt::AlignRight;
01733 else
01734 lbOpt.hAlign = Qt::AlignLeft;
01735
01736
01737 int marWidth = widgetLayoutProp(WT_ProgressBar, ProgressBar::SideTextSpace, option, widget);
01738
01739 drawKStylePrimitive(WT_ProgressBar, Generic::Text, option,
01740 horizontal? r.adjusted(0, marWidth, 0, -marWidth) : QRect(0, marWidth, r.height(), r.width()-marWidth),
01741 pal, flags, p, widget, &lbOpt);
01742 }
01743 else
01744 {
01745 if (pbOpt->textAlignment == Qt::AlignLeft)
01746 lbOpt.hAlign = Qt::AlignHCenter;
01747 else
01748 lbOpt.hAlign = pbOpt->textAlignment;
01749
01750
01751 QRect progressRect;
01752 double progress = pbOpt->progress - pbOpt->minimum;
01753 int steps = qMax(pbOpt->maximum - pbOpt->minimum, 1);
01754 bool busyIndicator = (steps <= 1);
01755
01756 int width;
01757 int height;
01758 if (busyIndicator)
01759 {
01760
01761 width = 0;
01762 height = 0;
01763 }
01764 else
01765 {
01766 double widthFrac = progress / steps;;
01767 width = qMin(r.width(), (int)(widthFrac * r.width()));
01768 height = qMin(r.height(), (int)(widthFrac * r.height()));
01769 }
01770
01771
01772
01773 if (width || height)
01774 {
01775 if (horizontal)
01776 p->setClipRect(handleRTL(option, QRect(r.x(), r.y(), width, r.height())));
01777 else if (!reverseLayout)
01778 p->setClipRect(QRect(r.height()-height, 0, r.height(), r.width()));
01779 else
01780 p->setClipRect(QRect(0, 0, height, r.width()));
01781 lbOpt.color = QPalette::HighlightedText;
01782 drawKStylePrimitive(WT_ProgressBar, Generic::Text, option,
01783 horizontal? r: QRect(0,0,r.height(),r.width()),
01784 pal, flags, p, widget, &lbOpt);
01785
01786 if (horizontal)
01787 p->setClipRect(handleRTL(option, QRect(r.x() + width, r.y(), r.width() - width, r.height())));
01788 else if (!reverseLayout)
01789 p->setClipRect(QRect(0, 0, r.height()-height, r.width()));
01790 else
01791 p->setClipRect(QRect(height, 0, r.height()-height, r.width()));
01792 lbOpt.color = QPalette::ButtonText;
01793 drawKStylePrimitive(WT_ProgressBar, Generic::Text, option,
01794 horizontal? r: QRect(0,0,r.height(),r.width()),
01795 pal, flags, p, widget, &lbOpt);
01796 p->setClipping(false);
01797 }
01798 else
01799 {
01800 lbOpt.color = QPalette::ButtonText;
01801 drawKStylePrimitive(WT_ProgressBar, Generic::Text, option,
01802 horizontal? r: QRect(0,0,r.height(),r.width()),
01803 pal, flags, p, widget, &lbOpt);
01804 }
01805 }
01806 p->restore();
01807 }
01808 return;
01809 }
01810
01811 case CE_MenuBarItem:
01812 {
01813 const QStyleOptionMenuItem* mOpt = ::qstyleoption_cast<const QStyleOptionMenuItem*>(option);
01814 if (!mOpt) return;
01815
01816
01817 drawKStylePrimitive(WT_MenuBarItem, MenuBarItem::Panel, option, r,
01818 pal, flags, p, widget);
01819
01820
01821 QRect textRect = insideMargin(r, WT_MenuBarItem, MenuBarItem::Margin, option, widget);
01822
01823
01824 TextOption lbOpt(mOpt->text);
01825 drawKStylePrimitive(WT_MenuBarItem, Generic::Text, option, textRect,
01826 pal, flags, p, widget, &lbOpt);
01827
01828 return;
01829 }
01830
01831 case CE_MenuBarEmptyArea:
01832 {
01833 drawKStylePrimitive(WT_MenuBar, MenuBar::EmptyArea, option, r,
01834 pal, flags, p, widget);
01835 return;
01836 }
01837
01838 case CE_MenuEmptyArea:
01839 case CE_MenuVMargin:
01840 case CE_MenuHMargin:
01841 {
01842 drawKStylePrimitive(WT_Menu, Menu::Background, option, r,
01843 pal, flags, p, widget);
01844 return;
01845 }
01846
01847 case CE_MenuItem:
01848 {
01849
01850
01851 drawKStylePrimitive(WT_Menu, Menu::Background, option, r,
01852 pal, flags, p, widget);
01853
01854 const QStyleOptionMenuItem* miOpt = ::qstyleoption_cast<const QStyleOptionMenuItem*>(option);
01855 if (!miOpt || miOpt->menuItemType == QStyleOptionMenuItem::EmptyArea) return;
01856
01857
01858 QRect ir = insideMargin(r, WT_MenuItem, MenuItem::Margin, option, widget);
01859
01860
01861
01862
01863 int iconColW = miOpt->maxIconWidth;
01864 iconColW = qMax(iconColW, widgetLayoutProp(WT_MenuItem, MenuItem::IconWidth, option, widget));
01865 int checkColW = widgetLayoutProp(WT_MenuItem, MenuItem::CheckWidth, option, widget);
01866 int checkSpace = widgetLayoutProp(WT_MenuItem, MenuItem::CheckSpace, option, widget);
01867
01868 int leftColW = iconColW;
01869
01870 bool checkAlongsideIcon = (miOpt->menuHasCheckableItems &&
01871 widgetLayoutProp(WT_MenuItem, MenuItem::CheckAlongsideIcon, option, widget) );
01872 if (checkAlongsideIcon)
01873 {
01874 leftColW = checkColW + checkSpace + iconColW;
01875 }
01876
01877
01878 int rightColW = widgetLayoutProp(WT_MenuItem, MenuItem::ArrowSpace, option, widget) +
01879 widgetLayoutProp(WT_MenuItem, MenuItem::ArrowWidth, option, widget);
01880
01881
01882 QRect leftColRect(ir.x(), r.y(), leftColW, r.height());
01883 drawKStylePrimitive(WT_MenuItem, MenuItem::CheckColumn, option, handleRTL(option, leftColRect),
01884 pal, flags, p, widget);
01885
01886
01887 if (miOpt->menuItemType == QStyleOptionMenuItem::Separator)
01888 {
01889 drawKStylePrimitive(WT_MenuItem, MenuItem::Separator, option, ir, pal, flags, p, widget);
01890 return;
01891 }
01892
01893
01894 bool active = (flags & State_Selected);
01895
01896
01897 if (active)
01898 drawKStylePrimitive(WT_MenuItem, MenuItem::ItemIndicator, option, handleRTL(option, r), pal, flags, p, widget);
01899
01900
01901 ColorMode textColor = (flags & State_Enabled) ? (widgetLayoutProp(WT_MenuItem, active ?
01902 MenuItem::ActiveTextColor :
01903 MenuItem::TextColor, option, widget))
01904 : (widgetLayoutProp(WT_MenuItem, active ?
01905 MenuItem::ActiveDisabledTextColor:
01906 MenuItem::DisabledTextColor, option, widget));
01907
01908
01909 leftColRect = QRect(ir.x(), ir.y(), leftColW, ir.height());
01910
01911 if (!checkAlongsideIcon && !miOpt->icon.isNull() )
01912 {
01913
01914 if (miOpt->checked)
01915 {
01916 drawKStylePrimitive(WT_MenuItem, MenuItem::CheckIcon,
01917 option, handleRTL(option, leftColRect), pal, flags,
01918 p, widget);
01919 }
01920 }
01921 else
01922 {
01923
01924 QRect checkColRect;
01925 if (checkAlongsideIcon)
01926 {
01927 checkColRect = QRect(leftColRect.x(), leftColRect.y(),
01928 checkColW, leftColRect.height() );
01929 }
01930 else
01931 {
01932 checkColRect = leftColRect;
01933 }
01934
01935 bool checked = miOpt->checked;
01936 if (miOpt->checkType == QStyleOptionMenuItem::NonExclusive)
01937 {
01938 drawKStylePrimitive(WT_MenuItem, checked ? MenuItem::CheckOn : MenuItem::CheckOff,
01939 option, handleRTL(option, checkColRect), pal, flags,
01940 p, widget);
01941 }
01942 else if (miOpt->checkType == QStyleOptionMenuItem::Exclusive)
01943 {
01944 drawKStylePrimitive(WT_MenuItem, checked ? MenuItem::RadioOn : MenuItem::RadioOff,
01945 option, handleRTL(option, checkColRect), pal, flags,
01946 p, widget);
01947 }
01948 }
01949
01950 if (!miOpt->icon.isNull())
01951 {
01952 int iconSize = pixelMetric(PM_SmallIconSize);
01953
01954 QRect iconColRect;
01955 if (checkAlongsideIcon)
01956 {
01957 iconColRect = QRect(leftColRect.x()+checkColW+checkSpace, leftColRect.y(),
01958 leftColRect.width()-(checkColW+checkSpace), leftColRect.height() );
01959 }
01960 else
01961 {
01962 iconColRect = leftColRect;
01963 }
01964 IconOption icoOpt;
01965 icoOpt.icon = miOpt->icon;
01966 icoOpt.active = flags & State_Selected;
01967 drawKStylePrimitive(WT_MenuItem, Generic::Icon, option,
01968 handleRTL(option, centerRect(iconColRect, iconSize, iconSize)),
01969 pal, flags, p, widget, &icoOpt);
01970 }
01971
01972
01973 leftColW += widgetLayoutProp(WT_MenuItem, MenuItem::IconSpace, option, widget);
01974
01975
01976 QString text = miOpt->text;
01977 QRect textRect = QRect(ir.x() + leftColW, ir.y(), ir.width() - leftColW - rightColW, ir.height());
01978 QFont font = miOpt->font;
01979 const QFont oldFont = p->font();
01980
01981 p->setFont(font);
01982 int tabPos = miOpt->text.indexOf(QLatin1Char('\t'));
01983 if (tabPos != -1)
01984 {
01985 text = miOpt->text.left(tabPos);
01986 QString accl = miOpt->text.mid (tabPos + 1);
01987
01988
01989 TextOption lbOpt(accl);
01990 lbOpt.color = textColor;
01991 lbOpt.hAlign = Qt::AlignRight;
01992 drawKStylePrimitive(WT_MenuItem, Generic::Text, option, handleRTL(option, textRect),
01993 pal, flags, p, widget, &lbOpt);
01994 }
01995
01996
01997 TextOption lbOpt(text);
01998 lbOpt.color = textColor;
01999 drawKStylePrimitive(WT_MenuItem, Generic::Text, option, handleRTL(option, textRect),
02000 pal, flags, p, widget, &lbOpt);
02001
02002 p->setFont(oldFont);
02003
02004
02005 if (miOpt->menuItemType == QStyleOptionMenuItem::SubMenu)
02006 {
02007 ColorOption arrowColor;
02008 arrowColor.color = textColor;
02009
02010 int aw = widgetLayoutProp(WT_MenuItem, MenuItem::ArrowWidth, option, widget);
02011
02012 QRect arrowRect(ir.x() + ir.width() - aw, ir.y(), aw, ir.height());
02013 drawKStylePrimitive(WT_MenuItem, option->direction == Qt::LeftToRight ?
02014 Generic::ArrowRight : Generic::ArrowLeft,
02015 option, handleRTL(option, arrowRect), pal, flags, p, widget, &arrowColor);
02016 }
02017
02018 return;
02019 }
02020
02021 case CE_ScrollBarAddLine:
02022 case CE_ScrollBarSubLine:
02023 {
02024 const QStyleOptionSlider* slOpt = ::qstyleoption_cast<const QStyleOptionSlider*>(option);
02025 if (!slOpt) return;
02026
02027
02028 r = internalSubControlRect(CC_ScrollBar, slOpt,
02029 element == CE_ScrollBarAddLine ? SC_ScrollBarAddLine : SC_ScrollBarSubLine, widget);
02030 const_cast<QStyleOption*>(option)->rect = r;
02031
02032
02033 bool doubleButton = false;
02034
02035
02036 if (element == CE_ScrollBarAddLine && widgetLayoutProp(WT_ScrollBar, ScrollBar::DoubleBotButton, option, widget))
02037 doubleButton = true;
02038 if (element == CE_ScrollBarSubLine && widgetLayoutProp(WT_ScrollBar, ScrollBar::DoubleTopButton, option, widget))
02039 doubleButton = true;
02040
02041 if (doubleButton)
02042 {
02043 if (flags & State_Horizontal)
02044 {
02045 DoubleButtonOption::ActiveButton ab = DoubleButtonOption::None;
02046
02047
02048 bool leftAdds, rightAdds;
02049 if (slOpt->direction == Qt::LeftToRight)
02050 {
02051 leftAdds = false;
02052 rightAdds = true;
02053 }
02054 else
02055 {
02056 leftAdds = true;
02057 rightAdds = false;
02058 }
02059
02060
02061 if (flags & State_Sunken)
02062 {
02063 if (((slOpt->activeSubControls & SC_ScrollBarAddLine) && leftAdds) ||
02064 ((slOpt->activeSubControls & SC_ScrollBarSubLine) && !leftAdds))
02065 ab = DoubleButtonOption::Left;
02066
02067 if (((slOpt->activeSubControls & SC_ScrollBarAddLine) && rightAdds) ||
02068 ((slOpt->activeSubControls & SC_ScrollBarSubLine) && !rightAdds))
02069 ab = DoubleButtonOption::Right;
02070 }
02071
02072 DoubleButtonOption bOpt(ab);
02073 drawKStylePrimitive(WT_ScrollBar, ScrollBar::DoubleButtonHor,
02074 option, r, pal, flags, p, widget, &bOpt);
02075
02076
02077 QRect leftSubButton = QRect(r.x(), r.y(), r.width()/2, r.height());
02078
02079 ColorOption colOpt;
02080 colOpt.color = widgetLayoutProp(WT_ScrollBar, ScrollBar::ArrowColor, option, widget);
02081 if (ab == DoubleButtonOption::Left)
02082 colOpt.color = widgetLayoutProp(WT_ScrollBar, ScrollBar::ActiveArrowColor, option, widget);
02083
02084 drawKStylePrimitive(WT_ScrollBar, Generic::ArrowLeft, option, leftSubButton, pal,
02085 flags, p, widget, &colOpt);
02086
02087
02088 QRect rightSubButton;
02089 rightSubButton.setBottomRight(r.bottomRight());
02090 rightSubButton.setLeft (leftSubButton.right() + 1);
02091 rightSubButton.setTop (r.top());
02092
02093
02094 colOpt.color = widgetLayoutProp(WT_ScrollBar, ScrollBar::ArrowColor, option, widget);
02095 if (ab == DoubleButtonOption::Right)
02096 colOpt.color = widgetLayoutProp(WT_ScrollBar, ScrollBar::ActiveArrowColor, option, widget);
02097
02098 drawKStylePrimitive(WT_ScrollBar, Generic::ArrowRight, option, rightSubButton, pal,
02099 flags, p, widget, &colOpt);
02100 }
02101 else
02102 {
02103 DoubleButtonOption::ActiveButton ab = DoubleButtonOption::None;
02104
02105
02106
02107
02108 if (flags & State_Sunken)
02109 {
02110 if (slOpt->activeSubControls & SC_ScrollBarSubLine)
02111 ab = DoubleButtonOption::Top;
02112
02113 if (slOpt->activeSubControls & SC_ScrollBarAddLine)
02114 ab = DoubleButtonOption::Bottom;
02115 }
02116
02117
02118 DoubleButtonOption bOpt(ab);
02119 drawKStylePrimitive(WT_ScrollBar, ScrollBar::DoubleButtonVert,
02120 option, r, pal, flags, p, widget, &bOpt);
02121
02122
02123 ColorOption colOpt;
02124 colOpt.color = widgetLayoutProp(WT_ScrollBar, ScrollBar::ArrowColor, option, widget);
02125
02126 if (ab == DoubleButtonOption::Top)
02127 colOpt.color = widgetLayoutProp(WT_ScrollBar, ScrollBar::ActiveArrowColor, option, widget);
02128
02129
02130 QRect topSubButton = QRect(r.x(), r.y(), r.width(), r.height()/2);
02131 drawKStylePrimitive(WT_ScrollBar, Generic::ArrowUp, option, topSubButton, pal,
02132 flags, p, widget, &colOpt);
02133
02134
02135 QRect botSubButton;
02136 botSubButton.setBottomRight(r.bottomRight());
02137 botSubButton.setLeft (r.left());
02138 botSubButton.setTop (topSubButton.bottom() + 1);
02139
02140 colOpt.color = widgetLayoutProp(WT_ScrollBar, ScrollBar::ArrowColor, option, widget);
02141
02142 if (ab == DoubleButtonOption::Bottom)
02143 colOpt.color = widgetLayoutProp(WT_ScrollBar, ScrollBar::ActiveArrowColor, option, widget);
02144
02145 drawKStylePrimitive(WT_ScrollBar, Generic::ArrowDown, option, botSubButton, pal,
02146 flags, p, widget, &colOpt);
02147 }
02148 }
02149 else
02150 {
02151 if (flags & State_Horizontal)
02152 {
02153 drawKStylePrimitive(WT_ScrollBar, ScrollBar::SingleButtonHor,
02154 option, r, pal, flags, p, widget);
02155
02156 int primitive;
02157 bool active = false;
02158
02159 if (element == CE_ScrollBarAddLine)
02160 {
02161 if (slOpt->direction == Qt::LeftToRight)
02162 primitive = Generic::ArrowRight;
02163 else
02164 primitive = Generic::ArrowLeft;
02165
02166 if ((slOpt->activeSubControls & SC_ScrollBarAddLine) && (flags & State_Sunken))
02167 active = true;
02168 }
02169 else
02170 {
02171 if (slOpt->direction == Qt::LeftToRight)
02172 primitive = Generic::ArrowLeft;
02173 else
02174 primitive = Generic::ArrowRight;
02175
02176 if ((slOpt->activeSubControls & SC_ScrollBarSubLine) && (flags & State_Sunken))
02177 active = true;
02178 }
02179
02180 ColorOption colOpt;
02181 colOpt.color = widgetLayoutProp(WT_ScrollBar, ScrollBar::ArrowColor, option, widget);
02182 if (active)
02183 colOpt.color = widgetLayoutProp(WT_ScrollBar, ScrollBar::ActiveArrowColor, option, widget);
02184
02185 drawKStylePrimitive(WT_ScrollBar, primitive, option, r, pal,
02186 flags, p, widget, &colOpt);
02187 }
02188 else
02189 {
02190 drawKStylePrimitive(WT_ScrollBar, ScrollBar::SingleButtonVert,
02191 option, r, pal, flags, p, widget);
02192
02193 int primitive;
02194 bool active = false;
02195
02196 if (element == CE_ScrollBarAddLine)
02197 {
02198 primitive = Generic::ArrowDown;
02199 if ((slOpt->activeSubControls & SC_ScrollBarAddLine) && (flags & State_Sunken))
02200 active = true;
02201 }
02202 else
02203 {
02204 primitive = Generic::ArrowUp;
02205 if ((slOpt->activeSubControls & SC_ScrollBarSubLine) && (flags & State_Sunken))
02206 active = true;
02207 }
02208
02209 ColorOption colOpt;
02210 colOpt.color = widgetLayoutProp(WT_ScrollBar, ScrollBar::ArrowColor, option, widget);
02211 if (active)
02212 colOpt.color = widgetLayoutProp(WT_ScrollBar, ScrollBar::ActiveArrowColor, option, widget);
02213
02214 drawKStylePrimitive(WT_ScrollBar, primitive, option, r, pal,
02215 flags, p, widget, &colOpt);
02216 }
02217 }
02218 return;
02219 }
02220
02221
02222
02223
02224
02225 case CE_ScrollBarSlider:
02226 {
02227 drawKStylePrimitive(WT_ScrollBar,
02228 (flags & State_Horizontal) ? ScrollBar::SliderHor :
02229 ScrollBar::SliderVert,
02230 option, r, pal, flags, p, widget);
02231 return;
02232 }
02233
02234 case CE_ScrollBarAddPage:
02235 {
02236 const QStyleOptionSlider* slOpt = ::qstyleoption_cast<const QStyleOptionSlider*>(option);
02237 if (!slOpt) return;
02238
02239 if (flags & State_Horizontal)
02240 drawKStylePrimitive(WT_ScrollBar,
02241 (slOpt->direction == Qt::LeftToRight) ? ScrollBar::GrooveAreaHorRight :
02242 ScrollBar::GrooveAreaHorLeft,
02243 option, r, pal, flags, p, widget);
02244 else
02245 drawKStylePrimitive(WT_ScrollBar, ScrollBar::GrooveAreaVertBottom,
02246 option, r, pal, flags, p, widget);
02247 return;
02248 }
02249
02250 case CE_ScrollBarSubPage:
02251 {
02252 const QStyleOptionSlider* slOpt = ::qstyleoption_cast<const QStyleOptionSlider*>(option);
02253 if (!slOpt) return;
02254
02255 if (flags & State_Horizontal)
02256 drawKStylePrimitive(WT_ScrollBar,
02257 (slOpt->direction == Qt::LeftToRight) ? ScrollBar::GrooveAreaHorLeft :
02258 ScrollBar::GrooveAreaHorRight,
02259 option, r, pal, flags, p, widget);
02260 else
02261 drawKStylePrimitive(WT_ScrollBar, ScrollBar::GrooveAreaVertTop,
02262 option, r, pal, flags, p, widget);
02263 return;
02264 }
02265
02266
02267
02268 case CE_TabBarTabShape:
02269 {
02270 const QStyleOptionTab* tabOpt = qstyleoption_cast<const QStyleOptionTab*>(option);
02271 if (!tabOpt) return;
02272
02273
02274 int tabOverlap = pixelMetric(PM_TabBarTabOverlap, option, widget);
02275 bool beginning = tabOpt->position == QStyleOptionTab::Beginning;
02276 bool onlyOne = tabOpt->position == QStyleOptionTab::OnlyOneTab;
02277 if (!beginning && !onlyOne) {
02278 switch (tabSide(tabOpt)) {
02279 case North:
02280 case South:
02281 if (option->direction == Qt::LeftToRight)
02282 r.adjust(-tabOverlap, 0, 0, 0);
02283 else
02284 r.adjust(0, 0, tabOverlap, 0);
02285 break;
02286 case East:
02287 case West:
02288 r.adjust(0, -tabOverlap, 0, 0);
02289 default:
02290 break;
02291 }
02292 }
02293
02294 int prim;
02295 switch (tabSide(tabOpt))
02296 {
02297 case North:
02298 prim = TabBar::NorthTab; break;
02299 case South:
02300 prim = TabBar::SouthTab; break;
02301 case East:
02302 prim = TabBar::EastTab; break;
02303 default:
02304 prim = TabBar::WestTab; break;
02305 }
02306
02307 drawKStylePrimitive(WT_TabBar, prim, option, r, pal, flags, p, widget);
02308
02309 return;
02310 }
02311
02312 case CE_TabBarTabLabel:
02313 {
02314 const QStyleOptionTab* tabOpt = qstyleoption_cast<const QStyleOptionTab*>(option);
02315 if (!tabOpt) return;
02316
02317
02318 QRect labelRect = subElementRect(SE_TabBarTabText, option, widget);
02319
02320 Side tabSd = tabSide(tabOpt);
02321
02322
02323
02324 if (!tabOpt->icon.isNull())
02325 {
02326 QStyleOptionTabV3 tabV3(*tabOpt);
02327 QSize iconSize = tabV3.iconSize;
02328 if (!iconSize.isValid()) {
02329 int iconExtent = pixelMetric(PM_SmallIconSize);
02330 iconSize = QSize(iconExtent, iconExtent);
02331 }
02332
02333 IconOption icoOpt;
02334 icoOpt.icon = tabOpt->icon;
02335 icoOpt.active = flags & State_Selected;
02336 icoOpt.size = iconSize;
02337
02338 if (tabOpt->text.isNull())
02339 {
02340
02341 drawKStylePrimitive(WT_TabBar, Generic::Icon, option, labelRect,
02342 pal, flags, p, widget, &icoOpt);
02343 return;
02344 }
02345
02346
02347 QRect iconRect;
02348
02349 if (tabSd == North || tabSd == South)
02350 {
02351
02352
02353
02354 if (tabOpt->direction == Qt::LeftToRight)
02355 {
02356
02357 iconRect = QRect(labelRect.x(), labelRect.y() + (labelRect.height() - iconSize.height() + 1) / 2,
02358 iconSize.width(), iconSize.height());
02359
02360
02361 labelRect.setLeft(labelRect.x() + iconSize.width() +
02362 widgetLayoutProp(WT_TabBar, TabBar::TabTextToIconSpace, option, widget));
02363 }
02364 else
02365 {
02366
02367 iconRect = QRect(labelRect.x() + labelRect.width() - iconSize.width(),
02368 labelRect.y() + (labelRect.height() - iconSize.height() + 1) / 2, iconSize.width(), iconSize.height());
02369
02370 labelRect.setWidth(labelRect.width() - iconSize.width() -
02371 widgetLayoutProp(WT_TabBar, TabBar::TabTextToIconSpace, option, widget));
02372 }
02373 }
02374 else
02375 {
02376 bool aboveIcon = false;
02377 if (tabSd == West && tabOpt->direction == Qt::RightToLeft)
02378 aboveIcon = true;
02379 if (tabSd == East && tabOpt->direction == Qt::LeftToRight)
02380 aboveIcon = true;
02381
02382 if (aboveIcon)
02383 {
02384 iconRect = QRect(labelRect.x() + (labelRect.width() - iconSize.width() + 1) / 2, labelRect.y(),
02385 iconSize.width(), iconSize.height());
02386 labelRect.setTop(labelRect.y() + iconSize.height() +
02387 widgetLayoutProp(WT_TabBar, TabBar::TabTextToIconSpace, option, widget));
02388 }
02389 else
02390 {
02391 iconRect = QRect(labelRect.x() + (labelRect.width() - iconSize.width() + 1) / 2,
02392 labelRect.y() + labelRect.height() - iconSize.height(),
02393 iconSize.width(), iconSize.height());
02394 labelRect.setHeight(labelRect.height() - iconSize.height() -
02395 widgetLayoutProp(WT_TabBar, TabBar::TabTextToIconSpace, option, widget));
02396 }
02397 }
02398
02399
02400 drawKStylePrimitive(WT_TabBar, Generic::Icon, option, iconRect,
02401 pal, flags, p, widget, &icoOpt);
02402 }
02403
02404
02405 if (!tabOpt->text.isNull())
02406 {
02407 TextOption lbOpt(tabOpt->text);
02408 if (widget)
02409 lbOpt.color = widget->foregroundRole();
02410
02411 int primitive = Generic::Text;
02412
02413 if (tabSd == East)
02414 primitive = TabBar::EastText;
02415 else if (tabSd == West)
02416 primitive = TabBar::WestText;
02417
02418 drawKStylePrimitive(WT_TabBar, primitive, option, labelRect,
02419 pal, flags, p, widget, &lbOpt);
02420 }
02421
02422
02423 if (tabOpt->state & State_HasFocus)
02424 {
02425 QRect focusRect = marginAdjustedTab(tabOpt, TabBar::TabFocusMargin);
02426 drawKStylePrimitive(WT_TabBar, Generic::FocusIndicator, option, focusRect,
02427 pal, flags, p, widget);
02428 }
02429 return;
02430 }
02431
02432 case CE_ToolBar:
02433 {
02434 if (flags & State_Horizontal)
02435 drawKStylePrimitive(WT_ToolBar, ToolBar::PanelHor,option,r,pal,flags,p,widget);
02436 else
02437 drawKStylePrimitive(WT_ToolBar, ToolBar::PanelVert,option,r,pal,flags,p,widget);
02438
02439 return;
02440 }
02441
02442 case CE_HeaderSection:
02443 {
02444 if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
02445 drawKStylePrimitive(WT_Header, (header->orientation==Qt::Horizontal)?Header::SectionHor:Header::SectionVert,
02446 option, r, pal, flags, p, widget);
02447 return;
02448 }
02449 }
02450
02451 case CE_HeaderLabel:
02452 {
02453 if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
02454 QRect textRect = r;
02455 if (!header->icon.isNull()) {
02456 bool enabled = flags & State_Enabled;
02457 QPixmap pm = header->icon.pixmap(pixelMetric(PM_SmallIconSize), enabled?QIcon::Normal:QIcon::Disabled);
02458
02459
02460 bool reverseLayout = header->direction == Qt::RightToLeft;
02461 int iy = r.top()+(r.height()-pm.height())/2;
02462 int ix = reverseLayout ? r.right()-pm.width() : r.left();
02463 QRect iconRect = QRect(ix, iy, pm.width(), pm.height() );
02464
02465 IconOption iconOpt;
02466 iconOpt.icon = pm;
02467 drawKStylePrimitive(WT_Header, Generic::Icon, option, iconRect, pal, flags, p, widget, &iconOpt);
02468
02469
02470 int spacing = widgetLayoutProp(WT_Header, Header::TextToIconSpace, option, widget);
02471 if (reverseLayout)
02472 {
02473 textRect.setRight(r.right()-iconRect.width()-spacing );
02474 }
02475 else
02476 {
02477 textRect.setLeft(r.x()+iconRect.width()+spacing );
02478 }
02479 }
02480
02481 TextOption lbOpt(header->text);
02482 lbOpt.hAlign = header->textAlignment;
02483 drawKStylePrimitive(WT_Header, Generic::Text, option, textRect, pal, flags, p, widget, &lbOpt);
02484 }
02485 return;
02486 }
02487
02488 case CE_Splitter:
02489 {
02490 if (flags&State_Horizontal)
02491 drawKStylePrimitive(WT_Splitter, Splitter::HandleHor, option, r, pal, flags, p, widget);
02492 else
02493 drawKStylePrimitive(WT_Splitter, Splitter::HandleVert, option, r, pal, flags, p, widget);
02494 return;
02495 }
02496
02497 default:
02498 break;
02499 }
02500
02501 QCommonStyle::drawControl(element, option, p, widget);
02502 }
02503
02504
02505 int KStyle::styleHint (StyleHint hint, const QStyleOption* option, const QWidget* widget, QStyleHintReturn* returnData) const
02506 {
02507 switch (hint)
02508 {
02509 case SH_MenuBar_MouseTracking:
02510 case SH_Menu_MouseTracking:
02511 return true;
02512
02513 case SH_TitleBar_NoBorder:
02514 return widgetLayoutProp(WT_Window, Window::NoTitleFrame, option, widget);
02515
02516 case SH_GroupBox_TextLabelVerticalAlignment:
02517 if (widgetLayoutProp(WT_GroupBox, GroupBox::TextAlignTop, option, widget) )
02518 return Qt::AlignTop;
02519 else
02520 return Qt::AlignVCenter;
02521
02522 case SH_GroupBox_TextLabelColor:
02523 {
02524 ColorMode cm( widgetLayoutProp(WT_GroupBox, GroupBox::TitleTextColor,
02525 option, widget) );
02526 return cm.color(option ? option->palette : qApp->palette()).rgba();
02527 }
02528
02529 case SH_DialogButtonLayout:
02530 return QDialogButtonBox::KdeLayout;
02531
02532 case SH_ScrollBar_MiddleClickAbsolutePosition:
02533 return true;
02534
02535
02536 case SH_ItemView_ShowDecorationSelected:
02537 return false;
02538
02539 case SH_ItemView_ActivateItemOnSingleClick:
02540 return d->m_componentData.config()->group("KDE").readEntry("SingleClick", KDE_DEFAULT_SINGLECLICK );
02541 case SH_KCustomStyleElement:
02542 if (!widget)
02543 return 0;
02544 return d->styleElements.value(widget->objectName(), 0);
02545
02546
02547 case SH_FormLayoutFormAlignment:
02548 return Qt::AlignLeft | Qt::AlignTop;
02549
02550
02551 case SH_FormLayoutLabelAlignment:
02552 return Qt::AlignRight;
02553
02554 case SH_FormLayoutFieldGrowthPolicy:
02555 return QFormLayout::ExpandingFieldsGrow;
02556
02557 case SH_FormLayoutWrapPolicy:
02558 return QFormLayout::DontWrapRows;
02559
02560 case SH_MessageBox_TextInteractionFlags:
02561 return true;
02562
02563 case SH_DialogButtonBox_ButtonsHaveIcons:
02564 return KGlobalSettings::showIconsOnPushButtons();
02565
02566 default:
02567 break;
02568 };
02569
02570 return QCommonStyle::styleHint(hint, option, widget, returnData);
02571 }
02572
02573 int KStyle::pixelMetric(PixelMetric metric, const QStyleOption* option, const QWidget* widget) const
02574 {
02575 switch (metric)
02576 {
02577 case PM_DefaultFrameWidth:
02578 if (qstyleoption_cast<const QStyleOptionGroupBox *>(option) )
02579 return widgetLayoutProp(WT_GroupBox, GroupBox::FrameWidth, option, widget);
02580 else
02581 return widgetLayoutProp(WT_Generic, Generic::DefaultFrameWidth, option, widget);
02582
02583 case PM_DefaultChildMargin:
02584 case PM_DefaultTopLevelMargin:
02585 return widgetLayoutProp(WT_Generic, Generic::DefaultLayoutMargin, option, widget);
02586
02587 case PM_LayoutHorizontalSpacing:
02588 case PM_LayoutVerticalSpacing:
02589
02590 return -1;
02591
02592 case PM_DefaultLayoutSpacing:
02593 return widgetLayoutProp(WT_Generic, Generic::DefaultLayoutSpacing, option, widget);
02594
02595 case PM_LayoutLeftMargin:
02596 case PM_LayoutTopMargin:
02597 case PM_LayoutRightMargin:
02598 case PM_LayoutBottomMargin:
02599 {
02600 PixelMetric marginMetric;
02601 if ((option && (option->state & QStyle::State_Window))
02602 || (widget && widget->isWindow())) {
02603 marginMetric = PM_DefaultTopLevelMargin;
02604 } else {
02605 marginMetric = PM_DefaultChildMargin;
02606 }
02607 return pixelMetric(marginMetric, option, widget);
02608 }
02609
02610 case PM_ButtonMargin:
02611 return 0;
02612
02613 case PM_ButtonDefaultIndicator:
02614
02615
02616
02617 return widgetLayoutProp(WT_PushButton, PushButton::DefaultIndicatorMargin, option, widget);
02618 case PM_ButtonShiftHorizontal:
02619 return widgetLayoutProp(WT_PushButton, PushButton::PressedShiftHorizontal, option, widget);
02620 case PM_ButtonShiftVertical:
02621 return widgetLayoutProp(WT_PushButton, PushButton::PressedShiftVertical, option, widget);
02622 case PM_MenuButtonIndicator:
02623 if (qstyleoption_cast<const QStyleOptionToolButton*>(option))
02624 return widgetLayoutProp(WT_ToolButton, ToolButton::MenuIndicatorSize, option, widget);
02625 else
02626 return widgetLayoutProp(WT_PushButton, PushButton::MenuIndicatorSize, option, widget);
02627
02628 case PM_SplitterWidth:
02629 return widgetLayoutProp(WT_Splitter, Splitter::Width, option, widget);
02630
02631 case PM_IndicatorWidth:
02632 case PM_IndicatorHeight:
02633 return widgetLayoutProp(WT_CheckBox, CheckBox::Size, option, widget);
02634
02635 case PM_ExclusiveIndicatorWidth:
02636 case PM_ExclusiveIndicatorHeight:
02637 return widgetLayoutProp(WT_RadioButton, RadioButton::Size, option, widget);
02638
02639 case PM_DockWidgetFrameWidth:
02640 return widgetLayoutProp(WT_DockWidget, DockWidget::FrameWidth, option, widget);
02641
02642 case PM_DockWidgetSeparatorExtent:
02643 return widgetLayoutProp(WT_DockWidget, DockWidget::SeparatorExtent, option, widget);
02644
02645
02646
02647
02648 case PM_DockWidgetTitleMargin:
02649 return widgetLayoutProp(WT_DockWidget, DockWidget::TitleMargin, option, widget);
02650
02651 case PM_ProgressBarChunkWidth:
02652 return widgetLayoutProp(WT_ProgressBar, ProgressBar::Precision, option, widget);
02653
02654 case PM_MenuBarPanelWidth:
02655 return 0;
02656
02657 case PM_MenuBarHMargin:
02658 {
02659
02660
02661 int spaceL = widgetLayoutProp(WT_MenuBar, MenuBar::Margin, option, widget) + widgetLayoutProp(WT_MenuBar, MenuBar::Margin + Left, option, widget);
02662
02663 return spaceL;
02664 }
02665
02666 case PM_MenuBarVMargin:
02667 {
02668
02669 int spaceT = widgetLayoutProp(WT_MenuBar, MenuBar::Margin, option, widget) + widgetLayoutProp(WT_MenuBar, MenuBar::Margin + Top, option, widget);
02670 return spaceT;
02671 }
02672
02673 case PM_MenuBarItemSpacing:
02674 return widgetLayoutProp(WT_MenuBar, MenuBar::ItemSpacing, option, widget);
02675
02676 case PM_MenuDesktopFrameWidth:
02677 return 0;
02678
02679 case PM_MenuPanelWidth:
02680 return widgetLayoutProp(WT_Menu, Menu::FrameWidth, option, widget);
02681
02682
02683
02684
02685
02686
02687
02688
02689
02690
02691
02692
02693
02694
02695
02696
02697
02698
02699
02700
02701 case PM_MenuScrollerHeight:
02702 return widgetLayoutProp(WT_Menu, Menu::ScrollerHeight, option, widget);
02703
02704 case PM_MenuTearoffHeight:
02705 return widgetLayoutProp(WT_Menu, Menu::TearOffHeight, option, widget);
02706
02707 case PM_TabBarTabHSpace:
02708 {
02709 const QStyleOptionTab* tabOpt = qstyleoption_cast<const QStyleOptionTab*>(option);
02710 if (tabOpt)
02711 {
02712
02713 if (tabOpt->text.isNull() && !tabOpt->icon.isNull())
02714 return 0;
02715 if (tabOpt->icon.isNull() && !tabOpt->text.isNull())
02716 return 0;
02717 }
02718
02719 return widgetLayoutProp(WT_TabBar, TabBar::TabTextToIconSpace, option, widget);
02720 }
02721
02722 case PM_TabBarTabVSpace:
02723 return 0;
02724
02725 case PM_TabBarBaseHeight:
02726 return widgetLayoutProp(WT_TabBar, TabBar::BaseHeight, option, widget);
02727
02728 case PM_TabBarBaseOverlap:
02729 return widgetLayoutProp(WT_TabBar, TabBar::BaseOverlap, option, widget);
02730
02731 case PM_TabBarTabOverlap:
02732 return widgetLayoutProp(WT_TabBar, TabBar::TabOverlap, option, widget);
02733
02734 case PM_TabBarScrollButtonWidth:
02735 return widgetLayoutProp(WT_TabBar, TabBar::ScrollButtonWidth, option, widget);
02736
02737 case PM_TabBarTabShiftVertical:
02738 return 1;
02739
02740 case PM_TabBarTabShiftHorizontal:
02741 return 0;
02742
02743 case PM_SliderControlThickness:
02744 return widgetLayoutProp(WT_Slider, Slider::HandleThickness, option, widget);
02745
02746 case PM_SliderLength:
02747 return widgetLayoutProp(WT_Slider, Slider::HandleLength, option, widget);
02748
02749 case PM_SliderThickness:
02750 {
02751
02752 return widgetLayoutProp(WT_Slider, Slider::HandleThickness, option, widget);
02753 }
02754
02755 case PM_SpinBoxFrameWidth:
02756 return widgetLayoutProp(WT_SpinBox, SpinBox::FrameWidth, option, widget);
02757
02758 case PM_ComboBoxFrameWidth:
02759 return widgetLayoutProp(WT_ComboBox, ComboBox::FrameWidth, option, widget);
02760
02761 case PM_HeaderMarkSize:
02762 return widgetLayoutProp(WT_Header, Header::MarkSize, option, widget);
02763
02764 case PM_HeaderMargin:
02765 return widgetLayoutProp(WT_Header, Header::TextToIconSpace, option, widget);
02766
02767 case PM_ToolBarFrameWidth:
02768 return widgetLayoutProp(WT_ToolBar, ToolBar::FrameWidth, option, widget);
02769
02770 case PM_ToolBarHandleExtent:
02771 return widgetLayoutProp(WT_ToolBar, ToolBar::HandleExtent, option, widget);
02772
02773 case PM_ToolBarSeparatorExtent:
02774 return widgetLayoutProp(WT_ToolBar, ToolBar::SeparatorExtent, option, widget);
02775
02776 case PM_ToolBarExtensionExtent:
02777 return widgetLayoutProp(WT_ToolBar, ToolBar::ExtensionExtent, option, widget);
02778
02779 case PM_ToolBarItemMargin:
02780 return widgetLayoutProp(WT_ToolBar, ToolBar::ItemMargin, option, widget);
02781
02782 case PM_ToolBarItemSpacing:
02783 return widgetLayoutProp(WT_ToolBar, ToolBar::ItemSpacing, option, widget);
02784
02785 case PM_ScrollBarExtent:
02786 return widgetLayoutProp(WT_ScrollBar, ScrollBar::BarWidth, option, widget);
02787
02788 case PM_TitleBarHeight:
02789 return widgetLayoutProp(WT_Window, Window::TitleHeight, option, widget);
02790
02791 default:
02792 break;
02793 }
02794
02795 return QCommonStyle::pixelMetric(metric, option, widget);
02796 }
02797
02798 int KStyle::layoutSpacingImplementation(QSizePolicy::ControlType control1, QSizePolicy::ControlType control2, Qt::Orientation orientation, const QStyleOption *option, const QWidget *widget) const
02799 {
02800 Q_UNUSED(control1); Q_UNUSED(control2); Q_UNUSED(orientation);
02801
02802 return pixelMetric(PM_DefaultLayoutSpacing, option, widget);
02803 }
02804
02805
02806 bool KStyle::isVerticalTab(const QStyleOptionTab* tbOpt) const
02807 {
02808 switch (tbOpt->shape)
02809 {
02810 case QTabBar::RoundedWest:
02811 case QTabBar::RoundedEast:
02812 case QTabBar::TriangularWest:
02813 case QTabBar::TriangularEast:
02814 return true;
02815 default:
02816 return false;
02817 }
02818 }
02819
02820 bool KStyle::isReflectedTab(const QStyleOptionTab* tbOpt) const
02821 {
02822 switch (tbOpt->shape)
02823 {
02824 case QTabBar::RoundedEast:
02825 case QTabBar::TriangularEast:
02826 case QTabBar::RoundedSouth:
02827 case QTabBar::TriangularSouth:
02828 return true;
02829 default:
02830 return false;
02831 }
02832 }
02833
02834 KStyle::Side KStyle::tabSide(const QStyleOptionTab* tbOpt) const
02835 {
02836 switch (tbOpt->shape)
02837 {
02838 case QTabBar::RoundedEast:
02839 case QTabBar::TriangularEast:
02840 return East;
02841 case QTabBar::RoundedWest:
02842 case QTabBar::TriangularWest:
02843 return West;
02844 case QTabBar::RoundedNorth:
02845 case QTabBar::TriangularNorth:
02846 return North;
02847 default:
02848 return South;
02849 }
02850 }
02851
02852 QRect KStyle::marginAdjustedTab(const QStyleOptionTab* tabOpt, int property) const
02853 {
02854 QRect r = tabOpt->rect;
02855
02856
02857
02858 bool vertical = isVerticalTab (tabOpt);
02859 bool flip = isReflectedTab(tabOpt);
02860
02861 QRect idializedGeometry = vertical ? QRect(0, 0, r.height(), r.width())
02862 : QRect(0, 0, r.width(), r.height());
02863
02864 QRect contentArea = insideMargin(idializedGeometry, WT_TabBar, property, tabOpt, 0);
02865
02866 int leftMargin = contentArea.x();
02867 int rightMargin = idializedGeometry.width() - 1 - contentArea.right();
02868 int topMargin = contentArea.y();
02869 int botMargin = idializedGeometry.height() - 1 - contentArea.bottom();
02870
02871 if (vertical)
02872 {
02873 int t = rightMargin;
02874 rightMargin = topMargin;
02875 topMargin = leftMargin;
02876 leftMargin = botMargin;
02877 botMargin = t;
02878
02879 if (!flip)
02880 qSwap(leftMargin, rightMargin);
02881 }
02882 else if (flip)
02883 {
02884 qSwap(topMargin, botMargin);
02885
02886 if (tabOpt->direction == Qt::RightToLeft)
02887 qSwap(leftMargin, rightMargin);
02888 }
02889
02890 QRect geom =
02891 QRect(QPoint(leftMargin, topMargin),
02892 QPoint(r.width() - 1 - rightMargin,
02893 r.height() - 1 - botMargin));
02894 geom.translate(r.topLeft());
02895 return geom;
02896 }
02897
02898 bool KStyle::useSideText(const QStyleOptionProgressBar* pbOpt) const
02899 {
02900 if (widgetLayoutProp(WT_ProgressBar, ProgressBar::SideText) == 0)
02901 return false;
02902
02903 if (!pbOpt) return false;
02904
02905 if (!pbOpt->textVisible) return false;
02906
02907 if (pbOpt->textAlignment & Qt::AlignHCenter) return false;
02908
02909
02910
02911 if (pbOpt->minimum == pbOpt->maximum) return false;
02912
02913 int widthAlloc = pbOpt->fontMetrics.width(QLatin1String("100%"));
02914
02915 if (pbOpt->fontMetrics.width(pbOpt->text) > widthAlloc)
02916 return false;
02917
02918 return true;
02919 }
02920
02921 int KStyle::sideTextWidth(const QStyleOptionProgressBar* pbOpt) const
02922 {
02923 return pbOpt->fontMetrics.width(QLatin1String("100%")) +
02924 2*widgetLayoutProp(WT_ProgressBar, ProgressBar::SideTextSpace);
02925 }
02926
02927 QRect KStyle::subElementRect(SubElement sr, const QStyleOption* option, const QWidget* widget) const
02928 {
02929 QRect r = option->rect;
02930
02931 switch (sr)
02932 {
02933 case SE_PushButtonContents:
02934 {
02935 const QStyleOptionButton* bOpt = qstyleoption_cast<const QStyleOptionButton*>(option);
02936 if (!bOpt) return r;
02937
02938 if ((bOpt->features & QStyleOptionButton::DefaultButton) || (bOpt->features & QStyleOptionButton::AutoDefaultButton))
02939 r = insideMargin(r, WT_PushButton, PushButton::DefaultIndicatorMargin, option, widget);
02940
02941 return insideMargin(r, WT_PushButton, PushButton::ContentsMargin, option, widget);
02942 }
02943
02944 case SE_PushButtonFocusRect:
02945 {
02946 const QStyleOptionButton* bOpt = qstyleoption_cast<const QStyleOptionButton*>(option);
02947 if (!bOpt) return r;
02948
02949 if ((bOpt->features & QStyleOptionButton::DefaultButton) || (bOpt->features & QStyleOptionButton::AutoDefaultButton))
02950 r = insideMargin(r, WT_PushButton, PushButton::DefaultIndicatorMargin, option, widget);
02951
02952 return insideMargin(r, WT_PushButton, PushButton::FocusMargin, option, widget);
02953 }
02954
02955 case SE_ToolBoxTabContents:
02956 {
02957 return insideMargin(r, WT_ToolBoxTab, ToolBoxTab::Margin, option, widget);
02958 }
02959
02960 case SE_CheckBoxContents:
02961 {
02962 r.setX(r.x() + widgetLayoutProp(WT_CheckBox, CheckBox::Size, option, widget) +
02963 widgetLayoutProp(WT_CheckBox, CheckBox::BoxTextSpace, option, widget));
02964 return handleRTL(option, r);
02965 }
02966
02967 case SE_RadioButtonContents:
02968 {
02969 r.setX(r.x() + widgetLayoutProp(WT_RadioButton, RadioButton::Size, option, widget) +
02970 widgetLayoutProp(WT_RadioButton, RadioButton::BoxTextSpace, option, widget));
02971 return handleRTL(option, r);
02972 }
02973
02974 case SE_CheckBoxFocusRect:
02975 {
02976 const QStyleOptionButton* bOpt = qstyleoption_cast<const QStyleOptionButton*>(option);
02977 if (!bOpt) return r;
02978
02979 QRect ret;
02980
02981 if (bOpt->text.isEmpty())
02982 {
02983
02984 QRect checkRect =
02985 handleRTL(option, subElementRect(SE_CheckBoxIndicator, option, widget) );
02986 ret = insideMargin(checkRect, WT_CheckBox, CheckBox::NoLabelFocusMargin, option, widget);
02987 }
02988 else
02989 {
02990
02991 QRect contentsRect =
02992 handleRTL(option, subElementRect(SE_CheckBoxContents, option, widget) );
02993 ret = insideMargin(contentsRect, WT_CheckBox, CheckBox::FocusMargin, option, widget);
02994 }
02995
02996 return handleRTL(option, ret);
02997 }
02998
02999 case SE_RadioButtonFocusRect:
03000 {
03001
03002 QRect contentsRect =
03003 handleRTL(option, subElementRect(SE_RadioButtonContents, option, widget) );
03004
03005
03006 return handleRTL(option,
03007 insideMargin(contentsRect, WT_RadioButton,
03008 RadioButton::FocusMargin, option, widget) );
03009 }
03010
03011 case SE_ProgressBarGroove:
03012 {
03013 const QStyleOptionProgressBar* pbOpt = ::qstyleoption_cast<const QStyleOptionProgressBar*>(option);
03014 if (useSideText(pbOpt))
03015 {
03016 r.setWidth(r.width() - sideTextWidth(pbOpt));
03017 return r;
03018 }
03019
03020
03021 return r;
03022 }
03023
03024 case SE_ProgressBarContents:
03025 {
03026 QRect grooveRect = subElementRect(SE_ProgressBarGroove, option, widget);
03027 return insideMargin(grooveRect, WT_ProgressBar, ProgressBar::GrooveMargin, option, widget);
03028 }
03029
03030 case SE_ProgressBarLabel:
03031 {
03032 const QStyleOptionProgressBar* pbOpt = ::qstyleoption_cast<const QStyleOptionProgressBar*>(option);
03033 if (useSideText(pbOpt))
03034 {
03035 int width = sideTextWidth(pbOpt);
03036 return QRect(r.x() + r.width() - width, r.y(), width, r.height());
03037 }
03038
03039
03040 return subElementRect(SE_PushButtonContents, option, widget);
03041 }
03042
03043
03044 case SE_TabWidgetTabContents:
03045 {
03046 const QStyleOptionTabWidgetFrame* tabOpt = qstyleoption_cast<const QStyleOptionTabWidgetFrame*>(option);
03047 if (!tabOpt) break;
03048
03049
03050 if (tabOpt->lineWidth == 0) break;
03051
03052
03053
03054 QRect pane = QCommonStyle::subElementRect(SE_TabWidgetTabPane, option, widget);
03055 int m = widgetLayoutProp(WT_TabWidget, TabWidget::ContentsMargin, option, widget);
03056 int top = m+widgetLayoutProp(WT_TabWidget, TabWidget::ContentsMargin+Top,
03057 option, widget);
03058 int bot = m+widgetLayoutProp(WT_TabWidget, TabWidget::ContentsMargin+Bot,
03059 option, widget);
03060 int left = m+widgetLayoutProp(WT_TabWidget, TabWidget::ContentsMargin+Left,
03061 option, widget);
03062 int right = m+widgetLayoutProp(WT_TabWidget, TabWidget::ContentsMargin+Right,
03063 option, widget);
03064
03065 switch (tabOpt->shape) {
03066 case QTabBar::RoundedNorth:
03067 case QTabBar::TriangularNorth:
03068 return pane.adjusted(left,top,-right,-bot);
03069 case QTabBar::RoundedEast:
03070 case QTabBar::TriangularEast:
03071 return pane.adjusted(bot,left, -top,-right);
03072 case QTabBar::RoundedSouth:
03073 case QTabBar::TriangularSouth:
03074 return pane.adjusted(right,bot, -left,-top);
03075 case QTabBar::RoundedWest:
03076 case QTabBar::TriangularWest:
03077 return pane.adjusted(top,right, -bot,-left);
03078 }
03079 }
03080
03081 case SE_TabBarTabText:
03082 {
03083 const QStyleOptionTab* tabOpt = qstyleoption_cast<const QStyleOptionTab*>(option);
03084 if (!tabOpt) return QRect();
03085
03086 QRect r = marginAdjustedTab(tabOpt, TabBar::TabContentsMargin);
03087 QStyleOptionTabV3 tov3(*tabOpt);
03088
03089 switch (tov3.shape)
03090 {
03091 case QTabBar::RoundedNorth:
03092 case QTabBar::TriangularNorth:
03093 case QTabBar::RoundedSouth:
03094 case QTabBar::TriangularSouth:
03095 if (tov3.direction == Qt::LeftToRight)
03096 r.adjust(tov3.leftButtonSize.width(), 0, -tov3.rightButtonSize.width(), 0);
03097 else
03098 r.adjust(tov3.rightButtonSize.width(), 0, -tov3.leftButtonSize.width(), 0);
03099 break;
03100 case QTabBar::RoundedEast:
03101 case QTabBar::TriangularEast:
03102 r.adjust(0, tov3.leftButtonSize.width(), 0, -tov3.rightButtonSize.width());
03103 break;
03104 case QTabBar::RoundedWest:
03105 case QTabBar::TriangularWest:
03106 r.adjust(0, tov3.rightButtonSize.width(), 0, -tov3.leftButtonSize.width());
03107 break;
03108 }
03109
03110 return r;
03111 }
03112
03113 default:
03114 break;
03115 }
03116
03117 return QCommonStyle::subElementRect(sr, option, widget);
03118 }
03119
03120 void KStyle::drawComplexControl (ComplexControl cc, const QStyleOptionComplex* opt,
03121 QPainter *p, const QWidget* w) const
03122 {
03123
03124 State flags = opt->state;
03125 QRect r = opt->rect;
03126 QPalette pal = opt->palette;
03127
03128 switch (cc)
03129 {
03130 case CC_ScrollBar:
03131 {
03132 QStyleOptionComplex* mutableOpt = const_cast<QStyleOptionComplex*>(opt);
03133 if ((mutableOpt->subControls & SC_ScrollBarSubLine) || (mutableOpt->subControls & SC_ScrollBarAddLine))
03134 {
03135
03136 mutableOpt->subControls |= SC_ScrollBarSubPage | SC_ScrollBarAddLine;
03137 }
03138
03139 }
03140 break;
03141
03142 case CC_Q3ListView:
03143 {
03144 const QStyleOptionQ3ListView* lvOpt = qstyleoption_cast<const QStyleOptionQ3ListView*>(opt);
03145 Q_ASSERT (lvOpt);
03146
03147 if (lvOpt->subControls & SC_Q3ListView)
03148 QCommonStyle::drawComplexControl(cc, opt, p, w);
03149
03150 if (lvOpt->items.isEmpty())
03151 return;
03152
03153
03154 if (lvOpt->subControls & (SC_Q3ListViewBranch | SC_Q3ListViewExpand))
03155 {
03156 QStyleOptionQ3ListViewItem item = lvOpt->items.at(0);
03157
03158 int y = r.y();
03159
03160 QStyleOption opt;
03161 opt.palette = lvOpt->palette;
03162 opt.direction = Qt::LeftToRight;
03163
03164
03165
03166
03167
03168 int cX = w ? w->property("contentsX").toInt() : 0;
03169 int cY = w ? w->property("contentsY").toInt() : 0;
03170
03171 QPoint adjustCoords = p->matrix().map(QPoint(0,0)) + QPoint(cX, cY);
03172 p->translate(-adjustCoords);
03173
03174 if (lvOpt->activeSubControls == SC_All && (lvOpt->subControls & SC_Q3ListViewExpand)) {
03175
03176
03177
03178 QStyleOption opt;
03179 opt.rect = QRect(r.topLeft() + adjustCoords, r.size());
03180 opt.state = State_Sibling;
03181 drawPrimitive(PE_IndicatorBranch, &opt, p, 0);
03182 } else {
03183 int childPos = 1;
03184
03185
03186 while (childPos < lvOpt->items.size() && y < r.height())
03187 {
03188 const QStyleOptionQ3ListViewItem& child = lvOpt->items.at(childPos);
03189 if (!(child.features & QStyleOptionQ3ListViewItem::Visible))
03190 {
03191 childPos++;
03192 continue;
03193 }
03194
03195
03196 opt.rect = QRect(r.x() + adjustCoords.x(), y + adjustCoords.y(),
03197 r.width(), child.height);
03198 opt.state = State_Item;
03199
03200 if (child.features & QStyleOptionQ3ListViewItem::Expandable || child.childCount)
03201 {
03202 opt.state |= State_Children;
03203 opt.state |= (child.state & State_Open);
03204 }
03205
03206
03207 int siblingPos = 0;
03208 for (siblingPos = childPos + 1; siblingPos < lvOpt->items.size(); ++siblingPos)
03209 {
03210 if (lvOpt->items.at(siblingPos).features & QStyleOptionQ3ListViewItem::Visible)
03211 {
03212 opt.state |= State_Sibling;
03213 break;
03214 }
03215 }
03216
03217
03218 if (y + child.height > 0)
03219 drawPrimitive(PE_IndicatorBranch, &opt, p, 0);
03220
03221 if (!siblingPos)
03222 break;
03223
03224
03225
03226 if ((opt.state & State_Children) && (opt.state & State_Sibling))
03227 {
03228 opt.state = State_Sibling;
03229 opt.rect = QRect(r.x() + adjustCoords.x(),
03230 y + adjustCoords.y() + child.height,
03231 r.width(), child.totalHeight - child.height);
03232 if (opt.rect.height())
03233 drawPrimitive(PE_IndicatorBranch, &opt, p, 0);
03234 }
03235
03236 y += child.totalHeight;
03237 childPos = siblingPos;
03238 }
03239 }
03240
03241 p->translate(adjustCoords);
03242 }
03243 }
03244 break;
03245
03246 case CC_Slider:
03247 {
03248 if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt))
03249 {
03250 QRect groove = subControlRect(CC_Slider, slider, SC_SliderGroove, w);
03251 QRect handle = subControlRect(CC_Slider, slider, SC_SliderHandle, w);
03252 bool hor = slider->orientation == Qt::Horizontal;
03253
03254 if (slider->subControls & SC_SliderTickmarks)
03255 {
03256
03257 QStyleOptionSlider tmpSlider = *slider;
03258 tmpSlider.subControls = SC_SliderTickmarks;
03259 QCommonStyle::drawComplexControl(cc, &tmpSlider, p, w);
03260 }
03261
03262 if ((slider->subControls & SC_SliderGroove) && groove.isValid())
03263 {
03264 drawKStylePrimitive(WT_Slider, hor ? Slider::GrooveHor : Slider::GrooveVert, opt, groove, pal, flags, p, w);
03265 }
03266
03267 if (slider->subControls & SC_SliderHandle)
03268 {
03269 drawKStylePrimitive(WT_Slider, hor ? Slider::HandleHor : Slider::HandleVert, opt, handle, pal, flags, p, w);
03270
03271 if (slider->state & State_HasFocus) {
03272 QRect focus = subElementRect(SE_SliderFocusRect, slider, w);
03273 drawKStylePrimitive(WT_Slider, Generic::FocusIndicator, opt, focus, pal, flags, p, w, 0);
03274 }
03275 }
03276 }
03277 return;
03278 }
03279
03280 case CC_SpinBox:
03281 {
03282 if (const QStyleOptionSpinBox *sb = qstyleoption_cast<const QStyleOptionSpinBox *>(opt) )
03283 {
03284 bool activeSbUp = sb->activeSubControls&SC_SpinBoxUp && (flags & State_Sunken);
03285 bool activeSbDown = sb->activeSubControls&SC_SpinBoxDown && (flags & State_Sunken);
03286
03287 if (sb->subControls & SC_SpinBoxFrame)
03288 {
03289 drawKStylePrimitive(WT_SpinBox, Generic::Frame, opt, r, pal, flags, p, w);
03290 }
03291
03292 if (sb->subControls & SC_SpinBoxEditField)
03293 {
03294 QRect editField = subControlRect(CC_SpinBox, opt, SC_SpinBoxEditField, w);
03295 drawKStylePrimitive(WT_SpinBox, SpinBox::EditField, opt, editField, pal, flags, p, w);
03296 }
03297
03298 QRect upRect, downRect;
03299 if (sb->subControls & (SC_SpinBoxUp | SC_SpinBoxDown))
03300 {
03301 upRect = subControlRect(CC_SpinBox, opt, SC_SpinBoxUp, w);
03302 downRect = subControlRect(CC_SpinBox, opt, SC_SpinBoxDown, w);
03303 QRect buttonAreaRect = upRect | downRect;
03304 drawKStylePrimitive(WT_SpinBox, SpinBox::ButtonArea, opt, buttonAreaRect, pal, flags, p, w);
03305 }
03306
03307 if (sb->subControls & SC_SpinBoxUp)
03308 {
03309
03310 State upFlags = flags;
03311 if (activeSbUp)
03312 upFlags |= State_Sunken;
03313 else
03314 upFlags &= ~State_Sunken;
03315
03316 drawKStylePrimitive(WT_SpinBox, SpinBox::UpButton, opt, upRect, pal, upFlags, p, w);
03317
03318
03319 int primitive;
03320 if (sb->buttonSymbols == QAbstractSpinBox::PlusMinus)
03321 primitive = SpinBox::PlusSymbol;
03322 else
03323 primitive = Generic::ArrowUp;
03324 drawKStylePrimitive(WT_SpinBox, primitive, opt, upRect, pal, upFlags, p, w);
03325 }
03326
03327 if (sb->subControls & SC_SpinBoxDown)
03328 {
03329
03330 State downFlags = flags;
03331 if (activeSbDown)
03332 downFlags |= State_Sunken;
03333 else
03334 downFlags &= ~State_Sunken;
03335
03336 drawKStylePrimitive(WT_SpinBox, SpinBox::DownButton, opt, downRect, pal, downFlags, p, w);
03337
03338
03339 int primitive;
03340 if (sb->buttonSymbols == QAbstractSpinBox::PlusMinus)
03341 primitive = SpinBox::MinusSymbol;
03342 else
03343 primitive = Generic::ArrowDown;
03344 drawKStylePrimitive(WT_SpinBox, primitive, opt, downRect, pal, downFlags, p, w);
03345 }
03346
03347 return;
03348 }
03349 }
03350
03351 case CC_ComboBox:
03352 {
03353 if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt) )
03354 {
03355 if (cb->subControls & SC_ComboBoxFrame)
03356 {
03357 drawKStylePrimitive(WT_ComboBox, Generic::Frame, opt, r, pal, flags, p, w);
03358
03359
03360 if (cb->state & State_HasFocus) {
03361 QRect editField = subControlRect(CC_ComboBox, opt, SC_ComboBoxEditField, w);
03362 QRect focusRect = insideMargin(editField, WT_ComboBox, ComboBox::FocusMargin, opt, w);
03363 drawKStylePrimitive(WT_ComboBox, Generic::FocusIndicator, opt, focusRect, pal, flags, p, w, 0);
03364 }
03365 }
03366
03367 if (cb->subControls & SC_ComboBoxEditField)
03368 {
03369 QRect editField = subControlRect(CC_ComboBox, opt, SC_ComboBoxEditField, w);
03370 drawKStylePrimitive(WT_ComboBox, ComboBox::EditField, opt, editField, pal, flags, p, w);
03371 }
03372
03373 if (cb->subControls & SC_ComboBoxArrow)
03374 {
03375 QRect buttonRect = subControlRect(CC_ComboBox, opt, SC_ComboBoxArrow, w);
03376 drawKStylePrimitive(WT_ComboBox, ComboBox::Button, opt, buttonRect, pal, flags, p, w);
03377
03378
03379 drawKStylePrimitive(WT_ComboBox, Generic::ArrowDown, opt, buttonRect, pal, flags, p, w);
03380 }
03381
03382 return;
03383 }
03384 break;
03385 }
03386
03387 case CC_ToolButton:
03388 {
03389 if (const QStyleOptionToolButton *tool = qstyleoption_cast<const QStyleOptionToolButton *>(opt)) {
03390 QRect buttonRect = subControlRect(cc, tool, SC_ToolButton, w);
03391 QRect menuRect = subControlRect(cc, tool, SC_ToolButtonMenu, w);
03392
03393
03394 State bflags = tool->state;
03395 if (bflags & State_AutoRaise) {
03396 if (!(bflags & State_MouseOver)) {
03397 bflags &= ~State_Raised;
03398 }
03399 }
03400 State mflags = bflags;
03401
03402 QStyleOption tOpt(0);
03403 tOpt.palette = pal;
03404
03405 if (tool->subControls & SC_ToolButton) {
03406 if (bflags & (State_Sunken | State_On | State_Raised)) {
03407 tOpt.rect = buttonRect;
03408 tOpt.state = bflags;
03409 drawPrimitive(PE_PanelButtonTool, &tOpt, p, w);
03410 }
03411 }
03412
03413 if (tool->subControls & SC_ToolButtonMenu) {
03414 tOpt.rect = menuRect;
03415 tOpt.state = mflags;
03416 drawPrimitive(PE_IndicatorButtonDropDown, &tOpt, p, w);
03417 } else if (tool->features & QStyleOptionToolButton::HasMenu) {
03418
03419
03420
03421 int size = widgetLayoutProp(WT_ToolButton, ToolButton::InlineMenuIndicatorSize, opt, w);
03422
03423 if (size) {
03424 int xOff = widgetLayoutProp(WT_ToolButton, ToolButton::InlineMenuIndicatorXOff, opt, w);
03425 int yOff = widgetLayoutProp(WT_ToolButton, ToolButton::InlineMenuIndicatorYOff, opt, w);
03426
03427 QRect r = QRect(buttonRect.right() + xOff, buttonRect.bottom() + yOff, size, size);
03428 tOpt.rect = r;
03429 tOpt.state = bflags;
03430 drawPrimitive(PE_IndicatorButtonDropDown, &tOpt, p, w);
03431 }
03432 }
03433
03434 if (flags & State_HasFocus) {
03435 QRect focusRect = insideMargin(r, WT_ToolButton, ToolButton::FocusMargin, opt, w);
03436 tOpt.rect = focusRect;
03437 tOpt.state = bflags;
03438 drawKStylePrimitive(WT_ToolButton, Generic::FocusIndicator, &tOpt, focusRect, pal, bflags, p, w);
03439 }
03440
03441
03442 QStyleOptionToolButton labelOpt = *tool;
03443 labelOpt.rect = buttonRect;
03444 drawControl(CE_ToolButtonLabel, &labelOpt, p, w);
03445
03446 return;
03447 }
03448 break;
03449 }
03450
03451 case CC_TitleBar:
03452 {
03453 const QStyleOptionTitleBar *tb =
03454 qstyleoption_cast<const QStyleOptionTitleBar *>(opt);
03455 if (!tb)
03456 break;
03457
03458
03459 drawKStylePrimitive(WT_Window, Window::TitlePanel, opt, r, pal, flags, p, w);
03460
03461
03462
03463 QRect textRect = subControlRect(CC_TitleBar, tb, SC_TitleBarLabel, w);
03464 TextOption textOpt(tb->text);
03465 textOpt.color = widgetLayoutProp(WT_Window, Window::TitleTextColor, opt, w);
03466 drawKStylePrimitive(WT_Window, Generic::Text, opt, textRect,
03467 pal, flags, p, w, &textOpt);
03468
03469 TitleButtonOption buttonKOpt;
03470 buttonKOpt.icon = tb->icon;
03471
03472 if ((tb->subControls & SC_TitleBarSysMenu) &&
03473 (tb->titleBarFlags & Qt::WindowSystemMenuHint))
03474 {
03475 buttonKOpt.active = (tb->activeSubControls & SC_TitleBarSysMenu)
03476 && (tb->state & State_Sunken);
03477 QRect br = subControlRect(CC_TitleBar, tb, SC_TitleBarSysMenu, w);
03478 drawKStylePrimitive(WT_Window, Window::ButtonMenu, opt, br, pal, flags, p, w,
03479 &buttonKOpt);
03480 }
03481
03482 if ((tb->subControls & SC_TitleBarMinButton) &&
03483 (tb->titleBarFlags & Qt::WindowMinimizeButtonHint))
03484 {
03485 buttonKOpt.active = (tb->activeSubControls & SC_TitleBarMinButton)
03486 && (tb->state & State_Sunken);
03487 QRect br = subControlRect(CC_TitleBar, tb, SC_TitleBarMinButton, w);
03488 drawKStylePrimitive(WT_Window, Window::ButtonMin, opt, br, pal, flags, p, w,
03489 &buttonKOpt);
03490 }
03491
03492 if ((tb->subControls & SC_TitleBarMaxButton) &&
03493 (tb->titleBarFlags & Qt::WindowMaximizeButtonHint))
03494 {
03495 buttonKOpt.active = (tb->activeSubControls & SC_TitleBarMaxButton)
03496 && (tb->state & State_Sunken);
03497 QRect br = subControlRect(CC_TitleBar, tb, SC_TitleBarMaxButton, w);
03498 drawKStylePrimitive(WT_Window, Window::ButtonMax, opt, br, pal, flags, p, w,
03499 &buttonKOpt);
03500 }
03501
03502 if ((tb->subControls & SC_TitleBarCloseButton) &&
03503 (tb->titleBarFlags & Qt::WindowSystemMenuHint))
03504 {
03505
03506
03507 buttonKOpt.active = (tb->activeSubControls & SC_TitleBarCloseButton)
03508 && (tb->state & State_Sunken);
03509 QRect br = subControlRect(CC_TitleBar, tb, SC_TitleBarCloseButton, w);
03510 drawKStylePrimitive(WT_Window, Window::ButtonClose, opt, br, pal, flags, p, w,
03511 &buttonKOpt);
03512 }
03513
03514 if ((tb->subControls & SC_TitleBarNormalButton) &&
03515 (((tb->titleBarFlags & Qt::WindowMinimizeButtonHint) &&
03516 (tb->titleBarState & Qt::WindowMinimized)) ||
03517 ((tb->titleBarFlags & Qt::WindowMaximizeButtonHint) &&
03518 (tb->titleBarState & Qt::WindowMaximized))))
03519 {
03520 buttonKOpt.active = (tb->activeSubControls & SC_TitleBarNormalButton)
03521 && (tb->state & State_Sunken);
03522 QRect br = subControlRect(CC_TitleBar, tb, SC_TitleBarNormalButton, w);
03523 drawKStylePrimitive(WT_Window, Window::ButtonRestore, opt, br, pal, flags, p, w,
03524 &buttonKOpt);
03525 }
03526
03527 if (tb->subControls & SC_TitleBarShadeButton)
03528 {
03529 buttonKOpt.active = (tb->activeSubControls & SC_TitleBarShadeButton)
03530 && (tb->state & State_Sunken);
03531 QRect br = subControlRect(CC_TitleBar, tb, SC_TitleBarShadeButton, w);
03532 drawKStylePrimitive(WT_Window, Window::ButtonShade, opt, br, pal, flags, p, w,
03533 &buttonKOpt);
03534 }
03535
03536 if (tb->subControls & SC_TitleBarUnshadeButton)
03537 {
03538 buttonKOpt.active = (tb->activeSubControls & SC_TitleBarUnshadeButton)
03539 && (tb->state & State_Sunken);
03540 QRect br = subControlRect(CC_TitleBar, tb, SC_TitleBarUnshadeButton, w);
03541 drawKStylePrimitive(WT_Window, Window::ButtonUnshade, opt, br, pal, flags, p, w,
03542 &buttonKOpt);
03543 }
03544
03545 if ((tb->subControls & SC_TitleBarContextHelpButton)
03546 && (tb->titleBarFlags & Qt::WindowContextHelpButtonHint))
03547 {
03548 buttonKOpt.active = (tb->activeSubControls & SC_TitleBarContextHelpButton)
03549 && (tb->state & State_Sunken);
03550 QRect br = subControlRect(CC_TitleBar, tb, SC_TitleBarContextHelpButton, w);
03551 drawKStylePrimitive(WT_Window, Window::ButtonHelp, opt, br, pal, flags, p, w,
03552 &buttonKOpt);
03553 }
03554
03555 return;
03556 }
03557
03558 default:
03559 break;
03560 }
03561
03562 QCommonStyle::drawComplexControl(cc, opt, p, w);
03563 }
03564
03565
03566 QRect KStyle::internalSubControlRect (ComplexControl control, const QStyleOptionComplex* option,
03567 SubControl subControl, const QWidget* widget) const
03568 {
03569 QRect r = option->rect;
03570
03571 if (control == CC_ScrollBar)
03572 {
03573 switch (subControl)
03574 {
03575
03576 case SC_ScrollBarSubLine:
03577 {
03578 int majorSize;
03579 if (widgetLayoutProp(WT_ScrollBar, ScrollBar::DoubleTopButton, option, widget))
03580 majorSize = widgetLayoutProp(WT_ScrollBar, ScrollBar::DoubleButtonHeight, option, widget);
03581 else
03582 majorSize = widgetLayoutProp(WT_ScrollBar, ScrollBar::SingleButtonHeight, option, widget);
03583
03584 if (option->state & State_Horizontal)
03585 return handleRTL(option, QRect(r.x(), r.y(), majorSize, r.height()));
03586 else
03587 return handleRTL(option, QRect(r.x(), r.y(), r.width(), majorSize));
03588
03589 }
03590
03591
03592 case SC_ScrollBarAddLine:
03593 {
03594 int majorSize;
03595 if (widgetLayoutProp(WT_ScrollBar, ScrollBar::DoubleBotButton, option, widget))
03596 majorSize = widgetLayoutProp(WT_ScrollBar, ScrollBar::DoubleButtonHeight, option, widget);
03597 else
03598 majorSize = widgetLayoutProp(WT_ScrollBar, ScrollBar::SingleButtonHeight, option, widget);
03599
03600 if (option->state & State_Horizontal)
03601 return handleRTL(option, QRect(r.right() - majorSize + 1, r.y(), majorSize, r.height()));
03602 else
03603 return handleRTL(option, QRect(r.x(), r.bottom() - majorSize + 1, r.width(), majorSize));
03604 }
03605
03606 default:
03607 break;
03608 }
03609 }
03610
03611 return QRect();
03612 }
03613
03614
03615 QRect KStyle::subControlRect(ComplexControl control, const QStyleOptionComplex* option,
03616 SubControl subControl, const QWidget* widget) const
03617 {
03618 QRect r = option->rect;
03619
03620 switch (control)
03621 {
03622 case CC_ScrollBar:
03623 {
03624 switch (subControl)
03625 {
03626
03627
03628
03629 case SC_ScrollBarSubLine:
03630 case SC_ScrollBarAddLine:
03631 return r;
03632
03633
03634 case SC_ScrollBarGroove:
03635 {
03636 QRect top = handleRTL(option, internalSubControlRect(control, option, SC_ScrollBarSubLine, widget));
03637 QRect bot = handleRTL(option, internalSubControlRect(control, option, SC_ScrollBarAddLine, widget));
03638
03639 QPoint topLeftCorner, botRightCorner;
03640 if (option->state & State_Horizontal)
03641 {
03642 topLeftCorner = QPoint(top.right() + 1, top.top());
03643 botRightCorner = QPoint(bot.left() - 1, top.bottom());
03644 }
03645 else
03646 {
03647 topLeftCorner = QPoint(top.left(), top.bottom() + 1);
03648 botRightCorner = QPoint(top.right(), bot.top() - 1);
03649 }
03650
03651 return handleRTL(option, QRect(topLeftCorner, botRightCorner));
03652 }
03653
03654 case SC_ScrollBarFirst:
03655 case SC_ScrollBarLast:
03656 return QRect();
03657
03658 case SC_ScrollBarSlider:
03659 {
03660 const QStyleOptionSlider* slOpt = ::qstyleoption_cast<const QStyleOptionSlider*>(option);
03661
03662
03663 QRect groove = handleRTL(option, subControlRect(control, option, SC_ScrollBarGroove, widget));
03664 Q_ASSERT (slOpt);
03665
03666 if (slOpt->minimum == slOpt->maximum)
03667 return groove;
03668
03669
03670 int space;
03671 if (option->state & State_Horizontal)
03672 space = groove.width();
03673 else
03674 space = groove.height();
03675
03676
03677 int sliderSize = int(space * float(slOpt->pageStep) /
03678 (slOpt->maximum - slOpt->minimum + slOpt->pageStep));
03679
03680 if (sliderSize < widgetLayoutProp(WT_ScrollBar, ScrollBar::MinimumSliderHeight, option, widget))
03681 sliderSize = widgetLayoutProp(WT_ScrollBar, ScrollBar::MinimumSliderHeight, option, widget);
03682
03683 if (sliderSize > space)
03684 sliderSize = space;
03685
03686
03687 space = space - sliderSize;
03688
03689
03690 if (space <= 0)
03691 return groove;
03692
03693 int pos = qRound(float(slOpt->sliderPosition - slOpt->minimum)/
03694 (slOpt->maximum - slOpt->minimum)*space);
03695 if (option->state & State_Horizontal)
03696 return handleRTL(option, QRect(groove.x() + pos, groove.y(), sliderSize, groove.height()));
03697 else
03698 return handleRTL(option, QRect(groove.x(), groove.y() + pos, groove.width(), sliderSize));
03699 }
03700
03701 case SC_ScrollBarSubPage:
03702 {
03703
03704 QRect slider = handleRTL(option, subControlRect(control, option, SC_ScrollBarSlider, widget));
03705 QRect groove = handleRTL(option, subControlRect(control, option, SC_ScrollBarGroove, widget));
03706
03707
03708 if (option->state & State_Horizontal)
03709 return handleRTL(option, QRect(groove.x(), groove.y(), slider.x() - groove.x(), groove.height()));
03710 else
03711 return handleRTL(option, QRect(groove.x(), groove.y(), groove.width(), slider.y() - groove.y()));
03712 }
03713
03714 case SC_ScrollBarAddPage:
03715 {
03716
03717 QRect slider = handleRTL(option, subControlRect(control, option, SC_ScrollBarSlider, widget));
03718 QRect groove = handleRTL(option, subControlRect(control, option, SC_ScrollBarGroove, widget));
03719
03720
03721 if (option->state & State_Horizontal)
03722 return handleRTL(option,
03723 QRect(slider.right() + 1, groove.y(), groove.right() - slider.right(), groove.height()));
03724 else
03725 return handleRTL(option,
03726 QRect(groove.x(), slider.bottom() + 1, groove.width(), groove.bottom() - slider.bottom()));
03727 }
03728
03729 default:
03730 break;
03731 }
03732 }
03733
03734 case CC_SpinBox:
03735 {
03736 if (const QStyleOptionSpinBox *sb = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
03737
03738 int fw = widgetLayoutProp(WT_SpinBox, SpinBox::FrameWidth, option, widget);
03739 int bw = widgetLayoutProp(WT_SpinBox, SpinBox::ButtonWidth, option, widget);
03740 int bm = widgetLayoutProp(WT_SpinBox, SpinBox::ButtonMargin, option, widget);
03741 int bml = bm + widgetLayoutProp(WT_SpinBox, SpinBox::ButtonMargin + Left, option, widget);
03742 int bmr = bm + widgetLayoutProp(WT_SpinBox, SpinBox::ButtonMargin + Right, option, widget);
03743 int bmt = bm + widgetLayoutProp(WT_SpinBox, SpinBox::ButtonMargin + Top, option, widget);
03744 int bmb = bm + widgetLayoutProp(WT_SpinBox, SpinBox::ButtonMargin + Bot, option, widget);
03745 int bs = widgetLayoutProp(WT_SpinBox, SpinBox::ButtonSpacing, option, widget);
03746 bool symmButtons = widgetLayoutProp(WT_SpinBox, SpinBox::SymmetricButtons, option, widget);
03747 bool supportFrameless = widgetLayoutProp(WT_SpinBox, SpinBox::SupportFrameless, option, widget);
03748
03749
03750 if (supportFrameless && !sb->frame)
03751 {
03752 bw = bw - bmr;
03753 fw = 0;
03754 bmt = bmb = bmr = 0;
03755 }
03756
03757 const int buttonsWidth = bw-bml-bmr;
03758 const int buttonsLeft = r.right()-bw+bml+1;
03759
03760
03761 int availableButtonHeight = r.height()-bmt-bmb - bs;
03762 if (symmButtons)
03763 {
03764
03765
03766
03767 if (availableButtonHeight%2 != 0)
03768 {
03769 --bs;
03770
03771
03772 availableButtonHeight = r.height()-bmt-bmb - bs;
03773 }
03774 }
03775 int heightUp = availableButtonHeight / 2;
03776 int heightDown = availableButtonHeight - heightUp;
03777
03778
03779 switch (subControl) {
03780 case SC_SpinBoxUp:
03781 return handleRTL(option,
03782 QRect(buttonsLeft, r.top()+bmt, buttonsWidth, heightUp) );
03783 case SC_SpinBoxDown:
03784 return handleRTL(option,
03785 QRect(buttonsLeft, r.bottom()-bmb-heightDown+1, buttonsWidth, heightDown) );
03786 case SC_SpinBoxEditField:
03787 {
03788 QRect labelRect(r.left()+fw, r.top()+fw, r.width()-fw-bw, r.height()-2*fw);
03789 labelRect = insideMargin(labelRect, WT_SpinBox, SpinBox::ContentsMargin, option, widget);
03790 return handleRTL(option, labelRect );
03791 }
03792 case SC_SpinBoxFrame:
03793 return (sb->frame || !supportFrameless) ? r : QRect();
03794 default:
03795 break;
03796 }
03797 }
03798 }
03799
03800 case CC_ComboBox:
03801 {
03802 if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
03803
03804 int fw = widgetLayoutProp(WT_ComboBox, ComboBox::FrameWidth, option, widget);
03805 int bw = widgetLayoutProp(WT_ComboBox, ComboBox::ButtonWidth, option, widget);
03806 int bm = widgetLayoutProp(WT_ComboBox, ComboBox::ButtonMargin, option, widget);
03807 int bml = bm + widgetLayoutProp(WT_ComboBox, ComboBox::ButtonMargin + Left, option, widget);
03808 int bmr = bm + widgetLayoutProp(WT_ComboBox, ComboBox::ButtonMargin + Right, option, widget);
03809 int bmt = bm + widgetLayoutProp(WT_ComboBox, ComboBox::ButtonMargin + Top, option, widget);
03810 int bmb = bm + widgetLayoutProp(WT_ComboBox, ComboBox::ButtonMargin + Bot, option, widget);
03811 bool supportFrameless = widgetLayoutProp(WT_ComboBox, ComboBox::SupportFrameless, option, widget);
03812
03813
03814 if (supportFrameless && !cb->frame)
03815 {
03816 bw = bw - bmr;
03817 fw = 0;
03818 bmt = bmb = bmr = 0;
03819 }
03820
03821 switch (subControl) {
03822 case SC_ComboBoxFrame:
03823 return (cb->frame || !supportFrameless) ? r : QRect();
03824 case SC_ComboBoxArrow:
03825 return handleRTL(option,
03826 QRect(r.right()-bw+bml+1, r.top()+bmt, bw-bml-bmr, r.height()-bmt-bmb) );
03827 case SC_ComboBoxEditField:
03828 {
03829 QRect labelRect(r.left()+fw, r.top()+fw, r.width()-fw-bw, r.height()-2*fw);
03830 labelRect = insideMargin(labelRect, WT_ComboBox, ComboBox::ContentsMargin, option, widget);
03831 return handleRTL(option, labelRect );
03832 }
03833 case SC_ComboBoxListBoxPopup:
03834
03835
03836
03837 return r;
03838 default:
03839 break;
03840 }
03841 }
03842 }
03843
03844 case CC_TitleBar:
03845 {
03846 const QStyleOptionTitleBar *tbOpt =
03847 qstyleoption_cast<const QStyleOptionTitleBar *>(option);
03848 if (!tbOpt)
03849 break;
03850
03851 QRect ret = insideMargin(r, WT_Window, Window::TitleMargin, option, widget);
03852
03853 const int btnHeight = ret.height();
03854 const int btnWidth = widgetLayoutProp(WT_Window, Window::ButtonWidth, option, widget);
03855 const int btnSpace = widgetLayoutProp(WT_Window, Window::ButtonSpace, option, widget);
03856 const int titleSpace = widgetLayoutProp(WT_Window, Window::ButtonToTextSpace, option, widget);
03857
03858 bool isMinimized = tbOpt->titleBarState & Qt::WindowMinimized;
03859 bool isMaximized = tbOpt->titleBarState & Qt::WindowMaximized;
03860
03861
03862
03863 bool menuCloseBtn = tbOpt->titleBarFlags & Qt::WindowSystemMenuHint;
03864 bool minBtn = !isMinimized &&
03865 (tbOpt->titleBarFlags & Qt::WindowMinimizeButtonHint);
03866 bool maxBtn = !isMaximized &&
03867 (tbOpt->titleBarFlags & Qt::WindowMaximizeButtonHint);
03868 bool restoreBtn =
03869 (isMinimized && (tbOpt->titleBarFlags & Qt::WindowMinimizeButtonHint)) ||
03870 (isMaximized && (tbOpt->titleBarFlags & Qt::WindowMaximizeButtonHint));
03871 bool shadeBtn = tbOpt->titleBarFlags & Qt::WindowShadeButtonHint;
03872 bool helpBtn = tbOpt->titleBarFlags & Qt::WindowContextHelpButtonHint;
03873
03874
03875 int btnOffsetCount = 0;
03876
03877 switch (subControl) {
03878 case SC_TitleBarLabel:
03879 {
03880 if (tbOpt->titleBarFlags & Qt::WindowTitleHint)
03881 {
03882 int cLeft = 0;
03883 int cRight = 0;
03884
03885 if (menuCloseBtn) {
03886
03887 ++cLeft;
03888 ++cRight;
03889 }
03890 if (minBtn) ++cRight;
03891 if (restoreBtn) ++cRight;
03892 if (maxBtn) ++cRight;
03893 if (shadeBtn) ++cRight;
03894 if (helpBtn) ++cRight;
03895
03896 ret.adjust( cLeft*btnWidth+(cLeft-1)*btnSpace+titleSpace, 0,
03897 -(titleSpace+cRight*btnWidth+(cRight-1)*btnSpace), 0 );
03898 }
03899 break;
03900 }
03901
03902 case SC_TitleBarSysMenu:
03903 {
03904 if (tbOpt->titleBarFlags & Qt::WindowSystemMenuHint) {
03905 ret.setRect(ret.left(), ret.top(), btnWidth, btnHeight);
03906 }
03907 break;
03908 }
03909
03910 case SC_TitleBarContextHelpButton:
03911 if (helpBtn)
03912 ++btnOffsetCount;
03913 case SC_TitleBarMinButton:
03914 if (minBtn)
03915 ++btnOffsetCount;
03916 else if (subControl == SC_TitleBarMinButton)
03917 return QRect();
03918 case SC_TitleBarNormalButton:
03919 if (restoreBtn)
03920 ++btnOffsetCount;
03921 else if (subControl == SC_TitleBarNormalButton)
03922 return QRect();
03923 case SC_TitleBarMaxButton:
03924 if (maxBtn)
03925 ++btnOffsetCount;
03926 else if (subControl == SC_TitleBarMaxButton)
03927 return QRect();
03928 case SC_TitleBarShadeButton:
03929 if (!isMinimized && shadeBtn)
03930 ++btnOffsetCount;
03931 else if (subControl == SC_TitleBarShadeButton)
03932 return QRect();
03933 case SC_TitleBarUnshadeButton:
03934 if (isMinimized && shadeBtn)
03935 ++btnOffsetCount;
03936 else if (subControl == SC_TitleBarUnshadeButton)
03937 return QRect();
03938 case SC_TitleBarCloseButton:
03939 {
03940 if (menuCloseBtn)
03941 ++btnOffsetCount;
03942 else if (subControl == SC_TitleBarCloseButton)
03943 return QRect();
03944
03945 ret.setRect(ret.right()-btnOffsetCount*btnWidth-(btnOffsetCount-1)*btnSpace,
03946 ret.top(), btnWidth, btnHeight);
03947 break;
03948 }
03949
03950 default:
03951 return QRect();
03952 }
03953
03954 return visualRect(tbOpt->direction, tbOpt->rect, ret);
03955
03956 }
03957
03958 default:
03959 break;
03960 }
03961
03962 return QCommonStyle::subControlRect(control, option, subControl, widget);
03963 }
03964
03965
03966
03967
03968
03969 static bool preceeds(const QPoint &pt, const QRect &bound,
03970 const QStyleOption* opt)
03971 {
03972 if (opt->state & QStyle::State_Horizontal)
03973 {
03974
03975 if (opt->direction == Qt::LeftToRight)
03976 return pt.x() < bound.right();
03977 else
03978 return pt.x() > bound.x();
03979 }
03980 else
03981 {
03982 return pt.y() < bound.y();
03983 }
03984 }
03985
03986 static QStyle::SubControl buttonPortion(const QRect &totalRect,
03987 const QPoint &pt,
03988 const QStyleOption* opt)
03989 {
03990 if (opt->state & QStyle::State_Horizontal)
03991 {
03992
03993 if (opt->direction == Qt::LeftToRight)
03994 return pt.x() < totalRect.center().x() ? QStyle::SC_ScrollBarSubLine : QStyle::SC_ScrollBarAddLine;
03995 else
03996 return pt.x() > totalRect.center().x() ? QStyle::SC_ScrollBarSubLine : QStyle::SC_ScrollBarAddLine;
03997 }
03998 else
03999 {
04000 return pt.y() < totalRect.center().y() ? QStyle::SC_ScrollBarSubLine : QStyle::SC_ScrollBarAddLine;
04001 }
04002 }
04003
04004 QStyle::SubControl KStyle::hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex* opt,
04005 const QPoint& pt, const QWidget* w) const
04006 {
04007 if (cc == CC_ScrollBar)
04008 {
04009
04010 QRect groove = subControlRect(CC_ScrollBar, opt, SC_ScrollBarGroove, w);
04011
04012 if (groove.contains(pt))
04013 {
04014
04015
04016 QRect slider = subControlRect(CC_ScrollBar, opt, SC_ScrollBarSlider, w);
04017
04018 if (slider.contains(pt))
04019 return SC_ScrollBarSlider;
04020 else if (preceeds(pt, slider, opt))
04021 return SC_ScrollBarSubPage;
04022 else
04023 return SC_ScrollBarAddPage;
04024 }
04025 else
04026 {
04027
04028 if (preceeds(pt, groove, opt))
04029 {
04030
04031 if (widgetLayoutProp(WT_ScrollBar, ScrollBar::DoubleTopButton, 0, w))
04032 {
04033 QRect buttonRect = internalSubControlRect(CC_ScrollBar, opt, SC_ScrollBarSubLine, w);
04034 return buttonPortion(buttonRect, pt, opt);
04035 }
04036 else
04037 return SC_ScrollBarSubLine;
04038 }
04039 else
04040 {
04041
04042 if (widgetLayoutProp(WT_ScrollBar, ScrollBar::DoubleBotButton, 0, w))
04043 {
04044 QRect buttonRect = internalSubControlRect(CC_ScrollBar, opt, SC_ScrollBarAddLine, w);
04045 return buttonPortion(buttonRect, pt, opt);
04046 }
04047 else
04048 return SC_ScrollBarAddLine;
04049 }
04050 }
04051 }
04052
04053 return QCommonStyle::hitTestComplexControl(cc, opt, pt, w);
04054 }
04055
04056
04057 QSize KStyle::sizeFromContents(ContentsType type, const QStyleOption* option, const QSize& contentsSize, const QWidget* widget) const
04058 {
04059 switch (type)
04060 {
04061 case CT_PushButton:
04062 {
04063 const QStyleOptionButton* bOpt = qstyleoption_cast<const QStyleOptionButton*>(option);
04064 if (!bOpt) return contentsSize;
04065
04066 QSize size = contentsSize;
04067
04068 if ((bOpt->features & QStyleOptionButton::DefaultButton) || (bOpt->features & QStyleOptionButton::AutoDefaultButton))
04069 size = expandDim(size, WT_PushButton, PushButton::DefaultIndicatorMargin, option, widget);
04070
04071
04072 size = expandDim(size, WT_PushButton, PushButton::ContentsMargin, option, widget);
04073
04074 if (bOpt->features & QStyleOptionButton::HasMenu) {
04075 size.setWidth(size.width() + widgetLayoutProp(WT_PushButton, PushButton::TextToIconSpace, option, widget));
04076 }
04077
04078 if (!bOpt->text.isEmpty() && !bOpt->icon.isNull()) {
04079
04080
04081 size.setWidth(size.width() - 4 + widgetLayoutProp(WT_PushButton, PushButton::TextToIconSpace, option, widget));
04082 }
04083 return size;
04084 }
04085
04086 case CT_ToolButton:
04087 {
04088
04089
04090
04091
04092
04093 QSize size = contentsSize;
04094 int menuAreaWidth = 0;
04095 if (const QStyleOptionToolButton* tbOpt = qstyleoption_cast<const QStyleOptionToolButton*>(option)) {
04096 if (tbOpt->features & QStyleOptionToolButton::MenuButtonPopup)
04097 menuAreaWidth = pixelMetric(QStyle::PM_MenuButtonIndicator, option, widget);
04098 else if (tbOpt->features & QStyleOptionToolButton::HasMenu)
04099 size.setWidth(size.width() + widgetLayoutProp(WT_ToolButton, ToolButton::InlineMenuIndicatorSize, tbOpt, widget));
04100 }
04101
04102 size.setWidth(size.width() - menuAreaWidth);
04103 if (size.width() < size.height())
04104 size.setWidth(size.height());
04105 size.setWidth(size.width() + menuAreaWidth);
04106
04107 return expandDim(size, WT_ToolButton, ToolButton::ContentsMargin, option, widget);
04108 }
04109
04110 case CT_CheckBox:
04111 {
04112
04113 int indicator = widgetLayoutProp(WT_CheckBox, CheckBox::Size, option, widget);
04114 int spacer = widgetLayoutProp(WT_CheckBox, CheckBox::BoxTextSpace, option, widget);
04115
04116
04117 QSize size = expandDim(contentsSize, WT_CheckBox, CheckBox::FocusMargin, option, widget);
04118
04119
04120 size.setHeight(qMax(size.height(), indicator));
04121
04122
04123 size.setWidth(size.width() + indicator + spacer);
04124
04125 return size;
04126 }
04127
04128 case CT_RadioButton:
04129 {
04130
04131 int indicator = widgetLayoutProp(WT_RadioButton, RadioButton::Size, option, widget);
04132 int spacer = widgetLayoutProp(WT_RadioButton, RadioButton::BoxTextSpace, option, widget);
04133
04134
04135 QSize size = expandDim(contentsSize, WT_RadioButton, RadioButton::FocusMargin, option, widget);
04136
04137
04138 size.setHeight(qMax(size.height(), indicator));
04139
04140
04141 size.setWidth(size.width() + indicator + spacer);
04142
04143 return size;
04144 }
04145
04146 case CT_ProgressBar:
04147 {
04148 QSize size = contentsSize;
04149
04150 const QStyleOptionProgressBar* pbOpt = ::qstyleoption_cast<const QStyleOptionProgressBar*>(option);
04151 if (useSideText(pbOpt))
04152 {
04153
04154 size.setWidth(size.width() + sideTextWidth(pbOpt));
04155 }
04156
04157 return size;
04158 }
04159
04160
04161 case CT_MenuBar:
04162 {
04163 int extraW = widgetLayoutProp(WT_MenuBar, MenuBar::Margin + Right, option, widget) -
04164 widgetLayoutProp(WT_MenuBar, MenuBar::Margin + Left, option, widget);
04165
04166 int extraH = widgetLayoutProp(WT_MenuBar, MenuBar::Margin + Bot, option, widget) -
04167 widgetLayoutProp(WT_MenuBar, MenuBar::Margin + Top, option, widget);
04168
04169 return QSize(contentsSize.width() + extraW, contentsSize.height() + extraH);
04170 }
04171
04172 case CT_Menu:
04173 {
04174 int extraW = widgetLayoutProp(WT_Menu, Menu::Margin + Right, option, widget) -
04175 widgetLayoutProp(WT_Menu, Menu::Margin + Left, option, widget);
04176
04177 int extraH = widgetLayoutProp(WT_Menu, Menu::Margin + Bot, option, widget) -
04178 widgetLayoutProp(WT_Menu, Menu::Margin + Top, option, widget);
04179
04180 return QSize(contentsSize.width() + extraW, contentsSize.height() + extraH);
04181 }
04182
04183 case CT_MenuItem:
04184 {
04185 const QStyleOptionMenuItem* miOpt = ::qstyleoption_cast<const QStyleOptionMenuItem*>(option);
04186 if (!miOpt) return contentsSize;
04187
04188
04189 QSize insideSize;
04190
04191 switch (miOpt->menuItemType)
04192 {
04193 case QStyleOptionMenuItem::Normal:
04194 case QStyleOptionMenuItem::DefaultItem:
04195 case QStyleOptionMenuItem::SubMenu:
04196 {
04197 int iconColW = miOpt->maxIconWidth;
04198 iconColW = qMax(iconColW, widgetLayoutProp(WT_MenuItem, MenuItem::IconWidth, option, widget));
04199
04200 int leftColW = iconColW;
04201 if (miOpt->menuHasCheckableItems &&
04202 widgetLayoutProp(WT_MenuItem, MenuItem::CheckAlongsideIcon, option, widget) )
04203 {
04204 leftColW = widgetLayoutProp(WT_MenuItem, MenuItem::CheckWidth, option, widget) +
04205 widgetLayoutProp(WT_MenuItem, MenuItem::CheckSpace, option, widget) +
04206 iconColW;
04207 }
04208
04209 leftColW += widgetLayoutProp(WT_MenuItem, MenuItem::IconSpace, option, widget);
04210
04211 int rightColW = widgetLayoutProp(WT_MenuItem, MenuItem::ArrowSpace, option, widget) +
04212 widgetLayoutProp(WT_MenuItem, MenuItem::ArrowWidth, option, widget);
04213
04214 QFontMetrics fm(miOpt->font);
04215
04216 int textW;
04217 int tabPos = miOpt->text.indexOf(QLatin1Char('\t'));
04218 if (tabPos == -1)
04219 {
04220
04221 textW = contentsSize.width();
04222 }
04223 else
04224 {
04225
04226
04227
04228
04229 textW = contentsSize.width() +
04230 widgetLayoutProp(WT_MenuItem,MenuItem::AccelSpace,option,widget);
04231 }
04232
04233 int h = qMax(contentsSize.height(), widgetLayoutProp(WT_MenuItem, MenuItem::MinHeight, option, widget));
04234 insideSize = QSize(leftColW + textW + rightColW, h);
04235 break;
04236 }
04237
04238 case QStyleOptionMenuItem::Separator:
04239 {
04240 insideSize = QSize(10, widgetLayoutProp(WT_MenuItem, MenuItem::SeparatorHeight, option, widget));
04241 }
04242 break;
04243
04244
04245
04246 case QStyleOptionMenuItem::Scroller:
04247 case QStyleOptionMenuItem::TearOff:
04248 case QStyleOptionMenuItem::Margin:
04249 case QStyleOptionMenuItem::EmptyArea:
04250 return contentsSize;
04251 }
04252
04253
04254 return expandDim(insideSize, WT_MenuItem, MenuItem::Margin, option, widget);
04255 }
04256
04257 case CT_MenuBarItem:
04258 return expandDim(contentsSize, WT_MenuBarItem, MenuBarItem::Margin, option, widget);
04259
04260 case CT_TabBarTab:
04261 {
04262
04263
04264
04265
04266 bool rotated = false;
04267 if (const QStyleOptionTab *tabOpt = qstyleoption_cast<const QStyleOptionTab*>(option)) {
04268 rotated = isVerticalTab(tabOpt);
04269 }
04270
04271 return expandDim(contentsSize, WT_TabBar, TabBar::TabContentsMargin, option, widget, rotated);
04272 }
04273
04274 case CT_TabWidget:
04275 {
04276 const QStyleOptionTabWidgetFrame* tabOpt = qstyleoption_cast<const QStyleOptionTabWidgetFrame*>(option);
04277 if (!tabOpt) break;
04278
04279 int m = widgetLayoutProp(WT_TabWidget, TabWidget::ContentsMargin, option, widget);
04280 int vert = 2*m +
04281 widgetLayoutProp(WT_TabWidget, TabWidget::ContentsMargin+Top, option, widget) +
04282 widgetLayoutProp(WT_TabWidget, TabWidget::ContentsMargin+Bot, option, widget);
04283 int hor = 2*m +
04284 widgetLayoutProp(WT_TabWidget, TabWidget::ContentsMargin+Left, option, widget) +
04285 widgetLayoutProp(WT_TabWidget, TabWidget::ContentsMargin+Right, option, widget);
04286
04287 switch (tabOpt->shape) {
04288 case QTabBar::RoundedNorth:
04289 case QTabBar::TriangularNorth:
04290 case QTabBar::RoundedWest:
04291 case QTabBar::TriangularWest:
04292 return contentsSize + QSize(hor, vert);
04293 case QTabBar::RoundedSouth:
04294 case QTabBar::TriangularSouth:
04295 case QTabBar::RoundedEast:
04296 case QTabBar::TriangularEast:
04297 return contentsSize + QSize(vert,hor);
04298 }
04299 }
04300
04301 case CT_HeaderSection:
04302 {
04303 if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
04304 QSize iconSize = header->icon.isNull() ? QSize(0,0) : QSize(22,22);
04305 QSize textSize = header->fontMetrics.size(0, header->text);
04306 int iconSpacing = widgetLayoutProp(WT_Header, Header::TextToIconSpace, option, widget);
04307 int w = iconSize.width() + iconSpacing + textSize.width();
04308 int h = qMax(iconSize.height(), textSize.height() );
04309
04310 return expandDim(QSize(w, h), WT_Header, Header::ContentsMargin, option, widget);
04311 }
04312 }
04313
04314 case CT_ComboBox:
04315 {
04316
04317 QSize size = contentsSize;
04318
04319
04320 size = expandDim(size, WT_ComboBox, ComboBox::ContentsMargin, option, widget);
04321
04322
04323 size.rwidth() += widgetLayoutProp(WT_ComboBox, ComboBox::ButtonWidth, option, widget);
04324
04325
04326 size.rwidth() += widgetLayoutProp(WT_ComboBox, ComboBox::FrameWidth, option, widget) * 2;
04327 size.rheight() += widgetLayoutProp(WT_ComboBox, ComboBox::FrameWidth, option, widget) * 2;
04328
04329 return size;
04330 }
04331
04332 default:
04333 break;
04334 }
04335
04336 return QCommonStyle::sizeFromContents(type, option, contentsSize, widget);
04337 }
04338
04339 bool KStyle::eventFilter(QObject *obj, QEvent *ev)
04340 {
04341 if (QCommonStyle::eventFilter(obj, ev) )
04342 return true;
04343
04344 if (QLabel *lbl = qobject_cast<QLabel*>(obj) ) {
04345 QWidget *buddy = lbl->buddy();
04346 if (buddy) {
04347 switch (ev->type() ) {
04348 case QEvent::MouseButtonPress:
04349 {
04350 QMouseEvent *mev = dynamic_cast<QMouseEvent*>(ev);
04351 if (!mev) break;
04352
04353 if (lbl->rect().contains(mev->pos() ) ) {
04354 clickedLabel = obj;
04355 lbl->repaint();
04356 }
04357 break;
04358 }
04359 case QEvent::MouseButtonRelease:
04360 {
04361 QMouseEvent *mev = dynamic_cast<QMouseEvent*>(ev);
04362 if (!mev) break;
04363
04364 if (clickedLabel) {
04365 clickedLabel = 0;
04366 lbl->update();
04367 }
04368
04369
04370 if (lbl->rect().contains(mev->pos() ) ) {
04371 buddy->setFocus(Qt::ShortcutFocusReason);
04372 }
04373 break;
04374 }
04375 case QEvent::Paint:
04376 if (obj == clickedLabel && buddy->isEnabled()) {
04377
04378 QPainter p(lbl);
04379 QStyleOptionFocusRect foOpts;
04380 QRect foRect(0,0,lbl->width(),lbl->height());
04381 foOpts.palette = lbl->palette();
04382 foOpts.rect = foRect;
04383 drawKStylePrimitive(WT_Generic, Generic::FocusIndicator, &foOpts,
04384 foRect, lbl->palette(), 0, &p, lbl);
04385 }
04386 break;
04387
04388 default:
04389 break;
04390 }
04391 }
04392 }
04393
04394 return false;
04395 }
04396
04397 KStyle::ColorMode::ColorMode(QPalette::ColorRole _role):
04398 mode(PaletteEntryMode),
04399 role(_role)
04400 {}
04401
04402 KStyle::ColorMode::ColorMode(Mode _mode, QPalette::ColorRole _role):
04403 mode(_mode),
04404 role(_role)
04405 {}
04406
04407 KStyle::ColorMode::operator int() const
04408 {
04409 return int(role) | int(mode);
04410 }
04411
04412 KStyle::ColorMode::ColorMode(int encoded)
04413 {
04414 mode = (encoded & BWAutoContrastMode) ? BWAutoContrastMode : PaletteEntryMode;
04415 role = QPalette::ColorRole(encoded & (~BWAutoContrastMode));
04416 }
04417
04418 QColor KStyle::ColorMode::color(const QPalette& palette)
04419 {
04420 QColor palColor = palette.color(role);
04421
04422 if (mode == BWAutoContrastMode) {
04423 if (qGray(palColor.rgb()) > 128) {
04424 palColor = Qt::black;
04425 } else {
04426 palColor = Qt::white;
04427 }
04428 }
04429 return palColor;
04430 }
04431
04432 KStyle::TextOption::TextOption()
04433 {
04434 init();
04435 }
04436
04437 KStyle::TextOption::TextOption(const QString& _text):
04438 text(_text)
04439 {
04440 init();
04441 }
04442
04443 void KStyle::TextOption::init()
04444 {
04445 hAlign = Qt::AlignLeft;
04446 }
04447
04448