1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox frontends: Qt4 GUI ("VirtualBox"):
|
---|
4 | * VBoxSettingsUtils 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 __VBoxSettingsUtils_h__
|
---|
24 | #define __VBoxSettingsUtils_h__
|
---|
25 |
|
---|
26 | #include <VBoxGlobal.h>
|
---|
27 |
|
---|
28 | /* Qt includes */
|
---|
29 | #ifdef Q_WS_WIN
|
---|
30 | #include <QDialog>
|
---|
31 | #include <QLineEdit>
|
---|
32 | #include <QPushButton>
|
---|
33 | #endif
|
---|
34 | #include <QHBoxLayout>
|
---|
35 | #include <QLabel>
|
---|
36 | #include <QTreeWidget>
|
---|
37 | #include <QHeaderView>
|
---|
38 | #include <QKeyEvent>
|
---|
39 | #include <QTableView>
|
---|
40 |
|
---|
41 | enum
|
---|
42 | {
|
---|
43 | /* mTwUSBFilters column numbers */
|
---|
44 | twUSBFilters_Name = 0,
|
---|
45 | };
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * QTreeWidget class reimplementation to use as boot items table.
|
---|
49 | * It has one unsorted column without header.
|
---|
50 | * Keymapping handlers for ctrl-up & ctrl-down are translated into
|
---|
51 | * boot-items up/down moving signals.
|
---|
52 | * Emits itemToggled() signal when the item changed.
|
---|
53 | */
|
---|
54 | class BootItemsTable : public QTreeWidget
|
---|
55 | {
|
---|
56 | Q_OBJECT;
|
---|
57 |
|
---|
58 | public:
|
---|
59 |
|
---|
60 | BootItemsTable (QWidget *aParent) : QTreeWidget (aParent)
|
---|
61 | {
|
---|
62 | header()->hide();
|
---|
63 | connect (this, SIGNAL (itemChanged (QTreeWidgetItem *, int)),
|
---|
64 | this, SLOT (onItemChanged()));
|
---|
65 | }
|
---|
66 |
|
---|
67 | ~BootItemsTable() {}
|
---|
68 |
|
---|
69 | signals:
|
---|
70 |
|
---|
71 | void moveItemUp();
|
---|
72 | void moveItemDown();
|
---|
73 | void itemToggled();
|
---|
74 |
|
---|
75 | private slots:
|
---|
76 |
|
---|
77 | void onItemChanged()
|
---|
78 | {
|
---|
79 | emit itemToggled();
|
---|
80 | }
|
---|
81 |
|
---|
82 | void keyPressEvent (QKeyEvent *aEvent)
|
---|
83 | {
|
---|
84 | if (aEvent->QInputEvent::modifiers () == Qt::ControlModifier)
|
---|
85 | {
|
---|
86 | switch (aEvent->key())
|
---|
87 | {
|
---|
88 | case Qt::Key_Up:
|
---|
89 | emit moveItemUp();
|
---|
90 | return;
|
---|
91 | case Qt::Key_Down:
|
---|
92 | emit moveItemDown();
|
---|
93 | return;
|
---|
94 | default:
|
---|
95 | break;
|
---|
96 | }
|
---|
97 | }
|
---|
98 | QTreeWidget::keyPressEvent (aEvent);
|
---|
99 | }
|
---|
100 | };
|
---|
101 |
|
---|
102 | #ifdef Q_WS_WIN
|
---|
103 | /**
|
---|
104 | * QDialog class reimplementation to use for adding network interface.
|
---|
105 | * It has one line-edit field for entering network interface's name and
|
---|
106 | * common dialog's ok/cancel buttons.
|
---|
107 | */
|
---|
108 | class VBoxAddNIDialog : public QDialog
|
---|
109 | {
|
---|
110 | Q_OBJECT
|
---|
111 |
|
---|
112 | public:
|
---|
113 |
|
---|
114 | VBoxAddNIDialog (QWidget *aParent, const QString &aIfaceName) :
|
---|
115 | QDialog (aParent),
|
---|
116 | mLeName (0)
|
---|
117 | {
|
---|
118 | setWindowTitle (tr ("Add Host Interface"));
|
---|
119 | QVBoxLayout *mainLayout = new QVBoxLayout (this);
|
---|
120 |
|
---|
121 | /* Setup Input layout */
|
---|
122 | QHBoxLayout *inputLayout = new QHBoxLayout();
|
---|
123 | QLabel *lbName = new QLabel (tr ("Interface Name"), this);
|
---|
124 | mLeName = new QLineEdit (aIfaceName, this);
|
---|
125 | mLeName->setWhatsThis (tr ("Descriptive name of the new "
|
---|
126 | "network interface"));
|
---|
127 | inputLayout->addWidget (lbName);
|
---|
128 | inputLayout->addWidget (mLeName);
|
---|
129 | connect (mLeName, SIGNAL (textChanged (const QString &)),
|
---|
130 | this, SLOT (validate()));
|
---|
131 | mainLayout->addLayout (inputLayout);
|
---|
132 |
|
---|
133 | /* Setup Button layout */
|
---|
134 | QHBoxLayout *buttonLayout = new QHBoxLayout();
|
---|
135 | mBtOk = new QPushButton (tr ("&OK"), this);
|
---|
136 | QPushButton *btCancel = new QPushButton (tr ("Cancel"), this);
|
---|
137 | connect (mBtOk, SIGNAL (clicked()), this, SLOT (accept()));
|
---|
138 | connect (btCancel, SIGNAL (clicked()), this, SLOT (reject()));
|
---|
139 | buttonLayout->addWidget (mBtOk);
|
---|
140 | buttonLayout->addStretch();
|
---|
141 | buttonLayout->addWidget (btCancel);
|
---|
142 | mainLayout->addLayout (buttonLayout);
|
---|
143 |
|
---|
144 | /* Resize to fit the aIfaceName in one string */
|
---|
145 | int requiredWidth = mLeName->fontMetrics().width (aIfaceName) +
|
---|
146 | inputLayout->spacing() +
|
---|
147 | lbName->fontMetrics().width (lbName->text()) +
|
---|
148 | lbName->frameWidth() * 2 +
|
---|
149 | lbName->lineWidth() * 2 +
|
---|
150 | mainLayout->margin() * 2;
|
---|
151 | resize (requiredWidth, minimumHeight());
|
---|
152 |
|
---|
153 | /* Validate interface name field */
|
---|
154 | validate();
|
---|
155 | }
|
---|
156 |
|
---|
157 | ~VBoxAddNIDialog() {}
|
---|
158 |
|
---|
159 | QString getName() { return mLeName->text(); }
|
---|
160 |
|
---|
161 | private slots:
|
---|
162 |
|
---|
163 | void validate()
|
---|
164 | {
|
---|
165 | mBtOk->setEnabled (!mLeName->text().isEmpty());
|
---|
166 | }
|
---|
167 |
|
---|
168 | private:
|
---|
169 |
|
---|
170 | void showEvent (QShowEvent *aEvent)
|
---|
171 | {
|
---|
172 | setFixedHeight (height());
|
---|
173 | QDialog::showEvent (aEvent);
|
---|
174 | }
|
---|
175 |
|
---|
176 | QPushButton *mBtOk;
|
---|
177 | QLineEdit *mLeName;
|
---|
178 | };
|
---|
179 | #endif
|
---|
180 |
|
---|
181 | class USBListItem : public QTreeWidgetItem
|
---|
182 | {
|
---|
183 | public:
|
---|
184 |
|
---|
185 | enum { USBListItemType = 1002 };
|
---|
186 |
|
---|
187 | USBListItem (QTreeWidget *aParent)
|
---|
188 | : QTreeWidgetItem (aParent, QStringList (QString::null), USBListItemType)
|
---|
189 | , mId (-1) {}
|
---|
190 |
|
---|
191 | USBListItem (QTreeWidget *aParent, QTreeWidgetItem *aPreceding)
|
---|
192 | : QTreeWidgetItem (aParent, aPreceding, USBListItemType)
|
---|
193 | , mId (-1) {}
|
---|
194 |
|
---|
195 | int mId;
|
---|
196 | };
|
---|
197 |
|
---|
198 | /**
|
---|
199 | * Table-View class reimplementation to extend standard QTableView.
|
---|
200 | */
|
---|
201 | class QITableView : public QTableView
|
---|
202 | {
|
---|
203 | Q_OBJECT;
|
---|
204 |
|
---|
205 | public:
|
---|
206 |
|
---|
207 | QITableView (QWidget *aParent) : QTableView (aParent) {}
|
---|
208 |
|
---|
209 | signals:
|
---|
210 |
|
---|
211 | void currentChanged (const QModelIndex &aCurrent);
|
---|
212 |
|
---|
213 | protected:
|
---|
214 |
|
---|
215 | void currentChanged (const QModelIndex &aCurrent,
|
---|
216 | const QModelIndex &aPrevious)
|
---|
217 | {
|
---|
218 | QTableView::currentChanged (aCurrent, aPrevious);
|
---|
219 | emit currentChanged (aCurrent);
|
---|
220 | }
|
---|
221 |
|
---|
222 | void focusInEvent (QFocusEvent *aEvent)
|
---|
223 | {
|
---|
224 | /* Restore edit-mode on focus in. */
|
---|
225 | QTableView::focusInEvent (aEvent);
|
---|
226 | if (model()->flags (currentIndex()) & Qt::ItemIsEditable)
|
---|
227 | edit (currentIndex());
|
---|
228 | }
|
---|
229 | };
|
---|
230 |
|
---|
231 | class VBoxWarnIconLabel: public QWidget
|
---|
232 | {
|
---|
233 | Q_OBJECT;
|
---|
234 |
|
---|
235 | public:
|
---|
236 |
|
---|
237 | VBoxWarnIconLabel (QWidget *aParent = NULL)
|
---|
238 | : QWidget (aParent)
|
---|
239 | {
|
---|
240 | QHBoxLayout *layout = new QHBoxLayout (this);
|
---|
241 | VBoxGlobal::setLayoutMargin (layout, 0);
|
---|
242 | layout->addWidget (&mIcon);
|
---|
243 | layout->addWidget (&mLabel);
|
---|
244 | setVisible (false);
|
---|
245 | }
|
---|
246 |
|
---|
247 | void setWarningPixmap (const QPixmap& aPixmap) { mIcon.setPixmap (aPixmap); }
|
---|
248 | void setWarningText (const QString& aText) { mLabel.setText (aText); }
|
---|
249 |
|
---|
250 | private:
|
---|
251 |
|
---|
252 | QLabel mIcon;
|
---|
253 | QLabel mLabel;
|
---|
254 | };
|
---|
255 |
|
---|
256 | #endif // __VBoxSettingsUtils_h__
|
---|
257 |
|
---|