Changeset 76907 in vbox
- Timestamp:
- Jan 21, 2019 7:44:01 AM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/medium
- Files:
-
- 2 edited
-
UIMediumSelector.cpp (modified) (10 diffs)
-
UIMediumSelector.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumSelector.cpp
r76892 r76907 75 75 76 76 void sigPerformSearch(); 77 void sigShowNextMatchingItem(); 78 void sigShowPreviousMatchingItem(); 77 79 78 80 public: … … 88 90 private: 89 91 90 void prepareWidgets();92 void prepareWidgets(); 91 93 QIComboBox *m_pSearchComboxBox; 92 94 QLineEdit *m_pSearchTermLineEdit; 93 QIToolButton *m_pSearchButton; 95 QIToolButton *m_pShowNextMatchButton; 96 QIToolButton *m_pShowPreviousMatchButton; 94 97 }; 95 98 … … 103 106 , m_pSearchComboxBox(0) 104 107 , m_pSearchTermLineEdit(0) 105 , m_pSearchButton(0) 108 , m_pShowNextMatchButton(0) 109 , m_pShowPreviousMatchButton(0) 106 110 { 107 111 prepareWidgets(); … … 133 137 m_pSearchTermLineEdit->setClearButtonEnabled(true); 134 138 pLayout->addWidget(m_pSearchTermLineEdit); 135 connect(m_pSearchTermLineEdit, &QILineEdit:: editingFinished,139 connect(m_pSearchTermLineEdit, &QILineEdit::textChanged, 136 140 this, &UIMediumSearchWidget::sigPerformSearch); 137 141 } 138 142 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 146 158 retranslateUi(); 147 159 } … … 171 183 if (m_pSearchTermLineEdit) 172 184 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 } 177 190 178 191 /********************************************************************************************************************************* … … 197 210 , m_pParent(pParent) 198 211 , m_pSearchWidget(0) 212 , m_iCurrentShownIndex(0) 199 213 , m_strMachineSettingsFilePath(machineSettigFilePath) 200 214 , m_strMachineName(machineName) … … 367 381 connect(m_pSearchWidget, &UIMediumSearchWidget::sigPerformSearch, 368 382 this, &UIMediumSelector::sltHandlePerformSearch); 383 connect(m_pSearchWidget, &UIMediumSearchWidget::sigShowNextMatchingItem, 384 this, &UIMediumSelector::sltHandleShowNextMatchingItem); 385 connect(m_pSearchWidget, &UIMediumSearchWidget::sigShowPreviousMatchingItem, 386 this, &UIMediumSelector::sltHandlehowPreviousMatchingItem); 369 387 } 370 388 } … … 583 601 } 584 602 603 void 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 613 void 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 585 622 void UIMediumSelector::selectMedium(const QUuid &uMediumID) 586 623 { … … 780 817 } 781 818 819 m_mathingItemList.clear(); 820 m_iCurrentShownIndex = 0; 821 782 822 UIMediumSearchWidget::SearchType searchType = 783 823 m_pSearchWidget->searchType(); … … 801 841 if (strMedium.contains(strTerm, Qt::CaseInsensitive)) 802 842 { 803 / / mark the item843 /* mark all the items by setting foregroung color to red: */ 804 844 for (int j = 0; j < m_pTreeWidget->columnCount(); ++j) 805 845 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]); 809 847 } 810 848 } 811 } 849 if (!m_mathingItemList.isEmpty()) 850 scrollToItem(m_mathingItemList[0]); 851 } 852 853 void 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 812 873 813 874 #include "UIMediumSelector.moc" -
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumSelector.h
r76892 r76907 70 70 void sltHandleRefresh(); 71 71 void sltHandlePerformSearch(); 72 void sltHandleShowNextMatchingItem(); 73 void sltHandlehowPreviousMatchingItem(); 72 74 73 75 private: … … 103 105 void saveDefaultForeground(); 104 106 void selectMedium(const QUuid &uMediumID); 105 107 void scrollToItem(UIMediumItem* pItem); 106 108 QWidget *m_pCentralWidget; 107 109 QVBoxLayout *m_pMainLayout; … … 120 122 QWidget *m_pParent; 121 123 UIMediumSearchWidget *m_pSearchWidget; 124 /** The list all items added to tree. kept in sync. with tree to make searching easier (faster). */ 122 125 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; 123 130 QBrush m_defaultItemForeground; 124 131 QString m_strMachineSettingsFilePath;
Note:
See TracChangeset
for help on using the changeset viewer.

