fix: update position of window to center, add traffic lights

This commit is contained in:
B.Melnik 2021-06-01 13:01:47 +03:00 committed by Pascal Precht
parent 70e17b0598
commit 26aae6d027
14 changed files with 228 additions and 6 deletions

View File

@ -10,6 +10,7 @@ import StatusQ.Core.Theme 0.1
import StatusQ.Controls 0.1
import StatusQ.Components 0.1
import StatusQ.Layout 0.1
import StatusQ.Platform 0.1
StatusWindow {
id: rootWindow
@ -29,6 +30,8 @@ StatusWindow {
Component.onCompleted: {
Theme.palette = lightTheme
apiDocsButton.checked = true
rootWindow.updatePosition();
}
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()
}
}
}

View File

@ -32,9 +32,11 @@ HEADERS += \
statuswindow.h
DISTFILES += \
../src/StatusQ/Components/StatusMacWindowButtons.qml \
../src/StatusQ/Controls/StatusBaseButton.qml \
../src/StatusQ/Controls/StatusButton.qml \
../src/StatusQ/Controls/StatusCheckBox.qml \
../src/StatusQ/Controls/StatusFlatRoundButton.qml \
../src/StatusQ/Controls/StatusRadioButton.qml \
../src/StatusQ/Controls/StatusSlider.qml \
../src/StatusQ/Controls/StatusSwitch.qml

View File

@ -36,8 +36,8 @@ void SandboxApp::restartEngine()
const QUrl url(applicationDirPath() + "/../main.qml");
QWindow *rootWindow = qobject_cast<QWindow*>(m_engine.rootObjects().at(0));
if (rootWindow) {
rootWindow->close();
rootWindow->deleteLater();
}
m_engine.clearComponentCache();
m_engine.load(url);

View File

@ -2,20 +2,63 @@
#define STATUSWINDOW_H
#include <QQuickWindow>
#include <QScreen>
class StatusWindow: public QQuickWindow
{
Q_OBJECT
Q_PROPERTY(bool isFullScreen READ isFullScreen NOTIFY isFullScreenChanged)
public:
struct EventCallbacks {
std::function<void()> onResize;
std::function<void()> willExitFullScreen;
std::function<void()> didExitFullScreen;
};
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:
void removeTitleBar(WId wid);
void removeTitleBar();
void showTitleBar();
void initCallbacks();
private:
EventCallbacks m_callbacks;
bool m_isFullScreen;
};
#endif // STATUSWINDOW_H

View File

@ -2,17 +2,52 @@
#include <QColor>
#include <QDebug>
#include <Foundation/Foundation.h>
#include <AppKit/NSView.h>
#include <AppKit/NSWindow.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];
window.titlebarAppearsTransparent = true;
window.titleVisibility = NSWindowTitleHidden;
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];
}

View File

@ -10,3 +10,4 @@ StatusLoadingIndicator 0.1 StatusLoadingIndicator.qml
StatusNavigationListItem 0.1 StatusNavigationListItem.qml
StatusRoundIcon 0.1 StatusRoundIcon.qml
StatusRoundedImage 0.1 StatusRoundedImage.qml
StatusMacWindowButtons 0.1 StatusMacWindowButtons.qml

View File

@ -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()
}
}
}
}

View File

@ -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