Changeset 71362 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Mar 16, 2018 8:16:36 AM (7 years ago)
- 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 28 28 # include <QGridLayout> 29 29 # include <QPushButton> 30 # include <QMenu> 30 31 31 32 /* GUI includes: */ … … 49 50 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 50 51 52 53 /********************************************************************************************************************************* 54 * UIPathOperations definition. * 55 *********************************************************************************************************************************/ 56 51 57 /** A collection of utility functions for some path string manipulations */ 52 58 class UIPathOperations … … 70 76 }; 71 77 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 */ 86 class UIGuestControlFileView : public QTableView 87 { 88 Q_OBJECT; 89 signals: 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 101 public: 102 103 UIGuestControlFileView(QWidget * parent = 0); 104 bool hasSelection() const; 105 106 protected: 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 */ 115 class UIFileDelegate : public QItemDelegate 116 { 117 118 Q_OBJECT; 119 120 protected: 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 */ 130 class UIStringInputDialog : public QIDialog 131 { 132 133 Q_OBJECT; 134 135 public: 136 137 UIStringInputDialog(QWidget *pParent = 0, Qt::WindowFlags flags = 0); 138 QString getString() const; 139 140 private: 141 142 QILineEdit *m_pLineEdit; 143 144 }; 145 146 /********************************************************************************************************************************* 147 * UIPathOperations implementation. * 148 *********************************************************************************************************************************/ 149 72 150 const QChar UIPathOperations::delimiter = QChar('/'); 73 151 … … 156 234 } 157 235 158 159 236 /********************************************************************************************************************************* 160 * UI FileDelegate definition.*237 * UIGuestControlFileView implementation. * 161 238 *********************************************************************************************************************************/ 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 240 UIGuestControlFileView::UIGuestControlFileView(QWidget * parent) 241 :QTableView(parent) 242 { 243 } 244 245 void 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 345 bool UIGuestControlFileView::hasSelection() const 346 { 347 QItemSelectionModel *pSelectionModel = selectionModel(); 348 if (!pSelectionModel) 349 return false; 350 return pSelectionModel->hasSelection(); 351 } 197 352 198 353 /********************************************************************************************************************************* … … 463 618 464 619 465 m_pView = new QTableView;620 m_pView = new UIGuestControlFileView; 466 621 if (m_pView) 467 622 { … … 479 634 //m_pView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); 480 635 481 connect(m_pView, & QTableView::doubleClicked,636 connect(m_pView, &UIGuestControlFileView::doubleClicked, 482 637 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); 483 659 484 660 } … … 545 721 m_pCopy->setIcon(UIIconPool::iconSet(QString(":/fd_copy_22px.png"))); 546 722 m_pToolBar->addAction(m_pCopy); 547 //m_pCopy->setEnabled(false);723 connect(m_pCopy, &QAction::triggered, this, &UIGuestControlFileTable::sltCopy); 548 724 } 549 725 … … 553 729 m_pCut->setIcon(UIIconPool::iconSet(QString(":/fd_move_22px.png"))); 554 730 m_pToolBar->addAction(m_pCut); 555 m_pCut->setEnabled(false);731 connect(m_pCut, &QAction::triggered, this, &UIGuestControlFileTable::sltCut); 556 732 } 557 733 … … 561 737 m_pPaste->setIcon(UIIconPool::iconSet(QString(":/shared_clipboard_16px.png"))); 562 738 m_pToolBar->addAction(m_pPaste); 563 m_pPaste->setEnabled(false);739 connect(m_pPaste, &QAction::triggered, this, &UIGuestControlFileTable::sltPaste); 564 740 } 565 741 } … … 810 986 } 811 987 988 void UIGuestControlFileTable::sltCopy() 989 { 990 } 991 992 void UIGuestControlFileTable::sltCut() 993 { 994 } 995 996 void UIGuestControlFileTable::sltPaste() 997 { 998 } 999 812 1000 void UIGuestControlFileTable::deleteByIndex(const QModelIndex &itemIndex) 813 1001 { … … 856 1044 if (m_pCreateNewDirectory) 857 1045 { 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")); 862 1049 } 863 1050 … … 1281 1468 void UIHostFileTable::deleteByItem(UIFileTableItem *item) 1282 1469 { 1470 if (item->isUpDirectory()) 1471 return; 1283 1472 if (!item->isDirectory()) 1284 1473 { -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileTable.h
r71350 r71362 38 38 class UIFileTableItem; 39 39 class UIGuestControlFileModel; 40 class UIGuestControlFile Table;40 class UIGuestControlFileView; 41 41 class UIToolBar; 42 42 … … 113 113 114 114 }; 115 115 116 116 117 /** This class serves a base class for file table. Currently a guest version … … 165 166 UIFileTableItem *m_pRootItem; 166 167 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; 171 169 UIGuestControlFileModel *m_pModel; 172 170 QILabel *m_pLocationLabel; … … 180 178 void sltDelete(); 181 179 void sltRename(); 180 void sltCopy(); 181 void sltCut(); 182 void sltPaste(); 182 183 void sltCreateNewDirectory(); 183 184
Note:
See TracChangeset
for help on using the changeset viewer.