diff options
author | Antti Hölttä <AHoelttae@luxoft.com> | 2019-02-19 15:36:39 +0100 |
---|---|---|
committer | Antti Hölttä <AHoelttae@luxoft.com> | 2019-03-18 16:42:31 +0100 |
commit | 8489f36322c585ec78199e6eb183000c74afae19 (patch) | |
tree | 8989b7cf6275b8b6cbffaa3b44467f5bd4ecdbf5 /plugin/redirect.cpp | |
parent | a5120f26d509a3464c79404de84e9428b8ddc690 (diff) |
Add redirect feature for manually fine tuning the cursor's movement
Cursornavigation now has a property redirects, that allows defining
exceptions to the navigation behaviour. A redirect allows defining
a starting and an ending angle and a target object.
If the move command's direction falls between the limits, the algorithm
is bypassed and cursor is moved to the target object.
Diffstat (limited to 'plugin/redirect.cpp')
-rw-r--r-- | plugin/redirect.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/plugin/redirect.cpp b/plugin/redirect.cpp new file mode 100644 index 0000000..3c33571 --- /dev/null +++ b/plugin/redirect.cpp @@ -0,0 +1,68 @@ +#include "redirect.h" +#include <QQuickItem> +#include <QtMath> +#include "inputtypes.h" + +Redirect::Redirect(QObject *parent) +:QObject(parent) +,m_start(-1) +,m_end(-1) +,m_target(nullptr) +{ +} + +Redirect::~Redirect() +{ +} + +qreal Redirect::start() const +{ + return m_start; +} + +qreal Redirect::end() const +{ + return m_end; +} + +QQuickItem *Redirect::target() const +{ + return m_target; +} + +void Redirect::setStart(qreal start) +{ + m_start = start; + m_startR = CursorNavigationCommand::fitAngle(qDegreesToRadians(start)); +} + +void Redirect::setEnd(qreal end) +{ + m_end = end; + m_endR = CursorNavigationCommand::fitAngle(qDegreesToRadians(end)); +} + +void Redirect::setTarget(QQuickItem *target) +{ + if (m_target) { + disconnect(m_target, &QObject::destroyed, this, &Redirect::onTargetDestroyed); + } + m_target = target; + if (m_target) { + connect(m_target, &QObject::destroyed, this, &Redirect::onTargetDestroyed); + } +} + +bool Redirect::angleIsIncluded(qreal angle) +{ + if (m_startR > m_endR) + return angle >= m_startR || angle <= m_endR; + else + return angle >= m_startR && angle <= m_endR; +} + +void Redirect::onTargetDestroyed() +{ + m_target = nullptr; +} + |