31 * @attention Currently not in use
33 char *UnitTypes[TYPENUM] = {
42 * My_Edit constructor. Initializes and sets variables of Multiline editor
44 * @param parent Parent widget of this widget. If set, this widget becomes a
45 * child window inside parent. If not set this widget becomes a
46 * top level window. Default: NULL
47 * @param name If set, name is sent to the Qobject constructor, so widget is
48 * identifiable (e.g. in Qt Designer)
50 My_Edit::My_Edit(QWidget *parent, const char *name)
51 : QMultiLineEdit(parent, name)
58 * @copydoc QWidget::keyPressEvent(QKeyEvent*)
60 void My_Edit::keyPressEvent(QKeyEvent *ev)
62 QMultiLineEdit::keyPressEvent(ev);
67 * Event invoked on program close.
68 * @copydoc QWidget::closeEvent(QCloseEvent*)
70 void Editor::closeEvent(QCloseEvent * e) {
75 * Editor constructor. Initializes and sets variables of Loglan Editor.
76 * @param hdir Home directory of program (specified in configuration file)
77 * @param parent Parent widget of this widget. If set, this widget becomes a
78 * child window inside parent. If not set this widget becomes a
79 * top level window. Default: NULL
80 * @param name If set, name is sent to the Qobject constructor, so widget is
81 * identifiable (e.g. in Qt Designer)
83 Editor::Editor(char *hdir,QWidget * parent , const char * name)
84 : QWidget(parent, name)
86 QFont f1("Helvetica", 10, QFont::Bold);
88 strcpy(HomeDir, hdir);
89 strcpy(find_text, "");
91 m = new QMenuBar(this, "menu");
93 QPopupMenu * file = new QPopupMenu();
94 QPopupMenu * comp = new QPopupMenu();
95 QPopupMenu * loglan = new QPopupMenu();
96 QPopupMenu *medit = new QPopupMenu();
104 m->insertItem("&File ", file);
105 m->insertItem("&Edit", medit);
106 m->insertItem("&Compile", this,SLOT(cmp()));
108 /* m->insertItem( "&LOGLAN ", loglan );*/
109 m->insertItem("&Properties", this, SLOT(props()));
111 file->insertItem("New ", this, SLOT(create()), CTRL + Key_N);
112 file->insertItem("Open ", this, SLOT(load()), CTRL + Key_O);
113 file->insertItem("Save ", this, SLOT(save()),CTRL + Key_S);
114 file->insertItem("Save as", this, SLOT(save_as()),CTRL + Key_A);
115 file->insertSeparator();
116 file->insertItem("Quit ", qApp, SLOT(quit()));
118 /* comp->insertItem("Compile ", this, SLOT(cmp()), CTRL + Key_C);*/
119 /* comp->insertItem("Gen ", this, SLOT(gen()), CTRL + Key_G);*/
120 /* comp->insertItem("Compile & Gen ", this, SLOT(comp_all()));*/
122 /* loglan->insertItem( "Program structure", this, SLOT(log_prog()));*/
123 /* loglan->insertItem( "Unit structure", this, SLOT(log_unit()));*/
125 e = new My_Edit( this, "editor" );
126 connect(e,SIGNAL(cursorMove()),this,SLOT(updateline()));
127 medit->insertItem("Copy ",e,SLOT(copy()),CTRL + Key_Insert);
128 medit->insertItem("Paste ",e,SLOT(paste()), SHIFT + Key_Insert);
129 medit->insertItem("Cut ",e,SLOT(cut()), CTRL + Key_Delete);
130 medit->insertItem("Clear All ",e,SLOT(clear()));
131 medit->insertSeparator();
132 medit->insertItem("Find ",this,SLOT(findText()), CTRL + Key_F);
133 medit->insertItem("Find Next ",this,SLOT(find_next()),CTRL + Key_L);
135 msg = new QMultiLineEdit( this, "messages" );
136 msg->setReadOnly(TRUE);
137 compiler_path.sprintf("%s/%s",HomeDir,"compile/logcomp");
138 gen_path.sprintf("%s/%s",HomeDir,"compile/gen");
139 file_path.sprintf("%s",HomeDir);
141 QFont f2("Times", 14, QFont::Bold);
143 QColor col(200, 200, 200);
144 QColorGroup grp(black, col, col.light(), col.dark(), col.dark(), black, col);
146 msg->setPalette(QPalette(grp, grp, grp));
147 position = new QLabel(this);
148 position->setFont(f2);
149 position->setFrameStyle(QFrame::NoFrame);
150 position->setAutoResize(TRUE);
162 * Displays line:column position of cursor
164 void Editor::updateline()
170 e->getCursorPosition(&cx, &cy);
171 sprintf(pom," %d:%d ", cx, cy);
172 position->setText(pom);
176 * Event invoked on resizing editor application window.
177 * @copydoc QWidget::resizeEvent(QResizeEvent*)
178 * @param event Currently does nothing
180 void Editor::resizeEvent(QResizeEvent *event)
183 e->setGeometry(0, m->height(), width(),
184 3 * (int)((height() - m->height()) / 4));
186 msg->setGeometry(0, m->height() + e->height(), width(),
187 (int)((height() - m->height()) / 4));
189 position->setGeometry(width() - 80,
190 m->height() + e->height() - 10,
197 * Displays additional window
201 QString fn = QFileDialog::getOpenFileName(file_path.data(), "*.log");
207 * Loads given file content to the editor.
208 * @param fileName Filename of file which will be read.
210 void Editor::load(const char *fileName)
212 fname.sprintf("%s", fileName);
215 if (!f.open(IO_ReadOnly))
218 e->setAutoUpdate(FALSE);
223 QString s = t.readLine();
228 e->setAutoUpdate(TRUE);
230 setCaption(fileName);
234 * Saves editor content to the file.
235 * If content has been read from file, it is written to this file. Otherwise
236 * dialog is shown to save content to the specified by user, file.
240 if (fname.isEmpty()) {
241 QString fn = QFileDialog::getSaveFileName(file_path.data(),
244 fname.sprintf("%s",fn.data());
254 * Saves editor content to the file.
255 * Forces saving editor content to the new file. Special dialog is shown for
258 void Editor::save_as()
260 QString fn = QFileDialog::getSaveFileName(file_path.data(), "*.log");
262 fname.sprintf("%s", fn.data());
269 * Saves editor content to the given filename.
270 * @param fileName File name of the file where content should be saved.
272 void Editor::save(const char *fileName)
275 if (!f.open(IO_WriteOnly))
278 f.writeBlock(e->text().data(), e->text().length());
283 * Empties editor content.
285 void Editor::create()
288 fname.sprintf("%s", "");
292 * @attention Currently not in use
299 * @attention Currently not in use.
301 * Saves and compiles code.
310 * @attention Currently not in use.
320 * @attention Currently not in use.
322 * Saves, compiles and generates code.
324 void Editor::comp_all()
331 * Invokes compiler in the giving mode.
332 * @param mode Mode of compilation. Possible values:
333 * - COMP_MODE - compilation mode
334 * - GEN_MODE - program generation mode
335 * - ALL_MODE - compilation & generation mode.
337 void Editor::compile(int mode)
341 msg->setAutoUpdate(FALSE);
342 msg->setReadOnly(FALSE);
346 /*i = fname.find('.');*/
349 QString fn = fname.data();
354 sprintf(cmd, "%s %s > comp_data!", compiler_path.data(),
358 sprintf(cmd, "%s %s > comp_data!", gen_path.data(), fn.data());
361 sprintf(cmd, "%s %s > comp_data!", compiler_path.data(),
364 sprintf(cmd, "%s %s >> comp_data!", gen_path.data(), fn.data());
369 QFile f("comp_data!");
370 if (!f.open(IO_ReadOnly))
375 QString s = t.readLine();
379 msg->setReadOnly(TRUE);
380 msg->setAutoUpdate(TRUE);
382 unlink("comp_data!");
387 * Displays window with editor properties
391 QDialog dlg(this, "Properties", TRUE);
394 files = new QLineEdit(&dlg, "f_path");
395 files->setGeometry(130, 20, 250, 30);
396 files->setText(file_path.data());
397 files->setMaxLength(32767);
398 files->setEchoMode(QLineEdit::Normal);
399 files->setFrame(TRUE);
402 tmpQLabel = new QLabel(&dlg, "Label_1");
403 tmpQLabel->setGeometry(10, 20, 100, 30);
404 tmpQLabel->setText("Path to files:");
405 tmpQLabel->setAlignment(289);
406 tmpQLabel->setMargin(-1);
408 tmpQLabel = new QLabel(&dlg, "Label_2");
409 tmpQLabel->setGeometry(10, 60, 100, 30);
410 tmpQLabel->setText("Path to compiler:");
411 tmpQLabel->setAlignment(289);
412 tmpQLabel->setMargin(-1);
415 tmpQLabel = new QLabel(&dlg, "Label_3");
416 tmpQLabel->setGeometry(10, 100, 100, 30);
417 tmpQLabel->setText("Path to gen:");
418 tmpQLabel->setAlignment(289);
419 tmpQLabel->setMargin(-1);
423 compp = new QLineEdit(&dlg, "l_path");
424 compp->setGeometry(130, 60, 250, 30);
425 compp->setText(compiler_path.data());
426 compp->setMaxLength(32767);
427 compp->setEchoMode(QLineEdit::Normal);
428 compp->setFrame(TRUE);
432 genp = new QLineEdit(&dlg, "g_path");
433 genp->setGeometry(130, 100, 250, 30);
434 genp->setText(gen_path.data());
435 genp->setMaxLength(32767);
436 genp->setEchoMode(QLineEdit::Normal);
437 genp->setFrame(TRUE);
440 QPushButton* tmpQPushButton;
441 tmpQPushButton = new QPushButton(&dlg, "OkBtn");
442 tmpQPushButton->setGeometry(90, 100, 70, 30);
443 tmpQPushButton->setText("Ok");
444 tmpQPushButton->setAutoRepeat(FALSE);
445 tmpQPushButton->setAutoResize(FALSE);
446 connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(accept()));
448 tmpQPushButton = new QPushButton(&dlg, "CancelBtn");
449 tmpQPushButton->setGeometry(180, 100, 70, 30);
450 tmpQPushButton->setText("Cancel");
451 tmpQPushButton->setAutoRepeat(FALSE);
452 tmpQPushButton->setAutoResize(FALSE);
453 connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(reject()));
454 dlg.resize(400, 140);
457 compiler_path.sprintf("%s", compp->text().ascii());
458 /* gen_path.sprintf("%s",genp->text()); */
459 file_path.sprintf("%s",files->text().ascii());
464 * @attention Currently not in use
466 void Editor::log_unit()
469 QDialog dlg(this, "unit", TRUE);
474 files = new QLineEdit(&dlg, "f_path");
475 files->setGeometry(130, 20, 250, 30);
477 files->setMaxLength(32767);
478 files->setEchoMode(QLineEdit::Normal);
479 files->setFrame(TRUE);
482 tmpQLabel = new QLabel(&dlg, "Label_1");
483 tmpQLabel->setGeometry(10, 20, 100, 30);
484 tmpQLabel->setText("Unit name:");
485 tmpQLabel->setAlignment(289);
486 tmpQLabel->setMargin(-1);
488 QPushButton* tmpQPushButton;
489 tmpQPushButton = new QPushButton(&dlg, "OkBtn");
490 tmpQPushButton->setGeometry(40, 170, 70, 30);
491 tmpQPushButton->setText("Ok");
492 tmpQPushButton->setAutoRepeat(FALSE);
493 tmpQPushButton->setAutoResize(FALSE);
494 connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(accept()));
496 tmpQPushButton = new QPushButton(&dlg, "CancelBtn");
497 tmpQPushButton->setGeometry(130, 170, 100, 30);
498 tmpQPushButton->setText("Cancel");
499 tmpQPushButton->setAutoRepeat(FALSE);
500 tmpQPushButton->setAutoResize(FALSE);
501 connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(reject()));
503 tmpQLabel = new QLabel(&dlg, "Label_1");
504 tmpQLabel->setGeometry(10, 50, 100, 60);
505 tmpQLabel->setText("Unit type:");
507 QListBox lst(&dlg, "type");
508 for(i = 0; i < TYPENUM; i++) {
509 lst.insertItem(UnitTypes[i]);
511 lst.setGeometry(130, 60, 180, 80);
512 lst.setCurrentItem(0);
515 strcpy(uname, files->text());
516 e->getCursorPosition(&cx, &cy);
518 txt.sprintf("UNIT %s : %s( <params> );\nBEGIN\n\nEND %s;",
519 uname, lst.text(lst.currentItem()).ascii(), uname);
520 e->insertAt(txt, cx, cy);
525 * @attention Currently not in use
527 void Editor::log_prog()
530 QDialog dlg(this, "unit", TRUE);
535 files = new QLineEdit(&dlg, "f_path");
536 files->setGeometry(130, 20, 250, 30);
538 files->setMaxLength(32767);
539 files->setEchoMode(QLineEdit::Normal);
540 files->setFrame(TRUE);
543 tmpQLabel = new QLabel(&dlg, "Label_1");
544 tmpQLabel->setGeometry(10, 20, 100, 30);
545 tmpQLabel->setText("Program name:");
547 QPushButton* tmpQPushButton;
548 tmpQPushButton = new QPushButton(&dlg, "OkBtn");
549 tmpQPushButton->setGeometry(40, 70, 70, 30);
550 tmpQPushButton->setText("Ok");
551 tmpQPushButton->setAutoRepeat(FALSE);
552 tmpQPushButton->setAutoResize(FALSE);
553 connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(accept()));
555 tmpQPushButton = new QPushButton(&dlg, "CancelBtn");
556 tmpQPushButton->setGeometry(130, 70, 100, 30);
557 tmpQPushButton->setText("Cancel");
558 tmpQPushButton->setAutoRepeat(FALSE);
559 tmpQPushButton->setAutoResize(FALSE);
560 connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(reject()));
563 strcpy(uname, files->text());
564 e->getCursorPosition(&cx, &cy);
566 txt.sprintf("PROGRAM %s\n\nBEGIN\n\nEND ", uname);
567 e->insertAt(txt, cx, cy);
572 * Searches for given text in editor content.
573 * Displays window to set search parameters. If text is found sets cursor
576 void Editor::findText()
578 QDialog dlg(this, "", TRUE);
582 QLineEdit *tmpQLineEdit;
583 tmpQLineEdit = new QLineEdit(&dlg, "LineEdit_1");
584 tmpQLineEdit->setGeometry(60, 10, 180, 30);
585 tmpQLineEdit->setText("");
588 tmpQLabel = new QLabel(&dlg, "Label_1");
589 tmpQLabel->setGeometry(10, 10, 50, 30);
591 QFont font("helvetica", 12, 75, 0);
592 font.setStyleHint((QFont::StyleHint)0);
593 //font.setCharSet((QFont::CharSet)0);
594 tmpQLabel->setFont(font);
596 tmpQLabel->setText("Text:");
598 QCheckBox *tmpQRadioButton;
599 tmpQRadioButton = new QCheckBox(&dlg, "RadioButton_1");
600 tmpQRadioButton->setGeometry(70, 50, 150, 30);
601 tmpQRadioButton->setText("Case sensitive");
602 tmpQRadioButton->setAutoRepeat(FALSE);
603 tmpQRadioButton->setAutoResize(FALSE);
605 QPushButton *okbtn, *cbtn;
606 okbtn = new QPushButton(&dlg, "PushButton_1");
607 okbtn->setGeometry(260, 10, 100, 30);
608 okbtn->setText("Find");
609 okbtn->setDefault(TRUE);
610 connect(okbtn,SIGNAL(clicked()), &dlg, SLOT(accept()));
612 cbtn = new QPushButton(&dlg, "PushButton_2");
613 cbtn->setGeometry(260, 50, 100, 30);
614 cbtn->setText("Close");
615 connect(cbtn, SIGNAL(clicked()), &dlg, SLOT(reject()));
619 e->getCursorPosition(&pom, &res);
620 sensitive = tmpQRadioButton->isChecked();
621 for (line = pom + 1; line < e->numLines(); line++) {
622 txt = new QString(e->textLine(line));
623 if (tmpQRadioButton->isChecked())
624 res = txt->find(tmpQLineEdit->text(), 0, TRUE);
626 res = txt->find(tmpQLineEdit->text(), 0, FALSE);
630 e->setCursorPosition(line, 1);
631 strcpy(find_text, tmpQLineEdit->text());
639 * Searches for next occurence of given text in editor content.
640 * Displays window to set search parameters. If text is found sets cursor
643 void Editor::find_next()
648 e->getCursorPosition(&pom, &res);
649 for(line = pom + 1; line < e->numLines(); line++) {
650 txt = new QString(e->textLine(line));
652 res=txt->find(find_text, 0, TRUE);
654 res=txt->find(find_text, 0, FALSE);
658 e->setCursorPosition(line, 1);
665 * Program main function.
666 * argv[1] is mandatory and should be a path to the home directory of
667 * application (same as in configuration file).
668 * @param argc Number of program arguments
669 * @param argv Program arguments
671 int main(int argc, char **argv)
673 QApplication app(argc, argv);
674 //app.setStyle(WindowsStyle);
675 editor = new Editor(argv[1]);
676 app.setMainWidget(editor);
677 editor->resize(600, 400);