2 #include <QtCore/QTextStream>
3 #include <QtGui/QApplication>
4 #include <QtGui/QMenuBar>
5 #include <QtGui/QFileDialog>
6 #include <QtGui/QColor>
7 #include <QtGui/QPalette>
8 #include <QtGui/QCloseEvent>
9 #include <QtGui/QTextDocument>
10 #include <QtGui/QMainWindow>
11 #include <QtGui/QStatusBar>
12 #include <QtGui/QCheckBox>
13 #include <QtGui/QVBoxLayout>
17 #include "editor-properties.h"
22 * @attention Currently not in use
24 char *UnitTypes[TYPENUM] = {
33 * My_Edit constructor. Initializes and sets variables of Multiline editor
35 * @param parent Parent widget of this widget. If set, this widget becomes a
36 * child window inside parent. If not set this widget becomes a
37 * top level window. Default: NULL
39 My_Edit::My_Edit(QWidget *parent = NULL)
45 * @copydoc QWidget::keyPressEvent(QKeyEvent*)
47 void My_Edit::keyPressEvent(QKeyEvent *ev)
49 QTextEdit::keyPressEvent(ev);
54 * Event invoked on program close.
55 * @copydoc QWidget::closeEvent(QCloseEvent*)
57 void Editor::closeEvent(QCloseEvent * e) {
62 * Editor constructor. Initializes and sets variables of Loglan Editor.
63 * @param hdir Home directory of program (specified in configuration file)
64 * @param parent Parent widget of this widget. If set, this widget becomes a
65 * child window inside parent. If not set this widget becomes a
66 * top level window. Default: NULL
68 Editor::Editor(char *hdir, QWidget * parent)
73 strcpy(HomeDir, hdir);
77 /* m->insertItem( "&LOGLAN ", loglan );*/
79 connect(actionQuit, SIGNAL(triggered()), this, SLOT(close()));
81 /* comp->insertItem("Compile ", this, SLOT(cmp()), CTRL + Key_C);*/
82 /* comp->insertItem("Gen ", this, SLOT(gen()), CTRL + Key_G);*/
83 /* comp->insertItem("Compile & Gen ", this, SLOT(comp_all()));*/
85 /* loglan->insertItem( "Program structure", this, SLOT(log_prog()));*/
86 /* loglan->insertItem( "Unit structure", this, SLOT(log_unit()));*/
88 connect(e, SIGNAL(cursorMove()), this, SLOT(updateline()));
89 connect(actionUndo, SIGNAL(triggered()), e, SLOT(undo()));
90 connect(actionRedo, SIGNAL(triggered()), e, SLOT(redo()));
91 connect(actionCopy, SIGNAL(triggered()), e, SLOT(copy()));
92 connect(actionPaste, SIGNAL(triggered()), e, SLOT(paste()));
93 connect(actionCut, SIGNAL(triggered()), e, SLOT(cut()));
94 connect(actionClear_all, SIGNAL(triggered()), e, SLOT(clear()));
96 compiler_path.sprintf("%s/%s", HomeDir, "compile/logcomp");
97 gen_path.sprintf("%s/%s", HomeDir, "compile/gen");
98 file_path.sprintf("%s", HomeDir);
100 position = new QLabel();
101 statusBar()->addPermanentWidget(position);
112 * Displays line:column position of cursor
114 void Editor::updateline()
120 cx = e->textCursor().blockNumber();
121 cy = e->textCursor().columnNumber();
122 sprintf(pom,"%d:%d ", cx, cy);
123 position->setText(pom);
127 * Displays additional window
129 void Editor::on_actionOpen_triggered()
131 QString fn = QFileDialog::getOpenFileName(this, "Load file", file_path, "*.log");
133 load(fn.toAscii().data());
137 * Loads given file content to the editor.
138 * @param fileName Filename of file which will be read.
140 void Editor::load(const char *fileName)
142 fname.sprintf("%s", fileName);
145 if (!f.open(QIODevice::ReadOnly | QIODevice::Text))
148 /*TODO: Does not exists in Qt4. Use layout and set the size policy (https://qt-project.org/forums/viewthread/2112)
149 e->setAutoUpdate(FALSE);
155 QString s = t.readLine();
160 /*TODO: Does not exists in Qt4. Use layout and set the size policy (https://qt-project.org/forums/viewthread/2112)
161 e->setAutoUpdate(TRUE);
164 setWindowTitle(fileName);
168 * Saves editor content to the file.
169 * If content has been read from file, it is written to this file. Otherwise
170 * dialog is shown to save content to the specified by user, file.
172 void Editor::on_actionSave_triggered()
174 if (fname.isEmpty()) {
175 QString fn = QFileDialog::getSaveFileName(this, "Save file",
178 fname.sprintf("%s", fn.toAscii().data());
179 save(fn.toAscii().data());
182 save(fname.toAscii().data());
184 setWindowTitle(fname);
188 * Saves editor content to the file.
189 * Forces saving editor content to the new file. Special dialog is shown for
192 void Editor::on_actionSave_as_triggered()
194 QString fn = QFileDialog::getSaveFileName(this, "Save file as",
197 fname.sprintf("%s", fn.toAscii().data());
198 save(fn.toAscii().data());
200 setWindowTitle(fname);
204 * Saves editor content to the given filename.
205 * @param fileName File name of the file where content should be saved.
207 void Editor::save(const char *fileName)
210 if (!f.open(QIODevice::WriteOnly | QIODevice::Text))
213 f.write(e->toPlainText().toAscii().data(), e->toPlainText().length());
218 * Empties editor content.
220 void Editor::on_actionNew_triggered()
223 fname.sprintf("%s", "");
227 * @attention Currently not in use
229 //void Editor::print()
234 * @attention Currently not in use.
236 * Saves and compiles code.
238 void Editor::on_actionCompile_triggered()
240 on_actionSave_triggered();
245 * @attention Currently not in use.
255 * @attention Currently not in use.
257 * Saves, compiles and generates code.
259 void Editor::comp_all()
261 on_actionSave_triggered();
266 * Invokes compiler in the giving mode.
267 * @param mode Mode of compilation. Possible values:
268 * - COMP_MODE - compilation mode
269 * - GEN_MODE - program generation mode
270 * - ALL_MODE - compilation & generation mode.
272 void Editor::compile(int mode)
275 /*TODO: Does not exists in Qt4. Use layout and set the size policy (https://qt-project.org/forums/viewthread/2112)
276 msg->setAutoUpdate(FALSE);
278 msg->setReadOnly(FALSE);
282 /*i = fname.find('.');*/
288 sprintf(cmd, "%s %s > comp_data!", compiler_path.toAscii().data(),
289 fname.toAscii().data());
292 sprintf(cmd, "%s %s > comp_data!", gen_path.toAscii().data(),
293 fname.toAscii().data());
296 sprintf(cmd, "%s %s > comp_data!", compiler_path.toAscii().data(),
297 fname.toAscii().data());
299 sprintf(cmd, "%s %s >> comp_data!", gen_path.toAscii().data(),
300 fname.toAscii().data());
305 QFile f("comp_data!");
306 if (!f.open(QIODevice::ReadOnly | QIODevice::Text))
311 QString s = t.readLine();
316 msg->setReadOnly(TRUE);
318 /*TODO: Does not exists in Qt4. Use layout and set the size policy (https://qt-project.org/forums/viewthread/2112)
319 msg->setAutoUpdate(TRUE);
322 unlink("comp_data!");
327 * Displays window with editor properties
329 void Editor::on_actionProperties_triggered()
331 EditorProperties *dlg = new EditorProperties(this, Qt::Dialog);
333 dlg->setDefaultCompilerPath(compiler_path);
334 dlg->setDefaultFilesPath(file_path);
336 tmpQLabel = new QLabel(&dlg, "Label_3");
337 tmpQLabel->setGeometry(10, 100, 100, 30);
338 tmpQLabel->setText("Path to gen:");
339 tmpQLabel->setAlignment(289);
340 tmpQLabel->setMargin(-1);
345 genp = new QLineEdit(&dlg, "g_path");
346 genp->setGeometry(130, 100, 250, 30);
347 genp->setText(gen_path.data());
348 genp->setMaxLength(32767);
349 genp->setEchoMode(QLineEdit::Normal);
350 genp->setFrame(TRUE);
354 compiler_path.sprintf("%s", dlg->getCompilerPath().toAscii().data());
355 /* gen_path.sprintf("%s",genp->text()); */
356 file_path.sprintf("%s", dlg->getFilesPath().toAscii().data());
361 * @attention Currently not in use
363 void Editor::log_unit()
366 Code commented during Qt4 migration.
367 Code is not used, so there is no rush with this...
371 QDialog dlg(this, Qt::Dialog);
376 files = new QLineEdit(&dlg, "f_path");
377 files->setGeometry(130, 20, 250, 30);
379 files->setMaxLength(32767);
380 files->setEchoMode(QLineEdit::Normal);
381 files->setFrame(TRUE);
384 tmpQLabel = new QLabel(&dlg, "Label_1");
385 tmpQLabel->setGeometry(10, 20, 100, 30);
386 tmpQLabel->setText("Unit name:");
387 tmpQLabel->setAlignment(289);
388 tmpQLabel->setMargin(-1);
390 QPushButton* tmpQPushButton;
391 tmpQPushButton = new QPushButton(&dlg, "OkBtn");
392 tmpQPushButton->setGeometry(40, 170, 70, 30);
393 tmpQPushButton->setText("Ok");
394 tmpQPushButton->setAutoRepeat(FALSE);
395 tmpQPushButton->setAutoResize(FALSE);
396 connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(accept()));
398 tmpQPushButton = new QPushButton(&dlg, "CancelBtn");
399 tmpQPushButton->setGeometry(130, 170, 100, 30);
400 tmpQPushButton->setText("Cancel");
401 tmpQPushButton->setAutoRepeat(FALSE);
402 tmpQPushButton->setAutoResize(FALSE);
403 connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(reject()));
405 tmpQLabel = new QLabel(&dlg, "Label_1");
406 tmpQLabel->setGeometry(10, 50, 100, 60);
407 tmpQLabel->setText("Unit type:");
409 QListBox lst(&dlg, "type");
410 for(i = 0; i < TYPENUM; i++) {
411 lst.insertItem(UnitTypes[i]);
413 lst.setGeometry(130, 60, 180, 80);
414 lst.setCurrentItem(0);
417 strcpy(uname, files->text());
418 e->getCursorPosition(&cx, &cy);
420 txt.sprintf("UNIT %s : %s( <params> );\nBEGIN\n\nEND %s;",
421 uname, lst.text(lst.currentItem()).ascii(), uname);
422 e->insertAt(txt, cx, cy);
428 * @attention Currently not in use
430 void Editor::log_prog()
433 Code commented during Qt4 migration.
434 Code is not used, so there is no rush with this...
438 QDialog dlg(this, "unit", TRUE);
443 files = new QLineEdit(&dlg, "f_path");
444 files->setGeometry(130, 20, 250, 30);
446 files->setMaxLength(32767);
447 files->setEchoMode(QLineEdit::Normal);
448 files->setFrame(TRUE);
451 tmpQLabel = new QLabel(&dlg, "Label_1");
452 tmpQLabel->setGeometry(10, 20, 100, 30);
453 tmpQLabel->setText("Program name:");
455 QPushButton* tmpQPushButton;
456 tmpQPushButton = new QPushButton(&dlg, "OkBtn");
457 tmpQPushButton->setGeometry(40, 70, 70, 30);
458 tmpQPushButton->setText("Ok");
459 tmpQPushButton->setAutoRepeat(FALSE);
460 tmpQPushButton->setAutoResize(FALSE);
461 connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(accept()));
463 tmpQPushButton = new QPushButton(&dlg, "CancelBtn");
464 tmpQPushButton->setGeometry(130, 70, 100, 30);
465 tmpQPushButton->setText("Cancel");
466 tmpQPushButton->setAutoRepeat(FALSE);
467 tmpQPushButton->setAutoResize(FALSE);
468 connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(reject()));
471 strcpy(uname, files->text());
472 e->getCursorPosition(&cx, &cy);
474 txt.sprintf("PROGRAM %s\n\nBEGIN\n\nEND ", uname);
475 e->insertAt(txt, cx, cy);
481 * Searches for given text in editor content.
482 * Displays window to set search parameters. If text is found sets cursor
485 void Editor::on_actionFind_triggered()
487 QDialog dlg(this, Qt::Dialog);
491 QLineEdit *tmpQLineEdit;
492 tmpQLineEdit = new QLineEdit("", &dlg);
493 tmpQLineEdit->setGeometry(60, 10, 180, 30);
496 tmpQLabel = new QLabel(&dlg);
497 tmpQLabel->setGeometry(10, 10, 50, 30);
499 tmpQLabel->setText("Text:");
501 QCheckBox *tmpQRadioButton;
502 tmpQRadioButton = new QCheckBox("Case sensitive", &dlg);
503 tmpQRadioButton->setGeometry(70, 50, 150, 30);
504 tmpQRadioButton->setAutoRepeat(FALSE);
506 /*TODO: Does not exists in Qt4. Use layout and set the size policy (https://qt-project.org/forums/viewthread/2112)
507 tmpQRadioButton->setAutoResize(FALSE);
510 QPushButton *okbtn, *cbtn;
511 okbtn = new QPushButton("Find", &dlg);
512 okbtn->setGeometry(260, 10, 100, 30);
513 okbtn->setDefault(TRUE);
514 connect(okbtn,SIGNAL(clicked()), &dlg, SLOT(accept()));
516 cbtn = new QPushButton("Close", &dlg);
517 cbtn->setGeometry(260, 50, 100, 30);
518 connect(cbtn, SIGNAL(clicked()), &dlg, SLOT(reject()));
522 sensitive = tmpQRadioButton->isChecked();
523 find_text = tmpQLineEdit->text();
525 QTextDocument::FindFlags flags = 0;
528 flags |= QTextDocument::FindCaseSensitively;
530 e->find(find_text, flags);
535 * Searches for next occurence of given text in editor content.
536 * Displays window to set search parameters. If text is found sets cursor
539 void Editor::on_actionFind_next_triggered()
541 if (!find_text.isEmpty()) {
542 QTextDocument::FindFlags flags = 0;
545 flags |= QTextDocument::FindCaseSensitively;
547 e->find(find_text, flags);
552 * Program main function.
553 * argv[1] is mandatory and should be a path to the home directory of
554 * application (same as in configuration file).
555 * @param argc Number of program arguments
556 * @param argv Program arguments
558 int main(int argc, char **argv)
560 QApplication app(argc, argv);
562 Editor editor(argv[1], NULL);