VirtualBox

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

Last change on this file since 13790 was 13790, checked in by vboxsync, 17 years ago

Fe/Qt4: Added first systray support (under development, compile with VBOX_GUI_WITH_SYSTRAY in VirtualBox4_DEFS).

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