Changeset View
Changeset View
Standalone View
Standalone View
src/include/ktexteditor/inlinenoteprovider.h
- This file was added.
1 | /* This file is part of the KDE libraries | ||||
---|---|---|---|---|---|
2 | | ||||
3 | Copyright 2018 Sven Brauch <mail@svenbrauch.de> | ||||
4 | Copyright 2018 Michal Srb <michalsrb@gmail.com> | ||||
5 | | ||||
6 | This library is free software; you can redistribute it and/or | ||||
7 | modify it under the terms of the GNU Lesser General Public | ||||
8 | License as published by the Free Software Foundation; either | ||||
9 | version 2.1 of the License, or (at your option) version 3, or any | ||||
10 | later version accepted by the membership of KDE e.V. (or its | ||||
11 | successor approved by the membership of KDE e.V.), which shall | ||||
12 | act as a proxy defined in Section 6 of version 3 of the license. | ||||
13 | | ||||
14 | This library is distributed in the hope that it will be useful, | ||||
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
17 | Library General Public License for more details. | ||||
18 | | ||||
19 | You should have received a copy of the GNU Library General Public License | ||||
20 | along with this library; see the file COPYING.LIB. If not, write to | ||||
21 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
22 | Boston, MA 02110-1301, USA. | ||||
23 | */ | ||||
24 | #ifndef KTEXTEDITOR_INLINENOTEPROVIDER_H | ||||
25 | #define KTEXTEDITOR_INLINENOTEPROVIDER_H | ||||
26 | | ||||
27 | #include <ktexteditor_export.h> | ||||
28 | | ||||
29 | #include <ktexteditor/inlinenote.h> | ||||
30 | | ||||
31 | namespace KTextEditor { | ||||
32 | /** | ||||
33 | * @brief A source of inline notes for a document. | ||||
34 | * | ||||
35 | * InlineNoteProvider is object that can be queried for inline notes in the | ||||
36 | * document. It emits signals when the notes change and should be queried again. | ||||
37 | * | ||||
38 | * @see InlineNoteInterface | ||||
39 | * @since 5.50 | ||||
40 | */ | ||||
41 | class KTEXTEDITOR_EXPORT InlineNoteProvider : public QObject | ||||
42 | { | ||||
43 | Q_OBJECT | ||||
44 | | ||||
45 | public: | ||||
46 | /** | ||||
47 | * Default constructor. | ||||
48 | */ | ||||
49 | InlineNoteProvider(); | ||||
50 | | ||||
51 | /** | ||||
52 | * Virtual destructor to allow inheritance. | ||||
53 | */ | ||||
54 | virtual ~InlineNoteProvider(); | ||||
55 | | ||||
56 | /** | ||||
57 | * Get list of inline notes for given line. | ||||
58 | * | ||||
59 | * Should return a vector of columns on which the notes are located. | ||||
60 | * 0 means the note is located before the first character of the line. | ||||
61 | * 1 means the note is located after the first character, etc. If the | ||||
62 | * returned number is bigger than the length of the line, the note will be | ||||
63 | * placed behind the text as if there were additional spaces. | ||||
64 | * | ||||
65 | * @param line Line number | ||||
66 | * @returns vector of columns where inline notes appear in this line | ||||
67 | */ | ||||
68 | virtual QVector<int> inlineNotes(int line) const = 0; | ||||
69 | | ||||
70 | /** | ||||
71 | * Width to be reserved for the note in the text. | ||||
72 | * | ||||
73 | * The method is given the height of the line and the metrics of current | ||||
74 | * font which it may use for calculating the width. | ||||
75 | * | ||||
76 | * @param height the height of the line in pixels | ||||
77 | * | ||||
78 | * @return the width of the note in pixels | ||||
79 | */ | ||||
80 | virtual QSize inlineNoteSize(const InlineNote& note) const = 0; | ||||
81 | | ||||
82 | /** | ||||
83 | * Paint the note into the line. | ||||
84 | * | ||||
85 | * The method should use the given painter to render the note into the | ||||
86 | * line. The painter is translated such that coordinates 0x0 mark the top | ||||
87 | * left corner of the note. The method should not paint outside rectangle | ||||
88 | * given by the height parameter and the width previously returned by the | ||||
89 | * width method. | ||||
90 | * | ||||
91 | * The method is given the height of the line, the metrics of current font | ||||
92 | * and the font which it may use during painting. | ||||
93 | * | ||||
94 | * @param note note to paint, containing location and index | ||||
95 | * @param painter painter prepared for rendering the note | ||||
96 | */ | ||||
97 | virtual void paintInlineNote(const InlineNote& note, QPainter& painter) const = 0; | ||||
98 | | ||||
99 | /** | ||||
100 | * Invoked when a note is activated by the user. | ||||
101 | * | ||||
102 | * This method is called when a user activates a note, i.e. clicks on it. | ||||
103 | * Coordinates of @p pos are in note coordinates, i.e. relative to the note's | ||||
104 | * top-left corner (same coordinate system as the painter has in paintInlineNote()). | ||||
105 | * | ||||
106 | * The default implementation does nothing. | ||||
107 | * | ||||
108 | * @param note the note which was activated | ||||
109 | * @param buttons the button(s) the note was clicked with | ||||
110 | * @param pos the point the note was clicked at | ||||
111 | */ | ||||
112 | virtual void inlineNoteActivated(const InlineNote& note, Qt::MouseButtons buttons, const QPoint& pos); | ||||
113 | | ||||
114 | /** | ||||
115 | * Invoked when the mouse cursor moves into the note when it was outside before. | ||||
116 | * | ||||
117 | * The default implementation does nothing. | ||||
118 | * | ||||
119 | * @param note the note which was activated | ||||
120 | * @param pos the location of the mouse cursor, in note coordinates | ||||
121 | */ | ||||
122 | virtual void inlineNoteFocusInEvent(const InlineNote& note, const QPoint& pos); | ||||
123 | | ||||
124 | /** | ||||
125 | * Invoked when the mouse cursor leaves the note. | ||||
126 | * | ||||
127 | * The default implementation does nothing. | ||||
128 | * | ||||
129 | * @param note the note which was deactivated | ||||
130 | */ | ||||
131 | virtual void inlineNoteFocusOutEvent(const InlineNote& note); | ||||
132 | | ||||
133 | /** | ||||
134 | * Invoked when the mouse cursor moves inside the note. | ||||
135 | * | ||||
136 | * The default implementation does nothing. | ||||
137 | * | ||||
138 | * @param note the note which was hovered | ||||
139 | * @param pos the location of the mouse cursor, in note coordinates | ||||
140 | */ | ||||
141 | virtual void inlineNoteMouseMoveEvent(const InlineNote& note, const QPoint& pos); | ||||
142 | | ||||
143 | Q_SIGNALS: | ||||
144 | /** | ||||
145 | * The provider should emit the signal inlineNotesReset() when almost all inline notes | ||||
146 | * changed. | ||||
147 | */ | ||||
148 | void inlineNotesReset(); | ||||
149 | | ||||
150 | /** | ||||
151 | * The provider should emit the signal inlineNotesChanged() when any of the | ||||
152 | * inline notes on the line changed. | ||||
153 | */ | ||||
154 | void inlineNotesChanged(int line); | ||||
155 | }; | ||||
156 | | ||||
157 | } | ||||
158 | | ||||
159 | #endif |