VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox4/include/VBoxSettingsUtils.h@ 10971

Last change on this file since 10971 was 10468, checked in by vboxsync, 16 years ago

FE/Qt4: Added an interface class for the settings selector. Implemented the
classical tree view approach.

  • 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 * 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
41enum
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 */
54class BootItemsTable : public QTreeWidget
55{
56 Q_OBJECT;
57
58public:
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
69signals:
70
71 void moveItemUp();
72 void moveItemDown();
73 void itemToggled();
74
75private 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 */
108class VBoxAddNIDialog : public QDialog
109{
110 Q_OBJECT
111
112public:
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
161private slots:
162
163 void validate()
164 {
165 mBtOk->setEnabled (!mLeName->text().isEmpty());
166 }
167
168private:
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
181class USBListItem : public QTreeWidgetItem
182{
183public:
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 */
201class QITableView : public QTableView
202{
203 Q_OBJECT;
204
205public:
206
207 QITableView (QWidget *aParent) : QTableView (aParent) {}
208
209signals:
210
211 void currentChanged (const QModelIndex &aCurrent);
212
213protected:
214
215 void currentChanged (const QModelIndex &aCurrent,
216 const QModelIndex &aPrevious)
217 {
218 QTableView::currentChanged (aCurrent, aPrevious);
219 emit currentChanged (aCurrent);
220 }
221};
222
223class VBoxWarnIconLabel: public QWidget
224{
225 Q_OBJECT;
226
227public:
228
229 VBoxWarnIconLabel (QWidget *aParent = NULL)
230 : QWidget (aParent)
231 {
232 QHBoxLayout *layout = new QHBoxLayout (this);
233 VBoxGlobal::setLayoutMargin (layout, 0);
234 layout->addWidget (&mIcon);
235 layout->addWidget (&mLabel);
236 setVisible (false);
237 }
238
239 void setWarningPixmap (const QPixmap& aPixmap) { mIcon.setPixmap (aPixmap); }
240 void setWarningText (const QString& aText) { mLabel.setText (aText); }
241
242private:
243
244 QLabel mIcon;
245 QLabel mLabel;
246};
247
248#endif // __VBoxSettingsUtils_h__
249
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