From: Rafał Długołęcki Date: Thu, 28 Jan 2016 19:38:09 +0000 (+0100) Subject: Move dialogs layout code into separate ui file X-Git-Tag: 3.4-b1~31 X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=51482069fdcb6419521f9f5cfcff5980a185428b;p=vlp.git Move dialogs layout code into separate ui file --- diff --git a/Makefile.am b/Makefile.am index 819b884..13dddd8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -163,25 +163,42 @@ bin_logint_HEADERS = \ clean-logint-extra: rm -f bin/logint -bin_logedit_SOURCES = src/edit/editor.cpp src/edit/editor.moc.cpp -bin_logedit_CPPFLAGS = $(bin_logedit_CFLAGS) +bin_logedit_SOURCES = \ + src/edit/editor.cpp \ + src/edit/editor.moc.cpp \ + src/edit/ProgramStructureDialog.cpp \ + src/edit/UnitStructureDialog.cpp +bin_logedit_CPPFLAGS = $(bin_logedit_CFLAGS) bin_logedit_LDADD = $(bin_logedit_LIBS) bin_logeditdir = src/edit bin_logedit_HEADERS =\ src/edit/editor.h \ - src/edit/ui/editor.h + src/edit/ui/editor.h \ + src/edit/ProgramStructureDialog.h \ + src/edit/ui/dialogs/ProgramStructureDialog.h \ + src/edit/UnitStructureDialog.h \ + src/edit/ui/dialogs/UnitStructureDialog.h src/edit/editor.moc.cpp: \ src/edit/editor.h \ - src/edit/ui/editor.h + src/edit/ui/editor.h \ + src/edit/ui/dialogs/ProgramStructureDialog.h \ + src/edit/ui/dialogs/UnitStructureDialog.h moc-qt4 src/edit/editor.h -o src/edit/editor.moc.cpp # $(MOC) src/edit/editor.h -o src/edit/editor.moc.cpp src/edit/ui/editor.h: uic src/edit/ui/editor.ui -o src/edit/ui/editor.h +src/edit/ui/dialogs/ProgramStructureDialog.h: + uic src/edit/ui/dialogs/ProgramStructureDialog.ui -o src/edit/ui/dialogs/ProgramStructureDialog.h + +src/edit/ui/dialogs/UnitStructureDialog.h: + uic src/edit/ui/dialogs/UnitStructureDialog.ui -o src/edit/ui/dialogs/UnitStructureDialog.h + clean-logedit-extra: + rm -f src/edit/ui/dialogs/*.h rm -f src/edit/ui/editor.h rm -f src/edit/*.moc.cpp rm -f bin/modules/logedit diff --git a/src/edit/ProgramStructureDialog.cpp b/src/edit/ProgramStructureDialog.cpp new file mode 100644 index 0000000..25750c8 --- /dev/null +++ b/src/edit/ProgramStructureDialog.cpp @@ -0,0 +1,27 @@ +#include "ProgramStructureDialog.h" + + +ProgramStructureDialog::ProgramStructureDialog(QWidget * parent) + : QDialog(parent) +{ + setupUi(this); + + connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); + connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); +} + +ProgramStructureDialog::~ProgramStructureDialog() +{ +} + +QString ProgramStructureDialog::getProgramName() +{ + return lineEdit->text(); +} + +QString ProgramStructureDialog::getCode() +{ + QString code; + code.sprintf("PROGRAM %s\n\nBEGIN\n\nEND", getProgramName().toStdString().c_str()); + return code; +} diff --git a/src/edit/ProgramStructureDialog.h b/src/edit/ProgramStructureDialog.h new file mode 100644 index 0000000..35fbe04 --- /dev/null +++ b/src/edit/ProgramStructureDialog.h @@ -0,0 +1,41 @@ +#ifndef _VLP_EDITOR_PROGRAMSTRUCTUREDIALOG_H +#define _VLP_EDITOR_PROGRAMSTRUCTUREDIALOG_H + +#include +#include + + +#include "ui/dialogs/ProgramStructureDialog.h" + +/** + * Program Structure Dialog class + * Displays dialog for generating code template for program structure + */ +class ProgramStructureDialog : public QDialog, private Ui::ProgramStructureDialog { +public: + /** + * Class constructor + */ + ProgramStructureDialog(QWidget * parent = 0); + + /** + * Class destuctor + */ + ~ProgramStructureDialog(); + + /** + * Gets user-passed program name + * + * @return program name entered in dialog + */ + QString getProgramName(); + + /** + * Gets program code template + * + * @return program code template with program name + */ + QString getCode(); +}; + +#endif /* _VLP_EDITOR_PROGRAMSTRUCTUREDIALOG_H */ diff --git a/src/edit/UnitStructureDialog.cpp b/src/edit/UnitStructureDialog.cpp new file mode 100644 index 0000000..a947a12 --- /dev/null +++ b/src/edit/UnitStructureDialog.cpp @@ -0,0 +1,47 @@ +#include "UnitStructureDialog.h" + +#define TYPENUM 5 + +const char *UnitTypes[TYPENUM] = { + "CLASS", + "PROCEDURE", + "FUNCTION", + "PROCESS", + "COROUTINE" +}; + +UnitStructureDialog::UnitStructureDialog(QWidget * parent) + : QDialog(parent) +{ + setupUi(this); + + for (int i = 0; i < TYPENUM; i++) { + QListWidgetItem *newItem = new QListWidgetItem; + newItem->setText(UnitTypes[i]); + listWidget->insertItem(i, newItem); + } + listWidget->setCurrentItem(0); + + connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); + connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); +} + +UnitStructureDialog::~UnitStructureDialog() +{ +} + +QString UnitStructureDialog::getUnitName() +{ + return lineEdit->text(); +} + +QString UnitStructureDialog::getCode() +{ + QString code; + code.sprintf("UNIT %s : %s( );\nBEGIN\n\nEND %s;", + getUnitName().toStdString().c_str(), + listWidget->currentItem()->text().toStdString().c_str(), + getUnitName().toStdString().c_str() + ); + return code; +} diff --git a/src/edit/UnitStructureDialog.h b/src/edit/UnitStructureDialog.h new file mode 100644 index 0000000..32fd7df --- /dev/null +++ b/src/edit/UnitStructureDialog.h @@ -0,0 +1,40 @@ +#ifndef _VLP_EDITOR_UNITSTRUCTUREDIALOG_H +#define _VLP_EDITOR_UNITSTRUCTUREDIALOG_H + +#include +#include + +#include "ui/dialogs/UnitStructureDialog.h" + +/** + * Program Unit Dialog class + * Displays dialog for generating code template for unit structure + */ +class UnitStructureDialog : public QDialog, private Ui::UnitStructureDialog { +public: + /** + * Class constructor + */ + UnitStructureDialog(QWidget * parent = 0); + + /** + * Class destuctor + */ + ~UnitStructureDialog(); + + /** + * Gets user-passed unit name + * + * @return unit name entered in dialog + */ + QString getUnitName(); + + /** + * Gets unit code template + * + * @return unit code template with unit name + */ + QString getCode(); +}; + +#endif /* _VLP_EDITOR_PROGRAMSTRUCTUREDIALOG_H */ diff --git a/src/edit/editor.cpp b/src/edit/editor.cpp index c832f3e..59e7f9e 100644 --- a/src/edit/editor.cpp +++ b/src/edit/editor.cpp @@ -14,20 +14,10 @@ #include #include -#include "editor.h" - -#define TYPENUM 5 +#include "ProgramStructureDialog.h" +#include "UnitStructureDialog.h" -/** - * @attention Currently not in use - */ -const char *UnitTypes[TYPENUM] = { - "CLASS", - "PROCEDURE", - "FUNCTION", - "PROCESS", - "COROUTINE" -}; +#include "editor.h" /** * Editor constructor. Initializes and sets variables of Loglan Editor. @@ -412,102 +402,19 @@ void Editor::on_actionCompile_Gen_triggered() void Editor::on_actionProgram_structure_triggered() { - QDialog dlg(this, "unit", TRUE); - 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); - tmpQLabel->setGeometry(10, 20, 100, 30); - tmpQLabel->setText("Program name:"); - - QPushButton* tmpQPushButton; - tmpQPushButton = new QPushButton(&dlg); - tmpQPushButton->setGeometry(40, 70, 70, 30); - tmpQPushButton->setText("Ok"); - tmpQPushButton->setAutoRepeat(FALSE); - connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(accept())); - - tmpQPushButton = new QPushButton(&dlg); - tmpQPushButton->setGeometry(130, 70, 100, 30); - tmpQPushButton->setText("Cancel"); - tmpQPushButton->setAutoRepeat(FALSE); - connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(reject())); - - if (dlg.exec()) { - strcpy(uname, files->text()); - - QString txt; - txt.sprintf("PROGRAM %s\n\nBEGIN\n\nEND", uname); + ProgramStructureDialog dialog(this); - editor->textCursor().insertText(txt); + if (dialog.exec()) { + editor->textCursor().insertText(dialog.getCode()); } } void Editor::on_actionUnit_structure_triggered() { - QDialog dlg(this, Qt::Dialog); - int 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); - tmpQLabel->setGeometry(10, 20, 100, 30); - tmpQLabel->setText("Unit name:"); - tmpQLabel->setAlignment(289); - tmpQLabel->setMargin(-1); - - QPushButton* tmpQPushButton; - tmpQPushButton = new QPushButton(&dlg); - tmpQPushButton->setGeometry(40, 170, 70, 30); - tmpQPushButton->setText("Ok"); - tmpQPushButton->setAutoRepeat(FALSE); - connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(accept())); - - tmpQPushButton = new QPushButton(&dlg); - tmpQPushButton->setGeometry(130, 170, 100, 30); - tmpQPushButton->setText("Cancel"); - tmpQPushButton->setAutoRepeat(FALSE); - connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(reject())); - - tmpQLabel = new QLabel(&dlg); - tmpQLabel->setGeometry(10, 50, 100, 60); - tmpQLabel->setText("Unit type:"); - - QListWidget *listWidget = new QListWidget(&dlg); - for(i = 0; i < TYPENUM; i++) { - QListWidgetItem *newItem = new QListWidgetItem; - newItem->setText(UnitTypes[i]); - listWidget->insertItem(i, newItem); - } - listWidget->setCurrentItem(0); - - if (dlg.exec()) { - strcpy(uname, files->text()); - - QString txt; - txt.sprintf("UNIT %s : %s( );\nBEGIN\n\nEND %s;", - uname, - listWidget->currentItem()->text().toStdString().c_str(), - uname - ); + UnitStructureDialog dialog(this); - editor->textCursor().insertText(txt); + if (dialog.exec()) { + editor->textCursor().insertText(dialog.getCode()); } } diff --git a/src/edit/ui/dialogs/ProgramStructureDialog.ui b/src/edit/ui/dialogs/ProgramStructureDialog.ui new file mode 100644 index 0000000..b4dfa31 --- /dev/null +++ b/src/edit/ui/dialogs/ProgramStructureDialog.ui @@ -0,0 +1,94 @@ + + + ProgramStructureDialog + + + + 0 + 0 + 318 + 108 + + + + Program Structure + + + + + + 6 + + + 20 + + + 20 + + + + + Program name + + + + + + + + 200 + 0 + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + ProgramStructureDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + ProgramStructureDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/edit/ui/dialogs/UnitStructureDialog.ui b/src/edit/ui/dialogs/UnitStructureDialog.ui new file mode 100644 index 0000000..74f1a5b --- /dev/null +++ b/src/edit/ui/dialogs/UnitStructureDialog.ui @@ -0,0 +1,135 @@ + + + UnitStructureDialog + + + + 0 + 0 + 486 + 262 + + + + Dialog + + + + + + + + + + Unit type + + + + + + + + 200 + 0 + + + + + + + + + + + + + 0 + 0 + + + + Unit name + + + + + + + + 0 + 0 + + + + + 200 + 0 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + UnitStructureDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + UnitStructureDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +