diff options
author | Shawn Rutledge <shawn.rutledge@digia.com> | 2013-03-11 11:05:30 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-03-18 13:44:38 +0100 |
commit | 69186a08270a9c585b19a5140a5fcf52e2bf5bc3 (patch) | |
tree | a2d80d8c17a567d9f81ca2216bf37d7e05f874e4 /src/imports/widgets | |
parent | 7fded5040f56b8def7a93fcce03f93f06bcc6bc4 (diff) |
Add ColorDialog to QtQuick.Dialogs
As with FileDialog, it tries QPA, then QColorDialog, and falls back to
a QML implementation (which is also provided here) if neither type of
native dialog is available.
Change-Id: I384928e1f7322bb6b867d4618d07c88c70e3cbfe
Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
Diffstat (limited to 'src/imports/widgets')
-rw-r--r-- | src/imports/widgets/qquickqcolordialog.cpp | 172 | ||||
-rw-r--r-- | src/imports/widgets/qquickqcolordialog_p.h | 78 | ||||
-rw-r--r-- | src/imports/widgets/widgets.pro | 4 | ||||
-rw-r--r-- | src/imports/widgets/widgetsplugin.cpp | 2 |
4 files changed, 256 insertions, 0 deletions
diff --git a/src/imports/widgets/qquickqcolordialog.cpp b/src/imports/widgets/qquickqcolordialog.cpp new file mode 100644 index 0000000000..abe6ffd004 --- /dev/null +++ b/src/imports/widgets/qquickqcolordialog.cpp @@ -0,0 +1,172 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtQml 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 "qquickqcolordialog_p.h" +#include "qquickitem.h" + +#include <private/qguiapplication_p.h> +#include <private/qqmlcontext_p.h> +#include <QWindow> +#include <QQuickWindow> +#include <QColorDialog> + +QT_BEGIN_NAMESPACE + +class QColorDialogHelper : public QPlatformColorDialogHelper +{ +public: + QColorDialogHelper() : + QPlatformColorDialogHelper() + { + connect(&m_dialog, SIGNAL(currentColorChanged(const QColor&)), this, SIGNAL(currentColorChanged(const QColor&))); + connect(&m_dialog, SIGNAL(colorSelected(const QColor&)), this, SIGNAL(colorSelected(const QColor&))); + connect(&m_dialog, SIGNAL(accepted()), this, SIGNAL(accept())); + connect(&m_dialog, SIGNAL(rejected()), this, SIGNAL(reject())); + } + + virtual void setCurrentColor(const QColor &c) { m_dialog.setCurrentColor(c); } + virtual QColor currentColor() const { return m_dialog.currentColor(); } + + virtual void exec() { m_dialog.exec(); } + + virtual bool show(Qt::WindowFlags f, Qt::WindowModality m, QWindow *parent) { + m_dialog.windowHandle()->setTransientParent(parent); + m_dialog.windowHandle()->setFlags(f); + m_dialog.setWindowModality(m); + m_dialog.setWindowTitle(QPlatformColorDialogHelper::options()->windowTitle()); + m_dialog.setOptions((QColorDialog::ColorDialogOptions)((int)(QPlatformColorDialogHelper::options()->options()))); + m_dialog.show(); + return m_dialog.isVisible(); + } + + virtual void hide() { m_dialog.hide(); } + +private: + QColorDialog m_dialog; +}; + +/*! + \qmltype QtColorDialog + \instantiates QQuickQColorDialog + \inqmlmodule QtQuick.PrivateWidgets 1 + \ingroup qtquick-visual + \brief Dialog component for choosing a color. + \since 5.1 + \internal + + QtColorDialog provides a means to instantiate and manage a QColorDialog. + It is not recommended to be used directly; it is an implementation + detail of \l ColorDialog in the \l QtQuick.Dialogs module. + + To use this type, you will need to import the module with the following line: + \code + import QtQuick.PrivateWidgets 1.0 + \endcode +*/ + +/*! + \qmlsignal QtQuick::Dialogs::ColorDialog::accepted + + The \a accepted signal is emitted when the user has finished using the + dialog. You can then inspect the \a color property to get the selection. + + Example: + + \qml + ColorDialog { + onAccepted: { console.log("Selected color: " + color) } + } + \endqml +*/ + +/*! + \qmlsignal QtQuick::Dialogs::ColorDialog::rejected + + The \a rejected signal is emitted when the user has dismissed the dialog, + either by closing the dialog window or by pressing the Cancel button. +*/ + +/*! + \class QQuickQColorDialog + \inmodule QtQuick.PrivateWidgets + \internal + + \brief The QQuickQColorDialog class is a wrapper for a QColorDialog. + + \since 5.1 +*/ + +/*! + Constructs a file dialog with parent window \a parent. +*/ +QQuickQColorDialog::QQuickQColorDialog(QObject *parent) + : QQuickAbstractColorDialog(parent) +{ +} + +/*! + Destroys the file dialog. +*/ +QQuickQColorDialog::~QQuickQColorDialog() +{ + if (m_dlgHelper) + m_dlgHelper->hide(); + delete m_dlgHelper; +} + +QPlatformColorDialogHelper *QQuickQColorDialog::helper() +{ + QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent()); + if (parentItem) + m_parentWindow = parentItem->window(); + + if (!m_dlgHelper) { + m_dlgHelper = new QColorDialogHelper(); + connect(m_dlgHelper, SIGNAL(currentColorChanged(const QColor&)), this, SLOT(setColor(QColor))); + connect(m_dlgHelper, SIGNAL(colorSelected(const QColor&)), this, SLOT(setColor(QColor))); + connect(m_dlgHelper, SIGNAL(accept()), this, SLOT(accept())); + connect(m_dlgHelper, SIGNAL(reject()), this, SLOT(reject())); + } + + return m_dlgHelper; +} + +QT_END_NAMESPACE diff --git a/src/imports/widgets/qquickqcolordialog_p.h b/src/imports/widgets/qquickqcolordialog_p.h new file mode 100644 index 0000000000..3fb0476299 --- /dev/null +++ b/src/imports/widgets/qquickqcolordialog_p.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtQml 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$ +** +****************************************************************************/ + +#ifndef QQUICKQCOLORDIALOG_P_H +#define QQUICKQCOLORDIALOG_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 "../dialogs/qquickabstractcolordialog_p.h" + +QT_BEGIN_NAMESPACE + +class QQuickQColorDialog : public QQuickAbstractColorDialog +{ + Q_OBJECT + +public: + QQuickQColorDialog(QObject *parent = 0); + virtual ~QQuickQColorDialog(); + +protected: + QPlatformColorDialogHelper *helper(); + + Q_DISABLE_COPY(QQuickQColorDialog) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickQColorDialog *) + +#endif // QQUICKQCOLORDIALOG_P_H diff --git a/src/imports/widgets/widgets.pro b/src/imports/widgets/widgets.pro index 7de5aa6c5a..c444674a75 100644 --- a/src/imports/widgets/widgets.pro +++ b/src/imports/widgets/widgets.pro @@ -6,12 +6,16 @@ IMPORT_VERSION = 1.0 SOURCES += \ qquickqfiledialog.cpp \ ../dialogs/qquickabstractfiledialog.cpp \ + qquickqcolordialog.cpp \ + ../dialogs/qquickabstractcolordialog.cpp \ ../dialogs/qquickabstractdialog.cpp \ widgetsplugin.cpp HEADERS += \ qquickqfiledialog_p.h \ ../dialogs/qquickabstractfiledialog_p.h \ + qquickqcolordialog_p.h \ + ../dialogs/qquickabstractcolordialog_p.h \ ../dialogs/qquickabstractdialog_p.h QT += quick-private gui-private core-private qml-private v8-private widgets diff --git a/src/imports/widgets/widgetsplugin.cpp b/src/imports/widgets/widgetsplugin.cpp index 6d3a56ca27..a29c9b3609 100644 --- a/src/imports/widgets/widgetsplugin.cpp +++ b/src/imports/widgets/widgetsplugin.cpp @@ -42,6 +42,7 @@ #include <QtQml/qqmlextensionplugin.h> #include <QtQml/qqml.h> #include "qquickqfiledialog_p.h" +#include "qquickqcolordialog_p.h" QT_BEGIN_NAMESPACE @@ -75,6 +76,7 @@ public: Q_ASSERT(QLatin1String(uri) == QLatin1String("QtQuick.PrivateWidgets")); qmlRegisterType<QQuickQFileDialog>(uri, 1, 0, "QtFileDialog"); + qmlRegisterType<QQuickQColorDialog>(uri, 1, 0, "QtColorDialog"); } }; |