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 * @copydoc QWidget::closeEvent(QCloseEvent*)
69 void Editor::closeEvent(QCloseEvent * e) {
74 * Editor constructor. Initializes and sets variables of Loglan Editor.
75 * @param hdir Home directory of program (specified in configuration file)
76 * @param parent Parent widget of this widget. If set, this widget becomes a
77 * child window inside parent. If not set this widget becomes a
78 * top level window. Default: NULL
79 * @param name If set, name is sent to the Qobject constructor, so widget is
80 * identifiable (e.g. in Qt Designer)
82 Editor::Editor(char *hdir,QWidget * parent , const char * name)
83 : QWidget(parent, name)
85 QFont f1("Helvetica", 10, QFont::Bold);
87 strcpy(HomeDir, hdir);
88 strcpy(find_text, "");
90 m = new QMenuBar(this, "menu");
92 QPopupMenu * file = new QPopupMenu();
93 QPopupMenu * comp = new QPopupMenu();
94 QPopupMenu * loglan = new QPopupMenu();
95 QPopupMenu *medit = new QPopupMenu();
103 m->insertItem("&File ", file);
104 m->insertItem("&Edit", medit);
105 m->insertItem("&Compile", this,SLOT(cmp()));
107 /* m->insertItem( "&LOGLAN ", loglan );*/
108 m->insertItem("&Properties", this, SLOT(props()));
110 file->insertItem("New ", this, SLOT(create()), CTRL + Key_N);
111 file->insertItem("Open ", this, SLOT(load()), CTRL + Key_O);
112 file->insertItem("Save ", this, SLOT(save()),CTRL + Key_S);
113 file->insertItem("Save as", this, SLOT(save_as()),CTRL + Key_A);
114 file->insertSeparator();
115 file->insertItem("Quit ", qApp, SLOT(quit()));
117 /* comp->insertItem("Compile ", this, SLOT(cmp()), CTRL + Key_C);*/
118 /* comp->insertItem("Gen ", this, SLOT(gen()), CTRL + Key_G);*/
119 /* comp->insertItem("Compile & Gen ", this, SLOT(comp_all()));*/
121 /* loglan->insertItem( "Program structure", this, SLOT(log_prog()));*/
122 /* loglan->insertItem( "Unit structure", this, SLOT(log_unit()));*/
124 e = new My_Edit( this, "editor" );
125 connect(e,SIGNAL(cursorMove()),this,SLOT(updateline()));
126 medit->insertItem("Copy ",e,SLOT(copy()),CTRL + Key_Insert);
127 medit->insertItem("Paste ",e,SLOT(paste()), SHIFT + Key_Insert);
128 medit->insertItem("Cut ",e,SLOT(cut()), CTRL + Key_Delete);
129 medit->insertItem("Clear All ",e,SLOT(clear()));
130 medit->insertSeparator();
131 medit->insertItem("Find ",this,SLOT(findText()), CTRL + Key_F);
132 medit->insertItem("Find Next ",this,SLOT(find_next()),CTRL + Key_L);
134 msg = new QMultiLineEdit( this, "messages" );
135 msg->setReadOnly(TRUE);
136 compiler_path.sprintf("%s/%s",HomeDir,"compile/logcomp");
137 gen_path.sprintf("%s/%s",HomeDir,"compile/gen");
138 file_path.sprintf("%s",HomeDir);
140 QFont f2("Times", 14, QFont::Bold);
142 QColor col(200, 200, 200);
143 QColorGroup grp(black, col, col.light(), col.dark(), col.dark(), black, col);
145 msg->setPalette(QPalette(grp, grp, grp));
146 position = new QLabel(this);
147 position->setFont(f2);
148 position->setFrameStyle(QFrame::NoFrame);
149 position->setAutoResize(TRUE);
161 * Displays line:column position of cursor
163 void Editor::updateline()
169 e->getCursorPosition(&cx, &cy);
170 sprintf(pom," %d:%d ", cx, cy);
171 position->setText(pom);
175 * Event invoked when resizing editor window.
176 * @copydoc QWidget::resizeEvent(QResizeEvent*)
177 * @param event Currently does nothing
179 void Editor::resizeEvent(QResizeEvent *event)
182 e->setGeometry(0, m->height(), width(),
183 3 * (int)((height() - m->height()) / 4));
185 msg->setGeometry(0, m->height() + e->height(), width(),
186 (int)((height() - m->height()) / 4));
188 position->setGeometry(width() - 80,
189 m->height() + e->height() - 10,
196 * Displays additional window
200 QString fn = QFileDialog::getOpenFileName(file_path.data(), "*.log");
206 * Loads given file content to the editor.
207 * @param fileName Filename of file which will be read.
209 void Editor::load(const char *fileName)
211 fname.sprintf("%s", fileName);
214 if (!f.open(IO_ReadOnly))
217 e->setAutoUpdate(FALSE);
222 QString s = t.readLine();
227 e->setAutoUpdate(TRUE);
229 setCaption(fileName);
233 * Saves editor content to the file.
234 * If content has been read from file, it is written to this file. Otherwise
235 * dialog is shown to save content to the specified by user, file.
239 if (fname.isEmpty()) {
240 QString fn = QFileDialog::getSaveFileName(file_path.data(),
243 fname.sprintf("%s",fn.data());
253 * Saves editor content to the file.
254 * Forces saving editor content to the new file. Special dialog is shown for
257 void Editor::save_as()
259 QString fn = QFileDialog::getSaveFileName(file_path.data(), "*.log");
261 fname.sprintf("%s", fn.data());
268 * Saves editor content to the given filename.
269 * @param fileName File name of the file where content should be saved.
271 void Editor::save(const char *fileName)
274 if (!f.open(IO_WriteOnly))
277 f.writeBlock(e->text().data(), e->text().length());
282 * Empties editor content.
284 void Editor::create()
287 fname.sprintf("%s", "");
291 * @attention Currently not in use
298 * @attention Currently not in use.
300 * Saves and compiles code.
309 * @attention Currently not in use.
319 * @attention Currently not in use.
321 * Saves, compiles and generates code.
323 void Editor::comp_all()
330 * Invokes compiler in the giving mode.
331 * @param mode Mode of compilation. Possible values:
332 * - COMP_MODE - compilation mode
333 * - GEN_MODE - program generation mode
334 * - ALL_MODE - compilation & generation mode.
336 void Editor::compile(int mode)
340 msg->setAutoUpdate(FALSE);
341 msg->setReadOnly(FALSE);
345 /*i = fname.find('.');*/
348 QString fn = fname.data();
353 sprintf(cmd, "%s %s > comp_data!", compiler_path.data(),
357 sprintf(cmd, "%s %s > comp_data!", gen_path.data(), fn.data());
360 sprintf(cmd, "%s %s > comp_data!", compiler_path.data(),
363 sprintf(cmd, "%s %s >> comp_data!", gen_path.data(), fn.data());
368 QFile f("comp_data!");
369 if (!f.open(IO_ReadOnly))
374 QString s = t.readLine();
378 msg->setReadOnly(TRUE);
379 msg->setAutoUpdate(TRUE);
381 unlink("comp_data!");
386 * Displays window with editor properties
390 QDialog dlg(this, "Properties", TRUE);
393 files = new QLineEdit(&dlg, "f_path");
394 files->setGeometry(130, 20, 250, 30);
395 files->setText(file_path.data());
396 files->setMaxLength(32767);
397 files->setEchoMode(QLineEdit::Normal);
398 files->setFrame(TRUE);
401 tmpQLabel = new QLabel(&dlg, "Label_1");
402 tmpQLabel->setGeometry(10, 20, 100, 30);
403 tmpQLabel->setText("Path to files:");
404 tmpQLabel->setAlignment(289);
405 tmpQLabel->setMargin(-1);
407 tmpQLabel = new QLabel(&dlg, "Label_2");
408 tmpQLabel->setGeometry(10, 60, 100, 30);
409 tmpQLabel->setText("Path to compiler:");
410 tmpQLabel->setAlignment(289);
411 tmpQLabel->setMargin(-1);
414 tmpQLabel = new QLabel(&dlg, "Label_3");
415 tmpQLabel->setGeometry(10, 100, 100, 30);
416 tmpQLabel->setText("Path to gen:");
417 tmpQLabel->setAlignment(289);
418 tmpQLabel->setMargin(-1);
422 compp = new QLineEdit(&dlg, "l_path");
423 compp->setGeometry(130, 60, 250, 30);
424 compp->setText(compiler_path.data());
425 compp->setMaxLength(32767);
426 compp->setEchoMode(QLineEdit::Normal);
427 compp->setFrame(TRUE);
431 genp = new QLineEdit(&dlg, "g_path");
432 genp->setGeometry(130, 100, 250, 30);
433 genp->setText(gen_path.data());
434 genp->setMaxLength(32767);
435 genp->setEchoMode(QLineEdit::Normal);
436 genp->setFrame(TRUE);
439 QPushButton* tmpQPushButton;
440 tmpQPushButton = new QPushButton(&dlg, "OkBtn");
441 tmpQPushButton->setGeometry(90, 100, 70, 30);
442 tmpQPushButton->setText("Ok");
443 tmpQPushButton->setAutoRepeat(FALSE);
444 tmpQPushButton->setAutoResize(FALSE);
445 connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(accept()));
447 tmpQPushButton = new QPushButton(&dlg, "CancelBtn");
448 tmpQPushButton->setGeometry(180, 100, 70, 30);
449 tmpQPushButton->setText("Cancel");
450 tmpQPushButton->setAutoRepeat(FALSE);
451 tmpQPushButton->setAutoResize(FALSE);
452 connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(reject()));
453 dlg.resize(400, 140);
456 compiler_path.sprintf("%s", compp->text().ascii());
457 /* gen_path.sprintf("%s",genp->text()); */
458 file_path.sprintf("%s",files->text().ascii());
463 * @attention Currently not in use
465 void Editor::log_unit()
468 QDialog dlg(this, "unit", TRUE);
473 files = new QLineEdit(&dlg, "f_path");
474 files->setGeometry(130, 20, 250, 30);
476 files->setMaxLength(32767);
477 files->setEchoMode(QLineEdit::Normal);
478 files->setFrame(TRUE);
481 tmpQLabel = new QLabel(&dlg, "Label_1");
482 tmpQLabel->setGeometry(10, 20, 100, 30);
483 tmpQLabel->setText("Unit name:");
484 tmpQLabel->setAlignment(289);
485 tmpQLabel->setMargin(-1);
487 QPushButton* tmpQPushButton;
488 tmpQPushButton = new QPushButton(&dlg, "OkBtn");
489 tmpQPushButton->setGeometry(40, 170, 70, 30);
490 tmpQPushButton->setText("Ok");
491 tmpQPushButton->setAutoRepeat(FALSE);
492 tmpQPushButton->setAutoResize(FALSE);
493 connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(accept()));
495 tmpQPushButton = new QPushButton(&dlg, "CancelBtn");
496 tmpQPushButton->setGeometry(130, 170, 100, 30);
497 tmpQPushButton->setText("Cancel");
498 tmpQPushButton->setAutoRepeat(FALSE);
499 tmpQPushButton->setAutoResize(FALSE);
500 connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(reject()));
502 tmpQLabel = new QLabel(&dlg, "Label_1");
503 tmpQLabel->setGeometry(10, 50, 100, 60);
504 tmpQLabel->setText("Unit type:");
506 QListBox lst(&dlg, "type");
507 for(i = 0; i < TYPENUM; i++) {
508 lst.insertItem(UnitTypes[i]);
510 lst.setGeometry(130, 60, 180, 80);
511 lst.setCurrentItem(0);
514 strcpy(uname, files->text());
515 e->getCursorPosition(&cx, &cy);
517 txt.sprintf("UNIT %s : %s( <params> );\nBEGIN\n\nEND %s;",
518 uname, lst.text(lst.currentItem()).ascii(), uname);
519 e->insertAt(txt, cx, cy);
524 * @attention Currently not in use
526 void Editor::log_prog()
529 QDialog dlg(this, "unit", TRUE);
534 files = new QLineEdit(&dlg, "f_path");
535 files->setGeometry(130, 20, 250, 30);
537 files->setMaxLength(32767);
538 files->setEchoMode(QLineEdit::Normal);
539 files->setFrame(TRUE);
542 tmpQLabel = new QLabel(&dlg, "Label_1");
543 tmpQLabel->setGeometry(10, 20, 100, 30);
544 tmpQLabel->setText("Program name:");
546 QPushButton* tmpQPushButton;
547 tmpQPushButton = new QPushButton(&dlg, "OkBtn");
548 tmpQPushButton->setGeometry(40, 70, 70, 30);
549 tmpQPushButton->setText("Ok");
550 tmpQPushButton->setAutoRepeat(FALSE);
551 tmpQPushButton->setAutoResize(FALSE);
552 connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(accept()));
554 tmpQPushButton = new QPushButton(&dlg, "CancelBtn");
555 tmpQPushButton->setGeometry(130, 70, 100, 30);
556 tmpQPushButton->setText("Cancel");
557 tmpQPushButton->setAutoRepeat(FALSE);
558 tmpQPushButton->setAutoResize(FALSE);
559 connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(reject()));
562 strcpy(uname, files->text());
563 e->getCursorPosition(&cx, &cy);
565 txt.sprintf("PROGRAM %s\n\nBEGIN\n\nEND ", uname);
566 e->insertAt(txt, cx, cy);
571 * Searches for given text in editor content.
572 * Displays window to set search parameters. If text is found sets cursor
575 void Editor::findText()
577 QDialog dlg(this, "", TRUE);
581 QLineEdit *tmpQLineEdit;
582 tmpQLineEdit = new QLineEdit(&dlg, "LineEdit_1");
583 tmpQLineEdit->setGeometry(60, 10, 180, 30);
584 tmpQLineEdit->setText("");
587 tmpQLabel = new QLabel(&dlg, "Label_1");
588 tmpQLabel->setGeometry(10, 10, 50, 30);
590 QFont font("helvetica", 12, 75, 0);
591 font.setStyleHint((QFont::StyleHint)0);
592 //font.setCharSet((QFont::CharSet)0);
593 tmpQLabel->setFont(font);
595 tmpQLabel->setText("Text:");
597 QCheckBox *tmpQRadioButton;
598 tmpQRadioButton = new QCheckBox(&dlg, "RadioButton_1");
599 tmpQRadioButton->setGeometry(70, 50, 150, 30);
600 tmpQRadioButton->setText("Case sensitive");
601 tmpQRadioButton->setAutoRepeat(FALSE);
602 tmpQRadioButton->setAutoResize(FALSE);
604 QPushButton *okbtn, *cbtn;
605 okbtn = new QPushButton(&dlg, "PushButton_1");
606 okbtn->setGeometry(260, 10, 100, 30);
607 okbtn->setText("Find");
608 okbtn->setDefault(TRUE);
609 connect(okbtn,SIGNAL(clicked()), &dlg, SLOT(accept()));
611 cbtn = new QPushButton(&dlg, "PushButton_2");
612 cbtn->setGeometry(260, 50, 100, 30);
613 cbtn->setText("Close");
614 connect(cbtn, SIGNAL(clicked()), &dlg, SLOT(reject()));
618 e->getCursorPosition(&pom, &res);
619 sensitive = tmpQRadioButton->isChecked();
620 for (line = pom + 1; line < e->numLines(); line++) {
621 txt = new QString(e->textLine(line));
622 if (tmpQRadioButton->isChecked())
623 res = txt->find(tmpQLineEdit->text(), 0, TRUE);
625 res = txt->find(tmpQLineEdit->text(), 0, FALSE);
629 e->setCursorPosition(line, 1);
630 strcpy(find_text, tmpQLineEdit->text());
638 * Searches for next occurence of given text in editor content.
639 * Displays window to set search parameters. If text is found sets cursor
642 void Editor::find_next()
647 e->getCursorPosition(&pom, &res);
648 for(line = pom + 1; line < e->numLines(); line++) {
649 txt = new QString(e->textLine(line));
651 res=txt->find(find_text, 0, TRUE);
653 res=txt->find(find_text, 0, FALSE);
657 e->setCursorPosition(line, 1);
664 * Program main function.
665 * argv[1] is mandatory and should be a path to the home directory of
666 * application (same as in configuration file).
667 * @param argc Number of program arguments
668 * @param argv Program arguments
670 int main(int argc, char **argv)
672 QApplication a(argc, argv);
673 //a.setStyle(WindowsStyle);
675 Defaults are zeroed, so created Editor widget become top-level window.
677 e = new Editor(argv[1]);