7#include <QtGui/qwindow.h>
10#include <QtCore/private/qcore_mac_p.h>
16@interface QIOSColorDialogController : UIColorPickerViewController <UIColorPickerViewControllerDelegate,
17 UIAdaptivePresentationControllerDelegate>
20@implementation QIOSColorDialogController {
21 QIOSColorDialog *m_colorDialog;
24- (instancetype)initWithQIOSColorDialog:(QIOSColorDialog *)dialog
26 if (self = [super init]) {
27 m_colorDialog = dialog;
29 self.presentationController.delegate = self;
30 self.supportsAlpha = dialog->options()->testOption(QColorDialogOptions::ShowAlphaChannel);
35- (
void)setQColor:(
const QColor &)qColor
38 const QColor::Spec spec = qColor.spec();
39 if (spec == QColor::Hsv) {
40 uiColor = [UIColor colorWithHue:qColor.hsvHueF()
41 saturation:qColor.hsvSaturationF()
42 brightness:qColor.valueF()
43 alpha:qColor.alphaF()];
45 uiColor = [UIColor colorWithRed:qColor.redF()
48 alpha:qColor.alphaF()];
50 self.selectedColor = uiColor;
55 UIColor *color = self.selectedColor;
56 CGFloat red = 0, green = 0, blue = 0, alpha = 0;
59 if ([color getRed:&red green:&green blue:&blue alpha:&alpha])
60 newColor.setRgbF(red, green, blue, alpha);
62 qWarning() <<
"Incompatible color space";
66 m_colorDialog->updateColor(newColor);
67 emit m_colorDialog->currentColorChanged(newColor);
72- (
void)colorPickerViewControllerDidSelectColor:(UIColorPickerViewController *)viewController
74 Q_UNUSED(viewController);
78- (
void)colorPickerViewControllerDidFinish:(UIColorPickerViewController *)viewController
80 Q_UNUSED(viewController);
82 emit m_colorDialog->accept();
86- (
void)presentationControllerDidDismiss:(UIPresentationController *)presentationController
88 Q_UNUSED(presentationController);
89 emit m_colorDialog->reject();
94QIOSColorDialog::QIOSColorDialog()
95 : m_viewController(
nullptr)
99QIOSColorDialog::~QIOSColorDialog()
104void QIOSColorDialog::exec()
106 m_eventLoop.exec(QEventLoop::DialogExec);
109bool QIOSColorDialog::show(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow *parent)
111 Q_UNUSED(windowFlags);
113 if (!m_viewController) {
114 m_viewController = [[QIOSColorDialogController alloc] initWithQIOSColorDialog:
this];
115 if (m_currentColor.isValid())
116 [m_viewController setQColor:m_currentColor];
119 if (windowModality == Qt::ApplicationModal || windowModality == Qt::WindowModal)
120 m_viewController.modalInPresentation = YES;
122 UIWindow *window = presentationWindow(parent);
127 if (window.rootViewController.presentedViewController)
130 [window.rootViewController presentViewController:m_viewController animated:YES completion:nil];
135void QIOSColorDialog::hide()
137 [m_viewController dismissViewControllerAnimated:YES completion:nil];
138 [m_viewController release];
139 m_viewController =
nullptr;
143void QIOSColorDialog::setCurrentColor(
const QColor &color)
146 if (m_viewController)
147 [m_viewController setQColor:color];
150QColor QIOSColorDialog::currentColor()
const
152 return m_currentColor;
155void QIOSColorDialog::updateColor(
const QColor &color)
157 m_currentColor = color;