Simplify QMainWindow::setUnifiedTitleAndToolBarOnMac

Task-number: QTBUG-83252
Change-Id: Ib6f7dcfe21407603d4cfd5d33f6615d8623db940
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Tor Arne Vestbø 2020-05-13 17:53:39 +02:00
parent 04739ce4b4
commit f02dde3d74
6 changed files with 31 additions and 36 deletions

View File

@ -170,6 +170,20 @@ protected:
QScopedPointer<QPlatformWindowPrivate> d_ptr; QScopedPointer<QPlatformWindowPrivate> d_ptr;
}; };
// ----------------- QPlatformInterface -----------------
namespace QPlatformInterface::Private {
#if defined(Q_OS_MACOS)
struct Q_GUI_EXPORT QCocoaWindow
{
QT_DECLARE_PLATFORM_INTERFACE(QCocoaWindow)
virtual void setContentBorderEnabled(bool enable) = 0;
};
#endif
} // QPlatformInterface::Private
QT_END_NAMESPACE QT_END_NAMESPACE
#endif //QPLATFORMWINDOW_H #endif //QPLATFORMWINDOW_H

View File

@ -41,6 +41,7 @@
#include <QtGui/private/qguiapplication_p.h> #include <QtGui/private/qguiapplication_p.h>
#include <qpa/qplatformopenglcontext.h> #include <qpa/qplatformopenglcontext.h>
#include <qpa/qplatformintegration.h> #include <qpa/qplatformintegration.h>
#include <qpa/qplatformwindow.h>
#include <AppKit/AppKit.h> #include <AppKit/AppKit.h>
@ -52,6 +53,7 @@ using namespace QPlatformInterface::Private;
QT_DEFINE_PLATFORM_INTERFACE(QCocoaGLContext, QOpenGLContext); QT_DEFINE_PLATFORM_INTERFACE(QCocoaGLContext, QOpenGLContext);
QT_DEFINE_PRIVATE_PLATFORM_INTERFACE(QCocoaGLIntegration); QT_DEFINE_PRIVATE_PLATFORM_INTERFACE(QCocoaGLIntegration);
QT_DEFINE_PRIVATE_PLATFORM_INTERFACE(QCocoaWindow);
QOpenGLContext *QPlatformInterface::QCocoaGLContext::fromNative(NSOpenGLContext *nativeContext, QOpenGLContext *shareContext) QOpenGLContext *QPlatformInterface::QCocoaGLContext::fromNative(NSOpenGLContext *nativeContext, QOpenGLContext *shareContext)
{ {

View File

@ -105,9 +105,6 @@ private:
// deregisters. // deregisters.
static void registerTouchWindow(QWindow *window, bool enable); static void registerTouchWindow(QWindow *window, bool enable);
// Enable the unified title and toolbar area for a window.
static void setContentBorderEnabled(QWindow *window, bool enable);
// Set the size of the unified title and toolbar area. // Set the size of the unified title and toolbar area.
static void setContentBorderThickness(QWindow *window, int topThickness, int bottomThickness); static void setContentBorderThickness(QWindow *window, int topThickness, int bottomThickness);

View File

@ -118,8 +118,6 @@ QPlatformNativeInterface::NativeResourceForIntegrationFunction QCocoaNativeInter
return NativeResourceForIntegrationFunction(QCocoaNativeInterface::registerContentBorderArea); return NativeResourceForIntegrationFunction(QCocoaNativeInterface::registerContentBorderArea);
if (resource.toLower() == "setcontentborderareaenabled") if (resource.toLower() == "setcontentborderareaenabled")
return NativeResourceForIntegrationFunction(QCocoaNativeInterface::setContentBorderAreaEnabled); return NativeResourceForIntegrationFunction(QCocoaNativeInterface::setContentBorderAreaEnabled);
if (resource.toLower() == "setcontentborderenabled")
return NativeResourceForIntegrationFunction(QCocoaNativeInterface::setContentBorderEnabled);
if (resource.toLower() == "setnstoolbar") if (resource.toLower() == "setnstoolbar")
return NativeResourceForIntegrationFunction(QCocoaNativeInterface::setNSToolbar); return NativeResourceForIntegrationFunction(QCocoaNativeInterface::setNSToolbar);
if (resource.toLower() == "testcontentborderposition") if (resource.toLower() == "testcontentborderposition")
@ -260,16 +258,6 @@ void QCocoaNativeInterface::setContentBorderAreaEnabled(QWindow *window, quintpt
cocoaWindow->setContentBorderAreaEnabled(identifier, enable); cocoaWindow->setContentBorderAreaEnabled(identifier, enable);
} }
void QCocoaNativeInterface::setContentBorderEnabled(QWindow *window, bool enable)
{
if (!window)
return;
QCocoaWindow *cocoaWindow = static_cast<QCocoaWindow *>(window->handle());
if (cocoaWindow)
cocoaWindow->setContentBorderEnabled(enable);
}
void QCocoaNativeInterface::setNSToolbar(QWindow *window, void *nsToolbar) void QCocoaNativeInterface::setNSToolbar(QWindow *window, void *nsToolbar)
{ {
QCocoaIntegration::instance()->setToolbar(window, static_cast<NSToolbar *>(nsToolbar)); QCocoaIntegration::instance()->setToolbar(window, static_cast<NSToolbar *>(nsToolbar));

View File

@ -98,7 +98,8 @@ class QDebug;
class QCocoaMenuBar; class QCocoaMenuBar;
class QCocoaWindow : public QObject, public QPlatformWindow class QCocoaWindow : public QObject, public QPlatformWindow,
public QPlatformInterface::Private::QCocoaWindow
{ {
Q_OBJECT Q_OBJECT
public: public:
@ -192,7 +193,7 @@ public:
void setContentBorderThickness(int topThickness, int bottomThickness); void setContentBorderThickness(int topThickness, int bottomThickness);
void registerContentBorderArea(quintptr identifier, int upper, int lower); void registerContentBorderArea(quintptr identifier, int upper, int lower);
void setContentBorderAreaEnabled(quintptr identifier, bool enable); void setContentBorderAreaEnabled(quintptr identifier, bool enable);
void setContentBorderEnabled(bool enable); void setContentBorderEnabled(bool enable) override;
bool testContentBorderAreaPosition(int position) const; bool testContentBorderAreaPosition(int position) const;
void applyContentBorderThickness(NSWindow *window = nullptr); void applyContentBorderThickness(NSWindow *window = nullptr);
void updateNSToolbar(); void updateNSToolbar();

View File

@ -67,9 +67,7 @@
#include "qtoolbar_p.h" #include "qtoolbar_p.h"
#endif #endif
#include "qwidgetanimator_p.h" #include "qwidgetanimator_p.h"
#ifdef Q_OS_MACOS #include <QtGui/qpa/qplatformwindow.h>
#include <qpa/qplatformnativeinterface.h>
#endif
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@ -1351,28 +1349,23 @@ bool QMainWindow::event(QEvent *event)
\since 5.2 \since 5.2
*/ */
void QMainWindow::setUnifiedTitleAndToolBarOnMac(bool set) void QMainWindow::setUnifiedTitleAndToolBarOnMac(bool enabled)
{ {
#ifdef Q_OS_MACOS #ifdef Q_OS_MACOS
if (!isWindow())
return;
Q_D(QMainWindow); Q_D(QMainWindow);
if (isWindow()) { d->useUnifiedToolBar = enabled;
d->useUnifiedToolBar = set;
createWinId(); createWinId();
QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); using namespace QPlatformInterface::Private;
if (!nativeInterface) if (auto *platformWindow = dynamic_cast<QCocoaWindow*>(window()->windowHandle()->handle()))
return; // Not Cocoa platform plugin. platformWindow->setContentBorderEnabled(enabled);
QPlatformNativeInterface::NativeResourceForIntegrationFunction function =
nativeInterface->nativeResourceFunctionForIntegration("setContentBorderEnabled");
if (!function)
return; // Not Cocoa platform plugin.
typedef void (*SetContentBorderEnabledFunction)(QWindow *window, bool enable);
(reinterpret_cast<SetContentBorderEnabledFunction>(function))(window()->windowHandle(), set);
update(); update();
}
#else #else
Q_UNUSED(set) Q_UNUSED(enabled)
#endif #endif
} }