VirtualBox

Changeset 99607 in vbox


Ignore:
Timestamp:
May 4, 2023 2:18:46 PM (17 months ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6832: Snapshot pane: Make sure snapshot-item name is visible on GUI startup or reload triggered while current VM being switched; We had to implement some private functionality cause out-of-the-box Qt was not capable of required thing.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/snapshots
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/snapshots/UISnapshotPane.cpp

    r99602 r99607  
    178178
    179179
     180/** QScrollBar subclass for snapshots widget. */
     181class UISnapshotScrollBar : public QScrollBar
     182{
     183    Q_OBJECT;
     184
     185signals:
     186
     187    /** Notify listeners about our visibility changed. */
     188    void sigNotifyAboutVisibilityChange();
     189
     190public:
     191
     192    /** Constructs scroll-bar passing @a enmOrientation and @a pParent to the base-class. */
     193    UISnapshotScrollBar(Qt::Orientation enmOrientation, QWidget *pParent = 0);
     194
     195protected:
     196
     197    /** Handles show @a pEvent. */
     198    virtual void showEvent(QShowEvent *pEvent) RT_OVERRIDE;
     199};
     200
     201
    180202/** QITreeWidget subclass for snapshots items. */
    181203class UISnapshotTree : public QITreeWidget
    182204{
    183205    Q_OBJECT;
     206
     207signals:
     208
     209    /** Notify listeners about one of scroll-bars visibility changed. */
     210    void sigNotifyAboutScrollBarVisibilityChange();
    184211
    185212public:
     
    505532
    506533/*********************************************************************************************************************************
     534*   Class UISnapshotScrollBar implementation.                                                                                    *
     535*********************************************************************************************************************************/
     536UISnapshotScrollBar::UISnapshotScrollBar(Qt::Orientation enmOrientation, QWidget *pParent /* = 0 */)
     537    : QScrollBar(enmOrientation, pParent)
     538{
     539}
     540
     541void UISnapshotScrollBar::showEvent(QShowEvent *pEvent)
     542{
     543    QScrollBar::showEvent(pEvent);
     544    emit sigNotifyAboutVisibilityChange();
     545}
     546
     547
     548/*********************************************************************************************************************************
    507549*   Class UISnapshotTree implementation.                                                                                         *
    508550*********************************************************************************************************************************/
     
    520562    setEditTriggers(  QAbstractItemView::SelectedClicked
    521563                    | QAbstractItemView::EditKeyPressed);
     564
     565    /* Replace scroll-bars: */
     566    UISnapshotScrollBar *pScrollBarH = new UISnapshotScrollBar(Qt::Horizontal, this);
     567    if (pScrollBarH)
     568    {
     569        connect(pScrollBarH, &UISnapshotScrollBar::sigNotifyAboutVisibilityChange,
     570                this, &UISnapshotTree::sigNotifyAboutScrollBarVisibilityChange);
     571        setHorizontalScrollBar(pScrollBarH);
     572    }
     573    UISnapshotScrollBar *pScrollBarV = new UISnapshotScrollBar(Qt::Vertical, this);
     574    if (pScrollBarV)
     575    {
     576        connect(pScrollBarV, &UISnapshotScrollBar::sigNotifyAboutVisibilityChange,
     577                this, &UISnapshotTree::sigNotifyAboutScrollBarVisibilityChange);
     578        setVerticalScrollBar(pScrollBarV);
     579    }
    522580}
    523581
     
    10981156
    10991157    /* Make the current item visible: */
    1100     if (pSnapshotItem)
    1101     {
    1102         m_pSnapshotTree->horizontalScrollBar()->setValue(0);
    1103         m_pSnapshotTree->scrollToItem(pSnapshotItem);
    1104         m_pSnapshotTree->horizontalScrollBar()->setValue(m_pSnapshotTree->indentation() * pSnapshotItem->level());
    1105     }
     1158    sltHandleScrollBarVisibilityChange();
    11061159
    11071160    /* Update action states: */
     
    12401293}
    12411294
     1295void UISnapshotPane::sltHandleScrollBarVisibilityChange()
     1296{
     1297    /* Acquire "current snapshot" item: */
     1298    const UISnapshotItem *pSnapshotItem = UISnapshotItem::toSnapshotItem(m_pSnapshotTree->currentItem());
     1299
     1300    /* Make the current item visible: */
     1301    if (pSnapshotItem)
     1302    {
     1303        m_pSnapshotTree->horizontalScrollBar()->setValue(0);
     1304        m_pSnapshotTree->scrollToItem(pSnapshotItem);
     1305        m_pSnapshotTree->horizontalScrollBar()->setValue(m_pSnapshotTree->indentation() * pSnapshotItem->level());
     1306    }
     1307}
     1308
    12421309void UISnapshotPane::prepare()
    12431310{
     
    13781445        connect(m_pSnapshotTree, &UISnapshotTree::itemDoubleClicked,
    13791446                this, &UISnapshotPane::sltHandleItemDoubleClick);
     1447        connect(m_pSnapshotTree, &UISnapshotTree::sigNotifyAboutScrollBarVisibilityChange,
     1448                this, &UISnapshotPane::sltHandleScrollBarVisibilityChange, Qt::QueuedConnection);
    13801449
    13811450        /* Add into layout: */
     
    14611530
    14621531            /* Choose current item: */
    1463             m_pSnapshotTree->scrollToItem(pCurrentItem);
    14641532            m_pSnapshotTree->setCurrentItem(pCurrentItem);
    14651533            sltHandleCurrentItemChange();
  • trunk/src/VBox/Frontends/VirtualBox/src/snapshots/UISnapshotPane.h

    r99218 r99607  
    165165        /** Handles tree-widget @a pItem double-click. */
    166166        void sltHandleItemDoubleClick(QTreeWidgetItem *pItem);
     167        /** Handles tree-widget's scroll-bar visibility change. */
     168        void sltHandleScrollBarVisibilityChange();
    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