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
qioscolordialog.mm
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
4#import <UIKit/UIKit.h>
5
6#include <QtGui/qwindow.h>
7#include <QDebug>
8
9#include <QtCore/private/qcore_mac_p.h>
10
11#include "qiosglobal.h"
12#include "qioscolordialog.h"
13#include "qiosintegration.h"
14
15@interface QIOSColorDialogController : UIColorPickerViewController <UIColorPickerViewControllerDelegate,
16 UIAdaptivePresentationControllerDelegate>
17@end
18
19@implementation QIOSColorDialogController {
20 QIOSColorDialog *m_colorDialog;
21}
22
23- (instancetype)initWithQIOSColorDialog:(QIOSColorDialog *)dialog
24{
25 if (self = [super init]) {
26 m_colorDialog = dialog;
27 self.delegate = self;
28 self.presentationController.delegate = self;
29 self.supportsAlpha = dialog->options()->testOption(QColorDialogOptions::ShowAlphaChannel);
30 }
31 return self;
32}
33
34- (void)setQColor:(const QColor &)qColor
35{
36 UIColor *uiColor;
37 const QColor::Spec spec = qColor.spec();
38 if (spec == QColor::Hsv) {
39 uiColor = [UIColor colorWithHue:qColor.hsvHueF()
40 saturation:qColor.hsvSaturationF()
41 brightness:qColor.valueF()
42 alpha:qColor.alphaF()];
43 } else {
44 uiColor = [UIColor colorWithRed:qColor.redF()
45 green:qColor.greenF()
46 blue:qColor.blueF()
47 alpha:qColor.alphaF()];
48 }
49 self.selectedColor = uiColor;
50}
51
52- (void)updateQColor
53{
54 UIColor *color = self.selectedColor;
55 CGFloat red = 0, green = 0, blue = 0, alpha = 0;
56
57 QColor newColor;
58 if ([color getRed:&red green:&green blue:&blue alpha:&alpha])
59 newColor.setRgbF(red, green, blue, alpha);
60 else
61 qWarning() << "Incompatible color space";
62
63
64 if (m_colorDialog) {
65 m_colorDialog->updateColor(newColor);
66 emit m_colorDialog->currentColorChanged(newColor);
67 }
68}
69
70// ----------------------UIColorPickerViewControllerDelegate--------------------------
71- (void)colorPickerViewControllerDidSelectColor:(UIColorPickerViewController *)viewController
72{
73 Q_UNUSED(viewController);
74 [self updateQColor];
75}
76
77- (void)colorPickerViewControllerDidFinish:(UIColorPickerViewController *)viewController
78{
79 Q_UNUSED(viewController);
80 [self updateQColor];
81 emit m_colorDialog->accept();
82}
83
84// ----------------------UIAdaptivePresentationControllerDelegate--------------------------
85- (void)presentationControllerDidDismiss:(UIPresentationController *)presentationController
86{
87 Q_UNUSED(presentationController);
88 emit m_colorDialog->reject();
89}
90
91@end
92
94 : m_viewController(nullptr)
95{
96}
97
102
104{
105 m_eventLoop.exec(QEventLoop::DialogExec);
106}
107
108bool QIOSColorDialog::show(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow *parent)
109{
110 Q_UNUSED(windowFlags);
111
112 if (!m_viewController) {
113 m_viewController = [[QIOSColorDialogController alloc] initWithQIOSColorDialog:this];
114 if (m_currentColor.isValid())
115 [m_viewController setQColor:m_currentColor];
116 }
117
118 if (windowModality == Qt::ApplicationModal || windowModality == Qt::WindowModal)
119 m_viewController.modalInPresentation = YES;
120
121 UIWindow *window = presentationWindow(parent);
122 if (!window)
123 return false;
124
125 // We can't present from view controller if already presenting
126 if (window.rootViewController.presentedViewController)
127 return false;
128
129 [window.rootViewController presentViewController:m_viewController animated:YES completion:nil];
130
131 return true;
132}
133
135{
136 [m_viewController dismissViewControllerAnimated:YES completion:nil];
137 [m_viewController release];
138 m_viewController = nullptr;
139 m_eventLoop.exit();
140}
141
143{
145 if (m_viewController)
146 [m_viewController setQColor:color];
147}
148
150{
151 return m_currentColor;
152}
153
155{
156 m_currentColor = color;
157}
158
159
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
Spec
The type of color specified, either RGB, extended RGB, HSV, CMYK or HSL.
Definition qcolor.h:35
@ Hsv
Definition qcolor.h:35
void setRgbF(float r, float g, float b, float a=1.0)
Sets the color channels of this color to r (red), g (green), b (blue) and a (alpha,...
Definition qcolor.cpp:1317
bool isValid() const noexcept
Returns true if the color is valid; otherwise returns false.
Definition qcolor.h:285
int exec(ProcessEventsFlags flags=AllEvents)
Enters the main event loop and waits until exit() is called.
void exit(int returnCode=0)
Tells the event loop to exit with a return code.
Options options
The various options that affect the look and feel of the dialog.
Definition qfiledialog.h:34
void setCurrentColor(const QColor &) override
void exec() override
QColor currentColor() const override
void hide() override
void updateColor(const QColor &)
bool show(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow *parent) override
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
\inmodule QtGui
Definition qwindow.h:63
WindowModality
@ WindowModal
@ ApplicationModal
float CGFloat
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
UIWindow * presentationWindow(QWindow *)
Definition qiosglobal.mm:96
#define qWarning
Definition qlogging.h:166
GLuint color
[2]
GLbyte GLbyte blue
Definition qopenglext.h:385
GLfloat GLfloat GLfloat alpha
Definition qopenglext.h:418
GLbyte green
Definition qopenglext.h:385
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
#define emit
#define Q_UNUSED(x)
QObject::connect nullptr
QFileDialog dialog(this)
[1]
aWidget window() -> setWindowTitle("New Window Title")
[2]
QGraphicsSvgItem * red