1 | /* $Id: QIListView.cpp 34064 2010-11-15 11:12:37Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
5 | * QIListView, QIItemDelegate class implementation
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2006-2008 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 | #include "QIListView.h"
|
---|
21 | #include "VBoxDefs.h"
|
---|
22 |
|
---|
23 | #if MAC_LEOPARD_STYLE
|
---|
24 | /* Qt includes */
|
---|
25 | # include <QPainter>
|
---|
26 | # include <QApplication>
|
---|
27 | # include <qmacstyle_mac.h>
|
---|
28 | #endif /* MAC_LEOPARD_STYLE */
|
---|
29 |
|
---|
30 |
|
---|
31 | /* QIListView class */
|
---|
32 |
|
---|
33 | QIListView::QIListView (QWidget *aParent /* = 0 */)
|
---|
34 | :QListView (aParent)
|
---|
35 | {
|
---|
36 | /* Track if the application lost the focus */
|
---|
37 | #if MAC_LEOPARD_STYLE
|
---|
38 | connect (QCoreApplication::instance(), SIGNAL (focusChanged (QWidget *, QWidget *)),
|
---|
39 | this, SLOT (focusChanged (QWidget *, QWidget *)));
|
---|
40 | /* 1 pixel line frame */
|
---|
41 | setMidLineWidth (1);
|
---|
42 | setLineWidth (0);
|
---|
43 | setFrameShape (QFrame::Box);
|
---|
44 | focusChanged (NULL, qApp->focusWidget());
|
---|
45 | /* Nesty hack to disable the focus rect on the list view. This interface
|
---|
46 | * may change at any time! */
|
---|
47 | static_cast<QMacStyle *> (style())->setFocusRectPolicy (this, QMacStyle::FocusDisabled);
|
---|
48 | #endif /* MAC_LEOPARD_STYLE */
|
---|
49 | }
|
---|
50 |
|
---|
51 | void QIListView::focusChanged (QWidget * /* aOld */, QWidget *aNow)
|
---|
52 | {
|
---|
53 | #if MAC_LEOPARD_STYLE
|
---|
54 | QColor bgColor (212, 221, 229);
|
---|
55 | if (aNow == NULL)
|
---|
56 | bgColor.setRgb (232, 232, 232);
|
---|
57 | QPalette pal = viewport()->palette();
|
---|
58 | pal.setColor (QPalette::Base, bgColor);
|
---|
59 | viewport()->setPalette (pal);
|
---|
60 | viewport()->setAutoFillBackground(true);
|
---|
61 | #else /* MAC_LEOPARD_STYLE */
|
---|
62 | Q_UNUSED (aNow);
|
---|
63 | #endif /* MAC_LEOPARD_STYLE */
|
---|
64 | }
|
---|
65 |
|
---|
66 | /* QIItemDelegate class */
|
---|
67 |
|
---|
68 | void QIItemDelegate::drawBackground (QPainter *aPainter, const QStyleOptionViewItem &aOption,
|
---|
69 | const QModelIndex &aIndex) const
|
---|
70 | {
|
---|
71 | #if MAC_LEOPARD_STYLE
|
---|
72 | NOREF (aIndex);
|
---|
73 | /* Macify for Leopard */
|
---|
74 | if (aOption.state & QStyle::State_Selected)
|
---|
75 | {
|
---|
76 | /* Standard color for selected items and focus on the widget */
|
---|
77 | QColor topLineColor (69, 128, 200);
|
---|
78 | QColor topGradColor (92, 147, 214);
|
---|
79 | QColor bottomGradColor (21, 83, 169);
|
---|
80 | /* Color for selected items and no focus on the widget */
|
---|
81 | if (QWidget *p = qobject_cast<QWidget *> (parent()))
|
---|
82 | if (!p->hasFocus())
|
---|
83 | {
|
---|
84 | topLineColor.setRgb (145, 160, 192);
|
---|
85 | topGradColor.setRgb (162, 177, 207);
|
---|
86 | bottomGradColor.setRgb (110, 129, 169);
|
---|
87 | }
|
---|
88 | /* Color for selected items and no focus on the application at all */
|
---|
89 | if (qApp->focusWidget() == NULL)
|
---|
90 | {
|
---|
91 | topLineColor.setRgb (151, 151, 151);
|
---|
92 | topGradColor.setRgb (180, 180, 180);
|
---|
93 | bottomGradColor.setRgb (137, 137, 137);
|
---|
94 | }
|
---|
95 | /* Paint the background */
|
---|
96 | QRect r = aOption.rect;
|
---|
97 | r.setTop (r.top() + 1);
|
---|
98 | QLinearGradient linearGrad (QPointF(0, r.top()), QPointF(0, r.bottom()));
|
---|
99 | linearGrad.setColorAt (0, topGradColor);
|
---|
100 | linearGrad.setColorAt (1, bottomGradColor);
|
---|
101 | aPainter->setPen (topLineColor);
|
---|
102 | aPainter->drawLine (r.left(), r.top() - 1, r.right(), r.top() - 1);
|
---|
103 | aPainter->fillRect (r, linearGrad);
|
---|
104 | }else
|
---|
105 | {
|
---|
106 | /* Color for items and no focus on the application at all */
|
---|
107 | QColor bgColor (212, 221, 229);
|
---|
108 | if (qApp->focusWidget() == NULL)
|
---|
109 | bgColor.setRgb (232, 232, 232);
|
---|
110 | aPainter->fillRect(aOption.rect, bgColor);
|
---|
111 | }
|
---|
112 | #else /* MAC_LEOPARD_STYLE */
|
---|
113 | QItemDelegate::drawBackground (aPainter, aOption, aIndex);
|
---|
114 | #endif /* MAC_LEOPARD_STYLE */
|
---|
115 | }
|
---|
116 |
|
---|