Changeset 77174 in vbox for trunk/src/VBox
- Timestamp:
- Feb 6, 2019 1:38:20 PM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r77154 r77174 975 975 src/logviewer/UIVMLogViewerTextEdit.cpp \ 976 976 src/medium/UIMediumEnumerator.cpp \ 977 src/medium/UIMediumSearchWidget.cpp \ 977 978 src/medium/viso/UIVisoContentBrowser.cpp \ 978 979 src/medium/viso/UIVisoHostBrowser.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumSearchWidget.cpp
r77013 r77174 19 19 #include <QLineEdit> 20 20 #include <QPushButton> 21 #include <QPainter> 21 22 #include <QVBoxLayout> 22 23 … … 37 38 38 39 40 /********************************************************************************************************************************* 41 * FilterByNameUUID definition/implementation. * 42 *********************************************************************************************************************************/ 43 39 44 class FilterByNameUUID : public QITreeWidgetItemFilter 40 45 { … … 56 61 if (!pMediumItem) 57 62 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)) 61 68 return false; 62 69 return true; … … 68 75 QString m_strSearchTerm; 69 76 }; 77 78 79 /********************************************************************************************************************************* 80 * UISearchLineEdit definition . * 81 *********************************************************************************************************************************/ 82 83 class UISearchLineEdit : public QLineEdit 84 { 85 86 Q_OBJECT; 87 88 public: 89 90 UISearchLineEdit(QWidget *pParent = 0); 91 void setMatchCount(int iMatchCount); 92 void setScroolToIndex(int iScrollToIndex); 93 94 protected: 95 96 virtual void paintEvent(QPaintEvent *pEvent) /* override */; 97 98 private: 99 100 int m_iMatchCount; 101 int m_iScrollToIndex; 102 }; 103 104 105 /********************************************************************************************************************************* 106 * UISearchLineEdit implementation . * 107 *********************************************************************************************************************************/ 108 109 UISearchLineEdit::UISearchLineEdit(QWidget *pParent /* = 0 */) 110 :QLineEdit(pParent) 111 , m_iMatchCount(0) 112 , m_iScrollToIndex(-1) 113 { 114 } 115 116 void 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 143 void UISearchLineEdit::setMatchCount(int iMatchCount) 144 { 145 if (m_iMatchCount == iMatchCount) 146 return; 147 m_iMatchCount = iMatchCount; 148 repaint(); 149 } 150 151 void 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 *********************************************************************************************************************************/ 70 163 71 164 UIMediumSearchWidget::UIMediumSearchWidget(QWidget *pParent) … … 76 169 , m_pShowPreviousMatchButton(0) 77 170 , m_pTreeWidget(0) 78 , m_iScrollToIndex( 0)171 , m_iScrollToIndex(-1) 79 172 { 80 173 prepareWidgets(); … … 101 194 } 102 195 103 m_pSearchTermLineEdit = new QLineEdit;196 m_pSearchTermLineEdit = new UISearchLineEdit; 104 197 if (m_pSearchTermLineEdit) 105 198 { 106 m_pSearchTermLineEdit->setClearButtonEnabled( true);199 m_pSearchTermLineEdit->setClearButtonEnabled(false); 107 200 pLayout->addWidget(m_pSearchTermLineEdit); 108 201 connect(m_pSearchTermLineEdit, &QLineEdit::textChanged, … … 158 251 goToNextPrevious(true); 159 252 } 253 else 254 m_iScrollToIndex = -1; 255 updateSearchLineEdit(m_matchedItemList.size(), m_iScrollToIndex); 160 256 } 161 257 … … 230 326 setUnderlineItemText(m_matchedItemList[m_iScrollToIndex], true); 231 327 m_pTreeWidget->scrollTo(m_pTreeWidget->itemIndex(m_matchedItemList[m_iScrollToIndex]), QAbstractItemView::PositionAtCenter); 232 328 updateSearchLineEdit(m_matchedItemList.size(), m_iScrollToIndex); 233 329 } 234 330 … … 244 340 goToNextPrevious(false); 245 341 } 342 343 void 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 34 34 class QITreeWidget; 35 35 class UIMediumItem; 36 class UISearchLineEdit; 36 37 37 38 … … 80 81 * takes care of the necessary decoration changes to mark the current item. */ 81 82 void goToNextPrevious(bool fNext); 83 /** Updates the feedback text of th line edit that shows # of matches. */ 84 void updateSearchLineEdit(int iMatchCount, int iScrollToIndex); 82 85 QIComboBox *m_pSearchComboxBox; 83 QLineEdit*m_pSearchTermLineEdit;86 UISearchLineEdit *m_pSearchTermLineEdit; 84 87 QIToolButton *m_pShowNextMatchButton; 85 88 QIToolButton *m_pShowPreviousMatchButton;
Note:
See TracChangeset
for help on using the changeset viewer.