~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kstyles/highcontrast/highcontrast.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * High Contrast Style (version 1.0)
 
3
 *     Copyright (C) 2004 Olaf Schmidt <ojschmidt@kde.org>
 
4
 *
 
5
 * Derived from Axes Style
 
6
 *     Copyright (C) 2003 Maksim Orlovich <orlovich@cs.rochester.edu>
 
7
 * 
 
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>
 
11
 * 
 
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.
 
15
 *
 
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.
 
20
 *
 
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.
 
25
 */
 
26
 
 
27
#include "highcontrast.h"
 
28
#include "highcontrast.moc"
 
29
 
 
30
#include <QtGui/qdrawutil.h>
 
31
#include <QtGui/QPainter>
 
32
#include <Qt3Support/Q3PointArray>
 
33
#include <QtGui/QStylePlugin>
 
34
 
 
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>
 
49
 
 
50
#include <kdrawutil.h>
 
51
 
 
52
// -- Style Plugin Interface -------------------------
 
53
class HighContrastStylePlugin : public QStylePlugin
 
54
{
 
55
        public:
 
56
                HighContrastStylePlugin() {}
 
57
                ~HighContrastStylePlugin() {}
 
58
 
 
59
                QStringList keys() const
 
60
                {
 
61
                        return QStringList() << "HighContrast";
 
62
                }
 
63
 
 
64
                QStyle* create( const QString& key )
 
65
                {
 
66
                        if ( key == "highcontrast" )
 
67
                                return new HighContrastStyle();
 
68
                        return 0;
 
69
                }
 
70
};
 
71
 
 
72
Q_EXPORT_PLUGIN (HighContrastStylePlugin)
 
73
// ---------------------------------------------------
 
74
 
 
75
 
 
76
 
 
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;
 
82
 
 
83
 
 
84
void addOffset (QRect* r, int offset, int lineWidth = 0)
 
85
{
 
86
        int offset1 = offset;
 
87
        int offset2 = offset;
 
88
 
 
89
        *r = r->normalized();
 
90
 
 
91
        if (lineWidth > 0)
 
92
        {
 
93
                offset1 += lineWidth/2;
 
94
                offset2 += lineWidth - lineWidth/2 - 1;
 
95
        }
 
96
 
 
97
        if (offset1 + offset2 > r->width())
 
98
                r->adjust (r->width()/2, 0, - (r->width() - r->width()/2), 0);
 
99
        else
 
100
                r->adjust (offset1, 0, -offset2, 0);
 
101
 
 
102
        if (offset1 + offset2 > r->height())
 
103
                r->adjust (0, r->height()/2, 0, - (r->height() - r->height()/2));
 
104
        else
 
105
                r->adjust (0, offset1, 0, -offset2);
 
106
}
 
107
 
 
108
 
 
109
// ---------------------------------------------------------------------------
 
110
 
 
111
HighContrastStyle::HighContrastStyle()
 
112
        : KStyle( 0, ThreeButtonScrollBar )
 
113
{
 
114
        QSettings settings;
 
115
        settings.beginGroup("/highcontraststyle/Settings/");
 
116
        bool useWideLines = settings.readBoolEntry("wideLines", false);
 
117
        hoverWidget = 0L;
 
118
        basicLineWidth = useWideLines ? 4 : 2;
 
119
}
 
120
 
 
121
 
 
122
HighContrastStyle::~HighContrastStyle()
 
123
{
 
124
}
 
125
 
 
126
 
 
127
void HighContrastStyle::polish( QPalette& pal )
 
128
{
 
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
 
132
        //background colour
 
133
        for (int c = 0; c < QPalette::NColorRoles; ++c)
 
134
                switch (c)
 
135
                {
 
136
                        case QPalette::Button:
 
137
                        case QPalette::Base:
 
138
                        case QPalette::Highlight:
 
139
                                pal.setColor(QPalette::Disabled, QPalette::ColorRole(c), pal.color(QPalette::Active, QPalette::Background));
 
140
                                break;
 
141
                        case QPalette::ButtonText:
 
142
                        case QPalette::Text:
 
143
                        case QPalette::HighlightedText:
 
144
                                pal.setColor(QPalette::Disabled, QPalette::ColorRole(c), pal.color(QPalette::Active, QPalette::Foreground));
 
145
                                break;
 
146
                        default:
 
147
                                pal.setColor(QPalette::Disabled, QPalette::ColorRole(c), pal.color(QPalette::Active, QPalette::ColorRole(c)));
 
148
                }
 
149
}
 
150
 
 
151
 
 
152
void HighContrastStyle::polish (QWidget* widget)
 
153
{
 
154
        if (widget->inherits ("QButton")
 
155
                   || widget->inherits ("QComboBox")
 
156
                   || widget->inherits ("QSpinWidget")
 
157
                   || widget->inherits ("QLineEdit")
 
158
                   || widget->inherits ("QTextEdit"))
 
159
        {
 
160
                widget->installEventFilter (this);
 
161
 
 
162
                Q3SpinWidget* spinwidget = qobject_cast<Q3SpinWidget*>(widget);
 
163
                if (spinwidget && spinwidget->editWidget())
 
164
                        spinwidget->editWidget()->installEventFilter (this);
 
165
        }
 
166
 
 
167
        KStyle::polish (widget);
 
168
}
 
169
 
 
170
 
 
171
void HighContrastStyle::unPolish (QWidget* widget)
 
172
{
 
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);
 
176
}
 
177
 
 
178
void HighContrastStyle::setColorsNormal (QPainter* p, const QColorGroup& cg, int flags, int highlight) const
 
179
{
 
180
        setColorsByState (p, cg, cg.foreground(), cg.background(), flags, highlight);
 
181
}
 
182
 
 
183
void HighContrastStyle::setColorsButton (QPainter* p, const QColorGroup& cg, int flags, int highlight) const
 
184
{
 
185
        setColorsByState (p, cg, cg.buttonText(), cg.button(), flags, highlight);
 
186
}
 
187
 
 
188
void HighContrastStyle::setColorsText (QPainter* p, const QColorGroup& cg, int flags, int highlight) const
 
189
{
 
190
        setColorsByState (p, cg, cg.text(), cg.base(), flags, highlight);
 
191
}
 
192
 
 
193
void HighContrastStyle::setColorsHighlight (QPainter* p, const QColorGroup& cg, int flags) const
 
194
{
 
195
        setColorsByState (p, cg, cg.highlightedText(), cg.highlight(), flags, 0);
 
196
}
 
197
 
 
198
void HighContrastStyle::setColorsByState (QPainter* p, const QColorGroup& cg, const QColor& fg, const QColor& bg, int flags, int highlight) const
 
199
{
 
200
        QFont font = p->font();
 
201
        font.setStrikeOut (! (flags & Style_Enabled));
 
202
        p->setFont (font);
 
203
 
 
204
        if ((flags & Style_Enabled) && (flags & highlight))
 
205
        {
 
206
                p->setPen  (QPen (cg.highlightedText(), basicLineWidth, flags & Style_Enabled ? Qt::SolidLine : Qt::DotLine));
 
207
                p->setBackgroundColor (cg.highlight());
 
208
        }
 
209
        else
 
210
        {
 
211
                p->setPen  (QPen (fg, basicLineWidth, flags & Style_Enabled ? Qt::SolidLine : Qt::DotLine));
 
212
                p->setBackgroundColor (bg);
 
213
        }
 
214
 
 
215
        p->setBrush (QBrush ());
 
216
}
 
217
 
 
218
void HighContrastStyle::drawRect (QPainter* p, QRect r, int offset, bool filled) const
 
219
{
 
220
        addOffset (&r, offset, p->pen().width());
 
221
        if (filled)
 
222
                p->fillRect (r, p->background().color());
 
223
 
 
224
        p->drawRect (r);
 
225
}
 
226
 
 
227
void HighContrastStyle::drawRoundRect (QPainter* p, QRect r, int offset, bool filled) const
 
228
{
 
229
        int lineWidth = p->pen().width();
 
230
        if ((r.width() >= 5*lineWidth + 2*offset) && (r.height() >= 5*lineWidth + 2*offset))
 
231
        {
 
232
                QRect r2 (r);
 
233
                addOffset (&r2, offset, lineWidth);
 
234
 
 
235
                addOffset (&r, offset); 
 
236
                QRect r3 (r);
 
237
                addOffset (&r3, lineWidth);
 
238
 
 
239
                p->save();
 
240
                p->setPen (Qt::NoPen);
 
241
                if (filled)
 
242
                        p->fillRect (r3, p->background().color());
 
243
                p->drawRect (r3);
 
244
                p->restore();
 
245
                
 
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());
 
254
        }
 
255
        else
 
256
                drawRect (p, r, offset, filled);
 
257
}
 
258
 
 
259
void HighContrastStyle::drawEllipse (QPainter* p, QRect r, int offset, bool filled) const
 
260
{
 
261
        addOffset (&r, offset, p->pen().width());
 
262
 
 
263
        if (filled) {
 
264
                p->save();
 
265
                p->setBrush (p->background().color());
 
266
                p->drawRoundRect (r, 99.0, 99.0);
 
267
                p->restore();
 
268
        }
 
269
        
 
270
        p->drawRoundRect (r, 99.0, 99.0);
 
271
}
 
272
 
 
273
void HighContrastStyle::drawArrow (QPainter* p, QRect r, PrimitiveElement arrow, int offset) const
 
274
{
 
275
        p->save();
 
276
        addOffset (&r, offset);
 
277
 
 
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);
 
285
                        
 
286
        Q3PointArray points (3);
 
287
        switch (arrow) {
 
288
                case PE_ArrowUp:
 
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);
 
294
                        break;
 
295
                }
 
296
                case PE_ArrowDown:
 
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);
 
302
                        break;
 
303
                }
 
304
                case PE_ArrowLeft: {
 
305
                        points.setPoint (0, r.topRight());
 
306
                        points.setPoint (1, r.bottomRight());
 
307
                        points.setPoint (2, r.left() + r.width()/7, r.center().y());
 
308
                        break;
 
309
                }
 
310
                default: {
 
311
                        points.setPoint (0, r.topLeft());
 
312
                        points.setPoint (1, r.bottomLeft());
 
313
                        points.setPoint (2, r.right() - r.width()/7, r.center().y());
 
314
                }
 
315
        }
 
316
 
 
317
        p->setPen (p->pen().color());
 
318
        p->setBrush (p->pen().color());
 
319
        p->drawPolygon (points);
 
320
        p->restore();
 
321
}
 
322
 
 
323
// This function draws primitive elements
 
324
void HighContrastStyle::drawPrimitive (PrimitiveElement pe,
 
325
                                                                QPainter *p,
 
326
                                                                const QRect &r,
 
327
                                                                const QColorGroup &cg,
 
328
                                                                SFlags flags,
 
329
                                                                const QStyleOption& opt ) const
 
330
{
 
331
        switch(pe)
 
332
        {
 
333
                case PE_StatusBarSection: {
 
334
                        //### TODO: Not everything uses this!
 
335
                        setColorsNormal (p, cg, Style_Enabled);
 
336
                        drawRect (p, r);
 
337
                        break;
 
338
                }
 
339
                // BUTTONS
 
340
                // -------------------------------------------------------------------
 
341
                case PE_ButtonDefault:
 
342
                case PE_ButtonDropDown:
 
343
                case PE_ButtonCommand:
 
344
                case PE_ButtonTool:
 
345
                case PE_ButtonBevel: {
 
346
                        setColorsButton (p, cg, flags, Style_On|Style_MouseOver|Style_Down);
 
347
                        drawRoundRect (p, r, 0, false);
 
348
                        break;
 
349
                }
 
350
 
 
351
                // FOCUS RECT
 
352
                // -------------------------------------------------------------------
 
353
                case PE_FocusRect: {
 
354
                        p->save();
 
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);
 
360
                        p->restore();
 
361
                        break;
 
362
                }
 
363
 
 
364
                case PE_HeaderArrow: {
 
365
                        setColorsButton (p, cg, flags, 0);
 
366
                        drawArrow (p, r, flags & Style_Down ? PE_ArrowDown : PE_ArrowUp, 2*basicLineWidth);
 
367
                        break;
 
368
                }
 
369
                // HEADER SECTION
 
370
                // -------------------------------------------------------------------
 
371
                case PE_HeaderSection: {
 
372
                        setColorsButton (p, cg, flags, 0);
 
373
                        drawRect (p, r);
 
374
                        break;
 
375
                }
 
376
 
 
377
 
 
378
                // SCROLLBAR
 
379
                // -------------------------------------------------------------------
 
380
                case PE_ScrollBarSlider: {
 
381
                        setColorsNormal (p, cg);
 
382
                        p->fillRect (r, p->background().color());
 
383
 
 
384
                        if (flags & Style_Enabled) {
 
385
                                setColorsHighlight (p, cg, flags);
 
386
                                drawRoundRect (p, r);
 
387
 
 
388
                                if (r.width() >= 7*basicLineWidth && r.height() >= 7*basicLineWidth) {
 
389
                                        QRect r2 (r);
 
390
                                        r2.setWidth (4*basicLineWidth);
 
391
                                        r2.setHeight (4*basicLineWidth);
 
392
                                        r2.moveCenter (r.center());
 
393
                                        drawRect (p, r2, 0, false);
 
394
                                }
 
395
                        }
 
396
                        break;
 
397
                }
 
398
 
 
399
                case PE_ScrollBarAddPage:
 
400
                case PE_ScrollBarSubPage: {
 
401
                        setColorsNormal (p, cg);
 
402
                        p->fillRect (r, p->background().color());
 
403
 
 
404
                        QRect r2 (r);
 
405
                        if (flags & Style_Horizontal)
 
406
                        {
 
407
                                if (r2.height() > 5*basicLineWidth)
 
408
                                {
 
409
                                        r2.setHeight (5*basicLineWidth);
 
410
                                        r2.moveCenter (r.center());
 
411
                                }
 
412
                        }
 
413
                        else
 
414
                        {
 
415
                                if (r2.width() > 5*basicLineWidth)
 
416
                                {
 
417
                                        r2.setWidth (5*basicLineWidth);
 
418
                                        r2.moveCenter (r.center());
 
419
                                }
 
420
                        }
 
421
                        setColorsText (p, cg, flags);
 
422
                        drawRect (p, r2);
 
423
                        
 
424
                        if (flags & Style_Horizontal)
 
425
                                r2.adjust (0, basicLineWidth, 0, -basicLineWidth);
 
426
                        else
 
427
                                r2.adjust (basicLineWidth, 0, -basicLineWidth, 0);
 
428
                        QPen pen = p->pen();
 
429
                        pen.setColor (p->background().color());
 
430
                        p->setPen (pen);
 
431
                        drawRect (p, r2);
 
432
 
 
433
                        break;
 
434
                }
 
435
 
 
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());
 
442
 
 
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);
 
450
                        }
 
451
                        break;
 
452
                }
 
453
 
 
454
                
 
455
                case PE_ProgressBarChunk: {
 
456
                        p->fillRect (r, Qt::color1);
 
457
                        break;
 
458
                }
 
459
 
 
460
 
 
461
                // CHECKBOX
 
462
                // -------------------------------------------------------------------
 
463
                case PE_Indicator: {
 
464
                        setColorsText (p, cg, flags);
 
465
 
 
466
                        //Draw the outer rect
 
467
                        drawRect (p, r);
 
468
 
 
469
                        if (!(flags & Style_Off))
 
470
                        {
 
471
                                QRect r2 (r);
 
472
                                addOffset (&r2, basicLineWidth);
 
473
                                if (flags & Style_On)
 
474
                                {
 
475
                                        p->drawLine (r2.topLeft(), r2.bottomRight());
 
476
                                        p->drawLine (r2.bottomLeft(), r2.topRight());
 
477
                                }
 
478
                                else
 
479
                                {       // Tristate
 
480
                                        p->drawLine (r2.left(), r2.top()+r2.width()/2, r2.right(), r2.top()+r2.width()/2);
 
481
                                }
 
482
                                QPen pen = p->pen();
 
483
                                pen.setColor (p->background().color());
 
484
                                p->setPen (pen);
 
485
                                drawRect (p, r2, 0, false);
 
486
                        }
 
487
                        break;
 
488
                }
 
489
                case PE_IndicatorMask: {
 
490
                        p->fillRect (r, Qt::color1);
 
491
                        break;
 
492
                }
 
493
                case PE_CheckMark: {
 
494
                        setColorsText (p, cg, flags);
 
495
 
 
496
                        if (flags & Style_On)
 
497
                        {
 
498
                                p->drawLine (r.topLeft(), r.bottomRight());
 
499
                                p->drawLine (r.bottomLeft(), r.topRight());
 
500
                        }
 
501
                        break;
 
502
                }
 
503
 
 
504
                // RADIOBUTTON (exclusive indicator)
 
505
                // -------------------------------------------------------------------
 
506
                case PE_ExclusiveIndicator: {
 
507
                        setColorsText (p, cg, flags);
 
508
                        drawEllipse (p, r);
 
509
 
 
510
                        // Indicator "dot"
 
511
                        if (flags & Style_On) {
 
512
                                p->setBackgroundColor (p->pen().color());
 
513
                                drawEllipse (p, r, 2*p->pen().width());
 
514
                        }
 
515
 
 
516
                        break;
 
517
                }
 
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);
 
523
                        p->drawEllipse (r);
 
524
                        break;
 
525
                }
 
526
 
 
527
 
 
528
                // SPLITTER/DOCKWINDOW HANDLES
 
529
                // -------------------------------------------------------------------
 
530
                case PE_DockWindowResizeHandle:
 
531
                case PE_Splitter: {
 
532
                        setColorsButton (p, cg, flags);
 
533
                        p->fillRect (r, p->background().color());
 
534
                        
 
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());
 
538
                        else
 
539
                                p->drawLine (r.left(), r.center().y(), r.right(), r.center().y());
 
540
                        break;
 
541
                }
 
542
 
 
543
 
 
544
                // GENERAL PANELS
 
545
                // -------------------------------------------------------------------
 
546
                case PE_Panel:
 
547
                case PE_GroupBoxFrame:
 
548
                case PE_PanelPopup: {
 
549
                        setColorsNormal (p, cg, flags, 0);
 
550
                        if (!opt.isDefault())
 
551
                        {
 
552
                                QPen pen = p->pen();
 
553
                                pen.setWidth (opt.lineWidth());
 
554
                                p->setPen (pen);
 
555
                        }
 
556
                        if (pe == PE_PanelPopup)
 
557
                                drawRect (p, r, 0, false);
 
558
                        else 
 
559
                                drawRoundRect (p, r, 0, false);
 
560
                        break;
 
561
                }
 
562
                case PE_WindowFrame:
 
563
                case PE_TabBarBase: {
 
564
                        setColorsNormal (p, cg, flags, 0);
 
565
                        drawRect (p, r, 0, false);
 
566
                        break;
 
567
                }
 
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()));
 
573
                        break;
 
574
                }
 
575
                case PE_PanelTabWidget:
 
576
                case PE_PanelGroupBox: {
 
577
                        setColorsNormal (p, cg, flags, 0);
 
578
                        drawRoundRect (p, r);
 
579
                        break;
 
580
                }
 
581
                case PE_PanelMenuBar: {                 // Menu
 
582
                        p->fillRect (r, cg.background());
 
583
                        break;
 
584
                }
 
585
                case PE_PanelDockWindow: {              // Toolbar
 
586
                        p->fillRect (r, cg.button());
 
587
                        break;
 
588
                }
 
589
 
 
590
 
 
591
 
 
592
                // SEPARATORS
 
593
                // -------------------------------------------------------------------
 
594
                case PE_Separator: {
 
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);
 
600
                        else
 
601
                                p->drawLine (r.left()+basicLineWidth, r.center().y(), r.right()-basicLineWidth + 1, r.center().y());
 
602
                        break;
 
603
                }
 
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);
 
610
                        else
 
611
                                p->drawLine (r.left()+basicLineWidth, r.center().y(), r.right()-basicLineWidth, r.center().y());
 
612
                        break;
 
613
                }
 
614
 
 
615
 
 
616
                // ARROWS
 
617
                // -------------------------------------------------------------------
 
618
                case PE_ArrowUp:
 
619
                case PE_ArrowDown:
 
620
                case PE_ArrowRight:
 
621
                case PE_ArrowLeft:
 
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);
 
628
                        break;
 
629
                }
 
630
 
 
631
                default: {
 
632
                        KStyle::drawPrimitive( pe, p, r, cg, flags, opt );
 
633
                }
 
634
        }
 
635
}
 
636
 
 
637
 
 
638
void HighContrastStyle::drawKStylePrimitive (KStylePrimitive kpe,
 
639
                                                                                QPainter* p,
 
640
                                                                                const QWidget* widget,
 
641
                                                                                const QRect &r,
 
642
                                                                                const QColorGroup &cg,
 
643
                                                                                SFlags flags,
 
644
                                                                                const QStyleOption &opt ) const
 
645
{
 
646
        if ( widget == hoverWidget )
 
647
                flags |= Style_MouseOver;
 
648
 
 
649
        switch ( kpe )
 
650
        {
 
651
                // TOOLBAR HANDLE
 
652
                // -------------------------------------------------------------------
 
653
                case KPE_ToolBarHandle:
 
654
                case KPE_DockWindowHandle:
 
655
                case KPE_GeneralHandle:
 
656
                {
 
657
                        setColorsButton (p, cg);
 
658
                        p->fillRect (r, p->background().color());
 
659
                        p->setBrush (QBrush (p->pen().color(), Qt::BDiagPattern));
 
660
                        drawRoundRect (p, r);
 
661
                        break;
 
662
                }
 
663
 
 
664
 
 
665
                // SLIDER GROOVE
 
666
                // -------------------------------------------------------------------
 
667
                case KPE_SliderGroove: {
 
668
                        setColorsText (p, cg, flags);
 
669
                        QRect r2 (r);
 
670
                        const QSlider *slider = qobject_cast<const QSlider*>(widget);
 
671
                        if (slider != 0)
 
672
                        {
 
673
                                if (slider->orientation() == Qt::Horizontal)
 
674
                                {
 
675
                                        if (r2.height() > 5*basicLineWidth)
 
676
                                        {
 
677
                                                r2.setHeight (5*basicLineWidth);
 
678
                                                r2.moveCenter (r.center());
 
679
                                        }
 
680
                                }
 
681
                                else
 
682
                                {
 
683
                                        if (r2.width() > 5*basicLineWidth)
 
684
                                        {
 
685
                                                r2.setWidth (5*basicLineWidth);
 
686
                                                r2.moveCenter (r.center());
 
687
                                        }
 
688
                                }
 
689
                        }
 
690
 
 
691
                        drawRoundRect (p, r2);
 
692
                        break;
 
693
                }
 
694
 
 
695
                // SLIDER HANDLE
 
696
                // -------------------------------------------------------------------
 
697
                case KPE_SliderHandle: {
 
698
                        setColorsHighlight (p, cg, flags);
 
699
                        drawRoundRect (p, r);
 
700
                        break;
 
701
                }
 
702
 
 
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;
 
714
 
 
715
                        } else {
 
716
                                direction = PE_ArrowDown;
 
717
                        }
 
718
                        setColorsText (p, cg, flags);
 
719
                        drawArrow (p, r, direction);
 
720
                        break;
 
721
                }
 
722
                case KPE_ListViewBranch: 
 
723
                        // TODO Draw (thick) dotted line. Check kstyle.cpp
 
724
                        // Fall down for now
 
725
                default:
 
726
                        KStyle::drawKStylePrimitive( kpe, p, widget, r, cg, flags, opt);
 
727
        }
 
728
}
 
729
 
 
730
 
 
731
void HighContrastStyle::drawControl (ControlElement element,
 
732
                                                                QPainter *p,
 
733
                                                                const QWidget *widget,
 
734
                                                                const QRect &r,
 
735
                                                                const QColorGroup &cg,
 
736
                                                                SFlags flags,
 
737
                                                                const QStyleOption& opt ) const
 
738
{
 
739
        if ( widget == hoverWidget )
 
740
                flags |= Style_MouseOver;
 
741
 
 
742
        switch (element)
 
743
        {
 
744
                // TABS
 
745
                // -------------------------------------------------------------------
 
746
                case CE_ToolBoxTab: {
 
747
                        setColorsNormal (p, cg, flags, Style_Selected);
 
748
                        drawRoundRect (p, r);
 
749
                        break;
 
750
                }
 
751
 
 
752
                case CE_TabBarTab: {
 
753
                        setColorsNormal (p, cg, flags, Style_Selected);
 
754
                        drawRoundRect (p, r);
 
755
                        
 
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, 
 
762
                                                         p->pen().color());
 
763
                                p->fillRect (r.left()+basicLineWidth, 
 
764
                                                         flags & Style_Selected ? basicLineWidth : 2*basicLineWidth,
 
765
                                                         r.width()-2*basicLineWidth,
 
766
                                                         basicLineWidth,
 
767
                                                         p->background().color());
 
768
                        } else {
 
769
                                p->fillRect (r.left(), r.bottom()-2*basicLineWidth+1, 
 
770
                                                         r.width(), 2*basicLineWidth, 
 
771
                                                         p->pen().color());
 
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());
 
777
                        }
 
778
                        break;
 
779
                }
 
780
 
 
781
 
 
782
                // PUSHBUTTON
 
783
                // -------------------------------------------------------------------
 
784
                case CE_PushButton: {
 
785
                        QPushButton *button = (QPushButton*) widget;
 
786
                        QRect br = r;
 
787
                        bool btnDefault = button->isDefault();
 
788
 
 
789
                        if (( btnDefault || button->autoDefault() ) && (button->isEnabled())) {
 
790
                                // Compensate for default indicator
 
791
                                static int di = pixelMetric( PM_ButtonDefaultIndicator );
 
792
                                addOffset (&br, di);
 
793
                        }
 
794
 
 
795
                        if ( btnDefault && (button->isEnabled()))
 
796
                                drawPrimitive( PE_ButtonDefault, p, r, cg, flags );
 
797
 
 
798
                        drawPrimitive( PE_ButtonCommand, p, br, cg, flags );
 
799
 
 
800
                        break;
 
801
                }
 
802
 
 
803
 
 
804
                // LABEL
 
805
                // -------------------------------------------------------------------
 
806
                case CE_ProgressBarLabel:
 
807
                case CE_TabBarLabel:
 
808
                case CE_RadioButtonLabel:
 
809
                case CE_CheckBoxLabel:
 
810
                case CE_ToolButtonLabel:
 
811
                case CE_PushButtonLabel: {
 
812
                        const QPixmap* pixmap = 0;
 
813
                        QPixmap icon;
 
814
                        QString text;
 
815
                        bool popup = false;
 
816
                        
 
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;
 
819
 
 
820
                        int x, y, w, h;
 
821
                        r.rect( &x, &y, &w, &h );
 
822
                        
 
823
                        if (element == CE_ProgressBarLabel) {
 
824
                                QProgressBar* progressbar = (QProgressBar*) widget;
 
825
                                text = progressbar->progressString();
 
826
                                setColorsNormal (p, cg, flags);
 
827
                        }
 
828
                        else if (element == CE_TabBarLabel) {
 
829
                                if (!opt.isDefault()) {
 
830
                                        QTab* tab = opt.tab();
 
831
                                        text = tab->text();
 
832
                                }
 
833
                                setColorsNormal (p, cg, flags, Style_Selected);
 
834
                        }
 
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);
 
843
                        }
 
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);
 
852
                        }
 
853
                        else {
 
854
                                const Q3Button* button = (const Q3Button*)widget;
 
855
                                pixmap = button->pixmap();
 
856
                                text = button->text();
 
857
                                setColorsNormal (p, cg);
 
858
                        }
 
859
 
 
860
                        // Does the button have a popup menu?
 
861
                        if (popup) {
 
862
                                int dx = pixelMetric (PM_MenuButtonIndicator, widget);
 
863
                                drawArrow (p, QRect(x + w - dx - 2, y + 2, dx, h - 4), PE_ArrowDown);
 
864
                                w -= dx;
 
865
                        }
 
866
 
 
867
                        // Draw the icon if there is one
 
868
                        if (!icon.isNull())
 
869
                        {
 
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);
 
874
                                else
 
875
                                        p->drawPixmap (x + 4, y + (h - icon.height()) / 2, icon);
 
876
 
 
877
                                int  pw = icon.width();
 
878
                                x += pw + 4;
 
879
                                w -= pw + 4;
 
880
                        }
 
881
 
 
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()));
 
885
 
 
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);
 
891
                        break;
 
892
                }
 
893
 
 
894
                // MENUBAR BACKGROUND
 
895
                // -------------------------------------------------------------------
 
896
                case CE_MenuBarEmptyArea:
 
897
                {
 
898
                        p->fillRect (r, cg.background());
 
899
                        break;
 
900
                }
 
901
 
 
902
                // DOCKWINDOW BACKGROUND
 
903
                // -------------------------------------------------------------------
 
904
                case CE_DockWindowEmptyArea:
 
905
                {
 
906
                        p->fillRect (r, cg.button());
 
907
                        break;
 
908
                }
 
909
 
 
910
                // MENUBAR ITEM
 
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();
 
917
 
 
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);
 
922
                        }
 
923
                        break;
 
924
                }
 
925
 
 
926
                // CHECKBOX
 
927
                // -------------------------------------------------------------------
 
928
                case CE_CheckBox: {
 
929
                        drawPrimitive (PE_Indicator, p, r, cg, flags);
 
930
                        break;
 
931
                }
 
932
 
 
933
                // RADIOBUTTON
 
934
                // -------------------------------------------------------------------
 
935
                case CE_RadioButton: {
 
936
                        drawPrimitive (PE_ExclusiveIndicator, p, r, cg, flags);
 
937
                        break;
 
938
                }
 
939
 
 
940
                // PROGRESSBAR
 
941
                // -------------------------------------------------------------------
 
942
                case CE_ProgressBarGroove: {
 
943
                        setColorsText (p, cg, flags);
 
944
                        const QProgressBar *progressbar = qobject_cast<const QProgressBar*>(widget);
 
945
                        if (progressbar) {
 
946
                                QRect r2 (r);
 
947
                                r2.setLeft (p->boundingRect (r, Qt::AlignVCenter|Qt::AlignLeft|Qt::TextShowMnemonic, progressbar->progressString()).right()
 
948
                                                + 4*basicLineWidth);
 
949
                                drawRoundRect (p, r2);
 
950
                        }
 
951
                        break;
 
952
                }
 
953
                case CE_ProgressBarContents: {
 
954
                        const QProgressBar *progressbar = qobject_cast<const QProgressBar*>(widget);
 
955
                        if (progressbar)
 
956
                        {
 
957
                                QRect r2 (r);
 
958
                                r2.setLeft (p->boundingRect (r, Qt::AlignVCenter|Qt::AlignLeft|Qt::TextShowMnemonic, progressbar->progressString()).right()
 
959
                                                + 4*basicLineWidth);
 
960
                                long progress = r2.width() * progressbar->progress();
 
961
                                if (progressbar->totalSteps() > 0)
 
962
                                {
 
963
                                        r2.setWidth (progress / progressbar->totalSteps());
 
964
                                }
 
965
                                else
 
966
                                {
 
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);
 
972
                                        r2.setWidth (width);
 
973
                                }
 
974
                                setColorsHighlight (p, cg, flags);
 
975
                                if (r2.width() > 0)
 
976
                                        drawRoundRect (p, r2);
 
977
                        }
 
978
                        break;
 
979
                }
 
980
 
 
981
                // POPUPMENU ITEM
 
982
                // -------------------------------------------------------------------
 
983
                case CE_PopupMenuItem: {
 
984
                        setColorsNormal (p, cg, flags, Style_Active|Style_MouseOver);
 
985
                        p->fillRect (r, p->background().color());
 
986
 
 
987
                        const QMenu *popupmenu = (const QMenu *) widget;
 
988
                        QMenuItem *mi = opt.menuItem();
 
989
                        if (!mi)
 
990
                                break;
 
991
 
 
992
                        int  tab        = opt.tabWidth();
 
993
                        int  checkcol   = opt.maxIconWidth();
 
994
                        bool checkable  = popupmenu->isCheckable();
 
995
                        bool reverse    = QApplication::isRightToLeft();
 
996
                        int x, y, w, h;
 
997
                        r.rect( &x, &y, &w, &h );
 
998
 
 
999
                        if ( checkable )
 
1000
                                checkcol = qMax( checkcol, 20 );
 
1001
 
 
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());
 
1005
                                break;
 
1006
                        }
 
1007
 
 
1008
                        // Do we have an icon?
 
1009
                        if ( mi->iconSet() && !mi->iconSet()->isNull() ) {
 
1010
                                QIcon::Mode mode;
 
1011
                                QRect cr = visualRect( QRect(x, y, checkcol, h), r );
 
1012
 
 
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;
 
1018
                                else
 
1019
                                        mode = QIcon::Normal;
 
1020
 
 
1021
                                // Draw the icon
 
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 );
 
1026
 
 
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() )
 
1030
                                {
 
1031
                                        drawRect (p, cr, 0, false);
 
1032
                                }
 
1033
                        }
 
1034
 
 
1035
                        // Are we checked? (This time without an icon)
 
1036
                        else if ( checkable && mi->isChecked() ) {
 
1037
                                int cx = reverse ? x+w - checkcol : x;
 
1038
 
 
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());
 
1044
                                else
 
1045
                                        rc.setHeight (rc.width());
 
1046
                                rc.moveCenter (center);
 
1047
                                        
 
1048
                                p->drawLine (rc.topLeft(), rc.bottomRight());
 
1049
                                p->drawLine (rc.topRight(), rc.bottomLeft());
 
1050
                        }
 
1051
 
 
1052
                        // Time to draw the menu item label...
 
1053
                        int xm = itemFrame + checkcol + itemHMargin; // X position margin
 
1054
 
 
1055
                        int xp = reverse ? // X position
 
1056
                                        x + tab + rightBorder + itemHMargin + itemFrame - 1 :
 
1057
                                        x + xm;
 
1058
 
 
1059
                        // Label width (minus the width of the accelerator portion)
 
1060
                        int tw = w - xm - tab - arrowHMargin - itemHMargin * 3 - itemFrame + 1;
 
1061
 
 
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
 
1067
                                p->save();
 
1068
                                mi->custom()->paint( p, cg, flags & Style_Active, flags & Style_Enabled, xp, y+m, tw, h-2*m );
 
1069
                                p->restore();
 
1070
                        }
 
1071
                        else {
 
1072
                                // The menu item doesn't draw it's own label
 
1073
                                QString s = mi->text();
 
1074
 
 
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;
 
1081
 
 
1082
                                        // Does the menu item have a tabstop? (for the accelerator text)
 
1083
                                        if ( t >= 0 ) {
 
1084
                                                int tabx = reverse ? x + rightBorder + itemHMargin + itemFrame :
 
1085
                                                        x + w - tab - rightBorder - itemHMargin - itemFrame;
 
1086
 
 
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 ) );
 
1089
                                                s = s.left( t );
 
1090
                                        }
 
1091
 
 
1092
                                        // Draw the left part of the label (or the whole label
 
1093
                                        // if there's no accelerator)
 
1094
 
 
1095
                                        p->drawText( xp, y+m, tw, h-2*m, text_flags, s, t );
 
1096
 
 
1097
                                }
 
1098
 
 
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();
 
1103
 
 
1104
                                        // Draw the pixmap
 
1105
                                        if ( pixmap->depth() == 1 )
 
1106
                                                p->setBackgroundMode( Qt::OpaqueMode );
 
1107
 
 
1108
                                        int diffw = ( ( w - pixmap->width() ) / 2 )
 
1109
                                                                        + ( ( w - pixmap->width() ) % 2 );
 
1110
                                        p->drawPixmap( x+diffw, y+itemFrame, *pixmap );
 
1111
 
 
1112
                                        if ( pixmap->depth() == 1 )
 
1113
                                                p->setBackgroundMode( Qt::TransparentMode );
 
1114
                                }
 
1115
                        }
 
1116
 
 
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 );
 
1123
 
 
1124
                                // Draw an arrow at the far end of the menu item
 
1125
                                drawArrow (p, vr, arrow);
 
1126
                        }
 
1127
                        break;
 
1128
                }
 
1129
 
 
1130
                default:
 
1131
                        KStyle::drawControl(element, p, widget, r, cg, flags, opt);
 
1132
        }
 
1133
}
 
1134
 
 
1135
void HighContrastStyle::drawControlMask (ControlElement element,
 
1136
                                                                                QPainter *p,
 
1137
                                                                                const QWidget *w,
 
1138
                                                                                const QRect &r,
 
1139
                                                                                const QStyleOption &opt) const
 
1140
{
 
1141
        switch (element) {
 
1142
                case CE_PushButton:
 
1143
                case CE_ToolBoxTab:
 
1144
                case CE_TabBarTab: 
 
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);
 
1155
                        break;
 
1156
                }
 
1157
 
 
1158
                default: {
 
1159
                        KStyle::drawControlMask (element, p, w, r, opt);
 
1160
                }
 
1161
        }
 
1162
}
 
1163
 
 
1164
// Helper to find the next sibling that's not hidden
 
1165
// Lifted from kstyle.cpp
 
1166
static Q3ListViewItem* nextVisibleSibling(Q3ListViewItem* item)
 
1167
{
 
1168
    Q3ListViewItem* sibling = item;
 
1169
    do
 
1170
    {
 
1171
        sibling = sibling->nextSibling();
 
1172
    }
 
1173
    while (sibling && !sibling->isVisible());
 
1174
    
 
1175
    return sibling;
 
1176
}
 
1177
 
 
1178
void HighContrastStyle::drawComplexControl (ComplexControl control,
 
1179
                                                                        QPainter *p,
 
1180
                                                                        const QWidget *widget,
 
1181
                                                                        const QRect &r,
 
1182
                                                                        const QColorGroup &cg,
 
1183
                                                                        SFlags flags,
 
1184
                                                                        SCFlags controls,
 
1185
                                                                        SCFlags active,
 
1186
                                                                        const QStyleOption& opt ) const
 
1187
{
 
1188
        if ( widget == hoverWidget )
 
1189
                flags |= Style_MouseOver;
 
1190
 
 
1191
        switch(control)
 
1192
        {
 
1193
                // COMBOBOX
 
1194
                // -------------------------------------------------------------------
 
1195
                case CC_ComboBox: {
 
1196
                        setColorsText (p, cg, flags);
 
1197
                        drawRoundRect (p, r);
 
1198
                        
 
1199
                        QRect r2 = QStyle::visualRect (querySubControlMetrics (CC_ComboBox, widget, SC_ComboBoxArrow), widget);
 
1200
                        if (flags & Style_HasFocus) {
 
1201
                                QRect r3 (r);
 
1202
                                if (r2.left() > 0)
 
1203
                                        r3.setRight (r2.left()+basicLineWidth-1);
 
1204
                                else
 
1205
                                        r3.setLeft (r2.right()-basicLineWidth+1);
 
1206
 
 
1207
                                drawPrimitive (PE_FocusRect, p, r3, cg, flags, QStyleOption (p->background().color()));
 
1208
                        }
 
1209
                        
 
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);
 
1215
                        }
 
1216
 
 
1217
                        setColorsText (p, cg, flags);
 
1218
                        break;
 
1219
                }
 
1220
 
 
1221
                // SPINWIDGET
 
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()));
 
1229
                        }
 
1230
                        
 
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);
 
1237
                        }
 
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);
 
1242
                        }
 
1243
 
 
1244
                        setColorsText (p, cg, flags);
 
1245
                        break;
 
1246
                }
 
1247
 
 
1248
                // TOOLBUTTON
 
1249
                // -------------------------------------------------------------------
 
1250
                case CC_ToolButton: {
 
1251
                        const QToolButton *toolbutton = (const QToolButton *) widget;
 
1252
 
 
1253
                        setColorsButton (p, cg, flags);
 
1254
                        p->fillRect (r, p->background().color());
 
1255
 
 
1256
                        QRect button, menuarea;
 
1257
                        button   = querySubControlMetrics(control, widget, SC_ToolButton, opt);
 
1258
                        menuarea = querySubControlMetrics(control, widget, SC_ToolButtonMenu, opt);
 
1259
 
 
1260
                        SFlags bflags = flags,
 
1261
                                   mflags = flags;
 
1262
 
 
1263
                        if (active & SC_ToolButton)
 
1264
                                bflags |= Style_Down;
 
1265
                        if (active & SC_ToolButtonMenu)
 
1266
                                mflags |= Style_Down;
 
1267
 
 
1268
                        if (controls & SC_ToolButton)
 
1269
                        {
 
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);
 
1273
 
 
1274
                                // Check whether to draw a background pixmap
 
1275
                                else if ( toolbutton->parentWidget() &&
 
1276
                                                  toolbutton->parentWidget()->backgroundPixmap() &&
 
1277
                                                  !toolbutton->parentWidget()->backgroundPixmap()->isNull() )
 
1278
                                {
 
1279
                                        QPixmap pixmap = *(toolbutton->parentWidget()->backgroundPixmap());
 
1280
                                        p->drawTiledPixmap( r, pixmap, toolbutton->pos() );
 
1281
                                }
 
1282
                        }
 
1283
 
 
1284
                        // Draw a toolbutton menu indicator if required
 
1285
                        if (controls & SC_ToolButtonMenu)
 
1286
                        {
 
1287
                                if (mflags & (Style_Down | Style_On | Style_Raised))
 
1288
                                        drawPrimitive(PE_ButtonDropDown, p, menuarea, cg, mflags, opt);
 
1289
                                drawArrow (p, menuarea, PE_ArrowDown);
 
1290
                        }
 
1291
 
 
1292
                        if (toolbutton->hasFocus() && !toolbutton->focusProxy()) {
 
1293
                                QRect fr = toolbutton->rect();
 
1294
                                addOffset (&fr, 3);
 
1295
                                drawPrimitive(PE_FocusRect, p, fr, cg, flags, QStyleOption (p->background().color()));
 
1296
                        }
 
1297
 
 
1298
                        break;
 
1299
                }
 
1300
 
 
1301
                // LISTVIEW
 
1302
                // -------------------------------------------------------------------
 
1303
                case CC_ListView: {
 
1304
                        /*
 
1305
                         * Sigh... Lifted and modified from kstyle.cpp 
 
1306
                         */
 
1307
                        /* 
 
1308
                         * Many thanks to TrollTech AS for donating CC_ListView from QWindowsStyle.
 
1309
                         * CC_ListView code is Copyright (C) 1998-2000 TrollTech AS.
 
1310
                         */
 
1311
 
 
1312
                        // Paint the icon and text.
 
1313
                        if ( controls & SC_ListView )
 
1314
                                QCommonStyle::drawComplexControl( control, p, widget, r, cg, flags, controls, active, opt );
 
1315
 
 
1316
                        // If we're have a branch or are expanded...
 
1317
                        if ( controls & (SC_ListViewBranch | SC_ListViewExpand) )
 
1318
                        {
 
1319
                                // If no list view item was supplied, break
 
1320
                                if (opt.isDefault())
 
1321
                                        break;
 
1322
 
 
1323
                                Q3ListViewItem *item  = opt.listViewItem();
 
1324
                                Q3ListViewItem *child = item->firstChild();
 
1325
 
 
1326
                                int y = r.y();
 
1327
                                int c;  // dotline vertice count
 
1328
                                int dotoffset = 0;
 
1329
                                Q3PointArray dotlines;
 
1330
 
 
1331
                                if ( active == SC_All && controls == SC_ListViewExpand ) {
 
1332
                                        // We only need to draw a vertical line
 
1333
                                        c = 2;
 
1334
                                        dotlines.resize(2);
 
1335
                                        dotlines[0] = QPoint( r.right(), r.top() );
 
1336
                                        dotlines[1] = QPoint( r.right(), r.bottom() );
 
1337
 
 
1338
                                } else {
 
1339
 
 
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 );
 
1344
                                        c = 0;
 
1345
 
 
1346
                                        // skip the stuff above the exposed rectangle
 
1347
                                        while ( child && y + child->height() <= 0 )
 
1348
                                        {
 
1349
                                                y += child->totalHeight();
 
1350
                                                child = nextVisibleSibling(child);
 
1351
                                        }
 
1352
 
 
1353
                                        int bx = r.width() / 2;
 
1354
 
 
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() );
 
1359
                                        if ( lh % 2 > 0 )
 
1360
                                                lh++;
 
1361
 
 
1362
                                        // Draw all the expand/close boxes...
 
1363
                                        QRect boxrect;
 
1364
                                        QStyle::StyleFlags boxflags;
 
1365
                                        while ( child && y < r.height() )
 
1366
                                        {
 
1367
                                                linebot = y + lh/2;
 
1368
                                                if ( (child->isExpandable() || child->childCount()) &&
 
1369
                                                         (child->height() > 0) )
 
1370
                                                {
 
1371
                                                        int h = qMin(lh, 24) - 4*basicLineWidth;
 
1372
                                                        if (h < 10) 
 
1373
                                                                h = 10;
 
1374
                                                        else 
 
1375
                                                                h &= ~1; // Force an even number of pixels
 
1376
                        
 
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;
 
1380
 
 
1381
                                                        // KStyle extension: Draw the box and expand/collapse indicator
 
1382
                                                        drawKStylePrimitive( KPE_ListViewExpander, p, NULL, boxrect, cg, boxflags, opt );
 
1383
 
 
1384
                                                        // dotlinery
 
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;
 
1391
                                                } else {
 
1392
                                                        // just dotlinery
 
1393
                                                        dotlines[c++] = QPoint( bx+1, linebot );
 
1394
                                                        dotlines[c++] = QPoint( r.width(), linebot );
 
1395
                                                }
 
1396
 
 
1397
                                                y += child->totalHeight();
 
1398
                                                child = nextVisibleSibling(child);
 
1399
                                        }
 
1400
 
 
1401
                                        if ( child ) // there's a child to draw, so move linebot to edge of rectangle
 
1402
                                                linebot = r.height();
 
1403
 
 
1404
                                        if ( linetop < linebot )
 
1405
                                        {
 
1406
                                                dotlines[c++] = QPoint( bx, linetop );
 
1407
                                                dotlines[c++] = QPoint( bx, linebot );
 
1408
                                        }
 
1409
                                }
 
1410
 
 
1411
                                // Draw all the branches...
 
1412
                                static int thickness = kPixelMetric( KPM_ListViewBranchThickness );
 
1413
                                int line; // index into dotlines
 
1414
                                QRect branchrect;
 
1415
                                QStyle::StyleFlags branchflags;
 
1416
                                for( line = 0; line < c; line += 2 )
 
1417
                                {
 
1418
                                        // assumptions here: lines are horizontal or vertical.
 
1419
                                        // lines always start with the numerically lowest
 
1420
                                        // coordinate.
 
1421
 
 
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() )
 
1426
                                        {
 
1427
                                                // Horizontal branch
 
1428
                                                int end = dotlines[line+1].x();
 
1429
                                                int point = dotlines[line].x();
 
1430
                                                int other = dotlines[line].y();
 
1431
 
 
1432
                                                branchrect  = QRect( point, other-(thickness/2), end-point, thickness );
 
1433
                                                branchflags = QStyle::State_Horizontal;
 
1434
 
 
1435
                                                // KStyle extension: Draw the horizontal branch
 
1436
                                                drawKStylePrimitive( KPE_ListViewBranch, p, NULL, branchrect, cg, branchflags, opt );
 
1437
 
 
1438
                                        } else {
 
1439
                                                // Vertical branch
 
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;
 
1444
 
 
1445
                                                branchrect  = QRect( other-(thickness/2), point, thickness, end-point );
 
1446
                                                if (!pixmapoffset)      // ### Hackish - used to hint the offset
 
1447
                                                        branchflags = QStyle::State_NoChange;
 
1448
                                                else
 
1449
                                                        branchflags = QStyle::State_None;
 
1450
 
 
1451
                                                // KStyle extension: Draw the vertical branch
 
1452
                                                drawKStylePrimitive( KPE_ListViewBranch, p, NULL, branchrect, cg, branchflags, opt );
 
1453
                                        }
 
1454
                                }
 
1455
                        }
 
1456
                        break;
 
1457
                }
 
1458
 
 
1459
                default:
 
1460
                        KStyle::drawComplexControl(control, p, widget,
 
1461
                                                r, cg, flags, controls, active, opt);
 
1462
                        break;
 
1463
        }
 
1464
}
 
1465
 
 
1466
void HighContrastStyle::drawComplexControlMask(ComplexControl c,
 
1467
                                                                                           QPainter *p,
 
1468
                                                                                           const QWidget *w,
 
1469
                                                                                           const QRect &r,
 
1470
                                                                                           const QStyleOption &o) const
 
1471
{
 
1472
        switch (c) {
 
1473
                case CC_SpinWidget:
 
1474
                case CC_ToolButton:
 
1475
                case CC_ComboBox: {
 
1476
                        p->fillRect (r, Qt::color0);
 
1477
                        break;
 
1478
                }
 
1479
                default: {
 
1480
                        KStyle::drawComplexControlMask (c, p, w, r, o);
 
1481
                }
 
1482
        }
 
1483
}
 
1484
 
 
1485
void HighContrastStyle::drawItem( QPainter *p,
 
1486
                                                           const QRect &r,
 
1487
                                                           int flags,
 
1488
                                                           const QColorGroup &cg,
 
1489
                                                           bool enabled,
 
1490
                                                           const QPixmap *pixmap,
 
1491
                                                           const QString &text,
 
1492
                                                           int len,
 
1493
                                                           const QColor *penColor ) const
 
1494
{
 
1495
        p->save();
 
1496
 
 
1497
        // make the disabled things use the cross-line
 
1498
        QFont font = p->font();
 
1499
        font.setStrikeOut (!enabled);
 
1500
        p->setFont (font);
 
1501
        
 
1502
        enabled = true; //do not ghost it in Qt
 
1503
 
 
1504
        KStyle::drawItem (p, r, flags, cg, enabled, pixmap, text, len, penColor);
 
1505
        
 
1506
        p->restore();
 
1507
}
 
1508
 
 
1509
QRect HighContrastStyle::querySubControlMetrics( ComplexControl control,
 
1510
                                                                        const QWidget* widget,
 
1511
                                                                  SubControl subcontrol,
 
1512
                                                                  const QStyleOption& opt ) const
 
1513
{
 
1514
        switch (control)
 
1515
        {
 
1516
                case CC_ComboBox : {
 
1517
                        int arrow = pixelMetric (PM_ScrollBarExtent, widget);
 
1518
                        switch (subcontrol)
 
1519
                        {
 
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);
 
1527
        
 
1528
                                default: break;
 
1529
                        }
 
1530
                        break;
 
1531
                }
 
1532
                case CC_SpinWidget : {
 
1533
                        int arrow = pixelMetric (PM_ScrollBarExtent, 0);
 
1534
                        switch (subcontrol)
 
1535
                        {
 
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);
 
1548
        
 
1549
                                default: break;
 
1550
                        }
 
1551
                        break;
 
1552
                }
 
1553
 
 
1554
                default: break;
 
1555
        }
 
1556
 
 
1557
        return KStyle::querySubControlMetrics (control, widget, subcontrol, opt);
 
1558
}
 
1559
 
 
1560
 
 
1561
int HighContrastStyle::pixelMetric(PixelMetric m, const QWidget *widget) const
 
1562
{
 
1563
        //### TODO: Use the tab metrics changes from Ker.
 
1564
        switch(m)
 
1565
        {
 
1566
                // BUTTONS
 
1567
                // -------------------------------------------------------------------
 
1568
                case PM_ButtonMargin:                           // Space btw. frame and label
 
1569
                        return 2*basicLineWidth;
 
1570
 
 
1571
                case PM_ButtonDefaultIndicator: {
 
1572
                        if ((widget != 0) && !widget->isEnabled())
 
1573
                                return 0;
 
1574
                        else
 
1575
                                return 2*basicLineWidth;
 
1576
                }
 
1577
 
 
1578
                case PM_ButtonShiftHorizontal:
 
1579
                case PM_ButtonShiftVertical:
 
1580
                        return 0;
 
1581
 
 
1582
                case PM_ScrollBarExtent: {
 
1583
                        int h = 0;
 
1584
                        if (widget != 0)
 
1585
                                h = (2*widget->fontMetrics().lineSpacing())/3;
 
1586
                        
 
1587
                        if (h > 9*basicLineWidth+4)
 
1588
                                return h;
 
1589
                        else
 
1590
                                return 9*basicLineWidth+4;
 
1591
                }
 
1592
 
 
1593
                case PM_DefaultFrameWidth: {
 
1594
                        if (widget && (widget->inherits ("QLineEdit") || widget->inherits ("QTextEdit")))
 
1595
                                return 2*basicLineWidth;
 
1596
                        else 
 
1597
                                return basicLineWidth;
 
1598
                }
 
1599
 
 
1600
                case PM_SpinBoxFrameWidth: {
 
1601
                        return 2*basicLineWidth;
 
1602
                }
 
1603
 
 
1604
                case PM_MenuButtonIndicator: {          // Arrow width
 
1605
                        int h = 0;
 
1606
                        if (widget != 0)
 
1607
                                h = widget->fontMetrics().lineSpacing()/2;
 
1608
                        
 
1609
                        if (h > 3*basicLineWidth)
 
1610
                                return h;
 
1611
                        else
 
1612
                                return 3*basicLineWidth;
 
1613
                }
 
1614
 
 
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: {
 
1621
                        int h = 0;
 
1622
                        if (widget != 0)
 
1623
                                h = widget->fontMetrics().lineSpacing()-2*basicLineWidth;
 
1624
                        
 
1625
                        if (h > 6*basicLineWidth)
 
1626
                                return h;
 
1627
                        else
 
1628
                                return 6*basicLineWidth;
 
1629
                }
 
1630
                
 
1631
                case PM_DockWindowSeparatorExtent: {
 
1632
                        return 2*basicLineWidth + 1;
 
1633
                }
 
1634
                case PM_DockWindowHandleExtent: {
 
1635
                        int w = 0;
 
1636
                        if (widget != 0)
 
1637
                                w = widget->fontMetrics().lineSpacing()/4;
 
1638
                        if (w > 5*basicLineWidth)
 
1639
                                return w;
 
1640
                        else
 
1641
                                return 5*basicLineWidth;
 
1642
                }
 
1643
 
 
1644
                default:
 
1645
                        return KStyle::pixelMetric(m, widget);
 
1646
        }
 
1647
}
 
1648
 
 
1649
int HighContrastStyle::kPixelMetric( KStylePixelMetric kpm, const QWidget *widget ) const
 
1650
{
 
1651
        switch (kpm) {
 
1652
                case KPM_ListViewBranchThickness:
 
1653
                        // XXX Proper support of thick branches requires reimplementation of
 
1654
                        // the drawKStylePrimitive KPE_ListViewBranch case.
 
1655
                        return basicLineWidth;
 
1656
                default:
 
1657
                        return KStyle::kPixelMetric(kpm, widget);
 
1658
        }
 
1659
}
 
1660
 
 
1661
QSize HighContrastStyle::sizeFromContents( ContentsType contents,
 
1662
                                                                                const QWidget* widget,
 
1663
                                                                                const QSize &contentSize,
 
1664
                                                                                const QStyleOption& opt ) const
 
1665
{
 
1666
        switch (contents)
 
1667
        {
 
1668
                // PUSHBUTTON SIZE
 
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;
 
1676
 
 
1677
                        w += bm + fw + 6;       // ### Add 6 to make way for bold font.
 
1678
                        h += bm + fw;
 
1679
 
 
1680
                        // Ensure we stick to standard width and heights.
 
1681
                        if (( button->isDefault() || button->autoDefault() ) && (button->isEnabled())) {
 
1682
                                if ( w < 80 && !button->text().isEmpty() )
 
1683
                                        w = 80;
 
1684
 
 
1685
                                // Compensate for default indicator
 
1686
                                int di = pixelMetric( PM_ButtonDefaultIndicator );
 
1687
                                w += di * 2;
 
1688
                                h += di * 2;
 
1689
                        }
 
1690
 
 
1691
                        if ( h < 22 )
 
1692
                                h = 22;
 
1693
 
 
1694
                        return QSize( w + basicLineWidth*2, h + basicLineWidth*2 );
 
1695
                }
 
1696
 
 
1697
                // TOOLBUTTON SIZE
 
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);
 
1703
                        break;
 
1704
                }
 
1705
 
 
1706
                // COMBOBOX SIZE
 
1707
                // -----------------------------------------------------------------
 
1708
                case CT_ComboBox: {
 
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;
 
1713
                }
 
1714
 
 
1715
                // POPUPMENU ITEM SIZE
 
1716
                // -----------------------------------------------------------------
 
1717
                case CT_PopupMenuItem: {
 
1718
                        if ( ! widget || opt.isDefault() )
 
1719
                                return contentSize;
 
1720
 
 
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();
 
1726
 
 
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;
 
1732
                        }
 
1733
                        else if ( mi->widget() ) {
 
1734
                        } else if ( mi->isSeparator() ) {
 
1735
                                w = 10; // Arbitrary
 
1736
                                h = 4;
 
1737
                        }
 
1738
                        else {
 
1739
                                if ( mi->pixmap() )
 
1740
                                        h = qMax( h, mi->pixmap()->height() + 2*itemFrame );
 
1741
                                else {
 
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 );
 
1747
                                }
 
1748
 
 
1749
                                if ( mi->iconSet() && ! mi->iconSet()->isNull() )
 
1750
                                        h = qMax( h, mi->iconSet()->pixmap(
 
1751
                                                                QIcon::Small, QIcon::Normal).height() +
 
1752
                                                                2 * itemFrame );
 
1753
                        }
 
1754
 
 
1755
                        if ( ! mi->text().isNull() && mi->text().find('\t') >= 0 )
 
1756
                                w += 12;
 
1757
                        else if ( mi->popup() )
 
1758
                                w += 2 * arrowHMargin;
 
1759
 
 
1760
                        if ( maxpmw )
 
1761
                                w += maxpmw + 6;
 
1762
                        if ( checkable && maxpmw < 20 )
 
1763
                                w += 20 - maxpmw;
 
1764
                        if ( checkable || maxpmw > 0 )
 
1765
                                w += 12;
 
1766
 
 
1767
                        w += rightBorder;
 
1768
 
 
1769
                        return QSize( w, h );
 
1770
                }
 
1771
 
 
1772
 
 
1773
                // LINEDIT SIZE
 
1774
                // -----------------------------------------------------------------
 
1775
                case CT_LineEdit: {
 
1776
                        return contentSize + QSize (4*basicLineWidth, 4*basicLineWidth);
 
1777
                }
 
1778
 
 
1779
 
 
1780
                default:
 
1781
                        return KStyle::sizeFromContents( contents, widget, contentSize, opt );
 
1782
        }
 
1783
}
 
1784
 
 
1785
QRect HighContrastStyle::subRect (SubRect subrect, const QWidget * widget) const
 
1786
{
 
1787
        switch (subrect) {
 
1788
                case SR_ProgressBarGroove:
 
1789
                case SR_ProgressBarContents:
 
1790
                case SR_ProgressBarLabel:
 
1791
                        return widget->rect();
 
1792
                default:
 
1793
                        return KStyle::subRect (subrect, widget);
 
1794
        }
 
1795
}
 
1796
 
 
1797
bool HighContrastStyle::eventFilter (QObject *object, QEvent *event)
 
1798
{
 
1799
        QWidget* widget = qobject_cast<QWidget*>(object);
 
1800
        if (widget)
 
1801
        {
 
1802
                // Handle hover effects.
 
1803
                if (event->type() == QEvent::Enter
 
1804
                                && (widget->inherits ("QButton")
 
1805
                                        || widget->inherits ("QComboBox")
 
1806
                                        || widget->inherits ("QSpinWidget")))
 
1807
                {
 
1808
                        hoverWidget = widget;
 
1809
                        widget->repaint (false);
 
1810
                }
 
1811
                else if (event->type() == QEvent::Leave
 
1812
                                        && (widget->inherits ("QButton")
 
1813
                                                || widget->inherits ("QComboBox")
 
1814
                                                || widget->inherits ("QSpinWidget")))
 
1815
                {
 
1816
                        if (object == hoverWidget)
 
1817
                                hoverWidget = 0L;
 
1818
                        widget->repaint (false);
 
1819
                }
 
1820
                // Make sure the focus rectangle is shown correctly.
 
1821
                else if (event->type() == QEvent::FocusIn || event->type() == QEvent::FocusOut)
 
1822
                {
 
1823
                        QWidget* widgetparent = qobject_cast<QWidget*>(widget->parent());
 
1824
                        while (widgetparent
 
1825
                                                        && ! widgetparent->inherits ("QComboBox")
 
1826
                                                        && ! widgetparent->inherits ("QSpinWidget"))
 
1827
                        {
 
1828
                                widgetparent = qobject_cast<QWidget*>(widgetparent->parent());
 
1829
                        }
 
1830
 
 
1831
                        if (widgetparent)
 
1832
                                widgetparent->repaint (false);
 
1833
                        else
 
1834
                                widget->repaint (false);
 
1835
                }
 
1836
        }
 
1837
        
 
1838
        return KStyle::eventFilter (object, event);
 
1839
}
 
1840
 
 
1841
// vim: set noet ts=4 sw=4:
 
1842
// kate: indent-width 4; replace-tabs off; smart-indent on; tab-width 4;