restore mSize attached property of theme fonts

This commit is contained in:
Marco Martin 2013-08-27 17:34:28 +02:00
parent 915598dca2
commit bd6927138f
4 changed files with 33 additions and 14 deletions

View File

@ -55,7 +55,7 @@ void CoreBindingsPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
QQmlContext *context = engine->rootContext(); QQmlContext *context = engine->rootContext();
ThemeProxy *theme = new ThemeProxy(context); ThemeProxy *theme = new ThemeProxy(engine);
context->setContextProperty("theme", theme); context->setContextProperty("theme", theme);
/* KDeclarative kdeclarative; /* KDeclarative kdeclarative;
@ -85,7 +85,8 @@ void CoreBindingsPlugin::registerTypes(const char *uri)
qmlRegisterType<Plasma::SvgItem>(uri, 2, 0, "SvgItem"); qmlRegisterType<Plasma::SvgItem>(uri, 2, 0, "SvgItem");
qmlRegisterType<Plasma::FrameSvgItem>(uri, 2, 0, "FrameSvgItem"); qmlRegisterType<Plasma::FrameSvgItem>(uri, 2, 0, "FrameSvgItem");
qmlRegisterType<ThemeProxy>(uri, 2, 0, "Theme"); //qmlRegisterType<ThemeProxy>(uri, 2, 0, "Theme");
qmlRegisterType<ThemeProxy>();
qmlRegisterType<Plasma::DataSource>(uri, 2, 0, "DataSource"); qmlRegisterType<Plasma::DataSource>(uri, 2, 0, "DataSource");
qmlRegisterType<Plasma::DataModel>(uri, 2, 0, "DataModel"); qmlRegisterType<Plasma::DataModel>(uri, 2, 0, "DataModel");

View File

@ -30,8 +30,9 @@
//********** Theme ************* //********** Theme *************
ThemeProxy::ThemeProxy(QObject *parent) ThemeProxy::ThemeProxy(QQmlEngine *parent)
: Plasma::Theme(parent) : Plasma::Theme(parent),
m_engine(parent)
{ {
m_defaultIconSize = KIconLoader::global()->currentSize(KIconLoader::Desktop); m_defaultIconSize = KIconLoader::global()->currentSize(KIconLoader::Desktop);
@ -58,14 +59,26 @@ QString ThemeProxy::themeName() const
return Plasma::Theme::themeName(); return Plasma::Theme::themeName();
} }
QFont ThemeProxy::defaultFont() const QJSValue ThemeProxy::defaultFont() const
{ {
return QApplication::font(); QJSValue val(m_engine->toScriptValue(QApplication::font()));
const QSize size(QFontMetrics(QApplication::font()).boundingRect("M").size());
QJSValue sizeObj(m_engine->newObject());
sizeObj.setProperty("width", size.width());
sizeObj.setProperty("height", size.height());
val.setProperty("mSize", sizeObj);
return val;
} }
QFont ThemeProxy::smallestFont() const QJSValue ThemeProxy::smallestFont() const
{ {
return KGlobalSettings::smallestReadableFont(); QJSValue val(m_engine->toScriptValue(KGlobalSettings::smallestReadableFont()));
const QSize size(QFontMetrics(QApplication::font()).boundingRect("M").size());
QJSValue sizeObj(m_engine->newObject());
sizeObj.setProperty("width", size.width());
sizeObj.setProperty("height", size.height());
val.setProperty("mSize", sizeObj);
return val;
} }
QSizeF ThemeProxy::mSize(const QFont &font) const QSizeF ThemeProxy::mSize(const QFont &font) const

View File

@ -24,6 +24,8 @@
#include <QFont> #include <QFont>
#include <QColor> #include <QColor>
#include <QJSValue>
#include <QQmlEngine>
#include <Plasma/Theme> #include <Plasma/Theme>
@ -43,8 +45,8 @@ class ThemeProxy : public Plasma::Theme
Q_PROPERTY(QString wallpaperPath READ wallpaperPath NOTIFY themeChanged) Q_PROPERTY(QString wallpaperPath READ wallpaperPath NOTIFY themeChanged)
//fonts //fonts
Q_PROPERTY(QFont defaultFont READ defaultFont NOTIFY defaultFontChanged) Q_PROPERTY(QJSValue defaultFont READ defaultFont NOTIFY defaultFontChanged)
Q_PROPERTY(QFont smallestFont READ smallestFont NOTIFY smallestFontChanged) Q_PROPERTY(QJSValue smallestFont READ smallestFont NOTIFY smallestFontChanged)
// colors // colors
Q_PROPERTY(QColor textColor READ textColor NOTIFY themeChanged) Q_PROPERTY(QColor textColor READ textColor NOTIFY themeChanged)
@ -84,12 +86,12 @@ class ThemeProxy : public Plasma::Theme
Q_PROPERTY(QQmlPropertyMap *iconSizes READ iconSizes NOTIFY iconSizesChanged) Q_PROPERTY(QQmlPropertyMap *iconSizes READ iconSizes NOTIFY iconSizesChanged)
public: public:
ThemeProxy(QObject *parent = 0); ThemeProxy(QQmlEngine *parent = 0);
~ThemeProxy(); ~ThemeProxy();
QString themeName() const; QString themeName() const;
QFont defaultFont() const; QJSValue defaultFont() const;
QFont smallestFont() const; QJSValue smallestFont() const;
/** /**
* @return The size of an uppercase M in a font, defaultFont() by default * @return The size of an uppercase M in a font, defaultFont() by default
*/ */
@ -136,6 +138,7 @@ Q_SIGNALS:
private: private:
int m_defaultIconSize; int m_defaultIconSize;
QQmlPropertyMap *m_iconSizes; QQmlPropertyMap *m_iconSizes;
QQmlEngine *m_engine;
}; };
#endif #endif

View File

@ -29,7 +29,9 @@ QtControls.Button {
checkable: true checkable: true
property string eventString property string eventString
width: theme.defaultFont.mSize.width*15 implicitWidth: theme.defaultFont.mSize.width * 15
Layout.minimumWidth: implicitWidth
Layout.maximumWidth: implicitWidth
onCheckedChanged: { onCheckedChanged: {
if (checked) { if (checked) {