Simplify QMainWindow::setUnifiedTitleAndToolBarOnMac
Task-number: QTBUG-83252 Change-Id: Ib6f7dcfe21407603d4cfd5d33f6615d8623db940 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
04739ce4b4
commit
f02dde3d74
@ -170,6 +170,20 @@ protected:
|
||||
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
|
||||
|
||||
#endif //QPLATFORMWINDOW_H
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include <QtGui/private/qguiapplication_p.h>
|
||||
#include <qpa/qplatformopenglcontext.h>
|
||||
#include <qpa/qplatformintegration.h>
|
||||
#include <qpa/qplatformwindow.h>
|
||||
|
||||
#include <AppKit/AppKit.h>
|
||||
|
||||
@ -52,6 +53,7 @@ using namespace QPlatformInterface::Private;
|
||||
|
||||
QT_DEFINE_PLATFORM_INTERFACE(QCocoaGLContext, QOpenGLContext);
|
||||
QT_DEFINE_PRIVATE_PLATFORM_INTERFACE(QCocoaGLIntegration);
|
||||
QT_DEFINE_PRIVATE_PLATFORM_INTERFACE(QCocoaWindow);
|
||||
|
||||
QOpenGLContext *QPlatformInterface::QCocoaGLContext::fromNative(NSOpenGLContext *nativeContext, QOpenGLContext *shareContext)
|
||||
{
|
||||
|
@ -105,9 +105,6 @@ private:
|
||||
// deregisters.
|
||||
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.
|
||||
static void setContentBorderThickness(QWindow *window, int topThickness, int bottomThickness);
|
||||
|
||||
|
@ -118,8 +118,6 @@ QPlatformNativeInterface::NativeResourceForIntegrationFunction QCocoaNativeInter
|
||||
return NativeResourceForIntegrationFunction(QCocoaNativeInterface::registerContentBorderArea);
|
||||
if (resource.toLower() == "setcontentborderareaenabled")
|
||||
return NativeResourceForIntegrationFunction(QCocoaNativeInterface::setContentBorderAreaEnabled);
|
||||
if (resource.toLower() == "setcontentborderenabled")
|
||||
return NativeResourceForIntegrationFunction(QCocoaNativeInterface::setContentBorderEnabled);
|
||||
if (resource.toLower() == "setnstoolbar")
|
||||
return NativeResourceForIntegrationFunction(QCocoaNativeInterface::setNSToolbar);
|
||||
if (resource.toLower() == "testcontentborderposition")
|
||||
@ -260,16 +258,6 @@ void QCocoaNativeInterface::setContentBorderAreaEnabled(QWindow *window, quintpt
|
||||
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)
|
||||
{
|
||||
QCocoaIntegration::instance()->setToolbar(window, static_cast<NSToolbar *>(nsToolbar));
|
||||
|
@ -98,7 +98,8 @@ class QDebug;
|
||||
|
||||
class QCocoaMenuBar;
|
||||
|
||||
class QCocoaWindow : public QObject, public QPlatformWindow
|
||||
class QCocoaWindow : public QObject, public QPlatformWindow,
|
||||
public QPlatformInterface::Private::QCocoaWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@ -192,7 +193,7 @@ public:
|
||||
void setContentBorderThickness(int topThickness, int bottomThickness);
|
||||
void registerContentBorderArea(quintptr identifier, int upper, int lower);
|
||||
void setContentBorderAreaEnabled(quintptr identifier, bool enable);
|
||||
void setContentBorderEnabled(bool enable);
|
||||
void setContentBorderEnabled(bool enable) override;
|
||||
bool testContentBorderAreaPosition(int position) const;
|
||||
void applyContentBorderThickness(NSWindow *window = nullptr);
|
||||
void updateNSToolbar();
|
||||
|
@ -67,9 +67,7 @@
|
||||
#include "qtoolbar_p.h"
|
||||
#endif
|
||||
#include "qwidgetanimator_p.h"
|
||||
#ifdef Q_OS_MACOS
|
||||
#include <qpa/qplatformnativeinterface.h>
|
||||
#endif
|
||||
#include <QtGui/qpa/qplatformwindow.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
@ -1351,28 +1349,23 @@ bool QMainWindow::event(QEvent *event)
|
||||
|
||||
\since 5.2
|
||||
*/
|
||||
void QMainWindow::setUnifiedTitleAndToolBarOnMac(bool set)
|
||||
void QMainWindow::setUnifiedTitleAndToolBarOnMac(bool enabled)
|
||||
{
|
||||
#ifdef Q_OS_MACOS
|
||||
if (!isWindow())
|
||||
return;
|
||||
|
||||
Q_D(QMainWindow);
|
||||
if (isWindow()) {
|
||||
d->useUnifiedToolBar = set;
|
||||
d->useUnifiedToolBar = enabled;
|
||||
createWinId();
|
||||
|
||||
QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
|
||||
if (!nativeInterface)
|
||||
return; // Not Cocoa platform plugin.
|
||||
QPlatformNativeInterface::NativeResourceForIntegrationFunction function =
|
||||
nativeInterface->nativeResourceFunctionForIntegration("setContentBorderEnabled");
|
||||
if (!function)
|
||||
return; // Not Cocoa platform plugin.
|
||||
using namespace QPlatformInterface::Private;
|
||||
if (auto *platformWindow = dynamic_cast<QCocoaWindow*>(window()->windowHandle()->handle()))
|
||||
platformWindow->setContentBorderEnabled(enabled);
|
||||
|
||||
typedef void (*SetContentBorderEnabledFunction)(QWindow *window, bool enable);
|
||||
(reinterpret_cast<SetContentBorderEnabledFunction>(function))(window()->windowHandle(), set);
|
||||
update();
|
||||
}
|
||||
#else
|
||||
Q_UNUSED(set)
|
||||
Q_UNUSED(enabled)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user