2 #include <Process/Focus/FocusDispatcher.hpp>
3 #include <Process/ProcessContext.hpp>
5 #include <score/tools/Bind.hpp>
7 #include <QGuiApplication>
12 template <
typename Tool_T,
typename ToolPalette_T,
typename Context_T,
typename Input_T>
17 const Input_T& input, ToolPalette_T& palette,
const Context_T& context)
20 , m_currentTool{palette.editionSettings().tool()}
22 auto screens = QGuiApplication::screens();
25 m_frameTime = 1000000. / screens.front()->refreshRate();
27 using EditionSettings_T
28 = std::remove_reference_t<decltype(palette.editionSettings())>;
29 con(palette.editionSettings(), &EditionSettings_T::toolChanged,
this,
30 &ToolPaletteInputDispatcher::on_toolChanged);
31 con(input, &Input_T::pressed,
this, &ToolPaletteInputDispatcher::on_pressed);
32 con(input, &Input_T::moved,
this, &ToolPaletteInputDispatcher::on_moved);
33 con(input, &Input_T::released,
this, &ToolPaletteInputDispatcher::on_released);
34 con(input, &Input_T::escPressed,
this, &ToolPaletteInputDispatcher::on_cancel);
37 void on_toolChanged(Tool_T t)
39 m_palette.desactivate(m_currentTool);
40 m_palette.activate(t);
44 m_palette.on_cancel();
45 m_prev = std::chrono::steady_clock::now();
46 m_palette.on_pressed(m_currentPoint);
50 void on_pressed(QPointF p)
54 m_context.context.focusDispatcher.focus(&m_context.presenter);
57 m_prev = std::chrono::steady_clock::now();
58 m_palette.on_pressed(p);
62 void on_moved(QPointF p)
64 using namespace std::literals::chrono_literals;
65 const auto t = std::chrono::steady_clock::now();
66 if(t - m_prev < std::chrono::microseconds((int64_t)m_frameTime))
71 m_palette.on_moved(p);
75 void on_released(QPointF p)
80 m_palette.on_released(p);
87 m_palette.on_cancel();
91 ToolPalette_T& m_palette;
92 const Context_T& m_context;
93 QPointF m_currentPoint;
96 std::chrono::steady_clock::time_point m_prev;
97 QPointF m_elapsedPoint;
99 qreal m_frameTime{16666};
100 bool m_running =
false;
Definition: LayerPresenter.hpp:34