File indexing completed on 2024-12-08 04:34:13

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 #include "messages/messageattachment.h"
0009 #include "messages/messageurl.h"
0010 
0011 #include <QAbstractTextDocumentLayout>
0012 #include <QModelIndex>
0013 #include <QString>
0014 #include <QStyleOptionViewItem>
0015 #include <QVector>
0016 #include <memory>
0017 
0018 class TextSelection;
0019 class QTextDocument;
0020 class MessageUrl;
0021 namespace MessageDelegateUtils
0022 {
0023 [[nodiscard]] std::unique_ptr<QTextDocument> createTextDocument(bool useItalic, const QString &text, int width);
0024 
0025 [[nodiscard]] bool generateToolTip(const QTextDocument *doc, const QPoint &pos, QString &formattedTooltip);
0026 
0027 void generateToolTip(const QString &toolTip, const QString &href, QString &formattedTooltip);
0028 
0029 [[nodiscard]] bool useItalicsForMessage(const QModelIndex &index);
0030 
0031 [[nodiscard]] bool pendingMessage(const QModelIndex &index);
0032 [[nodiscard]] QVector<QAbstractTextDocumentLayout::Selection> selection(TextSelection *selection,
0033                                                                         QTextDocument *doc,
0034                                                                         const QModelIndex &index,
0035                                                                         const QStyleOptionViewItem &option,
0036                                                                         const MessageAttachment &msgAttach = {},
0037                                                                         const MessageUrl &msgUrl = {},
0038                                                                         bool isAMessage = true);
0039 
0040 void drawSelection(QTextDocument *doc,
0041                    QRect rect,
0042                    int top,
0043                    QPainter *painter,
0044                    const QModelIndex &index,
0045                    const QStyleOptionViewItem &option,
0046                    TextSelection *selection,
0047                    const MessageAttachment &msgAttach,
0048                    const MessageUrl &msgUrl,
0049                    bool isAMessage = true);
0050 
0051 void setClipboardSelection(TextSelection *selection);
0052 
0053 [[nodiscard]] QSizeF dprAwareSize(const QPixmap &pixmap);
0054 
0055 [[nodiscard]] qreal basicMargin();
0056 [[nodiscard]] QSize timeStampSize(const QString &timeStampText, const QStyleOptionViewItem &option);
0057 [[nodiscard]] QSize textSizeHint(QTextDocument *doc, qreal *pBaseLine);
0058 [[nodiscard]] bool showIgnoreMessages(const QModelIndex &index);
0059 }