* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "view.h"
+#include <QMenu>
+#include <QMouseEvent>
-#include "marginwidget.h"
+#include "view.hpp"
+
+#include "marginwidget.hpp"
+
+#include <pv/widgets/popup.hpp>
+
+using std::shared_ptr;
namespace pv {
namespace view {
MarginWidget::MarginWidget(View &parent) :
QWidget(&parent),
- _view(parent)
+ view_(parent),
+ dragging_(false)
{
setAttribute(Qt::WA_NoSystemBackground, true);
+ setFocusPolicy(Qt::ClickFocus);
+ setMouseTracking(true);
+}
+
+void MarginWidget::show_popup(const shared_ptr<ViewItem> &item)
+{
+ pv::widgets::Popup *const p = item->create_popup(this);
+ if (p)
+ p->show();
+}
+
+void MarginWidget::leaveEvent(QEvent*)
+{
+ mouse_point_ = QPoint(-1, -1);
+ update();
+}
+
+void MarginWidget::contextMenuEvent(QContextMenuEvent *event)
+{
+ const shared_ptr<ViewItem> r = get_mouse_over_item(mouse_point_);
+ if (!r)
+ return;
+
+ QMenu *menu = r->create_context_menu(this);
+ if (menu)
+ menu->exec(event->globalPos());
}
void MarginWidget::clear_selection()
{
+ const auto items = this->items();
+ for (auto &i : items)
+ i->select(false);
+ update();
}
} // namespace view