VirtualBox

Changeset 71362 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Mar 16, 2018 8:16:36 AM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6699: Adding a context menu to guest control 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

    r71352 r71362  
    2828# include <QGridLayout>
    2929# include <QPushButton>
     30# include <QMenu>
    3031
    3132/* GUI includes: */
     
    4950#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    5051
     52
     53/*********************************************************************************************************************************
     54*   UIPathOperations definition.                                                                                                 *
     55*********************************************************************************************************************************/
     56
    5157/** A collection of utility functions for some path string manipulations */
    5258class UIPathOperations
     
    7076};
    7177
     78
     79/*********************************************************************************************************************************
     80*   UIGuestControlFileView definition.                                                                                           *
     81*********************************************************************************************************************************/
     82
     83/** Using QITableView causes the following problem when I click on the table items
     84    Qt WARNING: Cannot creat accessible child interface for object:  UIGuestControlFileView.....
     85    so for now subclass QTableView */
     86class UIGuestControlFileView : public QTableView
     87{
     88    Q_OBJECT;
     89signals:
     90
     91    void sigGoUp();
     92    void sigGoHome();
     93    void sigRefresh();
     94    void sigRename();
     95    void sigCreateNewDirectory();
     96    void sigDelete();
     97    void sigCut();
     98    void sigCopy();
     99    void sigPaste();
     100
     101public:
     102
     103    UIGuestControlFileView(QWidget * parent = 0);
     104    bool hasSelection() const;
     105
     106protected:
     107    void contextMenuEvent(QContextMenuEvent *pEvent);
     108};
     109
     110
     111/*********************************************************************************************************************************
     112*   UIFileDelegate definition.                                                                                                   *
     113*********************************************************************************************************************************/
     114/** A QItemDelegate child class to disable dashed lines drawn around selected cells in QTableViews */
     115class UIFileDelegate : public QItemDelegate
     116{
     117
     118    Q_OBJECT;
     119
     120protected:
     121        virtual void drawFocus ( QPainter * /*painter*/, const QStyleOptionViewItem & /*option*/, const QRect & /*rect*/ ) const {}
     122};
     123
     124
     125/*********************************************************************************************************************************
     126*   UIFileStringInputDialog definition.                                                                                          *
     127*********************************************************************************************************************************/
     128
     129/** A QIDialog child including a line edit whose text exposed when the dialog is accepted */
     130class UIStringInputDialog : public QIDialog
     131{
     132
     133    Q_OBJECT;
     134
     135public:
     136
     137    UIStringInputDialog(QWidget *pParent = 0, Qt::WindowFlags flags = 0);
     138    QString getString() const;
     139
     140private:
     141
     142    QILineEdit      *m_pLineEdit;
     143
     144};
     145
     146/*********************************************************************************************************************************
     147*   UIPathOperations implementation.                                                                                      *
     148*********************************************************************************************************************************/
     149
    72150const QChar UIPathOperations::delimiter = QChar('/');
    73151
     
    156234}
    157235
    158 
    159236/*********************************************************************************************************************************
    160 *   UIFileDelegate definition.                                                                                                   *
     237*   UIGuestControlFileView implementation.                                                                                      *
    161238*********************************************************************************************************************************/
    162 /** A QItemDelegate child class to disable dashed lines drawn around selected cells in QTableViews */
    163 class UIFileDelegate : public QItemDelegate
    164 {
    165 
    166     Q_OBJECT;
    167 
    168 protected:
    169         virtual void drawFocus ( QPainter * /*painter*/, const QStyleOptionViewItem & /*option*/, const QRect & /*rect*/ ) const {}
    170 };
    171 
    172 
    173 /*********************************************************************************************************************************
    174 *   UIFileStringInputDialog definition.                                                                                          *
    175 *********************************************************************************************************************************/
    176 
    177 /** A QIDialog child including a line edit whose text exposed when the dialog is accepted */
    178 class UIStringInputDialog : public QIDialog
    179 {
    180 
    181     Q_OBJECT;
    182 
    183 public:
    184 
    185     UIStringInputDialog(QWidget *pParent = 0, Qt::WindowFlags flags = 0);
    186     QString getString() const;
    187 
    188 private:
    189 
    190     QILineEdit      *m_pLineEdit;
    191 
    192     // virtual void accept() /* override */;
    193     // virtual void reject() /* override */;
    194 
    195 };
    196 
     239
     240UIGuestControlFileView::UIGuestControlFileView(QWidget * parent)
     241    :QTableView(parent)
     242{
     243}
     244
     245void UIGuestControlFileView::contextMenuEvent(QContextMenuEvent *pEvent)
     246{
     247    bool selectionAvaible = hasSelection();
     248
     249    QMenu *menu = new QMenu(this);
     250    if (!menu)
     251        return;
     252
     253    QAction *pActionGoUp = menu->addAction(UIVMInformationDialog::tr("Go up"));
     254    if (pActionGoUp)
     255    {
     256        pActionGoUp->setIcon(UIIconPool::iconSet(QString(":/arrow_up_10px_x2.png")));
     257        connect(pActionGoUp, &QAction::triggered, this, &UIGuestControlFileView::sigGoUp);
     258    }
     259    QAction *pActionGoHome = menu->addAction(UIVMInformationDialog::tr("Go home"));
     260    if (pActionGoHome)
     261    {
     262        pActionGoHome->setIcon(UIIconPool::iconSet(QString(":/nw_24px.png")));
     263        connect(pActionGoHome, &QAction::triggered, this, &UIGuestControlFileView::sigGoHome);
     264    }
     265
     266    QAction *pActionRefresh = menu->addAction(UIVMInformationDialog::tr("Refresh"));
     267    if (pActionRefresh)
     268    {
     269        pActionRefresh->setIcon(UIIconPool::iconSet(QString(":/refresh_22px.png")));
     270        connect(pActionRefresh, &QAction::triggered, this, &UIGuestControlFileView::sigRefresh);
     271    }
     272
     273    menu->addSeparator();
     274    QAction *pActionDelete = menu->addAction(UIVMInformationDialog::tr("Delete"));
     275    if (pActionDelete)
     276    {
     277        pActionDelete->setIcon(UIIconPool::iconSet(QString(":/vm_delete_32px.png")));
     278        pActionDelete->setEnabled(selectionAvaible);
     279        connect(pActionDelete, &QAction::triggered, this, &UIGuestControlFileView::sigDelete);
     280    }
     281
     282    QAction *pActionRename = menu->addAction(UIVMInformationDialog::tr("Rename"));
     283    if (pActionRename)
     284    {
     285        pActionRename->setIcon(UIIconPool::iconSet(QString(":/name_16px_x2.png")));
     286        pActionRename->setEnabled(selectionAvaible);
     287        pActionRename->setEnabled(selectionAvaible);
     288        connect(pActionRename, &QAction::triggered, this, &UIGuestControlFileView::sigRename);
     289    }
     290
     291    QAction *pActionCreateNewDirectory = menu->addAction(UIVMInformationDialog::tr("Create New Directory"));
     292    if (pActionCreateNewDirectory)
     293    {
     294        pActionCreateNewDirectory->setIcon(UIIconPool::iconSet(QString(":/sf_add_16px.png")));
     295        connect(pActionCreateNewDirectory, &QAction::triggered, this, &UIGuestControlFileView::sigCreateNewDirectory);
     296    }
     297
     298    QAction *pActionCopy = menu->addAction(UIVMInformationDialog::tr("Copy"));
     299    if (pActionCopy)
     300    {
     301        pActionCopy->setIcon(UIIconPool::iconSet(QString(":/fd_copy_22px.png")));
     302        pActionCopy->setEnabled(selectionAvaible);
     303        connect(pActionCopy, &QAction::triggered, this, &UIGuestControlFileView::sigCopy);
     304    }
     305
     306    QAction *pActionCut = menu->addAction(UIVMInformationDialog::tr("Cut"));
     307    if (pActionCut)
     308    {
     309        pActionCut->setIcon(UIIconPool::iconSet(QString(":/fd_move_22px.png")));
     310        pActionCut->setEnabled(selectionAvaible);
     311        connect(pActionCut, &QAction::triggered, this, &UIGuestControlFileView::sigCut);
     312    }
     313
     314    QAction *pActionPaste = menu->addAction(UIVMInformationDialog::tr("Paste"));
     315    if (pActionPaste)
     316    {
     317        pActionPaste->setIcon(UIIconPool::iconSet(QString(":/shared_clipboard_16px.png")));
     318        connect(pActionPaste, &QAction::triggered, this, &UIGuestControlFileView::sigPaste);
     319    }
     320
     321    menu->exec(pEvent->globalPos());
     322
     323    if (pActionGoUp)
     324        disconnect(pActionGoUp, &QAction::triggered, this, &UIGuestControlFileView::sigGoUp);
     325    if (pActionGoHome)
     326        disconnect(pActionGoHome, &QAction::triggered, this, &UIGuestControlFileView::sigGoHome);
     327    if (pActionRefresh)
     328        disconnect(pActionRefresh, &QAction::triggered, this, &UIGuestControlFileView::sigRefresh);
     329    if (pActionDelete)
     330        disconnect(pActionDelete, &QAction::triggered, this, &UIGuestControlFileView::sigDelete);
     331    if (pActionRename)
     332        disconnect(pActionRename, &QAction::triggered, this, &UIGuestControlFileView::sigRename);
     333    if (pActionCreateNewDirectory)
     334        disconnect(pActionCreateNewDirectory, &QAction::triggered, this, &UIGuestControlFileView::sigCreateNewDirectory);
     335    if (pActionCopy)
     336        disconnect(pActionCopy, &QAction::triggered, this, &UIGuestControlFileView::sigCopy);
     337    if (pActionCut)
     338        disconnect(pActionCut, &QAction::triggered, this, &UIGuestControlFileView::sigCut);
     339    if (pActionPaste)
     340        disconnect(pActionPaste, &QAction::triggered, this, &UIGuestControlFileView::sigPaste);
     341
     342    delete menu;
     343}
     344
     345bool UIGuestControlFileView::hasSelection() const
     346{
     347    QItemSelectionModel *pSelectionModel =  selectionModel();
     348    if (!pSelectionModel)
     349        return false;
     350    return pSelectionModel->hasSelection();
     351}
    197352
    198353/*********************************************************************************************************************************
     
    463618
    464619
    465     m_pView = new QTableView;
     620    m_pView = new UIGuestControlFileView;
    466621    if (m_pView)
    467622    {
     
    479634        //m_pView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    480635
    481         connect(m_pView, &QTableView::doubleClicked,
     636        connect(m_pView, &UIGuestControlFileView::doubleClicked,
    482637                this, &UIGuestControlFileTable::sltItemDoubleClicked);
     638
     639        connect(m_pView, &UIGuestControlFileView::sigGoUp,
     640                this, &UIGuestControlFileTable::sltGoUp);
     641        connect(m_pView, &UIGuestControlFileView::sigGoHome,
     642                this, &UIGuestControlFileTable::sltGoHome);
     643        connect(m_pView, &UIGuestControlFileView::sigRefresh,
     644                this, &UIGuestControlFileTable::sltRefresh);
     645        connect(m_pView, &UIGuestControlFileView::sigDelete,
     646                this, &UIGuestControlFileTable::sltDelete);
     647        connect(m_pView, &UIGuestControlFileView::sigRename,
     648                this, &UIGuestControlFileTable::sltRename);
     649
     650        connect(m_pView, &UIGuestControlFileView::sigCreateNewDirectory,
     651                this, &UIGuestControlFileTable::sltCreateNewDirectory);
     652
     653        connect(m_pView, &UIGuestControlFileView::sigCopy,
     654                this, &UIGuestControlFileTable::sltCopy);
     655        connect(m_pView, &UIGuestControlFileView::sigCut,
     656                this, &UIGuestControlFileTable::sltCut);
     657        connect(m_pView, &UIGuestControlFileView::sigPaste,
     658                this, &UIGuestControlFileTable::sltPaste);
    483659
    484660    }
     
    545721        m_pCopy->setIcon(UIIconPool::iconSet(QString(":/fd_copy_22px.png")));
    546722        m_pToolBar->addAction(m_pCopy);
    547         //m_pCopy->setEnabled(false);
     723        connect(m_pCopy, &QAction::triggered, this, &UIGuestControlFileTable::sltCopy);
    548724    }
    549725
     
    553729        m_pCut->setIcon(UIIconPool::iconSet(QString(":/fd_move_22px.png")));
    554730        m_pToolBar->addAction(m_pCut);
    555         m_pCut->setEnabled(false);
     731        connect(m_pCut, &QAction::triggered, this, &UIGuestControlFileTable::sltCut);
    556732    }
    557733
     
    561737        m_pPaste->setIcon(UIIconPool::iconSet(QString(":/shared_clipboard_16px.png")));
    562738        m_pToolBar->addAction(m_pPaste);
    563         m_pPaste->setEnabled(false);
     739        connect(m_pPaste, &QAction::triggered, this, &UIGuestControlFileTable::sltPaste);
    564740    }
    565741}
     
    810986}
    811987
     988void UIGuestControlFileTable::sltCopy()
     989{
     990}
     991
     992void UIGuestControlFileTable::sltCut()
     993{
     994}
     995
     996void UIGuestControlFileTable::sltPaste()
     997{
     998}
     999
    8121000void UIGuestControlFileTable::deleteByIndex(const QModelIndex &itemIndex)
    8131001{
     
    8561044    if (m_pCreateNewDirectory)
    8571045    {
    858         m_pCreateNewDirectory->setText(UIVMInformationDialog::tr("Create a new directory"));
    859         m_pCreateNewDirectory->setToolTip(UIVMInformationDialog::tr("Create a new directory"));
    860         m_pCreateNewDirectory->setStatusTip(UIVMInformationDialog::tr("Create a new directory"));
    861 
     1046        m_pCreateNewDirectory->setText(UIVMInformationDialog::tr("Create new directory"));
     1047        m_pCreateNewDirectory->setToolTip(UIVMInformationDialog::tr("Create new directory"));
     1048        m_pCreateNewDirectory->setStatusTip(UIVMInformationDialog::tr("Create new directory"));
    8621049    }
    8631050
     
    12811468void UIHostFileTable::deleteByItem(UIFileTableItem *item)
    12821469{
     1470    if (item->isUpDirectory())
     1471        return;
    12831472    if (!item->isDirectory())
    12841473    {
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileTable.h

    r71350 r71362  
    3838class UIFileTableItem;
    3939class UIGuestControlFileModel;
    40 class UIGuestControlFileTable;
     40class UIGuestControlFileView;
    4141class UIToolBar;
    4242
     
    113113
    114114};
     115
    115116
    116117/** This class serves a base class for file table. Currently a guest version
     
    165166    UIFileTableItem         *m_pRootItem;
    166167
    167     /** Using QITableView causes the following problem when I click on the table items
    168         Qt WARNING: Cannot creat accessible child interface for object:  UIGuestControlFileView.....
    169         so for now subclass QTableView */
    170     QTableView              *m_pView;
     168    UIGuestControlFileView  *m_pView;
    171169    UIGuestControlFileModel *m_pModel;
    172170    QILabel                 *m_pLocationLabel;
     
    180178    void sltDelete();
    181179    void sltRename();
     180    void sltCopy();
     181    void sltCut();
     182    void sltPaste();
    182183    void sltCreateNewDirectory();
    183184
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