Merge "share icon rounding code between Units/IconItem"
This commit is contained in:
commit
09e30e5f31
@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
#include "fadingnode_p.h"
|
#include "fadingnode_p.h"
|
||||||
#include "svgtexturenode.h"
|
#include "svgtexturenode.h"
|
||||||
|
#include "units.h"
|
||||||
|
|
||||||
IconItem::IconItem(QQuickItem *parent)
|
IconItem::IconItem(QQuickItem *parent)
|
||||||
: QQuickItem(parent),
|
: QQuickItem(parent),
|
||||||
@ -238,7 +239,7 @@ QSGNode* IconItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *update
|
|||||||
animatingNode->setProgress(m_animValue);
|
animatingNode->setProgress(m_animValue);
|
||||||
|
|
||||||
if (m_sizeChanged) {
|
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(),
|
const QRect destRect(QPointF(boundingRect().center() - QPointF(iconSize/2, iconSize/2)).toPoint(),
|
||||||
QSize(iconSize, iconSize));
|
QSize(iconSize, iconSize));
|
||||||
|
|
||||||
@ -259,7 +260,7 @@ QSGNode* IconItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *update
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (m_sizeChanged) {
|
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(),
|
const QRect destRect(QPointF(boundingRect().center() - QPointF(iconSize/2, iconSize/2)).toPoint(),
|
||||||
QSize(iconSize, iconSize));
|
QSize(iconSize, iconSize));
|
||||||
|
|
||||||
@ -283,38 +284,9 @@ void IconItem::animationFinished()
|
|||||||
update();
|
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()
|
void IconItem::loadPixmap()
|
||||||
{
|
{
|
||||||
const int size = adjustedSize(qMin(width(), height()));
|
const int size = Units::roundToIconSize(qMin(width(), height()));
|
||||||
|
|
||||||
//final pixmap to paint
|
//final pixmap to paint
|
||||||
QPixmap result;
|
QPixmap result;
|
||||||
|
@ -82,7 +82,6 @@ private Q_SLOTS:
|
|||||||
void valueChanged(const QVariant &value);
|
void valueChanged(const QVariant &value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int adjustedSize(int size);
|
|
||||||
//all the ways we can set an source. Only one of them will be valid
|
//all the ways we can set an source. Only one of them will be valid
|
||||||
QIcon m_icon;
|
QIcon m_icon;
|
||||||
Plasma::Svg *m_svgIcon;
|
Plasma::Svg *m_svgIcon;
|
||||||
|
@ -104,18 +104,24 @@ QQmlPropertyMap *Units::iconSizes() const
|
|||||||
return m_iconSizes;
|
return m_iconSizes;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Units::roundToIconSize(int size) const
|
int Units::roundToIconSize(int size)
|
||||||
{
|
{
|
||||||
if (size < devicePixelIconSize(KIconLoader::SizeSmall)) {
|
/*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*/
|
||||||
return devicePixelIconSize(KIconLoader::SizeSmall/2);
|
if (size < KIconLoader::SizeSmall) {
|
||||||
} else if (size < devicePixelIconSize(KIconLoader::SizeSmallMedium)) {
|
return KIconLoader::SizeSmall/2;
|
||||||
return devicePixelIconSize(KIconLoader::SizeSmall);
|
|
||||||
} else if (size < devicePixelIconSize(KIconLoader::SizeMedium)) {
|
} else if (size < KIconLoader::SizeSmallMedium) {
|
||||||
return devicePixelIconSize(KIconLoader::SizeSmallMedium);
|
return KIconLoader::SizeSmall;
|
||||||
} else if (size < devicePixelIconSize(KIconLoader::SizeLarge)) {
|
|
||||||
return devicePixelIconSize(KIconLoader::SizeMedium);
|
} else if (size < KIconLoader::SizeMedium) {
|
||||||
} else if (size < devicePixelIconSize(KIconLoader::SizeEnormous)) {
|
return KIconLoader::SizeSmallMedium;
|
||||||
return devicePixelIconSize(KIconLoader::SizeHuge);
|
|
||||||
|
} else if (size < KIconLoader::SizeLarge) {
|
||||||
|
return KIconLoader::SizeMedium;
|
||||||
|
|
||||||
|
} else if (size < KIconLoader::SizeHuge) {
|
||||||
|
return KIconLoader::SizeLarge;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ public:
|
|||||||
* @param int size the size we want to be rounded down
|
* @param int size the size we want to be rounded down
|
||||||
* @see iconSizes
|
* @see iconSizes
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE int roundToIconSize(int size) const;
|
Q_INVOKABLE static int roundToIconSize(int size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Pixel value for large spacing between elements.
|
* @return Pixel value for large spacing between elements.
|
||||||
|
Loading…
Reference in New Issue
Block a user