Qt 4.8
Public Functions | Protected Variables | List of all members
QCocoaColorPanelDelegate Class Reference
Inheritance diagram for QCocoaColorPanelDelegate:

Public Functions

(void) - colorChanged:
 
(NSColorPanel *) - colorPanel
 
(void) - exec
 
(void) - finishOffWithCode:
 
(id) - initWithColorPanel:stolenContentView:okButton:cancelButton:priv:
 
(void) - onCancelClicked
 
(void) - onOkClicked
 
(QColor- qtColor
 
(void) - relayout
 
(void) - setResultSet:
 
(void) - showColorPanel
 
(void) - updateQtColor
 

Protected Variables

NSButton * mCancelButton
 
NSColorPanel * mColorPanel
 
BOOL mDialogIsExecuting
 
CGFloat mExtraHeight
 
BOOL mHackedPanel
 
CGFloat mMinWidth
 
NSButton * mOkButton
 
QColorDialogPrivatemPriv
 
QColormQtColor
 
NSInteger mResultCode
 
BOOL mResultSet
 
NSView * mStolenContentView
 

Detailed Description

Definition at line 70 of file qcolordialog_mac.mm.

Functions

◆ colorChanged:()

- (void) colorChanged: (NSNotification *)  notification

Definition at line 193 of file qcolordialog_mac.mm.

193  :(NSNotification *)notification
194 {
195  Q_UNUSED(notification);
196  [self updateQtColor];
197 }
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ colorPanel()

- (NSColorPanel *) colorPanel

Definition at line 302 of file qcolordialog_mac.mm.

303 {
304  return mColorPanel;
305 }

◆ exec()

- (void) exec

Definition at line 344 of file qcolordialog_mac.mm.

345 {
348  mDialogIsExecuting = true;
349  bool modalEnded = false;
350  while (!modalEnded) {
351 #ifndef QT_NO_EXCEPTIONS
352  @try {
353  [NSApp runModalForWindow:mColorPanel];
354  modalEnded = true;
355  } @catch (NSException *) {
356  // For some reason, NSColorPanel throws an exception when
357  // clicking on 'SelectedMenuItemColor' from the 'Developer'
358  // palette (tab three).
359  }
360 #else
361  [NSApp runModalForWindow:mColorPanel];
362  modalEnded = true;
363 #endif
364  }
365 
367  if (mResultCode == NSCancelButton)
368  mPriv->colorDialog()->reject();
369  else
370  mPriv->colorDialog()->accept();
371 }
QColorDialog * colorDialog()
virtual void interrupt()=0
Interrupts event dispatching; i.
static QAbstractEventDispatcher * instance(QThread *thread=0)
Returns a pointer to the event dispatcher object for the specified thread.
virtual void accept()
Hides the modal dialog and sets the result code to Accepted.
Definition: qdialog.cpp:639
virtual void reject()
Hides the modal dialog and sets the result code to Rejected.
Definition: qdialog.cpp:650
QColorDialogPrivate * mPriv
static bool native_modal_dialog_active

◆ finishOffWithCode:()

- (void) finishOffWithCode: (NSInteger)  result

Definition at line 312 of file qcolordialog_mac.mm.

312  :(NSInteger)code
313 {
314  mResultCode = code;
315  if (mDialogIsExecuting) {
316  // We stop the current modal event loop. The control
317  // will then return inside -(void)exec below.
318  // It's important that the modal event loop is stopped before
319  // we accept/reject QColorDialog, since QColorDialog has its
320  // own event loop that needs to be stopped last.
321  [NSApp stopModalWithCode:code];
322  } else {
323  // Since we are not in a modal event loop, we can safely close
324  // down QColorDialog
325  // Calling accept() or reject() can in turn call closeCocoaColorPanel.
326  // This check will prevent any such recursion.
327  if (!mResultSet) {
328  mResultSet = true;
329  if (mResultCode == NSCancelButton) {
330  mPriv->colorDialog()->reject();
331  } else {
332  mPriv->colorDialog()->accept();
333  }
334  }
335  }
336 }
QColorDialog * colorDialog()
virtual void accept()
Hides the modal dialog and sets the result code to Accepted.
Definition: qdialog.cpp:639
virtual void reject()
Hides the modal dialog and sets the result code to Rejected.
Definition: qdialog.cpp:650
QColorDialogPrivate * mPriv

◆ initWithColorPanel:stolenContentView:okButton:cancelButton:priv:()

- (id) initWithColorPanel: (NSColorPanel *)  panel
stolenContentView: (NSView *)  stolenContentView
okButton: (NSButton *)  okButton
cancelButton: (NSButton *)  cancelButton
priv: (QColorDialogPrivate *)  priv 

Definition at line 103 of file qcolordialog_mac.mm.

103  :(NSColorPanel *)panel
104  stolenContentView:(NSView *)stolenContentView
105  okButton:(NSButton *)okButton
106  cancelButton:(NSButton *)cancelButton
107  priv:(QColorDialogPrivate *)priv
108 {
109  self = [super init];
110 
111  mColorPanel = panel;
112  mStolenContentView = stolenContentView;
113  mOkButton = okButton;
114  mCancelButton = cancelButton;
115  mPriv = priv;
116  mMinWidth = 0.0;
117  mExtraHeight = 0.0;
118  mHackedPanel = (okButton != 0);
119  mResultCode = NSCancelButton;
120  mDialogIsExecuting = false;
121  mResultSet = false;
122 
123 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
125  [mColorPanel setRestorable:NO];
126 #endif
127 
128  if (mHackedPanel) {
129  [self relayout];
130 
131  [okButton setAction:@selector(onOkClicked)];
132  [okButton setTarget:self];
133 
134  [cancelButton setAction:@selector(onCancelClicked)];
135  [cancelButton setTarget:self];
136  }
137 
138  [[NSNotificationCenter defaultCenter] addObserver:self
139  selector:@selector(colorChanged:)
140  name:NSColorPanelColorDidChangeNotification
141  object:mColorPanel];
142 
143  mQtColor = new QColor();
144  return self;
145 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
QColorDialogPrivate * mPriv
static const QMetaObjectPrivate * priv(const uint *data)
static const MacVersion MacintoshVersion
the version of the Macintosh operating system on which the application is run (Mac only)...
Definition: qglobal.h:1646

◆ onCancelClicked()

- (void) onCancelClicked

Definition at line 256 of file qcolordialog_mac.mm.

257 {
258  if (mHackedPanel) {
259  [[mStolenContentView window] close];
260  delete mQtColor;
261  mQtColor = new QColor();
262  [self finishOffWithCode:NSCancelButton];
263  }
264 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67

◆ onOkClicked()

- (void) onOkClicked

Definition at line 248 of file qcolordialog_mac.mm.

249 {
251  [[mStolenContentView window] close];
252  [self updateQtColor];
253  [self finishOffWithCode:NSOKButton];
254 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823

◆ qtColor()

- (QColor) qtColor

Definition at line 307 of file qcolordialog_mac.mm.

308 {
309  return *mQtColor;
310 }

◆ relayout()

- (void) relayout

Definition at line 199 of file qcolordialog_mac.mm.

Referenced by initWithColorPanel:stolenContentView:okButton:cancelButton:priv:.

200 {
202 
203  NSRect rect = [[mStolenContentView superview] frame];
204 
205  // should a priori be kept in sync with qfontdialog_mac.mm
206  const CGFloat ButtonMinWidth = 78.0; // 84.0 for Carbon
207  const CGFloat ButtonMinHeight = 32.0;
208  const CGFloat ButtonSpacing = 0.0;
209  const CGFloat ButtonTopMargin = 0.0;
210  const CGFloat ButtonBottomMargin = 7.0;
211  const CGFloat ButtonSideMargin = 9.0;
212 
213  [mOkButton sizeToFit];
214  NSSize okSizeHint = [mOkButton frame].size;
215 
216  [mCancelButton sizeToFit];
217  NSSize cancelSizeHint = [mCancelButton frame].size;
218 
219  const CGFloat ButtonWidth = qMin(qMax(ButtonMinWidth,
220  qMax(okSizeHint.width, cancelSizeHint.width)),
221  CGFloat((rect.size.width - 2.0 * ButtonSideMargin - ButtonSpacing) * 0.5));
222  const CGFloat ButtonHeight = qMax(ButtonMinHeight,
223  qMax(okSizeHint.height, cancelSizeHint.height));
224 
225  NSRect okRect = { { rect.size.width - ButtonSideMargin - ButtonWidth,
226  ButtonBottomMargin },
227  { ButtonWidth, ButtonHeight } };
228  [mOkButton setFrame:okRect];
229  [mOkButton setNeedsDisplay:YES];
230 
231  NSRect cancelRect = { { okRect.origin.x - ButtonSpacing - ButtonWidth,
232  ButtonBottomMargin },
233  { ButtonWidth, ButtonHeight } };
234  [mCancelButton setFrame:cancelRect];
235  [mCancelButton setNeedsDisplay:YES];
236 
237  const CGFloat Y = ButtonBottomMargin + ButtonHeight + ButtonTopMargin;
238  NSRect stolenCVRect = { { 0.0, Y },
239  { rect.size.width, rect.size.height - Y } };
240  [mStolenContentView setFrame:stolenCVRect];
241  [mStolenContentView setNeedsDisplay:YES];
242 
243  [[mStolenContentView superview] setNeedsDisplay:YES];
244  mMinWidth = 2 * ButtonSideMargin + ButtonSpacing + 2 * ButtonWidth;
245  mExtraHeight = Y;
246 }
const CGFloat ButtonSideMargin
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
const CGFloat ButtonBottomMargin
const CGFloat ButtonSpacing
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
const CGFloat ButtonTopMargin
const CGFloat ButtonMinWidth
const CGFloat ButtonMinHeight
float CGFloat

◆ setResultSet:()

- (void) setResultSet: (BOOL)  result

Definition at line 167 of file qcolordialog_mac.mm.

167  :(BOOL)result
168 {
169  mResultSet = result;
170 }

◆ showColorPanel()

- (void) showColorPanel

Definition at line 338 of file qcolordialog_mac.mm.

339 {
340  mDialogIsExecuting = false;
341  [mColorPanel makeKeyAndOrderFront:mColorPanel];
342 }

◆ updateQtColor()

- (void) updateQtColor

Definition at line 266 of file qcolordialog_mac.mm.

267 {
268  delete mQtColor;
269  mQtColor = new QColor();
270  NSColor *color = [mColorPanel color];
271  NSString *colorSpaceName = [color colorSpaceName];
272  if (colorSpaceName == NSDeviceCMYKColorSpace) {
273  CGFloat cyan = 0, magenta = 0, yellow = 0, black = 0, alpha = 0;
274  [color getCyan:&cyan magenta:&magenta yellow:&yellow black:&black alpha:&alpha];
275  mQtColor->setCmykF(cyan, magenta, yellow, black, alpha);
276  } else if (colorSpaceName == NSCalibratedRGBColorSpace || colorSpaceName == NSDeviceRGBColorSpace) {
277  CGFloat red = 0, green = 0, blue = 0, alpha = 0;
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];
282  CGFloat red = 0, green = 0, blue = 0, alpha = 0;
283  [tmpColor getRed:&red green:&green blue:&blue alpha:&alpha];
284  mQtColor->setRgbF(red, green, blue, alpha);
285  } else {
286  NSColorSpace *colorSpace = [color colorSpace];
287  if ([colorSpace colorSpaceModel] == NSCMYKColorSpaceModel && [color numberOfComponents] == 5){
288  CGFloat components[5];
289  [color getComponents:components];
290  mQtColor->setCmykF(components[0], components[1], components[2], components[3], components[4]);
291  } else {
292  NSColor *tmpColor = [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
293  CGFloat red = 0, green = 0, blue = 0, alpha = 0;
294  [tmpColor getRed:&red green:&green blue:&blue alpha:&alpha];
295  mQtColor->setRgbF(red, green, blue, alpha);
296  }
297  }
298 
300 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
void setRgbF(qreal r, qreal g, qreal b, qreal a=1.0)
Sets the color channels of this color to r (red), g (green), b (blue) and a (alpha, transparency).
Definition: qcolor.cpp:954
QColorDialogPrivate * mPriv
void setCmykF(qreal c, qreal m, qreal y, qreal k, qreal a=1.0)
Sets the color to CMYK values, c (cyan), m (magenta), y (yellow), k (black), and a (alpha-channel...
Definition: qcolor.cpp:2276
void setCurrentQColor(const QColor &color)
float CGFloat

Properties

◆ mCancelButton

- (NSButton*) mCancelButton
protected

Definition at line 74 of file qcolordialog_mac.mm.

◆ mColorPanel

- (NSColorPanel*) mColorPanel
protected

◆ mDialogIsExecuting

- (BOOL) mDialogIsExecuting
protected

Definition at line 81 of file qcolordialog_mac.mm.

◆ mExtraHeight

- (CGFloat) mExtraHeight
protected

Definition at line 78 of file qcolordialog_mac.mm.

◆ mHackedPanel

- (BOOL) mHackedPanel
protected

Definition at line 79 of file qcolordialog_mac.mm.

◆ mMinWidth

- (CGFloat) mMinWidth
protected

Definition at line 77 of file qcolordialog_mac.mm.

◆ mOkButton

- (NSButton*) mOkButton
protected

Definition at line 73 of file qcolordialog_mac.mm.

◆ mPriv

- (QColorDialogPrivate*) mPriv
protected

Definition at line 75 of file qcolordialog_mac.mm.

◆ mQtColor

- (QColor*) mQtColor
protected

Definition at line 76 of file qcolordialog_mac.mm.

◆ mResultCode

- (NSInteger) mResultCode
protected

Definition at line 80 of file qcolordialog_mac.mm.

◆ mResultSet

- (BOOL) mResultSet
protected

Definition at line 82 of file qcolordialog_mac.mm.

◆ mStolenContentView

- (NSView*) mStolenContentView
protected

Definition at line 72 of file qcolordialog_mac.mm.


The documentation for this class was generated from the following file: