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);
}
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,
VDirectory *p_srcDir, bool p_cut)
{

View File

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

View File

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