diff --git a/CMakeLists.txt b/CMakeLists.txt index e7f8373..c776517 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ endif () #LibExiv2_FOUND set (PPIC_CPP_FILES app/main.cpp + app/framelesswindow.cpp app/mainwindow.cpp app/graphicsview.cpp app/graphicsscene.cpp @@ -44,6 +45,7 @@ set (PPIC_CPP_FILES ) set (PPIC_HEADER_FILES + app/framelesswindow.h app/mainwindow.h app/graphicsview.h app/graphicsscene.h diff --git a/app/framelesswindow.cpp b/app/framelesswindow.cpp new file mode 100644 index 0000000..d2fdee9 --- /dev/null +++ b/app/framelesswindow.cpp @@ -0,0 +1,23 @@ +#include "framelesswindow.h" + +#include + +FramelessWindow::FramelessWindow(QWidget *parent) + : QWidget(parent) + , m_centralLayout(new QVBoxLayout(this)) +{ + this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint); + + m_centralLayout->setMargin(0); +} + +void FramelessWindow::setCentralWidget(QWidget *widget) +{ + if (m_centralWidget) { + m_centralLayout->removeWidget(m_centralWidget); + m_centralWidget->deleteLater(); + } + + m_centralLayout->addWidget(widget); + m_centralWidget = widget; +} diff --git a/app/framelesswindow.h b/app/framelesswindow.h new file mode 100644 index 0000000..28ab8cc --- /dev/null +++ b/app/framelesswindow.h @@ -0,0 +1,25 @@ +#ifndef FRAMELESSWINDOW_H +#define FRAMELESSWINDOW_H + +#include + +QT_BEGIN_NAMESPACE +class QVBoxLayout; +QT_END_NAMESPACE + +class FramelessWindow : public QWidget +{ + Q_OBJECT +public: + explicit FramelessWindow(QWidget *parent = nullptr); + + void setCentralWidget(QWidget * widget); + +signals: + +private: + QVBoxLayout * m_centralLayout = nullptr; + QWidget * m_centralWidget = nullptr; // just a pointer, doesn't take the ownership. +}; + +#endif // FRAMELESSWINDOW_H diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index 1d67962..ef87b3c 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -31,12 +31,10 @@ #endif // _WIN32 MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent) + FramelessWindow(parent) { if (Settings::instance()->stayOnTop()) { - this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint | Qt::WindowStaysOnTopHint); - } else { - this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint); + this->setWindowFlag(Qt::WindowStaysOnTopHint); } this->setAttribute(Qt::WA_TranslucentBackground, true); @@ -55,7 +53,7 @@ MainWindow::MainWindow(QWidget *parent) : m_exitAnimationGroup->addAnimation(m_fadeOutAnimation); m_exitAnimationGroup->addAnimation(m_floatUpAnimation); connect(m_exitAnimationGroup, &QParallelAnimationGroup::finished, - this, &QMainWindow::close); + this, &QWidget::close); GraphicsScene * scene = new GraphicsScene(this); @@ -290,7 +288,7 @@ void MainWindow::showEvent(QShowEvent *event) { updateWidgetsPosition(); - return QMainWindow::showEvent(event); + return FramelessWindow::showEvent(event); } void MainWindow::enterEvent(QEvent *event) @@ -302,7 +300,7 @@ void MainWindow::enterEvent(QEvent *event) m_prevButton->setOpacity(1); m_nextButton->setOpacity(1); - return QMainWindow::enterEvent(event); + return FramelessWindow::enterEvent(event); } void MainWindow::leaveEvent(QEvent *event) @@ -314,7 +312,7 @@ void MainWindow::leaveEvent(QEvent *event) m_prevButton->setOpacity(0); m_nextButton->setOpacity(0); - return QMainWindow::leaveEvent(event); + return FramelessWindow::leaveEvent(event); } void MainWindow::mousePressEvent(QMouseEvent *event) @@ -327,7 +325,7 @@ void MainWindow::mousePressEvent(QMouseEvent *event) event->accept(); } - return QMainWindow::mousePressEvent(event); + return FramelessWindow::mousePressEvent(event); } void MainWindow::mouseMoveEvent(QMouseEvent *event) @@ -343,14 +341,14 @@ void MainWindow::mouseMoveEvent(QMouseEvent *event) event->accept(); } - return QMainWindow::mouseMoveEvent(event); + return FramelessWindow::mouseMoveEvent(event); } void MainWindow::mouseReleaseEvent(QMouseEvent *event) { m_clickedOnWindow = false; - return QMainWindow::mouseReleaseEvent(event); + return FramelessWindow::mouseReleaseEvent(event); } void MainWindow::mouseDoubleClickEvent(QMouseEvent *event) @@ -391,7 +389,7 @@ void MainWindow::wheelEvent(QWheelEvent *event) m_graphicsView->zoomView(zoomIn ? 1.25 : 0.8); event->accept(); } else { - QMainWindow::wheelEvent(event); + FramelessWindow::wheelEvent(event); } } @@ -399,7 +397,7 @@ void MainWindow::resizeEvent(QResizeEvent *event) { updateWidgetsPosition(); - return QMainWindow::resizeEvent(event); + return FramelessWindow::resizeEvent(event); } void MainWindow::contextMenuEvent(QContextMenuEvent *event) @@ -514,7 +512,7 @@ void MainWindow::contextMenuEvent(QContextMenuEvent *event) menu->exec(mapToGlobal(event->pos())); menu->deleteLater(); - return QMainWindow::contextMenuEvent(event); + return FramelessWindow::contextMenuEvent(event); } bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result) @@ -600,7 +598,7 @@ bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *r return false; #else - return QMainWindow::nativeEvent(eventType, message, result); + return FramelessWindow::nativeEvent(eventType, message, result); #endif // _WIN32 } diff --git a/app/mainwindow.h b/app/mainwindow.h index 24d73c7..a62c587 100644 --- a/app/mainwindow.h +++ b/app/mainwindow.h @@ -1,7 +1,8 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H -#include +#include "framelesswindow.h" + #include #include #include @@ -15,7 +16,7 @@ class ToolButton; class GraphicsView; class NavigatorView; class BottomButtonGroup; -class MainWindow : public QMainWindow +class MainWindow : public FramelessWindow { Q_OBJECT