31 char *UnitTypes[5] = {"CLASS","PROCEDURE","FUNCTION","PROCESS","COROUTINE"};
34 My_Edit::My_Edit(QWidget *parent, const char *name)
35 : QMultiLineEdit(parent, name)
41 void My_Edit::keyPressEvent(QKeyEvent *ev)
43 QMultiLineEdit::keyPressEvent(ev);
48 void Editor::closeEvent ( QCloseEvent * e ) {
52 Editor::Editor( char *hdir,QWidget * parent , const char * name)
53 : QWidget( parent, name )
55 QFont f1("Helvetica", 10, QFont::Bold);
57 strcpy(HomeDir, hdir);
58 strcpy(find_text, "");
60 m = new QMenuBar(this, "menu");
62 QPopupMenu * file = new QPopupMenu();
63 QPopupMenu * comp = new QPopupMenu();
64 QPopupMenu * loglan = new QPopupMenu();
65 QPopupMenu *medit = new QPopupMenu();
73 m->insertItem("&File ", file);
74 m->insertItem("&Edit", medit);
75 m->insertItem("&Compile", this,SLOT(cmp()));
77 /* m->insertItem( "&LOGLAN ", loglan );*/
78 m->insertItem("&Properties", this, SLOT(props()));
80 file->insertItem("New ", this, SLOT(create()), CTRL + Key_N);
81 file->insertItem("Open ", this, SLOT(load()), CTRL + Key_O);
82 file->insertItem("Save ", this, SLOT(save()),CTRL + Key_S);
83 file->insertItem("Save as", this, SLOT(save_as()),CTRL + Key_A);
84 file->insertSeparator();
85 file->insertItem("Quit ", qApp, SLOT(quit()));
87 /* comp->insertItem("Compile ", this, SLOT(cmp()), CTRL + Key_C);*/
88 /* comp->insertItem("Gen ", this, SLOT(gen()), CTRL + Key_G);*/
89 /* comp->insertItem("Compile & Gen ", this, SLOT(comp_all()));*/
91 /* loglan->insertItem( "Program structure", this, SLOT(log_prog()));*/
92 /* loglan->insertItem( "Unit structure", this, SLOT(log_unit()));*/
94 e = new My_Edit( this, "editor" );
95 connect(e,SIGNAL(cursorMove()),this,SLOT(updateline()));
96 medit->insertItem("Copy ",e,SLOT(copy()),CTRL + Key_Insert);
97 medit->insertItem("Paste ",e,SLOT(paste()), SHIFT + Key_Insert);
98 medit->insertItem("Cut ",e,SLOT(cut()), CTRL + Key_Delete);
99 medit->insertItem("Clear All ",e,SLOT(clear()));
100 medit->insertSeparator();
101 medit->insertItem("Find ",this,SLOT(findText()), CTRL + Key_F);
102 medit->insertItem("Find Next ",this,SLOT(find_next()),CTRL + Key_L);
104 msg = new QMultiLineEdit( this, "messages" );
105 msg->setReadOnly(TRUE);
106 compiler_path.sprintf("%s/%s",HomeDir,"compile/logcomp");
107 gen_path.sprintf("%s/%s",HomeDir,"compile/gen");
108 file_path.sprintf("%s",HomeDir);
110 QFont f2("Times", 14, QFont::Bold);
112 QColor col(200, 200, 200);
113 QColorGroup grp(black, col, col.light(), col.dark(), col.dark(), black, col);
115 msg->setPalette(QPalette(grp, grp, grp));
116 position = new QLabel(this);
117 position->setFont(f2);
118 position->setFrameStyle(QFrame::NoFrame);
119 position->setAutoResize(TRUE);
127 void Editor::updateline()
133 e->getCursorPosition(&cx, &cy);
134 sprintf(pom," %d:%d ", cx, cy);
135 position->setText(pom);
138 void Editor::resizeEvent(QResizeEvent *)
141 e->setGeometry(0, m->height(), width(),
142 3 * (int)((height() - m->height()) / 4));
144 msg->setGeometry(0, m->height() + e->height(), width(),
145 (int)((height() - m->height()) / 4));
147 position->setGeometry(width() - 80,
148 m->height() + e->height() - 10,
157 QString fn = QFileDialog::getOpenFileName(file_path.data(), "*.log");
163 void Editor::load(const char *fileName)
165 fname.sprintf("%s", fileName);
168 if (!f.open(IO_ReadOnly))
171 e->setAutoUpdate(FALSE);
176 QString s = t.readLine();
181 e->setAutoUpdate(TRUE);
183 setCaption(fileName);
189 if (fname.isEmpty()) {
190 QString fn = QFileDialog::getSaveFileName(file_path.data(),
193 fname.sprintf("%s",fn.data());
202 void Editor::save_as()
204 QString fn = QFileDialog::getSaveFileName(file_path.data(), "*.log");
206 fname.sprintf("%s", fn.data());
212 void Editor::save(const char *fileName)
215 if (!f.open(IO_WriteOnly))
218 f.writeBlock(e->text().data(), e->text().length());
223 void Editor::create()
226 fname.sprintf("%s", "");
244 void Editor::comp_all()
250 void Editor::compile(int mode)
254 msg->setAutoUpdate(FALSE);
255 msg->setReadOnly(FALSE);
259 /*i = fname.find('.');*/
262 QString fn = fname.data();
266 sprintf(cmd, "%s %s > comp_data!", compiler_path.data(),
270 sprintf(cmd, "%s %s > comp_data!", gen_path.data(), fn.data());
273 sprintf(cmd, "%s %s > comp_data!", compiler_path.data(),
276 sprintf(cmd, "%s %s >> comp_data!", gen_path.data(), fn.data());
281 QFile f("comp_data!");
282 if (!f.open(IO_ReadOnly))
287 QString s = t.readLine();
291 msg->setReadOnly(TRUE);
292 msg->setAutoUpdate(TRUE);
294 unlink("comp_data!");
300 QDialog dlg(this, "Properties", TRUE);
303 files = new QLineEdit(&dlg, "f_path");
304 files->setGeometry(130, 20, 250, 30);
305 files->setText(file_path.data());
306 files->setMaxLength(32767);
307 files->setEchoMode(QLineEdit::Normal);
308 files->setFrame(TRUE);
311 tmpQLabel = new QLabel(&dlg, "Label_1");
312 tmpQLabel->setGeometry(10, 20, 100, 30);
313 tmpQLabel->setText("Path to files:");
314 tmpQLabel->setAlignment(289);
315 tmpQLabel->setMargin(-1);
317 tmpQLabel = new QLabel(&dlg, "Label_2");
318 tmpQLabel->setGeometry(10, 60, 100, 30);
319 tmpQLabel->setText("Path to compiler:");
320 tmpQLabel->setAlignment(289);
321 tmpQLabel->setMargin(-1);
324 tmpQLabel = new QLabel(&dlg, "Label_3");
325 tmpQLabel->setGeometry(10, 100, 100, 30);
326 tmpQLabel->setText("Path to gen:");
327 tmpQLabel->setAlignment(289);
328 tmpQLabel->setMargin(-1);
332 compp = new QLineEdit(&dlg, "l_path");
333 compp->setGeometry(130, 60, 250, 30);
334 compp->setText(compiler_path.data());
335 compp->setMaxLength(32767);
336 compp->setEchoMode(QLineEdit::Normal);
337 compp->setFrame(TRUE);
341 genp = new QLineEdit(&dlg, "g_path");
342 genp->setGeometry(130, 100, 250, 30);
343 genp->setText(gen_path.data());
344 genp->setMaxLength(32767);
345 genp->setEchoMode(QLineEdit::Normal);
346 genp->setFrame(TRUE);
349 QPushButton* tmpQPushButton;
350 tmpQPushButton = new QPushButton(&dlg, "OkBtn");
351 tmpQPushButton->setGeometry(90, 100, 70, 30);
352 tmpQPushButton->setText("Ok");
353 tmpQPushButton->setAutoRepeat(FALSE);
354 tmpQPushButton->setAutoResize(FALSE);
355 connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(accept()));
357 tmpQPushButton = new QPushButton(&dlg, "CancelBtn");
358 tmpQPushButton->setGeometry(180, 100, 70, 30);
359 tmpQPushButton->setText("Cancel");
360 tmpQPushButton->setAutoRepeat(FALSE);
361 tmpQPushButton->setAutoResize(FALSE);
362 connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(reject()));
363 dlg.resize(400, 140);
366 compiler_path.sprintf("%s", compp->text().ascii());
367 /* gen_path.sprintf("%s",genp->text()); */
368 file_path.sprintf("%s",files->text().ascii());
372 /* --------------------------------------- */
374 void Editor::log_unit()
377 QDialog dlg(this, "unit", TRUE);
382 files = new QLineEdit(&dlg, "f_path");
383 files->setGeometry(130, 20, 250, 30);
385 files->setMaxLength(32767);
386 files->setEchoMode(QLineEdit::Normal);
387 files->setFrame(TRUE);
390 tmpQLabel = new QLabel(&dlg, "Label_1");
391 tmpQLabel->setGeometry(10, 20, 100, 30);
392 tmpQLabel->setText("Unit name:");
393 tmpQLabel->setAlignment(289);
394 tmpQLabel->setMargin(-1);
396 QPushButton* tmpQPushButton;
397 tmpQPushButton = new QPushButton(&dlg, "OkBtn");
398 tmpQPushButton->setGeometry(40, 170, 70, 30);
399 tmpQPushButton->setText("Ok");
400 tmpQPushButton->setAutoRepeat(FALSE);
401 tmpQPushButton->setAutoResize(FALSE);
402 connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(accept()));
404 tmpQPushButton = new QPushButton(&dlg, "CancelBtn");
405 tmpQPushButton->setGeometry(130, 170, 100, 30);
406 tmpQPushButton->setText("Cancel");
407 tmpQPushButton->setAutoRepeat(FALSE);
408 tmpQPushButton->setAutoResize(FALSE);
409 connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(reject()));
411 tmpQLabel = new QLabel(&dlg, "Label_1");
412 tmpQLabel->setGeometry(10, 50, 100, 60);
413 tmpQLabel->setText("Unit type:");
415 QListBox lst(&dlg, "type");
416 for(i=0; i < TYPENUM; i++) {
417 lst.insertItem(UnitTypes[i]);
419 lst.setGeometry(130, 60, 180, 80);
420 lst.setCurrentItem(0);
423 strcpy(uname, files->text());
424 e->getCursorPosition(&cx, &cy);
426 txt.sprintf("UNIT %s : %s( <params> );\nBEGIN\n\nEND %s;",
427 uname, lst.text(lst.currentItem()).ascii(), uname);
428 e->insertAt(txt, cx, cy);
433 void Editor::log_prog()
436 QDialog dlg(this, "unit", TRUE);
441 files = new QLineEdit(&dlg, "f_path");
442 files->setGeometry(130, 20, 250, 30);
444 files->setMaxLength(32767);
445 files->setEchoMode(QLineEdit::Normal);
446 files->setFrame(TRUE);
449 tmpQLabel = new QLabel(&dlg, "Label_1");
450 tmpQLabel->setGeometry(10, 20, 100, 30);
451 tmpQLabel->setText("Program name:");
453 QPushButton* tmpQPushButton;
454 tmpQPushButton = new QPushButton(&dlg, "OkBtn");
455 tmpQPushButton->setGeometry(40, 70, 70, 30);
456 tmpQPushButton->setText("Ok");
457 tmpQPushButton->setAutoRepeat(FALSE);
458 tmpQPushButton->setAutoResize(FALSE);
459 connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(accept()));
461 tmpQPushButton = new QPushButton(&dlg, "CancelBtn");
462 tmpQPushButton->setGeometry(130, 70, 100, 30);
463 tmpQPushButton->setText("Cancel");
464 tmpQPushButton->setAutoRepeat(FALSE);
465 tmpQPushButton->setAutoResize(FALSE);
466 connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(reject()));
469 strcpy(uname, files->text());
470 e->getCursorPosition(&cx, &cy);
472 txt.sprintf("PROGRAM %s\n\nBEGIN\n\nEND ", uname);
473 e->insertAt(txt, cx, cy);
478 void Editor::findText()
480 QDialog dlg(this, "", TRUE);
484 QLineEdit *tmpQLineEdit;
485 tmpQLineEdit = new QLineEdit(&dlg, "LineEdit_1");
486 tmpQLineEdit->setGeometry(60, 10, 180, 30);
487 tmpQLineEdit->setText("");
490 tmpQLabel = new QLabel(&dlg, "Label_1");
491 tmpQLabel->setGeometry(10, 10, 50, 30);
493 QFont font("helvetica", 12, 75, 0);
494 font.setStyleHint((QFont::StyleHint)0);
495 //font.setCharSet((QFont::CharSet)0);
496 tmpQLabel->setFont(font);
498 tmpQLabel->setText("Text:");
500 QCheckBox *tmpQRadioButton;
501 tmpQRadioButton = new QCheckBox(&dlg, "RadioButton_1");
502 tmpQRadioButton->setGeometry(70, 50, 150, 30);
503 tmpQRadioButton->setText("Case sensitive");
504 tmpQRadioButton->setAutoRepeat(FALSE);
505 tmpQRadioButton->setAutoResize(FALSE);
507 QPushButton *okbtn, *cbtn;
508 okbtn = new QPushButton(&dlg, "PushButton_1");
509 okbtn->setGeometry(260, 10, 100, 30);
510 okbtn->setText("Find");
511 okbtn->setDefault(TRUE);
512 connect(okbtn,SIGNAL(clicked()), &dlg, SLOT(accept()));
514 cbtn = new QPushButton(&dlg, "PushButton_2");
515 cbtn->setGeometry(260, 50, 100, 30);
516 cbtn->setText("Close");
517 connect(cbtn, SIGNAL(clicked()), &dlg, SLOT(reject()));
521 e->getCursorPosition(&pom, &res);
522 sensitive = tmpQRadioButton->isChecked();
523 for (line = pom + 1; line < e->numLines(); line++) {
524 txt = new QString(e->textLine(line));
525 if (tmpQRadioButton->isChecked())
526 res = txt->find(tmpQLineEdit->text(), 0, TRUE);
528 res = txt->find(tmpQLineEdit->text(), 0, FALSE);
532 e->setCursorPosition(line, 1);
533 strcpy(find_text, tmpQLineEdit->text());
540 void Editor::find_next()
545 e->getCursorPosition(&pom,&res);
546 for(line = pom + 1; line < e->numLines(); line++) {
547 txt = new QString(e->textLine(line));
549 res=txt->find(find_text,0,TRUE);
551 res=txt->find(find_text,0,FALSE);
555 e->setCursorPosition(line,1);
561 int main(int argc, char **argv)
563 QApplication a(argc, argv);
564 //a.setStyle(WindowsStyle);
565 e = new Editor(argv[1]);