aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikko Syrjä <mikko@3d-system.fi>2019-02-08 22:14:27 +0200
committerMikko Syrjä <mikko@3d-system.fi>2019-02-08 22:14:27 +0200
commit09bf0771a29ad92e0eefb2066de5a06c3141dd18 (patch)
tree55a042e89c0352579159d0581dabf648bed3a393
parent4ba65342d3ce4d8945340a90b33d57a8932bf15d (diff)
downloadsymedit-09bf0771a29ad92e0eefb2066de5a06c3141dd18.tar.gz
symedit-09bf0771a29ad92e0eefb2066de5a06c3141dd18.zip
Implemented settings load and save.
-rw-r--r--Editor.qml3
-rw-r--r--main.cpp12
-rw-r--r--main.qml102
-rw-r--r--symedit.cpp89
-rw-r--r--symedit.h42
5 files changed, 179 insertions, 69 deletions
diff --git a/Editor.qml b/Editor.qml
index 4abd5fa..aa8bcfc 100644
--- a/Editor.qml
+++ b/Editor.qml
@@ -26,9 +26,6 @@ Rectangle
property bool horizontal: (height < width)
property real scalexy: (horizontal ? (height - margin * 2) / units : (width - margin * 2) / units)
- property int mousex: 0
- property int mousey: 0
-
property int startx: 0
property int starty: 0
property bool down: false
diff --git a/main.cpp b/main.cpp
index 9eb9e40..cbaf6a3 100644
--- a/main.cpp
+++ b/main.cpp
@@ -10,7 +10,11 @@ int main(int argc, char *argv[])
QGuiApplication app(argc, argv);
- SymEdit manager;
+ QCoreApplication::setOrganizationName("Syrja");
+ QCoreApplication::setOrganizationDomain("syrja.org");
+ QCoreApplication::setApplicationName("SymEdit");
+
+ SymEditManager manager;
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("manager", &manager);
@@ -19,5 +23,9 @@ int main(int argc, char *argv[])
if ( engine.rootObjects().isEmpty() )
return -1;
- return app.exec();
+ int result = app.exec();
+
+ manager.SaveSettings();
+
+ return result;
}
diff --git a/main.qml b/main.qml
index 203234d..153bce1 100644
--- a/main.qml
+++ b/main.qml
@@ -4,15 +4,17 @@ import QtQuick.Layouts 1.0
ApplicationWindow
{
- property alias mousex: editor.mousex
- property alias mousey: editor.mousey
+ property int mousex: 0
+ property int mousey: 0
+
+ property bool fill: false
property int align: 1
property int snap: 1
-
property int tool: 0
- property bool fill: false
id: window
+ x: 500
+ y: 100
visible: true
width: 640; height: 480
title: qsTr("Symbol editor") //%%
@@ -21,10 +23,10 @@ ApplicationWindow
{
Menu
{
- title: "File" //%%
+ title: qsTr("File") //%%
MenuItem
{
- text: "Open" //%%
+ text: qsTr("Open") //%%
shortcut: "Ctrl+O"
onTriggered:
{
@@ -33,7 +35,7 @@ ApplicationWindow
}
MenuItem
{
- text: "Save" //%%
+ text: qsTr("Save") //%%
shortcut: "Ctrl+S"
onTriggered:
{
@@ -43,17 +45,17 @@ ApplicationWindow
MenuSeparator { }
MenuItem
{
- text: "Exit" //%%
+ text: qsTr("Exit") //%%
shortcut: "F4"
onTriggered: { Qt.quit() }
}
}
Menu
{
- title: "Tool" //%%
+ title: qsTr("Tool") //%%
MenuItem
{
- text: "Select" //%%
+ text: qsTr("Select") //%%
checkable : true
checked: (tool === Editor.Tool.Select)
onTriggered: { tool = Editor.Tool.Select }
@@ -61,14 +63,14 @@ ApplicationWindow
MenuSeparator { }
MenuItem
{
- text: "Line" //%%
+ text: qsTr("Line") //%%
checkable : true
checked: (tool === Editor.Tool.Line)
onTriggered: { tool = Editor.Tool.Line }
}
MenuItem
{
- text: "Polyline" //%%
+ text: qsTr("Polyline") //%%
checkable : true
checked: (tool === Editor.Tool.Polyline)
onTriggered: { tool = Editor.Tool.Polyline }
@@ -76,14 +78,14 @@ ApplicationWindow
MenuSeparator { }
MenuItem
{
- text: "Rectangle Center" //%%
+ text: qsTr("Rectangle Center") //%%
checkable : true
checked: (tool === Editor.Tool.RectangleCenter)
onTriggered: { tool = Editor.Tool.RectangleCenter }
}
MenuItem
{
- text: "Rectangle Corners" //%%
+ text: qsTr("Rectangle Corners") //%%
checkable : true
checked: (tool === Editor.Tool.RectangleCorner)
onTriggered: { tool = Editor.Tool.RectangleCorner }
@@ -91,28 +93,28 @@ ApplicationWindow
MenuSeparator { }
MenuItem
{
- text: "Circle Center" //%%
+ text: qsTr("Circle Center") //%%
checkable : true
checked: (tool === Editor.Tool.CircleCenter)
onTriggered: { tool = Editor.Tool.CircleCenter }
}
MenuItem
{
- text: "Circle Horizontal" //%%
+ text: qsTr("Circle Horizontal") //%%
checkable : true
checked: (tool === Editor.Tool.CircleHorizontal)
onTriggered: { tool = Editor.Tool.CircleHorizontal }
}
MenuItem
{
- text: "Circle Vertical" //%%
+ text: qsTr("Circle Vertical") //%%
checkable : true
checked: (tool === Editor.Tool.CircleVertical)
onTriggered: { tool = Editor.Tool.CircleVertical }
}
MenuItem
{
- text: "Circle Corners" //%%
+ text: qsTr("Circle Corners") //%%
checkable : true
checked: (tool === Editor.Tool.CircleCorner)
onTriggered: { tool = Editor.Tool.CircleCorner }
@@ -120,14 +122,14 @@ ApplicationWindow
MenuSeparator { }
MenuItem
{
- text: "Semicircle" //%%
+ text: qsTr("Semicircle") //%%
checkable : true
checked: (tool === Editor.Tool.ArcSemicircle)
onTriggered: { tool = Editor.Tool.ArcSemicircle }
}
MenuItem
{
- text: "Quarter circle" //%%
+ text: qsTr("Quarter circle") //%%
checkable : true
checked: (tool === Editor.Tool.ArcQuarter)
onTriggered: { tool = Editor.Tool.ArcQuarter }
@@ -135,7 +137,7 @@ ApplicationWindow
MenuSeparator { }
MenuItem
{
- text: "Text" //%%
+ text: qsTr("Text") //%%
checkable : true
checked: (tool === Editor.Tool.Text)
onTriggered: { tool = Editor.Tool.Text }
@@ -143,10 +145,10 @@ ApplicationWindow
}
Menu
{
- title: "Help" //%%
+ title: qsTr("Help") //%%
MenuItem
{
- text: "Help" //%%
+ text: qsTr("Help") //%%
shortcut: "F1"
onTriggered:
{
@@ -156,7 +158,7 @@ ApplicationWindow
MenuSeparator { }
MenuItem
{
- text: "About" //%%
+ text: qsTr("About") //%%
onTriggered:
{
//##
@@ -174,36 +176,31 @@ ApplicationWindow
ToolButton { iconSource: "clear.png" }
ToolButton { iconSource: "copy.png" }
Item { Layout.fillWidth: true }
- CheckBox
- {
- id: fillcheck
- checked: fill
- text: "Fill"
- onClicked: { fill = !fill }
- }
- Label { text: "Alignment" } //%%
+ Label { text: qsTr("Alignment") } //%%
ComboBox
{
id: alignlist
model: [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
-/*
onCurrentIndexChanged:
{
+/*
if ( currentIndex == 0 ) { snap = 1 }
else if ( currentIndex == 1 ) { snap = 2 }
else if ( currentIndex == 2 ) { snap = 5 }
else if ( currentIndex == 3 ) { snap = 10 }
+*/
}
- function setsnap()
+ function setAlign()
{
+/*
if ( snap == 1 ) { currentIndex = 0 }
else if ( snap == 2 ) { currentIndex = 1 }
else if ( snap == 10 ) { currentIndex = 3 }
else { currentIndex = 2 } // default 5
- }
*/
+ }
}
- Label { text: "Snap" } //%%
+ Label { text: qsTr("Snap") } //%%
ComboBox
{
id: snaplist
@@ -215,7 +212,7 @@ ApplicationWindow
else if ( currentIndex == 2 ) { snap = 5 }
else if ( currentIndex == 3 ) { snap = 10 }
}
- function setsnap()
+ function setSnap()
{
if ( snap == 1 ) { currentIndex = 0 }
else if ( snap == 2 ) { currentIndex = 1 }
@@ -223,6 +220,13 @@ ApplicationWindow
else { currentIndex = 2 } // default 5
}
}
+ CheckBox
+ {
+ id: fillcheck
+ checked: fill
+ text: qsTr("Fill") //%%
+ onClicked: { fill = !fill }
+ }
}
}
@@ -242,11 +246,29 @@ ApplicationWindow
}
}
+ onXChanged: { manager.setPosition(Qt.point(x, y)) }
+ onYChanged: { manager.setPosition(Qt.point(x, y)) }
+ onWidthChanged: { manager.setSize(Qt.size(width, height)) }
+ onHeightChanged: { manager.setSize(Qt.size(width, height)) }
+
+ onFillChanged: { manager.setFill(fill); }
+ onAlignChanged: { manager.setAlign(align); }
+ onSnapChanged: { manager.setSnap(snap); }
+ onToolChanged: { manager.setTool(tool); }
+
Component.onCompleted:
{
- tool = Editor.Tool.Line
+ x = manager.getPosition().x
+ y = manager.getPosition().y
+ width = manager.getSize().width
+ height = manager.getSize().height
+
fill = manager.getFill()
- snap = manager.getSnap();
- snaplist.setsnap()
+ align = manager.getAlign()
+ snap = manager.getSnap()
+ tool = manager.getTool()
+
+ alignlist.setAlign()
+ snaplist.setSnap()
}
}
diff --git a/symedit.cpp b/symedit.cpp
index f077370..bdede00 100644
--- a/symedit.cpp
+++ b/symedit.cpp
@@ -1,48 +1,103 @@
#include <QGuiApplication>
+#include <QSettings>
#include "symedit.h"
+//
+// settings functions
+//
+//! Constructor.
+SymEditSettings::SymEditSettings() : Fill(false), Align(9), Snap(5), Tool(1)
+{
+
+}
+
+//
+// manager functions
+//
//! Constructor.
/*!
- \param parent //!< Optional parent.
+ \param parent Optional parent.
*/
-SymEdit::SymEdit(QObject* parent) : QObject(parent)
+SymEditManager::SymEditManager(QObject* parent) : QObject(parent)
{
- clipboard = QGuiApplication::clipboard();
+ LoadSettings();
}
//
-void SymEdit::setFill(bool fill)
+void SymEditManager::setPosition(QPoint point)
{
- //##
+ Settings.Position = point;
}
//
-bool SymEdit::getFill() const
+void SymEditManager::setSize(QSize size)
{
- return true; //##
+ Settings.Size = size;
}
//
-void SymEdit::setSnap(int snap)
+QPoint SymEditManager::getPosition() const
{
- //##
+ return Settings.Position;
}
//
-int SymEdit::getSnap() const
+QSize SymEditManager::getSize() const
{
- return 5; //##
+ return Settings.Size;
}
-//
-void SymEdit::setAlign(int align)
+//@{
+//! Set setting value.
+/*!
+ \param value Setting value.
+*/
+void SymEditManager::setFill(bool value) { Settings.Fill = value; }
+void SymEditManager::setAlign(int value) { Settings.Align = value; }
+void SymEditManager::setSnap(int value) { Settings.Snap = value; }
+void SymEditManager::setTool(int value) { Settings.Tool = value; }
+//@}
+
+//@{
+//! Get setting value.
+/*!
+ \return Setting value.
+*/
+bool SymEditManager::getFill() const { return Settings.Fill; }
+int SymEditManager::getAlign() const { return Settings.Align; }
+int SymEditManager::getSnap() const { return Settings.Snap; }
+int SymEditManager::getTool() const { return Settings.Tool; }
+//@}
+
+//! Load settings.
+void SymEditManager::LoadSettings()
{
- //##
+ QSettings settings;
+
+ Settings.Position.setX(settings.value("window/x", 100).toInt());
+ Settings.Position.setY(settings.value("window/y", 100).toInt());
+ Settings.Size.setWidth(settings.value("window/width", 500).toInt());
+ Settings.Size.setHeight(settings.value("window/height", 500).toInt());
+
+ Settings.Fill = settings.value("editor/fill", false).toBool();
+ Settings.Align = settings.value("editor/align", 9).toInt();
+ Settings.Snap = settings.value("editor/snap", 5).toInt();
+ Settings.Tool = settings.value("editor/tool", 1).toInt();
}
-//
-int SymEdit::getAlign() const
+//! Save settings.
+void SymEditManager::SaveSettings()
{
- return 9; //##
+ QSettings settings;
+
+ settings.setValue("window/x", Settings.Position.x());
+ settings.setValue("window/y", Settings.Position.y());
+ settings.setValue("window/width", Settings.Size.width());
+ settings.setValue("window/height", Settings.Size.height());
+
+ settings.setValue("editor/fill", Settings.Fill);
+ settings.setValue("editor/align", Settings.Align);
+ settings.setValue("editor/snap", Settings.Snap);
+ settings.setValue("editor/tool", Settings.Tool);
}
diff --git a/symedit.h b/symedit.h
index 1a71c55..7173e8b 100644
--- a/symedit.h
+++ b/symedit.h
@@ -3,25 +3,53 @@
#include <QObject>
#include <QString>
-#include <QClipboard>
+#include <QPoint>
+#include <QSize>
+
+//! Settings class.
+class SymEditSettings
+{
+public:
+ SymEditSettings();
+
+ QPoint Position; //!< Window position.
+ QSize Size; //!< Window size.
+
+ bool Fill; //!< Fill object.
+ int Align; //!< Text alignment.
+ int Snap; //!< Snap granularity.
+ int Tool; //!< Current tool.
+};
//! Manager class.
-class SymEdit : public QObject
+class SymEditManager : public QObject
{
Q_OBJECT
public:
- explicit SymEdit(QObject* parent = nullptr);
+ explicit SymEditManager(QObject* parent = nullptr);
+
+ Q_INVOKABLE void setPosition(QPoint point);
+ Q_INVOKABLE void setSize(QSize size);
+
+ Q_INVOKABLE QPoint getPosition() const;
+ Q_INVOKABLE QSize getSize() const;
Q_INVOKABLE void setFill(bool fill);
- Q_INVOKABLE bool getFill() const;
- Q_INVOKABLE void setSnap(int snap);
- Q_INVOKABLE int getSnap() const;
Q_INVOKABLE void setAlign(int align);
+ Q_INVOKABLE void setSnap(int snap);
+ Q_INVOKABLE void setTool(int tool);
+
+ Q_INVOKABLE bool getFill() const;
Q_INVOKABLE int getAlign() const;
+ Q_INVOKABLE int getTool() const;
+ Q_INVOKABLE int getSnap() const;
+
+ void LoadSettings();
+ void SaveSettings();
private:
- QClipboard* clipboard; //!< System clipboard.
+ SymEditSettings Settings; //!< Editor settings.
};
#endif