Commit 0555557a authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Allow to change icon too

parent 271ba22f
Pipeline #79569 passed with stage
in 43 minutes and 45 seconds
......@@ -6,10 +6,11 @@
#include "configurefilterswidget.h"
#include "core/filtersavedmanager.h"
#include "filternamedialog.h"
#include <KLocalizedString>
#include <KMessageBox>
#include <QInputDialog>
#include <QMenu>
#include <QPointer>
#include <QVBoxLayout>
using namespace MessageList::Core;
ConfigureFiltersWidget::ConfigureFiltersWidget(QWidget *parent)
......@@ -37,6 +38,7 @@ void ConfigureFiltersWidget::init()
auto item = new FilterListWidgetItem(mListFiltersWidget);
item->setText(filter.filterName);
item->setIdentifier(filter.identifier);
item->setIconName(filter.iconName);
item->setIcon(QIcon::fromTheme(filter.iconName));
mListFiltersWidget->addItem(item);
}
......@@ -48,16 +50,22 @@ void ConfigureFiltersWidget::slotCustomContextMenuRequested(const QPoint &pos)
if (item) {
QMenu menu(this);
const QString identifier = item->identifier();
menu.addAction(QIcon::fromTheme(QStringLiteral("edit-rename")), i18n("Rename..."), this, [this, identifier, item]() {
bool ok = false;
QString newName = QInputDialog::getText(this, i18n("Rename Filter"), i18n("name"), QLineEdit::Normal, item->text(), &ok);
if (ok) {
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())) {
updateFilterInfo(identifier, newName);
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.addSeparator();
menu.addAction(QIcon::fromTheme(QStringLiteral("edit-delete")), i18n("Remove"), this, [this, identifier, item]() {
......@@ -77,10 +85,10 @@ void ConfigureFiltersWidget::removeFilterInfo(const QString &identifier)
}
}
void ConfigureFiltersWidget::updateFilterInfo(const QString &identifier, const QString &newName)
void ConfigureFiltersWidget::updateFilterInfo(const QString &identifier, const QString &newName, const QString &newIconName)
{
if (!identifier.isEmpty()) {
FilterSavedManager::self()->updateFilter(identifier, newName);
FilterSavedManager::self()->updateFilter(identifier, newName, newIconName);
}
}
......@@ -102,3 +110,13 @@ void FilterListWidgetItem::setIdentifier(const QString &newIdentifier)
{
mIdentifier = newIdentifier;
}
const QString &FilterListWidgetItem::iconName() const
{
return mIconName;
}
void FilterListWidgetItem::setIconName(const QString &newIconName)
{
mIconName = newIconName;
}
......@@ -20,11 +20,15 @@ public:
explicit FilterListWidgetItem(QListWidget *parent = nullptr);
~FilterListWidgetItem() override;
const QString &identifier() const;
Q_REQUIRED_RESULT const QString &identifier() const;
void setIdentifier(const QString &newIdentifier);
Q_REQUIRED_RESULT const QString &iconName() const;
void setIconName(const QString &newIconName);
private:
QString mIdentifier;
QString mIconName;
};
class MESSAGELIST_TESTS_EXPORT ConfigureFiltersWidget : public QWidget
......@@ -35,7 +39,7 @@ public:
~ConfigureFiltersWidget() override;
private:
void updateFilterInfo(const QString &identifier, const QString &newName);
void updateFilterInfo(const QString &identifier, const QString &newName, const QString &newIconName = {});
void slotCustomContextMenuRequested(const QPoint &pos);
void removeFilterInfo(const QString &identifier);
void init();
......
......@@ -35,6 +35,11 @@ FilterNameDialog::~FilterNameDialog()
{
}
void FilterNameDialog::setFilterName(const QString &str)
{
mFilterNameWidget->setFilterName(str);
}
QString FilterNameDialog::filterName() const
{
return mFilterNameWidget->filterName();
......@@ -49,3 +54,8 @@ void FilterNameDialog::setExistingFilterNames(const QStringList &lst)
{
mFilterNameWidget->setExistingFilterNames(lst);
}
void FilterNameDialog::setIconName(const QString &icon)
{
mFilterNameWidget->setIconName(icon);
}
......@@ -21,10 +21,12 @@ public:
explicit FilterNameDialog(QWidget *parent = nullptr);
~FilterNameDialog() override;
void setFilterName(const QString &str);
Q_REQUIRED_RESULT QString filterName() const;
void setExistingFilterNames(const QStringList &lst);
void setIconName(const QString &icon);
Q_REQUIRED_RESULT QString iconName() const;
private:
......
......@@ -44,6 +44,16 @@ FilterNameWidget::~FilterNameWidget()
{
}
void FilterNameWidget::setFilterName(const QString &str)
{
mName->setText(str);
}
void FilterNameWidget::setIconName(const QString &icon)
{
mIconButton->setIcon(QIcon::fromTheme(icon));
}
QString FilterNameWidget::filterName() const
{
return mName->text();
......
......@@ -21,6 +21,9 @@ public:
explicit FilterNameWidget(QWidget *parent = nullptr);
~FilterNameWidget() override;
void setFilterName(const QString &str);
void setIconName(const QString &icon);
Q_REQUIRED_RESULT QString filterName() const;
void setExistingFilterNames(const QStringList &lst);
......
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