QString Flag::get_text() const
{
- const shared_ptr<TimeItem> ref_item = view_.get_reference_time_item();
- if (ref_item == nullptr || ref_item.get() == this) {
- return text_;
- } else {
- return Ruler::format_time_with_distance(
+ QString s;
+
+ const shared_ptr<TimeItem> ref_item = view_.ruler()->get_reference_item();
+
+ if (!ref_item || (ref_item.get() == this))
+ s = text_;
+ else
+ s = Ruler::format_time_with_distance(
ref_item->time(), ref_item->delta(time_),
view_.tick_prefix(), view_.time_unit(), view_.tick_precision());
- }
+
+ return s;
}
QRectF Flag::label_rect(const QRectF &rect) const
{
- const shared_ptr<TimeItem> ref_item = view_.get_reference_time_item();
- if (ref_item == nullptr || ref_item.get() == this) {
- return TimeMarker::label_rect(rect);
+ QRectF r;
+
+ const shared_ptr<TimeItem> ref_item = view_.ruler()->get_reference_item();
+ if (!ref_item || (ref_item.get() == this)) {
+ r = TimeMarker::label_rect(rect);
} else {
// TODO: Remove code duplication between here and cursor.cpp
const float x = get_x();
const QSizeF label_size(
text_size.width() + LabelPadding.width() * 2,
text_size.height() + LabelPadding.height() * 2);
- const float top = rect.height() - label_size.height() -
- TimeMarker::ArrowSize - 0.5f;
+
const float height = label_size.height();
+ const float top =
+ rect.height() - label_size.height() - TimeMarker::ArrowSize - 0.5f;
const pv::util::Timestamp& delta = ref_item->delta(time_);
if (delta >= 0)
- return QRectF(x, top, label_size.width(), height);
+ r = QRectF(x, top, label_size.width(), height);
else
- return QRectF(x - label_size.width(), top, label_size.width(), height);
+ r = QRectF(x - label_size.width(), top, label_size.width(), height);
}
+
+ return r;
}
pv::widgets::Popup* Flag::create_popup(QWidget *parent)
#include <extdef.h>
-#include <QApplication>
#include <QFontMetrics>
#include <QMenu>
#include <QMouseEvent>
void Ruler::item_hover(const shared_ptr<ViewItem> &item, QPoint pos)
{
- Q_UNUSED(pos);
+ (void)pos;
+
hover_item_ = dynamic_pointer_cast<TimeItem>(item);
}
-shared_ptr<TimeItem> Ruler::get_reference_item()
+shared_ptr<TimeItem> Ruler::get_reference_item() const
{
if (mouse_modifiers_ & Qt::ShiftModifier)
return nullptr;
- if (hover_item_ != nullptr)
+ if (hover_item_)
return hover_item_;
- shared_ptr<TimeItem> found(nullptr);
+ shared_ptr<TimeItem> ref_item;
const vector< shared_ptr<TimeItem> > items(view_.time_items());
+
for (auto i = items.rbegin(); i != items.rend(); i++) {
if ((*i)->enabled() && (*i)->selected()) {
- if (found == nullptr)
- found = *i;
- else
- return nullptr; // Return null if multiple items are selected
+ if (!ref_item)
+ ref_item = *i;
+ else {
+ // Return nothing if multiple items are selected
+ ref_item.reset();
+ break;
+ }
}
}
- return found;
+ return ref_item;
}
shared_ptr<ViewItem> Ruler::get_mouse_over_item(const QPoint &pt)
{
const vector< shared_ptr<TimeItem> > items(view_.time_items());
+
for (auto i = items.rbegin(); i != items.rend(); i++)
if ((*i)->enabled() && (*i)->label_rect(rect()).contains(pt))
return *i;
+
return nullptr;
}
pv::util::Timestamp get_ruler_time_from_absolute_time(const pv::util::Timestamp& abs_time) const;
pv::util::Timestamp get_absolute_time_from_ruler_time(const pv::util::Timestamp& ruler_time) const;
- shared_ptr<TimeItem> get_reference_item();
+ shared_ptr<TimeItem> get_reference_item() const;
protected:
virtual void contextMenuEvent(QContextMenuEvent *event) override;
view_.scale());
}
+const pv::util::Timestamp TimeItem::delta(const pv::util::Timestamp& other) const
+{
+ return other - time();
+}
+
} // namespace trace
} // namespace views
} // namespace pv
virtual float get_x() const = 0;
- virtual const pv::util::Timestamp delta(const pv::util::Timestamp& other) const = 0;
+ virtual const pv::util::Timestamp delta(const pv::util::Timestamp& other) const;
/**
* Drags the item to a delta relative to the drag point.
return roundf(((time_ - view_.offset()) / view_.scale()).convert_to<float>()) + 0.5f;
}
-const pv::util::Timestamp TimeMarker::delta(const pv::util::Timestamp& other) const
-{
- return other - time_;
-}
-
QPoint TimeMarker::drag_point(const QRect &rect) const
{
(void)rect;
float get_x() const override;
- virtual const pv::util::Timestamp delta(const pv::util::Timestamp& other) const override;
-
/**
* Gets the arrow-tip point of the time marker.
* @param rect the rectangle of the ruler area.
void TriggerMarker::set_time(const pv::util::Timestamp& time)
{
time_ = time;
+
view_.time_item_appearance_changed(true, true);
}
return ((time_ - view_.offset()) / view_.scale()).convert_to<float>();
}
-const pv::util::Timestamp TriggerMarker::delta(const pv::util::Timestamp& other) const
-{
- return other - time_;
-}
-
QPoint TriggerMarker::drag_point(const QRect &rect) const
{
(void)rect;
float get_x() const override;
- virtual const pv::util::Timestamp delta(const pv::util::Timestamp& other) const override;
-
/**
* Gets the arrow-tip point of the time marker.
* @param rect the rectangle of the ruler area.
// Note: Place defaults in View::reset_view_state(), not here
splitter_(new QSplitter()),
- header_was_shrunk_(false), // The splitter remains unchanged after a reset, so this goes here
+ header_was_shrunk_(false), // The splitter remains unchanged after a reset, so this goes here
sticky_scrolling_(false) // Default setting is set in MainWindow::setup_ui()
{
QVBoxLayout *root_layout = new QVBoxLayout(this);
splitter_->setHandleWidth(1); // Don't show a visible rubber band
splitter_->setCollapsible(0, false); // Prevent the header from collapsing
splitter_->setCollapsible(1, false); // Prevent the traces from collapsing
- splitter_->setStretchFactor(0, 0); // Prevent the panes from being resized
- splitter_->setStretchFactor(1, 1); // when the entire view is resized
+ splitter_->setStretchFactor(0, 0); // Prevent the panes from being resized
+ splitter_->setStretchFactor(1, 1); // when the entire view is resized
splitter_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
viewport_->installEventFilter(this);
return items;
}
-shared_ptr<TimeItem> View::get_reference_time_item()
-{
- return ruler_->get_reference_item();
-}
-
double View::scale() const
{
return scale_;
const Timestamp start_time = s->start_time();
left_time = left_time ?
min(*left_time, start_time) :
- start_time;
+ start_time;
right_time = right_time ?
max(*right_time, start_time + d->max_sample_count() / samplerate) :
- start_time + d->max_sample_count() / samplerate;
+ start_time + d->max_sample_count() / samplerate;
}
}
shared_ptr<Flag> View::add_flag(const Timestamp& time)
{
- shared_ptr<Flag> flag = make_shared<Flag>(
- *this, time, QString("%1").arg(next_flag_text_));
+ shared_ptr<Flag> flag =
+ make_shared<Flag>(*this, time, QString("%1").arg(next_flag_text_));
flags_.push_back(flag);
next_flag_text_ = (next_flag_text_ >= 'Z') ? 'A' :
*/
vector< shared_ptr<TimeItem> > time_items() const;
- shared_ptr<TimeItem> get_reference_time_item();
-
/**
* Returns the view time scale in seconds per pixel.
*/
void ViewWidget::keyReleaseEvent(QKeyEvent *event)
{
// Update mouse_modifiers_ also if modifiers change, but pointer doesn't move
- if (mouse_point_.x() >= 0 && mouse_point_.y() >= 0) // mouse is inside
+ if ((mouse_point_.x() >= 0) && (mouse_point_.y() >= 0)) // mouse is inside
mouse_modifiers_ = event->modifiers();
update();
}
void ViewWidget::keyPressEvent(QKeyEvent *event)
{
// Update mouse_modifiers_ also if modifiers change, but pointer doesn't move
- if (mouse_point_.x() >= 0 && mouse_point_.y() >= 0) // mouse is inside
+ if ((mouse_point_.x() >= 0) && (mouse_point_.y() >= 0)) // mouse is inside
mouse_modifiers_ = event->modifiers();
update();
}
protected:
pv::views::trace::View &view_;
QPoint mouse_point_;
- Qt::KeyboardModifiers mouse_modifiers_;
QPoint mouse_down_point_;
pv::util::Timestamp mouse_down_offset_;
shared_ptr<ViewItem> mouse_down_item_;
+
+ /// Keyboard modifiers that were active when mouse was last moved or clicked
+ Qt::KeyboardModifiers mouse_modifiers_;
+
bool item_dragging_;
};