vlp-7 Documented logedit.
[vlp.git] / src / edit / editor.cpp
index c506e5a64debfe36910642ba0357a4320a05e8a7..096f5aea3f49f6162954005b1cf1b416a45f29e0 100644 (file)
 
 #define TYPENUM        5
 
-
 Editor *e;
 
-char *UnitTypes[5] = {"CLASS","PROCEDURE","FUNCTION","PROCESS","COROUTINE"};
-
-
+/**
+ * @attention Currently not in use
+ */
+char *UnitTypes[TYPENUM] = {
+       "CLASS",
+       "PROCEDURE",
+       "FUNCTION",
+       "PROCESS",
+       "COROUTINE"
+};
+
+/**
+ * My_Edit constructor. Initializes and sets variables of Multiline editor
+ * widget.
+ * @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)
+ */
 My_Edit::My_Edit(QWidget *parent, const char *name)
        : QMultiLineEdit(parent, name)
 {
@@ -38,19 +54,33 @@ My_Edit::My_Edit(QWidget *parent, const char *name)
        name = NULL;
 }
 
+/**
+ * @copydoc QWidget::keyPressEvent(QKeyEvent*)
+ */
 void My_Edit::keyPressEvent(QKeyEvent *ev)
 {
        QMultiLineEdit::keyPressEvent(ev);
        emit cursorMove();
 }
 
-
-void Editor::closeEvent ( QCloseEvent * e ) {
+/**
+ * @copydoc QWidget::closeEvent(QCloseEvent*)
+ */
+void Editor::closeEvent(QCloseEvent * e) {
        e->ignore();
 }
 
-Editor::Editor( char *hdir,QWidget * parent , const char * name)
-       : QWidget( parent, name )
+/**
+ * Editor constructor. Initializes and sets variables of Loglan Editor.
+ * @param hdir Home directory of program (specified in configuration file)
+ * @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 , const char * name)
+       : QWidget(parent, name)
 {
        QFont f1("Helvetica", 10, QFont::Bold);
 
@@ -120,10 +150,16 @@ Editor::Editor( char *hdir,QWidget * parent , const char * name)
        resize(400, 300);
 }
 
+/**
+ * Editor destructor
+ */
 Editor::~Editor()
 {
 }
 
+/**
+ * Displays line:column position of cursor
+ */
 void Editor::updateline()
 {
        char pom[255];
@@ -135,7 +171,12 @@ void Editor::updateline()
        position->setText(pom);
 }
 
-void Editor::resizeEvent(QResizeEvent *)
+/**
+ * Event invoked when resizing editor window.
+ * @copydoc QWidget::resizeEvent(QResizeEvent*)
+ * @param event Currently does nothing
+ */
+void Editor::resizeEvent(QResizeEvent *event)
 {
        if (e && m) {
                e->setGeometry(0, m->height(), width(),
@@ -151,7 +192,9 @@ void Editor::resizeEvent(QResizeEvent *)
        }
 }
 
-
+/**
+ * Displays additional window 
+ */
 void Editor::load()
 {
        QString fn = QFileDialog::getOpenFileName(file_path.data(), "*.log");
@@ -159,7 +202,10 @@ void Editor::load()
                load(fn);
 }
 
-
+/**
+ * Loads given file content to the editor.
+ * @param fileName Filename of file which will be read.
+ */
 void Editor::load(const char *fileName)
 {
        fname.sprintf("%s", fileName);
@@ -183,7 +229,11 @@ void Editor::load(const char *fileName)
        setCaption(fileName);
 }
 
-
+/**
+ * Saves editor content to the file.
+ * 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()
 {
        if (fname.isEmpty()) {
@@ -199,6 +249,11 @@ void Editor::save()
        setCaption(fname);
 }
 
+/**
+ * Saves editor content to the file.
+ * Forces saving editor content to the new file. Special dialog is shown for
+ * that purpose.
+ */
 void Editor::save_as()
 {
        QString fn = QFileDialog::getSaveFileName(file_path.data(), "*.log");
@@ -209,6 +264,10 @@ void Editor::save_as()
        setCaption(fname);
 }
 
+/**
+ * Saves editor content to the given filename.
+ * @param fileName File name of the file where content should be saved.
+ */
 void Editor::save(const char *fileName)
 {
        QFile f(fileName);
@@ -219,34 +278,61 @@ void Editor::save(const char *fileName)
        f.close();
 }
 
-
+/**
+ * Empties editor content.
+ */
 void Editor::create()
 {
        e->clear();
        fname.sprintf("%s", "");
 }
 
+/**
+ * @attention Currently not in use
+ */
 void Editor::print()
 {
 }
 
+/**
+ * @attention Currently not in use.
+ * 
+ * Saves and compiles code.
+ */
 void Editor::cmp()
 {
        save();
        compile(COMP_MODE);
 }
 
+/**
+ * @attention Currently not in use.
+ * 
+ * Generates program.
+ */
 void Editor::gen()
 {
        compile(GEN_MODE);
 }
 
+/**
+ * @attention Currently not in use.
+ * 
+ * Saves, compiles and generates code.
+ */
 void Editor::comp_all()
 {
        save();
        compile(ALL_MODE);
 }
 
+/**
+ * Invokes compiler in the giving mode.
+ * @param mode Mode of compilation. Possible values:
+ *             - COMP_MODE - compilation mode
+ *             - GEN_MODE - program generation mode
+ *             - ALL_MODE - compilation & generation mode.
+ */
 void Editor::compile(int mode)
 {
        char cmd[255];
@@ -260,6 +346,7 @@ void Editor::compile(int mode)
        /* if (i>=0) {*/
 
        QString fn = fname.data();
+
        /*  fn.truncate(i);*/
        switch(mode) {
        case COMP_MODE:
@@ -275,7 +362,7 @@ void Editor::compile(int mode)
                system(cmd);
                sprintf(cmd, "%s %s >> comp_data!", gen_path.data(), fn.data());
        break;
-       } /*switch */
+       }
 
        system(cmd);
        QFile f("comp_data!");
@@ -295,6 +382,9 @@ void Editor::compile(int mode)
        /*}*/
 }
 
+/**
+ * Displays window with editor properties
+ */
 void Editor::props()
 {
        QDialog dlg(this, "Properties", TRUE);
@@ -369,8 +459,9 @@ void Editor::props()
        };
 }
 
-/* --------------------------------------- */
-
+/**
+ * @attention Currently not in use
+ */
 void Editor::log_unit()
 {
        QString txt;
@@ -413,7 +504,7 @@ void Editor::log_unit()
        tmpQLabel->setText("Unit type:");
 
        QListBox lst(&dlg, "type");
-       for(i=0; i < TYPENUM; i++) {
+       for(i = 0; i < TYPENUM; i++) {
                lst.insertItem(UnitTypes[i]);
        }
        lst.setGeometry(130, 60, 180, 80);
@@ -429,7 +520,9 @@ void Editor::log_unit()
        }
 }
 
-
+/**
+ * @attention Currently not in use
+ */
 void Editor::log_prog()
 {
        QString txt;
@@ -474,7 +567,11 @@ void Editor::log_prog()
        }
 }
 
-
+/**
+ * Searches for given text in editor content.
+ * Displays window to set search parameters. If text is found sets cursor
+ * position on it.
+ */
 void Editor::findText()
 {
        QDialog dlg(this, "", TRUE);
@@ -537,31 +634,46 @@ void Editor::findText()
        }
 }
 
+/**
+ * Searches for next occurence of given text in editor content.
+ * Displays window to set search parameters. If text is found sets cursor
+ * position on it.
+ */
 void Editor::find_next()
 {
        int pom,res,line;
        QString *txt;
 
-       e->getCursorPosition(&pom,&res);
+       e->getCursorPosition(&pom, &res);
        for(line = pom + 1; line < e->numLines(); line++) {
                txt = new QString(e->textLine(line));
                if (sensitive)
-                       res=txt->find(find_text,0,TRUE);
+                       res=txt->find(find_text, 0, TRUE);
                else
-                       res=txt->find(find_text,0,FALSE);
+                       res=txt->find(find_text, 0, FALSE);
 
                delete txt;
                if (res >= 0) {
-                       e->setCursorPosition(line,1);
+                       e->setCursorPosition(line, 1);
                        break;
                }
        }
 }
 
+/**
+ * Program main function.
+ * argv[1] is mandatory and should be a path to the home directory of
+ * application (same as in configuration file).
+ * @param argc Number of program arguments
+ * @param argv Program arguments
+ */
 int main(int argc, char **argv)
 {
        QApplication a(argc, argv);
        //a.setStyle(WindowsStyle);
+       /*
+       Defaults are zeroed, so created Editor widget become top-level window.
+       */
        e = new Editor(argv[1]);
        e->resize(600, 400);
        e->show();