Move iconSizes from theme here
This is means two things: - icon sizes have moved from theme.iconSizes.* to units.iconSizes.*, will provide porting script and update docs - we can kill PlasmaCore's ThemeProxy now. Icon sizing and dpi handling is kept outside of Plasma::Theme for now, as it pulls in too many deps.
This commit is contained in:
parent
c84e549715
commit
0dc8a7ee53
@ -11,7 +11,6 @@ set(plasmacomponents_SRCS
|
||||
qmenu.cpp
|
||||
qmenuitem.cpp
|
||||
units.cpp
|
||||
#../core/declarativeitemcontainer.cpp
|
||||
)
|
||||
|
||||
add_library(plasmacomponentsplugin SHARED ${plasmacomponents_SRCS})
|
||||
@ -22,6 +21,7 @@ target_link_libraries(plasmacomponentsplugin
|
||||
Qt5::Gui
|
||||
KF5::Declarative
|
||||
KF5::Plasma
|
||||
KF5::IconThemes
|
||||
KF5::Service #for kplugininfo.h
|
||||
)
|
||||
|
||||
|
@ -25,11 +25,21 @@
|
||||
#include <QtGlobal>
|
||||
#include <cmath>
|
||||
|
||||
#include <KIconLoader>
|
||||
|
||||
Units::Units (QObject *parent)
|
||||
: QObject(parent),
|
||||
m_gridUnit(-1)
|
||||
{
|
||||
m_iconSizes = new QQmlPropertyMap(this);
|
||||
m_iconSizes->insert("desktop", QVariant(KIconLoader::global()->currentSize(KIconLoader::Desktop)));
|
||||
m_iconSizes->insert("panel", QVariant(KIconLoader::global()->currentSize(KIconLoader::Panel)));
|
||||
m_iconSizes->insert("toolbar", KIconLoader::global()->currentSize(KIconLoader::Toolbar));
|
||||
m_iconSizes->insert("small", KIconLoader::global()->currentSize(KIconLoader::Small));
|
||||
m_iconSizes->insert("dialog", KIconLoader::global()->currentSize(KIconLoader::Dialog));
|
||||
|
||||
connect(KIconLoader::global(), SIGNAL(iconLoaderSettingsChanged()), this, SLOT(iconLoaderSettingsChanged()));
|
||||
|
||||
themeChanged();
|
||||
connect(&m_theme, SIGNAL(themeChanged()),
|
||||
this, SLOT(themeChanged()));
|
||||
@ -39,12 +49,35 @@ Units::~Units()
|
||||
{
|
||||
}
|
||||
|
||||
void Units::iconLoaderSettingsChanged()
|
||||
{
|
||||
m_iconSizes->insert("desktop", QVariant(KIconLoader::global()->currentSize(KIconLoader::Desktop)));
|
||||
m_iconSizes->insert("toolbar", KIconLoader::global()->currentSize(KIconLoader::Toolbar));
|
||||
m_iconSizes->insert("small", KIconLoader::global()->currentSize(KIconLoader::Small));
|
||||
m_iconSizes->insert("dialog", KIconLoader::global()->currentSize(KIconLoader::Dialog));
|
||||
|
||||
emit iconSizesChanged();
|
||||
}
|
||||
|
||||
QQmlPropertyMap *Units::iconSizes() const
|
||||
{
|
||||
return m_iconSizes;
|
||||
}
|
||||
|
||||
|
||||
qreal Units::dpiRatio() const
|
||||
{
|
||||
const qreal ratio = (qreal)QApplication::desktop()->physicalDpiX() / (qreal)96;
|
||||
return ratio;
|
||||
}
|
||||
|
||||
qreal Units::gridUnit() const
|
||||
{
|
||||
const int gridUnit = QFontMetrics(QApplication::font()).boundingRect("M").width();
|
||||
qDebug() << "FontMetrics: " << QApplication::font().pixelSize() << QFontMetrics(QApplication::font()).boundingRect("M");
|
||||
qDebug() << " MRect" << QFontMetrics(QApplication::font()).boundingRect("M").size();
|
||||
qDebug() << " like spacing" << QFontMetrics(QApplication::font()).boundingRect("M").size().height();
|
||||
|
||||
const int gridUnit = QFontMetrics(QApplication::font()).boundingRect("M").width();
|
||||
return m_gridUnit;
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#define UNITS_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QQmlPropertyMap>
|
||||
|
||||
#include <Plasma/Theme>
|
||||
|
||||
@ -34,11 +35,25 @@ class Units : public QObject
|
||||
*/
|
||||
Q_PROPERTY(qreal gridUnit READ gridUnit NOTIFY gridUnitChanged())
|
||||
|
||||
/**
|
||||
* icon sizes depending from the context: use those if possible
|
||||
* Access with theme.iconSizes.desktop theme.iconSizes.small etc.
|
||||
* available keys are:
|
||||
* * desktop
|
||||
* * toolbar
|
||||
* * small
|
||||
* * dialog
|
||||
*/
|
||||
Q_PROPERTY(QQmlPropertyMap *iconSizes READ iconSizes NOTIFY iconSizesChanged)
|
||||
|
||||
public:
|
||||
Units(QObject *parent = 0);
|
||||
~Units();
|
||||
|
||||
qreal gridUnit() const;
|
||||
qreal dpiRatio() const;
|
||||
|
||||
QQmlPropertyMap *iconSizes() const;
|
||||
|
||||
/**
|
||||
* @returns the number of pixels value density independent pixels correspond to.
|
||||
@ -53,13 +68,17 @@ public:
|
||||
|
||||
Q_SIGNALS:
|
||||
void gridUnitChanged();
|
||||
void iconSizesChanged();
|
||||
|
||||
private Q_SLOTS:
|
||||
void themeChanged();
|
||||
void iconLoaderSettingsChanged();
|
||||
|
||||
private:
|
||||
int m_gridUnit;
|
||||
Plasma::Theme m_theme;
|
||||
qreal m_dpiRatio;
|
||||
QQmlPropertyMap *m_iconSizes;
|
||||
};
|
||||
|
||||
#endif //UNITS_H
|
||||
|
Loading…
Reference in New Issue
Block a user