VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox4/include/VBoxVMSettingsHD.h@ 11968

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

Fe/Qt4: Fix Hard Disk UI issues: restoring edit-state of HD attachment table when getting focus, re-activating table (alt-tab), fixing F2 key functionality.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 8.2 KB
Line 
1/** @file
2 *
3 * VBox frontends: Qt4 GUI ("VirtualBox"):
4 * VBoxVMSettingsHD class declaration
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 __VBoxVMSettingsHD_h__
24#define __VBoxVMSettingsHD_h__
25
26#include "VBoxSettingsPage.h"
27#include "VBoxVMSettingsHD.gen.h"
28#include "COMDefs.h"
29#include "VBoxMediaComboBox.h"
30
31#include <QComboBox>
32
33/** Register type to store slot data */
34class HDSltValue
35{
36public:
37 HDSltValue()
38 : name (QString::null), bus (KStorageBus_Null)
39 , channel (0), device (0) {}
40 HDSltValue (const QString &aName, KStorageBus aBus,
41 LONG aChannel, LONG aDevice)
42 : name (aName), bus (aBus)
43 , channel (aChannel), device (aDevice) {}
44 HDSltValue (const HDSltValue &aOther)
45 : name (aOther.name), bus (aOther.bus)
46 , channel (aOther.channel), device (aOther.device) {}
47
48 HDSltValue& operator= (const HDSltValue &aOther)
49 {
50 name = aOther.name;
51 bus = aOther.bus;
52 channel = aOther.channel;
53 device = aOther.device;
54 return *this;
55 }
56
57 bool operator== (const HDSltValue &aOther)
58 {
59 return name == aOther.name &&
60 bus == aOther.bus &&
61 channel == aOther.channel &&
62 device == aOther.device;
63 }
64
65 bool operator!= (const HDSltValue &aOther)
66 {
67 return ! (*this == aOther);
68 }
69
70 QString name;
71 KStorageBus bus;
72 LONG channel;
73 LONG device;
74};
75Q_DECLARE_METATYPE (HDSltValue);
76
77/** Register type to store vdi data */
78class HDVdiValue
79{
80public:
81 HDVdiValue()
82 : name (QString::null), id (QUuid()) {}
83 HDVdiValue (const QString &aName, const QUuid &aId)
84 : name (aName), id (aId) {}
85 HDVdiValue (const HDVdiValue &aOther)
86 : name (aOther.name), id (aOther.id) {}
87
88 HDVdiValue& operator= (const HDVdiValue &aOther)
89 {
90 name = aOther.name;
91 id = aOther.id;
92 return *this;
93 }
94
95 bool operator== (const HDVdiValue &aOther)
96 {
97 return name == aOther.name &&
98 id == aOther.id;
99 }
100
101 bool operator!= (const HDVdiValue &aOther)
102 {
103 return ! (*this == aOther);
104 }
105
106 QString name;
107 QUuid id;
108};
109Q_DECLARE_METATYPE (HDVdiValue);
110
111/** Declare type to store both slt&vdi data */
112class HDValue
113{
114public:
115 HDValue (HDSltValue aSlt, HDVdiValue aVdi)
116 : slt (aSlt), vdi (aVdi) {}
117
118 /* Define sorting rules */
119 bool operator< (const HDValue &aOther) const
120 {
121 return slt.bus < aOther.slt.bus ||
122 (slt.bus == aOther.slt.bus && slt.channel < aOther.slt.channel) ||
123 (slt.bus == aOther.slt.bus && slt.channel == aOther.slt.channel && slt.device < aOther.slt.device);
124 }
125
126 HDSltValue slt;
127 HDVdiValue vdi;
128};
129
130/** QAbstractTableModel class reimplementation to feat slot/vdi
131 * selection mechanism */
132class HDItemsModel : public QAbstractTableModel
133{
134 Q_OBJECT;
135
136public:
137
138 HDItemsModel (QObject *aParent, int aSltId, int aVdiId)
139 : QAbstractTableModel (aParent)
140 , mSltId (aSltId), mVdiId (aVdiId) {}
141
142 int columnCount (const QModelIndex &aParent = QModelIndex()) const
143 { NOREF (aParent); return 2; }
144 int rowCount (const QModelIndex &aParent = QModelIndex()) const
145 { NOREF (aParent); return mSltList.count() + 1; }
146 Qt::ItemFlags flags (const QModelIndex &aIndex) const;
147
148 QVariant data (const QModelIndex &aIndex,
149 int aRole = Qt::DisplayRole) const;
150 bool setData (const QModelIndex &aIndex,
151 const QVariant &aValue,
152 int aRole = Qt::EditRole);
153 QVariant headerData (int aSection,
154 Qt::Orientation aOrientation,
155 int aRole = Qt::DisplayRole) const;
156
157 void addItem (const HDSltValue &aSlt = HDSltValue(),
158 const HDVdiValue &aVdi = HDVdiValue());
159 void delItem (int aIndex);
160
161 const QList<HDSltValue>& slotsList() { return mSltList; }
162 const QList<HDVdiValue>& vdiList() { return mVdiList; }
163 QList<HDValue> fullList (bool aSorted = true);
164
165 void removeSata();
166
167private:
168
169 QList<HDSltValue> mSltList;
170 QList<HDVdiValue> mVdiList;
171 int mSltId;
172 int mVdiId;
173};
174
175/** QComboBox class reimplementation used as editor for hd slot */
176class HDSltEditor : public QComboBox
177{
178 Q_OBJECT;
179 Q_PROPERTY (QVariant slot READ slot WRITE setSlot USER true);
180
181public:
182
183 HDSltEditor (QWidget *aParent);
184
185 QVariant slot() const;
186 void setSlot (QVariant aSlot);
187
188signals:
189
190 void readyToCommit (QWidget *aThis);
191
192private slots:
193
194 void onActivate();
195
196private:
197
198 void keyPressEvent (QKeyEvent *aEvent);
199 void populate (const HDSltValue &aIncluding);
200
201 QList<HDSltValue> mList;
202};
203
204/** VBoxMediaComboBox class reimplementation used as editor for hd vdi */
205class HDVdiEditor : public VBoxMediaComboBox
206{
207 Q_OBJECT;
208 Q_PROPERTY (QVariant vdi READ vdi WRITE setVdi USER true);
209
210public:
211
212 HDVdiEditor (QWidget *aParent);
213 ~HDVdiEditor();
214
215 QVariant vdi() const;
216 void setVdi (QVariant aVdi);
217
218 void tryToChooseUniqueVdi (QList<HDVdiValue> &aList);
219
220 static HDVdiEditor* activeEditor();
221
222signals:
223
224 void readyToCommit (QWidget *aThis);
225
226private slots:
227
228 void onActivate();
229
230private:
231
232 void keyPressEvent (QKeyEvent *aEvent);
233
234 static HDVdiEditor *mInstance;
235};
236
237/** Singleton QObject class reimplementation to use for making
238 * selected IDE & SATA slots unique */
239class HDSlotUniquizer : public QObject
240{
241 Q_OBJECT;
242
243public:
244
245 static HDSlotUniquizer* instance (QWidget *aParent = 0,
246 HDItemsModel *aWatched = 0,
247 const CMachine &aMachine = CMachine());
248
249 QList<HDSltValue> list (const HDSltValue &aIncluding, bool aFilter = true);
250
251 int sataCount() { return mSataCount; }
252 void setSataCount (int aSataCount)
253 {
254 mSataCount = aSataCount;
255 makeSATAList();
256 }
257
258 const CMachine& machine() const { return mMachine; }
259
260protected:
261
262 HDSlotUniquizer (QWidget *aParent, HDItemsModel *aWatched,
263 const CMachine &aMachine);
264 virtual ~HDSlotUniquizer();
265
266private:
267
268 void makeIDEList();
269 void makeSATAList();
270
271 static HDSlotUniquizer *mInstance;
272
273 int mSataCount;
274 HDItemsModel *mModel;
275 QList<HDSltValue> mIDEList;
276 QList<HDSltValue> mSATAList;
277 const CMachine &mMachine;
278};
279
280/** QWidget class reimplementation used as hard disks settings */
281class VBoxVMSettingsHD : public VBoxSettingsPage,
282 public Ui::VBoxVMSettingsHD
283{
284 Q_OBJECT;
285
286public:
287
288 VBoxVMSettingsHD();
289
290signals:
291
292 void signalToCloseEditor (QWidget *aEditor,
293 QAbstractItemDelegate::EndEditHint aCloseHint);
294 void hdChanged();
295
296protected:
297
298 void getFrom (const CMachine &aMachine);
299 void putBackTo();
300
301 void setValidator (QIWidgetValidator *aVal);
302 bool revalidate (QString &aWarning, QString &aTitle);
303
304 void setOrderAfter (QWidget *aWidget);
305
306 void retranslateUi();
307
308private slots:
309
310 void newClicked();
311 void delClicked();
312 void vdmClicked();
313
314 void onCurrentChanged (const QModelIndex &aIndex);
315 void cbSATAToggled (int);
316 void onMediaRemoved (VBoxDefs::DiskType, const QUuid &);
317
318private:
319
320 bool eventFilter (QObject *aObj, QEvent *aEvent);
321
322 int maxNameLength() const;
323 void showEvent (QShowEvent *aEvent);
324
325 CMachine mMachine;
326 QIWidgetValidator *mValidator;
327 HDItemsModel *mModel;
328 QAction *mNewAction;
329 QAction *mDelAction;
330 QAction *mVdmAction;
331 bool mWasTableSelected;
332};
333
334#endif // __VBoxVMSettingsHD_h__
335
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