Restore functionality of loglan helpers
authorRafał Długołęcki <rafal@dlugolecki.net.pl>
Wed, 27 Jan 2016 22:56:35 +0000 (23:56 +0100)
committerRafał Długołęcki <rafal@dlugolecki.net.pl>
Wed, 27 Jan 2016 22:56:35 +0000 (23:56 +0100)
src/edit/editor.cpp
src/edit/ui/editor.ui

index 1daa7e7a8640212a1f6e134d9dded156566f0275..5559ac4dbd0c95a45d48944b6abbb219719524ea 100644 (file)
@@ -11,6 +11,8 @@
 #include <QtGui/QStatusBar>
 #include <QtGui/QCheckBox>
 #include <QtGui/QVBoxLayout>
+#include <QtGui/QListWidget>
+#include <QtGui/QListWidgetItem>
 
 #include "editor.h"
 
@@ -44,9 +46,6 @@ Editor::Editor(int argc, char **argv)
        find_text = "";
        sensitive = FALSE;
 
-       /* loglan->insertItem( "Program structure", this, SLOT(log_prog()));*/
-       /* loglan->insertItem( "Unit structure", this, SLOT(log_unit()));*/
-
        compiler_path.sprintf("%s/%s", HomeDir, "compile/logcomp");
        gen_path.sprintf("%s/%s", HomeDir, "compile/gen");
        file_path.sprintf("%s", HomeDir);
@@ -252,8 +251,6 @@ void Editor::on_actionClear_all_triggered()
 void Editor::on_actionFind_triggered()
 {
        QDialog dlg(this, Qt::Dialog);
-       QString *txt;
-       int res, line, pom;
 
        QLineEdit *tmpQLineEdit;
        tmpQLineEdit = new QLineEdit("", &dlg);
@@ -411,14 +408,7 @@ void Editor::on_actionCompile_Gen_triggered()
 
 void Editor::on_actionProgram_structure_triggered()
 {
-       /*
-       Code commented during Qt4 migration.
-       Code is not used, so there is no rush with this...
-       */
-       /*
-       QString txt;
        QDialog dlg(this, "unit", TRUE);
-       int cx, cy;
        char uname[255];
 
        QLineEdit *files;
@@ -430,45 +420,37 @@ void Editor::on_actionProgram_structure_triggered()
        files->setFrame(TRUE);
 
        QLabel *tmpQLabel;
-       tmpQLabel = new QLabel(&dlg, "Label_1");
+       tmpQLabel = new QLabel(&dlg);
        tmpQLabel->setGeometry(10, 20, 100, 30);
        tmpQLabel->setText("Program name:");
 
        QPushButton* tmpQPushButton;
-       tmpQPushButton = new QPushButton(&dlg, "OkBtn");
+       tmpQPushButton = new QPushButton(&dlg);
        tmpQPushButton->setGeometry(40, 70, 70, 30);
        tmpQPushButton->setText("Ok");
        tmpQPushButton->setAutoRepeat(FALSE);
-       tmpQPushButton->setAutoResize(FALSE);
        connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(accept()));
 
-       tmpQPushButton = new QPushButton(&dlg, "CancelBtn");
+       tmpQPushButton = new QPushButton(&dlg);
        tmpQPushButton->setGeometry(130, 70, 100, 30);
        tmpQPushButton->setText("Cancel");
        tmpQPushButton->setAutoRepeat(FALSE);
-       tmpQPushButton->setAutoResize(FALSE);
        connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(reject()));
 
        if (dlg.exec()) {
                strcpy(uname, files->text());
-               e->getCursorPosition(&cx, &cy);
 
-               txt.sprintf("PROGRAM %s\n\nBEGIN\n\nEND ", uname);
-               e->insertAt(txt, cx, cy);
+               QString txt;
+               txt.sprintf("PROGRAM %s\n\nBEGIN\n\nEND", uname);
+
+               editor->textCursor().insertText(txt);
        }
-       */
 }
 
 void Editor::on_actionUnit_structure_triggered()
 {
-       /*
-       Code commented during Qt4 migration.
-       Code is not used, so there is no rush with this...
-       */
-       /*
-       QString txt;
        QDialog dlg(this, Qt::Dialog);
-       int cx, cy, i;
+       int i;
        char uname[255];
 
        QLineEdit* files;
@@ -480,47 +462,49 @@ void Editor::on_actionUnit_structure_triggered()
        files->setFrame(TRUE);
 
        QLabel* tmpQLabel;
-       tmpQLabel = new QLabel(&dlg, "Label_1");
+       tmpQLabel = new QLabel(&dlg);
        tmpQLabel->setGeometry(10, 20, 100, 30);
        tmpQLabel->setText("Unit name:");
        tmpQLabel->setAlignment(289);
        tmpQLabel->setMargin(-1);
 
        QPushButton* tmpQPushButton;
-       tmpQPushButton = new QPushButton(&dlg, "OkBtn");
+       tmpQPushButton = new QPushButton(&dlg);
        tmpQPushButton->setGeometry(40, 170, 70, 30);
        tmpQPushButton->setText("Ok");
        tmpQPushButton->setAutoRepeat(FALSE);
-       tmpQPushButton->setAutoResize(FALSE);
        connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(accept()));
 
-       tmpQPushButton = new QPushButton(&dlg, "CancelBtn");
+       tmpQPushButton = new QPushButton(&dlg);
        tmpQPushButton->setGeometry(130, 170, 100, 30);
        tmpQPushButton->setText("Cancel");
        tmpQPushButton->setAutoRepeat(FALSE);
-       tmpQPushButton->setAutoResize(FALSE);
        connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(reject()));
 
-       tmpQLabel = new QLabel(&dlg, "Label_1");
+       tmpQLabel = new QLabel(&dlg);
        tmpQLabel->setGeometry(10, 50, 100, 60);
        tmpQLabel->setText("Unit type:");
 
-       QListBox lst(&dlg, "type");
+       QListWidget *listWidget = new QListWidget(&dlg);
        for(i = 0; i < TYPENUM; i++) {
-               lst.insertItem(UnitTypes[i]);
+               QListWidgetItem *newItem = new QListWidgetItem;
+               newItem->setText(UnitTypes[i]);
+               listWidget->insertItem(i, newItem);
        }
-       lst.setGeometry(130, 60, 180, 80);
-       lst.setCurrentItem(0);
+       listWidget->setCurrentItem(0);
 
        if (dlg.exec()) {
                strcpy(uname, files->text());
-               e->getCursorPosition(&cx, &cy);
 
+               QString txt;
                txt.sprintf("UNIT %s : %s( <params> );\nBEGIN\n\nEND %s;",
-                       uname, lst.text(lst.currentItem()).ascii(), uname);
-               e->insertAt(txt, cx, cy);
+                       uname,
+                       listWidget->currentItem()->text().toStdString().c_str(),
+                       uname
+               );
+
+               editor->textCursor().insertText(txt);
        }
-       */
 }
 
 /**
index cfb03764c7902a9692abdb43449a2a6db1c79766..11c7c23c408ea25a90a6f5850670f3e31f722100 100644 (file)
    </widget>
    <widget class="QMenu" name="menuLoglan">
     <property name="enabled">
-     <bool>false</bool>
+     <bool>true</bool>
     </property>
     <property name="title">
      <string>Loglan</string>