File indexing completed on 2024-05-12 15:45:39

0001 /*
0002     SPDX-FileCopyrightText: 2006 Matt Broadstone <mbroadst@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KTEXTEDITOR_CONFIGINTERFACE_H
0008 #define KTEXTEDITOR_CONFIGINTERFACE_H
0009 
0010 #include <QStringList>
0011 #include <QVariant>
0012 #include <ktexteditor_export.h>
0013 
0014 namespace KTextEditor
0015 {
0016 /**
0017  * \class ConfigInterface configinterface.h <KTextEditor/ConfigInterface>
0018  *
0019  * \brief Config interface extension for the Document and View.
0020  *
0021  * \ingroup kte_group_view_extensions
0022  * \ingroup kte_group_doc_extensions
0023  *
0024  * \section config_intro Introduction
0025  *
0026  * The ConfigInterface provides methods to access and modify the low level
0027  * config information for a given Document or View. Examples of this config data can be
0028  * displaying the icon bar, showing line numbers, etc. This generally allows
0029  * access to settings that otherwise are only accessible during runtime.
0030  *
0031  * \section config_access Accessing the Interface
0032  *
0033  * The ConfigInterface is supposed to be an extension interface for a Document or View,
0034  * i.e. the Document or View inherits the interface \e provided that the
0035  * KTextEditor library in use implements the interface. Use qobject_cast to access
0036  * the interface:
0037  * \code
0038  * // ptr is of type KTextEditor::Document* or KTextEditor::View*
0039  * auto iface = qobject_cast<KTextEditor::ConfigInterface*>(ptr);
0040  *
0041  * if (iface) {
0042  *     // the implementation supports the interface
0043  *     // do stuff
0044  * } else {
0045  *     // the implementation does not support the interface
0046  * }
0047  * \endcode
0048  *
0049  * \section config_data Accessing Data
0050  *
0051  * A list of available config variables (or keys) can be obtained by calling
0052  * configKeys(). For all available keys configValue() returns the corresponding
0053  * value as QVariant. A value for a given key can be set by calling
0054  * setConfigValue(). Right now, when using KatePart as editor component,
0055  * KTextEditor::View has support for the following tuples:
0056  *  - line-numbers [bool], show/hide line numbers
0057  *  - icon-bar [bool], show/hide icon bar
0058  *  - folding-bar [bool], show/hide the folding bar
0059  *  - folding-preview [bool], enable/disable folding preview when mouse hovers
0060  *    on folded region
0061  *  - dynamic-word-wrap [bool], enable/disable dynamic word wrap
0062  *  - background-color [QColor], read/set the default background color
0063  *  - selection-color [QColor], read/set the default color for selections
0064  *  - search-highlight-color [QColor], read/set the background color for search
0065  *  - replace-highlight-color [QColor], read/set the background color for replaces
0066  *  - default-mark-type [uint], read/set the default mark type
0067  *  - allow-mark-menu [bool], enable/disable the menu shown when right clicking
0068  *    on the left gutter. When disabled, click on the gutter will always set
0069  *    or clear the mark of default type.
0070  *  - icon-border-color [QColor] read/set the icon border color (on the left,
0071  *    with the line numbers)
0072  *  - folding-marker-color [QColor] read/set folding marker colors (in the icon border)
0073  *  - line-number-color [QColor] read/set line number colors (in the icon border)
0074  *  - current-line-number-color [QColor] read/set current line number color (in the icon border)
0075  *  - modification-markers [bool] read/set whether the modification markers are shown
0076  *  - word-count [bool] enable/disable the counting of words and characters in the statusbar
0077  *  - line-count [bool] show/hide the total number of lines in the status bar (@since 5.66)
0078  *  - scrollbar-minimap [bool] enable/disable scrollbar minimap
0079  *  - scrollbar-preview [bool] enable/disable scrollbar text preview on hover
0080  *  - font [QFont] change the font
0081  *  - theme [QString] change the theme
0082  *
0083  * KTextEditor::Document has support for the following:
0084  *  - backup-on-save-local [bool], enable/disable backup when saving local files
0085  *  - backup-on-save-remote [bool], enable/disable backup when saving remote files
0086  *  - backup-on-save-suffix [string], set the suffix for file backups, e.g. "~"
0087  *  - backup-on-save-prefix [string], set the prefix for file backups, e.g. "."
0088  *  - replace-tabs [bool], whether to replace tabs
0089  *  - indent-pasted-text [bool], whether to indent pasted text
0090  *  - tab-width [int], read/set the width for tabs
0091  *  - indent-width [int], read/set the indentation width
0092  *  - on-the-fly-spellcheck [bool], enable/disable on the fly spellcheck
0093  *
0094  * The KTextEditor::Document or KTextEditor::View objects will emit the \p configChanged signal when appropriate.
0095  *
0096  * For instance, if you want to enable dynamic word wrap of a KTextEditor::View
0097  * simply call
0098  * \code
0099  * iface->setConfigValue("dynamic-word-wrap", true);
0100  * \endcode
0101  *
0102  * \see KTextEditor::View, KTextEditor::Document
0103  * \author Matt Broadstone \<mbroadst@gmail.com\>
0104  */
0105 class KTEXTEDITOR_EXPORT ConfigInterface
0106 {
0107 public:
0108     ConfigInterface();
0109 
0110     /**
0111      * Virtual destructor.
0112      */
0113     virtual ~ConfigInterface();
0114 
0115 public:
0116     /**
0117      * Get a list of all available keys.
0118      */
0119     virtual QStringList configKeys() const = 0;
0120     /**
0121      * Get a value for the \p key.
0122      */
0123     virtual QVariant configValue(const QString &key) = 0;
0124     /**
0125      * Set a the \p key's value to \p value.
0126      */
0127     virtual void setConfigValue(const QString &key, const QVariant &value) = 0;
0128 
0129 private:
0130     class ConfigInterfacePrivate *const d = nullptr;
0131 };
0132 
0133 }
0134 
0135 Q_DECLARE_INTERFACE(KTextEditor::ConfigInterface, "org.kde.KTextEditor.ConfigInterface")
0136 
0137 #endif