39 #ifndef PYTHONCODEEDITOR2_H_ 
   40 #define PYTHONCODEEDITOR2_H_ 
   42 #include <tulip/AutoCompletionDataBase.h> 
   45 #include <QListWidget> 
   46 #include <QPlainTextEdit> 
   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 insertSelectedItem();
 
   74   void keyPressEvent(QKeyEvent *e);
 
   75   void showEvent(QShowEvent * event);
 
   76   void hideEvent(QHideEvent * event);
 
   77   void mouseDoubleClickEvent(QMouseEvent * event);
 
   78   bool eventFilter(QObject *obj, QEvent * event);
 
   82 class TLP_PYTHON_SCOPE FindReplaceDialog : 
public QDialog  {
 
   86   Ui::FindReplaceDialogData *_ui;
 
   87   QPlainTextEdit *_editor;
 
   91   void setSearchResult(
const bool result);
 
   95   FindReplaceDialog(QPlainTextEdit *_editor, QWidget *parent=NULL);
 
   98   void setFindMode(
const bool findMode);
 
  100   void setTextToFind(
const QString &text);
 
  105   void textToFindChanged();
 
  108   void doReplaceFind();
 
  110   void setResetSearch() {
 
  113   void regexpToggled(
bool toggled);
 
  118   void hideEvent(QHideEvent * event);
 
  122 class TLP_PYTHON_SCOPE PythonCodeEditor : 
public QPlainTextEdit {
 
  126   friend class LineNumberArea;
 
  127   friend class AutoCompletionList;
 
  131   explicit PythonCodeEditor(QWidget *parent=0);
 
  134   QString getCleanCode() 
const;
 
  136   int lineNumberAreaWidth() 
const;
 
  138   void indicateScriptCurrentError(
int lineNumber);
 
  139   void clearErrorIndicator();
 
  144   void getCursorPosition(
int &line, 
int &col) 
const;
 
  145   void setCursorPosition(
int line, 
int col);
 
  146   void scrollToLine(
int line);
 
  148   void getSelection(
int &lineFrom, 
int &indexFrom, 
int &lineTo, 
int &indexTo) 
const;
 
  149   void setSelection(
int startLine, 
int startCol, 
int endLine, 
int endCol);
 
  150   void removeSelectedText();
 
  151   bool hasSelectedText() 
const;
 
  152   QString selectedText() 
const;
 
  155   int lineLength(
int lineNumber) 
const;
 
  157   void insertAt(QString text, 
int line, 
int col);
 
  159   void commentSelectedCode();
 
  160   void uncommentSelectedCode();
 
  162   void indentSelectedCode();
 
  163   void unindentSelectedCode();
 
  165   void setAutoIndentation(
const bool autoIndent) {
 
  166     this->_autoIndent = autoIndent;
 
  169   bool autoIndentation()
 const {
 
  173   void setIndentationGuides(
const bool indentGuides) {
 
  174     this->_indentGuides = indentGuides;
 
  177   bool indentationGuides()
 const {
 
  178     return _indentGuides;
 
  181   void setHighlightEditedLine(
const bool highlightCurLine) {
 
  182     this->_highlightCurLine = highlightCurLine;
 
  185   bool highlightEditedLine()
 const {
 
  186     return _highlightCurLine;
 
  189   void setFindReplaceActivated(
const bool activateFindReplace) {
 
  190     _findReplaceActivate = activateFindReplace;
 
  193   bool findReplaceActivated()
 const {
 
  194     return _findReplaceActivate;
 
  197   void setCommentShortcutsActivated(
const bool activateCommentShortcuts) {
 
  198     _commentShortcutsActivate = activateCommentShortcuts;
 
  201   bool commentShortcutsActivated()
 const {
 
  202     return _commentShortcutsActivate;
 
  205   void setIndentShortcutsActivated(
const bool activateIndentShortcuts) {
 
  206     _indentShortcutsActivate = activateIndentShortcuts;
 
  209   bool indentShortcutsActivated()
 const {
 
  210     return _indentShortcutsActivate;
 
  213   void setFileName(
const QString &fileName) {
 
  214     _pythonFileName = fileName;
 
  217   QString getFileName()
 const {
 
  218     return _pythonFileName;
 
  221   bool loadCodeFromFile(
const QString &filePath);
 
  223   bool saveCodeToFile();
 
  225   QDateTime getLastSavedTime()
 const {
 
  226     return _lastSavedTime;
 
  229   void setModuleEditor(
const bool moduleEditor) {
 
  230     this->_moduleEditor = moduleEditor;
 
  233   void analyseScriptCode(
const bool wholeText=
false);
 
  235   AutoCompletionDataBase *getAutoCompletionDb()
 const {
 
  236     return _autoCompletionDb;
 
  241   void resizeEvent(QResizeEvent *event);
 
  242   void showEvent(QShowEvent *);
 
  243   void paintEvent(QPaintEvent *event);
 
  244   void keyPressEvent (QKeyEvent * e);
 
  245   void wheelEvent(QWheelEvent * event);
 
  246   void mouseDoubleClickEvent(QMouseEvent * event);
 
  247   void mouseMoveEvent(QMouseEvent * event);
 
  248   void mousePressEvent(QMouseEvent * event);
 
  249   void mouseReleaseEvent(QMouseEvent * event);
 
  250   void lineNumberAreaPaintEvent(QPaintEvent *event);
 
  251   void insertFromMimeData(
const QMimeData * source);
 
  256   void updateLineNumberAreaWidth();
 
  257   void updateLineNumberArea(
const QRect &, 
int);
 
  258   void resetExtraSelections();
 
  260   virtual void highlightCurrentLine();
 
  261   void highlightErrors();
 
  262   virtual void showAutoCompletionList(
bool dotContext=
false);
 
  263   virtual void updateAutoCompletionList(
bool dotContext=
false);
 
  264   void highlightSelection();
 
  268   virtual void updateAutoCompletionListPosition();
 
  270   void createParenSelection(
int pos);
 
  271   void updateTabStopWidth();
 
  273   QString getEditedFunctionName() 
const;
 
  275   void showTooltip(
int line, 
int col, 
const QString &text);
 
  277   bool isTooltipActive() 
const;
 
  279   QFontMetrics fontMetrics() 
const;
 
  281   QWidget *_lineNumberArea;
 
  282   PythonCodeHighlighter *_highlighter;
 
  283   ParenMatcherHighlighter *_parenHighlighter;
 
  285   QVector<int> _currentErrorLines;
 
  287   AutoCompletionList *_autoCompletionList;
 
  288   AutoCompletionDataBase *_autoCompletionDb;
 
  290   FindReplaceDialog *_findReplaceDialog;
 
  294   bool _highlightCurLine;
 
  296   bool _findReplaceActivate;
 
  297   bool _commentShortcutsActivate;
 
  298   bool _indentShortcutsActivate;
 
  301   QString _toolTipText;
 
  302   QString _toolTipFunc;
 
  304   QString _pythonFileName;
 
  305   QDateTime _lastSavedTime;