summaryrefslogtreecommitdiffstats
path: root/tests/manual/corelib/tools/customtypesending/window.cpp
blob: fc158f10e66b5c78b069d502c90f060378439d1f (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
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#include <QtWidgets>
#include "window.h"

//! [Window constructor]
Window::Window(QWidget *parent)
    : QWidget(parent), editor(new QTextEdit(this))
{
    QPushButton *sendButton = new QPushButton(tr("&Send message"));

    connect(sendButton, &QPushButton::clicked,
            this, &Window::sendMessage);

    QHBoxLayout *buttonLayout = new QHBoxLayout;
    buttonLayout->addStretch();
    buttonLayout->addWidget(sendButton);
    buttonLayout->addStretch();

    QVBoxLayout *layout = new QVBoxLayout(this);
    layout->addWidget(editor);
    layout->addLayout(buttonLayout);

    setWindowTitle(tr("Custom Type Sending"));
}
//! [Window constructor]

//! [sending a message]
void Window::sendMessage()
{
    thisMessage = Message(editor->toPlainText(), thisMessage.headers());
    emit messageSent(thisMessage);
}
//! [sending a message]

//! [receiving a message]
void Window::setMessage(const Message &message)
{
    thisMessage = message;
    editor->setPlainText(thisMessage.body());
}
//! [receiving a message]