KTextAddons

textautogeneratelistviewtextselection.h
1/*
2 SPDX-FileCopyrightText: 2021 David Faure <faure@kde.org>
3 SPDX-FileCopyrightText: 2024-2025 Laurent Montel <montel@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#pragma once
9#include <QObject>
10#include <QPersistentModelIndex>
11
12class QTextCursor;
13class QTextDocument;
14namespace TextAutogenerateText
15{
16class TextAutogenerateListViewDelegate;
17class TextAutogenerateListViewTextSelection : public QObject
18{
20public:
21 explicit TextAutogenerateListViewTextSelection(TextAutogenerateListViewDelegate *delegate, QObject *parent = nullptr);
22 [[nodiscard]] bool hasSelection() const;
23 enum class Format : uint8_t {
24 Text,
25 Html,
26 };
27 [[nodiscard]] QString selectedText(Format format) const;
28 [[nodiscard]] bool contains(const QModelIndex &index, int charPos) const;
29 [[nodiscard]] QTextCursor selectionForIndex(const QModelIndex &index, QTextDocument *doc) const;
30
31 void clear();
32 void setTextSelectionStart(const QModelIndex &index, int charPos);
33 void setTextSelectionEnd(const QModelIndex &index, int charPos);
34 void setAttachmentTextAutogenerateListViewTextSelectionEnd(const QModelIndex &index, int charPos);
35 void selectWordUnderCursor(const QModelIndex &index, int charPos);
36 void selectMessage(const QModelIndex &index);
37
38 [[nodiscard]] bool mightStartDrag() const;
39 void setMightStartDrag(bool newMightStartDrag);
40
42 void repaintNeeded(const QModelIndex &index);
43
44private:
45 void selectWord(const QModelIndex &index, int charPos, QTextDocument *doc);
46 struct OrderedPositions {
47 int fromRow;
48 int fromCharPos;
49 int toRow;
50 int toCharPos;
51 };
52
53 [[nodiscard]] OrderedPositions orderedPositions() const;
54 void selectionText(const OrderedPositions ordered, Format format, int row, const QModelIndex &index, QTextDocument *doc, QString &str) const;
55
56 QPersistentModelIndex mStartIndex;
57 QPersistentModelIndex mEndIndex;
58 int mStartPos = -1; // first selected character in start row
59 int mEndPos = -1; // last selected character in end row
60 TextAutogenerateListViewDelegate *const mDelegate;
61 bool mMightStartDrag = false;
62};
63}
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Apr 25 2025 12:06:13 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.