[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [milou] lib: Only follow mouse when moved (Fixes Bug #372635)
From: Peifeng Yu <null () kde ! org>
Date: 2017-04-30 18:20:04
Message-ID: E1d4tS0-0001oY-Tu () code ! kde ! org
[Download RAW message or body]
Git commit a41a850a3943dbc1bd43b867def775e41902f987 by Peifeng Yu.
Committed on 30/04/2017 at 18:20.
Pushed by peifengyu into branch 'master'.
Only follow mouse when moved (Fixes Bug #372635)
Summary:
Use a new variable moved to detect if mouse moved and only change index if the mouse \
moved. This helps preventing index changes when only using keyboard to search \
something in milou and to not accidently start/open something you did not want (see \
bug report https://bugs.kde.org/show_bug.cgi?id=372635 )
BUG: 372635
In general the onEntered signal seems to be broken in Qt somehow as I could not make \
it work reliably with Qt 5.7.1. Sometimes it worked but mostly the code using \
onEntered failed to work with onPositionChanged (I guess this also does not always \
set it to true). Hence I tried containsMouse which seems to work reliably at least on \
Qt 5.7.1. Tests are appreciated especially on other Qt versions.
Reviewers: broulik, davidedmundson
Reviewed By: davidedmundson
Subscribers: ltoscano, qi437103, lfurmetz, anthonyfieroni, davidedmundson, \
plasma-devel
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D5490
M +1 -0 lib/CMakeLists.txt
A +40 -0 lib/mousehelper.cpp [License: GPL (v2/3)]
A +44 -0 lib/mousehelper.h [License: GPL (v2/3)]
M +12 -4 lib/qml/ResultDelegate.qml
M +9 -0 lib/qml/ResultsView.qml
M +5 -0 lib/qml/qmlplugins.cpp
https://commits.kde.org/milou/a41a850a3943dbc1bd43b867def775e41902f987
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 1f6d3aa..cce85ff 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -5,6 +5,7 @@ set (lib_SRCS
previewplugin.cpp
sourcesmodel.cpp
draghelper.cpp
+ mousehelper.cpp
)
add_library(milou SHARED ${lib_SRCS})
diff --git a/lib/mousehelper.cpp b/lib/mousehelper.cpp
new file mode 100644
index 0000000..d3e8bcf
--- /dev/null
+++ b/lib/mousehelper.cpp
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2017 Aetf <aetf@unlimitedcodeworks.xyz>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "mousehelper.h"
+
+#include <QCursor>
+
+using namespace Milou;
+
+MouseHelper::MouseHelper(QObject* parent)
+ : QObject(parent)
+{
+}
+
+MouseHelper::~MouseHelper()
+{
+}
+
+QPointF MouseHelper::globalMousePosition() const
+{
+ return QCursor::pos();
+}
diff --git a/lib/mousehelper.h b/lib/mousehelper.h
new file mode 100644
index 0000000..f3e18c0
--- /dev/null
+++ b/lib/mousehelper.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2017 Aetf <aetf@unlimitedcodeworks.xyz>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef MOUSEHELPER_H
+#define MOUSEHELPER_H
+
+#include <QObject>
+#include <QPoint>
+
+#include "milou_export.h"
+
+namespace Milou {
+
+class MILOU_EXPORT MouseHelper : public QObject
+{
+ Q_OBJECT
+
+public:
+ explicit MouseHelper(QObject* parent = nullptr);
+ ~MouseHelper();
+
+ Q_INVOKABLE QPointF globalMousePosition() const;
+};
+
+}
+#endif // MOUSEHELPER_H
diff --git a/lib/qml/ResultDelegate.qml b/lib/qml/ResultDelegate.qml
index 6fe6549..1820e88 100644
--- a/lib/qml/ResultDelegate.qml
+++ b/lib/qml/ResultDelegate.qml
@@ -81,10 +81,6 @@ MouseArea {
acceptedButtons: Qt.LeftButton
hoverEnabled: true
- onEntered: {
- listView.currentIndex = index
- }
-
onPressed: {
__pressed = true;
__pressX = mouse.x;
@@ -112,6 +108,11 @@ MouseArea {
__pressY = -1;
}
}
+
+ if (!listView.moved && listView.mouseMovedGlobally()) {
+ listView.moved = true
+ listView.currentIndex = index
+ }
}
onContainsMouseChanged: {
@@ -119,6 +120,13 @@ MouseArea {
__pressed = false;
__pressX = -1;
__pressY = -1;
+ } else {
+ if (listView.moved) {
+ listView.currentIndex = index
+ } else if (listView.mouseMovedGlobally()) {
+ listView.moved = true
+ listView.currentIndex = index
+ }
}
}
diff --git a/lib/qml/ResultsView.qml b/lib/qml/ResultsView.qml
index 8a9c85c..38a5cb9 100644
--- a/lib/qml/ResultsView.qml
+++ b/lib/qml/ResultsView.qml
@@ -54,6 +54,13 @@ ListView {
// be run when the model is populated
property bool runAutomatically
+ // This is used to disable mouse selection if the user interacts only with \
keyboard + property bool moved: false
+ property point savedMousePosition: Milou.MouseHelper.globalMousePosition()
+ function mouseMovedGlobally() {
+ return savedMousePosition != Milou.MouseHelper.globalMousePosition();
+ }
+
Milou.DragHelper {
id: dragHelper
dragIconSize: units.iconSizes.medium
@@ -67,6 +74,8 @@ ListView {
// and the results are presented
onModelReset: {
listView.currentIndex = 0
+ listView.moved = false
+ listView.savedMousePosition = Milou.MouseHelper.globalMousePosition()
if (runAutomatically) {
runCurrentIndex();
diff --git a/lib/qml/qmlplugins.cpp b/lib/qml/qmlplugins.cpp
index b10f635..8d05990 100644
--- a/lib/qml/qmlplugins.cpp
+++ b/lib/qml/qmlplugins.cpp
@@ -25,6 +25,7 @@
#include "sourcesmodel.h"
#include "preview.h"
#include "draghelper.h"
+#include "mousehelper.h"
#include <QtQml/qqml.h>
@@ -37,5 +38,9 @@ void QmlPlugins::registerTypes(const char *uri)
qmlRegisterType<Milou::SourcesModel> (uri, 0, 1, "SourcesModel");
qmlRegisterType<Milou::Preview> (uri, 0, 1, "Preview");
qmlRegisterType<Milou::DragHelper> (uri, 0, 2, "DragHelper");
+ qmlRegisterSingletonType<Milou::MouseHelper> (uri, 0, 1, "MouseHelper",
+ [](QQmlEngine*, QJSEngine*) -> \
QObject* { + return new Milou::MouseHelper();
+ });
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic