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.
This commit is contained in:
Mark Liversedge
2020-04-04 11:58:46 +01:00
parent 685c176eca
commit 39660ecc37
4 changed files with 51 additions and 4 deletions

View File

@@ -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<QScreen*>(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;

View File

@@ -1,5 +1,9 @@
#include <QMainWindow>
#ifdef Q_OS_MAC
#include <QMacToolBar>
#else
#include <QToolBar>
#endif
#include <QVBoxLayout>
#include <QLineEdit>
#include <QPushButton>
@@ -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;

View File

@@ -0,0 +1,13 @@
#include "NewMainWindow.h"
#include <Cocoa/Cocoa.h>
void
NewMainWindow::macNativeSettings()
{
NSView *nativeView = reinterpret_cast<NSView *>(winId());
NSWindow* nativeWindow = [nativeView window];
[nativeWindow setStyleMask: [nativeWindow styleMask] | NSFullSizeContentViewWindowMask | NSWindowTitleHidden];
[nativeWindow setTitlebarAppearsTransparent:YES];
[nativeWindow setMovableByWindowBackground:YES];
}

View File

@@ -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") {