(cherry picked from commit 050925ccac957dea3d4e138babdd7aa93925dffc)
This commit is contained in:
Jørgen Lind 2011-04-27 17:29:10 +02:00 committed by Samuel Rødal
parent 9b8759284b
commit 9f14dc661e
5 changed files with 39 additions and 5 deletions

View File

@ -457,8 +457,10 @@ QGraphicsSystem *QApplicationPrivate::graphics_system = 0; // default graphics s
QString QApplicationPrivate::graphics_system_name; // graphics system id - for delayed initialization
bool QApplicationPrivate::runtime_graphics_system = false;
#ifndef Q_WS_QPA
Q_GLOBAL_STATIC(QMutex, applicationFontMutex)
QFont *QApplicationPrivate::app_font = 0; // default application font
#endif
QFont *QApplicationPrivate::sys_font = 0; // default system font
QFont *QApplicationPrivate::set_font = 0; // default font set by programmer
@ -1146,11 +1148,14 @@ QApplication::~QApplication()
QApplicationPrivate::set_pal = 0;
app_palettes()->clear();
#ifndef Q_WS_QPA
{
QMutexLocker locker(applicationFontMutex());
delete QApplicationPrivate::app_font;
QApplicationPrivate::app_font = 0;
}
#endif
delete QApplicationPrivate::sys_font;
QApplicationPrivate::sys_font = 0;
delete QApplicationPrivate::set_font;
@ -1940,10 +1945,14 @@ void QApplicationPrivate::setSystemPalette(const QPalette &pal)
*/
QFont QApplication::font()
{
#ifndef Q_WS_QPA
QMutexLocker locker(applicationFontMutex());
if (!QApplicationPrivate::app_font)
QApplicationPrivate::app_font = new QFont(QLatin1String("Helvetica"));
return *QApplicationPrivate::app_font;
#else
return QGuiApplication::font();
#endif
}
/*!
@ -2022,11 +2031,15 @@ void QApplication::setFont(const QFont &font, const char *className)
bool all = false;
FontHash *hash = app_fonts();
if (!className) {
#ifndef Q_WS_QPA
QMutexLocker locker(applicationFontMutex());
if (!QApplicationPrivate::app_font)
QApplicationPrivate::app_font = new QFont(font);
else
*QApplicationPrivate::app_font = font;
#else
QGuiApplication::setFont(font);
#endif
if (hash && hash->size()) {
all = true;
hash->clear();

View File

@ -432,7 +432,9 @@ public:
static bool runtime_graphics_system;
private:
#ifndef Q_WS_QPA
static QFont *app_font; // private for a reason! Always use QApplication::font() instead!
#endif
public:
static QFont *sys_font;
static QFont *set_font;

View File

@ -47,6 +47,7 @@
#include <QtCore/private/qcoreapplication_p.h>
#include <QtCore/private/qabstracteventdispatcher_p.h>
#include <QtCore/qmutex.h>
#include <QtDebug>
#include <QtGui/QPlatformIntegration>
@ -92,6 +93,9 @@ QGuiApplicationPrivate *QGuiApplicationPrivate::self = 0;
QClipboard *QGuiApplicationPrivate::qt_clipboard = 0;
#endif
Q_GLOBAL_STATIC(QMutex, applicationFontMutex)
QFont *QGuiApplicationPrivate::app_font = 0;
QGuiApplication::QGuiApplication(int &argc, char **argv, int flags)
: QCoreApplication(*new QGuiApplicationPrivate(argc, argv, flags))
{
@ -738,5 +742,21 @@ QClipboard * QGuiApplication::clipboard()
}
#endif
QFont QGuiApplication::font()
{
QMutexLocker locker(applicationFontMutex());
if (!QGuiApplicationPrivate::app_font)
QGuiApplicationPrivate::app_font = new QFont(QLatin1String("Helvetica"));
return *QGuiApplicationPrivate::app_font;
}
void QGuiApplication::setFont(const QFont &font)
{
QMutexLocker locker(applicationFontMutex());
if (!QGuiApplicationPrivate::app_font)
QGuiApplicationPrivate::app_font = new QFont(font);
else
*QGuiApplicationPrivate::app_font = font;
}
QT_END_NAMESPACE

View File

@ -72,14 +72,11 @@ public:
static void setOverrideCursor(const QCursor &);
static void changeOverrideCursor(const QCursor &);
static void restoreOverrideCursor();
#endif
#endif
static QFont font();
static QFont font(const QWidget*);
static QFont font(const char *className);
static void setFont(const QFont &, const char* className = 0);
static QFontMetrics fontMetrics();
#endif
static void setFont(const QFont &);
#ifndef QT_NO_CLIPBOARD
static QClipboard *clipboard();

View File

@ -117,6 +117,8 @@ public:
#ifndef QT_NO_CLIPBOARD
static QClipboard *qt_clipboard;
#endif
static QFont *app_font;
private:
void init();