remove fonts from Plasma::Thmeme

replace FontProxy with default QFont QML2 bindings
This commit is contained in:
Marco Martin 2013-03-11 16:59:39 +01:00
parent f07387267a
commit 74d1a62bdd
4 changed files with 22 additions and 322 deletions

View File

@ -21,133 +21,10 @@
#include <QQmlPropertyMap>
#include <KGlobalSettings>
#include <KIconLoader>
#include <QApplication>
class FontProxySingleton
{
public:
FontProxySingleton()
: defaultFont(Plasma::Theme::DefaultFont),
desktopFont(Plasma::Theme::DesktopFont),
smallestFont(Plasma::Theme::SmallestFont)
{
}
FontProxy defaultFont;
FontProxy desktopFont;
FontProxy smallestFont;
};
Q_GLOBAL_STATIC(FontProxySingleton, privateFontProxySingleton)
FontProxy::FontProxy(Plasma::Theme::FontRole role, QObject *parent)
: QObject(parent),
m_fontRole(role)
{
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
this, SIGNAL(boldChanged()));
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
this, SIGNAL(capitalizationChanged()));
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
this, SIGNAL(familyChanged()));
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
this, SIGNAL(italicChanged()));
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
this, SIGNAL(letterSpacingChanged()));
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
this, SIGNAL(pixelSizeChanged()));
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
this, SIGNAL(pointSizeChanged()));
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
this, SIGNAL(strikeoutChanged()));
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
this, SIGNAL(underlineChanged()));
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
this, SIGNAL(weightChanged()));
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
this, SIGNAL(wordSpacingChanged()));
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
this, SIGNAL(mSizeChanged()));
}
FontProxy::~FontProxy()
{
}
FontProxy *FontProxy::defaultFont()
{
return &privateFontProxySingleton()->defaultFont;
}
FontProxy *FontProxy::desktopFont()
{
return &privateFontProxySingleton()->desktopFont;
}
FontProxy *FontProxy::smallestFont()
{
return &privateFontProxySingleton()->smallestFont;
}
bool FontProxy::bold() const
{
return Plasma::Theme::defaultTheme()->font(m_fontRole).bold();
}
FontProxy::Capitalization FontProxy::capitalization() const
{
return (FontProxy::Capitalization)Plasma::Theme::defaultTheme()->font(m_fontRole).capitalization();
}
QString FontProxy::family() const
{
return Plasma::Theme::defaultTheme()->font(m_fontRole).family();
}
bool FontProxy::italic() const
{
return Plasma::Theme::defaultTheme()->font(m_fontRole).italic();
}
qreal FontProxy::letterSpacing() const
{
return Plasma::Theme::defaultTheme()->font(m_fontRole).letterSpacing();
}
int FontProxy::pixelSize() const
{
return Plasma::Theme::defaultTheme()->font(m_fontRole).pixelSize();
}
qreal FontProxy::pointSize() const
{
return Plasma::Theme::defaultTheme()->font(m_fontRole).pointSizeF();
}
bool FontProxy::strikeout() const
{
return Plasma::Theme::defaultTheme()->font(m_fontRole).strikeOut();
}
bool FontProxy::underline() const
{
return Plasma::Theme::defaultTheme()->font(m_fontRole).underline();
}
FontProxy::Weight FontProxy::weight() const
{
return (FontProxy::Weight)Plasma::Theme::defaultTheme()->font(m_fontRole).weight();
}
qreal FontProxy::wordSpacing() const
{
return Plasma::Theme::defaultTheme()->font(m_fontRole).wordSpacing();
}
QSize FontProxy::mSize() const
{
return QFontMetrics(Plasma::Theme::defaultTheme()->font(m_fontRole)).boundingRect("M").size();
}
//********** Theme *************
@ -177,21 +54,22 @@ QString ThemeProxy::themeName() const
return Plasma::Theme::defaultTheme()->themeName();
}
QObject *ThemeProxy::defaultFont() const
QFont ThemeProxy::defaultFont() const
{
return FontProxy::defaultFont();
return QApplication::font();
}
QObject *ThemeProxy::desktopFont() const
QFont ThemeProxy::smallestFont() const
{
return FontProxy::desktopFont();
return KGlobalSettings::smallestReadableFont();
}
QObject *ThemeProxy::smallestFont() const
QSizeF ThemeProxy::mSize(const QFont &font) const
{
return FontProxy::smallestFont();
return QFontMetrics(font).boundingRect("M").size();
}
bool ThemeProxy::windowTranslucencyEnabled() const
{
return Plasma::Theme::defaultTheme()->windowTranslucencyEnabled();
@ -341,5 +219,5 @@ QQmlPropertyMap *ThemeProxy::iconSizes() const
return m_iconSizes;
}
#include "theme.moc"
#include "moc_theme.cpp"

View File

@ -19,6 +19,7 @@
#ifndef THEME_PROXY_P
#define THEME_PROXY_P
#include <QApplication>
#include <QObject>
#include <KUrl>
@ -29,142 +30,6 @@
class QQmlPropertyMap;
class FontProxy : public QObject
{
Q_OBJECT
/**
* true if the font is bold
*/
Q_PROPERTY(bool bold READ bold NOTIFY boldChanged)
/**
* One of
* MixedCase: The text is not changed
* AllUppercase: the text becomes UPPERCASE
* AllLowercase: the text becomes all lowercase
* SmallCaps: the lowercase characters becomes smaller uppercase ones
* Capitalize: the first letter of all words are uppercase
*/
Q_PROPERTY(Capitalization capitalization READ capitalization NOTIFY capitalizationChanged )
/**
* name of the font family
*/
Q_PROPERTY(QString family READ family NOTIFY familyChanged )
/**
* true if the font is italic
*/
Q_PROPERTY(bool italic READ italic NOTIFY italicChanged )
/**
* horizontal space between letters
*/
Q_PROPERTY(qreal letterSpacing READ letterSpacing NOTIFY letterSpacingChanged )
/**
* Size of the font in pixels: settings this is strongly discouraged.
* @see pointSize
*/
Q_PROPERTY(int pixelSize READ pixelSize NOTIFY pixelSizeChanged )
/**
* Size of the font in points
*/
Q_PROPERTY(qreal pointSize READ pointSize NOTIFY pointSizeChanged )
/**
* True if the text is striked out with an horizontal line
*/
Q_PROPERTY(bool strikeout READ strikeout NOTIFY strikeoutChanged )
/**
* True if all the text will be underlined
*/
Q_PROPERTY(bool underline READ underline NOTIFY underlineChanged )
/**
* One of:
* Light
* Normal
* DemiBold
* Bold
* Black
*/
Q_PROPERTY(Weight weight READ weight NOTIFY weightChanged )
/**
* Horizontal space between words
*/
Q_PROPERTY(qreal wordSpacing READ wordSpacing NOTIFY wordSpacingChanged )
/**
* Size in pixels of an uppercase "M" letter
*/
Q_PROPERTY(QSize mSize READ mSize NOTIFY mSizeChanged )
Q_ENUMS(Capitalization)
Q_ENUMS(Weight)
public:
enum Capitalization {
MixedCase = 0,
AllUppercase = 1,
AllLowercase = 2,
SmallCaps = 3,
Capitalize = 4
};
enum Weight {
Light = 25,
Normal = 50,
DemiBold = 63,
Bold = 75,
Black = 87
};
FontProxy(Plasma::Theme::FontRole role, QObject *parent = 0);
~FontProxy();
static FontProxy *defaultFont();
static FontProxy *desktopFont();
static FontProxy *smallestFont();
bool bold() const;
Capitalization capitalization() const;
QString family() const;
bool italic() const;
qreal letterSpacing() const;
int pixelSize() const;
qreal pointSize() const;
bool strikeout() const;
bool underline() const;
Weight weight() const;
qreal wordSpacing() const;
/**
* @return The size of an uppercase M in this font
*/
QSize mSize() const;
Q_SIGNALS:
void boldChanged();
void capitalizationChanged();
void familyChanged();
void italicChanged();
void letterSpacingChanged();
void pixelSizeChanged();
void pointSizeChanged();
void strikeoutChanged();
void underlineChanged();
void weightChanged();
void wordSpacingChanged();
void mSizeChanged();
private:
Plasma::Theme::FontRole m_fontRole;
};
/**
* QML wrapper for kdelibs Plasma::Theme
*
@ -181,9 +46,8 @@ class ThemeProxy : public QObject
Q_PROPERTY(QString wallpaperPath READ wallpaperPath NOTIFY themeChanged)
//fonts
Q_PROPERTY(QObject *defaultFont READ defaultFont CONSTANT)
Q_PROPERTY(QObject *desktopFont READ desktopFont CONSTANT)
Q_PROPERTY(QObject *smallestFont READ smallestFont CONSTANT)
Q_PROPERTY(QFont defaultFont READ defaultFont CONSTANT)
Q_PROPERTY(QFont smallestFont READ smallestFont CONSTANT)
// colors
Q_PROPERTY(QColor textColor READ textColor NOTIFY themeChanged)
@ -227,9 +91,13 @@ public:
~ThemeProxy();
QString themeName() const;
QObject *defaultFont() const;
QObject *desktopFont() const;
QObject *smallestFont() const;
QFont defaultFont() const;
QFont smallestFont() const;
/**
* @return The size of an uppercase M in a font, defaultFont() by default
*/
QSizeF mSize(const QFont &font = QApplication::font()) const;
bool windowTranslucencyEnabled() const;
KUrl homepage() const;
bool useGlobalSettings() const;

View File

@ -96,7 +96,6 @@ public:
hasWallpapers(false),
useNativeWidgetStyle(false)
{
generalFont = QApplication::font();
ThemeConfig config;
cacheTheme = config.cacheTheme();
@ -181,7 +180,6 @@ public:
KColorScheme buttonColorScheme;
KColorScheme viewColorScheme;
KConfigGroup cfg;
QFont generalFont;
QString defaultWallpaperTheme;
QString defaultWallpaperSuffix;
int defaultWallpaperWidth;
@ -378,7 +376,7 @@ const QString ThemePrivate::processStyleSheet(const QString &css)
stylesheet = QString("\n\
body {\n\
color: %textcolor;\n\
font-size: %fontsize;\n\
generalfont-size: %fontsize;\n\
font-family: %fontfamily;\n\
}\n\
a:active { color: %activatedlink; }\n\
@ -436,7 +434,7 @@ const QString ThemePrivate::processStyleSheet(const QString &css)
elements["%viewhovercolor"] = q->color(Theme::ViewHoverColor).name();
elements["%viewfocuscolor"] = q->color(Theme::ViewFocusColor).name();
QFont font = q->font(Theme::DefaultFont);
QFont font = QApplication::font();
elements["%fontsize"] = QString("%1pt").arg(font.pointSize());
elements["%fontfamily"] = font.family().split('[').first();
elements["%smallfontsize"] = QString("%1pt").arg(KGlobalSettings::smallestReadableFont().pointSize());
@ -831,34 +829,6 @@ QColor Theme::color(ColorRole role) const
return QColor();
}
void Theme::setFont(const QFont &font, FontRole role)
{
Q_UNUSED(role)
d->generalFont = font;
}
QFont Theme::font(FontRole role) const
{
switch (role) {
case DesktopFont: {
KConfigGroup cg(KSharedConfig::openConfig(), "General");
return cg.readEntry("desktopFont", d->generalFont);
}
break;
case DefaultFont:
default:
return d->generalFont;
break;
case SmallestFont:
return KGlobalSettings::smallestReadableFont();
break;
}
return d->generalFont;
}
bool Theme::windowTranslucencyEnabled() const
{
return d->compositingActive;

View File

@ -154,22 +154,6 @@ class PLASMA_EXPORT Theme : public QObject
*/
QColor color(ColorRole role) const;
/**
* Sets the default font to be used with themed items. Defaults to
* the application wide default font.
*
* @param font the new font
* @param role which role (usage pattern) to set the font for
*/
void setFont(const QFont &font, FontRole role = DefaultFont);
/**
* Returns the font to be used by themed items
*
* @param role which role (usage pattern) to get the font for
*/
QFont font(FontRole role) const;
/**
* @return true if the window manager effects (e.g. translucency, compositing) is active or not
*/