changeset 13409:1e76b221bc4a

Refactored code edit code, wired undo and redo.
author Jacob Dawid <jacob.dawid@googlemail.com>
date Tue, 12 Apr 2011 12:33:18 +0200
parents e954cbe099fe
children 12697e9bb608
files gui//src/CodeEdit.h gui//src/FileEditorMdiSubWindow.cpp
diffstat 2 files changed, 60 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/gui//src/CodeEdit.h	Tue Apr 12 12:27:52 2011 +0200
+++ b/gui//src/CodeEdit.h	Tue Apr 12 12:33:18 2011 +0200
@@ -36,74 +36,71 @@
 };
 
 /**TextEdit that supports highlited syntax and autocompletion.*/
-class CodeEdit: public QTextEdit
-{
-  Q_OBJECT
-
-  bool auto_indent;
-  QCompleter completion;
-  QStringListModel *completion_model;
-  QTimer braketsTimer, octaveCommandTimer, completionTimer;
-  QStringList completion_list;
-  int completionPosition;
-  
-  /**Builds auto completion list from block blockInit to blockEnd.*/
-  void buildAutoCompletionListSlide(QStringList &list, QTextBlock blockInit, QTextBlock blockEnd, QString word_to_complete, QString actual_word);
+class CodeEdit: public QTextEdit {
+    Q_OBJECT
+public:
+    CodeEdit(QWidget *parent = 0, QString syntaxF = QString());
+    ~CodeEdit();
+    void setAutoindent(bool ai_ok);
+    bool getAutoindent();
+    bool getbraketsMatchOk();
+ 
+    /**List of y top left positions of bounding rects of each visible block of text.
+    * @param list List of top left positions.
+    * @param first_line First visible block in TextEdit.
+    */
+    void publicBlockBoundingRectList(QVector<qreal>  &list, int &first_line);
 
-  bool text_modified_stop_ok; //Stops emit of text_modified signal
-  bool context_changed_ok;
-
-  //Editor properties
+public slots:
+    void undo();
+    void redo();
+    void deleteSelection();
+    void toggleBreakpoint();
+    void braketsMatch(bool rehigh=true);
+    void cursorChanged_cb();
+    void buildAutoCompletionList(int pos, int charsRemoved, int charsAdded );
+    void buildAutoCompletionList();
+    void doCompletion(const QModelIndex &index);
+    void octaveCommandCompletion();
+    void textModified_cb(bool ok);
 
-  /**Automatic indention for while, if, for, switch, do and try statements.*/
-  bool automatic_indention_statement_ok;
-  /**Auto completion*/
-  bool autocompletion_ok;
-   /**Brackets Macth*/
-  bool brakets_match_ok;
+signals:
+    void toggleBreakpoint(int lineno);
 
- protected:
-  Syntax *syntax;
-  QMenu  contextMenu;
-
-  void contextMenuEvent(QContextMenuEvent *e);
-  bool event( QEvent * e );
+    /**Dinamic help required.*/
+    void dynamic_help_required(const QString &text);
 
- public slots:
-  void undo();
-  void redo();
-  void deleteSelection();
-  void toggleBreakpoint();
-  void braketsMatch(bool rehigh=true);
-  void cursorChanged_cb();
-  void buildAutoCompletionList(int pos, int charsRemoved, int charsAdded );
-  void buildAutoCompletionList();
-  void doCompletion(const QModelIndex &index);
-  void octaveCommandCompletion();
-  void textModified_cb(bool ok);
+    /**Text modified.*/
+    void text_modified(bool ok);
 
- public:
-  CodeEdit(QWidget *parent = 0, QString syntaxF = QString());
-  ~CodeEdit();
-  void setAutoindent(bool ai_ok);
-  bool getAutoindent();
+protected:
+    Syntax *syntax;
+    QMenu  contextMenu;
+
+    void contextMenuEvent(QContextMenuEvent *e);
+    bool event( QEvent * e );
 
-  bool getbraketsMatchOk();
- 
-  /**List of y top left positions of bounding rects of each visible block of text.
-   * @param list List of top left positions.
-   * @param first_line First visible block in TextEdit.
-   */
-  void publicBlockBoundingRectList(QVector<qreal>  &list, int &first_line);
+private:
+    bool auto_indent;
+    QCompleter completion;
+    QStringListModel *completion_model;
+    QTimer braketsTimer, octaveCommandTimer, completionTimer;
+    QStringList completion_list;
+    int completionPosition;
+
+    /**Builds auto completion list from block blockInit to blockEnd.*/
+    void buildAutoCompletionListSlide(QStringList &list, QTextBlock blockInit, QTextBlock blockEnd, QString word_to_complete, QString actual_word);
 
- signals:
-  void toggleBreakpoint(int lineno);
+    bool text_modified_stop_ok; //Stops emit of text_modified signal
+    bool context_changed_ok;
 
-  /**Dinamic help required.*/
-  void dynamic_help_required(const QString &text);
+    //Editor properties
 
-  /**Text modified.*/
-  void text_modified(bool ok);
+    /**Automatic indention for while, if, for, switch, do and try statements.*/
+    bool automatic_indention_statement_ok;
+    /**Auto completion*/
+    bool autocompletion_ok;
+    /**Brackets Macth*/
+    bool brakets_match_ok;
 };
-
 #endif
--- a/gui//src/FileEditorMdiSubWindow.cpp	Tue Apr 12 12:27:52 2011 +0200
+++ b/gui//src/FileEditorMdiSubWindow.cpp	Tue Apr 12 12:33:18 2011 +0200
@@ -47,4 +47,7 @@
     layout->addWidget(m_statusBar);
     layout->setMargin(2);
     widget()->setLayout(layout);
+
+    connect(undoAction, SIGNAL(triggered()), m_codeEdit, SLOT(undo()));
+    connect(redoAction, SIGNAL(triggered()), m_codeEdit, SLOT(redo()));
 }