Skip to content

Commit

Permalink
generic: what's new carousel popup
Browse files Browse the repository at this point in the history
Signed-off-by: IonutMuthi <[email protected]>
  • Loading branch information
IonutMuthi committed Nov 27, 2024
1 parent defa4b1 commit 89feee5
Show file tree
Hide file tree
Showing 6 changed files with 333 additions and 1 deletion.
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ file(GLOB UI_LIST *.ui)

set(PROJECT_SOURCES ${SRC_LIST} ${HEADER_LIST} ${UI_LIST})

include(ScopyWhatsNew)
set(FOLDER ${CMAKE_SOURCE_DIR}/resources/whatsnew/)
set(RESOURCE_FILE ${CMAKE_SOURCE_DIR}/resources/whatsnew/whatsnew.qrc)
generate_whats_new("${RESOURCE_FILE}" "${FOLDER}")
file(GLOB WHATS_NEW_RESOURCES resources/whatsnew/whatsnew.qrc)
qt_add_resources(SCOPY_RESOURCES ${WHATS_NEW_RESOURCES})

include(ScopyAbout)
configure_about(./resources/about)
file(GLOB SCOPY_RESOURCE_FILES gui/res/resources.qrc resources/aboutpage.qrc)
Expand All @@ -80,6 +87,16 @@ if(ENABLE_TRANSLATION)
qt_add_resources(SCOPY_RESOURCES ${CMAKE_BINARY_DIR}/translations.qrc)
endif()

# file(GLOB WHATS_NEW_FILES ${CMAKE_CURRENT_SOURCE_DIR}/resources/whatsnew/*.html) set_source_files_properties(
# ${WHATS_NEW_FILES} PROPERTIES OUTPUT_LOCATION ${CMAKE_BINARY_DIR}/whatsnew MACOSX_PACKAGE_LOCATION
# ${CMAKE_BINARY_DIR}/whatsnew ) qt_add_translation(QM_FILES ${WHATS_NEW_FILES})

# set(WHATSNEW) foreach(file ${WHATS_NEW_FILES}) get_filename_component(file_name ${file} NAME_WE) set(WHATSNEW
# "${WHATSNEW}\n<file>${CMAKE_BINARY_DIR}/whatsnew/${file_name}</file>") endforeach()

# configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/resources/whatsnew/whatsnew.qrc ${CMAKE_CURRENT_BINARY_DIR}/whatsnew.qrc
# @ONLY )

if(DEFINED ENV{APPIMAGE})
add_compile_definitions(__appimage__)
endif()
Expand Down
45 changes: 45 additions & 0 deletions cmake/Modules/ScopyWhatsNew.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#
# Copyright (c) 2024 Analog Devices Inc.
#
# This file is part of Scopy
# (see https://www.github.com/analogdevicesinc/scopy).
#
# 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 3 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.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

if(DEFINED __INCLUDED_SCOPY_WHATS_NEW_CMAKE)
return()
endif()
set(__INCLUDED_SCOPY_WHATS_NEW_CMAKE TRUE)

function(generate_whats_new RESOURCE_FILE FOLDER)
# Specify the folder containing resources Create the list of HTML files recursively

file(GLOB_RECURSE HTML_FILES "${FOLDER}*.html")

# Start writing to the resource file
file(WRITE "${RESOURCE_FILE}" "<RCC>\n <qresource prefix=\"/whatsnew/\">\n")

# Loop through each HTML file and add it to the resource file
foreach(HTML_FILE ${HTML_FILES})
# Convert the file path to a resource path
file(RELATIVE_PATH relative ${FOLDER} ${HTML_FILE})

# Write the file to the resource file
file(APPEND "${RESOURCE_FILE}" " <file>${relative}</file>\n")
endforeach()

# End the resource file
file(APPEND "${RESOURCE_FILE}" " </qresource>\n</RCC>\n")
endfunction()
1 change: 1 addition & 0 deletions core/include/core/scopymainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public Q_SLOTS:
void handleScanner();
void enableScanner();
void deviceAutoconnect();
void showWhatsNew();

protected:
void closeEvent(QCloseEvent *event) override;
Expand Down
52 changes: 52 additions & 0 deletions core/include/core/whatsnewoverlay.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2024 Analog Devices Inc.
*
* This file is part of Scopy
* (see https://www.github.com/analogdevicesinc/scopy).
*
* 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 3 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/

#ifndef WHATSNEWOVERLAY_H
#define WHATSNEWOVERLAY_H

#include <QLabel>
#include <QWidget>
#include <popupwidget.h>
#include "scopy-core_export.h"
#include <QComboBox>
#include <QStackedWidget>

namespace scopy {
class SCOPY_CORE_EXPORT WhatsNewOverlay : public QWidget
{
Q_OBJECT
public:
explicit WhatsNewOverlay(QWidget *parent = nullptr);
~WhatsNewOverlay();

void showOverlay();

private:
PopupWidget *m_popupWidget;
QString getHtmlPageContent(QString fileName);
void initCarousel();
void generateVersionPage(QString filePath);

QStackedWidget *m_carouselWidget;
QComboBox *m_versionCb;
};
} // namespace scopy
#endif // WHATSNEWOVERLAY_H
18 changes: 17 additions & 1 deletion core/src/scopymainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <browsemenu.h>
#include <deviceautoconnect.h>
#include <style.h>
#include <whatsnewoverlay.h>

#include "logging_categories.h"
#include "qmessagebox.h"
Expand Down Expand Up @@ -255,6 +256,13 @@ void ScopyMainWindow::deviceAutoconnect()
}
}

void ScopyMainWindow::showWhatsNew()
{
WhatsNewOverlay *whatsNew = new WhatsNewOverlay(this);
whatsNew->move(this->rect().center() - whatsNew->rect().center());
QMetaObject::invokeMethod(whatsNew, &WhatsNewOverlay::showOverlay, Qt::QueuedConnection);
}

void ScopyMainWindow::save()
{
QString selectedFilter;
Expand Down Expand Up @@ -352,16 +360,23 @@ void ScopyMainWindow::setupPreferences()
if(p->get("general_show_status_bar").toBool()) {
StatusBarManager::GetInstance()->setEnabled(true);
}

if(p->get("general_first_run").toBool()) {
license = new LicenseOverlay(this);
auto versionCheckInfo = new VersionCheckMessage(this);

StatusBarManager::pushWidget(versionCheckInfo, "Should Scopy check for online versions?");

QMetaObject::invokeMethod(license, &LicenseOverlay::showOverlay, Qt::QueuedConnection);

connect(license->getContinueBtn(), &QPushButton::clicked, this, &ScopyMainWindow::showWhatsNew,
Qt::QueuedConnection);
}
}

if(p->get("general_show_whats_new").toBool() && !p->get("general_first_run").toBool()) {
showWhatsNew();
}
}
void ScopyMainWindow::initPreferences()
{
QElapsedTimer timer;
Expand All @@ -375,6 +390,7 @@ void ScopyMainWindow::initPreferences()
p->init("general_save_session", true);
p->init("general_save_attached", true);
p->init("general_doubleclick_attach", true);
p->init("general_show_whats_new", true);
#if defined(__linux__) && (defined(__arm__) || defined(__aarch64__))
p->init("general_use_opengl", false);
#else
Expand Down
201 changes: 201 additions & 0 deletions core/src/whatsnewoverlay.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
/*
* Copyright (c) 2024 Analog Devices Inc.
*
* This file is part of Scopy
* (see https://www.github.com/analogdevicesinc/scopy).
*
* 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 3 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/

#include "whatsnewoverlay.h"

#include <QCheckBox>
#include <QDir>
#include <QPushButton>
#include <qboxlayout.h>
#include <style.h>
#include <QDebug>
#include <QScrollArea>
#include <preferenceshelper.h>

using namespace scopy;

WhatsNewOverlay::WhatsNewOverlay(QWidget *parent)
: QWidget{parent}
{
// main layout vertical
// main is popup widget ??
this->resize(500, 400);
QVBoxLayout *mainLayout = new QVBoxLayout();
this->setLayout(mainLayout);

m_carouselWidget = new QStackedWidget(this);

// bottom of main layout has controll widget

QWidget *overlayControllWidget = new QWidget(this);
QVBoxLayout *overlayControllWidgetLayout = new QVBoxLayout(overlayControllWidget);

QWidget *optionsoverlayControllWidget = new QWidget(overlayControllWidget);
overlayControllWidgetLayout->addWidget(optionsoverlayControllWidget);
QHBoxLayout *optionsControllLayout = new QHBoxLayout(optionsoverlayControllWidget);
optionsoverlayControllWidget->setLayout(optionsControllLayout);

// TODO implement preference
QCheckBox *showAgain = new QCheckBox("Show this again", optionsoverlayControllWidget);
showAgain->setChecked(true);
optionsControllLayout->addWidget(showAgain);

connect(showAgain, &QCheckBox::toggled, this, [=](bool en) {
Preferences *p = Preferences::GetInstance();
p->set("general_show_whats_new", en);
});

// version picker
m_versionCb = new QComboBox(optionsoverlayControllWidget);
optionsControllLayout->addWidget(m_versionCb);

connect(m_versionCb, qOverload<int>(&QComboBox::currentIndexChanged), this,
[=](int idx) { m_carouselWidget->setCurrentIndex(idx); });

QPushButton *okButton = new QPushButton("Ok", optionsoverlayControllWidget);
connect(okButton, &QPushButton::clicked, this, [=]() { this->deleteLater(); });
Style::setStyle(okButton, style::properties::button::basicButton, true, true);
optionsControllLayout->addWidget(okButton);

mainLayout->addWidget(m_carouselWidget);
mainLayout->addWidget(overlayControllWidget);
Style::setBackgroundColor(this, json::theme::background_secondary);

initCarousel();
}

WhatsNewOverlay::~WhatsNewOverlay()
{
// TODO
}

void WhatsNewOverlay::showOverlay()
{
raise();
show();
}

void WhatsNewOverlay::initCarousel()
{
QDir dir(":/whatsnew");

// Get a list of all entries in the directory
QFileInfoList entries = dir.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name);

// Iterate through the list and print the folder names

for(int i = entries.count() - 1; i >= 0; i--) {
QFileInfo fileInfo = entries.at(i);
if(fileInfo.isDir()) {
// add option to combo
m_versionCb->addItem(fileInfo.fileName());
// create page and button for page
generateVersionPage(fileInfo.absoluteFilePath());
}
}
}

void WhatsNewOverlay::generateVersionPage(QString filePath)
{
QWidget *carouselContent = new QWidget(m_carouselWidget);
QVBoxLayout *carouselContentLayout = new QVBoxLayout(carouselContent);

// carousel control contains buttons for changeing info page
QWidget *carouselControllWidget = new QWidget(carouselContent);

QHBoxLayout *carouselControllLayout = new QHBoxLayout(carouselControllWidget);
carouselControllWidget->setLayout(carouselControllLayout);

QPushButton *previous = new QPushButton("<", carouselControllWidget);

QPushButton *next = new QPushButton(">", carouselControllWidget);

Style::setStyle(previous, style::properties::button::basicButton, true, true);
Style::setStyle(next, style::properties::button::basicButton, true, true);

carouselControllLayout->addWidget(previous);

QStackedWidget *versionCarouselWithControlls = new QStackedWidget(m_carouselWidget);

QDir versionDir(filePath);
QFileInfoList fileList = versionDir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot);

int i = 0;
for(const QFileInfo &page : fileList) {

QWidget *scrollWidget = new QWidget();
scrollWidget->setLayout(new QVBoxLayout());
QScrollArea *scrollArea = new QScrollArea();
scrollArea->setWidgetResizable(true);
scrollArea->setWidget(scrollWidget);

QTextBrowser *htmlPage = new QTextBrowser(scrollWidget);
QString filePath(page.absoluteFilePath());
htmlPage->setHtml(getHtmlPageContent(filePath));
htmlPage->setProperty("openExternalLinks", true);

scrollWidget->layout()->addWidget(htmlPage);
versionCarouselWithControlls->addWidget(scrollArea);

QPushButton *htmlPageButton = new QPushButton("", carouselControllWidget);

connect(htmlPageButton, &QPushButton::clicked, this,
[=]() { versionCarouselWithControlls->setCurrentIndex(i); });

carouselControllLayout->addWidget(htmlPageButton);
Style::setStyle(htmlPageButton, style::properties::button::basicButton, true, true);
i++;
}

carouselControllLayout->addWidget(next);

connect(previous, &QPushButton::clicked, this, [=]() {
int currentIndex = versionCarouselWithControlls->currentIndex();
versionCarouselWithControlls->setCurrentIndex(
(currentIndex - 1 + versionCarouselWithControlls->count()) %
versionCarouselWithControlls->count());
});

connect(next, &QPushButton::clicked, this, [=]() {
int currentIndex = versionCarouselWithControlls->currentIndex();
versionCarouselWithControlls->setCurrentIndex((currentIndex + 1) %
versionCarouselWithControlls->count());
});

carouselContentLayout->addWidget(versionCarouselWithControlls);
carouselContentLayout->addWidget(carouselControllWidget);

m_carouselWidget->addWidget(carouselContent);
}

QString WhatsNewOverlay::getHtmlPageContent(QString fileName)
{
QFile file(fileName);
file.open(QIODevice::ReadOnly);
QString text = QString(file.readAll());
file.close();

return text;
}

#include "moc_whatsnewoverlay.cpp"

#include <pluginbase/preferences.h>

0 comments on commit 89feee5

Please sign in to comment.