[26714] | 1 | /* $Id: UISettingsDialog.cpp 72059 2018-04-27 14:33:48Z vboxsync $ */
|
---|
[25177] | 2 | /** @file
|
---|
[52727] | 3 | * VBox Qt GUI - UISettingsDialog class implementation.
|
---|
[25177] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[72059] | 7 | * Copyright (C) 2006-2018 Oracle Corporation
|
---|
[25177] | 8 | *
|
---|
| 9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
| 10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
| 11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
| 12 | * General Public License (GPL) as published by the Free Software
|
---|
| 13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
| 14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
| 15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
| 16 | */
|
---|
[32667] | 17 |
|
---|
[52730] | 18 | #ifdef VBOX_WITH_PRECOMPILED_HEADERS
|
---|
| 19 | # include <precomp.h>
|
---|
| 20 | #else /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
| 21 |
|
---|
[72059] | 22 | /* Qt includes: */
|
---|
| 23 | # include <QCloseEvent>
|
---|
[52730] | 24 | # include <QProgressBar>
|
---|
| 25 | # include <QPushButton>
|
---|
| 26 | # include <QStackedWidget>
|
---|
| 27 | # include <QTimer>
|
---|
[32667] | 28 |
|
---|
[72059] | 29 | /* GUI includes: */
|
---|
| 30 | # include "QIWidgetValidator.h"
|
---|
[52730] | 31 | # include "VBoxGlobal.h"
|
---|
[72059] | 32 | # include "UIConverter.h"
|
---|
| 33 | # include "UIIconPool.h"
|
---|
[52730] | 34 | # include "UIMessageCenter.h"
|
---|
[72059] | 35 | # include "UIModalWindowManager.h"
|
---|
[52730] | 36 | # include "UIPopupCenter.h"
|
---|
[72059] | 37 | # include "UISettingsDialog.h"
|
---|
| 38 | # include "UISettingsPage.h"
|
---|
[63978] | 39 | # include "UISettingsSelector.h"
|
---|
[54921] | 40 | # include "UISettingsSerializer.h"
|
---|
[52730] | 41 | # include "UIToolBar.h"
|
---|
[72059] | 42 | # include "UIWarningPane.h"
|
---|
[60362] | 43 | # ifdef VBOX_WS_MAC
|
---|
[52730] | 44 | # include "VBoxUtils.h"
|
---|
[72059] | 45 | # endif
|
---|
[52730] | 46 |
|
---|
| 47 | #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
| 48 |
|
---|
[60362] | 49 | #ifdef VBOX_WS_MAC
|
---|
[59094] | 50 | # define VBOX_GUI_WITH_TOOLBAR_SETTINGS
|
---|
[72059] | 51 | #endif
|
---|
[25177] | 52 |
|
---|
[72059] | 53 |
|
---|
[37109] | 54 | UISettingsDialog::UISettingsDialog(QWidget *pParent)
|
---|
[32667] | 55 | : QIWithRetranslateUI<QIMainDialog>(pParent)
|
---|
| 56 | , m_pSelector(0)
|
---|
| 57 | , m_pStack(0)
|
---|
| 58 | , m_fPolished(false)
|
---|
[72059] | 59 | , m_enmConfigurationAccessLevel(ConfigurationAccessLevel_Null)
|
---|
[54932] | 60 | , m_pSerializeProcess(0)
|
---|
[55742] | 61 | , m_fSerializationIsInProgress(false)
|
---|
[65600] | 62 | , m_fSerializationClean(true)
|
---|
[47806] | 63 | , m_pStatusBar(0)
|
---|
| 64 | , m_pProcessBar(0)
|
---|
| 65 | , m_pWarningPane(0)
|
---|
[32667] | 66 | , m_fValid(true)
|
---|
| 67 | , m_fSilent(true)
|
---|
| 68 | , m_pWhatsThisTimer(new QTimer(this))
|
---|
[25177] | 69 | {
|
---|
[72059] | 70 | /* Prepare: */
|
---|
| 71 | prepare();
|
---|
[25177] | 72 | }
|
---|
| 73 |
|
---|
[32667] | 74 | UISettingsDialog::~UISettingsDialog()
|
---|
[25177] | 75 | {
|
---|
[54932] | 76 | /* Delete serializer if exists: */
|
---|
| 77 | if (serializeProcess())
|
---|
| 78 | {
|
---|
| 79 | delete m_pSerializeProcess;
|
---|
| 80 | m_pSerializeProcess = 0;
|
---|
| 81 | }
|
---|
[54922] | 82 |
|
---|
[47763] | 83 | /* Recall popup-pane if any: */
|
---|
| 84 | popupCenter().recall(m_pStack, "SettingsDialogWarning");
|
---|
[54922] | 85 |
|
---|
[32667] | 86 | /* Delete selector early! */
|
---|
| 87 | delete m_pSelector;
|
---|
[25177] | 88 | }
|
---|
| 89 |
|
---|
[37109] | 90 | void UISettingsDialog::execute()
|
---|
| 91 | {
|
---|
| 92 | /* Load data: */
|
---|
[54921] | 93 | loadOwnData();
|
---|
[37109] | 94 |
|
---|
[54928] | 95 | /* Execute dialog: */
|
---|
| 96 | exec();
|
---|
| 97 | }
|
---|
[37109] | 98 |
|
---|
[54928] | 99 | void UISettingsDialog::accept()
|
---|
| 100 | {
|
---|
[37109] | 101 | /* Save data: */
|
---|
[54921] | 102 | saveOwnData();
|
---|
[54928] | 103 |
|
---|
[65600] | 104 | /* If serialization was clean: */
|
---|
| 105 | if (m_fSerializationClean)
|
---|
| 106 | {
|
---|
| 107 | /* Call to base-class: */
|
---|
| 108 | QIWithRetranslateUI<QIMainDialog>::accept();
|
---|
| 109 | }
|
---|
[37109] | 110 | }
|
---|
| 111 |
|
---|
[72059] | 112 | void UISettingsDialog::reject()
|
---|
| 113 | {
|
---|
| 114 | if (!isSerializationInProgress())
|
---|
| 115 | QIWithRetranslateUI<QIMainDialog>::reject();
|
---|
| 116 | }
|
---|
| 117 |
|
---|
[33631] | 118 | void UISettingsDialog::sltCategoryChanged(int cId)
|
---|
| 119 | {
|
---|
[72059] | 120 | const int iIndex = m_pages.value(cId);
|
---|
| 121 |
|
---|
[60362] | 122 | #ifdef VBOX_WS_MAC
|
---|
[59727] | 123 | /* If index is within the stored size list bounds: */
|
---|
[72059] | 124 | if (iIndex < m_sizeList.count())
|
---|
[59727] | 125 | {
|
---|
| 126 | /* Get current/stored size: */
|
---|
| 127 | const QSize cs = size();
|
---|
[72059] | 128 | const QSize ss = m_sizeList.at(iIndex);
|
---|
[59727] | 129 |
|
---|
| 130 | /* Switch to the new page first if we are shrinking: */
|
---|
| 131 | if (cs.height() > ss.height())
|
---|
[72059] | 132 | m_pStack->setCurrentIndex(iIndex);
|
---|
[59727] | 133 |
|
---|
| 134 | /* Do the animation: */
|
---|
| 135 | ::darwinWindowAnimateResize(this, QRect (x(), y(), ss.width(), ss.height()));
|
---|
| 136 |
|
---|
| 137 | /* Switch to the new page last if we are zooming: */
|
---|
| 138 | if (cs.height() <= ss.height())
|
---|
[72059] | 139 | m_pStack->setCurrentIndex(iIndex);
|
---|
[59727] | 140 |
|
---|
| 141 | /* Unlock all page policies but lock the current one: */
|
---|
| 142 | for (int i = 0; i < m_pStack->count(); ++i)
|
---|
[72059] | 143 | m_pStack->widget(i)->setSizePolicy(QSizePolicy::Minimum, i == iIndex ? QSizePolicy::Minimum : QSizePolicy::Ignored);
|
---|
| 144 |
|
---|
[59727] | 145 | /* And make sure layouts are freshly calculated: */
|
---|
| 146 | foreach (QLayout *pLayout, findChildren<QLayout*>())
|
---|
| 147 | {
|
---|
| 148 | pLayout->update();
|
---|
| 149 | pLayout->activate();
|
---|
| 150 | }
|
---|
| 151 | }
|
---|
[72059] | 152 | #else /* !VBOX_WS_MAC */
|
---|
| 153 | m_pStack->setCurrentIndex(iIndex);
|
---|
| 154 | #endif /* !VBOX_WS_MAC */
|
---|
| 155 |
|
---|
[33631] | 156 | #ifdef VBOX_GUI_WITH_TOOLBAR_SETTINGS
|
---|
| 157 | setWindowTitle(title());
|
---|
[64159] | 158 | #else
|
---|
| 159 | m_pLbTitle->setText(m_pSelector->itemText(cId));
|
---|
| 160 | #endif
|
---|
[33631] | 161 | }
|
---|
| 162 |
|
---|
[37138] | 163 | void UISettingsDialog::sltMarkLoaded()
|
---|
[35131] | 164 | {
|
---|
[54932] | 165 | /* Delete serializer if exists: */
|
---|
| 166 | if (serializeProcess())
|
---|
| 167 | {
|
---|
| 168 | delete m_pSerializeProcess;
|
---|
| 169 | m_pSerializeProcess = 0;
|
---|
| 170 | }
|
---|
[54923] | 171 |
|
---|
[55742] | 172 | /* Mark serialization finished: */
|
---|
| 173 | m_fSerializationIsInProgress = false;
|
---|
[35131] | 174 | }
|
---|
| 175 |
|
---|
[37138] | 176 | void UISettingsDialog::sltMarkSaved()
|
---|
| 177 | {
|
---|
[54932] | 178 | /* Delete serializer if exists: */
|
---|
| 179 | if (serializeProcess())
|
---|
| 180 | {
|
---|
| 181 | delete m_pSerializeProcess;
|
---|
| 182 | m_pSerializeProcess = 0;
|
---|
| 183 | }
|
---|
[54923] | 184 |
|
---|
[55742] | 185 | /* Mark serialization finished: */
|
---|
| 186 | m_fSerializationIsInProgress = false;
|
---|
[37138] | 187 | }
|
---|
| 188 |
|
---|
[37106] | 189 | void UISettingsDialog::sltHandleProcessStarted()
|
---|
| 190 | {
|
---|
| 191 | m_pProcessBar->setValue(0);
|
---|
| 192 | m_pStatusBar->setCurrentWidget(m_pProcessBar);
|
---|
| 193 | }
|
---|
| 194 |
|
---|
[55655] | 195 | void UISettingsDialog::sltHandleProcessProgressChange(int iValue)
|
---|
[37106] | 196 | {
|
---|
[55655] | 197 | m_pProcessBar->setValue(iValue);
|
---|
[37106] | 198 | if (m_pProcessBar->value() == m_pProcessBar->maximum())
|
---|
| 199 | {
|
---|
| 200 | if (!m_fValid || !m_fSilent)
|
---|
| 201 | m_pStatusBar->setCurrentWidget(m_pWarningPane);
|
---|
| 202 | else
|
---|
| 203 | m_pStatusBar->setCurrentIndex(0);
|
---|
| 204 | }
|
---|
| 205 | }
|
---|
| 206 |
|
---|
[72059] | 207 | bool UISettingsDialog::eventFilter(QObject *pObject, QEvent *pEvent)
|
---|
| 208 | {
|
---|
| 209 | /* Ignore objects which are NOT widgets: */
|
---|
| 210 | if (!pObject->isWidgetType())
|
---|
| 211 | return QIMainDialog::eventFilter(pObject, pEvent);
|
---|
| 212 |
|
---|
| 213 | /* Ignore widgets which window is NOT settings window: */
|
---|
| 214 | QWidget *pWidget = static_cast<QWidget*>(pObject);
|
---|
| 215 | if (pWidget->window() != this)
|
---|
| 216 | return QIMainDialog::eventFilter(pObject, pEvent);
|
---|
| 217 |
|
---|
| 218 | /* Process different event-types: */
|
---|
| 219 | switch (pEvent->type())
|
---|
| 220 | {
|
---|
| 221 | /* Process enter/leave events to remember whats-this candidates: */
|
---|
| 222 | case QEvent::Enter:
|
---|
| 223 | case QEvent::Leave:
|
---|
| 224 | {
|
---|
| 225 | if (pEvent->type() == QEvent::Enter)
|
---|
| 226 | m_pWhatsThisCandidate = pWidget;
|
---|
| 227 | else
|
---|
| 228 | m_pWhatsThisCandidate = 0;
|
---|
| 229 |
|
---|
| 230 | m_pWhatsThisTimer->start(100);
|
---|
| 231 | break;
|
---|
| 232 | }
|
---|
| 233 | /* Process focus-in event to update whats-this pane: */
|
---|
| 234 | case QEvent::FocusIn:
|
---|
| 235 | {
|
---|
| 236 | sltUpdateWhatsThis(true /* got focus? */);
|
---|
| 237 | break;
|
---|
| 238 | }
|
---|
| 239 | default:
|
---|
| 240 | break;
|
---|
| 241 | }
|
---|
| 242 |
|
---|
| 243 | /* Base-class processing: */
|
---|
| 244 | return QIMainDialog::eventFilter(pObject, pEvent);
|
---|
| 245 | }
|
---|
| 246 |
|
---|
| 247 | void UISettingsDialog::retranslateUi()
|
---|
| 248 | {
|
---|
| 249 | /* Translate generated stuff: */
|
---|
| 250 | Ui::UISettingsDialog::retranslateUi(this);
|
---|
| 251 |
|
---|
| 252 | /* Translate warning stuff: */
|
---|
| 253 | m_strWarningHint = tr("Invalid settings detected");
|
---|
| 254 | if (!m_fValid || !m_fSilent)
|
---|
| 255 | m_pWarningPane->setWarningLabel(m_strWarningHint);
|
---|
| 256 |
|
---|
| 257 | #ifndef VBOX_GUI_WITH_TOOLBAR_SETTINGS
|
---|
| 258 | /* Retranslate current page headline: */
|
---|
| 259 | m_pLbTitle->setText(m_pSelector->itemText(m_pSelector->currentId()));
|
---|
| 260 | #endif
|
---|
| 261 |
|
---|
| 262 | /* Retranslate all validators: */
|
---|
| 263 | foreach (UIPageValidator *pValidator, findChildren<UIPageValidator*>())
|
---|
| 264 | if (!pValidator->lastMessage().isEmpty())
|
---|
| 265 | revalidate(pValidator);
|
---|
| 266 | revalidate();
|
---|
| 267 | }
|
---|
| 268 |
|
---|
| 269 | void UISettingsDialog::showEvent(QShowEvent *pEvent)
|
---|
| 270 | {
|
---|
| 271 | /* Base-class processing: */
|
---|
| 272 | QIMainDialog::showEvent(pEvent);
|
---|
| 273 |
|
---|
| 274 | /* One may think that QWidget::polish() is the right place to do things
|
---|
| 275 | * below, but apparently, by the time when QWidget::polish() is called,
|
---|
| 276 | * the widget style & layout are not fully done, at least the minimum
|
---|
| 277 | * size hint is not properly calculated. Since this is sometimes necessary,
|
---|
| 278 | * we provide our own "polish" implementation. */
|
---|
| 279 | if (m_fPolished)
|
---|
| 280 | return;
|
---|
| 281 |
|
---|
| 282 | m_fPolished = true;
|
---|
| 283 |
|
---|
| 284 | int iMinWidth = m_pSelector->minWidth();
|
---|
| 285 |
|
---|
| 286 | #ifdef VBOX_WS_MAC
|
---|
| 287 |
|
---|
| 288 | /* Remove all title bar buttons (Buggy Qt): */
|
---|
| 289 | ::darwinSetHidesAllTitleButtons(this);
|
---|
| 290 |
|
---|
| 291 | /* Unlock all page policies initially: */
|
---|
| 292 | for (int i = 0; i < m_pStack->count(); ++i)
|
---|
| 293 | m_pStack->widget(i)->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored);
|
---|
| 294 |
|
---|
| 295 | /* Activate every single page to get the optimal size: */
|
---|
| 296 | for (int i = m_pStack->count() - 1; i >= 0; --i)
|
---|
| 297 | {
|
---|
| 298 | /* Activate current page: */
|
---|
| 299 | m_pStack->setCurrentIndex(i);
|
---|
| 300 |
|
---|
| 301 | /* Lock current page policy temporary: */
|
---|
| 302 | m_pStack->widget(i)->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
---|
| 303 | /* And make sure layouts are freshly calculated: */
|
---|
| 304 | foreach (QLayout *pLayout, findChildren<QLayout*>())
|
---|
| 305 | {
|
---|
| 306 | pLayout->update();
|
---|
| 307 | pLayout->activate();
|
---|
| 308 | }
|
---|
| 309 |
|
---|
| 310 | /* Acquire minimum size-hint: */
|
---|
| 311 | QSize s = minimumSizeHint();
|
---|
| 312 | // WORKAROUND:
|
---|
| 313 | // Take into account the height of native tool-bar title.
|
---|
| 314 | // It will be applied only after widget is really shown.
|
---|
| 315 | // The height is 11pix * 2 (possible HiDPI support).
|
---|
| 316 | s.setHeight(s.height() + 11 * 2);
|
---|
| 317 | /* Also make sure that width is no less than tool-bar: */
|
---|
| 318 | if (iMinWidth > s.width())
|
---|
| 319 | s.setWidth(iMinWidth);
|
---|
| 320 | /* And remember the size finally: */
|
---|
| 321 | m_sizeList.insert(0, s);
|
---|
| 322 |
|
---|
| 323 | /* Unlock the policy for current page again: */
|
---|
| 324 | m_pStack->widget(i)->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored);
|
---|
| 325 | }
|
---|
| 326 |
|
---|
| 327 | sltCategoryChanged(m_pSelector->currentId());
|
---|
| 328 |
|
---|
| 329 | #else /* VBOX_WS_MAC */
|
---|
| 330 |
|
---|
| 331 | /* Resize to the minimum possible size: */
|
---|
| 332 | QSize s = minimumSize();
|
---|
| 333 | if (iMinWidth > s.width())
|
---|
| 334 | s.setWidth(iMinWidth);
|
---|
| 335 | resize(s);
|
---|
| 336 |
|
---|
| 337 | #endif /* VBOX_WS_MAC */
|
---|
| 338 | }
|
---|
| 339 |
|
---|
[54921] | 340 | void UISettingsDialog::loadData(QVariant &data)
|
---|
[37138] | 341 | {
|
---|
[55742] | 342 | /* Mark serialization started: */
|
---|
| 343 | m_fSerializationIsInProgress = true;
|
---|
[54921] | 344 |
|
---|
| 345 | /* Create settings loader: */
|
---|
[54932] | 346 | m_pSerializeProcess = new UISettingsSerializer(this, UISettingsSerializer::Load,
|
---|
| 347 | data, m_pSelector->settingPages());
|
---|
| 348 | AssertPtrReturnVoid(m_pSerializeProcess);
|
---|
[54923] | 349 | {
|
---|
| 350 | /* Configure settings loader: */
|
---|
[54932] | 351 | connect(m_pSerializeProcess, SIGNAL(sigNotifyAboutProcessStarted()), this, SLOT(sltHandleProcessStarted()));
|
---|
[55655] | 352 | connect(m_pSerializeProcess, SIGNAL(sigNotifyAboutProcessProgressChanged(int)), this, SLOT(sltHandleProcessProgressChange(int)));
|
---|
[54932] | 353 | connect(m_pSerializeProcess, SIGNAL(sigNotifyAboutProcessFinished()), this, SLOT(sltMarkLoaded()));
|
---|
[55655] | 354 |
|
---|
[54923] | 355 | /* Raise current page priority: */
|
---|
[54932] | 356 | m_pSerializeProcess->raisePriorityOfPage(m_pSelector->currentId());
|
---|
[55655] | 357 |
|
---|
[54923] | 358 | /* Start settings loader: */
|
---|
[54932] | 359 | m_pSerializeProcess->start();
|
---|
[55655] | 360 |
|
---|
| 361 | /* Upload data finally: */
|
---|
| 362 | data = m_pSerializeProcess->data();
|
---|
[54923] | 363 | }
|
---|
[37138] | 364 | }
|
---|
| 365 |
|
---|
[54921] | 366 | void UISettingsDialog::saveData(QVariant &data)
|
---|
[37138] | 367 | {
|
---|
[55742] | 368 | /* Mark serialization started: */
|
---|
| 369 | m_fSerializationIsInProgress = true;
|
---|
[54921] | 370 |
|
---|
[55655] | 371 | /* Create the 'settings saver': */
|
---|
| 372 | QPointer<UISettingsSerializerProgress> pDlgSerializeProgress =
|
---|
| 373 | new UISettingsSerializerProgress(this, UISettingsSerializer::Save,
|
---|
| 374 | data, m_pSelector->settingPages());
|
---|
| 375 | AssertPtrReturnVoid(static_cast<UISettingsSerializerProgress*>(pDlgSerializeProgress));
|
---|
[54923] | 376 | {
|
---|
[55655] | 377 | /* Make the 'settings saver' temporary parent for all sub-dialogs: */
|
---|
| 378 | windowManager().registerNewParent(pDlgSerializeProgress, windowManager().realParentWindow(this));
|
---|
| 379 |
|
---|
| 380 | /* Execute the 'settings saver': */
|
---|
| 381 | pDlgSerializeProgress->exec();
|
---|
| 382 |
|
---|
| 383 | /* Any modal dialog can be destroyed in own event-loop
|
---|
| 384 | * as a part of application termination procedure..
|
---|
| 385 | * We have to check if the dialog still valid. */
|
---|
| 386 | if (pDlgSerializeProgress)
|
---|
| 387 | {
|
---|
[65600] | 388 | /* Remember whether the serialization was clean: */
|
---|
| 389 | m_fSerializationClean = pDlgSerializeProgress->isClean();
|
---|
| 390 |
|
---|
[55655] | 391 | /* Upload 'settings saver' data: */
|
---|
| 392 | data = pDlgSerializeProgress->data();
|
---|
| 393 |
|
---|
| 394 | /* Delete the 'settings saver': */
|
---|
| 395 | delete pDlgSerializeProgress;
|
---|
| 396 | }
|
---|
[54923] | 397 | }
|
---|
[37138] | 398 | }
|
---|
| 399 |
|
---|
[72059] | 400 | void UISettingsDialog::setConfigurationAccessLevel(ConfigurationAccessLevel enmConfigurationAccessLevel)
|
---|
[25177] | 401 | {
|
---|
[50906] | 402 | /* Make sure something changed: */
|
---|
[72059] | 403 | if (m_enmConfigurationAccessLevel == enmConfigurationAccessLevel)
|
---|
[50906] | 404 | return;
|
---|
[45198] | 405 |
|
---|
[50906] | 406 | /* Apply new configuration access level: */
|
---|
[72059] | 407 | m_enmConfigurationAccessLevel = enmConfigurationAccessLevel;
|
---|
[50906] | 408 |
|
---|
| 409 | /* And propagate it to settings-page(s): */
|
---|
[45198] | 410 | foreach (UISettingsPage *pPage, m_pSelector->settingPages())
|
---|
[50906] | 411 | pPage->setConfigurationAccessLevel(configurationAccessLevel());
|
---|
[37109] | 412 | }
|
---|
| 413 |
|
---|
[32667] | 414 | void UISettingsDialog::addItem(const QString &strBigIcon,
|
---|
[51287] | 415 | const QString &strMediumIcon,
|
---|
[32667] | 416 | const QString &strSmallIcon,
|
---|
| 417 | int cId,
|
---|
| 418 | const QString &strLink,
|
---|
[32814] | 419 | UISettingsPage *pSettingsPage /* = 0 */,
|
---|
[32667] | 420 | int iParentId /* = -1 */)
|
---|
[25177] | 421 | {
|
---|
[45198] | 422 | /* Add new selector item: */
|
---|
[51287] | 423 | if (QWidget *pPage = m_pSelector->addItem(strBigIcon, strMediumIcon, strSmallIcon,
|
---|
[45198] | 424 | cId, strLink, pSettingsPage, iParentId))
|
---|
[34004] | 425 | {
|
---|
[45198] | 426 | /* Add stack-widget page if created: */
|
---|
[34004] | 427 | m_pages[cId] = m_pStack->addWidget(pPage);
|
---|
| 428 | }
|
---|
[45198] | 429 | /* Assign validator if necessary: */
|
---|
[32667] | 430 | if (pSettingsPage)
|
---|
[47846] | 431 | {
|
---|
| 432 | pSettingsPage->setId(cId);
|
---|
[32667] | 433 | assignValidator(pSettingsPage);
|
---|
[47846] | 434 | }
|
---|
[25177] | 435 | }
|
---|
| 436 |
|
---|
[47559] | 437 | void UISettingsDialog::revalidate(UIPageValidator *pValidator)
|
---|
| 438 | {
|
---|
| 439 | /* Perform page revalidation: */
|
---|
| 440 | UISettingsPage *pSettingsPage = pValidator->page();
|
---|
[47944] | 441 | QList<UIValidationMessage> messages;
|
---|
| 442 | bool fIsValid = pSettingsPage->validate(messages);
|
---|
[47559] | 443 |
|
---|
| 444 | /* Remember revalidation result: */
|
---|
| 445 | pValidator->setValid(fIsValid);
|
---|
| 446 |
|
---|
| 447 | /* Remember warning/error message: */
|
---|
[47944] | 448 | if (messages.isEmpty())
|
---|
[47559] | 449 | pValidator->setLastMessage(QString());
|
---|
| 450 | else
|
---|
| 451 | {
|
---|
[47944] | 452 | /* Prepare title prefix: */
|
---|
| 453 | // Its the only thing preventing us from moving this method to validator.
|
---|
| 454 | const QString strTitlePrefix(m_pSelector->itemTextByPage(pSettingsPage));
|
---|
| 455 | /* Prepare text: */
|
---|
| 456 | QStringList text;
|
---|
| 457 | foreach (const UIValidationMessage &message, messages)
|
---|
| 458 | {
|
---|
| 459 | /* Prepare title: */
|
---|
| 460 | const QString strTitle(message.first.isNull() ? tr("<b>%1</b> page:").arg(strTitlePrefix) :
|
---|
| 461 | tr("<b>%1: %2</b> page:").arg(strTitlePrefix, message.first));
|
---|
| 462 | /* Prepare paragraph: */
|
---|
| 463 | QStringList paragraph(message.second);
|
---|
| 464 | paragraph.prepend(strTitle);
|
---|
| 465 | /* Format text for iterated message: */
|
---|
| 466 | text << paragraph.join("<br>");
|
---|
| 467 | }
|
---|
| 468 | /* Remember text: */
|
---|
| 469 | pValidator->setLastMessage(text.join("<br><br>"));
|
---|
[49050] | 470 | LogRelFlow(("Settings Dialog: Page validation FAILED: {%s}\n",
|
---|
| 471 | pValidator->lastMessage().toUtf8().constData()));
|
---|
[47559] | 472 | }
|
---|
| 473 | }
|
---|
| 474 |
|
---|
| 475 | void UISettingsDialog::revalidate()
|
---|
| 476 | {
|
---|
| 477 | /* Perform dialog revalidation: */
|
---|
| 478 | m_fValid = true;
|
---|
| 479 | m_fSilent = true;
|
---|
[47846] | 480 | m_pWarningPane->setWarningLabel(QString());
|
---|
[47559] | 481 |
|
---|
| 482 | /* Enumerating all the validators we have: */
|
---|
| 483 | QList<UIPageValidator*> validators(findChildren<UIPageValidator*>());
|
---|
| 484 | foreach (UIPageValidator *pValidator, validators)
|
---|
| 485 | {
|
---|
| 486 | /* Is current validator have something to say? */
|
---|
| 487 | if (!pValidator->lastMessage().isEmpty())
|
---|
| 488 | {
|
---|
| 489 | /* What page is it related to? */
|
---|
| 490 | UISettingsPage *pFailedSettingsPage = pValidator->page();
|
---|
[49050] | 491 | LogRelFlow(("Settings Dialog: Dialog validation FAILED: Page *%s*\n",
|
---|
| 492 | pFailedSettingsPage->internalName().toUtf8().constData()));
|
---|
[47559] | 493 |
|
---|
| 494 | /* Show error first: */
|
---|
| 495 | if (!pValidator->isValid())
|
---|
| 496 | m_fValid = false;
|
---|
| 497 | /* Show warning if message is not an error: */
|
---|
| 498 | else
|
---|
| 499 | m_fSilent = false;
|
---|
| 500 |
|
---|
[47846] | 501 | /* Configure warning-pane label: */
|
---|
| 502 | m_pWarningPane->setWarningLabel(m_strWarningHint);
|
---|
[47595] | 503 |
|
---|
[47559] | 504 | /* Stop dialog revalidation on first error/warning: */
|
---|
[47595] | 505 | break;
|
---|
[47559] | 506 | }
|
---|
| 507 | }
|
---|
| 508 |
|
---|
[47806] | 509 | /* Make sure warning-pane visible if necessary: */
|
---|
[47559] | 510 | if ((!m_fValid || !m_fSilent) && m_pStatusBar->currentIndex() == 0)
|
---|
| 511 | m_pStatusBar->setCurrentWidget(m_pWarningPane);
|
---|
[47806] | 512 | /* Make sure empty-pane visible otherwise: */
|
---|
[47559] | 513 | else if (m_fValid && m_fSilent && m_pStatusBar->currentWidget() == m_pWarningPane)
|
---|
| 514 | m_pStatusBar->setCurrentIndex(0);
|
---|
| 515 |
|
---|
| 516 | /* Lock/unlock settings-page OK button according global validity status: */
|
---|
| 517 | m_pButtonBox->button(QDialogButtonBox::Ok)->setEnabled(m_fValid);
|
---|
| 518 | }
|
---|
| 519 |
|
---|
| 520 | void UISettingsDialog::sltHandleValidityChange(UIPageValidator *pValidator)
|
---|
| 521 | {
|
---|
| 522 | /* Determine which settings-page had called for revalidation: */
|
---|
[47563] | 523 | if (UISettingsPage *pSettingsPage = pValidator->page())
|
---|
[25177] | 524 | {
|
---|
[47563] | 525 | /* Determine settings-page name: */
|
---|
[47595] | 526 | const QString strPageName(pSettingsPage->internalName());
|
---|
[25177] | 527 |
|
---|
[49050] | 528 | LogRelFlow(("Settings Dialog: %s Page: Revalidation in progress..\n",
|
---|
| 529 | strPageName.toUtf8().constData()));
|
---|
[25177] | 530 |
|
---|
[47563] | 531 | /* Perform page revalidation: */
|
---|
| 532 | revalidate(pValidator);
|
---|
| 533 | /* Perform inter-page recorrelation: */
|
---|
| 534 | recorrelate(pSettingsPage);
|
---|
| 535 | /* Perform dialog revalidation: */
|
---|
| 536 | revalidate();
|
---|
[25177] | 537 |
|
---|
[49050] | 538 | LogRelFlow(("Settings Dialog: %s Page: Revalidation complete.\n",
|
---|
| 539 | strPageName.toUtf8().constData()));
|
---|
[25177] | 540 | }
|
---|
| 541 | }
|
---|
| 542 |
|
---|
[47846] | 543 | void UISettingsDialog::sltHandleWarningPaneHovered(UIPageValidator *pValidator)
|
---|
[47763] | 544 | {
|
---|
[49050] | 545 | LogRelFlow(("Settings Dialog: Warning-icon hovered: %s.\n", pValidator->internalName().toUtf8().constData()));
|
---|
[47763] | 546 |
|
---|
| 547 | /* Show corresponding popup: */
|
---|
| 548 | if (!m_fValid || !m_fSilent)
|
---|
| 549 | {
|
---|
| 550 | popupCenter().popup(m_pStack, "SettingsDialogWarning",
|
---|
[47846] | 551 | pValidator->lastMessage());
|
---|
[47763] | 552 | }
|
---|
| 553 | }
|
---|
| 554 |
|
---|
[47846] | 555 | void UISettingsDialog::sltHandleWarningPaneUnhovered(UIPageValidator *pValidator)
|
---|
[47763] | 556 | {
|
---|
[49050] | 557 | LogRelFlow(("Settings Dialog: Warning-icon unhovered: %s.\n", pValidator->internalName().toUtf8().constData()));
|
---|
[47763] | 558 |
|
---|
| 559 | /* Recall corresponding popup: */
|
---|
| 560 | popupCenter().recall(m_pStack, "SettingsDialogWarning");
|
---|
| 561 | }
|
---|
| 562 |
|
---|
[72059] | 563 | void UISettingsDialog::sltUpdateWhatsThis(bool fGotFocus)
|
---|
[25177] | 564 | {
|
---|
[32667] | 565 | QString strWhatsThisText;
|
---|
| 566 | QWidget *pWhatsThisWidget = 0;
|
---|
[25177] | 567 |
|
---|
[32667] | 568 | /* If focus had NOT changed: */
|
---|
| 569 | if (!fGotFocus)
|
---|
[25177] | 570 | {
|
---|
[32667] | 571 | /* We will use the recommended candidate: */
|
---|
| 572 | if (m_pWhatsThisCandidate && m_pWhatsThisCandidate != this)
|
---|
| 573 | pWhatsThisWidget = m_pWhatsThisCandidate;
|
---|
[25177] | 574 | }
|
---|
[32667] | 575 | /* If focus had changed: */
|
---|
[25177] | 576 | else
|
---|
| 577 | {
|
---|
[32667] | 578 | /* We will use the focused widget instead: */
|
---|
| 579 | pWhatsThisWidget = QApplication::focusWidget();
|
---|
[25177] | 580 | }
|
---|
| 581 |
|
---|
[32667] | 582 | /* If the given widget lacks the whats-this text, look at its parent: */
|
---|
| 583 | while (pWhatsThisWidget && pWhatsThisWidget != this)
|
---|
[25177] | 584 | {
|
---|
[32667] | 585 | strWhatsThisText = pWhatsThisWidget->whatsThis();
|
---|
| 586 | if (!strWhatsThisText.isEmpty())
|
---|
[25177] | 587 | break;
|
---|
[32667] | 588 | pWhatsThisWidget = pWhatsThisWidget->parentWidget();
|
---|
[25177] | 589 | }
|
---|
| 590 |
|
---|
[32667] | 591 | if (pWhatsThisWidget && !strWhatsThisText.isEmpty())
|
---|
| 592 | pWhatsThisWidget->setToolTip(QString("<qt>%1</qt>").arg(strWhatsThisText));
|
---|
[25177] | 593 | }
|
---|
| 594 |
|
---|
[72059] | 595 | void UISettingsDialog::prepare()
|
---|
[35131] | 596 | {
|
---|
[72059] | 597 | /* Apply UI decorations: */
|
---|
| 598 | Ui::UISettingsDialog::setupUi(this);
|
---|
[35131] | 599 |
|
---|
[72059] | 600 | /* Configure title: */
|
---|
| 601 | if (m_pLbTitle)
|
---|
| 602 | {
|
---|
| 603 | /* Page-title font is bold and larger but derived from the system font: */
|
---|
| 604 | QFont pageTitleFont = font();
|
---|
| 605 | pageTitleFont.setBold(true);
|
---|
| 606 | pageTitleFont.setPointSize(pageTitleFont.pointSize() + 2);
|
---|
| 607 | m_pLbTitle->setFont(pageTitleFont);
|
---|
| 608 | }
|
---|
[25177] | 609 |
|
---|
[72059] | 610 | /* Prepare selector: */
|
---|
| 611 | QGridLayout *pMainLayout = static_cast<QGridLayout*>(centralWidget()->layout());
|
---|
| 612 | if (pMainLayout)
|
---|
| 613 | {
|
---|
| 614 | #ifdef VBOX_GUI_WITH_TOOLBAR_SETTINGS
|
---|
[25177] | 615 |
|
---|
[72059] | 616 | /* No page-title with tool-bar: */
|
---|
| 617 | m_pLbTitle->hide();
|
---|
| 618 |
|
---|
| 619 | /* Create modern tool-bar selector: */
|
---|
| 620 | m_pSelector = new UISettingsSelectorToolBar(this);
|
---|
| 621 | if (m_pSelector)
|
---|
[25177] | 622 | {
|
---|
[72059] | 623 | /* Configure tool-bar: */
|
---|
| 624 | static_cast<UIToolBar*>(m_pSelector->widget())->enableMacToolbar();
|
---|
[25177] | 625 |
|
---|
[72059] | 626 | /* Add tool-bar into page: */
|
---|
| 627 | addToolBar(qobject_cast<QToolBar*>(m_pSelector->widget()));
|
---|
[25177] | 628 | }
|
---|
[72059] | 629 |
|
---|
| 630 | /* No title in this mode, we change the title of the window: */
|
---|
| 631 | pMainLayout->setColumnMinimumWidth(0, 0);
|
---|
| 632 | pMainLayout->setHorizontalSpacing(0);
|
---|
| 633 |
|
---|
| 634 | #else /* !VBOX_GUI_WITH_TOOLBAR_SETTINGS */
|
---|
| 635 |
|
---|
| 636 | /* Create classical tree-view selector: */
|
---|
| 637 | m_pSelector = new UISettingsSelectorTreeView(this);
|
---|
| 638 | if (m_pSelector)
|
---|
[25177] | 639 | {
|
---|
[72059] | 640 | /* Add into layout: */
|
---|
| 641 | pMainLayout->addWidget(m_pSelector->widget(), 0, 0, 2, 1);
|
---|
| 642 |
|
---|
| 643 | /* Set focus: */
|
---|
| 644 | m_pSelector->widget()->setFocus();
|
---|
[25177] | 645 | }
|
---|
| 646 |
|
---|
[72059] | 647 | #endif /* !VBOX_GUI_WITH_TOOLBAR_SETTINGS */
|
---|
[25177] | 648 |
|
---|
[72059] | 649 | connect(m_pSelector, SIGNAL(sigCategoryChanged(int)), this, SLOT(sltCategoryChanged(int)));
|
---|
| 650 | }
|
---|
[32667] | 651 |
|
---|
[72059] | 652 | /* Prepare stack-handler: */
|
---|
| 653 | if (m_pWtStackHandler)
|
---|
| 654 | {
|
---|
| 655 | /* Create page-stack layout: */
|
---|
| 656 | QVBoxLayout *pStackLayout = new QVBoxLayout(m_pWtStackHandler);
|
---|
| 657 | if (pStackLayout)
|
---|
| 658 | {
|
---|
| 659 | /* Confugre page-stack layout: */
|
---|
| 660 | pStackLayout->setContentsMargins(0, 0, 0, 0);
|
---|
[25177] | 661 |
|
---|
[72059] | 662 | /* Create page-stack: */
|
---|
| 663 | m_pStack = new QStackedWidget;
|
---|
| 664 | if (m_pStack)
|
---|
| 665 | {
|
---|
| 666 | /* Configure page-stack: */
|
---|
| 667 | popupCenter().setPopupStackOrientation(m_pStack, UIPopupStackOrientation_Bottom);
|
---|
[25177] | 668 |
|
---|
[72059] | 669 | /* Add into layout: */
|
---|
| 670 | pStackLayout->addWidget(m_pStack);
|
---|
| 671 | }
|
---|
| 672 | }
|
---|
| 673 | }
|
---|
[25177] | 674 |
|
---|
[72059] | 675 | /* Prepare button-box: */
|
---|
| 676 | if (m_pButtonBox)
|
---|
[59727] | 677 | {
|
---|
[72059] | 678 | m_pButtonBox->button(QDialogButtonBox::Ok)->setDefault(true);
|
---|
| 679 | connect(m_pButtonBox, &QIDialogButtonBox::helpRequested,
|
---|
| 680 | &msgCenter(), &UIMessageCenter::sltShowHelpHelpDialog);
|
---|
[59727] | 681 |
|
---|
[72059] | 682 | /* Create status-bar: */
|
---|
| 683 | m_pStatusBar = new QStackedWidget;
|
---|
| 684 | if (m_pStatusBar)
|
---|
[59727] | 685 | {
|
---|
[72059] | 686 | /* Add empty widget: */
|
---|
| 687 | m_pStatusBar->addWidget(new QWidget);
|
---|
[59727] | 688 |
|
---|
[72059] | 689 | /* Create process-bar: */
|
---|
| 690 | m_pProcessBar = new QProgressBar;
|
---|
| 691 | if (m_pProcessBar)
|
---|
| 692 | {
|
---|
| 693 | /* Configure process-bar: */
|
---|
| 694 | m_pProcessBar->setMinimum(0);
|
---|
| 695 | m_pProcessBar->setMaximum(100);
|
---|
[59727] | 696 |
|
---|
[72059] | 697 | /* Add into status-bar: */
|
---|
| 698 | m_pStatusBar->addWidget(m_pProcessBar);
|
---|
| 699 | }
|
---|
| 700 |
|
---|
| 701 | /* Create warning-pane: */
|
---|
| 702 | m_pWarningPane = new UIWarningPane;
|
---|
| 703 | if (m_pWarningPane)
|
---|
| 704 | {
|
---|
| 705 | /* Configure warning-pane: */
|
---|
| 706 | connect(m_pWarningPane, &UIWarningPane::sigHoverEnter,
|
---|
| 707 | this, &UISettingsDialog::sltHandleWarningPaneHovered);
|
---|
| 708 | connect(m_pWarningPane, &UIWarningPane::sigHoverLeave,
|
---|
| 709 | this, &UISettingsDialog::sltHandleWarningPaneUnhovered);
|
---|
| 710 |
|
---|
| 711 | /* Add into status-bar: */
|
---|
| 712 | m_pStatusBar->addWidget(m_pWarningPane);
|
---|
| 713 | }
|
---|
| 714 |
|
---|
| 715 | /* Add status-bar to button-box: */
|
---|
| 716 | m_pButtonBox->addExtraWidget(m_pStatusBar);
|
---|
| 717 | }
|
---|
[59727] | 718 | }
|
---|
| 719 |
|
---|
[72059] | 720 | /* Setup what's this stuff: */
|
---|
| 721 | qApp->installEventFilter(this);
|
---|
| 722 | m_pWhatsThisTimer->setSingleShot(true);
|
---|
| 723 | connect(m_pWhatsThisTimer, &QTimer::timeout,
|
---|
| 724 | this, &UISettingsDialog::sltUpdateWhatsThisNoFocus);
|
---|
| 725 |
|
---|
| 726 | /* Apply language settings: */
|
---|
| 727 | retranslateUi();
|
---|
[25177] | 728 | }
|
---|
| 729 |
|
---|
[32814] | 730 | void UISettingsDialog::assignValidator(UISettingsPage *pPage)
|
---|
[25177] | 731 | {
|
---|
[47559] | 732 | /* Assign validator: */
|
---|
| 733 | UIPageValidator *pValidator = new UIPageValidator(this, pPage);
|
---|
| 734 | connect(pValidator, SIGNAL(sigValidityChanged(UIPageValidator*)), this, SLOT(sltHandleValidityChange(UIPageValidator*)));
|
---|
| 735 | pPage->setValidator(pValidator);
|
---|
[47846] | 736 | m_pWarningPane->registerValidator(pValidator);
|
---|
[47559] | 737 |
|
---|
[63567] | 738 | /// @todo Why here?
|
---|
[47559] | 739 | /* Configure navigation (tab-order): */
|
---|
[32667] | 740 | pPage->setOrderAfter(m_pSelector->widget());
|
---|
[25177] | 741 | }
|
---|