Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickplatformcolordialog.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6#include <QtCore/qloggingcategory.h>
7#include <QtGui/qwindow.h>
8#include <QtQml/qqmlcontext.h>
9#include <QtQml/qqmlinfo.h>
10#include <QtQuick/qquickwindow.h>
11#include <QtQuickTemplates2/private/qquickdialog_p.h>
12#include <QtQuickTemplates2/private/qquickpopup_p_p.h>
13#include <QtQuickTemplates2/private/qquickpopupanchors_p.h>
14
16
18
19Q_LOGGING_CATEGORY(lcQuickPlatformColorDialog, "qt.quick.dialogs.quickplatformcolordialog")
20
22{
23 qCDebug(lcQuickPlatformColorDialog)
24 << "creating non-native Qt Quick ColorDialog with parent" << parent;
25
26 // Set a parent so that we get deleted if we can't be shown for whatever reason.
27 // Our eventual parent should be the window, however.
28 setParent(parent);
29
30 auto qmlContext = ::qmlContext(parent);
31 if (!qmlContext) {
32 qmlWarning(parent) << "No QQmlContext for QQuickPlatformColorDialog; can't create "
33 "non-native ColorDialog implementation";
34 return;
35 }
36
37 const auto dialogQmlUrl = QUrl(QStringLiteral(
38 "qrc:/qt-project.org/imports/QtQuick/Dialogs/quickimpl/qml/ColorDialog.qml"));
39 QQmlComponent colorDialogComponent(qmlContext->engine(), dialogQmlUrl, parent);
40 if (!colorDialogComponent.isReady()) {
41 qmlWarning(parent) << "Failed to load non-native ColorDialog implementation:\n"
42 << colorDialogComponent.errorString();
43 return;
44 }
45
46 m_dialog = qobject_cast<QQuickColorDialogImpl *>(colorDialogComponent.create());
47 if (!m_dialog) {
48 qmlWarning(parent) << "Failed to create an instance of the non-native ColorDialog:\n"
49 << colorDialogComponent.errorString();
50 return;
51 }
52 // Give it a parent until it's parented to the window in show().
53 m_dialog->setParent(this);
54
57
60}
61
63{
64 return m_dialog;
65}
66
68{
69 if (m_dialog)
70 m_dialog->setColor(color);
71}
72
74{
75 return m_dialog ? m_dialog->color().toRgb() : QColor();
76}
77
79{
80 qCWarning(lcQuickPlatformColorDialog)
81 << "exec() is not supported for the Qt Quick ColorDialog fallback";
82}
83
85 QWindow *parent)
86{
87 qCDebug(lcQuickPlatformColorDialog)
88 << "show called with flags" << flags << "modality" << modality << "parent" << parent;
89
90 if (!m_dialog || !parent)
91 return false;
92
93 auto quickWindow = qobject_cast<QQuickWindow *>(parent);
94
95 if (!quickWindow) {
96 qmlInfo(this->parent()) << "Parent window (" << parent
97 << ") of non-native dialog is not a QQuickWindow";
98 return false;
99 }
100
101 m_dialog->setParent(parent);
102 m_dialog->resetParentItem();
103
104 auto popupPrivate = QQuickPopupPrivate::get(m_dialog);
105 popupPrivate->getAnchors()->setCenterIn(m_dialog->parentItem());
106
107 QSharedPointer<QColorDialogOptions> options = QPlatformColorDialogHelper::options();
108
109 m_dialog->setTitle(options->windowTitle());
110 m_dialog->setOptions(options);
111
112 m_dialog->open();
113 return true;
114}
115
117{
118 if (!m_dialog)
119 return;
120
121 m_dialog->close();
122}
123
125{
126 return m_dialog;
127}
128
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
QColor toRgb() const noexcept
Create and returns an RGB QColor based on this color.
Definition qcolor.cpp:2035
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
void setParent(QObject *parent)
Makes the object a child of parent.
Definition qobject.cpp:2195
const QSharedPointer< QColorDialogOptions > & options() const
void currentColorChanged(const QColor &color)
The QQmlComponent class encapsulates a QML component definition.
QQmlEngine * engine() const
Return the context's QQmlEngine, or \nullptr if the context has no QQmlEngine or the QQmlEngine was d...
void setOptions(const QSharedPointer< QColorDialogOptions > &options)
void colorChanged(const QColor &color)
void setColor(const QColor &c)
void setTitle(const QString &title)
void accepted()
void rejected()
virtual void setCurrentColor(const QColor &color) override
virtual QColor currentColor() const override
QQuickColorDialogImpl * dialog() const
bool show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent) override
static QQuickPopupPrivate * get(QQuickPopup *popup)
void close()
\qmlmethod void QtQuick.Controls::Popup::close()
void open()
\qmlmethod void QtQuick.Controls::Popup::open()
\inmodule QtCore
Definition qurl.h:94
\inmodule QtGui
Definition qwindow.h:63
Combined button and popup list for selecting options.
WindowModality
#define Q_LOGGING_CATEGORY(name,...)
#define qCWarning(category,...)
#define qCDebug(category,...)
GLuint color
[2]
GLbitfield flags
QQmlContext * qmlContext(const QObject *obj)
Definition qqml.cpp:75
Q_QML_EXPORT QQmlInfo qmlInfo(const QObject *me)
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
#define QStringLiteral(str)
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
file setParent(multiPart)