VirtualBox

Changeset 70559 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jan 12, 2018 2:29:48 PM (7 years ago)
Author:
vboxsync
Message:

FE/Qt bugref:9072: Mark bookmarked line in text edit's line number widget

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogPage.cpp

    r70554 r70559  
    183183         return;
    184184    m_bookmarkVector.remove(index, 1);
     185    updateTextEditBookmarkLineSet();
    185186}
    186187
     
    188189{
    189190    m_bookmarkVector.clear();
     191    updateTextEditBookmarkLineSet();
    190192}
    191193
     
    198200
    199201    int lineNumber = m_bookmarkVector.at(bookmarkIndex).first;
    200     QTextDocument* document = m_pTextEdit->document();
    201     if(!document)
    202         return;
    203 
    204     QTextCursor cursor(document->findBlockByLineNumber(lineNumber));
    205     m_pTextEdit->moveCursor(QTextCursor::End);
    206     m_pTextEdit->setTextCursor(cursor);
    207 
     202    m_pTextEdit->scrollToLine(lineNumber);
    208203}
    209204
     
    216211{
    217212    m_bookmarkVector.push_back(bookmark);
     213    updateTextEditBookmarkLineSet();
    218214    emit sigBookmarksUpdated();
    219215}
     216
     217void UIVMLogPage::updateTextEditBookmarkLineSet()
     218{
     219    if(!m_pTextEdit)
     220        return;
     221    QSet<int> bookmarkLinesSet;
     222    for(int i = 0; i < m_bookmarkVector.size(); ++i)
     223    {
     224        bookmarkLinesSet.insert(m_bookmarkVector.at(i).first);
     225    }
     226    m_pTextEdit->setBookmarkLineSet(bookmarkLinesSet);
     227}
     228
    220229// void UIVMLogViewerWidget::sltCreateBookmarkAtCurrent()
    221230// {
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogPage.h

    r70554 r70559  
    9999    void cleanup();
    100100    void retranslateUi();
     101    void updateTextEditBookmarkLineSet();
    101102
    102103    QHBoxLayout    *m_pMainLayout;
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerTextEdit.cpp

    r70556 r70559  
    201201        if (block.isVisible() && bottom >= event->rect().top()) {
    202202            QString number = QString::number(blockNumber + 1);
     203            if (m_bookmarkLineSet.contains(blockNumber + 1))
     204            {
     205                painter.setBackgroundMode(Qt::OpaqueMode);
     206                painter.setBackground(QBrush(Qt::red));
     207            }
     208            else
     209            {
     210                painter.setBackgroundMode(Qt::TransparentMode);
     211            }
    203212            painter.setPen(Qt::black);
    204213            painter.drawText(0, top, m_pLineNumberArea->width(), m_pLineNumberArea->fontMetrics().lineSpacing(),
     
    275284}
    276285
     286void UIVMLogViewerTextEdit::scrollToLine(int lineNumber)
     287{
     288    QTextDocument* pDocument = document();
     289    if(!pDocument)
     290        return;
     291
     292    int halfPageLineCount = 0.5 * visibleLineCount() ;
     293    QTextCursor cursor(pDocument->findBlockByLineNumber(qMax(lineNumber - halfPageLineCount, 0)));
     294    moveCursor(QTextCursor::End);
     295    setTextCursor(cursor);
     296}
     297
     298int UIVMLogViewerTextEdit::visibleLineCount()
     299{
     300    int height = 0;
     301    if(viewport())
     302        height = viewport()->height();
     303    if(verticalScrollBar() && verticalScrollBar()->isVisible())
     304        height -= horizontalScrollBar()->height();
     305    int singleLineHeight = fontMetrics().lineSpacing();
     306    if(singleLineHeight == 0)
     307        return 0;
     308    return height / singleLineHeight;
     309}
     310
     311void UIVMLogViewerTextEdit::setBookmarkLineSet(const QSet<int>& lineSet)
     312{
     313    m_bookmarkLineSet = lineSet;
     314    repaint();
     315}
    277316
    278317#include "UIVMLogViewerTextEdit.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerTextEdit.h

    r70554 r70559  
    4444    void clearScrollBarMarkingsVector();
    4545
     46    void scrollToLine(int lineNumber);
     47
     48    void setBookmarkLineSet(const QSet<int>& lineSet);
     49
    4650protected:
    4751
     
    5458    void sltUpdateLineNumberAreaWidth(int newBlockCount);
    5559    void sltUpdateLineNumberArea(const QRect &, int);
     60    int  visibleLineCount();
    5661
    5762private:
     
    6368    QPair<int, QString>  m_iContextMenuBookmark;
    6469    QWidget             *m_pLineNumberArea;
     70    QSet<int>            m_bookmarkLineSet;
    6571};
    6672
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.cpp

    r70549 r70559  
    132132    if(!currentLogPage() || !m_pBookmarksPanel)
    133133        return;
     134    disconnect(m_pBookmarksPanel, &UIVMLogViewerBookmarksPanel::sigBookmarkSelected,
     135            this, &UIVMLogViewerWidget::gotoBookmark);
    134136    m_pBookmarksPanel->updateBookmarkList(currentLogPage()->bookmarkVector());
     137    connect(m_pBookmarksPanel, &UIVMLogViewerBookmarksPanel::sigBookmarkSelected,
     138            this, &UIVMLogViewerWidget::gotoBookmark);
    135139}
    136140
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