diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-09-05 18:24:01 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-09-05 18:24:01 +0200 |
commit | 9e63b4ecafcb66c275760cd28d2cfb0d258a474e (patch) | |
tree | bde33bb3e4d3c576637709f056ca994372d9a588 /spline-widget/spline-widget.cpp | |
parent | b77a3539a46f9ac8fc06ee701e00512aac4c7550 (diff) |
spline-widget: stop dragging when alt-tabbing away
Unfortunately now spline widgets grab keyboard focus. Qt doesn't seem to have a
better way to detect whether some other application gained focus.
Diffstat (limited to 'spline-widget/spline-widget.cpp')
-rw-r--r-- | spline-widget/spline-widget.cpp | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/spline-widget/spline-widget.cpp b/spline-widget/spline-widget.cpp index d4e01189..ed07419e 100644 --- a/spline-widget/spline-widget.cpp +++ b/spline-widget/spline-widget.cpp @@ -33,6 +33,8 @@ spline_widget::spline_widget(QWidget *parent) : { update_range(); setMouseTracking(true); + setFocusPolicy(Qt::ClickFocus); + setCursor(Qt::ArrowCursor); } spline_widget::~spline_widget() @@ -280,7 +282,6 @@ void spline_widget::mousePressEvent(QMouseEvent *e) points_t points = _config->getPoints(); if (e->button() == Qt::LeftButton) { - setFocus(); bool bTouchingPoint = false; moving_control_point_idx = -1; if (_config) @@ -314,7 +315,6 @@ void spline_widget::mousePressEvent(QMouseEvent *e) { _config->addPoint(pixel_coord_to_point(e->pos())); show_tooltip(e->pos()); - setFocus(); } } } @@ -322,7 +322,6 @@ void spline_widget::mousePressEvent(QMouseEvent *e) if (e->button() == Qt::RightButton) { - clearFocus(); if (_config) { int found_pt = -1; @@ -348,22 +347,15 @@ void spline_widget::mousePressEvent(QMouseEvent *e) void spline_widget::mouseMoveEvent(QMouseEvent *e) { - if (!_config || !isEnabled()) - return; - - const bool has_focus = hasFocus(); - - if (!has_focus) + if (!_config || !isEnabled() || !hasFocus() || !isActiveWindow()) { - moving_control_point_idx = -1; - setCursor(Qt::ArrowCursor); + clearFocus(); + return; } points_t points = _config->getPoints(); - if (hasFocus() && - moving_control_point_idx >= 0 && - moving_control_point_idx < points.size()) + if (moving_control_point_idx >= 0 && moving_control_point_idx < points.size()) { const int idx = moving_control_point_idx; @@ -419,8 +411,6 @@ void spline_widget::mouseMoveEvent(QMouseEvent *e) } else { - moving_control_point_idx = -1; - int i; bool is_on_point = is_on_pt(e->pos(), &i); @@ -442,10 +432,11 @@ void spline_widget::mouseMoveEvent(QMouseEvent *e) void spline_widget::mouseReleaseEvent(QMouseEvent *e) { - if (!_config || !isEnabled()) + if (!_config || !isEnabled() || !isActiveWindow() || !hasFocus()) + { + clearFocus(); return; - - clearFocus(); + } if (e->button() == Qt::LeftButton) { @@ -542,6 +533,16 @@ bool spline_widget::point_within_pixel(const QPointF& pt, const QPoint &pixel) return sqrt(QPointF::dotProduct(tmp, tmp)) < point_size; } +void spline_widget::focusOutEvent(QFocusEvent* e) +{ + if (moving_control_point_idx != -1) + QToolTip::hideText(); + moving_control_point_idx = -1; + lower(); + setCursor(Qt::ArrowCursor); + e->accept(); +} + QPointF spline_widget::pixel_coord_to_point(const QPoint& point) { if (!_config) |