Changeset 77078 in vbox
- Timestamp:
- Jan 31, 2019 3:34:30 PM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/logviewer
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogPage.cpp
r76606 r77078 339 339 void UIVMLogPage::setCurrentFont(QFont font) 340 340 { 341 if (!m_pTextEdit) 342 return; 343 m_pTextEdit->setCurrentFont(font); 344 } 341 if (m_pTextEdit) 342 m_pTextEdit->setCurrentFont(font); 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
r76581 r77078 117 117 void setCurrentFont(QFont font); 118 118 119 void setSearchResultOverlayShowHide(bool fShow); 120 void setSearchMatchCount(int iMatchCount); 121 119 122 private slots: 120 123 -
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerSearchPanel.cpp
r77030 r77078 80 80 , m_pMatchWholeWordCheckBox(0) 81 81 , m_pHighlightAllCheckBox(0) 82 , m_pWarningIcon(0)83 , m_pInfoLabel(0)84 82 , m_iSearchPosition(0) 85 , m_iMatchCount( -1)83 , m_iMatchCount(0) 86 84 { 87 85 /* Prepare: */ … … 101 99 m_iSearchPosition = 0; 102 100 m_matchLocationVector.clear(); 103 m_iMatchCount = -1; 104 configureInfoLabels(); 105 } 106 107 const QVector<float> &UIVMLogViewerSearchPanel::getMatchLocationVector() const 101 m_iMatchCount = 0; 102 } 103 104 const QVector<float> &UIVMLogViewerSearchPanel::matchLocationVector() const 108 105 { 109 106 return m_matchLocationVector; … … 113 110 { 114 111 return "SearchPanel"; 112 } 113 114 int UIVMLogViewerSearchPanel::marchCount() const 115 { 116 return m_iMatchCount; 115 117 } 116 118 … … 160 162 } 161 163 m_iSearchPosition = -1; 162 clearHighlighting( -1);164 clearHighlighting(); 163 165 } 164 166 … … 180 182 } 181 183 else 182 { 183 /* we need this check not to remove the 'not found' label 184 when the user toggles with this check-box: */ 185 if (m_iMatchCount != 0) 186 clearHighlighting(-1); 187 else 188 clearHighlighting(0); 189 } 190 configureInfoLabels(); 184 clearHighlighting(); 185 191 186 emit sigHighlightingUpdated(); 192 187 } … … 255 250 } 256 251 257 /* Create search field layout: */258 QHBoxLayout *pSearchErrorLayout = new QHBoxLayout;259 if (pSearchErrorLayout)260 {261 pSearchErrorLayout->setContentsMargins(0, 0, 0, 0);262 #ifdef VBOX_WS_MAC263 pSearchErrorLayout->setSpacing(5);264 #else265 pSearchErrorLayout->setSpacing(qApp->style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing) / 2);266 #endif267 268 /* Create warning-icon: */269 m_pWarningIcon = new QLabel;270 if (m_pWarningIcon)271 {272 m_pWarningIcon->hide();273 QIcon icon = UIIconPool::defaultIcon(UIIconPool::UIDefaultIconType_MessageBoxWarning, this);274 if (!icon.isNull())275 m_pWarningIcon->setPixmap(icon.pixmap(16, 16));276 pSearchErrorLayout->addWidget(m_pWarningIcon);277 }278 279 /* Create warning-label: */280 m_pInfoLabel = new QLabel;281 if (m_pInfoLabel)282 {283 m_pInfoLabel->hide();284 pSearchErrorLayout->addWidget(m_pInfoLabel);285 }286 287 mainLayout()->addLayout(pSearchErrorLayout);288 }289 290 252 /* Create case-sensitive check-box: */ 291 253 m_pCaseSensitiveCheckBox = new QCheckBox; … … 341 303 m_pHighlightAllCheckBox->setText(UIVMLogViewerWidget::tr("&Highlight All")); 342 304 m_pHighlightAllCheckBox->setToolTip(UIVMLogViewerWidget::tr("When checked, all occurence of the search text are highlighted")); 343 344 if (m_iMatchCount == 0)345 m_pInfoLabel->setText(UIVMLogViewerWidget::tr("String not found"));346 else if (m_iMatchCount > 0)347 m_pInfoLabel->setText(UIVMLogViewerWidget::tr("%1 Matches Found").arg(m_iMatchCount));348 305 } 349 306 … … 460 417 461 418 const QString &searchString = m_pSearchEditor->text(); 419 m_iMatchCount = countMatches(pDocument, searchString); 420 emit sigSearchUpdated(); 421 462 422 if (searchString.isEmpty()) 463 423 return; … … 473 433 } 474 434 else 475 {476 m_iMatchCount = -1;477 435 m_matchLocationVector.clear(); 478 }479 436 480 437 QTextCursor resultCursor(pDocument); … … 491 448 (direction == BackwardSearch && startPosition == endCursor.position())) 492 449 { 493 /* Set the match count 0 here since we did not call highLightAll function: */494 if (!m_pHighlightAllCheckBox->isChecked())495 m_iMatchCount = 0;496 configureInfoLabels();497 450 return; 498 451 } … … 515 468 pTextEdit->setTextCursor(resultCursor); 516 469 m_iSearchPosition = resultCursor.position(); 517 configureInfoLabels();518 470 } 519 471 … … 528 480 } 529 481 530 void UIVMLogViewerSearchPanel::clearHighlighting( int count)482 void UIVMLogViewerSearchPanel::clearHighlighting() 531 483 { 532 484 if (!viewer()) 533 485 return; 534 m_iMatchCount = count;535 486 m_matchLocationVector.clear(); 536 537 487 QTextDocument* pDocument = textDocument(); 538 488 if (pDocument) 539 489 pDocument->undo(); 540 490 541 configureInfoLabels();542 491 emit sigHighlightingUpdated(); 543 492 } … … 546 495 const QString &searchString) 547 496 { 548 clearHighlighting(0); 549 497 clearHighlighting(); 550 498 if (!pDocument) 551 499 return; … … 559 507 colorFormat.setBackground(Qt::yellow); 560 508 int lineCount = pDocument->lineCount(); 509 QTextDocument::FindFlags flags = constructFindFlags(ForwardSearch); 561 510 while (!highlightCursor.isNull() && !highlightCursor.atEnd()) 562 511 { 563 512 /* Hightlighting searches is always from the top of the document forward: */ 564 highlightCursor = pDocument->find(searchString, highlightCursor, constructFindFlags(ForwardSearch));513 highlightCursor = pDocument->find(searchString, highlightCursor, flags); 565 514 if (!highlightCursor.isNull()) 566 515 { 567 516 highlightCursor.mergeCharFormat(colorFormat); 568 ++m_iMatchCount;569 517 /* The following assumes we have single line blocks only: */ 570 518 int cursorLine = pDocument->findBlock(highlightCursor.position()).blockNumber(); … … 576 524 } 577 525 578 void UIVMLogViewerSearchPanel::configureInfoLabels() 579 { 580 if (!m_pSearchEditor || !m_pWarningIcon || !m_pInfoLabel) 581 return; 582 583 /* If no match has been found, mark the search editor: */ 584 if (m_iMatchCount == 0) 585 { 586 m_pSearchEditor->markError(); 587 m_pWarningIcon->setVisible(true); 588 m_pInfoLabel->setVisible(true); 589 } 590 else if (m_iMatchCount == -1) 591 { 592 m_pSearchEditor->unmarkError(); 593 m_pWarningIcon->setVisible(false); 594 m_pInfoLabel->setVisible(false); 595 } 596 else 597 { 598 m_pSearchEditor->unmarkError(); 599 m_pWarningIcon->setVisible(false); 600 m_pInfoLabel->setVisible(true); 601 } 602 /* Retranslate to get the label text corectly: */ 603 retranslateUi(); 604 } 605 606 QTextDocument::FindFlags UIVMLogViewerSearchPanel::constructFindFlags(SearchDirection eDirection) 526 int UIVMLogViewerSearchPanel::countMatches(QTextDocument *pDocument, const QString &searchString) const 527 { 528 if (!pDocument) 529 return 0; 530 if (searchString.isEmpty()) 531 return 0; 532 int count = 0; 533 QTextCursor cursor(pDocument); 534 QTextDocument::FindFlags flags = constructFindFlags(ForwardSearch); 535 while (!cursor.isNull() && !cursor.atEnd()) 536 { 537 cursor = pDocument->find(searchString, cursor, flags); 538 539 if (!cursor.isNull()) 540 ++count; 541 } 542 return count; 543 } 544 545 QTextDocument::FindFlags UIVMLogViewerSearchPanel::constructFindFlags(SearchDirection eDirection) const 607 546 { 608 547 QTextDocument::FindFlags findFlags; -
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerSearchPanel.h
r76954 r77078 46 46 47 47 void sigHighlightingUpdated(); 48 void sigSearchUpdated(); 48 49 49 50 public: … … 55 56 void refresh(); 56 57 void reset(); 57 const QVector<float> & getMatchLocationVector() const;58 const QVector<float> &matchLocationVector() const; 58 59 virtual QString panelName() const /* override */; 60 /** Returns the number of the matches to the current search. */ 61 int marchCount() const; 59 62 60 63 protected: … … 88 91 89 92 /** Clear the highlighting */ 90 void clearHighlight(); 91 void clearHighlighting(int count); 93 void clearHighlighting(); 92 94 93 95 /** Search routine. … … 97 99 void search(SearchDirection eDirection, bool highlight); 98 100 void highlightAll(QTextDocument *pDocument, const QString &searchString); 99 /** Controls the visibility of the warning icon and info labels.100 Also marks the search editor in case of no match.*/101 void configureInfoLabels();102 101 /** Constructs the find flags for QTextDocument::find function. */ 103 QTextDocument::FindFlags constructFindFlags(SearchDirection eDirection); 104 102 QTextDocument::FindFlags constructFindFlags(SearchDirection eDirection) const; 103 /** Searches the whole document and return the number of matches to the current search term. */ 104 int countMatches(QTextDocument *pDocument, const QString &searchString) const; 105 105 /** Holds the instance of search-editor we create. */ 106 106 UIVMLogViewerSearchField *m_pSearchEditor; … … 113 113 QCheckBox *m_pHighlightAllCheckBox; 114 114 115 /** Holds the instance of warning icon we create. */116 QLabel *m_pWarningIcon;117 /** Holds the instance of info label we create. */118 QLabel *m_pInfoLabel;119 120 115 /** Holds the position where we start the next search. */ 121 116 int m_iSearchPosition; 122 /** Holds the number of the matches for the string. 123 -1: highLightAll function is not called 124 0: no matches found 125 n > 0: n matches found. */ 117 /** Holds the number of the matches for the string. 0 for no matches. */ 126 118 int m_iMatchCount; 127 119 /** Stores relative positions of the lines of the matches. The values are [0,1] -
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerTextEdit.cpp
r76753 r77078 193 193 , m_bWrapLines(true) 194 194 , m_bHasContextMenu(false) 195 , m_fShowSearchResultOverlay(0) 196 , m_iMatchCount(0) 195 197 { 196 198 setMouseTracking(true); 197 199 //setStyleSheet("background-color: rgba(240, 240, 240, 75%) "); 198 200 prepare(); 199 200 201 201 } 202 202 … … 212 212 213 213 connect(this, &UIVMLogViewerTextEdit::blockCountChanged, this, &UIVMLogViewerTextEdit::sltUpdateLineNumberAreaWidth); 214 connect(this, &UIVMLogViewerTextEdit::updateRequest, this, &UIVMLogViewerTextEdit::slt UpdateLineNumberArea);214 connect(this, &UIVMLogViewerTextEdit::updateRequest, this, &UIVMLogViewerTextEdit::sltHandleUpdateRequest); 215 215 sltUpdateLineNumberAreaWidth(0); 216 216 … … 232 232 if (m_pLineNumberArea) 233 233 m_pLineNumberArea->setFont(font); 234 } 235 236 void UIVMLogViewerTextEdit::setSearchResultOverlayShowHide(bool fShow) 237 { 238 if (m_fShowSearchResultOverlay == fShow) 239 return; 240 m_fShowSearchResultOverlay = fShow; 241 if (viewport()) 242 viewport()->repaint(); 243 } 244 245 void UIVMLogViewerTextEdit::setSearchMatchCount(int iMatchCount) 246 { 247 if (m_iMatchCount == iMatchCount) 248 return; 249 m_iMatchCount = iMatchCount; 250 if (m_fShowSearchResultOverlay && viewport()) 251 viewport()->repaint(); 234 252 } 235 253 … … 400 418 } 401 419 420 void UIVMLogViewerTextEdit::paintEvent(QPaintEvent *pEvent) 421 { 422 QIWithRetranslateUI<QPlainTextEdit>::paintEvent(pEvent); 423 424 /** Draw an overlay with text in it to show the number of search matches: */ 425 if (viewport() && m_fShowSearchResultOverlay) 426 { 427 QPainter painter(viewport()); 428 QColor rectColor = viewport()->palette().color(QPalette::Active, QPalette::Dark); 429 double fontScale = 1.5; 430 rectColor.setAlpha(200); 431 432 QString strText = QString("%1 %2").arg(QString::number(m_iMatchCount)).arg(UIVMLogViewerWidget::tr("Matches Found")); 433 /** Space between the text and rectangle border. */ 434 QSize textMargin(5, 5); 435 /** Space between the rectangle and viewport edges. */ 436 QSize rectMargin(2, 2); 437 438 QSize rectSize(fontScale * QApplication::fontMetrics().width(strText) + textMargin.width(), 439 fontScale * QApplication::fontMetrics().height() + textMargin.height()); 440 QPoint topLeft(viewport()->rect().width() - rectSize.width() - rectMargin.width(), 441 viewport()->rect().height() - rectSize.height() - rectMargin.height()); 442 painter.fillRect(topLeft.x(),topLeft.y(), rectSize.width(), rectSize.height(), rectColor); 443 444 445 QFont pfont = QApplication::font(); 446 QColor fontColor(QPalette::WindowText); 447 painter.setPen(fontColor); 448 if (pfont.pixelSize() != -1) 449 pfont.setPixelSize(fontScale * pfont.pixelSize()); 450 else 451 pfont.setPointSize(fontScale * pfont.pointSize()); 452 painter.setFont(pfont); 453 454 painter.drawText(QRect(topLeft, rectSize), Qt::AlignCenter | Qt::AlignVCenter, strText); 455 } 456 } 457 402 458 void UIVMLogViewerTextEdit::sltUpdateLineNumberAreaWidth(int /* newBlockCount */) 403 459 { … … 405 461 } 406 462 407 void UIVMLogViewerTextEdit::slt UpdateLineNumberArea(const QRect &rect, int dy)463 void UIVMLogViewerTextEdit::sltHandleUpdateRequest(const QRect &rect, int dy) 408 464 { 409 465 if (dy) … … 414 470 if (rect.contains(viewport()->rect())) 415 471 sltUpdateLineNumberAreaWidth(0); 472 473 if (viewport()) 474 viewport()->repaint(); 475 416 476 } 417 477 -
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerTextEdit.h
r76581 r77078 67 67 int currentVerticalScrollBarValue() const; 68 68 void setCurrentVerticalScrollBarValue(int value); 69 void setCurrentFont(QFont font); 69 70 70 void setCurrentFont(QFont font); 71 void setSearchResultOverlayShowHide(bool fShow); 72 void setSearchMatchCount(int iMatchCount); 71 73 72 74 protected: … … 76 78 virtual void mouseMoveEvent(QMouseEvent *pEvent) /* override */; 77 79 virtual void leaveEvent(QEvent * pEvent) /* override */; 80 virtual void paintEvent(QPaintEvent *pEvent) /* override */; 78 81 virtual void retranslateUi() /* override */; 79 82 … … 82 85 void sltBookmark(); 83 86 void sltUpdateLineNumberAreaWidth(int newBlockCount); 84 void slt UpdateLineNumberArea(const QRect &, int);87 void sltHandleUpdateRequest(const QRect &, int); 85 88 int visibleLineCount(); 86 89 … … 107 110 the user the text edit's content is filtered (as oppesed to whole log file content. 108 111 And we dont display bookmarks and adding/deleting bookmarks are disabled. */ 109 bool 110 bool 111 bool 112 QString 112 bool m_bShownTextIsFiltered; 113 bool m_bShowLineNumbers; 114 bool m_bWrapLines; 115 QString m_strBackgroungText; 113 116 friend class UILineNumberArea; 114 bool m_bHasContextMenu; 117 bool m_bHasContextMenu; 118 bool m_fShowSearchResultOverlay; 119 int m_iMatchCount; 115 120 }; 116 121 -
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.cpp
r76977 r77078 301 301 void UIVMLogViewerWidget::sltSearchResultHighLigting() 302 302 { 303 if (!m_pSearchPanel) 304 return; 305 306 if (!currentLogPage()) 307 return; 308 currentLogPage()->setScrollBarMarkingsVector(m_pSearchPanel->getMatchLocationVector()); 303 if (!m_pSearchPanel || !currentLogPage()) 304 return; 305 currentLogPage()->setScrollBarMarkingsVector(m_pSearchPanel->matchLocationVector()); 306 } 307 308 void UIVMLogViewerWidget::sltHandleSearchUpdated() 309 { 310 if (!m_pSearchPanel || !currentLogPage()) 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->marchCount()); 309 315 } 310 316 … … 313 319 Q_UNUSED(tabIndex); 314 320 315 resetHighlighthing(); 316 if (m_pSearchPanel) 317 m_pSearchPanel->reset(); 321 /* Dont refresh the search here as it is refreshed by the filtering mechanism 322 which is updated as tab current index changes: */ 318 323 319 324 /* We keep a separate QVector<LogBookmark> for each log page: */ … … 493 498 connect(m_pSearchPanel, &UIVMLogViewerSearchPanel::sigHighlightingUpdated, 494 499 this, &UIVMLogViewerWidget::sltSearchResultHighLigting); 500 connect(m_pSearchPanel, &UIVMLogViewerSearchPanel::sigSearchUpdated, 501 this, &UIVMLogViewerWidget::sltHandleSearchUpdated); 495 502 connect(m_pSearchPanel, &UIVMLogViewerSearchPanel::sigHidePanel, 496 503 this, &UIVMLogViewerWidget::sltHandleHidePanel); … … 760 767 pLogPage->markForError(); 761 768 } 769 pLogPage->setSearchResultOverlayShowHide(m_pSearchPanel->isVisible()); 770 pLogPage->setSearchMatchCount(m_pSearchPanel->marchCount()); 771 pLogPage->setScrollBarMarkingsVector(m_pSearchPanel->matchLocationVector()); 762 772 } 763 773 } … … 862 872 m_visiblePanelsList.removeOne(panel); 863 873 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 } 864 881 } 865 882 … … 876 893 m_visiblePanelsList.push_back(panel); 877 894 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 } 878 903 } 879 904 -
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.h
r76977 r77078 114 114 /** Handles the search result highlight changes. */ 115 115 void sltSearchResultHighLigting(); 116 void sltHandleSearchUpdated(); 116 117 /** Handles the tab change of the logviewer. */ 117 118 void sltTabIndexChange(int tabIndex);
Note:
See TracChangeset
for help on using the changeset viewer.