Skip to content

Commit

Permalink
Movable Controls
Browse files Browse the repository at this point in the history
Now Controls Can Be Moved from the Blackboard as well
  • Loading branch information
sps014 committed May 20, 2019
1 parent 26cf443 commit 7c3e8ff
Show file tree
Hide file tree
Showing 10 changed files with 312 additions and 5 deletions.
8 changes: 6 additions & 2 deletions Operator.pro
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ DEFINES += QT_DEPRECATED_WARNINGS

SOURCES += \
main.cpp \
blackboard.cpp
blackboard.cpp \
nodecore.cpp \
connector.cpp

RESOURCES += qml.qrc

Expand All @@ -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
2 changes: 1 addition & 1 deletion Operator.pro.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.8.1, 2019-05-19T16:52:06. -->
<!-- Written by QtCreator 4.8.1, 2019-05-20T13:42:57. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down
29 changes: 28 additions & 1 deletion blackboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QObject*>(this);
QObjectList allc=cur->children();
for(int i=0;i<allc.length();i++)
{
QQuickItem* c=dynamic_cast<QQuickItem*>(allc[i]);
if(c!=nullptr)
{
c->setPosition(c->position()+q);
}
}
}
void BlackBoard::wheelEvent(QWheelEvent *event)
Expand All @@ -218,8 +231,22 @@ void BlackBoard::zoom(float amount)
{

m_squareDimension = static_cast<int>(amount * m_lock_squareDimension);
ZoomNodes();
update();
}
void BlackBoard::ZoomNodes()
{
QObject* cur=static_cast<QObject*>(this);
QObjectList allc=cur->children();
for(int i=0;i<allc.length();i++)
{
QQuickItem* c=dynamic_cast<QQuickItem*>(allc[i]);
if(c!=nullptr)
{
c->setScale(static_cast<qreal>(curZoom));
}
}
}

void BlackBoard::keyPressEvent(QKeyEvent *e)
{
Expand Down
3 changes: 2 additions & 1 deletion blackboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public slots:
int BigBlock() const;

void ZoomAmountModifier(int);

void MoveNodes(QPoint);
void ZoomNodes();
};

#endif // BLACKBOARD_H
6 changes: 6 additions & 0 deletions connector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "connector.h"

Connector::Connector()
{

}
17 changes: 17 additions & 0 deletions connector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef CONNECTOR_H
#define CONNECTOR_H

#include<QPoint>
#include<QColor>

class Connector
{
public:
Connector();
QPoint from;
QPoint to;
QColor lineColor;
float lineWidth=2.5f;
};

#endif // CONNECTOR_H
2 changes: 2 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include<blackboard.h>
#include<nodecore.h>

int main(int argc, char *argv[])
{
Expand All @@ -9,6 +10,7 @@ int main(int argc, char *argv[])
QGuiApplication app(argc, argv);

qmlRegisterType<BlackBoard>("blackBoard",1,0,"Board");
qmlRegisterType<NodeCore>("nodecore",1,0,"Node");

QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
Expand Down
7 changes: 7 additions & 0 deletions main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,6 +21,12 @@ Window {
{
id:board
anchors.fill: parent
Node
{
id:node
width: 200
height: 300
}

}
}
Expand Down
179 changes: 179 additions & 0 deletions nodecore.cpp
Original file line number Diff line number Diff line change
@@ -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<int>(width());
int h=static_cast<int>(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<int>(position().x()),static_cast<int>(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;
}
64 changes: 64 additions & 0 deletions nodecore.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#ifndef NODECORE_H
#define NODECORE_H

#include <QtQuick/QQuickPaintedItem>
#include<QPainter>
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

0 comments on commit 7c3e8ff

Please sign in to comment.