VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox4/include/VBoxVMSettingsUtils.h@ 9951

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

Fe/Qt4: VBox VM Network Settings (for windows) ported to qt4.

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