VirtualBox

Changeset 95233 in vbox


Ignore:
Timestamp:
Jun 8, 2022 3:46:27 PM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
151762
Message:

FE/Qt/Ds: bugref:6899: Machine settings: System page accessibility improvements (part 11); Reworking UIBootOrderEditor to be based on QITreeWidget instead of QListWidget; QITreeWidget is accessible comparing to previous base-class.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIDetailsGenerator.cpp

    r93996 r95233  
    1919#include <QApplication>
    2020#include <QDir>
     21#include <QRegularExpression>
    2122
    2223/* GUI includes: */
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/editors/UIBootOrderEditor.cpp

    r95227 r95233  
    1818/* Qt includes: */
    1919#include <QGridLayout>
     20#include <QHeaderView>
    2021#include <QLabel>
    2122#include <QRegularExpression>
     
    2829#include "UIIconPool.h"
    2930#include "QIToolBar.h"
     31#include "QITreeWidget.h"
    3032
    3133/* COM includes: */
     
    3537
    3638
    37 /** QListWidgetItem extension for our UIBootListWidget. */
    38 class UIBootListWidgetItem : public QListWidgetItem
    39 {
     39/** QITreeWidgetItem extension for our UIBootListWidget. */
     40class UIBootListWidgetItem : public QITreeWidgetItem
     41{
     42    Q_OBJECT;
     43
    4044public:
    4145
     
    4448
    4549    /** Returns the item type. */
    46     KDeviceType type() const;
     50    KDeviceType deviceType() const;
    4751
    4852    /** Performs item translation. */
     
    5660
    5761
    58 /** QListWidget subclass used as system settings boot-table. */
    59 class UIBootListWidget : public QIWithRetranslateUI<QListWidget>
     62/** QITreeWidget subclass used as system settings boot-table. */
     63class UIBootListWidget : public QIWithRetranslateUI<QITreeWidget>
    6064{
    6165    Q_OBJECT;
     
    6367signals:
    6468
    65     /** Notifies listeners about current table row changed.
    66       * @note  Same as base-class currentRowChanged but in wider cases. */
    67     void sigRowChanged(int iRow);
     69    /** Notifies listeners about current table row changed. */
     70    void sigRowChanged();
    6871
    6972public:
     
    117120    : m_enmType(enmType)
    118121{
    119     setCheckState(Qt::Unchecked);
     122    setCheckState(0, Qt::Unchecked);
    120123    switch(enmType)
    121124    {
    122         case KDeviceType_Floppy:   setIcon(UIIconPool::iconSet(":/fd_16px.png")); break;
    123         case KDeviceType_DVD:      setIcon(UIIconPool::iconSet(":/cd_16px.png")); break;
    124         case KDeviceType_HardDisk: setIcon(UIIconPool::iconSet(":/hd_16px.png")); break;
    125         case KDeviceType_Network:  setIcon(UIIconPool::iconSet(":/nw_16px.png")); break;
     125        case KDeviceType_Floppy:   setIcon(0, UIIconPool::iconSet(":/fd_16px.png")); break;
     126        case KDeviceType_DVD:      setIcon(0, UIIconPool::iconSet(":/cd_16px.png")); break;
     127        case KDeviceType_HardDisk: setIcon(0, UIIconPool::iconSet(":/hd_16px.png")); break;
     128        case KDeviceType_Network:  setIcon(0, UIIconPool::iconSet(":/nw_16px.png")); break;
    126129        default: break; /* Shut up, MSC! */
    127130    }
     
    129132}
    130133
    131 KDeviceType UIBootListWidgetItem::type() const
     134KDeviceType UIBootListWidgetItem::deviceType() const
    132135{
    133136    return m_enmType;
     
    136139void UIBootListWidgetItem::retranslateUi()
    137140{
    138     setText(gpConverter->toString(m_enmType));
     141    setText(0, gpConverter->toString(m_enmType));
    139142}
    140143
     
    145148
    146149UIBootListWidget::UIBootListWidget(QWidget *pParent /* = 0 */)
    147     : QIWithRetranslateUI<QListWidget>(pParent)
     150    : QIWithRetranslateUI<QITreeWidget>(pParent)
    148151{
    149152    prepare();
     
    159162    {
    160163        UIBootListWidgetItem *pItem = new UIBootListWidgetItem(data.m_enmType);
    161         pItem->setCheckState(data.m_fEnabled ? Qt::Checked : Qt::Unchecked);
    162         addItem(pItem);
    163     }
     164        pItem->setCheckState(0, data.m_fEnabled ? Qt::Checked : Qt::Unchecked);
     165        addTopLevelItem(pItem);
     166    }
     167
     168    /* Make sure at least one is chosen: */
     169    if (topLevelItemCount())
     170        setCurrentItem(topLevelItem(0));
    164171
    165172    /* Adjust table size after change: */
     
    173180
    174181    /* Enumerate all the items we have: */
    175     for (int i = 0; i < count(); ++i)
    176     {
    177         QListWidgetItem *pItem = item(i);
     182    for (int i = 0; i < topLevelItemCount(); ++i)
     183    {
     184        QTreeWidgetItem *pItem = topLevelItem(i);
    178185        UIBootItemData bootData;
    179         bootData.m_enmType = static_cast<UIBootListWidgetItem*>(pItem)->type();
    180         bootData.m_fEnabled = pItem->checkState() == Qt::Checked;
     186        bootData.m_enmType = static_cast<UIBootListWidgetItem*>(pItem)->deviceType();
     187        bootData.m_fEnabled = pItem->checkState(0) == Qt::Checked;
    181188        bootItems << bootData;
    182189    }
     
    200207void UIBootListWidget::retranslateUi()
    201208{
    202     for (int i = 0; i < count(); ++i)
    203         static_cast<UIBootListWidgetItem*>(item(i))->retranslateUi();
     209    for (int i = 0; i < topLevelItemCount(); ++i)
     210        static_cast<UIBootListWidgetItem*>(topLevelItem(i))->retranslateUi();
    204211
    205212    adjustSizeToFitContent();
     
    209216{
    210217    /* Call to base-class: */
    211     QListWidget::dropEvent(pEvent);
     218    QITreeWidget::dropEvent(pEvent);
    212219    /* Separately notify listeners: */
    213     emit sigRowChanged(currentRow());
     220    emit sigRowChanged();
    214221}
    215222
     
    248255        }
    249256    }
    250     return QListWidget::moveCursor(cursorAction, fModifiers);
     257    return QITreeWidget::moveCursor(cursorAction, fModifiers);
    251258}
    252259
    253260void UIBootListWidget::prepare()
    254261{
     262    header()->hide();
     263    setRootIsDecorated(false);
    255264    setDragDropMode(QAbstractItemView::InternalMove);
    256265    setSelectionMode(QAbstractItemView::SingleSelection);
    257266    setDropIndicatorShown(true);
    258     setUniformItemSizes(true);
    259     connect(this, &UIBootListWidget::currentRowChanged,
     267    connect(this, &UIBootListWidget::currentItemChanged,
    260268            this, &UIBootListWidget::sigRowChanged);
    261269}
     
    266274    const int iW = iH;
    267275    setFixedSize(sizeHintForColumn(0) + iW,
    268                  sizeHintForRow(0) * count() + iH);
    269 }
    270 
    271 QModelIndex UIBootListWidget::moveItemTo(const QModelIndex &index, int row)
     276                 sizeHintForRow(0) * topLevelItemCount() + iH);
     277}
     278
     279QModelIndex UIBootListWidget::moveItemTo(const QModelIndex &index, int iRow)
    272280{
    273281    /* Check validity: */
     
    276284
    277285    /* Check sanity: */
    278     if (row < 0 || row > model()->rowCount())
     286    if (iRow < 0 || iRow > model()->rowCount())
    279287        return QModelIndex();
    280288
    281289    QPersistentModelIndex oldIndex(index);
    282290    UIBootListWidgetItem *pItem = static_cast<UIBootListWidgetItem*>(itemFromIndex(oldIndex));
    283     insertItem(row, new UIBootListWidgetItem(*pItem));
    284     QPersistentModelIndex newIndex = model()->index(row, 0);
    285     delete takeItem(oldIndex.row());
    286     setCurrentRow(newIndex.row());
     291    insertTopLevelItem(iRow, new UIBootListWidgetItem(pItem->deviceType()));
     292    topLevelItem(iRow)->setCheckState(0, pItem->checkState(0));
     293    QPersistentModelIndex newIndex = model()->index(iRow, 0);
     294    delete takeTopLevelItem(oldIndex.row());
     295    setCurrentItem(topLevelItem(newIndex.row()));
    287296    return QModelIndex(newIndex);
    288297}
     
    573582{
    574583    /* Update move up/down actions: */
    575     if (m_pTable && m_pMoveUp)
    576         m_pMoveUp->setEnabled(m_pTable->hasFocus() && m_pTable->currentRow() > 0);
    577     if (m_pTable && m_pMoveDown)
    578         m_pMoveDown->setEnabled(m_pTable->hasFocus() && m_pTable->currentRow() < m_pTable->count() - 1);
     584    QTreeWidgetItem *pCurrentTopLevelItem = m_pTable->currentItem();
     585    const int iCurrentTopLevelItem = m_pTable->indexOfTopLevelItem(pCurrentTopLevelItem);
     586    if (m_pTable && m_pMoveUp && iCurrentTopLevelItem != -1)
     587        m_pMoveUp->setEnabled(m_pTable->hasFocus() && iCurrentTopLevelItem > 0);
     588    if (m_pTable && m_pMoveDown && iCurrentTopLevelItem != -1)
     589        m_pMoveDown->setEnabled(m_pTable->hasFocus() && iCurrentTopLevelItem < m_pTable->topLevelItemCount() - 1);
    579590}
    580591
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/editors/UIBootOrderEditor.h

    r95163 r95233  
    2121# pragma once
    2222#endif
    23 
    24 /* Qt includes: */
    25 #include <QListWidget>
    2623
    2724/* GUI includes: */
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