Changeset 103478 in vbox
- Timestamp:
- Feb 20, 2024 3:01:26 PM (13 months ago)
- svn:sync-xref-src-repo-rev:
- 161814
- 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 325 325 { 326 326 if (m_pTextEdit) 327 m_pTextEdit->scrollTo End();327 m_pTextEdit->scrollToBottom(); 328 328 } 329 329 -
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerTextEdit.cpp
r101561 r103478 33 33 #include <QPainter> 34 34 #include <QPlainTextEdit> 35 #include <QLabel> 35 36 #include <QScrollBar> 36 37 #include <QStyle> … … 41 42 #include "UIVMLogViewerTextEdit.h" 42 43 #include "UIVMLogViewerWidget.h" 44 45 /* Other VBox includes: */ 46 #include "iprt/assert.h" 43 47 44 48 /** We use a modified scrollbar style for our QPlainTextEdits to get the … … 68 72 "height: 0px;}"); 69 73 74 /********************************************************************************************************************************* 75 * UILogScrollLabel definition. * 76 *********************************************************************************************************************************/ 77 78 class UILogScrollLabel : public QLabel 79 { 80 Q_OBJECT; 81 82 public: 83 84 UILogScrollLabel(QWidget *pParent); 85 void setOpacity(float fOpacity); 86 87 protected: 88 89 virtual void paintEvent(QPaintEvent *pEvent) RT_OVERRIDE; 90 91 private: 92 93 float m_fOpacity; 94 }; 95 70 96 71 97 /********************************************************************************************************************************* … … 93 119 QVector<float> m_markingsVector; 94 120 }; 121 122 123 /********************************************************************************************************************************* 124 * UILogScrollLabel definition. * 125 *********************************************************************************************************************************/ 126 127 UILogScrollLabel::UILogScrollLabel(QWidget *pParent) 128 : QLabel(pParent) 129 , m_fOpacity(1.f) 130 { 131 } 132 133 void UILogScrollLabel::setOpacity(float fOpacity) 134 { 135 if (m_fOpacity == fOpacity) 136 return; 137 m_fOpacity = fOpacity; 138 update(); 139 } 140 141 void 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 } 95 149 96 150 … … 204 258 , m_bHasContextMenu(false) 205 259 , m_iVerticalScrollBarValue(0) 260 , m_pScrollToBottomLabel(0) 261 , m_pScrollToTopLabel(0) 206 262 { 207 263 configure(); … … 222 278 setWrapLines(false); 223 279 setReadOnly(true); 280 m_originalCursor = cursor(); 224 281 } 225 282 … … 233 290 { 234 291 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); 235 308 236 309 connect(this, &UIVMLogViewerTextEdit::blockCountChanged, this, &UIVMLogViewerTextEdit::sltUpdateLineNumberAreaWidth); … … 339 412 } 340 413 414 bool 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 341 451 void UIVMLogViewerTextEdit::contextMenuEvent(QContextMenuEvent *pEvent) 342 452 { … … 384 494 m_pLineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height())); 385 495 } 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 } 386 521 } 387 522 … … 452 587 } 453 588 454 void UIVMLogViewerTextEdit::scrollTo End()589 void UIVMLogViewerTextEdit::scrollToBottom() 455 590 { 456 591 moveCursor(QTextCursor::End); 592 ensureCursorVisible(); 593 } 594 595 void UIVMLogViewerTextEdit::scrollToTop() 596 { 597 moveCursor(QTextCursor::Start); 457 598 ensureCursorVisible(); 458 599 } -
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerTextEdit.h
r98844 r103478 32 32 #endif 33 33 34 class UILogScrollLabel; 35 34 36 /* GUI includes: */ 35 37 #include "QIWithRetranslateUI.h" … … 63 65 64 66 void scrollToLine(int lineNumber); 65 void scrollToEnd(); 67 void scrollToBottom(); 68 void scrollToTop(); 66 69 void setBookmarkLineSet(const QSet<int>& lineSet); 67 70 void setShownTextIsFiltered(bool warning); … … 90 93 virtual void leaveEvent(QEvent * pEvent) RT_OVERRIDE; 91 94 virtual void retranslateUi() RT_OVERRIDE; 95 virtual bool eventFilter(QObject *pObject, QEvent *pEvent) RT_OVERRIDE; 92 96 93 97 private slots: … … 127 131 bool m_bHasContextMenu; 128 132 int m_iVerticalScrollBarValue; 133 UILogScrollLabel *m_pScrollToBottomLabel; 134 UILogScrollLabel *m_pScrollToTopLabel; 135 QCursor m_originalCursor; 129 136 }; 130 137
Note:
See TracChangeset
for help on using the changeset viewer.