39 #ifndef PYTHONCODEEDITOR2_H_
40 #define PYTHONCODEEDITOR2_H_
42 #include <tulip/AutoCompletionDataBase.h>
44 #include <QtCore/QDateTime>
45 #include <QtGui/QListWidget>
46 #include <QtGui/QPlainTextEdit>
47 #include <QtGui/QDialog>
50 class FindReplaceDialogData;
53 class PythonCodeHighlighter;
54 class ParenMatcherHighlighter;
58 class PythonCodeEditor;
61 class TLP_PYTHON_SCOPE AutoCompletionList :
public QListWidget {
63 tlp::PythonCodeEditor *_codeEditor;
69 explicit AutoCompletionList(tlp::PythonCodeEditor *parent=0);
73 void keyPressEvent(QKeyEvent *e);
74 void showEvent(QShowEvent * event);
75 void hideEvent(QHideEvent * event);
76 bool eventFilter(QObject *obj, QEvent * event);
80 class TLP_PYTHON_SCOPE FindReplaceDialog :
public QDialog {
84 Ui::FindReplaceDialogData *_ui;
85 QPlainTextEdit *_editor;
89 void setSearchResult(
const bool result);
93 FindReplaceDialog(QPlainTextEdit *_editor, QWidget *parent=NULL);
96 void setFindMode(
const bool findMode);
98 void setTextToFind(
const QString &text);
103 void textToFindChanged();
106 void doReplaceFind();
108 void setResetSearch() {
111 void regexpToggled(
bool toggled);
116 void hideEvent(QHideEvent * event);
120 class TLP_PYTHON_SCOPE PythonCodeEditor :
public QPlainTextEdit {
124 friend class LineNumberArea;
125 friend class AutoCompletionList;
129 explicit PythonCodeEditor(QWidget *parent=0);
132 QString getCleanCode()
const;
134 int lineNumberAreaWidth()
const;
136 void indicateScriptCurrentError(
int lineNumber);
137 void clearErrorIndicator();
142 void getCursorPosition(
int &line,
int &col)
const;
143 void setCursorPosition(
int line,
int col);
144 void scrollToLine(
int line);
146 void getSelection(
int &lineFrom,
int &indexFrom,
int &lineTo,
int &indexTo)
const;
147 void setSelection(
int startLine,
int startCol,
int endLine,
int endCol);
148 void removeSelectedText();
149 bool hasSelectedText()
const;
150 QString selectedText()
const;
153 int lineLength(
int lineNumber)
const;
155 void insertAt(QString text,
int line,
int col);
157 void commentSelectedCode();
158 void uncommentSelectedCode();
160 void indentSelectedCode();
161 void unindentSelectedCode();
163 void setAutoIndentation(
const bool autoIndent) {
164 this->_autoIndent = autoIndent;
167 bool autoIndentation()
const {
171 void setIndentationGuides(
const bool indentGuides) {
172 this->_indentGuides = indentGuides;
175 bool indentationGuides()
const {
176 return _indentGuides;
179 void setHighlightEditedLine(
const bool highlightCurLine) {
180 this->_highlightCurLine = highlightCurLine;
183 bool highlightEditedLine()
const {
184 return _highlightCurLine;
187 void setFindReplaceActivated(
const bool activateFindReplace) {
188 _findReplaceActivate = activateFindReplace;
191 bool findReplaceActivated()
const {
192 return _findReplaceActivate;
195 void setCommentShortcutsActivated(
const bool activateCommentShortcuts) {
196 _commentShortcutsActivate = activateCommentShortcuts;
199 bool commentShortcutsActivated()
const {
200 return _commentShortcutsActivate;
203 void setIndentShortcutsActivated(
const bool activateIndentShortcuts) {
204 _indentShortcutsActivate = activateIndentShortcuts;
207 bool indentShortcutsActivated()
const {
208 return _indentShortcutsActivate;
211 void setFileName(
const QString &fileName) {
212 _pythonFileName = fileName;
215 QString getFileName()
const {
216 return _pythonFileName;
219 bool loadCodeFromFile(
const QString &filePath);
221 bool saveCodeToFile();
223 QDateTime getLastSavedTime()
const {
224 return _lastSavedTime;
227 void setModuleEditor(
const bool moduleEditor) {
228 this->_moduleEditor = moduleEditor;
231 void analyseScriptCode(
const bool wholeText=
false);
233 AutoCompletionDataBase *getAutoCompletionDb()
const {
234 return _autoCompletionDb;
239 void resizeEvent(QResizeEvent *event);
240 void showEvent(QShowEvent *);
241 void paintEvent(QPaintEvent *event);
242 void keyPressEvent (QKeyEvent * e);
243 void wheelEvent(QWheelEvent * event);
244 void mouseDoubleClickEvent(QMouseEvent * event);
245 void mouseMoveEvent(QMouseEvent * event);
246 void mousePressEvent(QMouseEvent * event);
247 void mouseReleaseEvent(QMouseEvent * event);
248 void lineNumberAreaPaintEvent(QPaintEvent *event);
249 void insertFromMimeData(
const QMimeData * source);
254 void updateLineNumberAreaWidth();
255 void updateLineNumberArea(
const QRect &,
int);
256 void resetExtraSelections();
258 virtual void highlightCurrentLine();
259 void highlightErrors();
260 virtual void showAutoCompletionList(
bool dotContext=
false);
261 virtual void updateAutoCompletionList(
bool dotContext=
false);
262 void highlightSelection();
266 virtual void updateAutoCompletionListPosition();
268 void createParenSelection(
int pos);
269 void updateTabStopWidth();
271 QString getEditedFunctionName()
const;
273 void showTooltip(
int line,
int col,
const QString &text);
275 bool isTooltipActive()
const;
277 QFontMetrics fontMetrics()
const;
279 QWidget *_lineNumberArea;
280 PythonCodeHighlighter *_highlighter;
281 ParenMatcherHighlighter *_parenHighlighter;
283 QVector<int> _currentErrorLines;
285 AutoCompletionList *_autoCompletionList;
286 AutoCompletionDataBase *_autoCompletionDb;
288 FindReplaceDialog *_findReplaceDialog;
292 bool _highlightCurLine;
294 bool _findReplaceActivate;
295 bool _commentShortcutsActivate;
296 bool _indentShortcutsActivate;
299 QString _toolTipText;
300 QString _toolTipFunc;
302 QString _pythonFileName;
303 QDateTime _lastSavedTime;