diff options
-rw-r--r-- | src/imports/platform/doc/images/qtlabsplatform-colordialog-gtk.png | bin | 0 -> 11057 bytes | |||
-rw-r--r-- | src/imports/platform/platform.pri | 2 | ||||
-rw-r--r-- | src/imports/platform/qquickplatformcolordialog.cpp | 157 | ||||
-rw-r--r-- | src/imports/platform/qquickplatformcolordialog_p.h | 89 | ||||
-rw-r--r-- | src/imports/platform/qtlabsplatformplugin.cpp | 2 |
5 files changed, 250 insertions, 0 deletions
diff --git a/src/imports/platform/doc/images/qtlabsplatform-colordialog-gtk.png b/src/imports/platform/doc/images/qtlabsplatform-colordialog-gtk.png Binary files differnew file mode 100644 index 00000000..e0785a05 --- /dev/null +++ b/src/imports/platform/doc/images/qtlabsplatform-colordialog-gtk.png diff --git a/src/imports/platform/platform.pri b/src/imports/platform/platform.pri index dbebccd5..289b7d4f 100644 --- a/src/imports/platform/platform.pri +++ b/src/imports/platform/platform.pri @@ -1,4 +1,5 @@ HEADERS += \ + $$PWD/qquickplatformcolordialog_p.h \ $$PWD/qquickplatformdialog_p.h \ $$PWD/qquickplatformiconloader_p.h \ $$PWD/qquickplatformmenu_p.h \ @@ -8,6 +9,7 @@ HEADERS += \ $$PWD/qquickplatformsystemtrayicon_p.h SOURCES += \ + $$PWD/qquickplatformcolordialog.cpp \ $$PWD/qquickplatformdialog.cpp \ $$PWD/qquickplatformiconloader.cpp \ $$PWD/qquickplatformmenu.cpp \ diff --git a/src/imports/platform/qquickplatformcolordialog.cpp b/src/imports/platform/qquickplatformcolordialog.cpp new file mode 100644 index 00000000..a69ba025 --- /dev/null +++ b/src/imports/platform/qquickplatformcolordialog.cpp @@ -0,0 +1,157 @@ +/**************************************************************************** +** +** 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 "qquickplatformcolordialog_p.h" + +#include <QtGui/qpa/qplatformtheme.h> +#include <QtGui/private/qguiapplication_p.h> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype ColorDialog + \inherits Dialog + \instantiates QQuickPlatformColorDialog + \inqmlmodule Qt.labs.platform + \since 5.8 + \brief A native color dialog. + + The ColorDialog type provides a QML API for native platform color dialogs. + + \image qtlabsplatform-colordialog-gtk.png + + To show a color dialog, construct an instance of ColorDialog, set the + desired properties, and call \l {Dialog::}{open()}. ColorDialog emits + the \l colorSelected() signal when the user has selected a color. + + \code + MenuItem { + text: "Color" + onTriggered: colorDialog.open() + } + + ColorDialog { + id: colorDialog + currentColor: "black" + onColorSelected: document.brush = color + } + \endcode + + ColorDialog is currently available on the following platforms: + + \list + \li OS X + \li Linux (when running with the GTK+ platform theme) + \endlist + + \labs +*/ + +/*! + \qmlsignal void Qt.labs.platform::ColorDialog::colorSelected(color color) + + This signal is emitted just after the user has clicked \uicontrol OK to select a \a color. + + \sa currentColor +*/ + +QQuickPlatformColorDialog::QQuickPlatformColorDialog(QObject *parent) + : QQuickPlatformDialog(parent), m_options(QColorDialogOptions::create()) +{ + QPlatformDialogHelper *dialog = QGuiApplicationPrivate::platformTheme()->createPlatformDialogHelper(QPlatformTheme::ColorDialog); + if (QPlatformColorDialogHelper *colorDialog = qobject_cast<QPlatformColorDialogHelper *>(dialog)) { + connect(colorDialog, &QPlatformColorDialogHelper::currentColorChanged, this, &QQuickPlatformColorDialog::currentColorChanged); + connect(colorDialog, &QPlatformColorDialogHelper::colorSelected, this, &QQuickPlatformColorDialog::colorSelected); + } + setHandle(dialog); +} + +/*! + \qmlproperty color Qt.labs.platform::ColorDialog::currentColor + + This property holds the currently selected color in the dialog. + + \sa colorSelected() +*/ +QColor QQuickPlatformColorDialog::currentColor() const +{ + if (QPlatformColorDialogHelper *colorDialog = qobject_cast<QPlatformColorDialogHelper *>(handle())) + return colorDialog->currentColor(); + return QColor(); +} + +void QQuickPlatformColorDialog::setCurrentColor(const QColor &color) +{ + if (QPlatformColorDialogHelper *colorDialog = qobject_cast<QPlatformColorDialogHelper *>(handle())) + colorDialog->setCurrentColor(color); +} + +/*! + \qmlproperty flags Qt.labs.platform::ColorDialog::options + + This property holds the various options that affect the look and feel of the dialog. + + By default, all options are disabled. + + Options should be set before showing the dialog. Setting them while the dialog is + visible is not guaranteed to have an immediate effect on the dialog (depending on + the option and on the platform). + + Available options: + \value ColorDialog.ShowAlphaChannel Allow the user to select the alpha component of a color. + \value ColorDialog.NoButtons Don't display \uicontrol OK and \uicontrol Cancel buttons (useful for "live dialogs"). +*/ +QColorDialogOptions::ColorDialogOptions QQuickPlatformColorDialog::options() const +{ + return m_options->options(); +} + +void QQuickPlatformColorDialog::setOptions(QColorDialogOptions::ColorDialogOptions options) +{ + if (options == m_options->options()) + return; + + m_options->setOptions(options); + emit optionsChanged(); +} + +void QQuickPlatformColorDialog::applyOptions() +{ + if (QPlatformColorDialogHelper *colorDialog = qobject_cast<QPlatformColorDialogHelper *>(handle())) + colorDialog->setOptions(m_options); +} + +QT_END_NAMESPACE diff --git a/src/imports/platform/qquickplatformcolordialog_p.h b/src/imports/platform/qquickplatformcolordialog_p.h new file mode 100644 index 00000000..48b4aac1 --- /dev/null +++ b/src/imports/platform/qquickplatformcolordialog_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 QQUICKPLATFORMCOLORDIALOG_P_H +#define QQUICKPLATFORMCOLORDIALOG_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 "qquickplatformdialog_p.h" +#include <QtGui/qcolor.h> +#include <QtQml/qqml.h> + +QT_BEGIN_NAMESPACE + +class QQuickPlatformColorDialog : public QQuickPlatformDialog +{ + Q_OBJECT + Q_PROPERTY(QColor currentColor READ currentColor WRITE setCurrentColor NOTIFY currentColorChanged FINAL) + Q_PROPERTY(QColorDialogOptions::ColorDialogOptions options READ options WRITE setOptions NOTIFY optionsChanged FINAL) + Q_FLAGS(QColorDialogOptions::ColorDialogOptions) + +public: + explicit QQuickPlatformColorDialog(QObject *parent = nullptr); + + QColor currentColor() const; + void setCurrentColor(const QColor &color); + + QColorDialogOptions::ColorDialogOptions options() const; + void setOptions(QColorDialogOptions::ColorDialogOptions options); + +Q_SIGNALS: + void optionsChanged(); + void currentColorChanged(); + void colorSelected(const QColor &color); + +protected: + void applyOptions() override; + +private: + QSharedPointer<QColorDialogOptions> m_options; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickPlatformColorDialog) + +#endif // QQUICKPLATFORMCOLORDIALOG_P_H diff --git a/src/imports/platform/qtlabsplatformplugin.cpp b/src/imports/platform/qtlabsplatformplugin.cpp index ba79058f..d6be08af 100644 --- a/src/imports/platform/qtlabsplatformplugin.cpp +++ b/src/imports/platform/qtlabsplatformplugin.cpp @@ -38,6 +38,7 @@ #include <QtQml/qqml.h> #include "qquickplatformdialog_p.h" +#include "qquickplatformcolordialog_p.h" #include "qquickplatformmenu_p.h" #include "qquickplatformmenubar_p.h" @@ -73,6 +74,7 @@ QtLabsPlatformPlugin::QtLabsPlatformPlugin(QObject *parent) : QQmlExtensionPlugi void QtLabsPlatformPlugin::registerTypes(const char *uri) { qmlRegisterUncreatableType<QQuickPlatformDialog>(uri, 1, 0, "Dialog", QQuickPlatformDialog::tr("Dialog is an abstract base class")); + qmlRegisterType<QQuickPlatformColorDialog>(uri, 1, 0, "ColorDialog"); qmlRegisterType<QQuickPlatformMenu>(uri, 1, 0, "Menu"); qmlRegisterType<QQuickPlatformMenuBar>(uri, 1, 0, "MenuBar"); |