Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/dialogs/qfontdialog_mac.mm

    r2 r561  
    22**
    33** 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)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    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.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** 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.
    3838** $QT_END_LICENSE$
    3939**
     
    4848#include <private/qfont_p.h>
    4949#include <private/qfontengine_p.h>
     50#include <private/qt_cocoa_helpers_mac_p.h>
    5051#include <private/qt_mac_p.h>
    5152#include <qdebug.h>
     
    7879#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5
    7980
    80 @protocol NSWindowDelegate <NSObject> @end
     81@protocol NSWindowDelegate <NSObject>
     82- (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize;
     83@end
    8184
    8285#endif
     
    8891    NSButton *mCancelButton;
    8992    QFontDialogPrivate *mPriv;
    90     NSFont *mCocoaFont;
    9193    QFont *mQtFont;
    9294    BOOL mPanelHackedWithButtons;
     
    120122@end
    121123
     124static 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
    122147@implementation QCocoaFontPanelDelegate
    123148- (id)initWithFontPanel:(NSFontPanel *)panel
     
    135160    mCancelButton = cancelButton;
    136161    mPriv = priv;
    137     mCocoaFont = 0;
    138162    mPanelHackedWithButtons = (okButton != 0);
    139163    mDialogExtraWidth = extraWidth;
     
    156180- (void)dealloc
    157181{
    158     if (mCocoaFont)
    159         [mCocoaFont release];
    160182    delete mQtFont;
    161183    [super dealloc];
     
    164186- (void)changeFont:(id)sender
    165187{
    166     Q_UNUSED(sender);
    167 
    168     QFont newFont;
    169 
    170     if (mCocoaFont)
    171         [mCocoaFont autorelease];
    172188    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)];
    194190    if (mPriv)
    195191        mPriv->updateSampleFont(*mQtFont);
     
    318314{
    319315    Q_ASSERT(mPanelHackedWithButtons);
     316    NSFontManager *fontManager = [NSFontManager sharedFontManager];
     317    [self setQtFont:qfontForCocoaFont([fontManager convertFont:[fontManager selectedFont]],
     318                                      *mQtFont)];
    320319    [[mStolenContentView window] close];
    321320    [self finishOffWithCode:NSOKButton];
     
    375374        }
    376375
    377         // temporary hack to work around bug in deleteLater() in Qt/Mac Cocoa
    378 #if 1
    379         bool deleteDialog = mPriv->fontDialog()->testAttribute(Qt::WA_DeleteOnClose);
    380         mPriv->fontDialog()->setAttribute(Qt::WA_DeleteOnClose, false);
    381 #endif
    382376        mPriv->done((code == NSOKButton) ? QDialog::Accepted : QDialog::Rejected);
    383 #if 1
    384         if (deleteDialog)
    385             delete mPriv->fontDialog();
    386 #endif
    387377    } else {
    388378        [NSApp stopModalWithCode:code];
     
    405395    [mFontPanel setDelegate:nil];
    406396    [[NSFontManager sharedFontManager] setDelegate:nil];
     397#ifdef QT_MAC_USE_COCOA
    407398    [[NSFontManager sharedFontManager] setTarget:nil];
     399#endif
    408400}
    409401@end
     
    529521    [ourPanel setDelegate:delegate];
    530522    [[NSFontManager sharedFontManager] setDelegate:delegate];
     523#ifdef QT_MAC_USE_COCOA
    531524    [[NSFontManager sharedFontManager] setTarget:delegate];
     525#endif
    532526    setFont(delegate, initial);
    533527
     
    580574void QFontDialogPrivate::closeCocoaFontPanel(void *delegate)
    581575{
     576    QMacCocoaAutoReleasePool pool;
    582577    QCocoaFontPanelDelegate *theDelegate = static_cast<QCocoaFontPanelDelegate *>(delegate);
    583578    NSWindow *ourPanel = [theDelegate actualPanel];
     
    611606}
    612607
    613 void QFontDialogPrivate::setFont(void * delegate, const QFont &font)
    614 {
     608void QFontDialogPrivate::setFont(void *delegate, const QFont &font)
     609{
     610    QMacCocoaAutoReleasePool pool;
    615611    QFontEngine *fe = font.d->engineForScript(QUnicodeTables::Common);
     612    NSFontManager *mgr = [NSFontManager sharedFontManager];
     613    NSFont *nsFont = 0;
     614
    616615#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
    617616    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];
    622640    [static_cast<QCocoaFontPanelDelegate *>(delegate) setQtFont:font];
    623641}
Note: See TracChangeset for help on using the changeset viewer.