From ecec774c83e5ab11c5d7b28ef526301b60863439 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9ry=20Mathieu=20=28Mathius=29?= Date: Mon, 19 Feb 2024 20:55:41 +0100 Subject: [PATCH] feat(dialogSettings): Allow to remove folder in monitoring tab with Delete or BackSpace key --- src/dialogsettings.cpp | 28 ++++++++++++++++++++++++++-- src/dialogsettings.h | 5 +++++ src/dialogsettings.ui | 7 ++++++- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/dialogsettings.cpp b/src/dialogsettings.cpp index f23dca5d..6eefe19b 100644 --- a/src/dialogsettings.cpp +++ b/src/dialogsettings.cpp @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -117,6 +119,10 @@ DialogSettings::DialogSettings( QWidget *parent) mAccountModel = new ModelAccountTree(this, treeAccounts); treeAccounts->header()->setSectionResizeMode(QHeaderView::ResizeToContents); treeAccounts->setCurrentIndex(mAccountModel->index(0, 0)); + treeAccounts->onKeyPressed(this, [](void * handle, QKeyEvent * event) + { + static_cast(handle)->onKeyPressedOnTreeAccount(event); + }); // New emails tab mModelNewEmails = new ModelNewEmails( this ); @@ -150,6 +156,14 @@ DialogSettings::DialogSettings( QWidget *parent) #endif } +void DialogSettings::onKeyPressedOnTreeAccount(QKeyEvent * event) +{ + if (event->key() == Qt::Key_Delete || event->key() == Qt::Key_Backspace) + { + accountRemove(); + } +} + void DialogSettings::accept() { BirdtrayApp* app = BirdtrayApp::get(); @@ -285,8 +299,13 @@ void DialogSettings::accountEditIndex(const QModelIndex &index) void DialogSettings::accountRemove() { - QModelIndex index = treeAccounts->currentIndex(); + if ( treeAccounts->currentIndex().isValid() ) + accountRemoveIndex( treeAccounts->currentIndex() ); +} + +void DialogSettings::accountRemoveIndex(const QModelIndex &index) +{ if ( !index.isValid() ) return; @@ -311,7 +330,12 @@ void DialogSettings::newEmailEditIndex(const QModelIndex &index) void DialogSettings::newEmailRemove() { - mModelNewEmails->remove( treeNewEmails->currentIndex() ); + newEmailRemoveIndex( treeNewEmails->currentIndex() ); +} + +void DialogSettings::newEmailRemoveIndex(const QModelIndex &index) +{ + mModelNewEmails->remove( index ); } void DialogSettings::onCheckUpdateButton() { diff --git a/src/dialogsettings.h b/src/dialogsettings.h index df83f153..35cb4790 100644 --- a/src/dialogsettings.h +++ b/src/dialogsettings.h @@ -2,6 +2,7 @@ #define SETTINGSDIALOG_H #include +#include #include #include #include @@ -51,12 +52,14 @@ class DialogSettings : public QDialog, public Ui::DialogSettings void accountEdit(); void accountEditIndex( const QModelIndex& index ); void accountRemove(); + void accountRemoveIndex( const QModelIndex& index ); // New Email buttons void newEmailAdd(); void newEmailEdit(); void newEmailEditIndex( const QModelIndex& index ); void newEmailRemove(); + void newEmailRemoveIndex( const QModelIndex& index ); // Advanced buttons void onCheckUpdateButton(); @@ -77,6 +80,8 @@ class DialogSettings : public QDialog, public Ui::DialogSettings */ static void onTranslatorsDialog(); + void onKeyPressedOnTreeAccount(QKeyEvent * event); + private: void changeIcon(QToolButton * button ); diff --git a/src/dialogsettings.ui b/src/dialogsettings.ui index 1a7029b8..391269c2 100644 --- a/src/dialogsettings.ui +++ b/src/dialogsettings.ui @@ -291,7 +291,7 @@ - + true @@ -1167,6 +1167,11 @@ p, li { white-space: pre-wrap; } QPushButton
colorbutton.h
+ + QTreeViewWithKeyEvents + QTreeView +
qtcomponents.h
+
tabWidget