1
/* This file is part of Maliit framework
3
* Copyright (C) 2012 Mattia Barbon <mattia@develer.com>
4
* Copyright (C) 2012 Openismus GmbH
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 as published by the Free Software Foundation; either
11
* version 2.1 of the licence, or (at your option) any later version.
13
* This library is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Lesser General Public License for more details.
18
* You should have received a copy of the GNU Lesser General Public
19
* License along with this library; if not, write to the
20
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21
* Boston, MA 02111-1307, USA.
24
#include "mainwindow.h"
25
#include "pluginsettings.h"
26
#include "stringentryedit.h"
27
#include "selectentrycombobox.h"
28
#include "boolentrycheckbox.h"
30
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
31
#include <QtWidgets/QVBoxLayout>
32
#include <QtWidgets/QLabel>
33
#include <QtGui/QInputMethod>
40
removeAllTabs (QTabWidget& tabs)
42
for (int iter(tabs.count() - 1); iter >= 0; ++iter) {
49
MainWindow::MainWindow() :
50
maliit_settings(Maliit::SettingsManager::create(this)),
55
im_testing_entry(new QTextEdit),
58
QVBoxLayout *l = new QVBoxLayout(this);
59
l->addWidget(new QLabel("Text entry for testing"));
61
im_testing_entry->setFocusPolicy(Qt::StrongFocus);
62
im_testing_entry->installEventFilter(this);
63
l->addWidget(im_testing_entry);
65
// Steals focus from im_testing_entry and therefore dismisses input
66
// method. Other widgets should set im_testing_entry as focus proxy.
67
QPushButton *dismiss_im = new QPushButton("Dismiss input method");
68
l->addWidget(dismiss_im);
71
connect(maliit_settings, SIGNAL(pluginSettingsReceived(QList<QSharedPointer<Maliit::PluginSettings> >)),
72
this, SLOT(pluginSettingsReceived(QList<QSharedPointer<Maliit::PluginSettings> >)));
73
connect(maliit_settings, SIGNAL(connected()),
74
this, SLOT(connected()));
77
bool MainWindow::eventFilter(QObject *watched,
80
// Let the input method show up on focus-in, not on second click:
81
if (watched == im_testing_entry
82
&& event->type() == QFocusEvent::FocusIn) {
83
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
84
qApp->inputMethod()->show();
86
if (QInputContext *ic = qApp->inputContext()) {
87
QEvent im_request(QEvent::RequestSoftwareInputPanel);
88
ic->filterEvent(&im_request);
96
void MainWindow::connected()
98
qDebug() << "SettingsWidget::connected()";
100
maliit_settings->loadPluginSettings();
103
void MainWindow::pluginSettingsReceived(const QList<QSharedPointer<Maliit::PluginSettings> > &settings)
105
qDebug() << "SettingsWidget::pluginSettingsReceived()";
107
const int current_index(tabs.count() > 0 ? tabs.currentIndex() : 0);
109
if (language_selector) {
110
disconnect(language_selector, SIGNAL(currentIndexChanged(int)),
111
this, SLOT(setLanguage(int)));
112
language_selector = 0;
115
disconnect(enable_all, SIGNAL(clicked()),
116
this, SLOT(enableAllLayouts()));
121
Q_FOREACH (const QSharedPointer<Maliit::PluginSettings> &setting, settings) {
122
const QString plugin_name(setting->pluginName());
123
QWidget *page(new QWidget);
124
QGridLayout *layout(new QGridLayout(page));
128
if (plugin_name == "server") {
129
language_selector = new QComboBox;
130
language_selector->setFocusProxy(im_testing_entry);
132
enable_all = new QPushButton("Enable all keyboard layouts");
133
enable_all->setFocusProxy(im_testing_entry);
135
Q_FOREACH (const QSharedPointer<Maliit::SettingsEntry> &entry, setting->configurationEntries()) {
140
if (entry->key() == "/maliit/onscreen/enabled") {
141
enabled_entry = entry;
142
} else if (entry->key() == "/maliit/onscreen/active") {
143
QStringList values = entry->attributes()[Maliit::SettingEntryAttributes::valueDomain].toStringList();
144
QStringList descriptions = entry->attributes()[Maliit::SettingEntryAttributes::valueDomainDescriptions].toStringList();
146
language_entry = entry;
147
language_selector->addItem("Select language");
148
for (int i = 0; i < values.count(); ++i) {
149
language_selector->addItem(descriptions[i], values[i]);
152
connect(language_entry.data(), SIGNAL(valueChanged()),
153
this, SLOT(languageChanged()));
157
connect(language_selector, SIGNAL(currentIndexChanged(int)),
158
this, SLOT(setLanguage(int)));
159
connect(enable_all, SIGNAL(clicked()),
160
this, SLOT(enableAllLayouts()));
162
layout->setColumnStretch(1, 1);
163
layout->addWidget(new QLabel("Layout"), row, 0);
164
layout->addWidget(language_selector, row, 1);
166
layout->addWidget(enable_all, row, 1);
169
language_selector->setCurrentIndex(language_selector->findData(language_entry->value()));
170
tabs.insertTab(0, page, plugin_name);
172
typedef QPair<QWidget*, QWidget*> WPair;
173
typedef QList<WPair> WPairList;
176
wlist.append(WPair(new QLabel("Plugin desc:"), new QLabel(setting->pluginDescription())));
178
Q_FOREACH (const QSharedPointer<Maliit::SettingsEntry> &entry, setting->configurationEntries()) {
183
wlist.append(WPair(new QLabel("Key:"), new QLabel(entry->key())));
184
wlist.append(WPair(new QLabel("Entry desc:"), new QLabel(entry->description())));
186
QWidget *second_widget(0);
187
const QVariant value(entry->value());
189
switch (entry->type()) {
190
case Maliit::StringType: {
191
const QStringList values = entry->attributes()[Maliit::SettingEntryAttributes::valueDomain].toStringList();
193
if (values.isEmpty()) {
194
second_widget = new StringEntryEdit(entry);
196
second_widget = new SelectEntryComboBox(entry);
199
case Maliit::IntType:
200
second_widget = new QLabel(QString::number(value.toInt()));
202
case Maliit::BoolType:
203
second_widget = new BoolEntryCheckBox(entry);
205
case Maliit::StringListType:
206
second_widget = new QLabel(value.toStringList().join(", "));
208
case Maliit::IntListType: {
209
const QVariantList values(value.toList());
212
Q_FOREACH (const QVariant &v, values) {
213
strings << QString::number(v.toInt());
216
second_widget = new QLabel(strings.join(", "));
221
wlist.append(WPair(new QLabel("Value:"), second_widget));
222
second_widget->setFocusProxy(im_testing_entry);
224
Q_FOREACH(const WPair& pair, wlist) {
225
layout->addWidget(pair.first, row, 0);
226
layout->addWidget(pair.second, row, 1);
230
tabs.addTab(page, plugin_name);
233
layout->setRowStretch(row, 10);
236
const int tabs_count(tabs.count());
238
if (tabs_count > 0) {
239
if (tabs_count > current_index) {
240
tabs.setCurrentIndex(current_index);
242
tabs.setCurrentIndex(0);
247
void MainWindow::setLanguage(int index)
249
if (index == 0 or not language_selector) {
253
qDebug() << "Setting layout" << language_selector->itemData(index);
255
if (language_entry && enabled_entry) {
256
const QString layout = language_selector->itemData(index).toString();
258
// Make sure the new layout is enabled
259
QStringList list = enabled_entry->value().toStringList();
260
if (!list.contains(layout)) {
261
qDebug() << "Enabling layout first";
263
enabled_entry->set(list);
266
// Now activate the new layout
267
language_entry->set(layout);
269
qCritical() << "Language entry is NULL";
273
void MainWindow::enableAllLayouts()
276
enabled_entry->set(enabled_entry->attributes()[Maliit::SettingEntryAttributes::valueDomain]);
278
qCritical() << "Enabled entry is NULL";
282
void MainWindow::languageChanged()
284
if (not language_selector) {
288
if (language_entry) {
289
qDebug() << "New language is" << language_entry->value();
291
language_selector->setCurrentIndex(language_selector->findData(language_entry->value()));
293
qDebug() << "No language is selected";