fix examples on MacOS
This commit is contained in:
parent
420d942762
commit
0e63a053de
|
@ -25,6 +25,7 @@
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include <QtGui/qpainter.h>
|
#include <QtGui/qpainter.h>
|
||||||
#include "../../framelesswindowsmanager.h"
|
#include "../../framelesswindowsmanager.h"
|
||||||
|
#include "../../utilities.h"
|
||||||
|
|
||||||
FRAMELESSHELPER_USE_NAMESPACE
|
FRAMELESSHELPER_USE_NAMESPACE
|
||||||
|
|
||||||
|
@ -44,7 +45,6 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(par
|
||||||
|
|
||||||
QMenuBar *mb = menuBar();
|
QMenuBar *mb = menuBar();
|
||||||
titleBarWidget->horizontalLayout->insertWidget(1, mb);
|
titleBarWidget->horizontalLayout->insertWidget(1, mb);
|
||||||
|
|
||||||
setMenuWidget(m_titleBar);
|
setMenuWidget(m_titleBar);
|
||||||
|
|
||||||
connect(this, &MainWindow::windowIconChanged, titleBarWidget->iconButton, &QPushButton::setIcon);
|
connect(this, &MainWindow::windowIconChanged, titleBarWidget->iconButton, &QPushButton::setIcon);
|
||||||
|
@ -101,7 +101,14 @@ void MainWindow::showEvent(QShowEvent *event)
|
||||||
m_helper->setTitleBarHeight(m_titleBar->height());
|
m_helper->setTitleBarHeight(m_titleBar->height());
|
||||||
m_helper->setResizeBorderThickness(4);
|
m_helper->setResizeBorderThickness(4);
|
||||||
m_helper->install();
|
m_helper->install();
|
||||||
|
#ifndef Q_OS_MAC
|
||||||
setContentsMargins(1, 1, 1, 1);
|
setContentsMargins(1, 1, 1, 1);
|
||||||
|
#else // Q_OS_MAC
|
||||||
|
titleBarWidget->minimizeButton->hide();
|
||||||
|
titleBarWidget->maximizeButton->hide();
|
||||||
|
titleBarWidget->closeButton->hide();
|
||||||
|
Utilities::showMacWindowButton(windowHandle());
|
||||||
|
#endif // Q_OS_MAC
|
||||||
inited = true;
|
inited = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,6 +128,7 @@ bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *r
|
||||||
}
|
}
|
||||||
#endif // Q_OS_WIN
|
#endif // Q_OS_WIN
|
||||||
|
|
||||||
|
#ifndef Q_OS_MAC
|
||||||
void MainWindow::changeEvent(QEvent *event)
|
void MainWindow::changeEvent(QEvent *event)
|
||||||
{
|
{
|
||||||
QWidget::changeEvent(event);
|
QWidget::changeEvent(event);
|
||||||
|
@ -165,3 +173,4 @@ void MainWindow::paintEvent(QPaintEvent *event)
|
||||||
painter.restore();
|
painter.restore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif // Q_OS_MAC
|
|
@ -39,8 +39,12 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void showEvent(QShowEvent *event) override;
|
void showEvent(QShowEvent *event) override;
|
||||||
|
|
||||||
|
#ifndef Q_OS_MAC
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
void changeEvent(QEvent *event) override;
|
void changeEvent(QEvent *event) override;
|
||||||
|
#endif // Q_OS_MAC
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
|
bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
|
||||||
#endif // Q_OS_WIN
|
#endif // Q_OS_WIN
|
||||||
|
|
|
@ -107,9 +107,15 @@ void Widget::showEvent(QShowEvent *event)
|
||||||
m_helper->setResizeBorderThickness(4);
|
m_helper->setResizeBorderThickness(4);
|
||||||
m_helper->setTitleBarHeight(m_titleBarWidget->height());
|
m_helper->setTitleBarHeight(m_titleBarWidget->height());
|
||||||
m_helper->install();
|
m_helper->install();
|
||||||
|
#ifndef Q_OS_MAC
|
||||||
const int margin = Utilities::getWindowVisibleFrameBorderThickness(winId());
|
const int margin = Utilities::getWindowVisibleFrameBorderThickness(winId());
|
||||||
setContentsMargins(margin, margin, margin, margin);
|
setContentsMargins(margin, margin, margin, margin);
|
||||||
|
#else // Q_OS_MAC
|
||||||
|
m_minimizeButton->hide();
|
||||||
|
m_maximizeButton->hide();
|
||||||
|
m_closeButton->hide();
|
||||||
|
Utilities::showMacWindowButton(windowHandle());
|
||||||
|
#endif // Q_OS_MAC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,6 +127,7 @@ void Widget::timerEvent(QTimerEvent *event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef Q_OS_MAC
|
||||||
void Widget::changeEvent(QEvent *event)
|
void Widget::changeEvent(QEvent *event)
|
||||||
{
|
{
|
||||||
QWidget::changeEvent(event);
|
QWidget::changeEvent(event);
|
||||||
|
@ -168,6 +175,7 @@ void Widget::paintEvent(QPaintEvent *event)
|
||||||
painter.restore();
|
painter.restore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif // Q_OS_MAC
|
||||||
|
|
||||||
void Widget::setupUi()
|
void Widget::setupUi()
|
||||||
{
|
{
|
||||||
|
@ -221,6 +229,9 @@ void Widget::setupUi()
|
||||||
titleBarLayout->setContentsMargins(0, 0, 0, 0);
|
titleBarLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
titleBarLayout->setSpacing(0);
|
titleBarLayout->setSpacing(0);
|
||||||
titleBarLayout->addSpacerItem(new QSpacerItem(10, 10));
|
titleBarLayout->addSpacerItem(new QSpacerItem(10, 10));
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
titleBarLayout->addStretch();
|
||||||
|
#endif // Q_OS_MAC
|
||||||
titleBarLayout->addWidget(m_windowTitleLabel);
|
titleBarLayout->addWidget(m_windowTitleLabel);
|
||||||
titleBarLayout->addStretch();
|
titleBarLayout->addStretch();
|
||||||
titleBarLayout->addWidget(m_minimizeButton);
|
titleBarLayout->addWidget(m_minimizeButton);
|
||||||
|
|
|
@ -43,8 +43,12 @@ public:
|
||||||
protected:
|
protected:
|
||||||
void showEvent(QShowEvent *event) override;
|
void showEvent(QShowEvent *event) override;
|
||||||
void timerEvent(QTimerEvent *event) override;
|
void timerEvent(QTimerEvent *event) override;
|
||||||
|
|
||||||
|
#ifndef Q_OS_MAC
|
||||||
void changeEvent(QEvent *event) override;
|
void changeEvent(QEvent *event) override;
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
#endif // Q_OS_MAC
|
||||||
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||||
bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result) override;
|
bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result) override;
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -119,6 +119,7 @@ void FramelessHelper::uninstall()
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
Utilities::unsetMacWindowHook(m_window);
|
Utilities::unsetMacWindowHook(m_window);
|
||||||
|
Utilities::unsetMacWindowFrameless(m_window);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
|
|
|
@ -72,6 +72,7 @@ FRAMELESSHELPER_API unsigned int getX11CursorForFrameSection(Qt::WindowFrameSect
|
||||||
FRAMELESSHELPER_API bool setMacWindowHook(QWindow* w);
|
FRAMELESSHELPER_API bool setMacWindowHook(QWindow* w);
|
||||||
FRAMELESSHELPER_API bool unsetMacWindowHook(QWindow* w);
|
FRAMELESSHELPER_API bool unsetMacWindowHook(QWindow* w);
|
||||||
FRAMELESSHELPER_API bool setMacWindowFrameless(QWindow* w);
|
FRAMELESSHELPER_API bool setMacWindowFrameless(QWindow* w);
|
||||||
|
FRAMELESSHELPER_API bool unsetMacWindowFrameless(QWindow* w);
|
||||||
FRAMELESSHELPER_API bool startMacDrag(QWindow* w, const QPoint& pos);
|
FRAMELESSHELPER_API bool startMacDrag(QWindow* w, const QPoint& pos);
|
||||||
FRAMELESSHELPER_API Qt::MouseButtons getMacMouseButtons();
|
FRAMELESSHELPER_API Qt::MouseButtons getMacMouseButtons();
|
||||||
FRAMELESSHELPER_API bool showMacWindowButton(QWindow *w);
|
FRAMELESSHELPER_API bool showMacWindowButton(QWindow *w);
|
||||||
|
|
|
@ -71,6 +71,55 @@ int getSystemMetric(const QWindow *window, const SystemMetric metric, const bool
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QColor getColorizationColor()
|
||||||
|
{
|
||||||
|
// ### TO BE IMPLEMENTED
|
||||||
|
return Qt::darkGray;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getWindowVisibleFrameBorderThickness(const WId winId)
|
||||||
|
{
|
||||||
|
// ### TO BE IMPLEMENTED
|
||||||
|
Q_UNUSED(winId);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool shouldAppsUseDarkMode()
|
||||||
|
{
|
||||||
|
// ### TO BE IMPLEMENTED
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ColorizationArea getColorizationArea()
|
||||||
|
{
|
||||||
|
// ### TO BE IMPLEMENTED
|
||||||
|
return ColorizationArea::NoArea;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isThemeChanged(const void *data)
|
||||||
|
{
|
||||||
|
// ### TO BE IMPLEMENTED
|
||||||
|
Q_UNUSED(data);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isSystemMenuRequested(const void *data, QPointF *pos)
|
||||||
|
{
|
||||||
|
// ### TO BE IMPLEMENTED
|
||||||
|
Q_UNUSED(data);
|
||||||
|
Q_UNUSED(pos);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool showSystemMenu(const WId winId, const QPointF &pos)
|
||||||
|
{
|
||||||
|
// ### TO BE IMPLEMENTED
|
||||||
|
Q_UNUSED(winId);
|
||||||
|
Q_UNUSED(pos);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static QList<NSWindow*> gFlsWindows;
|
static QList<NSWindow*> gFlsWindows;
|
||||||
static bool gNSWindowOverrode = false;
|
static bool gNSWindowOverrode = false;
|
||||||
|
|
||||||
|
@ -272,6 +321,33 @@ bool setMacWindowFrameless(QWindow* w)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool unsetMacWindowFrameless(QWindow* w)
|
||||||
|
{
|
||||||
|
NSView* view = reinterpret_cast<NSView *>(w->winId());
|
||||||
|
if (view == nullptr)
|
||||||
|
return false;
|
||||||
|
NSWindow* nswindow = [view window];
|
||||||
|
if (nswindow == nullptr)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
view.wantsLayer = NO;
|
||||||
|
|
||||||
|
nswindow.styleMask = nswindow.styleMask & ~NSWindowStyleMaskFullSizeContentView;
|
||||||
|
nswindow.titlebarAppearsTransparent = false;
|
||||||
|
nswindow.titleVisibility = NSWindowTitleVisible;
|
||||||
|
nswindow.hasShadow = true;
|
||||||
|
|
||||||
|
nswindow.movableByWindowBackground = false;
|
||||||
|
nswindow.movable = true;
|
||||||
|
|
||||||
|
nswindow.showsToolbarButton = true;
|
||||||
|
[nswindow standardWindowButton:NSWindowCloseButton].hidden = false;
|
||||||
|
[nswindow standardWindowButton:NSWindowMiniaturizeButton].hidden = false;
|
||||||
|
[nswindow standardWindowButton:NSWindowZoomButton].hidden = false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool showMacWindowButton(QWindow *w)
|
bool showMacWindowButton(QWindow *w)
|
||||||
{
|
{
|
||||||
NSView* view = reinterpret_cast<NSView *>(w->winId());
|
NSView* view = reinterpret_cast<NSView *>(w->winId());
|
||||||
|
|
Loading…
Reference in New Issue