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.
This commit is contained in:
parent
a2e8741449
commit
d5d8492bb3
@ -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));
|
||||
|
Loading…
x
Reference in New Issue
Block a user