From 75bc788c14e39f2d0643dae9818ca0eac2be72e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikko=20Syrj=C3=A4?= Date: Sun, 10 Mar 2019 00:23:41 +0200 Subject: Initial file open and save support. --- help/eng/menu.rst | 5 ++ help/fin/menu.rst | 5 ++ locale/symedit.en_GB.ts | 192 ++++++++++++++++++++++++++--------------------- locale/symedit.fi_FI.ts | 194 ++++++++++++++++++++++++++---------------------- locale/symedit.ts | 32 ++++++-- main.qml | 39 ++++++---- symedit.cpp | 61 ++++++++++++--- symedit.h | 5 +- 8 files changed, 327 insertions(+), 206 deletions(-) diff --git a/help/eng/menu.rst b/help/eng/menu.rst index a7e0606..8cc4a70 100644 --- a/help/eng/menu.rst +++ b/help/eng/menu.rst @@ -23,6 +23,11 @@ xxx xxx +Save as +^^^^^^^ + +xxx + |exit image| Exit ^^^^^^^^^^^^^^^^^ diff --git a/help/fin/menu.rst b/help/fin/menu.rst index a79e17d..e37a181 100644 --- a/help/fin/menu.rst +++ b/help/fin/menu.rst @@ -23,6 +23,11 @@ xxx xxx +Tallenna nimellä +^^^^^^^^^^^^^^^^ + +xxx + |exit image| Lopeta ^^^^^^^^^^^^^^^^^^^ diff --git a/locale/symedit.en_GB.ts b/locale/symedit.en_GB.ts index b77be70..197b567 100644 --- a/locale/symedit.en_GB.ts +++ b/locale/symedit.en_GB.ts @@ -5,319 +5,339 @@ - Symbol Editor + Symbol Editor - File + File - Open... + Open... - Save... + Save... + + + + Save as... - Exit + Exit - Edit + Edit - Undo + Undo - Redo + Redo - Cut + Cut - Copy + Copy - Paste + Paste - Rotate Right + Rotate Right - Rotate Left + Rotate Left - Raise Item + Raise Item - Lower Item + Lower Item - Delete Item + Delete Item - View + View - Zoom In + Zoom In - Zoom Out + Zoom Out - Maximum + Maximum - Show Grid + Show Grid - Preview + Preview - Tool + Tool - Select + Select - Line + Line - Rectangle Corner + Rectangle Corner - Rectangle Center + Rectangle Center - Circle Corner + Circle Corner - Circle Radius + Circle Radius - Circle Center + Circle Center - Semicircle + Semicircle - Quarter Circle + Quarter Circle - Text + Text - Help + Help - Contents + Contents - About + About - Undo edit + Undo edit - Redo edit + Redo edit - Cut symbol + Cut symbol - Copy symbol + Copy symbol - Paste symbol + Paste symbol - Rotate right + Rotate right - Rotate left + Rotate left - Raise item + Raise item - Lower item + Lower item - Delete item + Delete item - Maximum zoom + Maximum zoom - Preview symbol + Preview symbol - Select item + Select item - Draw line + Draw line - Rectangle corner + Rectangle corner - Rectangle center + Rectangle center - Circle corner + Circle corner - Circle radius + Circle radius - Circle center + Circle center - Draw text + Draw text - Snap Grid + Snap Grid - Fill Item + Fill Item - 0 No fill + 0 No fill - 1 Background + 1 Background - 2 Fill area + 2 Fill area - Line Width + Line Width - Text Size + Text Size - Alignment + Alignment - 1 Top right + 1 Top right - 2 Top center + 2 Top center - 3 Top left + 3 Top left - 4 Base right + 4 Base right - 5 Base center + 5 Base center - 6 Base left + 6 Base left - 7 Bottom right + 7 Bottom right - 8 Bottom center + 8 Bottom center - 9 Bottom left + 9 Bottom left - 10 Middle right + 10 Middle right - 11 Middle center + 11 Middle center - 12 Middle left + 12 Middle left - Text + Text - + + + Open File + + + + Save File + + + + Symbol files (*.txt) + + + + All files (*) + + - About Program + About Program - Symbol editor for 3D-Win + Symbol editor for 3D-Win @@ -333,7 +353,7 @@ - Read symbol from parameter <symbol>. + Read symbol from parameter <symbol>. @@ -343,11 +363,11 @@ Application language abbreviation <language>. - - - Symbol file is transfer file. - - + + + Symbol file is transfer file. + + Symbol file name. diff --git a/locale/symedit.fi_FI.ts b/locale/symedit.fi_FI.ts index 6fc8a18..2ba3bf0 100644 --- a/locale/symedit.fi_FI.ts +++ b/locale/symedit.fi_FI.ts @@ -5,319 +5,339 @@ - Symbolieditori + Symbolieditori - Tiedosto + Tiedosto - Avaa... + Avaa... - Tallenna... + Tallenna... + + + + Tallenna nimellä... - Lopeta + Lopeta - Muokkaa + Muokkaa - Kumoa + Kumoa - Tee uudelleen + Tee uudelleen - Leikkaa + Leikkaa - Kopioi + Kopioi - Liitä + Liitä - Käännä oikealle + Käännä oikealle - Käännä vasemmalle + Käännä vasemmalle - Nosta kohdetta + Nosta kohdetta - Alenna kohdetta + Alenna kohdetta - Poista kohde + Poista kohde - Näytä + Näytä - Lähennä + Lähennä - Loitonna + Loitonna - Maksimi + Maksimi - Ruudukko + Ruudukko - Esikatselu + Esikatselu - Työkalut + Työkalut - Valitse + Valitse - Viiva + Viiva - Suorakulmio kulmista + Suorakulmio kulmista - Suorakulmio keskeltä + Suorakulmio keskeltä - Ympyrä kulmista + Ympyrä kulmista - Ympyrä halkaisija + Ympyrä halkaisija - Ympyrä keskeltä + Ympyrä keskeltä - Puoliympyrä + Puoliympyrä - Neljännesympyrä + Neljännesympyrä - Teksti + Teksti - Ohje + Ohje - Sisältö + Sisältö - Tietoja + Tietoja - Kumoa toiminto + Kumoa toiminto - Tee toiminto uudelleen + Tee toiminto uudelleen - Leikkaa symboli + Leikkaa symboli - Kopioi symboli + Kopioi symboli - Liitä symboli + Liitä symboli - Käännä oikealle + Käännä oikealle - Käännä vasemmalle + Käännä vasemmalle - Nosta kohdetta + Nosta kohdetta - Alenna kohdetta + Alenna kohdetta - Poista kohde + Poista kohde - Maksimizoomaus + Maksimizoomaus - Symbolin esikatselu + Symbolin esikatselu - Valitse kohde + Valitse kohde - Piirrä viiva + Piirrä viiva - Suorakulmio kulmista + Suorakulmio kulmista - Suorakulmio keskeltä + Suorakulmio keskeltä - Ympyrä kulmista + Ympyrä kulmista - Ympyrä halkasija + Ympyrä halkasija - Ympyrä keskeltä + Ympyrä keskeltä - Piirrä teksti + Piirrä teksti - Tartunta + Tartunta - Täyttö + Täyttö - 0 Ei täyttöä + 0 Ei täyttöä - 1 Taustaväri + 1 Taustaväri - 2 Alueen täyttö + 2 Alueen täyttö - Viivan leveys + Viivan leveys - Tekstin koko + Tekstin koko - Asemointi + Asemointi - 1 Ylhäällä oikealla + 1 Ylhäällä oikealla - 2 Ylhäällä keskellä + 2 Ylhäällä keskellä - 3 Ylhäällä vasemmalla + 3 Ylhäällä vasemmalla - 4 Alareunassa oikealla + 4 Alareunassa oikealla - 5 Alareunassa keskellä + 5 Alareunassa keskellä - 6 Alareunassa vasemmalla + 6 Alareunassa vasemmalla - 7 Alhaalla oikealla + 7 Alhaalla oikealla - 8 Alhaalla keskellä + 8 Alhaalla keskellä - 9 Alhaalla vasemmalla + 9 Alhaalla vasemmalla - 10 Puolivälissä oikealla + 10 Puolivälissä oikealla - 11 Puolivälissä keskellä + 11 Puolivälissä keskellä - 12 Puolivälissä vasemmalla + 12 Puolivälissä vasemmalla - Teksti + Teksti - + + + Avaa tiedosto + + + + Tallenna tiedosto + + + + Symbolitiedostot (*.txt) + + + + Kaikki tiedostot (*) + + - Tietoja ohjelmasta + Tietoja ohjelmasta - 3D-Win symbolieditori + 3D-Win symbolieditori @@ -333,7 +353,7 @@ - Lue symboli parametrista <symboli>. + Lue symboli parametrista <symboli>. @@ -341,13 +361,13 @@ - Sovelluksen kielen lyhenne <kieli>. + Sovelluksen kielen lyhenne <kieli>. - - - Symbolitiedosto on siirtotiedosto. - - + + + Symbolitiedosto on siirtotiedosto. + + Symbolitiedoston nimi. diff --git a/locale/symedit.ts b/locale/symedit.ts index bf67612..3348176 100644 --- a/locale/symedit.ts +++ b/locale/symedit.ts @@ -15,6 +15,10 @@ + + + + @@ -235,7 +239,23 @@ - + + + + + + + + + + + + + + + + + @@ -343,11 +363,11 @@ - - - - - + + + + + diff --git a/main.qml b/main.qml index 43d06bf..32b64c9 100644 --- a/main.qml +++ b/main.qml @@ -36,7 +36,8 @@ ApplicationWindow { title: qsTrId("id_menu_file") MenuItem { text: qsTrId("id_menu_file_open"); shortcut: "Ctrl+O"; onTriggered: open() } - MenuItem { text: qsTrId("id_menu_file_save"); shortcut: "Ctrl+S"; onTriggered: save() } + MenuItem { text: qsTrId("id_menu_file_save"); shortcut: "Ctrl+S"; onTriggered: save(false) } + MenuItem { text: qsTrId("id_menu_file_save_as"); shortcut: "Ctrl+Shift+S"; onTriggered: save(true) } MenuSeparator { } MenuItem { text: qsTrId("id_menu_file_exit"); shortcut: "F4"; onTriggered: Qt.quit() } } @@ -272,19 +273,19 @@ ApplicationWindow FileDialog { id: filedialog - title: "Please choose a file" - folder: shortcuts.home + title: (selectExisting ? qsTrId("id_dialog_open_file") : qsTrId("id_dialog_save_file")) + nameFilters: [ qsTrId("id_dialog_symbol_files"), qsTrId("id_dialog_all_files") ] onAccepted: { -// console.log("You chose: " + fileDialog.fileUrls) -// Qt.quit() - } - onRejected: - { -// console.log("Canceled") -// Qt.quit() + if ( selectExisting ) + { + manager.open(fileUrl) + symbol = manager.getSymbol() + } + else // save + manager.save(fileUrl) + editor.update() } -// Component.onCompleted: visible = true } Dialog @@ -297,7 +298,6 @@ ApplicationWindow text: qsTrId("id_dialog_about_text") horizontalAlignment: Text.AlignHCenter } - standardButtons: StandardButton.Ok } @@ -345,14 +345,21 @@ ApplicationWindow function open() { + filedialog.selectExisting = true + filedialog.folder = manager.getTextSetting("Directory") filedialog.open() -// manager.open(true); - editor.update() } - function save() + function save(ask) { - //## + if ( ask ) + { + filedialog.selectExisting = false + filedialog.folder = manager.getTextSetting("Directory") + filedialog.open() + } + else + manager.save("") } function zoom(dir) diff --git a/symedit.cpp b/symedit.cpp index 8bb523c..9b14525 100644 --- a/symedit.cpp +++ b/symedit.cpp @@ -1,9 +1,9 @@ #include #include #include -//#include #include -#include +#include +#include #include "symedit.h" @@ -21,6 +21,7 @@ SymEditSettings::SymEditSettings() IntValues.emplace("Tool", 1); TextValues.emplace("TextValue", ""); + TextValues.emplace("Directory", ""); } //! Load settings. @@ -33,13 +34,14 @@ void SymEditSettings::Load() Size.setWidth(settings.value("window/width", 500).toInt()); Size.setHeight(settings.value("window/height", 500).toInt()); + TextValues.at("Directory") = settings.value("application/directory").toString(); + IntValues.at("FillItem") = settings.value("editor/fill", 0).toInt(); IntValues.at("Alignment") = settings.value("editor/align", 9).toInt(); IntValues.at("LineWidth") = settings.value("editor/width", 1).toInt(); IntValues.at("TextSize") = settings.value("editor/size", 1).toInt(); IntValues.at("SnapGrid") = settings.value("editor/snap", 5).toInt(); IntValues.at("Tool") = settings.value("editor/tool", 1).toInt(); - TextValues.at("TextValue") = settings.value("editor/text").toString(); } @@ -53,13 +55,14 @@ void SymEditSettings::Save() const settings.setValue("window/width", Size.width()); settings.setValue("window/height", Size.height()); + settings.setValue("application/directory", TextValues.at("Directory")); + settings.setValue("editor/fill", IntValues.at("FillItem")); settings.setValue("editor/align", IntValues.at("Alignment")); settings.setValue("editor/width", IntValues.at("LineWidth")); settings.setValue("editor/size", IntValues.at("TextSize")); settings.setValue("editor/snap", IntValues.at("SnapGrid")); settings.setValue("editor/tool", IntValues.at("Tool")); - settings.setValue("editor/text", TextValues.at("TextValue")); } @@ -87,7 +90,9 @@ SymEditManager::SymEditManager(const QString& filename, const QString& symbol) if ( !FileName.isEmpty() ) { - //## load file + QUrl fileurl; + fileurl.fromLocalFile(FileName); + open(fileurl); } if ( !symbol.isEmpty() ) @@ -435,16 +440,54 @@ bool SymEditManager::raiseItem(int dir) } //! Open symbol file. -bool SymEditManager::open(QString filename) +/*! + \param fileurl File name as URL. + \return True for success. +*/ +bool SymEditManager::open(QUrl fileurl) { - //## + QString filestring = fileurl.toString(); + int index = filestring.lastIndexOf('/') + 1; + QString directory = filestring.left(index); + setTextSetting("Directory", directory); + + QString filename = fileurl.toLocalFile(); + QFile file(filename); + if ( file.open(QIODevice::ReadOnly | QIODevice::Text) ) + { + QTextStream input(&file); + Symbol.Load(input.readLine()); + FileName = filename; + return true; + } return false; } //! Save symbol file. -bool SymEditManager::save(QString filename) +/*! + \param fileurl File name as URL. + \return True for success. +*/ +bool SymEditManager::save(QUrl fileurl) { - //## + QString filename = FileName; + if ( !fileurl.isEmpty() ) + { + QString filestring = fileurl.toString(); + int index = filestring.lastIndexOf('/') + 1; + QString directory = filestring.left(index); + setTextSetting("Directory", directory); + filename = fileurl.toLocalFile(); + } + + QFile file(filename); + if ( file.open(QIODevice::WriteOnly | QIODevice::Text) ) + { + QTextStream output(&file); + output << getSymbol(); + FileName = filename; + return true; + } return false; } diff --git a/symedit.h b/symedit.h index 8dda3e8..89223f0 100644 --- a/symedit.h +++ b/symedit.h @@ -6,6 +6,7 @@ #include #include #include +#include #include @@ -80,8 +81,8 @@ public: Q_INVOKABLE void rotateSymbol(int dir); Q_INVOKABLE bool raiseItem(int dir); - Q_INVOKABLE bool open(QString filename); - Q_INVOKABLE bool save(QString filename); + Q_INVOKABLE bool open(QUrl fileurl); + Q_INVOKABLE bool save(QUrl fileurl); Q_INVOKABLE bool undo(bool undo); Q_INVOKABLE void help(QString topic) const; -- cgit v1.2.3