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

Public Functions

(NSWindow *) - actualPanel
 
(void) - changeAttributes:
 
(void) - changeFont:
 
(void) - cleanUpAfterMyself
 
(NSSize) - dialogExtraSize
 
(void) - finishOffWithCode:
 
(NSFontPanel *) - fontPanel
 
(id) - initWithFontPanel:stolenContentView:okButton:cancelButton:priv:extraWidth:extraHeight:
 
(BOOL) - isAppModal
 
(void) - onCancelClicked
 
(void) - onOkClicked
 
(QFont- qtFont
 
(void) - relayout
 
(void) - relayoutToContentSize:
 
(void) - runApplicationModalPanel
 
(void) - setQtFont:
 
(void) - setSubwindowStacking
 
(void) - showModelessPanel
 
(void) - showWindowModalSheet:
 
(BOOL) - windowShouldClose:
 
(NSSize) - windowWillResize:toSize:
 

Protected Variables

BOOL mAppModal
 
NSButton * mCancelButton
 
CGFloat mDialogExtraHeight
 
CGFloat mDialogExtraWidth
 
NSFontPanel * mFontPanel
 
NSButton * mOkButton
 
BOOL mPanelHackedWithButtons
 
QFontDialogPrivatemPriv
 
QFontmQtFont
 
int mReturnCode
 
NSView * mStolenContentView
 

Detailed Description

Definition at line 97 of file qfontdialog_mac.mm.

Functions

◆ actualPanel()

- (NSWindow *) actualPanel

Definition at line 410 of file qfontdialog_mac.mm.

411 {
412  return [mStolenContentView window];
413 }

◆ changeAttributes:()

- (void) changeAttributes: (id)  sender

Definition at line 278 of file qfontdialog_mac.mm.

278  :(id)sender
279 {
280  NSDictionary *dummyAttribs = [NSDictionary dictionary];
281  NSDictionary *attribs = [sender convertAttributes:dummyAttribs];
282 
283 #ifdef QT_MAC_USE_COCOA
284  for (id key in attribs) {
285 #else
286  NSEnumerator *enumerator = [attribs keyEnumerator];
287  id key;
288  while((key = [enumerator nextObject])) {
289 #endif
290  NSNumber *number = static_cast<NSNumber *>([attribs objectForKey:key]);
291  if ([key isEqual:NSUnderlineStyleAttributeName]) {
292  mQtFont->setUnderline([number intValue] != NSUnderlineStyleNone);
293  } else if ([key isEqual:NSStrikethroughStyleAttributeName]) {
294  mQtFont->setStrikeOut([number intValue] != NSUnderlineStyleNone);
295  }
296  }
297 
298  if (mPriv)
300 }
void setUnderline(bool)
If enable is true, sets underline on; otherwise sets underline off.
Definition: qfont.cpp:1331
void setStrikeOut(bool)
If enable is true, sets strikeout on; otherwise sets strikeout off.
Definition: qfont.cpp:1378
int key
QFontDialogPrivate * mPriv
void updateSampleFont(const QFont &newFont)

◆ changeFont:()

- (void) changeFont: (id)  sender

Definition at line 270 of file qfontdialog_mac.mm.

270  :(id)sender
271 {
272  NSFont *dummyFont = [NSFont userFontOfSize:12.0];
273  [self setQtFont:qfontForCocoaFont([sender convertFont:dummyFont], *mQtFont)];
274  if (mPriv)
276 }
QFontDialogPrivate * mPriv
void updateSampleFont(const QFont &newFont)

◆ cleanUpAfterMyself()

- (void) cleanUpAfterMyself

Definition at line 468 of file qfontdialog_mac.mm.

469 {
471  NSView *ourContentView = [mFontPanel contentView];
472 
473  // return stolen stuff to its rightful owner
474  [mStolenContentView removeFromSuperview];
475  [mFontPanel setContentView:mStolenContentView];
476 
477  [mOkButton release];
478  [mCancelButton release];
479  [ourContentView release];
480  }
481  [mFontPanel setDelegate:nil];
482  [[NSFontManager sharedFontManager] setDelegate:nil];
483 #ifdef QT_MAC_USE_COCOA
484  [[NSFontManager sharedFontManager] setTarget:nil];
485 #endif
486 }

◆ dialogExtraSize()

- (NSSize) dialogExtraSize

Definition at line 415 of file qfontdialog_mac.mm.

Referenced by windowWillResize:toSize:.

416 {
417  // this must be recomputed each time, because sometimes the
418  // NSFontPanel has the NSDocModalWindowMask flag set, and sometimes
419  // not -- which affects the frame rect vs. content rect measurements
420 
421  // take the different frame rectangles into account for dialogExtra{Width,Height}
422  NSRect someRect = { { 0.0, 0.0 }, { 100000.0, 100000.0 } };
423  NSRect sharedFontPanelContentRect = [mFontPanel contentRectForFrameRect:someRect];
424  NSRect ourPanelContentRect = [NSWindow contentRectForFrameRect:someRect styleMask:StyleMask];
425 
426  NSSize result = { mDialogExtraWidth, mDialogExtraHeight };
427  result.width -= ourPanelContentRect.size.width - sharedFontPanelContentRect.size.width;
428  result.height -= ourPanelContentRect.size.height - sharedFontPanelContentRect.size.height;
429  return result;
430 }

◆ finishOffWithCode:()

- (void) finishOffWithCode: (NSInteger)  result

Definition at line 443 of file qfontdialog_mac.mm.

Referenced by windowShouldClose:.

443  :(NSInteger)code
444 {
445 #ifdef QT_MAC_USE_COCOA
446  QFontDialog *q = mPriv->fontDialog();
447  if (QWidget *parent = q->parentWidget()) {
448  if (parent->isWindow()) {
449  [qt_mac_window_for(parent) removeChildWindow:[mStolenContentView window]];
450  }
451  }
452 #endif
453 
454  if(code == NSOKButton)
455  mPriv->sampleEdit->setFont([self qtFont]);
456 
457  if (mAppModal) {
458  mReturnCode = code;
459  [NSApp stopModalWithCode:code];
460  } else {
461  if (code == NSOKButton)
462  mPriv->fontDialog()->accept();
463  else
464  mPriv->fontDialog()->reject();
465  }
466 }
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
void setFont(const QFont &)
Use the single-argument overload instead.
Definition: qwidget.cpp:4996
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
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
QLineEdit * sampleEdit
The QFontDialog class provides a dialog widget for selecting a font.
Definition: qfontdialog.h:59
QFontDialog * fontDialog()
QFontDialogPrivate * mPriv

◆ fontPanel()

- (NSFontPanel *) fontPanel

Definition at line 405 of file qfontdialog_mac.mm.

406 {
407  return mFontPanel;
408 }

◆ initWithFontPanel:stolenContentView:okButton:cancelButton:priv:extraWidth:extraHeight:()

- (id) initWithFontPanel: (NSFontPanel *)  panel
stolenContentView: (NSView *)  stolenContentView
okButton: (NSButton *)  okButton
cancelButton: (NSButton *)  cancelButton
priv: (QFontDialogPrivate *)  priv
extraWidth: (CGFloat extraWidth
extraHeight: (CGFloat extraHeight 

Definition at line 159 of file qfontdialog_mac.mm.

159  :(NSFontPanel *)panel
160  stolenContentView:(NSView *)stolenContentView
161  okButton:(NSButton *)okButton
162  cancelButton:(NSButton *)cancelButton
163  priv:(QFontDialogPrivate *)priv
164  extraWidth:(CGFloat)extraWidth
165  extraHeight:(CGFloat)extraHeight
166 {
167  self = [super init];
168  mFontPanel = panel;
169  mStolenContentView = stolenContentView;
170  mOkButton = okButton;
171  mCancelButton = cancelButton;
172  mPriv = priv;
173  mPanelHackedWithButtons = (okButton != 0);
174  mDialogExtraWidth = extraWidth;
175  mDialogExtraHeight = extraHeight;
176  mReturnCode = -1;
177  mAppModal = false;
178 
179 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
181  [mFontPanel setRestorable:NO];
182 #endif
183 
185  [self relayout];
186 
187  [okButton setAction:@selector(onOkClicked)];
188  [okButton setTarget:self];
189 
190  [cancelButton setAction:@selector(onCancelClicked)];
191  [cancelButton setTarget:self];
192  }
193 
194  mQtFont = new QFont();
195  return self;
196 }
float CGFloat
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
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
QFontDialogPrivate * mPriv
float CGFloat

◆ isAppModal()

- (BOOL) isAppModal

Definition at line 242 of file qfontdialog_mac.mm.

243 {
244  return mAppModal;
245 }

◆ onCancelClicked()

- (void) onCancelClicked

Definition at line 399 of file qfontdialog_mac.mm.

Referenced by windowShouldClose:.

400 {
402  [self finishOffWithCode:NSCancelButton];
403 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823

◆ onOkClicked()

- (void) onOkClicked

Definition at line 390 of file qfontdialog_mac.mm.

391 {
393  NSFontManager *fontManager = [NSFontManager sharedFontManager];
394  [self setQtFont:qfontForCocoaFont([fontManager convertFont:[fontManager selectedFont]],
395  *mQtFont)];
396  [self finishOffWithCode:NSOKButton];
397 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823

◆ qtFont()

- (QFont) qtFont

Definition at line 438 of file qfontdialog_mac.mm.

439 {
440  return *mQtFont;
441 }

◆ relayout()

- (void) relayout

Definition at line 346 of file qfontdialog_mac.mm.

Referenced by initWithFontPanel:stolenContentView:okButton:cancelButton:priv:extraWidth:extraHeight:.

347 {
348  [self relayoutToContentSize:[[mStolenContentView superview] frame].size];
349 }

◆ relayoutToContentSize:()

- (void) relayoutToContentSize: (NSSize)  frameSize

Definition at line 351 of file qfontdialog_mac.mm.

Referenced by windowWillResize:toSize:.

351  :(NSSize)frameSize
352 {
354 
355  [mOkButton sizeToFit];
356  NSSize okSizeHint = [mOkButton frame].size;
357 
358  [mCancelButton sizeToFit];
359  NSSize cancelSizeHint = [mCancelButton frame].size;
360 
361  const CGFloat ButtonWidth = qMin(qMax(ButtonMinWidth,
362  qMax(okSizeHint.width, cancelSizeHint.width)),
363  CGFloat((frameSize.width - 2.0 * ButtonSideMargin - ButtonSpacing) * 0.5));
364  const CGFloat ButtonHeight = qMax(ButtonMinHeight,
365  qMax(okSizeHint.height, cancelSizeHint.height));
366 
367  const CGFloat X = DialogSideMargin;
368  const CGFloat Y = ButtonBottomMargin + ButtonHeight + ButtonTopMargin;
369 
370  NSRect okRect = { { frameSize.width - ButtonSideMargin - ButtonWidth,
372  { ButtonWidth, ButtonHeight } };
373  [mOkButton setFrame:okRect];
374  [mOkButton setNeedsDisplay:YES];
375 
376  NSRect cancelRect = { { okRect.origin.x - ButtonSpacing - ButtonWidth,
378  { ButtonWidth, ButtonHeight } };
379  [mCancelButton setFrame:cancelRect];
380  [mCancelButton setNeedsDisplay:YES];
381 
382  NSRect stolenCVRect = { { X, Y },
383  { frameSize.width - X - X, frameSize.height - Y - DialogTopMargin } };
384  [mStolenContentView setFrame:stolenCVRect];
385  [mStolenContentView setNeedsDisplay:YES];
386 
387  [[mStolenContentView superview] setNeedsDisplay:YES];
388 }
const CGFloat ButtonSideMargin
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
const CGFloat DialogTopMargin
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 DialogSideMargin
const CGFloat ButtonTopMargin
const CGFloat ButtonMinWidth
const CGFloat ButtonMinHeight
float CGFloat

◆ runApplicationModalPanel()

- (void) runApplicationModalPanel

Definition at line 227 of file qfontdialog_mac.mm.

228 {
230  mAppModal = true;
231  NSWindow *ourPanel = [mStolenContentView window];
232  [ourPanel setReleasedWhenClosed:NO];
233  [NSApp runModalForWindow:ourPanel];
235 
236  if (mReturnCode == NSOKButton)
237  mPriv->fontDialog()->accept();
238  else
239  mPriv->fontDialog()->reject();
240 }
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
QFontDialog * fontDialog()
static bool native_modal_dialog_active
QFontDialogPrivate * mPriv

◆ setQtFont:()

- (void) setQtFont: (const QFont &)  newFont

Definition at line 432 of file qfontdialog_mac.mm.

432  :(const QFont &)newFont
433 {
434  delete mQtFont;
435  mQtFont = new QFont(newFont);
436 }
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64

◆ setSubwindowStacking()

- (void) setSubwindowStacking

Definition at line 198 of file qfontdialog_mac.mm.

199 {
200 #ifdef QT_MAC_USE_COCOA
201  // Stack the native dialog in front of its parent, if any:
202  QFontDialog *q = mPriv->fontDialog();
203  if (!qt_mac_is_macsheet(q)) {
204  if (QWidget *parent = q->parentWidget()) {
205  if (parent->isWindow()) {
206  [qt_mac_window_for(parent)
207  addChildWindow:[mStolenContentView window] ordered:NSWindowAbove];
208  }
209  }
210  }
211 #endif
212 }
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
bool qt_mac_is_macsheet(const QWidget *w)
Definition: qwidget_mac.mm:295
The QFontDialog class provides a dialog widget for selecting a font.
Definition: qfontdialog.h:59
QFontDialog * fontDialog()
QFontDialogPrivate * mPriv

◆ showModelessPanel()

- (void) showModelessPanel

Definition at line 220 of file qfontdialog_mac.mm.

221 {
222  mAppModal = false;
223  NSWindow *ourPanel = [mStolenContentView window];
224  [ourPanel makeKeyAndOrderFront:self];
225 }

◆ showWindowModalSheet:()

- (void) showWindowModalSheet: (QWidget *)  docWidget

Definition at line 247 of file qfontdialog_mac.mm.

247  :(QWidget *)docWidget
248 {
249 #ifdef QT_MAC_USE_COCOA
250  NSWindow *window = qt_mac_window_for(docWidget);
251 #else
252  WindowRef hiwindowRef = qt_mac_window_for(docWidget);
253  NSWindow *window = [[NSWindow alloc] initWithWindowRef:hiwindowRef];
254  CFRetain(hiwindowRef);
255 #endif
256 
257  mAppModal = false;
258  NSWindow *ourPanel = [mStolenContentView window];
259  [NSApp beginSheet:ourPanel
260  modalForWindow:window
261  modalDelegate:0
262  didEndSelector:0
263  contextInfo:0 ];
264 
265 #ifndef QT_MAC_USE_COCOA
266  CFRelease(hiwindowRef);
267 #endif
268 }
struct OpaqueWindowPtr * WindowRef
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
OSWindowRef qt_mac_window_for(const QWidget *)
Definition: qwidget_mac.mm:484
NSWindow * window

◆ windowShouldClose:()

- (BOOL) windowShouldClose: (id)  window

Definition at line 302 of file qfontdialog_mac.mm.

302  :(id)window
303 {
304  Q_UNUSED(window);
306  [self onCancelClicked];
307  } else {
308  [self finishOffWithCode:NSCancelButton];
309  }
310  return true;
311 }
NSWindow * window
#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

◆ windowWillResize:toSize:()

- (NSSize) windowWillResize: (NSWindow *)  window
toSize: (NSSize)  proposedFrameSize 

Definition at line 313 of file qfontdialog_mac.mm.

313  :(NSWindow *)window toSize:(NSSize)proposedFrameSize
314 {
315  if (mFontPanel == window) {
316  proposedFrameSize = [static_cast<id <NSWindowDelegate> >(mFontPanel) windowWillResize:mFontPanel toSize:proposedFrameSize];
317  } else {
318  /*
319  Ugly hack: NSFontPanel rearranges the layout of its main
320  component in windowWillResize:toSize:. So we temporarily
321  restore the stolen content view to its rightful owner,
322  call windowWillResize:toSize:, and steal the content view
323  again.
324  */
325  [mStolenContentView removeFromSuperview];
326  [mFontPanel setContentView:mStolenContentView];
327  NSSize extraSize = [self dialogExtraSize];
328  proposedFrameSize.width -= extraSize.width;
329  proposedFrameSize.height -= extraSize.height;
330  proposedFrameSize = [static_cast<id <NSWindowDelegate> >(mFontPanel) windowWillResize:mFontPanel toSize:proposedFrameSize];
331  NSRect frameRect = { { 0.0, 0.0 }, proposedFrameSize };
332  [mFontPanel setFrame:frameRect display:NO];
333  [mFontPanel setContentView:0];
334  [[window contentView] addSubview:mStolenContentView];
335  proposedFrameSize.width += extraSize.width;
336  proposedFrameSize.height += extraSize.height;
337  }
339  NSRect frameRect = { { 0.0, 0.0 }, proposedFrameSize };
340  NSRect contentRect = [NSWindow contentRectForFrameRect:frameRect styleMask:[window styleMask]];
341  [self relayoutToContentSize:contentRect.size];
342  }
343  return proposedFrameSize;
344 }
NSWindow * window

Properties

◆ mAppModal

- (BOOL) mAppModal
protected

Definition at line 108 of file qfontdialog_mac.mm.

◆ mCancelButton

- (NSButton*) mCancelButton
protected

Definition at line 101 of file qfontdialog_mac.mm.

◆ mDialogExtraHeight

- (CGFloat) mDialogExtraHeight
protected

Definition at line 106 of file qfontdialog_mac.mm.

◆ mDialogExtraWidth

- (CGFloat) mDialogExtraWidth
protected

Definition at line 105 of file qfontdialog_mac.mm.

◆ mFontPanel

- (NSFontPanel*) mFontPanel
protected

◆ mOkButton

- (NSButton*) mOkButton
protected

Definition at line 100 of file qfontdialog_mac.mm.

◆ mPanelHackedWithButtons

- (BOOL) mPanelHackedWithButtons
protected

Definition at line 104 of file qfontdialog_mac.mm.

◆ mPriv

- (QFontDialogPrivate*) mPriv
protected

Definition at line 102 of file qfontdialog_mac.mm.

◆ mQtFont

- (QFont*) mQtFont
protected

Definition at line 103 of file qfontdialog_mac.mm.

◆ mReturnCode

- (int) mReturnCode
protected

Definition at line 107 of file qfontdialog_mac.mm.

◆ mStolenContentView

- (NSView*) mStolenContentView
protected

Definition at line 99 of file qfontdialog_mac.mm.

Referenced by actualPanel, and windowWillResize:toSize:.


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