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 "libruqolawidgets_private_export.h"
0010 #include "misc/messagelistviewbase.h"
0011 #include "moderation/moderationreportinfos.h"
0012 #include <QPointer>
0013 class MessageListDelegate;
0014 class RocketChatAccount;
0015 class Room;
0016 namespace TextTranslator
0017 {
0018 class TranslatorMenu;
0019 }
0020 class LIBRUQOLAWIDGETS_TESTS_EXPORT MessageListView : public MessageListViewBase
0021 {
0022     Q_OBJECT
0023 public:
0024     enum class Mode {
0025         ThreadEditing,
0026         Editing,
0027         Viewing, /*when we show list of message as mentions, search etc.*/
0028         Moderation,
0029     };
0030 
0031     explicit MessageListView(RocketChatAccount *account, MessageListView::Mode mode, QWidget *parent = nullptr);
0032     ~MessageListView() override;
0033 
0034     void setRoom(Room *room);
0035 
0036     void setChannelSelected(Room *room);
0037 
0038     void setModel(QAbstractItemModel *newModel) override;
0039 
0040     void handleKeyPressEvent(QKeyEvent *ev);
0041 
0042     [[nodiscard]] MessageListView::Mode mode() const;
0043 
0044     void setRoomId(const QString &roomID);
0045 
0046     void goToMessage(const QString &messageId);
0047     void setCurrentRocketChatAccount(RocketChatAccount *currentRocketChatAccount);
0048 
0049     void clearTextDocumentCache();
0050 
0051     void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) override;
0052 
0053     void setSearchText(const QString &str);
0054 
0055 protected:
0056     void paintEvent(QPaintEvent *e) override;
0057     void contextMenuEvent(QContextMenuEvent *event) override;
0058 
0059     bool mouseEvent(QMouseEvent *event, const QStyleOptionViewItem &option, const QModelIndex &index) override;
0060     bool maybeStartDrag(QMouseEvent *event, const QStyleOptionViewItem &option, const QModelIndex &index) override;
0061     void wheelEvent(QWheelEvent *e) override;
0062 
0063 Q_SIGNALS:
0064     void modelChanged();
0065     void editMessageRequested(const QString &messageId, const QString &text);
0066     void quoteMessageRequested(const QString &messageId, const QString &text);
0067     void createNewDiscussion(const QString &messageId, const QString &originalMessage);
0068     void createPrivateConversation(const QString &userName);
0069     void loadHistoryRequested();
0070     void goToMessageRequested(const QString &messageId, const QString &messageDateTimeUtc);
0071     void replyInThreadRequested(const QString &messageId, const QString &text);
0072 
0073 private:
0074     LIBRUQOLAWIDGETS_NO_EXPORT void slotEditMessage(const QModelIndex &index);
0075     LIBRUQOLAWIDGETS_NO_EXPORT void slotDeleteMessage(const QModelIndex &index);
0076     LIBRUQOLAWIDGETS_NO_EXPORT void slotReportMessage(const QModelIndex &index);
0077     LIBRUQOLAWIDGETS_NO_EXPORT void slotSetAsFavorite(const QModelIndex &index, bool isStarred);
0078     LIBRUQOLAWIDGETS_NO_EXPORT void slotSetPinnedMessage(const QModelIndex &index, bool isPinned);
0079     LIBRUQOLAWIDGETS_NO_EXPORT void slotStartDiscussion(const QModelIndex &index);
0080     LIBRUQOLAWIDGETS_NO_EXPORT void slotStartPrivateConversation(const QString &userName);
0081     LIBRUQOLAWIDGETS_NO_EXPORT void slotTranslateMessage(const QModelIndex &index, bool checked);
0082     LIBRUQOLAWIDGETS_NO_EXPORT void createSeparator(QMenu &menu);
0083     LIBRUQOLAWIDGETS_NO_EXPORT void slotVerticalScrollbarChanged(int value);
0084     LIBRUQOLAWIDGETS_NO_EXPORT void slotReplyInThread(const QModelIndex &index);
0085     LIBRUQOLAWIDGETS_NO_EXPORT void slotDebugMessage(const QModelIndex &index);
0086     LIBRUQOLAWIDGETS_NO_EXPORT void slotMarkMessageAsUnread(const QModelIndex &index);
0087     LIBRUQOLAWIDGETS_NO_EXPORT void slotSelectAll(const QModelIndex &index);
0088     LIBRUQOLAWIDGETS_NO_EXPORT void slotShowFullThread(const QModelIndex &index);
0089     LIBRUQOLAWIDGETS_NO_EXPORT void slotQuoteMessage(const QModelIndex &index);
0090     LIBRUQOLAWIDGETS_NO_EXPORT void slotCopyLinkToMessage(const QModelIndex &index);
0091     LIBRUQOLAWIDGETS_NO_EXPORT void slotFollowMessage(const QModelIndex &index, bool messageIsFollowing);
0092     [[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT QString generatePermalink(const QString &messageId) const;
0093     LIBRUQOLAWIDGETS_NO_EXPORT void slotShowUserInfo(const QString &userName);
0094     LIBRUQOLAWIDGETS_NO_EXPORT void slotUpdateView();
0095     LIBRUQOLAWIDGETS_NO_EXPORT void slotTranslate(const QString &from, const QString &to, const QPersistentModelIndex &modelIndex);
0096     LIBRUQOLAWIDGETS_NO_EXPORT void slotTextToSpeech(const QModelIndex &index);
0097     LIBRUQOLAWIDGETS_NO_EXPORT void addDebugMenu(QMenu &menu, const QModelIndex &index);
0098     LIBRUQOLAWIDGETS_NO_EXPORT void addSelectedMessageBackgroundAnimation(const QModelIndex &index);
0099     LIBRUQOLAWIDGETS_NO_EXPORT void createTranslorMenu();
0100     LIBRUQOLAWIDGETS_NO_EXPORT void slotShowReportInfo(const ModerationReportInfos &info);
0101     [[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT QString selectedText(const QModelIndex &index) override;
0102     QPointer<Room> mRoom;
0103     const MessageListView::Mode mMode = MessageListView::Mode::Editing;
0104     MessageListDelegate *const mMessageListDelegate;
0105     TextTranslator::TranslatorMenu *mTranslatorMenu = nullptr;
0106     QPointer<RocketChatAccount> mCurrentRocketChatAccount;
0107 };