2
* This file is part of Maliit Plugins
4
* Copyright (C) 2012 Openismus GmbH
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 "abstractwordengine.h"
34
namespace MaliitKeyboard {
37
//! \class AbstractWordEngine
38
//! \brief Provides word candidates based on text model.
40
//! Derived classes need to provide an implementation for
41
//! fetchCandidates() and, optionally, addToUserDictionary().
42
//! \sa Model::Text, computeCandidates().
44
//! \fn void AbstractWordEngine::enabledChanged(bool enabled)
45
//! \brief Emitted when word engine toggles word candidate updates on/off.
46
//! \param enabled Whether word engine is enabled.
48
//! \fn void AbstractWordEngine::candidatesChanged(const WordCandidateList &candidates)
49
//! \brief Emitted when new candidates have been computed.
50
//! \param candidates The list of updated candidates.
52
//! \fn WordCandidateList AbstractWordEngine::fetchCandidates(Model::Text *text)
53
//! \brief Returns a list of candidates.
54
//! \param text The text model.
56
//! Needs to be implemented by derived classes. Will not be called if engine
57
//! is disabled or text model has no preedit.
59
//! \property AbstractWordEngine::enabled
60
//! \brief Whether the engine provides updates for word candidates.
62
class AbstractWordEnginePrivate
67
explicit AbstractWordEnginePrivate();
70
AbstractWordEnginePrivate::AbstractWordEnginePrivate()
75
//! \brief Constructor.
76
//! \param parent The owner of this instance. Can be 0, in case QObject
77
//! ownership is not required.
78
AbstractWordEngine::AbstractWordEngine(QObject *parent)
80
, d_ptr(new AbstractWordEnginePrivate)
83
//! \brief Destructor.
85
//! Needs to be implemented in derived classes.
86
AbstractWordEngine::~AbstractWordEngine()
90
//! \brief Returns whether the word engine is enabled.
91
//! \sa AbstractWordEngine::enabled
92
bool AbstractWordEngine::isEnabled() const
94
Q_D(const AbstractWordEngine);
99
//! \brief Set whether the engine should be enabled.
100
//! \param enabled Setting to true will be ignored if there's no word
101
//! prediction or error correction backend available.
102
//! \sa AbstractWordEngine::enabled
103
void AbstractWordEngine::setEnabled(bool enabled)
105
Q_D(AbstractWordEngine);
107
if (d->enabled != enabled) {
109
d->enabled = enabled;
110
Q_EMIT enabledChanged(d->enabled);
115
//! \brief Clears the current candidates.
117
//! Only has an effect when word engine is enabled, in which case
118
//! candidatesCanged() is emitted.
119
void AbstractWordEngine::clearCandidates()
122
Q_EMIT candidatesChanged(WordCandidateList());
127
//! \brief Computes new candidates, based on text model.
128
//! \param text The text model.
130
//! Can trigger emission of candidatesChanged().
131
void AbstractWordEngine::computeCandidates(Model::Text *text)
133
// FIXME: add possiblity to turn off the error correction for
134
// entries that does not need it (like password entries). Also,
135
// with that we probably will want to turn off preedit styling at
140
|| text->preedit().isEmpty()
141
|| not text->preedit().at(text->preedit().length() - 1).isLetterOrNumber()) {
142
// FIXME: We should here set some special preedit face in text
143
// model (say Disabled or None) which would be interpreted by
144
// editor to send no formatting informations along with
145
// preedit string. When this is done, preedit-string test
146
// needs to be adapted.
150
Q_EMIT candidatesChanged(fetchCandidates(text));
153
//! \brief Adds a word to user dictionary.
154
//! \param word A word.
156
//! Needs to be implemented in derived classes. This does nothing.
157
void AbstractWordEngine::addToUserDictionary(const QString &word)
162
}} // namespace MaliitKeyboard, Logic