VirtualBox

Changeset 88855 in vbox for trunk/src/VBox


Ignore:
Timestamp:
May 4, 2021 1:49:27 PM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10003: Reworking Chooser pane and Tool pane items to have native highlight foreground depending on background luminance.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/manager
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGlobal.cpp

    r84625 r88855  
    702702    const int iButtonMargin = data(GlobalItemData_ButtonMargin).toInt();
    703703
    704     /* Selected-item foreground: */
    705     if (model()->selectedItems().contains(unconst(this)))
    706     {
    707         const QPalette pal = palette();
    708         pPainter->setPen(pal.color(QPalette::HighlightedText));
    709     }
    710     /* Hovered item foreground: */
    711     else if (isHovered())
    712     {
    713         /* Prepare color: */
    714         const QPalette pal = palette();
     704    /* Selected or hovered item foreground: */
     705    if (model()->selectedItems().contains(unconst(this)) || isHovered())
     706    {
     707        /* Prepare palette: */
     708        const QPalette pal = QApplication::palette();
     709
     710        /* Get background color: */
    715711        const QColor highlight = pal.color(QPalette::Active, QPalette::Highlight);
    716         const QColor hhl = highlight.lighter(m_iHoverLightnessMax);
    717         if (hhl.value() - hhl.saturation() > 0)
    718             pPainter->setPen(pal.color(QPalette::Active, QPalette::Text));
     712        const QColor background = model()->selectedItems().contains(unconst(this))
     713                                ? highlight.lighter(m_iHighlightLightnessMin)
     714                                : highlight.lighter(m_iHoverLightnessMin);
     715
     716        /* Get foreground color: */
     717        const QColor simpleText = pal.color(QPalette::Active, QPalette::Text);
     718        const QColor highlightText = pal.color(QPalette::Active, QPalette::HighlightedText);
     719        const QColor lightText = simpleText.black() < highlightText.black() ? simpleText : highlightText;
     720        const QColor darkText = simpleText.black() > highlightText.black() ? simpleText : highlightText;
     721
     722        /* Gather foreground color for background one: */
     723        double dLuminance = (0.299 * background.red() + 0.587 * background.green() + 0.114 * background.blue()) / 255;
     724        //printf("luminance = %f\n", dLuminance);
     725        if (dLuminance > 0.5)
     726            pPainter->setPen(darkText);
    719727        else
    720             pPainter->setPen(pal.color(QPalette::Active, QPalette::HighlightedText));
     728            pPainter->setPen(lightText);
    721729    }
    722730
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemMachine.cpp

    r86779 r88855  
    10981098    if (model()->selectedItems().contains(unconst(this)) || isHovered())
    10991099    {
    1100         /* Prepare color: */
    1101         QPalette pal = palette();
    1102         QColor highlight = pal.color(QPalette::Active, QPalette::Highlight);
    1103         QColor hhl = highlight.lighter(m_iHoverLightnessMax);
    1104         if (hhl.value() - hhl.saturation() > 0)
    1105             pPainter->setPen(pal.color(QPalette::Active, QPalette::Text));
     1100        /* Prepare palette: */
     1101        const QPalette pal = QApplication::palette();
     1102
     1103        /* Get background color: */
     1104        const QColor highlight = pal.color(QPalette::Active, QPalette::Highlight);
     1105        const QColor background = model()->selectedItems().contains(unconst(this))
     1106                                ? highlight.lighter(m_iHighlightLightnessMin)
     1107                                : highlight.lighter(m_iHoverLightnessMin);
     1108
     1109        /* Get foreground color: */
     1110        const QColor simpleText = pal.color(QPalette::Active, QPalette::Text);
     1111        const QColor highlightText = pal.color(QPalette::Active, QPalette::HighlightedText);
     1112        const QColor lightText = simpleText.black() < highlightText.black() ? simpleText : highlightText;
     1113        const QColor darkText = simpleText.black() > highlightText.black() ? simpleText : highlightText;
     1114
     1115        /* Gather foreground color for background one: */
     1116        double dLuminance = (0.299 * background.red() + 0.587 * background.green() + 0.114 * background.blue()) / 255;
     1117        //printf("luminance = %f\n", dLuminance);
     1118        if (dLuminance > 0.5)
     1119            pPainter->setPen(darkText);
    11061120        else
    1107             pPainter->setPen(pal.color(QPalette::Active, QPalette::HighlightedText));
     1121            pPainter->setPen(lightText);
    11081122    }
    11091123
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/tools/UIToolsItem.cpp

    r82968 r88855  
    853853    const QPalette pal = palette();
    854854
    855     /* Selected item foreground: */
    856     if (model()->currentItem() == this)
    857     {
    858         const QColor textColor = isEnabled()
    859                                ? pal.color(QPalette::Active, QPalette::HighlightedText)
    860                                : pal.color(QPalette::Disabled, QPalette::Text);
    861         pPainter->setPen(textColor);
    862     }
    863     /* Hovered item foreground: */
    864     else if (isHovered())
    865     {
    866         /* Prepare color: */
    867         QColor defaultHighlighted = pal.color(QPalette::Active, QPalette::Highlight);
    868         QColor hoveredHighlighted = defaultHighlighted.lighter(m_iHoverLightnessMax);
    869         QColor textColor;
    870         if (hoveredHighlighted.value() - hoveredHighlighted.saturation() > 0)
    871             textColor = isEnabled()
    872                       ? pal.color(QPalette::Active, QPalette::Text)
    873                       : pal.color(QPalette::Disabled, QPalette::Text);
     855    /* Selected or hovered item foreground: */
     856    if (model()->currentItem() == this || isHovered())
     857    {
     858        /* Prepare palette: */
     859        const QPalette pal = QApplication::palette();
     860
     861        /* Get background color: */
     862        const QColor highlight = pal.color(QPalette::Active, QPalette::Highlight);
     863        const QColor background = model()->currentItem() == this
     864                                ? highlight.lighter(m_iHighlightLightnessMin)
     865                                : highlight.lighter(m_iHoverLightnessMin);
     866
     867        /* Get foreground color: */
     868        const QColor simpleText = pal.color(QPalette::Active, QPalette::Text);
     869        const QColor highlightText = pal.color(QPalette::Active, QPalette::HighlightedText);
     870        const QColor lightText = simpleText.black() < highlightText.black() ? simpleText : highlightText;
     871        const QColor darkText = simpleText.black() > highlightText.black() ? simpleText : highlightText;
     872
     873        /* Gather foreground color for background one: */
     874        double dLuminance = (0.299 * background.red() + 0.587 * background.green() + 0.114 * background.blue()) / 255;
     875        //printf("luminance = %f\n", dLuminance);
     876        if (dLuminance > 0.5)
     877            pPainter->setPen(darkText);
    874878        else
    875             textColor = isEnabled()
    876                       ? pal.color(QPalette::Active, QPalette::HighlightedText)
    877                       : pal.color(QPalette::Disabled, QPalette::Text);
    878         pPainter->setPen(textColor);
     879            pPainter->setPen(lightText);
    879880    }
    880881    /* Default item foreground: */
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