From: Joel Holdsworth Date: Sat, 20 Dec 2014 22:56:35 +0000 (+0000) Subject: MarginWidget: Moved in create_popup X-Git-Tag: pulseview-0.3.0~319 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=786b76785856c6cf8f5916c0b8d76a61695762f9;p=pulseview.git MarginWidget: Moved in create_popup --- diff --git a/pv/view/flag.cpp b/pv/view/flag.cpp index 81cfae87..01d13670 100644 --- a/pv/view/flag.cpp +++ b/pv/view/flag.cpp @@ -61,7 +61,12 @@ QString Flag::get_text() const pv::widgets::Popup* Flag::create_popup(QWidget *parent) { - pv::widgets::Popup *const popup = TimeMarker::create_popup(parent); + using pv::widgets::Popup; + + Popup *const popup = TimeMarker::create_popup(parent); + popup->set_position(parent->mapToGlobal( + point(parent->rect())), Popup::Bottom); + QFormLayout *const form = (QFormLayout*)popup->layout(); QLineEdit *const text_edit = new QLineEdit(popup); diff --git a/pv/view/header.cpp b/pv/view/header.cpp index 77ac1aa8..41dffca1 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -96,19 +96,6 @@ void Header::clear_selection() update(); } -void Header::show_popup(const shared_ptr &item) -{ - using pv::widgets::Popup; - - Popup *const p = item->create_popup(&view_); - if (!p) - return; - - const QPoint pt(width() - BaselineOffset, item->get_visual_y()); - p->set_position(mapToGlobal(pt), Popup::Right); - p->show(); -} - void Header::paintEvent(QPaintEvent*) { // The trace labels are not drawn with the arrows exactly on the diff --git a/pv/view/header.hpp b/pv/view/header.hpp index 10335cf5..48e06a7b 100644 --- a/pv/view/header.hpp +++ b/pv/view/header.hpp @@ -64,8 +64,6 @@ private: void clear_selection(); - void show_popup(const std::shared_ptr &item); - private: void paintEvent(QPaintEvent *event); diff --git a/pv/view/marginwidget.cpp b/pv/view/marginwidget.cpp index f8302f64..6b646832 100644 --- a/pv/view/marginwidget.cpp +++ b/pv/view/marginwidget.cpp @@ -22,6 +22,10 @@ #include "marginwidget.hpp" +#include + +using std::shared_ptr; + namespace pv { namespace view { @@ -35,6 +39,13 @@ MarginWidget::MarginWidget(View &parent) : setMouseTracking(true); } +void MarginWidget::show_popup(const shared_ptr &item) +{ + pv::widgets::Popup *const p = item->create_popup(this); + if (p) + p->show(); +} + void MarginWidget::clear_selection() { } diff --git a/pv/view/marginwidget.hpp b/pv/view/marginwidget.hpp index 6e98e4b0..5b6631af 100644 --- a/pv/view/marginwidget.hpp +++ b/pv/view/marginwidget.hpp @@ -21,6 +21,8 @@ #ifndef PULSEVIEW_PV_MARGINWIDGET_H #define PULSEVIEW_PV_MARGINWIDGET_H +#include + #include #include @@ -28,6 +30,7 @@ namespace pv { namespace view { class View; +class ViewItem; class MarginWidget : public QWidget { @@ -43,6 +46,13 @@ public: */ virtual QSize extended_size_hint() const = 0; +protected: + /** + * Shows the popup of a the specified @c ViewItem . + * @param item The item to show the popup for. + */ + void show_popup(const std::shared_ptr &item); + public Q_SLOTS: virtual void clear_selection(); diff --git a/pv/view/ruler.cpp b/pv/view/ruler.cpp index 47da23a8..7fa99875 100644 --- a/pv/view/ruler.cpp +++ b/pv/view/ruler.cpp @@ -29,7 +29,6 @@ #include "view.hpp" #include -#include using namespace Qt; @@ -199,15 +198,8 @@ void Ruler::mouseReleaseEvent(QMouseEvent *) { using pv::widgets::Popup; - if (!dragging_ && mouse_down_item_) { - Popup *const p = mouse_down_item_->create_popup(&view_); - if (p) { - const QPoint arrpos(mouse_down_item_->get_x(), - height() - ViewItem::HighlightRadius); - p->set_position(mapToGlobal(arrpos), Popup::Bottom); - p->show(); - } - } + if (!dragging_ && mouse_down_item_) + show_popup(mouse_down_item_); dragging_ = false; mouse_down_item_.reset(); diff --git a/pv/view/timemarker.cpp b/pv/view/timemarker.cpp index 5b21bfd8..894f023b 100644 --- a/pv/view/timemarker.cpp +++ b/pv/view/timemarker.cpp @@ -76,7 +76,7 @@ float TimeMarker::get_x() const QPoint TimeMarker::point(const QRect &rect) const { - return QPoint(get_x(), rect.right()); + return QPoint(get_x(), rect.bottom()); } QRectF TimeMarker::label_rect(const QRectF &rect) const @@ -159,6 +159,9 @@ pv::widgets::Popup* TimeMarker::create_popup(QWidget *parent) using pv::widgets::Popup; Popup *const popup = new Popup(parent); + popup->set_position(parent->mapToGlobal( + point(parent->rect())), Popup::Bottom); + QFormLayout *const form = new QFormLayout(popup); popup->setLayout(form); diff --git a/pv/view/trace.cpp b/pv/view/trace.cpp index df5a954b..bf1c4ae5 100644 --- a/pv/view/trace.cpp +++ b/pv/view/trace.cpp @@ -134,6 +134,8 @@ pv::widgets::Popup* Trace::create_popup(QWidget *parent) using pv::widgets::Popup; popup_ = new Popup(parent); + popup_->set_position(parent->mapToGlobal( + point(parent->rect())), Popup::Right); create_popup_form();