Commit 4d466c88 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Avoid to close dialogbox when we press enter/return

parent d4776f62
Pipeline #69911 canceled with stage
......@@ -12,6 +12,7 @@
#include <KLocalizedString>
#include <KMessageBox>
#include <QHBoxLayout>
#include <QKeyEvent>
#include <QLabel>
#include <QListWidget>
#include <QMenu>
......@@ -45,10 +46,10 @@ CustomDebugSettingsPage::CustomDebugSettingsPage(QWidget *parent)
connect(mListWidget, &QListWidget::itemSelectionChanged, this, &CustomDebugSettingsPage::updateButtons);
connect(mListWidget, &QListWidget::itemDoubleClicked, this, &CustomDebugSettingsPage::slotEditRule);
connect(mListWidget, &QListWidget::customContextMenuRequested, this, &CustomDebugSettingsPage::slotCustomContextMenu);
auto searchLine = new KListWidgetSearchLine(this, mListWidget);
searchLine->setObjectName(QStringLiteral("searchline"));
searchLine->setPlaceholderText(i18n("Search..."));
vbox->addWidget(searchLine);
mTreeListWidgetSearchLine = new KListWidgetSearchLine(this, mListWidget);
mTreeListWidgetSearchLine->setObjectName(QStringLiteral("searchline"));
mTreeListWidgetSearchLine->setPlaceholderText(i18n("Search..."));
vbox->addWidget(mTreeListWidgetSearchLine);
vbox->addWidget(mListWidget);
auto buttonLayout = new QVBoxLayout;
......@@ -67,12 +68,25 @@ CustomDebugSettingsPage::CustomDebugSettingsPage(QWidget *parent)
buttonLayout->addStretch();
connect(mRemoveRule, &QAbstractButton::clicked, this, &CustomDebugSettingsPage::slotRemoveRules);
updateButtons();
mTreeListWidgetSearchLine->installEventFilter(this);
}
CustomDebugSettingsPage::~CustomDebugSettingsPage()
{
}
bool CustomDebugSettingsPage::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::KeyPress && obj == mTreeListWidgetSearchLine) {
auto key = static_cast<QKeyEvent *>(event);
if ((key->key() == Qt::Key_Enter) || (key->key() == Qt::Key_Return)) {
event->accept();
return true;
}
}
return QWidget::eventFilter(obj, event);
}
void CustomDebugSettingsPage::slotCustomContextMenu(const QPoint &pos)
{
QMenu menu(this);
......
......@@ -12,6 +12,7 @@
#include <QWidget>
class QListWidget;
class QPushButton;
class KListWidgetSearchLine;
class LIBKDEBUGSETTINGS_EXPORT CustomDebugSettingsPage : public QWidget
{
Q_OBJECT
......@@ -22,6 +23,9 @@ public:
void fillList(const LoggingCategory::List &list);
Q_REQUIRED_RESULT LoggingCategory::List rules() const;
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
private:
void slotRemoveRules();
void slotAddRule();
......@@ -33,5 +37,6 @@ private:
QPushButton *const mAddRule;
QPushButton *const mEditRule;
QPushButton *const mRemoveRule;
KListWidgetSearchLine *mTreeListWidgetSearchLine = nullptr;
};
Markdown is supported
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