File indexing completed on 2024-05-19 05:04:27

0001 /*
0002    SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "delegateutils/textselection.h"
0010 #include "libruqolawidgets_private_export.h"
0011 #include "misc/messagelistdelegatebase.h"
0012 class QListView;
0013 
0014 class LIBRUQOLAWIDGETS_TESTS_EXPORT ServerErrorInfoHistoryDelegate : public MessageListDelegateBase
0015 {
0016     Q_OBJECT
0017 public:
0018     explicit ServerErrorInfoHistoryDelegate(QListView *view, QObject *parent = nullptr);
0019     ~ServerErrorInfoHistoryDelegate() override;
0020 
0021     void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
0022 
0023     [[nodiscard]] bool helpEvent(QHelpEvent *helpEvent, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index) override;
0024 
0025     [[nodiscard]] bool mouseEvent(QEvent *event, const QStyleOptionViewItem &option, const QModelIndex &index);
0026 
0027     [[nodiscard]] bool maybeStartDrag(QMouseEvent *event, const QStyleOptionViewItem &option, const QModelIndex &index);
0028 
0029 protected:
0030     [[nodiscard]] QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
0031 
0032     [[nodiscard]] RocketChatAccount *rocketChatAccount(const QModelIndex &index) const override;
0033 
0034 private:
0035     [[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT QTextDocument *documentForModelIndex(const QModelIndex &index, int width) const override;
0036 
0037     struct Layout {
0038         // Text message
0039         QRect textRect;
0040         qreal baseLine; // used to draw sender/timestamp
0041 
0042         QString timeStampText;
0043         QPoint timeStampPos;
0044         bool sameAccountAsPreviousMessage = false;
0045     };
0046     LIBRUQOLAWIDGETS_NO_EXPORT void drawAccountInfo(QPainter *painter, const QModelIndex &index, const QStyleOptionViewItem &option) const;
0047     [[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT ServerErrorInfoHistoryDelegate::Layout doLayout(const QStyleOptionViewItem &option,
0048                                                                                              const QModelIndex &index) const;
0049     [[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT QPoint adaptMousePosition(const QPoint &pos, QRect textRect, const QStyleOptionViewItem &option);
0050     [[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT QString cacheIdentifier(const QModelIndex &index) const;
0051 };