提交 d5d8492b 编写于 作者: J jp9000

UI: Add LineEditChanged and LineEditCanceled

These functions allow item delegates (editors) or item widgets with
event filters to detect whether a user has finished editing a line edit
control.  This separates the code so it can be used elsewhere than just
in the source tree widget.
上级 a2e87414
......@@ -24,6 +24,7 @@
#include <QLayout>
#include <QMessageBox>
#include <QDataStream>
#include <QKeyEvent>
#if !defined(_WIN32) && !defined(__APPLE__)
#include <QX11Info>
......@@ -293,3 +294,32 @@ void ExecThreadedWithoutBlocking(std::function<void()> func,
else
ExecuteFuncSafeBlockMsgBox(func, title, text);
}
bool LineEditCanceled(QEvent *event)
{
if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = reinterpret_cast<QKeyEvent *>(event);
return keyEvent->key() == Qt::Key_Escape;
}
return false;
}
bool LineEditChanged(QEvent *event)
{
if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = reinterpret_cast<QKeyEvent *>(event);
switch (keyEvent->key()) {
case Qt::Key_Tab:
case Qt::Key_Backtab:
case Qt::Key_Enter:
case Qt::Key_Return:
return true;
}
} else if (event->type() == QEvent::FocusOut) {
return true;
}
return false;
}
......@@ -102,3 +102,6 @@ static inline Qt::ConnectionType WaitConnection()
? Qt::DirectConnection
: Qt::BlockingQueuedConnection;
}
bool LineEditCanceled(QEvent *event);
bool LineEditChanged(QEvent *event);
......@@ -342,25 +342,13 @@ bool SourceTreeItem::eventFilter(QObject *object, QEvent *event)
if (editor != object)
return false;
if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
switch (keyEvent->key()) {
case Qt::Key_Escape:
QMetaObject::invokeMethod(this, "ExitEditMode",
Qt::QueuedConnection,
Q_ARG(bool, false));
return true;
case Qt::Key_Tab:
case Qt::Key_Backtab:
case Qt::Key_Enter:
case Qt::Key_Return:
QMetaObject::invokeMethod(this, "ExitEditMode",
Qt::QueuedConnection,
Q_ARG(bool, true));
return true;
}
} else if (event->type() == QEvent::FocusOut) {
if (LineEditCanceled(event)) {
QMetaObject::invokeMethod(this, "ExitEditMode",
Qt::QueuedConnection,
Q_ARG(bool, false));
return true;
}
if (LineEditChanged(event)) {
QMetaObject::invokeMethod(this, "ExitEditMode",
Qt::QueuedConnection,
Q_ARG(bool, true));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册