vlp-28 Moving editor to use QtDesigner files.
[vlp.git] / src / edit / editor.cpp
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;