summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeifeng Yu <[email protected]>2017-04-30 14:19:29 -0400
committerPeifeng Yu <[email protected]>2017-04-30 14:20:02 -0400
commita41a850a3943dbc1bd43b867def775e41902f987 (patch)
treef06ef8fb89fcc73ea007606f7a9e6fba57e137cd
parentc7c17d15580eabb0998d208759a764f7b8a9ed62 (diff)
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
-rw-r--r--lib/CMakeLists.txt1
-rw-r--r--lib/mousehelper.cpp40
-rw-r--r--lib/mousehelper.h44
-rw-r--r--lib/qml/ResultDelegate.qml16
-rw-r--r--lib/qml/ResultsView.qml9
-rw-r--r--lib/qml/qmlplugins.cpp5
6 files changed, 111 insertions, 4 deletions
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 <[email protected]>
+ *
+ * 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 <[email protected]>
+ *
+ * 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();
+ });
}