VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/ui/VBoxGlobalSettingsDlg.ui.h@ 441

Last change on this file since 441 was 382, checked in by vboxsync, 18 years ago

export to OSE again

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.8 KB
Line 
1/**
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
4 * "Global settings" dialog UI include (Qt Designer)
5 */
6
7/*
8 * Copyright (C) 2006 InnoTek Systemberatung GmbH
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 as published by the Free Software Foundation,
14 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
15 * distribution. VirtualBox OSE is distributed in the hope that it will
16 * be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * If you received this file as part of a commercial VirtualBox
19 * distribution, then only the terms of your commercial VirtualBox
20 * license agreement apply instead of the previous paragraph.
21 */
22
23/****************************************************************************
24** ui.h extension file, included from the uic-generated form implementation.
25**
26** If you wish to add, delete or rename functions or slots use
27** Qt Designer which will update this file, preserving your code. Create an
28** init() function in place of a constructor, and a destroy() function in
29** place of a destructor.
30*****************************************************************************/
31
32
33/**
34 * Returns the path to the item in the form of 'grandparent > parent > item'
35 * using the text of the first column of every item.
36 */
37static QString path (QListViewItem *li)
38{
39 static QString sep = ": ";
40 QString p;
41 QListViewItem *cur = li;
42 while (cur)
43 {
44 if (!p.isNull())
45 p = sep + p;
46 p = cur->text (0).simplifyWhiteSpace() + p;
47 cur = cur->parent();
48 }
49 return p;
50}
51
52
53enum
54{
55 // listView column numbers
56 listView_Category = 0,
57 listView_Id = 1,
58 listView_Link = 2,
59};
60
61void VBoxGlobalSettingsDlg::init()
62{
63 setCaption (tr ("VirtualBox Global Settings"));
64 setIcon (QPixmap::fromMimeSource ("settings_16px.png"));
65
66 /* all pages are initially valid */
67 valid = true;
68 buttonOk->setEnabled( true );
69 warningSpacer->changeSize( 0, 0, QSizePolicy::Expanding );
70 warningLabel->setHidden( true );
71 warningPixmap->setHidden( true );
72
73 /* disable unselecting items by clicking in the unused area of the list */
74 new QIListViewSelectionPreserver (this, listView);
75 /* hide the header and internal columns */
76 listView->header()->hide();
77 listView->setColumnWidthMode (listView_Id, QListView::Manual);
78 listView->setColumnWidthMode (listView_Link, QListView::Manual);
79 listView->hideColumn (listView_Id);
80 listView->hideColumn (listView_Link);
81 /* sort by the id column (to have pages in the desired order) */
82 listView->setSorting (listView_Id);
83 listView->sort();
84 /* disable further sorting (important for network adapters) */
85 listView->setSorting (-1);
86 /* set the first item selected */
87 listView->setSelected (listView->firstChild(), true);
88 listView_currentChanged (listView->firstChild());
89
90 warningPixmap->setMaximumSize( 16, 16 );
91 warningPixmap->setPixmap( QMessageBox::standardIcon( QMessageBox::Warning ) );
92
93 /* page title font is derived from the system font */
94 QFont f = font();
95 f.setBold( true );
96 f.setPointSize( f.pointSize() + 2 );
97 titleLabel->setFont( f );
98
99 /* setup the what's this label */
100 QApplication::setGlobalMouseTracking (true);
101 qApp->installEventFilter (this);
102 whatsThisTimer = new QTimer (this);
103 connect (whatsThisTimer, SIGNAL (timeout()), this, SLOT (updateWhatsThis()));
104 whatsThisCandidate = NULL;
105 whatsThisLabel->setTextFormat (Qt::RichText);
106 whatsThisLabel->setMinimumHeight (whatsThisLabel->frameWidth() * 2 +
107 4 /* seems that RichText adds some margin */ +
108 whatsThisLabel->fontMetrics().lineSpacing() * 3);
109
110 /*
111 * create and layout non-standard widgets
112 * ----------------------------------------------------------------------
113 */
114
115 hkeHostKey = new QIHotKeyEdit( pageKeyboard, "hkeHostKey" );
116 hkeHostKey->setSizePolicy(
117 QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed ));
118 QWhatsThis::add (hkeHostKey,
119 tr ("Displays the key used as a Host Key in the VM window. Activate the "
120 "entry field and press a new Host Key. Note that alphanumeric, "
121 "cursor movement and editing keys cannot be used as a Host Key."));
122 layoutHostKey->addWidget( hkeHostKey );
123 txHostKey->setBuddy( hkeHostKey );
124 setTabOrder (listView, hkeHostKey);
125
126 /*
127 * setup connections and set validation for pages
128 * ----------------------------------------------------------------------
129 */
130
131 /* General page */
132
133/// @todo (dmik) remove
134// leVDIFolder->setValidator (new QRegExpValidator (QRegExp (".+"), this));
135// leMachineFolder->setValidator (new QRegExpValidator (QRegExp (".+"), this));
136
137 wvalGeneral = new QIWidgetValidator (pageGeneral, this);
138 connect (wvalGeneral, SIGNAL (validityChanged (const QIWidgetValidator *)),
139 this, SLOT (enableOk( const QIWidgetValidator *)));
140
141 /* Keyboard page */
142
143 wvalKeyboard = new QIWidgetValidator( pageKeyboard, this );
144 connect (wvalKeyboard, SIGNAL (validityChanged (const QIWidgetValidator *)),
145 this, SLOT (enableOk( const QIWidgetValidator *)));
146
147 /*
148 * set initial values
149 * ----------------------------------------------------------------------
150 */
151
152 /* General page */
153
154 /* keyboard page */
155
156 /*
157 * update the Ok button state for pages with validation
158 * (validityChanged() connected to enableNext() will do the job)
159 */
160 wvalGeneral->revalidate();
161 wvalKeyboard->revalidate();
162}
163
164bool VBoxGlobalSettingsDlg::eventFilter (QObject *object, QEvent *event)
165{
166 if (!object->isWidgetType())
167 return QDialog::eventFilter (object, event);
168
169 QWidget *widget = static_cast <QWidget *> (object);
170 if (widget->topLevelWidget() != this)
171 return QDialog::eventFilter (object, event);
172
173 switch (event->type())
174 {
175 case QEvent::Enter:
176 case QEvent::Leave:
177 {
178 if (event->type() == QEvent::Enter)
179 whatsThisCandidate = widget;
180 else
181 whatsThisCandidate = NULL;
182 whatsThisTimer->start (100, true /* sshot */);
183 break;
184 }
185 case QEvent::FocusIn:
186 {
187 updateWhatsThis (true /* gotFocus */);
188 break;
189 }
190 default:
191 break;
192 }
193
194 return QDialog::eventFilter (object, event);
195}
196
197void VBoxGlobalSettingsDlg::listView_currentChanged (QListViewItem *item)
198{
199 Assert (item);
200 int id = item->text (1).toInt();
201 Assert (id >= 0);
202 titleLabel->setText (::path (item));
203 widgetStack->raiseWidget (id);
204}
205
206void VBoxGlobalSettingsDlg::enableOk (const QIWidgetValidator *wval)
207{
208 Q_UNUSED (wval);
209
210 /* detect the overall validity */
211 bool newValid = true;
212 {
213 QObjectList *l = this->queryList ("QIWidgetValidator");
214 QObjectListIt it (*l);
215 QObject *obj;
216 while ((obj = it.current()) != 0)
217 {
218 newValid &= ((QIWidgetValidator *) obj)->isValid();
219 ++it;
220 }
221 delete l;
222 }
223
224 if (valid != newValid)
225 {
226 valid = newValid;
227 buttonOk->setEnabled (valid);
228 if (valid)
229 warningSpacer->changeSize (0, 0, QSizePolicy::Expanding);
230 else
231 warningSpacer->changeSize (0, 0);
232 warningLabel->setHidden (valid);
233 warningPixmap->setHidden (valid);
234 }
235}
236
237void VBoxGlobalSettingsDlg::revalidate (QIWidgetValidator * /*wval*/)
238{
239 /* do individual validations for pages */
240
241 /* currently nothing */
242}
243
244/**
245 * Reads global settings from the given VMGlobalSettings instance
246 * and from the given CSystemProperties object.
247 */
248void VBoxGlobalSettingsDlg::getFrom (const CSystemProperties &props,
249 const VMGlobalSettings &gs)
250{
251 /* default folders */
252
253 leVDIFolder->setText (props.GetDefaultVDIFolder());
254 leMachineFolder->setText (props.GetDefaultMachineFolder());
255
256 /* proprietary GUI settings */
257
258 hkeHostKey->setKey (gs.hostKey() );
259 chbAutoCapture->setChecked (gs.autoCapture());
260
261// wvalXXXX->revalidate();
262}
263
264/**
265 * Writes global settings to the given VMGlobalSettings instance
266 * and to the given CSystemProperties object.
267 */
268void VBoxGlobalSettingsDlg::putBackTo (CSystemProperties &props,
269 VMGlobalSettings &gs)
270{
271 /* default folders */
272
273 if (leVDIFolder->isModified())
274 props.SetDefaultVDIFolder (leVDIFolder->text());
275 if (props.isOk() && leMachineFolder->isModified())
276 props.SetDefaultMachineFolder (leMachineFolder->text());
277
278 if (!props.isOk())
279 return;
280
281 /* proprietary GUI settings */
282
283 gs.setHostKey (hkeHostKey->key());
284 gs.setAutoCapture (chbAutoCapture->isChecked());
285}
286
287void VBoxGlobalSettingsDlg::updateWhatsThis (bool gotFocus /* = false */)
288{
289 QString text;
290
291 QWidget *widget = NULL;
292 if (!gotFocus)
293 {
294 if (whatsThisCandidate != NULL && whatsThisCandidate != this)
295 widget = whatsThisCandidate;
296 }
297 else
298 {
299 widget = focusData()->focusWidget();
300 }
301 /* if the given widget lacks the whats'this text, look at its parent */
302 while (widget && widget != this)
303 {
304 text = QWhatsThis::textFor (widget);
305 if (!text.isEmpty())
306 break;
307 widget = widget->parentWidget();
308 }
309
310 if (text.isEmpty() && !warningString.isEmpty())
311 text = warningString;
312 if (text.isEmpty())
313 text = QWhatsThis::textFor (this);
314
315 whatsThisLabel->setText (text);
316}
317
318void VBoxGlobalSettingsDlg::setWarning (const QString &warning)
319{
320 warningString = warning;
321 if (!warning.isEmpty())
322 warningString = QString ("<font color=red>%1</font>").arg (warning);
323
324 if (!warningString.isEmpty())
325 whatsThisLabel->setText (warningString);
326 else
327 updateWhatsThis (true);
328}
329
330void VBoxGlobalSettingsDlg::tbResetFolder_clicked()
331{
332 QToolButton *tb = ::qt_cast <QToolButton *> (sender());
333 Assert (tb);
334
335 QLineEdit *le = 0;
336 if (tb == tbResetVDIFolder) le = leVDIFolder;
337 else if (tb == tbResetMachineFolder) le = leMachineFolder;
338 Assert (le);
339
340 /*
341 * do this instead of le->setText (QString::null) to cause
342 * isModified() return true
343 */
344 le->selectAll();
345 le->del();
346}
347
348void VBoxGlobalSettingsDlg::tbSelectFolder_clicked()
349{
350 QToolButton *tb = ::qt_cast <QToolButton *> (sender());
351 Assert (tb);
352
353 QLineEdit *le = 0;
354 if (tb == tbSelectVDIFolder) le = leVDIFolder;
355 else if (tb == tbSelectMachineFolder) le = leMachineFolder;
356 Assert (le);
357
358 QString homeFolder = vboxGlobal().virtualBox().GetHomeFolder();
359
360 QFileDialog dlg (homeFolder, QString::null, this);
361 dlg.setMode (QFileDialog::DirectoryOnly);
362
363 if (!le->text().isEmpty())
364 {
365 /* set the first parent directory that exists as the current */
366#if 0 /** @todo fix this linux bustage properly */
367 QFileInfo fld (QDir (homeFolder), le->text());
368#else
369 const QDir _dir (homeFolder);
370 QFileInfo fld (_dir, le->text());
371#endif
372 do
373 {
374 QString dp = fld.dirPath (false);
375 fld = QFileInfo (dp);
376 }
377 while (!fld.exists() && !QDir (fld.absFilePath()).isRoot());
378
379 if (fld.exists())
380 dlg.setDir (fld.absFilePath());
381 }
382
383 if (dlg.exec() == QDialog::Accepted)
384 {
385 QString folder = QDir::convertSeparators (dlg.selectedFile());
386 /* remove trailing slash */
387 folder.truncate (folder.length() - 1);
388
389 /*
390 * do this instead of le->setText (folder) to cause
391 * isModified() return true
392 */
393 le->selectAll();
394 le->insert (folder);
395 }
396}
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