VirtualBox

Ignore:
Timestamp:
Dec 21, 2017 12:35:24 PM (7 years ago)
Author:
vboxsync
Message:

FE/Qt bugref:9072 Mark logviewer scrollbar when all the maches are highligthed

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r69933 r70272  
    545545        src/globals/UIMainEventListener.cpp \
    546546        src/globals/UIThreadPool.cpp \
     547        src/logviewer/UIVMLogViewerWidget.cpp \
    547548        src/medium/UIMediumEnumerator.cpp \
    548549        src/runtime/UIActionPoolRuntime.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerSearchPanel.cpp

    r70242 r70272  
    2121
    2222/* Qt includes: */
     23# include <QAction>
    2324# include <QCheckBox>
    2425# include <QComboBox>
     
    2930# include <QLabel>
    3031# include <QPlainTextEdit>
     32# include <QTextBlock>
    3133
    3234/* GUI includes: */
     
    7577}
    7678
     79const QVector<float> &UIVMLogViewerSearchPanel::getMatchLocationVector() const
     80{
     81    return m_matchLocationVector;
     82}
     83
    7784void UIVMLogViewerSearchPanel::hideEvent(QHideEvent *pEvent)
    7885{
     
    146153        if (m_iMatchCount != 0)
    147154            m_iMatchCount = -1;
     155
     156        m_matchLocationVector.clear();
    148157        pDocument->undo();
    149158    }
    150159    configureInfoLabels();
     160    emit sigHighlightingUpdated();
    151161}
    152162
     
    473483   }
    474484   else
     485   {
    475486       m_iMatchCount = -1;
     487       m_matchLocationVector.clear();
     488   }
    476489
    477490   QTextCursor resultCursor(pDocument);
     
    513526   m_iSearchPosition = resultCursor.position();
    514527   configureInfoLabels();
     528   emit sigHighlightingUpdated();
    515529}
    516530
     
    529543{
    530544    m_iMatchCount = 0;
     545    m_matchLocationVector.clear();
    531546    if (!pDocument)
    532547        return;
     
    540555    cursor.beginEditBlock();
    541556    colorFormat.setBackground(Qt::yellow);
    542 
     557    int lineCount = pDocument->lineCount();
    543558    while (!highlightCursor.isNull() && !highlightCursor.atEnd())
    544559    {
    545560        /* Hightlighting searches is always from the top of the document forward: */
    546561        highlightCursor = pDocument->find(searchString, highlightCursor, constructFindFlags(ForwardSearch));
    547 
    548562        if (!highlightCursor.isNull())
    549563        {
    550564            highlightCursor.mergeCharFormat(colorFormat);
    551565            ++m_iMatchCount;
     566            /* The following assumes we have single line blocks only: */
     567            int cursorLine = pDocument->findBlock(highlightCursor.position()).firstLineNumber();
     568            if (lineCount != 0)
     569                m_matchLocationVector.push_back(cursorLine / static_cast<float>(lineCount));
    552570        }
    553571    }
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerSearchPanel.h

    r70242 r70272  
    4242    Q_OBJECT;
    4343
     44signals:
     45    void sigHighlightingUpdated();
     46
    4447public:
    4548
     
    5053    void refresh();
    5154    void reset();
     55    const QVector<float> &getMatchLocationVector() const;
    5256
    5357protected:
     
    6367      * @param  strSearchString  Specifies search-string. */
    6468    void findCurrent(const QString &strSearchString);
     69    void sltHighlightAllCheckBox();
    6570
    66     void sltHighlightAllCheckBox();
    6771private:
    6872    enum SearchDirection { ForwardSearch, BackwardSearch };
     
    131135      n > 0: n matches found. */
    132136    int          m_iMatchCount;
     137    /** Stores relative positions of the lines of the matches. The values are [0,1] 0 being the first line 1 being the last. */
     138    QVector<float> m_matchLocationVector;
    133139};
    134140
    135141
    136142#endif /* !___UIVMLogViewerSearchPanel_h___ */
     143
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.cpp

    r70242 r70272  
    2727#  include <QFontDatabase>
    2828# endif
     29# include <QPainter>
    2930# include <QPlainTextEdit>
    3031# include <QScrollBar>
     
    4849#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    4950
     51/** We use a modified scrollbar style for our QPlainTextEdits to get the
     52    markings on the scrollbars correctly. The default scrollbarstyle does not
     53    reveal the height of the pushbuttons on the scrollbar to compute the marking
     54    locations correctlt. so we turn them off: */
     55const QString verticalScrollBarStyle("QScrollBar:vertical {"
     56                                     "border: 1px ridge grey; "
     57                                     "margin: 0px 0px 0 0px;}"
     58                                     "QScrollBar::handle:vertical {"
     59                                     "min-height: 10px;"
     60                                     "background: grey;}"
     61                                     "QScrollBar::add-line:vertical {"
     62                                     "width: 0px;}"
     63                                     "QScrollBar::sub-line:vertical {"
     64                                     "width: 0px;}");
     65
     66const QString horizontalScrollBarStyle("QScrollBar:horizontal {"
     67                                       "border: 1px ridge grey; "
     68                                       "margin: 0px 0px 0 0px;}"
     69                                       "QScrollBar::handle:horizontal {"
     70                                       "min-height: 10px;"
     71                                       "background: grey;}"
     72                                       "QScrollBar::add-line:horizontal {"
     73                                       "height: 0px;}"
     74                                       "QScrollBar::sub-line:horizontal {"
     75                                       "height: 0px;}");
     76
     77class UIIndicatorScrollBar : public QScrollBar
     78{
     79    Q_OBJECT;
     80
     81public:
     82
     83    UIIndicatorScrollBar(QWidget *parent = 0)
     84        :QScrollBar(parent)
     85    {
     86        setStyleSheet(verticalScrollBarStyle);
     87    }
     88
     89    void setMarkingsVector(const QVector<float> &vector)
     90    {
     91        m_markingsVector = vector;
     92    }
     93
     94protected:
     95
     96    virtual void paintEvent(QPaintEvent *pEvent) /* override */
     97    {
     98        QScrollBar::paintEvent(pEvent);
     99        /* Put a red line to marking position: */
     100        for (int i = 0; i < m_markingsVector.size(); ++i)
     101        {
     102            QPointF p1 = QPointF(0, m_markingsVector[i] * height());
     103            QPointF p2 = QPointF(width(), m_markingsVector[i] * height());
     104
     105            QPainter painter(this);
     106            painter.setRenderHint(QPainter::Antialiasing, true);
     107            painter.setPen(QPen(QColor(255, 0, 0, 255), 1.2f));
     108            painter.drawLine(p1, p2);
     109        }
     110    }
     111
     112private:
     113    /* Stores the relative (to scrollbar's height) positions of markings,
     114       where we draw a horizontal line. */
     115    QVector<float> m_markingsVector;
     116};
    50117UIVMLogViewerWidget::UIVMLogViewerWidget(EmbedTo enmEmbedding, QWidget *pParent /* = 0 */, const CMachine &machine /* = CMachine() */)
    51118    : QIWithRetranslateUI<QWidget>(pParent)
     
    205272}
    206273
     274void UIVMLogViewerWidget::sltSearchResultHighLigting()
     275{
     276    if (!m_pSearchPanel)
     277        return;
     278
     279    if (!currentLogPage())
     280        return;
     281    UIIndicatorScrollBar* scrollBar = qobject_cast<UIIndicatorScrollBar*>(currentLogPage()->verticalScrollBar());
     282    if (scrollBar)
     283        scrollBar->setMarkingsVector(m_pSearchPanel->getMatchLocationVector());
     284
     285    m_markingsVector = m_pSearchPanel->getMatchLocationVector();
     286    currentLogPage()->repaint();
     287}
     288
    207289void UIVMLogViewerWidget::setMachine(const CMachine &machine)
    208290{
     
    260342        /* Add VM Log-Viewer search-panel to main-layout: */
    261343        m_pMainLayout->insertWidget(2, m_pSearchPanel);
     344        connect(m_pSearchPanel, &UIVMLogViewerSearchPanel::sigHighlightingUpdated,
     345                this, &UIVMLogViewerWidget::sltSearchResultHighLigting);
    262346    }
    263347
     
    579663        {
    580664            /* Configure Log-Viewer: */
     665            pLogViewer->setVerticalScrollBar(new UIIndicatorScrollBar());
     666            pLogViewer->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
     667            QScrollBar *pHorizontalScrollBar = pLogViewer->horizontalScrollBar();
     668            if (pHorizontalScrollBar)
     669            {
     670                pHorizontalScrollBar->setStyleSheet(horizontalScrollBarStyle);
     671            }
    581672#if defined(RT_OS_SOLARIS)
    582673            /* Use system fixed-width font on Solaris hosts as the Courier family fonts don't render well. */
     
    588679            pLogViewer->setFont(font);
    589680            pLogViewer->setWordWrapMode(QTextOption::NoWrap);
    590             pLogViewer->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    591681            pLogViewer->setReadOnly(true);
    592682            /* Add Log-Viewer to page-layout: */
     
    603693    return m_logMap[currentLogPage()];
    604694}
     695
     696#include "UIVMLogViewerWidget.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.h

    r70185 r70272  
    7373protected:
    7474
    75 
    7675    /** Returns whether the window should be maximized when geometry being restored. */
    7776    virtual bool shouldBeMaximized() const /* override */;
     
    8786    /** Handles filter action triggering. */
    8887    void sltFilter();
     88
     89    /** Handles the search result highlight changes. */
     90    void sltSearchResultHighLigting();
    8991
    9092private:
     
    168170    /** @} */
    169171
     172    QVector<float> m_markingsVector;
     173
    170174    friend class UIVMLogViewerSearchPanel;
    171175    friend class UIVMLogViewerFilterPanel;
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