1
/* * This file is part of Maliit framework *
3
* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
6
* Contact: maliit-discuss@lists.maliit.org
8
* This library is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Lesser General Public
10
* License version 2.1 as published by the Free Software Foundation
11
* and appearing in the file LICENSE.LGPL included in the packaging
15
#ifndef MINPUTCONTEXT_H
16
#define MINPUTCONTEXT_H
18
#include <maliit/namespace.h>
19
#include <maliit/preeditinjectionevent.h>
22
#include <QInputContext>
28
class MImServerConnection;
31
* \brief On the application side, MInputContext implements input method
32
* support for the Meegotouch input method server.
34
* The base class QInputContext abstracts input method specific composing of
35
* input. It acts in between the input method and the widget receiving the
36
* composed input. MInputContext extends this functionality by connecting to
37
* Meegotouch input method server and accepting input it creates. This input
38
* is forwarded to the currently focused widget. MInputContext also notifies
39
* the Meegotouch input method server about the current state of input widgets
40
* on the application side.
42
class MInputContext : public QInputContext
45
friend class Ut_MInputContext;
48
//! \brief Constructor
49
explicit MInputContext(QSharedPointer<MImServerConnection> imServer, const QString &name, QObject *parent = 0);
52
virtual ~MInputContext();
55
virtual bool event(QEvent *event);
56
virtual QString identifierName();
57
virtual bool isComposing() const;
58
virtual QString language();
60
virtual void update();
61
virtual void mouseHandler(int x, QMouseEvent *event);
62
virtual void setFocusWidget(QWidget *w); // note: qt marks this as internal
63
virtual bool filterEvent(const QEvent *event);
66
virtual bool x11FilterEvent(QWidget *widget, XEvent *event);
71
/* Hooked up to the input method server.
72
* See MImServerConnection for documentation. */
73
void activationLostEvent();
74
void imInitiatedHide();
76
void commitString(const QString &string, int replacementStart = 0,
77
int replacementLength = 0, int cursorPos = -1);
79
void updatePreedit(const QString &string, const QList<Maliit::PreeditTextFormat> &preeditFormats,
80
int replacementStart = 0, int replacementLength = 0, int cursorPos = -1);
82
void keyEvent(int type, int key, int modifiers, const QString &text, bool autoRepeat,
83
int count, Maliit::EventRequestType requestType
84
= Maliit::EventRequestBoth);
86
void updateInputMethodArea(const QRect &rect);
88
void setGlobalCorrectionEnabled(bool);
90
void getPreeditRectangle(QRect &rectangle, bool &valid) const;
92
Q_SLOT void onInvokeAction(const QString &action, const QKeySequence &sequence);
94
void setRedirectKeys(bool enabled);
96
void setDetectableAutoRepeat(bool enabled);
98
void setSelection(int start, int length);
100
void getSelection(QString &selection, bool &valid) const;
102
void setLanguage(const QString &language);
103
/* End input method server connection slots. */
111
* \brief Emitted when input method area is changed
112
* \param region new input method area
114
void inputMethodAreaChanged(const QRect ®ion);
118
//! hides input method
119
void hideInputMethod();
121
void onDBusDisconnection();
122
void onDBusConnection();
125
* \brief Notifies input method server of copy availability.
126
* \param copyAvailable bool Specifies wheter copy is available
128
void handleCopyAvailabilityChange(bool copyAvailable);
131
* \brief Notifies input method server when the QML TextInput element has selected text changes
133
void handleSelectedTextChange();
136
* \brief Notifies input method server when the QLineEdit object's selection changed
138
void handleSelectionChanged();
140
//! Notify input method plugin about the application's active window prepare to change to a new \a orientation angle.
141
void notifyOrientationAboutToChange(Maliit::OrientationAngle orientation);
143
//! Notify input method plugin about new \a orientation angle of application's active window.
144
//! \note this method is called when the orientation change is finished
145
void notifyOrientationChanged(Maliit::OrientationAngle orientation);
147
//! Checks whether there is someting to paste in the clipboard and notifies input method plugin about it.
148
void handleClipboardDataChange();
151
Q_DISABLE_COPY(MInputContext)
153
enum InputPanelState {
154
InputPanelShowPending, // input panel showing requested, but activation pending
155
InputPanelShown, // panel showing
156
InputPanelHidden // panel hidden
159
void updatePreeditInternally(const QString &string,
160
const QList<Maliit::PreeditTextFormat> &preeditFormats,
161
int replacementStart = 0, int replacementLength = 0, int cursorPos = -1);
163
/* Hook up signals on the imServer to our slots. Used in constructor. */
164
void connectInputMethodServer();
165
/* Hook up signals and slots on the input method extension instance,
166
* (MInputMethodState and Maliit::InputMethod). Used in constructor. */
167
void connectInputMethodExtension();
169
void notifyCopyPasteState();
171
//! returns content type corresponding to specified hints
172
Maliit::TextContentType contentType(Qt::InputMethodHints hints) const;
174
//! returns the D-Bus object path for this instance
175
QString dbusObjectPath() const;
177
//! returns state for currently focused widget, key is attribute name.
178
QMap<QString, QVariant> getStateInformation() const;
180
//! finds focus scope item for item
181
static QGraphicsItem *findFocusScopeItem(QGraphicsItem *item);
183
bool isVisible(const QRect &rect, const QGraphicsView *view, const QGraphicsItem *item) const;
185
bool handlePreeditInjectionEvent(const Maliit::PreeditInjectionEvent *event);
187
//! Gets cursor start position, relative to widget surrounding text.
188
//! Parameter valid set to false on failure.
189
int cursorStartPosition(bool *valid);
191
bool active; // is connection active
192
InputPanelState inputPanelState; // state for the input method server's software input panel
194
/*! Timer for hiding the current Software Input Panel.
195
* This is mainly for switching directly between widgets
196
* that has input method enabled.
197
* The delayed hiding is handled in input-context because
198
* this has to work also with plain qt apps.
202
QSharedPointer<MImServerConnection> imServer;
204
bool correctionEnabled;
207
int preeditCursorPos;
209
QPointer<QObject> connectedObject;
213
//! redirect all hw key events to the input method or not
215
const QString objectPath; //!< D-Bus object path for this instance.
216
static int connectionCount; //!< Counter to allow multiple IC objects being registered via D-Bus
218
unsigned long currentKeyEventTime;