feat: Add cutsom window without titlebar for osx

This commit is contained in:
B.Melnik 2021-05-19 17:09:03 +03:00 committed by Michał
parent a1b7e70404
commit 4be2340d3e
6 changed files with 122 additions and 0 deletions

View File

@ -21,6 +21,7 @@ macro(add_target name type)
include/DOtherSide/DosQAbstractItemModel.h
include/DOtherSide/Utils.h
include/DOtherSide/DosDockClicker.h
include/DOtherSide/DOtherSideStatusWindow.h
src/DOtherSide.cpp
src/DosQMetaObject.cpp
src/DosQDeclarative.cpp
@ -30,8 +31,15 @@ macro(add_target name type)
src/DosQAbstractItemModel.cpp
src/DosQQuickImageProvider.cpp
src/DosDockClicker.cpp
src/DOtherSideStatusWindow.cpp
)
if (APPLE)
target_sources(${name} PUBLIC src/DOtherSideStatusWindow_osx.mm)
else()
target_sources(${name} PUBLIC ${CMAKE_SOURCE_DIR}/lib/src/DOtherSideStatusWindow_other.cpp)
endif()
if (WIN32)
target_compile_definitions(${name} PRIVATE -DWIN32)
endif()

View File

@ -0,0 +1,32 @@
#ifndef STATUSWINDOW_H
#define STATUSWINDOW_H
#include <QQuickWindow>
class StatusWindow: public QQuickWindow
{
Q_OBJECT
Q_PROPERTY(bool isFullScreen READ isFullScreen NOTIFY isFullScreenChanged)
public:
explicit StatusWindow(QWindow *parent = nullptr);
Q_INVOKABLE void toggleFullScreen();
bool isFullScreen() const;
signals:
void isFullScreenChanged();
private:
void removeTitleBar();
void showTitleBar();
void initCallbacks();
private:
bool m_isFullScreen;
};
#endif // STATUSWINDOW_H

View File

@ -58,12 +58,14 @@
#include "DOtherSide/DosQDeclarative.h"
#include "DOtherSide/DosQQuickImageProvider.h"
#include "DOtherSide/DosDockClicker.h"
#include "DOtherSide/DOtherSideStatusWindow.h"
namespace {
void register_meta_types()
{
qRegisterMetaType<QVector<int>>();
qmlRegisterType<StatusWindow>("DotherSide", 0 , 1, "StatusWindow");
}
}

View File

@ -0,0 +1,34 @@
#include "DOtherSide/DOtherSideStatusWindow.h"
StatusWindow::StatusWindow(QWindow *parent)
: QQuickWindow(parent),
m_isFullScreen(false)
{
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();
}
});
}
void StatusWindow::toggleFullScreen()
{
if (m_isFullScreen) {
showNormal();
} else {
showFullScreen();
}
}
bool StatusWindow::isFullScreen() const
{
return m_isFullScreen;
}

View File

@ -0,0 +1,35 @@
#include "DOtherSide/DOtherSideStatusWindow.h"
#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()
{
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

@ -0,0 +1,11 @@
#include "DOtherSide/DOtherSideStatusWindow.h"
void StatusWindow::removeTitleBar()
{
}
void StatusWindow::showTitleBar()
{
}