diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2020-10-31 23:24:07 +0100 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2020-11-25 19:05:11 +0100 |
commit | 7a74b863402e5f67ce7fd0a99ab3ad64b7296344 (patch) | |
tree | e930fa3ee7d43a835d014e70929656b84125672a /src/timeline | |
parent | Disable scroll helper on mobile (diff) | |
download | nheko-7a74b863402e5f67ce7fd0a99ab3ad64b7296344.tar.xz |
Pasteable textinput
Diffstat (limited to 'src/timeline')
-rw-r--r-- | src/timeline/InputBar.cpp | 46 | ||||
-rw-r--r-- | src/timeline/InputBar.h | 25 | ||||
-rw-r--r-- | src/timeline/TimelineModel.cpp | 1 | ||||
-rw-r--r-- | src/timeline/TimelineModel.h | 5 |
4 files changed, 77 insertions, 0 deletions
diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp new file mode 100644 index 00000000..d128631d --- /dev/null +++ b/src/timeline/InputBar.cpp @@ -0,0 +1,46 @@ +#include "InputBar.h" + +#include <QClipboard> +#include <QGuiApplication> +#include <QMimeData> + +#include "Logging.h" + +bool +InputBar::paste(bool fromMouse) +{ + const QMimeData *md = nullptr; + + if (fromMouse) { + if (QGuiApplication::clipboard()->supportsSelection()) { + md = QGuiApplication::clipboard()->mimeData(QClipboard::Selection); + } + } else { + md = QGuiApplication::clipboard()->mimeData(QClipboard::Clipboard); + } + + if (!md) + return false; + + if (md->hasImage()) { + return true; + } else { + nhlog::ui()->debug("formats: {}", md->formats().join(", ").toStdString()); + return false; + } +} + +void +InputBar::updateState(int selectionStart_, int selectionEnd_, int cursorPosition_, QString text_) +{ + selectionStart = selectionStart_; + selectionEnd = selectionEnd_; + cursorPosition = cursorPosition_; + text = text_; +} + +void +InputBar::send() +{ + nhlog::ui()->debug("Send: {}", text.toStdString()); +} diff --git a/src/timeline/InputBar.h b/src/timeline/InputBar.h new file mode 100644 index 00000000..78b06960 --- /dev/null +++ b/src/timeline/InputBar.h @@ -0,0 +1,25 @@ +#pragma once + +#include <QObject> + +class TimelineModel; + +class InputBar : public QObject { + Q_OBJECT + +public: + InputBar(TimelineModel *parent) + : QObject() + , room(parent) + {} + +public slots: + void send(); + bool paste(bool fromMouse); + void updateState(int selectionStart, int selectionEnd, int cursorPosition, QString text); + +private: + TimelineModel *room; + QString text; + int selectionStart = 0, selectionEnd = 0, cursorPosition = 0; +}; diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 8b80ea51..aeb4e8f5 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -1567,3 +1567,4 @@ TimelineModel::roomTopic() const return utils::replaceEmoji(utils::linkifyMessage( utils::escapeBlacklistedHtml(QString::fromStdString(info[room_id_].topic)))); } + diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index e1fb9196..58a1496c 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -10,6 +10,7 @@ #include "CacheCryptoStructs.h" #include "EventStore.h" +#include "InputBar.h" #include "ui/UserProfile.h" namespace mtx::http { @@ -149,6 +150,7 @@ class TimelineModel : public QAbstractListModel Q_PROPERTY(QString roomName READ roomName NOTIFY roomNameChanged) Q_PROPERTY(QString roomAvatarUrl READ roomAvatarUrl NOTIFY roomAvatarUrlChanged) Q_PROPERTY(QString roomTopic READ roomTopic NOTIFY roomTopicChanged) + Q_PROPERTY(InputBar *input READ input) public: explicit TimelineModel(TimelineViewManager *manager, @@ -271,6 +273,7 @@ public slots: QString roomName() const; QString roomTopic() const; + InputBar *input() { return &input_; } QString roomAvatarUrl() const; QString roomId() const { return room_id_; } @@ -320,6 +323,8 @@ private: TimelineViewManager *manager_; + InputBar input_{this}; + friend struct SendMessageVisitor; }; |