vlp-27 Removed some unused code. Added undo&redo to menu. Removed maximum window...
authorRafał Długołęcki <kontakt@dlugolecki.net.pl>
Wed, 30 Oct 2013 21:36:24 +0000 (22:36 +0100)
committerRafał Długołęcki <kontakt@dlugolecki.net.pl>
Wed, 30 Oct 2013 21:36:24 +0000 (22:36 +0100)
data/editor/editor-window.ui
src/edit/editor.cpp
src/edit/editor.h
src/edit/my_edit.h

index 409612b73fb90021f82f6d16de8a1b330405a8ea..5b3ee2698291320d6553874ceaeb61846e236692 100644 (file)
     <height>473</height>
    </rect>
   </property>
-  <property name="maximumSize">
-   <size>
-    <width>800</width>
-    <height>600</height>
-   </size>
-  </property>
   <property name="windowTitle">
    <string>MainWindow</string>
   </property>
        <number>3</number>
       </property>
       <item>
-       <widget class="My_Edit" name="e"/>
+       <widget class="My_Edit" name="e">
+        <property name="acceptDrops">
+         <bool>false</bool>
+        </property>
+       </widget>
       </item>
       <item>
        <widget class="QTextEdit" name="msg">
         <property name="sizePolicy">
-         <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
+         <sizepolicy hsizetype="Expanding" vsizetype="Minimum">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
@@ -91,6 +89,9 @@
     <property name="title">
      <string>Edit</string>
     </property>
+    <addaction name="actionUndo"/>
+    <addaction name="actionRedo"/>
+    <addaction name="separator"/>
     <addaction name="actionCopy"/>
     <addaction name="actionPaste"/>
     <addaction name="actionCut"/>
     <string>Properties</string>
    </property>
   </action>
+  <action name="actionUndo">
+   <property name="text">
+    <string>Undo</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+Z</string>
+   </property>
+  </action>
+  <action name="actionRedo">
+   <property name="text">
+    <string>Redo</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+Shift+Z</string>
+   </property>
+  </action>
  </widget>
  <customwidgets>
   <customwidget>
index bf1360cf1349848715d8c8b9c0d205d7db898de1..f6808a431810f29e83b2407ecbdd94a2b7e60e1f 100644 (file)
@@ -17,8 +17,6 @@
 
 #define TYPENUM        5
 
-Editor *editor;
-
 /**
  * @attention Currently not in use
  */
@@ -36,14 +34,10 @@ char *UnitTypes[TYPENUM] = {
  * @param parent Parent widget of this widget. If set, this widget becomes a 
  *               child window inside parent. If not set this widget becomes a
  *               top level window. Default: NULL
- * @deprecated @param name If set, name is sent to the Qobject constructor, so widget is
- *             identifiable (e.g. in Qt Designer)
  */
-My_Edit::My_Edit(QWidget *parent, const char *name)
+My_Edit::My_Edit(QWidget *parent = NULL)
        : QTextEdit(parent)
 {
-       parent = NULL;
-       name = NULL;
 }
 
 /**
@@ -69,8 +63,6 @@ void Editor::closeEvent(QCloseEvent * e) {
  * @param parent Parent widget of this widget. If set, this widget becomes a 
  *               child window inside parent. If not set this widget becomes a
  *               top level window. Default: NULL
- * @param name If set, name is sent to the Qobject constructor, so widget is
- *             identifiable (e.g. in Qt Designer)
  */
 Editor::Editor(char *hdir, QWidget * parent)
        : QMainWindow(parent)
@@ -80,28 +72,10 @@ Editor::Editor(char *hdir, QWidget * parent)
        strcpy(HomeDir, hdir);
        find_text = "";
        sensitive = FALSE;
-//     QMenu * file = NULL;
-/*     QMenu * comp = new QMenu();*/
-/*     QMenu * loglan = new QMenu();*/
-//     QMenu * medit = NULL;
-//     QAction* action = NULL;
-
-//     file = menuBar()->addMenu("&File");
-//     medit = menuBar()->addMenu("&Edit");
-
-//     action = menuBar()->addAction("&Compile", this, SLOT(cmp()));
 
        /*    m->insertItem( "&LOGLAN ", loglan );*/
 
-//     action = menuBar()->addAction("&Properties", this, SLOT(props()));
-
-//     file->addAction("New", this, SLOT(create()), QKeySequence(Qt::CTRL + Qt::Key_N));
-//     file->addAction("Open", this, SLOT(load()), QKeySequence(Qt::CTRL + Qt::Key_O));
-//     file->addAction("Save", this, SLOT(save()), QKeySequence(Qt::CTRL + Qt::Key_S));
-//     file->addAction("Save as", this, SLOT(save_as()), QKeySequence(Qt::CTRL + Qt::Key_A));
-//     file->addSeparator();
        connect(actionQuit, SIGNAL(triggered()), this, SLOT(close()));
-//     file->addAction("Quit ", this, SLOT(close()));
 
        /* comp->insertItem("Compile ", this, SLOT(cmp()), CTRL + Key_C);*/
        /* comp->insertItem("Gen ", this, SLOT(gen()), CTRL + Key_G);*/
@@ -110,40 +84,18 @@ Editor::Editor(char *hdir, QWidget * parent)
        /* loglan->insertItem( "Program structure", this, SLOT(log_prog()));*/
        /* loglan->insertItem( "Unit structure", this, SLOT(log_unit()));*/
        
-//     e = new My_Edit(this, "editor");
        connect(e, SIGNAL(cursorMove()), this, SLOT(updateline()));
+       connect(actionUndo, SIGNAL(triggered()), e, SLOT(undo()));
+       connect(actionRedo, SIGNAL(triggered()), e, SLOT(redo()));
        connect(actionCopy, SIGNAL(triggered()), e, SLOT(copy()));
        connect(actionPaste, SIGNAL(triggered()), e, SLOT(paste()));
        connect(actionCut, SIGNAL(triggered()), e, SLOT(cut()));
        connect(actionClear_all, SIGNAL(triggered()), e, SLOT(clear()));
-//     medit->addAction("Copy", e, SLOT(copy()), QKeySequence(Qt::CTRL + Qt::Key_Insert));
-//     medit->addAction("Paste", e, SLOT(paste()), QKeySequence(Qt::SHIFT + Qt::Key_Insert));
-//     medit->addAction("Cut", e, SLOT(cut()), QKeySequence(Qt::CTRL + Qt::Key_Delete));
-//     medit->addAction("Clear All", e, SLOT(clear()));
-//     medit->addSeparator();
-//     medit->addAction("Find", this, SLOT(findText()), QKeySequence(Qt::CTRL + Qt::Key_F));
-//     medit->addAction("Find Next", this, SLOT(find_next()), QKeySequence(Qt::CTRL + Qt::Key_L));
-
-//     msg = new QTextEdit(this);
-//     msg->setReadOnly(TRUE);
-
-//     QVBoxLayout * layout = new QVBoxLayout();
-//     layout->setContentsMargins (3, 0, 3, 0);
-//     layout->addWidget(e);
-//     layout->addWidget(msg);
-//     QWidget *window = new QWidget();
-//     window->setLayout(layout);
-//     setCentralWidget(window);
 
        compiler_path.sprintf("%s/%s", HomeDir, "compile/logcomp");
        gen_path.sprintf("%s/%s", HomeDir, "compile/gen");
        file_path.sprintf("%s", HomeDir);
 
-//     QColor col(200, 200, 200);
-//     QPalette grp(Qt::black, col, col.lighter(), col.darker(), col.darker(), Qt::black, col);
-
-//     msg->setPalette(grp);
-
        position = new QLabel();
        statusBar()->addPermanentWidget(position);
 }
@@ -170,30 +122,6 @@ void Editor::updateline()
        position->setText(pom);
 }
 
-/**
- * Event invoked on resizing editor application window.
- * @copydoc QWidget::resizeEvent(QResizeEvent*)
- * @param event Currently does nothing
- */
-void Editor::resizeEvent(QResizeEvent *event)
-{
-/*
-TODO: Remove entire method?
-       if (e && m) {
-               e->setGeometry(0, m->height(), width(),
-                               3 * (int)((height() - m->height()) / 4));
-
-               msg->setGeometry(0, m->height() + e->height(), width(),
-                               (int)((height() - m->height()) / 4));
-
-               position->setGeometry(width() - 80,
-                                               m->height() + e->height() - 10,
-                                               position->width(),
-                                               position->height());
-       }
-*/
-}
-
 /**
  * Displays additional window 
  */
@@ -671,9 +599,10 @@ void Editor::on_actionFind_next_triggered()
 int main(int argc, char **argv)
 {
        QApplication app(argc, argv);
-       editor = new Editor(argv[1], NULL);
-       editor->resize(600, 400);
-       editor->show();
+
+       Editor editor(argv[1], NULL);
+       editor.show();
+
        return app.exec();
 }
 
index 16f4cacb9a6517c4a29e4934e9fedea996d06a97..f619f22ad9176c7afa8746addc6a24f995441e3f 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef QWERTY_H
-#define QWERTY_H
+#ifndef VLP_EDITOR_H
+#define VLP_EDITOR_H
 
 #include <QtGui/QTextEdit>
 #include <QtGui/QMainWindow>
@@ -23,15 +23,7 @@ typedef struct {
        QStringList names;
        char name[255];
 } CategoryEntry;
-/*
-class My_Edit : public QTextEdit {
-       Q_OBJECT
-public:
-       My_Edit(QWidget *parent = 0, const char *name = 0);
-signals:
-       void cursorMove();
-};
-*/
+
 class Editor : public QMainWindow, private Ui::EditorWindow {
        Q_OBJECT
 public:
@@ -66,12 +58,8 @@ public slots:
        void updateline();
 
 protected:
-//     virtual void editorKeyPressEvent(QKeyEvent *ev);
-       void resizeEvent(QResizeEvent *);
        virtual void closeEvent (QCloseEvent * e);
 private:
-//     My_Edit *e;
-//     QTextEdit *msg;
        QLabel *position;
        QString fname;
        QString find_text;
@@ -79,4 +67,4 @@ private:
        char HomeDir[255];
 };
 
-#endif // QWERTY_H
+#endif /* VLP_EDITOR */
index 3a319fa01d1a2d481b61e6effc81f6589a1e612e..0b3e68a689b550ab536aad0f7856713d885dbdef 100644 (file)
@@ -6,11 +6,11 @@
 class My_Edit : public QTextEdit {
        Q_OBJECT
 public:
-       My_Edit(QWidget *parent = 0, const char *name = 0);
-signals:
-       void cursorMove();
+       My_Edit(QWidget *parent);
 protected:
        virtual void keyPressEvent(QKeyEvent*);
+signals:
+       void cursorMove();
 };
 
 #endif /* VLP_EDITOR_AREA */