Changeset 76762 in vbox
- Timestamp:
- Jan 10, 2019 8:57:13 PM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/medium/viso
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/medium/viso/UIVisoBrowserBase.cpp
r76730 r76762 32 32 : QWidget(pParent) 33 33 , m_pTreeView(0) 34 , m_pTableView(0)35 34 , m_pTitleLabel(0) 36 35 , m_pRightContainerWidget(0) … … 94 93 } 95 94 96 m_pTableView = new QTableView;97 if (m_pTableView)98 {99 m_pRightContainerLayout->addWidget(m_pTableView, 0, 0, 6, 4);100 m_pTableView->setSelectionMode(QAbstractItemView::ContiguousSelection);101 m_pTableView->setShowGrid(false);102 m_pTableView->setSelectionBehavior(QAbstractItemView::SelectRows);103 m_pTableView->setEditTriggers(QAbstractItemView::NoEditTriggers);104 m_pTableView->setAlternatingRowColors(true);105 QHeaderView *pVerticalHeader = m_pTableView->verticalHeader();106 if (pVerticalHeader)107 {108 m_pTableView->verticalHeader()->setVisible(false);109 /* Minimize the row height: */110 m_pTableView->verticalHeader()->setDefaultSectionSize(m_pTableView->verticalHeader()->minimumSectionSize());111 }112 QHeaderView *pHorizontalHeader = m_pTableView->horizontalHeader();113 if (pHorizontalHeader)114 {115 pHorizontalHeader->setHighlightSections(false);116 pHorizontalHeader->setSectionResizeMode(QHeaderView::Stretch);117 }118 }119 95 120 96 m_pVerticalToolBar = new UIToolBar; … … 135 111 void UIVisoBrowserBase::prepareConnections() 136 112 { 137 if (m_pTableView)138 connect(m_pTableView, &QTableView::doubleClicked,139 this, &UIVisoBrowserBase::sltHandleTableViewItemDoubleClick);140 113 if (m_pTreeView) 141 114 { … … 154 127 void UIVisoBrowserBase::sltHandleTreeSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected) 155 128 { 156 if (!m_pTableView)157 return;158 129 Q_UNUSED(deselected); 159 130 QModelIndexList indices = selected.indexes(); … … 163 134 treeSelectionChanged(selectedIndex); 164 135 } 136 165 137 166 138 void UIVisoBrowserBase::sltHandleTreeItemClicked(const QModelIndex &modelIndex) -
trunk/src/VBox/Frontends/VirtualBox/src/medium/viso/UIVisoBrowserBase.h
r76730 r76762 46 46 virtual void showHideHiddenObjects(bool bShow) = 0; 47 47 48 public slots: 49 50 void sltHandleTableViewItemDoubleClick(const QModelIndex &index); 51 48 52 protected: 49 53 … … 58 62 59 63 QTreeView *m_pTreeView; 60 QTableView *m_pTableView;61 64 QLabel *m_pTitleLabel; 62 65 QWidget *m_pRightContainerWidget; … … 69 72 70 73 private slots: 71 void sltHandleTableViewItemDoubleClick(const QModelIndex &index); 74 72 75 void sltHandleTreeSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected); 73 76 void sltHandleTreeItemClicked(const QModelIndex &modelIndex); -
trunk/src/VBox/Frontends/VirtualBox/src/medium/viso/UIVisoContentBrowser.cpp
r76750 r76762 27 27 #include <QLabel> 28 28 #include <QListView> 29 #include <QMimeData> 29 30 #include <QSplitter> 30 31 #include <QTableView> … … 39 40 40 41 42 43 /********************************************************************************************************************************* 44 * UIVisoContentTableView definition. * 45 *********************************************************************************************************************************/ 46 /** An QTableView extension mainly used to handle dropeed file objects from the host browser. */ 47 class UIVisoContentTableView : public QTableView 48 { 49 Q_OBJECT; 50 51 signals: 52 53 void sigNewItemsDropped(QStringList pathList); 54 55 public: 56 57 UIVisoContentTableView(QWidget *pParent = 0); 58 void dragEnterEvent(QDragEnterEvent *event); 59 void dropEvent(QDropEvent *event); 60 void dragMoveEvent(QDragMoveEvent *event); 61 }; 62 63 41 64 /********************************************************************************************************************************* 42 65 * UIVisoContentTreeProxyModel definition. * … … 56 79 /** Used to filter-out files and show only directories. */ 57 80 virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const /* override */; 58 59 81 }; 82 83 84 /********************************************************************************************************************************* 85 * UIVisoContentTableView implementation. * 86 *********************************************************************************************************************************/ 87 UIVisoContentTableView::UIVisoContentTableView(QWidget *pParent /* = 0 */) 88 :QTableView(pParent) 89 { 90 } 91 92 void UIVisoContentTableView::dragMoveEvent(QDragMoveEvent *event) 93 { 94 event->acceptProposedAction(); 95 96 } 97 98 void UIVisoContentTableView::dragEnterEvent(QDragEnterEvent *pEvent) 99 { 100 if (pEvent->mimeData()->hasFormat("application/vnd.text.list")) 101 pEvent->accept(); 102 else 103 pEvent->ignore(); 104 } 105 106 void UIVisoContentTableView::dropEvent(QDropEvent *pEvent) 107 { 108 if (pEvent->mimeData()->hasFormat("application/vnd.text.list")) 109 { 110 QByteArray itemData = pEvent->mimeData()->data("application/vnd.text.list"); 111 QDataStream stream(&itemData, QIODevice::ReadOnly); 112 QStringList pathList; 113 114 while (!stream.atEnd()) { 115 QString text; 116 stream >> text; 117 pathList << text; 118 } 119 emit sigNewItemsDropped(pathList); 120 } 121 } 60 122 61 123 … … 94 156 UIVisoContentBrowser::UIVisoContentBrowser(QWidget *pParent) 95 157 : QIWithRetranslateUI<UIVisoBrowserBase>(pParent) 158 , m_pTableView(0) 96 159 , m_pModel(0) 97 160 , m_pTableProxyModel(0) … … 342 405 } 343 406 407 m_pTableView = new UIVisoContentTableView; 344 408 if (m_pTableView) 345 409 { 410 m_pRightContainerLayout->addWidget(m_pTableView, 0, 0, 6, 4); 411 m_pTableView->setSelectionMode(QAbstractItemView::ContiguousSelection); 412 m_pTableView->setShowGrid(false); 413 m_pTableView->setSelectionBehavior(QAbstractItemView::SelectRows); 414 m_pTableView->setEditTriggers(QAbstractItemView::NoEditTriggers); 415 m_pTableView->setAlternatingRowColors(true); 416 QHeaderView *pVerticalHeader = m_pTableView->verticalHeader(); 417 if (pVerticalHeader) 418 { 419 m_pTableView->verticalHeader()->setVisible(false); 420 /* Minimize the row height: */ 421 m_pTableView->verticalHeader()->setDefaultSectionSize(m_pTableView->verticalHeader()->minimumSectionSize()); 422 } 423 QHeaderView *pHorizontalHeader = m_pTableView->horizontalHeader(); 424 if (pHorizontalHeader) 425 { 426 pHorizontalHeader->setHighlightSections(false); 427 pHorizontalHeader->setSectionResizeMode(QHeaderView::Stretch); 428 } 429 346 430 m_pTableView->setModel(m_pTableProxyModel); 347 431 setTableRootIndex(); … … 353 437 m_pTableView->setSortingEnabled(true); 354 438 m_pTableView->sortByColumn(0, Qt::AscendingOrder); 439 440 m_pTableView->setDragEnabled(false); 441 m_pTableView->setAcceptDrops(true); 442 m_pTableView->setDropIndicatorShown(true); 443 m_pTableView->setDragDropMode(QAbstractItemView::DropOnly); 355 444 } 356 445 … … 397 486 { 398 487 UIVisoBrowserBase::prepareConnections(); 488 489 if (m_pTableView) 490 { 491 connect(m_pTableView, &UIVisoContentTableView::doubleClicked, 492 this, &UIVisoBrowserBase::sltHandleTableViewItemDoubleClick); 493 connect(m_pTableView, &UIVisoContentTableView::sigNewItemsDropped, 494 this, &UIVisoContentBrowser::sltHandleDroppedItems); 495 } 496 399 497 if (m_pNewDirectoryAction) 400 498 connect(m_pNewDirectoryAction, &QAction::triggered, … … 668 766 } 669 767 768 void UIVisoContentBrowser::sltHandleDroppedItems(QStringList pathList) 769 { 770 addObjectsToViso(pathList); 771 } 772 670 773 void UIVisoContentBrowser::reset() 671 774 { -
trunk/src/VBox/Frontends/VirtualBox/src/medium/viso/UIVisoContentBrowser.h
r76750 r76762 43 43 class UIVisoContentTreeProxyModel; 44 44 class UICustomFileSystemItem; 45 class UIVisoContentTableView; 45 46 46 47 class SHARED_LIBRARY_STUFF UIVisoContentBrowser : public QIWithRetranslateUI<UIVisoBrowserBase> … … 79 80 void sltHandleTableSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected); 80 81 void sltHandleResetAction(); 82 void sltHandleDroppedItems(QStringList pathList); 81 83 82 84 private: … … 101 103 * in the table view. */ 102 104 QList<UICustomFileSystemItem*> tableSelectedItems(); 103 105 UIVisoContentTableView *m_pTableView; 104 106 UICustomFileSystemModel *m_pModel; 105 107 UICustomFileSystemProxyModel *m_pTableProxyModel; -
trunk/src/VBox/Frontends/VirtualBox/src/medium/viso/UIVisoHostBrowser.cpp
r76750 r76762 20 20 #include <QDir> 21 21 #include <QFileSystemModel> 22 #include <QGridLayout> 22 23 #include <QHeaderView> 23 24 #include <QLabel> 24 25 #include <QListView> 26 #include <QMimeData> 25 27 #include <QTableView> 26 28 #include <QTreeView> … … 44 46 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const /* override */; 45 47 UIVisoHostBrowserModel(QObject *pParent); 48 49 virtual QStringList mimeTypes() const /* override */; 50 /** Prepares the mime data as a list of text consisting of dragged objects full file path. */ 51 QMimeData *mimeData(const QModelIndexList &indexes) const /* override */; 46 52 47 53 protected: … … 78 84 } 79 85 86 QStringList UIVisoHostBrowserModel::mimeTypes() const 87 { 88 QStringList types; 89 types << "application/vnd.text.list"; 90 return types; 91 } 92 93 QMimeData *UIVisoHostBrowserModel::mimeData(const QModelIndexList &indexes) const 94 { 95 QMimeData *mimeData = new QMimeData(); 96 QByteArray encodedData; 97 98 QDataStream stream(&encodedData, QIODevice::WriteOnly); 99 100 foreach (const QModelIndex &index, indexes) { 101 if (index.isValid() && index.column() == 0) 102 { 103 QString strPath = fileInfo(index).filePath(); 104 if (!strPath.contains("..")) 105 stream << fileInfo(index).filePath(); 106 } 107 } 108 109 mimeData->setData("application/vnd.text.list", encodedData); 110 return mimeData; 111 } 112 80 113 /********************************************************************************************************************************* 81 114 * UIVisoHostBrowser implementation. * … … 87 120 , m_pTableModel(0) 88 121 , m_pAddAction(0) 122 , m_pTableView(0) 89 123 { 90 124 prepareObjects(); … … 128 162 } 129 163 164 m_pTableView = new QTableView; 130 165 if (m_pTableView) 131 166 { 167 m_pRightContainerLayout->addWidget(m_pTableView, 0, 0, 6, 4); 168 m_pTableView->setSelectionMode(QAbstractItemView::ContiguousSelection); 169 m_pTableView->setShowGrid(false); 170 m_pTableView->setSelectionBehavior(QAbstractItemView::SelectRows); 171 m_pTableView->setEditTriggers(QAbstractItemView::NoEditTriggers); 172 m_pTableView->setAlternatingRowColors(true); 173 QHeaderView *pVerticalHeader = m_pTableView->verticalHeader(); 174 if (pVerticalHeader) 175 { 176 m_pTableView->verticalHeader()->setVisible(false); 177 /* Minimize the row height: */ 178 m_pTableView->verticalHeader()->setDefaultSectionSize(m_pTableView->verticalHeader()->minimumSectionSize()); 179 } 180 QHeaderView *pHorizontalHeader = m_pTableView->horizontalHeader(); 181 if (pHorizontalHeader) 182 { 183 pHorizontalHeader->setHighlightSections(false); 184 pHorizontalHeader->setSectionResizeMode(QHeaderView::Stretch); 185 } 186 132 187 m_pTableView->setModel(m_pTableModel); 133 188 setTableRootIndex(); 134 189 /* Hide the "type" column: */ 135 190 m_pTableView->hideColumn(2); 191 192 m_pTableView->setSelectionMode(QAbstractItemView::ExtendedSelection); 193 m_pTableView->setDragDropMode(QAbstractItemView::DragOnly); 136 194 } 137 195 … … 154 212 { 155 213 UIVisoBrowserBase::prepareConnections(); 214 if (m_pTableView) 215 connect(m_pTableView, &QTableView::doubleClicked, 216 this, &UIVisoBrowserBase::sltHandleTableViewItemDoubleClick); 217 156 218 if (m_pTableView->selectionModel()) 157 219 connect(m_pTableView->selectionModel(), &QItemSelectionModel::selectionChanged, -
trunk/src/VBox/Frontends/VirtualBox/src/medium/viso/UIVisoHostBrowser.h
r76750 r76762 71 71 UIVisoHostBrowserModel *m_pTableModel; 72 72 QAction *m_pAddAction; 73 QTableView *m_pTableView; 74 73 75 }; 74 76
Note:
See TracChangeset
for help on using the changeset viewer.