Merge "share icon rounding code between Units/IconItem"

This commit is contained in:
Marco Martin 2014-09-25 14:52:27 +02:00 committed by Gerrit Code Review
commit 09e30e5f31
4 changed files with 22 additions and 45 deletions

View File

@ -34,6 +34,7 @@
#include "fadingnode_p.h"
#include "svgtexturenode.h"
#include "units.h"
IconItem::IconItem(QQuickItem *parent)
: QQuickItem(parent),
@ -238,7 +239,7 @@ QSGNode* IconItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *update
animatingNode->setProgress(m_animValue);
if (m_sizeChanged) {
const int iconSize = adjustedSize(qMin(boundingRect().size().width(), boundingRect().size().height()));
const int iconSize = Units::roundToIconSize(qMin(boundingRect().size().width(), boundingRect().size().height()));
const QRect destRect(QPointF(boundingRect().center() - QPointF(iconSize/2, iconSize/2)).toPoint(),
QSize(iconSize, iconSize));
@ -259,7 +260,7 @@ QSGNode* IconItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *update
}
if (m_sizeChanged) {
const int iconSize = adjustedSize(qMin(boundingRect().size().width(), boundingRect().size().height()));
const int iconSize = Units::roundToIconSize(qMin(boundingRect().size().width(), boundingRect().size().height()));
const QRect destRect(QPointF(boundingRect().center() - QPointF(iconSize/2, iconSize/2)).toPoint(),
QSize(iconSize, iconSize));
@ -283,38 +284,9 @@ void IconItem::animationFinished()
update();
}
int IconItem::adjustedSize(int size)
{
if (m_svgIcon) {
m_svgIcon->resize();
}
if (m_svgIcon &&
size > KIconLoader::SizeSmallMedium &&
size < KIconLoader::SizeMedium &&
m_svgIcon->elementSize(m_source.toString()).width() > KIconLoader::SizeSmallMedium &&
m_svgIcon->elementSize(m_source.toString()).width() < KIconLoader::SizeMedium) {
return m_svgIcon->elementSize(m_source.toString()).width();
} else if (size < KIconLoader::SizeSmall) {
//do nothing
return size;
} else if (size < KIconLoader::SizeSmallMedium) {
return KIconLoader::SizeSmall;
} else if (size < KIconLoader::SizeMedium) {
return KIconLoader::SizeSmallMedium;
} else if (size < KIconLoader::SizeLarge) {
return KIconLoader::SizeMedium;
} else if (size < KIconLoader::SizeHuge) {
return KIconLoader::SizeLarge;
//if size is more than 64, leave as is
}
return size;
}
void IconItem::loadPixmap()
{
const int size = adjustedSize(qMin(width(), height()));
const int size = Units::roundToIconSize(qMin(width(), height()));
//final pixmap to paint
QPixmap result;

View File

@ -82,7 +82,6 @@ private Q_SLOTS:
void valueChanged(const QVariant &value);
private:
int adjustedSize(int size);
//all the ways we can set an source. Only one of them will be valid
QIcon m_icon;
Plasma::Svg *m_svgIcon;

View File

@ -104,18 +104,24 @@ QQmlPropertyMap *Units::iconSizes() const
return m_iconSizes;
}
int Units::roundToIconSize(int size) const
int Units::roundToIconSize(int size)
{
if (size < devicePixelIconSize(KIconLoader::SizeSmall)) {
return devicePixelIconSize(KIconLoader::SizeSmall/2);
} else if (size < devicePixelIconSize(KIconLoader::SizeSmallMedium)) {
return devicePixelIconSize(KIconLoader::SizeSmall);
} else if (size < devicePixelIconSize(KIconLoader::SizeMedium)) {
return devicePixelIconSize(KIconLoader::SizeSmallMedium);
} else if (size < devicePixelIconSize(KIconLoader::SizeLarge)) {
return devicePixelIconSize(KIconLoader::SizeMedium);
} else if (size < devicePixelIconSize(KIconLoader::SizeEnormous)) {
return devicePixelIconSize(KIconLoader::SizeHuge);
/*Do *not* use devicePixelIconSize here, we want to use the sizes of the pixmaps of the smallest icons on the disk. And those are unaffected by dpi*/
if (size < KIconLoader::SizeSmall) {
return KIconLoader::SizeSmall/2;
} else if (size < KIconLoader::SizeSmallMedium) {
return KIconLoader::SizeSmall;
} else if (size < KIconLoader::SizeMedium) {
return KIconLoader::SizeSmallMedium;
} else if (size < KIconLoader::SizeLarge) {
return KIconLoader::SizeMedium;
} else if (size < KIconLoader::SizeHuge) {
return KIconLoader::SizeLarge;
} else {
return size;
}

View File

@ -128,7 +128,7 @@ public:
* @param int size the size we want to be rounded down
* @see iconSizes
*/
Q_INVOKABLE int roundToIconSize(int size) const;
Q_INVOKABLE static int roundToIconSize(int size);
/**
* @return Pixel value for large spacing between elements.