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>
|
2018-03-25 00:16:15 +03:00
|
|
|
#include <iterator>
|
|
|
|
#include <map>
|
2017-11-06 00:01:21 +03:00
|
|
|
|
2018-03-25 00:16:15 +03:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QDebug>
|
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>
|
|
|
|
|
|
|
|
#include "FlatButton.h"
|
2017-09-10 12:58:00 +03:00
|
|
|
#include "LoadingIndicator.h"
|
2018-03-25 00:16:15 +03:00
|
|
|
#include "SuggestionsPopup.hpp"
|
2017-09-10 12:58:00 +03:00
|
|
|
|
2018-02-18 23:52:31 +03:00
|
|
|
#include "dialogs/PreviewUploadOverlay.h"
|
2018-01-10 10:52:59 +03:00
|
|
|
|
2017-11-30 21:02:46 +03:00
|
|
|
#include "emoji/PickButton.h"
|
2017-11-30 14:53:28 +03:00
|
|
|
|
2018-01-10 10:52:59 +03:00
|
|
|
namespace dialogs {
|
2018-02-18 23:52:31 +03:00
|
|
|
class PreviewUploadOverlay;
|
2018-01-10 10:52:59 +03:00
|
|
|
}
|
|
|
|
|
2018-03-25 00:16:15 +03:00
|
|
|
struct SearchResult;
|
|
|
|
|
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();
|
2017-11-06 00:01:21 +03:00
|
|
|
void message(QString);
|
|
|
|
void command(QString name, QString args);
|
2018-02-18 23:52:31 +03:00
|
|
|
void image(QSharedPointer<QIODevice> data, const QString &filename);
|
|
|
|
void audio(QSharedPointer<QIODevice> data, const QString &filename);
|
|
|
|
void video(QSharedPointer<QIODevice> data, const QString &filename);
|
|
|
|
void file(QSharedPointer<QIODevice> data, 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);
|
|
|
|
void resultsRetrieved(const QVector<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:
|
|
|
|
void showResults(const QVector<SearchResult> &results);
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
popup_.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_;
|
|
|
|
|
2018-03-25 00:16:15 +03:00
|
|
|
SuggestionsPopup popup_;
|
|
|
|
|
|
|
|
void closeSuggestions() { popup_.hide(); }
|
|
|
|
void resetAnchor() { atTriggerPosition_ = -1; }
|
|
|
|
|
|
|
|
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:
|
2017-09-03 11:43:45 +03:00
|
|
|
TextInputWidget(QWidget *parent = 0);
|
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(); }
|
2018-06-30 15:13:15 +03:00
|
|
|
void addReply(const QString &username, const QString &msg);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-04-23 21:31:08 +03:00
|
|
|
private slots:
|
2017-09-03 11:43:45 +03:00
|
|
|
void addSelectedEmoji(const QString &emoji);
|
2017-04-23 21:31:08 +03:00
|
|
|
|
2017-04-06 02:06:42 +03:00
|
|
|
signals:
|
2017-09-03 11:43:45 +03:00
|
|
|
void sendTextMessage(QString msg);
|
|
|
|
void sendEmoteMessage(QString msg);
|
2017-12-01 18:33:49 +03:00
|
|
|
|
2018-02-18 23:52:31 +03:00
|
|
|
void uploadImage(const QSharedPointer<QIODevice> data, const QString &filename);
|
|
|
|
void uploadFile(const QSharedPointer<QIODevice> data, const QString &filename);
|
|
|
|
void uploadAudio(const QSharedPointer<QIODevice> data, const QString &filename);
|
|
|
|
void uploadVideo(const QSharedPointer<QIODevice> data, const QString &filename);
|
2017-12-01 18:33:49 +03:00
|
|
|
|
2017-10-08 22:38:38 +03:00
|
|
|
void sendJoinRoomRequest(const QString &room);
|
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_;
|
2017-11-30 21:02:46 +03:00
|
|
|
emoji::PickButton *emojiBtn_;
|
2018-03-18 18:08:13 +03:00
|
|
|
|
|
|
|
QColor borderColor_;
|
2017-04-06 02:06:42 +03:00
|
|
|
};
|