summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms/cocoa')
-rw-r--r--src/plugins/platforms/cocoa/qcocoabackingstore.mm3
-rw-r--r--src/plugins/platforms/cocoa/qcocoanativeinterface.h3
-rw-r--r--src/plugins/platforms/cocoa/qcocoanativeinterface.mm17
-rw-r--r--src/plugins/platforms/cocoa/qcocoatheme.mm24
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.h6
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.mm41
-rw-r--r--src/plugins/platforms/cocoa/qnsview.mm6
7 files changed, 85 insertions, 15 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoabackingstore.mm b/src/plugins/platforms/cocoa/qcocoabackingstore.mm
index 665b3d4c13..30c15d823a 100644
--- a/src/plugins/platforms/cocoa/qcocoabackingstore.mm
+++ b/src/plugins/platforms/cocoa/qcocoabackingstore.mm
@@ -73,7 +73,8 @@ QPaintDevice *QCocoaBackingStore::paintDevice()
}
#endif
- QImage::Format format = window()->format().hasAlpha()
+ QCocoaWindow *cocoaWindow = static_cast<QCocoaWindow *>(window()->handle());
+ QImage::Format format = (window()->format().hasAlpha() || cocoaWindow->m_drawContentBorderGradient)
? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32;
m_qImage = QImage(m_requestedSize * scaleFactor, format);
m_qImage.setDevicePixelRatio(scaleFactor);
diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.h b/src/plugins/platforms/cocoa/qcocoanativeinterface.h
index d30b281eb8..5c59c73847 100644
--- a/src/plugins/platforms/cocoa/qcocoanativeinterface.h
+++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.h
@@ -132,6 +132,9 @@ private:
// touch events, which then will be delivered until the widget
// deregisters.
static void registerTouchWindow(QWindow *window, bool enable);
+
+ // Request a unified title and toolbar look for the window.
+ static void setContentBorderThickness(QWindow *window, int topThickness, int bottomThickness);
};
#endif // QCOCOANATIVEINTERFACE_H
diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm
index 795d1a8149..eb520b97c9 100644
--- a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm
+++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm
@@ -123,6 +123,8 @@ QPlatformNativeInterface::NativeResourceForIntegrationFunction QCocoaNativeInter
return NativeResourceForIntegrationFunction(QCocoaNativeInterface::registerTouchWindow);
if (resource.toLower() == "setembeddedinforeignview")
return NativeResourceForIntegrationFunction(QCocoaNativeInterface::setEmbeddedInForeignView);
+ if (resource.toLower() == "setcontentborderthickness")
+ return NativeResourceForIntegrationFunction(QCocoaNativeInterface::setContentBorderThickness);
return 0;
}
@@ -268,14 +270,19 @@ void QCocoaNativeInterface::registerTouchWindow(QWindow *window, bool enable)
if (!window)
return;
- // Make sure the QCocoaWindow is created when enabling. Disabling might
- // happen on window destruction, don't (re)create the QCocoaWindow then.
- if (enable)
- window->create();
-
QCocoaWindow *cocoaWindow = static_cast<QCocoaWindow *>(window->handle());
if (cocoaWindow)
cocoaWindow->registerTouch(enable);
}
+void QCocoaNativeInterface::setContentBorderThickness(QWindow *window, int topThickness, int bottomThickness)
+{
+ if (!window)
+ return;
+
+ QCocoaWindow *cocoaWindow = static_cast<QCocoaWindow *>(window->handle());
+ if (cocoaWindow)
+ cocoaWindow->setContentBorderThickness(topThickness, bottomThickness);
+}
+
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/cocoa/qcocoatheme.mm b/src/plugins/platforms/cocoa/qcocoatheme.mm
index bf6c47f273..109649f24e 100644
--- a/src/plugins/platforms/cocoa/qcocoatheme.mm
+++ b/src/plugins/platforms/cocoa/qcocoatheme.mm
@@ -259,13 +259,17 @@ QPixmap QCocoaTheme::fileIconPixmap(const QFileInfo &fileInfo, const QSizeF &siz
NSImage *iconImage = [[NSWorkspace sharedWorkspace] iconForFile:QCFString::toNSString(fileInfo.canonicalFilePath())];
if (!iconImage)
return QPixmap();
-
- NSRect iconRect = NSMakeRect(0, 0, size.width(), size.height());
- NSGraphicsContext *gc = [NSGraphicsContext currentContext];
- CGImageRef cgImage = [iconImage CGImageForProposedRect:&iconRect
- context:([gc graphicsPort] ? gc : nil)
- hints:nil];
- QPixmap pixmap = QPixmap::fromImage(qt_mac_toQImage(cgImage));
+ NSSize pixmapSize = NSMakeSize(size.width(), size.height());
+ QPixmap pixmap(pixmapSize.width, pixmapSize.height);
+ pixmap.fill(Qt::transparent);
+ [iconImage setSize:pixmapSize];
+ NSRect iconRect = NSMakeRect(0, 0, pixmapSize.width, pixmapSize.height);
+ CGContextRef ctx = qt_mac_cg_context(&pixmap);
+ NSGraphicsContext *gc = [NSGraphicsContext graphicsContextWithGraphicsPort:ctx flipped:YES];
+ [NSGraphicsContext saveGraphicsState];
+ [NSGraphicsContext setCurrentContext:gc];
+ [iconImage drawInRect:iconRect fromRect:iconRect operation:NSCompositeSourceOver fraction:1.0 respectFlipped:YES hints:nil];
+ [NSGraphicsContext restoreGraphicsState];
return pixmap;
}
@@ -281,8 +285,12 @@ QVariant QCocoaTheme::themeHint(ThemeHint hint) const
case TabAllWidgets:
return QVariant(bool([[NSApplication sharedApplication] isFullKeyboardAccessEnabled]));
case IconPixmapSizes: {
+ qreal devicePixelRatio = qGuiApp->devicePixelRatio();
QList<int> sizes;
- sizes << 16 << 32 << 64 << 128;
+ sizes << 16 * devicePixelRatio
+ << 32 * devicePixelRatio
+ << 64 * devicePixelRatio
+ << 128 * devicePixelRatio;
return QVariant::fromValue(sizes);
}
case QPlatformTheme::PasswordMaskCharacter:
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h
index 69bea31343..c20773601d 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.h
+++ b/src/plugins/platforms/cocoa/qcocoawindow.h
@@ -157,6 +157,8 @@ public:
void setWindowCursor(NSCursor *cursor);
void registerTouch(bool enable);
+ void setContentBorderThickness(int topThickness, int bottomThickness);
+ void applyContentBorderThickness(NSWindow *window);
qreal devicePixelRatio() const;
bool isWindowExposable();
@@ -215,6 +217,10 @@ public: // for QNSView
NSInteger m_alertRequest;
id monitor;
+ bool m_drawContentBorderGradient;
+ int m_topContentBorderThickness;
+ int m_bottomContentBorderThickness;
+
// used by showFullScreen in fake mode
QRect m_normalGeometry;
Qt::WindowFlags m_oldWindowFlags;
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
index 5702689d84..f62a6d29ce 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.mm
+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
@@ -220,6 +220,9 @@ QCocoaWindow::QCocoaWindow(QWindow *tlw)
, m_overrideBecomeKey(false)
, m_alertRequest(NoAlertRequest)
, monitor(nil)
+ , m_drawContentBorderGradient(false)
+ , m_topContentBorderThickness(0)
+ , m_bottomContentBorderThickness(0)
, m_normalGeometry(QRect(0,0,-1,-1))
{
#ifdef QT_COCOA_ENABLE_WINDOW_DEBUG
@@ -511,6 +514,9 @@ NSUInteger QCocoaWindow::windowStyleMask(Qt::WindowFlags flags)
}
}
+ if (m_drawContentBorderGradient)
+ styleMask |= NSTexturedBackgroundWindowMask;
+
#ifdef QT_COCOA_ENABLE_WINDOW_DEBUG
qDebug("windowStyleMask of '%s': flags %X -> styleMask %lX", qPrintable(window()->title()), (int)flags, styleMask);
#endif
@@ -936,6 +942,9 @@ NSWindow * QCocoaWindow::createNSWindow()
}
m_windowModality = window()->modality();
+
+ applyContentBorderThickness(createdWindow);
+
return createdWindow;
}
@@ -1100,6 +1109,38 @@ void QCocoaWindow::registerTouch(bool enable)
[m_contentView setAcceptsTouchEvents:NO];
}
+void QCocoaWindow::setContentBorderThickness(int topThickness, int bottomThickness)
+{
+ m_topContentBorderThickness = topThickness;
+ m_bottomContentBorderThickness = bottomThickness;
+ bool enable = (topThickness > 0 || bottomThickness > 0);
+ m_drawContentBorderGradient = enable;
+
+ applyContentBorderThickness(m_nsWindow);
+}
+
+void QCocoaWindow::applyContentBorderThickness(NSWindow *window)
+{
+ if (!window)
+ return;
+
+ if (m_drawContentBorderGradient)
+ [window setStyleMask:[window styleMask] | NSTexturedBackgroundWindowMask];
+ else
+ [window setStyleMask:[window styleMask] & ~NSTexturedBackgroundWindowMask];
+
+ if (m_topContentBorderThickness > 0) {
+ [window setContentBorderThickness:m_topContentBorderThickness forEdge:NSMaxYEdge];
+ [window setAutorecalculatesContentBorderThickness:NO forEdge:NSMaxYEdge];
+ }
+
+ if (m_bottomContentBorderThickness > 0) {
+ [window setContentBorderThickness:m_topContentBorderThickness forEdge:NSMinYEdge];
+ [window setAutorecalculatesContentBorderThickness:NO forEdge:NSMinYEdge];
+ }
+}
+
+
qreal QCocoaWindow::devicePixelRatio() const
{
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm
index e183f93c6c..f7b129aea1 100644
--- a/src/plugins/platforms/cocoa/qnsview.mm
+++ b/src/plugins/platforms/cocoa/qnsview.mm
@@ -408,6 +408,9 @@ static QTouchDevice *touchDevice = 0;
m_shouldSetGLContextinDrawRect = false;
}
+ if (m_platformWindow->m_drawContentBorderGradient)
+ NSDrawWindowBackground(dirtyRect);
+
if (!m_backingStore)
return;
@@ -451,7 +454,8 @@ static QTouchDevice *touchDevice = 0;
// Optimization: Copy frame buffer content instead of blending for
// top-level windows where Qt fills the entire window content area.
- if (m_platformWindow->m_nsWindow)
+ // (But don't overpaint the title-bar gradient)
+ if (m_platformWindow->m_nsWindow && !m_platformWindow->m_drawContentBorderGradient)
CGContextSetBlendMode(cgContext, kCGBlendModeCopy);
CGContextDrawImage(cgContext, dirtyWindowRect, cleanImg);