43 #if !defined(QT_NO_COLORDIALOG) && defined(Q_WS_MAC) 48 #include <private/qapplication_p.h> 49 #include <private/qt_mac_p.h> 51 #import <AppKit/AppKit.h> 52 #import <Foundation/Foundation.h> 59 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5 60 @protocol NSWindowDelegate <NSObject>
61 - (void)windowDidResize:(NSNotification *)notification;
62 - (BOOL)windowShouldClose:(
id)window;
70 @interface QT_MANGLE_NAMESPACE(QCocoaColorPanelDelegate) : NSObject<NSWindowDelegate> {
84 - (id)initWithColorPanel:(NSColorPanel *)panel
85 stolenContentView:(NSView *)stolenContentView
86 okButton:(NSButton *)okButton
87 cancelButton:(NSButton *)cancelButton
89 - (void)colorChanged:(NSNotification *)notification;
92 - (void)onCancelClicked;
93 - (void)updateQtColor;
94 - (NSColorPanel *)colorPanel;
96 - (void)finishOffWithCode:(NSInteger)result;
97 - (void)showColorPanel;
99 - (void)setResultSet:(BOOL)result;
102 @implementation QT_MANGLE_NAMESPACE(QCocoaColorPanelDelegate)
103 - (id)initWithColorPanel:(NSColorPanel *)panel
104 stolenContentView:(NSView *)stolenContentView
105 okButton:(NSButton *)okButton
106 cancelButton:(NSButton *)cancelButton
112 mStolenContentView = stolenContentView;
113 mOkButton = okButton;
114 mCancelButton = cancelButton;
118 mHackedPanel = (okButton != 0);
119 mResultCode = NSCancelButton;
120 mDialogIsExecuting =
false;
123 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 131 [okButton setAction:@selector(onOkClicked)];
132 [okButton setTarget:self];
134 [cancelButton setAction:@selector(onCancelClicked)];
135 [cancelButton setTarget:self];
138 [[NSNotificationCenter defaultCenter] addObserver:self
139 selector:@selector(colorChanged:)
140 name:NSColorPanelColorDidChangeNotification
151 NSView *ourContentView = [
mColorPanel contentView];
159 [ourContentView release];
162 [[NSNotificationCenter defaultCenter] removeObserver:self];
167 - (void)setResultSet:(BOOL)result
172 - (BOOL)windowShouldClose:(
id)
window 177 if (mDialogIsExecuting) {
181 mPriv->colorDialog()->reject();
186 - (void)windowDidResize:(NSNotification *)notification
193 - (void)colorChanged:(NSNotification *)notification
214 NSSize okSizeHint = [
mOkButton frame].size;
220 qMax(okSizeHint.width, cancelSizeHint.width)),
223 qMax(okSizeHint.height, cancelSizeHint.height));
227 { ButtonWidth, ButtonHeight } };
231 NSRect cancelRect = { { okRect.origin.x -
ButtonSpacing - ButtonWidth,
233 { ButtonWidth, ButtonHeight } };
238 NSRect stolenCVRect = { { 0.0, Y },
239 { rect.size.width, rect.size.height - Y } };
256 - (void)onCancelClicked
266 - (void)updateQtColor
271 NSString *colorSpaceName = [color colorSpaceName];
272 if (colorSpaceName == NSDeviceCMYKColorSpace) {
274 [color getCyan:&cyan magenta:&magenta yellow:&yellow black:&black alpha:&alpha];
276 }
else if (colorSpaceName == NSCalibratedRGBColorSpace || colorSpaceName == NSDeviceRGBColorSpace) {
278 [color getRed:&red green:&green blue:&blue alpha:&alpha];
279 mQtColor->setRgbF(red,
green,
blue, alpha);
280 }
else if (colorSpaceName == NSNamedColorSpace) {
281 NSColor *tmpColor = [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
283 [tmpColor getRed:&red green:&green blue:&blue alpha:&alpha];
284 mQtColor->setRgbF(red,
green,
blue, alpha);
286 NSColorSpace *colorSpace = [color colorSpace];
287 if ([colorSpace colorSpaceModel] == NSCMYKColorSpaceModel && [color numberOfComponents] == 5){
289 [color getComponents:components];
290 mQtColor->setCmykF(components[0], components[1], components[2], components[3], components[4]);
292 NSColor *tmpColor = [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
294 [tmpColor getRed:&red green:&green blue:&blue alpha:&alpha];
295 mQtColor->setRgbF(red,
green,
blue, alpha);
299 mPriv->setCurrentQColor(*mQtColor);
302 - (NSColorPanel *)colorPanel
312 - (void)finishOffWithCode:(NSInteger)code
315 if (mDialogIsExecuting) {
321 [NSApp stopModalWithCode:code];
329 if (mResultCode == NSCancelButton) {
330 mPriv->colorDialog()->reject();
332 mPriv->colorDialog()->accept();
338 - (void)showColorPanel
340 mDialogIsExecuting =
false;
348 mDialogIsExecuting =
true;
349 bool modalEnded =
false;
350 while (!modalEnded) {
351 #ifndef QT_NO_EXCEPTIONS 353 [NSApp runModalForWindow:mColorPanel];
355 }
@catch (NSException *) {
361 [NSApp runModalForWindow:mColorPanel];
367 if (mResultCode == NSCancelButton)
368 mPriv->colorDialog()->reject();
370 mPriv->colorDialog()->accept();
382 QWidget *parent,
const QString &title, QColorDialog::ColorDialogOptions options)
412 NSColorPanel *colorPanel = [NSColorPanel sharedColorPanel];
416 [colorPanel setHidesOnDeactivate:false];
419 [colorPanel setShowsAlpha:options & QColorDialog::ShowAlphaChannel];
420 [colorPanel setTitle:(NSString*)(CFStringRef)QCFString(title)];
422 NSView *stolenContentView = 0;
423 NSButton *okButton = 0;
424 NSButton *cancelButton = 0;
426 if (hackColorPanel) {
428 stolenContentView = [colorPanel contentView];
429 [stolenContentView retain];
430 [colorPanel setContentView:0];
433 NSRect frameRect = { { 0.0, 0.0 }, { 0.0, 0.0 } };
434 NSView *ourContentView = [[NSView alloc] initWithFrame:frameRect];
435 [ourContentView addSubview:stolenContentView];
441 [colorPanel setContentView:ourContentView];
442 [colorPanel setDefaultButtonCell:[okButton cell]];
445 delegate = [[QT_MANGLE_NAMESPACE(QCocoaColorPanelDelegate) alloc] initWithColorPanel:colorPanel
446 stolenContentView:stolenContentView
448 cancelButton:cancelButton
450 [colorPanel setDelegate:static_cast<QT_MANGLE_NAMESPACE(QCocoaColorPanelDelegate) *>(delegate)];
452 [static_cast<QT_MANGLE_NAMESPACE(QCocoaColorPanelDelegate) *>(delegate) setResultSet:NO];
453 setCocoaPanelColor(initial);
454 [static_cast<QT_MANGLE_NAMESPACE(QCocoaColorPanelDelegate) *>(delegate) showColorPanel];
459 [static_cast<QT_MANGLE_NAMESPACE(QCocoaColorPanelDelegate) *>(delegate) onCancelClicked];
464 [static_cast<QT_MANGLE_NAMESPACE(QCocoaColorPanelDelegate) *>(delegate) release];
484 [static_cast<QT_MANGLE_NAMESPACE(QCocoaColorPanelDelegate) *>(delegate) exec];
494 nsColor = [NSColor colorWithDeviceCyan:color.cyanF()
495 magenta:color.magentaF()
496 yellow:color.yellowF()
498 alpha:color.alphaF()];
500 nsColor = [NSColor colorWithCalibratedRed:color.redF()
503 alpha:color.alphaF()];
505 [[theDelegate colorPanel] setColor:nsColor];
The QColor class provides colors based on RGB, HSV or CMYK values.
const CGFloat ButtonSideMargin
virtual void interrupt()=0
Interrupts event dispatching; i.
void macStartInterceptNSPanelCtor()
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
#define QT_END_NAMESPACE
This macro expands to.
void mac_nativeDialogModalHelp()
const CGFloat ButtonBottomMargin
void macStopInterceptNSPanelCtor()
static QAbstractEventDispatcher * instance(QThread *thread=0)
Returns a pointer to the event dispatcher object for the specified thread.
Spec
The type of color specified, either RGB, HSV, CMYK or HSL.
void _q_macRunNativeAppModalPanel()
void setCocoaPanelColor(const QColor &color)
The QString class provides a Unicode character string.
const CGFloat ButtonSpacing
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
#define QT_BEGIN_NAMESPACE
This macro expands to.
The QColorDialog class provides a dialog widget for specifying colors.
QColorDialogPrivate * mPriv
const CGFloat ButtonTopMargin
void openCocoaColorPanel(const QColor &initial, QWidget *parent, const QString &title, QColorDialog::ColorDialogOptions options)
void closeCocoaColorPanel()
const CGFloat ButtonMinWidth
NSColorPanel * mColorPanel
const CGFloat ButtonMinHeight
#define QT_MANGLE_NAMESPACE(name)
void releaseCocoaColorPanelDelegate()
bool singleShot
This static function calls a slot after a given time interval.
static bool native_modal_dialog_active
#define QT_USE_NAMESPACE
This macro expands to using QT_NAMESPACE if QT_NAMESPACE is defined and nothing otherwise.
static const MacVersion MacintoshVersion
the version of the Macintosh operating system on which the application is run (Mac only)...
void finishOffWithCode:(NSInteger result)
NSView * mStolenContentView
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
NSButton * macCreateButton(const char *text, NSView *superview)
Spec spec() const
Returns how the color was specified.