spacing hints move from theme to units
This commit is contained in:
parent
4094f01e22
commit
4da01ebce0
@ -39,6 +39,8 @@ Units::Units (QObject *parent)
|
|||||||
m_dpi = QApplication::desktop()->physicalDpiX();
|
m_dpi = QApplication::desktop()->physicalDpiX();
|
||||||
m_dpiScale = (qreal)m_dpi / (qreal)96;
|
m_dpiScale = (qreal)m_dpi / (qreal)96;
|
||||||
|
|
||||||
|
updateSpacing();
|
||||||
|
|
||||||
m_iconSizes = new QQmlPropertyMap(this);
|
m_iconSizes = new QQmlPropertyMap(this);
|
||||||
iconLoaderSettingsChanged();
|
iconLoaderSettingsChanged();
|
||||||
|
|
||||||
@ -47,6 +49,7 @@ Units::Units (QObject *parent)
|
|||||||
themeChanged();
|
themeChanged();
|
||||||
connect(&m_theme, SIGNAL(themeChanged()),
|
connect(&m_theme, SIGNAL(themeChanged()),
|
||||||
this, SLOT(themeChanged()));
|
this, SLOT(themeChanged()));
|
||||||
|
installEventFilter(qApp);
|
||||||
}
|
}
|
||||||
|
|
||||||
Units::~Units()
|
Units::~Units()
|
||||||
@ -158,7 +161,35 @@ void Units::printScreenInfo(QQuickItem* item)
|
|||||||
qDebug() << " gridUnit: " << QFontMetrics(QApplication::font()).boundingRect("M").size().height();
|
qDebug() << " gridUnit: " << QFontMetrics(QApplication::font()).boundingRect("M").size().height();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Units::smallSpacing() const
|
||||||
|
{
|
||||||
|
return m_smallSpacing;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Units::largeSpacing() const
|
||||||
|
{
|
||||||
|
return m_largeSpacing;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Units::updateSpacing()
|
||||||
|
{
|
||||||
|
const int _s = QFontMetrics(QApplication::font()).boundingRect("M").size().height();
|
||||||
|
if (_s != m_largeSpacing) {
|
||||||
|
m_smallSpacing = qMax(2, (int)(_s / 8)); // 1/8 of msize.height, at least 2
|
||||||
|
m_largeSpacing = _s; // msize.height
|
||||||
|
emit spacingChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Units::eventFilter(QObject *watched, QEvent *event)
|
||||||
|
{
|
||||||
|
if (watched == QCoreApplication::instance()) {
|
||||||
|
if (event->type() == QEvent::ApplicationFontChange || event->type() == QEvent::FontChange) {
|
||||||
|
updateSpacing();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QObject::eventFilter(watched, event);
|
||||||
|
}
|
||||||
|
|
||||||
#include "units.moc"
|
#include "units.moc"
|
||||||
|
|
||||||
|
@ -60,11 +60,18 @@ class Units : public QObject
|
|||||||
*/
|
*/
|
||||||
Q_PROPERTY(QQmlPropertyMap *iconSizes READ iconSizes NOTIFY iconSizesChanged)
|
Q_PROPERTY(QQmlPropertyMap *iconSizes READ iconSizes NOTIFY iconSizesChanged)
|
||||||
|
|
||||||
|
// layout hints
|
||||||
|
Q_PROPERTY(int smallSpacing READ smallSpacing NOTIFY spacingChanged)
|
||||||
|
Q_PROPERTY(int largeSpacing READ largeSpacing NOTIFY spacingChanged)
|
||||||
|
|
||||||
Q_PROPERTY(qreal dpiScale READ dpiScale WRITE setDpiScale NOTIFY dpiScaleChanged)
|
Q_PROPERTY(qreal dpiScale READ dpiScale WRITE setDpiScale NOTIFY dpiScaleChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Units(QObject *parent = 0);
|
Units(QObject *parent = 0);
|
||||||
~Units();
|
~Units();
|
||||||
|
|
||||||
|
bool eventFilter(QObject *watched, QEvent *event);
|
||||||
|
|
||||||
qreal gridUnit() const;
|
qreal gridUnit() const;
|
||||||
|
|
||||||
void setDpiScale(const qreal scale);
|
void setDpiScale(const qreal scale);
|
||||||
@ -72,6 +79,10 @@ public:
|
|||||||
|
|
||||||
QQmlPropertyMap *iconSizes() const;
|
QQmlPropertyMap *iconSizes() const;
|
||||||
|
|
||||||
|
int smallSpacing() const;
|
||||||
|
int largeSpacing() const;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns the number of pixels value density independent pixels correspond to.
|
* @returns the number of pixels value density independent pixels correspond to.
|
||||||
*/
|
*/
|
||||||
@ -93,17 +104,22 @@ Q_SIGNALS:
|
|||||||
void dpiScaleChanged();
|
void dpiScaleChanged();
|
||||||
void gridUnitChanged();
|
void gridUnitChanged();
|
||||||
void iconSizesChanged();
|
void iconSizesChanged();
|
||||||
|
void spacingChanged();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void themeChanged();
|
void themeChanged();
|
||||||
void iconLoaderSettingsChanged();
|
void iconLoaderSettingsChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void updateSpacing();
|
||||||
|
|
||||||
int m_gridUnit;
|
int m_gridUnit;
|
||||||
Plasma::Theme m_theme;
|
Plasma::Theme m_theme;
|
||||||
qreal m_dpiScale;
|
qreal m_dpiScale;
|
||||||
qreal m_dpi;
|
qreal m_dpi;
|
||||||
QQmlPropertyMap *m_iconSizes;
|
QQmlPropertyMap *m_iconSizes;
|
||||||
|
int m_smallSpacing;
|
||||||
|
int m_largeSpacing;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //UNITS_H
|
#endif //UNITS_H
|
||||||
|
@ -545,17 +545,6 @@ QSizeF Theme::mSize(const QFont &font) const
|
|||||||
return QFontMetrics(font).boundingRect("M").size();
|
return QFontMetrics(font).boundingRect("M").size();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Theme::smallSpacing() const
|
|
||||||
{
|
|
||||||
return d->smallSpacing;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Theme::largeSpacing() const
|
|
||||||
{
|
|
||||||
return d->largeSpacing;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,10 +83,6 @@ class PLASMA_EXPORT Theme : public QObject
|
|||||||
|
|
||||||
Q_PROPERTY(int defaultIconSize READ defaultIconSize NOTIFY defaultIconSizeChanged)
|
Q_PROPERTY(int defaultIconSize READ defaultIconSize NOTIFY defaultIconSizeChanged)
|
||||||
|
|
||||||
// layout hints
|
|
||||||
Q_PROPERTY(int smallSpacing READ smallSpacing NOTIFY defaultFontChanged)
|
|
||||||
Q_PROPERTY(int largeSpacing READ largeSpacing NOTIFY defaultFontChanged)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum ColorRole {
|
enum ColorRole {
|
||||||
TextColor = 0, /**< the text color to be used by items resting on the background */
|
TextColor = 0, /**< the text color to be used by items resting on the background */
|
||||||
@ -336,7 +332,16 @@ class PLASMA_EXPORT Theme : public QObject
|
|||||||
*/
|
*/
|
||||||
KPluginInfo pluginInfo() const;
|
KPluginInfo pluginInfo() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The default application font
|
||||||
|
* @since 5.0
|
||||||
|
*/
|
||||||
QFont defaultFont() const;
|
QFont defaultFont() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The smallest readable font
|
||||||
|
* @since 5.0
|
||||||
|
*/
|
||||||
QFont smallestFont() const;
|
QFont smallestFont() const;
|
||||||
|
|
||||||
QColor textColor() const;
|
QColor textColor() const;
|
||||||
@ -355,9 +360,6 @@ class PLASMA_EXPORT Theme : public QObject
|
|||||||
|
|
||||||
int defaultIconSize() const;
|
int defaultIconSize() const;
|
||||||
|
|
||||||
int smallSpacing() const;
|
|
||||||
int largeSpacing() const;
|
|
||||||
|
|
||||||
Q_INVOKABLE QSizeF mSize(const QFont &font = QApplication::font()) const;
|
Q_INVOKABLE QSizeF mSize(const QFont &font = QApplication::font()) const;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
|
Loading…
Reference in New Issue
Block a user