VirtualBox

Changeset 44737 in vbox


Ignore:
Timestamp:
Feb 18, 2013 2:08:20 PM (12 years ago)
Author:
vboxsync
Message:

FE/Qt: 6065: Initial commit of the Global settings / Input page / Shortcut panes.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsInput.cpp

    r44713 r44737  
    2424#include <QStyledItemDelegate>
    2525#include <QItemEditorFactory>
     26#include <QTabWidget>
    2627
    2728/* GUI includes: */
     29#include "QIWidgetValidator.h"
    2830#include "UIGlobalSettingsInput.h"
    2931#include "UIShortcutPool.h"
     
    3436/* Input page constructor: */
    3537UIGlobalSettingsInput::UIGlobalSettingsInput()
     38    : m_pValidator(0)
    3639{
    3740    /* Apply UI decorations: */
    3841    Ui::UIGlobalSettingsInput::setupUi(this);
    3942
    40     /* Set the new shortcut for the eraze-host-combo button: */
    41     m_pResetHostCombinationButton->setShortcut(QKeySequence());
    42     new QShortcut(QKeySequence(Qt::Key_Delete), m_pResetHostCombinationButton, SLOT(animateClick()));
    43     new QShortcut(QKeySequence(Qt::Key_Backspace), m_pResetHostCombinationButton, SLOT(animateClick()));
     43    /* Create selector model/table: */
     44    m_pSelectorModel = new UIHotKeyTableModel(this, UIActionPoolType_Selector);
     45    m_pSelectorTable = new UIHotKeyTable(m_pSelectorModel);
     46    /* Create machine model/table: */
     47    m_pMachineModel = new UIHotKeyTableModel(this, UIActionPoolType_Runtime);
     48    m_pMachineTable = new UIHotKeyTable(m_pMachineModel);
     49
     50    /* Create tab widget layout: */
     51    QVBoxLayout *pVerticalLayout = new QVBoxLayout;
     52    pVerticalLayout->setContentsMargins(0, 0, 0, 0);
     53    pVerticalLayout->setSpacing(1);
     54
     55    /* Create tab widget: */
     56    m_pTabWidget = new QTabWidget(this);
     57    m_pTabWidget->setMinimumWidth(400);
     58    m_pTabWidget->insertTab(UIHotKeyTableIndex_Selector, m_pSelectorTable, QString());
     59    m_pTabWidget->insertTab(UIHotKeyTableIndex_Machine, m_pMachineTable, QString());
     60    pVerticalLayout->addWidget(m_pTabWidget);
     61
     62    /* Create filter edit: */
     63    m_pFilterEditor = new QLineEdit(this);
     64    connect(m_pFilterEditor, SIGNAL(textChanged(const QString &)),
     65            this, SLOT(sltHandleFilterTextChange()));
     66    pVerticalLayout->addWidget(m_pFilterEditor);
     67
     68    /* Add vertical layout into main one: */
     69    m_pMainLayout->addLayout(pVerticalLayout, 0, 0);
    4470
    4571    /* Apply language settings: */
     
    5480    UISettingsPageGlobal::fetchData(data);
    5581
    56     /* Load to cache: */
    57     m_cache.m_strHostCombo = m_settings.hostCombo();
     82    /* Load host-combo shortcut to cache: */
     83    m_cache.m_shortcuts << UIShortcutCacheItem(UIHostCombo::hostComboCacheKey(), tr("Host Combo"),  m_settings.hostCombo(), QString());
     84    /* Load all other shortcuts to cache: */
     85    const QMap<QString, UIShortcut>& shortcuts = gShortcutPool->shortcuts();
     86    const QList<QString> shortcutKeys = shortcuts.keys();
     87    foreach (const QString &strShortcutKey, shortcutKeys)
     88    {
     89        const UIShortcut &shortcut = shortcuts[strShortcutKey];
     90        m_cache.m_shortcuts << UIShortcutCacheItem(strShortcutKey, VBoxGlobal::removeAccelMark(shortcut.description()),
     91                                                   shortcut.sequence().toString(QKeySequence::NativeText),
     92                                                   shortcut.defaultSequence().toString(QKeySequence::NativeText));
     93    }
     94    /* Load other things to cache: */
    5895    m_cache.m_fAutoCapture = m_settings.autoCapture();
    5996
     
    67104{
    68105    /* Fetch from cache: */
    69     m_pHostKeyEditor->setCombo(m_cache.m_strHostCombo);
     106    m_pSelectorModel->load(m_cache.m_shortcuts);
     107    m_pMachineModel->load(m_cache.m_shortcuts);
    70108    m_pEnableAutoGrabCheckbox->setChecked(m_cache.m_fAutoCapture);
     109
     110    /* Revalidate if possible: */
     111    if (m_pValidator)
     112        m_pValidator->revalidate();
    71113}
    72114
     
    76118{
    77119    /* Upload to cache: */
    78     m_cache.m_strHostCombo = m_pHostKeyEditor->combo().toString();
     120    m_pSelectorModel->save(m_cache.m_shortcuts);
     121    m_pMachineModel->save(m_cache.m_shortcuts);
    79122    m_cache.m_fAutoCapture = m_pEnableAutoGrabCheckbox->isChecked();
    80123}
     
    87130    UISettingsPageGlobal::fetchData(data);
    88131
    89     /* Save from cache: */
    90     m_settings.setHostCombo(m_cache.m_strHostCombo);
     132    /* Save host-combo shortcut from cache: */
     133    UIShortcutCacheItem fakeHostComboItem(UIHostCombo::hostComboCacheKey(), QString(), QString(), QString());
     134    int iIndexOfHostComboItem = m_cache.m_shortcuts.indexOf(fakeHostComboItem);
     135    if (iIndexOfHostComboItem != -1)
     136        m_settings.setHostCombo(m_cache.m_shortcuts[iIndexOfHostComboItem].currentSequence);
     137    /* Iterate over cached shortcuts: */
     138    QMap<QString, QString> sequences;
     139    foreach (const UIShortcutCacheItem &item, m_cache.m_shortcuts)
     140        sequences.insert(item.key, item.currentSequence);
     141    /* Save shortcut sequences from cache: */
     142    gShortcutPool->setOverrides(sequences);
     143    /* Save other things from cache: */
    91144    m_settings.setAutoCapture(m_cache.m_fAutoCapture);
    92145
     
    95148}
    96149
     150void UIGlobalSettingsInput::setValidator(QIWidgetValidator *pValidator)
     151{
     152    m_pValidator = pValidator;
     153    connect(m_pSelectorModel, SIGNAL(sigRevalidationRequired()), m_pValidator, SLOT(revalidate()));
     154    connect(m_pMachineModel, SIGNAL(sigRevalidationRequired()), m_pValidator, SLOT(revalidate()));
     155}
     156
     157bool UIGlobalSettingsInput::revalidate(QString &strWarning, QString &strTitle)
     158{
     159    /* Check for unique shortcuts: */
     160    if (!m_pSelectorModel->isAllShortcutsUnique())
     161    {
     162        strTitle += ": " + VBoxGlobal::removeAccelMark(m_pTabWidget->tabText(UIHotKeyTableIndex_Selector));
     163        strWarning = tr("there are duplicated shortcuts found.");
     164        return false;
     165    }
     166    else if (!m_pMachineModel->isAllShortcutsUnique())
     167    {
     168        strTitle += ": " + VBoxGlobal::removeAccelMark(m_pTabWidget->tabText(UIHotKeyTableIndex_Machine));
     169        strWarning = tr("there are duplicated shortcuts found.");
     170        return false;
     171    }
     172
     173    return true;
     174}
     175
    97176/* Navigation stuff: */
    98177void UIGlobalSettingsInput::setOrderAfter(QWidget *pWidget)
    99178{
    100     setTabOrder(pWidget, m_pHostKeyEditor);
    101     setTabOrder(m_pHostKeyEditor, m_pResetHostCombinationButton);
    102     setTabOrder(m_pResetHostCombinationButton, m_pEnableAutoGrabCheckbox);
     179    setTabOrder(pWidget, m_pTabWidget);
     180    setTabOrder(m_pTabWidget, m_pEnableAutoGrabCheckbox);
    103181}
    104182
     
    107185{
    108186    /* Translate uic generated strings: */
    109     Ui::UIGlobalSettingsInput::retranslateUi (this);
     187    Ui::UIGlobalSettingsInput::retranslateUi(this);
     188
     189    /* Translate tab-widget labels: */
     190    m_pTabWidget->setTabText(UIHotKeyTableIndex_Selector, tr("&VirtualBox Manager"));
     191    m_pTabWidget->setTabText(UIHotKeyTableIndex_Machine, tr("Virtual &Machine"));
     192    m_pSelectorTable->setWhatsThis(tr("Lists all the available shortcuts "
     193                                      "which can be configured."));
     194    m_pMachineTable->setWhatsThis(tr("Lists all the available shortcuts "
     195                                     "which can be configured."));
     196    m_pFilterEditor->setWhatsThis(tr("Allows to filter the shortcuts list."));
     197}
     198
     199/* Filtering stuff: */
     200void UIGlobalSettingsInput::sltHandleFilterTextChange()
     201{
     202    m_pSelectorModel->setFilter(m_pFilterEditor->text());
     203    m_pMachineModel->setFilter(m_pFilterEditor->text());
    110204}
    111205
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsInput.h

    r44662 r44737  
    2929#include "UIActionPool.h"
    3030
     31/* Forward declartions: */
     32class QTabWidget;
     33class QLineEdit;
     34class UIHotKeyTableModel;
     35class UIHotKeyTable;
     36
    3137/* Global settings / Input page / Cache / Shortcut cache item: */
    3238struct UIShortcutCacheItem
     
    103109struct UISettingsCacheGlobalInput
    104110{
    105     QString m_strHostCombo;
     111    UIShortcutCache m_shortcuts;
    106112    bool m_fAutoCapture;
    107113};
     
    133139    void saveFromCacheTo(QVariant &data);
    134140
     141    /* Validation stuff: */
     142    void setValidator(QIWidgetValidator *pValidator);
     143    bool revalidate(QString &strWarning, QString &strTitle);
     144
    135145    /* Navigation stuff: */
    136146    void setOrderAfter(QWidget *pWidget);
     
    139149    void retranslateUi();
    140150
     151private slots:
     152
     153    /* Handler: Filtering stuff: */
     154    void sltHandleFilterTextChange();
     155
    141156private:
    142157
    143158    /* Cache: */
     159    QIWidgetValidator *m_pValidator;
    144160    UISettingsCacheGlobalInput m_cache;
     161    QTabWidget *m_pTabWidget;
     162    QLineEdit *m_pFilterEditor;
     163    UIHotKeyTableModel *m_pSelectorModel;
     164    UIHotKeyTable *m_pSelectorTable;
     165    UIHotKeyTableModel *m_pMachineModel;
     166    UIHotKeyTable *m_pMachineTable;
     167};
     168
     169/* Hot-key table indexes: */
     170enum UIHotKeyTableIndex
     171{
     172    UIHotKeyTableIndex_Selector = 0,
     173    UIHotKeyTableIndex_Machine = 1
    145174};
    146175
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsInput.ui

    r44655 r44737  
    2727    <number>0</number>
    2828   </property>
    29    <item row="0" column="0">
    30     <spacer>
    31      <property name="orientation">
    32       <enum>Qt::Horizontal</enum>
    33      </property>
    34      <property name="sizeType">
    35       <enum>QSizePolicy::Fixed</enum>
    36      </property>
    37      <property name="sizeHint" stdset="0">
    38       <size>
    39        <width>40</width>
    40        <height>20</height>
    41       </size>
    42      </property>
    43     </spacer>
    44    </item>
    45    <item row="0" column="1">
    46     <widget class="QLabel" name="m_pHostKeyLabel">
    47      <property name="text">
    48       <string>Host &amp;Key:</string>
    49      </property>
    50      <property name="buddy">
    51       <cstring>m_pHostKeyEditor</cstring>
    52      </property>
    53     </widget>
    54    </item>
    55    <item row="0" column="2">
    56     <widget class="UIHostComboEditor" name="m_pHostKeyEditor">
    57      <property name="whatsThis">
    58       <string>Displays the key used as a Host Key in the VM window. Activate the entry field and press a new Host Key. Note that alphanumeric, cursor movement and editing keys cannot be used.</string>
    59      </property>
    60      <property name="sizePolicy">
    61       <sizepolicy hsizetype="MinimumExpanding" vsizetype="Minimum">
    62        <horstretch>0</horstretch>
    63        <verstretch>0</verstretch>
    64       </sizepolicy>
    65      </property>
    66     </widget>
    67    </item>
    68    <item row="0" column="3">
    69     <widget class="UIResetButton" name="m_pResetHostCombinationButton">
    70      <property name="focusPolicy">
    71       <enum>Qt::StrongFocus</enum>
    72      </property>
    73      <property name="toolTip">
    74       <string>Reset host combination</string>
    75      </property>
    76      <property name="whatsThis">
    77       <string>Resets the key combination used as the host combination in the VM window.</string>
    78      </property>
    79     </widget>
    80    </item>
    81    <item row="1" column="2" colspan="2">
     29   <item row="1" column="0">
    8230    <widget class="QCheckBox" name="m_pEnableAutoGrabCheckbox">
    8331     <property name="whatsThis">
     
    8937    </widget>
    9038   </item>
    91    <item row="2" column="0" colspan="4">
    92     <spacer>
    93      <property name="orientation">
    94       <enum>Qt::Vertical</enum>
    95      </property>
    96      <property name="sizeHint" stdset="0">
    97       <size>
    98        <width>0</width>
    99        <height>0</height>
    100       </size>
    101      </property>
    102     </spacer>
    103    </item>
    10439  </layout>
    10540 </widget>
    106  <customwidgets>
    107   <customwidget>
    108    <class>UIHostComboEditor</class>
    109    <extends>QLineEdit</extends>
    110    <header>UIHostComboEditor.h</header>
    111   </customwidget>
    112   <customwidget>
    113    <class>UIResetButton</class>
    114    <extends>QAbstractButton</extends>
    115    <header>UISpecialControls.h</header>
    116   </customwidget>
    117  </customwidgets>
     41 <customwidgets/>
    11842 <resources/>
    119  <connections>
    120   <connection>
    121    <sender>m_pResetHostCombinationButton</sender>
    122    <signal>clicked(bool)</signal>
    123    <receiver>m_pHostKeyEditor</receiver>
    124    <slot>sltClear()</slot>
    125    <hints>
    126     <hint type="sourcelabel">
    127      <x>111</x>
    128      <y>19</y>
    129     </hint>
    130     <hint type="destinationlabel">
    131      <x>124</x>
    132      <y>61</y>
    133     </hint>
    134    </hints>
    135   </connection>
    136  </connections>
     43 <connections/>
    13744</ui>
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHostComboEditor.cpp

    r44663 r44737  
    310310    /* Configure widget: */
    311311    setAttribute(Qt::WA_NativeWindow);
    312     setAlignment(Qt::AlignCenter);
    313312    setContextMenuPolicy(Qt::NoContextMenu);
    314313    connect(this, SIGNAL(selectionChanged()), this, SLOT(sltDeselect()));
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette