]> sigrok.org Git - pulseview.git/blame - pv/view/viewwidget.cpp
ViewWidget: Moved in drag_items
[pulseview.git] / pv / view / viewwidget.cpp
CommitLineData
40aca27e
JH
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2014 Joel Holdsworth <joel@airwebreathe.org.uk>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
b434cbaf
JH
21#include <algorithm>
22
23#include "rowitem.hpp"
24#include "timeitem.hpp"
40aca27e
JH
25#include "view.hpp"
26#include "viewwidget.hpp"
27
b434cbaf
JH
28using std::any_of;
29using std::shared_ptr;
30using std::vector;
31
40aca27e
JH
32namespace pv {
33namespace view {
34
35ViewWidget::ViewWidget(View &parent) :
36 QWidget(&parent),
37 view_(parent)
38{
39}
40
b434cbaf
JH
41bool ViewWidget::accept_drag() const
42{
43 const vector< shared_ptr<TimeItem> > items(view_.time_items());
44
45 const bool any_row_items_selected = any_of(view_.begin(), view_.end(),
46 [](const shared_ptr<RowItem> &r) { return r->selected(); });
47
48 const bool any_time_items_selected = any_of(items.begin(), items.end(),
49 [](const shared_ptr<TimeItem> &i) { return i->selected(); });
50
51 if (any_row_items_selected && !any_time_items_selected)
52 {
53 // Check all the drag items share a common owner
54 RowItemOwner *item_owner = nullptr;
55 for (shared_ptr<RowItem> r : view_)
56 if (r->dragging()) {
57 if (!item_owner)
58 item_owner = r->owner();
59 else if(item_owner != r->owner())
60 return false;
61 }
62
63 return true;
64 }
65 else if (any_time_items_selected && !any_row_items_selected)
66 {
67 return true;
68 }
69
70 return false;
71}
72
1dffa582
JH
73void ViewWidget::drag_items(const QPoint &delta)
74{
75 // Drag the row items
76 RowItemOwner *item_owner = nullptr;
77 for (std::shared_ptr<RowItem> r : view_)
78 if (r->dragging()) {
79 item_owner = r->owner();
80 r->drag_by(delta);
81
82 // Ensure the trace is selected
83 r->select();
84 }
85
86 if (item_owner) {
87 item_owner->restack_items();
88 for (const auto &r : *item_owner)
89 r->animate_to_layout_v_offset();
90 }
91
92 // Drag the time items
93 const vector< shared_ptr<TimeItem> > items(view_.time_items());
94 for (auto &i : items)
95 if (i->dragging())
96 i->drag_by(delta);
97}
98
40aca27e
JH
99} // namespace view
100} // namespace pv