Subclassed QGraphicsItem and QGraphicsItemLine.
--HG-- branch : dfighter-tools
This commit is contained in:
parent
83566116d9
commit
adece7564a
5 changed files with 182 additions and 5 deletions
|
@ -23,6 +23,9 @@
|
|||
#include <QMenu>
|
||||
#include <qevent.h>
|
||||
|
||||
#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 );
|
||||
}
|
||||
|
||||
|
||||
|
|
44
code/studio/src/plugins/gui_editor/expression_link.cpp
Normal file
44
code/studio/src/plugins/gui_editor/expression_link.cpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
// Ryzom Core Studio - Georges Editor Plugin
|
||||
//
|
||||
// Copyright (C) 2014 Laszlo Kis-Adam
|
||||
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
|
||||
//
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "expression_link.h"
|
||||
#include <QGraphicsItem>
|
||||
#include <QPen>
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
|
44
code/studio/src/plugins/gui_editor/expression_link.h
Normal file
44
code/studio/src/plugins/gui_editor/expression_link.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
// Ryzom Core Studio - Georges Editor Plugin
|
||||
//
|
||||
// Copyright (C) 2014 Laszlo Kis-Adam
|
||||
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
|
||||
//
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef EXPRESSION_LINK
|
||||
#define EXPRESSION_LINK
|
||||
|
||||
#include <QGraphicsItem>
|
||||
|
||||
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
|
||||
|
50
code/studio/src/plugins/gui_editor/expression_node.cpp
Normal file
50
code/studio/src/plugins/gui_editor/expression_node.cpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
// Ryzom Core Studio - Georges Editor Plugin
|
||||
//
|
||||
// Copyright (C) 2014 Laszlo Kis-Adam
|
||||
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
|
||||
//
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#include "expression_node.h"
|
||||
#include <QPainter>
|
||||
#include <QStyleOption>
|
||||
|
||||
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() );
|
||||
}
|
||||
|
37
code/studio/src/plugins/gui_editor/expression_node.h
Normal file
37
code/studio/src/plugins/gui_editor/expression_node.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
// Ryzom Core Studio - Georges Editor Plugin
|
||||
//
|
||||
// Copyright (C) 2014 Laszlo Kis-Adam
|
||||
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
|
||||
//
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#ifndef EXPRESSION_NODE
|
||||
#define EXPRESSION_NODE
|
||||
|
||||
#include <QGraphicsItem>
|
||||
|
||||
class ExpressionNode : public QGraphicsItem
|
||||
{
|
||||
public:
|
||||
ExpressionNode( QGraphicsItem *parent = NULL );
|
||||
~ExpressionNode();
|
||||
|
||||
QRectF boundingRect() const;
|
||||
void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget );
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in a new issue