Cocoa: Implement propagateSizeHints.
authorMorten Sorvig <morten.sorvig@nokia.com>
Wed, 26 Oct 2011 08:00:26 +0000 (10:00 +0200)
committerQt by Nokia <qt-info@nokia.com>
Thu, 27 Oct 2011 07:37:29 +0000 (09:37 +0200)
Change-Id: Idc1244ffbf975972f01d9ee48092500a72739d37
Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
src/plugins/platforms/cocoa/qcocoahelpers.h
src/plugins/platforms/cocoa/qcocoahelpers.mm
src/plugins/platforms/cocoa/qcocoawindow.h
src/plugins/platforms/cocoa/qcocoawindow.mm

index 78904bc..3c1c065 100644 (file)
@@ -77,6 +77,8 @@ CGImageRef qt_mac_image_to_cgimage(const QImage &image);
 NSImage *qt_mac_cgimage_to_nsimage(CGImageRef iamge);
 NSImage *qt_mac_create_nsimage(const QPixmap &pm);
 
+NSSize qt_mac_toNSSize(const QSize &qtSize);
+
 QChar qt_mac_qtKey2CocoaKey(Qt::Key key);
 Qt::Key qt_mac_cocoaKey2QtKey(QChar keyCode);
 
index 7e82405..113415f 100644 (file)
@@ -128,6 +128,10 @@ NSImage *qt_mac_create_nsimage(const QPixmap &pm)
     return qt_mac_cgimage_to_nsimage(qt_mac_image_to_cgimage(image));
 }
 
+NSSize qt_mac_toNSSize(const QSize &qtSize)
+{
+    return NSMakeSize(qtSize.width(), qtSize.height());
+}
 
 // Use this method to keep all the information in the TextSegment. As long as it is ordered
 // we are in OK shape, and we can influence that ourselves.
index dde64a1..23aab63 100644 (file)
@@ -64,6 +64,8 @@ public:
     void raise();
     void lower();
 
+    void propagateSizeHints();
+
     WId winId() const;
     NSView *contentView() const;
 
index 840d4d9..e587b05 100644 (file)
@@ -140,6 +140,26 @@ void QCocoaWindow::lower()
     [m_nsWindow orderFront: m_nsWindow];
 }
 
+void QCocoaWindow::propagateSizeHints()
+{
+    [m_nsWindow setMinSize : qt_mac_toNSSize(window()->minimumSize())];
+    [m_nsWindow setMaxSize : qt_mac_toNSSize(window()->maximumSize())];
+
+    if (!window()->sizeIncrement().isNull())
+        [m_nsWindow setResizeIncrements : qt_mac_toNSSize(window()->sizeIncrement())];
+
+    // We must set the window frame after setting the minimum size to prevent the window
+    // from being resized to the minimum size. Use QWindow::baseSize if set, otherwise
+    // use the current size.
+    QSize baseSize = window()->baseSize();
+    QRect rect = geometry();
+    if (!baseSize.isNull()) {
+        [m_nsWindow setFrame : NSMakeRect(rect.x(), rect.y(), baseSize.width(), baseSize.height()) display : YES];
+    } else {
+        [m_nsWindow setFrame : NSMakeRect(rect.x(), rect.y(), rect.width(), rect.height()) display : YES];
+    }
+}
+
 WId QCocoaWindow::winId() const
 {
     return WId(m_nsWindow);