VirtualBox

Changeset 79404 in vbox


Ignore:
Timestamp:
Jun 28, 2019 10:11:45 AM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
131645
Message:

FE/Qt: bugref:6143. Adding a simple color editor and making the layout list a single select one

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

Legend:

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

    r79398 r79404  
    1919#include <QApplication>
    2020#include <QCheckBox>
     21#include <QColorDialog>
    2122#include <QComboBox>
    2223#include <QFile>
    2324#include <QGroupBox>
    2425#include <QInputDialog>
     26#include <QHeaderView>
    2527#include <QLabel>
    2628#include <QLineEdit>
     
    502504    bool showNumPad();
    503505    void setShowNumPad(bool fShow);
     506
     507    const QColor &color(int iColorType) const;
     508    void setColor(int iColorType, const QColor &color);
    504509
    505510protected:
     
    543548
    544549    UISoftKeyboardKey *m_pKeyPressed;
    545     QColor m_keyDefaultColor;
     550    QColor m_keyBackgroundColor;
    546551    QColor m_keyHoverColor;
    547     QColor m_textDefaultColor;
    548     QColor m_textPressedColor;
     552    QColor m_fontDefaultColor;
     553    QColor m_fontPressedColor;
    549554    QColor m_keyEditColor;
    550555    QVector<UISoftKeyboardKey*> m_pressedModifiers;
     
    667672    Q_OBJECT;
    668673
     674public:
     675
     676    enum ColorTableRow
     677    {
     678        ColorTableRow_Background = 0,
     679        ColorTableRow_Font,
     680        ColorTableRow_Hover,
     681        ColorTableRow_Edit,
     682        ColorTableRow_Pressed,
     683        ColorTableRow_Max
     684    };
     685
    669686signals:
    670687
    671688    void sigShowNumPad(bool fShow);
    672689    void sigShowOSMenuKeys(bool fShow);
     690    void sigColorCellClicked(int iColorRow);
     691    void sigCloseSettingsWidget();
    673692
    674693public:
     
    677696    void setShowOSMenuKeys(bool fShow);
    678697    void setShowNumPad(bool fShow);
     698    void setTableItemColor(ColorTableRow tableRow, const QColor &color);
    679699
    680700protected:
     
    684704private slots:
    685705
     706    void sltColorCellClicked(int row, int column);
    686707
    687708private:
     
    689710    void prepareObjects();
    690711
    691     QCheckBox   *m_pShowNumPadCheckBox;
    692     QCheckBox   *m_pShowOsMenuButtonsCheckBox;
     712    QCheckBox    *m_pShowNumPadCheckBox;
     713    QCheckBox    *m_pShowOsMenuButtonsCheckBox;
     714    QGroupBox    *m_pColorTableGroupBox;
    693715    QTableWidget *m_pColorSelectionTable;
     716    QLabel       *m_pTitleLabel;
     717    QToolButton  *m_pCloseButton;
    694718};
    695719
     
    11641188    pLayout->addWidget(m_pLayoutListWidget);
    11651189    connect(m_pLayoutListWidget, &QListWidget::currentItemChanged, this, &UILayoutSelector::sltCurrentItemChanged);
    1166 
     1190    m_pLayoutListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
    11671191    QHBoxLayout *pButtonsLayout = new QHBoxLayout;
    11681192    pLayout->addLayout(pButtonsLayout);
     
    17121736    , m_pKeyBeingEdited(0)
    17131737    , m_pKeyPressed(0)
    1714     , m_keyDefaultColor(QColor(103, 128, 159))
     1738    , m_keyBackgroundColor(QColor(103, 128, 159))
    17151739    , m_keyHoverColor(QColor(108, 122, 137))
    1716     , m_textDefaultColor(QColor(46, 49, 49))
    1717     , m_textPressedColor(QColor(149, 165, 166))
     1740    , m_fontDefaultColor(QColor(46, 49, 49))
     1741    , m_fontPressedColor(QColor(149, 165, 166))
    17181742    , m_keyEditColor(QColor(249, 165, 166))
    17191743    , m_pCurrentKeyboardLayout(0)
     
    17951819                painter.setBrush(QBrush(m_keyHoverColor));
    17961820            else
    1797                 painter.setBrush(QBrush(m_keyDefaultColor));
     1821                painter.setBrush(QBrush(m_keyBackgroundColor));
    17981822
    17991823            if (&key  == m_pKeyPressed)
    1800                 painter.setPen(QPen(QColor(m_textPressedColor), 2));
     1824                painter.setPen(QPen(QColor(m_fontPressedColor), 2));
    18011825            else
    1802                 painter.setPen(QPen(QColor(m_textDefaultColor), 2));
     1826                painter.setPen(QPen(QColor(m_fontDefaultColor), 2));
    18031827
    18041828            painter.drawPolygon(key.polygon());
     
    18101834                QColor ledColor;
    18111835                if (key.state() == UIKeyState_NotPressed)
    1812                     ledColor = m_textDefaultColor;
     1836                    ledColor = m_fontDefaultColor;
    18131837                else if (key.state() == UIKeyState_Pressed)
    18141838                    ledColor = QColor(0, 255, 0);
     
    20052029    m_fShowNumPad = fShow;
    20062030    update();
     2031}
     2032
     2033const QColor &UISoftKeyboardWidget::color(int iColorType) const
     2034{
     2035    UISoftKeyboardSettingsWidget::ColorTableRow enmColorType = static_cast<UISoftKeyboardSettingsWidget::ColorTableRow>(iColorType);
     2036    switch (enmColorType)
     2037    {
     2038        case UISoftKeyboardSettingsWidget::ColorTableRow_Background:
     2039            return m_keyBackgroundColor;
     2040            break;
     2041        case UISoftKeyboardSettingsWidget::ColorTableRow_Edit:
     2042            return m_keyEditColor;
     2043            break;
     2044        case UISoftKeyboardSettingsWidget::ColorTableRow_Font:
     2045            return m_fontDefaultColor;
     2046            break;
     2047        case UISoftKeyboardSettingsWidget::ColorTableRow_Hover:
     2048            return m_keyHoverColor;
     2049            break;
     2050        case UISoftKeyboardSettingsWidget::ColorTableRow_Pressed:
     2051            return m_fontPressedColor;
     2052            break;
     2053        case UISoftKeyboardSettingsWidget::ColorTableRow_Max:
     2054        default:
     2055            return m_keyBackgroundColor;
     2056            break;
     2057    }
     2058    return m_keyBackgroundColor;
     2059}
     2060
     2061void UISoftKeyboardWidget::setColor(int iColorType, const QColor &color)
     2062{
     2063    UISoftKeyboardSettingsWidget::ColorTableRow enmColorType = static_cast<UISoftKeyboardSettingsWidget::ColorTableRow>(iColorType);
     2064    switch (enmColorType)
     2065    {
     2066        case UISoftKeyboardSettingsWidget::ColorTableRow_Background:
     2067            m_keyBackgroundColor = color;
     2068            break;
     2069        case UISoftKeyboardSettingsWidget::ColorTableRow_Edit:
     2070            m_keyEditColor = color;
     2071            break;
     2072        case UISoftKeyboardSettingsWidget::ColorTableRow_Font:
     2073            m_fontDefaultColor = color;
     2074            break;
     2075        case UISoftKeyboardSettingsWidget::ColorTableRow_Hover:
     2076            m_keyHoverColor = color;
     2077            break;
     2078        case UISoftKeyboardSettingsWidget::ColorTableRow_Pressed:
     2079            m_fontPressedColor = color;
     2080            break;
     2081        case UISoftKeyboardSettingsWidget::ColorTableRow_Max:
     2082        default:
     2083            break;
     2084    }
    20072085}
    20082086
     
    28882966    , m_pShowNumPadCheckBox(0)
    28892967    , m_pShowOsMenuButtonsCheckBox(0)
     2968    , m_pColorTableGroupBox(0)
    28902969    , m_pColorSelectionTable(0)
     2970    , m_pTitleLabel(0)
     2971    , m_pCloseButton(0)
     2972
    28912973{
    28922974    prepareObjects();
     
    29052987}
    29062988
     2989void UISoftKeyboardSettingsWidget::setTableItemColor(ColorTableRow tableRow, const QColor &color)
     2990{
     2991    if (!m_pColorSelectionTable)
     2992        return;
     2993    QTableWidgetItem *pItem = m_pColorSelectionTable->item(tableRow, 1);
     2994    if (!pItem)
     2995        return;
     2996    pItem->setBackground(color);
     2997    m_pColorSelectionTable->update();
     2998}
     2999
    29073000void UISoftKeyboardSettingsWidget::retranslateUi()
    29083001{
     3002    if (m_pTitleLabel)
     3003        m_pTitleLabel->setText(UISoftKeyboard::tr("Keyboard Settings"));
     3004    if (m_pCloseButton)
     3005    {
     3006        m_pCloseButton->setToolTip(UISoftKeyboard::tr("Close the layout list"));
     3007        m_pCloseButton->setText("Close");
     3008    }
    29093009    if (m_pShowNumPadCheckBox)
    29103010        m_pShowNumPadCheckBox->setText(UISoftKeyboard::tr("Show NumPad"));
    29113011    if (m_pShowOsMenuButtonsCheckBox)
    29123012        m_pShowOsMenuButtonsCheckBox->setText(UISoftKeyboard::tr("Show OS/Menu Keys"));
    2913 
     3013    if (m_pColorTableGroupBox)
     3014        m_pColorTableGroupBox->setTitle(UISoftKeyboard::tr("Button Colors"));
     3015    if (m_pColorSelectionTable)
     3016    {
     3017        QTableWidgetItem *pItem = m_pColorSelectionTable->itemAt(ColorTableRow_Background, 0);
     3018        if (pItem)
     3019            pItem->setText(UISoftKeyboard::tr("Button Background Color"));
     3020        pItem = m_pColorSelectionTable->item(ColorTableRow_Font, 0);
     3021        if (pItem)
     3022            pItem->setText(UISoftKeyboard::tr("Button Font Color"));
     3023        pItem = m_pColorSelectionTable->item(ColorTableRow_Hover, 0);
     3024        if (pItem)
     3025            pItem->setText(UISoftKeyboard::tr("Button Hover Color"));
     3026        pItem = m_pColorSelectionTable->item(ColorTableRow_Edit, 0);
     3027        if (pItem)
     3028            pItem->setText(UISoftKeyboard::tr("Button Edit Color"));
     3029        pItem = m_pColorSelectionTable->item(ColorTableRow_Pressed, 0);
     3030        if (pItem)
     3031            pItem->setText(UISoftKeyboard::tr("Pressed Button Color"));
     3032        m_pColorSelectionTable->setToolTip(UISoftKeyboard::tr("Click on the corresponding table cells to modify colors"));
     3033    }
    29143034}
    29153035
     
    29193039    if (!pSettingsLayout)
    29203040        return;
     3041
     3042    QHBoxLayout *pTitleLayout = new QHBoxLayout;
     3043    m_pCloseButton = new QToolButton;
     3044    m_pCloseButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
     3045    m_pCloseButton->setIcon(UIIconPool::defaultIcon(UIIconPool::UIDefaultIconType_DialogCancel));
     3046    m_pCloseButton->setAutoRaise(true);
     3047    connect(m_pCloseButton, &QToolButton::clicked, this, &UISoftKeyboardSettingsWidget::sigCloseSettingsWidget);
     3048    pTitleLayout->addWidget(m_pCloseButton);
     3049    pTitleLayout->addStretch(2);
     3050    m_pTitleLabel = new QLabel;
     3051    pTitleLayout->addWidget(m_pTitleLabel);
     3052    pSettingsLayout->addLayout(pTitleLayout, 0, 0, 1, 2);
     3053
    29213054    m_pShowNumPadCheckBox = new QCheckBox;
    29223055    m_pShowOsMenuButtonsCheckBox = new QCheckBox;
    2923 
    2924     pSettingsLayout->addWidget(m_pShowNumPadCheckBox, 0, 0, 1, 1);
    2925     pSettingsLayout->addWidget(m_pShowOsMenuButtonsCheckBox, 1, 0, 1, 1);
    2926 
     3056    pSettingsLayout->addWidget(m_pShowNumPadCheckBox, 1, 0, 1, 1);
     3057    pSettingsLayout->addWidget(m_pShowOsMenuButtonsCheckBox, 2, 0, 1, 1);
    29273058    connect(m_pShowNumPadCheckBox, &QCheckBox::toggled, this, &UISoftKeyboardSettingsWidget::sigShowNumPad);
    29283059    connect(m_pShowOsMenuButtonsCheckBox, &QCheckBox::toggled, this, &UISoftKeyboardSettingsWidget::sigShowOSMenuKeys);
    29293060
     3061    /* A groupbox to host the color table widget: */
     3062    m_pColorTableGroupBox = new QGroupBox;
     3063    QVBoxLayout *pTableGroupBoxLayout = new QVBoxLayout(m_pColorTableGroupBox);
     3064    pSettingsLayout->addWidget(m_pColorTableGroupBox, 3, 0, 2, 1);
     3065
     3066    /* Creating and configuring the color table widget: */
    29303067    m_pColorSelectionTable = new QTableWidget;
    2931     pSettingsLayout->addWidget(m_pShowOsMenuButtonsCheckBox, 2, 0, 2, 1);
    2932     m_pColorSelectionTable->setRowCount(3);
     3068    pTableGroupBoxLayout->addWidget(m_pColorSelectionTable);
     3069    m_pColorSelectionTable->setRowCount(ColorTableRow_Max);
    29333070    m_pColorSelectionTable->setColumnCount(2);
    2934 
     3071    m_pColorSelectionTable->horizontalHeader()->hide();
     3072    m_pColorSelectionTable->verticalHeader()->hide();
     3073    m_pColorSelectionTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
     3074    m_pColorSelectionTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
     3075    m_pColorSelectionTable->setFocusPolicy(Qt::NoFocus);
     3076    m_pColorSelectionTable->setSelectionMode(QAbstractItemView::NoSelection);
     3077    connect(m_pColorSelectionTable, &QTableWidget::cellClicked, this, &UISoftKeyboardSettingsWidget::sltColorCellClicked);
     3078
     3079    /* Create column 0 items: */
     3080    m_pColorSelectionTable->setItem(ColorTableRow_Background, 0, new QTableWidgetItem());
     3081    m_pColorSelectionTable->setItem(ColorTableRow_Font, 0, new QTableWidgetItem());
     3082    m_pColorSelectionTable->setItem(ColorTableRow_Hover, 0, new QTableWidgetItem());
     3083    m_pColorSelectionTable->setItem(ColorTableRow_Edit, 0, new QTableWidgetItem());
     3084    m_pColorSelectionTable->setItem(ColorTableRow_Pressed, 0, new QTableWidgetItem());
     3085
     3086    /* Create column 1 items: */
     3087    for (int i = ColorTableRow_Background; i < ColorTableRow_Max; ++i)
     3088    {
     3089        QTableWidgetItem *pItem = new QTableWidgetItem();
     3090        m_pColorSelectionTable->setItem(static_cast<ColorTableRow>(i), 1, pItem);
     3091        pItem->setIcon(UIIconPool::defaultIcon(UIIconPool::UIDefaultIconType_ArrowBack));
     3092    }
    29353093
    29363094    QSpacerItem *pSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding);
    29373095    if (pSpacer)
    2938         pSettingsLayout->addItem(pSpacer, 4, 0);
     3096        pSettingsLayout->addItem(pSpacer, 5, 0);
    29393097
    29403098    setLayout(pSettingsLayout);
     
    29423100}
    29433101
     3102void UISoftKeyboardSettingsWidget::sltColorCellClicked(int row, int column)
     3103{
     3104    if (column != 1 || row >= static_cast<int>(ColorTableRow_Max))
     3105        return;
     3106    emit sigColorCellClicked(row);
     3107}
    29443108
    29453109/*********************************************************************************************************************************
     
    29753139
    29763140    loadSettings();
     3141    configure();
    29773142    retranslateUi();
    29783143}
     
    31283293    if (m_pKeyboardWidget)
    31293294        m_pKeyboardWidget->setShowNumPad(fShow);
     3295}
     3296
     3297void UISoftKeyboard::sltHandleColorCellClick(int iColorRow)
     3298{
     3299    if (!m_pKeyboardWidget || iColorRow >= static_cast<int>(UISoftKeyboardSettingsWidget::ColorTableRow_Max))
     3300        return;
     3301    const QColor &currentColor = m_pKeyboardWidget->color(iColorRow);
     3302    QColorDialog colorDialog(currentColor, this);
     3303
     3304    if (colorDialog.exec() == QDialog::Rejected)
     3305        return;
     3306    QColor newColor = colorDialog.selectedColor();
     3307    if (currentColor == newColor)
     3308        return;
     3309    m_pKeyboardWidget->setColor(iColorRow, newColor);
     3310    m_pSettingsWidget->setTableItemColor(static_cast<UISoftKeyboardSettingsWidget::ColorTableRow>(iColorRow), newColor);
    31303311}
    31313312
     
    32003381    connect(m_pSettingsWidget, &UISoftKeyboardSettingsWidget::sigShowOSMenuKeys, this, &UISoftKeyboard::sltShowHideOSMenuKeys);
    32013382    connect(m_pSettingsWidget, &UISoftKeyboardSettingsWidget::sigShowNumPad, this, &UISoftKeyboard::sltShowHideNumPad);
     3383    connect(m_pSettingsWidget, &UISoftKeyboardSettingsWidget::sigColorCellClicked, this, &UISoftKeyboard::sltHandleColorCellClick);
     3384    connect(m_pSettingsWidget, &UISoftKeyboardSettingsWidget::sigCloseSettingsWidget, this, &UISoftKeyboard::sltShowHideSettingsWidget);
    32023385}
    32033386
     
    32393422             geometry.x(), geometry.y(), geometry.width(), geometry.height()));
    32403423    setDialogGeometry(geometry);
    3241 
     3424}
     3425
     3426void UISoftKeyboard::configure()
     3427{
     3428    setWindowIcon(UIIconPool::iconSetFull(":/vm_show_logs_32px.png", ":/vm_show_logs_16px.png"));
    32423429    if (m_pKeyboardWidget && m_pSettingsWidget)
    32433430    {
    32443431        m_pSettingsWidget->setShowOSMenuKeys(m_pKeyboardWidget->showOSMenuKeys());
    32453432        m_pSettingsWidget->setShowNumPad(m_pKeyboardWidget->showNumPad());
     3433
     3434        for (int i = static_cast<int>(UISoftKeyboardSettingsWidget::ColorTableRow_Background);
     3435             i < static_cast<int>(UISoftKeyboardSettingsWidget::ColorTableRow_Max); ++i)
     3436            m_pSettingsWidget->setTableItemColor(static_cast<UISoftKeyboardSettingsWidget::ColorTableRow>(i),
     3437                                                 m_pKeyboardWidget->color(i));
    32463438    }
    32473439}
  • trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.h

    r79385 r79404  
    8787    void sltShowHideOSMenuKeys(bool fShow);
    8888    void sltShowHideNumPad(bool fShow);
     89    void sltHandleColorCellClick(int iColorRow);
    8990
    9091private:
     
    9495    void saveSettings();
    9596    void loadSettings();
     97    void configure();
    9698    void updateStatusBarMessage(const QString &strLayoutName);
    9799    void updateLayoutSelector();
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