File indexing completed on 2024-06-09 04:59:24
0001 /* 0002 SPDX-FileCopyrightText: 2020 David Faure <faure@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "delegateutils/textselection.h" 0010 #include "delegateutils/textselectionimpl.h" 0011 0012 #include "messagedelegatehelperbase.h" 0013 0014 #include <QModelIndex> 0015 #include <QSize> 0016 class QTextDocument; 0017 0018 class QListView; 0019 class QPainter; 0020 class QRect; 0021 class QMouseEvent; 0022 class QHelpEvent; 0023 class QStyleOptionViewItem; 0024 class RocketChatAccount; 0025 0026 class MessageDelegateHelperText : public MessageDelegateHelperBase 0027 { 0028 Q_OBJECT 0029 public: 0030 explicit MessageDelegateHelperText(RocketChatAccount *account, QListView *view, TextSelectionImpl *textSelectionImpl); 0031 ~MessageDelegateHelperText() override; 0032 void draw(QPainter *painter, QRect rect, const QModelIndex &index, const QStyleOptionViewItem &option); 0033 [[nodiscard]] QSize sizeHint(const QModelIndex &index, int maxWidth, const QStyleOptionViewItem &option, qreal *pBaseLine) const; 0034 [[nodiscard]] bool handleMouseEvent(QMouseEvent *mouseEvent, QRect messageRect, const QStyleOptionViewItem &option, const QModelIndex &index); 0035 [[nodiscard]] bool handleHelpEvent(QHelpEvent *helpEvent, QRect messageRect, const QModelIndex &index); 0036 [[nodiscard]] bool maybeStartDrag(QMouseEvent *event, QRect messageRect, const QStyleOptionViewItem &option, const QModelIndex &index); 0037 0038 void setShowThreadContext(bool b); 0039 [[nodiscard]] bool showThreadContext() const; 0040 0041 [[nodiscard]] QString urlAt(const QModelIndex &index, QPoint relativePos) const; 0042 0043 private: 0044 friend class TextSelection; // for documentForIndex 0045 [[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT QString makeMessageText(const QPersistentModelIndex &index, bool connectToUpdates) const; 0046 /** 0047 * Creates (or retrieves from a cache) the QTextDocument for a given @p index. 0048 * @param width The width for layouting that QTextDocument. -1 if no layouting is desired (e.g. for converting to text or HTML) 0049 * @param widget The view to update when fetching thread context on demand. nullptr if this isn't needed (e.g. from SelectionManager) 0050 * @return the QTextDocument. Ownership remains with the cache, don't delete it. 0051 */ 0052 [[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT QTextDocument *documentForIndex(const QModelIndex &index) const override; 0053 [[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT QTextDocument *documentForIndex(const QModelIndex &index, int width, bool connectToUpdates) const; 0054 0055 bool mShowThreadContext = true; 0056 };