Changeset 70242 in vbox
- Timestamp:
- Dec 20, 2017 1:04:06 PM (7 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/logviewer
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerSearchPanel.cpp
r70231 r70242 51 51 , m_pMatchWholeWordCheckBox(0) 52 52 , m_pHighlightAllCheckBox(0) 53 , m_pWarningSpacer(0), m_pWarningIcon(0), m_p WarningLabel(0)53 , m_pWarningSpacer(0), m_pWarningIcon(0), m_pInfoLabel(0) 54 54 , m_iSearchPosition(0) 55 , m_iMatchCount(-1) 55 56 { 56 57 /* Prepare: */ … … 58 59 } 59 60 61 void UIVMLogViewerSearchPanel::refresh() 62 { 63 m_iSearchPosition = 0; 64 search(BackwardSearch, true); 65 } 66 67 void UIVMLogViewerSearchPanel::reset() 68 { 69 m_iSearchPosition = 0; 70 if (m_pHighlightAllCheckBox) 71 { 72 if (m_pHighlightAllCheckBox->checkState() == Qt::Checked) 73 m_pHighlightAllCheckBox->setCheckState(Qt::Unchecked); 74 } 75 } 76 77 void UIVMLogViewerSearchPanel::hideEvent(QHideEvent *pEvent) 78 { 79 /* Get focus-widget: */ 80 QWidget *pFocus = QApplication::focusWidget(); 81 /* If focus-widget is valid and child-widget of search-panel, 82 * focus next child-widget in line: */ 83 if (pFocus && pFocus->parent() == this) 84 focusNextPrevChild(true); 85 /* Call to base-class: */ 86 QWidget::hideEvent(pEvent); 87 reset(); 88 } 60 89 61 90 void UIVMLogViewerSearchPanel::find(int iButton) … … 80 109 /* Reset the position to force the search restart from the document's beginnig: */ 81 110 m_iSearchPosition = 0; 82 search( ForwardSearch);111 search(BackwardSearch, true); 83 112 } 84 113 /* If search-string is not valid, reset cursor position: */ … … 111 140 if (searchString.isEmpty()) 112 141 return; 113 highlightAll(pDocument, constructFindFlags(ForwardSearch),searchString);142 highlightAll(pDocument, searchString); 114 143 } 115 144 else 116 145 { 146 if (m_iMatchCount != 0) 147 m_iMatchCount = -1; 117 148 pDocument->undo(); 118 149 } 150 configureInfoLabels(); 119 151 } 120 152 … … 232 264 } 233 265 234 235 266 /* Create warning-spacer: */ 236 267 m_pWarningSpacer = new QSpacerItem(0, 0, QSizePolicy::Fixed, QSizePolicy::Minimum); … … 255 286 256 287 /* Create warning-label: */ 257 m_p WarningLabel = new QLabel;258 AssertPtrReturnVoid(m_p WarningLabel);288 m_pInfoLabel = new QLabel; 289 AssertPtrReturnVoid(m_pInfoLabel); 259 290 { 260 291 /* Configure warning-label: */ 261 m_p WarningLabel->hide();292 m_pInfoLabel->hide(); 262 293 /* Prepare font: */ 263 294 #ifdef VBOX_DARWIN_USE_NATIVE_CONTROLS 264 QFont font = m_p WarningLabel->font();295 QFont font = m_pInfoLabel->font(); 265 296 font.setPointSize(::darwinSmallFontSize()); 266 m_p WarningLabel->setFont(font);297 m_pInfoLabel->setFont(font); 267 298 #endif /* VBOX_DARWIN_USE_NATIVE_CONTROLS */ 268 299 /* Add warning-label to main-layout: */ 269 m_pMainLayout->addWidget(m_p WarningLabel);300 m_pMainLayout->addWidget(m_pInfoLabel); 270 301 } 271 302 … … 310 341 m_pHighlightAllCheckBox->setToolTip(UIVMLogViewerWidget::tr("All occurence of the search text are highlighted")); 311 342 312 m_pWarningLabel->setText(UIVMLogViewerWidget::tr("String not found")); 343 if (m_iMatchCount == 0) 344 m_pInfoLabel->setText(UIVMLogViewerWidget::tr("String not found")); 345 else if (m_iMatchCount > 0) 346 m_pInfoLabel->setText(UIVMLogViewerWidget::tr("%1 Matches Found").arg(m_iMatchCount)); 313 347 } 314 348 … … 417 451 } 418 452 419 void UIVMLogViewerSearchPanel::hideEvent(QHideEvent *pEvent) 420 { 421 /* Get focus-widget: */ 422 QWidget *pFocus = QApplication::focusWidget(); 423 /* If focus-widget is valid and child-widget of search-panel, 424 * focus next child-widget in line: */ 425 if (pFocus && pFocus->parent() == this) 426 focusNextPrevChild(true); 427 /* Call to base-class: */ 428 QWidget::hideEvent(pEvent); 429 } 430 431 void UIVMLogViewerSearchPanel::search(SearchDirection direction) 453 void UIVMLogViewerSearchPanel::search(SearchDirection direction, bool highlight) 432 454 { 433 455 QPlainTextEdit *pTextEdit = m_pViewer->currentLogPage(); … … 445 467 QTextCursor startCursor(pDocument); 446 468 447 /* Construct the find flags for QTextDocument::find function: */448 QTextDocument::FindFlags findFlags = constructFindFlags(direction);449 450 469 if (m_pHighlightAllCheckBox->isChecked()) 451 highlightAll(pDocument, findFlags, searchString); 470 { 471 if (highlight) 472 highlightAll(pDocument, searchString); 473 } 474 else 475 m_iMatchCount = -1; 452 476 453 477 QTextCursor resultCursor(pDocument); … … 455 479 if (direction == BackwardSearch) 456 480 startPosition -= searchString.length(); 457 resultCursor = pDocument->find(searchString, startPosition, findFlags);481 resultCursor = pDocument->find(searchString, startPosition, constructFindFlags(direction)); 458 482 459 483 /* Decide whether to wrap around or to end the search */ … … 464 488 (direction == BackwardSearch && startPosition == endCursor.position())) 465 489 { 466 toggleWarning(false); 490 /* Set the match count 0 here since we did not call highLightAll function: */ 491 if (!m_pHighlightAllCheckBox->isChecked()) 492 m_iMatchCount = 0; 493 configureInfoLabels(); 467 494 return; 468 495 } … … 471 498 { 472 499 m_iSearchPosition = startCursor.position(); 473 search(ForwardSearch );500 search(ForwardSearch, false); 474 501 return; 475 502 } … … 479 506 able to find the string at the end of the document: */ 480 507 m_iSearchPosition = endCursor.position() + searchString.length(); 481 search(BackwardSearch );508 search(BackwardSearch, false); 482 509 return; 483 510 } … … 485 512 pTextEdit->setTextCursor(resultCursor); 486 513 m_iSearchPosition = resultCursor.position(); 487 toggleWarning(true);514 configureInfoLabels(); 488 515 } 489 516 490 517 void UIVMLogViewerSearchPanel::findNext() 491 518 { 492 search(ForwardSearch );519 search(ForwardSearch, false); 493 520 } 494 521 495 522 void UIVMLogViewerSearchPanel::findBack() 496 523 { 497 search(BackwardSearch );524 search(BackwardSearch, false); 498 525 } 499 526 500 527 void UIVMLogViewerSearchPanel::highlightAll(QTextDocument *pDocument, 501 const QTextDocument::FindFlags &findFlags,502 528 const QString &searchString) 503 529 { 530 m_iMatchCount = 0; 504 531 if (!pDocument) 505 532 return; … … 512 539 QTextCursor cursor(pDocument); 513 540 cursor.beginEditBlock(); 514 515 541 colorFormat.setBackground(Qt::yellow); 516 542 517 543 while (!highlightCursor.isNull() && !highlightCursor.atEnd()) 518 544 { 519 highlightCursor = pDocument->find(searchString, highlightCursor, findFlags); 545 /* Hightlighting searches is always from the top of the document forward: */ 546 highlightCursor = pDocument->find(searchString, highlightCursor, constructFindFlags(ForwardSearch)); 520 547 521 548 if (!highlightCursor.isNull()) 549 { 522 550 highlightCursor.mergeCharFormat(colorFormat); 551 ++m_iMatchCount; 552 } 523 553 } 524 554 cursor.endEditBlock(); 525 555 } 526 556 527 void UIVMLogViewerSearchPanel::toggleWarning(bool fHide) 528 { 529 /* Adjust size of warning-spacer accordingly: */ 530 m_pWarningSpacer->changeSize(fHide ? 0 : 16, 0, QSizePolicy::Fixed, QSizePolicy::Minimum); 531 /* If visible mark the error for search-editor (changes text-color): */ 532 if (!fHide) 557 void UIVMLogViewerSearchPanel::configureInfoLabels() 558 { 559 /* If no match has been found, mark the search editor: */ 560 if (m_iMatchCount == 0) 561 { 533 562 m_pSearchEditor->markError(); 534 /* If hidden unmark the error for search-editor (changes text-color): */ 563 m_pWarningIcon->setVisible(true); 564 m_pInfoLabel->setVisible(true); 565 } 566 else if (m_iMatchCount == -1) 567 { 568 m_pSearchEditor->unmarkError(); 569 m_pWarningIcon->setVisible(false); 570 m_pInfoLabel->setVisible(false); 571 } 535 572 else 573 { 536 574 m_pSearchEditor->unmarkError(); 537 /* Show/hide the warning-icon: */ 538 m_pWarningIcon->setHidden(fHide); 539 /* Show/hide the warning-label: */ 540 m_pWarningLabel->setHidden(fHide); 575 m_pWarningIcon->setVisible(false); 576 m_pInfoLabel->setVisible(true); 577 } 578 /* Retranslate to get the label text corectly: */ 579 retranslateUi(); 541 580 } 542 581 -
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerSearchPanel.h
r70231 r70242 47 47 * @param pViewer Specifies instance of VM Log-Viewer. */ 48 48 UIVMLogViewerSearchPanel(QWidget *pParent, UIVMLogViewerWidget *pViewer); 49 /** Resets the saech position and starts a new search. */ 50 void refresh(); 51 void reset(); 52 53 protected: 54 55 virtual void hideEvent(QHideEvent* pEvent) /* override */; 49 56 50 57 private slots: … … 75 82 /** Handles Qt show @a pEvent. */ 76 83 void showEvent(QShowEvent *pEvent); 77 /** Handles Qt hide @a pEvent. */ 78 void hideEvent(QHideEvent *pEvent); 84 79 85 80 86 /** Search routine. 81 * @param eDirection Specifies the seach direction */ 82 void search(SearchDirection eDirection); 87 * @param eDirection Specifies the seach direction 88 * @param highlight if false highlight function is not called 89 thus we avoid calling highlighting for the same string repeatedly. */ 90 void search(SearchDirection eDirection, bool highlight); 83 91 /** Forward search routine wrapper. */ 84 92 void findNext(); 85 93 /** Backward search routine wrapper. */ 86 94 void findBack(); 87 void highlightAll(QTextDocument *pDocument, const QTextDocument::FindFlags &findFlags, const QString &searchString); 88 /** Shows/hides the search border warning using @a fHide as hint. */ 89 void toggleWarning(bool fHide); 95 void highlightAll(QTextDocument *pDocument, const QString &searchString); 96 /** Controls the visibility of the warning icon and info labels. 97 Also marks the search editor in case of no match.*/ 98 void configureInfoLabels(); 90 99 /** Constructs the find flags for QTextDocument::find function. */ 91 100 QTextDocument::FindFlags constructFindFlags(SearchDirection eDirection); … … 111 120 /** Holds the instance of warning icon we create. */ 112 121 QLabel *m_pWarningIcon; 113 /** Holds the instance of warninglabel we create. */114 QLabel *m_p WarningLabel;122 /** Holds the instance of info label we create. */ 123 QLabel *m_pInfoLabel; 115 124 /** Holds the instance of spacer item we create. */ 116 125 QSpacerItem *m_pSpacerItem; 117 126 /** Holds the position where we start the next search. */ 118 127 int m_iSearchPosition; 128 /** Holds the number of the matches for the string. 129 -1: highLightAll function is not called 130 0: no matches found 131 n > 0: n matches found. */ 132 int m_iMatchCount; 119 133 }; 120 134 -
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.cpp
r70207 r70242 165 165 m_pViewerContainer->setEnabled(!noLogsToShow); 166 166 m_pViewerContainer->show(); 167 if (m_pSearchPanel && m_pSearchPanel->isVisible()) 168 m_pSearchPanel->refresh(); 167 169 } 168 170
Note:
See TracChangeset
for help on using the changeset viewer.