2
* High Contrast Style (version 1.0)
3
* Copyright (C) 2004 Olaf Schmidt <ojschmidt@kde.org>
5
* Derived from Axes Style
6
* Copyright (C) 2003 Maksim Orlovich <orlovich@cs.rochester.edu>
8
* Axes Style based on KDE 3 HighColor Style,
9
* Copyright (C) 2001-2002 Karol Szwed <gallium@kde.org>
10
* (C) 2001-2002 Fredrik Höglund <fredrik@kde.org>
12
* This library is free software; you can redistribute it and/or
13
* modify it under the terms of the GNU Library General Public
14
* License version 2 as published by the Free Software Foundation.
16
* This library is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
* Library General Public License for more details.
21
* You should have received a copy of the GNU Library General Public License
22
* along with this library; see the file COPYING.LIB. If not, write to
23
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24
* Boston, MA 02110-1301, USA.
27
#include "highcontrast.h"
28
#include "highcontrast.moc"
30
#include <QtGui/qdrawutil.h>
31
#include <QtGui/QPainter>
32
#include <Qt3Support/Q3PointArray>
33
#include <QtGui/QStylePlugin>
35
#include <QtGui/QFont>
36
#include <QtGui/QComboBox>
37
#include <Qt3Support/Q3Header>
38
#include <QtGui/QMenuBar>
39
#include <QtGui/QPushButton>
40
#include <QtGui/QScrollBar>
41
#include <QtGui/QSlider>
42
#include <QtGui/QTabBar>
43
#include <QtGui/QToolButton>
44
#include <Qt3Support/Q3ToolBar>
45
#include <QtGui/QMenu>
46
#include <QtGui/QProgressBar>
47
#include <Qt3Support/Q3ListView>
48
#include <QtCore/QSettings>
50
#include <kdrawutil.h>
52
// -- Style Plugin Interface -------------------------
53
class HighContrastStylePlugin : public QStylePlugin
56
HighContrastStylePlugin() {}
57
~HighContrastStylePlugin() {}
59
QStringList keys() const
61
return QStringList() << "HighContrast";
64
QStyle* create( const QString& key )
66
if ( key == "highcontrast" )
67
return new HighContrastStyle();
72
Q_EXPORT_PLUGIN (HighContrastStylePlugin)
73
// ---------------------------------------------------
77
static const int itemFrame = 1;
78
static const int itemHMargin = 3;
79
static const int itemVMargin = 0;
80
static const int arrowHMargin = 6;
81
static const int rightBorder = 12;
84
void addOffset (QRect* r, int offset, int lineWidth = 0)
93
offset1 += lineWidth/2;
94
offset2 += lineWidth - lineWidth/2 - 1;
97
if (offset1 + offset2 > r->width())
98
r->adjust (r->width()/2, 0, - (r->width() - r->width()/2), 0);
100
r->adjust (offset1, 0, -offset2, 0);
102
if (offset1 + offset2 > r->height())
103
r->adjust (0, r->height()/2, 0, - (r->height() - r->height()/2));
105
r->adjust (0, offset1, 0, -offset2);
109
// ---------------------------------------------------------------------------
111
HighContrastStyle::HighContrastStyle()
112
: KStyle( 0, ThreeButtonScrollBar )
115
settings.beginGroup("/highcontraststyle/Settings/");
116
bool useWideLines = settings.readBoolEntry("wideLines", false);
118
basicLineWidth = useWideLines ? 4 : 2;
122
HighContrastStyle::~HighContrastStyle()
127
void HighContrastStyle::polish( QPalette& pal )
129
//We do not want the disabled widgets to be grayed out,
130
//as that may be hard indeed (and since we use crossed-out text instead),
131
//so we make disabled colors be the same as active foreground and
133
for (int c = 0; c < QPalette::NColorRoles; ++c)
136
case QPalette::Button:
138
case QPalette::Highlight:
139
pal.setColor(QPalette::Disabled, QPalette::ColorRole(c), pal.color(QPalette::Active, QPalette::Background));
141
case QPalette::ButtonText:
143
case QPalette::HighlightedText:
144
pal.setColor(QPalette::Disabled, QPalette::ColorRole(c), pal.color(QPalette::Active, QPalette::Foreground));
147
pal.setColor(QPalette::Disabled, QPalette::ColorRole(c), pal.color(QPalette::Active, QPalette::ColorRole(c)));
152
void HighContrastStyle::polish (QWidget* widget)
154
if (widget->inherits ("QButton")
155
|| widget->inherits ("QComboBox")
156
|| widget->inherits ("QSpinWidget")
157
|| widget->inherits ("QLineEdit")
158
|| widget->inherits ("QTextEdit"))
160
widget->installEventFilter (this);
162
Q3SpinWidget* spinwidget = qobject_cast<Q3SpinWidget*>(widget);
163
if (spinwidget && spinwidget->editWidget())
164
spinwidget->editWidget()->installEventFilter (this);
167
KStyle::polish (widget);
171
void HighContrastStyle::unPolish (QWidget* widget)
173
if (widget->inherits ("QWidget") || widget->inherits ("QComboBox") || widget->inherits ("QSpinWidget") || widget->inherits ("QLineEdit") || widget->inherits ("QTextEdit"))
174
widget->removeEventFilter (this);
175
KStyle::unPolish (widget);
178
void HighContrastStyle::setColorsNormal (QPainter* p, const QColorGroup& cg, int flags, int highlight) const
180
setColorsByState (p, cg, cg.foreground(), cg.background(), flags, highlight);
183
void HighContrastStyle::setColorsButton (QPainter* p, const QColorGroup& cg, int flags, int highlight) const
185
setColorsByState (p, cg, cg.buttonText(), cg.button(), flags, highlight);
188
void HighContrastStyle::setColorsText (QPainter* p, const QColorGroup& cg, int flags, int highlight) const
190
setColorsByState (p, cg, cg.text(), cg.base(), flags, highlight);
193
void HighContrastStyle::setColorsHighlight (QPainter* p, const QColorGroup& cg, int flags) const
195
setColorsByState (p, cg, cg.highlightedText(), cg.highlight(), flags, 0);
198
void HighContrastStyle::setColorsByState (QPainter* p, const QColorGroup& cg, const QColor& fg, const QColor& bg, int flags, int highlight) const
200
QFont font = p->font();
201
font.setStrikeOut (! (flags & Style_Enabled));
204
if ((flags & Style_Enabled) && (flags & highlight))
206
p->setPen (QPen (cg.highlightedText(), basicLineWidth, flags & Style_Enabled ? Qt::SolidLine : Qt::DotLine));
207
p->setBackgroundColor (cg.highlight());
211
p->setPen (QPen (fg, basicLineWidth, flags & Style_Enabled ? Qt::SolidLine : Qt::DotLine));
212
p->setBackgroundColor (bg);
215
p->setBrush (QBrush ());
218
void HighContrastStyle::drawRect (QPainter* p, QRect r, int offset, bool filled) const
220
addOffset (&r, offset, p->pen().width());
222
p->fillRect (r, p->background().color());
227
void HighContrastStyle::drawRoundRect (QPainter* p, QRect r, int offset, bool filled) const
229
int lineWidth = p->pen().width();
230
if ((r.width() >= 5*lineWidth + 2*offset) && (r.height() >= 5*lineWidth + 2*offset))
233
addOffset (&r2, offset, lineWidth);
235
addOffset (&r, offset);
237
addOffset (&r3, lineWidth);
240
p->setPen (Qt::NoPen);
242
p->fillRect (r3, p->background().color());
246
p->drawLine (r.left()+lineWidth, r2.top(), r.right()+1-lineWidth, r2.top());
247
p->fillRect (r.left()+1, r.top()+1, lineWidth, lineWidth, p->pen().color());
248
p->drawLine (r2.left(), r.top()+lineWidth, r2.left(), r.bottom()+1-lineWidth);
249
p->fillRect (r.left()+1, r.bottom()-lineWidth, lineWidth, lineWidth, p->pen().color());
250
p->drawLine (r.left()+lineWidth, r2.bottom(), r.right()+1-lineWidth, r2.bottom());
251
p->fillRect (r.right()-lineWidth, r.bottom()-lineWidth, lineWidth, lineWidth, p->pen().color());
252
p->drawLine (r2.right(), r.top()+lineWidth, r2.right(), r.bottom()+1-lineWidth);
253
p->fillRect (r.right()-lineWidth, r.top()+1, lineWidth, lineWidth, p->pen().color());
256
drawRect (p, r, offset, filled);
259
void HighContrastStyle::drawEllipse (QPainter* p, QRect r, int offset, bool filled) const
261
addOffset (&r, offset, p->pen().width());
265
p->setBrush (p->background().color());
266
p->drawRoundRect (r, 99.0, 99.0);
270
p->drawRoundRect (r, 99.0, 99.0);
273
void HighContrastStyle::drawArrow (QPainter* p, QRect r, PrimitiveElement arrow, int offset) const
276
addOffset (&r, offset);
278
QPoint center = r.center();
279
if (r.height() < r.width())
280
r.setWidth (r.height());
281
if (r.width() % 2 != 0)
282
r.setWidth (r.width() - 1);
283
r.setHeight (r.width());
284
r.moveCenter (center);
286
Q3PointArray points (3);
289
case PE_SpinWidgetUp:
290
case PE_SpinWidgetPlus: {
291
points.setPoint (0, r.bottomLeft());
292
points.setPoint (1, r.bottomRight());
293
points.setPoint (2, r.center().x(), r.top() + r.height()/7);
297
case PE_SpinWidgetDown:
298
case PE_SpinWidgetMinus: {
299
points.setPoint (0, r.topLeft());
300
points.setPoint (1, r.topRight());
301
points.setPoint (2, r.center().x(), r.bottom() - r.height()/7);
305
points.setPoint (0, r.topRight());
306
points.setPoint (1, r.bottomRight());
307
points.setPoint (2, r.left() + r.width()/7, r.center().y());
311
points.setPoint (0, r.topLeft());
312
points.setPoint (1, r.bottomLeft());
313
points.setPoint (2, r.right() - r.width()/7, r.center().y());
317
p->setPen (p->pen().color());
318
p->setBrush (p->pen().color());
319
p->drawPolygon (points);
323
// This function draws primitive elements
324
void HighContrastStyle::drawPrimitive (PrimitiveElement pe,
327
const QColorGroup &cg,
329
const QStyleOption& opt ) const
333
case PE_StatusBarSection: {
334
//### TODO: Not everything uses this!
335
setColorsNormal (p, cg, Style_Enabled);
340
// -------------------------------------------------------------------
341
case PE_ButtonDefault:
342
case PE_ButtonDropDown:
343
case PE_ButtonCommand:
345
case PE_ButtonBevel: {
346
setColorsButton (p, cg, flags, Style_On|Style_MouseOver|Style_Down);
347
drawRoundRect (p, r, 0, false);
352
// -------------------------------------------------------------------
355
p->setBrush (QBrush ());
356
p->setPen (QPen (cg.highlight(), basicLineWidth, Qt::SolidLine));
357
drawRoundRect (p, r, basicLineWidth, false);
358
p->setPen (QPen (cg.highlightedText(), basicLineWidth, Qt::DashLine));
359
drawRoundRect (p, r, basicLineWidth, false);
364
case PE_HeaderArrow: {
365
setColorsButton (p, cg, flags, 0);
366
drawArrow (p, r, flags & Style_Down ? PE_ArrowDown : PE_ArrowUp, 2*basicLineWidth);
370
// -------------------------------------------------------------------
371
case PE_HeaderSection: {
372
setColorsButton (p, cg, flags, 0);
379
// -------------------------------------------------------------------
380
case PE_ScrollBarSlider: {
381
setColorsNormal (p, cg);
382
p->fillRect (r, p->background().color());
384
if (flags & Style_Enabled) {
385
setColorsHighlight (p, cg, flags);
386
drawRoundRect (p, r);
388
if (r.width() >= 7*basicLineWidth && r.height() >= 7*basicLineWidth) {
390
r2.setWidth (4*basicLineWidth);
391
r2.setHeight (4*basicLineWidth);
392
r2.moveCenter (r.center());
393
drawRect (p, r2, 0, false);
399
case PE_ScrollBarAddPage:
400
case PE_ScrollBarSubPage: {
401
setColorsNormal (p, cg);
402
p->fillRect (r, p->background().color());
405
if (flags & Style_Horizontal)
407
if (r2.height() > 5*basicLineWidth)
409
r2.setHeight (5*basicLineWidth);
410
r2.moveCenter (r.center());
415
if (r2.width() > 5*basicLineWidth)
417
r2.setWidth (5*basicLineWidth);
418
r2.moveCenter (r.center());
421
setColorsText (p, cg, flags);
424
if (flags & Style_Horizontal)
425
r2.adjust (0, basicLineWidth, 0, -basicLineWidth);
427
r2.adjust (basicLineWidth, 0, -basicLineWidth, 0);
429
pen.setColor (p->background().color());
436
case PE_ScrollBarAddLine:
437
case PE_ScrollBarSubLine:
438
case PE_ScrollBarFirst:
439
case PE_ScrollBarLast: {
440
setColorsNormal (p, cg);
441
p->fillRect (r, p->background().color());
443
if (flags & Style_Enabled) {
444
setColorsButton (p, cg, flags);
445
drawRoundRect (p, r);
446
if (pe == PE_ScrollBarAddLine)
447
drawArrow (p, r, flags & Style_Horizontal ? PE_ArrowRight : PE_ArrowDown, r.height()/3);
448
else if (pe == PE_ScrollBarSubLine)
449
drawArrow (p, r, flags & Style_Horizontal ? PE_ArrowLeft : PE_ArrowUp, r.height()/3);
455
case PE_ProgressBarChunk: {
456
p->fillRect (r, Qt::color1);
462
// -------------------------------------------------------------------
464
setColorsText (p, cg, flags);
466
//Draw the outer rect
469
if (!(flags & Style_Off))
472
addOffset (&r2, basicLineWidth);
473
if (flags & Style_On)
475
p->drawLine (r2.topLeft(), r2.bottomRight());
476
p->drawLine (r2.bottomLeft(), r2.topRight());
480
p->drawLine (r2.left(), r2.top()+r2.width()/2, r2.right(), r2.top()+r2.width()/2);
483
pen.setColor (p->background().color());
485
drawRect (p, r2, 0, false);
489
case PE_IndicatorMask: {
490
p->fillRect (r, Qt::color1);
494
setColorsText (p, cg, flags);
496
if (flags & Style_On)
498
p->drawLine (r.topLeft(), r.bottomRight());
499
p->drawLine (r.bottomLeft(), r.topRight());
504
// RADIOBUTTON (exclusive indicator)
505
// -------------------------------------------------------------------
506
case PE_ExclusiveIndicator: {
507
setColorsText (p, cg, flags);
511
if (flags & Style_On) {
512
p->setBackgroundColor (p->pen().color());
513
drawEllipse (p, r, 2*p->pen().width());
518
case PE_ExclusiveIndicatorMask: {
519
p->fillRect (r, Qt::color0);
520
p->setBackgroundColor (Qt::color1);
521
p->setPen (Qt::NoPen);
522
p->setBrush (Qt::color1);
528
// SPLITTER/DOCKWINDOW HANDLES
529
// -------------------------------------------------------------------
530
case PE_DockWindowResizeHandle:
532
setColorsButton (p, cg, flags);
533
p->fillRect (r, p->background().color());
535
p->setPen (QPen (p->pen().color(), 1, Qt::DashLine));
536
if (flags & Style_Horizontal)
537
p->drawLine (r.center().x(), r.top(), r.center().x(), r.bottom());
539
p->drawLine (r.left(), r.center().y(), r.right(), r.center().y());
545
// -------------------------------------------------------------------
547
case PE_GroupBoxFrame:
548
case PE_PanelPopup: {
549
setColorsNormal (p, cg, flags, 0);
550
if (!opt.isDefault())
553
pen.setWidth (opt.lineWidth());
556
if (pe == PE_PanelPopup)
557
drawRect (p, r, 0, false);
559
drawRoundRect (p, r, 0, false);
563
case PE_TabBarBase: {
564
setColorsNormal (p, cg, flags, 0);
565
drawRect (p, r, 0, false);
568
case PE_PanelLineEdit: {
569
setColorsText (p, cg, flags, 0);
570
drawRoundRect (p, r);
571
if (flags & (Style_HasFocus | Style_Active))
572
drawPrimitive (PE_FocusRect, p, r, cg, flags, QStyleOption (p->background().color()));
575
case PE_PanelTabWidget:
576
case PE_PanelGroupBox: {
577
setColorsNormal (p, cg, flags, 0);
578
drawRoundRect (p, r);
581
case PE_PanelMenuBar: { // Menu
582
p->fillRect (r, cg.background());
585
case PE_PanelDockWindow: { // Toolbar
586
p->fillRect (r, cg.button());
593
// -------------------------------------------------------------------
595
setColorsNormal (p, cg);
596
p->fillRect (r, p->background().color());
597
p->setPen (p->pen().color());
598
if (flags & Style_Horizontal)
599
p->drawLine (r.center().x(), r.top()+basicLineWidth, r.center().x(), r.bottom()-basicLineWidth + 1);
601
p->drawLine (r.left()+basicLineWidth, r.center().y(), r.right()-basicLineWidth + 1, r.center().y());
604
case PE_DockWindowSeparator: {
605
setColorsButton (p, cg);
606
p->fillRect (r, p->background().color());
607
p->setPen (p->pen().color());
608
if (flags & Style_Horizontal)
609
p->drawLine (r.center().x(), r.top()+basicLineWidth, r.center().x(), r.bottom()-basicLineWidth);
611
p->drawLine (r.left()+basicLineWidth, r.center().y(), r.right()-basicLineWidth, r.center().y());
617
// -------------------------------------------------------------------
622
case PE_SpinWidgetPlus:
623
case PE_SpinWidgetUp:
624
case PE_SpinWidgetMinus:
625
case PE_SpinWidgetDown: {
626
setColorsNormal (p, cg, flags);
627
drawArrow (p, r, pe);
632
KStyle::drawPrimitive( pe, p, r, cg, flags, opt );
638
void HighContrastStyle::drawKStylePrimitive (KStylePrimitive kpe,
640
const QWidget* widget,
642
const QColorGroup &cg,
644
const QStyleOption &opt ) const
646
if ( widget == hoverWidget )
647
flags |= Style_MouseOver;
652
// -------------------------------------------------------------------
653
case KPE_ToolBarHandle:
654
case KPE_DockWindowHandle:
655
case KPE_GeneralHandle:
657
setColorsButton (p, cg);
658
p->fillRect (r, p->background().color());
659
p->setBrush (QBrush (p->pen().color(), Qt::BDiagPattern));
660
drawRoundRect (p, r);
666
// -------------------------------------------------------------------
667
case KPE_SliderGroove: {
668
setColorsText (p, cg, flags);
670
const QSlider *slider = qobject_cast<const QSlider*>(widget);
673
if (slider->orientation() == Qt::Horizontal)
675
if (r2.height() > 5*basicLineWidth)
677
r2.setHeight (5*basicLineWidth);
678
r2.moveCenter (r.center());
683
if (r2.width() > 5*basicLineWidth)
685
r2.setWidth (5*basicLineWidth);
686
r2.moveCenter (r.center());
691
drawRoundRect (p, r2);
696
// -------------------------------------------------------------------
697
case KPE_SliderHandle: {
698
setColorsHighlight (p, cg, flags);
699
drawRoundRect (p, r);
703
case KPE_ListViewExpander: {
704
// TODO There is no pixelMetric associated with the
705
// ListViewExpander in KStyle.
706
// To have a properly large expander, the CC_ListView case of
707
// drawComplexControl should be handled.
708
// Probably it would be better to add a KPM_ListViewExpander metric
709
// to the KStyle KStylePixelMetric enum, and have the KStyle
710
// drawComplexControl handle it.
711
PrimitiveElement direction;
712
if (flags & Style_On) { // Collapsed = On
713
direction = PE_ArrowRight;
716
direction = PE_ArrowDown;
718
setColorsText (p, cg, flags);
719
drawArrow (p, r, direction);
722
case KPE_ListViewBranch:
723
// TODO Draw (thick) dotted line. Check kstyle.cpp
726
KStyle::drawKStylePrimitive( kpe, p, widget, r, cg, flags, opt);
731
void HighContrastStyle::drawControl (ControlElement element,
733
const QWidget *widget,
735
const QColorGroup &cg,
737
const QStyleOption& opt ) const
739
if ( widget == hoverWidget )
740
flags |= Style_MouseOver;
745
// -------------------------------------------------------------------
746
case CE_ToolBoxTab: {
747
setColorsNormal (p, cg, flags, Style_Selected);
748
drawRoundRect (p, r);
753
setColorsNormal (p, cg, flags, Style_Selected);
754
drawRoundRect (p, r);
756
const QTabBar *tb = static_cast< const QTabBar * >(widget);
757
QTabBar::Shape shape = tb->shape();
758
if (shape == QTabBar:: TriangularSouth ||
759
shape == QTabBar:: RoundedSouth) {
760
p->fillRect (r.left(), r.top(),
761
r.width(), 2*basicLineWidth,
763
p->fillRect (r.left()+basicLineWidth,
764
flags & Style_Selected ? basicLineWidth : 2*basicLineWidth,
765
r.width()-2*basicLineWidth,
767
p->background().color());
769
p->fillRect (r.left(), r.bottom()-2*basicLineWidth+1,
770
r.width(), 2*basicLineWidth,
772
p->fillRect (r.left()+basicLineWidth,
773
r.bottom()-2*basicLineWidth+1,
774
r.width()-2*basicLineWidth,
775
flags & Style_Selected ? 2*basicLineWidth : basicLineWidth,
776
p->background().color());
783
// -------------------------------------------------------------------
784
case CE_PushButton: {
785
QPushButton *button = (QPushButton*) widget;
787
bool btnDefault = button->isDefault();
789
if (( btnDefault || button->autoDefault() ) && (button->isEnabled())) {
790
// Compensate for default indicator
791
static int di = pixelMetric( PM_ButtonDefaultIndicator );
795
if ( btnDefault && (button->isEnabled()))
796
drawPrimitive( PE_ButtonDefault, p, r, cg, flags );
798
drawPrimitive( PE_ButtonCommand, p, br, cg, flags );
805
// -------------------------------------------------------------------
806
case CE_ProgressBarLabel:
808
case CE_RadioButtonLabel:
809
case CE_CheckBoxLabel:
810
case CE_ToolButtonLabel:
811
case CE_PushButtonLabel: {
812
const QPixmap* pixmap = 0;
817
QIcon::Mode mode = flags & Style_Enabled ? ((flags & Style_HasFocus) ? QIcon::Active : QIcon::Normal) : QIcon::Disabled;
818
QIcon::State state = flags & Style_On ? QIcon::On : QIcon::Off;
821
r.rect( &x, &y, &w, &h );
823
if (element == CE_ProgressBarLabel) {
824
QProgressBar* progressbar = (QProgressBar*) widget;
825
text = progressbar->progressString();
826
setColorsNormal (p, cg, flags);
828
else if (element == CE_TabBarLabel) {
829
if (!opt.isDefault()) {
830
QTab* tab = opt.tab();
833
setColorsNormal (p, cg, flags, Style_Selected);
835
else if (element == CE_ToolButtonLabel) {
836
QToolButton* toolbutton = (QToolButton*) widget;
837
text = toolbutton->text();
838
pixmap = toolbutton->pixmap();
839
if (!toolbutton->iconSet().isNull())
840
icon = toolbutton->iconSet().pixmap (QIcon::Small, mode, state);
841
popup = toolbutton->popup();
842
setColorsButton (p, cg, flags);
844
else if (element == CE_PushButtonLabel) {
845
QPushButton* pushbutton = (QPushButton*) widget;
846
text = pushbutton->text();
847
pixmap = pushbutton->pixmap();
848
if (pushbutton->iconSet() && !pushbutton->iconSet()->isNull())
849
icon = pushbutton->iconSet()->pixmap (QIcon::Small, mode, state);
850
popup = pushbutton->popup();
851
setColorsButton (p, cg, flags);
854
const Q3Button* button = (const Q3Button*)widget;
855
pixmap = button->pixmap();
856
text = button->text();
857
setColorsNormal (p, cg);
860
// Does the button have a popup menu?
862
int dx = pixelMetric (PM_MenuButtonIndicator, widget);
863
drawArrow (p, QRect(x + w - dx - 2, y + 2, dx, h - 4), PE_ArrowDown);
867
// Draw the icon if there is one
870
// Center the iconset if there's no text or pixmap
871
if (text.isEmpty() && ((pixmap == 0) || pixmap->isNull()))
872
p->drawPixmap (x + (w - icon.width()) / 2,
873
y + (h - icon.height()) / 2, icon);
875
p->drawPixmap (x + 4, y + (h - icon.height()) / 2, icon);
877
int pw = icon.width();
882
// Draw a focus rect if the button has focus
883
if (flags & Style_HasFocus)
884
drawPrimitive (PE_FocusRect, p, r, cg, flags, QStyleOption (p->background().color()));
886
// Draw the label itself
887
QColor color = p->pen().color();
888
drawItem (p, QRect(x, y, w, h),
889
(element == CE_RadioButtonLabel || element == CE_CheckBoxLabel || element == CE_ProgressBarLabel) ? Qt::AlignVCenter|Qt::AlignLeft|Qt::TextShowMnemonic : Qt::AlignCenter|Qt::TextShowMnemonic,
890
cg, flags & Style_Enabled, pixmap, text, -1, &color);
894
// MENUBAR BACKGROUND
895
// -------------------------------------------------------------------
896
case CE_MenuBarEmptyArea:
898
p->fillRect (r, cg.background());
902
// DOCKWINDOW BACKGROUND
903
// -------------------------------------------------------------------
904
case CE_DockWindowEmptyArea:
906
p->fillRect (r, cg.button());
911
// -------------------------------------------------------------------
912
case CE_MenuBarItem: {
913
setColorsNormal (p, cg, flags, Style_Active|Style_MouseOver);
914
p->fillRect (r, p->background().color());
915
if (!opt.isDefault()) {
916
QMenuItem *mi = opt.menuItem();
918
QColor color = p->pen().color();
919
drawItem (p, r, Qt::AlignCenter | Qt::AlignVCenter | Qt::TextShowMnemonic
920
| Qt::TextDontClip | Qt::TextSingleLine, cg, flags,
921
mi->pixmap(), mi->text(), -1, &color);
927
// -------------------------------------------------------------------
929
drawPrimitive (PE_Indicator, p, r, cg, flags);
934
// -------------------------------------------------------------------
935
case CE_RadioButton: {
936
drawPrimitive (PE_ExclusiveIndicator, p, r, cg, flags);
941
// -------------------------------------------------------------------
942
case CE_ProgressBarGroove: {
943
setColorsText (p, cg, flags);
944
const QProgressBar *progressbar = qobject_cast<const QProgressBar*>(widget);
947
r2.setLeft (p->boundingRect (r, Qt::AlignVCenter|Qt::AlignLeft|Qt::TextShowMnemonic, progressbar->progressString()).right()
949
drawRoundRect (p, r2);
953
case CE_ProgressBarContents: {
954
const QProgressBar *progressbar = qobject_cast<const QProgressBar*>(widget);
958
r2.setLeft (p->boundingRect (r, Qt::AlignVCenter|Qt::AlignLeft|Qt::TextShowMnemonic, progressbar->progressString()).right()
960
long progress = r2.width() * progressbar->progress();
961
if (progressbar->totalSteps() > 0)
963
r2.setWidth (progress / progressbar->totalSteps());
967
int width = r2.width() / 5;
968
int left = progressbar->progress() % (2*(r2.width() - width));
969
if (left > r2.width() - width)
970
left = 2*(r2.width() - width) - left;
971
r2.setLeft (r2.left() + left);
974
setColorsHighlight (p, cg, flags);
976
drawRoundRect (p, r2);
982
// -------------------------------------------------------------------
983
case CE_PopupMenuItem: {
984
setColorsNormal (p, cg, flags, Style_Active|Style_MouseOver);
985
p->fillRect (r, p->background().color());
987
const QMenu *popupmenu = (const QMenu *) widget;
988
QMenuItem *mi = opt.menuItem();
992
int tab = opt.tabWidth();
993
int checkcol = opt.maxIconWidth();
994
bool checkable = popupmenu->isCheckable();
995
bool reverse = QApplication::isRightToLeft();
997
r.rect( &x, &y, &w, &h );
1000
checkcol = qMax( checkcol, 20 );
1002
// Are we a menu item separator?
1003
if ( mi->isSeparator() ) {
1004
p->drawLine (r.left() + 1, r.center().y(), r.right(), r.center().y());
1008
// Do we have an icon?
1009
if ( mi->iconSet() && !mi->iconSet()->isNull() ) {
1011
QRect cr = visualRect( QRect(x, y, checkcol, h), r );
1013
// Select the correct icon from the iconset
1014
if (!(flags & Style_Enabled))
1015
mode = QIcon::Disabled;
1016
else if (flags & Style_Active)
1017
mode = QIcon::Active;
1019
mode = QIcon::Normal;
1022
QPixmap pixmap = mi->iconSet()->pixmap( QIcon::Small, mode );
1023
QRect pmr( 0, 0, pixmap.width(), pixmap.height() );
1024
pmr.moveCenter( cr.center() );
1025
p->drawPixmap( pmr.topLeft(), pixmap );
1027
// Do we have an icon and are checked at the same time?
1028
// Then draw a square border around the icon
1029
if ( checkable && mi->isChecked() )
1031
drawRect (p, cr, 0, false);
1035
// Are we checked? (This time without an icon)
1036
else if ( checkable && mi->isChecked() ) {
1037
int cx = reverse ? x+w - checkcol : x;
1039
QRect rc (cx, y, checkcol, h);
1040
addOffset (&rc, 2*basicLineWidth);
1041
QPoint center = rc.center();
1042
if (rc.width() > rc.height())
1043
rc.setWidth (rc.height());
1045
rc.setHeight (rc.width());
1046
rc.moveCenter (center);
1048
p->drawLine (rc.topLeft(), rc.bottomRight());
1049
p->drawLine (rc.topRight(), rc.bottomLeft());
1052
// Time to draw the menu item label...
1053
int xm = itemFrame + checkcol + itemHMargin; // X position margin
1055
int xp = reverse ? // X position
1056
x + tab + rightBorder + itemHMargin + itemFrame - 1 :
1059
// Label width (minus the width of the accelerator portion)
1060
int tw = w - xm - tab - arrowHMargin - itemHMargin * 3 - itemFrame + 1;
1062
// Does the menu item draw it's own label?
1063
if ( mi->custom() ) {
1064
int m = itemVMargin;
1065
// Save the painter state in case the custom
1066
// paint method changes it in some way
1068
mi->custom()->paint( p, cg, flags & Style_Active, flags & Style_Enabled, xp, y+m, tw, h-2*m );
1072
// The menu item doesn't draw it's own label
1073
QString s = mi->text();
1075
// Does the menu item have a text label?
1076
if ( !s.isNull() ) {
1077
int t = s.find( '\t' );
1078
int m = itemVMargin;
1079
int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
1080
text_flags |= reverse ? Qt::AlignRight : Qt::AlignLeft;
1082
// Does the menu item have a tabstop? (for the accelerator text)
1084
int tabx = reverse ? x + rightBorder + itemHMargin + itemFrame :
1085
x + w - tab - rightBorder - itemHMargin - itemFrame;
1087
// Draw the right part of the label (accelerator text)
1088
p->drawText( tabx, y+m, tab, h-2*m, text_flags, s.mid( t+1 ) );
1092
// Draw the left part of the label (or the whole label
1093
// if there's no accelerator)
1095
p->drawText( xp, y+m, tw, h-2*m, text_flags, s, t );
1099
// The menu item doesn't have a text label
1100
// Check if it has a pixmap instead
1101
else if ( mi->pixmap() ) {
1102
QPixmap *pixmap = mi->pixmap();
1105
if ( pixmap->depth() == 1 )
1106
p->setBackgroundMode( Qt::OpaqueMode );
1108
int diffw = ( ( w - pixmap->width() ) / 2 )
1109
+ ( ( w - pixmap->width() ) % 2 );
1110
p->drawPixmap( x+diffw, y+itemFrame, *pixmap );
1112
if ( pixmap->depth() == 1 )
1113
p->setBackgroundMode( Qt::TransparentMode );
1117
// Does the menu item have a submenu?
1118
if ( mi->popup() ) {
1119
PrimitiveElement arrow = reverse ? PE_ArrowLeft : PE_ArrowRight;
1120
int dim = pixelMetric(PM_MenuButtonIndicator);
1121
QRect vr = visualRect( QRect( x + w - arrowHMargin - 2*itemFrame - dim,
1122
y + h / 2 - dim / 2, dim, dim), r );
1124
// Draw an arrow at the far end of the menu item
1125
drawArrow (p, vr, arrow);
1131
KStyle::drawControl(element, p, widget, r, cg, flags, opt);
1135
void HighContrastStyle::drawControlMask (ControlElement element,
1139
const QStyleOption &opt) const
1145
case CE_ProgressBarLabel:
1146
case CE_TabBarLabel:
1147
case CE_RadioButtonLabel:
1148
case CE_CheckBoxLabel:
1149
case CE_ToolButtonLabel:
1150
case CE_PushButtonLabel:
1151
case CE_MenuBarEmptyArea:
1152
case CE_MenuBarItem:
1153
case CE_PopupMenuItem: {
1154
p->fillRect (r, Qt::color0);
1159
KStyle::drawControlMask (element, p, w, r, opt);
1164
// Helper to find the next sibling that's not hidden
1165
// Lifted from kstyle.cpp
1166
static Q3ListViewItem* nextVisibleSibling(Q3ListViewItem* item)
1168
Q3ListViewItem* sibling = item;
1171
sibling = sibling->nextSibling();
1173
while (sibling && !sibling->isVisible());
1178
void HighContrastStyle::drawComplexControl (ComplexControl control,
1180
const QWidget *widget,
1182
const QColorGroup &cg,
1186
const QStyleOption& opt ) const
1188
if ( widget == hoverWidget )
1189
flags |= Style_MouseOver;
1194
// -------------------------------------------------------------------
1196
setColorsText (p, cg, flags);
1197
drawRoundRect (p, r);
1199
QRect r2 = QStyle::visualRect (querySubControlMetrics (CC_ComboBox, widget, SC_ComboBoxArrow), widget);
1200
if (flags & Style_HasFocus) {
1203
r3.setRight (r2.left()+basicLineWidth-1);
1205
r3.setLeft (r2.right()-basicLineWidth+1);
1207
drawPrimitive (PE_FocusRect, p, r3, cg, flags, QStyleOption (p->background().color()));
1210
setColorsButton (p, cg, flags);
1211
// Draw arrow if required
1212
if (controls & SC_ComboBoxArrow) {
1213
drawRoundRect (p, r2);
1214
drawArrow (p, r2, PE_ArrowDown, 2*basicLineWidth);
1217
setColorsText (p, cg, flags);
1222
// -------------------------------------------------------------------
1223
case CC_SpinWidget: {
1224
if (controls & SC_SpinWidgetFrame) {
1225
setColorsText (p, cg, flags);
1226
drawRoundRect (p, r);
1227
if (flags & Style_HasFocus)
1228
drawPrimitive(PE_FocusRect, p, r, cg, flags, QStyleOption (p->background().color()));
1231
setColorsButton (p, cg, flags);
1232
// Draw arrows if required
1233
if (controls & SC_SpinWidgetDown) {
1234
QRect r2 = QStyle::visualRect (querySubControlMetrics (CC_SpinWidget, widget, SC_SpinWidgetDown), widget);
1235
drawRoundRect (p, r2);
1236
drawArrow (p, r2, PE_SpinWidgetDown, 2*basicLineWidth);
1238
if (controls & SC_SpinWidgetUp) {
1239
QRect r2 = QStyle::visualRect (querySubControlMetrics (CC_SpinWidget, widget, SC_SpinWidgetUp), widget);
1240
drawRoundRect (p, r2);
1241
drawArrow (p, r2, PE_SpinWidgetUp, 2*basicLineWidth);
1244
setColorsText (p, cg, flags);
1249
// -------------------------------------------------------------------
1250
case CC_ToolButton: {
1251
const QToolButton *toolbutton = (const QToolButton *) widget;
1253
setColorsButton (p, cg, flags);
1254
p->fillRect (r, p->background().color());
1256
QRect button, menuarea;
1257
button = querySubControlMetrics(control, widget, SC_ToolButton, opt);
1258
menuarea = querySubControlMetrics(control, widget, SC_ToolButtonMenu, opt);
1260
SFlags bflags = flags,
1263
if (active & SC_ToolButton)
1264
bflags |= Style_Down;
1265
if (active & SC_ToolButtonMenu)
1266
mflags |= Style_Down;
1268
if (controls & SC_ToolButton)
1270
// If we're pressed, on, or raised...
1271
if (bflags & (Style_Down | Style_On | Style_Raised))
1272
drawPrimitive(PE_ButtonTool, p, button, cg, bflags, opt);
1274
// Check whether to draw a background pixmap
1275
else if ( toolbutton->parentWidget() &&
1276
toolbutton->parentWidget()->backgroundPixmap() &&
1277
!toolbutton->parentWidget()->backgroundPixmap()->isNull() )
1279
QPixmap pixmap = *(toolbutton->parentWidget()->backgroundPixmap());
1280
p->drawTiledPixmap( r, pixmap, toolbutton->pos() );
1284
// Draw a toolbutton menu indicator if required
1285
if (controls & SC_ToolButtonMenu)
1287
if (mflags & (Style_Down | Style_On | Style_Raised))
1288
drawPrimitive(PE_ButtonDropDown, p, menuarea, cg, mflags, opt);
1289
drawArrow (p, menuarea, PE_ArrowDown);
1292
if (toolbutton->hasFocus() && !toolbutton->focusProxy()) {
1293
QRect fr = toolbutton->rect();
1295
drawPrimitive(PE_FocusRect, p, fr, cg, flags, QStyleOption (p->background().color()));
1302
// -------------------------------------------------------------------
1305
* Sigh... Lifted and modified from kstyle.cpp
1308
* Many thanks to TrollTech AS for donating CC_ListView from QWindowsStyle.
1309
* CC_ListView code is Copyright (C) 1998-2000 TrollTech AS.
1312
// Paint the icon and text.
1313
if ( controls & SC_ListView )
1314
QCommonStyle::drawComplexControl( control, p, widget, r, cg, flags, controls, active, opt );
1316
// If we're have a branch or are expanded...
1317
if ( controls & (SC_ListViewBranch | SC_ListViewExpand) )
1319
// If no list view item was supplied, break
1320
if (opt.isDefault())
1323
Q3ListViewItem *item = opt.listViewItem();
1324
Q3ListViewItem *child = item->firstChild();
1327
int c; // dotline vertice count
1329
Q3PointArray dotlines;
1331
if ( active == SC_All && controls == SC_ListViewExpand ) {
1332
// We only need to draw a vertical line
1335
dotlines[0] = QPoint( r.right(), r.top() );
1336
dotlines[1] = QPoint( r.right(), r.bottom() );
1340
int linetop = 0, linebot = 0;
1341
// each branch needs at most two lines, ie. four end points
1342
dotoffset = (item->itemPos() + item->height() - y) % 2;
1343
dotlines.resize( item->childCount() * 4 );
1346
// skip the stuff above the exposed rectangle
1347
while ( child && y + child->height() <= 0 )
1349
y += child->totalHeight();
1350
child = nextVisibleSibling(child);
1353
int bx = r.width() / 2;
1355
// paint stuff in the magical area
1356
Q3ListView* v = item->listView();
1357
int lh = qMax( p->fontMetrics().height() + 2 * v->itemMargin(),
1358
QApplication::globalStrut().height() );
1362
// Draw all the expand/close boxes...
1364
QStyle::StyleFlags boxflags;
1365
while ( child && y < r.height() )
1368
if ( (child->isExpandable() || child->childCount()) &&
1369
(child->height() > 0) )
1371
int h = qMin(lh, 24) - 4*basicLineWidth;
1375
h &= ~1; // Force an even number of pixels
1377
// The primitive requires a rect.
1378
boxrect = QRect( bx-h/2, linebot-h/2, h, h );
1379
boxflags = child->isOpen() ? QStyle::State_Off : QStyle::State_On;
1381
// KStyle extension: Draw the box and expand/collapse indicator
1382
drawKStylePrimitive( KPE_ListViewExpander, p, NULL, boxrect, cg, boxflags, opt );
1385
p->setPen( cg.mid() );
1386
dotlines[c++] = QPoint( bx, linetop );
1387
dotlines[c++] = QPoint( bx, linebot - 5 );
1388
dotlines[c++] = QPoint( bx + 5, linebot );
1389
dotlines[c++] = QPoint( r.width(), linebot );
1390
linetop = linebot + 5;
1393
dotlines[c++] = QPoint( bx+1, linebot );
1394
dotlines[c++] = QPoint( r.width(), linebot );
1397
y += child->totalHeight();
1398
child = nextVisibleSibling(child);
1401
if ( child ) // there's a child to draw, so move linebot to edge of rectangle
1402
linebot = r.height();
1404
if ( linetop < linebot )
1406
dotlines[c++] = QPoint( bx, linetop );
1407
dotlines[c++] = QPoint( bx, linebot );
1411
// Draw all the branches...
1412
static int thickness = kPixelMetric( KPM_ListViewBranchThickness );
1413
int line; // index into dotlines
1415
QStyle::StyleFlags branchflags;
1416
for( line = 0; line < c; line += 2 )
1418
// assumptions here: lines are horizontal or vertical.
1419
// lines always start with the numerically lowest
1422
// point ... relevant coordinate of current point
1423
// end ..... same coordinate of the end of the current line
1424
// other ... the other coordinate of the current point/line
1425
if ( dotlines[line].y() == dotlines[line+1].y() )
1427
// Horizontal branch
1428
int end = dotlines[line+1].x();
1429
int point = dotlines[line].x();
1430
int other = dotlines[line].y();
1432
branchrect = QRect( point, other-(thickness/2), end-point, thickness );
1433
branchflags = QStyle::State_Horizontal;
1435
// KStyle extension: Draw the horizontal branch
1436
drawKStylePrimitive( KPE_ListViewBranch, p, NULL, branchrect, cg, branchflags, opt );
1440
int end = dotlines[line+1].y();
1441
int point = dotlines[line].y();
1442
int other = dotlines[line].x();
1443
int pixmapoffset = ((point & 1) != dotoffset ) ? 1 : 0;
1445
branchrect = QRect( other-(thickness/2), point, thickness, end-point );
1446
if (!pixmapoffset) // ### Hackish - used to hint the offset
1447
branchflags = QStyle::State_NoChange;
1449
branchflags = QStyle::State_None;
1451
// KStyle extension: Draw the vertical branch
1452
drawKStylePrimitive( KPE_ListViewBranch, p, NULL, branchrect, cg, branchflags, opt );
1460
KStyle::drawComplexControl(control, p, widget,
1461
r, cg, flags, controls, active, opt);
1466
void HighContrastStyle::drawComplexControlMask(ComplexControl c,
1470
const QStyleOption &o) const
1476
p->fillRect (r, Qt::color0);
1480
KStyle::drawComplexControlMask (c, p, w, r, o);
1485
void HighContrastStyle::drawItem( QPainter *p,
1488
const QColorGroup &cg,
1490
const QPixmap *pixmap,
1491
const QString &text,
1493
const QColor *penColor ) const
1497
// make the disabled things use the cross-line
1498
QFont font = p->font();
1499
font.setStrikeOut (!enabled);
1502
enabled = true; //do not ghost it in Qt
1504
KStyle::drawItem (p, r, flags, cg, enabled, pixmap, text, len, penColor);
1509
QRect HighContrastStyle::querySubControlMetrics( ComplexControl control,
1510
const QWidget* widget,
1511
SubControl subcontrol,
1512
const QStyleOption& opt ) const
1516
case CC_ComboBox : {
1517
int arrow = pixelMetric (PM_ScrollBarExtent, widget);
1520
case SC_ComboBoxFrame:
1521
return QRect (0, 0, widget->width(), widget->height());
1522
case SC_ComboBoxArrow:
1523
return QRect (widget->width() - arrow, 0, arrow, widget->height());
1524
case SC_ComboBoxEditField:
1525
return QRect (2*basicLineWidth, 2*basicLineWidth,
1526
widget->width() - arrow - 3*basicLineWidth, widget->height() - 4*basicLineWidth);
1532
case CC_SpinWidget : {
1533
int arrow = pixelMetric (PM_ScrollBarExtent, 0);
1536
case SC_SpinWidgetFrame:
1537
return QRect (0, 0, widget->width(), widget->height());
1538
case SC_SpinWidgetButtonField:
1539
return QRect (widget->width() - arrow, 0, arrow, widget->height());
1540
case SC_SpinWidgetUp:
1541
return QRect (widget->width() - arrow, 0, arrow, widget->height()/2);
1542
case SC_SpinWidgetDown:
1543
return QRect (widget->width() - arrow, widget->height()/2,
1544
arrow, widget->height()-widget->height()/2);
1545
case SC_SpinWidgetEditField:
1546
return QRect (2*basicLineWidth, 2*basicLineWidth,
1547
widget->width() - arrow - 3*basicLineWidth, widget->height() - 4*basicLineWidth);
1557
return KStyle::querySubControlMetrics (control, widget, subcontrol, opt);
1561
int HighContrastStyle::pixelMetric(PixelMetric m, const QWidget *widget) const
1563
//### TODO: Use the tab metrics changes from Ker.
1567
// -------------------------------------------------------------------
1568
case PM_ButtonMargin: // Space btw. frame and label
1569
return 2*basicLineWidth;
1571
case PM_ButtonDefaultIndicator: {
1572
if ((widget != 0) && !widget->isEnabled())
1575
return 2*basicLineWidth;
1578
case PM_ButtonShiftHorizontal:
1579
case PM_ButtonShiftVertical:
1582
case PM_ScrollBarExtent: {
1585
h = (2*widget->fontMetrics().lineSpacing())/3;
1587
if (h > 9*basicLineWidth+4)
1590
return 9*basicLineWidth+4;
1593
case PM_DefaultFrameWidth: {
1594
if (widget && (widget->inherits ("QLineEdit") || widget->inherits ("QTextEdit")))
1595
return 2*basicLineWidth;
1597
return basicLineWidth;
1600
case PM_SpinBoxFrameWidth: {
1601
return 2*basicLineWidth;
1604
case PM_MenuButtonIndicator: { // Arrow width
1607
h = widget->fontMetrics().lineSpacing()/2;
1609
if (h > 3*basicLineWidth)
1612
return 3*basicLineWidth;
1615
// CHECKBOXES / RADIO BUTTONS
1616
// -------------------------------------------------------------------
1617
case PM_ExclusiveIndicatorWidth: // Radiobutton size
1618
case PM_ExclusiveIndicatorHeight:
1619
case PM_IndicatorWidth: // Checkbox size
1620
case PM_IndicatorHeight: {
1623
h = widget->fontMetrics().lineSpacing()-2*basicLineWidth;
1625
if (h > 6*basicLineWidth)
1628
return 6*basicLineWidth;
1631
case PM_DockWindowSeparatorExtent: {
1632
return 2*basicLineWidth + 1;
1634
case PM_DockWindowHandleExtent: {
1637
w = widget->fontMetrics().lineSpacing()/4;
1638
if (w > 5*basicLineWidth)
1641
return 5*basicLineWidth;
1645
return KStyle::pixelMetric(m, widget);
1649
int HighContrastStyle::kPixelMetric( KStylePixelMetric kpm, const QWidget *widget ) const
1652
case KPM_ListViewBranchThickness:
1653
// XXX Proper support of thick branches requires reimplementation of
1654
// the drawKStylePrimitive KPE_ListViewBranch case.
1655
return basicLineWidth;
1657
return KStyle::kPixelMetric(kpm, widget);
1661
QSize HighContrastStyle::sizeFromContents( ContentsType contents,
1662
const QWidget* widget,
1663
const QSize &contentSize,
1664
const QStyleOption& opt ) const
1669
// ------------------------------------------------------------------
1670
case CT_PushButton: {
1671
const QPushButton* button = (const QPushButton*) widget;
1672
int w = contentSize.width();
1673
int h = contentSize.height();
1674
int bm = pixelMetric( PM_ButtonMargin, widget );
1675
int fw = pixelMetric( PM_DefaultFrameWidth, widget ) * 2;
1677
w += bm + fw + 6; // ### Add 6 to make way for bold font.
1680
// Ensure we stick to standard width and heights.
1681
if (( button->isDefault() || button->autoDefault() ) && (button->isEnabled())) {
1682
if ( w < 80 && !button->text().isEmpty() )
1685
// Compensate for default indicator
1686
int di = pixelMetric( PM_ButtonDefaultIndicator );
1694
return QSize( w + basicLineWidth*2, h + basicLineWidth*2 );
1698
// -----------------------------------------------------------------
1699
case CT_ToolButton: {
1700
int w = contentSize.width();
1701
int h = contentSize.height();
1702
return QSize(w + basicLineWidth*2 + 6, h + basicLineWidth*2 + 5);
1707
// -----------------------------------------------------------------
1709
const QComboBox *cb = static_cast< const QComboBox* > (widget);
1710
int borderSize = (cb->editable() ? 4 : 2) * basicLineWidth;
1711
int arrowSize = pixelMetric (PM_ScrollBarExtent, cb);
1712
return QSize(borderSize + basicLineWidth + arrowSize, borderSize) + contentSize;
1715
// POPUPMENU ITEM SIZE
1716
// -----------------------------------------------------------------
1717
case CT_PopupMenuItem: {
1718
if ( ! widget || opt.isDefault() )
1721
const QMenu *popup = (const QMenu *) widget;
1722
bool checkable = popup->isCheckable();
1723
QMenuItem *mi = opt.menuItem();
1724
int maxpmw = opt.maxIconWidth();
1725
int w = contentSize.width(), h = contentSize.height();
1727
if ( mi->custom() ) {
1728
w = mi->custom()->sizeHint().width();
1729
h = mi->custom()->sizeHint().height();
1730
if ( ! mi->custom()->fullSpan() )
1731
h += 2*itemVMargin + 2*itemFrame;
1733
else if ( mi->widget() ) {
1734
} else if ( mi->isSeparator() ) {
1735
w = 10; // Arbitrary
1740
h = qMax( h, mi->pixmap()->height() + 2*itemFrame );
1742
// Ensure that the minimum height for text-only menu items
1743
// is the same as the icon size used by KDE.
1744
h = qMax( h, 16 + 2*itemFrame );
1745
h = qMax( h, popup->fontMetrics().height()
1746
+ 2*itemVMargin + 2*itemFrame );
1749
if ( mi->iconSet() && ! mi->iconSet()->isNull() )
1750
h = qMax( h, mi->iconSet()->pixmap(
1751
QIcon::Small, QIcon::Normal).height() +
1755
if ( ! mi->text().isNull() && mi->text().find('\t') >= 0 )
1757
else if ( mi->popup() )
1758
w += 2 * arrowHMargin;
1762
if ( checkable && maxpmw < 20 )
1764
if ( checkable || maxpmw > 0 )
1769
return QSize( w, h );
1774
// -----------------------------------------------------------------
1776
return contentSize + QSize (4*basicLineWidth, 4*basicLineWidth);
1781
return KStyle::sizeFromContents( contents, widget, contentSize, opt );
1785
QRect HighContrastStyle::subRect (SubRect subrect, const QWidget * widget) const
1788
case SR_ProgressBarGroove:
1789
case SR_ProgressBarContents:
1790
case SR_ProgressBarLabel:
1791
return widget->rect();
1793
return KStyle::subRect (subrect, widget);
1797
bool HighContrastStyle::eventFilter (QObject *object, QEvent *event)
1799
QWidget* widget = qobject_cast<QWidget*>(object);
1802
// Handle hover effects.
1803
if (event->type() == QEvent::Enter
1804
&& (widget->inherits ("QButton")
1805
|| widget->inherits ("QComboBox")
1806
|| widget->inherits ("QSpinWidget")))
1808
hoverWidget = widget;
1809
widget->repaint (false);
1811
else if (event->type() == QEvent::Leave
1812
&& (widget->inherits ("QButton")
1813
|| widget->inherits ("QComboBox")
1814
|| widget->inherits ("QSpinWidget")))
1816
if (object == hoverWidget)
1818
widget->repaint (false);
1820
// Make sure the focus rectangle is shown correctly.
1821
else if (event->type() == QEvent::FocusIn || event->type() == QEvent::FocusOut)
1823
QWidget* widgetparent = qobject_cast<QWidget*>(widget->parent());
1825
&& ! widgetparent->inherits ("QComboBox")
1826
&& ! widgetparent->inherits ("QSpinWidget"))
1828
widgetparent = qobject_cast<QWidget*>(widgetparent->parent());
1832
widgetparent->repaint (false);
1834
widget->repaint (false);
1838
return KStyle::eventFilter (object, event);
1841
// vim: set noet ts=4 sw=4:
1842
// kate: indent-width 4; replace-tabs off; smart-indent on; tab-width 4;