summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plugins/platforms/cocoa/qcocoanativeinterface.h13
-rw-r--r--src/plugins/platforms/cocoa/qcocoanativeinterface.mm20
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.h7
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.mm59
-rw-r--r--src/widgets/widgets/qmainwindow.cpp6
-rw-r--r--src/widgets/widgets/qtoolbar.cpp18
-rw-r--r--src/widgets/widgets/qtoolbarlayout.cpp4
7 files changed, 84 insertions, 43 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.h b/src/plugins/platforms/cocoa/qcocoanativeinterface.h
index efdd433d8f..0318c52628 100644
--- a/src/plugins/platforms/cocoa/qcocoanativeinterface.h
+++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.h
@@ -133,16 +133,19 @@ private:
// deregisters.
static void registerTouchWindow(QWindow *window, bool enable);
- // Request a unified title and toolbar look for the window.
+ // 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);
- // Request a unified title and toolbar look for the window by registering
- // an area. Multiple callers can register areas and the platform plugin
+ // Set the size for a unified toolbar content border area.
+ // Multiple callers can register areas and the platform plugin
// will extend the "unified" area to cover them.
static void registerContentBorderArea(QWindow *window, quintptr identifer, int upper, int lower);
- // Enable the unified title and toolbar area.
- static void enableContentBorderArea(QWindow *window, bool enable);
+ // Enables or disiables a content border area.
+ static void setContentBorderAreaEnabled(QWindow *window, quintptr identifier, bool enable);
// Sets a NSToolbar instance for the given QWindow. The
// toolbar will be attached to the native NSWindow when
diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm
index d6a5be8d52..b18c586212 100644
--- a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm
+++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm
@@ -127,8 +127,10 @@ QPlatformNativeInterface::NativeResourceForIntegrationFunction QCocoaNativeInter
return NativeResourceForIntegrationFunction(QCocoaNativeInterface::setContentBorderThickness);
if (resource.toLower() == "registercontentborderarea")
return NativeResourceForIntegrationFunction(QCocoaNativeInterface::registerContentBorderArea);
- if (resource.toLower() == "enablecontentborderarea")
- return NativeResourceForIntegrationFunction(QCocoaNativeInterface::enableContentBorderArea);
+ if (resource.toLower() == "setcontentborderareaenabled")
+ return NativeResourceForIntegrationFunction(QCocoaNativeInterface::setContentBorderAreaEnabled);
+ if (resource.toLower() == "setcontentborderenabled")
+ return NativeResourceForIntegrationFunction(QCocoaNativeInterface::setContentBorderEnabled);
if (resource.toLower() == "setnstoolbar")
return NativeResourceForIntegrationFunction(QCocoaNativeInterface::setNSToolbar);
@@ -301,14 +303,24 @@ void QCocoaNativeInterface::registerContentBorderArea(QWindow *window, quintptr
cocoaWindow->registerContentBorderArea(identifier, upper, lower);
}
-void QCocoaNativeInterface::enableContentBorderArea(QWindow *window, bool enable)
+void QCocoaNativeInterface::setContentBorderAreaEnabled(QWindow *window, quintptr identifier, bool enable)
{
if (!window)
return;
QCocoaWindow *cocoaWindow = static_cast<QCocoaWindow *>(window->handle());
if (cocoaWindow)
- cocoaWindow->enableContentBorderArea(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)
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h
index b7a6a14d4a..d8eb0ed0bd 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.h
+++ b/src/plugins/platforms/cocoa/qcocoawindow.h
@@ -211,7 +211,8 @@ public:
void registerTouch(bool enable);
void setContentBorderThickness(int topThickness, int bottomThickness);
void registerContentBorderArea(quintptr identifier, int upper, int lower);
- void enableContentBorderArea(bool enable);
+ void setContentBorderAreaEnabled(quintptr identifier, bool enable);
+ void setContentBorderEnabled(bool enable);
void applyContentBorderThickness(NSWindow *window);
void updateNSToolbar();
@@ -289,7 +290,8 @@ public: // for QNSView
NSApplicationPresentationOptions m_presentationOptions;
struct BorderRange {
- BorderRange(int u, int l) : upper(u), lower(l) { }
+ BorderRange(quintptr i, int u, int l) : identifier(i), upper(u), lower(l) { }
+ quintptr identifier;
int upper;
int lower;
bool operator<(BorderRange const& right) const {
@@ -297,6 +299,7 @@ public: // for QNSView
}
};
QHash<quintptr, BorderRange> m_contentBorderAreas; // identifer -> uppper/lower
+ QHash<quintptr, bool> m_enabledContentBorderAreas; // identifer -> enabled state (true/false)
};
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
index b07b5e33be..515e2bf132 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.mm
+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
@@ -1596,28 +1596,17 @@ void QCocoaWindow::setContentBorderThickness(int topThickness, int bottomThickne
void QCocoaWindow::registerContentBorderArea(quintptr identifier, int upper, int lower)
{
- m_contentBorderAreas.insert(identifier, BorderRange(upper, lower));
-
- // Find consecutive registered border areas, starting from the top.
- QList<BorderRange> ranges = m_contentBorderAreas.values();
- std::sort(ranges.begin(), ranges.end());
- m_topContentBorderThickness = 0;
- foreach (BorderRange range, ranges) {
- // Is this sub-range adjacent to or overlaping the
- // existing total border area range? If so merge
- // it into the total range,
- if (range.upper <= (m_topContentBorderThickness + 1))
- m_topContentBorderThickness = qMax(m_topContentBorderThickness, range.lower);
- else
- break;
- }
+ m_contentBorderAreas.insert(identifier, BorderRange(identifier, upper, lower));
+ applyContentBorderThickness(m_nsWindow);
+}
- m_bottomContentBorderThickness = 0; // (not supported)
- if (m_drawContentBorderGradient)
- applyContentBorderThickness(m_nsWindow);
+void QCocoaWindow::setContentBorderAreaEnabled(quintptr identifier, bool enable)
+{
+ m_enabledContentBorderAreas.insert(identifier, enable);
+ applyContentBorderThickness(m_nsWindow);
}
-void QCocoaWindow::enableContentBorderArea(bool enable)
+void QCocoaWindow::setContentBorderEnabled(bool enable)
{
m_drawContentBorderGradient = enable;
applyContentBorderThickness(m_nsWindow);
@@ -1633,17 +1622,33 @@ void QCocoaWindow::applyContentBorderThickness(NSWindow *window)
return;
}
- [window setStyleMask:[window styleMask] | NSTexturedBackgroundWindowMask];
+ // Find consecutive registered border areas, starting from the top.
+ QList<BorderRange> ranges = m_contentBorderAreas.values();
+ std::sort(ranges.begin(), ranges.end());
+ int effectiveTopContentBorderThickness = m_topContentBorderThickness;
+ foreach (BorderRange range, ranges) {
+ // Skip disiabled ranges (typically hidden tool bars)
+ if (!m_enabledContentBorderAreas.value(range.identifier, false))
+ continue;
- if (m_topContentBorderThickness > 0) {
- [window setContentBorderThickness:m_topContentBorderThickness forEdge:NSMaxYEdge];
- [window setAutorecalculatesContentBorderThickness:NO forEdge:NSMaxYEdge];
+ // Is this sub-range adjacent to or overlaping the
+ // existing total border area range? If so merge
+ // it into the total range,
+ if (range.upper <= (effectiveTopContentBorderThickness + 1))
+ effectiveTopContentBorderThickness = qMax(effectiveTopContentBorderThickness, range.lower);
+ else
+ break;
}
- if (m_bottomContentBorderThickness > 0) {
- [window setContentBorderThickness:m_topContentBorderThickness forEdge:NSMinYEdge];
- [window setAutorecalculatesContentBorderThickness:NO forEdge:NSMinYEdge];
- }
+ int effectiveBottomContentBorderThickness = m_bottomContentBorderThickness;
+
+ [window setStyleMask:[window styleMask] | NSTexturedBackgroundWindowMask];
+
+ [window setContentBorderThickness:effectiveTopContentBorderThickness forEdge:NSMaxYEdge];
+ [window setAutorecalculatesContentBorderThickness:NO forEdge:NSMaxYEdge];
+
+ [window setContentBorderThickness:effectiveBottomContentBorderThickness forEdge:NSMinYEdge];
+ [window setAutorecalculatesContentBorderThickness:NO forEdge:NSMinYEdge];
}
void QCocoaWindow::updateNSToolbar()
diff --git a/src/widgets/widgets/qmainwindow.cpp b/src/widgets/widgets/qmainwindow.cpp
index 1d0268a244..90cfb1d7cb 100644
--- a/src/widgets/widgets/qmainwindow.cpp
+++ b/src/widgets/widgets/qmainwindow.cpp
@@ -1513,12 +1513,12 @@ void QMainWindow::setUnifiedTitleAndToolBarOnMac(bool set)
QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
QPlatformNativeInterface::NativeResourceForIntegrationFunction function =
- nativeInterface->nativeResourceFunctionForIntegration("enableContentBorderArea");
+ nativeInterface->nativeResourceFunctionForIntegration("setContentBorderEnabled");
if (!function)
return; // Not Cocoa platform plugin.
- typedef void (*EnableContentBorderAreaFunction)(QWindow *window, bool enable);
- (reinterpret_cast<EnableContentBorderAreaFunction>(function))(window()->windowHandle(), set);
+ typedef void (*SetContentBorderEnabledFunction)(QWindow *window, bool enable);
+ (reinterpret_cast<SetContentBorderEnabledFunction>(function))(window()->windowHandle(), set);
}
#endif
diff --git a/src/widgets/widgets/qtoolbar.cpp b/src/widgets/widgets/qtoolbar.cpp
index 53b77c34da..3fd615c3c7 100644
--- a/src/widgets/widgets/qtoolbar.cpp
+++ b/src/widgets/widgets/qtoolbar.cpp
@@ -1040,6 +1040,21 @@ static bool waitForPopup(QToolBar *tb, QWidget *popup)
return false;
}
+#ifdef Q_OS_OSX
+static void enableMacToolBar(QToolBar *toolbar, bool enable)
+{
+ QPlatformNativeInterface *nativeInterface = QApplication::platformNativeInterface();
+ QPlatformNativeInterface::NativeResourceForIntegrationFunction function =
+ nativeInterface->nativeResourceFunctionForIntegration("setContentBorderAreaEnabled");
+ if (!function)
+ return; // Not Cocoa platform plugin.
+
+ typedef void (*SetContentBorderAreaEnabledFunction)(QWindow *window, void *identifier, bool enabled);
+ (reinterpret_cast<SetContentBorderAreaEnabledFunction>(function))(toolbar->window()->windowHandle(), toolbar, enable);
+}
+#endif
+
+
/*! \reimp */
bool QToolBar::event(QEvent *event)
{
@@ -1062,6 +1077,9 @@ bool QToolBar::event(QEvent *event)
// fallthrough intended
case QEvent::Show:
d->toggleViewAction->setChecked(event->type() == QEvent::Show);
+#ifdef Q_OS_OSX
+ enableMacToolBar(this, event->type() == QEvent::Show);
+#endif
emit visibilityChanged(event->type() == QEvent::Show);
break;
case QEvent::ParentChange:
diff --git a/src/widgets/widgets/qtoolbarlayout.cpp b/src/widgets/widgets/qtoolbarlayout.cpp
index 020d180778..efd33da7fc 100644
--- a/src/widgets/widgets/qtoolbarlayout.cpp
+++ b/src/widgets/widgets/qtoolbarlayout.cpp
@@ -369,9 +369,9 @@ void QToolBarLayout::updateMacBorderMetrics()
typedef void (*RegisterContentBorderAreaFunction)(QWindow *window, void *identifier, int upper, int lower);
if (mainWindow->toolBarArea(tb) == Qt::TopToolBarArea) {
- (reinterpret_cast<RegisterContentBorderAreaFunction>(function))(tb->window()->windowHandle(), this, upper.y(), lower.y());
+ (reinterpret_cast<RegisterContentBorderAreaFunction>(function))(tb->window()->windowHandle(), tb, upper.y(), lower.y());
} else {
- (reinterpret_cast<RegisterContentBorderAreaFunction>(function))(tb->window()->windowHandle(), this, 0, 0);
+ (reinterpret_cast<RegisterContentBorderAreaFunction>(function))(tb->window()->windowHandle(), tb, 0, 0);
}
#endif
}