swift
Loading...
Searching...
No Matches
src
gui
eventfilter.cpp
1
// SPDX-FileCopyrightText: Copyright (C) 2019 swift Project Community / Contributors
2
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
4
#include "
eventfilter.h
"
5
6
#include <QKeyEvent>
7
#include <QPlainTextEdit>
8
9
#include "
misc/stringutils.h
"
10
11
namespace
swift::gui
12
{
13
bool
CUpperCaseEventFilter::eventFilter
(
QObject
*
object
,
QEvent
*
event
)
14
{
15
if
(
event
->type() ==
QEvent::KeyPress
)
16
{
17
if
(
auto
*e =
dynamic_cast<
QKeyEvent
*
>
(
event
))
18
{
19
// If QKeyEvent::text() returns an empty QString then let normal
20
// processing proceed as it may be a control (e.g. cursor movement)
21
// key. Otherwise convert the text to upper case and insert it at
22
// the current cursor position.
23
auto
*pte =
qobject_cast<QPlainTextEdit *>
(
object
);
24
if
(!pte)
25
{
26
return
false
;
27
}
28
if
(pte->isReadOnly())
29
{
30
return
false
;
31
}
32
33
if
(e->text().length() == 1)
34
{
35
const
QChar
c = e->text().front();
36
if
(c.
isLetter
())
37
{
38
const
ushort unicode = c.
unicode
();
39
if
(unicode > 127)
40
{
41
return
true
;
42
}
43
44
pte->insertPlainText(e->text().toUpper());
45
// return true to prevent further processing
46
return
true
;
47
}
48
// all codes like backspace etc.
49
return
false
;
50
}
// length
51
}
// key event
52
}
53
return
false
;
54
}
55
}
// namespace swift::gui
swift::gui::CUpperCaseEventFilter::eventFilter
bool eventFilter(QObject *object, QEvent *event)
Filter.
Definition
eventfilter.cpp:13
swift::gui::CUpperCaseEventFilter::QObject
QObject(QObject *parent)
eventfilter.h
swift::gui
GUI related classes.
Definition
altitudeedit.cpp:13
QChar
QChar::isLetter
bool isLetter(char32_t ucs4)
QChar::unicode
char16_t & unicode()
QEvent
QEvent::KeyPress
KeyPress
QKeyEvent
QObject::event
virtual bool event(QEvent *e)
QObject::qobject_cast
T qobject_cast(QObject *object)
stringutils.h
Generated on
for swift by
1.15.0