VirtualBox

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

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

FE/Qt4: Cumulative fix for VBoxSelectorWnd & VBoxVMListView: minor fixes for system-tray feature (coding style, correct callers) & fix for context-menu request feature (correct policy and invoke method used).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.2 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 QAction* vmActionConfig() const { return vmConfigAction; }
70 QAction* vmActionDelete() const { return vmDeleteAction; }
71 QAction* vmActionStart() const { return vmStartAction; }
72 QAction* vmActionDiscard() const { return vmDiscardAction; }
73 QAction* vmActionPause() const { return vmPauseAction; }
74 QAction* vmActionRefresh() const { return vmRefreshAction; }
75 QAction* vmActionShowLogs() const { return vmShowLogsAction; }
76
77 QString toolTipText() const;
78
79 bool accessible() const { return mAccessible; }
80 bool running() const { return (sessionState() != KSessionState_Closed); }
81 const CVirtualBoxErrorInfo &accessError() const { return mAccessError; }
82 KMachineState state() const { return mState; }
83 KSessionState sessionState() const { return mSessionState; }
84
85 bool recache();
86
87 bool canSwitchTo() const;
88 bool switchTo();
89
90 void updateActions();
91
92private:
93
94 /* Private member vars */
95 VBoxSelectorWnd *mParent;
96 CMachine mMachine;
97
98 QAction *vmConfigAction;
99 QAction *vmDeleteAction;
100 QAction *vmStartAction;
101 QAction *vmDiscardAction;
102 QAction *vmPauseAction;
103 QAction *vmRefreshAction;
104 QAction *vmShowLogsAction;
105
106 /* Cached machine data (to minimize server requests) */
107 QUuid mId;
108 QString mSettingsFile;
109
110 bool mAccessible;
111 CVirtualBoxErrorInfo mAccessError;
112
113 QString mName;
114 QString mSnapshotName;
115 KMachineState mState;
116 QDateTime mLastStateChange;
117 KSessionState mSessionState;
118 QString mOSTypeId;
119 ULONG mSnapshotCount;
120
121 ULONG mPid;
122
123private slots:
124
125 void vmSettings();
126 void vmDelete();
127 void vmStart();
128 void vmDiscard();
129 void vmPause(bool aPause);
130 void vmRefresh();
131 void vmShowLogs();
132};
133
134/* Make the pointer of this class public to the QVariant framework */
135Q_DECLARE_METATYPE(VBoxVMItem *);
136
137class VBoxVMModel: public QAbstractListModel
138{
139 Q_OBJECT;
140
141public:
142 enum { SnapShotDisplayRole = Qt::UserRole,
143 SnapShotFontRole,
144 SessionStateDisplayRole,
145 SessionStateDecorationRole,
146 SessionStateFontRole,
147 VBoxVMItemPtrRole };
148
149 VBoxVMModel(QObject *aParent = 0)
150 :QAbstractListModel (aParent) {}
151
152 void addItem (VBoxVMItem *aItem);
153 void removeItem (VBoxVMItem *aItem);
154 void refreshItem (VBoxVMItem *aItem);
155
156 void itemChanged (VBoxVMItem *aItem);
157
158 void clear();
159
160 VBoxVMItem *itemById (const QUuid &aId) const;
161 VBoxVMItem *itemByRow (int aRow) const;
162 QModelIndex indexById (const QUuid &aId) const;
163
164 int rowById (const QUuid &aId) const;;
165
166 void sort (Qt::SortOrder aOrder = Qt::AscendingOrder) { sort (0, aOrder); }
167
168 /* The following are necessary model implementations */
169 void sort (int aColumn, Qt::SortOrder aOrder = Qt::AscendingOrder);
170
171 int rowCount (const QModelIndex &aParent = QModelIndex()) const;
172
173 QVariant data (const QModelIndex &aIndex, int aRole) const;
174 QVariant headerData (int aSection, Qt::Orientation aOrientation,
175 int aRole = Qt::DisplayRole) const;
176
177 bool removeRows (int aRow, int aCount, const QModelIndex &aParent = QModelIndex());
178
179private:
180 static bool VBoxVMItemNameCompareLessThan (VBoxVMItem* aItem1, VBoxVMItem* aItem2);
181 static bool VBoxVMItemNameCompareGreaterThan (VBoxVMItem* aItem1, VBoxVMItem* aItem2);
182
183 /* Private member vars */
184 QList<VBoxVMItem *> mVMItemList;
185};
186
187class VBoxVMListView: public QIListView
188{
189 Q_OBJECT;
190
191public:
192 VBoxVMListView (QWidget *aParent = 0);
193
194 void selectItemByRow (int row);
195 void selectItemById (const QUuid &aID);
196 void ensureSomeRowSelected (int aRowHint);
197 VBoxVMItem * selectedItem() const;
198
199 void ensureCurrentVisible();
200
201signals:
202 void currentChanged();
203 void activated();
204
205protected slots:
206 void selectionChanged (const QItemSelection &aSelected, const QItemSelection &aDeselected);
207 void currentChanged (const QModelIndex &aCurrent, const QModelIndex &aPrevious);
208 void dataChanged (const QModelIndex &aTopLeft, const QModelIndex &aBottomRight);
209
210protected:
211 bool selectCurrent();
212};
213
214class VBoxVMItemPainter: public QIItemDelegate
215{
216public:
217 VBoxVMItemPainter (QObject *aParent = 0)
218 : QIItemDelegate (aParent), mMargin (8), mSpacing (mMargin * 3 / 2) {}
219
220 QSize sizeHint (const QStyleOptionViewItem &aOption,
221 const QModelIndex &aIndex) const;
222
223 void paint (QPainter *aPainter, const QStyleOptionViewItem &aOption,
224 const QModelIndex &aIndex) const;
225
226private:
227 inline QFontMetrics fontMetric (const QModelIndex &aIndex, int aRole) const { return QFontMetrics (aIndex.data (aRole).value<QFont>()); }
228 inline QIcon::Mode iconMode (QStyle::State aState) const
229 {
230 if (!(aState & QStyle::State_Enabled))
231 return QIcon::Disabled;
232 if (aState & QStyle::State_Selected)
233 return QIcon::Selected;
234 return QIcon::Normal;
235 }
236 inline QIcon::State iconState (QStyle::State aState) const { return aState & QStyle::State_Open ? QIcon::On : QIcon::Off; }
237
238 QRect rect (const QStyleOptionViewItem &aOption,
239 const QModelIndex &aIndex, int aRole) const;
240
241 void calcLayout (const QModelIndex &aIndex,
242 QRect *aOSType, QRect *aVMName, QRect *aShot,
243 QRect *aStateIcon, QRect *aState) const;
244
245 /* Private member vars */
246 int mMargin;
247 int mSpacing;
248};
249
250#endif /* __VBoxVMListView_h__ */
Note: See TracBrowser for help on using the repository browser.

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