Skip to content

Commit

Permalink
[1/3]try to init grid.
Browse files Browse the repository at this point in the history
  • Loading branch information
legobadman committed Jan 14, 2022
1 parent e18bbcc commit 3f736d8
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 6 deletions.
2 changes: 1 addition & 1 deletion designer/nodescene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "componentitem.h"
#include "timelineitem.h"
#include "dragpointitem.h"
#include "nodegrid.h"
#include <nodesys/nodegrid.h>
#include "nodesview.h"
#include "styletabwidget.h"
#include "nodeswidget.h"
Expand Down
2 changes: 1 addition & 1 deletion editor/res/templates/node-example.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<component id="display" x="194" y="34" w="32" h="32">
<image id="display-image" x="194" y="34" w="32" h="32" normal="" hovered="" selected=""/>
</component>
<background id="header-backboard" x="32" y="72" w="208" h="32" radius="0px 0px 0px 0px" normal-clr="#56608F" hoverd-clr="" selected-clr="">
<background id="header-backboard" x="32" y="72" w="208" h="32" radius="0px 0px 0px 0px" normal-clr="#536093" hoverd-clr="" selected-clr="">
<image id="" x="0" y="0" w="0" h="0" normal="" hovered="" selected=""/>
</background>
</header>
Expand Down
2 changes: 1 addition & 1 deletion designer/nodegrid.cpp → zenoui/nodesys/nodegrid.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "framework.h"
#include "nodegrid.h"
#include "nodesys_common.h"


NodeGridLineItem::NodeGridLineItem(NodeGridItem* grid, qreal x1, qreal y1, qreal x2, qreal y2, QGraphicsItem* parent)
Expand Down
4 changes: 4 additions & 0 deletions designer/nodegrid.h → zenoui/nodesys/nodegrid.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef __NODEGRID_H__
#define __NODEGRID_H__

#include <QtWidgets>
#include <QtSvg/QGraphicsSvgItem>
#include <render/common_id.h>

class NodeGridItem;

class NodeGridLineItem : public QGraphicsLineItem
Expand Down
2 changes: 2 additions & 0 deletions zenoui/nodesys/nodesys_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ enum STATUS_BTN
STATUS_VIEW,
};

#define PIXELS_IN_CELL 8

#define SCENE_INIT_WIDTH 64000
#define SCENE_INIT_HEIGHT 64000

Expand Down
3 changes: 1 addition & 2 deletions zenoui/nodesys/zenonode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void ZenoNode::initWangStyle(const QModelIndex& index, SubGraphModel* pModel)

bool bCollasped = m_index.data(ROLE_COLLASPED).toBool();
if (bCollasped)
onCollaspeLegacyUpdated(true);
onCollaspeUpdated(true);

// setPos will send geometry, but it's not supposed to happend during initialization.
setFlag(ItemSendsGeometryChanges);
Expand Down Expand Up @@ -306,7 +306,6 @@ ZenoBackgroundWidget* ZenoNode::initHeaderWangStyle(NODE_TYPE type)
ZenoBackgroundWidget* headerWidget = new ZenoBackgroundWidget(this);
auto headerBg = m_renderParams.headerBg;
headerWidget->setRadius(headerBg.lt_radius, headerBg.rt_radius, headerBg.lb_radius, headerBg.rb_radius);
headerBg.clr_normal.setAlphaF(0.6);
headerWidget->setColors(headerBg.bAcceptHovers, headerBg.clr_normal, headerBg.clr_hovered, headerBg.clr_selected);
headerWidget->setBorder(headerBg.border_witdh, headerBg.clr_border);

Expand Down
18 changes: 18 additions & 0 deletions zenoui/nodesys/zenosubgraphscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
#include "../io/zsgreader.h"
#include "../util/uihelper.h"
#include "nodesys_common.h"
#include "nodegrid.h"


ZenoSubGraphScene::ZenoSubGraphScene(QObject *parent)
: QGraphicsScene(parent)
, m_subgraphModel(nullptr)
, m_tempLink(nullptr)
, m_grid(nullptr)
{
ZtfUtil &inst = ZtfUtil::GetInstance();
m_nodeParams = inst.toUtilParam(inst.loadZtf(":/templates/node-example.xml"));
Expand All @@ -21,6 +23,22 @@ ZenoSubGraphScene::ZenoSubGraphScene(QObject *parent)
setSceneRect(-SCENE_INIT_WIDTH / 2, -SCENE_INIT_HEIGHT / 2, SCENE_INIT_WIDTH, SCENE_INIT_HEIGHT);
}

void ZenoSubGraphScene::initGrid(QRectF rc)
{
if (!m_grid)
{
//todo
//m_grid = new NodeGridItem(rc.size().toSize());
//m_grid->setPos(rc.topLeft());
//addItem(m_grid);
}
}

void ZenoSubGraphScene::onViewTransformChanged(qreal factor)
{
m_grid->setFactor(factor);
}

void ZenoSubGraphScene::initModel(SubGraphModel* pModel)
{
if (m_subgraphModel) {
Expand Down
4 changes: 4 additions & 0 deletions zenoui/nodesys/zenosubgraphscene.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ class SubGraphModel;
class ZenoNode;
class ZenoFullLink;
class ZenoTempLink;
class NodeGridItem;

class ZenoSubGraphScene : public QGraphicsScene
{
Q_OBJECT
public:
ZenoSubGraphScene(QObject* parent = nullptr);
void initModel(SubGraphModel* pModel);
void initGrid(QRectF rc);
QPointF getSocketPos(bool bInput, const QString &nodeid, const QString &portName);
void undo();
void redo();
Expand All @@ -39,6 +41,7 @@ public slots:
void onRowsAboutToBeRemoved(const QModelIndex &parent, int first, int last);
void onRowsInserted(const QModelIndex& parent, int first, int last);
void onLinkChanged(bool bAdd, const QString &outputId, const QString &outputPort, const QString &inputId, const QString &inputPort);
void onViewTransformChanged(qreal factor);

private slots:
void reload();
Expand All @@ -51,6 +54,7 @@ private slots:
QRectF m_scene_rect;
NodeUtilParam m_nodeParams;
SubGraphModel* m_subgraphModel;
NodeGridItem* m_grid;
std::map<QString, ZenoNode*> m_nodes;
std::map<EdgeInfo, ZenoFullLink*/*, cmpEdge*/> m_links;
ZenoTempLink* m_tempLink;
Expand Down
6 changes: 5 additions & 1 deletion zenoui/nodesys/zenosubgraphview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ZenoSubGraphView::ZenoSubGraphView(QWidget *parent)
, m_dragMove(false)
, m_menu(nullptr)
{
setBackgroundBrush(QBrush(QColor(25,25,25), Qt::SolidPattern));
setBackgroundBrush(QBrush(QColor("#272727"), Qt::SolidPattern));
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);//it's easy but not efficient
setDragMode(QGraphicsView::NoDrag);
setTransformationAnchor(QGraphicsView::NoAnchor);
Expand Down Expand Up @@ -92,7 +92,11 @@ void ZenoSubGraphView::setModel(SubGraphModel* pModel)
{
m_scene = new ZenoSubGraphScene(this);
m_scene->initModel(pModel);
QRectF rcView(QPointF(-2400, -3700), QPointF(3300, 4500));
m_scene->initGrid(rcView);

setScene(m_scene);
connect(this, SIGNAL(viewChanged(qreal)), m_scene, SLOT(onViewTransformChanged(qreal)));
if (!m_scene->_sceneRect().isNull())
_updateSceneRect();
}
Expand Down

0 comments on commit 3f736d8

Please sign in to comment.