diff --git a/ui/StatusQ/sandbox/CMakeLists.txt b/ui/StatusQ/sandbox/CMakeLists.txt index ead6a2bd06..f1adf46529 100644 --- a/ui/StatusQ/sandbox/CMakeLists.txt +++ b/ui/StatusQ/sandbox/CMakeLists.txt @@ -7,27 +7,32 @@ find_package( file(GLOB_RECURSE QML_FILES "../*.qml") file(GLOB_RECURSE JS_FILES "../*.js") +file(GLOB_RECURSE HEADERS *.h) +if(APPLE) + file(GLOB_RECURSE SOURCES *.cpp *.mm) +else() + file(GLOB_RECURSE SOURCES *.cpp) +endif() qt5_add_big_resources(QRC_FILES qml.qrc ../src/statusq.qrc ../src/assets.qrc) add_executable( ${PROJECT_NAME} - main.cpp - handler.cpp - sandboxapp.cpp - spellchecker.cpp + ${HEADERS} + ${SOURCES} ${QRC_FILES} ${QML_FILES} ${JS_FILES}) -if(APPLE) - target_sources(${PROJECT_NAME} PRIVATE statuswindow_mac.mm) -else() - target_sources(${PROJECT_NAME} PRIVATE statuswindow.cpp) -endif() - target_compile_definitions(${PROJECT_NAME} PRIVATE SRC_DIR="${CMAKE_CURRENT_LIST_DIR}") target_link_libraries( ${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Quick Qt5::QuickControls2 SortFilterProxyModel) + +if (APPLE) + find_library(AppKit AppKit) + find_library(Foundation Foundation) + + target_link_libraries(${PROJECT_NAME} PRIVATE ${AppKit} ${Foundation}) +endif() diff --git a/ui/StatusQ/sandbox/statuswindow.cpp b/ui/StatusQ/sandbox/statuswindow.cpp index 6a7a450ca8..58a7252803 100644 --- a/ui/StatusQ/sandbox/statuswindow.cpp +++ b/ui/StatusQ/sandbox/statuswindow.cpp @@ -1,5 +1,33 @@ #include "statuswindow.h" +StatusWindow::StatusWindow(QQuickWindow *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::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); + } +} + void StatusWindow::toggleFullScreen() { if (m_isFullScreen) { @@ -16,10 +44,26 @@ bool StatusWindow::isFullScreen() const void StatusWindow::removeTitleBar() { - +#ifdef Q_OS_WIN + removeTitleBarWin(); +#elif defined Q_OS_MACOS + removeTitleBarMac(); +#endif } void StatusWindow::showTitleBar() { - +#ifdef Q_OS_WIN + showTitleBarWin(); +#elif defined Q_OS_MACOS + showTitleBarMac(); +#endif } + +#ifdef Q_OS_WIN +void StatusWindow::removeTitleBarWin() +{} + +void StatusWindow::showTitleBarWin() +{} +#endif diff --git a/ui/StatusQ/sandbox/statuswindow.h b/ui/StatusQ/sandbox/statuswindow.h index 5ecf597fad..8b8bc1bef3 100644 --- a/ui/StatusQ/sandbox/statuswindow.h +++ b/ui/StatusQ/sandbox/statuswindow.h @@ -11,40 +11,11 @@ class StatusWindow: public QQuickWindow Q_PROPERTY(bool isFullScreen READ isFullScreen NOTIFY isFullScreenChanged) public: - struct EventCallbacks { - std::function onResize; - std::function willExitFullScreen; - std::function didExitFullScreen; - }; - - explicit StatusWindow(QWindow *parent = nullptr) - : 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(); - } - }); - - } + explicit StatusWindow(QQuickWindow *parent = nullptr); 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); - } - } + Q_INVOKABLE void updatePosition(); bool isFullScreen() const; @@ -54,10 +25,15 @@ signals: private: void removeTitleBar(); void showTitleBar(); - void initCallbacks(); +#ifdef Q_OS_WIN + void removeTitleBarWin(); + void showTitleBarWin(); +#elif defined Q_OS_MACOS + void removeTitleBarMac(); + void showTitleBarMac(); +#endif private: - EventCallbacks m_callbacks; bool m_isFullScreen; }; diff --git a/ui/StatusQ/sandbox/statuswindow_mac.mm b/ui/StatusQ/sandbox/statuswindow_mac.mm index f9113d405d..b553b55f1e 100644 --- a/ui/StatusQ/sandbox/statuswindow_mac.mm +++ b/ui/StatusQ/sandbox/statuswindow_mac.mm @@ -12,21 +12,7 @@ #include #include -void StatusWindow::toggleFullScreen() -{ - if (m_isFullScreen) { - showNormal(); - } else { - showFullScreen(); - } -} - -bool StatusWindow::isFullScreen() const -{ - return m_isFullScreen; -} - -void StatusWindow::removeTitleBar() +void StatusWindow::removeTitleBarMac() { NSView *nsView = reinterpret_cast(this->winId()); NSWindow *window = [nsView window]; @@ -39,7 +25,7 @@ void StatusWindow::removeTitleBar() [titleBarContainerView setHidden:YES]; } -void StatusWindow::showTitleBar() +void StatusWindow::showTitleBarMac() { NSView *nsView = reinterpret_cast(this->winId()); NSWindow *window = [nsView window];