chore: no longer based on QMainWindow
Since most of the features that QMainWindow offered will never be used in this program. We don't need a statusbar, a menubar, etc.
This commit is contained in:
parent
dc17e1d0b1
commit
3abc16d3ff
@ -28,6 +28,7 @@ endif ()
|
|||||||
#LibExiv2_FOUND
|
#LibExiv2_FOUND
|
||||||
set (PPIC_CPP_FILES
|
set (PPIC_CPP_FILES
|
||||||
app/main.cpp
|
app/main.cpp
|
||||||
|
app/framelesswindow.cpp
|
||||||
app/mainwindow.cpp
|
app/mainwindow.cpp
|
||||||
app/graphicsview.cpp
|
app/graphicsview.cpp
|
||||||
app/graphicsscene.cpp
|
app/graphicsscene.cpp
|
||||||
@ -44,6 +45,7 @@ set (PPIC_CPP_FILES
|
|||||||
)
|
)
|
||||||
|
|
||||||
set (PPIC_HEADER_FILES
|
set (PPIC_HEADER_FILES
|
||||||
|
app/framelesswindow.h
|
||||||
app/mainwindow.h
|
app/mainwindow.h
|
||||||
app/graphicsview.h
|
app/graphicsview.h
|
||||||
app/graphicsscene.h
|
app/graphicsscene.h
|
||||||
|
23
app/framelesswindow.cpp
Normal file
23
app/framelesswindow.cpp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#include "framelesswindow.h"
|
||||||
|
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
25
app/framelesswindow.h
Normal file
25
app/framelesswindow.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#ifndef FRAMELESSWINDOW_H
|
||||||
|
#define FRAMELESSWINDOW_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
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
|
@ -31,12 +31,10 @@
|
|||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent) :
|
MainWindow::MainWindow(QWidget *parent) :
|
||||||
QMainWindow(parent)
|
FramelessWindow(parent)
|
||||||
{
|
{
|
||||||
if (Settings::instance()->stayOnTop()) {
|
if (Settings::instance()->stayOnTop()) {
|
||||||
this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint | Qt::WindowStaysOnTopHint);
|
this->setWindowFlag(Qt::WindowStaysOnTopHint);
|
||||||
} else {
|
|
||||||
this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this->setAttribute(Qt::WA_TranslucentBackground, true);
|
this->setAttribute(Qt::WA_TranslucentBackground, true);
|
||||||
@ -55,7 +53,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
m_exitAnimationGroup->addAnimation(m_fadeOutAnimation);
|
m_exitAnimationGroup->addAnimation(m_fadeOutAnimation);
|
||||||
m_exitAnimationGroup->addAnimation(m_floatUpAnimation);
|
m_exitAnimationGroup->addAnimation(m_floatUpAnimation);
|
||||||
connect(m_exitAnimationGroup, &QParallelAnimationGroup::finished,
|
connect(m_exitAnimationGroup, &QParallelAnimationGroup::finished,
|
||||||
this, &QMainWindow::close);
|
this, &QWidget::close);
|
||||||
|
|
||||||
GraphicsScene * scene = new GraphicsScene(this);
|
GraphicsScene * scene = new GraphicsScene(this);
|
||||||
|
|
||||||
@ -290,7 +288,7 @@ void MainWindow::showEvent(QShowEvent *event)
|
|||||||
{
|
{
|
||||||
updateWidgetsPosition();
|
updateWidgetsPosition();
|
||||||
|
|
||||||
return QMainWindow::showEvent(event);
|
return FramelessWindow::showEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::enterEvent(QEvent *event)
|
void MainWindow::enterEvent(QEvent *event)
|
||||||
@ -302,7 +300,7 @@ void MainWindow::enterEvent(QEvent *event)
|
|||||||
m_prevButton->setOpacity(1);
|
m_prevButton->setOpacity(1);
|
||||||
m_nextButton->setOpacity(1);
|
m_nextButton->setOpacity(1);
|
||||||
|
|
||||||
return QMainWindow::enterEvent(event);
|
return FramelessWindow::enterEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::leaveEvent(QEvent *event)
|
void MainWindow::leaveEvent(QEvent *event)
|
||||||
@ -314,7 +312,7 @@ void MainWindow::leaveEvent(QEvent *event)
|
|||||||
m_prevButton->setOpacity(0);
|
m_prevButton->setOpacity(0);
|
||||||
m_nextButton->setOpacity(0);
|
m_nextButton->setOpacity(0);
|
||||||
|
|
||||||
return QMainWindow::leaveEvent(event);
|
return FramelessWindow::leaveEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::mousePressEvent(QMouseEvent *event)
|
void MainWindow::mousePressEvent(QMouseEvent *event)
|
||||||
@ -327,7 +325,7 @@ void MainWindow::mousePressEvent(QMouseEvent *event)
|
|||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
return QMainWindow::mousePressEvent(event);
|
return FramelessWindow::mousePressEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::mouseMoveEvent(QMouseEvent *event)
|
void MainWindow::mouseMoveEvent(QMouseEvent *event)
|
||||||
@ -343,14 +341,14 @@ void MainWindow::mouseMoveEvent(QMouseEvent *event)
|
|||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
return QMainWindow::mouseMoveEvent(event);
|
return FramelessWindow::mouseMoveEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::mouseReleaseEvent(QMouseEvent *event)
|
void MainWindow::mouseReleaseEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
m_clickedOnWindow = false;
|
m_clickedOnWindow = false;
|
||||||
|
|
||||||
return QMainWindow::mouseReleaseEvent(event);
|
return FramelessWindow::mouseReleaseEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::mouseDoubleClickEvent(QMouseEvent *event)
|
void MainWindow::mouseDoubleClickEvent(QMouseEvent *event)
|
||||||
@ -391,7 +389,7 @@ void MainWindow::wheelEvent(QWheelEvent *event)
|
|||||||
m_graphicsView->zoomView(zoomIn ? 1.25 : 0.8);
|
m_graphicsView->zoomView(zoomIn ? 1.25 : 0.8);
|
||||||
event->accept();
|
event->accept();
|
||||||
} else {
|
} else {
|
||||||
QMainWindow::wheelEvent(event);
|
FramelessWindow::wheelEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -399,7 +397,7 @@ void MainWindow::resizeEvent(QResizeEvent *event)
|
|||||||
{
|
{
|
||||||
updateWidgetsPosition();
|
updateWidgetsPosition();
|
||||||
|
|
||||||
return QMainWindow::resizeEvent(event);
|
return FramelessWindow::resizeEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::contextMenuEvent(QContextMenuEvent *event)
|
void MainWindow::contextMenuEvent(QContextMenuEvent *event)
|
||||||
@ -514,7 +512,7 @@ void MainWindow::contextMenuEvent(QContextMenuEvent *event)
|
|||||||
menu->exec(mapToGlobal(event->pos()));
|
menu->exec(mapToGlobal(event->pos()));
|
||||||
menu->deleteLater();
|
menu->deleteLater();
|
||||||
|
|
||||||
return QMainWindow::contextMenuEvent(event);
|
return FramelessWindow::contextMenuEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
|
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;
|
return false;
|
||||||
#else
|
#else
|
||||||
return QMainWindow::nativeEvent(eventType, message, result);
|
return FramelessWindow::nativeEvent(eventType, message, result);
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
#ifndef MAINWINDOW_H
|
#ifndef MAINWINDOW_H
|
||||||
#define MAINWINDOW_H
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include "framelesswindow.h"
|
||||||
|
|
||||||
#include <QParallelAnimationGroup>
|
#include <QParallelAnimationGroup>
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
@ -15,7 +16,7 @@ class ToolButton;
|
|||||||
class GraphicsView;
|
class GraphicsView;
|
||||||
class NavigatorView;
|
class NavigatorView;
|
||||||
class BottomButtonGroup;
|
class BottomButtonGroup;
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public FramelessWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user