mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
divetooltipitem.cpp: prettify the tooltip bounds and padding
When the tooltip is expanded, not enough padding is present right from the text and bottom from it, making the tooltip border appear very close to the text. When the tooltip is collapsed (no time entries) it clips the graph/pixmap which makes the graph bottom left corner appear to be outside of the tooltip, mainly because of the white border of the tooltip background and the background rounding. To prevent these visual artifacts and to prettify the tooltip this patch: - makes the rounding 8 instead of 10 of the background rectangle - doubles the padding left and right from the pixmap (the above two pretty much move the pixmap bottom left corner away from the rounded bottom left edge of the tooltip background) - add more padding right and bottom from the text - never reduce the height of the tooltip to be smaller than the graph/pixmap height. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
f0bd39c551
commit
003ddc6b52
1 changed files with 19 additions and 9 deletions
|
@ -32,10 +32,11 @@ void ToolTipItem::addToolTip(const QString &toolTip, const QIcon &icon, const QP
|
|||
} else if (!pixmap.isNull()) {
|
||||
iconItem->setPixmap(pixmap);
|
||||
}
|
||||
iconItem->setPos(iconMetrics.spacing, yValue);
|
||||
const int sp2 = iconMetrics.spacing * 2;
|
||||
iconItem->setPos(sp2, yValue);
|
||||
|
||||
QGraphicsSimpleTextItem *textItem = new QGraphicsSimpleTextItem(toolTip, this);
|
||||
textItem->setPos(iconMetrics.spacing + iconMetrics.sz_small + iconMetrics.spacing, yValue);
|
||||
textItem->setPos(sp2 + iconMetrics.sz_small + sp2, yValue);
|
||||
textItem->setBrush(QBrush(Qt::white));
|
||||
textItem->setFlag(ItemIgnoresTransformations);
|
||||
toolTips.push_back(qMakePair(iconItem, textItem));
|
||||
|
@ -100,14 +101,23 @@ void ToolTipItem::expand()
|
|||
height += sRect.height();
|
||||
}
|
||||
|
||||
/* Left padding, Icon Size, space, right padding */
|
||||
width += iconMetrics.spacing + iconMetrics.sz_small + iconMetrics.spacing + iconMetrics.spacing;
|
||||
const int sp2 = iconMetrics.spacing * 2;
|
||||
// pixmap left padding, icon, pixmap right padding, right padding */
|
||||
width += sp2 + iconMetrics.sz_small + sp2 + sp2 * 2;
|
||||
// bottom padding
|
||||
height += sp2;
|
||||
|
||||
if (width < title->boundingRect().width() + iconMetrics.spacing * 2)
|
||||
width = title->boundingRect().width() + iconMetrics.spacing * 2;
|
||||
|
||||
if (height < iconMetrics.sz_small)
|
||||
// clip the tooltip width
|
||||
if (width < title->boundingRect().width() + sp2)
|
||||
width = title->boundingRect().width() + sp2;
|
||||
// clip the height
|
||||
if (entryToolTip.first) {
|
||||
const int minH = entryToolTip.first->y() + entryToolTip.first->pixmap().height() + sp2;
|
||||
if (height < minH)
|
||||
height = minH;
|
||||
} else if (height < iconMetrics.sz_small) {
|
||||
height = iconMetrics.sz_small;
|
||||
}
|
||||
|
||||
nextRectangle.setWidth(width);
|
||||
nextRectangle.setHeight(height);
|
||||
|
@ -195,7 +205,7 @@ void ToolTipItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio
|
|||
painter->setClipRect(option->rect);
|
||||
painter->setPen(pen());
|
||||
painter->setBrush(brush());
|
||||
painter->drawRoundedRect(rect(), 10, 10, Qt::AbsoluteSize);
|
||||
painter->drawRoundedRect(rect(), 8, 8, Qt::AbsoluteSize);
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue