summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/tagwidget.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-10-24 16:23:49 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-10-24 09:49:36 -0700
commitd543196059ed8f035827ec082618b59a7885a339 (patch)
tree7a00e6030b8bae865480c950b892a87a1b64d23e /desktop-widgets/tagwidget.cpp
parenta9a4249b236f07418a3c678d3ec2b7791f957048 (diff)
downloadsubsurface-d543196059ed8f035827ec082618b59a7885a339.tar.gz
desktop: overwrite drag & drop in TagWidget
The interaction of Qt's drag & drop with GroupedLineEdit was exceedingly weird. The user was able to scroll the viewport making the text invisible. This implements a very primitive alternative drag & drop functionality: dropped text is regarged as a distinct tag. This means that it is not possible to modify existing tags by dropping in the middle of them. Arguably, this might even be better than arbitrary drag & drop. But even if not perfect, this fixes a very nasty UI behavior. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/tagwidget.cpp')
-rw-r--r--desktop-widgets/tagwidget.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/desktop-widgets/tagwidget.cpp b/desktop-widgets/tagwidget.cpp
index 743e4fbca..e7f2a9bfe 100644
--- a/desktop-widgets/tagwidget.cpp
+++ b/desktop-widgets/tagwidget.cpp
@@ -3,6 +3,7 @@
#include "mainwindow.h"
#include "tab-widgets/maintab.h"
#include <QCompleter>
+#include <QMimeData>
TagWidget::TagWidget(QWidget *parent) : GroupedLineEdit(parent), m_completer(NULL), lastFinishedTag(false)
{
@@ -211,3 +212,43 @@ void TagWidget::focusOutEvent(QFocusEvent *ev)
GroupedLineEdit::focusOutEvent(ev);
emit editingFinished();
}
+
+// Implement simple drag and drop: text dropped onto the widget
+// will be added as a new tag at the end. This overrides
+// Qt's implementation which resulted in weird UI behavior,
+// as the user may succeed in scrolling the view port.
+static void handleDragEvent(QDragMoveEvent *e)
+{
+ if (e->mimeData()->hasFormat(QStringLiteral("text/plain")))
+ e->acceptProposedAction();
+}
+
+void TagWidget::dragEnterEvent(QDragEnterEvent *e)
+{
+ handleDragEvent(e);
+}
+
+void TagWidget::dragMoveEvent(QDragMoveEvent *e)
+{
+ handleDragEvent(e);
+}
+
+void TagWidget::dragLeaveEvent(QDragLeaveEvent *)
+{
+}
+
+void TagWidget::dropEvent(QDropEvent *e)
+{
+ e->acceptProposedAction();
+
+ QString newTag = e->mimeData()->text().trimmed();
+ if (newTag.isEmpty())
+ return;
+
+ QString s = text().trimmed();
+ if (!s.isEmpty())
+ s += ", ";
+ s += newTag;
+ setText(s);
+ emit editingFinished();
+}