aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikko Syrjä <mikko@3d-system.fi>2019-02-12 01:40:43 +0200
committerMikko Syrjä <mikko@3d-system.fi>2019-02-12 01:40:43 +0200
commite27c60705740483291323c0b90faaf7f165cec4d (patch)
treed7d1eacdd0c0a72aabaf9488dea00b2920435ff2
parentda3b3bf7a2e764712b54d0c1d448c9a6fc1c21cd (diff)
downloadsymedit-e27c60705740483291323c0b90faaf7f165cec4d.tar.gz
symedit-e27c60705740483291323c0b90faaf7f165cec4d.zip
Windows compilation fixes.
-rw-r--r--Editor.qml66
-rw-r--r--main.cpp7
-rw-r--r--symbol.cpp10
-rw-r--r--symedit.cpp100
-rw-r--r--symedit.h12
5 files changed, 110 insertions, 85 deletions
diff --git a/Editor.qml b/Editor.qml
index ab91c22..2b030bc 100644
--- a/Editor.qml
+++ b/Editor.qml
@@ -20,9 +20,9 @@ Rectangle
enum Operation
{
- Move = 85,
- Line = 68,
- Radius = 82
+ Move = 85, // U
+ Line = 68, // D
+ Radius = 82 // R
}
property int margin: 20
@@ -66,11 +66,7 @@ Rectangle
onPressed:
{
- if ( tool === Editor.Tool.Select )
- {
-
- }
- else if ( tool === Editor.Tool.Polyline )
+ if ( tool === Editor.Tool.Polyline )
{
startx = endx
starty = endy
@@ -106,6 +102,23 @@ Rectangle
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
+ function paintline(context, start, end)
+ {
+ context.beginPath().moveTo((start.x + max) * scalexy, (max - start.y) * scalexy)
+ context.lineTo((end.x + max) * scalexy, (max - end.y) * scalexy)
+ context.closePath().stroke()
+ }
+
+ function paintcircle(context, center, radius, fill)
+ {
+ context.ellipse((center.x + max - radius) * scalexy, (max - center.y - radius) * scalexy,
+ radius * 2 * scalexy, radius * 2 * scalexy)
+ if ( fill )
+ context.fill()
+ else
+ context.stroke()
+ }
+
function paintgrid(context)
{
context.lineWidth = 0.2
@@ -130,30 +143,16 @@ Rectangle
}
context.lineWidth = 1
-
- context.beginPath().moveTo(0, max * scalexy)
- context.lineTo(units * scalexy, max * scalexy)
- context.closePath().stroke()
-
- context.beginPath().moveTo(max * scalexy, 0)
- context.lineTo(max * scalexy, units * scalexy)
- context.closePath().stroke()
+ paintline(context, Qt.point(0, -max), Qt.point(0, max))
+ paintline(context, Qt.point(-max, 0), Qt.point(max, 0))
context.strokeRect(0, 0, units * scalexy, units * scalexy)
}
- function paintcircle(context, center, radius, fill)
- {
- context.ellipse((center.x + max - radius) * scalexy, (max - center.y - radius) * scalexy,
- radius * 2 * scalexy, radius * 2 * scalexy)
- if ( fill )
- context.fill()
- else
- context.stroke()
- }
-
function paintsymbol(context)
{
+ context.lineWidth = 2
+
var previous = Qt.point(0, 0)
var index, count = manager.getItemCount()
for ( index = 0; index < count; index++ )
@@ -167,7 +166,7 @@ Rectangle
}
else if ( operation === Editor.Operation.Line )
{
- //##
+ paintline(context, previous, position)
previous = position
}
else if ( operation === Editor.Operation.Radius )
@@ -186,7 +185,6 @@ Rectangle
context.strokeStyle = "black"
context.fillStyle = "black"
-// context.lineWidth = 2
paintsymbol(context)
@@ -196,19 +194,15 @@ Rectangle
var cornery = (mousey > starty ? mousey : starty)
var deltax = Math.abs(mousex - startx)
var deltay = Math.abs(mousey - starty)
+ var start = Qt.point(startx, starty)
+ var end = Qt.point(mousex, mousey)
if ( tool > 10 && tool < 20 ) // line
{
if ( tool === Editor.Tool.Line )
- {
- context.beginPath().moveTo((startx + max) * scalexy, (max - starty) * scalexy)
- context.lineTo((mousex + max) * scalexy, (max - mousey) * scalexy)
- context.closePath().stroke()
- }
+ paintline(context, start, end)
else if ( tool === Editor.Tool.Polyline )
{
- context.beginPath().moveTo((startx + max) * scalexy, (max - starty) * scalexy)
- context.lineTo((mousex + max) * scalexy, (max - mousey) * scalexy)
- context.closePath().stroke()
+ paintline(context, start, end) //##
}
}
else if ( tool > 20 && tool < 30 ) // rectangle
diff --git a/main.cpp b/main.cpp
index cbaf6a3..75481a6 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,18 +1,19 @@
#include <QQmlContext>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
+#include <QSettings>
#include "symedit.h"
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
-
- QGuiApplication app(argc, argv);
-
QCoreApplication::setOrganizationName("Syrja");
QCoreApplication::setOrganizationDomain("syrja.org");
QCoreApplication::setApplicationName("SymEdit");
+ QSettings::setDefaultFormat(QSettings::IniFormat);
+
+ QGuiApplication app(argc, argv);
SymEditManager manager;
diff --git a/symbol.cpp b/symbol.cpp
index 367f0c8..604f91e 100644
--- a/symbol.cpp
+++ b/symbol.cpp
@@ -35,12 +35,14 @@ void SymEditSymbol::Load(const QString& buffer)
for ( const auto& string : list )
{
int operation = string.at(0).toLatin1();
- int x = string.mid(1).toInt();
- int y = x;
- int comma = string.indexOf(',');
+ int x, y, comma = string.indexOf(',');
if ( comma >= 0 )
+ {
+ x = string.mid(1, comma - 1).toInt();
y = string.mid(comma + 1).toInt();
-
+ }
+ else
+ x = y = string.mid(1).toInt();
Item item(operation, QPoint(x, y));
Items.push_back(item);
}
diff --git a/symedit.cpp b/symedit.cpp
index 902cd3c..def3037 100644
--- a/symedit.cpp
+++ b/symedit.cpp
@@ -12,6 +12,38 @@ SymEditSettings::SymEditSettings() : Fill(false), Align(9), Snap(5), Tool(1)
}
+//! Load settings.
+void SymEditSettings::Load()
+{
+ QSettings settings;
+
+ Position.setX(settings.value("window/x", 100).toInt());
+ Position.setY(settings.value("window/y", 100).toInt());
+ Size.setWidth(settings.value("window/width", 500).toInt());
+ Size.setHeight(settings.value("window/height", 500).toInt());
+
+ Fill = settings.value("editor/fill", false).toBool();
+ Align = settings.value("editor/align", 9).toInt();
+ Snap = settings.value("editor/snap", 5).toInt();
+ Tool = settings.value("editor/tool", 1).toInt();
+}
+
+//! Save settings.
+void SymEditSettings::Save() const
+{
+ QSettings settings;
+
+ settings.setValue("window/x", Position.x());
+ settings.setValue("window/y", Position.y());
+ settings.setValue("window/width", Size.width());
+ settings.setValue("window/height", Size.height());
+
+ settings.setValue("editor/fill", Fill);
+ settings.setValue("editor/align", Align);
+ settings.setValue("editor/snap", Snap);
+ settings.setValue("editor/tool", Tool);
+}
+
//
// manager functions
//
@@ -21,9 +53,15 @@ SymEditSettings::SymEditSettings() : Fill(false), Align(9), Snap(5), Tool(1)
*/
SymEditManager::SymEditManager(QObject* parent) : QObject(parent)
{
- LoadSettings();
+ Settings.Load();
- Symbol.Load("U00,00;R50;U-35,-35;D35,35;U-35,35;D35,-35;");
+ Symbol.Load("U00,00;R50;U-34,-34;D34,34;U-34,34;D34,-34;");
+}
+
+//! Set window initialized.
+void SymEditManager::setInitialized()
+{
+ Initialized = true;
}
//! Set window geometry.
@@ -33,8 +71,11 @@ SymEditManager::SymEditManager(QObject* parent) : QObject(parent)
*/
void SymEditManager::setGeometry(QPoint point, QSize size)
{
- Settings.Position = point;
- Settings.Size = size;
+ if ( Initialized )
+ {
+ Settings.Position = point;
+ Settings.Size = size;
+ }
}
//! Get window position.
@@ -77,38 +118,6 @@ 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();
-}
-
-//! Save settings.
-void SymEditManager::SaveSettings()
-{
- 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);
-}
-
//! Add symbol item.
/*!
\param operation Item operation.
@@ -152,21 +161,33 @@ int SymEditManager::getItemCount() const
return Symbol.GetItemCount();
}
-//
+//! Get item operation.
+/*!
+ \param index Item index.
+ \return Item operation.
+*/
int SymEditManager::getItemOperation(int index) const
{
const auto& item = Symbol.GetItem(index);
return item.Operation;
}
-//
+//! Get item position.
+/*!
+ \param index Item index.
+ \return Item position.
+*/
QPoint SymEditManager::getItemPoint(int index) const
{
const auto& item = Symbol.GetItem(index);
return item.Point;
}
-//
+//! Get item string.
+/*!
+ \param index Item index.
+ \return Item string.
+*/
QString SymEditManager::getItemString(int index) const
{
const auto& item = Symbol.GetItem(index);
@@ -180,6 +201,7 @@ bool SymEditManager::getItemFill(int index) const
return item.Fill;
}
+//
int SymEditManager::selectItem(QPoint point) const
{
return -1; //##
diff --git a/symedit.h b/symedit.h
index 306a38a..8e9ec9d 100644
--- a/symedit.h
+++ b/symedit.h
@@ -14,6 +14,9 @@ class SymEditSettings
public:
SymEditSettings();
+ void Load();
+ void Save() const;
+
QPoint Position; //!< Window position.
QSize Size; //!< Window size.
@@ -31,6 +34,11 @@ class SymEditManager : public QObject
public:
explicit SymEditManager(QObject* parent = nullptr);
+ //! Save settings.
+ void SaveSettings() const { Settings.Save(); }
+
+ Q_INVOKABLE void setInitialized();
+
Q_INVOKABLE void setGeometry(QPoint point, QSize size);
Q_INVOKABLE QPoint getPosition() const;
Q_INVOKABLE QSize getSize() const;
@@ -57,10 +65,8 @@ public:
Q_INVOKABLE int selectItem(QPoint point) const;
- void LoadSettings();
- void SaveSettings();
-
private:
+ bool Initialized = false; //!< Initialization mutex.
SymEditSymbol Symbol; //!< Current symbol.
SymEditSettings Settings; //!< Editor settings.
};