From 03e977df97bd869cdf18c8bb478d37e2239ed30c Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Thu, 22 Jul 2021 22:28:30 +0200 Subject: [PATCH] UI: Get ride of the custom borderless windows --- src/UI/AboutWindow.cc | 6 ++- src/UI/AboutWindow.hh | 4 +- src/UI/MainWindow.cc | 8 +++- src/UI/MainWindow.hh | 4 +- src/UI/TitleBar.cc | 54 -------------------------- src/UI/TitleBar.hh | 31 --------------- src/UI/Window.cc | 90 ------------------------------------------- src/UI/Window.hh | 41 -------------------- 8 files changed, 15 insertions(+), 223 deletions(-) delete mode 100644 src/UI/TitleBar.cc delete mode 100644 src/UI/TitleBar.hh delete mode 100644 src/UI/Window.cc delete mode 100644 src/UI/Window.hh diff --git a/src/UI/AboutWindow.cc b/src/UI/AboutWindow.cc index 863f139b..c2a0867b 100644 --- a/src/UI/AboutWindow.cc +++ b/src/UI/AboutWindow.cc @@ -1,5 +1,4 @@ #include "AboutWindow.hh" -#include "TitleBar.hh" #include <QCloseEvent> #include <QLabel> @@ -76,9 +75,12 @@ public: // Construct the AboutWindow AboutWindow::AboutWindow(QWidget *parent) noexcept - : Window(QIcon(":icons/vivy.png"), "Vivy - About", parent) + : QMainWindow(parent) , panels(new QTabWidget) { + setWindowIcon(QIcon(VIVY_ICON_APP)); + setWindowTitle("Vivy - About"); + panels->setMovable(false); panels->setTabsClosable(false); panels->setElideMode(Qt::ElideRight); diff --git a/src/UI/AboutWindow.hh b/src/UI/AboutWindow.hh index 1cb97627..7e498a77 100644 --- a/src/UI/AboutWindow.hh +++ b/src/UI/AboutWindow.hh @@ -4,13 +4,13 @@ #error "This is a C++ header" #endif -#include "Window.hh" +#include <QMainWindow> #include <QTabWidget> #include <QLabel> namespace Vivy { -class AboutWindow final : public Window { +class AboutWindow final : public QMainWindow { Q_OBJECT QTabWidget *panels; diff --git a/src/UI/MainWindow.cc b/src/UI/MainWindow.cc index c4325c55..02dc1218 100644 --- a/src/UI/MainWindow.cc +++ b/src/UI/MainWindow.cc @@ -39,8 +39,14 @@ using namespace Vivy; MainWindow::MainWindow() noexcept - : Window(QIcon(VIVY_ICON_APP), "Vivy") + : QMainWindow() { + setWindowIcon(QIcon(VIVY_ICON_APP)); + setWindowTitle("Vivy"); + setDocumentMode(true); + setDockNestingEnabled(true); + setTabShape(QTabWidget::Rounded); + /* Some declarations */ DCL_MENU(file, "&File"); DCL_MENU(edit, "&Edit"); diff --git a/src/UI/MainWindow.hh b/src/UI/MainWindow.hh index f7c34848..24f65893 100644 --- a/src/UI/MainWindow.hh +++ b/src/UI/MainWindow.hh @@ -10,14 +10,14 @@ #include "DocumentViews/AudioVisualizer.hh" #include "VivyDocumentView.hh" #include "AboutWindow.hh" -#include "Window.hh" #include <QMenu> #include <QFileDialog> #include <QMutex> +#include <QMainWindow> namespace Vivy { -class MainWindow final : public Window { +class MainWindow final : public QMainWindow { Q_OBJECT QTabWidget *documents{ nullptr }; diff --git a/src/UI/TitleBar.cc b/src/UI/TitleBar.cc deleted file mode 100644 index 98688fdf..00000000 --- a/src/UI/TitleBar.cc +++ /dev/null @@ -1,54 +0,0 @@ -#include "TitleBar.hh" -#include <QMenuBar> -#include <QString> -#include <QPushButton> -#include <QLabel> -#include <QIcon> -#include <QPixmap> -#include <QHBoxLayout> - -using namespace Vivy; - -TitleBar::TitleBar(const QIcon &icon, const QString &title, QWidget *parent) noexcept - : QWidget(parent) -{ - auto titleLayout = new QHBoxLayout; - titleLayout->setContentsMargins(0, 0, 0, 0); - setLayout(titleLayout); - setContentsMargins(0, 0, 0, 0); - - auto *iconLabel = new QLabel(this); // Index 0 - titleLabel = new QLabel("<h2>" + title + "</h2>", this); // Index 1 - auto *closeButton = new QPushButton(this); - - connect(closeButton, &QAbstractButton::clicked, this, - [=, this]() noexcept -> void { emit closed(); }); - - iconLabel->setPixmap(icon.pixmap(icon.actualSize(QSize(32, 32)))); - titleLabel->setTextInteractionFlags(Qt::NoTextInteraction); - titleLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); - closeButton->setIconSize(QSize(22, 22)); - closeButton->setIcon(QIcon(VIVY_ICON_CLOSE)); - closeButton->setFlat(true); - closeButton->setDefault(false); - closeButton->setStyleSheet("color: #1394B4;" - "border: none;"); - - titleLayout->addWidget(iconLabel); - titleLayout->addWidget(titleLabel); - titleLayout->addWidget(closeButton); -} - -QMenuBar * -TitleBar::menuBar() const noexcept -{ - if (privateMenuBar == nullptr) { - privateMenuBar = new QMenuBar(); // Index 2 - QHBoxLayout *titleLayout = qobject_cast<QHBoxLayout *>(layout()); - titleLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - privateMenuBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); - titleLayout->insertWidget(2, privateMenuBar); - } - - return privateMenuBar; -} diff --git a/src/UI/TitleBar.hh b/src/UI/TitleBar.hh deleted file mode 100644 index 64a161ea..00000000 --- a/src/UI/TitleBar.hh +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#ifndef __cplusplus -#error "This is a C++ header" -#endif - -#include <QWidget> -#include "../Lib/Utils.hh" - -class QIcon; -class QString; -class QMenuBar; -class QLabel; - -namespace Vivy -{ -class TitleBar final : public QWidget { - Q_OBJECT - - mutable QMenuBar *privateMenuBar{ nullptr }; - mutable QLabel *titleLabel{ nullptr }; - -public: - explicit TitleBar(const QIcon &, const QString &title, QWidget *parent = nullptr) noexcept; - - QMenuBar *menuBar() const noexcept; - -signals: - void closed(); -}; -} diff --git a/src/UI/Window.cc b/src/UI/Window.cc deleted file mode 100644 index c4e8f182..00000000 --- a/src/UI/Window.cc +++ /dev/null @@ -1,90 +0,0 @@ -#include "Window.hh" -#include "TitleBar.hh" - -#include <QMenuBar> -#include <QCloseEvent> -#include <QLabel> -#include <QPushButton> -#include <QVBoxLayout> -#include <QHBoxLayout> -#include <QEvent> -#include <QMouseEvent> -#include <QApplication> - -using namespace Vivy; - -Window::Window(const QIcon &icon, const QString &title) noexcept - : QMainWindow() -{ - setUpWindow(icon, title); - - // Main Window only - setDocumentMode(true); - setDockNestingEnabled(true); - setTabShape(QTabWidget::Rounded); -} - -Window::Window(const QIcon &icon, const QString &title, QWidget *parent) noexcept - : QMainWindow(parent, Qt::Dialog) -{ - // This is a popup - setUpWindow(icon, title); -} - -void -Window::setUpWindow(const QIcon &icon, const QString &title) -{ - if (isInit) - throw std::logic_error("Try to init multiple times the same window"); - isInit = true; - - setWindowIcon(icon); - setWindowTitle(title); - - auto *widget = new QWidget(this); - centralLayout = new QVBoxLayout; - titleBar = new TitleBar(icon, title, this); - - connect(titleBar, &TitleBar::closed, this, &AboutWindow::close); - setWindowFlags(Qt::FramelessWindowHint | windowFlags()); - QMainWindow::setCentralWidget(widget); - widget->setLayout(centralLayout); - centralLayout->addWidget(titleBar); - - widget->setContentsMargins(0, 0, 0, 0); - centralLayout->setContentsMargins(0, 0, 0, 0); - - setAnimated(true); -} - -void -Window::setCentralWidget(QWidget *widget) noexcept -{ - centralLayout->removeWidget(centralWidget); - delete centralWidget; - centralWidget = widget; - centralLayout->addWidget(centralWidget); -} - -void -Window::setLayout(QLayout *layout) noexcept -{ - if (centralWidget) - centralWidget->setLayout(layout); -} - -QLayout * -Window::layout() const noexcept -{ - return centralWidget ? centralWidget->layout() : nullptr; -} - -QMenuBar * -Window::menuBar() const noexcept -{ -#ifndef VIVY_MACOS - return titleBar->menuBar(); -#else - return QMainWindow::menuBar(); -#endif -} diff --git a/src/UI/Window.hh b/src/UI/Window.hh deleted file mode 100644 index 58aeb360..00000000 --- a/src/UI/Window.hh +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -#ifndef __cplusplus -#error "This is a C++ header" -#endif - -#include "TitleBar.hh" -#include <QMainWindow> - -class QIcon; -class QLayout; -class QString; -class QMenuBar; - -namespace Vivy -{ -class Window : public QMainWindow { - Q_OBJECT - -protected: - explicit Window(const QIcon &, const QString &) noexcept; - explicit Window(const QIcon &, const QString &, QWidget *parent) noexcept; - -private: - void setUpWindow(const QIcon &, const QString &title); - - bool isInit{ false }; - QWidget *centralWidget{ nullptr }; - QLayout *centralLayout{ nullptr }; - TitleBar *titleBar{ nullptr }; - -public: - ~Window() noexcept = default; - - void setCentralWidget(QWidget *) noexcept; - void setLayout(QLayout *) noexcept; - QLayout *layout() const noexcept; - - QMenuBar *menuBar() const noexcept; -}; -} -- GitLab