1 | #include <QPixmap> |
2 | #include <QThread> |
3 | |
4 | #include "MainWidget.h" |
5 | |
6 | MainWidget::MainWidget(QWidget *parent) |
7 | : QWidget(parent) |
8 | , m_image(new QLabel(this)) |
9 | , m_caption(new QLabel(tr(s: "Hello Internet!" ), m_image)) |
10 | , m_status(new QLabel(tr(s: "Please wait..." ), m_image)) |
11 | { |
12 | setFixedSize(w: 800, h: 450); |
13 | // set style sheet for the text labels: |
14 | m_caption->setContentsMargins(left: 18, top: 9, right: 9, bottom: 9); |
15 | m_caption->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); |
16 | m_caption->setWordWrap(true); |
17 | m_caption->setStyleSheet(QStringLiteral("background-color: rgba(255, 255, 255, 200); font: italic 18pt \"Sans Serif\";" )); |
18 | m_status->setContentsMargins(left: 18, top: 9, right: 9, bottom: 9); |
19 | m_status->setStyleSheet(QStringLiteral("background-color: rgba(255, 255, 255, 200); font: 10pt \"Sans Serif\";" )); |
20 | } |
21 | |
22 | MainWidget::~MainWidget() |
23 | { |
24 | } |
25 | |
26 | void MainWidget::resizeEvent(QResizeEvent *) |
27 | { |
28 | m_image->setGeometry(ax: 0, ay: 0, aw: width(), ah: height()); |
29 | m_caption->move(ax: 0, ay: 0); |
30 | m_caption->setFixedWidth(width()); |
31 | m_caption->setFixedHeight(qMax(a: m_caption->sizeHint().height(), b: height() / 3)); |
32 | m_status->setFixedWidth(width()); |
33 | m_status->setFixedHeight(qMax(a: m_status->sizeHint().height(), b: height() / 9)); |
34 | m_status->move(ax: 0, ay: height() - m_status->height()); |
35 | } |
36 | |
37 | void MainWidget::setImage(QImage image) |
38 | { |
39 | Q_ASSERT(thread() == QThread::currentThread()); |
40 | m_image->setPixmap(QPixmap::fromImage(image)); |
41 | } |
42 | |
43 | void MainWidget::setCaption(QString text) |
44 | { |
45 | m_caption->setText(text); |
46 | } |
47 | |
48 | void MainWidget::setStatus(QString text) |
49 | { |
50 | m_status->setText(text); |
51 | } |
52 | |
53 | #include "moc_MainWidget.cpp" |
54 | |