2
* This file is part of Maliit Plugins
4
* Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
6
* Contact: Mohammad Anwari <Mohammad.Anwari@nokia.com>
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 "models/key.h"
33
#include "view/renderer.h"
34
#include "view/abstracttexteditor.h"
35
#include "logic/languagefeatures.h"
36
#include "logic/layout.h"
37
#include "logic/keyareaconverter.h"
38
#include "logic/wordengine.h"
39
#include "dashboard.h"
41
#include <QInputMethodEvent>
42
#include <QTextCharFormat>
44
namespace MaliitKeyboard {
47
: public AbstractTextEditor
50
QTextEdit *const m_target;
53
explicit DashboardEditor(QTextEdit *target,
54
const EditorOptions &options,
59
virtual void sendPreeditString(const QString &preedit,
60
Model::Text::PreeditFace face,
61
const Replacement &replacement);
62
virtual void sendCommitString(const QString &commit);
63
virtual void sendKeyEvent(const QKeyEvent &ev);
64
virtual void invokeAction(const QString &command, const QKeySequence &sequence);
68
DashboardEditor::DashboardEditor(QTextEdit *target,
69
const EditorOptions &options,
71
: AbstractTextEditor(options, new Model::Text, new Logic::WordEngine, new Logic::LanguageFeatures, parent)
75
void DashboardEditor::sendPreeditString(const QString &preedit,
76
Model::Text::PreeditFace face,
77
const Replacement &replacement)
79
QList<QInputMethodEvent::Attribute> attribute_list;
80
QTextCharFormat char_format;
82
const int length(preedit.length());
85
case Model::Text::PreeditNoCandidates:
86
char_format.setFontUnderline(true);
87
char_format.setUnderlineStyle(QTextCharFormat::SpellCheckUnderline);
88
char_format.setUnderlineColor(Qt::red);
91
case Model::Text::PreeditActive:
92
char_format.setForeground(QBrush(QColor(153, 50, 204)));
93
char_format.setFontWeight(QFont::Bold);
96
case Model::Text::PreeditDefault:
98
char_format.setUnderlineStyle(QTextCharFormat::SingleUnderline);
99
char_format.setUnderlineColor(QColor(0, 0, 0));
103
attribute_list.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat,
107
if (replacement.cursor_position >= 0) {
108
attribute_list << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, replacement.cursor_position, 1, QVariant());
111
QInputMethodEvent *ev = new QInputMethodEvent(preedit, attribute_list);
113
if (replacement.start || replacement.length) {
114
ev->setCommitString("", replacement.start, replacement.length);
116
qApp->postEvent(m_target, ev);
119
void DashboardEditor::sendCommitString(const QString &commit)
121
QInputMethodEvent *ev = new QInputMethodEvent;
122
ev->setCommitString(commit);
123
qApp->postEvent(m_target, ev);
126
void DashboardEditor::sendKeyEvent(const QKeyEvent &ev)
128
QKeyEvent *new_ev = new QKeyEvent(ev.type(), ev.key(), ev.modifiers(), ev.text(), ev.isAutoRepeat(), ev.count());
129
qApp->postEvent(m_target, new_ev);
132
void DashboardEditor::invokeAction(const QString &command, const QKeySequence &sequence)
139
class DashboardPrivate
143
QTextEdit *text_entry;
144
DashboardEditor *editor;
145
QGraphicsProxyWidget *proxy_widget;
150
Logic::Layout::Orientation orientation;
152
explicit DashboardPrivate(Dashboard *q)
154
, text_entry(new QTextEdit)
155
, editor(new DashboardEditor(text_entry, EditorOptions(), q))
157
, vbox(new QVBoxLayout)
158
, top(new QSpacerItem(0, 0))
159
, bottom(new QSpacerItem(0, 0))
160
, buttons(new QWidget)
161
, orientation(Logic::Layout::Landscape)
165
Dashboard::Dashboard(QWidget *parent)
166
: QMainWindow(parent)
167
, d_ptr(new DashboardPrivate(this))
169
setWindowTitle("Maliit Keyboard Viewer");
172
QGraphicsView *v = new QGraphicsView;
173
v->setScene(new QGraphicsScene(v));
174
v->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
175
v->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
179
d_ptr->proxy_widget = v->scene()->addWidget(w = new QWidget);
180
d_ptr->proxy_widget->setTransformOriginPoint(d_ptr->proxy_widget->geometry().center());
183
QVBoxLayout *vbox = d_ptr->vbox;
186
QSpacerItem *top_spacer = d_ptr->top;
187
vbox->addItem(top_spacer);
189
QWidget *buttons = d_ptr->buttons;
191
vbox->addWidget(buttons);
192
QHBoxLayout *hbox = new QHBoxLayout;
193
buttons->setLayout(hbox);
195
QPushButton *show = new QPushButton("Show virtual keyboard");
196
connect(show, SIGNAL(clicked()),
197
this, SLOT(onShow()));
198
hbox->addWidget(show);
201
QPushButton *orientation_changed = new QPushButton("Change orientation");
202
connect(orientation_changed, SIGNAL(clicked()),
203
this, SLOT(onOrientationChangeClicked()));
204
hbox->addWidget(orientation_changed);
205
orientation_changed->show();
207
QPushButton *close = new QPushButton("Close application");
208
connect(close, SIGNAL(clicked()),
210
hbox->addWidget(close);
213
QTextEdit *te = d_ptr->text_entry;
218
QSpacerItem *bottom_spacer = d_ptr->bottom;
219
vbox->addItem(bottom_spacer);
224
Dashboard::~Dashboard()
227
void Dashboard::setRenderer(Renderer *renderer)
230
d->renderer = renderer;
233
AbstractTextEditor * Dashboard::editor() const
235
Q_D(const Dashboard);
239
void Dashboard::onShow()
247
d->top->changeSize(0, d->orientation == Logic::Layout::Landscape ? 50 : 80);
248
d->bottom->changeSize(0, d->orientation == Logic::Layout::Landscape ? 250 : 350);
249
d->vbox->invalidate();
253
void Dashboard::onHide()
256
d->top->changeSize(0, 0);
257
d->bottom->changeSize(0, 0);
258
d->vbox->invalidate();
262
void Dashboard::onOrientationChangeClicked()
266
d->orientation = (d->orientation == Logic::Layout::Landscape
267
? Logic::Layout::Portrait : Logic::Layout::Landscape);
268
static_cast<QGraphicsView *>(centralWidget())->rotate(d->orientation == Logic::Layout::Landscape ? 90 : 270);
269
const QSize &s(centralWidget()->size());
270
d->proxy_widget->resize(d->orientation == Logic::Layout::Landscape ? s : QSize(s.height(), s.width()));
272
Q_EMIT orientationChanged(d->orientation);
275
} // namespace MaliitKeyboard