Skip to content

Commit 8a745c8

Browse files
committed
ui: work on improving drag and drop magnetic behaviour
1 parent dc29b2f commit 8a745c8

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

src/plugins/score-plugin-scenario/Scenario/Application/Drops/ScenarioDropHandler.cpp

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,28 @@ MagneticStates magneticStates(
1717
const auto& scenario = pres.model();
1818

1919
// Check if we keep the current magnetism
20-
if(cur.horizontal)
21-
{
22-
const auto state_date = scenario.events.at(cur.horizontal->eventId()).date();
23-
24-
const double rel_y_distance = std::abs(cur.horizontal->heightPercentage() - pt.y);
25-
const double abs_y_distance = rel_y_distance * pres.view().height();
26-
27-
if(abs_y_distance < magnetic && state_date < pt.date)
28-
{
29-
return {cur.horizontal, cur.vertical, true};
30-
}
31-
}
32-
else if(cur.vertical)
33-
{
34-
auto cur_date = Scenario::parentEvent(*cur.vertical, scenario).date();
35-
const double abs_x_distance
36-
= std::abs((cur_date.impl - pt.date.impl) / pres.zoomRatio());
37-
if(abs_x_distance < magnetic)
38-
{
39-
return {cur.horizontal, cur.vertical, true};
40-
}
41-
}
20+
// if(cur.horizontal)
21+
// {
22+
// const auto state_date = scenario.events.at(cur.horizontal->eventId()).date();
23+
24+
// const double rel_y_distance = std::abs(cur.horizontal->heightPercentage() - pt.y);
25+
// const double abs_y_distance = rel_y_distance * pres.view().height();
26+
27+
// if(abs_y_distance < magnetic && state_date < pt.date)
28+
// {
29+
// return {cur.horizontal, cur.vertical, true};
30+
// }
31+
// }
32+
// else if(cur.vertical)
33+
// {
34+
// auto cur_date = Scenario::parentEvent(*cur.vertical, scenario).date();
35+
// const double abs_x_distance
36+
// = std::abs((cur_date.impl - pt.date.impl) / pres.zoomRatio());
37+
// if(abs_x_distance < magnetic)
38+
// {
39+
// return {cur.horizontal, cur.vertical, true};
40+
// }
41+
// }
4242

4343
EventModel& start_ev = scenario.startEvent();
4444
SCORE_ASSERT(!start_ev.states().empty());
@@ -57,14 +57,18 @@ MagneticStates magneticStates(
5757

5858
StateModel* min_y_state = start_st;
5959
double min_y_distance = std::numeric_limits<double>::max();
60+
StateModel* closest_x_y_state = start_st;
61+
QPointF closest_x_y_distance
62+
= {std::numeric_limits<double>::max(), std::numeric_limits<double>::max()};
63+
6064
for(auto& state : scenario.states)
6165
{
6266
const auto state_date = eventDates[state.eventId()];
6367

6468
if(state_date >= pt_msec)
6569
continue;
6670

67-
const TimeVal rel_x_distance{std::abs(state_date.impl - pt.date.impl)};
71+
const TimeVal rel_x_distance{pt.date.impl - state_date.impl};
6872
const double abs_x_distance = rel_x_distance.toPixels(pres.zoomRatio());
6973

7074
const double rel_y_distance = std::abs(state.heightPercentage() - pt.y);
@@ -86,11 +90,11 @@ MagneticStates magneticStates(
8690
eventDates.clear();
8791
if(min_x_distance < min_y_distance)
8892
{
89-
return {nullptr, min_x_state, min_x_distance < magnetic};
93+
return {nullptr, min_x_state, true};
9094
}
9195
else
9296
{
93-
return {min_y_state, nullptr, min_y_distance < magnetic};
97+
return {min_y_state, nullptr, true};
9498
}
9599
}
96100

0 commit comments

Comments
 (0)