From 7c3e8ff6707494b3cf27758c85348098ab90ebc7 Mon Sep 17 00:00:00 2001 From: Shivendra Pratap Singh Date: Mon, 20 May 2019 13:54:10 +0530 Subject: [PATCH] Movable Controls Now Controls Can Be Moved from the Blackboard as well --- Operator.pro | 8 ++- Operator.pro.user | 2 +- blackboard.cpp | 29 +++++++- blackboard.h | 3 +- connector.cpp | 6 ++ connector.h | 17 +++++ main.cpp | 2 + main.qml | 7 ++ nodecore.cpp | 179 ++++++++++++++++++++++++++++++++++++++++++++++ nodecore.h | 64 +++++++++++++++++ 10 files changed, 312 insertions(+), 5 deletions(-) create mode 100644 connector.cpp create mode 100644 connector.h create mode 100644 nodecore.cpp create mode 100644 nodecore.h diff --git a/Operator.pro b/Operator.pro index 10f29d6..ea2e661 100644 --- a/Operator.pro +++ b/Operator.pro @@ -14,7 +14,9 @@ DEFINES += QT_DEPRECATED_WARNINGS SOURCES += \ main.cpp \ - blackboard.cpp + blackboard.cpp \ + nodecore.cpp \ + connector.cpp RESOURCES += qml.qrc @@ -30,4 +32,6 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target HEADERS += \ - blackboard.h + blackboard.h \ + nodecore.h \ + connector.h diff --git a/Operator.pro.user b/Operator.pro.user index 604e450..eec0e8d 100644 --- a/Operator.pro.user +++ b/Operator.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/blackboard.cpp b/blackboard.cpp index f6ff8d0..b6d4d1a 100644 --- a/blackboard.cpp +++ b/blackboard.cpp @@ -191,7 +191,20 @@ void BlackBoard::mouseMoveEvent(QMouseEvent *event) m_mouseDownPosition=event->pos(); setOffsetX(m_offsetX+p.x()); setOffsetY(m_offsetY+p.y()); - + MoveNodes(p); + } +} +void BlackBoard::MoveNodes(QPoint q) +{ + QObject* cur=static_cast(this); + QObjectList allc=cur->children(); + for(int i=0;i(allc[i]); + if(c!=nullptr) + { + c->setPosition(c->position()+q); + } } } void BlackBoard::wheelEvent(QWheelEvent *event) @@ -218,8 +231,22 @@ void BlackBoard::zoom(float amount) { m_squareDimension = static_cast(amount * m_lock_squareDimension); + ZoomNodes(); update(); } +void BlackBoard::ZoomNodes() +{ + QObject* cur=static_cast(this); + QObjectList allc=cur->children(); + for(int i=0;i(allc[i]); + if(c!=nullptr) + { + c->setScale(static_cast(curZoom)); + } + } +} void BlackBoard::keyPressEvent(QKeyEvent *e) { diff --git a/blackboard.h b/blackboard.h index a89e614..55cac0d 100644 --- a/blackboard.h +++ b/blackboard.h @@ -76,7 +76,8 @@ public slots: int BigBlock() const; void ZoomAmountModifier(int); - + void MoveNodes(QPoint); + void ZoomNodes(); }; #endif // BLACKBOARD_H diff --git a/connector.cpp b/connector.cpp new file mode 100644 index 0000000..962377f --- /dev/null +++ b/connector.cpp @@ -0,0 +1,6 @@ +#include "connector.h" + +Connector::Connector() +{ + +} diff --git a/connector.h b/connector.h new file mode 100644 index 0000000..a7af046 --- /dev/null +++ b/connector.h @@ -0,0 +1,17 @@ +#ifndef CONNECTOR_H +#define CONNECTOR_H + +#include +#include + +class Connector +{ +public: + Connector(); + QPoint from; + QPoint to; + QColor lineColor; + float lineWidth=2.5f; +}; + +#endif // CONNECTOR_H diff --git a/main.cpp b/main.cpp index b820b99..a9eaf85 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,7 @@ #include #include #include +#include int main(int argc, char *argv[]) { @@ -9,6 +10,7 @@ int main(int argc, char *argv[]) QGuiApplication app(argc, argv); qmlRegisterType("blackBoard",1,0,"Board"); + qmlRegisterType("nodecore",1,0,"Node"); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); diff --git a/main.qml b/main.qml index 67df370..44d6ad6 100644 --- a/main.qml +++ b/main.qml @@ -3,6 +3,7 @@ import QtQuick.Window 2.2 import QtQuick.Controls 2.3 import blackBoard 1.0 import QtQuick.Controls.Material 2.3 +import nodecore 1.0 Window { id:win visible: true @@ -20,6 +21,12 @@ Window { { id:board anchors.fill: parent + Node + { + id:node + width: 200 + height: 300 + } } } diff --git a/nodecore.cpp b/nodecore.cpp new file mode 100644 index 0000000..431c9d2 --- /dev/null +++ b/nodecore.cpp @@ -0,0 +1,179 @@ +#include "nodecore.h" + +NodeCore::NodeCore() +{ + setAcceptedMouseButtons(Qt::AllButtons); +} + +void NodeCore::setBackgroundColor(const QColor color) +{ + if(color==m_backgroundColor) + return; + else + { + m_backgroundColor=color; + update(); + } +} +void NodeCore::setHighlightColor(const QColor color) +{ + if(color==m_highlightColor) + return; + else + { + m_highlightColor=color; + update(); + } +} +void NodeCore::setPanelColor(const QColor color) +{ + if(color==m_panelColor) + return; + else + { + m_panelColor=color; + update(); + } +} +void NodeCore::setPanelGradColor(const QColor color) +{ + if(color==m_panelGradColor) + return; + else + { + m_panelGradColor=color; + update(); + } +} +void NodeCore::setTitleFont(const QFont f) +{ + if(f==m_titleFont) + return; + else + { + m_titleFont=f; + update(); + } +} +void NodeCore::setPanelHeight(const int h) +{ + if(h==m_panelHeight) + return; + else + { + m_panelHeight=h; + update(); + } +} +void NodeCore::setTitleColor(const QColor c) +{ + if(c==m_titleColor) + return; + else + { + m_titleColor=c; + update(); + } +} +void NodeCore::setTitle(const QString c) +{ + if(c==m_title) + return; + else + { + m_title=c; + update(); + } +} + + +QColor NodeCore::backgroundColor() const +{ + return m_backgroundColor; +} +QColor NodeCore::highlightColor() const +{ + return m_highlightColor; +} +QColor NodeCore::panelColor() const +{ + return m_panelColor; +} +QColor NodeCore::panelGradColor() const +{ + return m_panelGradColor; +} +QColor NodeCore::titleColor() const +{ + return m_titleColor; +} +QString NodeCore::title() const +{ + return m_title; +} +QFont NodeCore::titleFont() const +{ + return m_titleFont; +} +int NodeCore::panelHeight() const +{ + return m_panelHeight; +} + + + + +void NodeCore::paint(QPainter *painter) +{ + DrawBody(painter); + DrawTitle(painter); +} +void NodeCore::DrawBody(QPainter *painter) +{ + int w=static_cast(width()); + int h=static_cast(height()); + + painter->fillRect(0,0,w,h,QBrush(m_backgroundColor)); + + QLinearGradient g(QPoint(0,0),QPoint(w,m_panelHeight)); + g.setColorAt(0,m_panelColor); + g.setColorAt(1,m_panelGradColor); + painter->fillRect(0,0,w,m_panelHeight,QBrush(g)); + + + painter->setPen(m_highlightColor); + painter->drawRect(1,1,w-2,h-2); + painter->drawRect(1,1,w,m_panelHeight-2); + + +} +void NodeCore::DrawTitle(QPainter *e) +{ + e->setPen(m_titleColor); + e->setFont(m_titleFont); + QFontMetrics f(m_titleFont); + int x=f.width(m_title); + int y=f.height(); + e->drawText(x/2,y,m_title); +} + +void NodeCore::mouseMoveEvent(QMouseEvent *e) +{ + if(isMouseDown) + { + QPoint curr=QPoint(static_cast(position().x()),static_cast(position().y())); + QPoint l=curr-lastMousePosition+e->pos(); + setPosition(l); + } +} + + +void NodeCore::mousePressEvent(QMouseEvent *e) +{ + isMouseDown=true; + lastMousePosition=e->pos(); +} +void NodeCore::mouseReleaseEvent(QMouseEvent *) +{ + isMouseDown=false; +} diff --git a/nodecore.h b/nodecore.h new file mode 100644 index 0000000..6a0a9c3 --- /dev/null +++ b/nodecore.h @@ -0,0 +1,64 @@ +#ifndef NODECORE_H +#define NODECORE_H + +#include +#include +class NodeCore : public QQuickPaintedItem +{ + Q_OBJECT + Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor) + Q_PROPERTY(QColor highlightColor READ highlightColor WRITE setHighlightColor) + Q_PROPERTY(QColor panelColor READ panelColor WRITE setPanelColor) + Q_PROPERTY(QColor panelGradColor READ panelGradColor WRITE setPanelGradColor) + Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor) + Q_PROPERTY(int panelHeight READ panelHeight WRITE setPanelHeight) + Q_PROPERTY(QString title READ title WRITE setTitle) + Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont) + +public: + NodeCore(); + QColor backgroundColor() const; + QColor highlightColor()const; + QColor panelColor()const; + QColor panelGradColor()const; + QString title()const; + QColor titleColor()const; + int panelHeight()const; + QFont titleFont()const; +protected: + void paint(QPainter*) override; + void mouseMoveEvent(QMouseEvent*)override; + void mousePressEvent(QMouseEvent*) override; + void mouseReleaseEvent(QMouseEvent*) override; + +signals: + +public slots: + void setBackgroundColor(const QColor); + void setHighlightColor(const QColor); + void setPanelColor(const QColor); + void setPanelGradColor(const QColor); + void setTitleColor(const QColor); + void setPanelHeight(const int); + void setTitle(const QString); + void setTitleFont(const QFont); + +private: + QColor m_backgroundColor=QColor(40,40,40); + QColor m_highlightColor=QColor(Qt::yellow); + QColor m_panelColor=QColor(Qt::blue); + QColor m_panelGradColor=QColor(Qt::green); + QColor m_titleColor=QColor(Qt::white); + QString m_title="Node"; + QFont m_titleFont=QFont("Segoe UI",12,-1,true); + + int m_panelHeight=40; + + bool isMouseDown; + QPoint lastMousePosition; + + void DrawBody(QPainter*); + void DrawTitle(QPainter*); +}; + +#endif // NODECORE_H