diff options
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | desktop-widgets/tagwidget.cpp | 41 | ||||
-rw-r--r-- | desktop-widgets/tagwidget.h | 6 |
3 files changed, 47 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 766787956..71ce9f2d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +- desktop: fix crash on drag&drop into tag widgets [#3030] - macOS: fix issue with HID dive computers like Suunto Eon Core/Steel [#2999] - windows: add missing modern Vista theme - mobile: add location service warning as required by Google Play 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(); +} diff --git a/desktop-widgets/tagwidget.h b/desktop-widgets/tagwidget.h index 510b3c48b..da5091658 100644 --- a/desktop-widgets/tagwidget.h +++ b/desktop-widgets/tagwidget.h @@ -26,7 +26,11 @@ slots: void completionHighlighted(const QString &text); protected: - void keyPressEvent(QKeyEvent *e); + void keyPressEvent(QKeyEvent *e) override; + void dragEnterEvent(QDragEnterEvent *e) override; + void dragLeaveEvent(QDragLeaveEvent *e) override; + void dragMoveEvent(QDragMoveEvent *e) override; + void dropEvent(QDropEvent *e) override; private: void focusOutEvent(QFocusEvent *ev) override; QCompleter *m_completer; |