From fea671e0abd75fbbd90946d759e45e1b1a4d3444 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:36:24 +0100 Subject: [PATCH] vlp-27 Removed some unused code. Added undo&redo to menu. Removed maximum window dimensions. --- data/editor/editor-window.ui | 33 ++++++++++---- src/edit/editor.cpp | 85 +++--------------------------------- src/edit/editor.h | 20 ++------- src/edit/my_edit.h | 6 +-- 4 files changed, 39 insertions(+), 105 deletions(-) diff --git a/data/editor/editor-window.ui b/data/editor/editor-window.ui index 409612b..5b3ee26 100644 --- a/data/editor/editor-window.ui +++ b/data/editor/editor-window.ui @@ -10,12 +10,6 @@ 473 - - - 800 - 600 - - MainWindow @@ -36,12 +30,16 @@ 3 - + + + false + + - + 0 0 @@ -91,6 +89,9 @@ Edit + + + @@ -204,6 +205,22 @@ Properties + + + Undo + + + Ctrl+Z + + + + + Redo + + + Ctrl+Shift+Z + + diff --git a/src/edit/editor.cpp b/src/edit/editor.cpp index bf1360c..f6808a4 100644 --- a/src/edit/editor.cpp +++ b/src/edit/editor.cpp @@ -17,8 +17,6 @@ #define TYPENUM 5 -Editor *editor; - /** * @attention Currently not in use */ @@ -36,14 +34,10 @@ char *UnitTypes[TYPENUM] = { * @param parent Parent widget of this widget. If set, this widget becomes a * child window inside parent. If not set this widget becomes a * top level window. Default: NULL - * @deprecated @param name If set, name is sent to the Qobject constructor, so widget is - * identifiable (e.g. in Qt Designer) */ -My_Edit::My_Edit(QWidget *parent, const char *name) +My_Edit::My_Edit(QWidget *parent = NULL) : QTextEdit(parent) { - parent = NULL; - name = NULL; } /** @@ -69,8 +63,6 @@ void Editor::closeEvent(QCloseEvent * e) { * @param parent Parent widget of this widget. If set, this widget becomes a * child window inside parent. If not set this widget becomes a * top level window. Default: NULL - * @param name If set, name is sent to the Qobject constructor, so widget is - * identifiable (e.g. in Qt Designer) */ Editor::Editor(char *hdir, QWidget * parent) : QMainWindow(parent) @@ -80,28 +72,10 @@ Editor::Editor(char *hdir, QWidget * parent) strcpy(HomeDir, hdir); find_text = ""; sensitive = FALSE; -// QMenu * file = NULL; -/* QMenu * comp = new QMenu();*/ -/* QMenu * loglan = new QMenu();*/ -// QMenu * medit = NULL; -// QAction* action = NULL; - -// file = menuBar()->addMenu("&File"); -// medit = menuBar()->addMenu("&Edit"); - -// action = menuBar()->addAction("&Compile", this, SLOT(cmp())); /* m->insertItem( "&LOGLAN ", loglan );*/ -// 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(); 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);*/ @@ -110,40 +84,18 @@ 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"); connect(e, SIGNAL(cursorMove()), this, SLOT(updateline())); + connect(actionUndo, SIGNAL(triggered()), e, SLOT(undo())); + connect(actionRedo, SIGNAL(triggered()), e, SLOT(redo())); 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); - -// msg->setPalette(grp); - position = new QLabel(); statusBar()->addPermanentWidget(position); } @@ -170,30 +122,6 @@ void Editor::updateline() position->setText(pom); } -/** - * Event invoked on resizing editor application window. - * @copydoc QWidget::resizeEvent(QResizeEvent*) - * @param event Currently does nothing - */ -void Editor::resizeEvent(QResizeEvent *event) -{ -/* -TODO: Remove entire method? - if (e && m) { - e->setGeometry(0, m->height(), width(), - 3 * (int)((height() - m->height()) / 4)); - - msg->setGeometry(0, m->height() + e->height(), width(), - (int)((height() - m->height()) / 4)); - - position->setGeometry(width() - 80, - m->height() + e->height() - 10, - position->width(), - position->height()); - } -*/ -} - /** * Displays additional window */ @@ -671,9 +599,10 @@ void Editor::on_actionFind_next_triggered() int main(int argc, char **argv) { QApplication app(argc, argv); - editor = new Editor(argv[1], NULL); - editor->resize(600, 400); - editor->show(); + + Editor editor(argv[1], NULL); + editor.show(); + return app.exec(); } diff --git a/src/edit/editor.h b/src/edit/editor.h index 16f4cac..f619f22 100644 --- a/src/edit/editor.h +++ b/src/edit/editor.h @@ -1,5 +1,5 @@ -#ifndef QWERTY_H -#define QWERTY_H +#ifndef VLP_EDITOR_H +#define VLP_EDITOR_H #include #include @@ -23,15 +23,7 @@ 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); -signals: - void cursorMove(); -}; -*/ + class Editor : public QMainWindow, private Ui::EditorWindow { Q_OBJECT public: @@ -66,12 +58,8 @@ public slots: void updateline(); protected: -// virtual void editorKeyPressEvent(QKeyEvent *ev); - void resizeEvent(QResizeEvent *); virtual void closeEvent (QCloseEvent * e); private: -// My_Edit *e; -// QTextEdit *msg; QLabel *position; QString fname; QString find_text; @@ -79,4 +67,4 @@ private: char HomeDir[255]; }; -#endif // QWERTY_H +#endif /* VLP_EDITOR */ diff --git a/src/edit/my_edit.h b/src/edit/my_edit.h index 3a319fa..0b3e68a 100644 --- a/src/edit/my_edit.h +++ b/src/edit/my_edit.h @@ -6,11 +6,11 @@ class My_Edit : public QTextEdit { Q_OBJECT public: - My_Edit(QWidget *parent = 0, const char *name = 0); -signals: - void cursorMove(); + My_Edit(QWidget *parent); protected: virtual void keyPressEvent(QKeyEvent*); +signals: + void cursorMove(); }; #endif /* VLP_EDITOR_AREA */ -- 2.30.2