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();
ThemeProxy *theme = new ThemeProxy(context);
ThemeProxy *theme = new ThemeProxy(engine);
context->setContextProperty("theme", theme);
/* KDeclarative kdeclarative;
@ -85,7 +85,8 @@ void CoreBindingsPlugin::registerTypes(const char *uri)
qmlRegisterType<Plasma::SvgItem>(uri, 2, 0, "SvgItem");
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::DataModel>(uri, 2, 0, "DataModel");

View File

@ -30,8 +30,9 @@
//********** Theme *************
ThemeProxy::ThemeProxy(QObject *parent)
: Plasma::Theme(parent)
ThemeProxy::ThemeProxy(QQmlEngine *parent)
: Plasma::Theme(parent),
m_engine(parent)
{
m_defaultIconSize = KIconLoader::global()->currentSize(KIconLoader::Desktop);
@ -58,14 +59,26 @@ QString ThemeProxy::themeName() const
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

View File

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

View File

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