diff --git a/CMakeLists.txt b/CMakeLists.txt index 3159722c543f7c58d882ba6f9f19b489847e9fb8..358bb9fd0fd49a8d7a4e65518acc8314ef4303ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,6 +62,7 @@ target_precompile_headers(Vivy PRIVATE # STL headers <memory> <vector> + <atomic> # Qt headers <QString> diff --git a/src/UI/AboutWindow.cc b/src/UI/AboutWindow.cc new file mode 100644 index 0000000000000000000000000000000000000000..2067e34c4bed4318f89d998fe6e5afd30e768e17 --- /dev/null +++ b/src/UI/AboutWindow.cc @@ -0,0 +1,50 @@ +#include "AboutWindow.hh" + +#include <QCloseEvent> + +using namespace Vivy; + +// See https://doc.qt.io/qt-5/richtext-html-subset.html for the supported +// rich text subset. +static const char *aboutContent = + "<body>" + " <h1>About Vivy</h1>" + " <p>Vivy is a replacement for Aegisub, writen in Qt5+and with less segfaults - hopefully.</p>" + " <p>The following libraries where used:</p>" + " <ul>" + " <li>Qt5</li>" + " <li>Lua</li>" + " <li>libavutils</li>" + " <li>libavcodec</li>" + " <li>libavformat</li>" + " </ul>" + "</body>"; + +AboutWindow::AboutWindow(QWidget *parent) noexcept + : QMainWindow(parent) +{ + setWindowIcon(QIcon(":/icons/vivy.png")); + panels = new QTabWidget(this); + panels->setMovable(false); + panels->setTabsClosable(false); + panels->setElideMode(Qt::ElideRight); + panels->setUsesScrollButtons(true); + panels->setDocumentMode(false); + setCentralWidget(panels); + + // Simple about message + QLabel *aboutLabel = new QLabel(panels); + aboutLabel->setTextFormat(Qt::RichText); + aboutLabel->setText(aboutContent); + aboutLabel->setTextInteractionFlags(Qt::NoTextInteraction); + + // Add the panels + panels->addTab(aboutLabel, "About"); +} + +void +AboutWindow::closeEvent(QCloseEvent *event) noexcept +{ + emit closed(); + event->accept(); +} diff --git a/src/UI/AboutWindow.hh b/src/UI/AboutWindow.hh new file mode 100644 index 0000000000000000000000000000000000000000..7e498a771e104ae7e7d292110bf21380a8ec2129 --- /dev/null +++ b/src/UI/AboutWindow.hh @@ -0,0 +1,28 @@ +#pragma once + +#ifndef __cplusplus +#error "This is a C++ header" +#endif + +#include <QMainWindow> +#include <QTabWidget> +#include <QLabel> + +namespace Vivy +{ +class AboutWindow final : public QMainWindow { + Q_OBJECT + + QTabWidget *panels; + +public: + explicit AboutWindow(QWidget *parent) noexcept; + ~AboutWindow() noexcept = default; + +signals: + void closed(); + +private: + void closeEvent(QCloseEvent *bar) noexcept override; +}; +} diff --git a/src/UI/DialogHelp.cc b/src/UI/DialogHelp.cc deleted file mode 100644 index bd0abab31efb949dabe7df5a357e9eedb98b9953..0000000000000000000000000000000000000000 --- a/src/UI/DialogHelp.cc +++ /dev/null @@ -1,54 +0,0 @@ -#include "DialogHelp.hh" -#include "../VivyApplication.hh" - -#include <QWidget> -#include <QLabel> -#include <QDialog> -#include <QPixmap> - -using namespace Vivy; - -// See https://doc.qt.io/qt-5/richtext-html-subset.html for the supported -// rich text subset. -static const char *aboutContentHeader = - "<body>" - "<h1>About Vivy</h1>" - "<p>Vivy is a replacement for Aegisub, writen in Qt5+and with less segfaults - hopefully.</p>" - "<p>The following libraries where used:</p>" - "<ul>" - " <li>Qt5</li>" - " <li>libavutils</li>" - " <li>libavcodec</li>" - " <li>libavformat</li>" - "</ul>"; -static const char *aboutContentFooter = "</body>"; - -DialogHelp::DialogHelp(QWidget *parent) noexcept - : QMessageBox(parent) -{ - setWindowTitle("Vivy - Help"); - setWindowFlags(Qt::Dialog); - setWindowModality(Qt::WindowModal); - QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - setSizePolicy(sizePolicy); - - setTextFormat(Qt::RichText); - setText(getAboutContent()); - setTextInteractionFlags(Qt::NoTextInteraction); - - adjustSize(); -} - -QString -DialogHelp::getAboutContent() const noexcept -{ - QString ret; - ret = aboutContentHeader; - - ret.append("<p>Vivy will handle the following most of the video and audio formats."); - ret.append("The audio formats are: " + Utils::audioFileSuffix.join(", ")); - ret.append("The video formats are: " + Utils::videoFileSuffix.join(", ") + "</p>"); - - ret.append(aboutContentFooter); - return ret; -} diff --git a/src/UI/DialogHelp.hh b/src/UI/DialogHelp.hh deleted file mode 100644 index 0bb5d9e09810ba60765cc462ae16237ccca8814e..0000000000000000000000000000000000000000 --- a/src/UI/DialogHelp.hh +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef VIVY_DIALOGHELP_H -#define VIVY_DIALOGHELP_H - -#ifndef __cplusplus -#error "This is a C++ header" -#endif - -#include <QMessageBox> -#include <QWidget> - -namespace Vivy -{ -class DialogHelp final : public QMessageBox { - Q_OBJECT - -public: - explicit DialogHelp(QWidget *parent = nullptr) noexcept; - ~DialogHelp() noexcept = default; - -private: - QString getAboutContent() const noexcept; -}; - -} - -#endif // VIVY_DIALOGHELP_H diff --git a/src/UI/MainWindow.cc b/src/UI/MainWindow.cc index a362c375b6364c810f0530debb0d414d8ab2efde..cee2d3c26f88b5d8c1e2c9be0e5f8d86a8801a23 100644 --- a/src/UI/MainWindow.cc +++ b/src/UI/MainWindow.cc @@ -1,10 +1,11 @@ #include "MainWindow.hh" -#include "DialogHelp.hh" #include "PropertyModel.hh" #include "VivyDocumentView.hh" +#include "AboutWindow.hh" #include "../Lib/Utils.hh" #include "../VivyApplication.hh" +#include <mutex> #include <algorithm> #include <functional> #include <QWindow> @@ -21,6 +22,7 @@ #include <QImage> #include <QToolBar> #include <QTabWidget> +#include <QEventLoop> #define DCL_MENU(menu, name) [[maybe_unused]] QMenu *menu##Menu = menuBar()->addMenu(name); @@ -163,8 +165,16 @@ MainWindow::openProperties(int index) noexcept void MainWindow::openDialogHelp() noexcept { - std::unique_ptr<DialogHelp> help_holder = std::make_unique<DialogHelp>(this); - help_holder->exec(); + if (aboutWindowMutex.try_lock() && aboutWindow == nullptr) { + aboutWindow = new AboutWindow(this); + QEventLoop loop; + connect(aboutWindow, &AboutWindow::closed, &loop, &QEventLoop::quit); + aboutWindow->show(); + loop.exec(); + delete aboutWindow; + aboutWindow = nullptr; + aboutWindowMutex.unlock(); + } } AbstractDocument * diff --git a/src/UI/MainWindow.hh b/src/UI/MainWindow.hh index d42f057cb204720379445e45bc78bae675243f07..0b4b82f1d8a4d75ca233ab08fbc2d575b098d3f5 100644 --- a/src/UI/MainWindow.hh +++ b/src/UI/MainWindow.hh @@ -1,5 +1,4 @@ -#ifndef VIVY_MAINWINDOW_H -#define VIVY_MAINWINDOW_H +#pragma once #ifndef __cplusplus #error "This is a C++ header" @@ -10,9 +9,11 @@ #include "../Lib/Document/VivyDocumentStore.hh" #include "DocumentViews/AudioVisualizer.hh" #include "VivyDocumentView.hh" +#include "AboutWindow.hh" #include <QMainWindow> #include <QMenu> #include <QFileDialog> +#include <QMutex> namespace Vivy { @@ -22,6 +23,9 @@ class MainWindow final : public QMainWindow { QTabWidget *documents{ nullptr }; QMenu *viewMenu{ nullptr }; + QMutex aboutWindowMutex{ QMutex::NonRecursive }; + AboutWindow *aboutWindow{ nullptr }; + public: explicit MainWindow(QWidget *parent = nullptr) noexcept; ~MainWindow() noexcept = default; @@ -89,5 +93,3 @@ private slots: }; } - -#endif // VIVY_MAINWINDOW_H