KTextEditor

texthintinterface.h
1 /*
2  SPDX-FileCopyrightText: 2001 Joseph Wenninger <[email protected]>
3  SPDX-FileCopyrightText: 2013-2014 Dominik Haumann <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #ifndef KTEXTEDITOR_TEXTHINTINTERFACE_H
9 #define KTEXTEDITOR_TEXTHINTINTERFACE_H
10 
11 #include <QString>
12 
13 #include <ktexteditor_export.h>
14 
15 #include <ktexteditor/cursor.h>
16 
17 namespace KTextEditor
18 {
19 class TextHintProvider;
20 class View;
21 
22 /**
23  * \class TextHintInterface texthininterface.h <KTextEditor/TextHintInterface>
24  *
25  * \brief Text hint interface showing tool tips under the mouse for the View.
26  *
27  * \ingroup kte_group_view_extensions
28  *
29  * \section texthint_introduction Introduction
30  *
31  * The text hint interface provides a way to show tool tips for text located
32  * under the mouse. Possible applications include showing a value of a variable
33  * when debugging an application, or showing a complete path of an include
34  * directive.
35  *
36  * \image html texthint.png "Text hint showing the contents of a variable"
37  *
38  * To register as text hint provider, call registerTextHintProvider() with an
39  * instance that inherits TextHintProvider. Finally, make sure you remove your
40  * text hint provider by calling unregisterTextHintProvider().
41  *
42  * Text hints are shown after the user hovers with the mouse for a delay of
43  * textHintDelay() milliseconds over the same word. To change the delay, call
44  * setTextHintDelay().
45  *
46  * \section texthint_access Accessing the TextHintInterface
47  *
48  * The TextHintInterface is an extension interface for a
49  * View, i.e. the View inherits the interface. Use qobject_cast to access the
50  * interface:
51  * \code
52  * // view is of type KTextEditor::View*
53  * auto iface = qobject_cast<KTextEditor::TextHintInterface*>(view);
54  *
55  * if (iface) {
56  * // the implementation supports the interface
57  * // myProvider inherits KTextEditor::TextHintProvider
58  * iface->registerTextHintProvider(myProvider);
59  * } else {
60  * // the implementation does not support the interface
61  * }
62  * \endcode
63  *
64  * \see TextHintProvider
65  * \since 4.11
66  */
67 class KTEXTEDITOR_EXPORT TextHintInterface
68 {
69 public:
71  virtual ~TextHintInterface();
72 
73  /**
74  * Register the text hint provider \p provider.
75  *
76  * Whenever the user hovers over text, \p provider will be asked for
77  * a text hint. When the provider is about to be destroyed, make
78  * sure to call unregisterTextHintProvider() to avoid a dangling pointer.
79  *
80  * @param provider text hint provider
81  * @see unregisterTextHintProvider(), TextHintProvider
82  */
83  virtual void registerTextHintProvider(KTextEditor::TextHintProvider *provider) = 0;
84 
85  /**
86  * Unregister the text hint provider \p provider.
87  *
88  * @param provider text hint provider to unregister
89  * @see registerTextHintProvider(), TextHintProvider
90  */
91  virtual void unregisterTextHintProvider(KTextEditor::TextHintProvider *provider) = 0;
92 
93  /**
94  * Set the text hint delay to \p delay milliseconds.
95  *
96  * The delay specifies the time the user needs to hover over the text
97  * before the tool tip is shown. Therefore, \p delay should not be
98  * too large, a value of 500 milliseconds is recommended and set by
99  * default.
100  *
101  * If \p delay is <= 0, the default delay will be set.
102  *
103  * \param delay tool tip delay in milliseconds
104  */
105  virtual void setTextHintDelay(int delay) = 0;
106 
107  /**
108  * Get the text hint delay in milliseconds.
109  * By default, the text hint delay is set to 500 milliseconds.
110  * It can be changed by calling \p setTextHintDelay().
111  */
112  virtual int textHintDelay() const = 0;
113 
114 private:
115  class TextHintInterfacePrivate *const d = nullptr;
116 };
117 
118 /**
119  * \brief Class to provide text hints for a View.
120  *
121  * The class TextHintProvider is used in combination with TextHintInterface.
122  * TextHintProvider allows to provide text hint information for text under
123  * the mouse cursor.
124  *
125  * To use this class, derive your provider from TextHintProvider and register
126  * it with TextHintInterface::registerTextHintProvider(). When not needed
127  * anymore, make sure to remove your provider by calling
128  * TextHintInterface::unregisterTextHintProvider(), otherwise the View will
129  * contain a dangling pointer to your potentially deleted provider.
130  *
131  * Detailed information about how to use the TextHintInterface can be found
132  * in the documentation about the TextHintInterface.
133  *
134  * \see TextHintInterface
135  * \p since 5.0
136  */
137 class KTEXTEDITOR_EXPORT TextHintProvider
138 {
139 public:
140  /**
141  * Default constructor.
142  */
144 
145  /**
146  * Virtual destructor to allow inheritance.
147  */
148  virtual ~TextHintProvider();
149 
150  /**
151  * This function is called whenever the users hovers over text such
152  * that the text hint delay passes. Then, textHint() is called
153  * for each registered TextHintProvider.
154  *
155  * Return the text hint (possibly Qt richtext) for @p view at @p position.
156  *
157  * If you do not have any contents to show, just return an empty QString().
158  *
159  * \param view the view that requests the text hint
160  * \param position text cursor under the mouse position
161  * \return text tool tip to be displayed, may be Qt richtext
162  */
163  virtual QString textHint(KTextEditor::View *view, const KTextEditor::Cursor &position) = 0;
164 
165 private:
166  class TextHintProviderPrivate *const d = nullptr;
167 };
168 
169 }
170 
171 Q_DECLARE_INTERFACE(KTextEditor::TextHintInterface, "org.kde.KTextEditor.TextHintInterface")
172 
173 #endif
Text hint interface showing tool tips under the mouse for the View.
The Cursor represents a position in a Document.
Definition: cursor.h:71
Class to provide text hints for a View.
A text widget with KXMLGUIClient that represents a Document.
Definition: view.h:146
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
Definition: katetextblock.h:22
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon May 8 2023 03:50:23 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.