File indexing completed on 2024-05-05 03:56:26

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 "virtualkeyboardwatcher.h"
0010 
0011 namespace Kirigami
0012 {
0013 namespace Platform
0014 {
0015 
0016 class KIRIGAMIPLATFORM_NO_EXPORT InputMethod::Private
0017 {
0018 public:
0019     bool available = false;
0020     bool enabled = false;
0021     bool active = false;
0022     bool visible = false;
0023 };
0024 
0025 InputMethod::InputMethod(QObject *parent)
0026     : QObject(parent)
0027     , d(std::make_unique<Private>())
0028 {
0029     auto watcher = VirtualKeyboardWatcher::self();
0030 
0031     connect(watcher, &VirtualKeyboardWatcher::availableChanged, this, [this]() {
0032         d->available = VirtualKeyboardWatcher::self()->available();
0033         Q_EMIT availableChanged();
0034     });
0035 
0036     connect(watcher, &VirtualKeyboardWatcher::enabledChanged, this, [this]() {
0037         d->enabled = VirtualKeyboardWatcher::self()->enabled();
0038         Q_EMIT enabledChanged();
0039     });
0040 
0041     connect(watcher, &VirtualKeyboardWatcher::activeChanged, this, [this]() {
0042         d->active = VirtualKeyboardWatcher::self()->active();
0043         Q_EMIT activeChanged();
0044     });
0045 
0046     connect(watcher, &VirtualKeyboardWatcher::visibleChanged, this, [this]() {
0047         d->visible = VirtualKeyboardWatcher::self()->visible();
0048         Q_EMIT visibleChanged();
0049     });
0050 
0051     connect(watcher, &VirtualKeyboardWatcher::willShowOnActiveChanged, this, [this]() {
0052         Q_EMIT willShowOnActiveChanged();
0053     });
0054 
0055     d->available = watcher->available();
0056     d->enabled = watcher->enabled();
0057     d->active = watcher->active();
0058     d->visible = watcher->visible();
0059 }
0060 
0061 InputMethod::~InputMethod() = default;
0062 
0063 bool InputMethod::available() const
0064 {
0065     return d->available;
0066 }
0067 
0068 bool InputMethod::enabled() const
0069 {
0070     return d->enabled;
0071 }
0072 
0073 bool InputMethod::active() const
0074 {
0075     return d->active;
0076 }
0077 
0078 bool InputMethod::visible() const
0079 {
0080     return d->visible;
0081 }
0082 
0083 bool InputMethod::willShowOnActive() const
0084 {
0085     return VirtualKeyboardWatcher::self()->willShowOnActive();
0086 }
0087 
0088 }
0089 }
0090 
0091 #include "moc_inputmethod.cpp"