VirtualBox

Changeset 79103 in vbox


Ignore:
Timestamp:
Jun 12, 2019 9:18:13 AM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
131265
Message:

FE/Qt: bugref:6143. Working on the layout editor.

File:
1 edited

Legend:

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

    r79089 r79103  
    1919#include <QApplication>
    2020#include <QFile>
     21#include <QGroupBox>
    2122#include <QLabel>
    2223#include <QLineEdit>
    2324#include <QMenu>
    2425#include <QPainter>
     26#include <QPushButton>
    2527#include <QStatusBar>
    2628#include <QStyle>
     
    7072*********************************************************************************************************************************/
    7173
    72 class UISoftKeyEditor : public QIWithRetranslateUI<QMainWindow>
     74class UISoftKeyEditor : public QIWithRetranslateUI<QWidget>
    7375{
    7476    Q_OBJECT;
    7577
     78signals:
     79
     80    void sigKeyCaptionEdited();
     81
    7682public:
    7783
    7884    UISoftKeyEditor(QWidget *pParent = 0);
     85    void setKey(UISoftKeyboardKey *pKey);
    7986
    8087protected:
    8188
    8289    virtual void retranslateUi() /* override */;
     90
     91private slots:
     92
     93    void sltHandleOkButton();
    8394
    8495private:
     
    8697    void prepareObjects();
    8798    void prepareConnections();
    88 
    89     QGridLayout *m_pEditorLayout;
    90 
     99    QWidget *prepareKeyCaptionEditWidgets();
     100
     101    QVBoxLayout *m_pMainLayout;
     102    QGridLayout *m_pCaptionEditorLayout;
     103    QGroupBox *m_pSelectedKeyGroupBox;
     104    QGroupBox *m_pCaptionEditGroupBox;
     105
     106    QLabel *m_pScanCodeLabel;
     107    QLabel *m_pPositionLabel;
    91108    QLabel *m_pBaseCaptionLabel;
    92109    QLabel *m_pShiftCaptionLabel;
    93110    QLabel *m_pAltGrCaptionLabel;
    94111
     112    QLineEdit *m_pScanCodeEdit;
     113    QLineEdit *m_pPositionEdit;
    95114    QLineEdit *m_pBaseCaptionEdit;
    96115    QLineEdit *m_pShiftCaptionEdit;
     
    99118    QPushButton *m_pOkButton;
    100119    QPushButton *m_pCancelButton;
     120    /** The key which is being currently edited. Might be Null. */
     121    UISoftKeyboardKey  *m_pKey;
    101122};
    102123
     
    147168    void setKeyGeometry(const QRect &rect);
    148169
    149     const QString &staticKeyCap() const;
    150     void setStaticKeyCap(const QString &strKeyCap);
    151 
    152     const QString &keyCap() const;
    153     void setKeyCap(const QString &strKeyCap);
     170    const QString baseCaption() const;
     171    void setBaseCaption(const QString &strBaseCaption);
     172
     173    const QString shiftCaption() const;
     174    void setShiftCaption(const QString &strShiftCaption);
     175
     176    const QString altGrCaption() const;
     177    void  setAltGrCaption(const QString &strAltGrCaption);
     178
     179    const QString text() const;
    154180
    155181    void setWidth(int iWidth);
     
    195221
    196222    void updateState(bool fPressed);
     223    void updateText();
    197224
    198225    QRect      m_keyGeometry;
    199     /** Static keycaps are what is obtained from the layout file, as opposed to the keycaps file.
    200       * normally they are the captions of modifier keys (Shift, etc) whose meaning stays the same across the layouts. */
    201     QString    m_strStaticKeyCap;
    202     /** Key caps are loaded from a keycap file and preferred over the static keycaps if they are not empty. */
    203     QString    m_strKeyCap;
     226
     227    QString    m_strBaseCaption;
     228    QString    m_strShiftCaption;
     229    QString    m_strAltGrCaption;
     230    /** m_strText is concatenation of base, shift, and altgr captions. */
     231    QString    m_strText;
    204232
    205233    /** Stores the key polygon in local coordinates. */
     
    267295
    268296    void sltHandleContextMenuRequest(const QPoint &point);
    269     void sltHandleLoadLayout(QAction *pSenderAction);
    270297    void sltHandleSaveKeyCapFile();
    271298    void sltHandleLoadKeyCapFile();
    272299    void sltHandleUnloadKeyCaps();
    273300    void sltHandleKepCapEditModeToggle(bool fToggle);
     301    void sltHandleKeyCaptionEdited();
    274302
    275303private:
     
    287315    void               prepareObjects();
    288316    void               enableDisableKeyCapEditMode(bool fEnable);
     317    /** Sets m_pKeyBeingEdited. */
     318    void               setKeyBeingEdited(UISoftKeyboardKey* pKey);
    289319
    290320    UISoftKeyboardKey *m_pKeyUnderMouse;
     
    296326    QColor m_textDefaultColor;
    297327    QColor m_textPressedColor;
     328    QColor m_keyEditColor;
    298329    QVector<UISoftKeyboardKey*> m_pressedModifiers;
    299330    QVector<UISoftKeyboardRow>  m_rows;
    300     QStringList defaultLayouts;
     331    QStringList m_defaultLayouts;
    301332
    302333    QSize m_minimumSize;
     
    314345
    315346    QMenu   *m_pContextMenu;
    316     QActionGroup *m_pLayoutActionGroup;
    317347    QAction *m_pShowPositionsAction;
    318     QAction *m_pLoadLayoutFileAction;
    319     QAction *m_pLastSelectedLayout;
    320348    QAction *m_pKeyCapEditModeToggleAction;
    321     QLineEdit *m_pKeyCapEditor;
     349    UISoftKeyEditor *m_pKeyCapEditor;
    322350    Mode       m_enmMode;
    323351};
     
    373401
    374402UISoftKeyEditor::UISoftKeyEditor(QWidget *pParent /* = 0 */)
    375     :QIWithRetranslateUI<QMainWindow>(pParent)
    376     , m_pEditorLayout(0)
     403    :QIWithRetranslateUI<QWidget>(pParent)
     404    , m_pMainLayout(0)
     405    , m_pCaptionEditorLayout(0)
     406    , m_pSelectedKeyGroupBox(0)
     407    , m_pCaptionEditGroupBox(0)
     408    , m_pScanCodeLabel(0)
     409    , m_pPositionLabel(0)
    377410    , m_pBaseCaptionLabel(0)
    378411    , m_pShiftCaptionLabel(0)
    379412    , m_pAltGrCaptionLabel(0)
     413    , m_pScanCodeEdit(0)
     414    , m_pPositionEdit(0)
    380415    , m_pBaseCaptionEdit(0)
    381416    , m_pShiftCaptionEdit(0)
     
    383418    , m_pOkButton(0)
    384419    , m_pCancelButton(0)
    385 {
     420    , m_pKey(0)
     421{
     422    setAutoFillBackground(true);
    386423    prepareObjects();
    387424}
    388425
     426void UISoftKeyEditor::setKey(UISoftKeyboardKey *pKey)
     427{
     428    if (m_pKey == pKey)
     429        return;
     430    m_pKey = pKey;
     431    if (m_pSelectedKeyGroupBox)
     432        m_pSelectedKeyGroupBox->setEnabled(m_pKey);
     433    if (!m_pKey)
     434        return;
     435    if (m_pScanCodeEdit)
     436        m_pScanCodeEdit->setText(QString::number(m_pKey->scanCode(), 16));
     437    if (m_pPositionEdit)
     438        m_pPositionEdit->setText(QString::number(m_pKey->position()));
     439    if (m_pBaseCaptionEdit)
     440        m_pBaseCaptionEdit->setText(m_pKey->baseCaption());
     441    if (m_pShiftCaptionEdit)
     442        m_pShiftCaptionEdit->setText(m_pKey->shiftCaption());
     443    if (m_pAltGrCaptionEdit)
     444        m_pAltGrCaptionEdit->setText(m_pKey->altGrCaption());
     445}
     446
    389447void UISoftKeyEditor::retranslateUi()
    390448{
     449    if (m_pScanCodeLabel)
     450        m_pScanCodeLabel->setText(UISoftKeyboard::tr("Scan Code"));
     451    if (m_pPositionLabel)
     452        m_pPositionLabel->setText(UISoftKeyboard::tr("Position"));
    391453    if (m_pBaseCaptionLabel)
    392         m_pBaseCaptionLabel->setText(UISoftKeyboard::tr("Base Caption"));
    393 
    394 
     454        m_pBaseCaptionLabel->setText(UISoftKeyboard::tr("Base"));
    395455    if (m_pShiftCaptionLabel)
    396         m_pShiftCaptionLabel->setText(UISoftKeyboard::tr("Shift Caption"));
    397 
     456        m_pShiftCaptionLabel->setText(UISoftKeyboard::tr("Shift"));
    398457    if (m_pAltGrCaptionLabel)
    399         m_pAltGrCaptionLabel->setText(UISoftKeyboard::tr("AltGr Caption"));
     458        m_pAltGrCaptionLabel->setText(UISoftKeyboard::tr("AltGr"));
     459    if (m_pOkButton)
     460        m_pOkButton->setText(UISoftKeyboard::tr("Ok"));
     461    if (m_pCancelButton)
     462        m_pCancelButton->setText(UISoftKeyboard::tr("Cancel"));
     463    if (m_pCaptionEditGroupBox)
     464        m_pCaptionEditGroupBox->setTitle(UISoftKeyboard::tr("Captions"));
     465    if (m_pSelectedKeyGroupBox)
     466        m_pSelectedKeyGroupBox->setTitle(UISoftKeyboard::tr("Selected Key"));
     467}
     468
     469void UISoftKeyEditor::sltHandleOkButton()
     470{
     471    if (!m_pKey)
     472        return;
     473    m_pKey->setBaseCaption(m_pBaseCaptionEdit->text());
     474    m_pKey->setShiftCaption(m_pShiftCaptionEdit->text());
     475    m_pKey->setAltGrCaption(m_pAltGrCaptionEdit->text());
     476    emit sigKeyCaptionEdited();
    400477}
    401478
    402479void UISoftKeyEditor::prepareObjects()
    403480{
    404     m_pEditorLayout = new QGridLayout;
    405 
    406     if (!m_pEditorLayout)
    407         return;
     481    m_pMainLayout = new QVBoxLayout;
     482    if (!m_pMainLayout)
     483        return;
     484    setLayout(m_pMainLayout);
     485
     486    m_pSelectedKeyGroupBox = new QGroupBox;
     487    m_pSelectedKeyGroupBox->setEnabled(false);
     488
     489    m_pMainLayout->addWidget(m_pSelectedKeyGroupBox);
     490    QGridLayout *pSelectedKeyLayout = new QGridLayout(m_pSelectedKeyGroupBox);
     491    pSelectedKeyLayout->setSpacing(0);
     492    pSelectedKeyLayout->setContentsMargins(0, 0, 0, 0);
     493
     494    m_pScanCodeLabel = new QLabel;
     495    m_pScanCodeEdit = new QLineEdit;
     496    m_pScanCodeLabel->setBuddy(m_pScanCodeEdit);
     497    m_pScanCodeEdit->setReadOnly(true);
     498    pSelectedKeyLayout->addWidget(m_pScanCodeLabel, 0, 0);
     499    pSelectedKeyLayout->addWidget(m_pScanCodeEdit, 0, 1);
     500
     501    m_pPositionLabel= new QLabel;
     502    m_pPositionEdit = new QLineEdit;
     503    m_pPositionLabel->setBuddy(m_pPositionEdit);
     504    m_pPositionEdit->setReadOnly(true);
     505    pSelectedKeyLayout->addWidget(m_pPositionLabel, 1, 0);
     506    pSelectedKeyLayout->addWidget(m_pPositionEdit, 1, 1);
     507
     508    QWidget *pCaptionEditor = prepareKeyCaptionEditWidgets();
     509    if (pCaptionEditor)
     510        pSelectedKeyLayout->addWidget(pCaptionEditor, 2, 0, 2, 2);
     511
     512    QSpacerItem *pSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding);
     513    if (pSpacer)
     514        pSelectedKeyLayout->addItem(pSpacer, 4, 1);
     515
     516    retranslateUi();
     517}
     518
     519QWidget *UISoftKeyEditor::prepareKeyCaptionEditWidgets()
     520{
     521    m_pCaptionEditGroupBox = new QGroupBox;
     522    if (!m_pCaptionEditGroupBox)
     523        return 0;
     524    m_pCaptionEditGroupBox->setFlat(false);
     525    QGridLayout *pCaptionEditorLayout = new QGridLayout(m_pCaptionEditGroupBox);
     526    pCaptionEditorLayout->setSpacing(0);
     527    pCaptionEditorLayout->setContentsMargins(0, 0, 0, 0);
     528
     529    if (!pCaptionEditorLayout)
     530        return 0;
    408531
    409532    m_pBaseCaptionLabel = new QLabel;
    410533    m_pBaseCaptionEdit = new QLineEdit;
    411534    m_pBaseCaptionLabel->setBuddy(m_pBaseCaptionEdit);
     535    pCaptionEditorLayout->addWidget(m_pBaseCaptionLabel, 0, 0);
     536    pCaptionEditorLayout->addWidget(m_pBaseCaptionEdit, 0, 1);
    412537
    413538    m_pShiftCaptionLabel = new QLabel;
    414539    m_pShiftCaptionEdit = new QLineEdit;
    415540    m_pShiftCaptionLabel->setBuddy(m_pShiftCaptionEdit);
     541    pCaptionEditorLayout->addWidget(m_pShiftCaptionLabel, 1, 0);
     542    pCaptionEditorLayout->addWidget(m_pShiftCaptionEdit, 1, 1);
    416543
    417544    m_pAltGrCaptionLabel = new QLabel;
    418545    m_pAltGrCaptionEdit = new QLineEdit;
    419546    m_pAltGrCaptionLabel->setBuddy(m_pAltGrCaptionEdit);
    420 
    421     setLayout(m_pEditorLayout);
    422 
    423     retranslateUi();
     547    pCaptionEditorLayout->addWidget(m_pAltGrCaptionLabel, 2, 0);
     548    pCaptionEditorLayout->addWidget(m_pAltGrCaptionEdit, 2, 1);
     549
     550
     551    m_pOkButton = new QPushButton;
     552    pCaptionEditorLayout->addWidget(m_pOkButton, 3, 0);
     553    connect(m_pOkButton, &QPushButton::pressed, this, &UISoftKeyEditor::sltHandleOkButton);
     554    m_pCancelButton = new QPushButton;
     555    pCaptionEditorLayout->addWidget(m_pCancelButton, 3, 1);
     556
     557    QSpacerItem *pSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding);
     558    if (pSpacer)
     559        pCaptionEditorLayout->addItem(pSpacer, 4, 1);
     560    return m_pCaptionEditGroupBox;
    424561}
    425562
     
    505642}
    506643
    507 const QString &UISoftKeyboardKey::staticKeyCap() const
    508 {
    509     return m_strStaticKeyCap;
    510 }
    511 
    512 void UISoftKeyboardKey::setStaticKeyCap(const QString &strStaticKeyCap)
    513 {
    514     m_strStaticKeyCap = strStaticKeyCap;
    515 }
    516 
    517 const QString &UISoftKeyboardKey::keyCap() const
    518 {
    519     return m_strKeyCap;
    520 }
    521 
    522 void UISoftKeyboardKey::setKeyCap(const QString &strKeyCap)
    523 {
    524     m_strKeyCap = strKeyCap;
     644const QString UISoftKeyboardKey::baseCaption() const
     645{
     646    return m_strBaseCaption;
     647}
     648
     649void UISoftKeyboardKey::setBaseCaption(const QString &strBaseCaption)
     650{
     651    m_strBaseCaption = strBaseCaption;
     652    updateText();
     653}
     654
     655const QString UISoftKeyboardKey::shiftCaption() const
     656{
     657    return m_strShiftCaption;
     658}
     659
     660void UISoftKeyboardKey::setShiftCaption(const QString &strShiftCaption)
     661{
     662    m_strShiftCaption = strShiftCaption;
     663    updateText();
     664}
     665
     666const QString UISoftKeyboardKey::altGrCaption() const
     667{
     668    return m_strAltGrCaption;
     669}
     670
     671void UISoftKeyboardKey::setAltGrCaption(const QString &strAltGrCaption)
     672{
     673    m_strAltGrCaption = strAltGrCaption;
     674    updateText();
     675}
     676
     677const QString UISoftKeyboardKey::text() const
     678{
     679    return m_strText;
    525680}
    526681
     
    695850}
    696851
     852void UISoftKeyboardKey::updateText()
     853{
     854    m_strText.clear();
     855    if (!m_strShiftCaption.isEmpty())
     856        m_strText += QString("%1\n").arg(m_strShiftCaption);
     857    if (!m_strBaseCaption.isEmpty())
     858        m_strText += QString("%1\n").arg(m_strBaseCaption);
     859    if (!m_strAltGrCaption.isEmpty())
     860        m_strText += QString("%1\n").arg(m_strAltGrCaption);
     861}
     862
    697863/*********************************************************************************************************************************
    698864*   UISoftKeyboardWidget implementation.                                                                                  *
     
    708874    , m_textDefaultColor(QColor(46, 49, 49))
    709875    , m_textPressedColor(QColor(149, 165, 166))
     876    , m_keyEditColor(QColor(249, 165, 166))
    710877    , m_iInitialHeight(0)
    711878    , m_iInitialWidth(0)
     
    719886    , m_pContextMenu(0)
    720887    , m_pShowPositionsAction(0)
    721     , m_pLoadLayoutFileAction(0)
    722     , m_pLastSelectedLayout(0)
    723888    , m_pKeyCapEditModeToggleAction(0)
    724889    , m_enmMode(Mode_Keyboard)
     
    745910        return;
    746911
    747     m_fScaleFactorX = width() / (float) m_iInitialWidth;
     912    int iEditDialogWidth = 0;
     913    if (m_enmMode == Mode_KeyCapEdit)
     914        iEditDialogWidth = 34 * QApplication::fontMetrics().width('x');
     915    m_fScaleFactorX = (width() - iEditDialogWidth) / (float) m_iInitialWidth;
    748916    m_fScaleFactorY = height() / (float) m_iInitialHeight;
    749917
     
    758926    float fLedRadius =  0.8 * unitSize;
    759927    float fLedMargin =  0.6 * unitSize;
    760     if (!m_pKeyBeingEdited && m_pKeyCapEditor)
     928
     929    if (m_enmMode == Mode_KeyCapEdit)
     930    {
     931        m_pKeyCapEditor->setGeometry(width() - iEditDialogWidth, 0,
     932                                     iEditDialogWidth, height());
     933        m_pKeyCapEditor->show();
     934        m_pKeyCapEditor->setFocus();
     935    }
     936    else
    761937        m_pKeyCapEditor->hide();
     938
    762939    for (int i = 0; i < m_rows.size(); ++i)
    763940    {
     
    767944            UISoftKeyboardKey &key = keys[j];
    768945            painter.translate(key.keyGeometry().x(), key.keyGeometry().y());
    769             if (&key  == m_pKeyUnderMouse)
     946
     947            if(&key  == m_pKeyBeingEdited)
     948                painter.setBrush(QBrush(m_keyEditColor));
     949            else if (&key  == m_pKeyUnderMouse)
    770950                painter.setBrush(QBrush(m_keyHoverColor));
    771951            else
    772952                painter.setBrush(QBrush(m_keyDefaultColor));
    773 
    774             if (m_enmMode == Mode_KeyCapEdit && &key == m_pKeyBeingEdited)
    775             {
    776                 m_pKeyCapEditor->setFont(painterFont);
    777                 m_pKeyCapEditor->setGeometry(m_fScaleFactorX * key.keyGeometry().x(), m_fScaleFactorY * key.keyGeometry().y(),
    778                                              m_fScaleFactorX * key.keyGeometry().width(), m_fScaleFactorY * key.keyGeometry().height());
    779                 m_pKeyCapEditor->show();
    780                 m_pKeyCapEditor->setFocus();
    781             }
    782953
    783954            if (&key  == m_pKeyPressed)
     
    794965                painter.drawText(textRect, Qt::TextWordWrap, QString::number(key.position()));
    795966            else
    796                 painter.drawText(textRect, Qt::TextWordWrap,
    797                                  !key.keyCap().isEmpty() ? key.keyCap() : key.staticKeyCap());
     967                painter.drawText(textRect, Qt::TextWordWrap, key.text());
    798968
    799969            if (key.type() != UIKeyType_Ordinary)
     
    8311001        if (m_pKeyBeingEdited && m_pKeyBeingEdited != m_pKeyUnderMouse)
    8321002        {
    833             printf("farkli %p\n", m_pKeyBeingEdited);
     1003            //printf("farkli %p\n", m_pKeyBeingEdited);
    8341004        }
    835         m_pKeyBeingEdited = m_pKeyUnderMouse;
    836         if (m_pKeyBeingEdited && m_pKeyCapEditor)
    837             m_pKeyCapEditor->setText(m_pKeyBeingEdited->keyCap());
     1005        setKeyBeingEdited(m_pKeyUnderMouse);
     1006        // if (m_pKeyBeingEdited && m_pKeyCapEditor)
     1007        //     m_pKeyCapEditor->setText(m_pKeyBeingEdited->keyCap());
    8381008    }
    8391009    update();
     
    8731043            if (pKeyEvent && pKeyEvent->key() == Qt::Key_Escape)
    8741044            {
    875                 m_pKeyBeingEdited = 0;
     1045                setKeyBeingEdited(0);
    8761046                update();
    8771047                return true;
     
    8791049            else if (pKeyEvent && (pKeyEvent->key() == Qt::Key_Enter || pKeyEvent->key() == Qt::Key_Return))
    8801050            {
    881                 if (m_pKeyBeingEdited)
    882                     m_pKeyBeingEdited->setStaticKeyCap(m_pKeyCapEditor->text());
    883                 m_pKeyBeingEdited = 0;
     1051                // if (m_pKeyBeingEdited)
     1052                //     m_pKeyBeingEdited->setStaticKeyCap(m_pKeyCapEditor->text());
     1053                setKeyBeingEdited(0);
    8841054                update();
    8851055                return true;
     
    9041074}
    9051075
    906 void UISoftKeyboardWidget::sltHandleLoadLayout(QAction *pSenderAction)
    907 {
    908     if (!pSenderAction)
    909         return;
    910     if (pSenderAction == m_pLoadLayoutFileAction)
    911     {
    912         const QString strFileName = QIFileDialog::getOpenFileName(QString(), UISoftKeyboard::tr("XML files (*.xml)"), this,
    913                                                                   UISoftKeyboard::tr("Choose file to load physical keyboard layout.."));
    914         if (!strFileName.isEmpty() && createKeyboard(strFileName))
    915         {
    916             m_pLastSelectedLayout = pSenderAction;
    917             m_pLoadLayoutFileAction->setData(strFileName);
    918             emit sigLayoutChange(strFileName);
    919             return;
    920         }
    921     }
    922     else
    923     {
    924         QString strLayout = pSenderAction->data().toString();
    925         if (!strLayout.isEmpty() && createKeyboard(strLayout))
    926         {
    927             m_pLastSelectedLayout = pSenderAction;
    928             emit sigLayoutChange(strLayout);
    929             return;
    930         }
    931     }
    932     /* In case something went wrong try to restore the previous layout: */
    933     if (m_pLastSelectedLayout)
    934     {
    935         QString strLayout = m_pLastSelectedLayout->data().toString();
    936         createKeyboard(strLayout);
    937         emit sigLayoutChange(strLayout);
    938         m_pLastSelectedLayout->setChecked(true);
    939     }
    940 }
     1076// void UISoftKeyboardWidget::sltHandleLoadLayout(QAction *pSenderAction)
     1077// {
     1078//     if (!pSenderAction)
     1079//         return;
     1080//     if (pSenderAction == m_pLoadLayoutFileAction)
     1081//     {
     1082//         const QString strFileName = QIFileDialog::getOpenFileName(QString(), UISoftKeyboard::tr("XML files (*.xml)"), this,
     1083//                                                                   UISoftKeyboard::tr("Choose file to load physical keyboard layout.."));
     1084//         if (!strFileName.isEmpty() && createKeyboard(strFileName))
     1085//         {
     1086//             m_pLastSelectedLayout = pSenderAction;
     1087//             m_pLoadLayoutFileAction->setData(strFileName);
     1088//             emit sigLayoutChange(strFileName);
     1089//             return;
     1090//         }
     1091//     }
     1092//     else
     1093//     {
     1094//         QString strLayout = pSenderAction->data().toString();
     1095//         if (!strLayout.isEmpty() && createKeyboard(strLayout))
     1096//         {
     1097//             m_pLastSelectedLayout = pSenderAction;
     1098//             emit sigLayoutChange(strLayout);
     1099//             return;
     1100//         }
     1101//     }
     1102//     /* In case something went wrong try to restore the previous layout: */
     1103//     if (m_pLastSelectedLayout)
     1104//     {
     1105//         QString strLayout = m_pLastSelectedLayout->data().toString();
     1106//         createKeyboard(strLayout);
     1107//         emit sigLayoutChange(strLayout);
     1108//         m_pLastSelectedLayout->setChecked(true);
     1109//     }
     1110// }
    9411111
    9421112void UISoftKeyboardWidget::sltHandleSaveKeyCapFile()
     
    9701140           UISoftKeyboardKey &key = keys[j];
    9711141           xmlWriter.writeTextElement("position", QString::number(key.position()));
    972            if (!key.keyCap().isEmpty())
    973                xmlWriter.writeTextElement("keycap", key.keyCap());
    974            else
    975                xmlWriter.writeTextElement("keycap", key.staticKeyCap());
     1142           xmlWriter.writeTextElement("basecaption", key.baseCaption());
     1143           xmlWriter.writeTextElement("shiftcaption", key.shiftCaption());
     1144           xmlWriter.writeTextElement("altgrcaption", key.altGrCaption());
     1145
     1146           // if (!key.keyCap().isEmpty())
     1147           //     xmlWriter.writeTextElement("keycap", key.keyCap());
     1148           // else
     1149           //     xmlWriter.writeTextElement("keycap", key.staticKeyCap());
    9761150           xmlWriter.writeEndElement();
    9771151       }
     
    9901164        return;
    9911165    UIKeyboardKeyCapReader keyCapReader(strFileName);
    992     const QMap<int, QString> &keyCapMap = keyCapReader.keyCapMap();
     1166    //const QMap<int, QString> &keyCapMap = keyCapReader.keyCapMap();
    9931167
    9941168    for (int i = 0; i < m_rows.size(); ++i)
    9951169    {
    996         QVector<UISoftKeyboardKey> &keys = m_rows[i].keys();
    997         for (int j = 0; j < keys.size(); ++j)
    998         {
    999             UISoftKeyboardKey &key = keys[j];
    1000             if (keyCapMap.contains(key.position()))
    1001                 key.setKeyCap(keyCapMap[key.position()]);
    1002         }
     1170        //QVector<UISoftKeyboardKey> &keys = m_rows[i].keys();
     1171        // for (int j = 0; j < keys.size(); ++j)
     1172        // {
     1173        //     UISoftKeyboardKey &key = keys[j];
     1174        //     if (keyCapMap.contains(key.position()))
     1175        //         key.setKeyCap(keyCapMap[key.position()]);
     1176        // }
    10031177    }
    10041178    emit sigKeyCapChange(strFileName);
     
    10071181void UISoftKeyboardWidget::sltHandleUnloadKeyCaps()
    10081182{
    1009     for (int i = 0; i < m_rows.size(); ++i)
    1010     {
    1011         QVector<UISoftKeyboardKey> &keys = m_rows[i].keys();
    1012         for (int j = 0; j < keys.size(); ++j)
    1013             keys[j].setKeyCap(QString());
    1014     }
     1183    // for (int i = 0; i < m_rows.size(); ++i)
     1184    // {
     1185    //     QVector<UISoftKeyboardKey> &keys = m_rows[i].keys();
     1186    //     for (int j = 0; j < keys.size(); ++j)
     1187    //         keys[j].setKeyCap(QString());
     1188    // }
    10151189    emit sigKeyCapChange(QString());
    10161190}
     
    10211195        m_enmMode = Mode_KeyCapEdit;
    10221196    else
     1197    {
    10231198        m_enmMode = Mode_Keyboard;
     1199        m_pKeyBeingEdited = 0;
     1200    }
     1201}
     1202
     1203void UISoftKeyboardWidget::sltHandleKeyCaptionEdited()
     1204{
     1205    update();
    10241206}
    10251207
     
    11081290{
    11091291    /* Choose the first layout action's data as the default layout: */
    1110     if (!m_pLayoutActionGroup->actions().empty())
    1111     {
    1112         QAction *pAction = m_pLayoutActionGroup->actions().at(0);
    1113         if (pAction)
    1114         {
    1115             QString strLayout = pAction->data().toString();
    1116             if (!strLayout.isEmpty())
    1117             {
    1118                 if (createKeyboard(strLayout))
    1119                 {
    1120                     emit sigLayoutChange(strLayout);
    1121                     m_pLastSelectedLayout = pAction;
    1122                     pAction->setChecked(true);
    1123                 }
    1124             }
    1125         }
    1126     }
     1292    if (m_defaultLayouts.isEmpty())
     1293        return;
     1294    const QString &strLayout = m_defaultLayouts.at(0);
     1295    if (createKeyboard(strLayout))
     1296        emit sigLayoutChange(strLayout);
    11271297}
    11281298
     
    12171387void UISoftKeyboardWidget::configure()
    12181388{
    1219     defaultLayouts << ":/101_ansi.xml" << ":/102_iso.xml";
     1389    m_defaultLayouts << ":/101_ansi.xml" << ":/102_iso.xml";
    12201390    setMouseTracking(true);
    12211391    setContextMenuPolicy(Qt::CustomContextMenu);
     
    12261396void UISoftKeyboardWidget::prepareObjects()
    12271397{
    1228     m_pKeyCapEditor = new QLineEdit(this);
     1398    m_pKeyCapEditor = new UISoftKeyEditor(this);
    12291399    if (m_pKeyCapEditor)
    12301400    {
    12311401        m_pKeyCapEditor->hide();
    12321402        m_pKeyCapEditor->installEventFilter(this);
     1403        connect(m_pKeyCapEditor, &UISoftKeyEditor::sigKeyCaptionEdited, this, &UISoftKeyboardWidget::sltHandleKeyCaptionEdited);
    12331404    }
    12341405    m_pContextMenu = new QMenu(this);
    1235     /* Layout menu: */
    1236     m_pLayoutActionGroup = new QActionGroup(this);
    1237     m_pLayoutActionGroup->setExclusive(true);
    1238     connect(m_pLayoutActionGroup, &QActionGroup::triggered, this, &UISoftKeyboardWidget::sltHandleLoadLayout);
    1239 
    1240     foreach (const QString &strLayout, defaultLayouts)
    1241     {
    1242         QString strName = strLayout.left(strLayout.indexOf('.'));
    1243         QAction *pAction = m_pLayoutActionGroup->addAction(QString("%1 %2").arg(UISoftKeyboard::tr("Load Layout ")).arg(strName.remove(":/")));
    1244         pAction->setData(strLayout);
    1245         pAction->setCheckable(true);
    1246     }
    1247     m_pLoadLayoutFileAction = m_pLayoutActionGroup->addAction(UISoftKeyboard::tr("Load Layout File..."));
    1248     m_pLoadLayoutFileAction->setCheckable(true);
    1249     m_pContextMenu->addActions(m_pLayoutActionGroup->actions());
    12501406
    12511407    /* Keycaps menu: */
     
    12741430        return;
    12751431    m_enmMode = Mode_KeyCapEdit;
     1432}
     1433
     1434void UISoftKeyboardWidget::setKeyBeingEdited(UISoftKeyboardKey* pKey)
     1435{
     1436    if (m_pKeyBeingEdited == pKey)
     1437        return;
     1438    m_pKeyBeingEdited = pKey;
     1439    if (m_pKeyCapEditor)
     1440        m_pKeyCapEditor->setKey(pKey);
    12761441}
    12771442
     
    13991564            m_xmlReader.skipCurrentElement();
    14001565    }
    1401     key.setStaticKeyCap(strKeyCap);
     1566    //key.setStaticKeyCap(strKeyCap);
    14021567}
    14031568
     
    15321697            m_xmlReader.skipCurrentElement();
    15331698    }
    1534 
    15351699    return true;
    15361700}
     
    15421706    while (m_xmlReader.readNextStartElement())
    15431707    {
    1544         if (m_xmlReader.name() == "keycap")
     1708        if (m_xmlReader.name() == "basecaption")
     1709            strKeyCap = m_xmlReader.readElementText();
     1710        if (m_xmlReader.name() == "shiftcaption")
     1711            strKeyCap = m_xmlReader.readElementText();
     1712        if (m_xmlReader.name() == "altgrcaption")
    15451713            strKeyCap = m_xmlReader.readElementText();
    15461714        else if (m_xmlReader.name() == "position")
     
    16571825
    16581826    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);
    16631827
    16641828    m_pSettingsButton = new QToolButton;
     
    16701834    statusBar()->addPermanentWidget(m_pSettingsButton);
    16711835
    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 
    16791836    retranslateUi();
    16801837}
Note: See TracChangeset for help on using the changeset viewer.

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