File indexing completed on 2024-12-01 04:37:01

0001 /*
0002    SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "inputtextmanager.h"
0010 #include <KTextEdit>
0011 
0012 #include "libruqolawidgets_private_export.h"
0013 #include <QPointer>
0014 class RocketChatAccount;
0015 class CompletionListView;
0016 class UserAndChannelCompletionDelegate;
0017 /**
0018  * @brief The MessageTextEdit class is the widget used for typing messages to be sent.
0019  */
0020 class LIBRUQOLAWIDGETS_TESTS_EXPORT MessageTextEdit : public KTextEdit
0021 {
0022     Q_OBJECT
0023 public:
0024     explicit MessageTextEdit(QWidget *parent = nullptr);
0025     ~MessageTextEdit() override;
0026 
0027     void setCurrentRocketChatAccount(RocketChatAccount *account, bool threadMessageDialog);
0028 
0029     void insertEmoji(const QString &text);
0030     [[nodiscard]] QString text() const;
0031 
0032     QSize sizeHint() const override;
0033     QSize minimumSizeHint() const override;
0034 
0035     void changeText(const QString &str, int cursorPosition);
0036 
0037     QMenu *mousePopupMenu() override;
0038 
0039     void setRoomId(const QString &roomId);
0040     [[nodiscard]] QString roomId() const;
0041 
0042 Q_SIGNALS:
0043 
0044     void sendMessage(const QString &str);
0045     void keyPressed(QKeyEvent *ev);
0046     void textEditing(bool clearNotification);
0047     void textClicked();
0048     void handleMimeData(const QMimeData *mimeData);
0049 
0050 protected:
0051     void keyPressEvent(QKeyEvent *e) override;
0052     void mousePressEvent(QMouseEvent *ev) override;
0053     void dropEvent(QDropEvent *e) override;
0054     void dragEnterEvent(QDragEnterEvent *event) override;
0055     void dragMoveEvent(QDragMoveEvent *event) override;
0056 
0057 private:
0058     LIBRUQOLAWIDGETS_NO_EXPORT void slotCompletionTypeChanged(InputTextManager::CompletionForType type);
0059     LIBRUQOLAWIDGETS_NO_EXPORT void slotCompletionAvailable();
0060     LIBRUQOLAWIDGETS_NO_EXPORT void slotComplete(const QModelIndex &index);
0061     LIBRUQOLAWIDGETS_NO_EXPORT void slotSetAsBold();
0062     LIBRUQOLAWIDGETS_NO_EXPORT void slotSetAsItalic();
0063     LIBRUQOLAWIDGETS_NO_EXPORT void slotSetAsStrikeOut();
0064     LIBRUQOLAWIDGETS_NO_EXPORT void insertFormat(QChar formatChar);
0065     LIBRUQOLAWIDGETS_NO_EXPORT void slotInsertCodeBlock();
0066     LIBRUQOLAWIDGETS_NO_EXPORT void loadSpellCheckingSettings();
0067     LIBRUQOLAWIDGETS_NO_EXPORT void slotLanguageChanged(const QString &lang);
0068     LIBRUQOLAWIDGETS_NO_EXPORT void slotSpellCheckingEnableChanged(bool b);
0069     LIBRUQOLAWIDGETS_NO_EXPORT void slotInsertMarkdownUrl();
0070     LIBRUQOLAWIDGETS_NO_EXPORT void slotLoginChanged();
0071     LIBRUQOLAWIDGETS_NO_EXPORT void switchAutoCorrectionLanguage(const QString &lang);
0072     LIBRUQOLAWIDGETS_NO_EXPORT void slotUpdateMessageFailed(const QString &str);
0073     LIBRUQOLAWIDGETS_NO_EXPORT void slotSelectFirstTextCompleter();
0074 
0075     QPointer<RocketChatAccount> mCurrentRocketChatAccount;
0076     InputTextManager *mCurrentInputTextManager = nullptr;
0077     CompletionListView *const mUserAndChannelCompletionListView;
0078     CompletionListView *const mEmojiCompletionListView;
0079     CompletionListView *const mCommandCompletionListView;
0080     UserAndChannelCompletionDelegate *mUserAndChannelCompletionDelegate = nullptr;
0081     QString mRoomId;
0082 };