2017-04-06 02:06:42 +03:00
|
|
|
/*
|
|
|
|
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-05-16 21:46:45 +03:00
|
|
|
#pragma once
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-11-06 00:01:21 +03:00
|
|
|
#include <deque>
|
2020-01-12 18:39:01 +03:00
|
|
|
#include <optional>
|
2017-11-06 00:01:21 +03:00
|
|
|
|
2020-01-31 18:25:43 +03:00
|
|
|
#include <QCoreApplication>
|
2017-04-06 02:06:42 +03:00
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QPaintEvent>
|
2017-04-23 21:31:08 +03:00
|
|
|
#include <QTextEdit>
|
2017-04-06 02:06:42 +03:00
|
|
|
#include <QWidget>
|
|
|
|
|
2018-02-18 23:52:31 +03:00
|
|
|
#include "dialogs/PreviewUploadOverlay.h"
|
2019-01-26 21:17:08 +03:00
|
|
|
#include "emoji/PickButton.h"
|
2019-06-12 06:36:46 +03:00
|
|
|
#include "popups/SuggestionsPopup.h"
|
2017-11-30 14:53:28 +03:00
|
|
|
|
2018-03-25 00:16:15 +03:00
|
|
|
struct SearchResult;
|
|
|
|
|
2018-07-17 16:37:25 +03:00
|
|
|
class FlatButton;
|
|
|
|
class LoadingIndicator;
|
|
|
|
|
2017-04-23 21:31:08 +03:00
|
|
|
class FilteredTextEdit : public QTextEdit
|
|
|
|
{
|
2017-09-03 11:43:45 +03:00
|
|
|
Q_OBJECT
|
2017-10-31 21:11:49 +03:00
|
|
|
|
2017-04-23 21:31:08 +03:00
|
|
|
public:
|
2017-09-03 11:43:45 +03:00
|
|
|
explicit FilteredTextEdit(QWidget *parent = nullptr);
|
2017-04-23 21:31:08 +03:00
|
|
|
|
2017-10-31 21:11:49 +03:00
|
|
|
void stopTyping();
|
|
|
|
|
2017-11-06 00:01:21 +03:00
|
|
|
QSize sizeHint() const override;
|
|
|
|
QSize minimumSizeHint() const override;
|
|
|
|
|
|
|
|
void submit();
|
|
|
|
|
2017-04-23 21:31:08 +03:00
|
|
|
signals:
|
2018-01-25 08:57:19 +03:00
|
|
|
void heightChanged(int height);
|
2017-10-31 21:11:49 +03:00
|
|
|
void startedTyping();
|
|
|
|
void stoppedTyping();
|
2018-02-18 23:52:31 +03:00
|
|
|
void startedUpload();
|
2020-04-13 17:22:30 +03:00
|
|
|
void message(QString msg);
|
2017-11-06 00:01:21 +03:00
|
|
|
void command(QString name, QString args);
|
2020-04-13 17:22:30 +03:00
|
|
|
void media(QSharedPointer<QIODevice> data, QString mimeClass, const QString &filename);
|
2017-11-06 00:01:21 +03:00
|
|
|
|
2018-03-25 00:16:15 +03:00
|
|
|
//! Trigger the suggestion popup.
|
|
|
|
void showSuggestions(const QString &query);
|
2020-01-31 18:08:30 +03:00
|
|
|
void resultsRetrieved(const std::vector<SearchResult> &results);
|
2018-04-14 14:12:36 +03:00
|
|
|
void selectNextSuggestion();
|
|
|
|
void selectPreviousSuggestion();
|
2018-04-10 11:47:23 +03:00
|
|
|
void selectHoveredSuggestion();
|
2018-03-25 00:16:15 +03:00
|
|
|
|
|
|
|
public slots:
|
2020-01-31 18:08:30 +03:00
|
|
|
void showResults(const std::vector<SearchResult> &results);
|
2018-03-25 00:16:15 +03:00
|
|
|
|
2017-11-06 00:01:21 +03:00
|
|
|
protected:
|
|
|
|
void keyPressEvent(QKeyEvent *event) override;
|
2018-01-10 10:52:59 +03:00
|
|
|
bool canInsertFromMimeData(const QMimeData *source) const override;
|
|
|
|
void insertFromMimeData(const QMimeData *source) override;
|
2018-03-25 00:16:15 +03:00
|
|
|
void focusOutEvent(QFocusEvent *event) override
|
|
|
|
{
|
2019-06-12 04:04:30 +03:00
|
|
|
suggestionsPopup_.hide();
|
2018-03-28 13:09:16 +03:00
|
|
|
QTextEdit::focusOutEvent(event);
|
2018-03-25 00:16:15 +03:00
|
|
|
}
|
2017-11-06 00:01:21 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::deque<QString> true_history_, working_history_;
|
|
|
|
size_t history_index_;
|
|
|
|
QTimer *typingTimer_;
|
|
|
|
|
2019-06-12 04:04:30 +03:00
|
|
|
SuggestionsPopup suggestionsPopup_;
|
2018-03-25 00:16:15 +03:00
|
|
|
|
2018-07-29 21:58:18 +03:00
|
|
|
enum class AnchorType
|
|
|
|
{
|
|
|
|
Tab = 0,
|
|
|
|
Sigil = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
AnchorType anchorType_ = AnchorType::Sigil;
|
|
|
|
|
|
|
|
int anchorWidth(AnchorType anchor) { return static_cast<int>(anchor); }
|
|
|
|
|
2019-06-12 04:04:30 +03:00
|
|
|
void closeSuggestions() { suggestionsPopup_.hide(); }
|
2018-03-25 00:16:15 +03:00
|
|
|
void resetAnchor() { atTriggerPosition_ = -1; }
|
2018-07-29 21:58:18 +03:00
|
|
|
bool isAnchorValid() { return atTriggerPosition_ != -1; }
|
|
|
|
bool hasAnchor(int pos, AnchorType anchor)
|
|
|
|
{
|
|
|
|
return pos == atTriggerPosition_ + anchorWidth(anchor);
|
|
|
|
}
|
2018-03-25 00:16:15 +03:00
|
|
|
|
|
|
|
QString query()
|
|
|
|
{
|
|
|
|
auto cursor = textCursor();
|
|
|
|
cursor.movePosition(QTextCursor::StartOfWord, QTextCursor::KeepAnchor);
|
|
|
|
return cursor.selectedText();
|
|
|
|
}
|
|
|
|
|
2018-02-18 23:52:31 +03:00
|
|
|
dialogs::PreviewUploadOverlay previewDialog_;
|
2018-01-10 10:52:59 +03:00
|
|
|
|
2018-03-25 00:16:15 +03:00
|
|
|
//! Latest position of the '@' character that triggers the username completer.
|
|
|
|
int atTriggerPosition_ = -1;
|
|
|
|
|
2017-11-06 00:01:21 +03:00
|
|
|
void textChanged();
|
2018-02-18 23:52:31 +03:00
|
|
|
void uploadData(const QByteArray data, const QString &media, const QString &filename);
|
2017-11-06 00:01:21 +03:00
|
|
|
void afterCompletion(int);
|
2018-02-18 23:52:31 +03:00
|
|
|
void showPreview(const QMimeData *source, const QStringList &formats);
|
2017-04-23 21:31:08 +03:00
|
|
|
};
|
|
|
|
|
2018-01-25 08:57:19 +03:00
|
|
|
class TextInputWidget : public QWidget
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2017-09-03 11:43:45 +03:00
|
|
|
Q_OBJECT
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2018-03-18 18:08:13 +03:00
|
|
|
Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor)
|
|
|
|
|
2017-04-06 02:06:42 +03:00
|
|
|
public:
|
2020-02-04 06:58:43 +03:00
|
|
|
TextInputWidget(QWidget *parent = nullptr);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-10-31 21:11:49 +03:00
|
|
|
void stopTyping();
|
|
|
|
|
2018-03-18 18:08:13 +03:00
|
|
|
QColor borderColor() const { return borderColor_; }
|
|
|
|
void setBorderColor(QColor &color) { borderColor_ = color; }
|
2018-06-09 16:03:14 +03:00
|
|
|
void disableInput()
|
|
|
|
{
|
|
|
|
input_->setEnabled(false);
|
|
|
|
input_->setPlaceholderText(tr("Connection lost. Nheko is trying to re-connect..."));
|
|
|
|
}
|
|
|
|
void enableInput()
|
|
|
|
{
|
|
|
|
input_->setEnabled(true);
|
|
|
|
input_->setPlaceholderText(tr("Write a message..."));
|
|
|
|
}
|
2018-03-18 18:08:13 +03:00
|
|
|
|
2017-04-06 02:06:42 +03:00
|
|
|
public slots:
|
2017-09-10 12:58:00 +03:00
|
|
|
void openFileSelection();
|
|
|
|
void hideUploadSpinner();
|
2017-11-16 17:33:52 +03:00
|
|
|
void focusLineEdit() { input_->setFocus(); }
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2019-01-26 21:17:08 +03:00
|
|
|
private slots:
|
|
|
|
void addSelectedEmoji(const QString &emoji);
|
|
|
|
|
2017-04-06 02:06:42 +03:00
|
|
|
signals:
|
2020-04-13 17:22:30 +03:00
|
|
|
void sendTextMessage(const QString &msg);
|
|
|
|
void sendEmoteMessage(QString msg);
|
2018-08-09 18:20:17 +03:00
|
|
|
void heightChanged(int height);
|
2017-12-01 18:33:49 +03:00
|
|
|
|
2019-12-05 17:31:53 +03:00
|
|
|
void uploadMedia(const QSharedPointer<QIODevice> data,
|
|
|
|
QString mimeClass,
|
2020-04-13 17:22:30 +03:00
|
|
|
const QString &filename);
|
2017-12-01 18:33:49 +03:00
|
|
|
|
2017-10-08 22:38:38 +03:00
|
|
|
void sendJoinRoomRequest(const QString &room);
|
2020-01-29 02:30:53 +03:00
|
|
|
void sendInviteRoomRequest(const QString &userid, const QString &reason);
|
|
|
|
void sendKickRoomRequest(const QString &userid, const QString &reason);
|
|
|
|
void sendBanRoomRequest(const QString &userid, const QString &reason);
|
|
|
|
void sendUnbanRoomRequest(const QString &userid, const QString &reason);
|
2020-05-18 15:02:14 +03:00
|
|
|
void changeRoomNick(const QString &displayname);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-10-31 21:11:49 +03:00
|
|
|
void startedTyping();
|
|
|
|
void stoppedTyping();
|
|
|
|
|
2017-11-03 09:54:17 +03:00
|
|
|
protected:
|
2017-11-16 17:33:52 +03:00
|
|
|
void focusInEvent(QFocusEvent *event) override;
|
|
|
|
void paintEvent(QPaintEvent *) override;
|
2017-11-03 09:54:17 +03:00
|
|
|
|
2017-04-06 02:06:42 +03:00
|
|
|
private:
|
2017-09-10 12:58:00 +03:00
|
|
|
void showUploadSpinner();
|
2017-11-06 00:01:21 +03:00
|
|
|
void command(QString name, QString args);
|
2017-09-03 11:43:45 +03:00
|
|
|
|
2017-09-10 12:58:00 +03:00
|
|
|
QHBoxLayout *topLayout_;
|
2017-09-03 11:43:45 +03:00
|
|
|
FilteredTextEdit *input_;
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-09-10 12:58:00 +03:00
|
|
|
LoadingIndicator *spinner_;
|
|
|
|
|
|
|
|
FlatButton *sendFileBtn_;
|
|
|
|
FlatButton *sendMessageBtn_;
|
2019-01-26 21:17:08 +03:00
|
|
|
emoji::PickButton *emojiBtn_;
|
2018-03-18 18:08:13 +03:00
|
|
|
|
|
|
|
QColor borderColor_;
|
2017-04-06 02:06:42 +03:00
|
|
|
};
|