fix: update position of window to center, add traffic lights
This commit is contained in:
parent
70e17b0598
commit
26aae6d027
|
@ -10,6 +10,7 @@ import StatusQ.Core.Theme 0.1
|
||||||
import StatusQ.Controls 0.1
|
import StatusQ.Controls 0.1
|
||||||
import StatusQ.Components 0.1
|
import StatusQ.Components 0.1
|
||||||
import StatusQ.Layout 0.1
|
import StatusQ.Layout 0.1
|
||||||
|
import StatusQ.Platform 0.1
|
||||||
|
|
||||||
StatusWindow {
|
StatusWindow {
|
||||||
id: rootWindow
|
id: rootWindow
|
||||||
|
@ -29,6 +30,8 @@ StatusWindow {
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
Theme.palette = lightTheme
|
Theme.palette = lightTheme
|
||||||
apiDocsButton.checked = true
|
apiDocsButton.checked = true
|
||||||
|
|
||||||
|
rootWindow.updatePosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
StatusAppLayout {
|
StatusAppLayout {
|
||||||
|
@ -251,4 +254,22 @@ StatusWindow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StatusMacTrafficLights {
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.top: parent.top
|
||||||
|
anchors.margins: 13
|
||||||
|
|
||||||
|
onClose: {
|
||||||
|
rootWindow.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
onMinimised: {
|
||||||
|
rootWindow.showMinimized()
|
||||||
|
}
|
||||||
|
|
||||||
|
onMaximized: {
|
||||||
|
rootWindow.toggleFullScreen()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,9 +32,11 @@ HEADERS += \
|
||||||
statuswindow.h
|
statuswindow.h
|
||||||
|
|
||||||
DISTFILES += \
|
DISTFILES += \
|
||||||
|
../src/StatusQ/Components/StatusMacWindowButtons.qml \
|
||||||
../src/StatusQ/Controls/StatusBaseButton.qml \
|
../src/StatusQ/Controls/StatusBaseButton.qml \
|
||||||
../src/StatusQ/Controls/StatusButton.qml \
|
../src/StatusQ/Controls/StatusButton.qml \
|
||||||
../src/StatusQ/Controls/StatusCheckBox.qml \
|
../src/StatusQ/Controls/StatusCheckBox.qml \
|
||||||
../src/StatusQ/Controls/StatusFlatRoundButton.qml \
|
../src/StatusQ/Controls/StatusFlatRoundButton.qml \
|
||||||
../src/StatusQ/Controls/StatusRadioButton.qml \
|
../src/StatusQ/Controls/StatusRadioButton.qml \
|
||||||
|
../src/StatusQ/Controls/StatusSlider.qml \
|
||||||
../src/StatusQ/Controls/StatusSwitch.qml
|
../src/StatusQ/Controls/StatusSwitch.qml
|
||||||
|
|
|
@ -36,8 +36,8 @@ void SandboxApp::restartEngine()
|
||||||
const QUrl url(applicationDirPath() + "/../main.qml");
|
const QUrl url(applicationDirPath() + "/../main.qml");
|
||||||
QWindow *rootWindow = qobject_cast<QWindow*>(m_engine.rootObjects().at(0));
|
QWindow *rootWindow = qobject_cast<QWindow*>(m_engine.rootObjects().at(0));
|
||||||
if (rootWindow) {
|
if (rootWindow) {
|
||||||
|
|
||||||
rootWindow->close();
|
rootWindow->close();
|
||||||
|
rootWindow->deleteLater();
|
||||||
}
|
}
|
||||||
m_engine.clearComponentCache();
|
m_engine.clearComponentCache();
|
||||||
m_engine.load(url);
|
m_engine.load(url);
|
||||||
|
|
|
@ -2,20 +2,63 @@
|
||||||
#define STATUSWINDOW_H
|
#define STATUSWINDOW_H
|
||||||
|
|
||||||
#include <QQuickWindow>
|
#include <QQuickWindow>
|
||||||
|
#include <QScreen>
|
||||||
|
|
||||||
class StatusWindow: public QQuickWindow
|
class StatusWindow: public QQuickWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY(bool isFullScreen READ isFullScreen NOTIFY isFullScreenChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
struct EventCallbacks {
|
||||||
|
std::function<void()> onResize;
|
||||||
|
std::function<void()> willExitFullScreen;
|
||||||
|
std::function<void()> didExitFullScreen;
|
||||||
|
};
|
||||||
|
|
||||||
explicit StatusWindow(QWindow *parent = nullptr)
|
explicit StatusWindow(QWindow *parent = nullptr)
|
||||||
: QQuickWindow(parent)
|
: QQuickWindow(parent),
|
||||||
|
m_isFullScreen(false)
|
||||||
{
|
{
|
||||||
removeTitleBar(winId());
|
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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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:
|
private:
|
||||||
void removeTitleBar(WId wid);
|
void removeTitleBar();
|
||||||
|
void showTitleBar();
|
||||||
|
void initCallbacks();
|
||||||
|
|
||||||
|
private:
|
||||||
|
EventCallbacks m_callbacks;
|
||||||
|
bool m_isFullScreen;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // STATUSWINDOW_H
|
#endif // STATUSWINDOW_H
|
||||||
|
|
|
@ -2,17 +2,52 @@
|
||||||
|
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
#include <Foundation/Foundation.h>
|
#include <Foundation/Foundation.h>
|
||||||
#include <AppKit/NSView.h>
|
#include <AppKit/NSView.h>
|
||||||
#include <AppKit/NSWindow.h>
|
#include <AppKit/NSWindow.h>
|
||||||
#include <AppKit/NSColor.h>
|
#include <AppKit/NSColor.h>
|
||||||
|
#include <AppKit/NSToolbar.h>
|
||||||
|
#include <AppKit/NSButton.h>
|
||||||
|
#include <AppKit/AppKit.h>
|
||||||
|
|
||||||
void StatusWindow::removeTitleBar(WId wid)
|
void StatusWindow::toggleFullScreen()
|
||||||
{
|
{
|
||||||
NSView *nsView = reinterpret_cast<NSView*>(wid);
|
if (m_isFullScreen) {
|
||||||
|
showNormal();
|
||||||
|
} else {
|
||||||
|
showFullScreen();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool StatusWindow::isFullScreen() const
|
||||||
|
{
|
||||||
|
return m_isFullScreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StatusWindow::removeTitleBar()
|
||||||
|
{
|
||||||
|
NSView *nsView = reinterpret_cast<NSView*>(this->winId());
|
||||||
NSWindow *window = [nsView window];
|
NSWindow *window = [nsView window];
|
||||||
|
|
||||||
window.titlebarAppearsTransparent = true;
|
window.titlebarAppearsTransparent = true;
|
||||||
window.titleVisibility = NSWindowTitleHidden;
|
window.titleVisibility = NSWindowTitleHidden;
|
||||||
window.styleMask |= NSWindowStyleMaskFullSizeContentView;
|
window.styleMask |= NSWindowStyleMaskFullSizeContentView;
|
||||||
|
NSButton* close = [window standardWindowButton:NSWindowCloseButton];
|
||||||
|
NSView* titleBarContainerView = close.superview.superview;
|
||||||
|
[titleBarContainerView setHidden:YES];
|
||||||
|
}
|
||||||
|
|
||||||
|
void StatusWindow::showTitleBar()
|
||||||
|
{
|
||||||
|
NSView *nsView = reinterpret_cast<NSView*>(this->winId());
|
||||||
|
NSWindow *window = [nsView window];
|
||||||
|
|
||||||
|
window.titlebarAppearsTransparent = true;
|
||||||
|
window.titleVisibility = NSWindowTitleHidden;
|
||||||
|
window.styleMask |= NSWindowStyleMaskFullSizeContentView;
|
||||||
|
NSButton* close = [window standardWindowButton:NSWindowCloseButton];
|
||||||
|
NSView* titleBarContainerView = close.superview.superview;
|
||||||
|
[titleBarContainerView setHidden:NO];
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,3 +10,4 @@ StatusLoadingIndicator 0.1 StatusLoadingIndicator.qml
|
||||||
StatusNavigationListItem 0.1 StatusNavigationListItem.qml
|
StatusNavigationListItem 0.1 StatusNavigationListItem.qml
|
||||||
StatusRoundIcon 0.1 StatusRoundIcon.qml
|
StatusRoundIcon 0.1 StatusRoundIcon.qml
|
||||||
StatusRoundedImage 0.1 StatusRoundedImage.qml
|
StatusRoundedImage 0.1 StatusRoundedImage.qml
|
||||||
|
StatusMacWindowButtons 0.1 StatusMacWindowButtons.qml
|
||||||
|
|
|
@ -0,0 +1,115 @@
|
||||||
|
import QtQuick 2.13
|
||||||
|
|
||||||
|
import StatusQ.Core 0.1
|
||||||
|
import StatusQ.Core.Theme 0.1
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
id: statusMacTrafficLights
|
||||||
|
|
||||||
|
signal close()
|
||||||
|
signal minimised()
|
||||||
|
signal maximized()
|
||||||
|
|
||||||
|
hoverEnabled: true
|
||||||
|
|
||||||
|
width: layout.implicitWidth
|
||||||
|
height: layout.implicitHeight
|
||||||
|
|
||||||
|
visible: Qt.platform.os === "osx" && !rootWindow.isFullScreen
|
||||||
|
|
||||||
|
readonly property color inactive: Theme.palette.name === "light" ? "#10000000"
|
||||||
|
: "#10FFFFFF"
|
||||||
|
readonly property color inactiveBorder: Theme.palette.name === "light" ? "#10000000"
|
||||||
|
: "#10FFFFFF"
|
||||||
|
|
||||||
|
Row {
|
||||||
|
id: layout
|
||||||
|
spacing: 8
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
width: 12
|
||||||
|
height: 12
|
||||||
|
radius: width / 2
|
||||||
|
antialiasing: true
|
||||||
|
|
||||||
|
color: closeSensor.pressed ? "#B24F47" : (rootWindow.active || statusMacTrafficLights.containsMouse ? Qt.lighter("#E9685C", 1.07)
|
||||||
|
: inactive )
|
||||||
|
border.color:closeSensor.pressed ? "#943229" : (rootWindow.active ? "#D14C40"
|
||||||
|
: inactiveBorder)
|
||||||
|
border.width: Theme.palette.name === "light" ? 0.5 : 0
|
||||||
|
|
||||||
|
Image {
|
||||||
|
anchors.centerIn: parent
|
||||||
|
visible: statusMacTrafficLights.containsMouse
|
||||||
|
source: closeSensor.pressed ? "../../assets/img/icons/traffic_lights/close_pressed.png"
|
||||||
|
: "../../assets/img/icons/traffic_lights/close.png"
|
||||||
|
scale: 0.25
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
id: closeSensor
|
||||||
|
anchors.fill: parent
|
||||||
|
|
||||||
|
onClicked: statusMacTrafficLights.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
width: 12
|
||||||
|
height: 12
|
||||||
|
radius: width / 2
|
||||||
|
antialiasing: true
|
||||||
|
|
||||||
|
color: miniSensor.pressed ? "#878E3B" : (rootWindow.active || statusMacTrafficLights.containsMouse ? Qt.lighter("#EDB84C", 1.07)
|
||||||
|
: inactive)
|
||||||
|
border.color:miniSensor.pressed ? "#986E29" : (rootWindow.active ? "#D79F3D"
|
||||||
|
: inactiveBorder)
|
||||||
|
border.width: Theme.palette.name === "light" ? 0.5 : 0
|
||||||
|
|
||||||
|
Image {
|
||||||
|
anchors.centerIn: parent
|
||||||
|
anchors.verticalCenterOffset: -0.25
|
||||||
|
visible: statusMacTrafficLights.containsMouse
|
||||||
|
source: miniSensor.pressed ? "../../assets/img/icons/traffic_lights/minimise_pressed.png"
|
||||||
|
: "../../assets/img/icons/traffic_lights/minimise.png"
|
||||||
|
scale: 0.27
|
||||||
|
}
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
id: miniSensor
|
||||||
|
anchors.fill: parent
|
||||||
|
|
||||||
|
onClicked: statusMacTrafficLights.minimised()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
width: 12
|
||||||
|
height: 12
|
||||||
|
radius: width / 2
|
||||||
|
antialiasing: true
|
||||||
|
|
||||||
|
color: maxiSensor.pressed ? "#48943f" : (rootWindow.active || statusMacTrafficLights.containsMouse ? Qt.lighter("#62C454", 1.06)
|
||||||
|
: inactive)
|
||||||
|
border.color: maxiSensor.pressed ? "#357225" : (rootWindow.active ? "#53A73E"
|
||||||
|
: inactiveBorder)
|
||||||
|
border.width: Theme.palette.name === "light" ? 0.5 : 0
|
||||||
|
|
||||||
|
Image {
|
||||||
|
anchors.centerIn: parent
|
||||||
|
visible: statusMacTrafficLights.containsMouse
|
||||||
|
source: maxiSensor.pressed ?"../../assets/img/icons/traffic_lights/maximize_pressed.png"
|
||||||
|
:"../../assets/img/icons/traffic_lights/maximize.png"
|
||||||
|
scale: 0.25
|
||||||
|
}
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
id: maxiSensor
|
||||||
|
anchors.fill: parent
|
||||||
|
|
||||||
|
onClicked: statusMacTrafficLights.maximized()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
module StatusQ.Platform
|
||||||
|
|
||||||
|
StatusMacTrafficLights 0.1 StatusMacTrafficLights.qml
|
||||||
|
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 493 B |
Binary file not shown.
After Width: | Height: | Size: 481 B |
Binary file not shown.
After Width: | Height: | Size: 340 B |
Binary file not shown.
After Width: | Height: | Size: 299 B |
Binary file not shown.
After Width: | Height: | Size: 222 B |
Binary file not shown.
After Width: | Height: | Size: 214 B |
Loading…
Reference in New Issue