matrixion/src/timeline/InputBar.h

116 lines
3.7 KiB
C
Raw Normal View History

2021-03-05 02:35:15 +03:00
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
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;
2021-07-15 21:37:52 +03:00
class ImagePackModel;
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
enum class MarkdownOverride
{
2021-01-21 02:47:36 +03:00
NOT_SPECIFIED, // no override set
2021-01-21 01:47:57 +03:00
ON,
OFF,
};
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();
2021-02-25 02:50:17 +03:00
void setText(QString newText);
2020-11-17 15:25:16 +03:00
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_; }
2021-03-26 02:42:46 +03:00
void message(QString body,
MarkdownOverride useMarkdown = MarkdownOverride::NOT_SPECIFIED,
bool rainbowify = false);
void reaction(const QString &reactedEvent, const QString &reactionKey);
2021-07-15 21:37:52 +03:00
void sticker(ImagePackModel *model, int row);
2020-11-01 01:24:07 +03:00
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);
void textChanged(QString newText);
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:
2021-04-01 18:51:10 +03:00
void emote(QString body, bool rainbowify);
2021-04-11 22:47:20 +03:00
void notice(QString body, bool rainbowify);
2020-11-09 05:12:37 +03:00
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
};