KVIrc  4.9.2
DeveloperAPIs
ScriptEditorImplementation.h
Go to the documentation of this file.
1 #ifndef _SCRIPTEDITOR_H_
2 #define _SCRIPTEDITOR_H_
3 
4 //=============================================================================
5 //
6 // File : ScriptEditorImplementation.h
7 // Creation date : Sun Mar 28 1999 16:11:48 CEST by Szymon Stefanek
8 //
9 // This file is part of the KVIrc IRC client distribution
10 // Copyright (C) 1999-2010 Szymon Stefanek <pragma at kvirc dot net>
11 //
12 // This program is FREE software. You can redistribute it and/or
13 // modify it under the terms of the GNU General Public License
14 // as published by the Free Software Foundation; either version 2
15 // of the License, or (at your option) any later version.
16 //
17 // This program is distributed in the HOPE that it will be USEFUL,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 // See the GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program. If not, write to the Free Software Foundation,
24 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 //
26 //=============================================================================
27 
28 #include "KviScriptEditor.h"
29 #include "KviPointerList.h"
30 #include "KviSelectors.h"
31 
32 #include <QCompleter>
33 #include <QLabel>
34 #include <QDialog>
35 #include <QEvent>
36 #include <QTextEdit>
37 #include <QListWidget>
38 #include <QCheckBox>
39 #include <QSyntaxHighlighter>
40 #include <QByteArray>
41 #include <QMenu>
42 
43 class QTimer;
44 
45 //typedef KviPointerList<int> ColumnList;
47 class ScriptEditorWidget : public QTextEdit
48 {
49  Q_OBJECT
51 public:
52  ScriptEditorWidget(QWidget * pParent);
53  virtual ~ScriptEditorWidget();
54 
55 public:
56  QString m_szFind;
57 
58 protected:
60  QCompleter * m_pCompleter;
61  QStringList * m_pListModulesNames;
62  QStringList * m_pListCompletition;
63  QTimer * m_pStartTimer;
64  QWidget * m_pParent;
66  QString m_szHelp;
67 
68 public:
72 
73  void createCompleter(QStringList & list);
74 
75  void loadCompleterFromFile();
76  QCompleter * completer() const { return m_pCompleter; };
77  QString textUnderCursor() const;
78  void updateOptions();
79  //void find1();
80  bool contextSensitiveHelp() const;
81 public slots:
82  void checkReadyCompleter();
83  void insertCompletion(const QString & szCompletion);
84  void slotFind();
85  void slotHelp();
86  void slotReplace();
87 protected slots:
89 signals:
90  void keyPressed();
91 
92 protected:
93  void contextMenuEvent(QContextMenuEvent * e);
94  virtual void keyPressEvent(QKeyEvent * e);
95  // void mouseReleaseEvent(QMouseEvent * e);
96 };
97 
98 class ScriptEditorWidgetColorOptions : public QDialog
99 {
100  Q_OBJECT
101 public:
102  ScriptEditorWidgetColorOptions(QWidget * pParent);
104 
105 private:
107 
108 protected:
109  KviColorSelector * addColorSelector(QWidget * pParent, const QString & txt, QColor * pOption, bool bEnabled);
110 
111 protected slots:
112  void okClicked();
113 };
114 
115 class ScriptEditorSyntaxHighlighter : public QSyntaxHighlighter
116 {
117 public:
120 
121 public:
122  QTextEdit * m_pTextEdit;
123 
124 public:
125  QTextEdit * textEdit() { return m_pTextEdit; }
126  void highlightBlock(const QString & szText);
128 
129 private:
131  {
132  QRegExp pattern;
133  QTextCharFormat format;
134  };
135 
136  QVector<KviScriptHighlightingRule> highlightingRules;
139 
140  QTextCharFormat bracketFormat;
141  QTextCharFormat punctuationFormat;
142  QTextCharFormat keywordFormat;
143  QTextCharFormat variableFormat;
144  QTextCharFormat normaltextFormat;
145  QTextCharFormat findFormat;
146  QTextCharFormat functionFormat;
147  QTextCharFormat commentFormat;
148 };
149 
151 {
152  Q_OBJECT
153 public:
154  ScriptEditorImplementation(QWidget * par);
155  virtual ~ScriptEditorImplementation();
156 
157 public:
158  QLineEdit * m_pFindLineEdit;
159 
160 protected:
163  QLabel * m_pRowColLabel;
165 
166 public:
167  virtual void setText(const char * txt);
168  virtual void setText(const QString & szText);
169  virtual void setText(const QByteArray & szText);
170  virtual void getText(QString & szText);
171  virtual void getText(QByteArray & szText);
172  virtual void setFindText(const QString & szText);
173  virtual void setEnabled(bool bEnabled);
174  virtual void setReadOnly(bool bReadOnly);
175  void setUnHighlightedText(const QString & szText);
176 
177  virtual void setFocus();
178  virtual bool isModified();
179  virtual void setModified(bool);
180 
181  int getCursor() { return m_pEditor->textCursor().position(); };
182  void setCursorPosition(int iPos);
183  int cursor() { return m_lastCursorPos; };
184  QLineEdit * findLineEdit() { return m_pFindLineEdit; };
185 protected:
186  virtual void focusInEvent(QFocusEvent * e);
187  void loadOptions();
188  void saveOptions();
189 protected slots:
190  void saveToFile();
191  void loadFromFile();
192  void configureColors();
193  void updateRowColLabel();
194  void slotFind();
195  void slotReplaceAll(const QString & szToReplace, const QString & szReplaceWith);
196  void slotInitFind();
197  void slotNextFind(const QString &);
198  void optionsDialogFinished(int iResult);
199 signals:
200  void find(const QString &);
201  void replaceAll(const QString & szToReplace, const QString & szReplaceWith);
202  void initFind();
203  void nextFind(const QString & szText);
204 };
205 
206 class ScriptEditorReplaceDialog : public QDialog
207 {
208  Q_OBJECT
209 public:
210  ScriptEditorReplaceDialog(QWidget * parent = 0, const QString & szName = QString());
212 
213 public:
214  QLineEdit * m_pFindLineEdit;
215  QLineEdit * m_pReplaceLineEdit;
216 
217 protected:
218  QPushButton * m_pReplaceButton;
219  QCheckBox * m_pCheckReplaceAll;
220  QWidget * m_pParent;
221 protected slots:
222  void textChanged(const QString &);
223  void slotReplace();
224  void slotNextFind();
225 signals:
226  void replaceAll(const QString &, const QString &);
227  void initFind();
228  void nextFind(const QString &);
229 };
230 
231 #endif // _SCRIPTEDITOR_H_
QLineEdit * m_pReplaceLineEdit
Definition: ScriptEditorImplementation.h:215
QLineEdit * m_pFindLineEdit
Definition: ScriptEditorImplementation.h:158
Definition: ScriptEditorImplementation.h:47
void slotInitFind()
Definition: ScriptEditorImplementation.cpp:822
QVector< KviScriptHighlightingRule > highlightingRules
Definition: ScriptEditorImplementation.h:136
void updateRowColLabel()
Definition: ScriptEditorImplementation.cpp:933
QLabel * m_pRowColLabel
Definition: ScriptEditorImplementation.h:163
void slotReplaceAll(const QString &szToReplace, const QString &szReplaceWith)
Definition: ScriptEditorImplementation.cpp:827
virtual void setFocus()
Definition: ScriptEditorImplementation.cpp:850
QWidget * m_pParent
Definition: ScriptEditorImplementation.h:64
ScriptEditorWidget(QWidget *pParent)
Definition: ScriptEditorImplementation.cpp:95
int getCursor()
Definition: ScriptEditorImplementation.h:181
void checkReadyCompleter()
Definition: ScriptEditorImplementation.cpp:143
virtual void setReadOnly(bool bReadOnly)
Definition: ScriptEditorImplementation.cpp:902
void setCursorPosition(int iPos)
Definition: ScriptEditorImplementation.cpp:944
QTextCharFormat normaltextFormat
Definition: ScriptEditorImplementation.h:144
Definition: ScriptEditorImplementation.h:98
QStringList * m_pListModulesNames
Definition: ScriptEditorImplementation.h:61
void saveToFile()
Definition: ScriptEditorImplementation.cpp:867
QString m_szFind
Definition: ScriptEditorImplementation.h:56
Definition: KviScriptEditor.h:43
QLineEdit * m_pFindLineEdit
Definition: ScriptEditorImplementation.h:214
QPushButton * m_pReplaceButton
Definition: ScriptEditorImplementation.h:218
QTextCharFormat commentFormat
Definition: ScriptEditorImplementation.h:147
virtual ~ScriptEditorImplementation()
Definition: ScriptEditorImplementation.cpp:774
void replaceAll(const QString &, const QString &)
Definition: ScriptEditorImplementation.h:130
virtual void getText(QString &szText)
Definition: ScriptEditorImplementation.cpp:922
void okClicked()
Definition: ScriptEditorImplementation.cpp:509
QCheckBox * m_pCheckReplaceAll
Definition: ScriptEditorImplementation.h:219
void disableSyntaxHighlighter()
Definition: ScriptEditorImplementation.cpp:303
QTextEdit * m_pTextEdit
Definition: ScriptEditorImplementation.h:122
QRegExp commentEndExpression
Definition: ScriptEditorImplementation.h:138
QTextCharFormat variableFormat
Definition: ScriptEditorImplementation.h:143
void slotFind()
Definition: ScriptEditorImplementation.cpp:812
void slotReplace()
Definition: ScriptEditorImplementation.cpp:1065
virtual void setEnabled(bool bEnabled)
Definition: ScriptEditorImplementation.cpp:860
QTextEdit * textEdit()
Definition: ScriptEditorImplementation.h:125
#define e
Definition: detector.cpp:69
QTextCharFormat functionFormat
Definition: ScriptEditorImplementation.h:146
ScriptEditorSyntaxHighlighter(ScriptEditorWidget *pWidget)
Definition: ScriptEditorImplementation.cpp:518
Definition: ScriptEditorImplementation.h:206
void textChanged(const QString &)
Definition: ScriptEditorImplementation.cpp:1057
bool contextSensitiveHelp() const
QTimer * m_pStartTimer
Definition: ScriptEditorImplementation.h:63
KviColorSelector * addColorSelector(QWidget *pParent, const QString &txt, QColor *pOption, bool bEnabled)
Definition: ScriptEditorImplementation.cpp:502
virtual void focusInEvent(QFocusEvent *e)
Definition: ScriptEditorImplementation.cpp:855
QTextCharFormat keywordFormat
Definition: ScriptEditorImplementation.h:142
QTextCharFormat bracketFormat
Definition: ScriptEditorImplementation.h:140
KviPointerList< KviSelectorInterface > * m_pSelectorInterfaceList
Definition: ScriptEditorImplementation.h:106
QTextCharFormat punctuationFormat
Definition: ScriptEditorImplementation.h:141
Definition: ScriptEditorImplementation.h:115
void enableSyntaxHighlighter()
Definition: ScriptEditorImplementation.cpp:296
void insertCompletion(const QString &szCompletion)
Definition: ScriptEditorImplementation.cpp:247
ScriptEditorSyntaxHighlighter * m_pSyntaxHighlighter
Definition: ScriptEditorImplementation.h:59
void configureColors()
Definition: ScriptEditorImplementation.cpp:975
int iIndex
Definition: ScriptEditorImplementation.h:65
virtual void setFindText(const QString &szText)
Definition: ScriptEditorImplementation.cpp:927
void replaceAll(const QString &szToReplace, const QString &szReplaceWith)
QLineEdit * findLineEdit()
Definition: ScriptEditorImplementation.h:184
void slotHelp()
Definition: ScriptEditorImplementation.cpp:292
int cursor()
Definition: ScriptEditorImplementation.h:183
QCompleter * completer() const
Definition: ScriptEditorImplementation.h:76
void contextMenuEvent(QContextMenuEvent *e)
Definition: ScriptEditorImplementation.cpp:265
void setUnHighlightedText(const QString &szText)
Definition: ScriptEditorImplementation.cpp:891
void slotNextFind(const QString &)
Definition: ScriptEditorImplementation.cpp:817
Definition: ScriptEditorImplementation.h:150
void updateOptions()
Definition: ScriptEditorImplementation.cpp:310
virtual void setModified(bool)
Definition: ScriptEditorImplementation.cpp:808
void nextFind(const QString &)
QRegExp pattern
Definition: ScriptEditorImplementation.h:132
void slotNextFind()
Definition: ScriptEditorImplementation.cpp:1079
ScriptEditorReplaceDialog(QWidget *parent=0, const QString &szName=QString())
Definition: ScriptEditorImplementation.cpp:994
QString m_szHelp
Definition: ScriptEditorImplementation.h:66
QTextCharFormat findFormat
Definition: ScriptEditorImplementation.h:145
virtual void keyPressEvent(QKeyEvent *e)
Definition: ScriptEditorImplementation.cpp:340
ScriptEditorSyntaxHighlighter * syntaxHighlighter()
Definition: ScriptEditorImplementation.h:69
C++ Template based double linked pointer list class.
ScriptEditorWidget * m_pEditor
Definition: ScriptEditorImplementation.h:162
virtual ~ScriptEditorWidget()
Definition: ScriptEditorImplementation.cpp:136
QRegExp commentStartExpression
Definition: ScriptEditorImplementation.h:137
void loadFromFile()
Definition: ScriptEditorImplementation.cpp:952
QCompleter * m_pCompleter
Definition: ScriptEditorImplementation.h:60
void optionsDialogFinished(int iResult)
Definition: ScriptEditorImplementation.cpp:985
void highlightBlock(const QString &szText)
Definition: ScriptEditorImplementation.cpp:578
ScriptEditorWidgetColorOptions * m_pOptionsDialog
Definition: ScriptEditorImplementation.h:161
void slotFind()
Definition: ScriptEditorImplementation.cpp:274
QTextCharFormat format
Definition: ScriptEditorImplementation.h:133
virtual void setText(const char *txt)
Definition: ScriptEditorImplementation.cpp:887
QStringList * m_pListCompletition
Definition: ScriptEditorImplementation.h:62
QWidget * m_pParent
Definition: ScriptEditorImplementation.h:220
virtual bool isModified()
Definition: ScriptEditorImplementation.cpp:804
void createCompleter(QStringList &list)
Definition: ScriptEditorImplementation.cpp:235
int m_lastCursorPos
Definition: ScriptEditorImplementation.h:164
Definition: KviSelectors.h:267
ScriptEditorImplementation(QWidget *par)
Definition: ScriptEditorImplementation.cpp:714
void loadCompleterFromFile()
Definition: ScriptEditorImplementation.cpp:220
ScriptEditorWidgetColorOptions(QWidget *pParent)
Definition: ScriptEditorImplementation.cpp:458
void saveOptions()
Definition: ScriptEditorImplementation.cpp:832
void slotReplace()
Definition: ScriptEditorImplementation.cpp:280
QString textUnderCursor() const
Definition: ScriptEditorImplementation.cpp:407
int iModulesCount
Definition: ScriptEditorImplementation.h:65
~ScriptEditorWidgetColorOptions()
Definition: ScriptEditorImplementation.cpp:497
void asyncCompleterCreation()
Definition: ScriptEditorImplementation.cpp:154
void nextFind(const QString &szText)
void updateSyntaxtTextFormat()
Definition: ScriptEditorImplementation.cpp:554
void loadOptions()
Definition: ScriptEditorImplementation.cpp:786
void find(const QString &)