VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/include/VBoxVMListView.h@ 19149

Last change on this file since 19149 was 17412, checked in by vboxsync, 16 years ago

FE/Qt4: there is no os_unknown.png

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.1 KB
Line 
1/** @file
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
4 * VBoxVMItem, VBoxVMModel, VBoxVMListView, VBoxVMItemPainter class declarations
5 */
6
7/*
8 * Copyright (C) 2006-2008 Sun Microsystems, Inc.
9 *
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.
17 *
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.
21 */
22
23#ifndef __VBoxVMListView_h__
24#define __VBoxVMListView_h__
25
26#include "VBoxGlobal.h"
27#include "QIListView.h"
28
29/* Qt includes */
30#include <QAbstractListModel>
31#include <QDateTime>
32
33class VBoxSelectorWnd;
34
35class VBoxVMItem
36{
37public:
38
39 VBoxVMItem (const CMachine &aMachine);
40 virtual ~VBoxVMItem();
41
42 CMachine machine() const { return mMachine; }
43
44 QString name() const { return mName; }
45 QIcon osIcon() const { return mAccessible ? vboxGlobal().vmGuestOSTypeIcon (mOSTypeId) : QPixmap (":/os_other.png"); }
46 QUuid id() const { return mId; }
47
48 QString sessionStateName() const;
49 QIcon sessionStateIcon() const { return mAccessible ? vboxGlobal().toIcon (mState) : QPixmap (":/state_aborted_16px.png"); }
50
51 QString snapshotName() const { return mSnapshotName; }
52 ULONG snapshotCount() const { return mSnapshotCount; }
53
54 QString toolTipText() const;
55
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; }
60
61 bool recache();
62
63 bool canSwitchTo() const;
64 bool switchTo();
65
66private:
67
68 /* Private member vars */
69 CMachine mMachine;
70
71 /* Cached machine data (to minimize server requests) */
72 QUuid mId;
73 QString mSettingsFile;
74
75 bool mAccessible;
76 CVirtualBoxErrorInfo mAccessError;
77
78 QString mName;
79 QString mSnapshotName;
80 KMachineState mState;
81 QDateTime mLastStateChange;
82 KSessionState mSessionState;
83 QString mOSTypeId;
84 ULONG mSnapshotCount;
85
86 ULONG mPid;
87};
88
89/* Make the pointer of this class public to the QVariant framework */
90Q_DECLARE_METATYPE(VBoxVMItem *);
91
92class VBoxVMModel: public QAbstractListModel
93{
94 Q_OBJECT;
95
96public:
97 enum { SnapShotDisplayRole = Qt::UserRole,
98 SnapShotFontRole,
99 SessionStateDisplayRole,
100 SessionStateDecorationRole,
101 SessionStateFontRole,
102 VBoxVMItemPtrRole };
103
104 VBoxVMModel(QObject *aParent = 0)
105 :QAbstractListModel (aParent) {}
106
107 void addItem (VBoxVMItem *aItem);
108 void removeItem (VBoxVMItem *aItem);
109 void refreshItem (VBoxVMItem *aItem);
110
111 void itemChanged (VBoxVMItem *aItem);
112
113 void clear();
114
115 VBoxVMItem *itemById (const QUuid &aId) const;
116 VBoxVMItem *itemByRow (int aRow) const;
117 QModelIndex indexById (const QUuid &aId) const;
118
119 int rowById (const QUuid &aId) const;;
120
121 void sort (Qt::SortOrder aOrder = Qt::AscendingOrder) { sort (0, aOrder); }
122
123 /* The following are necessary model implementations */
124 void sort (int aColumn, Qt::SortOrder aOrder = Qt::AscendingOrder);
125
126 int rowCount (const QModelIndex &aParent = QModelIndex()) const;
127
128 QVariant data (const QModelIndex &aIndex, int aRole) const;
129 QVariant headerData (int aSection, Qt::Orientation aOrientation,
130 int aRole = Qt::DisplayRole) const;
131
132 bool removeRows (int aRow, int aCount, const QModelIndex &aParent = QModelIndex());
133
134private:
135 static bool VBoxVMItemNameCompareLessThan (VBoxVMItem* aItem1, VBoxVMItem* aItem2);
136 static bool VBoxVMItemNameCompareGreaterThan (VBoxVMItem* aItem1, VBoxVMItem* aItem2);
137
138 /* Private member vars */
139 QList<VBoxVMItem *> mVMItemList;
140};
141
142class VBoxVMListView: public QIListView
143{
144 Q_OBJECT;
145
146public:
147 VBoxVMListView (QWidget *aParent = 0);
148
149 void selectItemByRow (int row);
150 void selectItemById (const QUuid &aID);
151 void ensureSomeRowSelected (int aRowHint);
152 VBoxVMItem * selectedItem() const;
153
154 void ensureCurrentVisible();
155
156signals:
157 void currentChanged();
158 void activated();
159
160protected slots:
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);
164
165protected:
166 bool selectCurrent();
167};
168
169class VBoxVMItemPainter: public QIItemDelegate
170{
171public:
172 VBoxVMItemPainter (QObject *aParent = 0)
173 : QIItemDelegate (aParent), mMargin (8), mSpacing (mMargin * 3 / 2) {}
174
175 QSize sizeHint (const QStyleOptionViewItem &aOption,
176 const QModelIndex &aIndex) const;
177
178 void paint (QPainter *aPainter, const QStyleOptionViewItem &aOption,
179 const QModelIndex &aIndex) const;
180
181private:
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
184 {
185 if (!(aState & QStyle::State_Enabled))
186 return QIcon::Disabled;
187 if (aState & QStyle::State_Selected)
188 return QIcon::Selected;
189 return QIcon::Normal;
190 }
191 inline QIcon::State iconState (QStyle::State aState) const { return aState & QStyle::State_Open ? QIcon::On : QIcon::Off; }
192
193 QRect rect (const QStyleOptionViewItem &aOption,
194 const QModelIndex &aIndex, int aRole) const;
195
196 void calcLayout (const QModelIndex &aIndex,
197 QRect *aOSType, QRect *aVMName, QRect *aShot,
198 QRect *aStateIcon, QRect *aState) const;
199
200 /* Private member vars */
201 int mMargin;
202 int mSpacing;
203};
204
205#endif /* __VBoxVMListView_h__ */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette