From 0b3d6be461c7016fc13b714ab752c2d3116b3bc9 Mon Sep 17 00:00:00 2001 From: Joern Date: Sun, 22 Feb 2015 12:32:54 +0100 Subject: [PATCH 1/2] TreeMap - UI nits/improvements ... draw Level 1 text at the end to have full contrast (not overlapped by level 2 brush) ... dynamically choose font size for Level 2 texts from 4 options (based on available space in rectangle) - easier readable on big screen - still usable on small screen --- src/TreeMapPlot.cpp | 60 +++++++++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/src/TreeMapPlot.cpp b/src/TreeMapPlot.cpp index 8cf0fa8ad..d7002d83b 100644 --- a/src/TreeMapPlot.cpp +++ b/src/TreeMapPlot.cpp @@ -113,14 +113,10 @@ TreeMapPlot::paintEvent(QPaintEvent *) root->rect.width()-8, root->rect.height()-8); - // first level - font.setPointSize(18); - painter.setFont(font); + // first level - rectangles, but not text yet pen.setWidth(5); pen.setColor(color); painter.setPen(pen); - color = GCColor::invertColor(color); - //color.setAlpha(127); int n=1; QColor cHSV, cRGB; @@ -132,36 +128,68 @@ TreeMapPlot::paintEvent(QPaintEvent *) brush.setColor(cRGB); painter.setBrush(brush); painter.drawRect(first->rect); - painter.drawText(first->rect, - Qt::AlignVCenter|Qt::AlignHCenter, - first->name); } - // second level + // second level - overlay rectangles - with text + QPen textPen(Qt::white); font.setPointSize(8); painter.setFont(font); - pen.setWidth(1); - pen.setColor(Qt::lightGray); - painter.setPen(pen); + + // overlay colors color = Qt::darkGray; color.setAlpha(127); brush.setColor(color); QColor hcolor(Qt::lightGray); hcolor.setAlpha(127); QBrush hbrush(hcolor); - - foreach (TreeMap *first, root->children) + QRect textRect; + QRect demandedTextRect; + foreach (TreeMap *first, root->children) { foreach (TreeMap *second, first->children) { if (second == highlight) painter.setBrush(hbrush); else painter.setBrush(brush); + painter.setPen(Qt::NoPen); painter.drawRect(second->rect.x()+2, second->rect.y()+2, second->rect.width()-4, second->rect.height()-4); - painter.setPen(pen); - painter.drawText(second->rect, Qt::AlignTop|Qt::AlignLeft, second->name); + + textRect.setRect(second->rect.x()+2, second->rect.y()+2,second->rect.width()-4, second->rect.height()-4 ); + // determine font size based on size of window and length of text / try to apply 3 different font sizes - then fall back to "8" + font.setPointSize(14); + painter.setFont(font); + painter.setPen(textPen); + demandedTextRect = painter.boundingRect(textRect, Qt::AlignTop|Qt::AlignLeft, second->name); + if (!textRect.contains(demandedTextRect)) { + font.setPointSize(12); + painter.setFont(font); + demandedTextRect = painter.boundingRect(textRect, Qt::AlignTop|Qt::AlignLeft, second->name); + if (!textRect.contains(demandedTextRect)) { + font.setPointSize(10); + painter.setFont(font); + demandedTextRect = painter.boundingRect(textRect, Qt::AlignTop|Qt::AlignLeft, second->name); + if (!textRect.contains(demandedTextRect)) { + // fall back to use smallest useful font / even if text may be clipped + font.setPointSize(8); + painter.setFont(font); + } + } + } + painter.drawText(textRect, Qt::AlignTop|Qt::AlignLeft, second->name); } + } + + // paint the text for level 1 now - to not overlap it with gray/alpha coming from level 2 drawing overlay + textPen.setColor(Qt::black); + font.setPointSize(18); + painter.setFont(font); + painter.setPen(textPen); + foreach (TreeMap *first, root->children) { + painter.drawText(first->rect, + Qt::AlignVCenter|Qt::AlignHCenter, + first->name); + } } bool From 5221e4eb2aa753397f58c9fcec066c191351e67c Mon Sep 17 00:00:00 2001 From: Joern Date: Sun, 22 Feb 2015 13:07:17 +0100 Subject: [PATCH 2/2] TreeMap/LTM Popup - Variable not filled ... counter variable not filled after moving from rides to activities --- src/TreeMapWindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TreeMapWindow.cpp b/src/TreeMapWindow.cpp index a9e90e4b9..a5cd14457 100644 --- a/src/TreeMapWindow.cpp +++ b/src/TreeMapWindow.cpp @@ -304,7 +304,7 @@ TreeMapWindow::cellClicked(QString f1, QString f2) const RideMetricFactory &factory = RideMetricFactory::instance(); const RideMetric *metric = factory.rideMetric(settings.symbol); - ltmPopup->setData(spec, metric, QString(tr("%1 activities"))); + ltmPopup->setData(spec, metric, QString(tr("%1 activities")).arg(count)); popup->show(); }