[PATCH] divetooltipitem.cpp: prettify the tooltip bounds and padding

Lubomir I. Ivanov neolit123 at gmail.com
Sun Nov 8 05:41:42 PST 2015


From: "Lubomir I. Ivanov" <neolit123 at gmail.com>

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 at gmail.com>
---

let me know if always showing the full graph is an issue...

one alternative is to hard-show/hide the graph when there are
no entries from get_plot_details_new().
---
 profile-widget/divetooltipitem.cpp | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/profile-widget/divetooltipitem.cpp b/profile-widget/divetooltipitem.cpp
index d481842..78de464 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();
 }
 
-- 
1.7.11.msysgit.0



More information about the subsurface mailing list