2
* This file is part of Maliit Plugins
4
* Copyright (C) 2012 Openismus GmbH. All rights reserved.
6
* Contact: maliit-discuss@lists.maliit.org
8
* Redistribution and use in source and binary forms, with or without modification,
9
* are permitted provided that the following conditions are met:
11
* Redistributions of source code must retain the above copyright notice, this list
12
* of conditions and the following disclaimer.
13
* Redistributions in binary form must reproduce the above copyright notice, this list
14
* of conditions and the following disclaimer in the documentation and/or other materials
15
* provided with the distribution.
16
* Neither the name of Nokia Corporation nor the names of its contributors may be
17
* used to endorse or promote products derived from this software without specific
18
* prior written permission.
20
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
21
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23
* THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
#include "eventhandler.h"
33
#include "layoutupdater.h"
34
#include "models/layout.h"
36
namespace MaliitKeyboard {
39
class EventHandlerPrivate
42
Model::Layout * const layout;
43
LayoutUpdater * const updater;
45
explicit EventHandlerPrivate(Model::Layout * const new_layout,
46
LayoutUpdater * const new_updater);
50
EventHandlerPrivate::EventHandlerPrivate(Model::Layout *const new_layout,
51
LayoutUpdater *const new_updater)
53
, updater(new_updater)
55
Q_ASSERT(new_layout != 0);
56
Q_ASSERT(new_updater != 0);
60
//! \brief Performs event handling for Model::Layout instance, using a LayoutUpdater instance.
62
//! Does not take ownership of either layout or updater.
63
EventHandler::EventHandler(Model::Layout * const layout,
64
LayoutUpdater * const updater,
67
, d_ptr(new EventHandlerPrivate(layout, updater))
71
EventHandler::~EventHandler()
75
void EventHandler::onExtendedKeysShown(const Key &key)
78
d->updater->onExtendedKeysShown(key);
82
void EventHandler::onEntered(int index)
86
const QVector<Key> &keys(d->layout->keyArea().keys());
88
if (index >= keys.count()) {
89
qWarning() << __PRETTY_FUNCTION__
90
<< "Invalid index:" << index
91
<< "Keys available:" << keys.count();
95
const Key &key(keys.at(index));
97
const Key pressed_key(d->updater->modifyKey(key, KeyDescription::PressedState));
98
d->layout->replaceKey(index, pressed_key);
99
d->updater->onKeyEntered(key);
101
Q_EMIT keyEntered(key);
105
void EventHandler::onExited(int index)
109
const QVector<Key> &keys(d->layout->keyArea().keys());
111
if (index >= keys.count()) {
112
qWarning() << __PRETTY_FUNCTION__
113
<< "Invalid index:" << index
114
<< "Keys available:" << keys.count();
118
const Key &key(keys.at(index));
120
const Key normal_key(d->updater->modifyKey(key, KeyDescription::NormalState));
121
d->layout->replaceKey(index, normal_key);
122
d->updater->onKeyExited(normal_key);
124
Q_EMIT keyExited(key);
128
void EventHandler::onPressed(int index)
132
const QVector<Key> &keys(d->layout->keyArea().keys());
134
if (index >= keys.count()) {
135
qWarning() << __PRETTY_FUNCTION__
136
<< "Invalid index:" << index
137
<< "Keys available:" << keys.count();
141
const Key &key(keys.at(index));
143
const Key pressed_key(d->updater->modifyKey(key, KeyDescription::PressedState));
144
d->layout->replaceKey(index, pressed_key);
145
d->updater->onKeyPressed(pressed_key);
147
Q_EMIT keyPressed(pressed_key);
151
void EventHandler::onReleased(int index)
155
const QVector<Key> &keys(d->layout->keyArea().keys());
157
if (index >= keys.count()) {
158
qWarning() << __PRETTY_FUNCTION__
159
<< "Invalid index:" << index
160
<< "Keys available:" << keys.count();
164
const Key &key(keys.at(index));
166
const Key normal_key(d->updater->modifyKey(key, KeyDescription::NormalState));
167
d->layout->replaceKey(index, normal_key);
168
d->updater->onKeyReleased(normal_key);
170
Q_EMIT keyReleased(normal_key);
174
void EventHandler::onPressAndHold(int index)
178
const QVector<Key> &keys(d->layout->keyArea().keys());
180
if (index >= keys.count()) {
181
qWarning() << __PRETTY_FUNCTION__
182
<< "Invalid index:" << index
183
<< "Keys available:" << keys.count();
187
const Key &key(keys.at(index));
189
// FIXME: long-press on space needs to work again to save words to dictionary!
190
if (key.hasExtendedKeys()) {
191
Q_EMIT extendedKeysShown(key);
194
Q_EMIT keyLongPressed(key);
197
void EventHandler::onWordCandidatePressed(QString word)
199
WordCandidate candidate(WordCandidate::SourcePrediction, word);
200
Q_EMIT wordCandidatePressed(candidate);
203
void EventHandler::onWordCandidateReleased(QString word)
205
WordCandidate candidate(WordCandidate::SourcePrediction, word);
206
Q_EMIT wordCandidateReleased(candidate);
209
void EventHandler::onLanguageChangeRequested(QString languageId)
213
d->updater->setActiveKeyboardId(languageId);
216
}} // namespace Logic, MaliitKeyboard