VirtualBox

Changeset 81293 in vbox


Ignore:
Timestamp:
Oct 16, 2019 6:46:56 AM (5 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6143. Adding a color theme list widget.

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

Legend:

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

    r81285 r81293  
    141141    bool fRelease;
    142142};
    143 
    144 
     143/* Name, background color, normal font color, hover color, edited button background color, pressed button font color. */
     144const char* predefinedColorThemes[][6] = {{"Solarized-Dark","#073642", "#586e75", "#dc322f", "#6c71c4", "#859900"},
     145                                          {"Solarized-Light","#b58900", "#586e75", "#dc322f", "#6c71c4", "#859900"},
     146                                          {0, 0, 0, 0, 0, 0}};
    145147/*********************************************************************************************************************************
    146148*   UISoftKeyboardPhysicalLayout definition.                                                                                     *
     
    534536
    535537    UISoftKeyboardColorTheme();
     538    UISoftKeyboardColorTheme(const QString &strName,
     539                             const QString &strBackgroundColor,
     540                             const QString &strNormalFontColor,
     541                             const QString &strHoverColor,
     542                             const QString &strEditedButtonBackgroundColor,
     543                             const QString &strPressedButtonFontColor);
     544
    536545    void setColor(KeyboardColorType enmColorType, const QColor &color);
    537546    QColor color(KeyboardColorType enmColorType) const;
     
    539548    void colorsFromStringList(const QStringList &colorStringList);
    540549
     550    const QString &name() const;
     551    void setName(const QString &strName);
     552
    541553private:
    542554
    543555    QVector<QColor> m_colors;
     556    QString m_strName;
    544557};
    545558
     
    565578    void sigStatusBarMessage(const QString &strMessage);
    566579    void sigPutKeyboardSequence(QVector<LONG> sequence);
    567 
    568580    void sigPutUsageCodesPress(QVector<QPair<LONG, LONG> > sequence);
    569581    void sigPutUsageCodesRelease(QVector<QPair<LONG, LONG> > sequence);
    570 
    571 
    572582    void sigCurrentLayoutChange();
    573583    void sigKeyToEdit(UISoftKeyboardKey* pKey);
     584    void sigCurrentColorThemeChanged();
    574585
    575586public:
     
    605616    void setHideMultimediaKeys(bool fHide);
    606617
    607     const QColor color(KeyboardColorType enmColorType) const;
     618    QColor color(KeyboardColorType enmColorType) const;
    608619    void setColor(KeyboardColorType ennmColorType, const QColor &color);
    609620
     
    615626    void updateLockKeyStates(bool fCapsLockState, bool fNumLockState, bool fScrollLockState);
    616627    void reset();
     628
     629    QStringList colorThemeNames() const;
     630    QString currentColorThemeName() const;
     631    void setColorTheme(const QString &strColorThemeName);
    617632
    618633protected:
     
    657672
    658673    UISoftKeyboardKey *m_pKeyPressed;
    659     UISoftKeyboardColorTheme m_colorTheme;
     674    UISoftKeyboardColorTheme *m_currentColorTheme;
     675    QVector<UISoftKeyboardColorTheme> m_colorThemes;
    660676    QVector<UISoftKeyboardKey*> m_pressedModifiers;
    661677    QVector<UISoftKeyboardPhysicalLayout> m_physicalLayouts;
     
    773789    void sigColorCellClicked(int iColorRow);
    774790    void sigCloseSettingsWidget();
     791    void sigColorThemeSelectionChanged(const QString &strColorThemeName);
    775792
    776793public:
     
    781798    void setHideMultimediaKeys(bool fHide);
    782799    void setTableItemColor(KeyboardColorType tableRow, const QColor &color);
     800    void setColorThemeNames(const QStringList &colorThemeNames);
     801    void setCurrentColorThemeName(const QString &strColorThemeName);
    783802
    784803protected:
     
    798817    QCheckBox    *m_pHideMultimediaKeysCheckBox;
    799818    QGroupBox    *m_pColorTableGroupBox;
     819    QListWidget  *m_pColorThemeList;
    800820    QTableWidget *m_pColorSelectionTable;
    801821    QLabel       *m_pTitleLabel;
     
    19942014}
    19952015
     2016UISoftKeyboardColorTheme::UISoftKeyboardColorTheme(const QString &strName,
     2017                                                   const QString &strBackgroundColor,
     2018                                                   const QString &strNormalFontColor,
     2019                                                   const QString &strHoverColor,
     2020                                                   const QString &strEditedButtonBackgroundColor,
     2021                                                   const QString &strPressedButtonFontColor)
     2022    :m_colors(QVector<QColor>(KeyboardColorType_Max))
     2023    ,m_strName(strName)
     2024{
     2025    m_colors[KeyboardColorType_Background].setNamedColor(strBackgroundColor);
     2026    m_colors[KeyboardColorType_Font].setNamedColor(strNormalFontColor);
     2027    m_colors[KeyboardColorType_Hover].setNamedColor(strHoverColor);
     2028    m_colors[KeyboardColorType_Edit].setNamedColor(strEditedButtonBackgroundColor);
     2029    m_colors[KeyboardColorType_Pressed].setNamedColor(strPressedButtonFontColor);
     2030}
     2031
     2032
    19962033void UISoftKeyboardColorTheme::setColor(KeyboardColorType enmColorType, const QColor &color)
    19972034{
     
    20252062    }
    20262063}
     2064
     2065const QString &UISoftKeyboardColorTheme::name() const
     2066{
     2067    return m_strName;
     2068}
     2069
     2070void UISoftKeyboardColorTheme::setName(const QString &strName)
     2071{
     2072    m_strName = strName;
     2073}
     2074
    20272075
    20282076/*********************************************************************************************************************************
     
    20352083    , m_pKeyBeingEdited(0)
    20362084    , m_pKeyPressed(0)
     2085    , m_currentColorTheme(0)
    20372086    , m_pCurrentKeyboardLayout(0)
    20382087    , m_iInitialHeight(0)
     
    20512100{
    20522101    prepareObjects();
     2102
     2103    int iIndex = 0;
     2104    while (predefinedColorThemes[iIndex][0])
     2105    {
     2106        m_colorThemes << UISoftKeyboardColorTheme(predefinedColorThemes[iIndex][0],
     2107                                                  predefinedColorThemes[iIndex][1],
     2108                                                  predefinedColorThemes[iIndex][2],
     2109                                                  predefinedColorThemes[iIndex][3],
     2110                                                  predefinedColorThemes[iIndex][4],
     2111                                                  predefinedColorThemes[iIndex][5]);
     2112        ++iIndex;
     2113    }
     2114
     2115    UISoftKeyboardColorTheme customTheme;
     2116    customTheme.setName("Custom");
     2117    m_colorThemes.append(customTheme);
     2118    m_currentColorTheme = &(m_colorThemes.back());
    20532119}
    20542120
     
    23652431}
    23662432
    2367 const QColor UISoftKeyboardWidget::color(KeyboardColorType enmColorType) const
    2368 {
    2369     return m_colorTheme.color(enmColorType);
     2433QColor UISoftKeyboardWidget::color(KeyboardColorType enmColorType) const
     2434{
     2435    if (!m_currentColorTheme)
     2436        return QColor();
     2437    return m_currentColorTheme->color(enmColorType);
    23702438}
    23712439
    23722440void UISoftKeyboardWidget::setColor(KeyboardColorType enmColorType, const QColor &color)
    23732441{
    2374     m_colorTheme.setColor(enmColorType, color);
     2442    if (m_currentColorTheme)
     2443        m_currentColorTheme->setColor(enmColorType, color);
     2444    update();
    23752445}
    23762446
    23772447QStringList UISoftKeyboardWidget::colorsToStringList() const
    23782448{
    2379     return m_colorTheme.colorsToStringList();
     2449    if (!m_currentColorTheme)
     2450        QStringList();
     2451    return m_currentColorTheme->colorsToStringList();
    23802452}
    23812453
    23822454void UISoftKeyboardWidget::colorsFromStringList(const QStringList &colorStringList)
    23832455{
    2384     m_colorTheme.colorsFromStringList(colorStringList);
     2456    if (m_currentColorTheme)
     2457        m_currentColorTheme->colorsFromStringList(colorStringList);
    23852458}
    23862459
     
    23902463        m_physicalLayouts[i].updateLockKeyStates(fCapsLockState, fNumLockState, fScrollLockState);
    23912464    update();
     2465}
     2466
     2467QStringList UISoftKeyboardWidget::colorThemeNames() const
     2468{
     2469    QStringList nameList;
     2470    foreach (const UISoftKeyboardColorTheme &theme, m_colorThemes)
     2471    {
     2472        nameList << theme.name();
     2473    }
     2474    return nameList;
     2475}
     2476
     2477QString UISoftKeyboardWidget::currentColorThemeName() const
     2478{
     2479    if (!m_currentColorTheme)
     2480        return QString();
     2481    return m_currentColorTheme->name();
     2482}
     2483
     2484void UISoftKeyboardWidget::setColorTheme(const QString &strColorThemeName)
     2485{
     2486    if (m_currentColorTheme && m_currentColorTheme->name() == strColorThemeName)
     2487        return;
     2488    for (int i = 0; i < m_colorThemes.size(); ++i)
     2489    {
     2490        if (m_colorThemes[i].name() == strColorThemeName)
     2491        {
     2492            m_currentColorTheme = &(m_colorThemes[i]);
     2493            break;
     2494        }
     2495    }
     2496    update();
     2497    emit sigCurrentColorThemeChanged();
    23922498}
    23932499
     
    33623468    , m_pHideMultimediaKeysCheckBox(0)
    33633469    , m_pColorTableGroupBox(0)
     3470    , m_pColorThemeList(0)
    33643471    , m_pColorSelectionTable(0)
    33653472    , m_pTitleLabel(0)
     
    33973504    pItem->setBackground(color);
    33983505    m_pColorSelectionTable->update();
     3506}
     3507
     3508void UISoftKeyboardSettingsWidget::setColorThemeNames(const QStringList &colorThemeNames)
     3509{
     3510    if (!m_pColorThemeList)
     3511        return;
     3512    foreach (const QString &strName, colorThemeNames)
     3513        m_pColorThemeList->addItem(strName);
     3514}
     3515
     3516void UISoftKeyboardSettingsWidget::setCurrentColorThemeName(const QString &strColorThemeName)
     3517{
     3518    if (!m_pColorThemeList)
     3519        return;
     3520    QList<QListWidgetItem*> items = m_pColorThemeList->findItems(strColorThemeName, Qt::MatchFixedString);
     3521    if (items.isEmpty())
     3522        return;
     3523    m_pColorThemeList->blockSignals(true);
     3524    m_pColorThemeList->setCurrentItem(items[0]);
     3525    m_pColorThemeList->blockSignals(false);
    33993526}
    34003527
     
    34323559        pItem = m_pColorSelectionTable->item(KeyboardColorType_Pressed, 0);
    34333560        if (pItem)
    3434             pItem->setText(UISoftKeyboard::tr("Pressed Button Color"));
     3561            pItem->setText(UISoftKeyboard::tr("Pressed Button Font Color"));
    34353562        m_pColorSelectionTable->setToolTip(UISoftKeyboard::tr("Click on the corresponding table cells to modify colors"));
    34363563    }
     
    34693596    QVBoxLayout *pTableGroupBoxLayout = new QVBoxLayout(m_pColorTableGroupBox);
    34703597    pSettingsLayout->addWidget(m_pColorTableGroupBox, 4, 0, 2, 1);
     3598
     3599    m_pColorThemeList = new QListWidget;
     3600    pTableGroupBoxLayout->addWidget(m_pColorThemeList);
     3601    connect(m_pColorThemeList, &QListWidget::currentTextChanged, this, &UISoftKeyboardSettingsWidget::sigColorThemeSelectionChanged);
    34713602
    34723603    /* Creating and configuring the color table widget: */
     
    36783809}
    36793810
     3811void UISoftKeyboard::sltHandleColorThemeListSelection(const QString &strColorThemeName)
     3812{
     3813    if (m_pKeyboardWidget)
     3814        m_pKeyboardWidget->setColorTheme(strColorThemeName);
     3815}
     3816
     3817void UISoftKeyboard::sltHandleKeyboardWidgetColorThemeChange()
     3818{
     3819    for (int i = (int)KeyboardColorType_Background;
     3820         i < (int)KeyboardColorType_Max; ++i)
     3821    {
     3822        KeyboardColorType enmType = (KeyboardColorType)i;
     3823        m_pSettingsWidget->setTableItemColor(enmType, m_pKeyboardWidget->color(enmType));
     3824    }
     3825}
    36803826
    36813827void UISoftKeyboard::sltCopyLayout()
     
    38083954    connect(m_pKeyboardWidget, &UISoftKeyboardWidget::sigKeyToEdit, this, &UISoftKeyboard::sltKeyToEditChanged);
    38093955    connect(m_pKeyboardWidget, &UISoftKeyboardWidget::sigStatusBarMessage, this, &UISoftKeyboard::sltStatusBarMessage);
     3956    connect(m_pKeyboardWidget, &UISoftKeyboardWidget::sigStatusBarMessage, this, &UISoftKeyboard::sltStatusBarMessage);
     3957    connect(m_pKeyboardWidget, &UISoftKeyboardWidget::sigCurrentColorThemeChanged, this, &UISoftKeyboard::sltHandleKeyboardWidgetColorThemeChange);
    38103958
    38113959    connect(m_pLayoutSelector, &UILayoutSelector::sigLayoutSelectionChanged, this, &UISoftKeyboard::sltLayoutSelectionChanged);
     
    38283976    connect(m_pSettingsWidget, &UISoftKeyboardSettingsWidget::sigColorCellClicked, this, &UISoftKeyboard::sltHandleColorCellClick);
    38293977    connect(m_pSettingsWidget, &UISoftKeyboardSettingsWidget::sigCloseSettingsWidget, this, &UISoftKeyboard::sltShowHideSettingsWidget);
     3978    connect(m_pSettingsWidget, &UISoftKeyboardSettingsWidget::sigColorThemeSelectionChanged, this, &UISoftKeyboard::sltHandleColorThemeListSelection);
     3979
    38303980}
    38313981
     
    38974047        m_pSettingsWidget->setHideMultimediaKeys(m_pKeyboardWidget->hideMultimediaKeys());
    38984048
     4049        m_pSettingsWidget->setColorThemeNames(m_pKeyboardWidget->colorThemeNames());
     4050        m_pSettingsWidget->setCurrentColorThemeName(m_pKeyboardWidget->currentColorThemeName());
     4051
    38994052        for (int i = (int)KeyboardColorType_Background;
    39004053             i < (int)KeyboardColorType_Max; ++i)
  • trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.h

    r81285 r81293  
    8686    void sltShowHideSidePanel();
    8787    void sltShowHideSettingsWidget();
     88    void sltHandleColorThemeListSelection(const QString &strColorThemeName);
     89    void sltHandleKeyboardWidgetColorThemeChange();
    8890    void sltCopyLayout();
    8991    void sltSaveLayout();
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