From: Akiko Date: Fri, 11 Oct 2013 08:19:15 +0000 (+0200) Subject: - fixed a connection/logic bug in the editor MainWindow X-Git-Url: http://community.linux-addicted.net/gitweb/?a=commitdiff_plain;h=a850eb594e626934d38da3bcbfe19b827661586b;p=qtinns.git - fixed a connection/logic bug in the editor MainWindow - the editor TextWindow now works like a real text editor - fixed a really ulgy bug in NCFile (qCompress/qDecompress looks broken in Qt5) - updated language files (English and German) - fixed two stupid bugs in NCFilesystem --- diff --git a/editor/MainWindow.cxx b/editor/MainWindow.cxx index b21bb5e..796c333 100644 --- a/editor/MainWindow.cxx +++ b/editor/MainWindow.cxx @@ -390,6 +390,9 @@ void MainWindow::slotTableStatus(quint32 from_row, quint32 to_row, ColType cols) // table item if (to_row != static_cast(table->rowCount())) { + disconnect(table, SIGNAL(cellChanged(qint32, qint32)), + this, SLOT(slotTableChange(qint32))); + table->setRowCount(to_row); for (quint32 row = 0; row < to_row; ++row) { @@ -481,9 +484,6 @@ void MainWindow::slotTableStatus(quint32 from_row, quint32 to_row, ColType cols) it6->setBackground(Grey); } - disconnect(table, SIGNAL(cellChanged(qint32, qint32)), - this, SLOT(slotTableChange(qint32))); - table->setItem(row, 0, it0); table->setItem(row, 1, it1); table->setItem(row, 2, it2); @@ -491,10 +491,9 @@ void MainWindow::slotTableStatus(quint32 from_row, quint32 to_row, ColType cols) table->setItem(row, 4, it4); table->setItem(row, 5, it5); table->setItem(row, 6, it6); - - connect(table, SIGNAL(cellChanged(qint32, qint32)), - this, SLOT(slotTableChange(qint32))); } + connect(table, SIGNAL(cellChanged(qint32, qint32)), + this, SLOT(slotTableChange(qint32))); } else { @@ -621,6 +620,8 @@ void MainWindow::slotTableAdd(NCFile& entry, quint32 row) connect(table, SIGNAL(cellChanged(qint32, qint32)), this, SLOT(slotTableChange(qint32))); + + setMode(Mode::Edited); } void MainWindow::slotTableReplace(NCFile& entry, quint32 row) @@ -664,7 +665,12 @@ void MainWindow::slotTableRemove(quint32 row) setMode(Mode::Edited); } -void MainWindow::slotTableIgnored() +void MainWindow::slotEntryReplace(NCFile& entry, quint32 row) +{ + _vfs->fileReplace(entry, row); +} + +void MainWindow::slotEntryIgnore() { _ui->wid_stack->setCurrentIndex(0); setMode(Mode::Edited); @@ -887,27 +893,27 @@ void MainWindow::setupActions() // image viewer connections connect(_img, SIGNAL(sigImageUpdate(NCFile&, quint32)), - this, SLOT(slotTableReplace(NCFile&, quint32))); + this, SLOT(slotEntryReplace(NCFile&, quint32))); connect(_img, SIGNAL(sigImageIgnored()), - this, SLOT(slotTableIgnored())); + this, SLOT(slotEntryIgnore())); // text viewer connections connect(_txt, SIGNAL(sigTextUpdate(NCFile&, quint32)), - this, SLOT(slotTableReplace(NCFile&, quint32))); + this, SLOT(slotEntryReplace(NCFile&, quint32))); connect(_txt, SIGNAL(sigTextIgnored()), - this, SLOT(slotTableIgnored())); + this, SLOT(slotEntryIgnore())); // dat viewer connections connect(_dat, SIGNAL(sigDatUpdate(NCFile&, quint32)), - this, SLOT(slotTableReplace(NCFile&, quint32))); + this, SLOT(slotEntryReplace(NCFile&, quint32))); connect(_dat, SIGNAL(sigDatIgnored()), - this, SLOT(slotTableIgnored())); + this, SLOT(slotEntryIgnore())); // object viewer connections connect(_obj, SIGNAL(sigObjectUpdate(NCFile&, quint32)), - this, SLOT(slotTableReplace(NCFile&, quint32))); + this, SLOT(slotEntryReplace(NCFile&, quint32))); connect(_obj, SIGNAL(sigObjectIgnored()), - this, SLOT(slotTableIgnored())); + this, SLOT(slotEntryIgnore())); // context menus for the QTableWidget ctx_sep1->setSeparator(true); diff --git a/editor/MainWindow.hxx b/editor/MainWindow.hxx index 87ac81d..dded375 100644 --- a/editor/MainWindow.hxx +++ b/editor/MainWindow.hxx @@ -81,7 +81,9 @@ public slots: void slotTableAdd(NCFile& entry, quint32 row); void slotTableReplace(NCFile& entry, quint32 row); void slotTableRemove(quint32 row); - void slotTableIgnored(); + + void slotEntryReplace(NCFile& entry, quint32 row); + void slotEntryIgnore(); protected: // protected stuff diff --git a/editor/TextWindow.cxx b/editor/TextWindow.cxx index 22e1bbf..3ba7bff 100644 --- a/editor/TextWindow.cxx +++ b/editor/TextWindow.cxx @@ -8,8 +8,7 @@ // --- constructors and deconstructors --- TextWindow::TextWindow(QWidget *parent) -: QMainWindow(parent), _ui(new Ui::TextWindow), _def(new DefSyntax(this)), _fx(new FxSyntax(this)), - _ini(new IniSyntax(this)), _num(0) +: QMainWindow(parent), _ui(new Ui::TextWindow), _syn(0), _num(0) { _ui->setupUi(this); @@ -19,9 +18,7 @@ TextWindow::TextWindow(QWidget *parent) TextWindow::~TextWindow() { - delete _ini; - delete _fx; - delete _def; + delete _syn; delete _ui; } @@ -29,14 +26,16 @@ TextWindow::~TextWindow() void TextWindow::slotTextSave() { - _entry.setOData(_ui->ed_text->toPlainText().toLocal8Bit()); - _entry.setOSize(_ui->ed_text->toPlainText().toLocal8Bit().size()); + _entry.setOData(_ui->ed_text->toPlainText().toLatin1()); + _entry.setOSize(_ui->ed_text->toPlainText().toLatin1().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); + + setMode(Mode::Fresh); } void TextWindow::slotTextDiscard() @@ -46,26 +45,40 @@ void TextWindow::slotTextDiscard() _ui->ed_text->clear(); emit sigTextIgnored(); + + setMode(Mode::Fresh); +} + +void TextWindow::slotEditDelete() +{ + _ui->ed_text->textCursor().removeSelectedText(); } void TextWindow::slotTextView(NCFile& entry, quint32 row) { _entry = entry; _num = row; - _def->setDocument(0); + _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())); + delete _syn; + if (entry.name().contains(".def", Qt::CaseInsensitive)) - _def->setDocument(_ui->ed_text->document()); + _syn = new DefSyntax(_ui->ed_text->document()); if (entry.name().contains(".fx", Qt::CaseInsensitive)) - _fx->setDocument(_ui->ed_text->document()); + _syn = new FxSyntax(_ui->ed_text->document()); if (entry.name().contains(".ini", Qt::CaseInsensitive)) - _ini->setDocument(_ui->ed_text->document()); + _syn = new IniSyntax(_ui->ed_text->document()); +} + +void TextWindow::slotTextChanged() +{ + setMode(Mode::Edited); } // --- protected methods --- @@ -95,8 +108,48 @@ void TextWindow::setMode(const Mode mode) void TextWindow::setupActions() { + QAction *ctx_sep1 = new QAction(this); + QAction *ctx_sep2 = new QAction(this); + + // file stuff connect(_ui->act_text_save, SIGNAL(triggered()), this, SLOT(slotTextSave())); connect(_ui->act_text_cancel, SIGNAL(triggered()), this, SLOT(slotTextDiscard())); + + // edit stuff + connect(_ui->act_edit_undo, SIGNAL(triggered()), + _ui->ed_text, SLOT(undo())); + connect(_ui->act_edit_redo, SIGNAL(triggered()), + _ui->ed_text, SLOT(redo())); + connect(_ui->act_edit_cut, SIGNAL(triggered()), + _ui->ed_text, SLOT(cut())); + connect(_ui->act_edit_copy, SIGNAL(triggered()), + _ui->ed_text, SLOT(copy())); + connect(_ui->act_edit_insert, SIGNAL(triggered()), + _ui->ed_text, SLOT(paste())); + connect(_ui->act_edit_delete, SIGNAL(triggered()), + this, SLOT(slotEditDelete())); + connect(_ui->act_edit_selall, SIGNAL(triggered()), + _ui->ed_text, SLOT(selectAll())); + + // recognize changes + connect(_ui->ed_text, SIGNAL(textChanged()), + this, SLOT(slotTextChanged())); + + // context menu + ctx_sep1->setSeparator(true); + ctx_sep2->setSeparator(true); + + _ui->ed_text->addAction(_ui->act_edit_undo); + _ui->ed_text->addAction(_ui->act_edit_redo); + _ui->ed_text->addAction(ctx_sep1); + _ui->ed_text->addAction(_ui->act_edit_cut); + _ui->ed_text->addAction(_ui->act_edit_copy); + _ui->ed_text->addAction(_ui->act_edit_insert); + _ui->ed_text->addAction(_ui->act_edit_delete); + _ui->ed_text->addAction(_ui->act_edit_selall); + _ui->ed_text->addAction(ctx_sep2); + _ui->ed_text->addAction(_ui->act_text_save); + _ui->ed_text->addAction(_ui->act_text_cancel); } diff --git a/editor/TextWindow.hxx b/editor/TextWindow.hxx index e4823f8..f6b09e7 100644 --- a/editor/TextWindow.hxx +++ b/editor/TextWindow.hxx @@ -7,9 +7,7 @@ namespace Ui { class TextWindow; } -class DefSyntax; -class FxSyntax; -class IniSyntax; +class QSyntaxHighlighter; class TextWindow : public QMainWindow { Q_OBJECT @@ -32,7 +30,10 @@ public slots: void slotTextSave(); void slotTextDiscard(); + void slotEditDelete(); + void slotTextView(NCFile& entry, quint32 row); + void slotTextChanged(); protected: virtual void changeEvent(QEvent *event); @@ -41,9 +42,7 @@ protected: private: Ui::TextWindow *_ui; - DefSyntax *_def; - FxSyntax *_fx; - IniSyntax *_ini; + QSyntaxHighlighter *_syn; NCFile _entry; quint32 _num; }; diff --git a/editor/TextWindow.ui b/editor/TextWindow.ui index 349800f..c04d836 100644 --- a/editor/TextWindow.ui +++ b/editor/TextWindow.ui @@ -44,12 +44,12 @@ + + Qt::ActionsContextMenu + - - 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"> @@ -160,7 +160,7 @@ p, li { white-space: pre-wrap; } 22 - + MM-TEXT @@ -168,7 +168,21 @@ p, li { white-space: pre-wrap; } - + + + MM-EDIT + + + + + + + + + + + + @@ -180,6 +194,41 @@ p, li { white-space: pre-wrap; } ME-TEXT-CANCEL + + + ME-EDIT-UNDO + + + + + ME-EDIT-REDO + + + + + ME-EDIT-CUT + + + + + ME-EDIT-COPY + + + + + ME-EDIT-INSERT + + + + + ME-EDIT-DELETE + + + + + ME-EDIT-SELALL + + diff --git a/editor/i18n_english.ts b/editor/i18n_english.ts index a22b50c..4e912d6 100644 --- a/editor/i18n_english.ts +++ b/editor/i18n_english.ts @@ -16,12 +16,12 @@ ME-DAT-SAVE - Save dat changes + Save changes ME-DAT-CANCEL - Discard dat changes + Discard changes @@ -210,94 +210,94 @@ ME-FILE-IMAGE - View image ... + View image file ... ME-FILE-TEXT - View text ... + Edit text file ... ME-FILE-DAT - View dat ... + View dat file ... ME-FILE-OBJECT - View 3D object ... + View 3d object ... - - + + 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 @@ -317,12 +317,12 @@ ME-OBJECT-SAVE - Save 3D object changes + Save changes ME-OBJECT-CANCEL - Discard 3D object changes + Discard changes @@ -333,34 +333,74 @@ QTinNS Editor - Text Viewer - + LAB-TEXT-NAME Text name: - + LAB-TEXT-LINES Lines: - + LAB-TEXT-SIZE Size: - + MM-TEXT Text - + + MM-EDIT + Edit + + + ME-TEXT-SAVE - Save text + Save changes - + ME-TEXT-CANCEL - Discard text + Discard changes + + + + ME-EDIT-UNDO + Undo + + + + ME-EDIT-REDO + Redo + + + + ME-EDIT-CUT + Cut + + + + ME-EDIT-COPY + Copy + + + + ME-EDIT-INSERT + Insert + + + + ME-EDIT-DELETE + Delete + + + + ME-EDIT-SELALL + Select all diff --git a/editor/i18n_french.ts b/editor/i18n_french.ts index cab46ff..ced766a 100644 --- a/editor/i18n_french.ts +++ b/editor/i18n_french.ts @@ -228,76 +228,76 @@ - - + + 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 @@ -333,34 +333,74 @@ - + LAB-TEXT-NAME - + LAB-TEXT-LINES - + LAB-TEXT-SIZE - + MM-TEXT - + + MM-EDIT + + + + ME-TEXT-SAVE - + ME-TEXT-CANCEL + + + ME-EDIT-UNDO + + + + + ME-EDIT-REDO + + + + + ME-EDIT-CUT + + + + + ME-EDIT-COPY + + + + + ME-EDIT-INSERT + + + + + ME-EDIT-DELETE + + + + + ME-EDIT-SELALL + + diff --git a/editor/i18n_german.ts b/editor/i18n_german.ts index a1fddc6..6c3d912 100644 --- a/editor/i18n_german.ts +++ b/editor/i18n_german.ts @@ -16,12 +16,12 @@ ME-DAT-SAVE - Speichere Dat Änderungen + Speichere Änderungen ME-DAT-CANCEL - Verwerfe Dat Änderungen + Verwerfe Änderungen @@ -210,17 +210,17 @@ ME-FILE-IMAGE - Bild anzeigen ... + Bilddatei anzeigen ... ME-FILE-TEXT - Text anzeigen ... + Textdatei bearbeiten ... ME-FILE-DAT - Dat anzeigen ... + Datdatei anzeigen ... @@ -228,76 +228,76 @@ 3D Objekt 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 @@ -317,12 +317,12 @@ ME-OBJECT-SAVE - Speichere 3D Objekt Änderungen + Speichere Änderungen ME-OBJECT-CANCEL - Verwerfe 3D Objekt Änderungen + Verwerfe Änderungen @@ -333,35 +333,74 @@ QTinNS Editor - Text Viewer - + LAB-TEXT-NAME Textdateiname: - + LAB-TEXT-LINES Zeilen: - + LAB-TEXT-SIZE Größe: - + MM-TEXT Text - + + MM-EDIT + Bearbeiten + + + ME-TEXT-SAVE Speichere Änderungen - + ME-TEXT-CANCEL - Verwerfe Änderungen - Text verwerfern + Verwerfe Änderungen + + + + ME-EDIT-UNDO + Rückgängig + + + + ME-EDIT-REDO + Wiederherstellen + + + + ME-EDIT-CUT + Ausschneiden + + + + ME-EDIT-COPY + Kopieren + + + + ME-EDIT-INSERT + Einfügen + + + + ME-EDIT-DELETE + Löschen + + + + ME-EDIT-SELALL + Alles markieren diff --git a/engine/GLWidget.cxx b/engine/GLWidget.cxx index 0e1bb94..8895445 100644 --- a/engine/GLWidget.cxx +++ b/engine/GLWidget.cxx @@ -47,7 +47,7 @@ void GLWidget::paintGL() glVertexPointer(3, GL_FLOAT, 0, _vertices.constData()); glEnableClientState(GL_VERTEX_ARRAY); - for (quint32 i = 0; i < _vertices.count(); ++i) + for (qint32 i = 0; i < _vertices.count(); ++i) glDrawArrays(GL_TRIANGLE_FAN, i * 4, 4); } } @@ -81,7 +81,7 @@ void GLWidget::mouseMoveEvent(QMouseEvent *event) _last_pos = event->pos(); } -void GLWidget::mouseReleaseEvent(QMouseEvent *event) +void GLWidget::mouseReleaseEvent(QMouseEvent * /*event*/) { emit sigClicked(); } diff --git a/filesystem/NCFile.cxx b/filesystem/NCFile.cxx index ad0d369..6bf527d 100644 --- a/filesystem/NCFile.cxx +++ b/filesystem/NCFile.cxx @@ -1,4 +1,3 @@ -#include #include "filesystem/NCFile.hxx" /* @@ -165,17 +164,17 @@ QByteArray NCFile::cData() const void NCFile::setOData(const QByteArray& data) { - _cdata = qCompress(data, 9).mid(sizeof (quint32)); + _cdata = qCompress(data, 9).mid(sizeof (_csize)); } QByteArray NCFile::oData() const { - QByteArray size; - QDataStream stream(&size, QIODevice::WriteOnly); + // this is the only way it works, qCompress/qDecompress is broken! + QByteArray data(sizeof (_osize) + _cdata.size(), '\0'); - stream << _csize; + data.replace(sizeof (_osize),_csize, _cdata); - return qUncompress(size + _cdata); + return qUncompress(data); } // --- status methods --- diff --git a/filesystem/NCFilesystem.cxx b/filesystem/NCFilesystem.cxx index 3f08a61..f992cef 100644 --- a/filesystem/NCFilesystem.cxx +++ b/filesystem/NCFilesystem.cxx @@ -437,7 +437,7 @@ NCFile NCFilesystem::fileRemove(const quint32& index) void NCFilesystem::recalc(QVector& files) { - quint32 base_offset = 0; + quint32 base_offset = sizeof (id.VFS) + sizeof (quint32); quint32 csize_offset = 0; for (auto& f : files) @@ -666,7 +666,7 @@ quint32 NCFilesystem::vfsSaver(const QString& filename) const ofile.close(); - emit sigFileStatus(0, _files.count() - 1, ColType::None); + emit sigFileStatus(0, _files.count(), ColType::None); return _files.count(); }