set margins around the icon dependent on the svg margins or on the

widget's contentsmargins if set

svn path=/trunk/KDE/kdelibs/; revision=1021623
This commit is contained in:
Marco Martin 2009-09-09 17:03:22 +00:00
parent 85defb5470
commit 1e4746035f
2 changed files with 60 additions and 12 deletions

View File

@ -101,6 +101,12 @@ void IconWidgetPrivate::readColors()
void IconWidgetPrivate::colorConfigChanged()
{
readColors();
if (drawBg) {
qreal left, top, right, bottom;
background->getMargins(left, top, right, bottom);
setVerticalMargin(IconWidgetPrivate::ItemMargin, left, top, right, bottom);
setHorizontalMargin(IconWidgetPrivate::ItemMargin, left, top, right, bottom);
}
q->update();
}
@ -326,6 +332,11 @@ void IconWidgetPrivate::init()
// setAcceptedMouseButtons(Qt::LeftButton);
q->setAcceptsHoverEvents(true);
background = new Plasma::FrameSvg(q);
background->setImagePath("widgets/viewitem");
background->setCacheAllRenderedFrames(true);
background->setElementPrefix("hover");
// Margins for horizontal mode (list views, tree views, table views)
setHorizontalMargin(IconWidgetPrivate::TextMargin, 1, 1);
setHorizontalMargin(IconWidgetPrivate::IconMargin, 1, 1);
@ -338,10 +349,6 @@ void IconWidgetPrivate::init()
setActiveMargins();
currentSize = QSizeF(-1, -1);
background = new Plasma::FrameSvg(q);
background->setImagePath("widgets/viewitem");
background->setCacheAllRenderedFrames(true);
}
void IconWidget::addIconAction(QAction *action)
@ -419,6 +426,16 @@ void IconWidget::setDrawBackground(bool draw)
d->setVerticalMargin(IconWidgetPrivate::IconMargin, focusHMargin, focusVMargin);
d->currentSize = QSizeF(-1, -1);
if (draw) {
qreal left, top, right, bottom;
d->background->getMargins(left, top, right, bottom);
d->setHorizontalMargin(IconWidgetPrivate::ItemMargin, left, top, right, bottom);
d->setVerticalMargin(IconWidgetPrivate::ItemMargin, left, top, right, bottom);
} else {
d->setHorizontalMargin(IconWidgetPrivate::ItemMargin, 0, 0);
d->setVerticalMargin(IconWidgetPrivate::ItemMargin, 0, 0);
}
update();
}
}
@ -506,6 +523,7 @@ void IconWidgetPrivate::layoutIcons(const QStyleOptionGraphicsItem *option)
verticalMargin[IconWidgetPrivate::IconMargin].top -
verticalMargin[IconWidgetPrivate::IconMargin].bottom;
}
iconWidth -= horizontalMargin[IconWidgetPrivate::ItemMargin].left + horizontalMargin[IconWidgetPrivate::ItemMargin].right;
} else {
//Horizontal layout
QFontMetricsF fm(q->font());
@ -521,6 +539,7 @@ void IconWidgetPrivate::layoutIcons(const QStyleOptionGraphicsItem *option)
verticalMargin[IconWidgetPrivate::IconMargin].top -
verticalMargin[IconWidgetPrivate::IconMargin].bottom;
}
iconWidth -= verticalMargin[IconWidgetPrivate::ItemMargin].top + verticalMargin[IconWidgetPrivate::ItemMargin].bottom;
}
iconSize = QSizeF(iconWidth, iconWidth);
@ -687,6 +706,7 @@ QPointF IconWidgetPrivate::iconPosition(const QStyleOptionGraphicsItem *option,
// Compute the nominal decoration rectangle
const QSizeF size = addMargin(iconSize, IconWidgetPrivate::IconMargin);
Qt::LayoutDirection direction = iconDirection(option);
//alignment depends from orientation and option->direction

View File

@ -299,29 +299,57 @@ void IconWidgetPrivate::setHorizontalMargin(MarginType type, qreal horizontal, q
QRectF IconWidgetPrivate::addMargin(const QRectF &rect, MarginType type) const
{
Q_ASSERT(activeMargins);
const Margin &m = activeMargins[type];
return rect.adjusted(-m.left, -m.top, m.right, m.bottom);
qreal left, top, right, bottom;
q->getContentsMargins(&left, &top, &right, &bottom);
if (type == ItemMargin && (left || top || right || bottom)) {
return rect.adjusted(-left, -top, right, bottom);
} else {
const Margin &m = activeMargins[type];
return rect.adjusted(-m.left, -m.top, m.right, m.bottom);
}
}
QRectF IconWidgetPrivate::subtractMargin(const QRectF &rect, MarginType type) const
{
Q_ASSERT(activeMargins);
const Margin &m = activeMargins[type];
return rect.adjusted(m.left, m.top, -m.right, -m.bottom);
qreal left, top, right, bottom;
q->getContentsMargins(&left, &top, &right, &bottom);
if (type == ItemMargin && (left || top || right || bottom)) {
return rect.adjusted(left, top, -right, -bottom);
} else {
const Margin &m = activeMargins[type];
return rect.adjusted(m.left, m.top, -m.right, -m.bottom);
}
}
QSizeF IconWidgetPrivate::addMargin(const QSizeF &size, MarginType type) const
{
Q_ASSERT(activeMargins);
const Margin &m = activeMargins[type];
return QSizeF(size.width() + m.left + m.right, size.height() + m.top + m.bottom);
qreal left, top, right, bottom;
q->getContentsMargins(&left, &top, &right, &bottom);
if (type == ItemMargin && (left || top || right || bottom)) {
return QSizeF(size.width() + left + right, size.height() + top + bottom);
} else {
const Margin &m = activeMargins[type];
return QSizeF(size.width() + m.left + m.right, size.height() + m.top + m.bottom);
}
}
QSizeF IconWidgetPrivate::subtractMargin(const QSizeF &size, MarginType type) const
{
Q_ASSERT(activeMargins);
const Margin &m = activeMargins[type];
return QSizeF(size.width() - m.left - m.right, size.height() - m.top - m.bottom);
qreal left, top, right, bottom;
q->getContentsMargins(&left, &top, &right, &bottom);
if (type == ItemMargin && (left || top || right || bottom)) {
return QSizeF(size.width() - left - right, size.height() - top - bottom);
} else {
const Margin &m = activeMargins[type];
return QSizeF(size.width() - m.left - m.right, size.height() - m.top - m.bottom);
}
}
QRectF IconWidgetPrivate::actionRect(ActionPosition position) const