manhattanstyle.cpp 42 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
Eike Ziller's avatar
Eike Ziller committed
3
4
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8
9
10
11
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
Eike Ziller's avatar
Eike Ziller committed
12
13
** a written agreement between you and The Qt Company.  For licensing terms and
** conditions see http://www.qt.io/terms-conditions.  For further information
Eike Ziller's avatar
Eike Ziller committed
14
** use the contact form at http://www.qt.io/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
18
19
20
21
22
23
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
**
Eike Ziller's avatar
Eike Ziller committed
25
26
** In addition, as a special exception, The Qt Company gives you certain additional
** rights.  These rights are described in The Qt Company LGPL Exception
con's avatar
con committed
27
28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
29
****************************************************************************/
con's avatar
con committed
30
31

#include "manhattanstyle.h"
hjk's avatar
hjk committed
32

con's avatar
con committed
33
#include "styleanimator.h"
hjk's avatar
hjk committed
34

35
36
#include <coreplugin/coreconstants.h>

37
#include <utils/hostosinfo.h>
38
39
#include <utils/stylehelper.h>

40
#include <utils/fancymainwindow.h>
41
#include <utils/theme/theme.h>
42

43
44
45
#include <QApplication>
#include <QComboBox>
#include <QDockWidget>
46
#include <QFormLayout>
47
48
#include <QLabel>
#include <QLineEdit>
49
#include <QMenuBar>
50
51
52
53
54
55
56
#include <QPainter>
#include <QPixmap>
#include <QStatusBar>
#include <QStyleFactory>
#include <QStyleOption>
#include <QToolBar>
#include <QToolButton>
hjk's avatar
hjk committed
57

58
59
using namespace Utils;

con's avatar
con committed
60
// We define a currently unused state for indicating animations
61
const QStyle::State State_Animating = QStyle::State(0x00000040);
con's avatar
con committed
62
63
64
65
66
67
68
69
70

// Because designer needs to disable this for widget previews
// we have a custom property that is inherited
bool styleEnabled(const QWidget *widget)
{
    const QWidget *p = widget;
    while (p) {
        if (p->property("_q_custom_style_disabled").toBool())
            return false;
Orgad Shaneh's avatar
Orgad Shaneh committed
71
        p = p->parentWidget();
con's avatar
con committed
72
73
74
75
76
77
78
    }
    return true;
}

// Consider making this a QStyle state
bool panelWidget(const QWidget *widget)
{
79
80
81
    if (!widget)
        return false;

Tobias Hunger's avatar
Tobias Hunger committed
82
    // Do not style dialogs or explicitly ignored widgets
83
    if ((widget->window()->windowFlags() & Qt::WindowType_Mask) == Qt::Dialog)
84
        return false;
con's avatar
con committed
85

86
    if (qobject_cast<const FancyMainWindow *>(widget))
87
88
        return true;

Jens Bache-Wiig's avatar
Jens Bache-Wiig committed
89
90
91
    if (qobject_cast<const QTabBar *>(widget))
        return styleEnabled(widget);

92
    const QWidget *p = widget;
con's avatar
con committed
93
    while (p) {
94
95
        if (qobject_cast<const QToolBar *>(p) ||
            qobject_cast<const QStatusBar *>(p) ||
96
            qobject_cast<const QMenuBar *>(p) ||
97
            p->property("panelwidget").toBool())
98
            return styleEnabled(widget);
con's avatar
con committed
99
100
101
102
103
        p = p->parentWidget();
    }
    return false;
}

104
105
106
107
108
109
110
// Consider making this a QStyle state
bool lightColored(const QWidget *widget)
{
    if (!widget)
        return false;

    // Don't style dialogs or explicitly ignored widgets
111
    if ((widget->window()->windowFlags() & Qt::WindowType_Mask) == Qt::Dialog)
112
113
114
115
116
117
118
119
120
121
122
        return false;

    const QWidget *p = widget;
    while (p) {
        if (p->property("lightColored").toBool())
            return true;
        p = p->parentWidget();
    }
    return false;
}

con's avatar
con committed
123
124
125
class ManhattanStylePrivate
{
public:
126
    explicit ManhattanStylePrivate();
con's avatar
con committed
127
    void init();
hjk's avatar
hjk committed
128
129

public:
130
131
132
133
    const QImage lineeditImage;
    const QImage lineeditImage_disabled;
    const QPixmap extButtonPixmap;
    const QPixmap closeButtonPixmap;
con's avatar
con committed
134
135
136
    StyleAnimator animator;
};

137
ManhattanStylePrivate::ManhattanStylePrivate() :
138
139
    lineeditImage(StyleHelper::dpiSpecificImageFile(QStringLiteral(":/core/images/inputfield.png"))),
    lineeditImage_disabled(StyleHelper::dpiSpecificImageFile(QStringLiteral(":/core/images/inputfield_disabled.png"))),
140
    extButtonPixmap(QLatin1String(":/core/images/extension.png")),
141
    closeButtonPixmap(QLatin1String(Core::Constants::ICON_CLOSE_BUTTON))
142
143
144
{
}

con's avatar
con committed
145
ManhattanStyle::ManhattanStyle(const QString &baseStyleName)
146
147
    : QProxyStyle(QStyleFactory::create(baseStyleName)),
    d(new ManhattanStylePrivate())
con's avatar
con committed
148
149
150
151
152
153
154
155
156
157
158
{
}

ManhattanStyle::~ManhattanStyle()
{
    delete d;
    d = 0;
}

QPixmap ManhattanStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const
{
159
    return QProxyStyle::generatedIconPixmap(iconMode, pixmap, opt);
con's avatar
con committed
160
161
162
163
164
}

QSize ManhattanStyle::sizeFromContents(ContentsType type, const QStyleOption *option,
                                       const QSize &size, const QWidget *widget) const
{
165
    QSize newSize = QProxyStyle::sizeFromContents(type, option, size, widget);
166

con's avatar
con committed
167
168
    if (type == CT_Splitter && widget && widget->property("minisplitter").toBool())
        return QSize(1, 1);
169
    else if (type == CT_ComboBox && panelWidget(widget))
Jens Bache-Wiig's avatar
Jens Bache-Wiig committed
170
        newSize += QSize(14, 0);
171
    return newSize;
con's avatar
con committed
172
173
174
175
}

QRect ManhattanStyle::subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const
{
176
    return QProxyStyle::subElementRect(element, option, widget);
con's avatar
con committed
177
178
179
180
181
}

QRect ManhattanStyle::subControlRect(ComplexControl control, const QStyleOptionComplex *option,
                                     SubControl subControl, const QWidget *widget) const
{
182
    return QProxyStyle::subControlRect(control, option, subControl, widget);
con's avatar
con committed
183
184
185
186
187
}

QStyle::SubControl ManhattanStyle::hitTestComplexControl(ComplexControl control, const QStyleOptionComplex *option,
                                                         const QPoint &pos, const QWidget *widget) const
{
188
    return QProxyStyle::hitTestComplexControl(control, option, pos, widget);
con's avatar
con committed
189
190
191
192
193
}

int ManhattanStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const
{
    int retval = 0;
194
    retval = QProxyStyle::pixelMetric(metric, option, widget);
con's avatar
con committed
195
196
197
198
199
200
201
202
203
    switch (metric) {
    case PM_SplitterWidth:
        if (widget && widget->property("minisplitter").toBool())
            retval = 1;
        break;
    case PM_ToolBarIconSize:
        if (panelWidget(widget))
            retval = 16;
        break;
204
    case PM_DockWidgetHandleExtent:
205
206
    case PM_DockWidgetSeparatorExtent:
        return 1;
207
208
209
    case PM_MenuPanelWidth:
    case PM_MenuBarHMargin:
    case PM_MenuBarVMargin:
con's avatar
con committed
210
211
212
213
214
215
    case PM_ToolBarFrameWidth:
        if (panelWidget(widget))
            retval = 1;
        break;
    case PM_ButtonShiftVertical:
    case PM_ButtonShiftHorizontal:
216
    case PM_MenuBarPanelWidth:
con's avatar
con committed
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
    case PM_ToolBarItemMargin:
    case PM_ToolBarItemSpacing:
        if (panelWidget(widget))
            retval = 0;
        break;
    case PM_DefaultFrameWidth:
        if (qobject_cast<const QLineEdit*>(widget) && panelWidget(widget))
            return 1;
        break;
    default:
        break;
    }
    return retval;
}

QPalette ManhattanStyle::standardPalette() const
{
234
    return QProxyStyle::standardPalette();
con's avatar
con committed
235
236
237
238
}

void ManhattanStyle::polish(QApplication *app)
{
239
    return QProxyStyle::polish(app);
con's avatar
con committed
240
241
242
243
}

void ManhattanStyle::unpolish(QApplication *app)
{
244
    return QProxyStyle::unpolish(app);
con's avatar
con committed
245
246
}

247
QPalette panelPalette(const QPalette &oldPalette, bool lightColored = false)
con's avatar
con committed
248
{
249
250
    QColor color = creatorTheme()->color(lightColored ? Theme::PanelTextColorDark
                                                      : Theme::PanelTextColorLight);
con's avatar
con committed
251
252
253
254
255
256
257
258
259
260
261
262
263
    QPalette pal = oldPalette;
    pal.setBrush(QPalette::All, QPalette::WindowText, color);
    pal.setBrush(QPalette::All, QPalette::ButtonText, color);
    pal.setBrush(QPalette::All, QPalette::Foreground, color);
    color.setAlpha(100);
    pal.setBrush(QPalette::Disabled, QPalette::WindowText, color);
    pal.setBrush(QPalette::Disabled, QPalette::ButtonText, color);
    pal.setBrush(QPalette::Disabled, QPalette::Foreground, color);
    return pal;
}

void ManhattanStyle::polish(QWidget *widget)
{
264
    QProxyStyle::polish(widget);
con's avatar
con committed
265

266
    // OxygenStyle forces a rounded widget mask on toolbars and dock widgets
Daniel Teske's avatar
Daniel Teske committed
267
    if (baseStyle()->inherits("OxygenStyle") || baseStyle()->inherits("Oxygen::Style")) {
268
        if (qobject_cast<QToolBar*>(widget) || qobject_cast<QDockWidget*>(widget)) {
269
            widget->removeEventFilter(baseStyle());
270
271
            widget->setContentsMargins(0, 0, 0, 0);
        }
con's avatar
con committed
272
273
    }
    if (panelWidget(widget)) {
Jens Bache-Wiig's avatar
Jens Bache-Wiig committed
274
275
276
277
278

        // Oxygen and possibly other styles override this
        if (qobject_cast<QDockWidget*>(widget))
            widget->setContentsMargins(0, 0, 0, 0);

con's avatar
con committed
279
        widget->setAttribute(Qt::WA_LayoutUsesWidgetRect, true);
con's avatar
con committed
280
281
        if (qobject_cast<QToolButton*>(widget)) {
            widget->setAttribute(Qt::WA_Hover);
282
            widget->setMaximumHeight(StyleHelper::navigationWidgetHeight() - 2);
283
        } else if (qobject_cast<QLineEdit*>(widget)) {
con's avatar
con committed
284
            widget->setAttribute(Qt::WA_Hover);
285
            widget->setMaximumHeight(StyleHelper::navigationWidgetHeight() - 2);
286
        } else if (qobject_cast<QLabel*>(widget)) {
287
            widget->setPalette(panelPalette(widget->palette(), lightColored(widget)));
288
        } else if (widget->property("panelwidget_singlerow").toBool()) {
289
            widget->setFixedHeight(StyleHelper::navigationWidgetHeight());
290
        } else if (qobject_cast<QStatusBar*>(widget)) {
291
            widget->setFixedHeight(StyleHelper::navigationWidgetHeight() + 2);
292
        } else if (qobject_cast<QComboBox*>(widget)) {
293
            widget->setMaximumHeight(StyleHelper::navigationWidgetHeight() - 2);
Jens Bache-Wiig's avatar
Jens Bache-Wiig committed
294
295
            widget->setAttribute(Qt::WA_Hover);
        }
con's avatar
con committed
296
297
298
299
300
    }
}

void ManhattanStyle::unpolish(QWidget *widget)
{
301
    QProxyStyle::unpolish(widget);
con's avatar
con committed
302
    if (panelWidget(widget)) {
con's avatar
con committed
303
        widget->setAttribute(Qt::WA_LayoutUsesWidgetRect, false);
con's avatar
con committed
304
305
306
307
        if (qobject_cast<QTabBar*>(widget))
            widget->setAttribute(Qt::WA_Hover, false);
        else if (qobject_cast<QToolBar*>(widget))
            widget->setAttribute(Qt::WA_Hover, false);
Jens Bache-Wiig's avatar
Jens Bache-Wiig committed
308
309
        else if (qobject_cast<QComboBox*>(widget))
            widget->setAttribute(Qt::WA_Hover, false);
con's avatar
con committed
310
311
312
313
314
    }
}

void ManhattanStyle::polish(QPalette &pal)
{
315
    QProxyStyle::polish(pal);
con's avatar
con committed
316
317
}

Alessandro Portale's avatar
Alessandro Portale committed
318
QIcon ManhattanStyle::standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget) const
con's avatar
con committed
319
{
Alessandro Portale's avatar
Alessandro Portale committed
320
321
322
323
324
325
326
327
328
    QIcon icon;
    switch (standardIcon) {
    case QStyle::SP_TitleBarCloseButton:
    case QStyle::SP_ToolBarHorizontalExtensionButton:
        return QIcon(standardPixmap(standardIcon, option, widget));
    default:
        icon = baseStyle()->standardIcon(standardIcon, option, widget);
    }
    return icon;
con's avatar
con committed
329
330
331
332
333
}

QPixmap ManhattanStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt,
                                       const QWidget *widget) const
{
334
    if (widget && !panelWidget(widget))
335
        return QProxyStyle::standardPixmap(standardPixmap, opt, widget);
336

con's avatar
con committed
337
338
    QPixmap pixmap;
    switch (standardPixmap) {
339
340
    case QStyle::SP_ToolBarHorizontalExtensionButton:
        pixmap = d->extButtonPixmap;
341
        break;
342
343
    case QStyle::SP_TitleBarCloseButton:
        pixmap = d->closeButtonPixmap;
con's avatar
con committed
344
345
        break;
    default:
346
        pixmap = QProxyStyle::standardPixmap(standardPixmap, opt, widget);
347
        break;
con's avatar
con committed
348
349
350
351
352
353
354
    }
    return pixmap;
}

int ManhattanStyle::styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget,
                              QStyleHintReturn *returnData) const
{
355
    int ret = QProxyStyle::styleHint(hint, option, widget, returnData);
con's avatar
con committed
356
357
    switch (hint) {
    case QStyle::SH_EtchDisabledText:
358
        if (panelWidget(widget) || qobject_cast<const QMenu *> (widget) )
359
            ret = false;
con's avatar
con committed
360
        break;
361
362
363
    case QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren:
        ret = true;
        break;
364
365
366
367
368
369
370
    case QStyle::SH_ItemView_ActivateItemOnSingleClick:
        // default depends on the style
        if (widget) {
            QVariant activationMode = widget->property("ActivationMode");
            if (activationMode.isValid())
                ret = activationMode.toBool();
        }
371
        break;
372
373
374
375
376
    case QStyle::SH_FormLayoutFieldGrowthPolicy:
        // The default in QMacStyle, FieldsStayAtSizeHint, is just always the wrong thing
        // Use the same as on all other shipped styles
        if (Utils::HostOsInfo::isMacHost())
            ret = QFormLayout::AllNonFixedFieldsGrow;
377
        break;
con's avatar
con committed
378
    default:
379
        break;
con's avatar
con committed
380
381
382
383
384
385
386
    }
    return ret;
}

void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option,
                                   QPainter *painter, const QWidget *widget) const
{
Alessandro Portale's avatar
Alessandro Portale committed
387
    if (!panelWidget(widget))
388
        return QProxyStyle::drawPrimitive(element, option, painter, widget);
con's avatar
con committed
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417

    bool animating = (option->state & State_Animating);
    int state = option->state;
    QRect rect = option->rect;
    QRect oldRect;
    QRect newRect;
    if (widget && (element == PE_PanelButtonTool) && !animating) {
        QWidget *w = const_cast<QWidget *> (widget);
        int oldState = w->property("_q_stylestate").toInt();
        oldRect = w->property("_q_stylerect").toRect();
        newRect = w->rect();
        w->setProperty("_q_stylestate", (int)option->state);
        w->setProperty("_q_stylerect", w->rect());

        // Determine the animated transition
        bool doTransition = ((state & State_On)         != (oldState & State_On)     ||
                             (state & State_MouseOver)  != (oldState & State_MouseOver));
        if (oldRect != newRect)
        {
            doTransition = false;
            d->animator.stopAnimation(widget);
        }

        if (doTransition) {
            QImage startImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied);
            QImage endImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied);
            Animation *anim = d->animator.widgetAnimation(widget);
            QStyleOption opt = *option;
            opt.state = (QStyle::State)oldState;
418
            opt.state |= State_Animating;
con's avatar
con committed
419
420
421
422
423
424
425
426
427
428
429
            startImage.fill(0);
            Transition *t = new Transition;
            t->setWidget(w);
            QPainter startPainter(&startImage);
            if (!anim) {
                drawPrimitive(element, &opt, &startPainter, widget);
            } else {
                anim->paint(&startPainter, &opt);
                d->animator.stopAnimation(widget);
            }
            QStyleOption endOpt = *option;
430
            endOpt.state |= State_Animating;
con's avatar
con committed
431
432
433
434
435
436
            t->setStartImage(startImage);
            d->animator.startAnimation(t);
            endImage.fill(0);
            QPainter endPainter(&endImage);
            drawPrimitive(element, &endOpt, &endPainter, widget);
            t->setEndImage(endImage);
437
438
439
440
            if (oldState & State_MouseOver)
                t->setDuration(150);
            else
                t->setDuration(75);
con's avatar
con committed
441
442
443
444
445
            t->setStartTime(QTime::currentTime());
        }
    }

    switch (element) {
446
    case PE_IndicatorDockWidgetResizeHandle:
447
        painter->fillRect(option->rect, creatorTheme()->color(Theme::DockWidgetResizeHandleColor));
448
449
450
451
        break;
    case PE_FrameDockWidget:
        QCommonStyle::drawPrimitive(element, option, painter, widget);
        break;
con's avatar
con committed
452
453
454
    case PE_PanelLineEdit:
        {
            painter->save();
455
456
457
458
459
460

            // Fill the line edit background
            QRect filledRect = option->rect.adjusted(1, 1, -1, -1);
            painter->setBrushOrigin(filledRect.topLeft());
            painter->fillRect(filledRect, option->palette.base());

con's avatar
con committed
461
            if (option->state & State_Enabled)
462
                StyleHelper::drawCornerImage(d->lineeditImage, painter, option->rect, 5, 5, 5, 5);
con's avatar
con committed
463
            else
464
                StyleHelper::drawCornerImage(d->lineeditImage_disabled, painter, option->rect, 5, 5, 5, 5);
con's avatar
con committed
465
466

            if (option->state & State_HasFocus || option->state & State_MouseOver) {
467
                QColor hover = StyleHelper::baseColor();
con's avatar
con committed
468
469
470
471
472
473
                if (state & State_HasFocus)
                    hover.setAlpha(100);
                else
                    hover.setAlpha(50);

                painter->setPen(QPen(hover, 1));
474
                painter->drawRect(QRectF(option->rect).adjusted(1.5, 1.5, -1.5, -1.5));
con's avatar
con committed
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
            }
            painter->restore();
        }
        break;

    case PE_FrameStatusBarItem:
        break;

    case PE_PanelButtonTool: {
            Animation *anim = d->animator.widgetAnimation(widget);
            if (!animating && anim) {
                anim->paint(painter, option);
            } else {
                bool pressed = option->state & State_Sunken || option->state & State_On;
                QColor shadow(0, 0, 0, 30);
                painter->setPen(shadow);
                if (pressed) {
492
493
494
                    QColor shade(0, 0, 0, 40);
                    painter->fillRect(rect, shade);
                    painter->drawLine(rect.topLeft() + QPoint(1, 0), rect.topRight() - QPoint(1, 0));
con's avatar
con committed
495
                    painter->drawLine(rect.topLeft(), rect.bottomLeft());
496
497
                    painter->drawLine(rect.topRight(), rect.bottomRight());
                   // painter->drawLine(rect.bottomLeft()  + QPoint(1, 0), rect.bottomRight()  - QPoint(1, 0));
con's avatar
con committed
498
499
                    QColor highlight(255, 255, 255, 30);
                    painter->setPen(highlight);
500
                } else if (option->state & State_Enabled && option->state & State_MouseOver) {
501
                    painter->fillRect(rect, creatorTheme()->color(Theme::PanelButtonToolBackgroundColorHover));
502
503
504
                } else if (widget && widget->property("highlightWidget").toBool()) {
                    QColor shade(0, 0, 0, 128);
                    painter->fillRect(rect, shade);
con's avatar
con committed
505
                }
506
507
508
509
510
511
512
                if (option->state & State_HasFocus && (option->state & State_KeyboardFocusChange)) {
                    QColor highlight = option->palette.highlight().color();
                    highlight.setAlphaF(0.4);
                    painter->setPen(QPen(highlight.lighter(), 1));
                    highlight.setAlphaF(0.3);
                    painter->setBrush(highlight);
                    painter->setRenderHint(QPainter::Antialiasing);
513
514
                    const QRectF rect = option->rect;
                    painter->drawRoundedRect(rect.adjusted(2.5, 2.5, -2.5, -2.5), 2, 2);
515
                }
con's avatar
con committed
516
517
518
519
520
521
           }
        }
        break;

    case PE_PanelStatusBar:
        {
522
523
            if (creatorTheme()->widgetStyle() == Theme::StyleDefault) {
                painter->save();
524
                QLinearGradient grad = StyleHelper::statusBarGradient(rect);
525
526
527
528
                painter->fillRect(rect, grad);
                painter->setPen(QColor(255, 255, 255, 60));
                painter->drawLine(rect.topLeft() + QPoint(0,1),
                                  rect.topRight()+ QPoint(0,1));
529
                painter->setPen(StyleHelper::borderColor().darker(110)); //TODO: make themable
530
531
532
533
534
                painter->drawLine(rect.topLeft(), rect.topRight());
                painter->restore();
            } else {
                painter->fillRect(rect, creatorTheme()->color(Theme::PanelStatusBarBackgroundColor));
            }
con's avatar
con committed
535
536
537
538
539
        }
        break;

    case PE_IndicatorToolBarSeparator:
        {
540
            QColor separatorColor = StyleHelper::borderColor();
con's avatar
con committed
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
            separatorColor.setAlpha(100);
            painter->setPen(separatorColor);
            const int margin = 6;
            if (option->state & State_Horizontal) {
                const int offset = rect.width()/2;
                painter->drawLine(rect.bottomLeft().x() + offset,
                            rect.bottomLeft().y() - margin,
                            rect.topLeft().x() + offset,
                            rect.topLeft().y() + margin);
            } else { //Draw vertical separator
                const int offset = rect.height()/2;
                painter->setPen(QPen(option->palette.background().color().darker(110)));
                painter->drawLine(rect.topLeft().x() + margin ,
                            rect.topLeft().y() + offset,
                            rect.topRight().x() - margin,
                            rect.topRight().y() + offset);
            }
        }
        break;

    case PE_IndicatorToolBarHandle:
        {
            bool horizontal = option->state & State_Horizontal;
            painter->save();
            QPainterPath path;
566
567
            int x = option->rect.x() + (horizontal ? 2 : 6);
            int y = option->rect.y() + (horizontal ? 6 : 2);
con's avatar
con committed
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
            static const int RectHeight = 2;
            if (horizontal) {
                while (y < option->rect.height() - RectHeight - 6) {
                    path.moveTo(x, y);
                    path.addRect(x, y, RectHeight, RectHeight);
                    y += 6;
                }
            } else {
                while (x < option->rect.width() - RectHeight - 6) {
                    path.moveTo(x, y);
                    path.addRect(x, y, RectHeight, RectHeight);
                    x += 6;
                }
            }

            painter->setPen(Qt::NoPen);
584
            QColor dark = StyleHelper::borderColor();
con's avatar
con committed
585
586
            dark.setAlphaF(0.4);

587
            QColor light = StyleHelper::baseColor();
con's avatar
con committed
588
589
590
591
592
593
594
595
596
597
598
599
600
601
            light.setAlphaF(0.4);

            painter->fillPath(path, light);
            painter->save();
            painter->translate(1, 1);
            painter->fillPath(path, dark);
            painter->restore();
            painter->translate(3, 3);
            painter->fillPath(path, light);
            painter->translate(1, 1);
            painter->fillPath(path, dark);
            painter->restore();
        }
        break;
602
603
604
605
606
    case PE_IndicatorArrowUp:
    case PE_IndicatorArrowDown:
    case PE_IndicatorArrowRight:
    case PE_IndicatorArrowLeft:
        {
607
            StyleHelper::drawArrow(element, painter, option);
608
609
        }
        break;
con's avatar
con committed
610
611

    default:
612
        QProxyStyle::drawPrimitive(element, option, painter, widget);
con's avatar
con committed
613
614
615
616
617
618
619
        break;
    }
}

void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *option,
                                 QPainter *painter, const QWidget *widget) const
{
620
    if (!panelWidget(widget) && !qobject_cast<const QMenu *>(widget))
621
        return QProxyStyle::drawControl(element, option, painter, widget);
con's avatar
con committed
622
623

    switch (element) {
624
    case CE_Splitter:
625
        if (creatorTheme()->widgetStyle() == Theme::StyleFlat)
626
            painter->fillRect(option->rect, creatorTheme()->color(Theme::SplitterColor));
627
        else
628
            painter->fillRect(option->rect, StyleHelper::borderColor());
629
630
631
632
633
634
635
636
        break;

    case CE_TabBarTabShape:
        // Most styles draw a single dark outline. This looks rather ugly when combined with our
        // single pixel dark separator so we adjust the first tab to compensate for this

        if (const QStyleOptionTabV3 *tab = qstyleoption_cast<const QStyleOptionTabV3 *>(option)) {
            QStyleOptionTabV3 adjustedTab = *tab;
637
638
639
640
            if (tab->cornerWidgets == QStyleOptionTab::NoCornerWidgets && (
                    tab->position == QStyleOptionTab::Beginning ||
                    tab->position == QStyleOptionTab::OnlyOneTab))
            {
641
642
643
644
645
646
647
648
649
650
                if (option->direction == Qt::LeftToRight)
                    adjustedTab.rect = adjustedTab.rect.adjusted(-1, 0, 0, 0);
                else
                    adjustedTab.rect = adjustedTab.rect.adjusted(0, 0, 1 ,0);
            }
            QProxyStyle::drawControl(element, &adjustedTab, painter, widget);
            return;
        }
        break;

651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
    case CE_MenuItem:
        painter->save();
        if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
            const bool enabled = mbi->state & State_Enabled;
            QStyleOptionMenuItem item = *mbi;
            item.rect = mbi->rect;
            const QColor color = creatorTheme()->color(enabled
                                                       ? Theme::MenuItemTextColorNormal
                                                       : Theme::MenuItemTextColorDisabled);
            if (color.isValid()) {
                QPalette pal = mbi->palette;
                pal.setBrush(QPalette::Text, color);
                item.palette = pal;
            }
            QProxyStyle::drawControl(element, &item, painter, widget);
        }
        painter->restore();
        break;

670
671
672
    case CE_MenuBarItem:
        painter->save();
        if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
673
            QColor highlightOutline = StyleHelper::borderColor().lighter(120);
674
675
676
677
678
679
            const bool act = mbi->state & (State_Sunken | State_Selected);
            const bool dis = !(mbi->state & State_Enabled);

            if (creatorTheme()->widgetStyle() == Theme::StyleFlat)
                painter->fillRect(option->rect, creatorTheme()->color(Theme::MenuBarItemBackgroundColor));
            else
680
                StyleHelper::menuGradient(painter, option->rect, option->rect);
681

682
683
684
            QStyleOptionMenuItem item = *mbi;
            item.rect = mbi->rect;
            QPalette pal = mbi->palette;
685
686
687
            pal.setBrush(QPalette::ButtonText, dis
                ? creatorTheme()->color(Theme::MenuBarItemTextColorDisabled)
                : creatorTheme()->color(Theme::MenuBarItemTextColorNormal));
688
689
690
691
692
            item.palette = pal;
            QCommonStyle::drawControl(element, &item, painter, widget);

            if (act) {
                // Fill|
693
                QColor baseColor = StyleHelper::baseColor();
694
695
696
697
698
699
700
                QLinearGradient grad(option->rect.topLeft(), option->rect.bottomLeft());
                grad.setColorAt(0, baseColor.lighter(120));
                grad.setColorAt(1, baseColor.lighter(130));
                painter->fillRect(option->rect.adjusted(1, 1, -1, 0), grad);

                // Outline
                painter->setPen(QPen(highlightOutline, 0));
701
                const QRect r = option->rect;
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
                painter->drawLine(QPoint(r.left(), r.top() + 1), QPoint(r.left(), r.bottom()));
                painter->drawLine(QPoint(r.right(), r.top() + 1), QPoint(r.right(), r.bottom()));
                painter->drawLine(QPoint(r.left() + 1, r.top()), QPoint(r.right() - 1, r.top()));
                highlightOutline.setAlpha(60);
                painter->setPen(QPen(highlightOutline, 0));
                painter->drawPoint(r.topLeft());
                painter->drawPoint(r.topRight());

                QPalette pal = mbi->palette;
                uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
                if (!styleHint(SH_UnderlineShortcut, mbi, widget))
                    alignment |= Qt::TextHideMnemonic;
                pal.setBrush(QPalette::Text, dis ? Qt::gray : QColor(0, 0, 0, 60));
                drawItemText(painter, item.rect.translated(0, 1), alignment, pal, mbi->state & State_Enabled, mbi->text, QPalette::Text);
                pal.setBrush(QPalette::Text, dis ? Qt::gray : Qt::white);
                drawItemText(painter, item.rect, alignment, pal, mbi->state & State_Enabled, mbi->text, QPalette::Text);
            }
        }
        painter->restore();
        break;

con's avatar
con committed
723
724
725
    case CE_ComboBoxLabel:
        if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
            if (panelWidget(widget)) {
726
                painter->save();
con's avatar
con committed
727
728
                QRect editRect = subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, widget);
                QPalette customPal = cb->palette;
729
                bool drawIcon = !(widget && widget->property("hideicon").toBool());
con's avatar
con committed
730

731
                if (!cb->currentIcon.isNull() && drawIcon) {
con's avatar
con committed
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
                    QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal
                                                                 : QIcon::Disabled;
                    QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, mode);
                    QRect iconRect(editRect);
                    iconRect.setWidth(cb->iconSize.width() + 4);
                    iconRect = alignedRect(cb->direction,
                                           Qt::AlignLeft | Qt::AlignVCenter,
                                           iconRect.size(), editRect);
                    if (cb->editable)
                        painter->fillRect(iconRect, customPal.brush(QPalette::Base));
                    drawItemPixmap(painter, iconRect, Qt::AlignCenter, pixmap);

                    if (cb->direction == Qt::RightToLeft)
                        editRect.translate(-4 - cb->iconSize.width(), 0);
                    else
                        editRect.translate(cb->iconSize.width() + 4, 0);
Jens Bache-Wiig's avatar
Jens Bache-Wiig committed
748
749
750

                    // Reserve some space for the down-arrow
                    editRect.adjust(0, 0, -13, 0);
con's avatar
con committed
751
752
                }

753
754
755
756
757
758
759
760
761
762
763
764
765
766
                QLatin1Char asterisk('*');
                int elideWidth = editRect.width();

                bool notElideAsterisk = widget && widget->property("notelideasterisk").toBool()
                                        && cb->currentText.endsWith(asterisk)
                                        && option->fontMetrics.width(cb->currentText) > elideWidth;

                QString text;
                if (notElideAsterisk) {
                    elideWidth -= option->fontMetrics.width(asterisk);
                    text = asterisk;
                }
                text.prepend(option->fontMetrics.elidedText(cb->currentText, Qt::ElideRight, elideWidth));

767
768
769
                if (creatorTheme()->flag(Theme::ComboBoxDrawTextShadow)
                    && (option->state & State_Enabled))
                {
770
                    painter->setPen(QColor(0, 0, 0, 70));
771
                    painter->drawText(editRect.adjusted(1, 0, -1, 0), Qt::AlignLeft | Qt::AlignVCenter, text);
772
                }
773
                if (!(option->state & State_Enabled))
774
775
                    painter->setOpacity(0.8);
                painter->setPen(creatorTheme()->color(Theme::ComboBoxTextColor));
776
                painter->drawText(editRect.adjusted(1, 0, -1, 0), Qt::AlignLeft | Qt::AlignVCenter, text);
777
778

                painter->restore();
con's avatar
con committed
779
            } else {
780
                QProxyStyle::drawControl(element, option, painter, widget);
con's avatar
con committed
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
            }
        }
        break;

    case CE_SizeGrip: {
            painter->save();
            QColor dark = Qt::white;
            dark.setAlphaF(0.1);
            int x, y, w, h;
            option->rect.getRect(&x, &y, &w, &h);
            int sw = qMin(h, w);
            if (h > w)
                painter->translate(0, h - w);
            else
                painter->translate(w - h, 0);
            int sx = x;
            int sy = y;
            int s = 4;
            painter->setPen(dark);
            if (option->direction == Qt::RightToLeft) {
                sx = x + sw;
                for (int i = 0; i < 4; ++i) {
                    painter->drawLine(x, sy, sx, sw);
                    sx -= s;
                    sy += s;
                }
            } else {
                for (int i = 0; i < 4; ++i) {
                    painter->drawLine(sx, sw, sw, sy);
                    sx += s;
                    sy += s;
                }
            }
            painter->restore();
        }
        break;

818
    case CE_MenuBarEmptyArea: {
819
            if (creatorTheme()->widgetStyle() == Theme::StyleDefault) {
820
                StyleHelper::menuGradient(painter, option->rect, option->rect);
821
                painter->save();
822
                painter->setPen(StyleHelper::borderColor());
823
824
825
826
827
828
                painter->drawLine(option->rect.bottomLeft() + QPointF(0.5, 0.5),
                                  option->rect.bottomRight() + QPointF(0.5, 0.5));
                painter->restore();
            } else {
                painter->fillRect(option->rect, creatorTheme()->color(Theme::MenuBarEmptyAreaBackgroundColor));
            }
829
830
831
        }
        break;

con's avatar
con committed
832
833
834
    case CE_ToolBar:
        {
            QRect rect = option->rect;
835
            bool horizontal = option->state & State_Horizontal;
836
837
838

            // Map offset for global window gradient
            QRect gradientSpan;
839
840
841
            if (widget) {
                QPoint offset = widget->window()->mapToGlobal(option->rect.topLeft()) -
                                widget->mapToGlobal(option->rect.topLeft());
842
                gradientSpan = QRect(offset, widget->window()->size());
843
            }
844
845
846

            bool drawLightColored = lightColored(widget);
            if (horizontal)
847
848
849
850
851
            {
                // draws the background of the 'Type hierarchy', 'Projects' headers
                if (creatorTheme()->widgetStyle() == Theme::StyleFlat)
                    painter->fillRect (rect, creatorTheme()->color(Theme::ToolBarBackgroundColor));
                else
852
                    StyleHelper::horizontalGradient(painter, gradientSpan, rect, drawLightColored);
853
854
855
856
            } else {
                if (creatorTheme()->widgetStyle() == Theme::StyleFlat)
                    painter->fillRect (rect, creatorTheme()->color(Theme::ToolBarBackgroundColor));
                else
857
                    StyleHelper::verticalGradient(painter, gradientSpan, rect, drawLightColored);
858
            }
con's avatar
con committed
859

860
            if (!drawLightColored) {
861
                painter->setPen(StyleHelper::borderColor());
862
            }
863
864
            else
                painter->setPen(QColor(0x888888));
con's avatar
con committed
865
866

            if (horizontal) {
867
868
869
                // Note: This is a hack to determine if the
                // toolbar should draw the top or bottom outline
                // (needed for the find toolbar for instance)
870
                QColor lighter(StyleHelper::sidebarHighlight());
871
872
                if (drawLightColored)
                    lighter = QColor(255, 255, 255, 180);
873
                if (widget && widget->property("topBorder").toBool()) {
874
875
876
                    painter->drawLine(rect.topLeft(), rect.topRight());
                    painter->setPen(lighter);
                    painter->drawLine(rect.topLeft() + QPoint(0, 1), rect.topRight() + QPoint(0, 1));
con's avatar
con committed
877
                } else {
878
879
880
                    painter->drawLine(rect.bottomLeft(), rect.bottomRight());
                    painter->setPen(lighter);
                    painter->drawLine(rect.topLeft(), rect.topRight());
con's avatar
con committed
881
882
                }
            } else {
883
884
                painter->drawLine(rect.topLeft(), rect.bottomLeft());
                painter->drawLine(rect.topRight(), rect.bottomRight());
con's avatar
con committed
885
886
887
            }
        }
        break;
888

con's avatar
con committed
889
    default:
890
        QProxyStyle::drawControl(element, option, painter, widget);
con's avatar
con committed
891
892
893
894
895
896
897
898
        break;
    }
}

void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
                                        QPainter *painter, const QWidget *widget) const
{
    if (!panelWidget(widget))
899
         return     QProxyStyle::drawComplexControl(control, option, painter, widget);
con's avatar
con committed
900
901
902
903
904

    QRect rect = option->rect;
    switch (control) {
    case CC_ToolButton:
        if (const QStyleOptionToolButton *toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
905
906
907
908
909
910
            bool reverse = option->direction == Qt::RightToLeft;
            bool drawborder = (widget && widget->property("showborder").toBool());

            if (drawborder)
                drawButtonSeparator(painter, rect, reverse);

con's avatar
con committed
911
912
913
914
915
916
            QRect button, menuarea;
            button = subControlRect(control, toolbutton, SC_ToolButton, widget);
            menuarea = subControlRect(control, toolbutton, SC_ToolButtonMenu, widget);

            State bflags = toolbutton->state;
            if (bflags & State_AutoRaise) {
917
                if (!(bflags & State_MouseOver))
con's avatar
con committed
918
919
920
921
                    bflags &= ~State_Raised;
            }

            State mflags = bflags;
922
923
924
925
926
927
            if (toolbutton->state & State_Sunken) {
                if (toolbutton->activeSubControls & SC_ToolButton)
                    bflags |= State_Sunken;
                if (toolbutton->activeSubControls & SC_ToolButtonMenu)
                    mflags |= State_Sunken;
            }
con's avatar
con committed
928
929
930
931

            QStyleOption tool(0);
            tool.palette = toolbutton->palette;
            if (toolbutton->subControls & SC_ToolButton) {
932
933
934
                tool.rect = button;
                tool.state = bflags;
                drawPrimitive(PE_PanelButtonTool, &tool, painter, widget);
con's avatar
con committed
935
936
937
            }

            QStyleOptionToolButton label = *toolbutton;
938
939

            label.palette = panelPalette(option->palette, lightColored(widget));
940
941
            if (widget && widget->property("highlightWidget").toBool())
                label.palette.setColor(QPalette::ButtonText, Qt::red);
con's avatar
con committed
942
943
            int fw = pixelMetric(PM_DefaultFrameWidth, option, widget);
            label.rect = button.adjusted(fw, fw, -fw, -fw);
944

con's avatar
con committed
945
946
947
948
949
950
951
952
953
954
955
            drawControl(CE_ToolButtonLabel, &label, painter, widget);

            if (toolbutton->subControls & SC_ToolButtonMenu) {
                tool.state = mflags;
                tool.rect = menuarea.adjusted(1, 1, -1, -1);
                if (mflags & (State_Sunken | State_On | State_Raised)) {
                    painter->setPen(Qt::gray);
                    painter->drawLine(tool.rect.topLeft(), tool.rect.bottomLeft());
                    if (mflags & (State_Sunken)) {
                        QColor shade(0, 0, 0, 50);
                        painter->fillRect(tool.rect.adjusted(0, -1, 1, 1), shade);
956
                    } else if (!HostOsInfo::isMacHost() && (mflags & State_MouseOver)) {
con's avatar
con committed
957
958
959
960
961
962
                        QColor shade(255, 255, 255, 50);
                        painter->fillRect(tool.rect.adjusted(0, -1, 1, 1), shade);
                    }
                }
                tool.rect = tool.rect.adjusted(2, 2, -2, -2);
                drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget);
963
            } else if (toolbutton->features & QStyleOptionToolButton::HasMenu
964
                       && widget && !widget->property("noArrow").toBool()) {
965
                int arrowSize = 6;
con's avatar
con committed
966
967
968
                QRect ir = toolbutton->rect.adjusted(1, 1, -1, -1);
                QStyleOptionToolButton newBtn = *toolbutton;
                newBtn.palette = panelPalette(option->palette);
969
970
                newBtn.rect = QRect(ir.right() - arrowSize - 1,
                                    ir.height() - arrowSize - 2, arrowSize, arrowSize);
971
                drawPrimitive(PE_IndicatorArrowDown, &newBtn, painter, widget);
con's avatar
con committed
972
973
974
975
976
            }
        }
        break;

    case CC_ComboBox:
Jens Bache-Wiig's avatar
Jens Bache-Wiig committed
977
        if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
con's avatar
con committed
978
            painter->save();
Jens Bache-Wiig's avatar
Jens Bache-Wiig committed
979
980
            bool isEmpty = cb->currentText.isEmpty() && cb->currentIcon.isNull();
            bool reverse = option->direction == Qt::RightToLeft;
981
            bool drawborder = !(widget && widget->property("hideborder").toBool());
982
            bool drawleftborder = (widget && widget->property("drawleftborder").toBool());
983
            bool alignarrow = !(widget && widget->property("alignarrow").toBool());
con's avatar
con committed
984

985
            if (drawborder) {
986
                drawButtonSeparator(painter, rect, reverse);
987
988
989
                if (drawleftborder)
                    drawButtonSeparator(painter, rect.adjusted(0, 0, -rect.width() + 2, 0), reverse);
            }
990

Jens Bache-Wiig's avatar
Jens Bache-Wiig committed
991
            QStyleOption toolbutton = *option;
Jens Bache-Wiig's avatar
Jens Bache-Wiig committed
992
993
            if (isEmpty)
                toolbutton.state &= ~(State_Enabled | State_Sunken);
994
            painter->save();
995
996
997
998
999
1000
            if (drawborder) {
                int leftClipAdjust = 0;
                if (drawleftborder)
                    leftClipAdjust = 2;
                painter->setClipRect(toolbutton.rect.adjusted(leftClipAdjust, 0, -2, 0));
            }
Jens Bache-Wiig's avatar
Jens Bache-Wiig committed
1001
            drawPrimitive(PE_PanelButtonTool, &toolbutton, painter, widget);
1002
            painter->restore();
con's avatar
con committed
1003
            // Draw arrow
1004
            int menuButtonWidth = 12;
con's avatar
con committed
1005
1006
            int left = !reverse ? rect.right() - menuButtonWidth : rect.left();
            int right = !reverse ? rect.right() : rect.left() + menuButtonWidth;
Jens Bache-Wiig's avatar
Jens Bache-Wiig committed
1007
            QRect arrowRect((left + right) / 2 + (reverse ? 6 : -6), rect.center().y() - 3, 9, 9);
1008
1009

            if (!alignarrow) {
1010
1011
1012
1013
1014
                int labelwidth = option->fontMetrics.width(cb->currentText);
                if (reverse)
                    arrowRect.moveLeft(qMax(rect.width() - labelwidth - menuButtonWidth - 2, 4));
                else
                    arrowRect.moveLeft(qMin(labelwidth + menuButtonWidth - 2, rect.width() - menuButtonWidth - 4));
1015
            }
con's avatar
con committed
1016
            if (option->state & State_On)
1017
1018
                arrowRect.translate(QProxyStyle::pixelMetric(PM_ButtonShiftHorizontal, option, widget),
                                    QProxyStyle::pixelMetric(PM_ButtonShiftVertical, option, widget));
Jens Bache-Wiig's avatar
Jens Bache-Wiig committed
1019

con's avatar
con committed
1020
1021
            QStyleOption arrowOpt = *option;
            arrowOpt.rect = arrowRect;
Jens Bache-Wiig's avatar
Jens Bache-Wiig committed
1022
1023
1024
            if (isEmpty)
                arrowOpt.state &= ~(State_Enabled | State_Sunken);

Jens Bache-Wiig's avatar
Jens Bache-Wiig committed
1025
1026
1027
1028
1029
1030
1031
1032
            if (styleHint(SH_ComboBox_Popup, option, widget)) {
                arrowOpt.rect.translate(0, -3);
                drawPrimitive(PE_IndicatorArrowUp, &arrowOpt, painter, widget);
                arrowOpt.rect.translate(0, 6);
                drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget);
            } else {
                drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget);
            }
1033

con's avatar
con committed
1034
1035
1036
            painter->restore();
        }
        break;
1037

con's avatar
con committed
1038
    default:
1039
        QProxyStyle::drawComplexControl(control, option, painter, widget);
con's avatar
con committed
1040
1041
1042
        break;
    }
}
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062

void ManhattanStyle::drawButtonSeparator(QPainter *painter, const QRect &rect, bool reverse) const
{
    QLinearGradient grad(rect.topRight(), rect.bottomRight());
    grad.setColorAt(0, QColor(255, 255, 255, 20));
    grad.setColorAt(0.4, QColor(255, 255, 255, 60));
    grad.setColorAt(0.7, QColor(255, 255, 255, 50));
    grad.setColorAt(1, QColor(255, 255, 255, 40));
    painter->setPen(QPen(grad, 0));
    painter->drawLine(rect.topRight(), rect.bottomRight());
    grad.setColorAt(0, QColor(0, 0, 0, 30));
    grad.setColorAt(0.4, QColor(0, 0, 0, 70));
    grad.setColorAt(0.7, QColor(0, 0, 0, 70));
    grad.setColorAt(1, QColor(0, 0, 0, 40));
    painter->setPen(QPen(grad, 0));
    if (!reverse)
       painter->drawLine(rect.topRight() - QPoint(1,0), rect.bottomRight() - QPoint(1,0));
    else
       painter->drawLine(rect.topLeft(), rect.bottomLeft());
 }