VirtualBox

Changeset 76907 in vbox


Ignore:
Timestamp:
Jan 21, 2019 7:44:01 AM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9183. Make it possible to walk thru the medium items mathing to search

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumSelector.cpp

    r76892 r76907  
    7575
    7676    void sigPerformSearch();
     77    void sigShowNextMatchingItem();
     78    void sigShowPreviousMatchingItem();
    7779
    7880public:
     
    8890private:
    8991
    90     void prepareWidgets();
     92    void              prepareWidgets();
    9193    QIComboBox       *m_pSearchComboxBox;
    9294    QLineEdit        *m_pSearchTermLineEdit;
    93     QIToolButton     *m_pSearchButton;
     95    QIToolButton     *m_pShowNextMatchButton;
     96    QIToolButton     *m_pShowPreviousMatchButton;
    9497};
    9598
     
    103106    , m_pSearchComboxBox(0)
    104107    , m_pSearchTermLineEdit(0)
    105     , m_pSearchButton(0)
     108    , m_pShowNextMatchButton(0)
     109    , m_pShowPreviousMatchButton(0)
    106110{
    107111    prepareWidgets();
     
    133137        m_pSearchTermLineEdit->setClearButtonEnabled(true);
    134138        pLayout->addWidget(m_pSearchTermLineEdit);
    135         connect(m_pSearchTermLineEdit, &QILineEdit::editingFinished,
     139        connect(m_pSearchTermLineEdit, &QILineEdit::textChanged,
    136140                this, &UIMediumSearchWidget::sigPerformSearch);
    137141    }
    138142
    139     m_pSearchButton = new QIToolButton;
    140     if (m_pSearchButton)
    141     {
    142         m_pSearchButton->setIcon(UIIconPool::iconSet(":/log_viewer_find_16px.png", ":/log_viewer_find_disabled_16px.png"));
    143         connect(m_pSearchButton, &QIToolButton::clicked, this, &UIMediumSearchWidget::sigPerformSearch);
    144         pLayout->addWidget(m_pSearchButton);
    145     }
     143    m_pShowPreviousMatchButton = new QIToolButton;
     144    if (m_pShowPreviousMatchButton)
     145    {
     146        m_pShowPreviousMatchButton->setIcon(UIIconPool::iconSet(":/log_viewer_search_backward_16px.png", ":/log_viewer_search_backward_disabled_16px.png"));
     147        connect(m_pShowPreviousMatchButton, &QIToolButton::clicked, this, &UIMediumSearchWidget::sigShowPreviousMatchingItem);
     148        pLayout->addWidget(m_pShowPreviousMatchButton);
     149    }
     150    m_pShowNextMatchButton = new QIToolButton;
     151    if (m_pShowNextMatchButton)
     152    {
     153        m_pShowNextMatchButton->setIcon(UIIconPool::iconSet(":/log_viewer_search_forward_16px.png", ":/log_viewer_search_forward_disabled_16px.png"));
     154        connect(m_pShowNextMatchButton, &QIToolButton::clicked, this, &UIMediumSearchWidget:: sigShowNextMatchingItem);
     155        pLayout->addWidget(m_pShowNextMatchButton);
     156    }
     157
    146158    retranslateUi();
    147159}
     
    171183    if (m_pSearchTermLineEdit)
    172184        m_pSearchTermLineEdit->setToolTip("Enter the search term and press Return");
    173     if (m_pSearchButton)
    174         m_pSearchButton->setToolTip("Search medium with the given name or UUID");
    175 }
    176 
     185    if (m_pShowPreviousMatchButton)
     186        m_pShowPreviousMatchButton->setToolTip("Show the previous item matching the search term");
     187    if (m_pShowNextMatchButton)
     188        m_pShowNextMatchButton->setToolTip("Show the next item matching the search term");
     189}
    177190
    178191/*********************************************************************************************************************************
     
    197210    , m_pParent(pParent)
    198211    , m_pSearchWidget(0)
     212    , m_iCurrentShownIndex(0)
    199213    , m_strMachineSettingsFilePath(machineSettigFilePath)
    200214    , m_strMachineName(machineName)
     
    367381        connect(m_pSearchWidget, &UIMediumSearchWidget::sigPerformSearch,
    368382                this, &UIMediumSelector::sltHandlePerformSearch);
     383        connect(m_pSearchWidget, &UIMediumSearchWidget::sigShowNextMatchingItem,
     384                this, &UIMediumSelector::sltHandleShowNextMatchingItem);
     385        connect(m_pSearchWidget, &UIMediumSearchWidget::sigShowPreviousMatchingItem,
     386                this, &UIMediumSelector::sltHandlehowPreviousMatchingItem);
    369387    }
    370388}
     
    583601}
    584602
     603void UIMediumSelector::sltHandleShowNextMatchingItem()
     604{
     605    if (m_mathingItemList.isEmpty())
     606        return;
     607
     608    if (++m_iCurrentShownIndex >= m_mathingItemList.size())
     609        m_iCurrentShownIndex = 0;
     610    scrollToItem(m_mathingItemList[m_iCurrentShownIndex]);
     611}
     612
     613void UIMediumSelector::sltHandlehowPreviousMatchingItem()
     614{
     615    if (m_mathingItemList.isEmpty())
     616        return;
     617    if (--m_iCurrentShownIndex < 0)
     618        m_iCurrentShownIndex = m_mathingItemList.size() -1;
     619    scrollToItem(m_mathingItemList[m_iCurrentShownIndex]);
     620}
     621
    585622void UIMediumSelector::selectMedium(const QUuid &uMediumID)
    586623{
     
    780817    }
    781818
     819    m_mathingItemList.clear();
     820    m_iCurrentShownIndex = 0;
     821
    782822    UIMediumSearchWidget::SearchType searchType =
    783823        m_pSearchWidget->searchType();
     
    801841        if (strMedium.contains(strTerm, Qt::CaseInsensitive))
    802842        {
    803             // mark the item
     843            /* mark all the items by setting foregroung color to red: */
    804844            for (int j = 0; j < m_pTreeWidget->columnCount(); ++j)
    805845                m_mediumItemList[i]->setData(j, Qt::ForegroundRole, QBrush(QColor(255, 0, 0)));
    806             QModelIndex itemIndex = m_pTreeWidget->itemIndex(m_mediumItemList[i]);
    807             if (itemIndex.isValid())
    808                 m_pTreeWidget->scrollTo(itemIndex);
     846            m_mathingItemList.append(m_mediumItemList[i]);
    809847        }
    810848    }
    811 }
     849    if (!m_mathingItemList.isEmpty())
     850        scrollToItem(m_mathingItemList[0]);
     851}
     852
     853void UIMediumSelector::scrollToItem(UIMediumItem* pItem)
     854{
     855    if (!pItem)
     856        return;
     857
     858    QModelIndex itemIndex = m_pTreeWidget->itemIndex(pItem);
     859    for (int i = 0; i < m_mediumItemList.size(); ++i)
     860    {
     861        QFont font = m_mediumItemList[i]->font(0);
     862        font.setBold(false);
     863        m_mediumItemList[i]->setFont(0, font);
     864    }
     865    QFont font = pItem->font(0);
     866    font.setBold(true);
     867    pItem->setFont(0, font);
     868
     869    m_pTreeWidget->scrollTo(itemIndex);
     870    //m_pTreeWidget->setCurrentIndex(itemIndex);
     871}
     872
    812873
    813874#include "UIMediumSelector.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumSelector.h

    r76892 r76907  
    7070    void sltHandleRefresh();
    7171    void sltHandlePerformSearch();
     72    void sltHandleShowNextMatchingItem();
     73    void sltHandlehowPreviousMatchingItem();
    7274
    7375 private:
     
    103105    void          saveDefaultForeground();
    104106    void          selectMedium(const QUuid &uMediumID);
    105 
     107    void          scrollToItem(UIMediumItem* pItem);
    106108    QWidget              *m_pCentralWidget;
    107109    QVBoxLayout          *m_pMainLayout;
     
    120122    QWidget              *m_pParent;
    121123    UIMediumSearchWidget *m_pSearchWidget;
     124    /** The list all items added to tree. kept in sync. with tree to make searching easier (faster). */
    122125    QList<UIMediumItem*>  m_mediumItemList;
     126    /** List of items that are matching to the search. */
     127    QList<UIMediumItem*>  m_mathingItemList;
     128    /** Index of the currently shown (scrolled) item in the m_mathingItemList. */
     129    int                   m_iCurrentShownIndex;
    123130    QBrush                m_defaultItemForeground;
    124131    QString               m_strMachineSettingsFilePath;
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