Scale units.iconSizes with dpi
This is still pretty rough. It seems to work fine for larger icons, but smaller ones get misaligned. This will need some corrections, such as locking the smaller sizes to 16, 22, 32, 48, 64, which should take care of this issue. With this change, parts of Plasma scale depending on the DPI. This is noticeable in Kickoff.
This commit is contained in:
parent
a2baa1c7c7
commit
124ae423c1
@ -35,11 +35,11 @@ Units::Units (QObject *parent)
|
||||
m_gridUnit(-1),
|
||||
m_devicePixelRatio(-1)
|
||||
{
|
||||
m_iconSizes = new QQmlPropertyMap(this);
|
||||
setDevicePixelRatio(0);
|
||||
updateSpacing();
|
||||
|
||||
m_iconSizes = new QQmlPropertyMap(this);
|
||||
iconLoaderSettingsChanged();
|
||||
//iconLoaderSettingsChanged();
|
||||
|
||||
connect(KIconLoader::global(), SIGNAL(iconLoaderSettingsChanged()), this, SLOT(iconLoaderSettingsChanged()));
|
||||
|
||||
@ -58,14 +58,15 @@ void Units::iconLoaderSettingsChanged()
|
||||
m_iconSizes->insert("default", QVariant(KIconLoader::global()->currentSize(KIconLoader::Desktop)));
|
||||
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("small", KIconLoader::global()->currentSize(KIconLoader::Small));
|
||||
m_iconSizes->insert("dialog", KIconLoader::global()->currentSize(KIconLoader::Dialog));
|
||||
|
||||
m_iconSizes->insert("smallMedium", KIconLoader::SizeSmallMedium);
|
||||
m_iconSizes->insert("medium", KIconLoader::SizeMedium);
|
||||
m_iconSizes->insert("large", KIconLoader::SizeLarge);
|
||||
m_iconSizes->insert("huge", KIconLoader::SizeHuge);
|
||||
m_iconSizes->insert("enormous", KIconLoader::SizeEnormous);
|
||||
m_iconSizes->insert("small", devicePixelIconSize(KIconLoader::SizeSmall));
|
||||
m_iconSizes->insert("smallMedium", devicePixelIconSize(KIconLoader::SizeSmallMedium));
|
||||
m_iconSizes->insert("medium", devicePixelIconSize(KIconLoader::SizeMedium));
|
||||
m_iconSizes->insert("large", devicePixelIconSize(KIconLoader::SizeLarge));
|
||||
m_iconSizes->insert("huge", devicePixelIconSize(KIconLoader::SizeHuge));
|
||||
m_iconSizes->insert("enormous", devicePixelIconSize(KIconLoader::SizeEnormous));
|
||||
|
||||
emit iconSizesChanged();
|
||||
}
|
||||
@ -75,6 +76,38 @@ QQmlPropertyMap *Units::iconSizes() const
|
||||
return m_iconSizes;
|
||||
}
|
||||
|
||||
int Units::devicePixelIconSize(const int size) const
|
||||
{
|
||||
/*
|
||||
enum StdSizes {
|
||||
SizeSmall=16,
|
||||
SizeSmallMedium=22,
|
||||
SizeMedium=32,
|
||||
SizeLarge=48,
|
||||
SizeHuge=64,
|
||||
SizeEnormous=128
|
||||
};
|
||||
*/
|
||||
// Scale the icon sizes up using the devicePixelRatio
|
||||
// This function returns the next stepping icon size
|
||||
// and multiplies the global settings with the dpi ratio.
|
||||
const int dpisize = devicePixelRatio() * size;
|
||||
int out = KIconLoader::SizeSmall;
|
||||
if (devicePixelRatio() < 1.5) {
|
||||
return size;
|
||||
} else if (devicePixelRatio() < 2.0) {
|
||||
out = size * 1.5;
|
||||
} else if (devicePixelRatio() < 2.5) {
|
||||
out = size * 2.0;
|
||||
} else if (devicePixelRatio() < 3.0) {
|
||||
out = size * 3.0;
|
||||
} else {
|
||||
out = dpisize;
|
||||
}
|
||||
//qDebug() << " Size in: " << size << dpisize << " -> " << out;
|
||||
return out;
|
||||
}
|
||||
|
||||
qreal Units::devicePixelRatio() const
|
||||
{
|
||||
return m_devicePixelRatio;
|
||||
@ -91,18 +124,14 @@ void Units::setDevicePixelRatio(const qreal scale)
|
||||
} else {
|
||||
m_devicePixelRatio = scale;
|
||||
}
|
||||
qDebug() << "Setting dpi scale to " << scale;
|
||||
qDebug() << "Setting dpi scale to " << scale;
|
||||
iconLoaderSettingsChanged();
|
||||
emit devicePixelRatioChanged();
|
||||
}
|
||||
}
|
||||
|
||||
int Units::gridUnit() const
|
||||
{
|
||||
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();
|
||||
qDebug() << "m_dpi: " << m_dpi;
|
||||
qDebug() << "m_devicePixelRatio: " << m_devicePixelRatio;
|
||||
const int gridUnit = QFontMetrics(QApplication::font()).boundingRect("M").width();
|
||||
return m_gridUnit;
|
||||
}
|
||||
@ -162,6 +191,14 @@ void Units::printScreenInfo(QQuickItem* item)
|
||||
qDebug() << "FontMetrics: " << QApplication::font().pointSize() << QFontMetrics(QApplication::font()).boundingRect("M");
|
||||
qDebug() << " MRect" << QFontMetrics(QApplication::font()).boundingRect("M").size();
|
||||
qDebug() << " gridUnit: " << QFontMetrics(QApplication::font()).boundingRect("M").size().height();
|
||||
|
||||
|
||||
qDebug() << " Small " << KIconLoader::SizeSmall << " -> " << devicePixelIconSize(KIconLoader::SizeSmall);
|
||||
qDebug() << " SMedi " << KIconLoader::SizeSmallMedium << " -> " << devicePixelIconSize(KIconLoader::SizeSmallMedium);
|
||||
qDebug() << " Mediu " << KIconLoader::SizeMedium << " -> " << devicePixelIconSize(KIconLoader::SizeMedium);
|
||||
qDebug() << " Large " << KIconLoader::SizeLarge << " -> " << devicePixelIconSize(KIconLoader::SizeLarge);
|
||||
qDebug() << " Huge " << KIconLoader::SizeHuge << " -> " << devicePixelIconSize(KIconLoader::SizeHuge);
|
||||
qDebug() << " Enorm " << KIconLoader::SizeEnormous << " -> " << devicePixelIconSize(KIconLoader::SizeEnormous);
|
||||
}
|
||||
|
||||
int Units::smallSpacing() const
|
||||
|
@ -1,5 +1,6 @@
|
||||
/***************************************************************************
|
||||
* Copyright 2013 Marco Martin <mart@kde.org> *
|
||||
* Copyright 2014 Sebastian Kügler <sebas@kde.org> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
@ -126,6 +127,10 @@ private Q_SLOTS:
|
||||
|
||||
private:
|
||||
void updateSpacing();
|
||||
/**
|
||||
* @return The dpi-adjusted size for a given icon size
|
||||
*/
|
||||
int devicePixelIconSize(const int size) const;
|
||||
|
||||
Plasma::Theme m_theme;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user