Changeset 86821 in vbox
- Timestamp:
- Nov 6, 2020 12:19:28 PM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 141265
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpBrowserWidget.cpp
r86816 r86821 86 86 void sigDragging(const QPoint &delta); 87 87 void sigSearchTextChanged(const QString &strSearchText); 88 void sigSelectNextMatch(); 89 void sigSelectPreviousMatch(); 88 90 89 91 public: 90 92 91 93 UIFindInPageWidget(QWidget *pParent = 0); 94 void setMatchCountAndCurrentIndex(int iTotalMatchCount, int iCurrentlyScrolledIndex); 95 void clearSearchField(); 92 96 93 97 protected: … … 100 104 void retranslateUi(); 101 105 UISearchLineEdit *m_pSearchLineEdit; 102 QIToolButton *m_p DownButton;103 QIToolButton *m_p UpButton;106 QIToolButton *m_pNextButton; 107 QIToolButton *m_pPreviousButton; 104 108 QLabel *m_pDragMoveLabel; 105 109 QPoint m_previousMousePosition; … … 140 144 void sltHandleFindWidgetDrag(const QPoint &delta); 141 145 void sltHandleFindInPageSearchTextChange(const QString &strSearchText); 146 void sltSelectPreviousMatch(); 147 void sltSelectNextMatch(); 142 148 143 149 private: … … 146 152 bool isRectInside(const QRect &rect, int iMargin) const; 147 153 void moveFindWidgetIn(int iMargin); 154 void findAllMatches(const QString &searchString); 155 void highlightFinds(int iSearchTermLength); 156 void selectMatch(int iMatchIndex, int iSearchStringLength); 148 157 const QHelpEngine* m_pHelpEngine; 149 150 158 UIFindInPageWidget *m_pFindInPageWidget; 151 159 /* Initilized as false and set to true once the find widget is positioned during first resize. */ 152 160 bool m_fFindWidgetPositioned; 153 161 const int m_iMarginForFindWidget; 162 /** Document positions of the cursors within the document for all matches. */ 163 QVector<int> m_matchedCursorPosition; 164 int m_iSelectedMatchIndex; 165 int m_iSearchTermLength; 154 166 }; 155 167 … … 255 267 }; 256 268 269 257 270 /********************************************************************************************************************************* 258 * UIFindInPageWidget implementation. *271 * UIFindInPageWidget implementation. * 259 272 *********************************************************************************************************************************/ 260 273 UIFindInPageWidget::UIFindInPageWidget(QWidget *pParent /* = 0 */) 261 274 : QIWithRetranslateUI<QWidget>(pParent) 262 275 , m_pSearchLineEdit(0) 263 , m_p DownButton(0)264 , m_p UpButton(0)276 , m_pNextButton(0) 277 , m_pPreviousButton(0) 265 278 , m_previousMousePosition(-1, -1) 266 279 { 267 280 prepare(); 281 } 282 283 void UIFindInPageWidget::setMatchCountAndCurrentIndex(int iTotalMatchCount, int iCurrentlyScrolledIndex) 284 { 285 if (!m_pSearchLineEdit) 286 return; 287 m_pSearchLineEdit->setMatchCount(iTotalMatchCount); 288 m_pSearchLineEdit->setScrollToIndex(iCurrentlyScrolledIndex); 289 } 290 291 void UIFindInPageWidget::clearSearchField() 292 { 293 if (!m_pSearchLineEdit) 294 return; 295 m_pSearchLineEdit->blockSignals(true); 296 m_pSearchLineEdit->reset(); 297 m_pSearchLineEdit->blockSignals(false); 268 298 } 269 299 … … 296 326 m_pSearchLineEdit = new UISearchLineEdit; 297 327 AssertReturnVoid(pLayout && m_pSearchLineEdit); 298 328 setFocusProxy(m_pSearchLineEdit); 299 329 QFontMetrics fontMetric(m_pSearchLineEdit->font()); 300 330 setMinimumSize(40 * fontMetric.width("x"), … … 316 346 pLayout->addWidget(m_pSearchLineEdit); 317 347 318 m_pUpButton = new QIToolButton; 319 m_pDownButton = new QIToolButton; 320 321 pLayout->addWidget(m_pUpButton); 322 pLayout->addWidget(m_pDownButton); 323 324 m_pUpButton->setIcon(UIIconPool::iconSet(":/arrow_up_10px.png")); 325 m_pDownButton->setIcon(UIIconPool::iconSet(":/arrow_down_10px.png")); 326 348 m_pPreviousButton = new QIToolButton; 349 m_pNextButton = new QIToolButton; 350 351 pLayout->addWidget(m_pPreviousButton); 352 pLayout->addWidget(m_pNextButton); 353 354 m_pPreviousButton->setIcon(UIIconPool::iconSet(":/arrow_up_10px.png")); 355 m_pNextButton->setIcon(UIIconPool::iconSet(":/arrow_down_10px.png")); 356 357 connect(m_pPreviousButton, &QIToolButton::pressed, this, &UIFindInPageWidget::sigSelectPreviousMatch); 358 connect(m_pNextButton, &QIToolButton::pressed, this, &UIFindInPageWidget::sigSelectNextMatch); 327 359 } 328 360 … … 581 613 , m_fFindWidgetPositioned(false) 582 614 , m_iMarginForFindWidget(qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin)) 583 { 615 , m_iSelectedMatchIndex(0) 616 , m_iSearchTermLength(0) 617 { 618 setUndoRedoEnabled(true); 584 619 connect(m_pFindInPageWidget, &UIFindInPageWidget::sigDragging, 585 620 this, &UIHelpBrowserViewer::sltHandleFindWidgetDrag); 586 621 connect(m_pFindInPageWidget, &UIFindInPageWidget::sigSearchTextChanged, 587 622 this, &UIHelpBrowserViewer::sltHandleFindInPageSearchTextChange); 623 624 connect(m_pFindInPageWidget, &UIFindInPageWidget::sigSelectPreviousMatch, 625 this, &UIHelpBrowserViewer::sltSelectPreviousMatch); 626 connect(m_pFindInPageWidget, &UIFindInPageWidget::sigSelectNextMatch, 627 this, &UIHelpBrowserViewer::sltSelectNextMatch); 628 588 629 m_pFindInPageWidget->setVisible(false); 589 630 retranslateUi(); … … 614 655 void UIHelpBrowserViewer::toggleFindInPageWidget(bool fVisible) 615 656 { 616 if (m_pFindInPageWidget) 617 { 618 m_pFindInPageWidget->setVisible(fVisible); 619 update(); 620 } 657 if (!m_pFindInPageWidget) 658 return; 659 m_pFindInPageWidget->setVisible(fVisible); 660 661 if (!fVisible) 662 { 663 document()->undo(); 664 m_pFindInPageWidget->clearSearchField(); 665 } 666 else 667 m_pFindInPageWidget->setFocus(); 621 668 } 622 669 … … 684 731 } 685 732 686 733 bool UIHelpBrowserViewer::isRectInside(const QRect &rect, int iMargin) const 687 734 { 688 735 if (rect.left() < iMargin || rect.top() < iMargin) … … 693 740 } 694 741 742 void UIHelpBrowserViewer::findAllMatches(const QString &searchString) 743 { 744 QTextDocument *pDocument = document(); 745 AssertReturnVoid(pDocument); 746 747 m_matchedCursorPosition.clear(); 748 if (searchString.isEmpty()) 749 return; 750 QTextCursor cursor(pDocument); 751 QTextDocument::FindFlags flags; 752 int iMatchCount = 0; 753 while (!cursor.isNull() && !cursor.atEnd()) 754 { 755 cursor = pDocument->find(searchString, cursor, flags); 756 if (!cursor.isNull()) 757 { 758 m_matchedCursorPosition << cursor.position() - searchString.length(); 759 ++iMatchCount; 760 } 761 } 762 } 763 764 void UIHelpBrowserViewer::highlightFinds(int iSearchTermLength) 765 { 766 QTextDocument* pDocument = document(); 767 AssertReturnVoid(pDocument); 768 /* Clear previous highlight: */ 769 pDocument->undo(); 770 771 QTextCursor highlightCursor(pDocument); 772 QTextCharFormat colorFormat(highlightCursor.charFormat()); 773 QTextCursor cursor(pDocument); 774 cursor.beginEditBlock(); 775 colorFormat.setBackground(Qt::yellow); 776 for (int i = 0; i < m_matchedCursorPosition.size(); ++i) 777 { 778 highlightCursor.setPosition(m_matchedCursorPosition[i]); 779 highlightCursor.setPosition(m_matchedCursorPosition[i] + iSearchTermLength, QTextCursor::KeepAnchor); 780 if (!highlightCursor.isNull()) 781 highlightCursor.mergeCharFormat(colorFormat); 782 } 783 cursor.endEditBlock(); 784 } 785 786 void UIHelpBrowserViewer::selectMatch(int iMatchIndex, int iSearchStringLength) 787 { 788 QTextCursor cursor = textCursor(); 789 /* Move the cursor to the beginning of the matched string: */ 790 cursor.setPosition(m_matchedCursorPosition.at(iMatchIndex), QTextCursor::MoveAnchor); 791 /* Move the cursor to the end of the matched string while keeping the anchor at the begining thus selecting the text: */ 792 cursor.setPosition(m_matchedCursorPosition.at(iMatchIndex) + iSearchStringLength, QTextCursor::KeepAnchor); 793 ensureCursorVisible(); 794 setTextCursor(cursor); 795 } 796 695 797 void UIHelpBrowserViewer::sltHandleOpenInNewTab() 696 798 { … … 718 820 void UIHelpBrowserViewer::sltHandleFindInPageSearchTextChange(const QString &strSearchText) 719 821 { 720 printf("%s\n", qPrintable(strSearchText)); 721 } 822 m_iSearchTermLength = strSearchText.length(); 823 findAllMatches(strSearchText); 824 highlightFinds(m_iSearchTermLength); 825 //scrollToMatch(int iMatchIndex); 826 selectMatch(0, m_iSearchTermLength); 827 if (m_pFindInPageWidget) 828 m_pFindInPageWidget->setMatchCountAndCurrentIndex(m_matchedCursorPosition.size(), 0); 829 } 830 831 void UIHelpBrowserViewer::sltSelectPreviousMatch() 832 { 833 m_iSelectedMatchIndex = m_iSelectedMatchIndex <= 0 ? m_matchedCursorPosition.size() - 1 : (m_iSelectedMatchIndex - 1); 834 selectMatch(m_iSelectedMatchIndex, m_iSearchTermLength); 835 if (m_pFindInPageWidget) 836 m_pFindInPageWidget->setMatchCountAndCurrentIndex(m_matchedCursorPosition.size(), m_iSelectedMatchIndex); 837 } 838 839 void UIHelpBrowserViewer::sltSelectNextMatch() 840 { 841 m_iSelectedMatchIndex = m_iSelectedMatchIndex >= m_matchedCursorPosition.size() - 1 ? 0 : (m_iSelectedMatchIndex + 1); 842 selectMatch(m_iSelectedMatchIndex, m_iSearchTermLength); 843 if (m_pFindInPageWidget) 844 m_pFindInPageWidget->setMatchCountAndCurrentIndex(m_matchedCursorPosition.size(), m_iSelectedMatchIndex); 845 } 846 722 847 723 848 /********************************************************************************************************************************* -
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerSearchPanel.cpp
r86814 r86821 409 409 { 410 410 m_pSearchEditor->setMatchCount(m_matchedCursorPosition.size()); 411 m_pSearchEditor->setScro olToIndex(m_matchedCursorPosition.empty() ? -1 : 0);411 m_pSearchEditor->setScrollToIndex(m_matchedCursorPosition.empty() ? -1 : 0); 412 412 } 413 413 if (m_pHighlightAllCheckBox->isChecked()) … … 494 494 textEdit()->ensureCursorVisible(); 495 495 textEdit()->setTextCursor(cursor); 496 return;497 496 } 498 497 … … 505 504 selectMatch(m_iSelectedMatchIndex, m_pSearchEditor->text()); 506 505 if (m_pSearchEditor) 507 m_pSearchEditor->setScro olToIndex(m_iSelectedMatchIndex);506 m_pSearchEditor->setScrollToIndex(m_iSelectedMatchIndex); 508 507 } 509 508 -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserSearchWidget.cpp
r84587 r86821 54 54 if (!m_pLineEdit) 55 55 return; 56 m_pLineEdit->setScro olToIndex(iScrollToIndex);56 m_pLineEdit->setScrollToIndex(iScrollToIndex); 57 57 } 58 58 -
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumSearchWidget.cpp
r82968 r86821 262 262 return; 263 263 m_pSearchTermLineEdit->setMatchCount(iMatchCount); 264 m_pSearchTermLineEdit->setScro olToIndex(iScrollToIndex);265 } 264 m_pSearchTermLineEdit->setScrollToIndex(iScrollToIndex); 265 } -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UISearchLineEdit.cpp
r86816 r86821 75 75 } 76 76 77 void UISearchLineEdit::setScro olToIndex(int iScrollToIndex)77 void UISearchLineEdit::setScrollToIndex(int iScrollToIndex) 78 78 { 79 79 if (m_iScrollToIndex == iScrollToIndex) -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UISearchLineEdit.h
r82968 r86821 41 41 UISearchLineEdit(QWidget *pParent = 0); 42 42 void setMatchCount(int iMatchCount); 43 void setScro olToIndex(int iScrollToIndex);43 void setScrollToIndex(int iScrollToIndex); 44 44 void reset(); 45 45
Note:
See TracChangeset
for help on using the changeset viewer.