3
* VBox frontends: Qt GUI ("VirtualBox"):
4
* VBoxVMItem, VBoxVMModel, VBoxVMListView, VBoxVMItemPainter class declarations
8
* Copyright (C) 2006-2008 Sun Microsystems, Inc.
10
* This file is part of VirtualBox Open Source Edition (OSE), as
11
* available from http://www.virtualbox.org. This file is free software;
12
* you can redistribute it and/or modify it under the terms of the GNU
13
* General Public License (GPL) as published by the Free Software
14
* Foundation, in version 2 as it comes in the "COPYING" file of the
15
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
19
* Clara, CA 95054 USA or visit http://www.sun.com if you need
20
* additional information or have any questions.
23
#ifndef __VBoxVMListView_h__
24
#define __VBoxVMListView_h__
26
#include "VBoxGlobal.h"
27
#include "QIListView.h"
30
#include <QAbstractListModel>
33
class VBoxSelectorWnd;
39
VBoxVMItem (const CMachine &aMachine);
40
virtual ~VBoxVMItem();
42
CMachine machine() const { return mMachine; }
44
QString name() const { return mName; }
45
QIcon osIcon() const { return mAccessible ? vboxGlobal().vmGuestOSTypeIcon (mOSTypeId) : QPixmap (":/os_other.png"); }
46
QString id() const { return mId; }
48
QString sessionStateName() const;
49
QIcon sessionStateIcon() const { return mAccessible ? vboxGlobal().toIcon (mState) : QPixmap (":/state_aborted_16px.png"); }
51
QString snapshotName() const { return mSnapshotName; }
52
ULONG snapshotCount() const { return mSnapshotCount; }
54
QString toolTipText() const;
56
bool accessible() const { return mAccessible; }
57
const CVirtualBoxErrorInfo &accessError() const { return mAccessError; }
58
KMachineState state() const { return mState; }
59
KSessionState sessionState() const { return mSessionState; }
63
bool canSwitchTo() const;
68
/* Private member vars */
71
/* Cached machine data (to minimize server requests) */
73
QString mSettingsFile;
76
CVirtualBoxErrorInfo mAccessError;
79
QString mSnapshotName;
81
QDateTime mLastStateChange;
82
KSessionState mSessionState;
89
/* Make the pointer of this class public to the QVariant framework */
90
Q_DECLARE_METATYPE(VBoxVMItem *);
92
class VBoxVMModel: public QAbstractListModel
97
enum { SnapShotDisplayRole = Qt::UserRole,
99
SessionStateDisplayRole,
100
SessionStateDecorationRole,
101
SessionStateFontRole,
104
VBoxVMModel(QObject *aParent = 0)
105
:QAbstractListModel (aParent) {}
107
void addItem (VBoxVMItem *aItem);
108
void removeItem (VBoxVMItem *aItem);
109
void refreshItem (VBoxVMItem *aItem);
111
void itemChanged (VBoxVMItem *aItem);
115
VBoxVMItem *itemById (const QString &aId) const;
116
VBoxVMItem *itemByRow (int aRow) const;
117
QModelIndex indexById (const QString &aId) const;
119
int rowById (const QString &aId) const;;
121
void sort (Qt::SortOrder aOrder = Qt::AscendingOrder) { sort (0, aOrder); }
123
/* The following are necessary model implementations */
124
void sort (int aColumn, Qt::SortOrder aOrder = Qt::AscendingOrder);
126
int rowCount (const QModelIndex &aParent = QModelIndex()) const;
128
QVariant data (const QModelIndex &aIndex, int aRole) const;
129
QVariant headerData (int aSection, Qt::Orientation aOrientation,
130
int aRole = Qt::DisplayRole) const;
132
bool removeRows (int aRow, int aCount, const QModelIndex &aParent = QModelIndex());
135
static bool VBoxVMItemNameCompareLessThan (VBoxVMItem* aItem1, VBoxVMItem* aItem2);
136
static bool VBoxVMItemNameCompareGreaterThan (VBoxVMItem* aItem1, VBoxVMItem* aItem2);
138
/* Private member vars */
139
QList<VBoxVMItem *> mVMItemList;
142
class VBoxVMListView: public QIListView
147
VBoxVMListView (QWidget *aParent = 0);
149
void selectItemByRow (int row);
150
void selectItemById (const QString &aID);
151
void ensureSomeRowSelected (int aRowHint);
152
VBoxVMItem * selectedItem() const;
154
void ensureCurrentVisible();
157
void currentChanged();
161
void selectionChanged (const QItemSelection &aSelected, const QItemSelection &aDeselected);
162
void currentChanged (const QModelIndex &aCurrent, const QModelIndex &aPrevious);
163
void dataChanged (const QModelIndex &aTopLeft, const QModelIndex &aBottomRight);
166
bool selectCurrent();
169
class VBoxVMItemPainter: public QIItemDelegate
172
VBoxVMItemPainter (QObject *aParent = 0)
173
: QIItemDelegate (aParent), mMargin (8), mSpacing (mMargin * 3 / 2) {}
175
QSize sizeHint (const QStyleOptionViewItem &aOption,
176
const QModelIndex &aIndex) const;
178
void paint (QPainter *aPainter, const QStyleOptionViewItem &aOption,
179
const QModelIndex &aIndex) const;
182
inline QFontMetrics fontMetric (const QModelIndex &aIndex, int aRole) const { return QFontMetrics (aIndex.data (aRole).value<QFont>()); }
183
inline QIcon::Mode iconMode (QStyle::State aState) const
185
if (!(aState & QStyle::State_Enabled))
186
return QIcon::Disabled;
187
if (aState & QStyle::State_Selected)
188
return QIcon::Selected;
189
return QIcon::Normal;
191
inline QIcon::State iconState (QStyle::State aState) const { return aState & QStyle::State_Open ? QIcon::On : QIcon::Off; }
193
QRect rect (const QStyleOptionViewItem &aOption,
194
const QModelIndex &aIndex, int aRole) const;
196
void calcLayout (const QModelIndex &aIndex,
197
QRect *aOSType, QRect *aVMName, QRect *aShot,
198
QRect *aStateIcon, QRect *aState) const;
200
/* Private member vars */
205
#endif /* __VBoxVMListView_h__ */