diff options
| author | Mikko Syrjä <mikko@3d-system.fi> | 2019-02-09 00:19:22 +0200 |
|---|---|---|
| committer | Mikko Syrjä <mikko@3d-system.fi> | 2019-02-09 00:19:22 +0200 |
| commit | 07fb2096878f9da573d663abeb3b62fb08cb3ccb (patch) | |
| tree | 0d7e69233a2af79f1aa486fe287498fd550ce273 | |
| parent | f82b71e1c3b6b632c5c1af918b319d86b49eae75 (diff) | |
| download | symedit-07fb2096878f9da573d663abeb3b62fb08cb3ccb.tar.gz symedit-07fb2096878f9da573d663abeb3b62fb08cb3ccb.zip | |
Initial symbol structure support.
| -rw-r--r-- | Editor.qml | 41 | ||||
| -rw-r--r-- | README.md | 5 | ||||
| -rw-r--r-- | main.qml | 26 | ||||
| -rw-r--r-- | symbol.cpp | 37 | ||||
| -rw-r--r-- | symbol.h | 28 | ||||
| -rw-r--r-- | symedit.cpp | 72 | ||||
| -rw-r--r-- | symedit.h | 16 | ||||
| -rw-r--r-- | symedit.pro | 9 |
8 files changed, 204 insertions, 30 deletions
@@ -18,6 +18,13 @@ Rectangle Text = 51 } + enum Operation + { + Move = 85, + Line = 68, + Radius = 82 + } + property int margin: 20 property int units: 100 property int max: units / 2 @@ -124,6 +131,38 @@ Rectangle context.strokeRect(0, 0, units * scalexy, units * scalexy) } + function paintsymbol(context) + { + var previous = Qt.point(0, 0) + var index, count = manager.getItemCount() + for ( index = 0; index < count; index++ ) + { + var operation = manager.getItemOperation(index) + var itempoint = manager.getItemPoint(index) + var itemfill = manager.getItemFill(index) + if ( operation === Editor.Operation.Move ) + { + previous = itempoint + } + else if ( operation === Editor.Operation.Line ) + { + //## + previous = itempoint + } + else if ( operation === Editor.Operation.Radius ) + { + var radius = itempoint.x + context.ellipse((previous.x + max - radius) * scalexy, + (max - previous.y - radius) * scalexy, + radius * 2 * scalexy, radius * 2 * scalexy) + if ( itemfill ) + context.fill() + else + context.stroke() + } + } + } + onPaint: { var context = getContext("2d") @@ -134,6 +173,8 @@ Rectangle context.fillStyle = "black" // context.lineWidth = 2 + paintsymbol(context) + if ( down ) { var cornerx = (mousex < startx ? mousex : startx) @@ -1,2 +1,3 @@ -# symedit -Symbol editor +# Symbol editor + +Simple symbol editor for use with 3D-Win. @@ -13,10 +13,7 @@ ApplicationWindow property int tool: 0 id: window - x: 500 - y: 100 visible: true - width: 640; height: 480 title: qsTr("Symbol editor") //%% menuBar: MenuBar @@ -176,6 +173,14 @@ ApplicationWindow ToolButton { iconSource: "clear.png" } ToolButton { iconSource: "copy.png" } Item { Layout.fillWidth: true } + CheckBox + { + id: fillcheck + checked: fill + text: qsTr("Fill") //%% + onClicked: { fill = !fill } + } + Item { Layout.fillWidth: true } Label { text: qsTr("Alignment") } //%% ComboBox { @@ -220,13 +225,6 @@ ApplicationWindow else { currentIndex = 2 } // default 5 } } - CheckBox - { - id: fillcheck - checked: fill - text: qsTr("Fill") //%% - onClicked: { fill = !fill } - } } } @@ -246,10 +244,10 @@ 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)) } + onXChanged: { manager.setGeometry(Qt.point(x, y), Qt.size(width, height)) } + onYChanged: { manager.setGeometry(Qt.point(x, y), Qt.size(width, height)) } + onWidthChanged: { manager.setGeometry(Qt.point(x, y), Qt.size(width, height)) } + onHeightChanged: { manager.setGeometry(Qt.point(x, y), Qt.size(width, height)) } onFillChanged: { manager.setFill(fill); } onAlignChanged: { manager.setAlign(align); } diff --git a/symbol.cpp b/symbol.cpp new file mode 100644 index 0000000..a415b11 --- /dev/null +++ b/symbol.cpp @@ -0,0 +1,37 @@ +#include "symbol.h" + +// +// symbol item functions +// +//! Constructor. +SymEditSymbol::Item::Item() +{ + +} + +// +// symbol functions +// +//! Constructor. +SymEditSymbol::SymEditSymbol() +{ + +} + +//! Load symbol from string. +/*! + \param string String buffer. +*/ +void SymEditSymbol::Load(const QString& string) +{ + +} + +//! Save symbol to string. +/*! + \param string String buffer. +*/ +void SymEditSymbol::Save(QString& string) const +{ + +} diff --git a/symbol.h b/symbol.h new file mode 100644 index 0000000..e9b2510 --- /dev/null +++ b/symbol.h @@ -0,0 +1,28 @@ +#ifndef SYMBOL_H +#define SYMBOL_H + +#include <vector> +#include <QPoint> + +class SymEditSymbol +{ +public: + SymEditSymbol(); + + class Item //!< Symbol item. + { + Item(); + + int Operation; //!< Item operation. + QPoint Point; //!< Item coordinates. + bool Fill; //!< Fill area. + }; + + void Load(const QString& string); + void Save(QString& string) const; + +private: + std::vector<Item> Items; //!< Symbol items. +}; + +#endif diff --git a/symedit.cpp b/symedit.cpp index bdede00..f31a556 100644 --- a/symedit.cpp +++ b/symedit.cpp @@ -24,25 +24,30 @@ SymEditManager::SymEditManager(QObject* parent) : QObject(parent) LoadSettings(); } -// -void SymEditManager::setPosition(QPoint point) +//! Set window geometry. +/*! + \param point Window position. + \param size Window size. +*/ +void SymEditManager::setGeometry(QPoint point, QSize size) { Settings.Position = point; -} - -// -void SymEditManager::setSize(QSize size) -{ Settings.Size = size; } -// +//! Get window position. +/*! + \return Window position. +*/ QPoint SymEditManager::getPosition() const { return Settings.Position; } -// +//! Get window size. +/*! + \return Window size. +*/ QSize SymEditManager::getSize() const { return Settings.Size; @@ -101,3 +106,52 @@ void SymEditManager::SaveSettings() settings.setValue("editor/snap", Settings.Snap); settings.setValue("editor/tool", Settings.Tool); } + +// +void SymEditManager::addItem(int operation, QPoint point) +{ + +} + +// +void SymEditManager::removeItem(int index) +{ + +} + + +// +int SymEditManager::getItemCount() const +{ + return 2; +} + +// +int SymEditManager::getItemOperation(int index) const +{ + if ( index == 0 ) + return 'U'; + else + return 'R'; +} + +// +QPoint SymEditManager::getItemPoint(int index) const +{ + if ( index == 0 ) + return QPoint(0, 0); + else + return QPoint(30, 30); +} + +// +QString SymEditManager::getItemString(int index) const +{ + return "T3"; +} + +// +bool SymEditManager::getItemFill(int index) const +{ + return false; +} @@ -6,6 +6,8 @@ #include <QPoint> #include <QSize> +#include "symbol.h" + //! Settings class. class SymEditSettings { @@ -29,9 +31,7 @@ class SymEditManager : public QObject public: explicit SymEditManager(QObject* parent = nullptr); - Q_INVOKABLE void setPosition(QPoint point); - Q_INVOKABLE void setSize(QSize size); - + Q_INVOKABLE void setGeometry(QPoint point, QSize size); Q_INVOKABLE QPoint getPosition() const; Q_INVOKABLE QSize getSize() const; @@ -45,10 +45,20 @@ public: Q_INVOKABLE int getTool() const; Q_INVOKABLE int getSnap() const; + Q_INVOKABLE void addItem(int operation, QPoint point); + Q_INVOKABLE void removeItem(int index); + + Q_INVOKABLE int getItemCount() const; + Q_INVOKABLE int getItemOperation(int index) const; + Q_INVOKABLE QPoint getItemPoint(int index) const; + Q_INVOKABLE QString getItemString(int index ) const; + Q_INVOKABLE bool getItemFill(int index) const; + void LoadSettings(); void SaveSettings(); private: + SymEditSymbol Symbol; //!< Current symbol. SymEditSettings Settings; //!< Editor settings. }; diff --git a/symedit.pro b/symedit.pro index da52c07..da59315 100644 --- a/symedit.pro +++ b/symedit.pro @@ -13,7 +13,8 @@ DEFINES += QT_DEPRECATED_WARNINGS #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += main.cpp \ - symedit.cpp + symedit.cpp \ + symbol.cpp RESOURCES += qml.qrc @@ -29,4 +30,8 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target HEADERS += \ - symedit.h + symedit.h \ + symbol.h + +DISTFILES += \ + README.md |
