VirtualBox

Changeset 70242 in vbox


Ignore:
Timestamp:
Dec 20, 2017 1:04:06 PM (7 years ago)
Author:
vboxsync
Message:

FE/Qt bugref:9072 Handling highlighting better in case of log refresh

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  
    5151    , m_pMatchWholeWordCheckBox(0)
    5252    , m_pHighlightAllCheckBox(0)
    53     , m_pWarningSpacer(0), m_pWarningIcon(0), m_pWarningLabel(0)
     53    , m_pWarningSpacer(0), m_pWarningIcon(0), m_pInfoLabel(0)
    5454    , m_iSearchPosition(0)
     55    , m_iMatchCount(-1)
    5556{
    5657    /* Prepare: */
     
    5859}
    5960
     61void UIVMLogViewerSearchPanel::refresh()
     62{
     63    m_iSearchPosition = 0;
     64    search(BackwardSearch, true);
     65}
     66
     67void 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
     77void 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}
    6089
    6190void UIVMLogViewerSearchPanel::find(int iButton)
     
    80109        /* Reset the position to force the search restart from the document's beginnig: */
    81110        m_iSearchPosition = 0;
    82         search(ForwardSearch);
     111        search(BackwardSearch, true);
    83112    }
    84113    /* If search-string is not valid, reset cursor position: */
     
    111140        if (searchString.isEmpty())
    112141            return;
    113         highlightAll(pDocument, constructFindFlags(ForwardSearch), searchString);
     142        highlightAll(pDocument, searchString);
    114143    }
    115144    else
    116145    {
     146        if (m_iMatchCount != 0)
     147            m_iMatchCount = -1;
    117148        pDocument->undo();
    118149    }
     150    configureInfoLabels();
    119151}
    120152
     
    232264        }
    233265
    234 
    235266        /* Create warning-spacer: */
    236267        m_pWarningSpacer = new QSpacerItem(0, 0, QSizePolicy::Fixed, QSizePolicy::Minimum);
     
    255286
    256287        /* Create warning-label: */
    257         m_pWarningLabel = new QLabel;
    258         AssertPtrReturnVoid(m_pWarningLabel);
     288        m_pInfoLabel = new QLabel;
     289        AssertPtrReturnVoid(m_pInfoLabel);
    259290        {
    260291            /* Configure warning-label: */
    261             m_pWarningLabel->hide();
     292            m_pInfoLabel->hide();
    262293            /* Prepare font: */
    263294#ifdef VBOX_DARWIN_USE_NATIVE_CONTROLS
    264             QFont font = m_pWarningLabel->font();
     295            QFont font = m_pInfoLabel->font();
    265296            font.setPointSize(::darwinSmallFontSize());
    266             m_pWarningLabel->setFont(font);
     297            m_pInfoLabel->setFont(font);
    267298#endif /* VBOX_DARWIN_USE_NATIVE_CONTROLS */
    268299            /* Add warning-label to main-layout: */
    269             m_pMainLayout->addWidget(m_pWarningLabel);
     300            m_pMainLayout->addWidget(m_pInfoLabel);
    270301        }
    271302
     
    310341    m_pHighlightAllCheckBox->setToolTip(UIVMLogViewerWidget::tr("All occurence of the search text are highlighted"));
    311342
    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));
    313347}
    314348
     
    417451}
    418452
    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)
     453void UIVMLogViewerSearchPanel::search(SearchDirection direction, bool highlight)
    432454{
    433455   QPlainTextEdit *pTextEdit = m_pViewer->currentLogPage();
     
    445467   QTextCursor startCursor(pDocument);
    446468
    447    /* Construct the find flags for QTextDocument::find function: */
    448    QTextDocument::FindFlags findFlags = constructFindFlags(direction);
    449 
    450469   if (m_pHighlightAllCheckBox->isChecked())
    451        highlightAll(pDocument, findFlags, searchString);
     470   {
     471       if (highlight)
     472           highlightAll(pDocument, searchString);
     473   }
     474   else
     475       m_iMatchCount = -1;
    452476
    453477   QTextCursor resultCursor(pDocument);
     
    455479   if (direction == BackwardSearch)
    456480       startPosition -= searchString.length();
    457    resultCursor = pDocument->find(searchString, startPosition, findFlags);
     481   resultCursor = pDocument->find(searchString, startPosition, constructFindFlags(direction));
    458482
    459483   /* Decide whether to wrap around or to end the search */
     
    464488           (direction == BackwardSearch && startPosition == endCursor.position()))
    465489       {
    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();
    467494           return;
    468495       }
     
    471498       {
    472499           m_iSearchPosition = startCursor.position();
    473            search(ForwardSearch);
     500           search(ForwardSearch, false);
    474501           return;
    475502       }
     
    479506              able to find the string at the end of the document: */
    480507           m_iSearchPosition = endCursor.position() + searchString.length();
    481            search(BackwardSearch);
     508           search(BackwardSearch, false);
    482509           return;
    483510       }
     
    485512   pTextEdit->setTextCursor(resultCursor);
    486513   m_iSearchPosition = resultCursor.position();
    487    toggleWarning(true);
     514   configureInfoLabels();
    488515}
    489516
    490517void UIVMLogViewerSearchPanel::findNext()
    491518{
    492     search(ForwardSearch);
     519    search(ForwardSearch, false);
    493520}
    494521
    495522void UIVMLogViewerSearchPanel::findBack()
    496523{
    497     search(BackwardSearch);
     524    search(BackwardSearch, false);
    498525}
    499526
    500527void UIVMLogViewerSearchPanel::highlightAll(QTextDocument *pDocument,
    501                                             const QTextDocument::FindFlags &findFlags,
    502528                                            const QString &searchString)
    503529{
     530    m_iMatchCount = 0;
    504531    if (!pDocument)
    505532        return;
     
    512539    QTextCursor cursor(pDocument);
    513540    cursor.beginEditBlock();
    514 
    515541    colorFormat.setBackground(Qt::yellow);
    516542
    517543    while (!highlightCursor.isNull() && !highlightCursor.atEnd())
    518544    {
    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));
    520547
    521548        if (!highlightCursor.isNull())
     549        {
    522550            highlightCursor.mergeCharFormat(colorFormat);
     551            ++m_iMatchCount;
     552        }
    523553    }
    524554    cursor.endEditBlock();
    525555}
    526556
    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)
     557void UIVMLogViewerSearchPanel::configureInfoLabels()
     558{
     559    /* If no match has been found, mark the search editor: */
     560    if (m_iMatchCount == 0)
     561    {
    533562        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    }
    535572    else
     573    {
    536574        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();
    541580}
    542581
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerSearchPanel.h

    r70231 r70242  
    4747      * @param  pViewer  Specifies instance of VM Log-Viewer. */
    4848    UIVMLogViewerSearchPanel(QWidget *pParent, UIVMLogViewerWidget *pViewer);
     49    /** Resets the saech position and starts a new search. */
     50    void refresh();
     51    void reset();
     52
     53protected:
     54
     55    virtual void hideEvent(QHideEvent* pEvent) /* override */;
    4956
    5057private slots:
     
    7582    /** Handles Qt show @a pEvent. */
    7683    void showEvent(QShowEvent *pEvent);
    77     /** Handles Qt hide @a pEvent. */
    78     void hideEvent(QHideEvent *pEvent);
     84
    7985
    8086    /** 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);
    8391    /** Forward search routine wrapper. */
    8492    void findNext();
    8593    /** Backward search routine wrapper. */
    8694    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();
    9099    /** Constructs the find flags for QTextDocument::find function. */
    91100    QTextDocument::FindFlags constructFindFlags(SearchDirection eDirection);
     
    111120    /** Holds the instance of warning icon we create. */
    112121    QLabel      *m_pWarningIcon;
    113     /** Holds the instance of warning label we create. */
    114     QLabel      *m_pWarningLabel;
     122    /** Holds the instance of info label we create. */
     123    QLabel      *m_pInfoLabel;
    115124    /** Holds the instance of spacer item we create. */
    116125    QSpacerItem *m_pSpacerItem;
    117126    /** Holds the position where we start the next search. */
    118127    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;
    119133};
    120134
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.cpp

    r70207 r70242  
    165165    m_pViewerContainer->setEnabled(!noLogsToShow);
    166166    m_pViewerContainer->show();
     167    if (m_pSearchPanel && m_pSearchPanel->isVisible())
     168        m_pSearchPanel->refresh();
    167169}
    168170
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette