~timo-jyrinki/ubuntu/trusty/maliit-framework/fix_qt52

« back to all changes in this revision

Viewing changes to examples/apps/widgetproperties/mainwindow.cpp

  • Committer: Package Import Robot
  • Author(s): Ricardo Salveti de Araujo
  • Date: 2013-07-23 19:47:04 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: package-import@ubuntu.com-20130723194704-0o18p2ao0x9sa1zx
Tags: upstream-0.99.0+git20130615+97e8335
ImportĀ upstreamĀ versionĀ 0.99.0+git20130615+97e8335

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include "mainwindow.h"
2
 
 
3
 
#include <maliit/inputmethod.h>
4
 
#include <maliit/namespace.h>
5
 
 
6
 
#include <cstdlib>
7
 
 
8
 
#include <QApplication>
9
 
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
10
 
#include <QInputContext>
11
 
#endif
12
 
#include <QCheckBox>
13
 
#include <QLabel>
14
 
#include <QLineEdit>
15
 
#include <QTextEdit>
16
 
#include <QPushButton>
17
 
#include <QVariant>
18
 
#include <QVBoxLayout>
19
 
 
20
 
namespace {
21
 
    const char * const FillerText = "Mauris pretium vehicula tellus, vitae "
22
 
            "tristique sapien malesuada a. Mauris vel ipsum ante. Donec "
23
 
            "faucibus quam sit amet neque rhoncus sit amet egestas eros "
24
 
            "ullamcorper. Integer laoreet augue eget dui viverra et pharetra "
25
 
            "dui porttitor. Donec sodales venenatis sollicitudin. Sed sodales "
26
 
            "lacinia ligula, at fringilla lacus adipiscing in. Nam purus nisi,"
27
 
            " pulvinar in tristique eget, tincidunt eu ante. Donec eros eros, "
28
 
            "molestie nec pellentesque ut, imperdiet sed metus. Quisque et "
29
 
            "erat ante. Cum sociis natoque penatibus et magnis dis parturient "
30
 
            "montes, nascetur ridiculus mus. Pellentesque faucibus consectetur "
31
 
            "tortor sed accumsan. Mauris id metus felis. Aenean at volutpat "
32
 
            "nunc. Pellentesque habitant morbi tristique senectus et netus et "
33
 
            "malesuada fames ac turpis egestas. Suspendisse non ultricies "
34
 
            "turpis.";
35
 
 
36
 
    bool enableFullScreenMode()
37
 
    {
38
 
        static const bool fullscreen(qApp->arguments().contains("-fullscreen"));
39
 
        return fullscreen;
40
 
    }
41
 
}
42
 
 
43
 
MainWindow::MainWindow()
44
 
    : QMainWindow()
45
 
    , entryWithProperties(new QTextEdit)
46
 
{
47
 
    setWindowTitle("Maliit widget properties test application");
48
 
 
49
 
    QVBoxLayout *vbox = new QVBoxLayout;
50
 
 
51
 
    // Clicking the button will steal focus from the text edit, thus hiding
52
 
    // the virtual keyboard:
53
 
    QPushButton *hideVkb = new QPushButton("Hide virtual keyboard");
54
 
    vbox->addWidget(hideVkb);
55
 
 
56
 
    QCheckBox *translucencyCheckBox(new QCheckBox("Make input method translucent"));
57
 
    translucencyCheckBox->setFocusProxy(entryWithProperties);
58
 
 
59
 
    QCheckBox *preferNumbersCheckBox(new QCheckBox("Prefer numbers (show symview first)"));
60
 
    preferNumbersCheckBox->setFocusProxy(entryWithProperties);
61
 
 
62
 
    QCheckBox *suppressionCheckBox(new QCheckBox("Suppress virtual keyboard while retaining focus"));
63
 
    suppressionCheckBox->setFocusProxy(entryWithProperties);
64
 
 
65
 
    QTextEdit *hiddenText(new QTextEdit);
66
 
    hiddenText->setTextColor(Qt::gray);
67
 
    hiddenText->setFontPointSize(16);
68
 
    hiddenText->setText(FillerText);
69
 
 
70
 
    vbox->addWidget(new QLabel("Requires Harmattan keyboard plugin to show its "
71
 
                               "impact, sorry!"));
72
 
    vbox->addWidget(new QLabel("Regular line edit"));
73
 
    vbox->addWidget(new QLineEdit);
74
 
    vbox->addWidget(entryWithProperties);
75
 
    vbox->addWidget(translucencyCheckBox);
76
 
    vbox->addWidget(preferNumbersCheckBox);
77
 
    vbox->addWidget(suppressionCheckBox);
78
 
    vbox->addStretch();
79
 
    vbox->addWidget(hiddenText);
80
 
 
81
 
    connect(translucencyCheckBox, SIGNAL(toggled(bool)),
82
 
            this,                 SLOT(onTranslucencyToggled(bool)));
83
 
 
84
 
    connect(preferNumbersCheckBox, SIGNAL(toggled(bool)),
85
 
            this,                  SLOT(onPreferNumbersToggled(bool)));
86
 
 
87
 
    connect(suppressionCheckBox, SIGNAL(toggled(bool)),
88
 
            this,                SLOT(onSuppressionToggled(bool)));
89
 
 
90
 
    QPushButton *closeApp = new QPushButton("Close application");
91
 
    vbox->addWidget(closeApp);
92
 
    connect(closeApp, SIGNAL(clicked()),
93
 
            this,     SLOT(close()));
94
 
 
95
 
    setCentralWidget(new QWidget);
96
 
    centralWidget()->setLayout(vbox);
97
 
 
98
 
    if (enableFullScreenMode()) {
99
 
        showFullScreen();
100
 
    } else {
101
 
        show();
102
 
    }
103
 
}
104
 
 
105
 
void MainWindow::onTranslucencyToggled(bool value)
106
 
{
107
 
    entryWithProperties->setProperty(Maliit::InputMethodQuery::translucentInputMethod, QVariant(value));
108
 
    // API not available on Qt 5 anymore (TODO: find another approach to fix it there)
109
 
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
110
 
    if (QInputContext *ic = qApp->inputContext()) {
111
 
        ic->update();
112
 
    }
113
 
#endif
114
 
}
115
 
 
116
 
void MainWindow::onPreferNumbersToggled(bool value)
117
 
{
118
 
    entryWithProperties->setInputMethodHints(value ? (entryWithProperties->inputMethodHints() | Qt::ImhPreferNumbers)
119
 
                                                   : (entryWithProperties->inputMethodHints() & ~Qt::ImhPreferNumbers));
120
 
    // API not available on Qt 5 anymore (TODO: find another approach to fix it there)
121
 
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
122
 
    if (QInputContext *ic = qApp->inputContext()) {
123
 
        ic->update();
124
 
    }
125
 
#endif
126
 
}
127
 
 
128
 
void MainWindow::onSuppressionToggled(bool value)
129
 
{
130
 
    entryWithProperties->setProperty(Maliit::InputMethodQuery::suppressInputMethod, QVariant(value));
131
 
    // API not available on Qt 5 anymore (TODO: find another approach to fix it there)
132
 
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
133
 
    if (QInputContext *ic = qApp->inputContext()) {
134
 
        ic->update();
135
 
    }
136
 
#endif
137
 
}