VirtualBox

Changeset 103478 in vbox


Ignore:
Timestamp:
Feb 20, 2024 3:01:26 PM (13 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
161814
Message:

FE/Qt: bugref:9072. Implementing buttons to navigate to the bottom/top of the log.

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

Legend:

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

    r98844 r103478  
    325325{
    326326    if (m_pTextEdit)
    327         m_pTextEdit->scrollToEnd();
     327        m_pTextEdit->scrollToBottom();
    328328}
    329329
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerTextEdit.cpp

    r101561 r103478  
    3333#include <QPainter>
    3434#include <QPlainTextEdit>
     35#include <QLabel>
    3536#include <QScrollBar>
    3637#include <QStyle>
     
    4142#include "UIVMLogViewerTextEdit.h"
    4243#include "UIVMLogViewerWidget.h"
     44
     45/* Other VBox includes: */
     46#include "iprt/assert.h"
    4347
    4448/** We use a modified scrollbar style for our QPlainTextEdits to get the
     
    6872                                       "height: 0px;}");
    6973
     74/*********************************************************************************************************************************
     75*   UILogScrollLabel definition.                                                                                             *
     76*********************************************************************************************************************************/
     77
     78class UILogScrollLabel : public QLabel
     79{
     80    Q_OBJECT;
     81
     82public:
     83
     84    UILogScrollLabel(QWidget *pParent);
     85    void setOpacity(float fOpacity);
     86
     87protected:
     88
     89    virtual void paintEvent(QPaintEvent *pEvent) RT_OVERRIDE;
     90
     91private:
     92
     93    float m_fOpacity;
     94};
     95
    7096
    7197/*********************************************************************************************************************************
     
    93119    QVector<float> m_markingsVector;
    94120};
     121
     122
     123/*********************************************************************************************************************************
     124*   UILogScrollLabel definition.                                                                                             *
     125*********************************************************************************************************************************/
     126
     127UILogScrollLabel::UILogScrollLabel(QWidget *pParent)
     128    : QLabel(pParent)
     129    , m_fOpacity(1.f)
     130{
     131}
     132
     133void UILogScrollLabel::setOpacity(float fOpacity)
     134{
     135    if (m_fOpacity == fOpacity)
     136        return;
     137    m_fOpacity = fOpacity;
     138    update();
     139}
     140
     141void UILogScrollLabel::paintEvent(QPaintEvent *pEvent)
     142{
     143    Q_UNUSED(pEvent);
     144    QPainter painter(this);
     145    painter.setBrush(Qt::red);
     146    painter.setOpacity(m_fOpacity);
     147    painter.drawPixmap(0, 0, pixmap());
     148}
    95149
    96150
     
    204258    , m_bHasContextMenu(false)
    205259    , m_iVerticalScrollBarValue(0)
     260    , m_pScrollToBottomLabel(0)
     261    , m_pScrollToTopLabel(0)
    206262{
    207263    configure();
     
    222278    setWrapLines(false);
    223279    setReadOnly(true);
     280    m_originalCursor = cursor();
    224281}
    225282
     
    233290{
    234291    m_pLineNumberArea = new UILineNumberArea(this);
     292    AssertReturnVoid(m_pLineNumberArea);
     293
     294    m_pScrollToBottomLabel = new UILogScrollLabel(this);
     295    m_pScrollToTopLabel = new UILogScrollLabel(this);
     296    AssertReturnVoid(m_pScrollToBottomLabel);
     297    AssertReturnVoid(m_pScrollToTopLabel);
     298
     299    m_pScrollToBottomLabel->installEventFilter(this);
     300    m_pScrollToTopLabel->installEventFilter(this);
     301
     302    const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize);
     303    m_pScrollToBottomLabel->setPixmap(UIIconPool::iconSet(":/vm_discard_32px.png").pixmap(iIconMetric, iIconMetric));
     304    m_pScrollToBottomLabel->setOpacity(0.4);
     305
     306    m_pScrollToTopLabel->setPixmap(UIIconPool::iconSet(":/file_manager_go_up_24px.png").pixmap(iIconMetric, iIconMetric));
     307    m_pScrollToTopLabel->setOpacity(0.4);
    235308
    236309    connect(this, &UIVMLogViewerTextEdit::blockCountChanged, this, &UIVMLogViewerTextEdit::sltUpdateLineNumberAreaWidth);
     
    339412}
    340413
     414bool UIVMLogViewerTextEdit::eventFilter(QObject *pObject, QEvent *pEvent)
     415{
     416    if (pObject == m_pScrollToBottomLabel || pObject == m_pScrollToTopLabel)
     417    {
     418        UILogScrollLabel *pLabel = qobject_cast<UILogScrollLabel*>(pObject);
     419        if (pLabel)
     420        {
     421            switch(pEvent->type())
     422            {
     423                case (QEvent::Enter):
     424                {
     425                    setCursor(Qt::PointingHandCursor);
     426                    pLabel->setOpacity(1.0);
     427                    break;
     428                }
     429                case (QEvent::Leave):
     430                {
     431                    setCursor(m_originalCursor);
     432                    pLabel->setOpacity(0.4);
     433                    break;
     434                }
     435                case (QEvent::MouseButtonPress):
     436                {
     437                    if (pObject == m_pScrollToBottomLabel)
     438                        scrollToBottom();
     439                    else
     440                        scrollToTop();
     441                    break;
     442                }
     443                default:
     444                    break;
     445            }
     446        }
     447    }
     448    return QIWithRetranslateUI<QPlainTextEdit>::eventFilter(pObject, pEvent);
     449}
     450
    341451void UIVMLogViewerTextEdit::contextMenuEvent(QContextMenuEvent *pEvent)
    342452{
     
    384494        m_pLineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height()));
    385495    }
     496
     497   if (m_pScrollToBottomLabel && m_pScrollToTopLabel)
     498   {
     499       QScrollBar *pVScrollBar = verticalScrollBar();
     500       QScrollBar *pHScrollBar = horizontalScrollBar();
     501
     502       int iMarginX = 0;
     503       if (pVScrollBar)
     504           iMarginX = pVScrollBar->width();
     505       if (iMarginX == 0)
     506           iMarginX = m_pScrollToBottomLabel->width();
     507       iMarginX += 2 * QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin);
     508       int iMarginY = 0;
     509       if (pHScrollBar)
     510           iMarginY = pHScrollBar->height();
     511       if (iMarginY == 0)
     512           iMarginY = m_pScrollToTopLabel->height();
     513
     514
     515       m_pScrollToBottomLabel->move(width() - iMarginX - m_pScrollToBottomLabel->width(),
     516                                     0.5 * m_pScrollToBottomLabel->height());
     517
     518       m_pScrollToTopLabel->move(width() - iMarginX - m_pScrollToTopLabel->width(),
     519                                  height() - iMarginY - 1.5 * m_pScrollToTopLabel->height());
     520   }
    386521}
    387522
     
    452587}
    453588
    454 void UIVMLogViewerTextEdit::scrollToEnd()
     589void UIVMLogViewerTextEdit::scrollToBottom()
    455590{
    456591    moveCursor(QTextCursor::End);
     592    ensureCursorVisible();
     593}
     594
     595void UIVMLogViewerTextEdit::scrollToTop()
     596{
     597    moveCursor(QTextCursor::Start);
    457598    ensureCursorVisible();
    458599}
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerTextEdit.h

    r98844 r103478  
    3232#endif
    3333
     34class UILogScrollLabel;
     35
    3436/* GUI includes: */
    3537#include "QIWithRetranslateUI.h"
     
    6365
    6466    void scrollToLine(int lineNumber);
    65     void scrollToEnd();
     67    void scrollToBottom();
     68    void scrollToTop();
    6669    void setBookmarkLineSet(const QSet<int>& lineSet);
    6770    void setShownTextIsFiltered(bool warning);
     
    9093    virtual void leaveEvent(QEvent * pEvent) RT_OVERRIDE;
    9194    virtual void retranslateUi() RT_OVERRIDE;
     95    virtual bool eventFilter(QObject *pObject, QEvent *pEvent) RT_OVERRIDE;
    9296
    9397private slots:
     
    127131    bool         m_bHasContextMenu;
    128132    int          m_iVerticalScrollBarValue;
     133    UILogScrollLabel *m_pScrollToBottomLabel;
     134    UILogScrollLabel *m_pScrollToTopLabel;
     135    QCursor      m_originalCursor;
    129136 };
    130137
Note: See TracChangeset for help on using the changeset viewer.

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