VirtualBox

Changeset 63851 in vbox


Ignore:
Timestamp:
Sep 15, 2016 11:00:39 AM (8 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6899: Accessibility support (step 33): Selector UI: UISnapshotPane: Replace QTreeWidget with own UISnapshotTree (required for accessibility override).

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

Legend:

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

    r63804 r63851  
    565565        src/selector/UIVirtualBoxEventHandler.cpp \
    566566        src/selector/UIVMDesktop.cpp \
     567        src/selector/UISnapshotPane.cpp \
    567568        src/settings/machine/UIMachineSettingsStorage.cpp \
    568569        src/settings/machine/UIMachineSettingsUSB.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.cpp

    r63838 r63851  
    148148    /** Holds the cached machine state. */
    149149    KMachineState            m_enmMachineState;
     150};
     151
     152
     153/** QTreeWidget subclass for snapshots items. */
     154class UISnapshotTree : public QTreeWidget
     155{
     156    Q_OBJECT;
     157
     158public:
     159
     160    /** Constructs snapshot tree passing @a pParent to the base-class. */
     161    UISnapshotTree(QWidget *pParent);
    150162};
    151163
     
    455467
    456468/*********************************************************************************************************************************
     469*   Class UISnapshotTree implementation.                                                                                         *
     470*********************************************************************************************************************************/
     471
     472UISnapshotTree::UISnapshotTree(QWidget *pParent)
     473    : QTreeWidget(pParent)
     474{
     475    /* No header: */
     476    header()->hide();
     477    /* All columns as one: */
     478    setAllColumnsShowFocus(true);
     479    /* Our own context menu: */
     480    setContextMenuPolicy(Qt::CustomContextMenu);
     481
     482#if QT_VERSION < 0x050000
     483    // WORKAROUND:
     484    // The snapshots widget is not very useful if there are a lot
     485    // of snapshots in a tree and the current Qt style decides not
     486    // to draw lines (branches) between the snapshot nodes; it is
     487    // then often unclear which snapshot is a child of another.
     488    // So on platforms whose styles do not normally draw branches,
     489    // we use QWindowsStyle which is present on every platform and
     490    // draws required thing like we want. */
     491// #if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS)
     492    QWindowsStyle *pTreeWidgetStyle = new QWindowsStyle;
     493    setStyle(pTreeWidgetStyle);
     494    connect(this, SIGNAL(destroyed(QObject *)), pTreeWidgetStyle, SLOT(deleteLater()));
     495// #endif
     496#endif /* QT_VERSION < 0x050000 */
     497}
     498
     499
     500/*********************************************************************************************************************************
    457501*   Class UISnapshotPane implementation.                                                                                         *
    458502*********************************************************************************************************************************/
     
    469513    , m_pActionCloneSnapshot(new QAction(m_pCurrentStateItemActionGroup))
    470514    , m_fShapshotOperationsAllowed(false)
    471     , m_pTreeWidget(0)
     515    , m_pSnapshotTree(0)
    472516{
    473517    /* Cache pixmaps: */
     
    521565    m_pActionCloneSnapshot->setShortcut(QString("Ctrl+Shift+C"));
    522566
    523     /* Create tree-widget: */
    524     m_pTreeWidget = new QTreeWidget(this);
    525     m_pTreeWidget->header()->hide();
    526     m_pTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
    527     m_pTreeWidget->setAllColumnsShowFocus(true);
    528     /* Add tree-widget into layout: */
    529     pLayout->addWidget(m_pTreeWidget);
    530 
    531 #if QT_VERSION < 0x050000
    532     // WORKAROUND:
    533     // The snapshots widget is not very useful if there are a lot
    534     // of snapshots in a tree and the current Qt style decides not
    535     // to draw lines (branches) between the snapshot nodes; it is
    536     // then often unclear which snapshot is a child of another.
    537     // So on platforms whose styles do not normally draw branches,
    538     // we use QWindowsStyle which is present on every platform and
    539     // draws required thing like we want. */
    540 // #if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS)
    541     QWindowsStyle *pTreeWidgetStyle = new QWindowsStyle;
    542     m_pTreeWidget->setStyle(pTreeWidgetStyle);
    543     connect(m_pTreeWidget, SIGNAL(destroyed(QObject *)), pTreeWidgetStyle, SLOT(deleteLater()));
    544 // #endif
    545 #endif /* QT_VERSION < 0x050000 */
     567    /* Create snapshot tree: */
     568    m_pSnapshotTree = new UISnapshotTree(this);
     569    /* Add snapshot tree into layout: */
     570    pLayout->addWidget(m_pSnapshotTree);
    546571
    547572    /* Setup timer: */
    548573    m_ageUpdateTimer.setSingleShot(true);
    549574
    550     /* Setup tree-widget connections: */
    551     connect(m_pTreeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
     575    /* Setup snapshot tree connections: */
     576    connect(m_pSnapshotTree, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
    552577            this, SLOT(sltCurrentItemChanged(QTreeWidgetItem *)));
    553     connect(m_pTreeWidget, SIGNAL(customContextMenuRequested(const QPoint &)),
     578    connect(m_pSnapshotTree, SIGNAL(customContextMenuRequested(const QPoint &)),
    554579            this, SLOT(sltContextMenuRequested(const QPoint &)));
    555     connect(m_pTreeWidget, SIGNAL(itemChanged(QTreeWidgetItem *, int)),
     580    connect(m_pSnapshotTree, SIGNAL(itemChanged(QTreeWidgetItem *, int)),
    556581            this, SLOT(sltItemChanged(QTreeWidgetItem *)));
    557     connect(m_pTreeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
     582    connect(m_pSnapshotTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
    558583            this, SLOT(sltItemDoubleClicked(QTreeWidgetItem *)));
    559584    /* Setup snapshot operation connections: */
     
    624649    if (pSnapshotItem)
    625650    {
    626         m_pTreeWidget->horizontalScrollBar()->setValue(0);
    627         m_pTreeWidget->scrollToItem(pSnapshotItem);
    628         m_pTreeWidget->horizontalScrollBar()->setValue(m_pTreeWidget->indentation() * pSnapshotItem->level());
     651        m_pSnapshotTree->horizontalScrollBar()->setValue(0);
     652        m_pSnapshotTree->scrollToItem(pSnapshotItem);
     653        m_pSnapshotTree->horizontalScrollBar()->setValue(m_pSnapshotTree->indentation() * pSnapshotItem->level());
    629654    }
    630655
     
    682707{
    683708    /* Search for corresponding item: */
    684     const QTreeWidgetItem *pItem = m_pTreeWidget->itemAt(point);
     709    const QTreeWidgetItem *pItem = m_pSnapshotTree->itemAt(point);
    685710    if (!pItem)
    686711        return;
     
    710735
    711736    /* Show menu: */
    712     menu.exec(m_pTreeWidget->viewport()->mapToGlobal(point));
     737    menu.exec(m_pSnapshotTree->viewport()->mapToGlobal(point));
    713738}
    714739
     
    784809    /* Recache new session state: */
    785810    m_enmSessionState = enmState;
    786     sltCurrentItemChanged(m_pTreeWidget->currentItem());
     811    sltCurrentItemChanged(m_pSnapshotTree->currentItem());
    787812}
    788813
     
    794819
    795820    /* Search for smallest snapshot age to optimize timer timeout: */
    796     const SnapshotAgeFormat age = traverseSnapshotAge(m_pTreeWidget->invisibleRootItem());
     821    const SnapshotAgeFormat age = traverseSnapshotAge(m_pSnapshotTree->invisibleRootItem());
    797822    switch (age)
    798823    {
     
    842867            QString strSnapshotName = tr("Snapshot %1");
    843868            QRegExp regExp(QString("^") + strSnapshotName.arg("([0-9]+)") + QString("$"));
    844             QTreeWidgetItemIterator iterator(m_pTreeWidget);
     869            QTreeWidgetItemIterator iterator(m_pSnapshotTree);
    845870            while (*iterator)
    846871            {
     
    908933    {
    909934        /* Acquire currently chosen snapshot item: */
    910         const SnapshotWgtItem *pSnapshotItem = toSnapshotItem(m_pTreeWidget->currentItem());
     935        const SnapshotWgtItem *pSnapshotItem = toSnapshotItem(m_pSnapshotTree->currentItem());
    911936        AssertPtr(pSnapshotItem);
    912937        if (!pSnapshotItem)
     
    931956            {
    932957                /* Take snapshot of changed current state: */
    933                 m_pTreeWidget->setCurrentItem(currentStateItem());
     958                m_pSnapshotTree->setCurrentItem(currentStateItem());
    934959                if (!takeSnapshot())
    935960                    break;
     
    9831008    {
    9841009        /* Acquire currently chosen snapshot item: */
    985         const SnapshotWgtItem *pSnapshotItem = toSnapshotItem(m_pTreeWidget->currentItem());
     1010        const SnapshotWgtItem *pSnapshotItem = toSnapshotItem(m_pSnapshotTree->currentItem());
    9861011        AssertPtr(pSnapshotItem);
    9871012        if (!pSnapshotItem)
     
    10531078{
    10541079    /* Acquire currently chosen snapshot item: */
    1055     const SnapshotWgtItem *pSnapshotItem = toSnapshotItem(m_pTreeWidget->currentItem());
     1080    const SnapshotWgtItem *pSnapshotItem = toSnapshotItem(m_pSnapshotTree->currentItem());
    10561081    AssertReturnVoid(pSnapshotItem);
    10571082
     
    10721097{
    10731098    /* Acquire currently chosen snapshot item: */
    1074     const SnapshotWgtItem *pSnapshotItem = toSnapshotItem(m_pTreeWidget->currentItem());
     1099    const SnapshotWgtItem *pSnapshotItem = toSnapshotItem(m_pSnapshotTree->currentItem());
    10751100    AssertReturnVoid(pSnapshotItem);
    10761101
     
    11101135    /* Remember the selected item and it's first child: */
    11111136    QString strSelectedItem, strFirstChildOfSelectedItem;
    1112     const SnapshotWgtItem *pSnapshotItem = toSnapshotItem(m_pTreeWidget->currentItem());
     1137    const SnapshotWgtItem *pSnapshotItem = toSnapshotItem(m_pSnapshotTree->currentItem());
    11131138    if (pSnapshotItem)
    11141139    {
     
    11191144
    11201145    /* Clear the tree: */
    1121     m_pTreeWidget->clear();
     1146    m_pSnapshotTree->clear();
    11221147
    11231148    /* If machine has snapshots: */
     
    11451170
    11461171        /* Choose current item: */
    1147         m_pTreeWidget->scrollToItem(pCurrentItem);
    1148         m_pTreeWidget->setCurrentItem(pCurrentItem);
     1172        m_pSnapshotTree->scrollToItem(pCurrentItem);
     1173        m_pSnapshotTree->setCurrentItem(pCurrentItem);
    11491174        sltCurrentItemChanged(pCurrentItem);
    11501175    }
     
    11551180        m_pCurrentSnapshotItem = 0;
    11561181
    1157         /* Add the "current state" item as a child of tree-widget: */
    1158         SnapshotWgtItem *pCsi = new SnapshotWgtItem(this, m_pTreeWidget, m_comMachine);
     1182        /* Add the "current state" item as a child of snapshot tree: */
     1183        SnapshotWgtItem *pCsi = new SnapshotWgtItem(this, m_pSnapshotTree, m_comMachine);
    11591184        pCsi->setBold(true);
    11601185        pCsi->recache();
    11611186
    11621187        /* Choose current item: */
    1163         m_pTreeWidget->setCurrentItem(pCsi);
     1188        m_pSnapshotTree->setCurrentItem(pCsi);
    11641189        sltCurrentItemChanged(pCsi);
    11651190    }
     
    11681193    sltUpdateSnapshotsAge();
    11691194
    1170     /* Adjust tree-widget: */
    1171     m_pTreeWidget->resizeColumnToContents(0);
     1195    /* Adjust snapshot tree: */
     1196    m_pSnapshotTree->resizeColumnToContents(0);
    11721197}
    11731198
     
    11761201    /* Create a child of passed item: */
    11771202    SnapshotWgtItem *pSnapshotItem = pItem ? new SnapshotWgtItem(this, pItem, comSnapshot) :
    1178                                              new SnapshotWgtItem(this, m_pTreeWidget, comSnapshot);
     1203                                             new SnapshotWgtItem(this, m_pSnapshotTree, comSnapshot);
    11791204    /* And recache it's content: */
    11801205    pSnapshotItem->recache();
     
    12011226{
    12021227    /* Search for the first item with required ID: */
    1203     QTreeWidgetItemIterator it(m_pTreeWidget);
     1228    QTreeWidgetItemIterator it(m_pSnapshotTree);
    12041229    while (*it)
    12051230    {
     
    12191244    QTreeWidgetItem *pCsi = m_pCurrentSnapshotItem ?
    12201245                            m_pCurrentSnapshotItem->child(m_pCurrentSnapshotItem->childCount() - 1) :
    1221                             m_pTreeWidget->invisibleRootItem()->child(0);
     1246                            m_pSnapshotTree->invisibleRootItem()->child(0);
    12221247    return static_cast<SnapshotWgtItem*>(pCsi);
    12231248}
     
    12661291}
    12671292
     1293#include "UISnapshotPane.moc"
     1294
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.h

    r63838 r63851  
    3232
    3333/* Forward declarations: */
    34 class QTreeWidget;
     34class UISnapshotTree;
    3535class QTreeWidgetItem;
    3636class SnapshotWgtItem;
     
    185185    QIcon            m_snapshotIconOnline;
    186186
    187     /** Holds the tree-widget instance. */
    188     QTreeWidget     *m_pTreeWidget;
     187    /** Holds the snapshot tree instance. */
     188    UISnapshotTree  *m_pSnapshotTree;
    189189};
    190190
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