~michael-sheldon/ubuntu-keyboard/fix-oxide-dismiss-test

« back to all changes in this revision

Viewing changes to src/view/abstracttexteditor.h

  • Committer: Thomas Moenicke
  • Date: 2013-07-19 12:05:07 UTC
  • Revision ID: thomas.moenicke@canonical.com-20130719120507-lzw5oq50xm567x0j
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of Maliit Plugins
 
3
 *
 
4
 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
 
5
 *
 
6
 * Contact: Mohammad Anwari <Mohammad.Anwari@nokia.com>
 
7
 *
 
8
 * Redistribution and use in source and binary forms, with or without modification,
 
9
 * are permitted provided that the following conditions are met:
 
10
 *
 
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.
 
19
 *
 
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.
 
29
 *
 
30
 */
 
31
 
 
32
#ifndef MALIIT_KEYBOARD_TEXTEDITOR_H
 
33
#define MALIIT_KEYBOARD_TEXTEDITOR_H
 
34
 
 
35
#include "models/key.h"
 
36
#include "models/wordcandidate.h"
 
37
#include "models/text.h"
 
38
#include "logic/abstractwordengine.h"
 
39
#include "logic/abstractlanguagefeatures.h"
 
40
 
 
41
#include <QtCore>
 
42
#include <QtGui/QKeyEvent>
 
43
 
 
44
namespace MaliitKeyboard {
 
45
 
 
46
struct EditorOptions
 
47
{
 
48
    EditorOptions();
 
49
    // all delays are in milliseconds
 
50
    int backspace_auto_repeat_delay; // delay before first automatically repeated key
 
51
    int backspace_auto_repeat_interval; // interval between automatically repeated keys
 
52
};
 
53
 
 
54
class AbstractTextEditorPrivate;
 
55
 
 
56
class AbstractTextEditor
 
57
    : public QObject
 
58
{
 
59
    Q_OBJECT
 
60
    Q_DISABLE_COPY(AbstractTextEditor)
 
61
    Q_DECLARE_PRIVATE(AbstractTextEditor)
 
62
    Q_PROPERTY(bool preeditEnabled READ isPreeditEnabled
 
63
                                   WRITE setPreeditEnabled
 
64
                                   NOTIFY preeditEnabledChanged)
 
65
    Q_PROPERTY(bool autoCorrectEnabled READ isAutoCorrectEnabled
 
66
                                       WRITE setAutoCorrectEnabled
 
67
                                       NOTIFY autoCorrectEnabledChanged)
 
68
    Q_PROPERTY(bool autoCapsEnabled READ isAutoCapsEnabled
 
69
                                    WRITE setAutoCapsEnabled
 
70
                                    NOTIFY autoCapsEnabledChanged)
 
71
 
 
72
public:
 
73
    struct Replacement
 
74
    {
 
75
        Replacement()
 
76
            : start(0)
 
77
            , length(0)
 
78
            , cursor_position(-1)
 
79
        {}
 
80
 
 
81
        Replacement(int position)
 
82
            : start(0)
 
83
            , length(0)
 
84
            , cursor_position(position)
 
85
        {}
 
86
 
 
87
        Replacement(int r_start,
 
88
                    int r_length,
 
89
                    int position)
 
90
            : start(r_start)
 
91
            , length(r_length)
 
92
            , cursor_position(position)
 
93
        {}
 
94
 
 
95
        int start;
 
96
        int length;
 
97
        int cursor_position;
 
98
    };
 
99
 
 
100
    explicit AbstractTextEditor(const EditorOptions &options,
 
101
                                Model::Text *text,
 
102
                                Logic::AbstractWordEngine *word_engine,
 
103
                                Logic::AbstractLanguageFeatures *language_features,
 
104
                                QObject *parent = 0);
 
105
    virtual ~AbstractTextEditor() = 0;
 
106
 
 
107
    Model::Text * text() const;
 
108
    Logic::AbstractWordEngine * wordEngine() const;
 
109
    Logic::AbstractLanguageFeatures * languageFeatures() const;
 
110
 
 
111
    Q_SLOT void onKeyPressed(const Key &key);
 
112
    Q_SLOT void onKeyReleased(const Key &key);
 
113
    Q_SLOT void onKeyEntered(const Key &key);
 
114
    Q_SLOT void onKeyExited(const Key &key);
 
115
    Q_SLOT void onCursorPositionChanged(int cursor_position,
 
116
                                        const QString &surrounding_text);
 
117
    Q_SLOT void replacePreedit(const QString &replacement);
 
118
    Q_SLOT void replaceAndCommitPreedit(const QString &replacement);
 
119
    Q_SLOT void clearPreedit();
 
120
 
 
121
    bool isPreeditEnabled() const;
 
122
    Q_SLOT void setPreeditEnabled(bool enabled);
 
123
    Q_SIGNAL void preeditEnabledChanged(bool enabled);
 
124
 
 
125
    bool isAutoCorrectEnabled() const;
 
126
    Q_SLOT void setAutoCorrectEnabled(bool enabled);
 
127
    Q_SIGNAL void autoCorrectEnabledChanged(bool enabled);
 
128
 
 
129
    bool isAutoCapsEnabled() const;
 
130
    Q_SLOT void setAutoCapsEnabled(bool enabled);
 
131
    Q_SIGNAL void autoCapsEnabledChanged(bool enabled);
 
132
 
 
133
    Q_SLOT void showUserCandidate();
 
134
    Q_SLOT void addToUserDictionary(const QString &word);
 
135
 
 
136
    Q_SIGNAL void keyboardClosed();
 
137
    Q_SIGNAL void wordCandidatesChanged(const WordCandidateList &word_candidates);
 
138
    Q_SIGNAL void autoCapsActivated();
 
139
    Q_SIGNAL void leftLayoutSelected();
 
140
    Q_SIGNAL void rightLayoutSelected();
 
141
 
 
142
    Q_SLOT virtual void onLanguageChanged(const QString& languageId);
 
143
 
 
144
private:
 
145
    const QScopedPointer<AbstractTextEditorPrivate> d_ptr;
 
146
 
 
147
    void sendPreeditString(const QString &preedit,
 
148
                           Model::Text::PreeditFace face);
 
149
 
 
150
    virtual void sendPreeditString(const QString &preedit,
 
151
                                   Model::Text::PreeditFace face,
 
152
                                   const Replacement &replacement) = 0;
 
153
    virtual void sendCommitString(const QString &commit) = 0;
 
154
    virtual void sendKeyEvent(const QKeyEvent &ev) = 0;
 
155
    virtual void invokeAction(const QString &action, const QKeySequence &sequence) = 0;
 
156
 
 
157
    void commitPreedit();
 
158
    Q_SLOT void autoRepeatBackspace();
 
159
};
 
160
 
 
161
} // namespace MaliitKeyboard
 
162
 
 
163
#endif // MALIIT_KEYBOARD_ABSTRACTTEXTEDITOR_H