diff options
author | Topi Reinio <topi.reinio@digia.com> | 2013-09-24 14:26:54 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-26 12:39:20 +0200 |
commit | ff3b658c771d8fbc17109ff5e0096ad1fe62f2e4 (patch) | |
tree | 39900b5fabb1dc3e923ec0c48168d09557b28f96 /examples/macextras | |
parent | 8312bc37499461375fc2ee7a3e1b1eb6df948370 (diff) |
Doc: Create documentation structure for Qt Mac Extrasv5.2.0-alpha1
Create documentation structure for the module
- Module qdocconf
- Documentation pages for module index, namespace/classes,
examples (not much content yet)
Other doc-related changes
- Enable running 'make docs' on all platforms
- Move examples under examples/macextras for a clean
installing to QT_INSTALL_EXAMPLES
- Ensure documented classes use correct \inmodule and
\since commands
- Add \namespace QtMac
- Other minor fixes
Change-Id: I1376d68fcd7ab324a5d3355f1d15914092900e5b
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
Diffstat (limited to 'examples/macextras')
-rw-r--r-- | examples/macextras/embeddedqwindow/embeddedqwindow.pro | 9 | ||||
-rw-r--r-- | examples/macextras/embeddedqwindow/main.mm | 115 | ||||
-rw-r--r-- | examples/macextras/embeddedqwindow/window.cpp | 209 | ||||
-rw-r--r-- | examples/macextras/embeddedqwindow/window.h | 74 | ||||
-rw-r--r-- | examples/macextras/macextras.pro | 5 | ||||
-rw-r--r-- | examples/macextras/macfunctions/macfunctions.pro | 11 | ||||
-rw-r--r-- | examples/macextras/macfunctions/macfunctions.qrc | 5 | ||||
-rw-r--r-- | examples/macextras/macfunctions/main.cpp | 62 | ||||
-rw-r--r-- | examples/macextras/macfunctions/qtlogo.png | bin | 0 -> 1478 bytes | |||
-rw-r--r-- | examples/macextras/macpasteboardmime/macpasteboardmime.pro | 6 | ||||
-rw-r--r-- | examples/macextras/macpasteboardmime/main.cpp | 155 |
11 files changed, 651 insertions, 0 deletions
diff --git a/examples/macextras/embeddedqwindow/embeddedqwindow.pro b/examples/macextras/embeddedqwindow/embeddedqwindow.pro new file mode 100644 index 0000000..022a614 --- /dev/null +++ b/examples/macextras/embeddedqwindow/embeddedqwindow.pro @@ -0,0 +1,9 @@ +TEMPLATE = app + +OBJECTIVE_SOURCES += main.mm +HEADERS += window.h +SOURCES += window.cpp +LIBS += -framework Cocoa + +QT += gui widgets macextras +QT += widgets-private gui-private core-private diff --git a/examples/macextras/embeddedqwindow/main.mm b/examples/macextras/embeddedqwindow/main.mm new file mode 100644 index 0000000..f24533b --- /dev/null +++ b/examples/macextras/embeddedqwindow/main.mm @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** 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 <Cocoa/Cocoa.h> + +#include "window.h" + +#include <QtGui> +#include <qpa/qplatformnativeinterface.h> + + +NSView *getEmbeddableView(QWindow *qtWindow) +{ + // Make sure the platform window is created + qtWindow->create(); + + QPlatformNativeInterface *platformNativeInterface = QGuiApplication::platformNativeInterface(); + + // Inform the window that it's a "guest" of a non-QWindow + typedef void (*SetEmbeddedInForeignViewFunction)(QPlatformWindow *window, bool embedded); + reinterpret_cast<SetEmbeddedInForeignViewFunction>(platformNativeInterface-> + nativeResourceFunctionForIntegration("setEmbeddedInForeignView"))(qtWindow->handle(), true); + + // Get the Qt content NSView for the QWindow from the Qt platform plugin + NSView *qtView = (NSView *)platformNativeInterface->nativeResourceForWindow("nsview", qtWindow); + return qtView; // qtView is ready for use. +} + +@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"]; + [window setBackgroundColor:[NSColor blueColor]]; // if you see blue something is wrong + + // Create the QWindow and embed its view. + Window *qtWindow = new Window(); // ### who owns this window? + NSView *qtView = getEmbeddableView(qtWindow); + [window setContentView:qtView]; + + // Show the NSWindow + [window makeKeyAndOrderFront:NSApp]; +} +@end + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + + // Start Cocoa. Create NSApplicaiton. + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + [NSApplication sharedApplication]; + + // Schedule call to create the UI using a timer. + WindowCreator *windowCreator= [WindowCreator alloc]; + [NSTimer scheduledTimerWithTimeInterval:0 target:windowCreator selector:@selector(createWindow) userInfo:nil repeats:NO]; + + // Starte the Cocoa event loop. + [(NSApplication *)NSApp run]; + [NSApp release]; + [pool release]; + exit(0); + return 0; +} + + + diff --git a/examples/macextras/embeddedqwindow/window.cpp b/examples/macextras/embeddedqwindow/window.cpp new file mode 100644 index 0000000..1868591 --- /dev/null +++ b/examples/macextras/embeddedqwindow/window.cpp @@ -0,0 +1,209 @@ +/**************************************************************************** +** +** 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 "window.h" + +#include <private/qguiapplication_p.h> + +#include <QBackingStore> +#include <QPainter> +#include <QtWidgets> + +static int colorIndexId = 0; + +QColor colorTable[] = +{ + QColor("#f09f8f"), + QColor("#a2bff2"), + QColor("#c0ef8f") +}; + +Window::Window(QScreen *screen) + : QWindow(screen) + , m_backgroundColorIndex(colorIndexId++) + , m_backingStore(0) +{ + initialize(); +} + +Window::Window(QWindow *parent) + : QWindow(parent) + , m_backgroundColorIndex(colorIndexId++) + , m_backingStore(0) +{ + initialize(); +} + +void Window::initialize() +{ + if (parent()) + setGeometry(QRect(160, 120, 320, 240)); + else { + setGeometry(QRect(10, 10, 640, 480)); + + setSizeIncrement(QSize(10, 10)); + setBaseSize(QSize(640, 480)); + setMinimumSize(QSize(240, 160)); + setMaximumSize(QSize(800, 600)); + } + + setFlags(flags() | Qt::SubWindow); // Don't create a toplevel window. + + create(); + m_backingStore = new QBackingStore(this); + + m_image = QImage(geometry().size(), QImage::Format_RGB32); + m_image.fill(colorTable[m_backgroundColorIndex % (sizeof(colorTable) / sizeof(colorTable[0]))].rgba()); + + m_lastPos = QPoint(-1, -1); + m_renderTimer = 0; +} + +void Window::mousePressEvent(QMouseEvent *event) +{ + m_lastPos = event->pos(); +} + +void Window::mouseMoveEvent(QMouseEvent *event) +{ + if (m_lastPos != QPoint(-1, -1)) { + QPainter p(&m_image); + p.setRenderHint(QPainter::Antialiasing); + p.drawLine(m_lastPos, event->pos()); + m_lastPos = event->pos(); + } + + scheduleRender(); +} + +void Window::mouseReleaseEvent(QMouseEvent *event) +{ + if (m_lastPos != QPoint(-1, -1)) { + QPainter p(&m_image); + p.setRenderHint(QPainter::Antialiasing); + p.drawLine(m_lastPos, event->pos()); + m_lastPos = QPoint(-1, -1); + } + + scheduleRender(); +} + +void Window::exposeEvent(QExposeEvent *) +{ + scheduleRender(); +} + +void Window::resizeEvent(QResizeEvent *) +{ + QImage old = m_image; + + //qDebug() << "Window::resizeEvent" << width << height; + + int width = qMax(geometry().width(), old.width()); + int height = qMax(geometry().height(), old.height()); + + if (width > old.width() || height > old.height()) { + m_image = QImage(width, height, QImage::Format_RGB32); + m_image.fill(colorTable[(m_backgroundColorIndex) % (sizeof(colorTable) / sizeof(colorTable[0]))].rgba()); + + QPainter p(&m_image); + p.drawImage(0, 0, old); + } + + render(); +} + +void Window::keyPressEvent(QKeyEvent *event) +{ + switch (event->key()) { + case Qt::Key_Backspace: + m_text.chop(1); + break; + case Qt::Key_Enter: + case Qt::Key_Return: + m_text.append('\n'); + break; + default: + m_text.append(event->text()); + break; + } + scheduleRender(); +} + +void Window::scheduleRender() +{ + if (!m_renderTimer) + m_renderTimer = startTimer(1); +} + +void Window::timerEvent(QTimerEvent *) +{ + render(); + killTimer(m_renderTimer); + m_renderTimer = 0; +} + +void Window::render() +{ + if (!m_backingStore) + return; + QRect rect(QPoint(), geometry().size()); + + m_backingStore->resize(rect.size()); + + m_backingStore->beginPaint(rect); + + QPaintDevice *device = m_backingStore->paintDevice(); + + QPainter p(device); + p.drawImage(0, 0, m_image); + + QFont font; + font.setPixelSize(32); + + p.setFont(font); + p.drawText(rect, 0, m_text); + + m_backingStore->endPaint(); + m_backingStore->flush(rect); +} + + diff --git a/examples/macextras/embeddedqwindow/window.h b/examples/macextras/embeddedqwindow/window.h new file mode 100644 index 0000000..cdd6ebd --- /dev/null +++ b/examples/macextras/embeddedqwindow/window.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** 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 <QWindow> +#include <QImage> + +class Window : public QWindow +{ +public: + Window(QWindow *parent = 0); + Window(QScreen *screen); + +protected: + void mousePressEvent(QMouseEvent *); + void mouseMoveEvent(QMouseEvent *); + void mouseReleaseEvent(QMouseEvent *); + + void keyPressEvent(QKeyEvent *); + + void exposeEvent(QExposeEvent *); + void resizeEvent(QResizeEvent *); + + void timerEvent(QTimerEvent *); + +private: + void render(); + void scheduleRender(); + void initialize(); + + QString m_text; + QImage m_image; + QPoint m_lastPos; + int m_backgroundColorIndex; + QBackingStore *m_backingStore; + int m_renderTimer; +}; diff --git a/examples/macextras/macextras.pro b/examples/macextras/macextras.pro new file mode 100644 index 0000000..8fe1d13 --- /dev/null +++ b/examples/macextras/macextras.pro @@ -0,0 +1,5 @@ +TEMPLATE = subdirs + +mac:SUBDIRS = macfunctions +mac:!ios:SUBDIRS += embeddedqwindow \ + macpasteboardmime diff --git a/examples/macextras/macfunctions/macfunctions.pro b/examples/macextras/macfunctions/macfunctions.pro new file mode 100644 index 0000000..8d11880 --- /dev/null +++ b/examples/macextras/macfunctions/macfunctions.pro @@ -0,0 +1,11 @@ +TEMPLATE = app +TARGET = macfunctions +DEPENDPATH += . +INCLUDEPATH += . +QT += widgets macextras + +# Input +SOURCES += main.cpp + +RESOURCES += \ + macfunctions.qrc diff --git a/examples/macextras/macfunctions/macfunctions.qrc b/examples/macextras/macfunctions/macfunctions.qrc new file mode 100644 index 0000000..04a9419 --- /dev/null +++ b/examples/macextras/macfunctions/macfunctions.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file>qtlogo.png</file> + </qresource> +</RCC> diff --git a/examples/macextras/macfunctions/main.cpp b/examples/macextras/macfunctions/main.cpp new file mode 100644 index 0000000..a1563ba --- /dev/null +++ b/examples/macextras/macfunctions/main.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtMacExtras module 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 <QGuiApplication> +#include <QMenu> +#include <QPixmap> +#include <QWidget> +#include <qmacfunctions.h> + +int main(int argc, char **argv) +{ + QGuiApplication app(argc, argv); + + QWidget widget; + widget.show(); + + // Pixmap <-> CGImage conversion + QPixmap pixmap(":qtlogo.png"); + CGImageRef cgImage = QtMac::toCGImageRef(pixmap); + QPixmap pixmap2 = QtMac::fromCGImageRef(cgImage); + + return app.exec(); +} diff --git a/examples/macextras/macfunctions/qtlogo.png b/examples/macextras/macfunctions/qtlogo.png Binary files differnew file mode 100644 index 0000000..d75936b --- /dev/null +++ b/examples/macextras/macfunctions/qtlogo.png diff --git a/examples/macextras/macpasteboardmime/macpasteboardmime.pro b/examples/macextras/macpasteboardmime/macpasteboardmime.pro new file mode 100644 index 0000000..3ce4cd4 --- /dev/null +++ b/examples/macextras/macpasteboardmime/macpasteboardmime.pro @@ -0,0 +1,6 @@ +QT += macextras widgets + +SOURCES += main.cpp + + + diff --git a/examples/macextras/macpasteboardmime/main.cpp b/examples/macextras/macpasteboardmime/main.cpp new file mode 100644 index 0000000..4d3063a --- /dev/null +++ b/examples/macextras/macpasteboardmime/main.cpp @@ -0,0 +1,155 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtMacExtras module 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 <QApplication> +#include <QDebug> +#include <QDragEnterEvent> +#include <QDropEvent> +#include <QWidget> + +#include <qmacpasteboardmime.h> + +class VCardMime : public QMacPasteboardMime +{ +public: + VCardMime() : QMacPasteboardMime(MIME_ALL) + { } + + QString convertorName() + { + return QString("VCardMime"); + } + + bool canConvert(const QString &mime, QString flav) + { + return mimeFor(flav) == mime; + } + + QString mimeFor(QString flav) + { + if (flav == QString("public.vcard")) + return QString("application/x-mycompany-VCard"); + return QString(); + } + + QString flavorFor(const QString &mime) + { + if (mime == QString("application/x-mycompany-VCard")) + return QString("public.vcard"); + return QString(); + } + + QVariant convertToMime(const QString &mime, QList<QByteArray> data, QString flav) + { + Q_UNUSED(mime); + Q_UNUSED(flav); + + QByteArray all; + foreach (QByteArray i, data) { + all += i; + } + return QVariant(all); + } + + QList<QByteArray> convertFromMime(const QString &mime, QVariant data, QString flav) + { + Q_UNUSED(mime); + Q_UNUSED(data); + Q_UNUSED(flav); + // Todo: implement! + return QList<QByteArray>(); + } + +}; + +class TestWidget : public QWidget +{ +public: + TestWidget() : QWidget(0) + { + vcardMime = new VCardMime(); + setAcceptDrops(true); + } + + ~TestWidget() + { + delete vcardMime; + } + + void dragEnterEvent(QDragEnterEvent *e) + { + e->accept(); + + } + + virtual void dropEvent(QDropEvent *e) + { + e->accept(); + contentsDropEvent(e); + } + + void contentsDropEvent(QDropEvent* e) + { + if ( e->mimeData()->hasFormat( "application/x-mycompany-VCard" ) ) + { + QString s = QString( e->mimeData()->data( "application/x-mycompany-VCard" ) ); + + // s now contains text of vcard + qDebug() << "got vcard" << s.count(); + + e->acceptProposedAction(); + } + } +private: + VCardMime *vcardMime; +}; + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + qRegisterDraggedTypes(QStringList() << QLatin1String("public.vcard")); + + TestWidget wid1; + wid1.show(); + + return app.exec(); +} |