1 /* 2 Actiona 3 Copyright (C) 2005 Jonathan Mercier-Ganady 4 5 Actiona is free software: you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation, either version 3 of the License, or 8 (at your option) any later version. 9 10 Actiona is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 Contact : jmgr@jmgr.info 19 */ 20 21 #pragma once 22 23 #include "actiontools_global.h" 24 #include "subparameter.h" 25 #include "abstractcodeeditor.h" 26 27 #include <QLineEdit> 28 #include <QRegExp> 29 30 class QMenu; 31 class QAbstractItemModel; 32 33 namespace ActionTools 34 { 35 class ParameterContainer; 36 class CodeLineEditButton; 37 38 class ACTIONTOOLSSHARED_EXPORT CodeLineEdit : public QLineEdit, public AbstractCodeEditor 39 { 40 Q_OBJECT 41 Q_PROPERTY(bool code READ isCode WRITE setCode) 42 43 public: 44 CodeLineEdit(QWidget *parent, const QRegExp ®expValidation = QRegExp()); 45 ~CodeLineEdit() override ; 46 isMultiline()47 bool isMultiline() const { return mMultiline; } isCode()48 bool isCode() const { return mCode; } isEmbedded()49 bool isEmbedded() const { return mEmbedded; } 50 codeButton()51 CodeLineEditButton *codeButton() const { return mCodeButton; } editorButton()52 CodeLineEditButton *editorButton() const { return mEditorButton; } 53 54 void setCode(bool code); 55 void setEmbedded(bool embedded); 56 57 void setAllowTextCodeChange(bool allowTextCodeChange); 58 void setShowEditorButton(bool showEditorButton); 59 void setFromSubParameter(const SubParameter &subParameter); setRegexpValidation(const QRegExp & regexpValidation)60 void setRegexpValidation(const QRegExp ®expValidation) { mRegExp = regexpValidation; } 61 62 void addShortcuts(QMenu *menu); 63 64 void setCompletionModel(QAbstractItemModel *completionModel) override; 65 void setParameterContainer(const ParameterContainer *parameterContainer) override; 66 QSet<QString> findVariables() const override; 67 68 public slots: 69 void reverseCode(); 70 void onTextChanged(const QString &text); 71 void openEditor(int line = -1, int column = -1) override; 72 73 signals: 74 void codeChanged(bool code); 75 76 protected: 77 void contextMenuEvent(QContextMenuEvent *event) override; 78 void resizeEvent(QResizeEvent *event) override; 79 virtual void insertVariable(const QString &variable); 80 81 private slots: 82 void showVariableMenuAsPopup(); 83 void insertVariable(QAction *action); 84 85 protected: 86 virtual QMenu *createVariablesMenu(QMenu *parentMenu, bool ignoreMultiline = false); 87 virtual QMenu *createResourcesMenu(QMenu *parentMenu, bool ignoreMultiline = false); 88 89 private: 90 void resizeButtons(); 91 void addVariablesAndResourcesMenus(QMenu *menu); 92 93 void mouseMoveEvent(QMouseEvent *event) override; 94 void multilineCheck(const QString &text); 95 96 void mouseDoubleClickEvent(QMouseEvent *event) override; 97 void paintEvent(QPaintEvent *event) override; 98 99 const ActionTools::ParameterContainer *mParameterContainer; 100 bool mCode; 101 bool mMultiline; 102 bool mAllowTextCodeChange; 103 bool mShowEditorButton; 104 bool mEmbedded; 105 QAction *mSwitchTextCode; 106 QAction *mOpenEditor; 107 QRegExp mRegExp; 108 QAbstractItemModel *mCompletionModel; 109 CodeLineEditButton *mCodeButton; 110 CodeLineEditButton *mEditorButton; 111 CodeLineEditButton *mInsertButton; 112 113 Q_DISABLE_COPY(CodeLineEdit) 114 }; 115 } 116 117