enable multiple selection in file list

Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
Le Tan 2016-12-03 17:42:09 +08:00
parent 02d5300821
commit 46c8025215
3 changed files with 20 additions and 5 deletions

View File

@ -483,6 +483,17 @@ void VDirectoryTree::mousePressEvent(QMouseEvent *event)
QTreeWidget::mousePressEvent(event); QTreeWidget::mousePressEvent(event);
} }
void VDirectoryTree::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Return) {
QTreeWidgetItem *item = currentItem();
if (item) {
item->setExpanded(!item->isExpanded());
}
}
QTreeWidget::keyPressEvent(event);
}
bool VDirectoryTree::copyDirectory(VDirectory *p_destDir, const QString &p_destName, bool VDirectoryTree::copyDirectory(VDirectory *p_destDir, const QString &p_destName,
VDirectory *p_srcDir, bool p_cut) VDirectory *p_srcDir, bool p_cut)
{ {

View File

@ -38,6 +38,7 @@ private slots:
protected: protected:
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
private: private:
void updateDirectoryTreeOne(QTreeWidgetItem *p_parent, int depth); void updateDirectoryTreeOne(QTreeWidgetItem *p_parent, int depth);

View File

@ -20,6 +20,7 @@ void VFileList::setupUI()
{ {
fileList = new QListWidget(this); fileList = new QListWidget(this);
fileList->setContextMenuPolicy(Qt::CustomContextMenu); fileList->setContextMenuPolicy(Qt::CustomContextMenu);
fileList->setSelectionMode(QAbstractItemView::ExtendedSelection);
QVBoxLayout *mainLayout = new QVBoxLayout; QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(fileList); mainLayout->addWidget(fileList);
@ -27,7 +28,7 @@ void VFileList::setupUI()
connect(fileList, &QListWidget::customContextMenuRequested, connect(fileList, &QListWidget::customContextMenuRequested,
this, &VFileList::contextMenuRequested); this, &VFileList::contextMenuRequested);
connect(fileList, &QListWidget::itemClicked, connect(fileList, &QListWidget::itemActivated,
this, &VFileList::handleItemClicked); this, &VFileList::handleItemClicked);
setLayout(mainLayout); setLayout(mainLayout);
@ -221,9 +222,11 @@ QVector<QListWidgetItem *> VFileList::updateFileListAdded()
// Delete the file related to current item // Delete the file related to current item
void VFileList::deleteFile() void VFileList::deleteFile()
{ {
QListWidgetItem *curItem = fileList->currentItem(); QList<QListWidgetItem *> items = fileList->selectedItems();
Q_ASSERT(curItem); Q_ASSERT(!items.isEmpty());
deleteFile(getVFile(curItem)); for (int i = 0; i < items.size(); ++i) {
deleteFile(getVFile(items.at(i)));
}
} }
// @p_file may or may not be listed in VFileList // @p_file may or may not be listed in VFileList
@ -274,7 +277,7 @@ void VFileList::contextMenuRequested(QPoint pos)
menu.addAction(pasteAct); menu.addAction(pasteAct);
} }
if (item) { if (item && fileList->selectedItems().size() == 1) {
menu.addSeparator(); menu.addSeparator();
menu.addAction(fileInfoAct); menu.addAction(fileInfoAct);
} }