1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-09 14:27:56 +00:00

Improved context menu behavior (multiple selection)

This commit is contained in:
Christophe Dumez 2010-11-13 16:00:14 +00:00
parent c47dbfb1f5
commit 578a5c9551

View File

@ -48,6 +48,7 @@ AutomatedRssDownloader::AutomatedRssDownloader(QWidget *parent) :
{ {
ui->setupUi(this); ui->setupUi(this);
ui->listRules->setSortingEnabled(true); ui->listRules->setSortingEnabled(true);
ui->listRules->setSelectionMode(QAbstractItemView::MultiSelection);
connect(ui->listRules, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayRulesListMenu(const QPoint&))); connect(ui->listRules, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayRulesListMenu(const QPoint&)));
m_ruleList = RssDownloadRuleList::instance(); m_ruleList = RssDownloadRuleList::instance();
initLabelCombobox(); initLabelCombobox();
@ -249,17 +250,24 @@ void AutomatedRssDownloader::on_addRuleBtn_clicked()
void AutomatedRssDownloader::on_removeRuleBtn_clicked() void AutomatedRssDownloader::on_removeRuleBtn_clicked()
{ {
QListWidgetItem * item = ui->listRules->currentItem(); const QList<QListWidgetItem*> selection = ui->listRules->selectedItems();
if(!item) return; if(selection.isEmpty()) return;
// Ask for confirmation // Ask for confirmation
if(QMessageBox::question(this, tr("Rule deletion confirmation"), tr("Are you sure you want to remove the download rule named %1?").arg(item->text()), QMessageBox::Yes, QMessageBox::No) != QMessageBox::Yes) QString confirm_text;
if(selection.count() == 1)
confirm_text = tr("Are you sure you want to remove the download rule named %1?").arg(selection.first()->text());
else
confirm_text = tr("Are you sure you want to remove the selected download rules?");
if(QMessageBox::question(this, tr("Rule deletion confirmation"), confirm_text, QMessageBox::Yes, QMessageBox::No) != QMessageBox::Yes)
return; return;
// Actually remove the item foreach(QListWidgetItem *item, selection) {
ui->listRules->removeItemWidget(item); // Actually remove the item
// Remove it from the m_ruleList ui->listRules->removeItemWidget(item);
m_ruleList->removeRule(item->text()); // Remove it from the m_ruleList
// Clean up memory m_ruleList->removeRule(item->text());
delete item; // Clean up memory
delete item;
}
} }
void AutomatedRssDownloader::on_browseSP_clicked() void AutomatedRssDownloader::on_browseSP_clicked()
@ -308,9 +316,13 @@ void AutomatedRssDownloader::displayRulesListMenu(const QPoint &pos)
QAction *delAct = 0; QAction *delAct = 0;
QAction *renameAct = 0; QAction *renameAct = 0;
if(!ui->listRules->selectedItems().isEmpty()) { if(!ui->listRules->selectedItems().isEmpty()) {
delAct = menu.addAction(QIcon(":/Icons/oxygen/list-remove.png"), tr("Delete rule")); if(ui->listRules->selectedItems().count() == 1) {
menu.addSeparator(); delAct = menu.addAction(QIcon(":/Icons/oxygen/list-remove.png"), tr("Delete rule"));
renameAct = menu.addAction(QIcon(":/Icons/oxygen/edit_clear.png"), tr("Rename rule...")); menu.addSeparator();
renameAct = menu.addAction(QIcon(":/Icons/oxygen/edit_clear.png"), tr("Rename rule..."));
} else {
delAct = menu.addAction(QIcon(":/Icons/oxygen/list-remove.png"), tr("Delete selected rules"));
}
} }
QAction *act = menu.exec(QCursor::pos()); QAction *act = menu.exec(QCursor::pos());
if(!act) return; if(!act) return;