mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 16:18:42 +00:00
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:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
13
src/Gui/NewMainWindowMac.mm
Normal file
13
src/Gui/NewMainWindowMac.mm
Normal 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];
|
||||
}
|
||||
@@ -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") {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user