VirtualBox

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

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

Backed out 32068 - see comment #163 in bug #2664.

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