QIListView.cpp revision 8e0c2ca3abd721979958f95b9af73b60665478c8
6646N/A/** @file
6646N/A *
6646N/A * VBox frontends: Qt GUI ("VirtualBox"):
6646N/A * QIListView, QIItemDelegate class implementation
6646N/A */
6646N/A
6646N/A/*
6646N/A * Copyright (C) 2006-2008 Sun Microsystems, Inc.
6646N/A *
6646N/A * This file is part of VirtualBox Open Source Edition (OSE), as
6646N/A * available from http://www.virtualbox.org. This file is free software;
6646N/A * you can redistribute it and/or modify it under the terms of the GNU
6646N/A * General Public License (GPL) as published by the Free Software
6646N/A * Foundation, in version 2 as it comes in the "COPYING" file of the
6646N/A * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
6646N/A * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
6646N/A *
6646N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
6646N/A * Clara, CA 95054 USA or visit http://www.sun.com if you need
6646N/A * additional information or have any questions.
6646N/A */
6646N/A
6646N/A#include "QIListView.h"
6646N/A#include "VBoxDefs.h"
6646N/A
6646N/A#if MAC_LEOPARD_STYLE
6646N/A/* Qt includes */
6646N/A# include <QPainter>
6646N/A# include <QApplication>
6646N/A# include <qmacstyle_mac.h>
6646N/A#endif /* MAC_LEOPARD_STYLE */
6646N/A
6646N/A
6646N/A/* VBoxVMListView class */
6646N/A
6646N/AQIListView::QIListView (QWidget *aParent /* = 0 */)
6646N/A :QListView (aParent)
6646N/A{
6646N/A /* Track if the application lost the focus */
6646N/A#if MAC_LEOPARD_STYLE
6646N/A connect (QCoreApplication::instance(), SIGNAL (focusChanged (QWidget *, QWidget *)),
6646N/A this, SLOT (focusChanged (QWidget *, QWidget *)));
6646N/A /* 1 pixel line frame */
setMidLineWidth (1);
setLineWidth (0);
setFrameShape (QFrame::Box);
focusChanged (NULL, this);
/* Nesty hack to disable the focus rect on the list view. This interface
* may change at any time! */
static_cast<QMacStyle *> (style())->setFocusRectPolicy (this, QMacStyle::FocusDisabled);
#endif /* MAC_LEOPARD_STYLE */
}
void QIListView::focusChanged (QWidget * /* aOld */, QWidget *aNow)
{
#if MAC_LEOPARD_STYLE
QColor bgColor (212, 221, 229);
if (aNow == NULL)
bgColor.setRgb (232, 232, 232);
QPalette pal = viewport()->palette();
pal.setColor (QPalette::Base, bgColor);
viewport()->setPalette (pal);
viewport()->setAutoFillBackground (true);
#else /* MAC_LEOPARD_STYLE */
Q_UNUSED (aNow);
#endif /* MAC_LEOPARD_STYLE */
}
/* VBoxVMItemPainter class */
void QIItemDelegate::drawBackground (QPainter *aPainter, const QStyleOptionViewItem &aOption,
const QModelIndex &aIndex) const
{
#if MAC_LEOPARD_STYLE
NOREF (aIndex);
/* Macify for Leopard */
if (aOption.state & QStyle::State_Selected)
{
/* Standard color for selected items and focus on the widget */
QColor topLineColor (69, 128, 200);
QColor topGradColor (92, 147, 214);
QColor bottomGradColor (21, 83, 169);
/* Color for selected items and no focus on the widget */
if (QWidget *p = qobject_cast<QWidget *> (parent()))
if (!p->hasFocus())
{
topLineColor.setRgb (145, 160, 192);
topGradColor.setRgb (162, 177, 207);
bottomGradColor.setRgb (110, 129, 169);
}
/* Color for selected items and no focus on the application at all */
if (qApp->focusWidget() == NULL)
{
topLineColor.setRgb (151, 151, 151);
topGradColor.setRgb (180, 180, 180);
bottomGradColor.setRgb (137, 137, 137);
}
/* Paint the background */
QRect r = aOption.rect;
r.setTop (r.top() + 1);
QLinearGradient linearGrad (QPointF(0, r.top()), QPointF(0, r.bottom()));
linearGrad.setColorAt (0, topGradColor);
linearGrad.setColorAt (1, bottomGradColor);
aPainter->setPen (topLineColor);
aPainter->drawLine (r.left(), r.top() - 1, r.right(), r.top() - 1);
aPainter->fillRect (r, linearGrad);
}
#else /* MAC_LEOPARD_STYLE */
QItemDelegate::drawBackground (aPainter, aOption, aIndex);
#endif /* MAC_LEOPARD_STYLE */
}