From f99b2f0701a9a0603f29f9c790326ec2a8fe5153 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Wed, 30 Oct 2013 22:04:12 +0100 Subject: [PATCH] vlp-28 Moving editor to use QtDesigner files. --- Makefile.am | 19 ++- data/editor/editor-window.ui | 217 +++++++++++++++++++++++++++++++++++ src/edit/editor.cpp | 106 +++++++++-------- src/edit/editor.h | 31 ++--- src/edit/my_edit.h | 16 +++ 5 files changed, 322 insertions(+), 67 deletions(-) create mode 100644 data/editor/editor-window.ui create mode 100644 src/edit/my_edit.h diff --git a/Makefile.am b/Makefile.am index 14dcd62..f716d46 100644 --- a/Makefile.am +++ b/Makefile.am @@ -105,6 +105,7 @@ src/kernel/options.moc.cpp: moc-qt4 src/kernel/options.h -o src/kernel/options.moc.cpp clean-logker-extra: + rm -rf src/kernel/ui rm -f src/kernel/*.moc.cpp rm -f bin/logker @@ -149,19 +150,31 @@ bin_logint_HEADERS = \ clean-logint-extra: rm -f bin/logint -bin_logedit_SOURCES = src/edit/editor.cpp src/edit/editor.moc.cpp +bin_logedit_SOURCES = \ + src/edit/editor.cpp \ + src/edit/editor.moc.cpp \ + src/edit/my_edit.moc.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/editor.h \ + src/edit/my_edit.h \ + src/edit/ui/editor-window.h -src/edit/editor.moc.cpp: src/edit/editor.h +src/edit/ui/editor-window.h: data/editor/editor-window.ui + if [ ! -d src/edit/ui ]; then mkdir -p src/edit/ui; fi + uic-qt4 data/editor/editor-window.ui -o src/edit/ui/editor-window.h + +src/edit/editor.moc.cpp: $(bin_logedit_HEADERS) 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/my_edit.moc.cpp: $(bin_logedit_HEADERS) + moc-qt4 src/edit/my_edit.h -o src/edit/my_edit.moc.cpp clean-logedit-extra: + rm -rf src/edit/ui rm -f src/edit/*.moc.cpp rm -f bin/modules/logedit rm -f bin/logedit diff --git a/data/editor/editor-window.ui b/data/editor/editor-window.ui new file mode 100644 index 0000000..409612b --- /dev/null +++ b/data/editor/editor-window.ui @@ -0,0 +1,217 @@ + + + EditorWindow + + + + 0 + 0 + 523 + 473 + + + + + 800 + 600 + + + + MainWindow + + + + + 0 + + + + + QLayout::SetMaximumSize + + + 3 + + + 3 + + + + + + + + + 0 + 0 + + + + + 16777215 + 100 + + + + false + + + true + + + false + + + + + + + + + + + 0 + 0 + 523 + 20 + + + + + File + + + + + + + + + + + Edit + + + + + + + + + + + + Tools + + + + + + + + + + + + + New + + + Ctrl+N + + + + + Open + + + Ctrl+O + + + + + Save + + + Ctrl+S + + + + + Save as + + + Ctrl+Shift+S + + + + + Quit + + + + + Copy + + + Ctrl+C + + + + + Paste + + + Ctrl+V + + + + + Cut + + + Ctrl+X + + + + + Clear All + + + + + Find + + + Ctrl+F + + + + + Find Next + + + Ctrl+L + + + + + Compile + + + + + Properties + + + + + + My_Edit + QTextEdit +
../my_edit.h
+
+
+ + +
diff --git a/src/edit/editor.cpp b/src/edit/editor.cpp index fe7bc25..bf1360c 100644 --- a/src/edit/editor.cpp +++ b/src/edit/editor.cpp @@ -13,6 +13,7 @@ #include #include "editor.h" +#include "my_edit.h" #define TYPENUM 5 @@ -74,30 +75,33 @@ void Editor::closeEvent(QCloseEvent * e) { Editor::Editor(char *hdir, QWidget * parent) : QMainWindow(parent) { + setupUi(this); + strcpy(HomeDir, hdir); find_text = ""; sensitive = FALSE; - QMenu * file = NULL; +// QMenu * file = NULL; /* QMenu * comp = new QMenu();*/ /* QMenu * loglan = new QMenu();*/ - QMenu * medit = NULL; - QAction* action = NULL; +// QMenu * medit = NULL; +// QAction* action = NULL; - file = menuBar()->addMenu("&File"); - medit = menuBar()->addMenu("&Edit"); +// file = menuBar()->addMenu("&File"); +// medit = menuBar()->addMenu("&Edit"); - action = menuBar()->addAction("&Compile", this, SLOT(cmp())); +// action = menuBar()->addAction("&Compile", this, SLOT(cmp())); /* m->insertItem( "&LOGLAN ", loglan );*/ - action = menuBar()->addAction("&Properties", this, SLOT(props())); +// action = menuBar()->addAction("&Properties", this, SLOT(props())); - file->addAction("New", this, SLOT(create()), QKeySequence(Qt::CTRL + Qt::Key_N)); - file->addAction("Open", this, SLOT(load()), QKeySequence(Qt::CTRL + Qt::Key_O)); - file->addAction("Save", this, SLOT(save()), QKeySequence(Qt::CTRL + Qt::Key_S)); - file->addAction("Save as", this, SLOT(save_as()), QKeySequence(Qt::CTRL + Qt::Key_A)); - file->addSeparator(); - file->addAction("Quit ", this, SLOT(close())); +// file->addAction("New", this, SLOT(create()), QKeySequence(Qt::CTRL + Qt::Key_N)); +// file->addAction("Open", this, SLOT(load()), QKeySequence(Qt::CTRL + Qt::Key_O)); +// file->addAction("Save", this, SLOT(save()), QKeySequence(Qt::CTRL + Qt::Key_S)); +// file->addAction("Save as", this, SLOT(save_as()), QKeySequence(Qt::CTRL + Qt::Key_A)); +// file->addSeparator(); + connect(actionQuit, SIGNAL(triggered()), this, SLOT(close())); +// file->addAction("Quit ", this, SLOT(close())); /* comp->insertItem("Compile ", this, SLOT(cmp()), CTRL + Key_C);*/ /* comp->insertItem("Gen ", this, SLOT(gen()), CTRL + Key_G);*/ @@ -105,36 +109,40 @@ Editor::Editor(char *hdir, QWidget * parent) /* loglan->insertItem( "Program structure", this, SLOT(log_prog()));*/ /* loglan->insertItem( "Unit structure", this, SLOT(log_unit()));*/ - - e = new My_Edit(this, "editor"); + +// e = new My_Edit(this, "editor"); connect(e, SIGNAL(cursorMove()), this, SLOT(updateline())); - medit->addAction("Copy", e, SLOT(copy()), QKeySequence(Qt::CTRL + Qt::Key_Insert)); - medit->addAction("Paste", e, SLOT(paste()), QKeySequence(Qt::SHIFT + Qt::Key_Insert)); - medit->addAction("Cut", e, SLOT(cut()), QKeySequence(Qt::CTRL + Qt::Key_Delete)); - medit->addAction("Clear All", e, SLOT(clear())); - medit->addSeparator(); - medit->addAction("Find", this, SLOT(findText()), QKeySequence(Qt::CTRL + Qt::Key_F)); - medit->addAction("Find Next", this, SLOT(find_next()), QKeySequence(Qt::CTRL + Qt::Key_L)); - - msg = new QTextEdit(this); - msg->setReadOnly(TRUE); - - QVBoxLayout * layout = new QVBoxLayout(); - layout->setContentsMargins (3, 0, 3, 0); - layout->addWidget(e); - layout->addWidget(msg); - QWidget *window = new QWidget(); - window->setLayout(layout); - setCentralWidget(window); + connect(actionCopy, SIGNAL(triggered()), e, SLOT(copy())); + connect(actionPaste, SIGNAL(triggered()), e, SLOT(paste())); + connect(actionCut, SIGNAL(triggered()), e, SLOT(cut())); + connect(actionClear_all, SIGNAL(triggered()), e, SLOT(clear())); +// medit->addAction("Copy", e, SLOT(copy()), QKeySequence(Qt::CTRL + Qt::Key_Insert)); +// medit->addAction("Paste", e, SLOT(paste()), QKeySequence(Qt::SHIFT + Qt::Key_Insert)); +// medit->addAction("Cut", e, SLOT(cut()), QKeySequence(Qt::CTRL + Qt::Key_Delete)); +// medit->addAction("Clear All", e, SLOT(clear())); +// medit->addSeparator(); +// medit->addAction("Find", this, SLOT(findText()), QKeySequence(Qt::CTRL + Qt::Key_F)); +// medit->addAction("Find Next", this, SLOT(find_next()), QKeySequence(Qt::CTRL + Qt::Key_L)); + +// msg = new QTextEdit(this); +// msg->setReadOnly(TRUE); + +// QVBoxLayout * layout = new QVBoxLayout(); +// layout->setContentsMargins (3, 0, 3, 0); +// layout->addWidget(e); +// layout->addWidget(msg); +// QWidget *window = new QWidget(); +// window->setLayout(layout); +// setCentralWidget(window); compiler_path.sprintf("%s/%s", HomeDir, "compile/logcomp"); gen_path.sprintf("%s/%s", HomeDir, "compile/gen"); file_path.sprintf("%s", HomeDir); - QColor col(200, 200, 200); - QPalette grp(Qt::black, col, col.lighter(), col.darker(), col.darker(), Qt::black, col); +// QColor col(200, 200, 200); +// QPalette grp(Qt::black, col, col.lighter(), col.darker(), col.darker(), Qt::black, col); - msg->setPalette(grp); +// msg->setPalette(grp); position = new QLabel(); statusBar()->addPermanentWidget(position); @@ -189,7 +197,7 @@ TODO: Remove entire method? /** * Displays additional window */ -void Editor::load() +void Editor::on_actionOpen_triggered() { QString fn = QFileDialog::getOpenFileName(this, "Load file", file_path, "*.log"); if (!fn.isEmpty()) @@ -232,7 +240,7 @@ void Editor::load(const char *fileName) * If content has been read from file, it is written to this file. Otherwise * dialog is shown to save content to the specified by user, file. */ -void Editor::save() +void Editor::on_actionSave_triggered() { if (fname.isEmpty()) { QString fn = QFileDialog::getSaveFileName(this, "Save file", @@ -252,7 +260,7 @@ void Editor::save() * Forces saving editor content to the new file. Special dialog is shown for * that purpose. */ -void Editor::save_as() +void Editor::on_actionSave_as_triggered() { QString fn = QFileDialog::getSaveFileName(this, "Save file as", file_path, "*.log"); @@ -280,7 +288,7 @@ void Editor::save(const char *fileName) /** * Empties editor content. */ -void Editor::create() +void Editor::on_actionNew_triggered() { e->clear(); fname.sprintf("%s", ""); @@ -289,18 +297,18 @@ void Editor::create() /** * @attention Currently not in use */ -void Editor::print() -{ -} +//void Editor::print() +//{ +//} /** * @attention Currently not in use. * * Saves and compiles code. */ -void Editor::cmp() +void Editor::on_actionCompile_triggered() { - save(); + on_actionSave_triggered(); compile(COMP_MODE); } @@ -321,7 +329,7 @@ void Editor::gen() */ void Editor::comp_all() { - save(); + on_actionSave_triggered(); compile(ALL_MODE); } @@ -389,7 +397,7 @@ void Editor::compile(int mode) /** * Displays window with editor properties */ -void Editor::props() +void Editor::on_actionProperties_triggered() { QDialog dlg(this, Qt::Dialog); @@ -587,7 +595,7 @@ void Editor::log_prog() * Displays window to set search parameters. If text is found sets cursor * position on it. */ -void Editor::findText() +void Editor::on_actionFind_triggered() { QDialog dlg(this, Qt::Dialog); QString *txt; @@ -641,7 +649,7 @@ void Editor::findText() * Displays window to set search parameters. If text is found sets cursor * position on it. */ -void Editor::find_next() +void Editor::on_actionFind_next_triggered() { if (!find_text.isEmpty()) { QTextDocument::FindFlags flags = 0; diff --git a/src/edit/editor.h b/src/edit/editor.h index 5c8fa50..16f4cac 100644 --- a/src/edit/editor.h +++ b/src/edit/editor.h @@ -7,6 +7,7 @@ #include #include +#include "ui/editor-window.h" #define COMP_MODE 1 #define GEN_MODE 2 @@ -22,17 +23,16 @@ typedef struct { QStringList names; char name[255]; } CategoryEntry; - +/* class My_Edit : public QTextEdit { Q_OBJECT public: My_Edit(QWidget *parent = 0, const char *name = 0); - virtual void keyPressEvent(QKeyEvent *ev); signals: void cursorMove(); }; - -class Editor : public QMainWindow { +*/ +class Editor : public QMainWindow, private Ui::EditorWindow { Q_OBJECT public: QString compiler_path; @@ -45,32 +45,33 @@ public: void compile(int mode); public slots: - void load(); + void on_actionOpen_triggered(); void load(const char *fileName); - void save(); + void on_actionSave_triggered(); void save(const char *fileName); - void save_as(); - void create(); - void props(); - void print(); - void cmp(); + void on_actionSave_as_triggered(); + void on_actionNew_triggered(); + void on_actionProperties_triggered(); +// void print(); + void on_actionCompile_triggered(); void gen(); void comp_all(); void log_unit(); void log_prog(); - void findText(); - void find_next(); + void on_actionFind_triggered(); + void on_actionFind_next_triggered(); //void gotoline(); void updateline(); protected: +// virtual void editorKeyPressEvent(QKeyEvent *ev); void resizeEvent(QResizeEvent *); virtual void closeEvent (QCloseEvent * e); private: - My_Edit *e; - QTextEdit *msg; +// My_Edit *e; +// QTextEdit *msg; QLabel *position; QString fname; QString find_text; diff --git a/src/edit/my_edit.h b/src/edit/my_edit.h new file mode 100644 index 0000000..3a319fa --- /dev/null +++ b/src/edit/my_edit.h @@ -0,0 +1,16 @@ +#ifndef VLP_EDITOR_AREA_H +#define VLP_EDITOR_AREA_H + +#include + +class My_Edit : public QTextEdit { + Q_OBJECT +public: + My_Edit(QWidget *parent = 0, const char *name = 0); +signals: + void cursorMove(); +protected: + virtual void keyPressEvent(QKeyEvent*); +}; + +#endif /* VLP_EDITOR_AREA */ -- 2.30.2