* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
+#include <algorithm>
+#include <cassert>
+
+#include <QDebug>
+#include <QToolTip>
+
#include "cursorpair.hpp"
#include "pv/util.hpp"
#include "ruler.hpp"
#include "view.hpp"
-#include <algorithm>
-#include <cassert>
-
using std::max;
using std::make_pair;
using std::min;
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
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)
p.setBrush(QBrush(ViewportFillColor));
const pair<float, float> 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());
}
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, s2);
}
-void CursorPair::compute_text_size(QPainter &p)
+pair<float, float> CursorPair::get_cursor_offsets() const
{
assert(first_);
assert(second_);
- text_size_ = p.boundingRect(QRectF(), 0, format_string()).size();
+ return pair<float, float>(first_->get_x(), second_->get_x());
}
-pair<float, float> 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<float, float>(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
cursors_ = make_shared<CursorPair>(*this);
next_flag_text_ = 'A';
trigger_markers_.clear();
+ hover_widget_ = nullptr;
hover_point_ = QPoint(-1, -1);
scroll_needs_defaults_ = true;
saved_v_offset_ = 0;
return hover_point_;
}
+const QWidget* View::hover_widget() const
+{
+ return hover_widget_;
+}
+
int64_t View::get_nearest_level_change(const QPoint &p)
{
// Is snapping disabled?
const QEvent::Type type = event->type();
if (type == QEvent::MouseMove) {
+ if (object)
+ hover_widget_ = qobject_cast<QWidget*>(object);
+
const QMouseEvent *const mouse_event = (QMouseEvent*)event;
if (object == viewport_)
hover_point_ = mouse_event->pos();
else if (object == ruler_)
- // Adjust the hover point's y coordinate so that it's relative to
- // the top of the viewport. The result may be negative.
- hover_point_ = QPoint(mouse_event->pos().x(),
- mouse_event->pos().y() - ruler_->sizeHint().height());
+ hover_point_ = mouse_event->pos();
else if (object == header_)
hover_point_ = QPoint(0, mouse_event->y());
else
{
// Determine signal that the mouse cursor is hovering over
signal_under_mouse_cursor_.reset();
- for (shared_ptr<Signal> s : signals_) {
- const pair<int, int> extents = s->v_extents();
- const int top = s->get_visual_y() + extents.first;
- const int btm = s->get_visual_y() + extents.second;
- if ((hover_point_.y() >= top) && (hover_point_.y() <= btm)
- && s->base()->enabled())
- signal_under_mouse_cursor_ = s;
+ if (hover_widget_ == this) {
+ for (shared_ptr<Signal> s : signals_) {
+ const pair<int, int> extents = s->v_extents();
+ const int top = s->get_visual_y() + extents.first;
+ const int btm = s->get_visual_y() + extents.second;
+ if ((hover_point_.y() >= top) && (hover_point_.y() <= btm)
+ && s->base()->enabled())
+ signal_under_mouse_cursor_ = s;
+ }
}
// Update all trace tree items
r->hover_point_changed(hover_point_);
// Notify any other listeners
- hover_point_changed(hover_point_);
+ hover_point_changed(hover_widget_, hover_point_);
}
void View::row_item_appearance_changed(bool label, bool content)