From f7b360f1cbf32d5bc140918bef50da8c618d53eb Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Fri, 12 Sep 2014 23:45:57 +0200 Subject: [PATCH] Subclassed QGraphicsItem and QGraphicsItemLine. --- .../plugins/gui_editor/expression_editor.cpp | 12 +++-- .../plugins/gui_editor/expression_link.cpp | 44 ++++++++++++++++ .../src/plugins/gui_editor/expression_link.h | 44 ++++++++++++++++ .../plugins/gui_editor/expression_node.cpp | 50 +++++++++++++++++++ .../src/plugins/gui_editor/expression_node.h | 37 ++++++++++++++ 5 files changed, 182 insertions(+), 5 deletions(-) create mode 100644 code/studio/src/plugins/gui_editor/expression_link.cpp create mode 100644 code/studio/src/plugins/gui_editor/expression_link.h create mode 100644 code/studio/src/plugins/gui_editor/expression_node.cpp create mode 100644 code/studio/src/plugins/gui_editor/expression_node.h diff --git a/code/studio/src/plugins/gui_editor/expression_editor.cpp b/code/studio/src/plugins/gui_editor/expression_editor.cpp index 2909b0835..5fad4f054 100644 --- a/code/studio/src/plugins/gui_editor/expression_editor.cpp +++ b/code/studio/src/plugins/gui_editor/expression_editor.cpp @@ -23,6 +23,9 @@ #include #include +#include "expression_node.h" +#include "expression_link.h" + ExpressionEditor::ExpressionEditor( QWidget *parent ) : QWidget( parent ) { @@ -68,7 +71,7 @@ void ExpressionEditor::contextMenuEvent( QContextMenuEvent *e ) void ExpressionEditor::onAddRect() { - QGraphicsRectItem *item = new QGraphicsRectItem( 0, 0, 100, 100 ); + QGraphicsItem *item = new ExpressionNode(); item->setFlags( QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable ); m_scene->addItem( item ); } @@ -93,10 +96,9 @@ void ExpressionEditor::onLinkItems() QGraphicsItem *from = l[ 0 ]; QGraphicsItem *to = l[ 1 ]; - QGraphicsLineItem *line = new QGraphicsLineItem(); - line->setLine( QLineF( from->pos(), to->pos() ) ); - line->setPen( QPen( Qt::darkRed, 1.0 ) ); - m_scene->addItem( line ); + ExpressionLink *link = new ExpressionLink(); + link->link( from, to ); + m_scene->addItem( link ); } diff --git a/code/studio/src/plugins/gui_editor/expression_link.cpp b/code/studio/src/plugins/gui_editor/expression_link.cpp new file mode 100644 index 000000000..55f0f8421 --- /dev/null +++ b/code/studio/src/plugins/gui_editor/expression_link.cpp @@ -0,0 +1,44 @@ +// Ryzom Core Studio - Georges Editor Plugin +// +// Copyright (C) 2014 Laszlo Kis-Adam +// Copyright (C) 2010 Ryzom Core +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include "expression_link.h" +#include +#include + +ExpressionLink::ExpressionLink( QGraphicsItem *parent ) : +QGraphicsLineItem( parent ) +{ + m_from = NULL; + m_to = NULL; +} + +ExpressionLink::~ExpressionLink() +{ +} + +void ExpressionLink::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ) +{ + if( m_from != NULL ) + setLine( QLineF( m_from->pos(), m_to->pos() ) ); + + setPen( QPen( Qt::darkRed ) ); + + QGraphicsLineItem::paint( painter, option, widget ); +} + + diff --git a/code/studio/src/plugins/gui_editor/expression_link.h b/code/studio/src/plugins/gui_editor/expression_link.h new file mode 100644 index 000000000..d45900691 --- /dev/null +++ b/code/studio/src/plugins/gui_editor/expression_link.h @@ -0,0 +1,44 @@ +// Ryzom Core Studio - Georges Editor Plugin +// +// Copyright (C) 2014 Laszlo Kis-Adam +// Copyright (C) 2010 Ryzom Core +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#ifndef EXPRESSION_LINK +#define EXPRESSION_LINK + +#include + +class ExpressionLink : public QGraphicsLineItem +{ +public: + ExpressionLink( QGraphicsItem *parent = NULL ); + ~ExpressionLink(); + + void link( QGraphicsItem *from, QGraphicsItem *to ){ + m_from = from; + m_to = to; + } + + void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ); + +private: + QGraphicsItem *m_from; + QGraphicsItem *m_to; + +}; + +#endif + diff --git a/code/studio/src/plugins/gui_editor/expression_node.cpp b/code/studio/src/plugins/gui_editor/expression_node.cpp new file mode 100644 index 000000000..3fc0d7d2b --- /dev/null +++ b/code/studio/src/plugins/gui_editor/expression_node.cpp @@ -0,0 +1,50 @@ +// Ryzom Core Studio - Georges Editor Plugin +// +// Copyright (C) 2014 Laszlo Kis-Adam +// Copyright (C) 2010 Ryzom Core +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#include "expression_node.h" +#include +#include + +ExpressionNode::ExpressionNode( QGraphicsItem *parent ) : +QGraphicsItem( parent ) +{ +} + +ExpressionNode::~ExpressionNode() +{ +} + +QRectF ExpressionNode::boundingRect() const +{ + return QRectF( 0, 0, 100, 100 ); +} + +void ExpressionNode::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ) +{ + if( option->state & QStyle::State_Selected ) + { + QPen outline; + outline.setStyle( Qt::DotLine ); + painter->setPen( outline ); + + } + + painter->drawRect( boundingRect() ); +} + diff --git a/code/studio/src/plugins/gui_editor/expression_node.h b/code/studio/src/plugins/gui_editor/expression_node.h new file mode 100644 index 000000000..354905c3e --- /dev/null +++ b/code/studio/src/plugins/gui_editor/expression_node.h @@ -0,0 +1,37 @@ +// Ryzom Core Studio - Georges Editor Plugin +// +// Copyright (C) 2014 Laszlo Kis-Adam +// Copyright (C) 2010 Ryzom Core +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#ifndef EXPRESSION_NODE +#define EXPRESSION_NODE + +#include + +class ExpressionNode : public QGraphicsItem +{ +public: + ExpressionNode( QGraphicsItem *parent = NULL ); + ~ExpressionNode(); + + QRectF boundingRect() const; + void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ); + +}; + +#endif +