summaryrefslogtreecommitdiffstats
path: root/tests/manual/widgets/inputmethods/main.cpp
blob: 2378e95aea71d0d58901c8f8b431e6e09eb9cb0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include <QApplication>
#include <QFormLayout>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QMainWindow>
#include <QVBoxLayout>

#include "controlview.h"
#include "referenceview.h"
#include "testview.h"
#include "webview.h"

// Test for input method events for QWebEngineView. This makes possible to
// manually customize QInputMethodEvent and validate that it is rendered
// properly in a web view.

class MainWindow : public QMainWindow
{
    Q_OBJECT
public:
    explicit MainWindow(QWidget *parent = 0);

private slots:
    void sendInputMethodEvents();

private:
    void closeEvent(QCloseEvent *event) override;

    ControlView *m_controlView;
    ReferenceView *m_referenceView;
    WebView *m_webView;
    TestView *m_testView;

    QLabel *m_referenceProcessed;
    QLabel *m_webProcessed;
};

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , m_controlView(new ControlView)
    , m_referenceView(new ReferenceView)
    , m_webView(new WebView)
    , m_testView(new TestView)
    , m_referenceProcessed(new QLabel)
    , m_webProcessed(new QLabel)
{
    m_controlView->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    m_controlView->setFixedWidth(300);

    m_webView->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    m_webView->setFixedWidth(280);
    m_webView->setFixedHeight(150);

    m_testView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    m_testView->setMinimumWidth(400);

    QWidget *centralWidget = new QWidget;

    QGroupBox *referenceGroup = new QGroupBox(tr("Reference"));
    referenceGroup->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
    referenceGroup->setMinimumWidth(300);
    QFormLayout *referenceProcessedForm = new QFormLayout;
    referenceProcessedForm->addRow(tr("Processed:"), m_referenceProcessed);
    QVBoxLayout *referenceLayout = new QVBoxLayout;
    referenceLayout->addWidget(m_referenceView);
    referenceLayout->addLayout(referenceProcessedForm);
    referenceGroup->setLayout(referenceLayout);

    QGroupBox *webGroup = new QGroupBox(tr("Web"));
    webGroup->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
    webGroup->setMinimumWidth(300);
    QFormLayout *webProcessedForm = new QFormLayout;
    webProcessedForm->addRow(tr("Processed:"), m_webProcessed);
    QVBoxLayout *webLayout = new QVBoxLayout;
    webLayout->addWidget(m_webView);
    webLayout->addLayout(webProcessedForm);
    webGroup->setLayout(webLayout);

    QVBoxLayout *leftLayout = new QVBoxLayout;
    leftLayout->addWidget(m_controlView);
    leftLayout->addWidget(referenceGroup);
    leftLayout->addWidget(webGroup);

    QHBoxLayout *centralLayout = new QHBoxLayout;
    centralLayout->addLayout(leftLayout);
    centralLayout->addWidget(m_testView);

    connect(m_testView, &TestView::sendInputMethodData, m_controlView,
            &ControlView::receiveInputMethodData);
    connect(m_testView, &TestView::requestInputMethodEvent, this,
            &MainWindow::sendInputMethodEvents);
    connect(m_controlView, &ControlView::requestInputMethodEvent, this,
            &MainWindow::sendInputMethodEvents);

    centralWidget->setLayout(centralLayout);
    setCentralWidget(centralWidget);
    setWindowTitle(tr("Input Methods Format Manual Test"));
}

void MainWindow::sendInputMethodEvents()
{
    bool processed;
    QString resultText;

    QString text = m_controlView->getText();
    QList<QInputMethodEvent::Attribute> attrs = m_controlView->getAtrributes();
    QInputMethodEvent im(text, attrs);

    processed = QApplication::sendEvent(m_referenceView->referenceInput(), &im);
    resultText = processed ? QStringLiteral("<font color='green'>TRUE</font>")
                           : QStringLiteral("<font color='red'>FALSE</font>");
    m_referenceProcessed->setText(resultText);

    processed = QApplication::sendEvent(m_webView->focusProxy(), &im);
    resultText = processed ? QStringLiteral("<font color='green'>TRUE</font>")
                           : QStringLiteral("<font color='red'>FALSE</font>");
    m_webProcessed->setText(resultText);
}

void MainWindow::closeEvent(QCloseEvent *event)
{
    m_testView->cancelTest();
    QMainWindow::closeEvent(event);
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}

#include "main.moc"