diff options
author | Benjamin Saunders <ben.e.saunders@gmail.com> | 2017-11-05 13:01:21 -0800 |
---|---|---|
committer | mujx <mujx@users.noreply.github.com> | 2017-11-05 23:01:21 +0200 |
commit | 4ccb5ed81f1787a3cca12e5ca705fad4e3fa8ca5 (patch) | |
tree | 397e54883914fc354c06b27640282e7e941c7bd1 /include | |
parent | 2929d4a3a43d5780da37b34feac86c92d08a17f1 (diff) |
Add input history, enable multi-line input, refactor commands (#119)
This also fixes the transmission of mis-typed commands as messages,
fixes inability to send messages that start with a command, and does
some initial work towards automatically resizing the input field to fit
the input message.
Diffstat (limited to 'include')
-rw-r--r-- | include/TextInputWidget.h | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/include/TextInputWidget.h b/include/TextInputWidget.h index 32da6ba3..70b1c213 100644 --- a/include/TextInputWidget.h +++ b/include/TextInputWidget.h @@ -17,6 +17,8 @@ #pragma once +#include <deque> + #include <QHBoxLayout> #include <QPaintEvent> #include <QTextEdit> @@ -29,26 +31,36 @@ namespace msgs = matrix::events::messages; -static const QString EMOTE_COMMAND("/me "); -static const QString JOIN_COMMAND("/join "); - class FilteredTextEdit : public QTextEdit { Q_OBJECT -private: - QTimer *typingTimer_; - public: explicit FilteredTextEdit(QWidget *parent = nullptr); - void keyPressEvent(QKeyEvent *event); void stopTyping(); + QSize sizeHint() const override; + QSize minimumSizeHint() const override; + + void submit(); + signals: - void enterPressed(); void startedTyping(); void stoppedTyping(); + void message(QString); + void command(QString name, QString args); + +protected: + void keyPressEvent(QKeyEvent *event) override; + +private: + std::deque<QString> true_history_, working_history_; + size_t history_index_; + QTimer *typingTimer_; + + void textChanged(); + void afterCompletion(int); }; class TextInputWidget : public QFrame @@ -62,7 +74,6 @@ public: void stopTyping(); public slots: - void onSendButtonClicked(); void openFileSelection(); void hideUploadSpinner(); void focusLineEdit() { input_->setFocus(); }; @@ -84,8 +95,7 @@ protected: private: void showUploadSpinner(); - QString parseEmoteCommand(const QString &cmd); - QString parseJoinCommand(const QString &cmd); + void command(QString name, QString args); QHBoxLayout *topLayout_; FilteredTextEdit *input_; |