Changeset View
Changeset View
Standalone View
Standalone View
src/include/ktexteditor/inlinenote.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_INLINENOTE_H | ||||
25 | #define KTEXTEDITOR_INLINENOTE_H | ||||
26 | | ||||
27 | #include <ktexteditor/view.h> | ||||
28 | #include <ktexteditor/cursor.h> | ||||
29 | | ||||
30 | class QFont; | ||||
31 | namespace KTextEditor { class InlineNoteProvider; } | ||||
32 | | ||||
33 | namespace KTextEditor { | ||||
34 | | ||||
35 | /** | ||||
36 | * Describes an inline note. | ||||
37 | * | ||||
38 | * This structure contains all the information required to deal with | ||||
39 | * a particular inline note. It is instantiated and populated with information | ||||
40 | * internally by KTextEditor based on the list of notes returned by | ||||
41 | * InlineNoteProvider::inlineNotes(), and then passed back to the user of the API. | ||||
42 | * | ||||
43 | * Users of the InlineNoteInterface API should never need to modify instances | ||||
44 | * of this structure. | ||||
45 | * | ||||
46 | * @since 5.50 | ||||
47 | */ | ||||
48 | class KTEXTEDITOR_EXPORT InlineNote | ||||
49 | { | ||||
50 | public: | ||||
51 | /** | ||||
52 | * Constructs an inline note. User code usually does not need to call this, | ||||
53 | * notes are created from the columns returned by InlineNoteProvider::inlineNotes(int line), | ||||
54 | * and then passed around as handles grouping useful information. | ||||
55 | */ | ||||
56 | InlineNote(InlineNoteProvider* provider, const KTextEditor::Cursor& position, int index, | ||||
57 | const KTextEditor::View* view, QFont font, int lineHeight, bool hasFocus); | ||||
58 | | ||||
59 | /** | ||||
60 | * Constructs an invalid inline note, i.e. isValid() will return false. | ||||
61 | */ | ||||
62 | InlineNote(); | ||||
63 | | ||||
64 | /** | ||||
65 | * Returns the column this note appears in. | ||||
66 | */ | ||||
67 | int column() const; | ||||
68 | | ||||
69 | /** | ||||
70 | * Returns the width of this note in pixels. | ||||
71 | */ | ||||
72 | qreal width() const; | ||||
73 | | ||||
74 | /** | ||||
75 | * Tells whether this note is valid, i.e. whether it has a valid provider and location set. | ||||
76 | */ | ||||
77 | bool isValid() const; | ||||
78 | | ||||
79 | /** | ||||
80 | * Equality of notes. Only checks provider, index, and position. | ||||
81 | */ | ||||
82 | bool operator==(const InlineNote& other) const; | ||||
83 | | ||||
84 | /** | ||||
85 | * Transforms the given @p pos from note coordinates to global (screen) coordinates. | ||||
86 | * | ||||
87 | * Useful for showing a popup; to e.g. show a popup at the bottom left corner | ||||
88 | * of a note, show it at @c mapToGlobal({0, noteHeight}). | ||||
89 | */ | ||||
90 | QPoint mapToGlobal(const QPoint& pos) const; | ||||
91 | | ||||
92 | /** | ||||
93 | * The provider which created this note | ||||
94 | */ | ||||
95 | InlineNoteProvider* provider() const; | ||||
96 | | ||||
97 | /** | ||||
98 | * The view this note is shown in | ||||
99 | */ | ||||
100 | const KTextEditor::View* view() const; | ||||
101 | | ||||
102 | /** | ||||
103 | * The position of this note | ||||
104 | */ | ||||
105 | KTextEditor::Cursor position() const; | ||||
106 | | ||||
107 | /** | ||||
108 | * The index of this note, i.e. its index in the vector returned by | ||||
109 | * the provider for a given line | ||||
110 | */ | ||||
111 | int index() const; | ||||
112 | | ||||
113 | /** | ||||
114 | * Whether the mouse cursor is currently over this note; only set | ||||
115 | * when paintInlineNote() is called | ||||
116 | */ | ||||
117 | bool hasFocus() const; | ||||
118 | | ||||
119 | /** | ||||
120 | * The font of the text surrounding this note | ||||
121 | */ | ||||
122 | QFont font() const; | ||||
123 | | ||||
124 | /** | ||||
125 | * The height of the line containing this note | ||||
126 | */ | ||||
127 | int lineHeight() const; | ||||
128 | | ||||
129 | private: | ||||
130 | InlineNoteProvider* m_provider = nullptr; | ||||
131 | const KTextEditor::View* m_view = nullptr; | ||||
132 | KTextEditor::Cursor m_position; | ||||
133 | int m_index = -1; | ||||
134 | bool m_hasFocus = false; | ||||
135 | QFont m_font; | ||||
136 | int m_lineHeight = -1; | ||||
137 | | ||||
138 | // For future use, in case members need to be added. | ||||
139 | // TODO KF6: remove if it turns out this is unneeded. | ||||
140 | class InlineNotePrivate* d = nullptr; | ||||
141 | }; | ||||
142 | | ||||
143 | } | ||||
144 | | ||||
145 | #endif |