VirtualBox

Changeset 81298 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Oct 16, 2019 5:15:13 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
134003
Message:

FE/Qt: bugref:6143. Replacing the color selection table with a set of buttons.

File:
1 edited

Legend:

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

    r81294 r81298  
    3131#include <QPainter>
    3232#include <QPicture>
     33#include <QPushButton>
    3334#include <QSplitter>
    3435#include <QStatusBar>
     
    5455
    5556/* Forward declarations: */
     57class UISoftKeyboardColorButton;
    5658class UISoftKeyboardLayout;
    5759class UISoftKeyboardRow;
     
    6668/** Set a generous file size limit. */
    6769const qint64 iFileSizeLimit = _256K;
    68 
    6970const QString strSubDirectorName("keyboardLayouts");
     71
     72typedef QPair<QLabel*, UISoftKeyboardColorButton*> ColorSelectLabelButton;
    7073
    7174enum KeyState
     
    145148                                          {"Solarized-Light","#b58900", "#586e75", "#dc322f", "#6c71c4", "#859900"},
    146149                                          {0, 0, 0, 0, 0, 0}};
     150
     151
     152/*********************************************************************************************************************************
     153*   UISoftKeyboardColorButton definition.                                                                                        *
     154*********************************************************************************************************************************/
     155
     156class UISoftKeyboardColorButton : public QPushButton
     157{
     158    Q_OBJECT;
     159
     160public:
     161
     162    UISoftKeyboardColorButton(KeyboardColorType enmColorType, QWidget *pParent = 0);
     163    KeyboardColorType colorType() const;
     164
     165public:
     166
     167    KeyboardColorType m_enmColorType;
     168};
    147169
    148170
     
    625647
    626648    /** Unlike modifier and ordinary keys we update the state of the Lock keys thru event singals we receieve
    627       * from the guest OS. Parameter fXXXState is true if the corresponding key is locked. */
     649      * from the guest OS. Parameter f???State is true if the corresponding key is locked. */
    628650    void updateLockKeyStates(bool fCapsLockState, bool fNumLockState, bool fScrollLockState);
    629651    void reset();
     
    809831private slots:
    810832
    811     void sltColorCellClicked(int row, int column);
     833    void sltColorSelectionButtonClicked();
    812834
    813835private:
     
    819841    QCheckBox    *m_pHideMultimediaKeysCheckBox;
    820842    QGroupBox    *m_pColorTableGroupBox;
    821     QListWidget  *m_pColorThemeList;
    822     QTableWidget *m_pColorSelectionTable;
     843    QComboBox    *m_pColorThemeComboBox;
    823844    QLabel       *m_pTitleLabel;
    824845    QToolButton  *m_pCloseButton;
     846    QVector<ColorSelectLabelButton> m_colorSelectLabelsButtons;
    825847};
     848
     849
     850/*********************************************************************************************************************************
     851*   UISoftKeyboardColorButton implementation.                                                                                    *
     852*********************************************************************************************************************************/
     853
     854
     855UISoftKeyboardColorButton::UISoftKeyboardColorButton(KeyboardColorType enmColorType, QWidget *pParent /*= 0 */)
     856    :QPushButton(pParent)
     857    , m_enmColorType(enmColorType){}
     858
     859KeyboardColorType UISoftKeyboardColorButton::colorType() const
     860{
     861    return m_enmColorType;
     862}
    826863
    827864
     
    34703507    , m_pHideMultimediaKeysCheckBox(0)
    34713508    , m_pColorTableGroupBox(0)
    3472     , m_pColorThemeList(0)
    3473     , m_pColorSelectionTable(0)
     3509    , m_pColorThemeComboBox(0)
    34743510    , m_pTitleLabel(0)
    34753511    , m_pCloseButton(0)
     
    34993535void UISoftKeyboardSettingsWidget::setTableItemColor(KeyboardColorType tableRow, const QColor &color)
    35003536{
    3501     if (!m_pColorSelectionTable)
    3502         return;
    3503     QTableWidgetItem *pItem = m_pColorSelectionTable->item(tableRow, 1);
    3504     if (!pItem)
    3505         return;
    3506     pItem->setBackground(color);
    3507     m_pColorSelectionTable->update();
     3537    if (m_colorSelectLabelsButtons.size() > tableRow && m_colorSelectLabelsButtons[tableRow].second)
     3538    {
     3539        UISoftKeyboardColorButton *pButton = m_colorSelectLabelsButtons[tableRow].second;
     3540        QPalette pal = pButton->palette();
     3541        pal.setColor(QPalette::Button, color);
     3542        pButton->setAutoFillBackground(true);
     3543        pButton->setPalette(pal);
     3544        pButton->update();
     3545    }
    35083546}
    35093547
    35103548void UISoftKeyboardSettingsWidget::setColorThemeNames(const QStringList &colorThemeNames)
    35113549{
    3512     if (!m_pColorThemeList)
    3513         return;
     3550    if (!m_pColorThemeComboBox)
     3551        return;
     3552    m_pColorThemeComboBox->blockSignals(true);
    35143553    foreach (const QString &strName, colorThemeNames)
    3515         m_pColorThemeList->addItem(strName);
     3554        m_pColorThemeComboBox->addItem(strName);
     3555    m_pColorThemeComboBox->blockSignals(false);
    35163556}
    35173557
    35183558void UISoftKeyboardSettingsWidget::setCurrentColorThemeName(const QString &strColorThemeName)
    35193559{
    3520     if (!m_pColorThemeList)
    3521         return;
    3522     QList<QListWidgetItem*> items = m_pColorThemeList->findItems(strColorThemeName, Qt::MatchFixedString);
    3523     if (items.isEmpty())
    3524         return;
    3525     m_pColorThemeList->blockSignals(true);
    3526     m_pColorThemeList->setCurrentItem(items[0]);
    3527     m_pColorThemeList->blockSignals(false);
     3560    if (!m_pColorThemeComboBox)
     3561        return;
     3562    int iItemIndex = m_pColorThemeComboBox->findText(strColorThemeName, Qt::MatchFixedString);
     3563    if (iItemIndex == -1)
     3564        return;
     3565    m_pColorThemeComboBox->blockSignals(true);
     3566    m_pColorThemeComboBox->setCurrentIndex(iItemIndex);
     3567    m_pColorThemeComboBox->blockSignals(false);
    35283568}
    35293569
     
    35453585    if (m_pColorTableGroupBox)
    35463586        m_pColorTableGroupBox->setTitle(UISoftKeyboard::tr("Button Colors"));
    3547     if (m_pColorSelectionTable)
    3548     {
    3549         QTableWidgetItem *pItem = m_pColorSelectionTable->itemAt(KeyboardColorType_Background, 0);
    3550         if (pItem)
    3551             pItem->setText(UISoftKeyboard::tr("Button Background Color"));
    3552         pItem = m_pColorSelectionTable->item(KeyboardColorType_Font, 0);
    3553         if (pItem)
    3554             pItem->setText(UISoftKeyboard::tr("Button Font Color"));
    3555         pItem = m_pColorSelectionTable->item(KeyboardColorType_Hover, 0);
    3556         if (pItem)
    3557             pItem->setText(UISoftKeyboard::tr("Button Hover Color"));
    3558         pItem = m_pColorSelectionTable->item(KeyboardColorType_Edit, 0);
    3559         if (pItem)
    3560             pItem->setText(UISoftKeyboard::tr("Button Edit Color"));
    3561         pItem = m_pColorSelectionTable->item(KeyboardColorType_Pressed, 0);
    3562         if (pItem)
    3563             pItem->setText(UISoftKeyboard::tr("Pressed Button Font Color"));
    3564         m_pColorSelectionTable->setToolTip(UISoftKeyboard::tr("Click on the corresponding table cells to modify colors"));
     3587
     3588    if (m_colorSelectLabelsButtons.size() == KeyboardColorType_Max)
     3589    {
     3590        if (m_colorSelectLabelsButtons[KeyboardColorType_Background].first)
     3591            m_colorSelectLabelsButtons[KeyboardColorType_Background].first->setText(UISoftKeyboard::tr("Button Background Color"));
     3592        if (m_colorSelectLabelsButtons[KeyboardColorType_Font].first)
     3593            m_colorSelectLabelsButtons[KeyboardColorType_Font].first->setText(UISoftKeyboard::tr("Button Font Color"));
     3594        if (m_colorSelectLabelsButtons[KeyboardColorType_Hover].first)
     3595            m_colorSelectLabelsButtons[KeyboardColorType_Hover].first->setText(UISoftKeyboard::tr("Button Hover Color"));
     3596        if (m_colorSelectLabelsButtons[KeyboardColorType_Edit].first)
     3597            m_colorSelectLabelsButtons[KeyboardColorType_Edit].first->setText(UISoftKeyboard::tr("Button Edit Color"));
     3598        if (m_colorSelectLabelsButtons[KeyboardColorType_Pressed].first)
     3599            m_colorSelectLabelsButtons[KeyboardColorType_Pressed].first->setText(UISoftKeyboard::tr("Pressed Button Font Color"));
    35653600    }
    35663601}
     
    35973632    m_pColorTableGroupBox = new QGroupBox;
    35983633    QVBoxLayout *pTableGroupBoxLayout = new QVBoxLayout(m_pColorTableGroupBox);
    3599     pSettingsLayout->addWidget(m_pColorTableGroupBox, 4, 0, 2, 1);
    3600 
    3601     m_pColorThemeList = new QListWidget;
    3602     pTableGroupBoxLayout->addWidget(m_pColorThemeList);
    3603     connect(m_pColorThemeList, &QListWidget::currentTextChanged, this, &UISoftKeyboardSettingsWidget::sigColorThemeSelectionChanged);
    3604 
    3605     /* Creating and configuring the color table widget: */
    3606     m_pColorSelectionTable = new QTableWidget;
    3607     pTableGroupBoxLayout->addWidget(m_pColorSelectionTable);
    3608     m_pColorSelectionTable->setRowCount(KeyboardColorType_Max);
    3609     m_pColorSelectionTable->setColumnCount(2);
    3610     m_pColorSelectionTable->horizontalHeader()->hide();
    3611     m_pColorSelectionTable->verticalHeader()->hide();
    3612     m_pColorSelectionTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    3613     m_pColorSelectionTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
    3614     m_pColorSelectionTable->setFocusPolicy(Qt::NoFocus);
    3615     m_pColorSelectionTable->setSelectionMode(QAbstractItemView::NoSelection);
    3616     connect(m_pColorSelectionTable, &QTableWidget::cellClicked, this, &UISoftKeyboardSettingsWidget::sltColorCellClicked);
    3617 
    3618     /* Create column 0 items: */
    3619     m_pColorSelectionTable->setItem(KeyboardColorType_Background, 0, new QTableWidgetItem());
    3620     m_pColorSelectionTable->setItem(KeyboardColorType_Font, 0, new QTableWidgetItem());
    3621     m_pColorSelectionTable->setItem(KeyboardColorType_Hover, 0, new QTableWidgetItem());
    3622     m_pColorSelectionTable->setItem(KeyboardColorType_Edit, 0, new QTableWidgetItem());
    3623     m_pColorSelectionTable->setItem(KeyboardColorType_Pressed, 0, new QTableWidgetItem());
    3624 
    3625     /* Create column 1 items: */
     3634    pSettingsLayout->addWidget(m_pColorTableGroupBox, 4, 0, 1, 1);
     3635
     3636    m_pColorThemeComboBox = new QComboBox;
     3637    pTableGroupBoxLayout->addWidget(m_pColorThemeComboBox);
     3638    connect(m_pColorThemeComboBox, &QComboBox::currentTextChanged, this, &UISoftKeyboardSettingsWidget::sigColorThemeSelectionChanged);
     3639
     3640    /* Creating and configuring the color selection buttons: */
     3641    QGridLayout *pColorSelectionLayout = new QGridLayout;
     3642    pColorSelectionLayout->setSpacing(1);
     3643    pTableGroupBoxLayout->addLayout(pColorSelectionLayout);
    36263644    for (int i = KeyboardColorType_Background; i < KeyboardColorType_Max; ++i)
    36273645    {
    3628         QTableWidgetItem *pItem = new QTableWidgetItem();
    3629         m_pColorSelectionTable->setItem(static_cast<KeyboardColorType>(i), 1, pItem);
    3630         pItem->setIcon(UIIconPool::defaultIcon(UIIconPool::UIDefaultIconType_ArrowBack));
     3646        QLabel *pLabel = new QLabel;
     3647        UISoftKeyboardColorButton *pButton = new UISoftKeyboardColorButton((KeyboardColorType)i);
     3648        pColorSelectionLayout->addWidget(pLabel, i, 0, 1, 1);
     3649        pColorSelectionLayout->addWidget(pButton, i, 1, 1, 1);
     3650        m_colorSelectLabelsButtons.append(ColorSelectLabelButton(pLabel, pButton));
     3651        connect(pButton, &UISoftKeyboardColorButton::clicked, this, &UISoftKeyboardSettingsWidget::sltColorSelectionButtonClicked);
    36313652    }
    36323653
     
    36393660}
    36403661
    3641 void UISoftKeyboardSettingsWidget::sltColorCellClicked(int row, int column)
    3642 {
    3643     if (column != 1 || row >= static_cast<int>(KeyboardColorType_Max))
    3644         return;
    3645     emit sigColorCellClicked(row);
     3662void UISoftKeyboardSettingsWidget::sltColorSelectionButtonClicked()
     3663{
     3664    UISoftKeyboardColorButton *pButton = qobject_cast<UISoftKeyboardColorButton*>(sender());
     3665    if (!pButton)
     3666        return;
     3667    emit sigColorCellClicked((int)pButton->colorType());
    36463668}
    36473669
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