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

Add lineeditcatchreturnkey for replacing KLineEdit

parent d35b55a4
cmake_minimum_required(VERSION 3.5)
set(PIM_VERSION "5.14.40")
set(PIM_VERSION "5.14.41")
project(libkdepim VERSION ${PIM_VERSION})
......
......@@ -55,6 +55,7 @@ set(kdepim_misc_LIB_SRCS
misc/emailvalidator.cpp
misc/maillistdrag.cpp
misc/uistatesaver.cpp
misc/lineeditcatchreturnkey.cpp
)
set(kdepim_multiplyingline_LIB_SRCS
......@@ -158,6 +159,7 @@ ecm_generate_headers(libkdepim_Camelcasemisc_HEADERS
MaillistDrag
UiStateSaver
KCursorSaver
LineEditCatchReturnKey
REQUIRED_HEADERS libkdepim_misc_HEADERS
PREFIX Libkdepim
RELATIVE misc
......
/*
Copyright (C) 2020 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "lineeditcatchreturnkey.h"
#include <QEvent>
#include <QKeyEvent>
#include <QLineEdit>
using namespace KPIM;
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);
}
/*
Copyright (C) 2020 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef LINEEDITCATCHRETURNKEY_H
#define LINEEDITCATCHRETURNKEY_H
#include <QObject>
#include "kdepim_export.h"
class QLineEdit;
namespace KPIM {
class KDEPIM_EXPORT 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;
};
}
#endif // LINEEDITCATCHRETURNKEY_H
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