StatusQ/sandbox/statuswindow.h

65 lines
1.6 KiB
C
Raw Normal View History

2021-05-20 06:25:52 +00:00
#ifndef STATUSWINDOW_H
#define STATUSWINDOW_H
#include <QQuickWindow>
#include <QScreen>
2021-05-20 06:25:52 +00:00
class StatusWindow: public QQuickWindow
{
Q_OBJECT
Q_PROPERTY(bool isFullScreen READ isFullScreen NOTIFY isFullScreenChanged)
2021-05-20 06:25:52 +00:00
public:
struct EventCallbacks {
std::function<void()> onResize;
std::function<void()> willExitFullScreen;
std::function<void()> didExitFullScreen;
};
2021-05-20 06:25:52 +00:00
explicit StatusWindow(QWindow *parent = nullptr)
: QQuickWindow(parent),
m_isFullScreen(false)
2021-05-20 06:25:52 +00:00
{
removeTitleBar();
connect(this, &QQuickWindow::windowStateChanged, [&](Qt::WindowState windowState) {
if (windowState == Qt::WindowNoState) {
removeTitleBar();
m_isFullScreen = false;
emit isFullScreenChanged();
} else if (windowState == Qt::WindowFullScreen) {
m_isFullScreen = true;
emit isFullScreenChanged();
showTitleBar();
}
});
2021-05-20 06:25:52 +00:00
}
Q_INVOKABLE void toggleFullScreen();
Q_INVOKABLE void updatePosition() {
auto point = QPoint(screen()->geometry().center().x() - geometry().width() / 2, screen()->geometry().center().y() - geometry().height() / 2);
if (point != this->position()) {
this->setPosition(point);
}
}
bool isFullScreen() const;
signals:
void isFullScreenChanged();
private:
void removeTitleBar();
void showTitleBar();
void initCallbacks();
2021-05-20 06:25:52 +00:00
private:
EventCallbacks m_callbacks;
bool m_isFullScreen;
2021-05-20 06:25:52 +00:00
};
#endif // STATUSWINDOW_H