Skip to content

Commit

Permalink
feat(dialogSettings): Allow to remove folder in monitoring tab with D…
Browse files Browse the repository at this point in the history
…elete or BackSpace key
  • Loading branch information
MathiusD committed Feb 19, 2024
1 parent c13cf65 commit ecec774
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
28 changes: 26 additions & 2 deletions src/dialogsettings.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <Qt>

#include <QFileDialog>
#include <QColorDialog>
#include <QMessageBox>
Expand Down Expand Up @@ -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<DialogSettings*>(handle)->onKeyPressedOnTreeAccount(event);
});

// New emails tab
mModelNewEmails = new ModelNewEmails( this );
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;

Expand All @@ -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() {
Expand Down
5 changes: 5 additions & 0 deletions src/dialogsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define SETTINGSDIALOG_H

#include <QDialog>
#include <QKeyEvent>
#include <QProgressDialog>
#include <QPalette>
#include <QtCore/QStringListModel>
Expand Down Expand Up @@ -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();
Expand All @@ -77,6 +80,8 @@ class DialogSettings : public QDialog, public Ui::DialogSettings
*/
static void onTranslatorsDialog();

void onKeyPressedOnTreeAccount(QKeyEvent * event);

private:
void changeIcon(QToolButton * button );

Expand Down
7 changes: 6 additions & 1 deletion src/dialogsettings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QTreeView" name="treeAccounts">
<widget class="QTreeViewWithKeyEvents" name="treeAccounts">
<property name="enabled">
<bool>true</bool>
</property>
Expand Down Expand Up @@ -1167,6 +1167,11 @@ p, li { white-space: pre-wrap; }
<extends>QPushButton</extends>
<header>colorbutton.h</header>
</customwidget>
<customwidget>
<class>QTreeViewWithKeyEvents</class>
<extends>QTreeView</extends>
<header>qtcomponents.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>tabWidget</tabstop>
Expand Down

0 comments on commit ecec774

Please sign in to comment.