summaryrefslogtreecommitdiffstats
path: root/profile-widget
diff options
context:
space:
mode:
authorGravatar Lubomir I. Ivanov <neolit123@gmail.com>2015-11-08 15:41:42 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-11-10 09:08:57 -0800
commit003ddc6b52eb2dce06abc95a7c96f90bc40ec6be (patch)
tree5ea1bb351ab3e40bf98e62bda15fa57ea04ee6a7 /profile-widget
parentf0bd39c55103969c3e30df88f51846f70cd6d56f (diff)
downloadsubsurface-003ddc6b52eb2dce06abc95a7c96f90bc40ec6be.tar.gz
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>
Diffstat (limited to 'profile-widget')
-rw-r--r--profile-widget/divetooltipitem.cpp28
1 files changed, 19 insertions, 9 deletions
diff --git a/profile-widget/divetooltipitem.cpp b/profile-widget/divetooltipitem.cpp
index d4818422b..78de4641b 100644
--- a/profile-widget/divetooltipitem.cpp
+++ b/profile-widget/divetooltipitem.cpp
@@ -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();
}