Changeset 561 for trunk/src/gui/dialogs/qfontdialog_mac.mm
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/dialogs/qfontdialog_mac.mm
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 48 48 #include <private/qfont_p.h> 49 49 #include <private/qfontengine_p.h> 50 #include <private/qt_cocoa_helpers_mac_p.h> 50 51 #include <private/qt_mac_p.h> 51 52 #include <qdebug.h> … … 78 79 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5 79 80 80 @protocol NSWindowDelegate <NSObject> @end 81 @protocol NSWindowDelegate <NSObject> 82 - (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize; 83 @end 81 84 82 85 #endif … … 88 91 NSButton *mCancelButton; 89 92 QFontDialogPrivate *mPriv; 90 NSFont *mCocoaFont;91 93 QFont *mQtFont; 92 94 BOOL mPanelHackedWithButtons; … … 120 122 @end 121 123 124 static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) 125 { 126 QFont newFont; 127 if (cocoaFont) { 128 int pSize = qRound([cocoaFont pointSize]); 129 QString family(qt_mac_NSStringToQString([cocoaFont familyName])); 130 QString typeface(qt_mac_NSStringToQString([cocoaFont fontName])); 131 132 int hyphenPos = typeface.indexOf(QLatin1Char('-')); 133 if (hyphenPos != -1) { 134 typeface.remove(0, hyphenPos + 1); 135 } else { 136 typeface = QLatin1String("Normal"); 137 } 138 139 newFont = QFontDatabase().font(family, typeface, pSize); 140 newFont.setUnderline(resolveFont.underline()); 141 newFont.setStrikeOut(resolveFont.strikeOut()); 142 143 } 144 return newFont; 145 } 146 122 147 @implementation QCocoaFontPanelDelegate 123 148 - (id)initWithFontPanel:(NSFontPanel *)panel … … 135 160 mCancelButton = cancelButton; 136 161 mPriv = priv; 137 mCocoaFont = 0;138 162 mPanelHackedWithButtons = (okButton != 0); 139 163 mDialogExtraWidth = extraWidth; … … 156 180 - (void)dealloc 157 181 { 158 if (mCocoaFont)159 [mCocoaFont release];160 182 delete mQtFont; 161 183 [super dealloc]; … … 164 186 - (void)changeFont:(id)sender 165 187 { 166 Q_UNUSED(sender);167 168 QFont newFont;169 170 if (mCocoaFont)171 [mCocoaFont autorelease];172 188 NSFont *dummyFont = [NSFont userFontOfSize:12.0]; 173 mCocoaFont = [sender convertFont:dummyFont]; 174 if (mCocoaFont) { 175 [mCocoaFont retain]; 176 177 int pSize = qRound([mCocoaFont pointSize]); 178 QString family(QCFString::toQString(reinterpret_cast<CFStringRef>([mCocoaFont familyName]))); 179 QString typeface(QCFString::toQString(reinterpret_cast<CFStringRef>([mCocoaFont fontName]))); 180 // qDebug() << "original family" << family << "typeface" << typeface << "psize" << pSize; 181 int hyphenPos = typeface.indexOf(QLatin1Char('-')); 182 if (hyphenPos != -1) { 183 typeface.remove(0, hyphenPos + 1); 184 } else { 185 typeface = QLatin1String("Normal"); 186 } 187 // qDebug() << " massaged family" << family << "typeface" << typeface << "psize" << pSize; 188 newFont = QFontDatabase().font(family, typeface, pSize); 189 newFont.setUnderline(mQtFont->underline()); 190 newFont.setStrikeOut(mQtFont->strikeOut()); 191 } 192 193 [self setQtFont:newFont]; 189 [self setQtFont:qfontForCocoaFont([sender convertFont:dummyFont], *mQtFont)]; 194 190 if (mPriv) 195 191 mPriv->updateSampleFont(*mQtFont); … … 318 314 { 319 315 Q_ASSERT(mPanelHackedWithButtons); 316 NSFontManager *fontManager = [NSFontManager sharedFontManager]; 317 [self setQtFont:qfontForCocoaFont([fontManager convertFont:[fontManager selectedFont]], 318 *mQtFont)]; 320 319 [[mStolenContentView window] close]; 321 320 [self finishOffWithCode:NSOKButton]; … … 375 374 } 376 375 377 // temporary hack to work around bug in deleteLater() in Qt/Mac Cocoa378 #if 1379 bool deleteDialog = mPriv->fontDialog()->testAttribute(Qt::WA_DeleteOnClose);380 mPriv->fontDialog()->setAttribute(Qt::WA_DeleteOnClose, false);381 #endif382 376 mPriv->done((code == NSOKButton) ? QDialog::Accepted : QDialog::Rejected); 383 #if 1384 if (deleteDialog)385 delete mPriv->fontDialog();386 #endif387 377 } else { 388 378 [NSApp stopModalWithCode:code]; … … 405 395 [mFontPanel setDelegate:nil]; 406 396 [[NSFontManager sharedFontManager] setDelegate:nil]; 397 #ifdef QT_MAC_USE_COCOA 407 398 [[NSFontManager sharedFontManager] setTarget:nil]; 399 #endif 408 400 } 409 401 @end … … 529 521 [ourPanel setDelegate:delegate]; 530 522 [[NSFontManager sharedFontManager] setDelegate:delegate]; 523 #ifdef QT_MAC_USE_COCOA 531 524 [[NSFontManager sharedFontManager] setTarget:delegate]; 525 #endif 532 526 setFont(delegate, initial); 533 527 … … 580 574 void QFontDialogPrivate::closeCocoaFontPanel(void *delegate) 581 575 { 576 QMacCocoaAutoReleasePool pool; 582 577 QCocoaFontPanelDelegate *theDelegate = static_cast<QCocoaFontPanelDelegate *>(delegate); 583 578 NSWindow *ourPanel = [theDelegate actualPanel]; … … 611 606 } 612 607 613 void QFontDialogPrivate::setFont(void * delegate, const QFont &font) 614 { 608 void QFontDialogPrivate::setFont(void *delegate, const QFont &font) 609 { 610 QMacCocoaAutoReleasePool pool; 615 611 QFontEngine *fe = font.d->engineForScript(QUnicodeTables::Common); 612 NSFontManager *mgr = [NSFontManager sharedFontManager]; 613 NSFont *nsFont = 0; 614 616 615 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 617 616 if (qstrcmp(fe->name(), "CoreText") == 0) { 618 const NSFont *nsFont = reinterpret_cast<const NSFont *>(static_cast<QCoreTextFontEngineMulti *>(fe)->ctfont); 619 [[NSFontManager sharedFontManager] setSelectedFont:nsFont isMultiple:NO]; 620 } 621 #endif 617 nsFont = reinterpret_cast<const NSFont *>(static_cast<QCoreTextFontEngineMulti *>(fe)->ctfont); 618 } else 619 #endif 620 { 621 int weight = 5; 622 NSFontTraitMask mask = 0; 623 if (font.style() == QFont::StyleItalic) { 624 mask |= NSItalicFontMask; 625 } 626 if (font.weight() == QFont::Bold) { 627 weight = 9; 628 mask |= NSBoldFontMask; 629 } 630 631 NSFontManager *mgr = [NSFontManager sharedFontManager]; 632 QFontInfo fontInfo(font); 633 nsFont = [mgr fontWithFamily:qt_mac_QStringToNSString(fontInfo.family()) 634 traits:mask 635 weight:weight 636 size:fontInfo.pointSize()]; 637 } 638 639 [mgr setSelectedFont:nsFont isMultiple:NO]; 622 640 [static_cast<QCocoaFontPanelDelegate *>(delegate) setQtFont:font]; 623 641 }
Note:
See TracChangeset
for help on using the changeset viewer.