1
/* $Id: QIListView.cpp $ */
4
* VBox frontends: Qt GUI ("VirtualBox"):
5
* QIListView, QIItemDelegate class implementation
9
* Copyright (C) 2006-2012 Oracle Corporation
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.
23
# include <QApplication>
24
# include <qmacstyle_mac.h>
25
#endif /* MAC_LEOPARD_STYLE */
28
#include "QIListView.h"
30
QIListView::QIListView (QWidget *aParent /* = 0 */)
33
/* Track if the application lost the focus */
35
connect (QCoreApplication::instance(), SIGNAL (focusChanged (QWidget *, QWidget *)),
36
this, SLOT (focusChanged (QWidget *, QWidget *)));
37
/* 1 pixel line frame */
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 */
48
void QIListView::focusChanged (QWidget * /* aOld */, QWidget *aNow)
51
QColor bgColor (212, 221, 229);
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 */
60
#endif /* MAC_LEOPARD_STYLE */
63
/* QIItemDelegate class */
65
void QIItemDelegate::drawBackground (QPainter *aPainter, const QStyleOptionViewItem &aOption,
66
const QModelIndex &aIndex) const
70
/* Macify for Leopard */
71
if (aOption.state & QStyle::State_Selected)
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()))
81
topLineColor.setRgb (145, 160, 192);
82
topGradColor.setRgb (162, 177, 207);
83
bottomGradColor.setRgb (110, 129, 169);
85
/* Color for selected items and no focus on the application at all */
86
if (qApp->focusWidget() == NULL)
88
topLineColor.setRgb (151, 151, 151);
89
topGradColor.setRgb (180, 180, 180);
90
bottomGradColor.setRgb (137, 137, 137);
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);
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);
110
#else /* MAC_LEOPARD_STYLE */
111
QItemDelegate::drawBackground (aPainter, aOption, aIndex);
112
#endif /* MAC_LEOPARD_STYLE */