VirtualBox

Changeset 79434 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jul 1, 2019 11:31:44 AM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6143. Saving and loading the color theme.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataDefs.cpp

    r78680 r79434  
    206206/* Soft Keyboard: */
    207207const char *UIExtraDataDefs::GUI_SoftKeyboard_DialogGeometry = "GUI/SoftKeyboardDialogGeometry";
     208const char *UIExtraDataDefs::GUI_SoftKeyboard_ColorTheme  = "GUI/SoftKeyboardDialogGeometry";
    208209
    209210/* File Manager options: */
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataDefs.h

    r79250 r79434  
    385385      * @{ */
    386386        extern const char *GUI_SoftKeyboard_DialogGeometry;
     387        extern const char *GUI_SoftKeyboard_ColorTheme;
    387388    /** @} */
    388389
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.cpp

    r79365 r79434  
    43084308}
    43094309
     4310void UIExtraDataManager::setSoftKeyboardColorTheme(const QStringList &colorStringList)
     4311{
     4312    setExtraDataStringList(GUI_SoftKeyboard_ColorTheme, colorStringList);
     4313}
     4314
     4315QStringList UIExtraDataManager::softKeyboardColorTheme()
     4316{
     4317    return extraDataStringList(GUI_SoftKeyboard_ColorTheme);
     4318}
     4319
    43104320void UIExtraDataManager::setFileManagerOptions(bool fListDirectoriesFirst,
    43114321                                               bool fShowDeleteConfirmation,
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.h

    r78680 r79434  
    676676        void setSoftKeyboardDialogGeometry(const QRect &geometry, bool fMaximized);
    677677        bool softKeyboardDialogShouldBeMaximized();
     678        void setSoftKeyboardColorTheme(const QStringList &colorStringList);
     679        QStringList softKeyboardColorTheme();
    678680    /** @} */
    679681
  • trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.cpp

    r79412 r79434  
    6262
    6363/* Forward declarations: */
    64 class UISoftKeyboardWidget;
    6564class UISoftKeyboardLayout;
    6665class UISoftKeyboardRow;
     66class UISoftKeyboardWidget;
    6767
    6868const int iMessageTimeout = 3000;
     
    9494    QString m_strAltGr;
    9595    QString m_strShiftAltGr;
     96};
     97
     98enum KeyboardColorType
     99{
     100    KeyboardColorType_Background = 0,
     101    KeyboardColorType_Font,
     102    KeyboardColorType_Hover,
     103    KeyboardColorType_Edit,
     104    KeyboardColorType_Pressed,
     105    KeyboardColorType_Max
    96106};
    97107
     
    452462
    453463/*********************************************************************************************************************************
     464*   UISoftKeyboardColorTheme definition.                                                                                  *
     465*********************************************************************************************************************************/
     466
     467class UISoftKeyboardColorTheme
     468{
     469public:
     470
     471    UISoftKeyboardColorTheme();
     472    void setColor(KeyboardColorType enmColorType, const QColor &color);
     473    QColor color(KeyboardColorType enmColorType) const;
     474    QStringList colorsToStringList() const;
     475    void colorsFromStringList(const QStringList &colorStringList);
     476
     477private:
     478    QVector<QColor> m_colors;
     479};
     480
     481/*********************************************************************************************************************************
    454482*   UISoftKeyboardWidget definition.                                                                                  *
    455483*********************************************************************************************************************************/
     
    505533    void setShowNumPad(bool fShow);
    506534
    507     const QColor &color(int iColorType) const;
    508     void setColor(int iColorType, const QColor &color);
     535    const QColor color(KeyboardColorType enmColorType) const;
     536    void setColor(KeyboardColorType ennmColorType, const QColor &color);
     537
     538    QStringList colorsToStringList() const;
     539    void colorsFromStringList(const QStringList &colorStringList);
    509540
    510541protected:
     
    548579
    549580    UISoftKeyboardKey *m_pKeyPressed;
    550     QColor m_keyBackgroundColor;
    551     QColor m_keyHoverColor;
    552     QColor m_fontDefaultColor;
    553     QColor m_fontPressedColor;
    554     QColor m_keyEditColor;
     581    UISoftKeyboardColorTheme m_colorTheme;
    555582    QVector<UISoftKeyboardKey*> m_pressedModifiers;
    556583    QVector<UISoftKeyboardPhysicalLayout> m_physicalLayouts;
     
    672699    Q_OBJECT;
    673700
    674 public:
    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 
    686701signals:
    687702
     
    696711    void setShowOSMenuKeys(bool fShow);
    697712    void setShowNumPad(bool fShow);
    698     void setTableItemColor(ColorTableRow tableRow, const QColor &color);
     713    void setTableItemColor(KeyboardColorType tableRow, const QColor &color);
    699714
    700715protected:
     
    717732    QToolButton  *m_pCloseButton;
    718733};
     734
    719735
    720736/*********************************************************************************************************************************
     
    17291745
    17301746/*********************************************************************************************************************************
     1747*   UISoftKeyboardColorTheme implementation.                                                                                     *
     1748*********************************************************************************************************************************/
     1749
     1750UISoftKeyboardColorTheme::UISoftKeyboardColorTheme()
     1751    : m_colors(QVector<QColor>(KeyboardColorType_Max))
     1752{
     1753    m_colors[KeyboardColorType_Background] = QColor(103, 128, 159);
     1754    m_colors[KeyboardColorType_Hover] = QColor(108, 122, 137);
     1755    m_colors[KeyboardColorType_Font] = QColor(46, 49, 49);
     1756    m_colors[KeyboardColorType_Pressed] = QColor(149, 165, 166);
     1757    m_colors[KeyboardColorType_Edit] = QColor(249, 165, 166);
     1758}
     1759
     1760void UISoftKeyboardColorTheme::setColor(KeyboardColorType enmColorType, const QColor &color)
     1761{
     1762    if ((int) enmColorType >= m_colors.size())
     1763        return;
     1764    m_colors[(int)enmColorType] = color;
     1765}
     1766
     1767QColor UISoftKeyboardColorTheme::color(KeyboardColorType enmColorType) const
     1768{
     1769    if ((int) enmColorType >= m_colors.size())
     1770        return QColor();
     1771    return m_colors[(int)enmColorType];
     1772}
     1773
     1774QStringList UISoftKeyboardColorTheme::colorsToStringList() const
     1775{
     1776    QStringList colorStringList;
     1777    foreach (const QColor &color, m_colors)
     1778        colorStringList << color.name(QColor::HexArgb);
     1779    return colorStringList;
     1780}
     1781
     1782void UISoftKeyboardColorTheme::colorsFromStringList(const QStringList &colorStringList)
     1783{
     1784    for (int i = 0; i < colorStringList.size() && i < m_colors.size(); ++i)
     1785    {
     1786        if (!QColor::isValidColor(colorStringList[i]))
     1787            continue;
     1788        m_colors[i].setNamedColor(colorStringList[i]);
     1789    }
     1790}
     1791
     1792
     1793/*********************************************************************************************************************************
    17311794*   UISoftKeyboardWidget implementation.                                                                                  *
    17321795*********************************************************************************************************************************/
     
    17371800    , m_pKeyBeingEdited(0)
    17381801    , m_pKeyPressed(0)
    1739     , m_keyBackgroundColor(QColor(103, 128, 159))
    1740     , m_keyHoverColor(QColor(108, 122, 137))
    1741     , m_fontDefaultColor(QColor(46, 49, 49))
    1742     , m_fontPressedColor(QColor(149, 165, 166))
    1743     , m_keyEditColor(QColor(249, 165, 166))
    17441802    , m_pCurrentKeyboardLayout(0)
    17451803    , m_iInitialHeight(0)
     
    18161874
    18171875            if(&key  == m_pKeyBeingEdited)
    1818                 painter.setBrush(QBrush(m_keyEditColor));
     1876                painter.setBrush(QBrush(color(KeyboardColorType_Edit)));
    18191877            else if (&key  == m_pKeyUnderMouse)
    1820                 painter.setBrush(QBrush(m_keyHoverColor));
     1878                painter.setBrush(QBrush(color(KeyboardColorType_Hover)));
    18211879            else
    1822                 painter.setBrush(QBrush(m_keyBackgroundColor));
     1880                painter.setBrush(QBrush(color(KeyboardColorType_Background)));
    18231881
    18241882            if (&key  == m_pKeyPressed)
    1825                 painter.setPen(QPen(QColor(m_fontPressedColor), 2));
     1883                painter.setPen(QPen(color(KeyboardColorType_Pressed), 2));
    18261884            else
    1827                 painter.setPen(QPen(QColor(m_fontDefaultColor), 2));
     1885                painter.setPen(QPen(color(KeyboardColorType_Font), 2));
    18281886
    18291887            painter.drawPolygon(key.polygon());
     
    18351893                QColor ledColor;
    18361894                if (key.state() == UIKeyState_NotPressed)
    1837                     ledColor = m_fontDefaultColor;
     1895                    ledColor = color(KeyboardColorType_Font);
    18381896                else if (key.state() == UIKeyState_Pressed)
    18391897                    ledColor = QColor(0, 255, 0);
     
    20322090}
    20332091
    2034 const QColor &UISoftKeyboardWidget::color(int iColorType) const
    2035 {
    2036     UISoftKeyboardSettingsWidget::ColorTableRow enmColorType = static_cast<UISoftKeyboardSettingsWidget::ColorTableRow>(iColorType);
    2037     switch (enmColorType)
    2038     {
    2039         case UISoftKeyboardSettingsWidget::ColorTableRow_Background:
    2040             return m_keyBackgroundColor;
    2041         case UISoftKeyboardSettingsWidget::ColorTableRow_Edit:
    2042             return m_keyEditColor;
    2043         case UISoftKeyboardSettingsWidget::ColorTableRow_Font:
    2044             return m_fontDefaultColor;
    2045         case UISoftKeyboardSettingsWidget::ColorTableRow_Hover:
    2046             return m_keyHoverColor;
    2047         case UISoftKeyboardSettingsWidget::ColorTableRow_Pressed:
    2048             return m_fontPressedColor;
    2049         case UISoftKeyboardSettingsWidget::ColorTableRow_Max:
    2050         default:
    2051             return m_keyBackgroundColor;
    2052     }
    2053 }
    2054 
    2055 void UISoftKeyboardWidget::setColor(int iColorType, const QColor &color)
    2056 {
    2057     UISoftKeyboardSettingsWidget::ColorTableRow enmColorType = static_cast<UISoftKeyboardSettingsWidget::ColorTableRow>(iColorType);
    2058     switch (enmColorType)
    2059     {
    2060         case UISoftKeyboardSettingsWidget::ColorTableRow_Background:
    2061             m_keyBackgroundColor = color;
    2062             break;
    2063         case UISoftKeyboardSettingsWidget::ColorTableRow_Edit:
    2064             m_keyEditColor = color;
    2065             break;
    2066         case UISoftKeyboardSettingsWidget::ColorTableRow_Font:
    2067             m_fontDefaultColor = color;
    2068             break;
    2069         case UISoftKeyboardSettingsWidget::ColorTableRow_Hover:
    2070             m_keyHoverColor = color;
    2071             break;
    2072         case UISoftKeyboardSettingsWidget::ColorTableRow_Pressed:
    2073             m_fontPressedColor = color;
    2074             break;
    2075         case UISoftKeyboardSettingsWidget::ColorTableRow_Max:
    2076         default:
    2077             break;
    2078     }
     2092const QColor UISoftKeyboardWidget::color(KeyboardColorType enmColorType) const
     2093{
     2094    return m_colorTheme.color(enmColorType);
     2095}
     2096
     2097void UISoftKeyboardWidget::setColor(KeyboardColorType enmColorType, const QColor &color)
     2098{
     2099    m_colorTheme.setColor(enmColorType, color);
     2100}
     2101
     2102QStringList UISoftKeyboardWidget::colorsToStringList() const
     2103{
     2104    return m_colorTheme.colorsToStringList();
     2105}
     2106
     2107void UISoftKeyboardWidget::colorsFromStringList(const QStringList &colorStringList)
     2108{
     2109    m_colorTheme.colorsFromStringList(colorStringList);
    20792110}
    20802111
     
    21312162    update();
    21322163}
    2133 
    2134 // void UISoftKeyboardWidget::updateKeyCaptionsInLayout(UISoftKeyboardKey *pKey)
    2135 // {
    2136 //     if (!m_pCurrentKeyboardLayout || !pKey)
    2137 //         return;
    2138 
    2139 //     /* Assuming the key captions are changed for the current layout: */
    2140 //     KeyCaptions newCaptions;
    2141 //     // newCaptions.m_strBase = pKey->baseCaption();
    2142 //     // newCaptions.m_strShift = pKey->shiftCaption();
    2143 //     // newCaptions.m_strAltGr = pKey->altGrCaption();
    2144 //     // newCaptions.m_strShiftAltGr = pKey->shiftAltGrCaption();
    2145 //     m_pCurrentKeyboardLayout->updateKeyCaptions(pKey->position(), newCaptions);
    2146 // }
    21472164
    21482165void UISoftKeyboardWidget::addLayout(const UISoftKeyboardLayout &newLayout)
     
    29812998}
    29822999
    2983 void UISoftKeyboardSettingsWidget::setTableItemColor(ColorTableRow tableRow, const QColor &color)
     3000void UISoftKeyboardSettingsWidget::setTableItemColor(KeyboardColorType tableRow, const QColor &color)
    29843001{
    29853002    if (!m_pColorSelectionTable)
     
    30093026    if (m_pColorSelectionTable)
    30103027    {
    3011         QTableWidgetItem *pItem = m_pColorSelectionTable->itemAt(ColorTableRow_Background, 0);
     3028        QTableWidgetItem *pItem = m_pColorSelectionTable->itemAt(KeyboardColorType_Background, 0);
    30123029        if (pItem)
    30133030            pItem->setText(UISoftKeyboard::tr("Button Background Color"));
    3014         pItem = m_pColorSelectionTable->item(ColorTableRow_Font, 0);
     3031        pItem = m_pColorSelectionTable->item(KeyboardColorType_Font, 0);
    30153032        if (pItem)
    30163033            pItem->setText(UISoftKeyboard::tr("Button Font Color"));
    3017         pItem = m_pColorSelectionTable->item(ColorTableRow_Hover, 0);
     3034        pItem = m_pColorSelectionTable->item(KeyboardColorType_Hover, 0);
    30183035        if (pItem)
    30193036            pItem->setText(UISoftKeyboard::tr("Button Hover Color"));
    3020         pItem = m_pColorSelectionTable->item(ColorTableRow_Edit, 0);
     3037        pItem = m_pColorSelectionTable->item(KeyboardColorType_Edit, 0);
    30213038        if (pItem)
    30223039            pItem->setText(UISoftKeyboard::tr("Button Edit Color"));
    3023         pItem = m_pColorSelectionTable->item(ColorTableRow_Pressed, 0);
     3040        pItem = m_pColorSelectionTable->item(KeyboardColorType_Pressed, 0);
    30243041        if (pItem)
    30253042            pItem->setText(UISoftKeyboard::tr("Pressed Button Color"));
     
    30613078    m_pColorSelectionTable = new QTableWidget;
    30623079    pTableGroupBoxLayout->addWidget(m_pColorSelectionTable);
    3063     m_pColorSelectionTable->setRowCount(ColorTableRow_Max);
     3080    m_pColorSelectionTable->setRowCount(KeyboardColorType_Max);
    30643081    m_pColorSelectionTable->setColumnCount(2);
    30653082    m_pColorSelectionTable->horizontalHeader()->hide();
     
    30723089
    30733090    /* Create column 0 items: */
    3074     m_pColorSelectionTable->setItem(ColorTableRow_Background, 0, new QTableWidgetItem());
    3075     m_pColorSelectionTable->setItem(ColorTableRow_Font, 0, new QTableWidgetItem());
    3076     m_pColorSelectionTable->setItem(ColorTableRow_Hover, 0, new QTableWidgetItem());
    3077     m_pColorSelectionTable->setItem(ColorTableRow_Edit, 0, new QTableWidgetItem());
    3078     m_pColorSelectionTable->setItem(ColorTableRow_Pressed, 0, new QTableWidgetItem());
     3091    m_pColorSelectionTable->setItem(KeyboardColorType_Background, 0, new QTableWidgetItem());
     3092    m_pColorSelectionTable->setItem(KeyboardColorType_Font, 0, new QTableWidgetItem());
     3093    m_pColorSelectionTable->setItem(KeyboardColorType_Hover, 0, new QTableWidgetItem());
     3094    m_pColorSelectionTable->setItem(KeyboardColorType_Edit, 0, new QTableWidgetItem());
     3095    m_pColorSelectionTable->setItem(KeyboardColorType_Pressed, 0, new QTableWidgetItem());
    30793096
    30803097    /* Create column 1 items: */
    3081     for (int i = ColorTableRow_Background; i < ColorTableRow_Max; ++i)
     3098    for (int i = KeyboardColorType_Background; i < KeyboardColorType_Max; ++i)
    30823099    {
    30833100        QTableWidgetItem *pItem = new QTableWidgetItem();
    3084         m_pColorSelectionTable->setItem(static_cast<ColorTableRow>(i), 1, pItem);
     3101        m_pColorSelectionTable->setItem(static_cast<KeyboardColorType>(i), 1, pItem);
    30853102        pItem->setIcon(UIIconPool::defaultIcon(UIIconPool::UIDefaultIconType_ArrowBack));
    30863103    }
     
    30963113void UISoftKeyboardSettingsWidget::sltColorCellClicked(int row, int column)
    30973114{
    3098     if (column != 1 || row >= static_cast<int>(ColorTableRow_Max))
     3115    if (column != 1 || row >= static_cast<int>(KeyboardColorType_Max))
    30993116        return;
    31003117    emit sigColorCellClicked(row);
    31013118}
     3119
    31023120
    31033121/*********************************************************************************************************************************
     
    31273145    {
    31283146        m_pKeyboardWidget->loadLayouts();
    3129         updateLayoutSelector();
    31303147        if (m_pLayoutEditor)
    31313148            m_pLayoutEditor->setPhysicalLayoutList(m_pKeyboardWidget->physicalLayouts());
     
    32913308void UISoftKeyboard::sltHandleColorCellClick(int iColorRow)
    32923309{
    3293     if (!m_pKeyboardWidget || iColorRow >= static_cast<int>(UISoftKeyboardSettingsWidget::ColorTableRow_Max))
    3294         return;
    3295     const QColor &currentColor = m_pKeyboardWidget->color(iColorRow);
     3310    if (!m_pKeyboardWidget || iColorRow >= static_cast<int>(KeyboardColorType_Max))
     3311        return;
     3312    const QColor &currentColor = m_pKeyboardWidget->color(static_cast<KeyboardColorType>(iColorRow));
    32963313    QColorDialog colorDialog(currentColor, this);
    32973314
     
    33013318    if (currentColor == newColor)
    33023319        return;
    3303     m_pKeyboardWidget->setColor(iColorRow, newColor);
    3304     m_pSettingsWidget->setTableItemColor(static_cast<UISoftKeyboardSettingsWidget::ColorTableRow>(iColorRow), newColor);
     3320    m_pKeyboardWidget->setColor(static_cast<KeyboardColorType>(iColorRow), newColor);
     3321    m_pSettingsWidget->setTableItemColor(static_cast<KeyboardColorType>(iColorRow), newColor);
    33053322}
    33063323
     
    33923409    LogRel2(("GUI: Soft Keyboard: Geometry saved as: Origin=%dx%d, Size=%dx%d\n",
    33933410             saveGeometry.x(), saveGeometry.y(), saveGeometry.width(), saveGeometry.height()));
     3411    if (m_pKeyboardWidget)
     3412        gEDataManager->setSoftKeyboardColorTheme(m_pKeyboardWidget->colorsToStringList());
    33943413}
    33953414
     
    34163435             geometry.x(), geometry.y(), geometry.width(), geometry.height()));
    34173436    setDialogGeometry(geometry);
     3437    if (m_pKeyboardWidget)
     3438        m_pKeyboardWidget->colorsFromStringList(gEDataManager->softKeyboardColorTheme());
    34183439}
    34193440
     
    34263447        m_pSettingsWidget->setShowNumPad(m_pKeyboardWidget->showNumPad());
    34273448
    3428         for (int i = static_cast<int>(UISoftKeyboardSettingsWidget::ColorTableRow_Background);
    3429              i < static_cast<int>(UISoftKeyboardSettingsWidget::ColorTableRow_Max); ++i)
    3430             m_pSettingsWidget->setTableItemColor(static_cast<UISoftKeyboardSettingsWidget::ColorTableRow>(i),
    3431                                                  m_pKeyboardWidget->color(i));
     3449        for (int i = (int)KeyboardColorType_Background;
     3450             i < (int)KeyboardColorType_Max; ++i)
     3451        {
     3452            KeyboardColorType enmType = (KeyboardColorType)i;
     3453            m_pSettingsWidget->setTableItemColor(enmType, m_pKeyboardWidget->color(enmType));
     3454        }
    34323455    }
    34333456}
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