File indexing completed on 2024-05-12 15:45:41
0001 /* 0002 SPDX-FileCopyrightText: 2001 Joseph Wenninger <jowenn@kde.org> 0003 SPDX-FileCopyrightText: 2013-2014 Dominik Haumann <dhaumann@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef KTEXTEDITOR_TEXTHINTINTERFACE_H 0009 #define KTEXTEDITOR_TEXTHINTINTERFACE_H 0010 0011 #include <QString> 0012 0013 #include <ktexteditor_export.h> 0014 0015 #include <ktexteditor/cursor.h> 0016 0017 namespace KTextEditor 0018 { 0019 class TextHintProvider; 0020 class View; 0021 0022 /** 0023 * \class TextHintInterface texthininterface.h <KTextEditor/TextHintInterface> 0024 * 0025 * \brief Text hint interface showing tool tips under the mouse for the View. 0026 * 0027 * \ingroup kte_group_view_extensions 0028 * 0029 * \section texthint_introduction Introduction 0030 * 0031 * The text hint interface provides a way to show tool tips for text located 0032 * under the mouse. Possible applications include showing a value of a variable 0033 * when debugging an application, or showing a complete path of an include 0034 * directive. 0035 * 0036 * \image html texthint.png "Text hint showing the contents of a variable" 0037 * 0038 * To register as text hint provider, call registerTextHintProvider() with an 0039 * instance that inherits TextHintProvider. Finally, make sure you remove your 0040 * text hint provider by calling unregisterTextHintProvider(). 0041 * 0042 * Text hints are shown after the user hovers with the mouse for a delay of 0043 * textHintDelay() milliseconds over the same word. To change the delay, call 0044 * setTextHintDelay(). 0045 * 0046 * \section texthint_access Accessing the TextHintInterface 0047 * 0048 * The TextHintInterface is an extension interface for a 0049 * View, i.e. the View inherits the interface. Use qobject_cast to access the 0050 * interface: 0051 * \code 0052 * // view is of type KTextEditor::View* 0053 * auto iface = qobject_cast<KTextEditor::TextHintInterface*>(view); 0054 * 0055 * if (iface) { 0056 * // the implementation supports the interface 0057 * // myProvider inherits KTextEditor::TextHintProvider 0058 * iface->registerTextHintProvider(myProvider); 0059 * } else { 0060 * // the implementation does not support the interface 0061 * } 0062 * \endcode 0063 * 0064 * \see TextHintProvider 0065 * \since 4.11 0066 */ 0067 class KTEXTEDITOR_EXPORT TextHintInterface 0068 { 0069 public: 0070 TextHintInterface(); 0071 virtual ~TextHintInterface(); 0072 0073 /** 0074 * Register the text hint provider \p provider. 0075 * 0076 * Whenever the user hovers over text, \p provider will be asked for 0077 * a text hint. When the provider is about to be destroyed, make 0078 * sure to call unregisterTextHintProvider() to avoid a dangling pointer. 0079 * 0080 * @param provider text hint provider 0081 * @see unregisterTextHintProvider(), TextHintProvider 0082 */ 0083 virtual void registerTextHintProvider(KTextEditor::TextHintProvider *provider) = 0; 0084 0085 /** 0086 * Unregister the text hint provider \p provider. 0087 * 0088 * @param provider text hint provider to unregister 0089 * @see registerTextHintProvider(), TextHintProvider 0090 */ 0091 virtual void unregisterTextHintProvider(KTextEditor::TextHintProvider *provider) = 0; 0092 0093 /** 0094 * Set the text hint delay to \p delay milliseconds. 0095 * 0096 * The delay specifies the time the user needs to hover over the text 0097 * before the tool tip is shown. Therefore, \p delay should not be 0098 * too large, a value of 500 milliseconds is recommended and set by 0099 * default. 0100 * 0101 * If \p delay is <= 0, the default delay will be set. 0102 * 0103 * \param delay tool tip delay in milliseconds 0104 */ 0105 virtual void setTextHintDelay(int delay) = 0; 0106 0107 /** 0108 * Get the text hint delay in milliseconds. 0109 * By default, the text hint delay is set to 500 milliseconds. 0110 * It can be changed by calling \p setTextHintDelay(). 0111 */ 0112 virtual int textHintDelay() const = 0; 0113 0114 private: 0115 class TextHintInterfacePrivate *const d = nullptr; 0116 }; 0117 0118 /** 0119 * \brief Class to provide text hints for a View. 0120 * 0121 * The class TextHintProvider is used in combination with TextHintInterface. 0122 * TextHintProvider allows to provide text hint information for text under 0123 * the mouse cursor. 0124 * 0125 * To use this class, derive your provider from TextHintProvider and register 0126 * it with TextHintInterface::registerTextHintProvider(). When not needed 0127 * anymore, make sure to remove your provider by calling 0128 * TextHintInterface::unregisterTextHintProvider(), otherwise the View will 0129 * contain a dangling pointer to your potentially deleted provider. 0130 * 0131 * Detailed information about how to use the TextHintInterface can be found 0132 * in the documentation about the TextHintInterface. 0133 * 0134 * \see TextHintInterface 0135 * \p since 5.0 0136 */ 0137 class KTEXTEDITOR_EXPORT TextHintProvider 0138 { 0139 public: 0140 /** 0141 * Default constructor. 0142 */ 0143 TextHintProvider(); 0144 0145 /** 0146 * Virtual destructor to allow inheritance. 0147 */ 0148 virtual ~TextHintProvider(); 0149 0150 /** 0151 * This function is called whenever the users hovers over text such 0152 * that the text hint delay passes. Then, textHint() is called 0153 * for each registered TextHintProvider. 0154 * 0155 * Return the text hint (possibly Qt richtext) for @p view at @p position. 0156 * 0157 * If you do not have any contents to show, just return an empty QString(). 0158 * 0159 * \param view the view that requests the text hint 0160 * \param position text cursor under the mouse position 0161 * \return text tool tip to be displayed, may be Qt richtext 0162 */ 0163 virtual QString textHint(KTextEditor::View *view, const KTextEditor::Cursor &position) = 0; 0164 0165 private: 0166 class TextHintProviderPrivate *const d = nullptr; 0167 }; 0168 0169 } 0170 0171 Q_DECLARE_INTERFACE(KTextEditor::TextHintInterface, "org.kde.KTextEditor.TextHintInterface") 0172 0173 #endif