Changeset 64170 in vbox
- Timestamp:
- Oct 6, 2016 4:04:57 PM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 111152
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r64163 r64170 555 555 src/selector/UIVirtualBoxEventHandler.cpp \ 556 556 src/selector/UISnapshotPane.cpp \ 557 src/settings/global/UIGlobalSettingsInput.cpp \ 557 558 src/settings/machine/UIMachineSettingsStorage.cpp \ 558 559 src/settings/machine/UIMachineSettingsUSB.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsInput.cpp
r64162 r64170 39 39 #include <QShortcut> 40 40 41 42 41 /* Namespaces: */ 43 42 using namespace UIExtraDataDefs; 44 43 45 44 46 /* Input page constructor: */ 47 UIGlobalSettingsInput::UIGlobalSettingsInput() 48 : m_pTabWidget(0) 49 , m_pSelectorFilterEditor(0), m_pSelectorModel(0), m_pSelectorTable(0) 50 , m_pMachineFilterEditor(0), m_pMachineModel(0), m_pMachineTable(0) 51 { 52 /* Apply UI decorations: */ 53 Ui::UIGlobalSettingsInput::setupUi(this); 54 55 /* Create tab widget: */ 56 m_pTabWidget = new QTabWidget(this); 57 m_pTabWidget->setMinimumWidth(400); 58 m_pMainLayout->addWidget(m_pTabWidget, 0, 0, 1, 2); 59 60 /* Create selector tab: */ 61 QWidget *pSelectorTab = new QWidget; 62 m_pTabWidget->insertTab(UIHotKeyTableIndex_Selector, pSelectorTab, QString()); 63 m_pSelectorFilterEditor = new QLineEdit(pSelectorTab); 64 m_pSelectorModel = new UIHotKeyTableModel(this, UIActionPoolType_Selector); 65 m_pSelectorTable = new UIHotKeyTable(pSelectorTab, m_pSelectorModel, "m_pSelectorTable"); 66 connect(m_pSelectorFilterEditor, SIGNAL(textChanged(const QString &)), 67 m_pSelectorModel, SLOT(sltHandleFilterTextChange(const QString &))); 68 QVBoxLayout *pSelectorLayout = new QVBoxLayout(pSelectorTab); 69 #ifndef VBOX_WS_WIN 70 /* On Windows host that looks ugly, but 71 * On Mac OS X and X11 that deserves it's place. */ 72 pSelectorLayout->setContentsMargins(0, 0, 0, 0); 73 #endif /* !VBOX_WS_WIN */ 74 pSelectorLayout->setSpacing(1); 75 pSelectorLayout->addWidget(m_pSelectorFilterEditor); 76 pSelectorLayout->addWidget(m_pSelectorTable); 77 setTabOrder(m_pTabWidget, m_pSelectorFilterEditor); 78 setTabOrder(m_pSelectorFilterEditor, m_pSelectorTable); 79 80 /* Create machine tab: */ 81 QWidget *pMachineTab = new QWidget; 82 m_pTabWidget->insertTab(UIHotKeyTableIndex_Machine, pMachineTab, QString()); 83 m_pMachineFilterEditor = new QLineEdit(pMachineTab); 84 m_pMachineModel = new UIHotKeyTableModel(this, UIActionPoolType_Runtime); 85 m_pMachineTable = new UIHotKeyTable(pMachineTab, m_pMachineModel, "m_pMachineTable"); 86 connect(m_pMachineFilterEditor, SIGNAL(textChanged(const QString &)), 87 m_pMachineModel, SLOT(sltHandleFilterTextChange(const QString &))); 88 QVBoxLayout *pMachineLayout = new QVBoxLayout(pMachineTab); 89 #ifndef VBOX_WS_WIN 90 /* On Windows host that looks ugly, but 91 * On Mac OS X and X11 that deserves it's place. */ 92 pMachineLayout->setContentsMargins(0, 0, 0, 0); 93 #endif /* !VBOX_WS_WIN */ 94 pMachineLayout->setSpacing(1); 95 pMachineLayout->addWidget(m_pMachineFilterEditor); 96 pMachineLayout->addWidget(m_pMachineTable); 97 setTabOrder(m_pSelectorTable, m_pMachineFilterEditor); 98 setTabOrder(m_pMachineFilterEditor, m_pMachineTable); 99 100 /* In the VM process we start by displaying the machine tab: */ 101 if (VBoxGlobal::instance()->isVMConsoleProcess()) 102 m_pTabWidget->setCurrentWidget(pMachineTab); 103 104 /* Prepare validation: */ 105 prepareValidation(); 106 107 /* Apply language settings: */ 108 retranslateUi(); 109 } 110 111 /* Load data to cache from corresponding external object(s), 112 * this task COULD be performed in other than GUI thread: */ 113 void UIGlobalSettingsInput::loadToCacheFrom(QVariant &data) 114 { 115 /* Fetch data to properties & settings: */ 116 UISettingsPageGlobal::fetchData(data); 117 118 /* Load host-combo shortcut to cache: */ 119 m_cache.m_shortcuts << UIShortcutCacheItem(UIHostCombo::hostComboCacheKey(), tr("Host Key Combination"), m_settings.hostCombo(), QString()); 120 /* Load all other shortcuts to cache: */ 121 const QMap<QString, UIShortcut>& shortcuts = gShortcutPool->shortcuts(); 122 const QList<QString> shortcutKeys = shortcuts.keys(); 123 foreach (const QString &strShortcutKey, shortcutKeys) 124 { 125 const UIShortcut &shortcut = shortcuts[strShortcutKey]; 126 m_cache.m_shortcuts << UIShortcutCacheItem(strShortcutKey, VBoxGlobal::removeAccelMark(shortcut.description()), 127 shortcut.sequence().toString(QKeySequence::NativeText), 128 shortcut.defaultSequence().toString(QKeySequence::NativeText)); 129 } 130 /* Load other things to cache: */ 131 m_cache.m_fAutoCapture = m_settings.autoCapture(); 132 133 /* Upload properties & settings to data: */ 134 UISettingsPageGlobal::uploadData(data); 135 } 136 137 /* Load data to corresponding widgets from cache, 138 * this task SHOULD be performed in GUI thread only: */ 139 void UIGlobalSettingsInput::getFromCache() 140 { 141 /* Fetch from cache: */ 142 m_pSelectorModel->load(m_cache.m_shortcuts); 143 m_pMachineModel->load(m_cache.m_shortcuts); 144 m_pEnableAutoGrabCheckbox->setChecked(m_cache.m_fAutoCapture); 145 146 /* Revalidate: */ 147 revalidate(); 148 } 149 150 /* Save data from corresponding widgets to cache, 151 * this task SHOULD be performed in GUI thread only: */ 152 void UIGlobalSettingsInput::putToCache() 153 { 154 /* Upload to cache: */ 155 m_pSelectorModel->save(m_cache.m_shortcuts); 156 m_pMachineModel->save(m_cache.m_shortcuts); 157 m_cache.m_fAutoCapture = m_pEnableAutoGrabCheckbox->isChecked(); 158 } 159 160 /* Save data from cache to corresponding external object(s), 161 * this task COULD be performed in other than GUI thread: */ 162 void UIGlobalSettingsInput::saveFromCacheTo(QVariant &data) 163 { 164 /* Fetch data to properties & settings: */ 165 UISettingsPageGlobal::fetchData(data); 166 167 /* Save host-combo shortcut from cache: */ 168 UIShortcutCacheItem fakeHostComboItem(UIHostCombo::hostComboCacheKey(), QString(), QString(), QString()); 169 int iIndexOfHostComboItem = m_cache.m_shortcuts.indexOf(fakeHostComboItem); 170 if (iIndexOfHostComboItem != -1) 171 m_settings.setHostCombo(m_cache.m_shortcuts[iIndexOfHostComboItem].currentSequence); 172 /* Iterate over cached shortcuts: */ 173 QMap<QString, QString> sequences; 174 foreach (const UIShortcutCacheItem &item, m_cache.m_shortcuts) 175 sequences.insert(item.key, item.currentSequence); 176 /* Save shortcut sequences from cache: */ 177 gShortcutPool->setOverrides(sequences); 178 /* Save other things from cache: */ 179 m_settings.setAutoCapture(m_cache.m_fAutoCapture); 180 181 /* Upload properties & settings to data: */ 182 UISettingsPageGlobal::uploadData(data); 183 } 184 185 bool UIGlobalSettingsInput::validate(QList<UIValidationMessage> &messages) 186 { 187 /* Pass by default: */ 188 bool fPass = true; 189 190 /* Check VirtualBox Manager page for unique shortcuts: */ 191 if (!m_pSelectorModel->isAllShortcutsUnique()) 192 { 193 UIValidationMessage message; 194 message.first = VBoxGlobal::removeAccelMark(m_pTabWidget->tabText(UIHotKeyTableIndex_Selector)); 195 message.second << tr("Some items have the same shortcuts assigned."); 196 messages << message; 197 fPass = false; 198 } 199 200 /* Check Virtual Machine page for unique shortcuts: */ 201 if (!m_pMachineModel->isAllShortcutsUnique()) 202 { 203 UIValidationMessage message; 204 message.first = VBoxGlobal::removeAccelMark(m_pTabWidget->tabText(UIHotKeyTableIndex_Machine)); 205 message.second << tr("Some items have the same shortcuts assigned."); 206 messages << message; 207 fPass = false; 208 } 209 210 /* Return result: */ 211 return fPass; 212 } 213 214 /* Navigation stuff: */ 215 void UIGlobalSettingsInput::setOrderAfter(QWidget *pWidget) 216 { 217 setTabOrder(pWidget, m_pTabWidget); 218 setTabOrder(m_pMachineTable, m_pEnableAutoGrabCheckbox); 219 } 220 221 /* Translation stuff: */ 222 void UIGlobalSettingsInput::retranslateUi() 223 { 224 /* Translate uic generated strings: */ 225 Ui::UIGlobalSettingsInput::retranslateUi(this); 226 227 /* Translate tab-widget labels: */ 228 m_pTabWidget->setTabText(UIHotKeyTableIndex_Selector, tr("&VirtualBox Manager")); 229 m_pTabWidget->setTabText(UIHotKeyTableIndex_Machine, tr("Virtual &Machine")); 230 m_pSelectorTable->setWhatsThis(tr("Lists all available shortcuts which can be configured.")); 231 m_pMachineTable->setWhatsThis(tr("Lists all available shortcuts which can be configured.")); 232 m_pSelectorFilterEditor->setWhatsThis(tr("Holds a sequence to filter the shortcut list.")); 233 m_pMachineFilterEditor->setWhatsThis(tr("Holds a sequence to filter the shortcut list.")); 234 } 235 236 void UIGlobalSettingsInput::prepareValidation() 237 { 238 /* Prepare validation: */ 239 connect(m_pSelectorModel, SIGNAL(sigRevalidationRequired()), this, SLOT(revalidate())); 240 connect(m_pMachineModel, SIGNAL(sigRevalidationRequired()), this, SLOT(revalidate())); 241 } 242 45 /* Global settings / Input page / Cache / Shortcut cache item sort functor: */ 46 class UIShortcutCacheItemFunctor 47 { 48 public: 49 50 UIShortcutCacheItemFunctor(int iColumn, Qt::SortOrder order) 51 : m_iColumn(iColumn) 52 , m_order(order) 53 { 54 } 55 56 bool operator()(const UIShortcutCacheItem &item1, const UIShortcutCacheItem &item2) 57 { 58 switch (m_iColumn) 59 { 60 case 0: return m_order == Qt::AscendingOrder ? item1.description < item2.description : item1.description > item2.description; 61 case 1: return m_order == Qt::AscendingOrder ? item1.currentSequence < item2.currentSequence : item1.currentSequence > item2.currentSequence; 62 default: break; 63 } 64 return m_order == Qt::AscendingOrder ? item1.key < item2.key : item1.key > item2.key; 65 } 66 67 private: 68 69 int m_iColumn; 70 Qt::SortOrder m_order; 71 }; 72 73 74 /* A model representing hot-key combination table: */ 75 class UIHotKeyTableModel : public QAbstractTableModel 76 { 77 Q_OBJECT; 78 79 signals: 80 81 /* Notifier: Readiness stuff: */ 82 void sigShortcutsLoaded(); 83 84 /* Notifier: Validation stuff: */ 85 void sigRevalidationRequired(); 86 87 public: 88 89 /* Constructor: */ 90 UIHotKeyTableModel(QObject *pParent, UIActionPoolType type); 91 92 /* API: Loading/saving stuff: */ 93 void load(const UIShortcutCache &shortcuts); 94 void save(UIShortcutCache &shortcuts); 95 96 /* API: Validation stuff: */ 97 bool isAllShortcutsUnique(); 98 99 private slots: 100 101 /* Handler: Filtering stuff: */ 102 void sltHandleFilterTextChange(const QString &strText); 103 104 private: 105 106 /* Internal API: Size stuff: */ 107 int rowCount(const QModelIndex &parent = QModelIndex()) const; 108 int columnCount(const QModelIndex &parent = QModelIndex()) const; 109 110 /* Internal API: Data stuff: */ 111 Qt::ItemFlags flags(const QModelIndex &index) const; 112 QVariant headerData(int iSection, Qt::Orientation orientation, int iRole = Qt::DisplayRole) const; 113 QVariant data(const QModelIndex &index, int iRole = Qt::DisplayRole) const; 114 bool setData(const QModelIndex &index, const QVariant &value, int iRole = Qt::EditRole); 115 116 /* Internal API: Sorting stuff: */ 117 void sort(int iColumn, Qt::SortOrder order = Qt::AscendingOrder); 118 119 /* Helper: Filtering stuff: */ 120 void applyFilter(); 121 122 /* Variables: */ 123 UIActionPoolType m_type; 124 QString m_strFilter; 125 UIShortcutCache m_shortcuts; 126 UIShortcutCache m_filteredShortcuts; 127 QSet<QString> m_duplicatedSequences; 128 }; 129 130 131 /* A table reflecting hot-key combinations: */ 132 class UIHotKeyTable : public QTableView 133 { 134 Q_OBJECT; 135 136 public: 137 138 /* Hot-key table field indexes: */ 139 enum Section 140 { 141 Section_Name = 0, 142 Section_Value = 1 143 }; 144 145 /* Constructor: */ 146 UIHotKeyTable(QWidget *pParent, UIHotKeyTableModel *pModel, const QString &strObjectName); 147 148 private slots: 149 150 /* Handler: Readiness stuff: */ 151 void sltHandleShortcutsLoaded(); 152 }; 153 154 155 /********************************************************************************************************************************* 156 * Class UIHotKeyTableModel implementation. * 157 *********************************************************************************************************************************/ 243 158 244 159 UIHotKeyTableModel::UIHotKeyTableModel(QObject *pParent, UIActionPoolType type) … … 329 244 switch (index.column()) 330 245 { 331 case UIHotKeyTable Section_Name: return Qt::ItemIsEnabled | Qt::ItemIsSelectable;332 case UIHotKeyTable Section_Value: return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;246 case UIHotKeyTable::Section_Name: return Qt::ItemIsEnabled | Qt::ItemIsSelectable; 247 case UIHotKeyTable::Section_Value: return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable; 333 248 default: break; 334 249 } … … 349 264 switch (iSection) 350 265 { 351 case UIHotKeyTable Section_Name: return tr("Name");352 case UIHotKeyTable Section_Value: return tr("Shortcut");266 case UIHotKeyTable::Section_Name: return tr("Name"); 267 case UIHotKeyTable::Section_Value: return tr("Shortcut"); 353 268 default: break; 354 269 } … … 375 290 switch (index.column()) 376 291 { 377 case UIHotKeyTable Section_Name:292 case UIHotKeyTable::Section_Name: 378 293 { 379 294 /* Return shortcut description: */ 380 295 return m_filteredShortcuts[iIndex].description; 381 296 } 382 case UIHotKeyTable Section_Value:297 case UIHotKeyTable::Section_Value: 383 298 { 384 299 /* If that is host-combo cell: */ … … 405 320 switch (index.column()) 406 321 { 407 case UIHotKeyTable Section_Value: return m_filteredShortcuts[iIndex].key == UIHostCombo::hostComboCacheKey() ?322 case UIHotKeyTable::Section_Value: return m_filteredShortcuts[iIndex].key == UIHostCombo::hostComboCacheKey() ? 408 323 QVariant::fromValue(UIHostComboWrapper(m_filteredShortcuts[iIndex].currentSequence)) : 409 324 QVariant::fromValue(UIHotKey(m_type == UIActionPoolType_Runtime ? … … 423 338 switch (index.column()) 424 339 { 425 case UIHotKeyTable Section_Value:340 case UIHotKeyTable::Section_Value: 426 341 { 427 342 if (m_filteredShortcuts[iIndex].key != UIHostCombo::hostComboCacheKey() && … … 440 355 switch (index.column()) 441 356 { 442 case UIHotKeyTable Section_Value:357 case UIHotKeyTable::Section_Value: 443 358 { 444 359 if (m_duplicatedSequences.contains(m_filteredShortcuts[iIndex].key)) … … 469 384 switch (index.column()) 470 385 { 471 case UIHotKeyTable Section_Value:386 case UIHotKeyTable::Section_Value: 472 387 { 473 388 /* Get index: */ … … 554 469 555 470 471 /********************************************************************************************************************************* 472 * Class UIHotKeyTable implementation. * 473 *********************************************************************************************************************************/ 474 556 475 UIHotKeyTable::UIHotKeyTable(QWidget *pParent, UIHotKeyTableModel *pModel, const QString &strObjectName) 557 476 : QTableView(pParent) … … 576 495 horizontalHeader()->setStretchLastSection(false); 577 496 #if QT_VERSION >= 0x050000 578 horizontalHeader()->setSectionResizeMode( UIHotKeyTableSection_Name, QHeaderView::Interactive);579 horizontalHeader()->setSectionResizeMode( UIHotKeyTableSection_Value, QHeaderView::Stretch);497 horizontalHeader()->setSectionResizeMode(Section_Name, QHeaderView::Interactive); 498 horizontalHeader()->setSectionResizeMode(Section_Value, QHeaderView::Stretch); 580 499 #else /* QT_VERSION < 0x050000 */ 581 horizontalHeader()->setResizeMode( UIHotKeyTableSection_Name, QHeaderView::Interactive);582 horizontalHeader()->setResizeMode( UIHotKeyTableSection_Value, QHeaderView::Stretch);500 horizontalHeader()->setResizeMode(Section_Name, QHeaderView::Interactive); 501 horizontalHeader()->setResizeMode(Section_Value, QHeaderView::Stretch); 583 502 #endif /* QT_VERSION < 0x050000 */ 584 503 … … 614 533 615 534 /* Configure sorting: */ 616 sortByColumn( UIHotKeyTableSection_Name, Qt::AscendingOrder);535 sortByColumn(Section_Name, Qt::AscendingOrder); 617 536 setSortingEnabled(true); 618 537 } 619 538 539 540 /********************************************************************************************************************************* 541 * Class UIGlobalSettingsInput implementation. * 542 *********************************************************************************************************************************/ 543 544 /* Input page constructor: */ 545 UIGlobalSettingsInput::UIGlobalSettingsInput() 546 : m_pTabWidget(0) 547 , m_pSelectorFilterEditor(0), m_pSelectorModel(0), m_pSelectorTable(0) 548 , m_pMachineFilterEditor(0), m_pMachineModel(0), m_pMachineTable(0) 549 { 550 /* Apply UI decorations: */ 551 Ui::UIGlobalSettingsInput::setupUi(this); 552 553 /* Create tab widget: */ 554 m_pTabWidget = new QTabWidget(this); 555 m_pTabWidget->setMinimumWidth(400); 556 m_pMainLayout->addWidget(m_pTabWidget, 0, 0, 1, 2); 557 558 /* Create selector tab: */ 559 QWidget *pSelectorTab = new QWidget; 560 m_pTabWidget->insertTab(UIHotKeyTableIndex_Selector, pSelectorTab, QString()); 561 m_pSelectorFilterEditor = new QLineEdit(pSelectorTab); 562 m_pSelectorModel = new UIHotKeyTableModel(this, UIActionPoolType_Selector); 563 m_pSelectorTable = new UIHotKeyTable(pSelectorTab, m_pSelectorModel, "m_pSelectorTable"); 564 connect(m_pSelectorFilterEditor, SIGNAL(textChanged(const QString &)), 565 m_pSelectorModel, SLOT(sltHandleFilterTextChange(const QString &))); 566 QVBoxLayout *pSelectorLayout = new QVBoxLayout(pSelectorTab); 567 #ifndef VBOX_WS_WIN 568 /* On Windows host that looks ugly, but 569 * On Mac OS X and X11 that deserves it's place. */ 570 pSelectorLayout->setContentsMargins(0, 0, 0, 0); 571 #endif /* !VBOX_WS_WIN */ 572 pSelectorLayout->setSpacing(1); 573 pSelectorLayout->addWidget(m_pSelectorFilterEditor); 574 pSelectorLayout->addWidget(m_pSelectorTable); 575 setTabOrder(m_pTabWidget, m_pSelectorFilterEditor); 576 setTabOrder(m_pSelectorFilterEditor, m_pSelectorTable); 577 578 /* Create machine tab: */ 579 QWidget *pMachineTab = new QWidget; 580 m_pTabWidget->insertTab(UIHotKeyTableIndex_Machine, pMachineTab, QString()); 581 m_pMachineFilterEditor = new QLineEdit(pMachineTab); 582 m_pMachineModel = new UIHotKeyTableModel(this, UIActionPoolType_Runtime); 583 m_pMachineTable = new UIHotKeyTable(pMachineTab, m_pMachineModel, "m_pMachineTable"); 584 connect(m_pMachineFilterEditor, SIGNAL(textChanged(const QString &)), 585 m_pMachineModel, SLOT(sltHandleFilterTextChange(const QString &))); 586 QVBoxLayout *pMachineLayout = new QVBoxLayout(pMachineTab); 587 #ifndef VBOX_WS_WIN 588 /* On Windows host that looks ugly, but 589 * On Mac OS X and X11 that deserves it's place. */ 590 pMachineLayout->setContentsMargins(0, 0, 0, 0); 591 #endif /* !VBOX_WS_WIN */ 592 pMachineLayout->setSpacing(1); 593 pMachineLayout->addWidget(m_pMachineFilterEditor); 594 pMachineLayout->addWidget(m_pMachineTable); 595 setTabOrder(m_pSelectorTable, m_pMachineFilterEditor); 596 setTabOrder(m_pMachineFilterEditor, m_pMachineTable); 597 598 /* In the VM process we start by displaying the machine tab: */ 599 if (VBoxGlobal::instance()->isVMConsoleProcess()) 600 m_pTabWidget->setCurrentWidget(pMachineTab); 601 602 /* Prepare validation: */ 603 prepareValidation(); 604 605 /* Apply language settings: */ 606 retranslateUi(); 607 } 608 609 /* Load data to cache from corresponding external object(s), 610 * this task COULD be performed in other than GUI thread: */ 611 void UIGlobalSettingsInput::loadToCacheFrom(QVariant &data) 612 { 613 /* Fetch data to properties & settings: */ 614 UISettingsPageGlobal::fetchData(data); 615 616 /* Load host-combo shortcut to cache: */ 617 m_cache.m_shortcuts << UIShortcutCacheItem(UIHostCombo::hostComboCacheKey(), tr("Host Key Combination"), m_settings.hostCombo(), QString()); 618 /* Load all other shortcuts to cache: */ 619 const QMap<QString, UIShortcut>& shortcuts = gShortcutPool->shortcuts(); 620 const QList<QString> shortcutKeys = shortcuts.keys(); 621 foreach (const QString &strShortcutKey, shortcutKeys) 622 { 623 const UIShortcut &shortcut = shortcuts[strShortcutKey]; 624 m_cache.m_shortcuts << UIShortcutCacheItem(strShortcutKey, VBoxGlobal::removeAccelMark(shortcut.description()), 625 shortcut.sequence().toString(QKeySequence::NativeText), 626 shortcut.defaultSequence().toString(QKeySequence::NativeText)); 627 } 628 /* Load other things to cache: */ 629 m_cache.m_fAutoCapture = m_settings.autoCapture(); 630 631 /* Upload properties & settings to data: */ 632 UISettingsPageGlobal::uploadData(data); 633 } 634 635 /* Load data to corresponding widgets from cache, 636 * this task SHOULD be performed in GUI thread only: */ 637 void UIGlobalSettingsInput::getFromCache() 638 { 639 /* Fetch from cache: */ 640 m_pSelectorModel->load(m_cache.m_shortcuts); 641 m_pMachineModel->load(m_cache.m_shortcuts); 642 m_pEnableAutoGrabCheckbox->setChecked(m_cache.m_fAutoCapture); 643 644 /* Revalidate: */ 645 revalidate(); 646 } 647 648 /* Save data from corresponding widgets to cache, 649 * this task SHOULD be performed in GUI thread only: */ 650 void UIGlobalSettingsInput::putToCache() 651 { 652 /* Upload to cache: */ 653 m_pSelectorModel->save(m_cache.m_shortcuts); 654 m_pMachineModel->save(m_cache.m_shortcuts); 655 m_cache.m_fAutoCapture = m_pEnableAutoGrabCheckbox->isChecked(); 656 } 657 658 /* Save data from cache to corresponding external object(s), 659 * this task COULD be performed in other than GUI thread: */ 660 void UIGlobalSettingsInput::saveFromCacheTo(QVariant &data) 661 { 662 /* Fetch data to properties & settings: */ 663 UISettingsPageGlobal::fetchData(data); 664 665 /* Save host-combo shortcut from cache: */ 666 UIShortcutCacheItem fakeHostComboItem(UIHostCombo::hostComboCacheKey(), QString(), QString(), QString()); 667 int iIndexOfHostComboItem = m_cache.m_shortcuts.indexOf(fakeHostComboItem); 668 if (iIndexOfHostComboItem != -1) 669 m_settings.setHostCombo(m_cache.m_shortcuts[iIndexOfHostComboItem].currentSequence); 670 /* Iterate over cached shortcuts: */ 671 QMap<QString, QString> sequences; 672 foreach (const UIShortcutCacheItem &item, m_cache.m_shortcuts) 673 sequences.insert(item.key, item.currentSequence); 674 /* Save shortcut sequences from cache: */ 675 gShortcutPool->setOverrides(sequences); 676 /* Save other things from cache: */ 677 m_settings.setAutoCapture(m_cache.m_fAutoCapture); 678 679 /* Upload properties & settings to data: */ 680 UISettingsPageGlobal::uploadData(data); 681 } 682 683 bool UIGlobalSettingsInput::validate(QList<UIValidationMessage> &messages) 684 { 685 /* Pass by default: */ 686 bool fPass = true; 687 688 /* Check VirtualBox Manager page for unique shortcuts: */ 689 if (!m_pSelectorModel->isAllShortcutsUnique()) 690 { 691 UIValidationMessage message; 692 message.first = VBoxGlobal::removeAccelMark(m_pTabWidget->tabText(UIHotKeyTableIndex_Selector)); 693 message.second << tr("Some items have the same shortcuts assigned."); 694 messages << message; 695 fPass = false; 696 } 697 698 /* Check Virtual Machine page for unique shortcuts: */ 699 if (!m_pMachineModel->isAllShortcutsUnique()) 700 { 701 UIValidationMessage message; 702 message.first = VBoxGlobal::removeAccelMark(m_pTabWidget->tabText(UIHotKeyTableIndex_Machine)); 703 message.second << tr("Some items have the same shortcuts assigned."); 704 messages << message; 705 fPass = false; 706 } 707 708 /* Return result: */ 709 return fPass; 710 } 711 712 /* Navigation stuff: */ 713 void UIGlobalSettingsInput::setOrderAfter(QWidget *pWidget) 714 { 715 setTabOrder(pWidget, m_pTabWidget); 716 setTabOrder(m_pMachineTable, m_pEnableAutoGrabCheckbox); 717 } 718 719 /* Translation stuff: */ 720 void UIGlobalSettingsInput::retranslateUi() 721 { 722 /* Translate uic generated strings: */ 723 Ui::UIGlobalSettingsInput::retranslateUi(this); 724 725 /* Translate tab-widget labels: */ 726 m_pTabWidget->setTabText(UIHotKeyTableIndex_Selector, tr("&VirtualBox Manager")); 727 m_pTabWidget->setTabText(UIHotKeyTableIndex_Machine, tr("Virtual &Machine")); 728 m_pSelectorTable->setWhatsThis(tr("Lists all available shortcuts which can be configured.")); 729 m_pMachineTable->setWhatsThis(tr("Lists all available shortcuts which can be configured.")); 730 m_pSelectorFilterEditor->setWhatsThis(tr("Holds a sequence to filter the shortcut list.")); 731 m_pMachineFilterEditor->setWhatsThis(tr("Holds a sequence to filter the shortcut list.")); 732 } 733 734 void UIGlobalSettingsInput::prepareValidation() 735 { 736 /* Prepare validation: */ 737 connect(m_pSelectorModel, SIGNAL(sigRevalidationRequired()), this, SLOT(revalidate())); 738 connect(m_pMachineModel, SIGNAL(sigRevalidationRequired()), this, SLOT(revalidate())); 739 } 740 741 # include "UIGlobalSettingsInput.moc" 742 -
trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsInput.h
r62493 r64170 74 74 }; 75 75 76 /* Global settings / Input page / Cache / Shortcut cache item sort functor: */77 class UIShortcutCacheItemFunctor78 {79 public:80 81 UIShortcutCacheItemFunctor(int iColumn, Qt::SortOrder order)82 : m_iColumn(iColumn)83 , m_order(order)84 {85 }86 87 bool operator()(const UIShortcutCacheItem &item1, const UIShortcutCacheItem &item2)88 {89 switch (m_iColumn)90 {91 case 0: return m_order == Qt::AscendingOrder ? item1.description < item2.description : item1.description > item2.description;92 case 1: return m_order == Qt::AscendingOrder ? item1.currentSequence < item2.currentSequence : item1.currentSequence > item2.currentSequence;93 default: break;94 }95 return m_order == Qt::AscendingOrder ? item1.key < item2.key : item1.key > item2.key;96 }97 98 private:99 100 int m_iColumn;101 Qt::SortOrder m_order;102 };103 104 76 /* Global settings / Input page / Cache / Shortcut cache: */ 105 77 typedef QList<UIShortcutCacheItem> UIShortcutCache; … … 116 88 { 117 89 Q_OBJECT; 90 91 /* Hot-key table indexes: */ 92 enum UIHotKeyTableIndex 93 { 94 UIHotKeyTableIndex_Selector = 0, 95 UIHotKeyTableIndex_Machine = 1 96 }; 118 97 119 98 public: … … 163 142 }; 164 143 165 /* Hot-key table indexes: */166 enum UIHotKeyTableIndex167 {168 UIHotKeyTableIndex_Selector = 0,169 UIHotKeyTableIndex_Machine = 1170 };171 172 /* Hot-key table field indexes: */173 enum UIHotKeyTableSection174 {175 UIHotKeyTableSection_Name = 0,176 UIHotKeyTableSection_Value = 1177 };178 179 /* A model representing hot-key combination table: */180 class UIHotKeyTableModel : public QAbstractTableModel181 {182 Q_OBJECT;183 184 signals:185 186 /* Notifier: Readiness stuff: */187 void sigShortcutsLoaded();188 189 /* Notifier: Validation stuff: */190 void sigRevalidationRequired();191 192 public:193 194 /* Constructor: */195 UIHotKeyTableModel(QObject *pParent, UIActionPoolType type);196 197 /* API: Loading/saving stuff: */198 void load(const UIShortcutCache &shortcuts);199 void save(UIShortcutCache &shortcuts);200 201 /* API: Validation stuff: */202 bool isAllShortcutsUnique();203 204 private slots:205 206 /* Handler: Filtering stuff: */207 void sltHandleFilterTextChange(const QString &strText);208 209 private:210 211 /* Internal API: Size stuff: */212 int rowCount(const QModelIndex &parent = QModelIndex()) const;213 int columnCount(const QModelIndex &parent = QModelIndex()) const;214 215 /* Internal API: Data stuff: */216 Qt::ItemFlags flags(const QModelIndex &index) const;217 QVariant headerData(int iSection, Qt::Orientation orientation, int iRole = Qt::DisplayRole) const;218 QVariant data(const QModelIndex &index, int iRole = Qt::DisplayRole) const;219 bool setData(const QModelIndex &index, const QVariant &value, int iRole = Qt::EditRole);220 221 /* Internal API: Sorting stuff: */222 void sort(int iColumn, Qt::SortOrder order = Qt::AscendingOrder);223 224 /* Helper: Filtering stuff: */225 void applyFilter();226 227 /* Variables: */228 UIActionPoolType m_type;229 QString m_strFilter;230 UIShortcutCache m_shortcuts;231 UIShortcutCache m_filteredShortcuts;232 QSet<QString> m_duplicatedSequences;233 };234 235 /* A table reflecting hot-key combinations: */236 class UIHotKeyTable : public QTableView237 {238 Q_OBJECT;239 240 public:241 242 /* Constructor: */243 UIHotKeyTable(QWidget *pParent, UIHotKeyTableModel *pModel, const QString &strObjectName);244 245 private slots:246 247 /* Handler: Readiness stuff: */248 void sltHandleShortcutsLoaded();249 };250 251 144 #endif // __UIGlobalSettingsInput_h__ 252 145
Note:
See TracChangeset
for help on using the changeset viewer.