VirtualBox

Ignore:
Timestamp:
Jun 11, 2019 1:03:19 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6143. Sme prep. work for a more able key editor

Location:
trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.cpp

    r79082 r79089  
    6464    UIKeyType_Modifier,
    6565    UIKeyType_Max
     66};
     67
     68/*********************************************************************************************************************************
     69*   UISoftKeyEditor definition.                                                                                  *
     70*********************************************************************************************************************************/
     71
     72class UISoftKeyEditor : public QIWithRetranslateUI<QMainWindow>
     73{
     74    Q_OBJECT;
     75
     76public:
     77
     78    UISoftKeyEditor(QWidget *pParent = 0);
     79
     80protected:
     81
     82    virtual void retranslateUi() /* override */;
     83
     84private:
     85
     86    void prepareObjects();
     87    void prepareConnections();
     88
     89    QGridLayout *m_pEditorLayout;
     90
     91    QLabel *m_pBaseCaptionLabel;
     92    QLabel *m_pShiftCaptionLabel;
     93    QLabel *m_pAltGrCaptionLabel;
     94
     95    QLineEdit *m_pBaseCaptionEdit;
     96    QLineEdit *m_pShiftCaptionEdit;
     97    QLineEdit *m_pAltGrCaptionEdit;
     98
     99    QPushButton *m_pOkButton;
     100    QPushButton *m_pCancelButton;
    66101};
    67102
     
    196231{
    197232    Q_OBJECT;
     233    enum Mode
     234    {
     235        Mode_KeyCapEdit,
     236        Mode_Keyboard,
     237        Mode_Max
     238    };
    198239
    199240signals:
     
    227268    void sltHandleContextMenuRequest(const QPoint &point);
    228269    void sltHandleLoadLayout(QAction *pSenderAction);
    229     void sltHandleKeyCapEdit();
    230270    void sltHandleSaveKeyCapFile();
    231271    void sltHandleLoadKeyCapFile();
    232272    void sltHandleUnloadKeyCaps();
    233     void sltHandleKepCApEditModeToggle(bool fToggle);
     273    void sltHandleKepCapEditModeToggle(bool fToggle);
    234274
    235275private:
     
    278318    QAction *m_pLoadLayoutFileAction;
    279319    QAction *m_pLastSelectedLayout;
    280     QAction *m_pChangeKeyCapAction;
     320    QAction *m_pKeyCapEditModeToggleAction;
    281321    QLineEdit *m_pKeyCapEditor;
     322    Mode       m_enmMode;
    282323};
    283324
     
    326367    QMap<int, QString> m_keyCapMap;
    327368};
     369
     370/*********************************************************************************************************************************
     371*   UISoftKeyEditor implementation.                                                                                  *
     372*********************************************************************************************************************************/
     373
     374UISoftKeyEditor::UISoftKeyEditor(QWidget *pParent /* = 0 */)
     375    :QIWithRetranslateUI<QMainWindow>(pParent)
     376    , m_pEditorLayout(0)
     377    , m_pBaseCaptionLabel(0)
     378    , m_pShiftCaptionLabel(0)
     379    , m_pAltGrCaptionLabel(0)
     380    , m_pBaseCaptionEdit(0)
     381    , m_pShiftCaptionEdit(0)
     382    , m_pAltGrCaptionEdit(0)
     383    , m_pOkButton(0)
     384    , m_pCancelButton(0)
     385{
     386    prepareObjects();
     387}
     388
     389void UISoftKeyEditor::retranslateUi()
     390{
     391    if (m_pBaseCaptionLabel)
     392        m_pBaseCaptionLabel->setText(UISoftKeyboard::tr("Base Caption"));
     393
     394
     395    if (m_pShiftCaptionLabel)
     396        m_pShiftCaptionLabel->setText(UISoftKeyboard::tr("Shift Caption"));
     397
     398    if (m_pAltGrCaptionLabel)
     399        m_pAltGrCaptionLabel->setText(UISoftKeyboard::tr("AltGr Caption"));
     400}
     401
     402void UISoftKeyEditor::prepareObjects()
     403{
     404    m_pEditorLayout = new QGridLayout;
     405
     406    if (!m_pEditorLayout)
     407        return;
     408
     409    m_pBaseCaptionLabel = new QLabel;
     410    m_pBaseCaptionEdit = new QLineEdit;
     411    m_pBaseCaptionLabel->setBuddy(m_pBaseCaptionEdit);
     412
     413    m_pShiftCaptionLabel = new QLabel;
     414    m_pShiftCaptionEdit = new QLineEdit;
     415    m_pShiftCaptionLabel->setBuddy(m_pShiftCaptionEdit);
     416
     417    m_pAltGrCaptionLabel = new QLabel;
     418    m_pAltGrCaptionEdit = new QLineEdit;
     419    m_pAltGrCaptionLabel->setBuddy(m_pAltGrCaptionEdit);
     420
     421    setLayout(m_pEditorLayout);
     422
     423    retranslateUi();
     424}
    328425
    329426/*********************************************************************************************************************************
     
    624721    , m_pLoadLayoutFileAction(0)
    625722    , m_pLastSelectedLayout(0)
    626     , m_pChangeKeyCapAction(0)
     723    , m_pKeyCapEditModeToggleAction(0)
     724    , m_enmMode(Mode_Keyboard)
    627725{
    628726
     
    674772                painter.setBrush(QBrush(m_keyDefaultColor));
    675773
    676             if (&key == m_pKeyBeingEdited)
     774            if (m_enmMode == Mode_KeyCapEdit && &key == m_pKeyBeingEdited)
    677775            {
    678776                m_pKeyCapEditor->setFont(painterFont);
     
    680778                                             m_fScaleFactorX * key.keyGeometry().width(), m_fScaleFactorY * key.keyGeometry().height());
    681779                m_pKeyCapEditor->show();
    682 
     780                m_pKeyCapEditor->setFocus();
    683781            }
    684782
     
    725823        return;
    726824    m_pKeyPressed = keyUnderMouse(pEvent);
    727     handleKeyPress(m_pKeyPressed);
     825
     826    if (m_enmMode == Mode_Keyboard)
     827        handleKeyPress(m_pKeyPressed);
     828    else if (m_enmMode == Mode_KeyCapEdit)
     829    {
     830        /* If the editor is shown already for another key clicking away accepts the entered text: */
     831        if (m_pKeyBeingEdited && m_pKeyBeingEdited != m_pKeyUnderMouse)
     832        {
     833            printf("farkli %p\n", m_pKeyBeingEdited);
     834        }
     835        m_pKeyBeingEdited = m_pKeyUnderMouse;
     836        if (m_pKeyBeingEdited && m_pKeyCapEditor)
     837            m_pKeyCapEditor->setText(m_pKeyBeingEdited->keyCap());
     838    }
    728839    update();
    729840}
     
    736847    if (!m_pKeyPressed)
    737848        return;
    738     handleKeyRelease(m_pKeyPressed);
     849
     850    if (m_enmMode == Mode_Keyboard)
     851        handleKeyRelease(m_pKeyPressed);
     852
     853    update();
    739854    m_pKeyPressed = 0;
    740     update();
    741855}
    742856
     
    826940}
    827941
    828 void UISoftKeyboardWidget::sltHandleKeyCapEdit()
    829 {
    830     m_pKeyBeingEdited = m_pKeyUnderMouse;
    831     if (m_pKeyBeingEdited && m_pKeyCapEditor)
    832         m_pKeyCapEditor->setText(m_pKeyBeingEdited->keyCap());
    833 }
    834 
    835942void UISoftKeyboardWidget::sltHandleSaveKeyCapFile()
    836943{
     
    9091016}
    9101017
    911 void UISoftKeyboardWidget::sltHandleKepCApEditModeToggle(bool fToggle)
    912 {
    913     Q_UNUSED(fToggle);
     1018void UISoftKeyboardWidget::sltHandleKepCapEditModeToggle(bool fToggle)
     1019{
     1020    if (fToggle)
     1021        m_enmMode = Mode_KeyCapEdit;
     1022    else
     1023        m_enmMode = Mode_Keyboard;
    9141024}
    9151025
     
    10191129void UISoftKeyboardWidget::showContextMenu(const QPoint &globalPoint)
    10201130{
    1021     m_pChangeKeyCapAction->setEnabled(m_pKeyUnderMouse && !m_pShowPositionsAction->isChecked());
    10221131    m_pContextMenu->exec(globalPoint);
    10231132    update();
     
    11251234    m_pContextMenu = new QMenu(this);
    11261235    /* Layout menu: */
    1127     QMenu *pLayoutMenu = m_pContextMenu->addMenu(UISoftKeyboard::tr("Load Layout"));
    11281236    m_pLayoutActionGroup = new QActionGroup(this);
    11291237    m_pLayoutActionGroup->setExclusive(true);
     
    11391247    m_pLoadLayoutFileAction = m_pLayoutActionGroup->addAction(UISoftKeyboard::tr("Load Layout File..."));
    11401248    m_pLoadLayoutFileAction->setCheckable(true);
    1141     pLayoutMenu->addActions(m_pLayoutActionGroup->actions());
     1249    m_pContextMenu->addActions(m_pLayoutActionGroup->actions());
    11421250
    11431251    /* Keycaps menu: */
    1144     QMenu *pKeycapsMenu = m_pContextMenu->addMenu(UISoftKeyboard::tr("Keycaps"));
    1145     QAction *pKeyCapEditModeToggleAction = pKeycapsMenu->addAction(UISoftKeyboard::tr("Key captions editing mode"));
    1146     connect(pKeyCapEditModeToggleAction, &QAction::toggled, this, &UISoftKeyboardWidget::sltHandleKepCApEditModeToggle);
    1147     pKeyCapEditModeToggleAction->setCheckable(true);
    1148     pKeyCapEditModeToggleAction->setChecked(false);
    1149 
    1150     m_pShowPositionsAction = pKeycapsMenu->addAction(UISoftKeyboard::tr("Show key positions instead of key caps"));
     1252    m_pKeyCapEditModeToggleAction = m_pContextMenu->addAction(UISoftKeyboard::tr("Key captions editing mode"));
     1253    connect(m_pKeyCapEditModeToggleAction, &QAction::toggled, this, &UISoftKeyboardWidget::sltHandleKepCapEditModeToggle);
     1254    m_pKeyCapEditModeToggleAction->setCheckable(true);
     1255    m_pKeyCapEditModeToggleAction->setChecked(false);
     1256
     1257#ifdef DEBUG
     1258    m_pShowPositionsAction = m_pContextMenu->addAction(UISoftKeyboard::tr("Show key positions instead of key caps"));
    11511259    m_pShowPositionsAction->setCheckable(true);
    11521260    m_pShowPositionsAction->setChecked(false);
    1153 
    1154     m_pChangeKeyCapAction = pKeycapsMenu->addAction(UISoftKeyboard::tr("Add/change key cap"));
    1155     connect(m_pChangeKeyCapAction, &QAction::triggered, this, &UISoftKeyboardWidget::sltHandleKeyCapEdit);
    1156     QAction *pSaveKeyCapFile = pKeycapsMenu->addAction(UISoftKeyboard::tr("Save key caps to file..."));
     1261#endif
     1262
     1263    QAction *pSaveKeyCapFile = m_pContextMenu->addAction(UISoftKeyboard::tr("Save key caps to file..."));
    11571264    connect(pSaveKeyCapFile, &QAction::triggered, this, &UISoftKeyboardWidget::sltHandleSaveKeyCapFile);
    1158     QAction *pLoadKeyCapFile = pKeycapsMenu->addAction(UISoftKeyboard::tr("Load key caps from file..."));
     1265    QAction *pLoadKeyCapFile = m_pContextMenu->addAction(UISoftKeyboard::tr("Load key caps from file..."));
    11591266    connect(pLoadKeyCapFile, &QAction::triggered, this, &UISoftKeyboardWidget::sltHandleLoadKeyCapFile);
    1160     QAction *pUnloadKeyCaps = pKeycapsMenu->addAction(UISoftKeyboard::tr("Unload key caps"));
     1267    QAction *pUnloadKeyCaps = m_pContextMenu->addAction(UISoftKeyboard::tr("Unload key caps"));
    11611268    connect(pUnloadKeyCaps, &QAction::triggered, this, &UISoftKeyboardWidget::sltHandleUnloadKeyCaps);
    11621269}
     
    11661273    if (m_fInKeyCapEditMode == fEnable)
    11671274        return;
    1168 
     1275    m_enmMode = Mode_KeyCapEdit;
    11691276}
    11701277
     
    14781585void UISoftKeyboard::retranslateUi()
    14791586{
     1587    if (m_pSettingsButton)
     1588        m_pSettingsButton->setToolTip(tr("Settings Menu"));
    14801589}
    14811590
     
    15471656            this, &UISoftKeyboard::sltHandleStatusBarContextMenuRequest);
    15481657
     1658    statusBar()->setStyleSheet( "QStatusBar::item { border: 0px}" );
     1659    // QWidget *pStatusBarWidget = new QWidget;
     1660    // QHBoxLayout *pStatusBarLayout = new QHBoxLayout(pStatusBarWidget);
     1661    // pStatusBarLayout->setSpacing(0);
     1662    // pStatusBarLayout->setContentsMargins(0, 0, 0, 0);
     1663
    15491664    m_pSettingsButton = new QToolButton;
    1550     m_pSettingsButton->setIcon(UIIconPool::iconSet(":/vm_settings_16px.png"));
     1665    m_pSettingsButton->setIcon(UIIconPool::iconSet(":/keyboard_settings_16px.png"));
    15511666    m_pSettingsButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    15521667    const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize);
     
    15551670    statusBar()->addPermanentWidget(m_pSettingsButton);
    15561671
     1672    QToolButton *pButton = new QToolButton;
     1673    pButton->setIcon(UIIconPool::iconSet(":/hd_modify_16px.png"));
     1674    pButton->setStyleSheet("QToolButton { border: 0px none black; margin: 0px 0px 0px 0px; } QToolButton::menu-indicator {image: none;}");
     1675    statusBar()->addPermanentWidget(pButton);
     1676
     1677
     1678
     1679    retranslateUi();
    15571680}
    15581681
  • trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.h

    r79082 r79089  
    6464    void sltHandleKeyCapFileChange(const QString &strKeyCapFileName);
    6565    void sltHandleStatusBarContextMenuRequest(const QPoint &point);
     66
    6667private:
    6768
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