VirtualBox

Changeset 71792 in vbox


Ignore:
Timestamp:
Apr 9, 2018 5:08:47 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
121895
Message:

FE/Qt: bugref:6699 Implementing 'select all' and 'invert selection' actions for the guest file manager

Location:
trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileTable.cpp

    r71693 r71792  
    720720    , m_pCreateNewDirectory(0)
    721721    , m_pShowProperties(0)
     722    , m_pSelectAll(0)
     723    , m_pInvertSelection(0)
     724
    722725{
    723726    prepareObjects();
     
    919922    }
    920923
     924    m_pSelectAll = new QAction(this);
     925    {
     926        m_pSelectAll->setIcon(UIIconPool::iconSet(QString(":/session_info_32px.png")));
     927        m_pToolBar->addAction(m_pSelectAll);
     928        connect(m_pSelectAll, &QAction::triggered, this, &UIGuestControlFileTable::sltSelectAll);
     929    }
     930
     931    m_pInvertSelection = new QAction(this);
     932    {
     933        m_pInvertSelection->setIcon(UIIconPool::iconSet(QString(":/session_info_32px.png")));
     934        m_pToolBar->addAction(m_pInvertSelection);
     935        connect(m_pInvertSelection, &QAction::triggered, this, &UIGuestControlFileTable::sltInvertSelection);
     936    }
     937
    921938    disableSelectionDependentActions();
    922939}
     
    12141231void UIGuestControlFileTable::sltSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
    12151232{
    1216     /* Disable all the action that operate on some selection: */
    1217     if (!deselected.isEmpty() && selected.isEmpty())
     1233    if (m_pView->hasSelection())
     1234        enableSelectionDependentActions();
     1235    else
    12181236        disableSelectionDependentActions();
    1219 
    1220     /* Enable all the action that operate on some selection: */
    1221     if (deselected.isEmpty() && !selected.isEmpty())
    1222         enableSelectionDependentActions();
    12231237}
    12241238
     
    12311245    QStringList pathList = comboLocation.split(UIPathOperations::delimiter, QString::SkipEmptyParts);
    12321246    goIntoDirectory(pathList);
     1247}
     1248
     1249void UIGuestControlFileTable::sltSelectAll()
     1250{
     1251    if (!m_pModel || !m_pView)
     1252        return;
     1253    m_pView->selectAll();
     1254    deSelectUpDirectoryItem();
     1255}
     1256
     1257void UIGuestControlFileTable::sltInvertSelection()
     1258{
     1259    setSelectionForAll(QItemSelectionModel::QItemSelectionModel::Toggle | QItemSelectionModel::Rows);
     1260    deSelectUpDirectoryItem();
     1261}
     1262
     1263void UIGuestControlFileTable::deSelectUpDirectoryItem()
     1264{
     1265    if (!m_pView)
     1266        return;
     1267    QItemSelectionModel *pSelectionModel = m_pView->selectionModel();
     1268    if (!pSelectionModel)
     1269        return;
     1270    QModelIndex currentRoot = m_pView->rootIndex();
     1271    if (!currentRoot.isValid())
     1272        return;
     1273
     1274    /* Make sure that "up directory item" (if exists) is deselected: */
     1275    for (int i = 0; i < m_pModel->rowCount(currentRoot); ++i)
     1276    {
     1277        QModelIndex index = m_pModel->index(i, 0, currentRoot);
     1278        if (!index.isValid())
     1279            continue;
     1280
     1281        UIFileTableItem *item = static_cast<UIFileTableItem*>(index.internalPointer());
     1282        if (item && item->isUpDirectory())
     1283        {
     1284            pSelectionModel->select(index, QItemSelectionModel::QItemSelectionModel::Deselect | QItemSelectionModel::Rows);
     1285        }
     1286    }
     1287}
     1288
     1289void UIGuestControlFileTable::setSelectionForAll(QItemSelectionModel::SelectionFlags flags)
     1290{
     1291    if (!m_pView)
     1292        return;
     1293    QItemSelectionModel *pSelectionModel = m_pView->selectionModel();
     1294    if (!pSelectionModel)
     1295        return;
     1296    QModelIndex currentRoot = m_pView->rootIndex();
     1297    if (!currentRoot.isValid())
     1298        return;
     1299
     1300    for (int i = 0; i < m_pModel->rowCount(currentRoot); ++i)
     1301    {
     1302        QModelIndex index = m_pModel->index(i, 0, currentRoot);
     1303        if (!index.isValid())
     1304            continue;
     1305        pSelectionModel->select(index, flags);
     1306    }
    12331307}
    12341308
     
    13121386        m_pShowProperties->setToolTip(UIVMInformationDialog::tr("Show the properties of the selected item(s)"));
    13131387        m_pShowProperties->setStatusTip(UIVMInformationDialog::tr("Show the properties of the selected item(s)"));
     1388    }
     1389
     1390    if (m_pSelectAll)
     1391    {
     1392        m_pSelectAll->setText(UIVMInformationDialog::tr("Select All"));
     1393        m_pSelectAll->setToolTip(UIVMInformationDialog::tr("Select All"));
     1394        m_pSelectAll->setStatusTip(UIVMInformationDialog::tr("Select All"));
     1395    }
     1396
     1397    if (m_pInvertSelection)
     1398    {
     1399        m_pInvertSelection->setText(UIVMInformationDialog::tr("Invert Selection"));
     1400        m_pInvertSelection->setToolTip(UIVMInformationDialog::tr("Invert Selection"));
     1401        m_pInvertSelection->setStatusTip(UIVMInformationDialog::tr("Invert Selection"));
    13141402    }
    13151403}
     
    14821570
    14831571#include "UIGuestControlFileTable.moc"
    1484 
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileTable.h

    r71693 r71792  
    2020
    2121/* Qt includes: */
    22 # include <QMutex>
     22#include <QItemSelectionModel>
     23#include <QMutex>
    2324#include <QThread>
    2425#include <QWidget>
     
    304305    void sltSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected);
    305306    void sltLocationComboCurrentChange(const QString &strLocation);
     307    void sltSelectAll();
     308    void sltInvertSelection();
    306309
    307310private:
     
    316319    void            enableSelectionDependentActions();
    317320    void            disableSelectionDependentActions();
     321    void            deSelectUpDirectoryItem();
     322    void            setSelectionForAll(QItemSelectionModel::SelectionFlags flags);
    318323    QGridLayout     *m_pMainLayout;
    319324    QComboBox       *m_pLocationComboBox;
     
    326331    QAction         *m_pCreateNewDirectory;
    327332    QAction         *m_pShowProperties;
     333    QAction         *m_pSelectAll;
     334    QAction         *m_pInvertSelection;
    328335    /** The vector of action which need some selection to work on like cut, copy etc. */
    329336    QVector<QAction*> m_selectionDependentActions;
     
    335342
    336343#endif /* !___UIGuestControlFileTable_h___ */
    337 
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