From ee82be38a73a631755eb1dc6520378caa22790c1 Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Fri, 16 Jul 2021 15:43:40 +0200 Subject: [PATCH] UI: Replace the simple help window by an about window with multiple tabs --- CMakeLists.txt | 1 + src/UI/AboutWindow.cc | 50 +++++++++++++++++++++++++++++++++++++++ src/UI/AboutWindow.hh | 28 ++++++++++++++++++++++ src/UI/DialogHelp.cc | 54 ------------------------------------------- src/UI/DialogHelp.hh | 26 --------------------- src/UI/MainWindow.cc | 16 ++++++++++--- src/UI/MainWindow.hh | 10 ++++---- 7 files changed, 98 insertions(+), 87 deletions(-) create mode 100644 src/UI/AboutWindow.cc create mode 100644 src/UI/AboutWindow.hh delete mode 100644 src/UI/DialogHelp.cc delete mode 100644 src/UI/DialogHelp.hh diff --git a/CMakeLists.txt b/CMakeLists.txt index 3159722c..358bb9fd 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 00000000..2067e34c --- /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 00000000..7e498a77 --- /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 bd0abab3..00000000 --- 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 0bb5d9e0..00000000 --- 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 a362c375..cee2d3c2 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 d42f057c..0b4b82f1 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 -- GitLab