get the margins right.
give the natural svg size if the icon is a svg svn path=/trunk/KDE/kdelibs/; revision=1118304
This commit is contained in:
parent
c08007f131
commit
b9de116f33
@ -588,10 +588,10 @@ void IconWidgetPrivate::layoutIcons(const QStyleOptionGraphicsItem *option)
|
|||||||
|
|
||||||
//aspect ratio very "tall"
|
//aspect ratio very "tall"
|
||||||
if (!text.isEmpty() || !infoText.isEmpty()) {
|
if (!text.isEmpty() || !infoText.isEmpty()) {
|
||||||
if (currentSize.width() < heightAvail) {
|
if (currentSize.width() < heightAvail) {
|
||||||
iconWidth = currentSize.width() -
|
iconWidth = currentSize.width() -
|
||||||
horizontalMargin[IconWidgetPrivate::IconMargin].left -
|
verticalMargin[IconWidgetPrivate::IconMargin].left -
|
||||||
horizontalMargin[IconWidgetPrivate::IconMargin].right;
|
verticalMargin[IconWidgetPrivate::IconMargin].right;
|
||||||
} else {
|
} else {
|
||||||
iconWidth = heightAvail -
|
iconWidth = heightAvail -
|
||||||
verticalMargin[IconWidgetPrivate::IconMargin].top -
|
verticalMargin[IconWidgetPrivate::IconMargin].top -
|
||||||
@ -600,7 +600,8 @@ void IconWidgetPrivate::layoutIcons(const QStyleOptionGraphicsItem *option)
|
|||||||
} else {
|
} else {
|
||||||
iconWidth = qMin(heightAvail, currentSize.width());
|
iconWidth = qMin(heightAvail, currentSize.width());
|
||||||
}
|
}
|
||||||
iconWidth -= horizontalMargin[IconWidgetPrivate::ItemMargin].left + horizontalMargin[IconWidgetPrivate::ItemMargin].right;
|
|
||||||
|
iconWidth -= verticalMargin[IconWidgetPrivate::ItemMargin].left + verticalMargin[IconWidgetPrivate::ItemMargin].right;
|
||||||
} else {
|
} else {
|
||||||
//Horizontal layout
|
//Horizontal layout
|
||||||
//if there is text resize the icon in order to make room for the text
|
//if there is text resize the icon in order to make room for the text
|
||||||
@ -609,12 +610,11 @@ void IconWidgetPrivate::layoutIcons(const QStyleOptionGraphicsItem *option)
|
|||||||
iconWidth = qMin(currentSize.height(), currentSize.width());
|
iconWidth = qMin(currentSize.height(), currentSize.width());
|
||||||
} else {
|
} else {
|
||||||
iconWidth = currentSize.height() -
|
iconWidth = currentSize.height() -
|
||||||
verticalMargin[IconWidgetPrivate::IconMargin].top -
|
horizontalMargin[IconWidgetPrivate::IconMargin].top -
|
||||||
verticalMargin[IconWidgetPrivate::IconMargin].bottom;
|
horizontalMargin[IconWidgetPrivate::IconMargin].bottom;
|
||||||
}
|
}
|
||||||
iconWidth -= verticalMargin[IconWidgetPrivate::ItemMargin].top + verticalMargin[IconWidgetPrivate::ItemMargin].bottom;
|
iconWidth -= horizontalMargin[IconWidgetPrivate::ItemMargin].top + horizontalMargin[IconWidgetPrivate::ItemMargin].bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
iconSize = QSizeF(iconWidth, iconWidth);
|
iconSize = QSizeF(iconWidth, iconWidth);
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
@ -644,6 +644,7 @@ void IconWidget::setSvg(const QString &svgFilePath, const QString &elementId)
|
|||||||
d->iconSvgElement = elementId;
|
d->iconSvgElement = elementId;
|
||||||
d->iconSvgElementChanged = true;
|
d->iconSvgElementChanged = true;
|
||||||
d->icon = QIcon();
|
d->icon = QIcon();
|
||||||
|
updateGeometry();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -659,7 +660,18 @@ QString IconWidget::svg() const
|
|||||||
QSizeF IconWidget::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const
|
QSizeF IconWidget::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const
|
||||||
{
|
{
|
||||||
if (which == Qt::PreferredSize) {
|
if (which == Qt::PreferredSize) {
|
||||||
return sizeFromIconSize(KIconLoader::SizeMedium);
|
int iconSize = KIconLoader::SizeMedium;
|
||||||
|
if (d->iconSvg) {
|
||||||
|
QSizeF oldSize = d->iconSvg->size();
|
||||||
|
d->iconSvg->resize();
|
||||||
|
if (d->iconSvgElement.isNull()) {
|
||||||
|
iconSize = qMax(d->iconSvg->size().width(), d->iconSvg->size().height());
|
||||||
|
} else {
|
||||||
|
iconSize = qMax(d->iconSvg->elementSize(d->iconSvgElement).width(), d->iconSvg->elementSize(d->iconSvgElement).width());
|
||||||
|
}
|
||||||
|
d->iconSvg->resize(oldSize);
|
||||||
|
}
|
||||||
|
return sizeFromIconSize(iconSize);
|
||||||
} else if (which == Qt::MinimumSize) {
|
} else if (which == Qt::MinimumSize) {
|
||||||
return sizeFromIconSize(KIconLoader::SizeSmall);
|
return sizeFromIconSize(KIconLoader::SizeSmall);
|
||||||
} else {
|
} else {
|
||||||
@ -1436,26 +1448,24 @@ QSizeF IconWidget::sizeFromIconSize(const qreal iconWidth) const
|
|||||||
{
|
{
|
||||||
d->setActiveMargins();
|
d->setActiveMargins();
|
||||||
if (d->text.isEmpty() && d->infoText.isEmpty()) {
|
if (d->text.isEmpty() && d->infoText.isEmpty()) {
|
||||||
//no text, less calculations
|
//no text, just the icon size
|
||||||
return d->addMargin(d->addMargin(QSizeF(iconWidth, iconWidth), IconWidgetPrivate::IconMargin),
|
return QSizeF(iconWidth, iconWidth);
|
||||||
IconWidgetPrivate::ItemMargin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QFontMetricsF fm(d->widgetFont());
|
QFontMetricsF fm(d->widgetFont());
|
||||||
qreal width = 0;
|
qreal width = 0;
|
||||||
|
|
||||||
if (d->orientation == Qt::Vertical) {
|
if (d->orientation == Qt::Vertical) {
|
||||||
// make room for at most 14 characters
|
|
||||||
width = qMax(d->maxWordWidth(d->text),
|
width = qMax(d->maxWordWidth(d->text),
|
||||||
d->maxWordWidth(d->infoText)) +
|
d->maxWordWidth(d->infoText)) +
|
||||||
fm.width("xxx") +
|
fm.width("xxx") +
|
||||||
d->horizontalMargin[IconWidgetPrivate::TextMargin].left +
|
d->verticalMargin[IconWidgetPrivate::TextMargin].left +
|
||||||
d->horizontalMargin[IconWidgetPrivate::TextMargin].right;
|
d->verticalMargin[IconWidgetPrivate::TextMargin].right;
|
||||||
|
|
||||||
width = qMax(width,
|
width = qMax(width,
|
||||||
iconWidth +
|
iconWidth +
|
||||||
d->horizontalMargin[IconWidgetPrivate::IconMargin].left +
|
d->verticalMargin[IconWidgetPrivate::IconMargin].left +
|
||||||
d->horizontalMargin[IconWidgetPrivate::IconMargin].right);
|
d->verticalMargin[IconWidgetPrivate::IconMargin].right);
|
||||||
} else {
|
} else {
|
||||||
width = iconWidth +
|
width = iconWidth +
|
||||||
d->horizontalMargin[IconWidgetPrivate::IconMargin].left +
|
d->horizontalMargin[IconWidgetPrivate::IconMargin].left +
|
||||||
|
Loading…
x
Reference in New Issue
Block a user