From 4ba65342d3ce4d8945340a90b33d57a8932bf15d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikko=20Syrj=C3=A4?= Date: Thu, 7 Feb 2019 00:49:47 +0200 Subject: Added C++ connection manager class. --- Editor.qml | 13 +++++++------ main.cpp | 9 ++++++++- main.qml | 8 +++++--- symedit.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ symedit.h | 27 +++++++++++++++++++++++++++ symedit.pro | 6 +++++- 6 files changed, 100 insertions(+), 11 deletions(-) create mode 100644 symedit.cpp create mode 100644 symedit.h diff --git a/Editor.qml b/Editor.qml index 0c14ef6..4abd5fa 100644 --- a/Editor.qml +++ b/Editor.qml @@ -162,13 +162,14 @@ Rectangle { if ( tool === Editor.Tool.RectangleCenter ) { - //## - } - else if ( tool === Editor.Tool.RectangleCorner ) - { - context.rect((cornerx + max) * scalexy, (max - cornery) * scalexy, - deltax * scalexy, deltay * scalexy) + cornerx = startx + (mousex < startx ? -deltax : -deltax) + cornery = starty + (mousey < starty ? deltay : deltay) + deltax *= 2 + deltay *= 2 } + else if ( tool === Editor.Tool.RectangleCorner ) { } + context.rect((cornerx + max) * scalexy, (max - cornery) * scalexy, + deltax * scalexy, deltay * scalexy) if ( fill ) context.fill() else diff --git a/main.cpp b/main.cpp index 5298d03..9eb9e40 100644 --- a/main.cpp +++ b/main.cpp @@ -1,15 +1,22 @@ +#include #include #include +#include "symedit.h" + int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); + SymEdit manager; + QQmlApplicationEngine engine; + engine.rootContext()->setContextProperty("manager", &manager); + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); - if (engine.rootObjects().isEmpty()) + if ( engine.rootObjects().isEmpty() ) return -1; return app.exec(); diff --git a/main.qml b/main.qml index 36f0d5f..203234d 100644 --- a/main.qml +++ b/main.qml @@ -6,7 +6,8 @@ ApplicationWindow { property alias mousex: editor.mousex property alias mousey: editor.mousey - property real snap: 5.0 + property int align: 1 + property int snap: 1 property int tool: 0 property bool fill: false @@ -243,8 +244,9 @@ ApplicationWindow Component.onCompleted: { + tool = Editor.Tool.Line + fill = manager.getFill() + snap = manager.getSnap(); snaplist.setsnap() - fill = true - tool = Editor.Tool.Select } } diff --git a/symedit.cpp b/symedit.cpp new file mode 100644 index 0000000..f077370 --- /dev/null +++ b/symedit.cpp @@ -0,0 +1,48 @@ +#include + +#include "symedit.h" + +//! Constructor. +/*! + \param parent //!< Optional parent. +*/ +SymEdit::SymEdit(QObject* parent) : QObject(parent) +{ + clipboard = QGuiApplication::clipboard(); +} + +// +void SymEdit::setFill(bool fill) +{ + //## +} + +// +bool SymEdit::getFill() const +{ + return true; //## +} + +// +void SymEdit::setSnap(int snap) +{ + //## +} + +// +int SymEdit::getSnap() const +{ + return 5; //## +} + +// +void SymEdit::setAlign(int align) +{ + //## +} + +// +int SymEdit::getAlign() const +{ + return 9; //## +} diff --git a/symedit.h b/symedit.h new file mode 100644 index 0000000..1a71c55 --- /dev/null +++ b/symedit.h @@ -0,0 +1,27 @@ +#ifndef SYMEDIT_H +#define SYMEDIT_H + +#include +#include +#include + +//! Manager class. +class SymEdit : public QObject +{ + Q_OBJECT + +public: + explicit SymEdit(QObject* parent = nullptr); + + 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 int getAlign() const; + +private: + QClipboard* clipboard; //!< System clipboard. +}; + +#endif diff --git a/symedit.pro b/symedit.pro index b5bab04..da52c07 100644 --- a/symedit.pro +++ b/symedit.pro @@ -12,7 +12,8 @@ DEFINES += QT_DEPRECATED_WARNINGS # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp +SOURCES += main.cpp \ + symedit.cpp RESOURCES += qml.qrc @@ -26,3 +27,6 @@ QML_DESIGNER_IMPORT_PATH = qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target + +HEADERS += \ + symedit.h -- cgit v1.2.3