X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;ds=sidebyside;f=pv%2Fviews%2Ftrace%2Fcursorpair.cpp;h=0135c45742e83de4cd3b06c5f6668cb57e492004;hb=b571a8e7e0dc3e3b6daa58f27050e76466f006dd;hp=86198c5217a2f1129bc750d6f553f2ee51c6eeea;hpb=641574bcc118be0b6dc3a65039ab3497f9d7241a;p=pulseview.git
diff --git a/pv/views/trace/cursorpair.cpp b/pv/views/trace/cursorpair.cpp
index 86198c5..0135c45 100644
--- a/pv/views/trace/cursorpair.cpp
+++ b/pv/views/trace/cursorpair.cpp
@@ -17,15 +17,18 @@
* along with this program; if not, see .
*/
+#include
+#include
+
+#include
+#include
+
#include "cursorpair.hpp"
#include "pv/util.hpp"
#include "ruler.hpp"
#include "view.hpp"
-#include
-#include
-
using std::max;
using std::make_pair;
using std::min;
@@ -44,6 +47,8 @@ CursorPair::CursorPair(View &view) :
first_(new Cursor(view, 0.0)),
second_(new Cursor(view, 1.0))
{
+ connect(&view_, SIGNAL(hover_point_changed(const QWidget*, QPoint)),
+ this, SLOT(on_hover_point_changed(const QWidget*, QPoint)));
}
bool CursorPair::enabled() const
@@ -110,38 +115,41 @@ void CursorPair::paint_label(QPainter &p, const QRect &rect, bool hover)
if (!enabled())
return;
- const QColor text_color =
- ViewItem::select_text_color(Cursor::FillColor);
-
+ const QColor text_color = ViewItem::select_text_color(Cursor::FillColor);
p.setPen(text_color);
- compute_text_size(p);
- QRectF delta_rect(label_rect(rect));
+ QString text = format_string();
+ text_size_ = p.boundingRect(QRectF(), 0, text).size();
+
+ QRectF delta_rect(label_rect(rect));
const int radius = delta_rect.height() / 2;
- const QRectF text_rect(delta_rect.intersected(
- rect).adjusted(radius, 0, -radius, 0));
- if (text_rect.width() >= text_size_.width()) {
- const int highlight_radius = delta_rect.height() / 2 - 2;
-
- if (selected()) {
- p.setBrush(Qt::transparent);
- p.setPen(highlight_pen());
- p.drawRoundedRect(delta_rect, radius, radius);
- }
-
- p.setBrush(hover ? Cursor::FillColor.lighter() :
- Cursor::FillColor);
- p.setPen(Cursor::FillColor.darker());
+ QRectF text_rect(delta_rect.intersected(rect).adjusted(radius, 0, -radius, 0));
+
+ if (text_rect.width() < text_size_.width()) {
+ text = "...";
+ text_size_ = p.boundingRect(QRectF(), 0, text).size();
+ label_incomplete_ = true;
+ } else
+ label_incomplete_ = false;
+
+ if (selected()) {
+ p.setBrush(Qt::transparent);
+ p.setPen(highlight_pen());
p.drawRoundedRect(delta_rect, radius, radius);
+ }
- delta_rect.adjust(1, 1, -1, -1);
- p.setPen(Cursor::FillColor.lighter());
- p.drawRoundedRect(delta_rect, highlight_radius, highlight_radius);
+ p.setBrush(hover ? Cursor::FillColor.lighter() : Cursor::FillColor);
+ p.setPen(Cursor::FillColor.darker());
+ p.drawRoundedRect(delta_rect, radius, radius);
- p.setPen(text_color);
- p.drawText(text_rect, Qt::AlignCenter | Qt::AlignVCenter,
- format_string());
- }
+ delta_rect.adjust(1, 1, -1, -1);
+ p.setPen(Cursor::FillColor.lighter());
+ const int highlight_radius = delta_rect.height() / 2 - 2;
+ p.drawRoundedRect(delta_rect, highlight_radius, highlight_radius);
+ label_area_ = delta_rect;
+
+ p.setPen(text_color);
+ p.drawText(text_rect, Qt::AlignCenter | Qt::AlignVCenter, text);
}
void CursorPair::paint_back(QPainter &p, ViewItemPaintParams &pp)
@@ -153,10 +161,8 @@ void CursorPair::paint_back(QPainter &p, ViewItemPaintParams &pp)
p.setBrush(QBrush(ViewportFillColor));
const pair offsets(get_cursor_offsets());
- const int l = (int)max(min(
- offsets.first, offsets.second), 0.0f);
- const int r = (int)min(max(
- offsets.first, offsets.second), (float)pp.width());
+ const int l = (int)max(min(offsets.first, offsets.second), 0.0f);
+ const int r = (int)min(max(offsets.first, offsets.second), (float)pp.width());
p.drawRect(l, pp.top(), r - l, pp.height());
}
@@ -167,27 +173,33 @@ QString CursorPair::format_string()
const pv::util::Timestamp diff = abs(second_->time() - first_->time());
const QString s1 = Ruler::format_time_with_distance(
- diff, diff, prefix, view_.time_unit(), view_.tick_precision(), false);
+ diff, diff, prefix, view_.time_unit(), 12, false); /* Always use 12 precision digits */
const QString s2 = util::format_time_si(
1 / diff, pv::util::SIPrefix::unspecified, 4, "Hz", false);
- return QString("%1 / %2").arg(s1).arg(s2);
+ return QString("%1 / %2").arg(s1, s2);
}
-void CursorPair::compute_text_size(QPainter &p)
+pair CursorPair::get_cursor_offsets() const
{
assert(first_);
assert(second_);
- text_size_ = p.boundingRect(QRectF(), 0, format_string()).size();
+ return pair(first_->get_x(), second_->get_x());
}
-pair CursorPair::get_cursor_offsets() const
+void CursorPair::on_hover_point_changed(const QWidget* widget, const QPoint& hp)
{
- assert(first_);
- assert(second_);
+ if (widget != view_.ruler())
+ return;
- return pair(first_->get_x(), second_->get_x());
+ if (!label_incomplete_)
+ return;
+
+ if (label_area_.contains(hp))
+ QToolTip::showText(view_.mapToGlobal(hp), format_string());
+ else
+ QToolTip::hideText(); // TODO Will break other tooltips when there can be others
}
} // namespace trace