1 /**************************************************************************** |
1 /**************************************************************************** |
2 ** |
2 ** |
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
4 ** All rights reserved. |
4 ** All rights reserved. |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
6 ** |
6 ** |
7 ** This file is part of the QtGui module of the Qt Toolkit. |
7 ** This file is part of the QtGui module of the Qt Toolkit. |
8 ** |
8 ** |
987 \reimp |
987 \reimp |
988 */ |
988 */ |
989 void QFontDialog::setVisible(bool visible) |
989 void QFontDialog::setVisible(bool visible) |
990 { |
990 { |
991 Q_D(QFontDialog); |
991 Q_D(QFontDialog); |
992 if (visible) |
992 if (visible) { |
993 d->selectedFont = QFont(); |
993 if (testAttribute(Qt::WA_WState_ExplicitShowHide) && !testAttribute(Qt::WA_WState_Hidden)) |
994 |
994 return; |
995 #if defined(Q_WS_MAC) |
995 } else if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden)) |
996 bool isCurrentlyVisible = (isVisible() || d->delegate); |
|
997 |
|
998 if (!visible == !isCurrentlyVisible) |
|
999 return; |
996 return; |
1000 |
997 #ifdef Q_WS_MAC |
1001 if (visible) { |
998 if (d->canBeNativeDialog()){ |
1002 if (!(d->opts & DontUseNativeDialog) && QFontDialogPrivate::sharedFontPanelAvailable) { |
999 if (d->setVisible_sys(visible)){ |
1003 d->delegate = QFontDialogPrivate::openCocoaFontPanel( |
1000 d->nativeDialogInUse = true; |
1004 currentFont(), parentWidget(), windowTitle(), options(), d); |
1001 // Set WA_DontShowOnScreen so that QDialog::setVisible(visible) below |
1005 QFontDialogPrivate::sharedFontPanelAvailable = false; |
1002 // updates the state correctly, but skips showing the non-native version: |
1006 return; |
1003 setAttribute(Qt::WA_DontShowOnScreen, true); |
|
1004 } else { |
|
1005 d->nativeDialogInUse = false; |
|
1006 setAttribute(Qt::WA_DontShowOnScreen, false); |
1007 } |
1007 } |
1008 |
1008 } |
1009 setWindowFlags(windowModality() == Qt::WindowModal ? Qt::Sheet : DefaultWindowFlags); |
1009 #endif // Q_WS_MAC |
1010 } else { |
|
1011 if (d->delegate) { |
|
1012 QFontDialogPrivate::closeCocoaFontPanel(d->delegate); |
|
1013 d->delegate = 0; |
|
1014 QFontDialogPrivate::sharedFontPanelAvailable = true; |
|
1015 return; |
|
1016 } |
|
1017 } |
|
1018 #endif |
|
1019 |
|
1020 QDialog::setVisible(visible); |
1010 QDialog::setVisible(visible); |
1021 } |
1011 } |
1022 |
1012 |
1023 /*! |
1013 /*! |
1024 Closes the dialog and sets its result code to \a result. If this dialog |
1014 Closes the dialog and sets its result code to \a result. If this dialog |
1030 void QFontDialog::done(int result) |
1020 void QFontDialog::done(int result) |
1031 { |
1021 { |
1032 Q_D(QFontDialog); |
1022 Q_D(QFontDialog); |
1033 QDialog::done(result); |
1023 QDialog::done(result); |
1034 if (result == Accepted) { |
1024 if (result == Accepted) { |
1035 d->selectedFont = currentFont(); |
1025 // We check if this is the same font we had before, if so we emit currentFontChanged |
|
1026 QFont selectedFont = currentFont(); |
|
1027 if(selectedFont != d->selectedFont) |
|
1028 emit(currentFontChanged(selectedFont)); |
|
1029 d->selectedFont = selectedFont; |
1036 emit fontSelected(d->selectedFont); |
1030 emit fontSelected(d->selectedFont); |
1037 } else { |
1031 } else |
1038 d->selectedFont = QFont(); |
1032 d->selectedFont = QFont(); |
1039 } |
|
1040 if (d->receiverToDisconnectOnClose) { |
1033 if (d->receiverToDisconnectOnClose) { |
1041 disconnect(this, SIGNAL(fontSelected(QFont)), |
1034 disconnect(this, SIGNAL(fontSelected(QFont)), |
1042 d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose); |
1035 d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose); |
1043 d->receiverToDisconnectOnClose = 0; |
1036 d->receiverToDisconnectOnClose = 0; |
1044 } |
1037 } |
1045 d->memberToDisconnectOnClose.clear(); |
1038 d->memberToDisconnectOnClose.clear(); |
1046 } |
1039 } |
1047 |
1040 |
|
1041 #ifdef Q_WS_MAC |
|
1042 bool QFontDialogPrivate::canBeNativeDialog() |
|
1043 { |
|
1044 Q_Q(QFontDialog); |
|
1045 if (nativeDialogInUse) |
|
1046 return true; |
|
1047 if (q->testAttribute(Qt::WA_DontShowOnScreen)) |
|
1048 return false; |
|
1049 if (opts & QFontDialog::DontUseNativeDialog) |
|
1050 return false; |
|
1051 |
|
1052 QLatin1String staticName(QFontDialog::staticMetaObject.className()); |
|
1053 QLatin1String dynamicName(q->metaObject()->className()); |
|
1054 return (staticName == dynamicName); |
|
1055 } |
|
1056 #endif // Q_WS_MAC |
|
1057 |
1048 /*! |
1058 /*! |
1049 \fn QFont QFontDialog::getFont(bool *ok, const QFont &initial, QWidget* parent, const char* name) |
1059 \fn QFont QFontDialog::getFont(bool *ok, const QFont &initial, QWidget* parent, const char* name) |
1050 \since 4.5 |
1060 \since 4.5 |
1051 |
1061 |
1052 Call getFont(\a ok, \a initial, \a parent) instead. |
1062 Call getFont(\a ok, \a initial, \a parent) instead. |