~ubuntu-branches/ubuntu/trusty/virtualbox-lts-xenial/trusty-proposed

« back to all changes in this revision

Viewing changes to src/VBox/Frontends/VirtualBox/src/extensions/QIListView.cpp

  • Committer: Package Import Robot
  • Author(s): Gianfranco Costamagna
  • Date: 2016-02-23 14:28:26 UTC
  • Revision ID: package-import@ubuntu.com-20160223142826-bdu69el2z6wa2a44
Tags: upstream-4.3.36-dfsg
ImportĀ upstreamĀ versionĀ 4.3.36-dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: QIListView.cpp $ */
 
2
/** @file
 
3
 *
 
4
 * VBox frontends: Qt GUI ("VirtualBox"):
 
5
 * QIListView, QIItemDelegate class implementation
 
6
 */
 
7
 
 
8
/*
 
9
 * Copyright (C) 2006-2012 Oracle Corporation
 
10
 *
 
11
 * This file is part of VirtualBox Open Source Edition (OSE), as
 
12
 * available from http://www.virtualbox.org. This file is free software;
 
13
 * you can redistribute it and/or modify it under the terms of the GNU
 
14
 * General Public License (GPL) as published by the Free Software
 
15
 * Foundation, in version 2 as it comes in the "COPYING" file of the
 
16
 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
 
17
 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
 
18
 */
 
19
 
 
20
#if MAC_LEOPARD_STYLE
 
21
/* Qt includes: */
 
22
# include <QPainter>
 
23
# include <QApplication>
 
24
# include <qmacstyle_mac.h>
 
25
#endif /* MAC_LEOPARD_STYLE */
 
26
 
 
27
/* GUI includes: */
 
28
#include "QIListView.h"
 
29
 
 
30
QIListView::QIListView (QWidget *aParent /* = 0 */)
 
31
    :QListView (aParent)
 
32
{
 
33
    /* Track if the application lost the focus */
 
34
#if MAC_LEOPARD_STYLE
 
35
    connect (QCoreApplication::instance(), SIGNAL (focusChanged (QWidget *, QWidget *)),
 
36
             this, SLOT (focusChanged (QWidget *, QWidget *)));
 
37
    /* 1 pixel line frame */
 
38
    setMidLineWidth (1);
 
39
    setLineWidth (0);
 
40
    setFrameShape (QFrame::Box);
 
41
    focusChanged (NULL, qApp->focusWidget());
 
42
    /* Nesty hack to disable the focus rect on the list view. This interface
 
43
     * may change at any time! */
 
44
    static_cast<QMacStyle *> (style())->setFocusRectPolicy (this, QMacStyle::FocusDisabled);
 
45
#endif /* MAC_LEOPARD_STYLE */
 
46
}
 
47
 
 
48
void QIListView::focusChanged (QWidget * /* aOld */, QWidget *aNow)
 
49
{
 
50
#if MAC_LEOPARD_STYLE
 
51
    QColor bgColor (212, 221, 229);
 
52
    if (aNow == NULL)
 
53
        bgColor.setRgb (232, 232, 232);
 
54
    QPalette pal = viewport()->palette();
 
55
    pal.setColor (QPalette::Base, bgColor);
 
56
    viewport()->setPalette (pal);
 
57
    viewport()->setAutoFillBackground(true);
 
58
#else /* MAC_LEOPARD_STYLE */
 
59
    Q_UNUSED (aNow);
 
60
#endif /* MAC_LEOPARD_STYLE */
 
61
}
 
62
 
 
63
/* QIItemDelegate class */
 
64
 
 
65
void QIItemDelegate::drawBackground (QPainter *aPainter, const QStyleOptionViewItem &aOption,
 
66
                                     const QModelIndex &aIndex) const
 
67
{
 
68
#if MAC_LEOPARD_STYLE
 
69
    NOREF (aIndex);
 
70
    /* Macify for Leopard */
 
71
    if (aOption.state & QStyle::State_Selected)
 
72
    {
 
73
        /* Standard color for selected items and focus on the widget */
 
74
        QColor topLineColor (69, 128, 200);
 
75
        QColor topGradColor (92, 147, 214);
 
76
        QColor bottomGradColor (21, 83, 169);
 
77
        /* Color for selected items and no focus on the widget */
 
78
        if (QWidget *p = qobject_cast<QWidget *> (parent()))
 
79
            if (!p->hasFocus())
 
80
            {
 
81
                topLineColor.setRgb (145, 160, 192);
 
82
                topGradColor.setRgb (162, 177, 207);
 
83
                bottomGradColor.setRgb (110, 129, 169);
 
84
            }
 
85
        /* Color for selected items and no focus on the application at all */
 
86
        if (qApp->focusWidget() == NULL)
 
87
            {
 
88
                topLineColor.setRgb (151, 151, 151);
 
89
                topGradColor.setRgb (180, 180, 180);
 
90
                bottomGradColor.setRgb (137, 137, 137);
 
91
            }
 
92
        /* Paint the background */
 
93
        QRect r = aOption.rect;
 
94
        r.setTop (r.top() + 1);
 
95
        QLinearGradient linearGrad (QPointF(0, r.top()), QPointF(0, r.bottom()));
 
96
        linearGrad.setColorAt (0, topGradColor);
 
97
        linearGrad.setColorAt (1, bottomGradColor);
 
98
        aPainter->setPen (topLineColor);
 
99
        aPainter->drawLine (r.left(), r.top() - 1, r.right(), r.top() - 1);
 
100
        aPainter->fillRect (r, linearGrad);
 
101
    }
 
102
    else
 
103
    {
 
104
        /* Color for items and no focus on the application at all */
 
105
        QColor bgColor (212, 221, 229);
 
106
        if (qApp->focusWidget() == NULL)
 
107
            bgColor.setRgb (232, 232, 232);
 
108
        aPainter->fillRect(aOption.rect, bgColor);
 
109
    }
 
110
#else /* MAC_LEOPARD_STYLE */
 
111
    QItemDelegate::drawBackground (aPainter, aOption, aIndex);
 
112
#endif /* MAC_LEOPARD_STYLE */
 
113
}
 
114