Changeset 65685 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Feb 8, 2017 3:55:22 PM (8 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/settings/global
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsInput.cpp
r65679 r65685 54 54 55 55 56 /** Global settings: Input page: Shortcut cell cachestructure. */57 class UI ShortcutCacheCell : public QITableViewCell56 /** Global settings: Input page: Shortcut cell data structure. */ 57 class UIDataShortcutCell : public QITableViewCell 58 58 { 59 59 Q_OBJECT; … … 64 64 * @param pParent Brings the row this cell belongs too. 65 65 * @param strText Brings the text describing this cell. */ 66 UI ShortcutCacheCell(QITableViewRow *pParent, const QString &strText)66 UIDataShortcutCell(QITableViewRow *pParent, const QString &strText) 67 67 : QITableViewCell(pParent) 68 68 , m_strText(strText) … … 79 79 80 80 81 /** Global settings: Input page: Shortcut cachestructure. */82 class UI ShortcutCacheRow : public QITableViewRow81 /** Global settings: Input page: Shortcut data structure. */ 82 class UIDataShortcutRow : public QITableViewRow 83 83 { 84 84 Q_OBJECT; … … 92 92 * @param strCurrentSequence Brings the current held sequence. 93 93 * @param strDefaultSequence Brings the default held sequence. */ 94 UI ShortcutCacheRow(QITableView *pParent,94 UIDataShortcutRow(QITableView *pParent, 95 95 const QString &strKey, 96 96 const QString &strDescription, … … 108 108 109 109 /** Constructs table row on the basis of @a other one. */ 110 UI ShortcutCacheRow(const UIShortcutCacheRow &other)110 UIDataShortcutRow(const UIDataShortcutRow &other) 111 111 : QITableViewRow(other.table()) 112 112 , m_strKey(other.key()) … … 120 120 121 121 /** Destructs table row. */ 122 ~UI ShortcutCacheRow()122 ~UIDataShortcutRow() 123 123 { 124 124 /* Destroy cells: */ … … 127 127 128 128 /** Copies a table row from @a other one. */ 129 UI ShortcutCacheRow &operator=(const UIShortcutCacheRow &other)129 UIDataShortcutRow &operator=(const UIDataShortcutRow &other) 130 130 { 131 131 /* Reassign variables: */ … … 145 145 146 146 /** Returns whether this row equals to @a other. */ 147 bool operator==(const UI ShortcutCacheRow &other) const147 bool operator==(const UIDataShortcutRow &other) const 148 148 { 149 149 /* Compare by the key only: */ … … 189 189 { 190 190 /* Create cells on the basis of description and current sequence: */ 191 m_cells = qMakePair(new UI ShortcutCacheCell(this, m_strDescription),192 new UI ShortcutCacheCell(this, m_strCurrentSequence));191 m_cells = qMakePair(new UIDataShortcutCell(this, m_strDescription), 192 new UIDataShortcutCell(this, m_strCurrentSequence)); 193 193 } 194 194 … … 213 213 214 214 /** Holds the cell instances. */ 215 QPair<UI ShortcutCacheCell*, UIShortcutCacheCell*> m_cells;215 QPair<UIDataShortcutCell*, UIDataShortcutCell*> m_cells; 216 216 }; 217 typedef QList<UI ShortcutCacheRow> UIShortcutCache;218 219 220 /** Global settings: Input page cachestructure. */221 class UI SettingsCacheGlobalInput217 typedef QList<UIDataShortcutRow> UIShortcutCache; 218 219 220 /** Global settings: Input page data structure. */ 221 class UIDataSettingsGlobalInput 222 222 { 223 223 public: 224 224 225 225 /** Constructs cache. */ 226 UI SettingsCacheGlobalInput()226 UIDataSettingsGlobalInput() 227 227 : m_fAutoCapture(false) 228 228 {} … … 230 230 /** Returns the shortcuts cache [full access]. */ 231 231 UIShortcutCache &shortcuts() { return m_shortcuts; } 232 /** Returns the shortcuts cache [read-only access]. */ 233 const UIShortcutCache &shortcuts() const { return m_shortcuts; } 232 234 233 235 /** Defines whether the keyboard auto-capture is @a fEnabled. */ … … 235 237 /** Returns whether the keyboard auto-capture is enabled. */ 236 238 bool autoCapture() const { return m_fAutoCapture; } 239 240 /** Returns whether the @a other passed data is equal to this one. */ 241 bool equal(const UIDataSettingsGlobalInput &other) const 242 { 243 return (m_shortcuts == other.m_shortcuts) && 244 (m_fAutoCapture == other.m_fAutoCapture); 245 } 246 247 /** Returns whether the @a other passed data is equal to this one. */ 248 bool operator==(const UIDataSettingsGlobalInput &other) const { return equal(other); } 249 /** Returns whether the @a other passed data is different from this one. */ 250 bool operator!=(const UIDataSettingsGlobalInput &other) const { return !equal(other); } 237 251 238 252 private: … … 261 275 /** Returns whether the @a item1 is more/less than the @a item2. 262 276 * @note Order depends on the one set through constructor, stored in m_order. */ 263 bool operator()(const UI ShortcutCacheRow &item1, const UIShortcutCacheRow &item2)277 bool operator()(const UIDataShortcutRow &item1, const UIDataShortcutRow &item2) 264 278 { 265 279 switch (m_iColumn) … … 401 415 { 402 416 /* Load shortcuts: */ 403 foreach (const UI ShortcutCacheRow &item, shortcuts)417 foreach (const UIDataShortcutRow &item, shortcuts) 404 418 { 405 419 /* Filter out unnecessary shortcuts: */ … … 419 433 { 420 434 /* Save model items: */ 421 foreach (const UI ShortcutCacheRow &item, m_shortcuts)435 foreach (const UIDataShortcutRow &item, m_shortcuts) 422 436 { 423 437 /* Search for corresponding cache item index: */ … … 435 449 /* Enumerate all the sequences: */ 436 450 QMap<QString, QString> usedSequences; 437 foreach (const UI ShortcutCacheRow &item, m_shortcuts)451 foreach (const UIDataShortcutRow &item, m_shortcuts) 438 452 if (!item.currentSequence().isEmpty()) 439 453 usedSequences.insertMulti(item.currentSequence(), item.key()); … … 624 638 int iIndex = index.row(); 625 639 /* Set sequence to shortcut: */ 626 UI ShortcutCacheRow &filteredShortcut = m_filteredShortcuts[iIndex];640 UIDataShortcutRow &filteredShortcut = m_filteredShortcuts[iIndex]; 627 641 int iShortcutIndex = m_shortcuts.indexOf(filteredShortcut); 628 642 if (iShortcutIndex != -1) … … 652 666 qStableSort(m_shortcuts.begin(), m_shortcuts.end(), UIShortcutCacheItemFunctor(iColumn, order)); 653 667 /* Make sure host-combo item is always the first one: */ 654 UI ShortcutCacheRow fakeHostComboItem(0, UIHostCombo::hostComboCacheKey(), QString(), QString(), QString());668 UIDataShortcutRow fakeHostComboItem(0, UIHostCombo::hostComboCacheKey(), QString(), QString(), QString()); 655 669 int iIndexOfHostComboItem = m_shortcuts.indexOf(fakeHostComboItem); 656 670 if (iIndexOfHostComboItem != -1) 657 671 { 658 UI ShortcutCacheRow hostComboItem = m_shortcuts.takeAt(iIndexOfHostComboItem);672 UIDataShortcutRow hostComboItem = m_shortcuts.takeAt(iIndexOfHostComboItem); 659 673 m_shortcuts.prepend(hostComboItem); 660 674 } … … 684 698 { 685 699 /* Check if the description matches the filter: */ 686 foreach (const UI ShortcutCacheRow &item, m_shortcuts)700 foreach (const UIDataShortcutRow &item, m_shortcuts) 687 701 { 688 702 /* If neither description nor sequence matches the filter, skip item: */ … … 876 890 UISettingsPageGlobal::fetchData(data); 877 891 878 /* Load to cache: */ 879 m_pCache->shortcuts() << UIShortcutCacheRow(m_pMachineTable, UIHostCombo::hostComboCacheKey(), tr("Host Key Combination"), m_settings.hostCombo(), QString()); 880 const QMap<QString, UIShortcut>& shortcuts = gShortcutPool->shortcuts(); 892 /* Clear cache initially: */ 893 m_pCache->clear(); 894 895 /* Prepare old data: */ 896 UIDataSettingsGlobalInput oldData; 897 898 /* Gather old data: */ 899 oldData.shortcuts() << UIDataShortcutRow(m_pMachineTable, UIHostCombo::hostComboCacheKey(), tr("Host Key Combination"), m_settings.hostCombo(), QString()); 900 const QMap<QString, UIShortcut> &shortcuts = gShortcutPool->shortcuts(); 881 901 const QList<QString> shortcutKeys = shortcuts.keys(); 882 902 foreach (const QString &strShortcutKey, shortcutKeys) … … 886 906 strShortcutKey.startsWith(GUI_Input_SelectorShortcuts) ? m_pSelectorTable : 0; 887 907 AssertPtr(pParent); 888 m_pCache->shortcuts() << UIShortcutCacheRow(pParent, strShortcutKey, VBoxGlobal::removeAccelMark(shortcut.description()), 889 shortcut.sequence().toString(QKeySequence::NativeText), 890 shortcut.defaultSequence().toString(QKeySequence::NativeText)); 891 } 892 m_pCache->setAutoCapture(m_settings.autoCapture()); 908 oldData.shortcuts() << UIDataShortcutRow(pParent, strShortcutKey, VBoxGlobal::removeAccelMark(shortcut.description()), 909 shortcut.sequence().toString(QKeySequence::NativeText), 910 shortcut.defaultSequence().toString(QKeySequence::NativeText)); 911 } 912 oldData.setAutoCapture(m_settings.autoCapture()); 913 914 /* Cache old data: */ 915 m_pCache->cacheInitialData(oldData); 893 916 894 917 /* Upload properties & settings to data: */ … … 898 921 void UIGlobalSettingsInput::getFromCache() 899 922 { 900 /* Fetch from cache: */ 901 m_pSelectorModel->load(m_pCache->shortcuts()); 902 m_pMachineModel->load(m_pCache->shortcuts()); 903 m_pEnableAutoGrabCheckbox->setChecked(m_pCache->autoCapture()); 923 /* Get old data from cache: */ 924 const UIDataSettingsGlobalInput &oldData = m_pCache->base(); 925 926 /* Load old data from cache: */ 927 m_pSelectorModel->load(oldData.shortcuts()); 928 m_pMachineModel->load(oldData.shortcuts()); 929 m_pEnableAutoGrabCheckbox->setChecked(oldData.autoCapture()); 904 930 905 931 /* Revalidate: */ … … 909 935 void UIGlobalSettingsInput::putToCache() 910 936 { 911 /* Upload to cache: */ 912 m_pSelectorModel->save(m_pCache->shortcuts()); 913 m_pMachineModel->save(m_pCache->shortcuts()); 914 m_pCache->setAutoCapture(m_pEnableAutoGrabCheckbox->isChecked()); 937 /* Prepare new data: */ 938 UIDataSettingsGlobalInput newData = m_pCache->base(); 939 940 /* Gather new data: */ 941 m_pSelectorModel->save(newData.shortcuts()); 942 m_pMachineModel->save(newData.shortcuts()); 943 newData.setAutoCapture(m_pEnableAutoGrabCheckbox->isChecked()); 944 945 /* Cache new data: */ 946 m_pCache->cacheCurrentData(newData); 915 947 } 916 948 … … 920 952 UISettingsPageGlobal::fetchData(data); 921 953 922 /* Save from cache: */ 923 UIShortcutCacheRow fakeHostComboItem(0, UIHostCombo::hostComboCacheKey(), QString(), QString(), QString()); 924 int iIndexOfHostComboItem = m_pCache->shortcuts().indexOf(fakeHostComboItem); 925 if (iIndexOfHostComboItem != -1) 926 m_settings.setHostCombo(m_pCache->shortcuts()[iIndexOfHostComboItem].currentSequence()); 927 QMap<QString, QString> sequences; 928 foreach (const UIShortcutCacheRow &item, m_pCache->shortcuts()) 929 sequences.insert(item.key(), item.currentSequence()); 930 gShortcutPool->setOverrides(sequences); 931 m_settings.setAutoCapture(m_pCache->autoCapture()); 954 // WORKAROUND: 955 // For now we are using out-of-the-box Qt functions to search for a corresponding shortcuts. 956 // Those functions assumes that container elements implement operator==() which we can use 957 // either for "index-match" (to just find shortcut item independent on parameters) or for 958 // "full-match" (to find exact shortcut item including all parameters) but not for both, 959 // so since "index-match" is most commonly used, we need separate "full-match" functor 960 // to check whether the shortcut item was changed, for now we can't do that. 961 962 /* Save host-combo shortcut from cache: */ 963 UIDataShortcutRow fakeHostComboItem(0, UIHostCombo::hostComboCacheKey(), QString(), QString(), QString()); 964 //const int iIndexOfHostComboItemBase = m_pCache->base().shortcuts().indexOf(fakeHostComboItem); 965 const int iIndexOfHostComboItemData = m_pCache->data().shortcuts().indexOf(fakeHostComboItem); 966 if ( iIndexOfHostComboItemData != -1 967 //&& iIndexOfHostComboItemData != iIndexOfHostComboItemBase 968 ) 969 m_settings.setHostCombo(m_pCache->data().shortcuts().at(iIndexOfHostComboItemData).currentSequence()); 970 971 /* Save other shortcut sequences from cache: */ 972 QMap<QString, QString> sequencesBase; 973 QMap<QString, QString> sequencesData; 974 foreach (const UIDataShortcutRow &item, m_pCache->base().shortcuts()) 975 sequencesBase.insert(item.key(), item.currentSequence()); 976 foreach (const UIDataShortcutRow &item, m_pCache->data().shortcuts()) 977 sequencesData.insert(item.key(), item.currentSequence()); 978 if (sequencesData != sequencesBase) 979 gShortcutPool->setOverrides(sequencesData); 980 981 /* Save new data from cache: */ 982 if (m_pCache->wasChanged()) 983 { 984 /* Save other things from cache: */ 985 if (m_pCache->data().autoCapture() != m_pCache->base().autoCapture()) 986 m_settings.setAutoCapture(m_pCache->data().autoCapture()); 987 } 932 988 933 989 /* Upload properties & settings to data: */ … … 964 1020 } 965 1021 966 /* Navigation stuff: */967 1022 void UIGlobalSettingsInput::setOrderAfter(QWidget *pWidget) 968 1023 { … … 971 1026 } 972 1027 973 /* Translation stuff: */974 1028 void UIGlobalSettingsInput::retranslateUi() 975 1029 { -
trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsInput.h
r65679 r65685 26 26 class QTabWidget; 27 27 class QLineEdit; 28 class UI SettingsCacheGlobalInput;28 class UIDataSettingsGlobalInput; 29 29 class UIHotKeyTableModel; 30 30 class UIHotKeyTable; 31 typedef UISettingsCache<UIDataSettingsGlobalInput> UISettingsCacheGlobalInput; 31 32 32 33
Note:
See TracChangeset
for help on using the changeset viewer.