Skip to content

Commit 1d2660b

Browse files
committed
Merge #357 [stable-3.16] nmc/2025/2278-Welcome_Popup_Wizard
2 parents 7ec796b + 7174efd commit 1d2660b

4 files changed

Lines changed: 430 additions & 2 deletions

File tree

src/gui/nmcgui/nmcadvertwidget.cpp

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
/*
2+
* Copyright (C) by Eugen Fischer
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but
10+
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* for more details.
13+
*/
14+
15+
#include "nmcadvertwidget.h"
16+
#include <QDebug>
17+
#include <QEvent>
18+
#include <QApplication>
19+
#include <QBoxLayout>
20+
#include <QGraphicsPixmapItem>
21+
22+
NMCAdvertWidget::NMCAdvertWidget(QWidget *parent)
23+
: QWidget(parent),
24+
m_graphicsView(new NMCCustomGraphicsView(this))
25+
{
26+
setFixedSize(700, 502);
27+
auto *layout = new QHBoxLayout(this);
28+
setLayout(layout);
29+
30+
m_graphicsView->setScene(&m_graphicsScene);
31+
layout->addWidget(m_graphicsView);
32+
layout->setContentsMargins(0, 0, 0, 0);
33+
34+
m_graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
35+
m_graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
36+
37+
generatePixmapList(QStringLiteral(":/client/theme/NMCIcons/configuration1.png"));
38+
generatePixmapList(QStringLiteral(":/client/theme/NMCIcons/configuration2.png"));
39+
generatePixmapList(QStringLiteral(":/client/theme/NMCIcons/configuration3.png"));
40+
41+
initStartButton();
42+
43+
// Set initial page
44+
m_graphicsView->show();
45+
46+
m_arrow_left = new NMCClickableLabel(m_graphicsView);
47+
m_arrow_left->setPixmap(QIcon(QStringLiteral(":/client/theme/NMCIcons/navigation-left.svg")).pixmap(32, 32));
48+
connect(m_arrow_left, &NMCClickableLabel::clicked, this, [this]() {
49+
m_animationTimer.stop();
50+
loadPicture(false);
51+
});
52+
53+
m_arrow_right = new NMCClickableLabel(m_graphicsView);
54+
m_arrow_right->setPixmap(QIcon(QStringLiteral(":/client/theme/NMCIcons/navigation-right.svg")).pixmap(32, 32));
55+
connect(m_arrow_right, &NMCClickableLabel::clicked, this, [this]() {
56+
m_animationTimer.stop();
57+
loadPicture();
58+
});
59+
60+
if (!m_pixmapList.empty()) {
61+
loadPNG(m_pixmapList.first());
62+
m_currentImageId = 0;
63+
}
64+
65+
m_animationTimer.setInterval(5000);
66+
connect(&m_animationTimer, &QTimer::timeout, this, [this]() {
67+
++m_currentImageId;
68+
if (m_currentImageId >= m_pixmapList.size()) {
69+
m_currentImageId = 0;
70+
}
71+
selectTextByID();
72+
});
73+
74+
m_animationTimer.start();
75+
setStartButton();
76+
setDetailText(QCoreApplication::translate("", "ADVERT_DETAIL_TEXT_1"));
77+
setHeaderText(QCoreApplication::translate("", "ADVERT_HEADER_TEXT_1"));
78+
setHeader(QCoreApplication::translate("", "ADVERT_HEADER_1"));
79+
setArrows();
80+
}
81+
void NMCAdvertWidget::loadPNG(const QPixmap &pixmap)
82+
{
83+
auto *pixmapItem = m_graphicsScene.addPixmap(pixmap.scaled(window()->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
84+
if (pixmapItem) {
85+
m_graphicsView->setFixedSize(pixmapItem->pixmap().size());
86+
m_graphicsView->update();
87+
}
88+
}
89+
90+
void NMCAdvertWidget::generatePixmapList(const QString &name)
91+
{
92+
QPixmap pixmap(name);
93+
m_pixmapList.append(pixmap.scaled(window()->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
94+
}
95+
96+
void NMCAdvertWidget::initStartButton()
97+
{
98+
if (!m_pushButton)
99+
{
100+
m_pushButton = new QPushButton(QCoreApplication::translate("", "START_NOW"), m_graphicsView);
101+
m_pushButton->setStyleSheet(QStringLiteral(
102+
"QPushButton {"
103+
" font-size: 15px;"
104+
" border: 0px solid black;"
105+
" border-radius: 4px;"
106+
" background-color: white;"
107+
" color: black;"
108+
"}"
109+
"QPushButton:hover {"
110+
" background-color: #ededed;"
111+
"}"
112+
));
113+
m_pushButton->setFixedSize(130, 32);
114+
115+
connect(m_pushButton, &QPushButton::clicked, this, &NMCAdvertWidget::close);
116+
}
117+
}
118+
119+
void NMCAdvertWidget::setStartButton()
120+
{
121+
if (m_pushButton && m_graphicsView)
122+
{
123+
m_graphicsScene.addWidget(m_pushButton);
124+
m_pushButton->setGeometry(m_graphicsView->width() / 2 - 60, m_graphicsView->height() - 64, 120, 32);
125+
}
126+
}
127+
128+
void NMCAdvertWidget::setDetailText(const QString &p_text)
129+
{
130+
if (!m_detailText)
131+
{
132+
m_detailText = new QLabel(p_text, m_graphicsView);
133+
m_detailText->setWordWrap(true);
134+
m_detailText->setAlignment(Qt::AlignCenter);
135+
m_detailText->setStyleSheet(QStringLiteral("font-size: 15px; color: white"));
136+
m_graphicsScene.addWidget(m_detailText);
137+
}
138+
else
139+
{
140+
m_detailText->setText(p_text);
141+
}
142+
143+
m_detailText->setFixedWidth(380);
144+
145+
int detailTextY = m_graphicsView->height() - 88 - m_detailText->sizeHint().height();
146+
int detailTextX = m_graphicsView->width() / 2 - m_detailText->sizeHint().width() / 2;
147+
148+
m_detailText->setGeometry(detailTextX, detailTextY, m_detailText->sizeHint().width(), m_detailText->sizeHint().height());
149+
}
150+
151+
void NMCAdvertWidget::setHeaderText(const QString &p_text)
152+
{
153+
if (!m_headerText)
154+
{
155+
m_headerText = new QLabel(p_text, m_graphicsView);
156+
m_headerText->setWordWrap(true);
157+
m_headerText->setAlignment(Qt::AlignCenter);
158+
m_headerText->setStyleSheet(QStringLiteral("font-size: 28px; color: white"));
159+
m_graphicsScene.addWidget(m_headerText);
160+
}
161+
else
162+
{
163+
m_headerText->setText(p_text);
164+
}
165+
166+
int headerTextY = m_graphicsView->height() - 96 - m_detailText->sizeHint().height() - m_headerText->sizeHint().height();
167+
int headerTextX = m_graphicsView->width() / 2 - m_headerText->sizeHint().width() / 2;
168+
169+
m_headerText->setGeometry(headerTextX, headerTextY, m_headerText->sizeHint().width(), m_headerText->sizeHint().height());
170+
}
171+
172+
void NMCAdvertWidget::setHeader(const QString &p_text)
173+
{
174+
if (!m_header)
175+
{
176+
m_header = new QLabel(p_text, m_graphicsView);
177+
m_header->setAlignment(Qt::AlignCenter);
178+
m_header->setStyleSheet(QStringLiteral("font-size: 22px; color: white; font-weight: bold;"));
179+
m_graphicsScene.addWidget(m_header);
180+
}
181+
else
182+
{
183+
m_header->setText(p_text);
184+
}
185+
186+
int headerY = m_graphicsView->height() - 146 - m_detailText->sizeHint().height() - m_headerText->sizeHint().height();
187+
int headerX = m_graphicsView->width() / 2 - m_header->sizeHint().width() / 2;
188+
189+
m_header->setGeometry(headerX, headerY, m_header->sizeHint().width(), m_header->sizeHint().height());
190+
}
191+
192+
void NMCAdvertWidget::setArrows()
193+
{
194+
int arrowY = m_graphicsView->height() - 130;
195+
m_arrow_left->move(qMax(112, 20), arrowY);
196+
m_arrow_right->move(qMin(m_graphicsView->width() - 130, m_graphicsView->width() - 50), arrowY);
197+
}
198+
199+
void NMCAdvertWidget::loadPicture(bool next)
200+
{
201+
m_currentImageId = (m_currentImageId + (next ? 1 : -1) + 3) % 3;
202+
selectTextByID();
203+
}
204+
205+
void NMCAdvertWidget::selectTextByID()
206+
{
207+
loadPNG(m_pixmapList.at(m_currentImageId));
208+
209+
switch (m_currentImageId) {
210+
case 0:
211+
setDetailText(QCoreApplication::translate("", "ADVERT_DETAIL_TEXT_1"));
212+
setHeaderText(QCoreApplication::translate("", "ADVERT_HEADER_TEXT_1"));
213+
break;
214+
case 1:
215+
setDetailText(QCoreApplication::translate("", "ADVERT_DETAIL_TEXT_2"));
216+
setHeaderText(QCoreApplication::translate("", "ADVERT_HEADER_TEXT_2"));
217+
break;
218+
case 2:
219+
setDetailText(QCoreApplication::translate("", "ADVERT_DETAIL_TEXT_3"));
220+
setHeaderText(QCoreApplication::translate("", "ADVERT_HEADER_TEXT_3"));
221+
break;
222+
default:
223+
break;
224+
}
225+
226+
if (m_header)
227+
{
228+
m_header->setVisible(m_currentImageId == 0);
229+
}
230+
}

0 commit comments

Comments
 (0)