From 30d931b866bf6cdf7900d0c7f85734e0bfe03a6f Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Sun, 22 May 2016 19:03:56 +0200 Subject: Setup a Qt.labs.platform module This change just prepares the infrastructure and imports an icon loader helper that will be used for the platform menu, dialog, and system tray icon implementations. Change-Id: I34a93050a7c988134c3daa986aca6021eac7a4d1 Reviewed-by: Mitch Curtis --- src/imports/imports.pro | 1 + src/imports/platform/doc/qtlabsplatform.qdocconf | 37 +++++++ .../platform/doc/src/qtlabsplatform-index.qdoc | 50 ++++++++++ .../platform/doc/src/qtlabsplatform-qmltypes.qdoc | 58 +++++++++++ src/imports/platform/platform.pri | 5 + src/imports/platform/platform.pro | 21 ++++ src/imports/platform/qmldir | 3 + src/imports/platform/qquickplatformiconloader.cpp | 111 +++++++++++++++++++++ src/imports/platform/qquickplatformiconloader_p.h | 89 +++++++++++++++++ src/imports/platform/qtlabsplatformplugin.cpp | 71 +++++++++++++ 10 files changed, 446 insertions(+) create mode 100644 src/imports/platform/doc/qtlabsplatform.qdocconf create mode 100644 src/imports/platform/doc/src/qtlabsplatform-index.qdoc create mode 100644 src/imports/platform/doc/src/qtlabsplatform-qmltypes.qdoc create mode 100644 src/imports/platform/platform.pri create mode 100644 src/imports/platform/platform.pro create mode 100644 src/imports/platform/qmldir create mode 100644 src/imports/platform/qquickplatformiconloader.cpp create mode 100644 src/imports/platform/qquickplatformiconloader_p.h create mode 100644 src/imports/platform/qtlabsplatformplugin.cpp (limited to 'src/imports') diff --git a/src/imports/imports.pro b/src/imports/imports.pro index 3227cb99..e1da66c9 100644 --- a/src/imports/imports.pro +++ b/src/imports/imports.pro @@ -2,6 +2,7 @@ TEMPLATE = subdirs SUBDIRS += \ controls \ calendar \ + platform \ templates SUBDIRS += \ diff --git a/src/imports/platform/doc/qtlabsplatform.qdocconf b/src/imports/platform/doc/qtlabsplatform.qdocconf new file mode 100644 index 00000000..e7afb662 --- /dev/null +++ b/src/imports/platform/doc/qtlabsplatform.qdocconf @@ -0,0 +1,37 @@ +include($QT_INSTALL_DOCS/global/qt-module-defaults.qdocconf) + +project = QtLabsPlatform +description = Qt Labs Platform Reference Documentation +version = $QT_VERSION + +qhp.projects = QtLabsPlatform + +qhp.QtLabsPlatform.file = qtlabsplatform.qhp +qhp.QtLabsPlatform.namespace = org.qt-project.qtlabsplatform.$QT_VERSION_TAG +qhp.QtLabsPlatform.virtualFolder = qtlabsplatform +qhp.QtLabsPlatform.indexTitle = Qt Labs Platform +qhp.QtLabsPlatform.indexRoot = + +qhp.QtLabsPlatform.filterAttributes = qtlabsplatform $QT_VERSION qtrefdoc +qhp.QtLabsPlatform.customFilters.Qt.name = QtLabsPlatform $QT_VERSION +qhp.QtLabsPlatform.customFilters.Qt.filterAttributes = qtlabsplatform $QT_VERSION + +qhp.QtLabsPlatform.subprojects = qmltypes +qhp.QtLabsPlatform.subprojects.qmltypes.title = QML Types +qhp.QtLabsPlatform.subprojects.qmltypes.indexTitle = Qt Labs Platform QML Types +qhp.QtLabsPlatform.subprojects.qmltypes.selectors = qmlclass +qhp.QtLabsPlatform.subprojects.qmltypes.sortPages = true + +depends = qtcore qtgui qtdoc qtqml qtquick qtquickcontrols2 + +headerdirs += ../ +sourcedirs += ../ + +imagedirs += images + +navigation.landingpage = "Qt Labs Platform" +navigation.qmltypespage = "Qt Labs Platform QML Types" + +tagfile = qtlabsplatform.tags + +macro.labs = "\\note \\e{Types in Qt.labs modules are not guaranteed to remain compatible in future versions.}" diff --git a/src/imports/platform/doc/src/qtlabsplatform-index.qdoc b/src/imports/platform/doc/src/qtlabsplatform-index.qdoc new file mode 100644 index 00000000..aec2a923 --- /dev/null +++ b/src/imports/platform/doc/src/qtlabsplatform-index.qdoc @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \page qtlabsplatform-index.html + \title Qt Labs Platform + + \brief The experimental Qt Labs Platform module provides QML types for + native platform extensions. + + The experimental Qt Labs Platform module provides QML types for native + platform extensions. The module was introduced in Qt 5.8. + + \section1 QML Types + + \generatelist {qmltypesbymodule Qt.labs.platform} + + \labs + + \section1 Related Information + + \list + \li \l{Qt Quick} + \li \l{Qt Quick Controls 2} + \endlist +*/ diff --git a/src/imports/platform/doc/src/qtlabsplatform-qmltypes.qdoc b/src/imports/platform/doc/src/qtlabsplatform-qmltypes.qdoc new file mode 100644 index 00000000..470b93c4 --- /dev/null +++ b/src/imports/platform/doc/src/qtlabsplatform-qmltypes.qdoc @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \qmlmodule Qt.labs.platform 1.0 + \title Qt Labs Platform QML Types + \ingroup qmlmodules + \brief Provides QML types for native platform extensions. + + The experimental \l{Qt Labs Platform} module provides QML types for native + platform extensions. These QML types work in conjunction with \l{Qt Quick} + and \l{Qt Quick Controls 2}. + + The QML types can be imported into your application using the + following import statement in your .qml file: + + \badcode + import Qt.labs.platform 1.0 + \endcode + + \section1 QML Types + + \generatelist {qmltypesbymodule Qt.labs.platform} + + \labs + + \section1 Related Information + + \list + \li \l {Qt Quick Controls 2 QML Types} + \endlist + + \noautolist +*/ diff --git a/src/imports/platform/platform.pri b/src/imports/platform/platform.pri new file mode 100644 index 00000000..453ed447 --- /dev/null +++ b/src/imports/platform/platform.pri @@ -0,0 +1,5 @@ +HEADERS += \ + $$PWD/qquickplatformiconloader_p.h + +SOURCES += \ + $$PWD/qquickplatformiconloader.cpp diff --git a/src/imports/platform/platform.pro b/src/imports/platform/platform.pro new file mode 100644 index 00000000..8126860b --- /dev/null +++ b/src/imports/platform/platform.pro @@ -0,0 +1,21 @@ +TARGET = qtlabsplatformplugin +TARGETPATH = Qt/labs/platform +IMPORT_VERSION = 1.0 + +QT += qml quick +QT_PRIVATE += core-private gui-private qml-private quick-private + +DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII + +QMAKE_DOCS = $$PWD/doc/qtlabsplatform.qdocconf + +OTHER_FILES += \ + qmldir + +SOURCES += \ + $$PWD/qtlabsplatformplugin.cpp + +include(platform.pri) + +CONFIG += no_cxx_module +load(qml_plugin) diff --git a/src/imports/platform/qmldir b/src/imports/platform/qmldir new file mode 100644 index 00000000..9653b7d3 --- /dev/null +++ b/src/imports/platform/qmldir @@ -0,0 +1,3 @@ +module Qt.labs.platform +plugin qtlabsplatformplugin +classname QtLabsPlatformPlugin diff --git a/src/imports/platform/qquickplatformiconloader.cpp b/src/imports/platform/qquickplatformiconloader.cpp new file mode 100644 index 00000000..08df44d9 --- /dev/null +++ b/src/imports/platform/qquickplatformiconloader.cpp @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Labs Platform module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickplatformiconloader_p.h" + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +QQuickPlatformIconLoader::QQuickPlatformIconLoader(int slot, QObject *parent) + : m_parent(parent), + m_slot(slot), + m_enabled(false) +{ + Q_ASSERT(slot != -1 && parent); +} + +bool QQuickPlatformIconLoader::isEnabled() const +{ + return m_enabled; +} + +void QQuickPlatformIconLoader::setEnabled(bool enabled) +{ + m_enabled = enabled; + if (m_enabled) + loadIcon(); +} + +QIcon QQuickPlatformIconLoader::icon() const +{ + QIcon fallback = QPixmap::fromImage(image()); + return QIcon::fromTheme(m_iconName, fallback); +} + +QUrl QQuickPlatformIconLoader::iconSource() const +{ + return m_iconSource; +} + +void QQuickPlatformIconLoader::setIconSource(const QUrl& source) +{ + m_iconSource = source; + if (m_enabled) + loadIcon(); +} + +QString QQuickPlatformIconLoader::iconName() const +{ + return m_iconName; +} + +void QQuickPlatformIconLoader::setIconName(const QString& name) +{ + m_iconName = name; + if (m_enabled) + loadIcon(); +} + +void QQuickPlatformIconLoader::loadIcon() +{ + if (m_iconSource.isEmpty()) { + clear(m_parent); + } else { + load(qmlEngine(m_parent), m_iconSource); + if (m_slot != -1 && isLoading()) { + connectFinished(m_parent, m_slot); + m_slot = -1; + } + } + + if (!isLoading()) + m_parent->metaObject()->method(m_slot).invoke(m_parent); +} + +QT_END_NAMESPACE diff --git a/src/imports/platform/qquickplatformiconloader_p.h b/src/imports/platform/qquickplatformiconloader_p.h new file mode 100644 index 00000000..5ddb625f --- /dev/null +++ b/src/imports/platform/qquickplatformiconloader_p.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Labs Platform module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKPLATFORMICONLOADER_P_H +#define QQUICKPLATFORMICONLOADER_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QObject; + +class QQuickPlatformIconLoader : public QQuickPixmap +{ +public: + QQuickPlatformIconLoader(int slot, QObject *parent); + + bool isEnabled() const; + void setEnabled(bool enabled); + + QIcon icon() const; + + QUrl iconSource() const; + void setIconSource(const QUrl &source); + + QString iconName() const; + void setIconName(const QString &name); + +private: + void loadIcon(); + + QObject *m_parent; + int m_slot; + bool m_enabled; + QIcon m_icon; + QUrl m_iconSource; + QString m_iconName; +}; + +QT_END_NAMESPACE + +#endif // QQUICKPLATFORMICONLOADER_P_H diff --git a/src/imports/platform/qtlabsplatformplugin.cpp b/src/imports/platform/qtlabsplatformplugin.cpp new file mode 100644 index 00000000..c691e1cf --- /dev/null +++ b/src/imports/platform/qtlabsplatformplugin.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Labs Templates module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +static inline void initResources() +{ +#ifdef QT_STATIC + Q_INIT_RESOURCE(qmake_Qt_labs_platform); +#endif +} + +QT_BEGIN_NAMESPACE + +class QtLabsPlatformPlugin: public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) + +public: + QtLabsPlatformPlugin(QObject *parent = nullptr); + void registerTypes(const char *uri) override; +}; + +QtLabsPlatformPlugin::QtLabsPlatformPlugin(QObject *parent) : QQmlExtensionPlugin(parent) +{ + initResources(); +} + +void QtLabsPlatformPlugin::registerTypes(const char *uri) +{ + Q_UNUSED(uri) +} + +QT_END_NAMESPACE + +#include "qtlabsplatformplugin.moc" -- cgit v1.2.3