From: Akiko Date: Fri, 4 Oct 2013 19:53:06 +0000 (+0200) Subject: - added text viewer component to editor (TextWindow similar to ImageWindow) X-Git-Url: http://community.linux-addicted.net/gitweb/?a=commitdiff_plain;h=c33df008462387182ea0d3093d67d1335f849775;p=qtinns.git - added text viewer component to editor (TextWindow similar to ImageWindow) - updated English and German language - small editor fixes for MainWindow and ImageWindow --- diff --git a/editor/CMakeLists.txt b/editor/CMakeLists.txt index f3f0415..fe3ac52 100644 --- a/editor/CMakeLists.txt +++ b/editor/CMakeLists.txt @@ -1,7 +1,7 @@ # Qt sources -set (E_SOURCES Main.cxx MainWindow.cxx ImageWindow.cxx) -set (E_HEADERS MainWindow.hxx ImageWindow.hxx) -set (E_UI_FILES MainWindow.ui ImageWindow.ui) +set (E_SOURCES Main.cxx MainWindow.cxx ImageWindow.cxx TextWindow.cxx) +set (E_HEADERS MainWindow.hxx ImageWindow.hxx TextWindow.hxx) +set (E_UI_FILES MainWindow.ui ImageWindow.ui TextWindow.ui) set (E_RES_FILES Resources.qrc) set (E_TS_FILES i18n_english.ts i18n_french.ts i18n_german.ts) diff --git a/editor/ImageWindow.cxx b/editor/ImageWindow.cxx index 4ac1561..24cd8c5 100644 --- a/editor/ImageWindow.cxx +++ b/editor/ImageWindow.cxx @@ -47,7 +47,7 @@ void ImageWindow::slotImageDiscard() emit sigImageIgnored(); } -void ImageWindow::slotViewImage(NCFile& entry, quint32 row) +void ImageWindow::slotImageView(NCFile& entry, quint32 row) { _entry = entry; _num = row; diff --git a/editor/ImageWindow.hxx b/editor/ImageWindow.hxx index 6a9370a..79ad1ce 100644 --- a/editor/ImageWindow.hxx +++ b/editor/ImageWindow.hxx @@ -29,7 +29,7 @@ public slots: void slotImageSave(); void slotImageDiscard(); - void slotViewImage(NCFile& entry, quint32 row); + void slotImageView(NCFile& entry, quint32 row); protected: // well well, you know, the protected stuff ... it's always the same diff --git a/editor/ImageWindow.ui b/editor/ImageWindow.ui index c2c1a60..4b83613 100644 --- a/editor/ImageWindow.ui +++ b/editor/ImageWindow.ui @@ -18,9 +18,6 @@ - - 3 - @@ -37,11 +34,14 @@ 0 0 - 794 - 572 + 782 + 530 - + + + 0 + @@ -58,98 +58,98 @@ - - - - - 0 - 0 - - - - - 0 - - - 0 - - - - - LAB-STATUS-NAME - - - - - - - - - - true - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - LAB-STATUS-SIZE - - - - - - - true - - - 0 - - - 16384 - - - - - - - X - - - - - - - true - - - 0 - - - 16384 - - - - - - + + + + + 0 + 0 + + + + + 0 + + + 0 + + + + + LAB-STATUS-NAME + + + + + + + + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + LAB-STATUS-SIZE + + + + + + + true + + + 0 + + + 16384 + + + + + + + X + + + + + + + true + + + 0 + + + 16384 + + + + + + diff --git a/editor/MainWindow.cxx b/editor/MainWindow.cxx index 7100be0..df5aa50 100644 --- a/editor/MainWindow.cxx +++ b/editor/MainWindow.cxx @@ -12,6 +12,7 @@ #include "ui_MainWindow.h" #include "filesystem/NCFilesystem.hxx" #include "ImageWindow.hxx" +#include "TextWindow.hxx" // --- internal typedefs --- @@ -33,13 +34,15 @@ const QString TableHeader("header size;position;compressed size;original size;na MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), _ui(new Ui::MainWindow), _translator(new QTranslator(this)), _settings(new QSettings("LinuxAddicted", "QTinNS Editor", this)), _vfs(new NCFilesystem), - _img(new ImageWindow(this)), _def_status(new QLabel) + _img(new ImageWindow(this)), _txt(new TextWindow(this)), _def_status(new QLabel) { _ui->setupUi(this); _ui->wid_table->setColumnCount(7); _ui->wid_table->setHorizontalHeaderLabels(TableHeader.split(";")); _ui->wid_table->setSelectionBehavior(QAbstractItemView::SelectRows); + _ui->wid_stack->addWidget(_img); + _ui->wid_stack->addWidget(_txt); _ui->wid_stack->setCurrentIndex(0); statusBar()->insertWidget(0, _def_status); @@ -77,9 +80,13 @@ MainWindow::~MainWindow() _img->setVisible(false); _ui->wid_stack->removeWidget(_img); + _txt->setVisible(false); + _ui->wid_stack->removeWidget(_txt); + statusBar()->removeWidget(_def_status); delete _def_status; + delete _txt; delete _img; delete _vfs; delete _settings; @@ -209,8 +216,18 @@ void MainWindow::slotFileImage() QTW *table = _ui->wid_table; NCFile entry = _vfs->fileGet(table->currentRow()); - _img->slotViewImage(entry, table->currentRow()); - _ui->wid_stack->setCurrentIndex(1); + _img->slotImageView(entry, table->currentRow()); + _ui->wid_stack->setCurrentWidget(_img); + setMode(Mode::Blocked); +} + +void MainWindow::slotFileText() +{ + QTW *table = _ui->wid_table; + NCFile entry = _vfs->fileGet(table->currentRow()); + + _txt->slotTextView(entry, table->currentRow()); + _ui->wid_stack->setCurrentWidget(_txt); setMode(Mode::Blocked); } @@ -271,6 +288,7 @@ void MainWindow::slotTableSelected() QTW *table = _ui->wid_table; NCFile entry = _vfs->fileGet(table->currentRow()); QImage image = QImage::fromData(entry.oData()); + QString text = entry.name(); setMode(Mode::Selected); @@ -288,6 +306,13 @@ void MainWindow::slotTableSelected() _ui->act_file_image->setEnabled(false); else _ui->act_file_image->setEnabled(true); + + if (text.contains(".def", Qt::CaseInsensitive) || text.contains(".fx", Qt::CaseInsensitive) + || text.contains(".ini", Qt::CaseInsensitive) || text.contains(".txt", Qt::CaseInsensitive) + || text.contains(".tsc", Qt::CaseInsensitive)) + _ui->act_file_text->setEnabled(true); + else + _ui->act_file_image->setEnabled(false); } void MainWindow::slotTableChange(qint32 row) @@ -596,7 +621,7 @@ void MainWindow::slotTableRemove(quint32 row) setMode(Mode::Edited); } -void MainWindow::slotImageIgnored() +void MainWindow::slotTableIgnored() { _ui->wid_stack->setCurrentIndex(0); setMode(Mode::Edited); @@ -682,6 +707,7 @@ void MainWindow::setMode(const Mode mode) _ui->act_file_conv_win->setEnabled(false); _ui->act_file_conv_lin->setEnabled(false); _ui->act_file_image->setEnabled(false); + _ui->act_file_text->setEnabled(false); switch (mode) { @@ -771,6 +797,8 @@ void MainWindow::setupActions() this, SLOT(slotFileConvLin())); connect(_ui->act_file_image, SIGNAL(triggered()), this, SLOT(slotFileImage())); + connect(_ui->act_file_text, SIGNAL(triggered()), + this, SLOT(slotFileText())); connect(_ui->act_lang_english, SIGNAL(triggered()), this, SLOT(slotLangEnglish())); @@ -812,7 +840,13 @@ void MainWindow::setupActions() connect(_img, SIGNAL(sigImageUpdate(NCFile&, quint32)), this, SLOT(slotTableReplace(NCFile&, quint32))); connect(_img, SIGNAL(sigImageIgnored()), - this, SLOT(slotImageIgnored())); + this, SLOT(slotTableIgnored())); + + // text viewer connections + connect(_txt, SIGNAL(sigTextUpdate(NCFile&, quint32)), + this, SLOT(slotTableIgnored())); + connect(_txt, SIGNAL(sigTextIgnored()), + this, SLOT(slotTableIgnored())); // context menus for the QTableWidget ctx_sep1->setSeparator(true); @@ -833,4 +867,5 @@ void MainWindow::setupActions() table->addAction(_ui->act_file_conv_lin); table->addAction(ctx_sep4); table->addAction(_ui->act_file_image); + table->addAction(_ui->act_file_text); } diff --git a/editor/MainWindow.hxx b/editor/MainWindow.hxx index 63361da..fae4d86 100644 --- a/editor/MainWindow.hxx +++ b/editor/MainWindow.hxx @@ -13,6 +13,7 @@ class QTranslator; class NCFile; class NCFilesystem; class ImageWindow; +class TextWindow; class MainWindow : public QMainWindow { Q_OBJECT @@ -54,6 +55,7 @@ public slots: void slotFileConvWin(); void slotFileConvLin(); void slotFileImage(); + void slotFileText(); void slotLangEnglish(); void slotLangFrench(); @@ -75,8 +77,7 @@ public slots: void slotTableAdd(NCFile& entry, quint32 row); void slotTableReplace(NCFile& entry, quint32 row); void slotTableRemove(quint32 row); - - void slotImageIgnored(); + void slotTableIgnored(); protected: // protected stuff @@ -91,6 +92,7 @@ private: QSettings *_settings; NCFilesystem *_vfs; ImageWindow *_img; + TextWindow *_txt; QLabel *_def_status; QString _filename; }; diff --git a/editor/MainWindow.ui b/editor/MainWindow.ui index 51b0dd4..4c86a90 100644 --- a/editor/MainWindow.ui +++ b/editor/MainWindow.ui @@ -117,6 +117,7 @@ + @@ -239,6 +240,11 @@ ME-FILE-IMAGE + + + ME-FILE-TEXT + + diff --git a/editor/TextWindow.cxx b/editor/TextWindow.cxx new file mode 100644 index 0000000..fc74001 --- /dev/null +++ b/editor/TextWindow.cxx @@ -0,0 +1,85 @@ +#include +#include "TextWindow.hxx" +#include "ui_TextWindow.h" + +// --- constructors and deconstructors --- + +TextWindow::TextWindow(QWidget *parent) +: QMainWindow(parent), _ui(new Ui::TextWindow), _num(0) +{ + _ui->setupUi(this); + + setupActions(); + setMode(Mode::Fresh); +} + +TextWindow::~TextWindow() +{ + delete _ui; +} + +// --- public slots --- + +void TextWindow::slotTextSave() +{ + _entry.setOData(_ui->ed_text->toPlainText().toLocal8Bit()); + _entry.setOSize(_ui->ed_text->toPlainText().toLocal8Bit().size()); + _entry.setCSize(_entry.cData().size()); + _entry.setName(_ui->ed_name->text()); + _entry.setNameLength(_entry.name().size() + 1); + _entry.setHSize(_entry.headerSize() + _entry.nameLength()); + + emit sigTextUpdate(_entry, _num); +} + +void TextWindow::slotTextDiscard() +{ + _entry = NCFile(); + _num = 0; + _ui->ed_text->clear(); + + emit sigTextIgnored(); +} + +void TextWindow::slotTextView(NCFile& entry, quint32 row) +{ + _entry = entry; + _num = row; + _ui->ed_text->setPlainText(entry.oData()); + _ui->ed_name->setText(entry.name()); + _ui->ed_lines->setText(QString::number(_ui->ed_text->document()->lineCount())); + _ui->ed_size->setText(QString::number(_ui->ed_text->toPlainText().size())); +} + +// --- protected methods --- + +void TextWindow::changeEvent(QEvent *event) +{ + if (event->type() == QEvent::LanguageChange) + _ui->retranslateUi(this); + else + QMainWindow::changeEvent(event); +} + +void TextWindow::setMode(const Mode mode) +{ + switch (mode) + { + case Mode::Edited: + _ui->act_text_save->setEnabled(true); + + break; + + case Mode::Fresh: + default: + _ui->act_text_save->setEnabled(false); + } +} + +void TextWindow::setupActions() +{ + connect(_ui->act_text_save, SIGNAL(triggered()), + this, SLOT(slotTextSave())); + connect(_ui->act_text_cancel, SIGNAL(triggered()), + this, SLOT(slotTextDiscard())); +} diff --git a/editor/TextWindow.hxx b/editor/TextWindow.hxx new file mode 100644 index 0000000..a5b0845 --- /dev/null +++ b/editor/TextWindow.hxx @@ -0,0 +1,43 @@ +#pragma once + +#include +#include "filesystem/NCFile.hxx" + +namespace Ui +{ + class TextWindow; +} + +class TextWindow : public QMainWindow { + Q_OBJECT +signals: + void sigTextUpdate(NCFile& entry, quint32 row) const; + void sigTextIgnored() const; + +public: + // internal typedefs + enum class Mode : quint8 { + Fresh, + Edited + }; + + // constructors and deconstructors + explicit TextWindow(QWidget *parent = 0); + virtual ~TextWindow(); + +public slots: + void slotTextSave(); + void slotTextDiscard(); + + void slotTextView(NCFile& entry, quint32 row); + +protected: + virtual void changeEvent(QEvent *event); + void setMode(const Mode mode = Mode::Fresh); + void setupActions(); + +private: + Ui::TextWindow *_ui; + NCFile _entry; + quint32 _num; +}; diff --git a/editor/TextWindow.ui b/editor/TextWindow.ui new file mode 100644 index 0000000..349800f --- /dev/null +++ b/editor/TextWindow.ui @@ -0,0 +1,186 @@ + + + TextWindow + + + + 0 + 0 + 800 + 600 + + + + FRM-TEXT + + + + + + + + + + QFrame::NoFrame + + + QFrame::Plain + + + true + + + + + 0 + 0 + 782 + 530 + + + + + 0 + + + + + + + + true + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> + + + + + + + + + + + + 0 + + + + + LAB-TEXT-NAME + + + + + + + + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + LAB-TEXT-LINES + + + + + + + + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + LAB-TEXT-SIZE + + + + + + + + + + true + + + + + + + + + + + + 0 + 0 + 800 + 22 + + + + + MM-TEXT + + + + + + + + + + ME-TEXT-SAVE + + + + + ME-TEXT-CANCEL + + + + + + diff --git a/editor/i18n_english.ts b/editor/i18n_english.ts index 90bf6c4..9cb1f64 100644 --- a/editor/i18n_english.ts +++ b/editor/i18n_english.ts @@ -6,30 +6,30 @@ FRM-IMAGE - QTinNS Editor Viewer + QTinNS Editor Image Viewer - + LAB-STATUS-NAME Image name: - + LAB-STATUS-SIZE Image size: - + MM-IMAGE Image - + ME-IMAGE-SAVE Save changes - + ME-IMAGE-CANCEL Discard changes @@ -38,7 +38,6 @@ MainWindow - FRM-MAINWINDOW QTinNS Editor @@ -73,194 +72,199 @@ File - + ME-APP-QUIT Quit - + ME-APP-NEW New virtual filesystem - + ME-APP-OPEN Open virtual filesystem ... - + ME-APP-SAVE Save virtual filesystem - + ME-APP-SAVEAS Save virtual filesystem as ... - + ME-ABOUT-APP About QTinNS Editor ... - + ME-ABOUT-QT About Qt framework ... - + ME-LANG-ENGLISH English - + ME-LANG-FRENCH French - + ME-LANG-GERMAN German - + ME-STYLE-DEFAULT System Default - + ME-STYLE-WINDOWS ME-STYLE-CDE Windows - + ME-STYLE-GTK ME-STYLE-CLEANLOOKS GTK+ - + ME-STYLE-FUSION ME-STYLE-PLASTIQUE Fusion - + ME-FILE-ADD Add file(s) ... - + ME-FILE-REPLACE Replace file ... - + ME-FILE-REMOVE Remove file ... - + ME-FILE-SAVE-PLAIN Save plain file as ... - + ME-FILE-SAVE-PAK Save PAK file as ... - + ME-FILE-SAVE-ZLIB Save ZLIB file as ... - + ME-FILE-CONV-WIN Convert UNIX path to Windows path - + ME-FILE-CONV-LIN Convert Windows path to UNIX path - + ME-FILE-IMAGE View image ... - - + + ME-FILE-TEXT + View text ... + + + + DIA-OPEN-FILE Open files ... - - + + FLT-FILE-VFS DIA-SAVE-FILE Neocron VFS file (*.vfs *.pak) - + DIA-OPEN-VFS Open virtual filesystem ... - + DIA-SAVE-VFS Save virtual filesystem ... - - + + FLT-FILE-ANY File (*.*) - + DIA-SAVE-PLAIN Save file ... - + FLT-FILE-PLAIN File (*.*) - + DIA-SAVE-PAK Save PAK file ... - + FLT-FILE-PAK Neocron PAK file (*.pak) - + DIA-SAVE-ZLIB Save ZLIB file ... - + FLT-FILE-ZLIB ZLIB file (*.z) - + MSG-UPD-FILE Virtual filesystem - + MSG-UPD-WITH with - + MSG-UPD-ENTRIES entries @@ -284,4 +288,42 @@ Discard changes + + TextWindow + + + FRM-TEXT + QTinNS Editor Text Viewer + + + + LAB-TEXT-NAME + Text name: + + + + LAB-TEXT-LINES + Lines: + + + + LAB-TEXT-SIZE + Size: + + + + MM-TEXT + Text + + + + ME-TEXT-SAVE + Save text + + + + ME-TEXT-CANCEL + Discard text + + diff --git a/editor/i18n_french.ts b/editor/i18n_french.ts index 63c8560..487db01 100644 --- a/editor/i18n_french.ts +++ b/editor/i18n_french.ts @@ -9,27 +9,27 @@ - + LAB-STATUS-NAME - + LAB-STATUS-SIZE - + MM-IMAGE - + ME-IMAGE-SAVE - + ME-IMAGE-CANCEL @@ -38,7 +38,6 @@ MainWindow - FRM-MAINWINDOW @@ -73,196 +72,239 @@ - + ME-APP-QUIT - + ME-APP-NEW - + ME-APP-OPEN - + ME-APP-SAVE - + ME-APP-SAVEAS - + ME-ABOUT-APP - + ME-ABOUT-QT - + ME-LANG-ENGLISH - + ME-LANG-FRENCH - + ME-LANG-GERMAN - + ME-STYLE-DEFAULT - + ME-STYLE-WINDOWS ME-STYLE-CDE - + ME-STYLE-GTK ME-STYLE-CLEANLOOKS - + ME-STYLE-FUSION ME-STYLE-PLASTIQUE - + ME-FILE-ADD - + ME-FILE-REPLACE - + ME-FILE-REMOVE - + ME-FILE-SAVE-PLAIN - + ME-FILE-SAVE-PAK - + ME-FILE-SAVE-ZLIB - + ME-FILE-CONV-WIN - + ME-FILE-CONV-LIN - + ME-FILE-IMAGE - - + + ME-FILE-TEXT + + + + + DIA-OPEN-FILE - - + + FLT-FILE-VFS DIA-SAVE-FILE - + DIA-OPEN-VFS - + DIA-SAVE-VFS - - + + FLT-FILE-ANY - + DIA-SAVE-PLAIN - + FLT-FILE-PLAIN - + DIA-SAVE-PAK - + FLT-FILE-PAK - + DIA-SAVE-ZLIB - + FLT-FILE-ZLIB - + MSG-UPD-FILE - + MSG-UPD-WITH - + MSG-UPD-ENTRIES + + TextWindow + + + FRM-TEXT + + + + + LAB-TEXT-NAME + + + + + LAB-TEXT-LINES + + + + + LAB-TEXT-SIZE + + + + + MM-TEXT + + + + + ME-TEXT-SAVE + + + + + ME-TEXT-CANCEL + + + diff --git a/editor/i18n_german.ts b/editor/i18n_german.ts index dc9c5d0..33b8481 100644 --- a/editor/i18n_german.ts +++ b/editor/i18n_german.ts @@ -6,30 +6,30 @@ FRM-IMAGE - QTinNS Editor Viewer + QTinNS Editor Image Viewer - + LAB-STATUS-NAME - Bildname: + Bilddateiname: - + LAB-STATUS-SIZE Bildgröße: - + MM-IMAGE Bild - + ME-IMAGE-SAVE Speichere Änderungen - + ME-IMAGE-CANCEL Verwerfe Änderungen @@ -38,7 +38,6 @@ MainWindow - FRM-MAINWINDOW QTinNS Editor @@ -73,194 +72,199 @@ Datei - + ME-APP-QUIT Beenden - + ME-APP-NEW Neues virtuelles Dateisystem - + ME-APP-OPEN Virtuelles Dateisystem öffnen ... - + ME-APP-SAVE Virtuelles Dateisystem speichern - + ME-APP-SAVEAS Virtuelles Dateisystem speichern als ... - + ME-ABOUT-APP Über QTinNS Editor ... - + ME-ABOUT-QT Über Qt Framework ... - + ME-LANG-ENGLISH Englisch - + ME-LANG-FRENCH Französisch - + ME-LANG-GERMAN Deutsch - + ME-STYLE-DEFAULT System Standard - + ME-STYLE-WINDOWS ME-STYLE-CDE Windows - + ME-STYLE-GTK ME-STYLE-CLEANLOOKS GTK+ - + ME-STYLE-FUSION ME-STYLE-PLASTIQUE Fusion - + ME-FILE-ADD Füge Datei(en) hinzu ... - + ME-FILE-REPLACE Ersetze Datei ... - + ME-FILE-REMOVE Entferne Datei ... - + ME-FILE-SAVE-PLAIN Speichere normale Datei als ... - + ME-FILE-SAVE-PAK Speichere PAK Datei als ... - + ME-FILE-SAVE-ZLIB Speichere ZLIB Datei als ... - + ME-FILE-CONV-WIN Konvertiere UNIX Pfad nach Windows - + ME-FILE-CONV-LIN Konvertiere Windows Pfad nach UNIX - + ME-FILE-IMAGE Bild anzeigen ... - - + + ME-FILE-TEXT + Text anzeigen ... + + + + DIA-OPEN-FILE Datei öffnen ... - - + + FLT-FILE-VFS DIA-SAVE-FILE Neocron VFS Datei (*.vfs *.pak) - + DIA-OPEN-VFS Virtuelles Dateisystem öffnen ... - + DIA-SAVE-VFS Virtuelles Dateisystem speichern ... - - + + FLT-FILE-ANY Datei (*.*) - + DIA-SAVE-PLAIN Datei speichern ... - + FLT-FILE-PLAIN Datei (*.*) - + DIA-SAVE-PAK PAK Datei speichern ... - + FLT-FILE-PAK Neocron PAK Datei (*.pak) - + DIA-SAVE-ZLIB ZLIB Datei speichern ... - + FLT-FILE-ZLIB ZLIB Datei (*.z) - + MSG-UPD-FILE Virtuelles Dateisystem - + MSG-UPD-WITH mit - + MSG-UPD-ENTRIES Einträgen @@ -284,4 +288,43 @@ Verwerfe Änderungen + + TextWindow + + + FRM-TEXT + QTinNS Editor Text Viewer + + + + LAB-TEXT-NAME + Textdateiname: + + + + LAB-TEXT-LINES + Zeilen: + + + + LAB-TEXT-SIZE + Größe: + + + + MM-TEXT + Text + + + + ME-TEXT-SAVE + Speichere Änderungen + + + + ME-TEXT-CANCEL + Verwerfe Änderungen + Text verwerfern + +