2020-11-01 01:24:07 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QObject>
|
2020-11-17 04:37:43 +03:00
|
|
|
#include <QTimer>
|
2020-11-09 05:12:37 +03:00
|
|
|
#include <deque>
|
2020-11-01 01:24:07 +03:00
|
|
|
|
2020-11-15 06:52:49 +03:00
|
|
|
#include <mtx/common.hpp>
|
|
|
|
#include <mtx/responses/messages.hpp>
|
|
|
|
|
2020-11-01 01:24:07 +03:00
|
|
|
class TimelineModel;
|
2020-11-15 06:52:49 +03:00
|
|
|
class QMimeData;
|
2020-11-25 19:02:23 +03:00
|
|
|
class QDropEvent;
|
2020-11-15 06:52:49 +03:00
|
|
|
class QStringList;
|
2020-11-01 01:24:07 +03:00
|
|
|
|
2020-11-09 05:12:37 +03:00
|
|
|
class InputBar : public QObject
|
|
|
|
{
|
2020-11-01 01:24:07 +03:00
|
|
|
Q_OBJECT
|
2020-11-15 06:52:49 +03:00
|
|
|
Q_PROPERTY(bool uploading READ uploading NOTIFY uploadingChanged)
|
2020-11-01 01:24:07 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
InputBar(TimelineModel *parent)
|
|
|
|
: QObject()
|
|
|
|
, room(parent)
|
2020-11-17 04:37:43 +03:00
|
|
|
{
|
|
|
|
typingRefresh_.setInterval(10'000);
|
|
|
|
typingRefresh_.setSingleShot(true);
|
|
|
|
typingTimeout_.setInterval(5'000);
|
|
|
|
typingTimeout_.setSingleShot(true);
|
|
|
|
connect(&typingRefresh_, &QTimer::timeout, this, &InputBar::startTyping);
|
|
|
|
connect(&typingTimeout_, &QTimer::timeout, this, &InputBar::stopTyping);
|
|
|
|
}
|
2020-11-01 01:24:07 +03:00
|
|
|
|
|
|
|
public slots:
|
2020-11-17 15:25:16 +03:00
|
|
|
QString text() const;
|
|
|
|
QString previousText();
|
|
|
|
QString nextText();
|
|
|
|
|
2020-11-01 01:24:07 +03:00
|
|
|
void send();
|
2020-11-09 05:12:37 +03:00
|
|
|
void paste(bool fromMouse);
|
2020-11-25 19:02:23 +03:00
|
|
|
void insertMimeData(const QMimeData *data);
|
2020-11-01 01:24:07 +03:00
|
|
|
void updateState(int selectionStart, int selectionEnd, int cursorPosition, QString text);
|
2020-11-15 06:52:49 +03:00
|
|
|
void openFileSelection();
|
|
|
|
bool uploading() const { return uploading_; }
|
2020-11-16 01:14:47 +03:00
|
|
|
void callButton();
|
2020-11-01 01:24:07 +03:00
|
|
|
|
2020-11-20 03:22:36 +03:00
|
|
|
QObject *completerFor(QString completerName);
|
|
|
|
|
2020-11-17 04:37:43 +03:00
|
|
|
private slots:
|
|
|
|
void startTyping();
|
|
|
|
void stopTyping();
|
|
|
|
|
2020-11-09 05:12:37 +03:00
|
|
|
signals:
|
|
|
|
void insertText(QString text);
|
2020-11-15 06:52:49 +03:00
|
|
|
void uploadingChanged(bool value);
|
2020-11-09 05:12:37 +03:00
|
|
|
|
2020-11-01 01:24:07 +03:00
|
|
|
private:
|
2020-11-09 05:12:37 +03:00
|
|
|
void message(QString body);
|
|
|
|
void emote(QString body);
|
|
|
|
void command(QString name, QString args);
|
2020-11-15 06:52:49 +03:00
|
|
|
void image(const QString &filename,
|
|
|
|
const std::optional<mtx::crypto::EncryptedFile> &file,
|
|
|
|
const QString &url,
|
|
|
|
const QString &mime,
|
|
|
|
uint64_t dsize,
|
|
|
|
const QSize &dimensions,
|
|
|
|
const QString &blurhash);
|
|
|
|
void file(const QString &filename,
|
|
|
|
const std::optional<mtx::crypto::EncryptedFile> &encryptedFile,
|
|
|
|
const QString &url,
|
|
|
|
const QString &mime,
|
|
|
|
uint64_t dsize);
|
|
|
|
void audio(const QString &filename,
|
|
|
|
const std::optional<mtx::crypto::EncryptedFile> &file,
|
|
|
|
const QString &url,
|
|
|
|
const QString &mime,
|
|
|
|
uint64_t dsize);
|
|
|
|
void video(const QString &filename,
|
|
|
|
const std::optional<mtx::crypto::EncryptedFile> &file,
|
|
|
|
const QString &url,
|
|
|
|
const QString &mime,
|
|
|
|
uint64_t dsize);
|
|
|
|
|
|
|
|
void showPreview(const QMimeData &source, QString path, const QStringList &formats);
|
|
|
|
void setUploading(bool value)
|
|
|
|
{
|
|
|
|
if (value != uploading_) {
|
|
|
|
uploading_ = value;
|
|
|
|
emit uploadingChanged(value);
|
|
|
|
}
|
|
|
|
}
|
2020-11-09 05:12:37 +03:00
|
|
|
|
2020-11-17 04:37:43 +03:00
|
|
|
QTimer typingRefresh_;
|
|
|
|
QTimer typingTimeout_;
|
2020-11-01 01:24:07 +03:00
|
|
|
TimelineModel *room;
|
2020-11-09 05:12:37 +03:00
|
|
|
std::deque<QString> history_;
|
|
|
|
std::size_t history_index_ = 0;
|
2020-11-01 01:24:07 +03:00
|
|
|
int selectionStart = 0, selectionEnd = 0, cursorPosition = 0;
|
2020-11-15 06:52:49 +03:00
|
|
|
bool uploading_ = false;
|
2020-11-01 01:24:07 +03:00
|
|
|
};
|