vlp-28 Moving editor to use QtDesigner files.
authorRafał Długołęcki <kontakt@dlugolecki.net.pl>
Wed, 30 Oct 2013 21:04:12 +0000 (22:04 +0100)
committerRafał Długołęcki <kontakt@dlugolecki.net.pl>
Wed, 30 Oct 2013 21:04:12 +0000 (22:04 +0100)
Makefile.am
data/editor/editor-window.ui [new file with mode: 0644]
src/edit/editor.cpp
src/edit/editor.h
src/edit/my_edit.h [new file with mode: 0644]

index 14dcd629a50a891c210037d0e5fcc42acaecd5bb..f716d463ec38af161d071ecf80f58d075dc2def8 100644 (file)
@@ -105,6 +105,7 @@ src/kernel/options.moc.cpp:
        moc-qt4 src/kernel/options.h -o src/kernel/options.moc.cpp
        
 clean-logker-extra:
+       rm -rf src/kernel/ui
        rm -f src/kernel/*.moc.cpp
        rm -f bin/logker
        
@@ -149,19 +150,31 @@ bin_logint_HEADERS = \
 clean-logint-extra:
        rm -f bin/logint
 
-bin_logedit_SOURCES = src/edit/editor.cpp src/edit/editor.moc.cpp 
+bin_logedit_SOURCES = \
+       src/edit/editor.cpp \
+       src/edit/editor.moc.cpp \
+       src/edit/my_edit.moc.cpp
 bin_logedit_CPPFLAGS = $(bin_logedit_CFLAGS) 
 bin_logedit_LDADD = $(bin_logedit_LIBS)
 bin_logeditdir = src/edit
 bin_logedit_HEADERS =\
-       src/edit/editor.h
+       src/edit/editor.h \
+       src/edit/my_edit.h \
+       src/edit/ui/editor-window.h
 
-src/edit/editor.moc.cpp: src/edit/editor.h
+src/edit/ui/editor-window.h: data/editor/editor-window.ui
+       if [ ! -d src/edit/ui ]; then mkdir -p src/edit/ui; fi
+       uic-qt4 data/editor/editor-window.ui -o src/edit/ui/editor-window.h
+
+src/edit/editor.moc.cpp:  $(bin_logedit_HEADERS)
        moc-qt4 src/edit/editor.h -o src/edit/editor.moc.cpp
 #      $(MOC) src/edit/editor.h -o src/edit/editor.moc.cpp
+src/edit/my_edit.moc.cpp:  $(bin_logedit_HEADERS)
+       moc-qt4 src/edit/my_edit.h -o src/edit/my_edit.moc.cpp
 
 
 clean-logedit-extra:
+       rm -rf src/edit/ui
        rm -f src/edit/*.moc.cpp
        rm -f bin/modules/logedit
        rm -f bin/logedit
diff --git a/data/editor/editor-window.ui b/data/editor/editor-window.ui
new file mode 100644 (file)
index 0000000..409612b
--- /dev/null
@@ -0,0 +1,217 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>EditorWindow</class>
+ <widget class="QMainWindow" name="EditorWindow">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>523</width>
+    <height>473</height>
+   </rect>
+  </property>
+  <property name="maximumSize">
+   <size>
+    <width>800</width>
+    <height>600</height>
+   </size>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <widget class="QWidget" name="centralwidget">
+   <layout class="QVBoxLayout" name="verticalLayout_2">
+    <property name="margin">
+     <number>0</number>
+    </property>
+    <item>
+     <layout class="QVBoxLayout" name="verticalLayout" stretch="0,0">
+      <property name="sizeConstraint">
+       <enum>QLayout::SetMaximumSize</enum>
+      </property>
+      <property name="leftMargin">
+       <number>3</number>
+      </property>
+      <property name="rightMargin">
+       <number>3</number>
+      </property>
+      <item>
+       <widget class="My_Edit" name="e"/>
+      </item>
+      <item>
+       <widget class="QTextEdit" name="msg">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="maximumSize">
+         <size>
+          <width>16777215</width>
+          <height>100</height>
+         </size>
+        </property>
+        <property name="autoFillBackground">
+         <bool>false</bool>
+        </property>
+        <property name="readOnly">
+         <bool>true</bool>
+        </property>
+        <property name="acceptRichText">
+         <bool>false</bool>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </item>
+   </layout>
+  </widget>
+  <widget class="QMenuBar" name="menubar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>523</width>
+     <height>20</height>
+    </rect>
+   </property>
+   <widget class="QMenu" name="menuFile">
+    <property name="title">
+     <string>File</string>
+    </property>
+    <addaction name="actionNew"/>
+    <addaction name="actionOpen"/>
+    <addaction name="actionSave"/>
+    <addaction name="actionSave_as"/>
+    <addaction name="separator"/>
+    <addaction name="actionQuit"/>
+   </widget>
+   <widget class="QMenu" name="menuEdit">
+    <property name="title">
+     <string>Edit</string>
+    </property>
+    <addaction name="actionCopy"/>
+    <addaction name="actionPaste"/>
+    <addaction name="actionCut"/>
+    <addaction name="actionClear_all"/>
+    <addaction name="separator"/>
+    <addaction name="actionFind"/>
+    <addaction name="actionFind_next"/>
+   </widget>
+   <widget class="QMenu" name="menuTools">
+    <property name="title">
+     <string>Tools</string>
+    </property>
+    <addaction name="actionCompile"/>
+    <addaction name="separator"/>
+    <addaction name="actionProperties"/>
+   </widget>
+   <addaction name="menuFile"/>
+   <addaction name="menuEdit"/>
+   <addaction name="menuTools"/>
+  </widget>
+  <widget class="QStatusBar" name="statusbar"/>
+  <action name="actionNew">
+   <property name="text">
+    <string>New</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+N</string>
+   </property>
+  </action>
+  <action name="actionOpen">
+   <property name="text">
+    <string>Open</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+O</string>
+   </property>
+  </action>
+  <action name="actionSave">
+   <property name="text">
+    <string>Save</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+S</string>
+   </property>
+  </action>
+  <action name="actionSave_as">
+   <property name="text">
+    <string>Save as</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+Shift+S</string>
+   </property>
+  </action>
+  <action name="actionQuit">
+   <property name="text">
+    <string>Quit</string>
+   </property>
+  </action>
+  <action name="actionCopy">
+   <property name="text">
+    <string>Copy</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+C</string>
+   </property>
+  </action>
+  <action name="actionPaste">
+   <property name="text">
+    <string>Paste</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+V</string>
+   </property>
+  </action>
+  <action name="actionCut">
+   <property name="text">
+    <string>Cut</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+X</string>
+   </property>
+  </action>
+  <action name="actionClear_all">
+   <property name="text">
+    <string>Clear All</string>
+   </property>
+  </action>
+  <action name="actionFind">
+   <property name="text">
+    <string>Find</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+F</string>
+   </property>
+  </action>
+  <action name="actionFind_next">
+   <property name="text">
+    <string>Find Next</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+L</string>
+   </property>
+  </action>
+  <action name="actionCompile">
+   <property name="text">
+    <string>Compile</string>
+   </property>
+  </action>
+  <action name="actionProperties">
+   <property name="text">
+    <string>Properties</string>
+   </property>
+  </action>
+ </widget>
+ <customwidgets>
+  <customwidget>
+   <class>My_Edit</class>
+   <extends>QTextEdit</extends>
+   <header>../my_edit.h</header>
+  </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
index fe7bc25b3fb20995e220bf3fdb4e958826860d05..bf1360cf1349848715d8c8b9c0d205d7db898de1 100644 (file)
@@ -13,6 +13,7 @@
 #include <QtGui/QVBoxLayout>
 
 #include "editor.h"
+#include "my_edit.h"
 
 #define TYPENUM        5
 
@@ -74,30 +75,33 @@ void Editor::closeEvent(QCloseEvent * e) {
 Editor::Editor(char *hdir, QWidget * parent)
        : QMainWindow(parent)
 {
+       setupUi(this);
+
        strcpy(HomeDir, hdir);
        find_text = "";
        sensitive = FALSE;
-       QMenu * file = NULL;
+//     QMenu * file = NULL;
 /*     QMenu * comp = new QMenu();*/
 /*     QMenu * loglan = new QMenu();*/
-       QMenu * medit = NULL;
-       QAction* action = NULL;
+//     QMenu * medit = NULL;
+//     QAction* action = NULL;
 
-       file = menuBar()->addMenu("&File");
-       medit = menuBar()->addMenu("&Edit");
+//     file = menuBar()->addMenu("&File");
+//     medit = menuBar()->addMenu("&Edit");
 
-       action = menuBar()->addAction("&Compile", this, SLOT(cmp()));
+//     action = menuBar()->addAction("&Compile", this, SLOT(cmp()));
 
        /*    m->insertItem( "&LOGLAN ", loglan );*/
 
-       action = menuBar()->addAction("&Properties", this, SLOT(props()));
+//     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();
-       file->addAction("Quit ", this, SLOT(close()));
+//     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);*/
@@ -105,36 +109,40 @@ 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");
+       
+//     e = new My_Edit(this, "editor");
        connect(e, SIGNAL(cursorMove()), this, SLOT(updateline()));
-       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);
+       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);
+//     QColor col(200, 200, 200);
+//     QPalette grp(Qt::black, col, col.lighter(), col.darker(), col.darker(), Qt::black, col);
 
-       msg->setPalette(grp);
+//     msg->setPalette(grp);
 
        position = new QLabel();
        statusBar()->addPermanentWidget(position);
@@ -189,7 +197,7 @@ TODO: Remove entire method?
 /**
  * Displays additional window 
  */
-void Editor::load()
+void Editor::on_actionOpen_triggered()
 {
        QString fn = QFileDialog::getOpenFileName(this, "Load file", file_path, "*.log");
        if (!fn.isEmpty())
@@ -232,7 +240,7 @@ void Editor::load(const char *fileName)
  * If content has been read from file, it is written to this file. Otherwise
  * dialog is shown to save content to the specified by user, file.
  */
-void Editor::save()
+void Editor::on_actionSave_triggered()
 {
        if (fname.isEmpty()) {
                QString fn = QFileDialog::getSaveFileName(this, "Save file", 
@@ -252,7 +260,7 @@ void Editor::save()
  * Forces saving editor content to the new file. Special dialog is shown for
  * that purpose.
  */
-void Editor::save_as()
+void Editor::on_actionSave_as_triggered()
 {
        QString fn = QFileDialog::getSaveFileName(this, "Save file as",
                                                        file_path, "*.log");
@@ -280,7 +288,7 @@ void Editor::save(const char *fileName)
 /**
  * Empties editor content.
  */
-void Editor::create()
+void Editor::on_actionNew_triggered()
 {
        e->clear();
        fname.sprintf("%s", "");
@@ -289,18 +297,18 @@ void Editor::create()
 /**
  * @attention Currently not in use
  */
-void Editor::print()
-{
-}
+//void Editor::print()
+//{
+//}
 
 /**
  * @attention Currently not in use.
  * 
  * Saves and compiles code.
  */
-void Editor::cmp()
+void Editor::on_actionCompile_triggered()
 {
-       save();
+       on_actionSave_triggered();
        compile(COMP_MODE);
 }
 
@@ -321,7 +329,7 @@ void Editor::gen()
  */
 void Editor::comp_all()
 {
-       save();
+       on_actionSave_triggered();
        compile(ALL_MODE);
 }
 
@@ -389,7 +397,7 @@ void Editor::compile(int mode)
 /**
  * Displays window with editor properties
  */
-void Editor::props()
+void Editor::on_actionProperties_triggered()
 {
        QDialog dlg(this, Qt::Dialog);
 
@@ -587,7 +595,7 @@ void Editor::log_prog()
  * Displays window to set search parameters. If text is found sets cursor
  * position on it.
  */
-void Editor::findText()
+void Editor::on_actionFind_triggered()
 {
        QDialog dlg(this, Qt::Dialog);
        QString *txt;
@@ -641,7 +649,7 @@ void Editor::findText()
  * Displays window to set search parameters. If text is found sets cursor
  * position on it.
  */
-void Editor::find_next()
+void Editor::on_actionFind_next_triggered()
 {
        if (!find_text.isEmpty()) {
                QTextDocument::FindFlags flags = 0;
index 5c8fa502ac99929af98fc7e8e19990c3b137d18d..16f4cacb9a6517c4a29e4934e9fedea996d06a97 100644 (file)
@@ -7,6 +7,7 @@
 #include <QtGui/QPushButton>
 #include <QtGui/QLabel>
 
+#include "ui/editor-window.h"
 
 #define COMP_MODE      1
 #define GEN_MODE       2
@@ -22,17 +23,16 @@ 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);
-       virtual void keyPressEvent(QKeyEvent *ev);
 signals:
        void cursorMove();
 };
-
-class Editor : public QMainWindow {
+*/
+class Editor : public QMainWindow, private Ui::EditorWindow {
        Q_OBJECT
 public:
        QString compiler_path;
@@ -45,32 +45,33 @@ public:
        void compile(int mode);
 
 public slots:
-       void load();
+       void on_actionOpen_triggered();
        void load(const char *fileName);
-       void save();
+       void on_actionSave_triggered();
        void save(const char *fileName);
-       void save_as();
-       void create();
-       void props();
-       void print();
-       void cmp();
+       void on_actionSave_as_triggered();
+       void on_actionNew_triggered();
+       void on_actionProperties_triggered();
+//     void print();
+       void on_actionCompile_triggered();
        void gen();
        void comp_all();
 
        void log_unit();
        void log_prog();
 
-       void findText();
-       void find_next();
+       void on_actionFind_triggered();
+       void on_actionFind_next_triggered();
        //void gotoline();
        void updateline();
 
 protected:
+//     virtual void editorKeyPressEvent(QKeyEvent *ev);
        void resizeEvent(QResizeEvent *);
        virtual void closeEvent (QCloseEvent * e);
 private:
-       My_Edit *e;
-       QTextEdit *msg;
+//     My_Edit *e;
+//     QTextEdit *msg;
        QLabel *position;
        QString fname;
        QString find_text;
diff --git a/src/edit/my_edit.h b/src/edit/my_edit.h
new file mode 100644 (file)
index 0000000..3a319fa
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef VLP_EDITOR_AREA_H
+#define VLP_EDITOR_AREA_H
+
+#include <QtGui/QTextEdit>
+
+class My_Edit : public QTextEdit {
+       Q_OBJECT
+public:
+       My_Edit(QWidget *parent = 0, const char *name = 0);
+signals:
+       void cursorMove();
+protected:
+       virtual void keyPressEvent(QKeyEvent*);
+};
+
+#endif /* VLP_EDITOR_AREA */