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