VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox4/include/VBoxVMListView.h@ 14296

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

Fe/Qt4: Systray: Restructured code.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.4 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 : public QObject
36{
37 Q_OBJECT;
38
39public:
40
41 enum Action
42 {
43 Config = 0,
44 Delete,
45 Start,
46 Discard,
47 Pause,
48 Refresh,
49 ShowLogs
50 };
51
52public:
53
54 VBoxVMItem (const CMachine &aMachine, VBoxSelectorWnd *pParent);
55 virtual ~VBoxVMItem();
56
57 CMachine machine() const { return mMachine; }
58
59 QString name() const { return mName; }
60 QIcon osIcon() const { return mAccessible ? vboxGlobal().vmGuestOSTypeIcon (mOSTypeId) :QPixmap (":/os_unknown.png"); }
61 QUuid id() const { return mId; }
62
63 QString sessionStateName() const;
64 QIcon sessionStateIcon() const { return mAccessible ? vboxGlobal().toIcon (mState) : QPixmap (":/state_aborted_16px.png"); }
65
66 QString snapshotName() const { return mSnapshotName; }
67 ULONG snapshotCount() const { return mSnapshotCount; }
68
69 QString toolTipText() const;
70
71 bool accessible() const { return mAccessible; }
72 bool running() const { return (sessionState() != KSessionState_Closed); }
73 const CVirtualBoxErrorInfo &accessError() const { return mAccessError; }
74 KMachineState state() const { return mState; }
75 KSessionState sessionState() const { return mSessionState; }
76
77 bool recache();
78
79 bool canSwitchTo() const;
80 bool switchTo();
81
82private:
83
84 /* Private member vars */
85 VBoxSelectorWnd *mParent;
86 CMachine mMachine;
87
88 /* Cached machine data (to minimize server requests) */
89 QUuid mId;
90 QString mSettingsFile;
91
92 bool mAccessible;
93 CVirtualBoxErrorInfo mAccessError;
94
95 QString mName;
96 QString mSnapshotName;
97 KMachineState mState;
98 QDateTime mLastStateChange;
99 KSessionState mSessionState;
100 QString mOSTypeId;
101 ULONG mSnapshotCount;
102
103 ULONG mPid;
104};
105
106/* Make the pointer of this class public to the QVariant framework */
107Q_DECLARE_METATYPE(VBoxVMItem *);
108
109class VBoxVMModel: public QAbstractListModel
110{
111 Q_OBJECT;
112
113public:
114 enum { SnapShotDisplayRole = Qt::UserRole,
115 SnapShotFontRole,
116 SessionStateDisplayRole,
117 SessionStateDecorationRole,
118 SessionStateFontRole,
119 VBoxVMItemPtrRole };
120
121 VBoxVMModel(QObject *aParent = 0)
122 :QAbstractListModel (aParent) {}
123
124 void addItem (VBoxVMItem *aItem);
125 void removeItem (VBoxVMItem *aItem);
126 void refreshItem (VBoxVMItem *aItem);
127
128 void itemChanged (VBoxVMItem *aItem);
129
130 void clear();
131
132 VBoxVMItem *itemById (const QUuid &aId) const;
133 VBoxVMItem *itemByRow (int aRow) const;
134 QModelIndex indexById (const QUuid &aId) const;
135
136 int rowById (const QUuid &aId) const;;
137
138 void sort (Qt::SortOrder aOrder = Qt::AscendingOrder) { sort (0, aOrder); }
139
140 /* The following are necessary model implementations */
141 void sort (int aColumn, Qt::SortOrder aOrder = Qt::AscendingOrder);
142
143 int rowCount (const QModelIndex &aParent = QModelIndex()) const;
144
145 QVariant data (const QModelIndex &aIndex, int aRole) const;
146 QVariant headerData (int aSection, Qt::Orientation aOrientation,
147 int aRole = Qt::DisplayRole) const;
148
149 bool removeRows (int aRow, int aCount, const QModelIndex &aParent = QModelIndex());
150
151private:
152 static bool VBoxVMItemNameCompareLessThan (VBoxVMItem* aItem1, VBoxVMItem* aItem2);
153 static bool VBoxVMItemNameCompareGreaterThan (VBoxVMItem* aItem1, VBoxVMItem* aItem2);
154
155 /* Private member vars */
156 QList<VBoxVMItem *> mVMItemList;
157};
158
159class VBoxVMListView: public QIListView
160{
161 Q_OBJECT;
162
163public:
164 VBoxVMListView (QWidget *aParent = 0);
165
166 void selectItemByRow (int row);
167 void selectItemById (const QUuid &aID);
168 void ensureSomeRowSelected (int aRowHint);
169 VBoxVMItem * selectedItem() const;
170
171 void ensureCurrentVisible();
172
173signals:
174 void currentChanged();
175 void activated();
176
177protected slots:
178 void selectionChanged (const QItemSelection &aSelected, const QItemSelection &aDeselected);
179 void currentChanged (const QModelIndex &aCurrent, const QModelIndex &aPrevious);
180 void dataChanged (const QModelIndex &aTopLeft, const QModelIndex &aBottomRight);
181
182protected:
183 bool selectCurrent();
184};
185
186class VBoxVMItemPainter: public QIItemDelegate
187{
188public:
189 VBoxVMItemPainter (QObject *aParent = 0)
190 : QIItemDelegate (aParent), mMargin (8), mSpacing (mMargin * 3 / 2) {}
191
192 QSize sizeHint (const QStyleOptionViewItem &aOption,
193 const QModelIndex &aIndex) const;
194
195 void paint (QPainter *aPainter, const QStyleOptionViewItem &aOption,
196 const QModelIndex &aIndex) const;
197
198private:
199 inline QFontMetrics fontMetric (const QModelIndex &aIndex, int aRole) const { return QFontMetrics (aIndex.data (aRole).value<QFont>()); }
200 inline QIcon::Mode iconMode (QStyle::State aState) const
201 {
202 if (!(aState & QStyle::State_Enabled))
203 return QIcon::Disabled;
204 if (aState & QStyle::State_Selected)
205 return QIcon::Selected;
206 return QIcon::Normal;
207 }
208 inline QIcon::State iconState (QStyle::State aState) const { return aState & QStyle::State_Open ? QIcon::On : QIcon::Off; }
209
210 QRect rect (const QStyleOptionViewItem &aOption,
211 const QModelIndex &aIndex, int aRole) const;
212
213 void calcLayout (const QModelIndex &aIndex,
214 QRect *aOSType, QRect *aVMName, QRect *aShot,
215 QRect *aStateIcon, QRect *aState) const;
216
217 /* Private member vars */
218 int mMargin;
219 int mSpacing;
220};
221
222#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