Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nmc/2025/2278-Welcome_Popup_Wizard #354

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ find_package(Qt${QT_MAJOR_VERSION} REQUIRED COMPONENTS Widgets Svg Qml Quick Qui
find_package(KF6Archive REQUIRED)
find_package(KF6GuiAddons)

#NMC customization: needed to find the ui file in a different location than the header file
set(CMAKE_AUTOUIC_SEARCH_PATHS "${CMAKE_SOURCE_DIR}/src/gui")

if (NOT TARGET Qt::GuiPrivate)
message(FATAL_ERROR "Could not find GuiPrivate component of Qt. It might be shipped as a separate package, please check that.")
endif()
Expand Down Expand Up @@ -257,6 +260,10 @@ set(client_SRCS
wizard/linklabel.cpp
)

file(GLOB NMC_FILES "nmcgui/*")
set(NMC_SRCS ${NMC_FILES})
list(APPEND client_SRCS ${NMC_SRCS})

if (WITH_WEBENGINE)
list(APPEND client_SRCS
wizard/webviewpage.h
Expand Down
238 changes: 238 additions & 0 deletions src/gui/nmcgui/nmcadvertwidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
/*
* Copyright (C) by Eugen Fischer
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/

#include "nmcadvertwidget.h"
#include "QtCore/qdebug.h"
#include "QtGui/qevent.h"
#include "QtWidgets/qapplication.h"
#include "QtWidgets/qboxlayout.h"
#include "QGraphicsPixmapItem"

NMCAdvertWidget::NMCAdvertWidget(QWidget *parent) : QWidget(parent)
,m_graphicsView(new NMCCustomGraphicsView(this))
{
setFixedSize(700,502);
QHBoxLayout *layout = new QHBoxLayout(this);
setLayout(layout);
m_graphicsView->setScene(&m_graphicsScene);
layout->addWidget(m_graphicsView);
layout->setContentsMargins(0, 0, 0, 0);

m_graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

generatePixmapList(":/client/theme/NMCIcons/configuration1.png");
generatePixmapList(":/client/theme/NMCIcons/configuration2.png");
generatePixmapList(":/client/theme/NMCIcons/configuration3.png");

initStartButton();

//Set initial page
m_graphicsView->show();

m_arrow_left = new NMCClickableLabel(m_graphicsView);
m_arrow_left->setPixmap(QIcon(QLatin1String(":/client/theme/NMCIcons/navigation-left.svg")).pixmap(32,32));
connect(m_arrow_left, &NMCClickableLabel::clicked, this, [this](){
m_animationTimer.stop();
loadPicture(false);
});

m_arrow_right = new NMCClickableLabel(m_graphicsView);
m_arrow_right->setPixmap(QIcon(QLatin1String(":/client/theme/NMCIcons/navigation-right.svg")).pixmap(32,32));
connect(m_arrow_right, &NMCClickableLabel::clicked, this, [this](){
m_animationTimer.stop();
loadPicture();
});

if(!m_pixmapList.empty())
{
loadPNG(m_pixmapList.first());
m_currentImageId = 0;
}

m_animationTimer.setInterval(5000);
connect(&m_animationTimer, &QTimer::timeout, this, [this](){

++m_currentImageId;
if(m_pixmapList.size()-1 < m_currentImageId)
{
m_currentImageId = 0;
}
selectTextByID();
});

m_animationTimer.start();
setStartButton();
setDetailText(QCoreApplication::translate("", "ADVERT_DETAIL_TEXT_1"));
setHeaderText(QCoreApplication::translate("", "ADVERT_HEADER_TEXT_1"));
setHeader(QCoreApplication::translate("", "ADVERT_HEADER_1"));
setArrows();
}

void NMCAdvertWidget::loadPNG(const QPixmap &pixmap)
{
QGraphicsPixmapItem *pixmapItem = m_graphicsScene.addPixmap(pixmap.scaled(window()->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
m_graphicsView->setFixedSize(pixmapItem->pixmap().size());
m_graphicsView->update();
}

void NMCAdvertWidget::generatePixmapList(const QString &name)
{
QPixmap pixmap(name);
m_pixmapList.append(pixmap.scaled(window()->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
}

void NMCAdvertWidget::initStartButton()
{
if(m_pushButton == nullptr)
{
m_pushButton = new QPushButton(QCoreApplication::translate("", "START_NOW"), m_graphicsView);
if(m_pushButton != nullptr)
{
const QString styleSheet = "QPushButton {"
" font-size: 15px;"
" border: 0px solid black;"
" border-radius: 4px;"
" background-color: white;"
" color: black;"
"}"
"QPushButton:hover {"
" background-color: #ededed;"
"}";
m_pushButton->setStyleSheet(styleSheet);
m_pushButton->setFixedSize(130,32);

connect(m_pushButton, &QPushButton::clicked, this, [this](){
this->close();
});
}
}
}

void NMCAdvertWidget::setStartButton()
{
if (m_pushButton != nullptr && m_graphicsView != nullptr)
{
m_graphicsScene.addWidget(m_pushButton);
m_pushButton->setGeometry(m_graphicsView->width()/2 - 60, m_graphicsView->height() - 32 - 32, 120, 32);
}
}

void NMCAdvertWidget::setDetailText(const QString &p_text)
{
if(m_detailText)
{
m_detailText->setText(p_text);
}
else{
m_detailText = new QLabel(p_text, m_graphicsView);
}

m_detailText->setFixedWidth(380);
m_detailText->setStyleSheet("font-size: 15px; color: white");
m_detailText->setWordWrap(true);
m_detailText->setAlignment(Qt::AlignCenter);

m_graphicsScene.addWidget(m_detailText);
//88 is the result of all margins and buttonszie
m_detailText->setGeometry(m_graphicsView->width()/2 - m_detailText->sizeHint().width()/2, m_graphicsView->height() - 88 - m_detailText->sizeHint().height(), m_detailText->sizeHint().width(), m_detailText->sizeHint().height());
}

void NMCAdvertWidget::setHeaderText(const QString &p_text)
{
if(m_headerText)
{
m_headerText->setText(p_text);
}
else{
m_headerText = new QLabel(p_text, m_graphicsView);
}

m_headerText->setFixedWidth(380);
m_headerText->setStyleSheet("font-size: 28px; color: white");
m_headerText->setWordWrap(true);
m_headerText->setAlignment(Qt::AlignCenter);

m_graphicsScene.addWidget(m_headerText);
//96 is the result of all margins and buttonszie
m_headerText->setGeometry(m_graphicsView->width()/2 - m_headerText->sizeHint().width()/2, m_graphicsView->height() - 96 - m_detailText->sizeHint().height() - m_headerText->sizeHint().height(), m_headerText->sizeHint().width(), m_headerText->sizeHint().height());
}

void NMCAdvertWidget::setHeader(const QString &p_text)
{
m_header = new QLabel(p_text, m_graphicsView);
m_header->setStyleSheet("font-size: 22px; color: white; font-weight: bold;");
m_header->setAlignment(Qt::AlignCenter);

m_graphicsScene.addWidget(m_header);
//146 is the result of all margins and buttonszie
m_header->setGeometry(m_graphicsView->width()/2 - m_header->sizeHint().width()/2, m_graphicsView->height() - 146 - m_detailText->sizeHint().height() - m_headerText->sizeHint().height(), m_header->sizeHint().width(), m_header->sizeHint().height());
}

void NMCAdvertWidget::setArrows()
{
m_arrow_left->move( 112, m_graphicsView->height() - 130);
m_arrow_right->move( m_graphicsView->width() - 130, m_graphicsView->height() - 130);
}

void NMCAdvertWidget::loadPicture(bool next)
{
if(next)
{
++m_currentImageId;
}
else{
--m_currentImageId;
}
if(m_currentImageId < 0)
{
m_currentImageId = 2;
}
if(m_currentImageId > 2)
{
m_currentImageId = 0;
}

selectTextByID();
}

void NMCAdvertWidget::selectTextByID()
{
loadPNG(m_pixmapList.at(m_currentImageId));

switch (m_currentImageId) {
case 0: {
setDetailText(QCoreApplication::translate("", "ADVERT_DETAIL_TEXT_1"));
setHeaderText(QCoreApplication::translate("", "ADVERT_HEADER_TEXT_1"));
break;
}
case 1: {
setDetailText(QCoreApplication::translate("", "ADVERT_DETAIL_TEXT_2"));
setHeaderText(QCoreApplication::translate("", "ADVERT_HEADER_TEXT_2"));
break;
}
case 2: {
setDetailText(QCoreApplication::translate("", "ADVERT_DETAIL_TEXT_3"));
setHeaderText(QCoreApplication::translate("", "ADVERT_HEADER_TEXT_3"));
break;
}
default:
break;
}

if(m_header)
{
m_currentImageId != 0 ? m_header->setVisible(false) : m_header->setVisible(true);
}
}
Loading