VirtualBox

Changeset 77174 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Feb 6, 2019 1:38:20 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9340. Showing number of search matches in the line edit of the medium search panel.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r77154 r77174  
    975975        src/logviewer/UIVMLogViewerTextEdit.cpp \
    976976        src/medium/UIMediumEnumerator.cpp \
     977        src/medium/UIMediumSearchWidget.cpp \
    977978        src/medium/viso/UIVisoContentBrowser.cpp \
    978979        src/medium/viso/UIVisoHostBrowser.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumSearchWidget.cpp

    r77013 r77174  
    1919#include <QLineEdit>
    2020#include <QPushButton>
     21#include <QPainter>
    2122#include <QVBoxLayout>
    2223
     
    3738
    3839
     40/*********************************************************************************************************************************
     41*   FilterByNameUUID definition/implementation.                                                                                  *
     42*********************************************************************************************************************************/
     43
    3944class FilterByNameUUID : public QITreeWidgetItemFilter
    4045{
     
    5661        if (!pMediumItem)
    5762            return false;
    58         if (m_enmSearchType == UIMediumSearchWidget::SearchByUUID && !pMediumItem->id().toString().contains(m_strSearchTerm))
    59             return false;
    60         if (m_enmSearchType == UIMediumSearchWidget::SearchByName && !pMediumItem->name().contains(m_strSearchTerm))
     63        if (m_enmSearchType == UIMediumSearchWidget::SearchByUUID &&
     64            !pMediumItem->id().toString().contains(m_strSearchTerm, Qt::CaseInsensitive))
     65            return false;
     66        if (m_enmSearchType == UIMediumSearchWidget::SearchByName &&
     67            !pMediumItem->name().contains(m_strSearchTerm, Qt::CaseInsensitive))
    6168            return false;
    6269        return true;
     
    6875    QString m_strSearchTerm;
    6976};
     77
     78
     79/*********************************************************************************************************************************
     80*   UISearchLineEdit definition             .                                                                                    *
     81*********************************************************************************************************************************/
     82
     83class UISearchLineEdit : public QLineEdit
     84{
     85
     86    Q_OBJECT;
     87
     88public:
     89
     90    UISearchLineEdit(QWidget *pParent = 0);
     91    void setMatchCount(int iMatchCount);
     92    void setScroolToIndex(int iScrollToIndex);
     93
     94protected:
     95
     96    virtual void paintEvent(QPaintEvent *pEvent) /* override */;
     97
     98private:
     99
     100    int m_iMatchCount;
     101    int m_iScrollToIndex;
     102};
     103
     104
     105/*********************************************************************************************************************************
     106*   UISearchLineEdit implementation         .                                                                                    *
     107*********************************************************************************************************************************/
     108
     109UISearchLineEdit::UISearchLineEdit(QWidget *pParent /* = 0 */)
     110    :QLineEdit(pParent)
     111    , m_iMatchCount(0)
     112    , m_iScrollToIndex(-1)
     113{
     114}
     115
     116void UISearchLineEdit::paintEvent(QPaintEvent *pEvent)
     117{
     118    QLineEdit::paintEvent(pEvent);
     119
     120
     121    QPainter painter(this);
     122
     123    QFont pfont = font();
     124    QString strText = QString("%1/%2").arg(QString::number(m_iScrollToIndex + 1)).arg(QString::number(m_iMatchCount));
     125    QSize textSize(QApplication::fontMetrics().width(strText),
     126                   QApplication::fontMetrics().height());
     127
     128    /* Dont draw anything if we dont have enough space: */
     129    if (textSize.width() > 0.5 * width())
     130        return;
     131    int iTopMargin = (height() - textSize.height()) / 2;
     132    int iRightMargin = iTopMargin;
     133
     134
     135    QColor fontColor(Qt::darkGray);
     136    painter.setPen(fontColor);
     137    painter.setFont(pfont);
     138
     139    painter.drawText(QRect(width() - textSize.width() - iRightMargin, iTopMargin, textSize.width(), textSize.height()),
     140                     Qt::AlignCenter | Qt::AlignVCenter, strText);
     141}
     142
     143void UISearchLineEdit::setMatchCount(int iMatchCount)
     144{
     145    if (m_iMatchCount == iMatchCount)
     146        return;
     147    m_iMatchCount = iMatchCount;
     148    repaint();
     149}
     150
     151void UISearchLineEdit::setScroolToIndex(int iScrollToIndex)
     152{
     153    if (m_iScrollToIndex == iScrollToIndex)
     154        return;
     155    m_iScrollToIndex = iScrollToIndex;
     156    repaint();
     157}
     158
     159
     160/*********************************************************************************************************************************
     161*   UIMediumSearchWidget implementation      .                                                                                   *
     162*********************************************************************************************************************************/
    70163
    71164UIMediumSearchWidget::UIMediumSearchWidget(QWidget *pParent)
     
    76169    , m_pShowPreviousMatchButton(0)
    77170    , m_pTreeWidget(0)
    78     , m_iScrollToIndex(0)
     171    , m_iScrollToIndex(-1)
    79172{
    80173    prepareWidgets();
     
    101194    }
    102195
    103     m_pSearchTermLineEdit = new QLineEdit;
     196    m_pSearchTermLineEdit = new UISearchLineEdit;
    104197    if (m_pSearchTermLineEdit)
    105198    {
    106         m_pSearchTermLineEdit->setClearButtonEnabled(true);
     199        m_pSearchTermLineEdit->setClearButtonEnabled(false);
    107200        pLayout->addWidget(m_pSearchTermLineEdit);
    108201        connect(m_pSearchTermLineEdit, &QLineEdit::textChanged,
     
    158251        goToNextPrevious(true);
    159252    }
     253    else
     254        m_iScrollToIndex = -1;
     255    updateSearchLineEdit(m_matchedItemList.size(), m_iScrollToIndex);
    160256}
    161257
     
    230326    setUnderlineItemText(m_matchedItemList[m_iScrollToIndex], true);
    231327    m_pTreeWidget->scrollTo(m_pTreeWidget->itemIndex(m_matchedItemList[m_iScrollToIndex]), QAbstractItemView::PositionAtCenter);
    232 
     328    updateSearchLineEdit(m_matchedItemList.size(), m_iScrollToIndex);
    233329}
    234330
     
    244340    goToNextPrevious(false);
    245341}
     342
     343void UIMediumSearchWidget::updateSearchLineEdit(int iMatchCount, int iScrollToIndex)
     344{
     345    if (!m_pSearchTermLineEdit)
     346        return;
     347    m_pSearchTermLineEdit->setMatchCount(iMatchCount);
     348    m_pSearchTermLineEdit->setScroolToIndex(iScrollToIndex);
     349}
     350
     351#include "UIMediumSearchWidget.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumSearchWidget.h

    r77013 r77174  
    3434class QITreeWidget;
    3535class UIMediumItem;
     36class UISearchLineEdit;
    3637
    3738
     
    8081     *  takes care of the necessary decoration changes to mark the current item. */
    8182    void    goToNextPrevious(bool fNext);
     83    /** Updates the feedback text of th line edit that shows # of matches. */
     84    void    updateSearchLineEdit(int iMatchCount, int iScrollToIndex);
    8285    QIComboBox       *m_pSearchComboxBox;
    83     QLineEdit        *m_pSearchTermLineEdit;
     86    UISearchLineEdit *m_pSearchTermLineEdit;
    8487    QIToolButton     *m_pShowNextMatchButton;
    8588    QIToolButton     *m_pShowPreviousMatchButton;
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