Changeset 78462 in vbox
- Timestamp:
- May 10, 2019 2:56:17 PM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 130491
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/logviewer
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogPage.cpp
r77078 r78462 342 342 m_pTextEdit->setCurrentFont(font); 343 343 } 344 345 void UIVMLogPage::setSearchResultOverlayShowHide(bool fShow)346 {347 if (m_pTextEdit)348 m_pTextEdit->setSearchResultOverlayShowHide(fShow);349 }350 351 void UIVMLogPage::setSearchMatchCount(int iMatchCount)352 {353 if (m_pTextEdit)354 m_pTextEdit->setSearchMatchCount(iMatchCount);355 } -
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogPage.h
r77078 r78462 117 117 void setCurrentFont(QFont font); 118 118 119 void setSearchResultOverlayShowHide(bool fShow);120 void setSearchMatchCount(int iMatchCount);121 122 119 private slots: 123 120 -
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerSearchPanel.cpp
r78459 r78462 82 82 , m_pMatchWholeWordCheckBox(0) 83 83 , m_pHighlightAllCheckBox(0) 84 , m_iSearchCursorPosition(0)85 , m_iMatchCount(0)86 84 { 87 85 /* Prepare: */ … … 91 89 void UIVMLogViewerSearchPanel::refresh() 92 90 { 93 m_iSearchCursorPosition = 0;94 91 /* We start the search from the end of the doc. assuming log's end is more interesting: */ 95 search(BackwardSearch, true);92 performSearch(BackwardSearch, true); 96 93 emit sigHighlightingUpdated(); 97 94 } … … 99 96 void UIVMLogViewerSearchPanel::reset() 100 97 { 101 m_iSe archCursorPosition= 0;98 m_iSelectedMatchIndex = 0; 102 99 m_matchLocationVector.clear(); 103 setMatchCount(0);100 m_matchedCursorPosition.clear(); 104 101 if (m_pSearchEditor) 105 102 m_pSearchEditor->reset(); … … 118 115 int UIVMLogViewerSearchPanel::matchCount() const 119 116 { 120 return m_ iMatchCount;117 return m_matchedCursorPosition.size(); 121 118 } 122 119 … … 140 137 m_pPreviousButton->setEnabled(!strSearchString.isEmpty()); 141 138 142 143 139 /* If search-string is not empty: */ 144 140 if (!strSearchString.isEmpty()) 145 141 { 146 142 /* Reset the position to force the search restart from the document's end: */ 147 m_iSearchCursorPosition = 0; 148 search(BackwardSearch, true); 143 performSearch(BackwardSearch, true); 149 144 emit sigHighlightingUpdated(); 150 145 return; 151 146 } 147 152 148 /* If search-string is empty, reset cursor position: */ 153 149 if (!viewer()) … … 165 161 pBrowser->setTextCursor(cursor); 166 162 } 167 m_iSearchCursorPosition = -1; 168 setMatchCount(0); 163 m_matchedCursorPosition.clear(); 164 m_matchLocationVector.clear(); 165 clearHighlighting(); 169 166 emit sigSearchUpdated(); 170 clearHighlighting();171 167 } 172 168 … … 201 197 { 202 198 refresh(); 199 } 200 201 void UIVMLogViewerSearchPanel::sltSelectNextPreviousMatch() 202 { 203 moveSelection(sender() == m_pNextButton); 203 204 } 204 205 … … 282 283 { 283 284 connect(m_pSearchEditor, &UIVMLogViewerSearchField::textChanged, this, &UIVMLogViewerSearchPanel::sltSearchTextChanged); 284 connect(m_pNextButton, &QIToolButton::clicked, this, &UIVMLogViewerSearchPanel:: findNext);285 connect(m_pPreviousButton, &QIToolButton::clicked, this, &UIVMLogViewerSearchPanel:: findPrevious);285 connect(m_pNextButton, &QIToolButton::clicked, this, &UIVMLogViewerSearchPanel::sltSelectNextPreviousMatch); 286 connect(m_pPreviousButton, &QIToolButton::clicked, this, &UIVMLogViewerSearchPanel::sltSelectNextPreviousMatch); 286 287 287 288 connect(m_pHighlightAllCheckBox, &QCheckBox::stateChanged, … … 413 414 /* Select all the text: */ 414 415 m_pSearchEditor->selectAll(); 415 m_pSearchEditor->setMatchCount(m_ iMatchCount);416 } 417 } 418 419 void UIVMLogViewerSearchPanel:: search(SearchDirection direction, bool highlight)416 m_pSearchEditor->setMatchCount(m_matchedCursorPosition.size()); 417 } 418 } 419 420 void UIVMLogViewerSearchPanel::performSearch(SearchDirection , bool ) 420 421 { 421 422 QPlainTextEdit *pTextEdit = textEdit(); … … 429 430 430 431 const QString &searchString = m_pSearchEditor->text(); 431 setMatchCount(countMatches(pDocument, searchString));432 432 emit sigSearchUpdated(); 433 433 … … 435 435 return; 436 436 437 QTextCursor endCursor(pDocument); 438 endCursor.movePosition(QTextCursor::End); 439 QTextCursor startCursor(pDocument); 440 437 findAll(pDocument, searchString); 438 m_iSelectedMatchIndex = 0; 439 selectMatch(m_iSelectedMatchIndex, searchString); 440 if (m_pSearchEditor) 441 { 442 m_pSearchEditor->setMatchCount(m_matchedCursorPosition.size()); 443 m_pSearchEditor->setScroolToIndex(m_matchedCursorPosition.empty() ? -1 : 0); 444 } 441 445 if (m_pHighlightAllCheckBox->isChecked()) 442 { 443 if (highlight) 444 highlightAll(pDocument, searchString); 445 } 446 else 447 m_matchLocationVector.clear(); 448 449 QTextCursor resultCursor(pDocument); 450 int startPosition = m_iSearchCursorPosition; 451 if (direction == BackwardSearch) 452 startPosition -= searchString.length(); 453 resultCursor = pDocument->find(searchString, startPosition, constructFindFlags(direction)); 454 455 /* Decide whether to wrap around or to end the search */ 456 if (resultCursor.isNull()) 457 { 458 /* End the search if we search the whole document with no find: */ 459 if ((direction == ForwardSearch && startPosition == startCursor.position()) || 460 (direction == BackwardSearch && startPosition == endCursor.position())) 461 { 462 return; 463 } 464 /* Wrap the search */ 465 if (direction == ForwardSearch) 466 { 467 m_iSearchCursorPosition = startCursor.position(); 468 search(ForwardSearch, false); 469 return; 470 } 471 else 472 { 473 /* Set the search position away from the end position to be 474 able to find the string at the end of the document: */ 475 m_iSearchCursorPosition = endCursor.position() + searchString.length(); 476 search(BackwardSearch, false); 477 return; 478 } 479 } 480 pTextEdit->setTextCursor(resultCursor); 481 m_iSearchCursorPosition = resultCursor.position(); 482 } 483 484 void UIVMLogViewerSearchPanel::findNext() 485 { 486 search(ForwardSearch, false); 487 } 488 489 void UIVMLogViewerSearchPanel::findPrevious() 490 { 491 search(BackwardSearch, false); 446 highlightAll(pDocument, searchString); 492 447 } 493 448 … … 496 451 if (!viewer()) 497 452 return; 498 m_matchLocationVector.clear();499 453 QTextDocument* pDocument = textDocument(); 500 454 if (pDocument) 501 455 pDocument->undo(); 502 503 456 emit sigHighlightingUpdated(); 504 457 } … … 518 471 cursor.beginEditBlock(); 519 472 colorFormat.setBackground(Qt::yellow); 520 int lineCount = pDocument->lineCount(); 521 QTextDocument::FindFlags flags = constructFindFlags(ForwardSearch); 522 while (!highlightCursor.isNull() && !highlightCursor.atEnd()) 523 { 524 /* Hightlighting searches is always from the top of the document forward: */ 525 highlightCursor = pDocument->find(searchString, highlightCursor, flags); 473 for (int i = 0; i < m_matchedCursorPosition.size(); ++i) 474 { 475 highlightCursor.setPosition(m_matchedCursorPosition[i]); 476 highlightCursor.setPosition(m_matchedCursorPosition[i] + searchString.length(), QTextCursor::KeepAnchor); 477 526 478 if (!highlightCursor.isNull()) 527 479 { 528 480 highlightCursor.mergeCharFormat(colorFormat); 481 } 482 } 483 cursor.endEditBlock(); 484 } 485 486 void UIVMLogViewerSearchPanel::findAll(QTextDocument *pDocument, const QString &searchString) 487 { 488 if (!pDocument) 489 return; 490 m_matchedCursorPosition.clear(); 491 m_matchLocationVector.clear(); 492 if (searchString.isEmpty()) 493 return; 494 QTextCursor cursor(pDocument); 495 QTextDocument::FindFlags flags = constructFindFlags(ForwardSearch); 496 int lineCount = pDocument->lineCount(); 497 while (!cursor.isNull() && !cursor.atEnd()) 498 { 499 cursor = pDocument->find(searchString, cursor, flags); 500 501 if (!cursor.isNull()) 502 { 503 m_matchedCursorPosition << cursor.position() - searchString.length(); 529 504 /* The following assumes we have single line blocks only: */ 530 int cursorLine = pDocument->findBlock( highlightCursor.position()).blockNumber();505 int cursorLine = pDocument->findBlock(cursor.position()).blockNumber(); 531 506 if (lineCount != 0) 532 507 m_matchLocationVector.push_back(cursorLine / static_cast<float>(lineCount)); 533 508 } 534 509 } 535 cursor.endEditBlock(); 510 } 511 512 void UIVMLogViewerSearchPanel::selectMatch(int iMatchIndex, const QString &searchString) 513 { 514 if (!textEdit()) 515 return; 516 if (searchString.isEmpty()) 517 return; 518 if (iMatchIndex < 0 || iMatchIndex >= m_matchedCursorPosition.size()) 519 return; 520 521 QTextCursor cursor = textEdit()->textCursor(); 522 /* Move the cursor to the beginning of the matched string: */ 523 cursor.setPosition(m_matchedCursorPosition.at(iMatchIndex), QTextCursor::MoveAnchor); 524 /* Move the cursor to the end of the matched string while keeping the anchor at the begining thus selecting the text: */ 525 cursor.setPosition(m_matchedCursorPosition.at(iMatchIndex)+searchString.length(), QTextCursor::KeepAnchor); 526 textEdit()->setTextCursor(cursor); 527 return; 528 } 529 530 void UIVMLogViewerSearchPanel::moveSelection(bool fForward) 531 { 532 if (fForward) 533 m_iSelectedMatchIndex = m_iSelectedMatchIndex >= m_matchedCursorPosition.size() - 1 ? 0 : (m_iSelectedMatchIndex + 1); 534 else 535 m_iSelectedMatchIndex = m_iSelectedMatchIndex <= 0 ? m_matchedCursorPosition.size() - 1 : (m_iSelectedMatchIndex - 1); 536 selectMatch(m_iSelectedMatchIndex, m_pSearchEditor->text()); 537 if (m_pSearchEditor) 538 m_pSearchEditor->setScroolToIndex(m_iSelectedMatchIndex); 536 539 } 537 540 … … 555 558 } 556 559 557 void UIVMLogViewerSearchPanel::setMatchCount(int iCount)558 {559 if (m_iMatchCount == iCount)560 return;561 m_iMatchCount = iCount;562 if (m_pSearchEditor)563 m_pSearchEditor->setMatchCount(iCount);564 }565 566 560 QTextDocument::FindFlags UIVMLogViewerSearchPanel::constructFindFlags(SearchDirection eDirection) const 567 561 { -
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerSearchPanel.h
r78459 r78462 82 82 void sltCaseSentitiveCheckBox(); 83 83 void sltMatchWholeWordCheckBox(); 84 /** Forward search routine wrapper. */ 85 void findNext(); 86 /** Backward search routine wrapper. */ 87 void findPrevious(); 84 void sltSelectNextPreviousMatch(); 88 85 89 86 private: … … 98 95 * @param highlight if false highlight function is not called 99 96 thus we avoid calling highlighting for the same string repeatedly. */ 100 void search(SearchDirection eDirection, bool highlight);97 void performSearch(SearchDirection eDirection, bool highlight); 101 98 void highlightAll(QTextDocument *pDocument, const QString &searchString); 99 void findAll(QTextDocument *pDocument, const QString &searchString); 100 void selectMatch(int iMatchIndex, const QString &searchString); 101 void moveSelection(bool fForward); 102 102 103 /** Constructs the find flags for QTextDocument::find function. */ 103 104 QTextDocument::FindFlags constructFindFlags(SearchDirection eDirection) const; 104 105 /** Searches the whole document and return the number of matches to the current search term. */ 105 106 int countMatches(QTextDocument *pDocument, const QString &searchString) const; 106 void setMatchCount(int iCount);107 107 /** Holds the instance of search-editor we create. */ 108 108 UISearchLineEdit *m_pSearchEditor; … … 114 114 QCheckBox *m_pMatchWholeWordCheckBox; 115 115 QCheckBox *m_pHighlightAllCheckBox; 116 117 /** Holds the position where we start the next search. */ 118 int m_iSearchCursorPosition; 119 /** Holds the number of the matches for the string. 0 for no matches. */ 120 int m_iMatchCount; 121 122 /** Stores relative positions of the lines of the matches. The values are [0,1] 116 /** Stores relative positions of the lines of the matches wrt. total # of lines. The values are in [0,1] 123 117 0 being the first line 1 being the last. */ 124 118 QVector<float> m_matchLocationVector; 119 /** Document positions of the cursors within th document for all matches. */ 120 QVector<int> m_matchedCursorPosition; 121 /** The index of the curently selected item within m_matchedCursorPosition. */ 122 int m_iSelectedMatchIndex; 125 123 }; 126 124 -
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerTextEdit.cpp
r77275 r78462 193 193 , m_bWrapLines(true) 194 194 , m_bHasContextMenu(false) 195 , m_fShowSearchResultOverlay(0)196 , m_iMatchCount(0)197 195 { 198 196 configure(); … … 241 239 if (m_pLineNumberArea) 242 240 m_pLineNumberArea->setFont(font); 243 }244 245 void UIVMLogViewerTextEdit::setSearchResultOverlayShowHide(bool fShow)246 {247 if (m_fShowSearchResultOverlay == fShow)248 return;249 m_fShowSearchResultOverlay = fShow;250 if (viewport())251 viewport()->repaint();252 }253 254 void UIVMLogViewerTextEdit::setSearchMatchCount(int iMatchCount)255 {256 if (m_iMatchCount == iMatchCount)257 return;258 m_iMatchCount = iMatchCount;259 if (m_fShowSearchResultOverlay && viewport())260 viewport()->repaint();261 241 } 262 242 … … 386 366 } 387 367 388 void UIVMLogViewerTextEdit::paintEvent(QPaintEvent *pEvent)389 {390 QIWithRetranslateUI<QPlainTextEdit>::paintEvent(pEvent);391 392 /* Draw an overlay with text in it to show the number of search matches: */393 if (viewport() && (m_fShowSearchResultOverlay || m_bShownTextIsFiltered))394 {395 QPainter painter(viewport());396 QColor rectColor = viewport()->palette().color(QPalette::Active, QPalette::Dark);397 double fontScale = 1.5;398 rectColor.setAlpha(200);399 400 QString strText;401 if (m_fShowSearchResultOverlay)402 strText = QString("%1 %2").arg(QString::number(m_iMatchCount)).arg(UIVMLogViewerWidget::tr("Matches Found"));403 if (m_bShownTextIsFiltered)404 {405 if (!strText.isEmpty())406 strText.append(" / ");407 strText.append(UIVMLogViewerWidget::tr("Filtered"));408 }409 /* Space between the text and rectangle border: */410 QSize textMargin(5, 5);411 /* Space between the rectangle and viewport edges: */412 QSize rectMargin(2, 2);413 414 QSize rectSize(fontScale * QApplication::fontMetrics().width(strText) + textMargin.width(),415 fontScale * QApplication::fontMetrics().height() + textMargin.height());416 QPoint topLeft(viewport()->rect().width() - rectSize.width() - rectMargin.width(),417 viewport()->rect().height() - rectSize.height() - rectMargin.height());418 painter.fillRect(topLeft.x(),topLeft.y(), rectSize.width(), rectSize.height(), rectColor);419 420 421 QFont pfont = QApplication::font();422 QColor fontColor(QPalette::WindowText);423 painter.setPen(fontColor);424 if (pfont.pixelSize() != -1)425 pfont.setPixelSize(fontScale * pfont.pixelSize());426 else427 pfont.setPointSize(fontScale * pfont.pointSize());428 painter.setFont(pfont);429 430 painter.drawText(QRect(topLeft, rectSize), Qt::AlignCenter | Qt::AlignVCenter, strText);431 }432 }433 434 368 void UIVMLogViewerTextEdit::sltUpdateLineNumberAreaWidth(int /* newBlockCount */) 435 369 { -
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerTextEdit.h
r77275 r78462 69 69 void setCurrentFont(QFont font); 70 70 71 void setSearchResultOverlayShowHide(bool fShow);72 void setSearchMatchCount(int iMatchCount);73 74 71 protected: 75 72 … … 78 75 virtual void mouseMoveEvent(QMouseEvent *pEvent) /* override */; 79 76 virtual void leaveEvent(QEvent * pEvent) /* override */; 80 virtual void paintEvent(QPaintEvent *pEvent) /* override */;81 77 virtual void retranslateUi() /* override */; 82 78 … … 117 113 friend class UILineNumberArea; 118 114 bool m_bHasContextMenu; 119 bool m_fShowSearchResultOverlay; 120 int m_iMatchCount; 121 }; 115 }; 122 116 123 117 -
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.cpp
r78459 r78462 310 310 if (!m_pSearchPanel || !currentLogPage()) 311 311 return; 312 for (int i = 0; i < m_logPageList.size(); ++i)313 if (UIVMLogPage *pPage = qobject_cast<UIVMLogPage*>(m_logPageList[i]))314 pPage->setSearchMatchCount(m_pSearchPanel->matchCount());315 312 } 316 313 … … 767 764 pLogPage->markForError(); 768 765 } 769 pLogPage->setSearchResultOverlayShowHide(m_pSearchPanel->isVisible());770 pLogPage->setSearchMatchCount(m_pSearchPanel->matchCount());771 766 pLogPage->setScrollBarMarkingsVector(m_pSearchPanel->matchLocationVector()); 772 767 } … … 872 867 m_visiblePanelsList.removeOne(panel); 873 868 manageEscapeShortCut(); 874 /* Hide the search result overlay on the text edit: */875 if (panel == m_pSearchPanel)876 {877 for (int i = 0; i < m_logPageList.size(); ++i)878 if (UIVMLogPage *pPage = qobject_cast<UIVMLogPage*>(m_logPageList[i]))879 pPage->setSearchResultOverlayShowHide(false);880 }881 869 } 882 870 … … 893 881 m_visiblePanelsList.push_back(panel); 894 882 manageEscapeShortCut(); 895 896 /* Show the search result overlay on the text edit: */897 if (panel == m_pSearchPanel)898 {899 for (int i = 0; i < m_logPageList.size(); ++i)900 if (UIVMLogPage *pPage = qobject_cast<UIVMLogPage*>(m_logPageList[i]))901 pPage->setSearchResultOverlayShowHide(true);902 }903 883 } 904 884
Note:
See TracChangeset
for help on using the changeset viewer.