-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: IonutMuthi <[email protected]>
- Loading branch information
1 parent
defa4b1
commit 89feee5
Showing
6 changed files
with
333 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |