File indexing completed on 2024-04-21 03:57:49
0001 /* 0002 SPDX-FileCopyrightText: 2019 Dominik Haumann <dhaumann@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KTEXTEDITOR_VARIABLE_EXPANSION_HELPERS_H 0008 #define KTEXTEDITOR_VARIABLE_EXPANSION_HELPERS_H 0009 0010 #include <QDialog> 0011 #include <QHash> 0012 #include <QList> 0013 #include <QPointer> 0014 #include <QString> 0015 0016 class QListView; 0017 class QLineEdit; 0018 class QSortFilterProxyModel; 0019 class VariableItemModel; 0020 class TextEditButton; 0021 0022 namespace KTextEditor 0023 { 0024 class View; 0025 class Variable; 0026 } 0027 0028 /** 0029 * Helper for macro expansion. 0030 */ 0031 namespace KateMacroExpander 0032 { 0033 /** 0034 * Expands the @p input text based on the @p view. 0035 * @return the expanded text. 0036 */ 0037 QString expandMacro(const QString &input, KTextEditor::View *view); 0038 } 0039 0040 /** 0041 * Helper dialog that shows a non-modal dialog listing all available 0042 * variables. If the user selects a variable, the variable is inserted 0043 * into the respective widget. 0044 */ 0045 class KateVariableExpansionDialog : public QDialog 0046 { 0047 public: 0048 KateVariableExpansionDialog(QWidget *parent); 0049 ~KateVariableExpansionDialog() override; 0050 0051 /** 0052 * Adds @p variable to the expansion list view. 0053 */ 0054 void addVariable(const KTextEditor::Variable &variable); 0055 0056 /** 0057 * Returns true if no variables were added at all to the dialog. 0058 */ 0059 int isEmpty() const; 0060 0061 /** 0062 * Adds @p widget to the list of widgets that trigger showing this dialog. 0063 */ 0064 void addWidget(QWidget *widget); 0065 0066 protected: 0067 /** 0068 * Reimplemented for the following reasons: 0069 * - Show this dialog if one of the widgets added with addWidget() has focus. 0070 * - Catch the resize-event for widgets (e.g. QTextEdit) where we manually 0071 * added a clickable action in the corner 0072 */ 0073 bool eventFilter(QObject *watched, QEvent *event) override; 0074 0075 /** 0076 * Called whenever a widget was deleted. If all widgets are deleted, 0077 * this dialog deletes itself via deleteLater(). 0078 */ 0079 void onObjectDeleted(QObject *object); 0080 0081 private: 0082 QAction *m_showAction; 0083 QHash<QWidget *, QPointer<TextEditButton>> m_textEditButtons; 0084 QList<QObject *> m_widgets; 0085 QList<KTextEditor::Variable> m_variables; 0086 VariableItemModel *m_variableModel; 0087 QSortFilterProxyModel *m_filterModel; 0088 QListView *m_listView; 0089 QLineEdit *m_filterEdit; 0090 }; 0091 0092 #endif // KTEXTEDITOR_VARIABLE_EXPANSION_HELPERS_H 0093 0094 // kate: space-indent on; indent-width 4; replace-tabs on;