File indexing completed on 2024-12-01 04:36:51

0001 /*
0002    SPDX-FileCopyrightText: 2022-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 <QListView>
0011 #include <QVector>
0012 class PluginTextInterface;
0013 class LIBRUQOLAWIDGETS_TESTS_EXPORT MessageListViewBase : public QListView
0014 {
0015     Q_OBJECT
0016 public:
0017     explicit MessageListViewBase(QWidget *parent = nullptr);
0018     ~MessageListViewBase() override;
0019 
0020     void checkIfAtBottom();
0021     void updateVerticalPageStep();
0022     void maybeScrollToBottom();
0023     void copyMessageToClipboard(const QModelIndex &index = {});
0024 
0025 Q_SIGNALS:
0026     void errorMessage(const QString &message);
0027     void successMessage(const QString &message);
0028     void textToSpeech(const QString &str);
0029     void needToClearSizeHintCache();
0030 
0031 protected:
0032     void resizeEvent(QResizeEvent *ev) override;
0033 
0034     void mouseReleaseEvent(QMouseEvent *event) override;
0035     void mouseDoubleClickEvent(QMouseEvent *event) override;
0036 
0037     void mousePressEvent(QMouseEvent *event) override;
0038     void mouseMoveEvent(QMouseEvent *event) override;
0039 
0040     void leaveEvent(QEvent *event) override;
0041 
0042     virtual bool maybeStartDrag(QMouseEvent *event, const QStyleOptionViewItem &option, const QModelIndex &index);
0043     virtual bool mouseEvent(QMouseEvent *event, const QStyleOptionViewItem &option, const QModelIndex &index);
0044     [[nodiscard]] QStyleOptionViewItem listViewOptions() const;
0045 
0046     void addTextPlugins(QMenu *menu, const QString &selectedText);
0047 
0048     QVector<PluginTextInterface *> mPluginTextInterface;
0049 
0050     [[nodiscard]] virtual QString selectedText(const QModelIndex &index);
0051 
0052 private:
0053     LIBRUQOLAWIDGETS_NO_EXPORT void handleMouseEvent(QMouseEvent *event);
0054     bool mAtBottom = true;
0055     QPoint mPressedPosition;
0056     QPersistentModelIndex mCurrentIndex = {};
0057 };