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

Allow to remove KLineEdit

parent db153569
......@@ -24,7 +24,7 @@
#include <QDialogButtonBox>
#include <QVBoxLayout>
#include <QLabel>
#include <KLineEdit>
#include <QLineEdit>
#include <QPushButton>
SelectHeadersDialogTest::SelectHeadersDialogTest(QObject *parent)
......@@ -56,10 +56,9 @@ void SelectHeadersDialogTest::shouldHaveDefaultValue()
QVERIFY(lab);
QVERIFY(!lab->text().isEmpty());
KLineEdit *mNewHeader = dlg.findChild<KLineEdit *>(QStringLiteral("newheader"));
QLineEdit *mNewHeader = dlg.findChild<QLineEdit *>(QStringLiteral("newheader"));
QVERIFY(mNewHeader);
QVERIFY(mNewHeader->isClearButtonEnabled());
QVERIFY(mNewHeader->trapReturnKey());
QPushButton *mAddNewHeader = dlg.findChild<QPushButton *>(QStringLiteral("addnewheader"));
QVERIFY(mAddNewHeader);
......
......@@ -30,6 +30,8 @@
#include <KSharedConfig>
#include <QDialogButtonBox>
#include <KConfigGroup>
#include <QEvent>
#include <QKeyEvent>
using namespace KSieveUi;
......@@ -64,11 +66,12 @@ SelectHeadersDialog::SelectHeadersDialog(QWidget *parent)
QHBoxLayout *hbox = new QHBoxLayout;
mNewHeader = new KLineEdit(this);
mNewHeader = new QLineEdit(this);
new LineEditCatchReturnKey(mNewHeader, this);
mNewHeader->setObjectName(QStringLiteral("newheader"));
mNewHeader->setClearButtonEnabled(true);
mNewHeader->setTrapReturnKey(true);
connect(mNewHeader, &KLineEdit::returnPressed, this, &SelectHeadersDialog::slotAddNewHeader);
//mNewHeader->setTrapReturnKey(true);
connect(mNewHeader, &QLineEdit::returnPressed, this, &SelectHeadersDialog::slotAddNewHeader);
mNewHeader->setClearButtonEnabled(true);
mAddNewHeader = new QPushButton(this);
......@@ -77,7 +80,7 @@ SelectHeadersDialog::SelectHeadersDialog(QWidget *parent)
mAddNewHeader->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
mAddNewHeader->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
connect(mAddNewHeader, &QPushButton::clicked, this, &SelectHeadersDialog::slotAddNewHeader);
connect(mNewHeader, &KLineEdit::textChanged, this, &SelectHeadersDialog::slotNewHeaderTextChanged);
connect(mNewHeader, &QLineEdit::textChanged, this, &SelectHeadersDialog::slotNewHeaderTextChanged);
hbox->addWidget(mNewHeader);
hbox->addWidget(mAddNewHeader);
......@@ -320,3 +323,33 @@ void SelectHeaderTypeComboBox::setCode(const QString &code)
mCode = code;
changeReadOnlyStatus();
}
LineEditCatchReturnKey::LineEditCatchReturnKey(QLineEdit *lineEdit, QObject *parent)
: QObject(parent)
, mLineEdit(lineEdit)
{
mLineEdit->installEventFilter(this);
}
LineEditCatchReturnKey::~LineEditCatchReturnKey()
{
}
bool LineEditCatchReturnKey::eventFilter(QObject *obj, QEvent *event)
{
if (obj == mLineEdit) {
if (event->type() == QEvent::KeyPress) {
QKeyEvent *e = static_cast<QKeyEvent *>(event);
if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
const bool stopEvent = (e->modifiers() == Qt::NoButton ||
e->modifiers() == Qt::KeypadModifier);
if (stopEvent) {
Q_EMIT mLineEdit->returnPressed();
}
return true;
}
}
}
return QObject::eventFilter(obj, event);
}
......@@ -27,6 +27,20 @@
class KLineEdit;
class QPushButton;
namespace KSieveUi {
class LineEditCatchReturnKey : public QObject
{
Q_OBJECT
public:
explicit LineEditCatchReturnKey(QLineEdit *lineEdit, QObject *parent = nullptr);
~LineEditCatchReturnKey();
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
private:
QLineEdit *mLineEdit = nullptr;
};
class SelectHeadersWidget : public QListWidget
{
Q_OBJECT
......@@ -61,7 +75,7 @@ private:
void readConfig();
void writeConfig();
SelectHeadersWidget *mListWidget = nullptr;
KLineEdit *mNewHeader = nullptr;
QLineEdit *mNewHeader = nullptr;
QPushButton *mAddNewHeader = 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