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
#include "overrideinputmethod.h"
17
#include <maliit/plugins/abstractinputmethodhost.h>
20
#include <QApplication>
21
#include <QDesktopWidget>
25
const char * const overrideSubViewId("OverridePluginSubview1");
26
const char * const actionKeyName = "actionKey";
27
const char * const actionKeyLabel = "Enter";
30
using Maliit::Plugins::AbstractSurface;
31
using Maliit::Plugins::AbstractWidgetSurface;
33
OverrideInputMethod::OverrideInputMethod(MAbstractInputMethodHost *host)
34
: MAbstractInputMethod(host)
35
, surfaceFactory(host->surfaceFactory())
36
, surface(qSharedPointerDynamicCast<AbstractWidgetSurface>(surfaceFactory->create(AbstractSurface::PositionCenterBottom | AbstractSurface::TypeWidget)))
37
, mainWidget(new QPushButton(surface->widget()))
38
, showIsInhibited(false)
39
, showRequested(false)
40
, activeActionKeyOverride()
43
mainWidget->setText(actionKeyLabel);
44
connect(mainWidget, SIGNAL(clicked()), this, SLOT(handleButtonClicked()));
46
// Used only for unittest/sanity test
47
inputMethodHost()->sendCommitString("Maliit");
48
inputMethodHost()->sendPreeditString("Mali", QList<Maliit::PreeditTextFormat>(), 0, 6);
53
OverrideInputMethod::~OverrideInputMethod()
56
// Slot for our action key
57
void OverrideInputMethod::handleButtonClicked()
59
const QKeyEvent event(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier);
61
inputMethodHost()->sendKeyEvent(event);
64
void OverrideInputMethod::show()
67
if (showIsInhibited) {
71
// Set size of the input method
72
const QSize &screenSize = surfaceFactory->screenSize();
73
surface->setSize(QSize(screenSize.width() - 200, 200));
74
mainWidget->resize(mainWidget->parentWidget()->size());
79
void OverrideInputMethod::hide()
84
showRequested = false;
89
QList<MAbstractInputMethod::MInputMethodSubView>
90
OverrideInputMethod::subViews(Maliit::HandlerState state) const
92
QList<MAbstractInputMethod::MInputMethodSubView> subViews;
94
if (state == Maliit::OnScreen) {
95
MAbstractInputMethod::MInputMethodSubView subView1;
96
subView1.subViewId = overrideSubViewId;
97
subView1.subViewTitle = "Override plugin subview 1";
98
subViews.append(subView1);
103
QString OverrideInputMethod::activeSubView(Maliit::HandlerState state) const
105
QString subView = (state == Maliit::OnScreen) ? overrideSubViewId : "";
109
void OverrideInputMethod::setState(const QSet<Maliit::HandlerState> &state)
111
if (state.contains(Maliit::OnScreen)) {
112
if (showRequested && !showIsInhibited) {
120
void OverrideInputMethod::handleClientChange()
127
void OverrideInputMethod::handleVisualizationPriorityChange(bool inhibitShow)
129
if (showIsInhibited == inhibitShow) {
132
showIsInhibited = inhibitShow;
143
void OverrideInputMethod::handleAppOrientationAboutToChange(int angle)
145
// Rotate your input method UI here
149
void OverrideInputMethod::handleAppOrientationChanged(int angle)
151
// Can typically be forwarded to handleAppOrientationAboutToChange
152
// as long as that method will not do anything when newAngle == previousAngle
156
void OverrideInputMethod::update()
158
// empty default implementation
161
void OverrideInputMethod::reset()
163
// empty default implementation
166
void OverrideInputMethod::handleFocusChange(bool focusIn)
168
// empty default implementation
172
void OverrideInputMethod::switchContext(Maliit::SwitchDirection direction,
173
bool enableAnimation)
175
// empty default implementation
177
Q_UNUSED(enableAnimation);
180
void OverrideInputMethod::setPreedit(const QString &preeditString,
183
// empty default implementation
184
Q_UNUSED(preeditString);
188
void OverrideInputMethod::setActiveSubView(const QString &subViewId,
189
Maliit::HandlerState state)
191
// Ignored as input method only support one subview
196
void OverrideInputMethod::setKeyOverrides(const QMap<QString, QSharedPointer<MKeyOverride> > &overrides)
198
if (activeActionKeyOverride) {
199
disconnect(activeActionKeyOverride.data(), SIGNAL(keyAttributesChanged(const QString &, const MKeyOverride::KeyOverrideAttributes)),
200
this, SLOT(onKeyAttributesChanged(const QString &, const MKeyOverride::KeyOverrideAttributes)));
201
activeActionKeyOverride.clear();
204
QMap<QString, QSharedPointer<MKeyOverride> >::const_iterator actionKeyOverrideIter(overrides.find(actionKeyName));
206
if (actionKeyOverrideIter != overrides.end()) {
207
QSharedPointer<MKeyOverride> overrideShared = *actionKeyOverrideIter;
209
if (overrideShared) {
210
connect(overrideShared.data(), SIGNAL(keyAttributesChanged(const QString &, const MKeyOverride::KeyOverrideAttributes)),
211
this, SLOT(onKeyAttributesChanged(const QString &, const MKeyOverride::KeyOverrideAttributes)));
212
activeActionKeyOverride = overrideShared;
216
updateActionKey(MKeyOverride::All);
219
void OverrideInputMethod::onKeyAttributesChanged(const QString &keyId,
220
const MKeyOverride::KeyOverrideAttributes changedAttributes)
222
if (keyId == actionKeyName) {
223
updateActionKey(changedAttributes);
227
void OverrideInputMethod::updateActionKey (const MKeyOverride::KeyOverrideAttributes changedAttributes)
229
const bool useKeyOverride(activeActionKeyOverride);
231
if (changedAttributes & MKeyOverride::Label) {
232
bool useDefault(false);
234
if (useKeyOverride) {
235
const QString label(activeActionKeyOverride->label());
237
if (label.isEmpty()) {
240
mainWidget->setText(label);
247
mainWidget->setText(actionKeyLabel);
250
if (changedAttributes & MKeyOverride::Icon) {
253
if (changedAttributes & MKeyOverride::Highlighted) {
256
if (changedAttributes & MKeyOverride::Enabled) {