KTextEditor

abstractannotationitemdelegate.h
1/*
2 SPDX-FileCopyrightText: 2017-2018 Friedrich W. H. Kossebau <kossebau@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef KTEXTEDITOR_ABSTRACTANNOTATIONITEMDELEGATE_H
8#define KTEXTEDITOR_ABSTRACTANNOTATIONITEMDELEGATE_H
9
10#include <ktexteditor_export.h>
11
12#include <QObject>
13#include <QStyleOption>
14
15class QHelpEvent;
16class QPoint;
17
18namespace KTextEditor
19{
20class AnnotationModel;
21class View;
22
23/**
24 * \brief The style option set for an annotation item, as painted by AbstractAnnotationItemDelegate
25 *
26 * \since 5.53
27 * \see KTextEditor::AbstractAnnotationItemDelegate
28 */
29class KTEXTEDITOR_EXPORT StyleOptionAnnotationItem : public QStyleOption
30{
31public:
32 // TODO: not sure what SO_Default implies, but no clue how to maintain a user type registry?
33 enum StyleOptionType {
34 Type = SO_Default
35 };
36 enum StyleOptionVersion {
37 Version = 1
38 };
39
40 /**
41 * Index of the displayed line in the wrapped lines for the given real line
42 */
43 int wrappedLine = 0;
44 /**
45 * Number of wrapped lines for the given real line
46 *
47 * A value of 1 means no wrapping has happened and the real line is displayed as one line.
48 */
49 int wrappedLineCount = 1;
50 /**
51 * Index of the displayed line in the displayed lines for the same group
52 */
53 int visibleWrappedLineInGroup = 0;
54
55 /**
56 * The view where the annotation is shown
57 *
58 * There is always a view set.
59 */
60 KTextEditor::View *view = nullptr;
61 /**
62 * Recommended size for icons or other symbols that will be rendered by the delegate
63 *
64 * The default value is QSize(-1, -1).
65 */
67 /**
68 * The metrics of the font used for rendering the text document
69 */
71
72 /**
73 * Enum for describing the relative position of a real line in the row of consecutive
74 * displayed lines which belong to the same group of annotation items
75 * @see AnnotationItemGroupPositions
76 */
78 InvalidGroupPosition = 0, ///< Position not specified or not belonging to a group
79 InGroup = 0x1 << 0, ///< Real line belongs to a group
80 GroupBegin = 0x1 << 1, ///< Real line is first of consecutive lines from same group
81 GroupEnd = 0x1 << 2, ///< Real line is last of consecutive lines from same group
82 };
83 /// Stores a combination of #AnnotationItemGroupPosition values.
85
86 /**
87 * Relative position of the real line in the row of consecutive displayed lines
88 * which belong to the same group of annotation items
89 */
90 AnnotationItemGroupPositions annotationItemGroupingPosition = InvalidGroupPosition;
91
92public:
95 StyleOptionAnnotationItem &operator=(const StyleOptionAnnotationItem &) = default;
96
97protected:
98 explicit StyleOptionAnnotationItem(int version);
99};
100
101/**
102 * \class AbstractAnnotationItemDelegate abstractannotationitemdelegate.h <KTextEditor/AbstractAnnotationItemDelegate>
103 *
104 * \brief A delegate for rendering line annotation information and handling events
105 *
106 * \section annodelegate_intro Introduction
107 *
108 * AbstractAnnotationItemDelegate is a base class that can be reimplemented
109 * to customize the rendering of annotation information for each line in a document.
110 * It provides also the hooks to define handling of help events like tooltip or of
111 * the request for a context menu.
112 *
113 * \section annodelegate_impl Implementing an AbstractAnnotationItemDelegate
114 *
115 * The public interface of this class is loosely based on the QAbstractItemDelegate
116 * interfaces. It has five methods to implement.
117 *
118 * \since 5.53
119 * \see KTextEditor::AnnotationModel, KTextEditor::AnnotationViewInterface
120 */
121class KTEXTEDITOR_EXPORT AbstractAnnotationItemDelegate : public QObject
122{
123 Q_OBJECT
124
125protected:
126 explicit AbstractAnnotationItemDelegate(QObject *parent = nullptr);
127
128public:
130
131public:
132 /**
133 * This pure abstract function must be reimplemented to provide custom rendering.
134 * Use the painter and style option to render the annotation information for the line
135 * specified by the arguments @p model and @p line.
136 * @param painter the painter object
137 * @param option the option object with the info needed for styling
138 * @param model the annotation model providing the annotation information
139 * @param line index of the real line the annotation information should be painted for
140 *
141 * Reimplement this in line with sizeHint().
142 */
143 virtual void paint(QPainter *painter, const KTextEditor::StyleOptionAnnotationItem &option, KTextEditor::AnnotationModel *model, int line) const = 0;
144 /**
145 * This pure abstract function must be reimplemented to provide custom rendering.
146 * Use the style option to calculate the best size for the annotation information
147 * for the line specified by the arguments @p model and @p line.
148 * This should be the size for the display for a single displayed content line,
149 * i.e. with no line wrapping or consecutive multiple annotation item of the same group assumed.
150 *
151 * @note If AnnotationViewInterface::uniformAnnotationItemSizes() is @c true for the view
152 * this delegate is used by, it is assumed that the returned value is the same for
153 * any line.
154 *
155 * @param option the option object with the info needed for styling
156 * @param model the annotation model providing the annotation information
157 * @param line index of the real line the annotation information should be painted for
158 * @return best size for the annotation information
159 *
160 * Reimplement this in line with paint().
161 */
162 virtual QSize sizeHint(const KTextEditor::StyleOptionAnnotationItem &option, KTextEditor::AnnotationModel *model, int line) const = 0;
163 /**
164 * Whenever a help event occurs, this function is called with the event view option
165 * and @p model and @p line specifying the item where the event occurs.
166 * This pure abstract function must be reimplemented to provide custom tooltips.
167 * @param event the help event
168 * @param view the view for which the help event is requested
169 * @param option the style option object with the info needed for styling, including the rect of the annotation
170 * @param model the annotation model providing the annotation information
171 * @param line index of the real line the annotation information should be painted for
172 * @return @c true if the event could be handled (implies that the data obtained from the model had the required role), @c false otherwise
173 *
174 * Reimplement this in line with hideTooltip().
175 */
176 virtual bool helpEvent(QHelpEvent *event,
177 KTextEditor::View *view,
180 int line) = 0;
181 /**
182 * This pure abstract function must be reimplemented to provide custom tooltips.
183 * It is called whenever a possible still shown tooltip no longer is valid,
184 * e.g. if the annotations have been hidden.
185 * @param view the view for which the tooltip was requested
186 *
187 * Reimplement this in line with helpEvent().
188 */
189 virtual void hideTooltip(KTextEditor::View *view) = 0;
190
191Q_SIGNALS:
192 /**
193 * This signal must be emitted when the sizeHint() for @p model and @p line changed.
194 * The view automatically connects to this signal and relayouts as necessary.
195 * If AnnotationViewInterface::uniformAnnotationItemSizes is set on the view,
196 * it is sufficient to emit sizeHintChanged only for one line.
197 * @param model the annotation model providing the annotation information
198 * @param line index of the real line the annotation information should be painted for
199 */
201};
202
203}
204
205#endif
A delegate for rendering line annotation information and handling events.
virtual void hideTooltip(KTextEditor::View *view)=0
This pure abstract function must be reimplemented to provide custom tooltips.
virtual bool helpEvent(QHelpEvent *event, KTextEditor::View *view, const KTextEditor::StyleOptionAnnotationItem &option, KTextEditor::AnnotationModel *model, int line)=0
Whenever a help event occurs, this function is called with the event view option and model and line s...
void sizeHintChanged(KTextEditor::AnnotationModel *model, int line)
This signal must be emitted when the sizeHint() for model and line changed.
virtual QSize sizeHint(const KTextEditor::StyleOptionAnnotationItem &option, KTextEditor::AnnotationModel *model, int line) const =0
This pure abstract function must be reimplemented to provide custom rendering.
virtual void paint(QPainter *painter, const KTextEditor::StyleOptionAnnotationItem &option, KTextEditor::AnnotationModel *model, int line) const =0
This pure abstract function must be reimplemented to provide custom rendering.
An model for providing line annotation information.
The style option set for an annotation item, as painted by AbstractAnnotationItemDelegate.
QSize decorationSize
Recommended size for icons or other symbols that will be rendered by the delegate.
AnnotationItemGroupPosition
Enum for describing the relative position of a real line in the row of consecutive displayed lines wh...
QFontMetricsF contentFontMetrics
The metrics of the font used for rendering the text document.
A text widget with KXMLGUIClient that represents a Document.
Definition view.h:244
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:11:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.