File indexing completed on 2024-06-09 04:59:22

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 "messageattachmentdelegatehelperbase.h"
0010 
0011 #include <QIcon>
0012 #include <QRect>
0013 #include <QString>
0014 
0015 class LIBRUQOLAWIDGETS_TESTS_EXPORT MessageAttachmentDelegateHelperFile : public MessageAttachmentDelegateHelperBase
0016 {
0017 public:
0018     explicit MessageAttachmentDelegateHelperFile(RocketChatAccount *account, QListView *view, TextSelectionImpl *textSelectionImpl);
0019     ~MessageAttachmentDelegateHelperFile() override;
0020     void draw(const MessageAttachment &msgAttach,
0021               QPainter *painter,
0022               QRect attachmentsRect,
0023               const QModelIndex &index,
0024               const QStyleOptionViewItem &option) const override;
0025     [[nodiscard]] QSize sizeHint(const MessageAttachment &msgAttach, const QModelIndex &index, int maxWidth, const QStyleOptionViewItem &option) const override;
0026     [[nodiscard]] bool handleMouseEvent(const MessageAttachment &msgAttach,
0027                                         QMouseEvent *mouseEvent,
0028                                         QRect attachmentsRect,
0029                                         const QStyleOptionViewItem &option,
0030                                         const QModelIndex &index) override;
0031 
0032 private:
0033     struct FileLayout {
0034         QString title;
0035         QString description;
0036         QSize titleSize;
0037         QSize descriptionSize;
0038         QRect downloadButtonRect;
0039         int y; // relative
0040         int height;
0041         QString link;
0042     };
0043     [[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT FileLayout doLayout(const MessageAttachment &msgAttach,
0044                                                                  const QStyleOptionViewItem &option,
0045                                                                  int attachmentsWidth) const;
0046     LIBRUQOLAWIDGETS_NO_EXPORT void handleDownloadClicked(const QString &link, QWidget *widget);
0047     friend class MessageDelegateHelperFileTest;
0048     const QIcon mDownloadIcon;
0049     [[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT QPoint adaptMousePosition(const QPoint &pos,
0050                                                                        const MessageAttachment &msgAttach,
0051                                                                        QRect attachmentsRect,
0052                                                                        const QStyleOptionViewItem &option) override;
0053 };