Commit d0ed9537 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Allow to double click for editing filter

parent c6392c37
......@@ -24,6 +24,7 @@ ConfigureFiltersWidget::ConfigureFiltersWidget(QWidget *parent)
mainLayout->addWidget(mListFiltersWidget);
mListFiltersWidget->setContextMenuPolicy(Qt::CustomContextMenu);
connect(mListFiltersWidget, &QListWidget::customContextMenuRequested, this, &ConfigureFiltersWidget::slotCustomContextMenuRequested);
connect(mListFiltersWidget, &QListWidget::itemDoubleClicked, this, &ConfigureFiltersWidget::slotConfigureFilter);
init();
}
......@@ -44,31 +45,40 @@ void ConfigureFiltersWidget::init()
}
}
void ConfigureFiltersWidget::slotConfigureFilter(QListWidgetItem *widgetItem)
{
if (widgetItem) {
auto item = static_cast<FilterListWidgetItem *>(widgetItem);
const QString identifier = item->identifier();
QPointer<FilterNameDialog> dlg = new FilterNameDialog(this);
dlg->setFilterName(item->text());
dlg->setIconName(item->iconName());
if (dlg->exec()) {
QString newName = dlg->filterName();
const QString newIconName = dlg->iconName();
newName = newName.trimmed();
if (!newName.isEmpty() && ((newName != item->text()) || (newIconName != item->iconName()))) {
updateFilterInfo(identifier, newName, newIconName);
item->setText(newName);
item->setIconName(newIconName);
item->setIcon(QIcon::fromTheme(newIconName));
}
}
delete dlg;
}
}
void ConfigureFiltersWidget::slotCustomContextMenuRequested(const QPoint &pos)
{
auto item = static_cast<FilterListWidgetItem *>(mListFiltersWidget->itemAt(pos));
if (item) {
QMenu menu(this);
const QString identifier = item->identifier();
menu.addAction(QIcon::fromTheme(QStringLiteral("edit-rename")), i18n("Configure..."), this, [this, identifier, item]() {
QPointer<FilterNameDialog> dlg = new FilterNameDialog(this);
dlg->setFilterName(item->text());
dlg->setIconName(item->iconName());
if (dlg->exec()) {
QString newName = dlg->filterName();
const QString newIconName = dlg->iconName();
newName = newName.trimmed();
if (!newName.isEmpty() && ((newName != item->text()) || (newIconName != item->iconName()))) {
updateFilterInfo(identifier, newName, newIconName);
item->setText(newName);
item->setIconName(newIconName);
item->setIcon(QIcon::fromTheme(newIconName));
}
}
delete dlg;
menu.addAction(QIcon::fromTheme(QStringLiteral("edit-rename")), i18n("Configure..."), this, [this, item]() {
slotConfigureFilter(item);
});
menu.addSeparator();
menu.addAction(QIcon::fromTheme(QStringLiteral("edit-delete")), i18n("Remove"), this, [this, identifier, item]() {
menu.addAction(QIcon::fromTheme(QStringLiteral("edit-delete")), i18n("Remove"), this, [this, item]() {
const QString identifier = item->identifier();
if (KMessageBox::questionYesNo(this, i18n("Do you want to delete this filter?"), i18n("Remove Filter")) == KMessageBox::Yes) {
removeFilterInfo(identifier);
delete item;
......
......@@ -42,6 +42,7 @@ private:
void updateFilterInfo(const QString &identifier, const QString &newName, const QString &newIconName = {});
void slotCustomContextMenuRequested(const QPoint &pos);
void removeFilterInfo(const QString &identifier);
void slotConfigureFilter(QListWidgetItem *item);
void init();
QListWidget *const mListFiltersWidget;
};
......
......@@ -24,6 +24,7 @@ FilterNameWidget::FilterNameWidget(QWidget *parent)
mainLayout->setContentsMargins({});
mName->setObjectName(QStringLiteral("mName"));
mName->setClearButtonEnabled(true);
mIconButton->setObjectName(QStringLiteral("mIconButton"));
mIconButton->setFixedSize(32, 32);
new KPIM::LineEditCatchReturnKey(mName, this);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment