aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@digia.com>2013-01-07 13:53:45 +0100
committerMorten Johan Sørvig <morten.sorvig@digia.com>2013-01-31 08:42:47 +0100
commit8a6721e4240fdf693955bbbc7bc60d58fbf158a5 (patch)
tree5c151d35291c51de6668872b7606697b719dd08c /examples
parent77ea1322d192cd3b9a807370cc90df5a598a2550 (diff)
Add QtMacNativeWidget example.
Needs implementation support in the Qt Cocoa platform plugin. Change-Id: Ie8c37889758ada7d3503b1abf4432f0722b13735 Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/qtmacnativewidget/main.mm129
-rw-r--r--examples/qtmacnativewidget/qtmacnativewidget.pro11
2 files changed, 140 insertions, 0 deletions
diff --git a/examples/qtmacnativewidget/main.mm b/examples/qtmacnativewidget/main.mm
new file mode 100644
index 0000000..fd3cc87
--- /dev/null
+++ b/examples/qtmacnativewidget/main.mm
@@ -0,0 +1,129 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+#include <Cocoa/Cocoa.h>
+#include <qtmacnativewidget.h>
+
+class RedWidget : public QWidget
+{
+public:
+ RedWidget() {
+
+ }
+
+ void resizeEvent(QResizeEvent *)
+ {
+ qDebug() << "RedWidget::resize" << size();
+ }
+
+ void paintEvent(QPaintEvent *event)
+ {
+ QPainter p(this);
+ QRect rect(QPoint(0, 0), size());
+ qDebug() << "Painting geometry" << rect;
+ p.fillRect(rect, QColor(133, 50, 50));
+ }
+};
+
+@interface WindowCreator : NSObject {}
+- (void)createWindow;
+@end
+
+@implementation WindowCreator
+- (void)createWindow {
+
+ // Create the NSWindow
+ NSRect frame = NSMakeRect(500, 500, 500, 500);
+ NSWindow* window = [[NSWindow alloc] initWithContentRect:frame
+ styleMask:NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask
+ backing:NSBackingStoreBuffered
+ defer:NO];
+ [window setTitle:@"NSWindow"];
+
+ // Create widget hierarchy with QPushButton and QLineEdit
+ QtMacNativeWidget *nativeWidget = new QtMacNativeWidget();
+
+ QHBoxLayout *hlayout = new QHBoxLayout();
+ hlayout->addWidget(new QPushButton("Push", nativeWidget));
+ hlayout->addWidget(new QLineEdit);
+
+ QVBoxLayout *vlayout = new QVBoxLayout();
+ vlayout->addLayout(hlayout);
+
+ //RedWidget * redWidget = new RedWidget;
+ //vlayout->addWidget(redWidget);
+
+ nativeWidget->setLayout(vlayout);
+
+ // Get the NSView for QMacNativeWidget and set it as the content view for the NSWindow
+ [window setContentView:nativeWidget->nativeView()];
+
+ // show() must be called on nativeWiget to get the widgets int he correct state.
+ nativeWidget->show();
+
+ // Show the NSWindow
+ [window makeKeyAndOrderFront:NSApp];
+}
+@end
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ // Start Cocoa. Create NSApplicaiton.
+ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+ [NSApplication sharedApplication];
+
+ // Schedule call to create the UI using a zero timer.
+ WindowCreator *windowCreator= [WindowCreator alloc];
+ [NSTimer scheduledTimerWithTimeInterval:0 target:windowCreator selector:@selector(createWindow) userInfo:nil repeats:NO];
+
+ // Stare the Cocoa event loop.
+ [(NSApplication *)NSApp run];
+ [NSApp release];
+ [pool release];
+ exit(0);
+ return 0;
+}
+
+
+
diff --git a/examples/qtmacnativewidget/qtmacnativewidget.pro b/examples/qtmacnativewidget/qtmacnativewidget.pro
new file mode 100644
index 0000000..07d271e
--- /dev/null
+++ b/examples/qtmacnativewidget/qtmacnativewidget.pro
@@ -0,0 +1,11 @@
+TEMPLATE = app
+
+include (../../src/qtmacextras.pri)
+
+OBJECTIVE_SOURCES += main.mm
+LIBS += -framework Cocoa
+
+QT += gui widgets
+QT += widgets-private gui-private core-private
+
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0