#include <QtGui/QFileDialog>
#include <QtGui/QColor>
#include <QtGui/QPalette>
-#include <QtGui/QCloseEvent>
#include <QtGui/QTextDocument>
#include <QtGui/QMainWindow>
#include <QtGui/QStatusBar>
#include <QtGui/QCheckBox>
#include <QtGui/QVBoxLayout>
+#include <QtGui/QListWidget>
+#include <QtGui/QListWidgetItem>
-#include "editor.h"
+#include "ProgramStructureDialog.h"
+#include "UnitStructureDialog.h"
+#include "PreferencesDialog.h"
+#include "FindDialog.h"
-#define TYPENUM 5
+#include "editor.h"
-/**
- * @attention Currently not in use
- */
-char *UnitTypes[TYPENUM] = {
- "CLASS",
- "PROCEDURE",
- "FUNCTION",
- "PROCESS",
- "COROUTINE"
-};
+namespace loglan {
+namespace vlp {
/**
* Editor constructor. Initializes and sets variables of Loglan Editor.
if (argc > 1) {
strcpy(HomeDir, argv[1]);
+ fprintf(stderr, "EDIT: HomeDir inited with: %s (%s)\n", HomeDir, argv[1]);
}
find_text = "";
sensitive = FALSE;
- /* loglan->insertItem( "Program structure", this, SLOT(log_prog()));*/
- /* loglan->insertItem( "Unit structure", this, SLOT(log_unit()));*/
-
compiler_path.sprintf("%s/%s", HomeDir, "compile/logcomp");
gen_path.sprintf("%s/%s", HomeDir, "compile/gen");
file_path.sprintf("%s", HomeDir);
editor->clear();
QTextStream textStream(&file);
- while (!file.atEnd()) {
- editor->append(textStream.readLine());
- }
+ editor->append(textStream.readAll());
+// while (!file.atEnd()) {
+// editor->append(textStream.readLine());
+// }
file.close();
/* fn.truncate(i);*/
switch(mode) {
case COMP_MODE:
- sprintf(cmd, "%s %s > comp_data!", compiler_path.toAscii().data(),
- fname.toAscii().data());
+ sprintf(cmd, "%s %s > comp_data!", compiler_path.toStdString().c_str(),
+ fname.toStdString().c_str());
break;
case GEN_MODE:
- sprintf(cmd, "%s %s > comp_data!", gen_path.toAscii().data(),
- fname.toAscii().data());
+ sprintf(cmd, "%s %s > comp_data!", gen_path.toStdString().c_str(),
+ fname.toStdString().c_str());
break;
case ALL_MODE:
- sprintf(cmd, "%s %s > comp_data!", compiler_path.toAscii().data(),
- fname.toAscii().data());
+ sprintf(cmd, "%s %s > comp_data!", compiler_path.toStdString().c_str(),
+ fname.toStdString().c_str());
system(cmd);
- sprintf(cmd, "%s %s >> comp_data!", gen_path.toAscii().data(),
- fname.toAscii().data());
+ sprintf(cmd, "%s %s >> comp_data!", gen_path.toStdString().c_str(),
+ fname.toStdString().c_str());
break;
}
*/
void Editor::on_actionNew_triggered()
{
- editor->clear();
- fname.sprintf("%s", "");}
+ on_actionClear_all_triggered();
+ fname.sprintf("%s", "");
+}
/**
* Displays additional window
}
void Editor::on_actionCopy_triggered()
{
+ editor->copy();
}
void Editor::on_actionPaste_triggered()
{
+ editor->paste();
}
void Editor::on_actionCut_triggered()
{
+ editor->cut();
}
void Editor::on_actionClear_all_triggered()
{
+ editor->clear();
}
/**
*/
void Editor::on_actionFind_triggered()
{
- QDialog dlg(this, Qt::Dialog);
- QString *txt;
- int res, line, pom;
-
- QLineEdit *tmpQLineEdit;
- tmpQLineEdit = new QLineEdit("", &dlg);
- tmpQLineEdit->setGeometry(60, 10, 180, 30);
-
- QLabel *tmpQLabel;
- tmpQLabel = new QLabel(&dlg);
- tmpQLabel->setGeometry(10, 10, 50, 30);
-
- tmpQLabel->setText("Text:");
-
- QCheckBox *tmpQRadioButton;
- tmpQRadioButton = new QCheckBox("Case sensitive", &dlg);
- tmpQRadioButton->setGeometry(70, 50, 150, 30);
- tmpQRadioButton->setAutoRepeat(FALSE);
-
- QPushButton *okbtn, *cbtn;
- okbtn = new QPushButton("Find", &dlg);
- okbtn->setGeometry(260, 10, 100, 30);
- okbtn->setDefault(TRUE);
- connect(okbtn,SIGNAL(clicked()), &dlg, SLOT(accept()));
-
- cbtn = new QPushButton("Close", &dlg);
- cbtn->setGeometry(260, 50, 100, 30);
- connect(cbtn, SIGNAL(clicked()), &dlg, SLOT(reject()));
+ dialog::FindDialog dialog(this);
- dlg.resize(380, 90);
-
- if (dlg.exec()) {
- sensitive = tmpQRadioButton->isChecked();
- find_text = tmpQLineEdit->text();
+ if (dialog.exec()) {
+ sensitive = dialog.isCaseSensitive();
+ find_text = dialog.getSearchText();
QTextDocument::FindFlags flags = 0;
if (sensitive) {
flags |= QTextDocument::FindCaseSensitively;
}
+
editor->find(find_text, flags);
}
}
*/
void Editor::on_actionPreferences_triggered()
{
- QDialog dlg(this, Qt::Dialog);
-
- QLineEdit *files;
- files = new QLineEdit(&dlg);
- files->setGeometry(130, 20, 250, 30);
- files->setText(file_path);
- files->setMaxLength(32767);
- files->setEchoMode(QLineEdit::Normal);
- files->setFrame(TRUE);
-
- QLabel *tmpQLabel;
- tmpQLabel = new QLabel("Path to files:", &dlg);
- tmpQLabel->setGeometry(10, 20, 100, 30);
- tmpQLabel->setAlignment(Qt::AlignLeft);
- tmpQLabel->setMargin(-1);
-
- tmpQLabel = new QLabel("Path to compiler:", &dlg);
- tmpQLabel->setGeometry(10, 60, 100, 30);
- tmpQLabel->setAlignment(Qt::AlignLeft);
- tmpQLabel->setMargin(-1);
-
- /*
- tmpQLabel = new QLabel(&dlg, "Label_3");
- tmpQLabel->setGeometry(10, 100, 100, 30);
- tmpQLabel->setText("Path to gen:");
- tmpQLabel->setAlignment(289);
- tmpQLabel->setMargin(-1);
- */
-
- QLineEdit *compp;
- compp = new QLineEdit(compiler_path, &dlg);
- compp->setGeometry(130, 60, 250, 30);
- compp->setMaxLength(32767);
- compp->setEchoMode(QLineEdit::Normal);
- compp->setFrame(TRUE);
-
- /*
- QLineEdit* genp;
- genp = new QLineEdit(&dlg, "g_path");
- genp->setGeometry(130, 100, 250, 30);
- genp->setText(gen_path.data());
- genp->setMaxLength(32767);
- genp->setEchoMode(QLineEdit::Normal);
- genp->setFrame(TRUE);
- */
-
- QPushButton* tmpQPushButton;
- tmpQPushButton = new QPushButton("Ok", &dlg);
- tmpQPushButton->setGeometry(90, 100, 70, 30);
- tmpQPushButton->setAutoRepeat(FALSE);
- connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(accept()));
-
- tmpQPushButton = new QPushButton("Cancel", &dlg);
- tmpQPushButton->setGeometry(180, 100, 70, 30);
- tmpQPushButton->setAutoRepeat(FALSE);
- connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(reject()));
-
- dlg.resize(400, 140);
-
- if (dlg.exec()) {
- compiler_path.sprintf("%s", compp->text().toAscii().data());
- /* gen_path.sprintf("%s",genp->text()); */
- file_path.sprintf("%s", files->text().toAscii().data());
+ dialog::PreferencesDialog dialog(this);
+
+ dialog.setCompilerPath(compiler_path);
+ dialog.setFilesPath(file_path);
+ dialog.setGenPath(gen_path);
+
+ if (dialog.exec()) {
+ compiler_path.sprintf("%s", dialog.getCompilerPath().toStdString().c_str());
+ gen_path.sprintf("%s",dialog.getGenPath().toStdString().c_str());
+ file_path.sprintf("%s", dialog.getFilesPath().toStdString().c_str());
};
}
/**
- * @attention Currently not in use.
- *
* Saves and compiles code.
*/
void Editor::on_actionCompile_triggered()
}
/**
- * @attention Currently not in use.
- *
* Generates program.
*/
void Editor::on_actionGen_triggered()
}
/**
- * @attention Currently not in use.
- *
* Saves, compiles and generates code.
*/
void Editor::on_actionCompile_Gen_triggered()
void Editor::on_actionProgram_structure_triggered()
{
- /*
- Code commented during Qt4 migration.
- Code is not used, so there is no rush with this...
- */
- /*
- QString txt;
- QDialog dlg(this, "unit", TRUE);
- int cx, cy;
- char uname[255];
-
- QLineEdit *files;
- files = new QLineEdit(&dlg, "f_path");
- files->setGeometry(130, 20, 250, 30);
- files->setText("");
- files->setMaxLength(32767);
- files->setEchoMode(QLineEdit::Normal);
- files->setFrame(TRUE);
-
- QLabel *tmpQLabel;
- tmpQLabel = new QLabel(&dlg, "Label_1");
- tmpQLabel->setGeometry(10, 20, 100, 30);
- tmpQLabel->setText("Program name:");
-
- QPushButton* tmpQPushButton;
- tmpQPushButton = new QPushButton(&dlg, "OkBtn");
- tmpQPushButton->setGeometry(40, 70, 70, 30);
- tmpQPushButton->setText("Ok");
- tmpQPushButton->setAutoRepeat(FALSE);
- tmpQPushButton->setAutoResize(FALSE);
- connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(accept()));
-
- tmpQPushButton = new QPushButton(&dlg, "CancelBtn");
- tmpQPushButton->setGeometry(130, 70, 100, 30);
- tmpQPushButton->setText("Cancel");
- tmpQPushButton->setAutoRepeat(FALSE);
- tmpQPushButton->setAutoResize(FALSE);
- connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(reject()));
-
- if (dlg.exec()) {
- strcpy(uname, files->text());
- e->getCursorPosition(&cx, &cy);
-
- txt.sprintf("PROGRAM %s\n\nBEGIN\n\nEND ", uname);
- e->insertAt(txt, cx, cy);
+ dialog::ProgramStructureDialog dialog(this);
+
+ if (dialog.exec()) {
+ editor->textCursor().insertText(dialog.getCode());
}
- */
}
void Editor::on_actionUnit_structure_triggered()
{
- /*
- Code commented during Qt4 migration.
- Code is not used, so there is no rush with this...
- */
- /*
- QString txt;
- QDialog dlg(this, Qt::Dialog);
- int cx, cy, i;
- char uname[255];
-
- QLineEdit* files;
- files = new QLineEdit(&dlg, "f_path");
- files->setGeometry(130, 20, 250, 30);
- files->setText("");
- files->setMaxLength(32767);
- files->setEchoMode(QLineEdit::Normal);
- files->setFrame(TRUE);
-
- QLabel* tmpQLabel;
- tmpQLabel = new QLabel(&dlg, "Label_1");
- tmpQLabel->setGeometry(10, 20, 100, 30);
- tmpQLabel->setText("Unit name:");
- tmpQLabel->setAlignment(289);
- tmpQLabel->setMargin(-1);
-
- QPushButton* tmpQPushButton;
- tmpQPushButton = new QPushButton(&dlg, "OkBtn");
- tmpQPushButton->setGeometry(40, 170, 70, 30);
- tmpQPushButton->setText("Ok");
- tmpQPushButton->setAutoRepeat(FALSE);
- tmpQPushButton->setAutoResize(FALSE);
- connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(accept()));
-
- tmpQPushButton = new QPushButton(&dlg, "CancelBtn");
- tmpQPushButton->setGeometry(130, 170, 100, 30);
- tmpQPushButton->setText("Cancel");
- tmpQPushButton->setAutoRepeat(FALSE);
- tmpQPushButton->setAutoResize(FALSE);
- connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(reject()));
-
- tmpQLabel = new QLabel(&dlg, "Label_1");
- tmpQLabel->setGeometry(10, 50, 100, 60);
- tmpQLabel->setText("Unit type:");
-
- QListBox lst(&dlg, "type");
- for(i = 0; i < TYPENUM; i++) {
- lst.insertItem(UnitTypes[i]);
- }
- lst.setGeometry(130, 60, 180, 80);
- lst.setCurrentItem(0);
+ dialog::UnitStructureDialog dialog(this);
- if (dlg.exec()) {
- strcpy(uname, files->text());
- e->getCursorPosition(&cx, &cy);
-
- txt.sprintf("UNIT %s : %s( <params> );\nBEGIN\n\nEND %s;",
- uname, lst.text(lst.currentItem()).ascii(), uname);
- e->insertAt(txt, cx, cy);
+ if (dialog.exec()) {
+ editor->textCursor().insertText(dialog.getCode());
}
- */
+}
+
+}
}
/**
* 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 app(argc, argv);
- Editor * editor = new Editor(argc, argv);
+ loglan::vlp::Editor * editor = new loglan::vlp::Editor(argc, argv);
editor->show();
return app.exec();
}