File indexing completed on 2024-04-28 15:27:42

0001 /*
0002  * SPDX-FileCopyrightText: 2021 Arjen Hiemstra <ahiemstra@heimr.nl>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #include "inputmethod.h"
0008 
0009 #include "libkirigami/virtualkeyboardwatcher.h"
0010 
0011 class Q_DECL_HIDDEN InputMethod::Private
0012 {
0013 public:
0014     bool available = false;
0015     bool enabled = false;
0016     bool active = false;
0017     bool visible = false;
0018 };
0019 
0020 InputMethod::InputMethod(QObject *parent)
0021     : QObject(parent)
0022     , d(std::make_unique<Private>())
0023 {
0024     auto watcher = Kirigami::VirtualKeyboardWatcher::self();
0025 
0026     connect(watcher, &Kirigami::VirtualKeyboardWatcher::availableChanged, this, [this]() {
0027         d->available = Kirigami::VirtualKeyboardWatcher::self()->available();
0028         Q_EMIT availableChanged();
0029     });
0030 
0031     connect(watcher, &Kirigami::VirtualKeyboardWatcher::enabledChanged, this, [this]() {
0032         d->enabled = Kirigami::VirtualKeyboardWatcher::self()->enabled();
0033         Q_EMIT enabledChanged();
0034     });
0035 
0036     connect(watcher, &Kirigami::VirtualKeyboardWatcher::activeChanged, this, [this]() {
0037         d->active = Kirigami::VirtualKeyboardWatcher::self()->active();
0038         Q_EMIT activeChanged();
0039     });
0040 
0041     connect(watcher, &Kirigami::VirtualKeyboardWatcher::visibleChanged, this, [this]() {
0042         d->visible = Kirigami::VirtualKeyboardWatcher::self()->visible();
0043         Q_EMIT visibleChanged();
0044     });
0045 
0046     connect(watcher, &Kirigami::VirtualKeyboardWatcher::willShowOnActiveChanged, this, [this]() {
0047         Q_EMIT willShowOnActiveChanged();
0048     });
0049 
0050     d->available = watcher->available();
0051     d->enabled = watcher->enabled();
0052     d->active = watcher->active();
0053     d->visible = watcher->visible();
0054 }
0055 
0056 InputMethod::~InputMethod() = default;
0057 
0058 bool InputMethod::available() const
0059 {
0060     return d->available;
0061 }
0062 
0063 bool InputMethod::enabled() const
0064 {
0065     return d->enabled;
0066 }
0067 
0068 void InputMethod::setEnabled(bool newEnabled)
0069 {
0070     if (newEnabled == d->enabled) {
0071         return;
0072     }
0073 
0074     d->enabled = newEnabled;
0075     Q_EMIT enabledChanged();
0076 }
0077 
0078 bool InputMethod::active() const
0079 {
0080     return d->active;
0081 }
0082 
0083 void InputMethod::setActive(bool newActive)
0084 {
0085     if (newActive == d->active) {
0086         return;
0087     }
0088 
0089     d->active = newActive;
0090     Q_EMIT activeChanged();
0091 }
0092 
0093 bool InputMethod::visible() const
0094 {
0095     return d->visible;
0096 }
0097 
0098 bool InputMethod::willShowOnActive() const
0099 {
0100     return Kirigami::VirtualKeyboardWatcher::self()->willShowOnActive();
0101 }
0102 
0103 #include "moc_inputmethod.cpp"