Kirigami2

inputmethod.cpp
1 /*
2  * SPDX-FileCopyrightText: 2021 Arjen Hiemstra <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 
7 #include "inputmethod.h"
8 
9 #include "libkirigami/virtualkeyboardwatcher.h"
10 
11 class Q_DECL_HIDDEN InputMethod::Private
12 {
13 public:
14  bool available = false;
15  bool enabled = false;
16  bool active = false;
17  bool visible = false;
18 };
19 
20 InputMethod::InputMethod(QObject *parent)
21  : QObject(parent)
22  , d(std::make_unique<Private>())
23 {
24  auto watcher = Kirigami::VirtualKeyboardWatcher::self();
25 
26  connect(watcher, &Kirigami::VirtualKeyboardWatcher::availableChanged, this, [this]() {
27  d->available = Kirigami::VirtualKeyboardWatcher::self()->available();
28  Q_EMIT availableChanged();
29  });
30 
31  connect(watcher, &Kirigami::VirtualKeyboardWatcher::enabledChanged, this, [this]() {
32  d->enabled = Kirigami::VirtualKeyboardWatcher::self()->enabled();
33  Q_EMIT enabledChanged();
34  });
35 
36  connect(watcher, &Kirigami::VirtualKeyboardWatcher::activeChanged, this, [this]() {
37  d->active = Kirigami::VirtualKeyboardWatcher::self()->active();
38  Q_EMIT activeChanged();
39  });
40 
41  connect(watcher, &Kirigami::VirtualKeyboardWatcher::visibleChanged, this, [this]() {
42  d->visible = Kirigami::VirtualKeyboardWatcher::self()->visible();
43  Q_EMIT visibleChanged();
44  });
45 
46  connect(watcher, &Kirigami::VirtualKeyboardWatcher::willShowOnActiveChanged, this, [this]() {
47  Q_EMIT willShowOnActiveChanged();
48  });
49 
50  d->available = watcher->available();
51  d->enabled = watcher->enabled();
52  d->active = watcher->active();
53  d->visible = watcher->visible();
54 }
55 
56 InputMethod::~InputMethod() = default;
57 
58 bool InputMethod::available() const
59 {
60  return d->available;
61 }
62 
63 bool InputMethod::enabled() const
64 {
65  return d->enabled;
66 }
67 
68 void InputMethod::setEnabled(bool newEnabled)
69 {
70  if (newEnabled == d->enabled) {
71  return;
72  }
73 
74  d->enabled = newEnabled;
75  Q_EMIT enabledChanged();
76 }
77 
78 bool InputMethod::active() const
79 {
80  return d->active;
81 }
82 
83 void InputMethod::setActive(bool newActive)
84 {
85  if (newActive == d->active) {
86  return;
87  }
88 
89  d->active = newActive;
90  Q_EMIT activeChanged();
91 }
92 
93 bool InputMethod::visible() const
94 {
95  return d->visible;
96 }
97 
99 {
100  return Kirigami::VirtualKeyboardWatcher::self()->willShowOnActive();
101 }
Q_EMITQ_EMIT
bool visible
Is the current input method visible?
Definition: inputmethod.h:64
bool enabled
Is the current input method enabled?
Definition: inputmethod.h:41
bool willShowOnActive
Will the input method be shown when a text input field gains focus?
Definition: inputmethod.h:77
bool active
Is the current input method active?
Definition: inputmethod.h:53
This exposes information about the current used input method.
Definition: inputmethod.h:17
bool available
Is an input method available?
Definition: inputmethod.h:32
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 04:14:23 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.