From 39660ecc373fd59e68e2d297c006053d2805fe15 Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Sat, 4 Apr 2020 11:58:46 +0100 Subject: [PATCH] NewMainWindow Prototype - MacOS Native .. basics for Mac native toolbar without title and support for resize and full screen etc. .. toolbar is empty and will need cocoa elements added but will fix up when MS Windows native support is to the same level. .. suspect only Linux will use frameless and might move to accepting the toolbar is present on Linux. --- src/Gui/NewMainWindow.cpp | 28 ++++++++++++++++++++++++---- src/Gui/NewMainWindow.h | 11 +++++++++++ src/Gui/NewMainWindowMac.mm | 13 +++++++++++++ src/src.pro | 3 +++ 4 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 src/Gui/NewMainWindowMac.mm diff --git a/src/Gui/NewMainWindow.cpp b/src/Gui/NewMainWindow.cpp index 220367e20..0caa4d592 100644 --- a/src/Gui/NewMainWindow.cpp +++ b/src/Gui/NewMainWindow.cpp @@ -17,6 +17,15 @@ constexpr double gl_hoverzone = 10; // how many px to be hovering on an edge? NewMainWindow::NewMainWindow(QApplication *app) : QMainWindow(NULL), state(Inactive), resize(None), app(app) { + // We handle all the aesthetics +#ifdef Q_OS_MAC + setWindowFlags(windowFlags() | Qt::Window | Qt::WindowSystemMenuHint); + macNativeSettings(); +#else + setWindowFlags(windowFlags() | Qt::Window | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint); +#endif + + // setup main = new QWidget(this); main->setStyleSheet("background: white;"); @@ -29,7 +38,6 @@ NewMainWindow::NewMainWindow(QApplication *app) : QMainWindow(NULL), state(Inact // toolbar setupToolbar(); - // set geometry etc initialPosition(); @@ -41,8 +49,12 @@ NewMainWindow::NewMainWindow(QApplication *app) : QMainWindow(NULL), state(Inact void NewMainWindow::setupToolbar() { - // toolbar +#ifdef Q_OS_MAC + toolbar = new QMacToolBar(this); + this->window()->winId(); // this forces a windowhandle to be created + toolbar->attachToWindow(this->window()->windowHandle()); +#else toolbar = new QToolBar(this); toolbar->setFixedHeight(gl_toolbarheight * dpiYFactor); toolbar->setStyleSheet("background-color: lightGray;"); @@ -107,6 +119,7 @@ NewMainWindow::setupToolbar() setFocus(); toolbar->show(); +#endif } void @@ -127,8 +140,6 @@ NewMainWindow::initialPosition() // lets go show(); - // no frame thanks - setWindowFlags(windowFlags() | Qt::Window | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint); // center on the biggest screen windowHandle()->setScreen(const_cast(biggest)); @@ -145,6 +156,10 @@ NewMainWindow::initialPosition() bool NewMainWindow::isDragHotSpot(QPoint pos) { +#ifdef Q_OS_MAC + // we don't handle resize on Mac + return false; +#endif if (pos.y() > gl_hoverzone && pos.y() < gl_toolbarheight * dpiYFactor) return true; return false; @@ -155,6 +170,11 @@ NewMainWindow::isResizeHotSpot(QPoint pos) { int returning = None; +#ifdef Q_OS_MAC + // we don't handle resize on Mac + return returning; +#endif + if (pos.y() < gl_hoverzone) { returning = Top; if (pos.x() < gl_hoverzone) returning = TL; diff --git a/src/Gui/NewMainWindow.h b/src/Gui/NewMainWindow.h index 88ec057f8..29c2f32d0 100644 --- a/src/Gui/NewMainWindow.h +++ b/src/Gui/NewMainWindow.h @@ -1,5 +1,9 @@ #include +#ifdef Q_OS_MAC +#include +#else #include +#endif #include #include #include @@ -35,6 +39,9 @@ class NewMainWindow : public QMainWindow // windows, mac and linux in a local manner void setupToolbar(); +#ifdef Q_OS_MAC + void macNativeSettings(); +#endif // set initial geometry, screen etc void initialPosition(); @@ -46,7 +53,11 @@ class NewMainWindow : public QMainWindow QWidget *main; QVBoxLayout *layout; +#ifdef Q_OS_MAC + QMacToolBar *toolbar; +#else QToolBar *toolbar; +#endif QLineEdit *searchbox; QPushButton *quitbutton, *minimisebutton; diff --git a/src/Gui/NewMainWindowMac.mm b/src/Gui/NewMainWindowMac.mm new file mode 100644 index 000000000..839905f73 --- /dev/null +++ b/src/Gui/NewMainWindowMac.mm @@ -0,0 +1,13 @@ +#include "NewMainWindow.h" +#include + +void +NewMainWindow::macNativeSettings() +{ + NSView *nativeView = reinterpret_cast(winId()); + NSWindow* nativeWindow = [nativeView window]; + + [nativeWindow setStyleMask: [nativeWindow styleMask] | NSFullSizeContentViewWindowMask | NSWindowTitleHidden]; + [nativeWindow setTitlebarAppearsTransparent:YES]; + [nativeWindow setMovableByWindowBackground:YES]; +} diff --git a/src/src.pro b/src/src.pro index e9e4981fb..d97006751 100644 --- a/src/src.pro +++ b/src/src.pro @@ -160,6 +160,9 @@ macx { # on mac we use native buttons and video, but have native fullscreen support LIBS += -lobjc -framework IOKit -framework AppKit + # mac native controls for new mainwindow + OBJECTIVE_SOURCES += Gui/NewMainWindowMac.mm + # on mac we use QTKit or AV Foundation contains(DEFINES, "GC_VIDEO_AV") {