From 82e45b6d632a77d7545141868b7a81e67897d164 Mon Sep 17 00:00:00 2001 From: cemycc Date: Wed, 3 Aug 2011 23:08:56 +0300 Subject: [PATCH] Changed: #1307 Added Phrase editor files and base functions --- .../translation_manager/editor_phrase.cpp | 116 ++++++++++++++++++ .../translation_manager/editor_phrase.cpp.txt | 53 -------- .../{editor_phrase.h.txt => editor_phrase.h} | 6 + .../translation_manager/editor_worksheet.cpp | 10 +- .../translation_manager/editor_worksheet.h | 2 - .../translation_manager_editor.h | 10 ++ .../translation_manager_main_window.cpp | 24 +++- .../translation_manager_main_window.h | 3 +- 8 files changed, 158 insertions(+), 66 deletions(-) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.cpp delete mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.cpp.txt rename code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/{editor_phrase.h.txt => editor_phrase.h} (86%) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.cpp new file mode 100644 index 000000000..4036f8425 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.cpp @@ -0,0 +1,116 @@ +// Translation Manager Plugin - OVQT Plugin +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Emanuel Costea +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Nel includes +#include "nel/misc/path.h" +#include "nel/misc/diff_tool.h" + +// Qt includes +#include +#include +#include +#include + +// Project includes +#include "editor_phrase.h" +#include "translation_manager_constants.h" + +using namespace std; + +namespace Plugin { + +void CEditorPhrase::open(QString filename) +{ + vector phrases; + if(readPhraseFile(filename.toStdString(), phrases, false)) + { + text_edit = new QTextEdit(); + // read the file content + QFile file(filename); + QTextStream in(&file); + // set the file content to the text edit + QString content = in.readAll(); + text_edit->setText(content); + // window settings + setCurrentFile(filename); + setAttribute(Qt::WA_DeleteOnClose); + setWidget(text_edit); + editor_type = Constants::ED_PHRASE; + current_file = filename; + } else { + QErrorMessage error; + error.showMessage("This file is not a phrase file."); + error.exec(); + } +} + +void CEditorPhrase::activateWindow() +{ + showMaximized(); +} + +void CEditorPhrase::save() +{ + QFile file(current_file); + QTextStream out(&file); + out<toPlainText(); + setCurrentFile(current_file); +} + +void CEditorPhrase::saveAs(QString filename) +{ + QFile file(filename); + QTextStream out(&file); + out<toPlainText(); + current_file = filename; + setCurrentFile(current_file); +} + +void CEditorPhrase::closeEvent(QCloseEvent *event) +{ + if(isWindowModified()) + { + QMessageBox msgBox; + msgBox.setText("The document has been modified."); + msgBox.setInformativeText("Do you want to save your changes?"); + msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); + msgBox.setDefaultButton(QMessageBox::Save); + int ret = msgBox.exec(); + switch (ret) + { + case QMessageBox::Save: + save(); + event->accept(); + close(); + break; + case QMessageBox::Discard: + event->accept(); + close(); + break; + case QMessageBox::Cancel: + event->ignore(); + break; + default: + break; + } + } else { + event->accept(); + close(); + } +} + +} \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.cpp.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.cpp.txt deleted file mode 100644 index 83d360d8a..000000000 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.cpp.txt +++ /dev/null @@ -1,53 +0,0 @@ -// Translation Manager Plugin - OVQT Plugin -// Copyright (C) 2010 Winch Gate Property Limited -// Copyright (C) 2011 Emanuel Costea -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -// Qt includes -#include -#include -#include -#include - -// Project includes -#include "editor_phrase.h" -#include "translation_manager_constants.h" - -using namespace std; - -namespace Plugin { - -void CEditorPhrase::open(QString filename) -{ - -} - -void CEditorPhrase::activateWindow() -{ - -} - -void CEditorPhrase::save() -{ - -} - -void CEditorPhrase::saveAs(QString filename) -{ - -} - - -} \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.h.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.h similarity index 86% rename from code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.h.txt rename to code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.h index 539314eaf..21152ad16 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.h.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.h @@ -20,11 +20,14 @@ // Qt includes #include +#include +#include #include #include #include #include #include +#include // Project includes #include "translation_manager_editor.h" @@ -34,6 +37,8 @@ namespace Plugin { class CEditorPhrase : public CEditor { Q_OBJECT +private: + QTextEdit *text_edit; public: CEditorPhrase(QMdiArea* parent) : CEditor(parent) {} CEditorPhrase() : CEditor() {} @@ -41,6 +46,7 @@ public: void save(); void saveAs(QString filename); void activateWindow(); + void closeEvent(QCloseEvent *event); }; } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.cpp index 2c7261805..39b86d76a 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.cpp @@ -202,6 +202,7 @@ void CEditorWorksheet::saveAs(QString filename) } ucstring s = prepareExcelSheet(new_file); NLMISC::CI18N::writeTextFile(filename.toStdString(), s, false); + current_file = filename; setCurrentFile(filename); } @@ -484,15 +485,6 @@ void CEditorWorksheet::mergeWorksheetFile(QString filename) } } -void CEditorWorksheet::setCurrentFile(QString filename) -{ - QFileInfo *file = new QFileInfo(filename); - current_file = file->canonicalFilePath(); - setWindowModified(false); - setWindowTitle(file->fileName() + "[*]"); - setWindowFilePath(current_file); -} - void CEditorWorksheet::closeEvent(QCloseEvent *event) { if(isWindowModified()) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.h index 983dba4bc..a124188bc 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.h @@ -65,8 +65,6 @@ private Q_SLOTS: void worksheetEditorChanged(QTableWidgetItem * item); void insertRow(); void deleteRow(); -private: - void setCurrentFile(QString filename); }; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_editor.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_editor.h index 767dd90de..39ef74f2a 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_editor.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_editor.h @@ -23,6 +23,7 @@ #include #include #include +#include namespace Plugin { @@ -52,6 +53,15 @@ public: { current_stack = stack; } + void setCurrentFile(QString filename) + { + QFileInfo *file = new QFileInfo(filename); + current_file = file->canonicalFilePath(); + setWindowModified(false); + setWindowTitle(file->fileName() + "[*]"); + setWindowFilePath(current_file); + } + }; } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.cpp index e6fa9508a..f12c6a830 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.cpp @@ -217,6 +217,14 @@ void CMainWindow::open() new_window->open(file_name); new_window->activateWindow(); } + // phrase editor + if(isPhraseEditor(file_name)) + { + CEditorPhrase *new_window = new CEditorPhrase(_ui.mdiArea); + new_window->setUndoStack(m_undoStack); + new_window->open(file_name); + new_window->activateWindow(); + } #ifndef QT_NO_CURSOR QApplication::restoreOverrideCursor(); #endif @@ -559,12 +567,26 @@ bool CMainWindow::isWorksheetEditor(QString filename) STRING_MANAGER::TWorksheet wk_file; if(loadExcelSheet(filename.toStdString(), wk_file, true) == true) { - return true; + if(wk_file.ColCount > 1) + return true; + else + return false; } else { return false; } } +bool CMainWindow::isPhraseEditor(QString filename) +{ + vector phrases; + if(readPhraseFile(filename.toStdString(), phrases, false)) + { + return true; + } else { + return false; + } +} + bool CCoreListener::closeMainWindow() const { return true; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.h index bd21f698d..c58ce9826 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.h @@ -45,6 +45,7 @@ #include "ui_translation_manager_main_window.h" #include #include "editor_worksheet.h" +#include "editor_phrase.h" class QWidget; @@ -101,7 +102,7 @@ private: // Worksheet specific functions CEditorWorksheet* getEditorByWorksheetType(const QString &type); bool isWorksheetEditor(QString filename); - + bool isPhraseEditor(QString filename); };