Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
// Qt-Security score:significant reason:default
4
5
#
include
"qquickplatformcolordialog_p.h"
6
7
#
include
<
QtCore
/
qloggingcategory
.
h
>
8
#
include
<
QtGui
/
qwindow
.
h
>
9
#
include
<
QtQml
/
qqmlcontext
.
h
>
10
#
include
<
QtQml
/
qqmlinfo
.
h
>
11
#
include
<
QtQml
/
qqmlcomponent
.
h
>
12
#
include
<
QtQuick
/
qquickwindow
.
h
>
13
#
include
<
QtQuickTemplates2
/
private
/
qquickdialog_p
.
h
>
14
#
include
<
QtQuickTemplates2
/
private
/
qquickdialog_p_p
.
h
>
15
#
include
<
QtQuickTemplates2
/
private
/
qquickpopup_p_p
.
h
>
16
#
include
<
QtQuickTemplates2
/
private
/
qquickpopupanchors_p
.
h
>
17
18
#
include
"qquickcolordialogimpl_p.h"
19
20
QT_BEGIN_NAMESPACE
21
22
Q_STATIC_LOGGING_CATEGORY(lcQuickPlatformColorDialog,
"qt.quick.dialogs.quickplatformcolordialog"
)
23
24
QQuickPlatformColorDialog::QQuickPlatformColorDialog(QObject *parent)
25
{
26
qCDebug(lcQuickPlatformColorDialog)
27
<<
"creating non-native Qt Quick ColorDialog with parent"
<< parent;
28
29
// Set a parent so that we get deleted if we can't be shown for whatever reason.
30
// Our eventual parent should be the window, however.
31
setParent(parent);
32
33
auto
qmlContext = ::qmlContext(parent);
34
if
(!qmlContext) {
35
qmlWarning(parent) <<
"No QQmlContext for QQuickPlatformColorDialog; can't create "
36
"non-native ColorDialog implementation"
;
37
return
;
38
}
39
40
const
auto
dialogQmlUrl = QUrl(QStringLiteral(
41
"qrc:/qt-project.org/imports/QtQuick/Dialogs/quickimpl/qml/ColorDialog.qml"
));
42
QQmlComponent colorDialogComponent(qmlContext->engine(), dialogQmlUrl, parent);
43
if
(!colorDialogComponent.isReady()) {
44
qmlWarning(parent) <<
"Failed to load non-native ColorDialog implementation:\n"
45
<< colorDialogComponent.errorString();
46
return
;
47
}
48
49
m_dialog = qobject_cast<QQuickColorDialogImpl *>(colorDialogComponent.create());
50
if
(!m_dialog) {
51
qmlWarning(parent) <<
"Failed to create an instance of the non-native ColorDialog:\n"
52
<< colorDialogComponent.errorString();
53
return
;
54
}
55
// Give it a parent until it's parented to the window in show().
56
m_dialog->setParent(
this
);
57
58
connect(m_dialog, &QQuickDialog::accepted,
this
, &QPlatformDialogHelper::accept);
59
connect(m_dialog, &QQuickDialog::rejected,
this
, &QPlatformDialogHelper::reject);
60
61
connect(m_dialog, &QQuickColorDialogImpl::colorChanged,
this
,
62
&QQuickPlatformColorDialog::currentColorChanged);
63
}
64
65
bool
QQuickPlatformColorDialog::isValid()
const
66
{
67
return
m_dialog;
68
}
69
70
void
QQuickPlatformColorDialog::setCurrentColor(
const
QColor &color)
71
{
72
if
(m_dialog)
73
m_dialog->setColor(color);
74
}
75
76
QColor QQuickPlatformColorDialog::currentColor()
const
77
{
78
return
m_dialog ? m_dialog->color().toRgb() : QColor();
79
}
80
81
void
QQuickPlatformColorDialog::exec()
82
{
83
qCWarning(lcQuickPlatformColorDialog)
84
<<
"exec() is not supported for the Qt Quick ColorDialog fallback"
;
85
}
86
87
bool
QQuickPlatformColorDialog::show(Qt::WindowFlags flags, Qt::WindowModality modality,
88
QWindow *parent)
89
{
90
qCDebug(lcQuickPlatformColorDialog)
91
<<
"show called with flags"
<< flags <<
"modality"
<< modality <<
"parent"
<< parent;
92
93
if
(!m_dialog || !parent)
94
return
false
;
95
96
auto
quickWindow = qobject_cast<QQuickWindow *>(parent);
97
98
if
(!quickWindow) {
99
qmlInfo(
this
->parent()) <<
"Parent window ("
<< parent
100
<<
") of non-native dialog is not a QQuickWindow"
;
101
return
false
;
102
}
103
104
m_dialog->setParent(parent);
105
m_dialog->resetParentItem();
106
107
auto
popupPrivate = QQuickPopupPrivate::get(m_dialog);
108
popupPrivate->getAnchors()->setCenterIn(m_dialog->parentItem());
109
popupPrivate->setPopupWindowFlags(flags);
110
111
QSharedPointer<QColorDialogOptions> options = QPlatformColorDialogHelper::options();
112
113
m_dialog->setTitle(options->windowTitle());
114
m_dialog->setOptions(options);
115
m_dialog->setWindowModality(modality);
116
m_dialog->open();
117
return
true
;
118
}
119
120
void
QQuickPlatformColorDialog::hide()
121
{
122
if
(!m_dialog)
123
return
;
124
125
m_dialog->close();
126
}
127
128
QQuickColorDialogImpl *QQuickPlatformColorDialog::dialog()
const
129
{
130
return
m_dialog;
131
}
132
133
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtdeclarative
src
quickdialogs
quickdialogsquickimpl
qquickplatformcolordialog.cpp
Generated on
for Qt by
1.18.0