VirtualBox

Ignore:
Timestamp:
Apr 9, 2019 1:42:43 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: Coloring the search line edit wrt. the match count.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UISearchLineEdit.cpp

    r77723 r78060  
    2727    , m_iMatchCount(0)
    2828    , m_iScrollToIndex(-1)
     29    , m_fMark(true)
     30    , m_unmarkColor(palette().color(QPalette::Base))
     31    , m_markColor(QColor(m_unmarkColor.red(),
     32                         0.5 * m_unmarkColor.green(),
     33                         0.5 * m_unmarkColor.blue()))
    2934{
    3035}
     
    3641    /* No search terms. no search. nothing to show here: */
    3742    if (text().isEmpty())
     43    {
     44        colorBackground(false);
    3845        return;
    39 
     46    }
    4047    /* Draw the total match count and the current scrolled item's index on the right hand side of the line edit: */
    4148    QPainter painter(this);
     
    5764    painter.drawText(QRect(width() - textSize.width() - iRightMargin, iTopMargin, textSize.width(), textSize.height()),
    5865                     Qt::AlignCenter | Qt::AlignVCenter, strText);
     66    colorBackground(m_iMatchCount == 0);
    5967}
    6068
     
    7482    repaint();
    7583}
     84
     85void UISearchLineEdit::colorBackground(bool fWarning)
     86{
     87    QPalette mPalette = palette();
     88    /** Make sure we reset color. */
     89    if (!fWarning || !m_fMark)
     90    {
     91        mPalette.setColor(QPalette::Base, m_unmarkColor);
     92        setPalette(mPalette);
     93        return;
     94    }
     95
     96    if (m_fMark && fWarning)
     97    {
     98        mPalette.setColor(QPalette::Base, m_markColor);
     99        setPalette(mPalette);
     100        return;
     101    }
     102}
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UISearchLineEdit.h

    r77723 r78060  
    4949private:
    5050
     51    void colorBackground(bool fWarning);
     52
    5153    /** Stores the total number of matched items. */
    52     int m_iMatchCount;
     54    int  m_iMatchCount;
    5355    /** Stores the index of the currently scrolled/made-visible item withing the list of search results.
    5456      * Must be smaller that or equal to m_iMatchCount. */
    55     int m_iScrollToIndex;
     57    int  m_iScrollToIndex;
     58    /** When true we color line edit background with a more reddish color. */
     59    bool m_fMark;
     60    QColor m_unmarkColor;
     61    QColor m_markColor;
    5662};
    5763
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