First commit for sie code generator project.
347
Software/sie_cg/arrow.cpp
Normal file
@ -0,0 +1,347 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
** All rights reserved.
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
|
**
|
||||||
|
** $QT_BEGIN_LICENSE:LGPL$
|
||||||
|
** Commercial Usage
|
||||||
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||||
|
** accordance with the Qt Commercial License Agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Nokia gives you certain additional
|
||||||
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3.0 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU General Public License version 3.0 requirements will be
|
||||||
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||||
|
**
|
||||||
|
** If you have questions regarding the use of this file, please contact
|
||||||
|
** Nokia at qt-info@nokia.com.
|
||||||
|
** $QT_END_LICENSE$
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <QtGui>
|
||||||
|
|
||||||
|
#include "arrow.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
const qreal Pi = 3.14;
|
||||||
|
|
||||||
|
Arrow::Arrow(DiagramTextItem *startItem, DiagramTextItem *endItem,
|
||||||
|
QGraphicsItem *parent, QGraphicsScene *scene)
|
||||||
|
: QGraphicsPathItem(parent, scene)
|
||||||
|
{
|
||||||
|
myStartItem = startItem;
|
||||||
|
myEndItem = endItem;
|
||||||
|
arrowSize = 10;
|
||||||
|
moving=0;
|
||||||
|
//setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||||
|
setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||||
|
myColor = Qt::black;
|
||||||
|
setPen(QPen(myColor, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||||
|
myOwnerScene = scene;
|
||||||
|
lineItem *newLine= new lineItem(QPointF(0,0),QPointF(0,0),this);
|
||||||
|
myOwnerScene->addItem(newLine);
|
||||||
|
addLine(newLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Arrow::removeLine(lineItem *line)
|
||||||
|
{
|
||||||
|
int index = myLines.indexOf(line);
|
||||||
|
int cIndex = myCLines.indexOf(line);
|
||||||
|
if(cIndex!=-1) index = cIndex; //Prevent segmentation fault
|
||||||
|
|
||||||
|
if (index != -1){
|
||||||
|
//Adjust the corners
|
||||||
|
if(myLines.count()>1)
|
||||||
|
{
|
||||||
|
if(index==0)
|
||||||
|
{
|
||||||
|
myCorners.removeAt(0);
|
||||||
|
myOwnerScene->removeItem(myCLines.at(0));
|
||||||
|
myCLines.removeAt(0);
|
||||||
|
}
|
||||||
|
else if(index>0)
|
||||||
|
{
|
||||||
|
myCorners.removeAt(index-1);
|
||||||
|
myOwnerScene->removeItem(myCLines.at(index-1));
|
||||||
|
myCLines.removeAt(index-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
myLines.removeAt(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
//If lines is empty the arrow is removed
|
||||||
|
if (myLines.isEmpty())
|
||||||
|
{
|
||||||
|
this->startItem()->ownerItem()->removeArrow(this);
|
||||||
|
this->endItem()->ownerItem()->removeArrow(this);
|
||||||
|
this->myOwnerScene->removeItem(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Arrow::removeLines()
|
||||||
|
{
|
||||||
|
foreach (lineItem *line, myLines) {
|
||||||
|
scene()->removeItem(line);
|
||||||
|
delete line;
|
||||||
|
}
|
||||||
|
foreach (lineItem *line, myCLines) {
|
||||||
|
scene()->removeItem(line);
|
||||||
|
delete line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Arrow::addLine(lineItem *line)
|
||||||
|
{
|
||||||
|
myLines.append(line);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
QRectF Arrow::boundingRect() const
|
||||||
|
{
|
||||||
|
qreal extra = (pen().width() + arrowSize*2) / 2.0;
|
||||||
|
|
||||||
|
return QGraphicsPathItem::boundingRect()
|
||||||
|
.normalized()
|
||||||
|
.adjusted(-extra, -extra, extra, extra);
|
||||||
|
}
|
||||||
|
|
||||||
|
QPainterPath Arrow::shape() const
|
||||||
|
{
|
||||||
|
QPainterPath path = QGraphicsPathItem::shape();
|
||||||
|
return path; //FIXME, Arrow heads must to be include
|
||||||
|
}
|
||||||
|
|
||||||
|
void Arrow::updatePosition()
|
||||||
|
{
|
||||||
|
QPainterPath myPath;
|
||||||
|
myPath.moveTo(myStartItem->ownerItem()->pos()+myStartItem->offset()+
|
||||||
|
QPointF(arrowSize,0));
|
||||||
|
if(!myCorners.isEmpty())
|
||||||
|
foreach(QPointF corner, myCorners){
|
||||||
|
myPath.lineTo(corner);
|
||||||
|
}
|
||||||
|
myPath.lineTo(myEndItem->ownerItem()->pos()+myEndItem->offset()-
|
||||||
|
QPointF(arrowSize,0));
|
||||||
|
|
||||||
|
setPath(myPath);
|
||||||
|
|
||||||
|
}
|
||||||
|
//! [3]
|
||||||
|
|
||||||
|
void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *,
|
||||||
|
QWidget *)
|
||||||
|
{
|
||||||
|
QPen myPen = pen();
|
||||||
|
myPen.setColor(myColor);
|
||||||
|
painter->setPen(myPen);
|
||||||
|
painter->setBrush(myColor);
|
||||||
|
|
||||||
|
QPointF endPos=myEndItem->ownerItem()->pos()+myEndItem->offset()-
|
||||||
|
QPointF(arrowSize,0);
|
||||||
|
QPointF startPos=myStartItem->ownerItem()->pos()+myStartItem->offset()+
|
||||||
|
QPointF(arrowSize,0);
|
||||||
|
|
||||||
|
if(myCorners.isEmpty())
|
||||||
|
{
|
||||||
|
myLines.first()->setLine(QLineF(startPos,endPos));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
myLines.first()->setLine(QLineF(startPos,myCorners.first()));
|
||||||
|
for(int i=0; i<myCorners.count()-1;i++)
|
||||||
|
myLines.at(i+1)->setLine(QLineF(myCorners.at(i),myCorners.at(i+1)));
|
||||||
|
myLines.last()->setLine(QLineF(myCorners.last(),endPos));
|
||||||
|
}
|
||||||
|
|
||||||
|
//Drawing arrow selected
|
||||||
|
for(int i=0; i<myLines.count();i++)
|
||||||
|
if (isSelected())
|
||||||
|
{
|
||||||
|
painter->setPen(QPen(Qt::gray, 2, Qt::SolidLine));
|
||||||
|
QLineF myLine = myLines.at(i)->line();
|
||||||
|
painter->drawLine(myLine);
|
||||||
|
foreach (lineItem *line, myLines) { line->setColor(Qt::gray);}
|
||||||
|
foreach (lineItem *line, myCLines) { line->setColor(Qt::gray);}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (lineItem *line, myLines) { line->setColor(myColor);}
|
||||||
|
foreach (lineItem *line, myCLines) { line->setColor(myColor);}
|
||||||
|
}
|
||||||
|
|
||||||
|
//End arrow head
|
||||||
|
QPointF arrowP1=QPointF(endPos+QPointF(0,arrowSize));
|
||||||
|
QPointF arrowP2=QPointF(endPos+QPointF(0,-arrowSize));
|
||||||
|
|
||||||
|
arrowHeadEnd.clear();
|
||||||
|
arrowHeadEnd << endPos+QPointF(arrowSize,0) << arrowP1 << arrowP2;
|
||||||
|
|
||||||
|
painter->drawPolygon(arrowHeadEnd);
|
||||||
|
//Start arrow head
|
||||||
|
arrowP1=QPointF(startPos+QPointF(-arrowSize,arrowSize));
|
||||||
|
arrowP2=QPointF(startPos+QPointF(-arrowSize,-arrowSize));
|
||||||
|
|
||||||
|
arrowHeadStart.clear();
|
||||||
|
arrowHeadStart << startPos << arrowP1 << arrowP2;
|
||||||
|
painter->drawPolygon(arrowHeadStart);
|
||||||
|
|
||||||
|
//Set visible corners
|
||||||
|
bool anySelected = 0;
|
||||||
|
|
||||||
|
foreach(lineItem *line,myLines){ if(line->isSelected())anySelected=1;}
|
||||||
|
foreach(lineItem *line,myCLines){ if(line->isSelected())anySelected=1;}
|
||||||
|
if(isSelected()) anySelected=1;
|
||||||
|
|
||||||
|
if(anySelected)
|
||||||
|
setVisibleCorners(1);
|
||||||
|
else
|
||||||
|
setVisibleCorners(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Arrow::createCorner(QPointF cornerPos, lineItem *inLine)
|
||||||
|
{
|
||||||
|
createCorner(cornerPos,myLines.indexOf(inLine));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Arrow::createCorner(QPointF cornerPos, int index)
|
||||||
|
{
|
||||||
|
if (index != -1)
|
||||||
|
{
|
||||||
|
myCorners.insert(index,cornerPos);
|
||||||
|
lineItem *newLine= new lineItem(QPointF(0,0),QPointF(0,0),this);
|
||||||
|
myOwnerScene->addItem(newLine);
|
||||||
|
newLine->setZValue(this->zValue());
|
||||||
|
addLine(newLine);
|
||||||
|
newLine= new lineItem(cornerPos+QPointF(-0.5,-0.5) ,
|
||||||
|
cornerPos+QPointF(0.5,0.5),this,6,1);
|
||||||
|
myOwnerScene->addItem(newLine);
|
||||||
|
newLine->setZValue(this->zValue()+0.1);
|
||||||
|
myCLines.insert(index,newLine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Arrow::moveCorner(QPointF cornerPos, lineItem *inLine)
|
||||||
|
{
|
||||||
|
int index = myCLines.indexOf(inLine);
|
||||||
|
|
||||||
|
if (index != -1)
|
||||||
|
{
|
||||||
|
cornerPos=mapFromItem(inLine,cornerPos);
|
||||||
|
myCorners.replace(index,cornerPos);
|
||||||
|
updatePosition();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Arrow::setVisibleCorners(bool visible)
|
||||||
|
{
|
||||||
|
foreach (lineItem *line, myCLines) {
|
||||||
|
line->setVisible(visible);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QDomElement Arrow::toXml(QDomDocument &document,
|
||||||
|
QList<DiagramItem*> sceneItems) const
|
||||||
|
{
|
||||||
|
QDomElement diagramArrow = document.createElement("Arrow");
|
||||||
|
|
||||||
|
//Set attibutes; startItem
|
||||||
|
diagramArrow.setAttribute("start-x",startOffset().x());
|
||||||
|
diagramArrow.setAttribute("start-y",startOffset().y());
|
||||||
|
diagramArrow.setAttribute("start-Owner",
|
||||||
|
sceneItems.indexOf(startOwner()));
|
||||||
|
diagramArrow.setAttribute("start-ID",this->startItem()->textID());
|
||||||
|
|
||||||
|
//Set attibutes; endItem
|
||||||
|
diagramArrow.setAttribute("end-x",endOffset().x());
|
||||||
|
diagramArrow.setAttribute("end-y",endOffset().y());
|
||||||
|
diagramArrow.setAttribute("end-Owner",
|
||||||
|
sceneItems.indexOf(endOwner()));
|
||||||
|
diagramArrow.setAttribute("end-ID",this->endItem()->textID());
|
||||||
|
|
||||||
|
diagramArrow.setAttribute("color",myColor.name());
|
||||||
|
|
||||||
|
//Corners list
|
||||||
|
int i=0;
|
||||||
|
if(!myCorners.isEmpty())
|
||||||
|
{
|
||||||
|
QDomElement arrowCorners = document.createElement("arrowCorners");
|
||||||
|
foreach(QPointF corner, myCorners)
|
||||||
|
{
|
||||||
|
QDomElement arrowCorner = document.createElement("arrowCorner");
|
||||||
|
arrowCorner.setAttribute("x",corner.x());
|
||||||
|
arrowCorner.setAttribute("y",corner.y());
|
||||||
|
i++;
|
||||||
|
arrowCorners.appendChild(arrowCorner);
|
||||||
|
}
|
||||||
|
|
||||||
|
diagramArrow.appendChild(arrowCorners);
|
||||||
|
}
|
||||||
|
return (diagramArrow);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Arrow::snapToGrid(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
//TODO implement polygon drag
|
||||||
|
QPointF diffPos= event->scenePos()-previousPos;
|
||||||
|
//Update corners:
|
||||||
|
for(int i=0; i < myCorners.count();i++)
|
||||||
|
{
|
||||||
|
myCLines.at(i)->setLine(QLineF(myCLines.at(i)->line().p1()+diffPos,
|
||||||
|
myCLines.at(i)->line().p2()+diffPos));
|
||||||
|
QPointF itemPos = myCLines.at(i)->line().p1()+QPointF(0.5,0.5);
|
||||||
|
moveCorner(itemPos,myCLines.at(i));
|
||||||
|
}
|
||||||
|
updatePosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Arrow::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
//if(this->isSelected())
|
||||||
|
{
|
||||||
|
previousPos = event->scenePos();
|
||||||
|
moving=1;
|
||||||
|
}
|
||||||
|
QGraphicsPathItem::mousePressEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Arrow::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
if(moving && isSelected())
|
||||||
|
{
|
||||||
|
snapToGrid(event);
|
||||||
|
previousPos = event->scenePos();
|
||||||
|
}
|
||||||
|
moving=0;
|
||||||
|
QGraphicsPathItem::mouseReleaseEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Arrow::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
if(moving && isSelected())
|
||||||
|
{
|
||||||
|
snapToGrid(event);
|
||||||
|
previousPos = event->scenePos();
|
||||||
|
}
|
||||||
|
QGraphicsPathItem::mouseMoveEvent(event);
|
||||||
|
}
|
134
Software/sie_cg/arrow.h
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
** All rights reserved.
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
|
**
|
||||||
|
** $QT_BEGIN_LICENSE:LGPL$
|
||||||
|
** Commercial Usage
|
||||||
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||||
|
** accordance with the Qt Commercial License Agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Nokia gives you certain additional
|
||||||
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3.0 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU General Public License version 3.0 requirements will be
|
||||||
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||||
|
**
|
||||||
|
** If you have questions regarding the use of this file, please contact
|
||||||
|
** Nokia at qt-info@nokia.com.
|
||||||
|
** $QT_END_LICENSE$
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef ARROW_H
|
||||||
|
#define ARROW_H
|
||||||
|
|
||||||
|
#include <QGraphicsLineItem>
|
||||||
|
#include <QtXml>
|
||||||
|
#include "diagramtextitem.h"
|
||||||
|
#include "lineitem.h"
|
||||||
|
#include "diagramitem.h"
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QGraphicsPolygonItem;
|
||||||
|
class QGraphicsLineItem;
|
||||||
|
class QGraphicsPathItem;
|
||||||
|
class QGraphicsScene;
|
||||||
|
class QRectF;
|
||||||
|
class QGraphicsSceneMouseEvent;
|
||||||
|
class QPainterPath;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
class lineItem;
|
||||||
|
|
||||||
|
class Arrow : public QGraphicsPathItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum { Type = UserType + 32 };
|
||||||
|
|
||||||
|
Arrow(DiagramTextItem *startItem, DiagramTextItem *endItem,
|
||||||
|
QGraphicsItem *parent = 0, QGraphicsScene *scene = 0);
|
||||||
|
|
||||||
|
int type() const
|
||||||
|
{ return Type; }
|
||||||
|
QRectF boundingRect() const;
|
||||||
|
QPainterPath shape() const;
|
||||||
|
void setColor(const QColor &color)
|
||||||
|
{ myColor=color; }
|
||||||
|
DiagramTextItem *startItem() const
|
||||||
|
{ return myStartItem; }
|
||||||
|
DiagramTextItem *endItem() const
|
||||||
|
{ return myEndItem; }
|
||||||
|
|
||||||
|
void removeLine(lineItem *line);
|
||||||
|
void removeLines();
|
||||||
|
bool addLine(lineItem *line);
|
||||||
|
|
||||||
|
void createCorner(QPointF cornerPos, lineItem *inLine);
|
||||||
|
void createCorner(QPointF cornerPos, int index);
|
||||||
|
void moveCorner(QPointF cornerPos, lineItem *inLine);
|
||||||
|
|
||||||
|
void setVisibleCorners(bool visible);
|
||||||
|
|
||||||
|
void snapToGrid(QGraphicsSceneMouseEvent *event);
|
||||||
|
|
||||||
|
QDomDocument toXmlFormat();
|
||||||
|
|
||||||
|
QPointF startOffset() const
|
||||||
|
{ return myStartItem->offset();}
|
||||||
|
|
||||||
|
QPointF endOffset() const
|
||||||
|
{ return myEndItem->offset();}
|
||||||
|
|
||||||
|
DiagramItem *startOwner() const
|
||||||
|
{ return myStartItem->ownerItem();}
|
||||||
|
DiagramItem *endOwner() const
|
||||||
|
{ return myEndItem->ownerItem();}
|
||||||
|
|
||||||
|
QDomElement toXml(QDomDocument &,QList<DiagramItem*>) const;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void updatePosition();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
|
QWidget *widget = 0);
|
||||||
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
|
||||||
|
private:
|
||||||
|
DiagramTextItem *myStartItem;
|
||||||
|
DiagramTextItem *myEndItem;
|
||||||
|
QColor myColor;
|
||||||
|
QPolygonF arrowHeadEnd;
|
||||||
|
QPolygonF arrowHeadStart;
|
||||||
|
QList<lineItem *> myLines;
|
||||||
|
QList<lineItem *> myCLines;
|
||||||
|
QList<QPointF> myCorners;
|
||||||
|
QGraphicsScene *myOwnerScene;
|
||||||
|
qreal arrowSize;
|
||||||
|
bool moving;
|
||||||
|
QPointF previousPos;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
356
Software/sie_cg/block_editor/arrow.cpp
Normal file
@ -0,0 +1,356 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
** All rights reserved.
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
|
**
|
||||||
|
** $QT_BEGIN_LICENSE:LGPL$
|
||||||
|
** Commercial Usage
|
||||||
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||||
|
** accordance with the Qt Commercial License Agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Nokia gives you certain additional
|
||||||
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3.0 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU General Public License version 3.0 requirements will be
|
||||||
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||||
|
**
|
||||||
|
** If you have questions regarding the use of this file, please contact
|
||||||
|
** Nokia at qt-info@nokia.com.
|
||||||
|
** $QT_END_LICENSE$
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <QtGui>
|
||||||
|
|
||||||
|
#include "arrow.h"
|
||||||
|
#include "lineitem.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
const qreal Pi = 3.14;
|
||||||
|
|
||||||
|
Arrow::Arrow( QPointF startP,QPointF endP,
|
||||||
|
QGraphicsItem *parent, QGraphicsScene *scene)
|
||||||
|
: QGraphicsPathItem(parent, scene)
|
||||||
|
{
|
||||||
|
startPoint=startP;
|
||||||
|
endPoint=endP;
|
||||||
|
arrowSize = 10;
|
||||||
|
moving=0;
|
||||||
|
//setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||||
|
setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||||
|
myColor = Qt::black;
|
||||||
|
setPen(QPen(myColor, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||||
|
//setZValue(0.0);
|
||||||
|
myOwnerScene = scene;
|
||||||
|
lineItem *newLine= new lineItem(QPointF(0,0),QPointF(0,0),this);
|
||||||
|
myOwnerScene->addItem(newLine);
|
||||||
|
addLine(newLine);
|
||||||
|
|
||||||
|
updatePosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Arrow::removeLine(lineItem *line)
|
||||||
|
{
|
||||||
|
int index = myLines.indexOf(line);
|
||||||
|
|
||||||
|
if (index != -1){
|
||||||
|
//Adjust the corners
|
||||||
|
if(myLines.count()>1)
|
||||||
|
{
|
||||||
|
if(index==0)
|
||||||
|
{
|
||||||
|
myCorners.removeAt(0);
|
||||||
|
myOwnerScene->removeItem(myCLines.at(0));
|
||||||
|
myCLines.removeAt(0);
|
||||||
|
}
|
||||||
|
else if(index>0)
|
||||||
|
{
|
||||||
|
myCorners.removeAt(index-1);
|
||||||
|
myOwnerScene->removeItem(myCLines.at(index-1));
|
||||||
|
myCLines.removeAt(index-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
myLines.removeAt(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
//If lines is empty the arrow is removed
|
||||||
|
if (myLines.count()<3)
|
||||||
|
{
|
||||||
|
removeLines();
|
||||||
|
myOwnerScene->removeItem(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Arrow::removeLines()
|
||||||
|
{
|
||||||
|
foreach (lineItem *line, myLines) {
|
||||||
|
scene()->removeItem(line);
|
||||||
|
delete line;
|
||||||
|
}
|
||||||
|
foreach (lineItem *line, myCLines) {
|
||||||
|
scene()->removeItem(line);
|
||||||
|
delete line;
|
||||||
|
}
|
||||||
|
if(myOwnerScene->items().indexOf(SECLine)!=-1)
|
||||||
|
{
|
||||||
|
scene()->removeItem(SECLine);
|
||||||
|
delete SECLine;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Arrow::addLine(lineItem *line)
|
||||||
|
{
|
||||||
|
myLines.append(line);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
QRectF Arrow::boundingRect() const
|
||||||
|
{
|
||||||
|
qreal extra = (pen().width() + arrowSize*2) / 2.0;
|
||||||
|
|
||||||
|
return QGraphicsPathItem::boundingRect()
|
||||||
|
.normalized()
|
||||||
|
.adjusted(-extra, -extra, extra, extra);
|
||||||
|
}
|
||||||
|
|
||||||
|
QPainterPath Arrow::shape() const
|
||||||
|
{
|
||||||
|
QPainterPath path = QGraphicsPathItem::shape();
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Arrow::updatePosition()
|
||||||
|
{
|
||||||
|
QPainterPath myPath;
|
||||||
|
myPath.moveTo(startPoint);
|
||||||
|
if(!myCorners.isEmpty())
|
||||||
|
foreach(QPointF corner, myCorners){
|
||||||
|
myPath.lineTo(corner);
|
||||||
|
}
|
||||||
|
myPath.lineTo(endPoint);
|
||||||
|
|
||||||
|
setPath(myPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *,
|
||||||
|
QWidget *)
|
||||||
|
{
|
||||||
|
//Update line positions
|
||||||
|
QPen myPen = pen();
|
||||||
|
myPen.setColor(myColor);
|
||||||
|
painter->setPen(myPen);
|
||||||
|
painter->setBrush(myColor);
|
||||||
|
|
||||||
|
QPointF endPos=endPoint;
|
||||||
|
QPointF startPos=startPoint;
|
||||||
|
|
||||||
|
if(myCorners.isEmpty())
|
||||||
|
{
|
||||||
|
myLines.first()->setLine(QLineF(startPos,endPos));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
myLines.first()->setLine(QLineF(startPos,myCorners.first()));
|
||||||
|
for(int i=0; i<myCorners.count()-1;i++)
|
||||||
|
myLines.at(i+1)->setLine(QLineF(myCorners.at(i),myCorners.at(i+1)));
|
||||||
|
myLines.last()->setLine(QLineF(myCorners.last(),endPos));
|
||||||
|
}
|
||||||
|
|
||||||
|
//Drawing arrow selected
|
||||||
|
for(int i=0; i<myLines.count();i++)
|
||||||
|
{
|
||||||
|
if (isSelected())
|
||||||
|
{
|
||||||
|
painter->setPen(QPen(Qt::gray, 2, Qt::SolidLine));
|
||||||
|
QLineF myLine = myLines.at(i)->line();
|
||||||
|
painter->drawLine(myLine);
|
||||||
|
foreach (lineItem *line, myLines) { line->setColor(Qt::gray);}
|
||||||
|
foreach (lineItem *line, myCLines) { line->setColor(Qt::gray);}
|
||||||
|
if(myOwnerScene->items().indexOf(SECLine)!=-1)
|
||||||
|
SECLine->setColor(Qt::gray);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (lineItem *line, myLines) { line->setColor(myColor);}
|
||||||
|
foreach (lineItem *line, myCLines) { line->setColor(myColor);}
|
||||||
|
if(myOwnerScene->items().indexOf(SECLine)!=-1)
|
||||||
|
SECLine->setColor(myColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setSelectedArrows();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Arrow::setSelectedArrows()
|
||||||
|
{
|
||||||
|
bool anySelected = 0;
|
||||||
|
|
||||||
|
foreach(lineItem *line,myLines){ if(line->isSelected())anySelected=1;}
|
||||||
|
foreach(lineItem *line,myCLines){ if(line->isSelected())anySelected=1;}
|
||||||
|
if(isSelected()) anySelected=1;
|
||||||
|
|
||||||
|
if(anySelected)
|
||||||
|
setVisibleCorners(1);
|
||||||
|
else
|
||||||
|
setVisibleCorners(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Arrow::createCorner(QPointF cornerPos, lineItem *inLine)
|
||||||
|
{
|
||||||
|
createCorner(cornerPos,myLines.indexOf(inLine));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Arrow::createCorner(QPointF cornerPos, int index)
|
||||||
|
{
|
||||||
|
if (index != -1)
|
||||||
|
{
|
||||||
|
myCorners.insert(index,cornerPos);
|
||||||
|
lineItem *newLine= new lineItem(cornerPos,cornerPos,this);
|
||||||
|
myOwnerScene->addItem(newLine);
|
||||||
|
newLine->setZValue(this->zValue());
|
||||||
|
addLine(newLine);
|
||||||
|
newLine= new lineItem(cornerPos+QPointF(-0.5,-0.5) ,
|
||||||
|
cornerPos+QPointF(0.5,0.5),this,6,1);
|
||||||
|
myOwnerScene->addItem(newLine);
|
||||||
|
newLine->setZValue(this->zValue()+0.1);
|
||||||
|
myCLines.insert(index,newLine);
|
||||||
|
}
|
||||||
|
updatePosition();
|
||||||
|
}
|
||||||
|
void Arrow::createFirstCorner()
|
||||||
|
{
|
||||||
|
if(myOwnerScene->items().indexOf(SECLine)==-1)
|
||||||
|
{
|
||||||
|
SECLine = new lineItem(startPoint+QPointF(-0.5,-0.5) ,
|
||||||
|
startPoint+QPointF(0.5,0.5),this,6,1);
|
||||||
|
myOwnerScene->addItem(SECLine);
|
||||||
|
SECLine->setVisible(1);
|
||||||
|
SECLine->setZValue(this->zValue()+0.1);
|
||||||
|
}
|
||||||
|
updatePosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Arrow::moveCorner(QPointF cornerPos, lineItem *inLine, bool relative)
|
||||||
|
{
|
||||||
|
int index = myCLines.indexOf(inLine);
|
||||||
|
if(relative) cornerPos=mapFromItem(inLine,cornerPos);
|
||||||
|
|
||||||
|
if (index != -1)
|
||||||
|
{
|
||||||
|
myCorners.replace(index,cornerPos);
|
||||||
|
}
|
||||||
|
else if (inLine == SECLine)
|
||||||
|
{
|
||||||
|
startPoint=cornerPos;
|
||||||
|
endPoint=cornerPos;
|
||||||
|
}
|
||||||
|
updatePosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Arrow::setVisibleCorners(bool visible)
|
||||||
|
{
|
||||||
|
foreach (lineItem *line, myCLines) {
|
||||||
|
line->setVisible(visible);
|
||||||
|
}
|
||||||
|
if(myOwnerScene->items().indexOf(SECLine)!=-1)
|
||||||
|
{
|
||||||
|
SECLine->setVisible(1);
|
||||||
|
}
|
||||||
|
updatePosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Arrow::snapToGrid(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
//TODO implement polygon drag
|
||||||
|
QPointF diffPos= event->scenePos()-previousPos;
|
||||||
|
printf("diff[%f|%f]\n",diffPos.x(),diffPos.y()); fflush(stdout);
|
||||||
|
//Update corners:
|
||||||
|
for(int i=0; i < myCorners.count();i++)
|
||||||
|
{
|
||||||
|
myCLines.at(i)->setLine(QLineF(myCLines.at(i)->line().p1()+diffPos,
|
||||||
|
myCLines.at(i)->line().p2()+diffPos));
|
||||||
|
QPointF itemPos = myCLines.at(i)->line().p1()+QPointF(0.5,0.5);
|
||||||
|
moveCorner(itemPos,myCLines.at(i));
|
||||||
|
}
|
||||||
|
if(myOwnerScene->items().indexOf(SECLine)!=-1)
|
||||||
|
{
|
||||||
|
SECLine->setLine(QLineF(SECLine->line().p1()+diffPos,
|
||||||
|
SECLine->line().p2()+diffPos));
|
||||||
|
QPointF itemPos = SECLine->line().p1()+QPointF(0.5,0.5);
|
||||||
|
moveCorner(itemPos,SECLine);
|
||||||
|
}
|
||||||
|
updatePosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Arrow::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
//if(this->isSelected())
|
||||||
|
{
|
||||||
|
previousPos = event->scenePos();
|
||||||
|
moving=1;
|
||||||
|
}
|
||||||
|
QGraphicsPathItem::mousePressEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Arrow::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
if(moving && isSelected())
|
||||||
|
{
|
||||||
|
snapToGrid(event);
|
||||||
|
previousPos = event->scenePos();
|
||||||
|
}
|
||||||
|
moving=0;
|
||||||
|
QGraphicsPathItem::mouseReleaseEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Arrow::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
if(moving && isSelected())
|
||||||
|
{
|
||||||
|
snapToGrid(event);
|
||||||
|
previousPos = event->scenePos();
|
||||||
|
}
|
||||||
|
QGraphicsPathItem::mouseMoveEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
QDomElement Arrow::toXml(QDomDocument &document) const
|
||||||
|
{
|
||||||
|
QDomElement diagramArrow = document.createElement("Polygon");
|
||||||
|
//Point list
|
||||||
|
if(!myCorners.isEmpty())
|
||||||
|
{
|
||||||
|
QDomElement arrowCorner;
|
||||||
|
//start point
|
||||||
|
arrowCorner = document.createElement("Point");
|
||||||
|
arrowCorner.setAttribute("x",(startPoint-QPointF(500,500)).x());
|
||||||
|
arrowCorner.setAttribute("y",(startPoint-QPointF(500,500)).y());
|
||||||
|
diagramArrow.appendChild(arrowCorner);
|
||||||
|
//corner points
|
||||||
|
foreach(QPointF corner, myCorners)
|
||||||
|
{
|
||||||
|
arrowCorner = document.createElement("Point");
|
||||||
|
arrowCorner.setAttribute("x",(corner-QPointF(500,500)).x());
|
||||||
|
arrowCorner.setAttribute("y",(corner-QPointF(500,500)).y());
|
||||||
|
diagramArrow.appendChild(arrowCorner);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (diagramArrow);
|
||||||
|
}
|
124
Software/sie_cg/block_editor/arrow.h
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
** All rights reserved.
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
|
**
|
||||||
|
** $QT_BEGIN_LICENSE:LGPL$
|
||||||
|
** Commercial Usage
|
||||||
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||||
|
** accordance with the Qt Commercial License Agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Nokia gives you certain additional
|
||||||
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3.0 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU General Public License version 3.0 requirements will be
|
||||||
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||||
|
**
|
||||||
|
** If you have questions regarding the use of this file, please contact
|
||||||
|
** Nokia at qt-info@nokia.com.
|
||||||
|
** $QT_END_LICENSE$
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef ARROW_H
|
||||||
|
#define ARROW_H
|
||||||
|
|
||||||
|
#include <QGraphicsLineItem>
|
||||||
|
#include <QtXml>
|
||||||
|
#include "diagramtextitem.h"
|
||||||
|
#include "diagramscene.h"
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QGraphicsPolygonItem;
|
||||||
|
class QGraphicsLineItem;
|
||||||
|
class QGraphicsPathItem;
|
||||||
|
class QGraphicsScene;
|
||||||
|
class QRectF;
|
||||||
|
class QGraphicsSceneMouseEvent;
|
||||||
|
class QPainterPath;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
class lineItem;
|
||||||
|
class DiagramScene;
|
||||||
|
|
||||||
|
class Arrow : public QGraphicsPathItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum { Type = UserType + 32 };
|
||||||
|
|
||||||
|
Arrow(QPointF startPoint,QPointF endPoint,
|
||||||
|
QGraphicsItem *parent = 0, QGraphicsScene *scene = 0);
|
||||||
|
|
||||||
|
int type() const
|
||||||
|
{ return Type; }
|
||||||
|
QRectF boundingRect() const;
|
||||||
|
QPainterPath shape() const;
|
||||||
|
void setColor(const QColor &color)
|
||||||
|
{ myColor=color; }
|
||||||
|
|
||||||
|
void removeLine(lineItem *line);
|
||||||
|
void removeLines();
|
||||||
|
bool addLine(lineItem *line);
|
||||||
|
void setStartPoint(QPointF point){startPoint=point;}
|
||||||
|
void setEndPoint(QPointF point){endPoint=point;}
|
||||||
|
|
||||||
|
QPointF getStartPoint(){return startPoint;}
|
||||||
|
QPointF getEndPoint(){return endPoint;}
|
||||||
|
|
||||||
|
void createCorner(QPointF cornerPos, lineItem *inLine);
|
||||||
|
void createCorner(QPointF cornerPos, int index);
|
||||||
|
void moveCorner(QPointF cornerPos, lineItem *inLine, bool relative = 1);
|
||||||
|
|
||||||
|
void setVisibleCorners(bool visible);
|
||||||
|
|
||||||
|
void snapToGrid(QGraphicsSceneMouseEvent *event);
|
||||||
|
|
||||||
|
QDomDocument toXmlFormat();
|
||||||
|
QDomElement toXml(QDomDocument &) const;
|
||||||
|
void createFirstCorner();
|
||||||
|
void setSelectedArrows();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void updatePosition();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
|
QWidget *widget = 0);
|
||||||
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QColor myColor;
|
||||||
|
QList<lineItem *> myLines;
|
||||||
|
QList<lineItem *> myCLines;
|
||||||
|
lineItem *SECLine;
|
||||||
|
QPointF startPoint;
|
||||||
|
QPointF endPoint;
|
||||||
|
QList<QPointF> myCorners;
|
||||||
|
QGraphicsScene *myOwnerScene;
|
||||||
|
qreal arrowSize;
|
||||||
|
bool moving;
|
||||||
|
QPointF previousPos;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
BIN
Software/sie_cg/block_editor/diagramitem.o
Normal file
430
Software/sie_cg/block_editor/diagramscene.cpp
Normal file
@ -0,0 +1,430 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
** All rights reserved.
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
|
**
|
||||||
|
** $QT_BEGIN_LICENSE:LGPL$
|
||||||
|
** Commercial Usage
|
||||||
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||||
|
** accordance with the Qt Commercial License Agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Nokia gives you certain additional
|
||||||
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3.0 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU General Public License version 3.0 requirements will be
|
||||||
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||||
|
**
|
||||||
|
** If you have questions regarding the use of this file, please contact
|
||||||
|
** Nokia at qt-info@nokia.com.
|
||||||
|
** $QT_END_LICENSE$
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <QtGui>
|
||||||
|
#include <QHash>
|
||||||
|
#include "diagramscene.h"
|
||||||
|
|
||||||
|
DiagramScene::DiagramScene(QMenu *itemMenu, QObject *parent)
|
||||||
|
: QGraphicsScene(parent)
|
||||||
|
{
|
||||||
|
myItemMenu = itemMenu;
|
||||||
|
myMode = MoveItem;
|
||||||
|
|
||||||
|
line = 0;
|
||||||
|
textItem = 0;
|
||||||
|
myItemColor = Qt::white;
|
||||||
|
myTextColor = Qt::black;
|
||||||
|
myLineColor = Qt::black;
|
||||||
|
snapToGrid=1;
|
||||||
|
myGrid=10;
|
||||||
|
myPolygonPath=0;
|
||||||
|
myCorners=0;
|
||||||
|
|
||||||
|
TitleText = new DiagramTextItem(0,0,1,0xFFF,255,"BLOCK NAME HERE (not visible)",
|
||||||
|
QPointF(250,250));
|
||||||
|
addItem(TitleText);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramScene::editorLostFocus(DiagramTextItem *item)
|
||||||
|
{
|
||||||
|
QTextCursor cursor = item->textCursor();
|
||||||
|
cursor.clearSelection();
|
||||||
|
item->setTextCursor(cursor);
|
||||||
|
|
||||||
|
if (item->toPlainText().isEmpty()) {
|
||||||
|
removeItem(item);
|
||||||
|
item->deleteLater();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramScene::drawBackground(QPainter *p, const QRectF &r)
|
||||||
|
{
|
||||||
|
p -> save();
|
||||||
|
|
||||||
|
p -> setRenderHint(QPainter::Antialiasing, false);
|
||||||
|
p -> setRenderHint(QPainter::TextAntialiasing, true);
|
||||||
|
p -> setRenderHint(QPainter::SmoothPixmapTransform, false);
|
||||||
|
|
||||||
|
p -> setPen(Qt::NoPen);
|
||||||
|
p -> setBrush(Qt::white);
|
||||||
|
p -> drawRect(r);
|
||||||
|
|
||||||
|
|
||||||
|
p -> setPen(Qt::gray);
|
||||||
|
p -> setBrush(Qt::NoBrush);
|
||||||
|
qreal limite_x = r.x() + r.width();
|
||||||
|
qreal limite_y = r.y() + r.height();
|
||||||
|
|
||||||
|
int g_x = (int)ceil(r.x());
|
||||||
|
while (g_x % myGrid) ++ g_x;
|
||||||
|
int g_y = (int)ceil(r.y());
|
||||||
|
while (g_y % myGrid) ++ g_y;
|
||||||
|
|
||||||
|
QPolygon points;
|
||||||
|
for (int gx = g_x ; gx < limite_x ; gx += myGrid) {
|
||||||
|
for (int gy = g_y ; gy < limite_y ; gy += myGrid) {
|
||||||
|
points << QPoint(gx, gy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p -> drawPoints(points);
|
||||||
|
|
||||||
|
p->drawLine(500,0,500,1000);
|
||||||
|
p->drawLine(0,500,1000,500);
|
||||||
|
|
||||||
|
p -> restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramScene::doSnapToGrid(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
|
{
|
||||||
|
if(snapToGrid){
|
||||||
|
mouseEvent->setScenePos(QPointF(
|
||||||
|
int(mouseEvent->scenePos().x()/myGrid)*myGrid,
|
||||||
|
int(mouseEvent->scenePos().y()/myGrid)*myGrid
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
|
{
|
||||||
|
doSnapToGrid(mouseEvent);
|
||||||
|
QString Text;
|
||||||
|
|
||||||
|
if (mouseEvent->button() != Qt::LeftButton)
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch (myMode)
|
||||||
|
{
|
||||||
|
case InsertText:
|
||||||
|
//TODO: limit text items to 255 maximum
|
||||||
|
if(myTextType<256)
|
||||||
|
if(myTextType & 0b10000000)
|
||||||
|
Text = "IN " +myTypeString;
|
||||||
|
else
|
||||||
|
Text = "OUT " +myTypeString;
|
||||||
|
else
|
||||||
|
Text = myTypeString;
|
||||||
|
|
||||||
|
textItem = new DiagramTextItem(0,0,1,myTextType,0,Text,
|
||||||
|
mouseEvent->scenePos());
|
||||||
|
if(addTextItem(textItem))
|
||||||
|
{
|
||||||
|
textItem->setZValue(1000.0);
|
||||||
|
connect(textItem, SIGNAL(lostFocus(DiagramTextItem*)),
|
||||||
|
this, SLOT(editorLostFocus(DiagramTextItem*)));
|
||||||
|
addItem(textItem);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
delete(textItem);
|
||||||
|
QMessageBox::warning(0,"Full","The block can only have only"
|
||||||
|
"255 text items");
|
||||||
|
}
|
||||||
|
emit textInserted(textItem);
|
||||||
|
break;
|
||||||
|
case EditPolygon:
|
||||||
|
if(line == 0 && items().indexOf(myPolygonPath)==-1)
|
||||||
|
{
|
||||||
|
line = new QGraphicsLineItem(QLineF(mouseEvent->scenePos(),
|
||||||
|
mouseEvent->scenePos()));
|
||||||
|
line->setPen(QPen(Qt::blue, 2));
|
||||||
|
line->setZValue(1000.0);
|
||||||
|
addItem(line);
|
||||||
|
}
|
||||||
|
else if(line != 0 && items().indexOf(myPolygonPath)==-1 &&
|
||||||
|
line->line().length()>5)
|
||||||
|
{
|
||||||
|
myPolygonPath = new Arrow(line->line().p1(),line->line().p2(),
|
||||||
|
0,this);
|
||||||
|
QLineF newLine(line->line().p2(),line->line().p2());
|
||||||
|
line->setLine(newLine);
|
||||||
|
}
|
||||||
|
else if(line != 0 && items().indexOf(myPolygonPath)!=-1 &&
|
||||||
|
line->line().length()>5)
|
||||||
|
{
|
||||||
|
myPolygonPath->createCorner(line->line().p1(),myCorners);
|
||||||
|
myPolygonPath->setEndPoint(line->line().p2());
|
||||||
|
myPolygonPath->updatePosition();
|
||||||
|
QLineF newLine(line->line().p2(),line->line().p2());
|
||||||
|
line->setLine(newLine);
|
||||||
|
|
||||||
|
myCorners++;
|
||||||
|
}
|
||||||
|
|
||||||
|
case MoveItem:
|
||||||
|
QGraphicsScene::mousePressEvent(mouseEvent);
|
||||||
|
break;
|
||||||
|
default: ;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
|
{
|
||||||
|
doSnapToGrid(mouseEvent);
|
||||||
|
if (myMode == EditPolygon && line != 0 )
|
||||||
|
{
|
||||||
|
QLineF newLine(line->line().p1(), mouseEvent->scenePos());
|
||||||
|
line->setLine(newLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
QGraphicsScene::mouseMoveEvent(mouseEvent);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
|
{
|
||||||
|
doSnapToGrid(mouseEvent);
|
||||||
|
if (myMode == EditPolygon && line != 0 && myCorners>0)
|
||||||
|
{
|
||||||
|
if(myPolygonPath->getStartPoint()!=line->line().p2())
|
||||||
|
myPolygonPath->createCorner(line->line().p2(),myCorners);
|
||||||
|
|
||||||
|
myPolygonPath->setEndPoint(myPolygonPath->getStartPoint());
|
||||||
|
myPolygonPath->createFirstCorner();
|
||||||
|
myPolygonPath->updatePosition();
|
||||||
|
myCorners=0;
|
||||||
|
removeItem(line);
|
||||||
|
line = 0;
|
||||||
|
myMode = MoveItem;
|
||||||
|
emit textInserted(textItem);//Is the same for all buttons
|
||||||
|
}
|
||||||
|
else if (myMode != EditPolygon)
|
||||||
|
{
|
||||||
|
QGraphicsScene::mouseDoubleClickEvent(mouseEvent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
|
{
|
||||||
|
doSnapToGrid(mouseEvent);
|
||||||
|
if (myMode != EditPolygon && line == 0)
|
||||||
|
QGraphicsScene::mouseReleaseEvent(mouseEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DiagramScene::isItemChange(int type)
|
||||||
|
{
|
||||||
|
foreach (QGraphicsItem *item, selectedItems()) {
|
||||||
|
if (item->type() == type)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDomDocument DiagramScene::toXmlFormat()
|
||||||
|
{
|
||||||
|
QDomDocument document;
|
||||||
|
QDomComment initialComments=document.createComment(
|
||||||
|
"File for SIE Code Generator. Custmos Blocks");
|
||||||
|
document.appendChild(initialComments);
|
||||||
|
QDomElement diagram = document.createElement("CustomItem");
|
||||||
|
diagram.setAttribute("BlockName",TitleText->toPlainText());
|
||||||
|
document.appendChild(diagram);
|
||||||
|
//Lists of items
|
||||||
|
QList<DiagramTextItem *> Items;
|
||||||
|
QList<Arrow *> Arrows;
|
||||||
|
foreach(QGraphicsItem *item, items())
|
||||||
|
{
|
||||||
|
if(item->type() == DiagramTextItem::Type)
|
||||||
|
Items.append(qgraphicsitem_cast<DiagramTextItem *>(item));
|
||||||
|
else if(item->type() == Arrow::Type)
|
||||||
|
Arrows.append(qgraphicsitem_cast<Arrow *>(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Arrows.count()>1) {printf("Something is wrong.\n"); fflush(stdout);}
|
||||||
|
|
||||||
|
//Create the XML structure
|
||||||
|
diagram.appendChild(myPolygonPath->toXml(document));
|
||||||
|
|
||||||
|
QDomElement element;
|
||||||
|
if(Items.count()>0)
|
||||||
|
{
|
||||||
|
QDomElement textItems = document.createElement("TextItems");
|
||||||
|
foreach(DiagramTextItem *item, Items)
|
||||||
|
{
|
||||||
|
if(item->styleIO() != 0xFFF)
|
||||||
|
{
|
||||||
|
element = item->toXml(document);
|
||||||
|
element.setAttribute("ID",textItemsByID.key(item));
|
||||||
|
textItems.appendChild(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
diagram.appendChild(textItems);
|
||||||
|
}
|
||||||
|
|
||||||
|
return(document);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DiagramScene::fromXmlFormat(QDomDocument document)
|
||||||
|
{
|
||||||
|
//Read items TODO: in future... add multi items on same file
|
||||||
|
QDomNodeList customsItems = document.elementsByTagName("CustomItem");
|
||||||
|
if(!customsItems.at(0).isElement())
|
||||||
|
return -1;
|
||||||
|
//Load the first item in the document
|
||||||
|
QDomElement customItem = customsItems.at(0).toElement();
|
||||||
|
if(customItem.attribute("BlockName")=="")
|
||||||
|
TitleText->setPlainText("Please set Block Name");
|
||||||
|
else
|
||||||
|
TitleText->setPlainText(customItem.attribute("BlockName"));
|
||||||
|
TitleText->updatePosition();
|
||||||
|
for (QDomNode node = customItem.firstChild() ;
|
||||||
|
!node.isNull() ;
|
||||||
|
node = node.nextSibling())
|
||||||
|
{
|
||||||
|
QDomElement element = node.toElement();
|
||||||
|
if(element.tagName()=="Polygon")
|
||||||
|
{
|
||||||
|
QList<QPointF> points;
|
||||||
|
for (QDomNode node = element.firstChild() ;
|
||||||
|
!node.isNull() ;
|
||||||
|
node = node.nextSibling())
|
||||||
|
{
|
||||||
|
QDomElement point = node.toElement();
|
||||||
|
if(point.tagName()!="Point")
|
||||||
|
return -1;
|
||||||
|
points.append(QPointF((QPointF(point.attribute("x").toFloat(),0)
|
||||||
|
+QPointF(500,500)).x(),
|
||||||
|
(QPointF(0,point.attribute("y").toFloat())
|
||||||
|
+QPointF(500,500)).y()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(points.count()>0)
|
||||||
|
{
|
||||||
|
myPolygonPath = new Arrow(points.at(0),points.at(0),0,this);
|
||||||
|
for(int i=1; i< points.count();i++)
|
||||||
|
{
|
||||||
|
myPolygonPath->createCorner(points.at(i),i-1);
|
||||||
|
}
|
||||||
|
myPolygonPath->createFirstCorner();
|
||||||
|
myPolygonPath->updatePosition();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(element.tagName()=="TextItems")
|
||||||
|
{
|
||||||
|
for (QDomNode node = element.firstChild() ;
|
||||||
|
!node.isNull() ;
|
||||||
|
node = node.nextSibling())
|
||||||
|
{
|
||||||
|
QDomElement textItemE = node.toElement();
|
||||||
|
if(textItemE.tagName()!="TextItem")
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
int myStyleIO = textItemE.attribute("myStyleIO").toInt();
|
||||||
|
int myID = textItemE.attribute("ID").toInt();
|
||||||
|
bool editableItem = textItemE.attribute("editableItem").toInt();
|
||||||
|
QPointF posOffset=
|
||||||
|
QPointF((QPointF(textItemE.attribute("posOffset-x")
|
||||||
|
.toFloat(),0)+QPointF(500,500)).x(),
|
||||||
|
(-QPointF(0,textItemE.attribute("posOffset-y")
|
||||||
|
.toFloat())+QPointF(500,500)).y());
|
||||||
|
QString itemString=textItemE.attribute("text");
|
||||||
|
|
||||||
|
if(myStyleIO==0)
|
||||||
|
{
|
||||||
|
if(!editableItem)
|
||||||
|
myStyleIO=256;
|
||||||
|
else
|
||||||
|
myStyleIO=257;
|
||||||
|
}
|
||||||
|
|
||||||
|
DiagramTextItem * newTextItem =
|
||||||
|
new DiagramTextItem(0,0,1,myStyleIO,myID,itemString,posOffset);
|
||||||
|
newTextItem->setZValue(1000.0);
|
||||||
|
connect(newTextItem, SIGNAL(lostFocus(DiagramTextItem*)),
|
||||||
|
this, SLOT(editorLostFocus(DiagramTextItem*)));
|
||||||
|
addItem(newTextItem);
|
||||||
|
textItemsByID.insert(myID,newTextItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramScene::cleanScene()
|
||||||
|
{
|
||||||
|
//Lists of items
|
||||||
|
QList<DiagramTextItem *> Items;
|
||||||
|
foreach(QGraphicsItem *item, items())
|
||||||
|
{
|
||||||
|
if(item->type() == DiagramTextItem::Type)
|
||||||
|
Items.append(qgraphicsitem_cast<DiagramTextItem *>(item));
|
||||||
|
}
|
||||||
|
//Remove Diagram Text Items
|
||||||
|
foreach(DiagramTextItem *item, Items)
|
||||||
|
{
|
||||||
|
if(item->styleIO() != 0xFFF)
|
||||||
|
{
|
||||||
|
removeItem(item);
|
||||||
|
delete(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Remove Polygon Path
|
||||||
|
if(items().indexOf(myPolygonPath)!=-1)
|
||||||
|
{
|
||||||
|
myPolygonPath->removeLines();
|
||||||
|
removeItem(myPolygonPath);
|
||||||
|
delete(myPolygonPath);
|
||||||
|
}
|
||||||
|
TitleText->setPlainText("BLOCK NAME HERE (not visible)");
|
||||||
|
TitleText->updatePosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
int DiagramScene::addTextItem(DiagramTextItem * textItem)
|
||||||
|
{
|
||||||
|
for(int i=0; i<255; i++)
|
||||||
|
{
|
||||||
|
QHash<int,DiagramTextItem *>::iterator iter= textItemsByID.find(i);
|
||||||
|
if(iter==textItemsByID.end())
|
||||||
|
{
|
||||||
|
textItemsByID.insert(i,textItem);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramScene::removeTextItem(DiagramTextItem * textItem)
|
||||||
|
{
|
||||||
|
textItemsByID.remove(textItemsByID.key(textItem));
|
||||||
|
}
|
121
Software/sie_cg/block_editor/diagramscene.h
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
** All rights reserved.
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
|
**
|
||||||
|
** $QT_BEGIN_LICENSE:LGPL$
|
||||||
|
** Commercial Usage
|
||||||
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||||
|
** accordance with the Qt Commercial License Agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Nokia gives you certain additional
|
||||||
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3.0 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU General Public License version 3.0 requirements will be
|
||||||
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||||
|
**
|
||||||
|
** If you have questions regarding the use of this file, please contact
|
||||||
|
** Nokia at qt-info@nokia.com.
|
||||||
|
** $QT_END_LICENSE$
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef DIAGRAMSCENE_H
|
||||||
|
#define DIAGRAMSCENE_H
|
||||||
|
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
#include <QDesktopServices>
|
||||||
|
#include <QtXml>
|
||||||
|
#include "diagramtextitem.h"
|
||||||
|
#include "arrow.h"
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QGraphicsSceneMouseEvent;
|
||||||
|
class QMenu;
|
||||||
|
class QPointF;
|
||||||
|
class QGraphicsLineItem;
|
||||||
|
class QFont;
|
||||||
|
class QGraphicsTextItem;
|
||||||
|
class QColor;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
class Arrow;
|
||||||
|
class DiagramTextItem;
|
||||||
|
|
||||||
|
class DiagramScene : public QGraphicsScene
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum Mode { MoveItem , EditPolygon, InsertText };
|
||||||
|
|
||||||
|
DiagramScene(QMenu *itemMenu, QObject *parent = 0);
|
||||||
|
|
||||||
|
QDomDocument toXmlFormat();
|
||||||
|
int fromXmlFormat(QDomDocument xmlDocument);
|
||||||
|
void cleanScene();
|
||||||
|
void setTextType(int type,QString text){myTextType=type;myTypeString=text;}
|
||||||
|
void resetMyPolygon(){myPolygonPath=0;}
|
||||||
|
|
||||||
|
QHash<int,DiagramTextItem*> getTextItemsByID;
|
||||||
|
|
||||||
|
int addTextItem(DiagramTextItem * textItem);
|
||||||
|
void removeTextItem(DiagramTextItem * textItem);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void setMode(Mode mode){myMode=mode;}
|
||||||
|
void editorLostFocus(DiagramTextItem *item);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void textInserted(QGraphicsTextItem *item);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
||||||
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
||||||
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
||||||
|
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
void drawBackground(QPainter *p, const QRectF &r);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool isItemChange(int type);
|
||||||
|
void doSnapToGrid(QGraphicsSceneMouseEvent *mouseEvent);
|
||||||
|
QMenu *myItemMenu;
|
||||||
|
Mode myMode;
|
||||||
|
int myTextType;
|
||||||
|
QString myTypeString;
|
||||||
|
bool leftButtonDown;
|
||||||
|
QPointF startPoint;
|
||||||
|
QGraphicsLineItem *line;
|
||||||
|
Arrow *myPolygonPath;
|
||||||
|
QFont myFont;
|
||||||
|
DiagramTextItem *textItem;
|
||||||
|
DiagramTextItem *TitleText;
|
||||||
|
QColor myTextColor;
|
||||||
|
QColor myItemColor;
|
||||||
|
QColor myLineColor;
|
||||||
|
bool snapToGrid;
|
||||||
|
short int myGrid;
|
||||||
|
int myCorners;
|
||||||
|
QHash<int,DiagramTextItem*> textItemsByID;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
30
Software/sie_cg/block_editor/diagramscene.pro
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
HEADERS = mainwindow.h \
|
||||||
|
diagramscene.h \
|
||||||
|
arrow.h \
|
||||||
|
diagramtextitem.h \
|
||||||
|
lineitem.h
|
||||||
|
SOURCES = mainwindow.cpp \
|
||||||
|
main.cpp \
|
||||||
|
arrow.cpp \
|
||||||
|
diagramtextitem.cpp \
|
||||||
|
diagramscene.cpp \
|
||||||
|
lineitem.cpp
|
||||||
|
RESOURCES = diagramscene.qrc
|
||||||
|
|
||||||
|
TARGET = blockeditor
|
||||||
|
|
||||||
|
# install
|
||||||
|
target.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/diagramscene
|
||||||
|
sources.files = $$SOURCES \
|
||||||
|
$$HEADERS \
|
||||||
|
$$RESOURCES \
|
||||||
|
$$FORMS \
|
||||||
|
diagramscene.pro \
|
||||||
|
images
|
||||||
|
sources.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/diagramscene
|
||||||
|
INSTALLS += target \
|
||||||
|
sources
|
||||||
|
symbian:include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
|
||||||
|
QT += xml \
|
||||||
|
svg \
|
||||||
|
network
|
245
Software/sie_cg/block_editor/diagramscene.pro.user
Normal file
@ -0,0 +1,245 @@
|
|||||||
|
<!DOCTYPE QtCreatorProject>
|
||||||
|
<qtcreator>
|
||||||
|
<data>
|
||||||
|
<variable>RunConfiguration0-BaseEnvironmentBase</variable>
|
||||||
|
<value type="int">2</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>RunConfiguration0-CommandLineArguments</variable>
|
||||||
|
<valuelist type="QVariantList"/>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>RunConfiguration0-ProFile</variable>
|
||||||
|
<value type="QString">diagramscene.pro</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>RunConfiguration0-RunConfiguration.name</variable>
|
||||||
|
<value type="QString">diagramscene</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>RunConfiguration0-UseDyldImageSuffix</variable>
|
||||||
|
<value type="bool">false</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>RunConfiguration0-UseTerminal</variable>
|
||||||
|
<value type="bool">false</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>RunConfiguration0-UserEnvironmentChanges</variable>
|
||||||
|
<valuelist type="QVariantList"/>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>RunConfiguration0-UserSetName</variable>
|
||||||
|
<value type="bool">false</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>RunConfiguration0-UserSetWorkingDirectory</variable>
|
||||||
|
<value type="bool">false</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>RunConfiguration0-UserWorkingDirectory</variable>
|
||||||
|
<value type="QString"></value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>RunConfiguration0-type</variable>
|
||||||
|
<value type="QString">Qt4ProjectManager.Qt4RunConfiguration</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>activeRunConfiguration</variable>
|
||||||
|
<value type="int">0</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>activebuildconfiguration</variable>
|
||||||
|
<value type="QString">Debug</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>buildConfiguration-Debug</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value>
|
||||||
|
<value key="QtVersionId" type="int">0</value>
|
||||||
|
<value key="ToolChain" type="int">0</value>
|
||||||
|
<value key="addQDumper" type=""></value>
|
||||||
|
<value key="buildConfiguration" type="int">2</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>buildConfiguration-Release</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Release</value>
|
||||||
|
<value key="QtVersionId" type="int">0</value>
|
||||||
|
<value key="addQDumper" type=""></value>
|
||||||
|
<value key="buildConfiguration" type="int">0</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>buildconfiguration-Debug-buildstep0</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value>
|
||||||
|
<valuelist key="abstractProcess.Environment" type="QVariantList">
|
||||||
|
<value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-MI4KrAyPP5,guid=5c5c5e6146195c74b6ad266d4cc07afd</value>
|
||||||
|
<value type="QString">DEFAULTS_PATH=/usr/share/gconf/gnome.default.path</value>
|
||||||
|
<value type="QString">DESKTOP_SESSION=gnome</value>
|
||||||
|
<value type="QString">DISPLAY=:0.0</value>
|
||||||
|
<value type="QString">GDMSESSION=gnome</value>
|
||||||
|
<value type="QString">GDM_KEYBOARD_LAYOUT=es</value>
|
||||||
|
<value type="QString">GDM_LANG=en_US.utf8</value>
|
||||||
|
<value type="QString">GNOME_DESKTOP_SESSION_ID=this-is-deprecated</value>
|
||||||
|
<value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-CFAuJK</value>
|
||||||
|
<value type="QString">GNOME_KEYRING_PID=1516</value>
|
||||||
|
<value type="QString">GTK_MODULES=canberra-gtk-module</value>
|
||||||
|
<value type="QString">HOME=/home/juan64bits</value>
|
||||||
|
<value type="QString">LANG=en_US.utf8</value>
|
||||||
|
<value type="QString">LD_LIBRARY_PATH=/usr/lib/qtcreator</value>
|
||||||
|
<value type="QString">LOGNAME=juan64bits</value>
|
||||||
|
<value type="QString">MANDATORY_PATH=/usr/share/gconf/gnome.mandatory.path</value>
|
||||||
|
<value type="QString">ORBIT_SOCKETDIR=/tmp/orbit-juan64bits</value>
|
||||||
|
<value type="QString">PATH=/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games</value>
|
||||||
|
<value type="QString">PWD=/home/juan64bits</value>
|
||||||
|
<value type="QString">QTDIR=/usr/share/qt4</value>
|
||||||
|
<value type="QString">SESSION_MANAGER=local/Maximus:@/tmp/.ICE-unix/1534,unix/Maximus:/tmp/.ICE-unix/1534</value>
|
||||||
|
<value type="QString">SHELL=/bin/bash</value>
|
||||||
|
<value type="QString">SPEECHD_PORT=7560</value>
|
||||||
|
<value type="QString">SSH_AGENT_PID=1570</value>
|
||||||
|
<value type="QString">SSH_AUTH_SOCK=/tmp/keyring-CFAuJK/ssh</value>
|
||||||
|
<value type="QString">USER=juan64bits</value>
|
||||||
|
<value type="QString">USERNAME=juan64bits</value>
|
||||||
|
<value type="QString">XAUTHORITY=/var/run/gdm/auth-for-juan64bits-V4ry7M/database</value>
|
||||||
|
<value type="QString">XDG_CONFIG_DIRS=/etc/xdg/xdg-gnome:/etc/xdg</value>
|
||||||
|
<value type="QString">XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/</value>
|
||||||
|
<value type="QString">XDG_SESSION_COOKIE=b9a7fbc4d869fc15bd6cdd474bcc9a28-1287682812.550485-1725059380</value>
|
||||||
|
</valuelist>
|
||||||
|
<valuelist key="abstractProcess.arguments" type="QVariantList">
|
||||||
|
<value type="QString">/home/juan64bits/QT/diagramscene/block_editor/diagramscene.pro</value>
|
||||||
|
<value type="QString">-spec</value>
|
||||||
|
<value type="QString">linux-g++</value>
|
||||||
|
<value type="QString">-r</value>
|
||||||
|
<value type="QString">CONFIG+=debug</value>
|
||||||
|
</valuelist>
|
||||||
|
<value key="abstractProcess.command" type="QString">/usr/bin/qmake-qt4</value>
|
||||||
|
<value key="abstractProcess.enabled" type="bool">false</value>
|
||||||
|
<value key="abstractProcess.workingDirectory" type="QString">/home/juan64bits/QT/diagramscene/block_editor</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>buildconfiguration-Debug-buildstep1</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value>
|
||||||
|
<valuelist key="abstractProcess.Environment" type="QVariantList">
|
||||||
|
<value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-MI4KrAyPP5,guid=5c5c5e6146195c74b6ad266d4cc07afd</value>
|
||||||
|
<value type="QString">DEFAULTS_PATH=/usr/share/gconf/gnome.default.path</value>
|
||||||
|
<value type="QString">DESKTOP_SESSION=gnome</value>
|
||||||
|
<value type="QString">DISPLAY=:0.0</value>
|
||||||
|
<value type="QString">GDMSESSION=gnome</value>
|
||||||
|
<value type="QString">GDM_KEYBOARD_LAYOUT=es</value>
|
||||||
|
<value type="QString">GDM_LANG=en_US.utf8</value>
|
||||||
|
<value type="QString">GNOME_DESKTOP_SESSION_ID=this-is-deprecated</value>
|
||||||
|
<value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-CFAuJK</value>
|
||||||
|
<value type="QString">GNOME_KEYRING_PID=1516</value>
|
||||||
|
<value type="QString">GTK_MODULES=canberra-gtk-module</value>
|
||||||
|
<value type="QString">HOME=/home/juan64bits</value>
|
||||||
|
<value type="QString">LANG=en_US.utf8</value>
|
||||||
|
<value type="QString">LD_LIBRARY_PATH=/usr/lib/qtcreator</value>
|
||||||
|
<value type="QString">LOGNAME=juan64bits</value>
|
||||||
|
<value type="QString">MANDATORY_PATH=/usr/share/gconf/gnome.mandatory.path</value>
|
||||||
|
<value type="QString">ORBIT_SOCKETDIR=/tmp/orbit-juan64bits</value>
|
||||||
|
<value type="QString">PATH=/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games</value>
|
||||||
|
<value type="QString">PWD=/home/juan64bits</value>
|
||||||
|
<value type="QString">QTDIR=/usr/share/qt4</value>
|
||||||
|
<value type="QString">SESSION_MANAGER=local/Maximus:@/tmp/.ICE-unix/1534,unix/Maximus:/tmp/.ICE-unix/1534</value>
|
||||||
|
<value type="QString">SHELL=/bin/bash</value>
|
||||||
|
<value type="QString">SPEECHD_PORT=7560</value>
|
||||||
|
<value type="QString">SSH_AGENT_PID=1570</value>
|
||||||
|
<value type="QString">SSH_AUTH_SOCK=/tmp/keyring-CFAuJK/ssh</value>
|
||||||
|
<value type="QString">USER=juan64bits</value>
|
||||||
|
<value type="QString">USERNAME=juan64bits</value>
|
||||||
|
<value type="QString">XAUTHORITY=/var/run/gdm/auth-for-juan64bits-V4ry7M/database</value>
|
||||||
|
<value type="QString">XDG_CONFIG_DIRS=/etc/xdg/xdg-gnome:/etc/xdg</value>
|
||||||
|
<value type="QString">XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/</value>
|
||||||
|
<value type="QString">XDG_SESSION_COOKIE=b9a7fbc4d869fc15bd6cdd474bcc9a28-1287682812.550485-1725059380</value>
|
||||||
|
</valuelist>
|
||||||
|
<value key="abstractProcess.IgnoreReturnValue" type="bool">false</value>
|
||||||
|
<valuelist key="abstractProcess.arguments" type="QVariantList">
|
||||||
|
<value type="QString">-w</value>
|
||||||
|
</valuelist>
|
||||||
|
<value key="abstractProcess.command" type="QString">/usr/bin/make</value>
|
||||||
|
<value key="abstractProcess.enabled" type="bool">true</value>
|
||||||
|
<value key="abstractProcess.workingDirectory" type="QString">/home/juan64bits/QT/diagramscene/block_editor</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>buildconfiguration-Debug-cleanstep0</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value>
|
||||||
|
<value key="cleanConfig" type="bool">true</value>
|
||||||
|
<valuelist key="makeargs" type="QVariantList">
|
||||||
|
<value type="QString">clean</value>
|
||||||
|
</valuelist>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>buildconfiguration-Release-buildstep0</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Release</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>buildconfiguration-Release-buildstep1</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Release</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>buildconfiguration-Release-cleanstep0</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Release</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>buildconfigurations</variable>
|
||||||
|
<valuelist type="QVariantList">
|
||||||
|
<value type="QString">Debug</value>
|
||||||
|
<value type="QString">Release</value>
|
||||||
|
</valuelist>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>buildstep0</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString"></value>
|
||||||
|
<value key="mkspec" type="QString"></value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>buildstep1</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString"></value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>buildsteps</variable>
|
||||||
|
<valuelist type="QVariantList">
|
||||||
|
<value type="QString">trolltech.qt4projectmanager.qmake</value>
|
||||||
|
<value type="QString">trolltech.qt4projectmanager.make</value>
|
||||||
|
</valuelist>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>cleanstep0</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString"></value>
|
||||||
|
<value key="clean" type="bool">true</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>cleansteps</variable>
|
||||||
|
<valuelist type="QVariantList">
|
||||||
|
<value type="QString">trolltech.qt4projectmanager.make</value>
|
||||||
|
</valuelist>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>defaultFileEncoding</variable>
|
||||||
|
<value type="QByteArray">System</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>project</variable>
|
||||||
|
<valuemap type="QVariantMap"/>
|
||||||
|
</data>
|
||||||
|
</qtcreator>
|
28
Software/sie_cg/block_editor/diagramscene.qrc
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<RCC>
|
||||||
|
<qresource prefix="/">
|
||||||
|
<file>../images/pointer.png</file>
|
||||||
|
<file>../images/linepointer.png</file>
|
||||||
|
<file>../images/textpointer.png</file>
|
||||||
|
<file>../images/bold.png</file>
|
||||||
|
<file>../images/italic.png</file>
|
||||||
|
<file>../images/underline.png</file>
|
||||||
|
<file>../images/floodfill.png</file>
|
||||||
|
<file>../images/bringtofront.png</file>
|
||||||
|
<file>../images/delete.png</file>
|
||||||
|
<file>../images/sendtoback.png</file>
|
||||||
|
<file>../images/linecolor.png</file>
|
||||||
|
<file>../images/background1.png</file>
|
||||||
|
<file>../images/background2.png</file>
|
||||||
|
<file>../images/background3.png</file>
|
||||||
|
<file>../images/background4.png</file>
|
||||||
|
<file>../images/exit.png</file>
|
||||||
|
<file>../images/new.png</file>
|
||||||
|
<file>../images/no.png</file>
|
||||||
|
<file>../images/open.png</file>
|
||||||
|
<file>../images/save.png</file>
|
||||||
|
<file>../images/save_as.png</file>
|
||||||
|
<file>../images/yes.png</file>
|
||||||
|
<file>../images/zoom_in.png</file>
|
||||||
|
<file>../images/zoom_out.png</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
165
Software/sie_cg/block_editor/diagramtextitem.cpp
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
** All rights reserved.
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
|
**
|
||||||
|
** $QT_BEGIN_LICENSE:LGPL$
|
||||||
|
** Commercial Usage
|
||||||
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||||
|
** accordance with the Qt Commercial License Agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Nokia gives you certain additional
|
||||||
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3.0 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU General Public License version 3.0 requirements will be
|
||||||
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||||
|
**
|
||||||
|
** If you have questions regarding the use of this file, please contact
|
||||||
|
** Nokia at qt-info@nokia.com.
|
||||||
|
** $QT_END_LICENSE$
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <QtGui>
|
||||||
|
|
||||||
|
#include "diagramtextitem.h"
|
||||||
|
#include "diagramscene.h"
|
||||||
|
|
||||||
|
DiagramTextItem::DiagramTextItem(
|
||||||
|
QGraphicsItem *parent, QGraphicsScene *scene,
|
||||||
|
bool editable, int styleIO,
|
||||||
|
unsigned char ID, QString defaultText, QPointF offset)
|
||||||
|
: QGraphicsTextItem(parent, scene)
|
||||||
|
{
|
||||||
|
myOwnerScene=scene;
|
||||||
|
myStyleIO = styleIO;
|
||||||
|
myID=ID;
|
||||||
|
editableItem=editable;
|
||||||
|
setPlainText(defaultText);
|
||||||
|
posOffset=offset;
|
||||||
|
//setFlag(QGraphicsItem::ItemIsMovable,0);
|
||||||
|
if(editable)
|
||||||
|
setFlag(QGraphicsItem::ItemIsSelectable,1);
|
||||||
|
else
|
||||||
|
setFlag(QGraphicsItem::ItemIsFocusable,0);
|
||||||
|
|
||||||
|
updatePosition();
|
||||||
|
moving=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramTextItem::updatePosition()
|
||||||
|
{
|
||||||
|
if(myStyleIO>255)
|
||||||
|
setPos(posOffset+QPointF(-boundingRect().width()/2,
|
||||||
|
-boundingRect().height()/2));
|
||||||
|
else if(myStyleIO & 0b10000000)
|
||||||
|
setPos(posOffset+QPointF(0,-boundingRect().height()/2));
|
||||||
|
else //OUT
|
||||||
|
setPos(posOffset+QPointF(-boundingRect().width(),
|
||||||
|
-boundingRect().height()/2));
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant DiagramTextItem::itemChange(GraphicsItemChange change,
|
||||||
|
const QVariant &value)
|
||||||
|
{
|
||||||
|
if (change == QGraphicsItem::ItemSelectedHasChanged)
|
||||||
|
emit selectedChange(this);
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramTextItem::focusOutEvent(QFocusEvent *event)
|
||||||
|
{
|
||||||
|
if(editableItem)
|
||||||
|
{
|
||||||
|
if(toPlainText()=="") setPlainText("?");
|
||||||
|
//updatePosition();
|
||||||
|
setTextInteractionFlags(Qt::NoTextInteraction);
|
||||||
|
emit lostFocus(this);
|
||||||
|
QGraphicsTextItem::focusOutEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramTextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
if(editableItem)
|
||||||
|
{
|
||||||
|
if (textInteractionFlags() == Qt::NoTextInteraction)
|
||||||
|
setTextInteractionFlags(Qt::TextEditorInteraction);
|
||||||
|
}
|
||||||
|
QGraphicsTextItem::mouseDoubleClickEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramTextItem::snapToGrid(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
if(myStyleIO!=0xFFF)
|
||||||
|
setOffset(event->scenePos());
|
||||||
|
updatePosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
moving=1;
|
||||||
|
//snapToGrid(event);
|
||||||
|
QGraphicsTextItem::mousePressEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
moving=0;
|
||||||
|
QGraphicsTextItem::mouseReleaseEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
if(moving)
|
||||||
|
snapToGrid(event);
|
||||||
|
|
||||||
|
QGraphicsTextItem::mouseMoveEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
QDomElement DiagramTextItem::toXml(QDomDocument &document) const
|
||||||
|
{
|
||||||
|
QDomElement textItem = document.createElement("TextItem");
|
||||||
|
textItem.setAttribute("text",toPlainText());
|
||||||
|
if(myStyleIO<256)
|
||||||
|
{
|
||||||
|
textItem.setAttribute("myStyleIO",myStyleIO);
|
||||||
|
textItem.setAttribute("editableItem",0);
|
||||||
|
}
|
||||||
|
else if (myStyleIO==256)
|
||||||
|
{
|
||||||
|
textItem.setAttribute("myStyleIO",0);
|
||||||
|
textItem.setAttribute("editableItem",0);
|
||||||
|
}
|
||||||
|
else if (myStyleIO==257)
|
||||||
|
{
|
||||||
|
textItem.setAttribute("myStyleIO",0);
|
||||||
|
textItem.setAttribute("editableItem",1);
|
||||||
|
}
|
||||||
|
textItem.setAttribute("posOffset-x",
|
||||||
|
QPointF(posOffset-QPointF(500,500)).x());
|
||||||
|
textItem.setAttribute("posOffset-y",
|
||||||
|
-QPointF(posOffset-QPointF(500,500)).y());
|
||||||
|
return (textItem);
|
||||||
|
}
|
||||||
|
|
118
Software/sie_cg/block_editor/diagramtextitem.h
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
** All rights reserved.
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
|
**
|
||||||
|
** $QT_BEGIN_LICENSE:LGPL$
|
||||||
|
** Commercial Usage
|
||||||
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||||
|
** accordance with the Qt Commercial License Agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Nokia gives you certain additional
|
||||||
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3.0 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU General Public License version 3.0 requirements will be
|
||||||
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||||
|
**
|
||||||
|
** If you have questions regarding the use of this file, please contact
|
||||||
|
** Nokia at qt-info@nokia.com.
|
||||||
|
** $QT_END_LICENSE$
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef DIAGRAMTEXTITEM_H
|
||||||
|
#define DIAGRAMTEXTITEM_H
|
||||||
|
|
||||||
|
#include <QGraphicsTextItem>
|
||||||
|
#include <QPen>
|
||||||
|
#include "diagramscene.h"
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QFocusEvent;
|
||||||
|
class QGraphicsItem;
|
||||||
|
class QGraphicsScene;
|
||||||
|
class QGraphicsSceneMouseEvent;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
class DiagramTextItem : public QGraphicsTextItem
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum { Type = UserType + 3 };
|
||||||
|
|
||||||
|
DiagramTextItem(
|
||||||
|
QGraphicsItem *parent = 0, QGraphicsScene *scene = 0,
|
||||||
|
bool editable =1, int styleIO = 0,
|
||||||
|
unsigned char ID=0, QString defaultText="<text>",
|
||||||
|
QPointF offset=QPointF(0,0));
|
||||||
|
|
||||||
|
int type() const
|
||||||
|
{ return Type;}
|
||||||
|
|
||||||
|
int styleIO()
|
||||||
|
{ return myStyleIO;}
|
||||||
|
|
||||||
|
unsigned char ID()
|
||||||
|
{ return myID;}
|
||||||
|
|
||||||
|
unsigned char textID() const
|
||||||
|
{ return myID;}
|
||||||
|
|
||||||
|
QPointF offset() const
|
||||||
|
{ return posOffset;}
|
||||||
|
|
||||||
|
void setOffset(QPointF offset)
|
||||||
|
{ posOffset=offset;}
|
||||||
|
|
||||||
|
bool isEditable()
|
||||||
|
{ return editableItem;}
|
||||||
|
|
||||||
|
void snapToGrid(QGraphicsSceneMouseEvent *event);
|
||||||
|
|
||||||
|
QDomElement toXml(QDomDocument &document) const;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void updatePosition();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void lostFocus(DiagramTextItem *item);
|
||||||
|
void selectedChange(QGraphicsItem *item);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||||
|
void focusOutEvent(QFocusEvent *event);
|
||||||
|
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool editableItem;
|
||||||
|
QPointF posOffset;
|
||||||
|
int myStyleIO;
|
||||||
|
unsigned char myID;
|
||||||
|
QGraphicsScene *myOwnerScene;
|
||||||
|
bool moving;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
140
Software/sie_cg/block_editor/lineitem.cpp
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
** All rights reserved.
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
|
**
|
||||||
|
** $QT_BEGIN_LICENSE:LGPL$
|
||||||
|
** Commercial Usage
|
||||||
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||||
|
** accordance with the Qt Commercial License Agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Nokia gives you certain additional
|
||||||
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3.0 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU General Public License version 3.0 requirements will be
|
||||||
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||||
|
**
|
||||||
|
** If you have questions regarding the use of this file, please contact
|
||||||
|
** Nokia at qt-info@nokia.com.
|
||||||
|
** $QT_END_LICENSE$
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <QtGui>
|
||||||
|
|
||||||
|
#include "lineitem.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
lineItem::lineItem(QPointF startPoint, QPointF endItem, Arrow *ownerArrow,
|
||||||
|
int wt, bool movable, QGraphicsItem *parent, QGraphicsScene *scene)
|
||||||
|
: QGraphicsLineItem(parent, scene)
|
||||||
|
{
|
||||||
|
isMovable=movable;
|
||||||
|
if(isMovable)
|
||||||
|
{
|
||||||
|
setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||||
|
|
||||||
|
myColor = Qt::black;
|
||||||
|
setPen(QPen(myColor, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||||
|
setLine(QLineF(startPoint,endItem));
|
||||||
|
myOwnerArrow = ownerArrow;
|
||||||
|
pWidth=wt;
|
||||||
|
moveItem=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
QRectF lineItem::boundingRect() const
|
||||||
|
{
|
||||||
|
qreal extra = (pen().width() + 20) / 2.0;
|
||||||
|
|
||||||
|
return QRectF(line().p1(), QSizeF(line().p2().x() - line().p1().x(),
|
||||||
|
line().p2().y() - line().p1().y()))
|
||||||
|
.normalized()
|
||||||
|
.adjusted(-extra, -extra, extra, extra);
|
||||||
|
}
|
||||||
|
|
||||||
|
QPainterPath lineItem::shape() const
|
||||||
|
{
|
||||||
|
QPainterPath path = QGraphicsLineItem::shape();
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
void lineItem::updatePos()
|
||||||
|
{
|
||||||
|
QPointF itemPos = this->line().p1()+QPointF(0.5,0.5);
|
||||||
|
myOwnerArrow->moveCorner(itemPos,this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lineItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *,
|
||||||
|
QWidget *)
|
||||||
|
{
|
||||||
|
QPen myPen = pen();
|
||||||
|
myPen.setColor(myColor);
|
||||||
|
myPen.setWidth(pWidth);
|
||||||
|
painter->setPen(myPen);
|
||||||
|
painter->setBrush(myColor);
|
||||||
|
|
||||||
|
setLine(line());
|
||||||
|
painter->drawLine(line());
|
||||||
|
|
||||||
|
//Drawing arrow selected
|
||||||
|
if (isSelected()) {
|
||||||
|
painter->setPen(QPen(Qt::gray, pWidth, Qt::SolidLine));
|
||||||
|
QLineF myLine = line();
|
||||||
|
painter->drawLine(myLine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void lineItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
|
{
|
||||||
|
if(!isMovable)
|
||||||
|
{
|
||||||
|
myOwnerArrow->createCorner(mouseEvent->scenePos(),this);
|
||||||
|
}
|
||||||
|
QGraphicsLineItem::mouseDoubleClickEvent(mouseEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void lineItem::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
|
{
|
||||||
|
QGraphicsLineItem::mousePressEvent(mouseEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lineItem::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
|
{
|
||||||
|
if(isMovable)
|
||||||
|
{
|
||||||
|
updatePos();
|
||||||
|
}
|
||||||
|
QGraphicsLineItem::mouseMoveEvent(mouseEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
|
{
|
||||||
|
if(isMovable)
|
||||||
|
{
|
||||||
|
updatePos();
|
||||||
|
}
|
||||||
|
QGraphicsLineItem::mouseReleaseEvent(mouseEvent);
|
||||||
|
}
|
96
Software/sie_cg/block_editor/lineitem.h
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
** All rights reserved.
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
|
**
|
||||||
|
** $QT_BEGIN_LICENSE:LGPL$
|
||||||
|
** Commercial Usage
|
||||||
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||||
|
** accordance with the Qt Commercial License Agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Nokia gives you certain additional
|
||||||
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3.0 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU General Public License version 3.0 requirements will be
|
||||||
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||||
|
**
|
||||||
|
** If you have questions regarding the use of this file, please contact
|
||||||
|
** Nokia at qt-info@nokia.com.
|
||||||
|
** $QT_END_LICENSE$
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef LINEITEM_H
|
||||||
|
#define LINEITEM_H
|
||||||
|
|
||||||
|
#include <QGraphicsLineItem>
|
||||||
|
#include "arrow.h"
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QGraphicsPolygonItem;
|
||||||
|
class QGraphicsLineItem;
|
||||||
|
class QGraphicsScene;
|
||||||
|
class QRectF;
|
||||||
|
class QGraphicsSceneMouseEvent;
|
||||||
|
class QPainterPath;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
class lineItem : public QGraphicsLineItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum { Type = UserType + 4 };
|
||||||
|
|
||||||
|
lineItem(QPointF startPoint, QPointF endItem, Arrow *ownerArrow, int wt=2,
|
||||||
|
bool movable = 0, QGraphicsItem *parent = 0, QGraphicsScene *scene = 0);
|
||||||
|
|
||||||
|
int type() const
|
||||||
|
{ return Type;}
|
||||||
|
QRectF boundingRect() const;
|
||||||
|
QPainterPath shape() const;
|
||||||
|
void setColor(const QColor &color)
|
||||||
|
{ myColor=color; }
|
||||||
|
|
||||||
|
Arrow * myOwner()
|
||||||
|
{ return myOwnerArrow;}
|
||||||
|
|
||||||
|
bool itemIsMovable() {return isMovable;}
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void updatePos();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
|
QWidget *widget = 0);
|
||||||
|
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QColor myColor;
|
||||||
|
int pWidth;
|
||||||
|
Arrow *myOwnerArrow;
|
||||||
|
int moveItem;
|
||||||
|
bool isMovable;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
55
Software/sie_cg/block_editor/main.cpp
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
** All rights reserved.
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
|
**
|
||||||
|
** $QT_BEGIN_LICENSE:LGPL$
|
||||||
|
** Commercial Usage
|
||||||
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||||
|
** accordance with the Qt Commercial License Agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Nokia gives you certain additional
|
||||||
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3.0 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU General Public License version 3.0 requirements will be
|
||||||
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||||
|
**
|
||||||
|
** If you have questions regarding the use of this file, please contact
|
||||||
|
** Nokia at qt-info@nokia.com.
|
||||||
|
** $QT_END_LICENSE$
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <QtGui>
|
||||||
|
|
||||||
|
#include "mainwindow.h"
|
||||||
|
|
||||||
|
int main(int argv, char *args[])
|
||||||
|
{
|
||||||
|
Q_INIT_RESOURCE(diagramscene);
|
||||||
|
|
||||||
|
QApplication app(argv, args);
|
||||||
|
MainWindow mainWindow;
|
||||||
|
mainWindow.setGeometry(100, 100, 1024, 640);
|
||||||
|
mainWindow.show();
|
||||||
|
return app.exec();
|
||||||
|
}
|
413
Software/sie_cg/block_editor/mainwindow.cpp
Normal file
@ -0,0 +1,413 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
** All rights reserved.
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
|
**
|
||||||
|
** $QT_BEGIN_LICENSE:LGPL$
|
||||||
|
** Commercial Usage
|
||||||
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||||
|
** accordance with the Qt Commercial License Agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Nokia gives you certain additional
|
||||||
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3.0 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU General Public License version 3.0 requirements will be
|
||||||
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||||
|
**
|
||||||
|
** If you have questions regarding the use of this file, please contact
|
||||||
|
** Nokia at qt-info@nokia.com.
|
||||||
|
** $QT_END_LICENSE$
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <QtGui>
|
||||||
|
#include <QLabel>
|
||||||
|
|
||||||
|
#include "mainwindow.h"
|
||||||
|
|
||||||
|
const int InsertTextButton = 10;
|
||||||
|
|
||||||
|
MainWindow::MainWindow()
|
||||||
|
{
|
||||||
|
createActions();
|
||||||
|
createToolBox();
|
||||||
|
createMenus();
|
||||||
|
|
||||||
|
scene = new DiagramScene(itemMenu);
|
||||||
|
scene->setSceneRect(QRectF(0, 0, 1000, 1000));
|
||||||
|
connect(scene, SIGNAL(textInserted(QGraphicsTextItem*)),
|
||||||
|
this, SLOT(textInserted(QGraphicsTextItem*)));
|
||||||
|
|
||||||
|
createToolbars();
|
||||||
|
|
||||||
|
QHBoxLayout *layout = new QHBoxLayout;
|
||||||
|
layout->addWidget(toolBox);
|
||||||
|
view = new QGraphicsView(scene);
|
||||||
|
layout->addWidget(view);
|
||||||
|
|
||||||
|
QWidget *widget = new QWidget;
|
||||||
|
widget->setLayout(layout);
|
||||||
|
|
||||||
|
setCentralWidget(widget);
|
||||||
|
setWindowTitle(tr("SIE Code Generator (Block Editor)"));
|
||||||
|
setUnifiedTitleAndToolBarOnMac(true);
|
||||||
|
myFilePath = "";
|
||||||
|
|
||||||
|
if(QApplication::argc()>1)
|
||||||
|
{newDiagram(QString(QApplication::argv()[1]));}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::deleteItem()
|
||||||
|
{
|
||||||
|
foreach (QGraphicsItem *item, scene->selectedItems())
|
||||||
|
{
|
||||||
|
if (item->type() == Arrow::Type) {
|
||||||
|
qgraphicsitem_cast<Arrow *>(item)->removeLines();
|
||||||
|
scene->removeItem(item);
|
||||||
|
delete(item);
|
||||||
|
}
|
||||||
|
//If line is deleted then is romoved from the arrow owner
|
||||||
|
else if (item->type() == lineItem::Type &&
|
||||||
|
!qgraphicsitem_cast<lineItem *>(item)->itemIsMovable()) {
|
||||||
|
|
||||||
|
qgraphicsitem_cast<lineItem *>(item)->myOwner()->removeLine(
|
||||||
|
qgraphicsitem_cast<lineItem *>(item));
|
||||||
|
qgraphicsitem_cast<lineItem *>(item)->myOwner()->updatePosition();
|
||||||
|
scene->removeItem(item);
|
||||||
|
delete(item);
|
||||||
|
}
|
||||||
|
else if (item->type() == DiagramTextItem::Type) {
|
||||||
|
if(qgraphicsitem_cast<DiagramTextItem *>(item)->styleIO()!=0xFFF)
|
||||||
|
{
|
||||||
|
scene->removeTextItem(qgraphicsitem_cast
|
||||||
|
<DiagramTextItem *>(item));
|
||||||
|
scene->removeItem(item);
|
||||||
|
delete(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::textInserted(QGraphicsTextItem*)
|
||||||
|
{
|
||||||
|
buttonGroup->button(selectedButton)->setChecked(false);
|
||||||
|
scene->setMode(DiagramScene::MoveItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MainWindow::sceneScaleChanged(const QString &scale)
|
||||||
|
{
|
||||||
|
double newScale = scale.left(scale.indexOf(tr("%"))).toDouble() / 100.0;
|
||||||
|
QMatrix oldMatrix = view->matrix();
|
||||||
|
view->resetMatrix();
|
||||||
|
view->translate(oldMatrix.dx(), oldMatrix.dy());
|
||||||
|
view->scale(newScale, newScale);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::about()
|
||||||
|
{
|
||||||
|
QMessageBox::question(this, tr("About SIE Code Generator"),
|
||||||
|
tr("TODO <b>:)</b>"));
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget *MainWindow::createToolButton(int ID, QString type, QIcon icon)
|
||||||
|
{
|
||||||
|
QToolButton *button = new QToolButton;
|
||||||
|
button->setIcon(icon);
|
||||||
|
button->setIconSize(QSize(50, 50));
|
||||||
|
button->setCheckable(true);
|
||||||
|
button->setText(type);
|
||||||
|
buttonGroup->addButton(button,ID);
|
||||||
|
|
||||||
|
QGridLayout *layout = new QGridLayout;
|
||||||
|
layout->addWidget(button, 0, 0, Qt::AlignHCenter);
|
||||||
|
layout->addWidget(new QLabel(type), 1, 0, Qt::AlignCenter);
|
||||||
|
|
||||||
|
QWidget *widget = new QWidget;
|
||||||
|
widget->setLayout(layout);
|
||||||
|
|
||||||
|
return widget;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::createToolBox()
|
||||||
|
{
|
||||||
|
buttonGroup = new QButtonGroup;
|
||||||
|
buttonGroup->setExclusive(false);
|
||||||
|
connect(buttonGroup, SIGNAL(buttonClicked(int)),
|
||||||
|
this, SLOT(buttonGroupClicked(int)));
|
||||||
|
|
||||||
|
QGridLayout *layout = new QGridLayout;
|
||||||
|
//INPUTS
|
||||||
|
int i=0;
|
||||||
|
layout->addWidget(createToolButton(129+i,tr("Bool"),
|
||||||
|
QIcon(":/images/background1.png")),++i,0);
|
||||||
|
layout->addWidget(createToolButton(129+i,tr("Char"),
|
||||||
|
QIcon(":/images/background1.png")),++i,0);
|
||||||
|
layout->addWidget(createToolButton(129+i,tr("Integer"),
|
||||||
|
QIcon(":/images/background1.png")),++i,0);
|
||||||
|
layout->addWidget(createToolButton(129+i,tr("Double"),
|
||||||
|
QIcon(":/images/background1.png")),++i,0);
|
||||||
|
layout->addWidget(createToolButton(129+i,tr("Float"),
|
||||||
|
QIcon(":/images/background1.png")),++i,0);
|
||||||
|
|
||||||
|
//OUTPUTS
|
||||||
|
i=0;
|
||||||
|
layout->addWidget(createToolButton(i,tr("Bool"),
|
||||||
|
QIcon(":/images/background3.png")),++i,1);
|
||||||
|
layout->addWidget(createToolButton(i,tr("Char"),
|
||||||
|
QIcon(":/images/background3.png")),++i,1);
|
||||||
|
layout->addWidget(createToolButton(i,tr("Integer"),
|
||||||
|
QIcon(":/images/background3.png")),++i,1);
|
||||||
|
layout->addWidget(createToolButton(i,tr("Double"),
|
||||||
|
QIcon(":/images/background3.png")),++i,1);
|
||||||
|
layout->addWidget(createToolButton(i,tr("Float"),
|
||||||
|
QIcon(":/images/background3.png")),++i,1);
|
||||||
|
|
||||||
|
layout->setRowStretch(3, 10);
|
||||||
|
layout->setColumnStretch(2, 10);
|
||||||
|
QWidget *ioWidget = new QWidget;
|
||||||
|
ioWidget->setLayout(layout);
|
||||||
|
|
||||||
|
layout = new QGridLayout;
|
||||||
|
//Labels
|
||||||
|
layout->addWidget(createToolButton(256,tr("Label"),
|
||||||
|
QIcon(":/images/background4.png")),0,0);
|
||||||
|
//Values
|
||||||
|
layout->addWidget(createToolButton(257,tr("Value"),
|
||||||
|
QIcon(":/images/background4.png")),0,1);
|
||||||
|
|
||||||
|
//Polygon
|
||||||
|
layout->addWidget(createToolButton(258,tr("Polygon"),
|
||||||
|
QIcon(":/images/background2.png")),1,0);
|
||||||
|
|
||||||
|
layout->setRowStretch(3, 10);
|
||||||
|
layout->setColumnStretch(2, 10);
|
||||||
|
QWidget *labelWidget = new QWidget;
|
||||||
|
labelWidget->setLayout(layout);
|
||||||
|
|
||||||
|
|
||||||
|
toolBox = new QToolBox;
|
||||||
|
toolBox->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Ignored));
|
||||||
|
toolBox->setMinimumWidth(labelWidget->sizeHint().width());
|
||||||
|
toolBox->addItem(labelWidget, tr("Basic draw"));
|
||||||
|
toolBox->addItem(ioWidget, tr("Inputs/Outputs"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::buttonGroupClicked(int id)
|
||||||
|
{
|
||||||
|
QList<QAbstractButton *> buttons = buttonGroup->buttons();
|
||||||
|
foreach (QAbstractButton *button, buttons)
|
||||||
|
{if (buttonGroup->button(id) != button) button->setChecked(false);}
|
||||||
|
selectedButton=id;
|
||||||
|
|
||||||
|
if(id==258)
|
||||||
|
{ //Polygon edition
|
||||||
|
scene->setMode(DiagramScene::EditPolygon);
|
||||||
|
} else {
|
||||||
|
scene->setMode(DiagramScene::InsertText);
|
||||||
|
}
|
||||||
|
|
||||||
|
scene->setTextType(id,buttonGroup->button(id)->text());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::createActions()
|
||||||
|
{
|
||||||
|
|
||||||
|
deleteAction = new QAction(QIcon(":/images/delete.png"),
|
||||||
|
tr("&Delete"), this);
|
||||||
|
deleteAction->setShortcut(tr("Ctrl+Delete"));
|
||||||
|
deleteAction->setStatusTip(tr("Delete item from diagram"));
|
||||||
|
connect(deleteAction, SIGNAL(triggered()),
|
||||||
|
this, SLOT(deleteItem()));
|
||||||
|
|
||||||
|
|
||||||
|
newAction = new QAction(QIcon(":/images/new.png"),tr("&New"),this);
|
||||||
|
newAction->setShortcuts(QKeySequence::New);
|
||||||
|
newAction->setStatusTip("New diagram");
|
||||||
|
connect(newAction,SIGNAL(triggered()),this,SLOT(newDiagram()));
|
||||||
|
|
||||||
|
saveAction = new QAction(QIcon(":/images/save.png"),tr("&Save"),this);
|
||||||
|
saveAction->setShortcuts(QKeySequence::Save);
|
||||||
|
saveAction->setStatusTip("Save current diagram");
|
||||||
|
connect(saveAction,SIGNAL(triggered()),this,SLOT(saveDiagram()));
|
||||||
|
|
||||||
|
saveAsAction = new QAction(QIcon(":/images/save_as.png"),
|
||||||
|
tr("Save &As..."),this);
|
||||||
|
saveAsAction->setShortcuts(QKeySequence::SaveAs);
|
||||||
|
saveAsAction->setStatusTip("Save current diagram with another name");
|
||||||
|
connect(saveAsAction,SIGNAL(triggered()),this,SLOT(saveAsDiagram()));
|
||||||
|
|
||||||
|
openAction = new QAction(QIcon(":/images/open.png"),tr("&Open"),this);
|
||||||
|
openAction->setShortcuts(QKeySequence::Open);
|
||||||
|
openAction->setStatusTip("Open diagram");
|
||||||
|
connect(openAction,SIGNAL(triggered()),this,SLOT(openDiagram()));
|
||||||
|
|
||||||
|
exitAction = new QAction(tr("E&xit"), this);
|
||||||
|
exitAction->setShortcuts(QKeySequence::Quit);
|
||||||
|
exitAction->setStatusTip(tr("Quit diagram editor"));
|
||||||
|
connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
|
||||||
|
|
||||||
|
aboutAction = new QAction(tr("A&bout"), this);
|
||||||
|
aboutAction->setShortcut(tr("Ctrl+B"));
|
||||||
|
connect(aboutAction, SIGNAL(triggered()),
|
||||||
|
this, SLOT(about()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::createMenus()
|
||||||
|
{
|
||||||
|
fileMenu = menuBar()->addMenu(tr("&File"));
|
||||||
|
fileMenu->addAction(newAction);
|
||||||
|
fileMenu->addAction(openAction);
|
||||||
|
fileMenu->addSeparator();
|
||||||
|
fileMenu->addAction(saveAction);
|
||||||
|
fileMenu->addAction(saveAsAction);
|
||||||
|
fileMenu->addSeparator();
|
||||||
|
fileMenu->addAction(exitAction);
|
||||||
|
|
||||||
|
itemMenu = menuBar()->addMenu(tr("&Item"));
|
||||||
|
itemMenu->addAction(deleteAction);
|
||||||
|
|
||||||
|
aboutMenu = menuBar()->addMenu(tr("&Help"));
|
||||||
|
aboutMenu->addAction(aboutAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::createToolbars()
|
||||||
|
{
|
||||||
|
fileToolBar = addToolBar(tr("File"));
|
||||||
|
fileToolBar->addAction(newAction);
|
||||||
|
fileToolBar->addAction(openAction);
|
||||||
|
fileToolBar->addAction(saveAction);
|
||||||
|
|
||||||
|
editToolBar = addToolBar(tr("Edit"));
|
||||||
|
editToolBar->addAction(deleteAction);
|
||||||
|
|
||||||
|
sceneScaleCombo = new QComboBox;
|
||||||
|
QStringList scales;
|
||||||
|
scales << tr("75%") << tr("100%") << tr("125%") << tr("150%") << tr("175%");
|
||||||
|
sceneScaleCombo->addItems(scales);
|
||||||
|
sceneScaleCombo->setCurrentIndex(1);
|
||||||
|
connect(sceneScaleCombo, SIGNAL(currentIndexChanged(QString)),
|
||||||
|
this, SLOT(sceneScaleChanged(QString)));
|
||||||
|
|
||||||
|
editToolBar->addWidget(sceneScaleCombo);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MainWindow::newDiagram(QString filePath)
|
||||||
|
{
|
||||||
|
saveIfNeeded();
|
||||||
|
scene->cleanScene();
|
||||||
|
myFilePath="";
|
||||||
|
|
||||||
|
if(filePath=="")
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
myFilePath=filePath;
|
||||||
|
QFile file(myFilePath);
|
||||||
|
if(file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
|
{
|
||||||
|
QDomDocument document;
|
||||||
|
bool parsing=document.setContent(&file);
|
||||||
|
file.close();
|
||||||
|
if(!parsing)
|
||||||
|
{
|
||||||
|
QMessageBox::warning(this,"Aborting","Failed to parse file, "
|
||||||
|
"wrong format or encoding.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
scene->fromXmlFormat(document);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
QMessageBox::critical(this,"Error","Could not open file for read.");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::saveIfNeeded()
|
||||||
|
{
|
||||||
|
if(myFilePath!="" || scene->items().count()>0)
|
||||||
|
{}//TODO save opened or modified diagram
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MainWindow::openDiagram()
|
||||||
|
{
|
||||||
|
QString
|
||||||
|
filePath = QFileDialog::getOpenFileName(this,"Open",
|
||||||
|
currentDir(),"Custom item for SIE code generator (*.die)");
|
||||||
|
|
||||||
|
if(filePath.isEmpty())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if(!QFileInfo(filePath).isReadable())
|
||||||
|
{
|
||||||
|
QMessageBox::critical(this,"Error","File is not readable "
|
||||||
|
" or not exists.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
newDiagram(filePath);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MainWindow::saveDiagram()
|
||||||
|
{
|
||||||
|
if(myFilePath=="")
|
||||||
|
{
|
||||||
|
saveAsDiagram();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if(!QFileInfo(myFilePath).isWritable() && QFileInfo(myFilePath).exists())
|
||||||
|
{
|
||||||
|
QMessageBox::critical(this,"Error","File is not writable.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
QFile file(myFilePath);
|
||||||
|
if(file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||||
|
{
|
||||||
|
QDomDocument document = scene->toXmlFormat();
|
||||||
|
QTextStream out(&file);
|
||||||
|
out.setCodec("UTF-8");
|
||||||
|
out << document.toString(4);
|
||||||
|
file.close();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
QMessageBox::critical(this,"Error","Could not open file for write.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MainWindow::saveAsDiagram()
|
||||||
|
{
|
||||||
|
QString filePath = QFileDialog::getSaveFileName(this,"Save as...",
|
||||||
|
currentDir(),"Custom item for SIE code generator (*.die)");
|
||||||
|
|
||||||
|
if(!filePath.isEmpty())
|
||||||
|
{
|
||||||
|
myFilePath = filePath;
|
||||||
|
saveDiagram();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
136
Software/sie_cg/block_editor/mainwindow.h
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
** All rights reserved.
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
|
**
|
||||||
|
** $QT_BEGIN_LICENSE:LGPL$
|
||||||
|
** Commercial Usage
|
||||||
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||||
|
** accordance with the Qt Commercial License Agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Nokia gives you certain additional
|
||||||
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3.0 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU General Public License version 3.0 requirements will be
|
||||||
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||||
|
**
|
||||||
|
** If you have questions regarding the use of this file, please contact
|
||||||
|
** Nokia at qt-info@nokia.com.
|
||||||
|
** $QT_END_LICENSE$
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef MAINWINDOW_H
|
||||||
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QtXml>
|
||||||
|
|
||||||
|
#include "diagramscene.h"
|
||||||
|
#include "diagramtextitem.h"
|
||||||
|
#include "lineitem.h"
|
||||||
|
#include "arrow.h"
|
||||||
|
|
||||||
|
class DiagramScene;
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QAction;
|
||||||
|
class QToolBox;
|
||||||
|
class QSpinBox;
|
||||||
|
class QComboBox;
|
||||||
|
class QFontComboBox;
|
||||||
|
class QButtonGroup;
|
||||||
|
class QLineEdit;
|
||||||
|
class QGraphicsTextItem;
|
||||||
|
class QFont;
|
||||||
|
class QToolButton;
|
||||||
|
class QAbstractButton;
|
||||||
|
class QGraphicsView;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
class MainWindow : public QMainWindow
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
MainWindow();
|
||||||
|
QString filePath() const
|
||||||
|
{ return myFilePath;}
|
||||||
|
QString currentDir() const
|
||||||
|
{ return QDir::currentPath();}
|
||||||
|
|
||||||
|
void saveIfNeeded();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void deleteItem();
|
||||||
|
void sceneScaleChanged(const QString &scale);
|
||||||
|
void about();
|
||||||
|
bool newDiagram(QString pathFile="");
|
||||||
|
bool openDiagram();
|
||||||
|
bool saveDiagram();
|
||||||
|
bool saveAsDiagram();
|
||||||
|
void buttonGroupClicked(int id);
|
||||||
|
void textInserted(QGraphicsTextItem*);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void createToolBox();
|
||||||
|
void createActions();
|
||||||
|
void createMenus();
|
||||||
|
void createToolbars();
|
||||||
|
QWidget *createToolButton(int ID, QString type,QIcon icon);
|
||||||
|
|
||||||
|
DiagramScene *scene;
|
||||||
|
QGraphicsView *view;
|
||||||
|
|
||||||
|
QAction *newAction;
|
||||||
|
QAction *saveAction;
|
||||||
|
QAction *saveAsAction;
|
||||||
|
QAction *openAction;
|
||||||
|
|
||||||
|
QAction *exitAction;
|
||||||
|
QAction *addAction;
|
||||||
|
QAction *deleteAction;
|
||||||
|
|
||||||
|
QAction *aboutAction;
|
||||||
|
|
||||||
|
QMenu *fileMenu;
|
||||||
|
QMenu *itemMenu;
|
||||||
|
QMenu *aboutMenu;
|
||||||
|
|
||||||
|
QToolBar *fileToolBar;
|
||||||
|
QToolBar *editToolBar;
|
||||||
|
|
||||||
|
QToolBox *toolBox;
|
||||||
|
|
||||||
|
QComboBox *sceneScaleCombo;
|
||||||
|
|
||||||
|
QButtonGroup *buttonGroup;
|
||||||
|
|
||||||
|
int selectedButton;
|
||||||
|
|
||||||
|
QString myFilePath;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
18
Software/sie_cg/block_editor/test_block1.die
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<!--File for SIE Code Generator. Custmos Blocks-->
|
||||||
|
<CustomItem BlockName="Test Block 1">
|
||||||
|
<Polygon>
|
||||||
|
<Point x="-120" y="0"/>
|
||||||
|
<Point x="-70" y="-50"/>
|
||||||
|
<Point x="90" y="-50"/>
|
||||||
|
<Point x="140" y="0"/>
|
||||||
|
<Point x="90" y="50"/>
|
||||||
|
<Point x="-70" y="50"/>
|
||||||
|
</Polygon>
|
||||||
|
<TextItems>
|
||||||
|
<TextItem myStyleIO="0" posOffset-y="-30" editableItem="0" ID="0" text="Value" posOffset-x="-40"/>
|
||||||
|
<TextItem myStyleIO="0" posOffset-y="-30" editableItem="1" ID="1" text="0.001" posOffset-x="40"/>
|
||||||
|
<TextItem myStyleIO="2" posOffset-y="-0" editableItem="0" ID="3" text="OUT Char " posOffset-x="140"/>
|
||||||
|
<TextItem myStyleIO="130" posOffset-y="-0" editableItem="0" ID="4" text=" IN Bool" posOffset-x="-120"/>
|
||||||
|
<TextItem myStyleIO="0" posOffset-y="30" editableItem="0" ID="2" text="Test Block 1" posOffset-x="0"/>
|
||||||
|
</TextItems>
|
||||||
|
</CustomItem>
|
15
Software/sie_cg/block_editor/test_block2.die
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<!--File for SIE Code Generator. Custmos Blocks-->
|
||||||
|
<CustomItem BlockName="Test Block 2">
|
||||||
|
<Polygon>
|
||||||
|
<Point x="-50" y="-20"/>
|
||||||
|
<Point x="-30" y="0"/>
|
||||||
|
<Point x="-50" y="20"/>
|
||||||
|
<Point x="30" y="20"/>
|
||||||
|
<Point x="60" y="0"/>
|
||||||
|
<Point x="40" y="-20"/>
|
||||||
|
</Polygon>
|
||||||
|
<TextItems>
|
||||||
|
<TextItem myStyleIO="130" posOffset-y="-0" editableItem="0" ID="1" text=" IN Bool" posOffset-x="-30"/>
|
||||||
|
<TextItem myStyleIO="0" posOffset-y="30" editableItem="0" ID="0" text="Test Block 2" posOffset-x="-10"/>
|
||||||
|
</TextItems>
|
||||||
|
</CustomItem>
|
15
Software/sie_cg/block_editor/test_block3.die
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<!--File for SIE Code Generator. Custmos Blocks-->
|
||||||
|
<CustomItem BlockName="Test Block 3">
|
||||||
|
<Polygon>
|
||||||
|
<Point x="-30" y="0"/>
|
||||||
|
<Point x="-50" y="20"/>
|
||||||
|
<Point x="50" y="20"/>
|
||||||
|
<Point x="70" y="0"/>
|
||||||
|
<Point x="50" y="-20"/>
|
||||||
|
<Point x="-50" y="-20"/>
|
||||||
|
</Polygon>
|
||||||
|
<TextItems>
|
||||||
|
<TextItem myStyleIO="0" posOffset-y="30" editableItem="0" ID="1" text="Test Block 3" posOffset-x="0"/>
|
||||||
|
<TextItem myStyleIO="1" posOffset-y="-0" editableItem="0" ID="0" text="OUT Bool " posOffset-x="60"/>
|
||||||
|
</TextItems>
|
||||||
|
</CustomItem>
|
29
Software/sie_cg/block_editor/test_block4.die
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<!--File for SIE Code Generator. Custmos Blocks-->
|
||||||
|
<CustomItem BlockName="BLOCK NAME HERE (not visible)">
|
||||||
|
<Polygon>
|
||||||
|
<Point x="-60" y="100"/>
|
||||||
|
<Point x="100" y="100"/>
|
||||||
|
<Point x="100" y="60"/>
|
||||||
|
<Point x="50" y="60"/>
|
||||||
|
<Point x="50" y="20"/>
|
||||||
|
<Point x="100" y="20"/>
|
||||||
|
<Point x="100" y="-10"/>
|
||||||
|
<Point x="100" y="-20"/>
|
||||||
|
<Point x="50" y="-20"/>
|
||||||
|
<Point x="50" y="-40"/>
|
||||||
|
<Point x="50" y="-60"/>
|
||||||
|
<Point x="100" y="-60"/>
|
||||||
|
<Point x="100" y="-100"/>
|
||||||
|
<Point x="-60" y="-100"/>
|
||||||
|
<Point x="-60" y="-20"/>
|
||||||
|
<Point x="-100" y="-20"/>
|
||||||
|
<Point x="-100" y="20"/>
|
||||||
|
<Point x="-60" y="20"/>
|
||||||
|
</Polygon>
|
||||||
|
<TextItems>
|
||||||
|
<TextItem myStyleIO="1" posOffset-y="-80" editableItem="0" ID="8" text="OUT Bool" posOffset-x="100"/>
|
||||||
|
<TextItem myStyleIO="1" posOffset-y="-0" editableItem="0" ID="1" text="OUT Bool" posOffset-x="100"/>
|
||||||
|
<TextItem myStyleIO="1" posOffset-y="80" editableItem="0" ID="6" text="OUT Bool" posOffset-x="100"/>
|
||||||
|
<TextItem myStyleIO="130" posOffset-y="-0" editableItem="0" ID="5" text="IN Bool" posOffset-x="-100"/>
|
||||||
|
</TextItems>
|
||||||
|
</CustomItem>
|
295
Software/sie_cg/diagramitem.cpp
Normal file
@ -0,0 +1,295 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
** All rights reserved.
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
|
**
|
||||||
|
** $QT_BEGIN_LICENSE:LGPL$
|
||||||
|
** Commercial Usage
|
||||||
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||||
|
** accordance with the Qt Commercial License Agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Nokia gives you certain additional
|
||||||
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3.0 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU General Public License version 3.0 requirements will be
|
||||||
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||||
|
**
|
||||||
|
** If you have questions regarding the use of this file, please contact
|
||||||
|
** Nokia at qt-info@nokia.com.
|
||||||
|
** $QT_END_LICENSE$
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <QtGui>
|
||||||
|
|
||||||
|
#include "diagramitem.h"
|
||||||
|
#include "arrow.h"
|
||||||
|
#include "diagramtextitem.h"
|
||||||
|
#include "lineitem.h"
|
||||||
|
|
||||||
|
DiagramItem::DiagramItem(
|
||||||
|
QMenu *contextMenu,
|
||||||
|
QString diagramType,
|
||||||
|
QDomElement *domElement,
|
||||||
|
QGraphicsItem *parent, QGraphicsScene *scene,
|
||||||
|
QPointF position, double zV)
|
||||||
|
: QGraphicsPolygonItem(parent, scene)
|
||||||
|
{
|
||||||
|
myDiagramType = diagramType;
|
||||||
|
myContextMenu = contextMenu;
|
||||||
|
myOwnerScene = scene;
|
||||||
|
myDomElement=domElement;
|
||||||
|
setPos(position);
|
||||||
|
setZValue(zV);
|
||||||
|
myColor = Qt::white;
|
||||||
|
|
||||||
|
for (QDomNode node = myDomElement->firstChild() ;
|
||||||
|
!node.isNull() ;
|
||||||
|
node = node.nextSibling())
|
||||||
|
{
|
||||||
|
QDomElement element = node.toElement();
|
||||||
|
if(element.tagName()=="Polygon")
|
||||||
|
{
|
||||||
|
//READING POLYGON POINTS
|
||||||
|
QList<QPointF> points;
|
||||||
|
for (QDomNode node = element.firstChild() ;
|
||||||
|
!node.isNull() ;
|
||||||
|
node = node.nextSibling())
|
||||||
|
{
|
||||||
|
QDomElement point = node.toElement();
|
||||||
|
if(point.tagName()=="Point")
|
||||||
|
points.append(QPointF(
|
||||||
|
point.attribute("x").toFloat(),
|
||||||
|
point.attribute("y").toFloat()));
|
||||||
|
}
|
||||||
|
//CREATING POLYGON
|
||||||
|
if(points.count()>0)
|
||||||
|
foreach(QPointF p, points)
|
||||||
|
myPolygon << p;
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(element.tagName()=="TextItems" && myOwnerScene!=0)
|
||||||
|
{
|
||||||
|
for (QDomNode node = element.firstChild() ;
|
||||||
|
!node.isNull() ;
|
||||||
|
node = node.nextSibling())
|
||||||
|
{
|
||||||
|
QDomElement textItemE = node.toElement();
|
||||||
|
if(textItemE.tagName()=="TextItem")
|
||||||
|
{
|
||||||
|
int myStyleIO = textItemE.attribute("myStyleIO").
|
||||||
|
toInt();
|
||||||
|
int myID = textItemE.attribute("ID").toInt();
|
||||||
|
bool editableItem = textItemE.attribute("editableItem").
|
||||||
|
toInt();
|
||||||
|
QPointF posOffset=
|
||||||
|
QPointF(textItemE.attribute("posOffset-x").
|
||||||
|
toFloat(),
|
||||||
|
-textItemE.attribute("posOffset-y").
|
||||||
|
toFloat());
|
||||||
|
QString itemString=textItemE.attribute("text");
|
||||||
|
|
||||||
|
DiagramTextItem * newTextItem =
|
||||||
|
new DiagramTextItem(0,0,editableItem,this,myStyleIO,
|
||||||
|
myID,itemString,posOffset);
|
||||||
|
myOwnerScene->addItem(newTextItem);
|
||||||
|
addText(newTextItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setPolygon(myPolygon);
|
||||||
|
setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||||
|
setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DiagramItem::setValue(unsigned char ID, QString value)
|
||||||
|
{
|
||||||
|
foreach(DiagramTextItem *item, textItems)
|
||||||
|
{
|
||||||
|
if(item->isEditable())
|
||||||
|
{
|
||||||
|
if(item->textID()==ID)
|
||||||
|
item->setPlainText(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
DiagramTextItem *DiagramItem::pointerText(unsigned char ID)
|
||||||
|
{
|
||||||
|
foreach(DiagramTextItem *item, textItems)
|
||||||
|
{
|
||||||
|
if(item->textID()==ID)
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char DiagramItem::existArrow(DiagramTextItem *startItem,
|
||||||
|
DiagramTextItem *endItem)
|
||||||
|
{
|
||||||
|
foreach (Arrow *arrow, arrows) {
|
||||||
|
if(arrow->startItem() == startItem &&
|
||||||
|
arrow->endItem() == endItem)
|
||||||
|
return 1; //Already exist
|
||||||
|
else if(arrow->endItem()== endItem)
|
||||||
|
return 1; //End item (INPOUT) already connected
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramItem::removeArrow(Arrow *arrow)
|
||||||
|
{
|
||||||
|
int index = arrows.indexOf(arrow);
|
||||||
|
|
||||||
|
if (index != -1)
|
||||||
|
arrows.removeAt(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramItem::removeArrows()
|
||||||
|
{
|
||||||
|
foreach (Arrow *arrow, arrows) {
|
||||||
|
arrow->startItem()->ownerItem()->removeArrow(arrow);
|
||||||
|
arrow->endItem()->ownerItem()->removeArrow(arrow);
|
||||||
|
arrow->removeLines();
|
||||||
|
scene()->removeItem(arrow);
|
||||||
|
delete arrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramItem::addArrow(Arrow *arrow)
|
||||||
|
{
|
||||||
|
arrows.append(arrow);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramItem::removeTextItem(DiagramTextItem *textItem)
|
||||||
|
{
|
||||||
|
int index = textItems.indexOf(textItem);
|
||||||
|
|
||||||
|
if (index != -1)
|
||||||
|
textItems.removeAt(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramItem::removeTextItems()
|
||||||
|
{
|
||||||
|
foreach (DiagramTextItem *textItem, textItems) {
|
||||||
|
textItem->ownerItem()->removeTextItem(textItem);
|
||||||
|
scene()->removeItem(textItem);
|
||||||
|
delete textItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QPixmap DiagramItem::image() const
|
||||||
|
{
|
||||||
|
QSize mySize=this->boundingRect().size().toSize()*1.4;
|
||||||
|
QPixmap pixmap(mySize);
|
||||||
|
pixmap.fill(Qt::transparent);
|
||||||
|
QPainter painter(&pixmap);
|
||||||
|
int penWidth;
|
||||||
|
if(mySize.width()>mySize.height())
|
||||||
|
penWidth = int(mySize.width()/32);
|
||||||
|
else
|
||||||
|
penWidth = int(mySize.height()/32);
|
||||||
|
|
||||||
|
painter.setPen(QPen(Qt::black, penWidth));
|
||||||
|
painter.translate(mySize.width()/2, mySize.height()/2);
|
||||||
|
QPolygonF Polygon = myPolygon;
|
||||||
|
Polygon = Polygon << Polygon.first(); //Adjust the last segment
|
||||||
|
painter.drawPolyline(Polygon);
|
||||||
|
//TODO text on icon may be interesting
|
||||||
|
return pixmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
||||||
|
{
|
||||||
|
scene()->clearSelection();
|
||||||
|
setSelected(true);
|
||||||
|
myContextMenu->exec(event->screenPos());
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant DiagramItem::itemChange(GraphicsItemChange change,
|
||||||
|
const QVariant &value)
|
||||||
|
{
|
||||||
|
if (change == QGraphicsItem::ItemPositionChange) {
|
||||||
|
foreach (Arrow *arrow, arrows) {
|
||||||
|
arrow->updatePosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramItem::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
|
{
|
||||||
|
foreach (DiagramTextItem *texts, textItems) {
|
||||||
|
texts->updatePosition();
|
||||||
|
}
|
||||||
|
foreach (Arrow *arrow, arrows) {
|
||||||
|
arrow->updatePosition();
|
||||||
|
}
|
||||||
|
QGraphicsPolygonItem::mouseMoveEvent(mouseEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
|
{
|
||||||
|
foreach (DiagramTextItem *texts, textItems) {
|
||||||
|
texts->updatePosition();
|
||||||
|
}
|
||||||
|
foreach (Arrow *arrow, arrows) {
|
||||||
|
arrow->updatePosition();
|
||||||
|
}
|
||||||
|
QGraphicsPolygonItem::mouseReleaseEvent(mouseEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
QDomElement DiagramItem::toXml(QDomDocument &document) const
|
||||||
|
{
|
||||||
|
QDomElement diagramItem = document.createElement("DiagramItem");
|
||||||
|
|
||||||
|
//Set attibutes; type and position
|
||||||
|
diagramItem.setAttribute("type",diagramType());
|
||||||
|
diagramItem.setAttribute("x",pos().x());
|
||||||
|
diagramItem.setAttribute("y",pos().y());
|
||||||
|
diagramItem.setAttribute("z",zValue());
|
||||||
|
diagramItem.setAttribute("color",myColor.name());
|
||||||
|
|
||||||
|
//Lists of values (text on editable labels)
|
||||||
|
int i=0;
|
||||||
|
QDomElement diagramValues = document.createElement("diagramValues");
|
||||||
|
foreach(DiagramTextItem *item, textItems)
|
||||||
|
{
|
||||||
|
if(item->isEditable())
|
||||||
|
{
|
||||||
|
QDomElement diagramValue = document.createElement("diagramValue");
|
||||||
|
diagramValue.setAttribute("value", item->toPlainText());
|
||||||
|
diagramValue.setAttribute("ID", item->textID());
|
||||||
|
i++;
|
||||||
|
diagramValues.appendChild(diagramValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
diagramItem.appendChild(diagramValues);
|
||||||
|
|
||||||
|
return (diagramItem);
|
||||||
|
}
|
||||||
|
|
141
Software/sie_cg/diagramitem.h
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
** All rights reserved.
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
|
**
|
||||||
|
** $QT_BEGIN_LICENSE:LGPL$
|
||||||
|
** Commercial Usage
|
||||||
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||||
|
** accordance with the Qt Commercial License Agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Nokia gives you certain additional
|
||||||
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3.0 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU General Public License version 3.0 requirements will be
|
||||||
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||||
|
**
|
||||||
|
** If you have questions regarding the use of this file, please contact
|
||||||
|
** Nokia at qt-info@nokia.com.
|
||||||
|
** $QT_END_LICENSE$
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef DIAGRAMITEM_H
|
||||||
|
#define DIAGRAMITEM_H
|
||||||
|
|
||||||
|
#include <QGraphicsPixmapItem>
|
||||||
|
#include <QGraphicsSimpleTextItem>
|
||||||
|
#include <QList>
|
||||||
|
#include <QtXml>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QPixmap;
|
||||||
|
class QGraphicsItem;
|
||||||
|
class QGraphicsScene;
|
||||||
|
class QTextEdit;
|
||||||
|
class QGraphicsSceneMouseEvent;
|
||||||
|
class QMenu;
|
||||||
|
class QGraphicsSceneContextMenuEvent;
|
||||||
|
class QPainter;
|
||||||
|
class QStyleOptionGraphicsItem;
|
||||||
|
class QWidget;
|
||||||
|
class QPolygonF;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
class QObject;
|
||||||
|
|
||||||
|
class Arrow;
|
||||||
|
class DiagramTextItem;
|
||||||
|
|
||||||
|
class DiagramItem : public QGraphicsPolygonItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum { Type = UserType + 15 };
|
||||||
|
|
||||||
|
DiagramItem(QMenu *contextMenu,
|
||||||
|
QString diagramType,
|
||||||
|
QDomElement *domElement,
|
||||||
|
QGraphicsItem *parent = 0, QGraphicsScene *scene = 0,
|
||||||
|
QPointF position = QPointF(0,0), double zV=500);
|
||||||
|
|
||||||
|
void removeArrow(Arrow *arrow);
|
||||||
|
void removeArrows();
|
||||||
|
void addArrow(Arrow *arrow);
|
||||||
|
|
||||||
|
void addText(DiagramTextItem *externalTextItem)
|
||||||
|
{ textItems.append(externalTextItem);}
|
||||||
|
|
||||||
|
void removeTextItem(DiagramTextItem *textItem);
|
||||||
|
void removeTextItems();
|
||||||
|
|
||||||
|
QString diagramType() const
|
||||||
|
{ return myDiagramType; }
|
||||||
|
|
||||||
|
QPolygonF polygon() const
|
||||||
|
{ return myPolygon; }
|
||||||
|
|
||||||
|
QDomElement *getDomElement()
|
||||||
|
{return myDomElement;}
|
||||||
|
|
||||||
|
QPixmap image() const;
|
||||||
|
|
||||||
|
int type() const
|
||||||
|
{ return Type;}
|
||||||
|
|
||||||
|
QList<DiagramTextItem *> getTextItems() const
|
||||||
|
{ return textItems;}
|
||||||
|
|
||||||
|
unsigned char existArrow(DiagramTextItem *startItem,
|
||||||
|
DiagramTextItem *endItem);
|
||||||
|
|
||||||
|
|
||||||
|
void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
|
{QGraphicsPolygonItem::mousePressEvent(mouseEvent);}
|
||||||
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
||||||
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
||||||
|
|
||||||
|
QDomElement toXml(QDomDocument &) const;
|
||||||
|
|
||||||
|
bool setValue(unsigned char ioID, QString value);
|
||||||
|
DiagramTextItem * pointerText(unsigned char ID);
|
||||||
|
|
||||||
|
void setColor(const QColor &color)
|
||||||
|
{ myColor=color; setBrush(color); }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
|
||||||
|
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString myDiagramType;
|
||||||
|
QPolygonF myPolygon;
|
||||||
|
QMenu *myContextMenu;
|
||||||
|
QList<Arrow *> arrows;
|
||||||
|
QList<DiagramTextItem *> textItems;
|
||||||
|
QGraphicsScene *myOwnerScene;
|
||||||
|
DiagramTextItem *textItem;
|
||||||
|
QColor myColor;
|
||||||
|
QDomElement *myDomElement;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
545
Software/sie_cg/diagramscene.cpp
Normal file
@ -0,0 +1,545 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
** All rights reserved.
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
|
**
|
||||||
|
** $QT_BEGIN_LICENSE:LGPL$
|
||||||
|
** Commercial Usage
|
||||||
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||||
|
** accordance with the Qt Commercial License Agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Nokia gives you certain additional
|
||||||
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3.0 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU General Public License version 3.0 requirements will be
|
||||||
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||||
|
**
|
||||||
|
** If you have questions regarding the use of this file, please contact
|
||||||
|
** Nokia at qt-info@nokia.com.
|
||||||
|
** $QT_END_LICENSE$
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <QtGui>
|
||||||
|
#include <QHash>
|
||||||
|
#include "diagramscene.h"
|
||||||
|
#include "arrow.h"
|
||||||
|
|
||||||
|
DiagramScene::DiagramScene(QMenu *itemMenu, MainWindow *ownerWindow,
|
||||||
|
QObject *parent)
|
||||||
|
: QGraphicsScene(parent)
|
||||||
|
{
|
||||||
|
myItemMenu = itemMenu;
|
||||||
|
myMode = MoveItem;
|
||||||
|
myItemType = "";
|
||||||
|
line = 0;
|
||||||
|
textItem = 0;
|
||||||
|
myItemColor = Qt::white;
|
||||||
|
myTextColor = Qt::black;
|
||||||
|
myLineColor = Qt::black;
|
||||||
|
snapToGrid=1;
|
||||||
|
myGrid=10;
|
||||||
|
drawGrid=1;
|
||||||
|
myOwnerWindow=ownerWindow;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramScene::setLineColor(const QColor &color)
|
||||||
|
{
|
||||||
|
myLineColor = color;
|
||||||
|
if (isItemChange(Arrow::Type)) {
|
||||||
|
Arrow *item =
|
||||||
|
qgraphicsitem_cast<Arrow *>(selectedItems().first());
|
||||||
|
item->setColor(myLineColor);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramScene::setTextColor(const QColor &color)
|
||||||
|
{
|
||||||
|
myTextColor = color;
|
||||||
|
if (isItemChange(DiagramTextItem::Type)) {
|
||||||
|
DiagramTextItem *item =
|
||||||
|
qgraphicsitem_cast<DiagramTextItem *>(selectedItems().first());
|
||||||
|
item->setDefaultTextColor(myTextColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramScene::setItemColor(const QColor &color)
|
||||||
|
{
|
||||||
|
myItemColor = color;
|
||||||
|
if (isItemChange(DiagramItem::Type)) {
|
||||||
|
DiagramItem *item =
|
||||||
|
qgraphicsitem_cast<DiagramItem *>(selectedItems().first());
|
||||||
|
item->setColor(myItemColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramScene::setFont(const QFont &font)
|
||||||
|
{
|
||||||
|
myFont = font;
|
||||||
|
|
||||||
|
if (isItemChange(DiagramTextItem::Type)) {
|
||||||
|
QGraphicsTextItem *item =
|
||||||
|
qgraphicsitem_cast<DiagramTextItem *>(selectedItems().first());
|
||||||
|
//At this point the selection can change so the first selected item might not be a DiagramTextItem
|
||||||
|
if (item)
|
||||||
|
item->setFont(myFont);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramScene::setMode(Mode mode)
|
||||||
|
{
|
||||||
|
myMode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramScene::setItemType(QString type)
|
||||||
|
{
|
||||||
|
myItemType = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramScene::editorLostFocus(DiagramTextItem *item)
|
||||||
|
{
|
||||||
|
QTextCursor cursor = item->textCursor();
|
||||||
|
cursor.clearSelection();
|
||||||
|
item->setTextCursor(cursor);
|
||||||
|
|
||||||
|
if (item->toPlainText().isEmpty()) {
|
||||||
|
removeItem(item);
|
||||||
|
item->deleteLater();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
|
{
|
||||||
|
doSnapToGrid(mouseEvent);
|
||||||
|
|
||||||
|
if (mouseEvent->button() != Qt::LeftButton)
|
||||||
|
return;
|
||||||
|
|
||||||
|
DiagramItem *item;
|
||||||
|
switch (myMode) {
|
||||||
|
case InsertItem:
|
||||||
|
item = new DiagramItem(myItemMenu,myItemType,
|
||||||
|
domElementsByName.value(myItemType),0,this);
|
||||||
|
item->setColor(myItemColor);
|
||||||
|
addItem(item);
|
||||||
|
item->setPos(mouseEvent->scenePos());
|
||||||
|
emit itemInserted(item);
|
||||||
|
break;
|
||||||
|
case InsertLine:
|
||||||
|
line = new QGraphicsLineItem(QLineF(mouseEvent->scenePos(),
|
||||||
|
mouseEvent->scenePos()));
|
||||||
|
line->setPen(QPen(myLineColor, 2));
|
||||||
|
line->setZValue(1000.0);
|
||||||
|
addItem(line);
|
||||||
|
snapToGrid=0;
|
||||||
|
break;
|
||||||
|
case InsertText:
|
||||||
|
textItem = new DiagramTextItem();
|
||||||
|
textItem->setFont(myFont);
|
||||||
|
textItem->setTextInteractionFlags(Qt::TextEditorInteraction);
|
||||||
|
textItem->setZValue(1000.0);
|
||||||
|
connect(textItem, SIGNAL(lostFocus(DiagramTextItem*)),
|
||||||
|
this, SLOT(editorLostFocus(DiagramTextItem*)));
|
||||||
|
connect(textItem, SIGNAL(selectedChange(QGraphicsItem*)),
|
||||||
|
this, SIGNAL(itemSelected(QGraphicsItem*)));
|
||||||
|
addItem(textItem);
|
||||||
|
textItem->setDefaultTextColor(myTextColor);
|
||||||
|
textItem->setPos(mouseEvent->scenePos());
|
||||||
|
emit textInserted(textItem);
|
||||||
|
default:
|
||||||
|
;
|
||||||
|
}
|
||||||
|
QGraphicsScene::mousePressEvent(mouseEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramScene::doSnapToGrid(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
|
{
|
||||||
|
if(snapToGrid){
|
||||||
|
mouseEvent->setScenePos(QPointF(
|
||||||
|
int(mouseEvent->scenePos().x()/myGrid)*myGrid,
|
||||||
|
int(mouseEvent->scenePos().y()/myGrid)*myGrid
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
|
{
|
||||||
|
doSnapToGrid(mouseEvent);
|
||||||
|
if (myMode == InsertLine && line != 0) {
|
||||||
|
QLineF newLine(line->line().p1(), mouseEvent->scenePos());
|
||||||
|
line->setLine(newLine);
|
||||||
|
} else if (myMode == MoveItem) {
|
||||||
|
QGraphicsScene::mouseMoveEvent(mouseEvent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
|
{
|
||||||
|
doSnapToGrid(mouseEvent);
|
||||||
|
QGraphicsScene::mouseDoubleClickEvent(mouseEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
|
{
|
||||||
|
doSnapToGrid(mouseEvent);
|
||||||
|
if (line != 0 && myMode == InsertLine) {
|
||||||
|
QList<QGraphicsItem *> startItems = items(line->line().p1());
|
||||||
|
if (startItems.count() && startItems.first() == line)
|
||||||
|
startItems.removeFirst();
|
||||||
|
QList<QGraphicsItem *> endItems = items(line->line().p2());
|
||||||
|
if (endItems.count() && endItems.first() == line)
|
||||||
|
endItems.removeFirst();
|
||||||
|
|
||||||
|
removeItem(line);
|
||||||
|
delete line;
|
||||||
|
//Diferents items and valid type
|
||||||
|
if (startItems.count() > 0 && endItems.count() > 0 &&
|
||||||
|
startItems.first()->type() == DiagramTextItem::Type &&
|
||||||
|
endItems.first()->type() == DiagramTextItem::Type &&
|
||||||
|
startItems.first() != endItems.first())
|
||||||
|
{
|
||||||
|
DiagramTextItem *startItem_ =
|
||||||
|
qgraphicsitem_cast<DiagramTextItem *>(startItems.first());
|
||||||
|
DiagramTextItem *endItem_ =
|
||||||
|
qgraphicsitem_cast<DiagramTextItem *>(endItems.first());
|
||||||
|
|
||||||
|
//Real first and end item
|
||||||
|
DiagramTextItem *startItem = startItem_;
|
||||||
|
DiagramTextItem *endItem = endItem_;
|
||||||
|
if(startItem_->styleIO()>>7)
|
||||||
|
{
|
||||||
|
startItem = endItem_;
|
||||||
|
endItem = startItem_;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Inputs to outputs and diferent owner diagram item
|
||||||
|
if(startItem->styleIO()>0 &&
|
||||||
|
endItem->styleIO()>0 &&
|
||||||
|
(startItem->styleIO()>>7 != endItem->styleIO()>>7) &&
|
||||||
|
(startItem->ownerItem() != endItem->ownerItem()) &&
|
||||||
|
!endItem->ownerItem()->existArrow(startItem,endItem)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Arrow *arrow = new Arrow(startItem, endItem,0,this);
|
||||||
|
arrow->setColor(myLineColor);
|
||||||
|
startItem->ownerItem()->addArrow(arrow);
|
||||||
|
endItem->ownerItem()->addArrow(arrow);
|
||||||
|
arrow->setZValue(0.0);
|
||||||
|
addItem(arrow);
|
||||||
|
arrow->updatePosition();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
line = 0;
|
||||||
|
snapToGrid=1;
|
||||||
|
QGraphicsScene::mouseReleaseEvent(mouseEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DiagramScene::isItemChange(int type)
|
||||||
|
{
|
||||||
|
foreach (QGraphicsItem *item, selectedItems()) {
|
||||||
|
if (item->type() == type)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDomDocument DiagramScene::toXmlFormat()
|
||||||
|
{
|
||||||
|
QDomDocument document;
|
||||||
|
QDomComment initialComments=document.createComment(
|
||||||
|
"\nFile for SIE Code Generator.\n"
|
||||||
|
"**WARNING**If you are going to edit this file note that:\n"
|
||||||
|
"In order to segmentation faults prevention the load process \n"
|
||||||
|
"is started loading the libraries, then items and finally arrows.\n"
|
||||||
|
"Arrows depend of items, and items depend of libraries!!!!\n");
|
||||||
|
document.appendChild(initialComments);
|
||||||
|
QDomElement diagram = document.createElement("Diagram");
|
||||||
|
document.appendChild(diagram);
|
||||||
|
|
||||||
|
//Lists of items
|
||||||
|
QList<DiagramItem *> Items;
|
||||||
|
QList<Arrow *> Arrows;
|
||||||
|
foreach(QGraphicsItem *item, items())
|
||||||
|
{
|
||||||
|
if(item->type() == DiagramItem::Type)
|
||||||
|
Items.append(qgraphicsitem_cast<DiagramItem *>(item));
|
||||||
|
else if(item->type() == Arrow::Type)
|
||||||
|
Arrows.append(qgraphicsitem_cast<Arrow *>(item));
|
||||||
|
}
|
||||||
|
//Create the XML structure
|
||||||
|
QDomElement element;
|
||||||
|
if(!libraryList.isEmpty())
|
||||||
|
{
|
||||||
|
QDomElement libraries = document.createElement("Libraries");
|
||||||
|
foreach(QString lib, libraryList)
|
||||||
|
{
|
||||||
|
element = document.createElement("Library");
|
||||||
|
element.setAttribute("Dir",lib);
|
||||||
|
libraries.appendChild(element);
|
||||||
|
}
|
||||||
|
diagram.appendChild(libraries);
|
||||||
|
|
||||||
|
}
|
||||||
|
if(!Items.isEmpty())
|
||||||
|
{
|
||||||
|
QDomElement diagramItems = document.createElement("DiagramItems");
|
||||||
|
foreach(DiagramItem *item, Items)
|
||||||
|
{
|
||||||
|
element = item->toXml(document);
|
||||||
|
element.setAttribute("ID",Items.indexOf(item)); //save index
|
||||||
|
diagramItems.appendChild(element);
|
||||||
|
}
|
||||||
|
diagram.appendChild(diagramItems);
|
||||||
|
}
|
||||||
|
if(!Arrows.isEmpty())
|
||||||
|
{
|
||||||
|
QDomElement arrowItems = document.createElement("Arrows");
|
||||||
|
foreach(Arrow *item, Arrows)
|
||||||
|
{
|
||||||
|
element = item->toXml(document,Items);
|
||||||
|
element.setAttribute("ID",Arrows.indexOf(item)); //save index
|
||||||
|
arrowItems.appendChild(element);
|
||||||
|
}
|
||||||
|
diagram.appendChild(arrowItems);
|
||||||
|
}
|
||||||
|
return(document);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DiagramScene::fromXmlFormat(QDomDocument document)
|
||||||
|
{
|
||||||
|
//Read diagrams TODO: in future... add multi projects functionality
|
||||||
|
QHash<int , DiagramItem *> DiagramsID;
|
||||||
|
QDomNodeList diagrams = document.elementsByTagName("Diagram");
|
||||||
|
if(!diagrams.at(0).isElement())
|
||||||
|
return 0;
|
||||||
|
//Load the first diagram in the document
|
||||||
|
QDomElement diagram = diagrams.at(0).toElement();
|
||||||
|
//In order to segmentation faults prevention the load process
|
||||||
|
//is started loading the libraries, then items and finally arrows.
|
||||||
|
//Arrows depend of items, and items depend of libraries!!!
|
||||||
|
//TODO: rewrite this process for reading in the order specified
|
||||||
|
for (QDomNode node = diagram.firstChild() ;
|
||||||
|
!node.isNull() ;
|
||||||
|
node = node.nextSibling())
|
||||||
|
{
|
||||||
|
QDomElement element = node.toElement();
|
||||||
|
if(element.tagName()=="Libraries")
|
||||||
|
{
|
||||||
|
libraryList.clear();
|
||||||
|
for (QDomNode node = element.firstChild() ;
|
||||||
|
!node.isNull() ;
|
||||||
|
node = node.nextSibling())
|
||||||
|
{
|
||||||
|
//Load library directory
|
||||||
|
QDomElement Library = node.toElement();
|
||||||
|
if(Library.tagName()!="Library")
|
||||||
|
return 0;
|
||||||
|
libraryList.append(Library.attribute("Dir"));
|
||||||
|
}
|
||||||
|
myOwnerWindow->updateLibraries();
|
||||||
|
}
|
||||||
|
else if(element.tagName()=="DiagramItems") //Load diagram items
|
||||||
|
{
|
||||||
|
for (QDomNode node = element.firstChild() ;
|
||||||
|
!node.isNull() ;
|
||||||
|
node = node.nextSibling())
|
||||||
|
{
|
||||||
|
//Load diagram item and add to scene
|
||||||
|
QDomElement diagramItem = node.toElement();
|
||||||
|
if(diagramItem.tagName()!="DiagramItem")
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
QPointF position = QPointF(diagramItem.attribute("x").toFloat(),
|
||||||
|
diagramItem.attribute("y").toFloat());
|
||||||
|
//PREVENT Segmentation faults:
|
||||||
|
if(!domElementsByName.contains(
|
||||||
|
diagramItem.attribute("type")))
|
||||||
|
{
|
||||||
|
QMessageBox::critical(0,"Error",QObject::tr(
|
||||||
|
"Diagram can't be loaded, because the"
|
||||||
|
" library for block [") +
|
||||||
|
diagramItem.attribute("type") +tr(
|
||||||
|
"] can't be found."));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DiagramItem *newItem=new DiagramItem(
|
||||||
|
myItemMenu,
|
||||||
|
diagramItem.attribute("type"),
|
||||||
|
domElementsByName.value(diagramItem.attribute("type")),
|
||||||
|
0,this, position,
|
||||||
|
diagramItem.attribute("z").toDouble());
|
||||||
|
|
||||||
|
newItem->setColor(QColor(diagramItem.attribute("color")));
|
||||||
|
|
||||||
|
addItem(newItem);
|
||||||
|
DiagramsID.insert(diagramItem.attribute("ID").toInt(),newItem);
|
||||||
|
for (QDomNode node = diagramItem.firstChild() ;
|
||||||
|
!node.isNull() ;
|
||||||
|
node = node.nextSibling())
|
||||||
|
{
|
||||||
|
//Load diagram text values and set on diagram item
|
||||||
|
QDomElement diagramValues = node.toElement();
|
||||||
|
if(diagramValues.tagName()!="diagramValues")
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
for (QDomNode node = diagramValues.firstChild() ;
|
||||||
|
!node.isNull() ;
|
||||||
|
node = node.nextSibling())
|
||||||
|
{
|
||||||
|
QDomElement diagramValue = node.toElement();
|
||||||
|
if(diagramValue.tagName()!="diagramValue")
|
||||||
|
return 0;
|
||||||
|
newItem->setValue(diagramValue.attribute("ID").toInt(),
|
||||||
|
diagramValue.attribute("value"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(element.tagName()=="Arrows")
|
||||||
|
{
|
||||||
|
|
||||||
|
for (QDomNode node = element.firstChild() ;
|
||||||
|
!node.isNull() ;
|
||||||
|
node = node.nextSibling())
|
||||||
|
{
|
||||||
|
//Load arrow item and add to scene
|
||||||
|
QDomElement arrow = node.toElement();
|
||||||
|
if(arrow.tagName()!="Arrow")
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
DiagramTextItem *startItem=
|
||||||
|
DiagramsID.value(arrow.attribute("start-Owner").toInt())
|
||||||
|
->pointerText(arrow.attribute("start-ID").toInt());
|
||||||
|
DiagramTextItem *endItem=
|
||||||
|
DiagramsID.value(arrow.attribute("end-Owner").toInt())
|
||||||
|
->pointerText(arrow.attribute("end-ID").toInt());
|
||||||
|
|
||||||
|
Arrow *newArrow = new Arrow(startItem, endItem,0,this);
|
||||||
|
newArrow->setColor(QColor(arrow.attribute("color")));
|
||||||
|
startItem->ownerItem()->addArrow(newArrow);
|
||||||
|
endItem->ownerItem()->addArrow(newArrow);
|
||||||
|
newArrow->setZValue(0.0);
|
||||||
|
addItem(newArrow);
|
||||||
|
newArrow->updatePosition();
|
||||||
|
|
||||||
|
for (QDomNode node = arrow.firstChild() ;
|
||||||
|
!node.isNull() ;
|
||||||
|
node = node.nextSibling())
|
||||||
|
{
|
||||||
|
//Load diagram text values and set on diagram item
|
||||||
|
QDomElement arrowCorners = node.toElement();
|
||||||
|
if(arrowCorners.tagName()!="arrowCorners")
|
||||||
|
return 0;
|
||||||
|
int i=0;
|
||||||
|
for (QDomNode node = arrowCorners.firstChild() ;
|
||||||
|
!node.isNull() ;
|
||||||
|
node = node.nextSibling())
|
||||||
|
{
|
||||||
|
QDomElement arrowCorner = node.toElement();
|
||||||
|
if(arrowCorner.tagName()!="arrowCorner")
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
QPointF cornerPos =
|
||||||
|
QPointF(arrowCorner.attribute("x").toFloat(),
|
||||||
|
arrowCorner.attribute("y").toFloat());
|
||||||
|
|
||||||
|
newArrow->createCorner(cornerPos,++i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramScene::cleanScene()
|
||||||
|
{
|
||||||
|
//Lists of items
|
||||||
|
QList<DiagramItem *> Items;
|
||||||
|
QList<Arrow *> Arrows;
|
||||||
|
foreach(QGraphicsItem *item, items())
|
||||||
|
{
|
||||||
|
if(item->type() == DiagramItem::Type)
|
||||||
|
Items.append(qgraphicsitem_cast<DiagramItem *>(item));
|
||||||
|
else if(item->type() == Arrow::Type)
|
||||||
|
Arrows.append(qgraphicsitem_cast<Arrow *>(item));
|
||||||
|
}
|
||||||
|
//Delete only DiagramItems: When a diagramitem is deleted his arrows and
|
||||||
|
//textitems have to be deleted too, so if we delete only diagramitems then
|
||||||
|
//we are deleting all items in the scene. This is in order to prevent
|
||||||
|
//segmentation faults.
|
||||||
|
foreach(DiagramItem *item, Items)
|
||||||
|
{
|
||||||
|
item->removeArrows();
|
||||||
|
item->removeTextItems();
|
||||||
|
removeItem(item);
|
||||||
|
delete(item);
|
||||||
|
}
|
||||||
|
//Delete the text items without parents
|
||||||
|
foreach(QGraphicsItem *item, items())
|
||||||
|
{
|
||||||
|
removeItem(item);
|
||||||
|
delete(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramScene::drawBackground(QPainter *p, const QRectF &r)
|
||||||
|
{
|
||||||
|
QGraphicsScene::drawBackground(p,r);
|
||||||
|
if(drawGrid)
|
||||||
|
{
|
||||||
|
p -> save();
|
||||||
|
|
||||||
|
p -> setRenderHint(QPainter::Antialiasing, false);
|
||||||
|
p -> setRenderHint(QPainter::TextAntialiasing, true);
|
||||||
|
p -> setRenderHint(QPainter::SmoothPixmapTransform, false);
|
||||||
|
|
||||||
|
p -> setPen(Qt::NoPen);
|
||||||
|
p -> setBrush(Qt::white);
|
||||||
|
p -> drawRect(r);
|
||||||
|
|
||||||
|
|
||||||
|
p -> setPen(Qt::black);
|
||||||
|
p -> setBrush(Qt::NoBrush);
|
||||||
|
qreal limite_x = r.x() + r.width();
|
||||||
|
qreal limite_y = r.y() + r.height();
|
||||||
|
|
||||||
|
int g_x = (int)ceil(r.x());
|
||||||
|
while (g_x % myGrid) ++ g_x;
|
||||||
|
int g_y = (int)ceil(r.y());
|
||||||
|
while (g_y % myGrid) ++ g_y;
|
||||||
|
|
||||||
|
QPolygon points;
|
||||||
|
for (int gx = g_x ; gx < limite_x ; gx += myGrid) {
|
||||||
|
for (int gy = g_y ; gy < limite_y ; gy += myGrid) {
|
||||||
|
points << QPoint(gx, gy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p -> drawPoints(points);
|
||||||
|
p -> restore();
|
||||||
|
}
|
||||||
|
}
|
142
Software/sie_cg/diagramscene.h
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
** All rights reserved.
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
|
**
|
||||||
|
** $QT_BEGIN_LICENSE:LGPL$
|
||||||
|
** Commercial Usage
|
||||||
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||||
|
** accordance with the Qt Commercial License Agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Nokia gives you certain additional
|
||||||
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3.0 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU General Public License version 3.0 requirements will be
|
||||||
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||||
|
**
|
||||||
|
** If you have questions regarding the use of this file, please contact
|
||||||
|
** Nokia at qt-info@nokia.com.
|
||||||
|
** $QT_END_LICENSE$
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef DIAGRAMSCENE_H
|
||||||
|
#define DIAGRAMSCENE_H
|
||||||
|
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
#include <QDesktopServices>
|
||||||
|
#include <QtXml>
|
||||||
|
#include "diagramitem.h"
|
||||||
|
#include "diagramtextitem.h"
|
||||||
|
#include "mainwindow.h"
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QGraphicsSceneMouseEvent;
|
||||||
|
class QMenu;
|
||||||
|
class QPointF;
|
||||||
|
class QGraphicsLineItem;
|
||||||
|
class QFont;
|
||||||
|
class QGraphicsTextItem;
|
||||||
|
class QColor;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
class MainWindow;
|
||||||
|
|
||||||
|
class DiagramScene : public QGraphicsScene
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum Mode { InsertItem, InsertLine, InsertText, MoveItem };
|
||||||
|
|
||||||
|
DiagramScene(QMenu *itemMenu, MainWindow *ownerWindow = 0,
|
||||||
|
QObject *parent = 0);
|
||||||
|
|
||||||
|
QFont font() const
|
||||||
|
{ return myFont; }
|
||||||
|
QColor textColor() const
|
||||||
|
{ return myTextColor; }
|
||||||
|
QColor itemColor() const
|
||||||
|
{ return myItemColor; }
|
||||||
|
QColor lineColor() const
|
||||||
|
{ return myLineColor; }
|
||||||
|
void setLineColor(const QColor &color);
|
||||||
|
void setTextColor(const QColor &color);
|
||||||
|
void setItemColor(const QColor &color);
|
||||||
|
void setFont(const QFont &font);
|
||||||
|
void setDawGrid(bool value) {drawGrid=value;}
|
||||||
|
|
||||||
|
QDomDocument toXmlFormat();
|
||||||
|
int fromXmlFormat(QDomDocument xmlDocument);
|
||||||
|
void cleanScene();
|
||||||
|
|
||||||
|
QStringList getLibList(){return libraryList;}
|
||||||
|
void setLibList(QStringList list)
|
||||||
|
{libraryList=list;}
|
||||||
|
|
||||||
|
void setDomElementsByName(QHash<QString , QDomElement*> hash)
|
||||||
|
{domElementsByName=hash;}
|
||||||
|
|
||||||
|
void setButtonIdByName(QHash<QString , int> hash)
|
||||||
|
{buttonIdByName=hash;}
|
||||||
|
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void setMode(Mode mode);
|
||||||
|
void setItemType(QString type);
|
||||||
|
void editorLostFocus(DiagramTextItem *item);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void itemInserted(DiagramItem *item);
|
||||||
|
void textInserted(QGraphicsTextItem *item);
|
||||||
|
void itemSelected(QGraphicsItem *item);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
||||||
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
||||||
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
||||||
|
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
||||||
|
void drawBackground(QPainter *p, const QRectF &r);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool isItemChange(int type);
|
||||||
|
void doSnapToGrid(QGraphicsSceneMouseEvent *mouseEvent);
|
||||||
|
QString myItemType;
|
||||||
|
QMenu *myItemMenu;
|
||||||
|
Mode myMode;
|
||||||
|
bool leftButtonDown;
|
||||||
|
QPointF startPoint;
|
||||||
|
QGraphicsLineItem *line;
|
||||||
|
QFont myFont;
|
||||||
|
DiagramTextItem *textItem;
|
||||||
|
QColor myTextColor;
|
||||||
|
QColor myItemColor;
|
||||||
|
QColor myLineColor;
|
||||||
|
bool snapToGrid;
|
||||||
|
bool drawGrid;
|
||||||
|
short int myGrid;
|
||||||
|
QStringList libraryList;
|
||||||
|
QHash<QString , QDomElement*> domElementsByName;
|
||||||
|
QHash<QString , int> buttonIdByName;
|
||||||
|
MainWindow *myOwnerWindow;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
33
Software/sie_cg/diagramscene.pro
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
HEADERS = mainwindow.h \
|
||||||
|
diagramitem.h \
|
||||||
|
diagramscene.h \
|
||||||
|
arrow.h \
|
||||||
|
diagramtextitem.h \
|
||||||
|
lineitem.h
|
||||||
|
SOURCES = mainwindow.cpp \
|
||||||
|
diagramitem.cpp \
|
||||||
|
main.cpp \
|
||||||
|
arrow.cpp \
|
||||||
|
diagramtextitem.cpp \
|
||||||
|
diagramscene.cpp \
|
||||||
|
lineitem.cpp
|
||||||
|
RESOURCES = diagramscene.qrc
|
||||||
|
|
||||||
|
TARGET = diagrameditor
|
||||||
|
|
||||||
|
# install
|
||||||
|
target.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/diagramscene
|
||||||
|
sources.files = $$SOURCES \
|
||||||
|
$$HEADERS \
|
||||||
|
$$RESOURCES \
|
||||||
|
$$FORMS \
|
||||||
|
diagramscene.pro \
|
||||||
|
images
|
||||||
|
sources.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/diagramscene
|
||||||
|
INSTALLS += target \
|
||||||
|
sources
|
||||||
|
symbian:include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
|
||||||
|
QT += xml \
|
||||||
|
svg \
|
||||||
|
network
|
||||||
|
FORMS += librarydialog.ui
|
247
Software/sie_cg/diagramscene.pro.user
Normal file
@ -0,0 +1,247 @@
|
|||||||
|
<!DOCTYPE QtCreatorProject>
|
||||||
|
<qtcreator>
|
||||||
|
<data>
|
||||||
|
<variable>RunConfiguration0-BaseEnvironmentBase</variable>
|
||||||
|
<value type="int">2</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>RunConfiguration0-CommandLineArguments</variable>
|
||||||
|
<valuelist type="QVariantList"/>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>RunConfiguration0-ProFile</variable>
|
||||||
|
<value type="QString">diagramscene.pro</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>RunConfiguration0-RunConfiguration.name</variable>
|
||||||
|
<value type="QString">diagramscene</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>RunConfiguration0-UseDyldImageSuffix</variable>
|
||||||
|
<value type="bool">false</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>RunConfiguration0-UseTerminal</variable>
|
||||||
|
<value type="bool">false</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>RunConfiguration0-UserEnvironmentChanges</variable>
|
||||||
|
<valuelist type="QVariantList"/>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>RunConfiguration0-UserSetName</variable>
|
||||||
|
<value type="bool">false</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>RunConfiguration0-UserSetWorkingDirectory</variable>
|
||||||
|
<value type="bool">false</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>RunConfiguration0-UserWorkingDirectory</variable>
|
||||||
|
<value type="QString"></value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>RunConfiguration0-type</variable>
|
||||||
|
<value type="QString">Qt4ProjectManager.Qt4RunConfiguration</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>activeRunConfiguration</variable>
|
||||||
|
<value type="int">0</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>activebuildconfiguration</variable>
|
||||||
|
<value type="QString">Debug</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>buildConfiguration-Debug</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value>
|
||||||
|
<value key="QtVersionId" type="int">0</value>
|
||||||
|
<value key="ToolChain" type="int">0</value>
|
||||||
|
<value key="addQDumper" type=""></value>
|
||||||
|
<value key="buildConfiguration" type="int">2</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>buildConfiguration-Release</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Release</value>
|
||||||
|
<value key="QtVersionId" type="int">0</value>
|
||||||
|
<value key="addQDumper" type=""></value>
|
||||||
|
<value key="buildConfiguration" type="int">0</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>buildconfiguration-Debug-buildstep0</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value>
|
||||||
|
<valuelist key="abstractProcess.Environment" type="QVariantList">
|
||||||
|
<value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-MI4KrAyPP5,guid=5c5c5e6146195c74b6ad266d4cc07afd</value>
|
||||||
|
<value type="QString">DEFAULTS_PATH=/usr/share/gconf/gnome.default.path</value>
|
||||||
|
<value type="QString">DESKTOP_SESSION=gnome</value>
|
||||||
|
<value type="QString">DISPLAY=:0.0</value>
|
||||||
|
<value type="QString">GDMSESSION=gnome</value>
|
||||||
|
<value type="QString">GDM_KEYBOARD_LAYOUT=es</value>
|
||||||
|
<value type="QString">GDM_LANG=en_US.utf8</value>
|
||||||
|
<value type="QString">GNOME_DESKTOP_SESSION_ID=this-is-deprecated</value>
|
||||||
|
<value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-CFAuJK</value>
|
||||||
|
<value type="QString">GNOME_KEYRING_PID=1516</value>
|
||||||
|
<value type="QString">GTK_MODULES=canberra-gtk-module</value>
|
||||||
|
<value type="QString">HOME=/home/juan64bits</value>
|
||||||
|
<value type="QString">LANG=en_US.utf8</value>
|
||||||
|
<value type="QString">LANGUAGE=</value>
|
||||||
|
<value type="QString">LD_LIBRARY_PATH=/usr/lib/qtcreator</value>
|
||||||
|
<value type="QString">LOGNAME=juan64bits</value>
|
||||||
|
<value type="QString">MANDATORY_PATH=/usr/share/gconf/gnome.mandatory.path</value>
|
||||||
|
<value type="QString">ORBIT_SOCKETDIR=/tmp/orbit-juan64bits</value>
|
||||||
|
<value type="QString">PATH=/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games</value>
|
||||||
|
<value type="QString">PWD=/home/juan64bits</value>
|
||||||
|
<value type="QString">QTDIR=/usr/share/qt4</value>
|
||||||
|
<value type="QString">SESSION_MANAGER=local/Maximus:@/tmp/.ICE-unix/1534,unix/Maximus:/tmp/.ICE-unix/1534</value>
|
||||||
|
<value type="QString">SHELL=/bin/bash</value>
|
||||||
|
<value type="QString">SPEECHD_PORT=7560</value>
|
||||||
|
<value type="QString">SSH_AGENT_PID=1570</value>
|
||||||
|
<value type="QString">SSH_AUTH_SOCK=/tmp/keyring-CFAuJK/ssh</value>
|
||||||
|
<value type="QString">USER=juan64bits</value>
|
||||||
|
<value type="QString">USERNAME=juan64bits</value>
|
||||||
|
<value type="QString">XAUTHORITY=/var/run/gdm/auth-for-juan64bits-V4ry7M/database</value>
|
||||||
|
<value type="QString">XDG_CONFIG_DIRS=/etc/xdg/xdg-gnome:/etc/xdg</value>
|
||||||
|
<value type="QString">XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/</value>
|
||||||
|
<value type="QString">XDG_SESSION_COOKIE=b9a7fbc4d869fc15bd6cdd474bcc9a28-1287682812.550485-1725059380</value>
|
||||||
|
</valuelist>
|
||||||
|
<valuelist key="abstractProcess.arguments" type="QVariantList">
|
||||||
|
<value type="QString">/home/juan64bits/QT/diagramscene/diagramscene.pro</value>
|
||||||
|
<value type="QString">-spec</value>
|
||||||
|
<value type="QString">linux-g++</value>
|
||||||
|
<value type="QString">-r</value>
|
||||||
|
<value type="QString">CONFIG+=debug</value>
|
||||||
|
</valuelist>
|
||||||
|
<value key="abstractProcess.command" type="QString">/usr/bin/qmake-qt4</value>
|
||||||
|
<value key="abstractProcess.enabled" type="bool">false</value>
|
||||||
|
<value key="abstractProcess.workingDirectory" type="QString">/home/juan64bits/QT/diagramscene</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>buildconfiguration-Debug-buildstep1</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value>
|
||||||
|
<valuelist key="abstractProcess.Environment" type="QVariantList">
|
||||||
|
<value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-MI4KrAyPP5,guid=5c5c5e6146195c74b6ad266d4cc07afd</value>
|
||||||
|
<value type="QString">DEFAULTS_PATH=/usr/share/gconf/gnome.default.path</value>
|
||||||
|
<value type="QString">DESKTOP_SESSION=gnome</value>
|
||||||
|
<value type="QString">DISPLAY=:0.0</value>
|
||||||
|
<value type="QString">GDMSESSION=gnome</value>
|
||||||
|
<value type="QString">GDM_KEYBOARD_LAYOUT=es</value>
|
||||||
|
<value type="QString">GDM_LANG=en_US.utf8</value>
|
||||||
|
<value type="QString">GNOME_DESKTOP_SESSION_ID=this-is-deprecated</value>
|
||||||
|
<value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-CFAuJK</value>
|
||||||
|
<value type="QString">GNOME_KEYRING_PID=1516</value>
|
||||||
|
<value type="QString">GTK_MODULES=canberra-gtk-module</value>
|
||||||
|
<value type="QString">HOME=/home/juan64bits</value>
|
||||||
|
<value type="QString">LANG=en_US.utf8</value>
|
||||||
|
<value type="QString">LANGUAGE=</value>
|
||||||
|
<value type="QString">LD_LIBRARY_PATH=/usr/lib/qtcreator</value>
|
||||||
|
<value type="QString">LOGNAME=juan64bits</value>
|
||||||
|
<value type="QString">MANDATORY_PATH=/usr/share/gconf/gnome.mandatory.path</value>
|
||||||
|
<value type="QString">ORBIT_SOCKETDIR=/tmp/orbit-juan64bits</value>
|
||||||
|
<value type="QString">PATH=/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games</value>
|
||||||
|
<value type="QString">PWD=/home/juan64bits</value>
|
||||||
|
<value type="QString">QTDIR=/usr/share/qt4</value>
|
||||||
|
<value type="QString">SESSION_MANAGER=local/Maximus:@/tmp/.ICE-unix/1534,unix/Maximus:/tmp/.ICE-unix/1534</value>
|
||||||
|
<value type="QString">SHELL=/bin/bash</value>
|
||||||
|
<value type="QString">SPEECHD_PORT=7560</value>
|
||||||
|
<value type="QString">SSH_AGENT_PID=1570</value>
|
||||||
|
<value type="QString">SSH_AUTH_SOCK=/tmp/keyring-CFAuJK/ssh</value>
|
||||||
|
<value type="QString">USER=juan64bits</value>
|
||||||
|
<value type="QString">USERNAME=juan64bits</value>
|
||||||
|
<value type="QString">XAUTHORITY=/var/run/gdm/auth-for-juan64bits-V4ry7M/database</value>
|
||||||
|
<value type="QString">XDG_CONFIG_DIRS=/etc/xdg/xdg-gnome:/etc/xdg</value>
|
||||||
|
<value type="QString">XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/</value>
|
||||||
|
<value type="QString">XDG_SESSION_COOKIE=b9a7fbc4d869fc15bd6cdd474bcc9a28-1287682812.550485-1725059380</value>
|
||||||
|
</valuelist>
|
||||||
|
<value key="abstractProcess.IgnoreReturnValue" type="bool">false</value>
|
||||||
|
<valuelist key="abstractProcess.arguments" type="QVariantList">
|
||||||
|
<value type="QString">-w</value>
|
||||||
|
</valuelist>
|
||||||
|
<value key="abstractProcess.command" type="QString">/usr/bin/make</value>
|
||||||
|
<value key="abstractProcess.enabled" type="bool">true</value>
|
||||||
|
<value key="abstractProcess.workingDirectory" type="QString">/home/juan64bits/QT/diagramscene</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>buildconfiguration-Debug-cleanstep0</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value>
|
||||||
|
<value key="cleanConfig" type="bool">true</value>
|
||||||
|
<valuelist key="makeargs" type="QVariantList">
|
||||||
|
<value type="QString">clean</value>
|
||||||
|
</valuelist>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>buildconfiguration-Release-buildstep0</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Release</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>buildconfiguration-Release-buildstep1</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Release</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>buildconfiguration-Release-cleanstep0</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Release</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>buildconfigurations</variable>
|
||||||
|
<valuelist type="QVariantList">
|
||||||
|
<value type="QString">Debug</value>
|
||||||
|
<value type="QString">Release</value>
|
||||||
|
</valuelist>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>buildstep0</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString"></value>
|
||||||
|
<value key="mkspec" type="QString"></value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>buildstep1</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString"></value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>buildsteps</variable>
|
||||||
|
<valuelist type="QVariantList">
|
||||||
|
<value type="QString">trolltech.qt4projectmanager.qmake</value>
|
||||||
|
<value type="QString">trolltech.qt4projectmanager.make</value>
|
||||||
|
</valuelist>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>cleanstep0</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString"></value>
|
||||||
|
<value key="clean" type="bool">true</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>cleansteps</variable>
|
||||||
|
<valuelist type="QVariantList">
|
||||||
|
<value type="QString">trolltech.qt4projectmanager.make</value>
|
||||||
|
</valuelist>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>defaultFileEncoding</variable>
|
||||||
|
<value type="QByteArray">System</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>project</variable>
|
||||||
|
<valuemap type="QVariantMap"/>
|
||||||
|
</data>
|
||||||
|
</qtcreator>
|
28
Software/sie_cg/diagramscene.qrc
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<RCC>
|
||||||
|
<qresource prefix="/">
|
||||||
|
<file>images/pointer.png</file>
|
||||||
|
<file>images/linepointer.png</file>
|
||||||
|
<file>images/textpointer.png</file>
|
||||||
|
<file>images/bold.png</file>
|
||||||
|
<file>images/italic.png</file>
|
||||||
|
<file>images/underline.png</file>
|
||||||
|
<file>images/floodfill.png</file>
|
||||||
|
<file>images/bringtofront.png</file>
|
||||||
|
<file>images/delete.png</file>
|
||||||
|
<file>images/sendtoback.png</file>
|
||||||
|
<file>images/linecolor.png</file>
|
||||||
|
<file>images/background1.png</file>
|
||||||
|
<file>images/background2.png</file>
|
||||||
|
<file>images/background3.png</file>
|
||||||
|
<file>images/background4.png</file>
|
||||||
|
<file>images/exit.png</file>
|
||||||
|
<file>images/new.png</file>
|
||||||
|
<file>images/no.png</file>
|
||||||
|
<file>images/open.png</file>
|
||||||
|
<file>images/save.png</file>
|
||||||
|
<file>images/save_as.png</file>
|
||||||
|
<file>images/yes.png</file>
|
||||||
|
<file>images/zoom_in.png</file>
|
||||||
|
<file>images/zoom_out.png</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
162
Software/sie_cg/diagramtextitem.cpp
Normal file
@ -0,0 +1,162 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
** All rights reserved.
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
|
**
|
||||||
|
** $QT_BEGIN_LICENSE:LGPL$
|
||||||
|
** Commercial Usage
|
||||||
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||||
|
** accordance with the Qt Commercial License Agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Nokia gives you certain additional
|
||||||
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3.0 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU General Public License version 3.0 requirements will be
|
||||||
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||||
|
**
|
||||||
|
** If you have questions regarding the use of this file, please contact
|
||||||
|
** Nokia at qt-info@nokia.com.
|
||||||
|
** $QT_END_LICENSE$
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <QtGui>
|
||||||
|
|
||||||
|
#include "diagramtextitem.h"
|
||||||
|
#include "diagramscene.h"
|
||||||
|
|
||||||
|
DiagramTextItem::DiagramTextItem(QGraphicsItem *parent, QGraphicsScene *scene,
|
||||||
|
bool editable, DiagramItem *ownerItem, unsigned char styleIO,
|
||||||
|
unsigned char ID, QString defaultText, QPointF offset)
|
||||||
|
: QGraphicsTextItem(parent, scene)
|
||||||
|
{
|
||||||
|
myOwnerItem = ownerItem;
|
||||||
|
myStyleIO = styleIO;
|
||||||
|
myID=ID;
|
||||||
|
editableItem=editable;
|
||||||
|
if(myOwnerItem==0)
|
||||||
|
setZValue(1000.0);
|
||||||
|
else
|
||||||
|
setZValue(myOwnerItem->zValue());
|
||||||
|
|
||||||
|
setPlainText(defaultText);
|
||||||
|
posOffset=offset;
|
||||||
|
|
||||||
|
if(editable)
|
||||||
|
{
|
||||||
|
if (myOwnerItem==0)
|
||||||
|
setFlag(QGraphicsItem::ItemIsMovable);
|
||||||
|
setFlag(QGraphicsItem::ItemIsSelectable);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
setFlag(QGraphicsItem::ItemIsFocusable,0);
|
||||||
|
|
||||||
|
updatePosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramTextItem::updatePosition()
|
||||||
|
{
|
||||||
|
QPointF myOwnerPos;
|
||||||
|
|
||||||
|
|
||||||
|
if(myOwnerItem!=0)
|
||||||
|
{
|
||||||
|
setZValue(myOwnerItem->zValue());
|
||||||
|
myOwnerPos= myOwnerItem->pos();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setZValue(1000.0);
|
||||||
|
myOwnerPos=pos();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(myStyleIO==0)
|
||||||
|
setPos(myOwnerPos+posOffset+QPointF(-boundingRect().width()/2,
|
||||||
|
-boundingRect().height()/2));
|
||||||
|
else if(myStyleIO & 0b10000000)
|
||||||
|
setPos(myOwnerPos+posOffset+QPointF(0,-boundingRect().height()/2));
|
||||||
|
else //OUT
|
||||||
|
setPos(myOwnerPos+posOffset+QPointF(-boundingRect().width(),
|
||||||
|
-boundingRect().height()/2));
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant DiagramTextItem::itemChange(GraphicsItemChange change,
|
||||||
|
const QVariant &value)
|
||||||
|
{
|
||||||
|
if (change == QGraphicsItem::ItemSelectedHasChanged)
|
||||||
|
emit selectedChange(this);
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramTextItem::focusOutEvent(QFocusEvent *event)
|
||||||
|
{
|
||||||
|
if(editableItem)
|
||||||
|
{
|
||||||
|
if(toPlainText()=="") setPlainText("?");
|
||||||
|
if(myOwnerItem!=0) updatePosition();
|
||||||
|
setTextInteractionFlags(Qt::NoTextInteraction);
|
||||||
|
emit lostFocus(this);
|
||||||
|
QGraphicsTextItem::focusOutEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramTextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
if(editableItem)
|
||||||
|
{
|
||||||
|
if (textInteractionFlags() == Qt::NoTextInteraction)
|
||||||
|
setTextInteractionFlags(Qt::TextEditorInteraction);
|
||||||
|
QGraphicsTextItem::mouseDoubleClickEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
if (myOwnerItem!=0)
|
||||||
|
{
|
||||||
|
setSelected(0);
|
||||||
|
myOwnerItem->mousePressEvent(event);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
QGraphicsTextItem::mousePressEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
if (myOwnerItem!=0)
|
||||||
|
{
|
||||||
|
myOwnerItem->mouseReleaseEvent(event);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
QGraphicsTextItem::mouseReleaseEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagramTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
if (myOwnerItem!=0)
|
||||||
|
{
|
||||||
|
myOwnerItem->mouseMoveEvent(event);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
QGraphicsTextItem::mouseMoveEvent(event);
|
||||||
|
}
|
110
Software/sie_cg/diagramtextitem.h
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
** All rights reserved.
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
|
**
|
||||||
|
** $QT_BEGIN_LICENSE:LGPL$
|
||||||
|
** Commercial Usage
|
||||||
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||||
|
** accordance with the Qt Commercial License Agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Nokia gives you certain additional
|
||||||
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3.0 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU General Public License version 3.0 requirements will be
|
||||||
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||||
|
**
|
||||||
|
** If you have questions regarding the use of this file, please contact
|
||||||
|
** Nokia at qt-info@nokia.com.
|
||||||
|
** $QT_END_LICENSE$
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef DIAGRAMTEXTITEM_H
|
||||||
|
#define DIAGRAMTEXTITEM_H
|
||||||
|
|
||||||
|
#include <QGraphicsTextItem>
|
||||||
|
#include <QPen>
|
||||||
|
#include "diagramitem.h"
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QFocusEvent;
|
||||||
|
class QGraphicsItem;
|
||||||
|
class QGraphicsScene;
|
||||||
|
class QGraphicsSceneMouseEvent;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
class DiagramTextItem : public QGraphicsTextItem
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum { Type = UserType + 3 };
|
||||||
|
|
||||||
|
DiagramTextItem(
|
||||||
|
QGraphicsItem *parent = 0, QGraphicsScene *scene = 0,
|
||||||
|
bool editable =1, DiagramItem *ownerItem=0, unsigned char styleIO = 0,
|
||||||
|
unsigned char ID=0, QString defaultText="<text>",
|
||||||
|
QPointF offset=QPointF(0,0));
|
||||||
|
|
||||||
|
int type() const
|
||||||
|
{ return Type;}
|
||||||
|
|
||||||
|
unsigned char styleIO() const
|
||||||
|
{ return myStyleIO;}
|
||||||
|
|
||||||
|
unsigned char textID() const
|
||||||
|
{ return myID;}
|
||||||
|
|
||||||
|
QPointF offset() const
|
||||||
|
{ return posOffset;}
|
||||||
|
|
||||||
|
DiagramItem *ownerItem() const
|
||||||
|
{ return myOwnerItem; }
|
||||||
|
|
||||||
|
bool isEditable()
|
||||||
|
{ return editableItem;}
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void updatePosition();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void lostFocus(DiagramTextItem *item);
|
||||||
|
void selectedChange(QGraphicsItem *item);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||||
|
void focusOutEvent(QFocusEvent *event);
|
||||||
|
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool editableItem;
|
||||||
|
DiagramItem *myOwnerItem;
|
||||||
|
QPointF posOffset;
|
||||||
|
unsigned char myStyleIO;
|
||||||
|
unsigned char myID;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
BIN
Software/sie_cg/images/background1.png
Normal file
After Width: | Height: | Size: 289 B |
BIN
Software/sie_cg/images/background2.png
Normal file
After Width: | Height: | Size: 285 B |
BIN
Software/sie_cg/images/background3.png
Normal file
After Width: | Height: | Size: 330 B |
BIN
Software/sie_cg/images/background4.png
Normal file
After Width: | Height: | Size: 342 B |
BIN
Software/sie_cg/images/bold.png
Normal file
After Width: | Height: | Size: 274 B |
BIN
Software/sie_cg/images/bringtofront.png
Normal file
After Width: | Height: | Size: 514 B |
BIN
Software/sie_cg/images/delete.png
Normal file
After Width: | Height: | Size: 3.1 KiB |
BIN
Software/sie_cg/images/exit.png
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
Software/sie_cg/images/floodfill.png
Normal file
After Width: | Height: | Size: 282 B |
BIN
Software/sie_cg/images/italic.png
Normal file
After Width: | Height: | Size: 247 B |
BIN
Software/sie_cg/images/linecolor.png
Normal file
After Width: | Height: | Size: 145 B |
BIN
Software/sie_cg/images/linepointer.png
Normal file
After Width: | Height: | Size: 141 B |
BIN
Software/sie_cg/images/lower1.png
Normal file
After Width: | Height: | Size: 318 B |
BIN
Software/sie_cg/images/new.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
Software/sie_cg/images/no.png
Normal file
After Width: | Height: | Size: 831 B |
BIN
Software/sie_cg/images/open.png
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
Software/sie_cg/images/pointer.png
Normal file
After Width: | Height: | Size: 173 B |
BIN
Software/sie_cg/images/preview.png
Normal file
After Width: | Height: | Size: 3.2 KiB |
BIN
Software/sie_cg/images/raise1.png
Normal file
After Width: | Height: | Size: 293 B |
BIN
Software/sie_cg/images/save.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
Software/sie_cg/images/save_as.png
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
Software/sie_cg/images/sendtoback.png
Normal file
After Width: | Height: | Size: 430 B |
BIN
Software/sie_cg/images/textpointer.png
Normal file
After Width: | Height: | Size: 753 B |
BIN
Software/sie_cg/images/underline.png
Normal file
After Width: | Height: | Size: 250 B |
BIN
Software/sie_cg/images/yes.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
Software/sie_cg/images/zoom_in.png
Normal file
After Width: | Height: | Size: 3.4 KiB |
BIN
Software/sie_cg/images/zoom_out.png
Normal file
After Width: | Height: | Size: 3.3 KiB |
BIN
Software/sie_cg/librarydialog.o
Normal file
99
Software/sie_cg/librarydialog.ui
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>libraryDialog</class>
|
||||||
|
<widget class="QDialog" name="libraryDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>333</width>
|
||||||
|
<height>341</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Dialog</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QListWidget" name="listLib"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="addLib">
|
||||||
|
<property name="text">
|
||||||
|
<string>&Add Library</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="delLib">
|
||||||
|
<property name="text">
|
||||||
|
<string>&Remove library</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="editLib">
|
||||||
|
<property name="text">
|
||||||
|
<string>&Edit library</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="Line" name="line">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>libraryDialog</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>316</x>
|
||||||
|
<y>260</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>286</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>libraryDialog</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>248</x>
|
||||||
|
<y>254</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>157</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
137
Software/sie_cg/lineitem.cpp
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
** All rights reserved.
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
|
**
|
||||||
|
** $QT_BEGIN_LICENSE:LGPL$
|
||||||
|
** Commercial Usage
|
||||||
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||||
|
** accordance with the Qt Commercial License Agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Nokia gives you certain additional
|
||||||
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3.0 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU General Public License version 3.0 requirements will be
|
||||||
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||||
|
**
|
||||||
|
** If you have questions regarding the use of this file, please contact
|
||||||
|
** Nokia at qt-info@nokia.com.
|
||||||
|
** $QT_END_LICENSE$
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <QtGui>
|
||||||
|
|
||||||
|
#include "lineitem.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
lineItem::lineItem(QPointF startPoint, QPointF endItem, Arrow *ownerArrow,
|
||||||
|
int wt, bool movable, QGraphicsItem *parent, QGraphicsScene *scene)
|
||||||
|
: QGraphicsLineItem(parent, scene)
|
||||||
|
{
|
||||||
|
isMovable=movable;
|
||||||
|
if(isMovable) setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||||
|
|
||||||
|
setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||||
|
|
||||||
|
myColor = Qt::black;
|
||||||
|
setPen(QPen(myColor, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||||
|
setLine(QLineF(startPoint,endItem));
|
||||||
|
myOwnerArrow = ownerArrow;
|
||||||
|
pWidth=wt;
|
||||||
|
moveItem=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
QRectF lineItem::boundingRect() const
|
||||||
|
{
|
||||||
|
qreal extra = (pen().width() + 20) / 2.0;
|
||||||
|
|
||||||
|
return QRectF(line().p1(), QSizeF(line().p2().x() - line().p1().x(),
|
||||||
|
line().p2().y() - line().p1().y()))
|
||||||
|
.normalized()
|
||||||
|
.adjusted(-extra, -extra, extra, extra);
|
||||||
|
}
|
||||||
|
|
||||||
|
QPainterPath lineItem::shape() const
|
||||||
|
{
|
||||||
|
QPainterPath path = QGraphicsLineItem::shape();
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
void lineItem::updatePos()
|
||||||
|
{
|
||||||
|
QPointF itemPos = this->line().p1();
|
||||||
|
myOwnerArrow->moveCorner(itemPos,this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lineItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *,
|
||||||
|
QWidget *)
|
||||||
|
{
|
||||||
|
QPen myPen = pen();
|
||||||
|
myPen.setColor(myColor);
|
||||||
|
myPen.setWidth(pWidth);
|
||||||
|
painter->setPen(myPen);
|
||||||
|
painter->setBrush(myColor);
|
||||||
|
|
||||||
|
setLine(line());
|
||||||
|
painter->drawLine(line());
|
||||||
|
|
||||||
|
//Drawing arrow selected
|
||||||
|
if (isSelected()) {
|
||||||
|
painter->setPen(QPen(Qt::gray, pWidth, Qt::SolidLine));
|
||||||
|
QLineF myLine = line();
|
||||||
|
painter->drawLine(myLine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void lineItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
|
{
|
||||||
|
if(!isMovable)
|
||||||
|
{
|
||||||
|
myOwnerArrow->createCorner(mouseEvent->pos(),this);
|
||||||
|
}
|
||||||
|
QGraphicsLineItem::mouseDoubleClickEvent(mouseEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void lineItem::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
|
{
|
||||||
|
QGraphicsLineItem::mousePressEvent(mouseEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lineItem::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
|
{
|
||||||
|
if(isMovable)
|
||||||
|
{
|
||||||
|
updatePos();
|
||||||
|
}
|
||||||
|
QGraphicsLineItem::mouseMoveEvent(mouseEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
|
{
|
||||||
|
if(isMovable)
|
||||||
|
{
|
||||||
|
updatePos();
|
||||||
|
}
|
||||||
|
QGraphicsLineItem::mouseReleaseEvent(mouseEvent);
|
||||||
|
}
|
98
Software/sie_cg/lineitem.h
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
** All rights reserved.
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
|
**
|
||||||
|
** $QT_BEGIN_LICENSE:LGPL$
|
||||||
|
** Commercial Usage
|
||||||
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||||
|
** accordance with the Qt Commercial License Agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Nokia gives you certain additional
|
||||||
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3.0 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU General Public License version 3.0 requirements will be
|
||||||
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||||
|
**
|
||||||
|
** If you have questions regarding the use of this file, please contact
|
||||||
|
** Nokia at qt-info@nokia.com.
|
||||||
|
** $QT_END_LICENSE$
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef LINEITEM_H
|
||||||
|
#define LINEITEM_H
|
||||||
|
|
||||||
|
#include <QGraphicsLineItem>
|
||||||
|
|
||||||
|
#include "diagramitem.h"
|
||||||
|
#include "arrow.h"
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QGraphicsPolygonItem;
|
||||||
|
class QGraphicsLineItem;
|
||||||
|
class QGraphicsScene;
|
||||||
|
class QRectF;
|
||||||
|
class QGraphicsSceneMouseEvent;
|
||||||
|
class QPainterPath;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
class lineItem : public QGraphicsLineItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum { Type = UserType + 4 };
|
||||||
|
|
||||||
|
lineItem(QPointF startPoint, QPointF endItem, Arrow *ownerArrow, int wt=2,
|
||||||
|
bool movable = 0, QGraphicsItem *parent = 0, QGraphicsScene *scene = 0);
|
||||||
|
|
||||||
|
int type() const
|
||||||
|
{ return Type;}
|
||||||
|
QRectF boundingRect() const;
|
||||||
|
QPainterPath shape() const;
|
||||||
|
void setColor(const QColor &color)
|
||||||
|
{ myColor=color; }
|
||||||
|
|
||||||
|
Arrow * myOwner()
|
||||||
|
{ return myOwnerArrow;}
|
||||||
|
|
||||||
|
bool itemIsMovable() {return isMovable;}
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void updatePos();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
|
QWidget *widget = 0);
|
||||||
|
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QColor myColor;
|
||||||
|
int pWidth;
|
||||||
|
Arrow *myOwnerArrow;
|
||||||
|
int moveItem;
|
||||||
|
bool isMovable;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
55
Software/sie_cg/main.cpp
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
** All rights reserved.
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
|
**
|
||||||
|
** $QT_BEGIN_LICENSE:LGPL$
|
||||||
|
** Commercial Usage
|
||||||
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||||
|
** accordance with the Qt Commercial License Agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Nokia gives you certain additional
|
||||||
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3.0 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU General Public License version 3.0 requirements will be
|
||||||
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||||
|
**
|
||||||
|
** If you have questions regarding the use of this file, please contact
|
||||||
|
** Nokia at qt-info@nokia.com.
|
||||||
|
** $QT_END_LICENSE$
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <QtGui>
|
||||||
|
|
||||||
|
#include "mainwindow.h"
|
||||||
|
|
||||||
|
int main(int argv, char *args[])
|
||||||
|
{
|
||||||
|
Q_INIT_RESOURCE(diagramscene);
|
||||||
|
|
||||||
|
QApplication app(argv, args);
|
||||||
|
MainWindow mainWindow;
|
||||||
|
mainWindow.setGeometry(100, 100, 1024, 640);
|
||||||
|
mainWindow.show();
|
||||||
|
return app.exec();
|
||||||
|
}
|
929
Software/sie_cg/mainwindow.cpp
Normal file
@ -0,0 +1,929 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
** All rights reserved.
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
|
**
|
||||||
|
** $QT_BEGIN_LICENSE:LGPL$
|
||||||
|
** Commercial Usage
|
||||||
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||||
|
** accordance with the Qt Commercial License Agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Nokia gives you certain additional
|
||||||
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3.0 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU General Public License version 3.0 requirements will be
|
||||||
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||||
|
**
|
||||||
|
** If you have questions regarding the use of this file, please contact
|
||||||
|
** Nokia at qt-info@nokia.com.
|
||||||
|
** $QT_END_LICENSE$
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <QtGui>
|
||||||
|
#include <QLabel>
|
||||||
|
|
||||||
|
#include "mainwindow.h"
|
||||||
|
|
||||||
|
const int InsertTextButton = 100000;
|
||||||
|
|
||||||
|
MainWindow::MainWindow()
|
||||||
|
{
|
||||||
|
buttonGroup=0;
|
||||||
|
toolBox=0;
|
||||||
|
|
||||||
|
createActions();
|
||||||
|
createMenus();
|
||||||
|
scene = new DiagramScene(itemMenu,this);
|
||||||
|
scene->setSceneRect(QRectF(0, 0, 5000, 5000));
|
||||||
|
connect(scene, SIGNAL(itemInserted(DiagramItem*)),
|
||||||
|
this, SLOT(itemInserted(DiagramItem*)));
|
||||||
|
connect(scene, SIGNAL(textInserted(QGraphicsTextItem*)),
|
||||||
|
this, SLOT(textInserted(QGraphicsTextItem*)));
|
||||||
|
connect(scene, SIGNAL(itemSelected(QGraphicsItem*)),
|
||||||
|
this, SLOT(itemSelected(QGraphicsItem*)));
|
||||||
|
createToolBox();
|
||||||
|
createToolbars();
|
||||||
|
|
||||||
|
setWindowTitle(tr("SIE Code Generator (Diagram Editor)"));
|
||||||
|
setUnifiedTitleAndToolBarOnMac(true);
|
||||||
|
myFilePath = "";
|
||||||
|
libDialog=0;
|
||||||
|
|
||||||
|
if(QApplication::argc()>1)
|
||||||
|
{newDiagram(QString(QApplication::argv()[1]));}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::backgroundButtonGroupClicked(QAbstractButton *button)
|
||||||
|
{
|
||||||
|
QList<QAbstractButton *> buttons = backgroundButtonGroup->buttons();
|
||||||
|
foreach (QAbstractButton *myButton, buttons) {
|
||||||
|
if (myButton != button)
|
||||||
|
button->setChecked(false);
|
||||||
|
}
|
||||||
|
QString text = button->text();
|
||||||
|
if (text == tr("Blue Grid"))
|
||||||
|
scene->setBackgroundBrush(QPixmap(":/images/background1.png"));
|
||||||
|
else if (text == tr("White Grid"))
|
||||||
|
scene->setBackgroundBrush(QPixmap(":/images/background2.png"));
|
||||||
|
else if (text == tr("Gray Grid"))
|
||||||
|
scene->setBackgroundBrush(QPixmap(":/images/background3.png"));
|
||||||
|
else
|
||||||
|
scene->setBackgroundBrush(QPixmap(":/images/background4.png"));
|
||||||
|
|
||||||
|
scene->update();
|
||||||
|
view->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::buttonGroupClicked(int id)
|
||||||
|
{
|
||||||
|
QList<QAbstractButton *> buttons = buttonGroup->buttons();
|
||||||
|
foreach (QAbstractButton *button, buttons) {
|
||||||
|
if (buttonGroup->button(id) != button)
|
||||||
|
button->setChecked(false);
|
||||||
|
}
|
||||||
|
if (id == InsertTextButton) {
|
||||||
|
scene->setMode(DiagramScene::InsertText);
|
||||||
|
} else {
|
||||||
|
scene->setItemType(buttonGroup->button(id)->text()); //Block name
|
||||||
|
scene->setMode(DiagramScene::InsertItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::deleteItem()
|
||||||
|
{
|
||||||
|
foreach (QGraphicsItem *item, scene->selectedItems()) {
|
||||||
|
if (item->type() == DiagramItem::Type) {
|
||||||
|
qgraphicsitem_cast<DiagramItem *>(item)->removeArrows();
|
||||||
|
qgraphicsitem_cast<DiagramItem *>(item)->removeTextItems();
|
||||||
|
scene->removeItem(item);
|
||||||
|
delete(item);
|
||||||
|
}
|
||||||
|
//If arrow is deleted then is romoved from diagram owner
|
||||||
|
else if (item->type() == Arrow::Type) {
|
||||||
|
qgraphicsitem_cast<Arrow *>(item)->removeLines();
|
||||||
|
qgraphicsitem_cast<Arrow *>(item)->startItem()->ownerItem()
|
||||||
|
->removeArrow(qgraphicsitem_cast<Arrow *>(item));
|
||||||
|
qgraphicsitem_cast<Arrow *>(item)->endItem()->ownerItem()
|
||||||
|
->removeArrow(qgraphicsitem_cast<Arrow *>(item));
|
||||||
|
scene->removeItem(item);
|
||||||
|
delete(item);
|
||||||
|
}
|
||||||
|
//If line is deleted then is romoved from the arrow owner
|
||||||
|
else if (item->type() == lineItem::Type &&
|
||||||
|
!qgraphicsitem_cast<lineItem *>(item)->itemIsMovable()) {
|
||||||
|
|
||||||
|
qgraphicsitem_cast<lineItem *>(item)->myOwner()->removeLine(
|
||||||
|
qgraphicsitem_cast<lineItem *>(item));
|
||||||
|
qgraphicsitem_cast<lineItem *>(item)->myOwner()->updatePosition();
|
||||||
|
scene->removeItem(item);
|
||||||
|
delete(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::pointerGroupClicked(int)
|
||||||
|
{
|
||||||
|
scene->setMode(DiagramScene::Mode(pointerTypeGroup->checkedId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::bringToFront()
|
||||||
|
{
|
||||||
|
sendTo(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::sendToBack()
|
||||||
|
{
|
||||||
|
sendTo(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::sendTo(bool value)
|
||||||
|
{
|
||||||
|
if (scene->selectedItems().isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QGraphicsItem *selectedItem = scene->selectedItems().first();
|
||||||
|
QList<QGraphicsItem *> overlapItems = selectedItem->collidingItems();
|
||||||
|
|
||||||
|
qreal zValue = 0;
|
||||||
|
foreach (QGraphicsItem *item, overlapItems) {
|
||||||
|
if (item->zValue() <= zValue &&
|
||||||
|
item->type() == DiagramItem::Type)
|
||||||
|
{
|
||||||
|
if(value)
|
||||||
|
zValue = item->zValue() + 0.1;
|
||||||
|
else
|
||||||
|
zValue = item->zValue() - 0.1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
selectedItem->setZValue(zValue);
|
||||||
|
if(selectedItem->type() == DiagramItem::Type)
|
||||||
|
foreach (DiagramTextItem *texts,
|
||||||
|
qgraphicsitem_cast<DiagramItem *>(selectedItem)->getTextItems())
|
||||||
|
{
|
||||||
|
texts->updatePosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::itemInserted(DiagramItem *item)
|
||||||
|
{
|
||||||
|
pointerTypeGroup->button(int(DiagramScene::MoveItem))->setChecked(true);
|
||||||
|
scene->setMode(DiagramScene::Mode(pointerTypeGroup->checkedId()));
|
||||||
|
buttonGroup->button(buttonIdByName.value(item->diagramType()))->setChecked(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::textInserted(QGraphicsTextItem *)
|
||||||
|
{
|
||||||
|
buttonGroup->button(InsertTextButton)->setChecked(false);
|
||||||
|
scene->setMode(DiagramScene::Mode(pointerTypeGroup->checkedId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::currentFontChanged(const QFont &)
|
||||||
|
{
|
||||||
|
handleFontChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::fontSizeChanged(const QString &)
|
||||||
|
{
|
||||||
|
handleFontChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::sceneScaleChanged(const QString &scale)
|
||||||
|
{
|
||||||
|
double newScale = scale.left(scale.indexOf(tr("%"))).toDouble() / 100.0;
|
||||||
|
QMatrix oldMatrix = view->matrix();
|
||||||
|
view->resetMatrix();
|
||||||
|
view->translate(oldMatrix.dx(), oldMatrix.dy());
|
||||||
|
view->scale(newScale, newScale);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::textColorChanged()
|
||||||
|
{
|
||||||
|
textAction = qobject_cast<QAction *>(sender());
|
||||||
|
fontColorToolButton->setIcon(createColorToolButtonIcon(
|
||||||
|
":/images/textpointer.png",
|
||||||
|
qVariantValue<QColor>(textAction->data())));
|
||||||
|
textButtonTriggered();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::itemColorChanged()
|
||||||
|
{
|
||||||
|
fillAction = qobject_cast<QAction *>(sender());
|
||||||
|
fillColorToolButton->setIcon(createColorToolButtonIcon(
|
||||||
|
":/images/floodfill.png",
|
||||||
|
qVariantValue<QColor>(fillAction->data())));
|
||||||
|
fillButtonTriggered();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::lineColorChanged()
|
||||||
|
{
|
||||||
|
lineAction = qobject_cast<QAction *>(sender());
|
||||||
|
lineColorToolButton->setIcon(createColorToolButtonIcon(
|
||||||
|
":/images/linecolor.png",
|
||||||
|
qVariantValue<QColor>(lineAction->data())));
|
||||||
|
lineButtonTriggered();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::textButtonTriggered()
|
||||||
|
{
|
||||||
|
scene->setTextColor(qVariantValue<QColor>(textAction->data()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::fillButtonTriggered()
|
||||||
|
{
|
||||||
|
scene->setItemColor(qVariantValue<QColor>(fillAction->data()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::lineButtonTriggered()
|
||||||
|
{
|
||||||
|
scene->setLineColor(qVariantValue<QColor>(lineAction->data()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::handleFontChange()
|
||||||
|
{
|
||||||
|
QFont font = fontCombo->currentFont();
|
||||||
|
font.setPointSize(fontSizeCombo->currentText().toInt());
|
||||||
|
font.setWeight(boldAction->isChecked() ? QFont::Bold : QFont::Normal);
|
||||||
|
font.setItalic(italicAction->isChecked());
|
||||||
|
font.setUnderline(underlineAction->isChecked());
|
||||||
|
|
||||||
|
scene->setFont(font);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::itemSelected(QGraphicsItem *item)
|
||||||
|
{
|
||||||
|
DiagramTextItem *textItem =
|
||||||
|
qgraphicsitem_cast<DiagramTextItem *>(item);
|
||||||
|
|
||||||
|
QFont font = textItem->font();
|
||||||
|
QColor color = textItem->defaultTextColor();
|
||||||
|
fontCombo->setCurrentFont(font);
|
||||||
|
fontSizeCombo->setEditText(QString().setNum(font.pointSize()));
|
||||||
|
boldAction->setChecked(font.weight() == QFont::Bold);
|
||||||
|
italicAction->setChecked(font.italic());
|
||||||
|
underlineAction->setChecked(font.underline());
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::about()
|
||||||
|
{
|
||||||
|
QMessageBox::question(this, tr("About SIE Code Generator"),
|
||||||
|
tr("TODO <b>:)</b>"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::addLibrariesButtons(QGridLayout *layout)
|
||||||
|
{
|
||||||
|
int i=1;
|
||||||
|
domElementsByName.clear(); buttonIdByName.clear();
|
||||||
|
QDomDocument customItems;
|
||||||
|
foreach(QString filepath, libraryList)
|
||||||
|
{
|
||||||
|
customItems = parseDocument(filepath);
|
||||||
|
for (QDomNode node = customItems.firstChild() ;
|
||||||
|
!node.isNull() ;
|
||||||
|
node = node.nextSibling())
|
||||||
|
{
|
||||||
|
QDomElement *customItem = new QDomElement(node.toElement());
|
||||||
|
if(customItem->tagName()=="CustomItem")
|
||||||
|
{
|
||||||
|
if(domElementsByName.contains(
|
||||||
|
customItem->attribute("BlockName")))
|
||||||
|
{
|
||||||
|
QMessageBox::warning(this,"Block name in use.",
|
||||||
|
"The library " + filepath +
|
||||||
|
" has one block called" +
|
||||||
|
customItem->attribute("BlockName") +
|
||||||
|
" that is already in use. Only the "
|
||||||
|
" first Block loaded can be used, this"
|
||||||
|
" library will be ignored.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
domElementsByName.insert(customItem->attribute("BlockName"),
|
||||||
|
customItem);
|
||||||
|
buttonIdByName.insert(customItem->attribute("BlockName"),i-1);
|
||||||
|
|
||||||
|
scene->setDomElementsByName(domElementsByName);
|
||||||
|
scene->setButtonIdByName(buttonIdByName);
|
||||||
|
|
||||||
|
layout->addWidget(createCellWidget(
|
||||||
|
customItem->attribute("BlockName"),
|
||||||
|
domElementsByName.
|
||||||
|
value(customItem->attribute("BlockName"))),i/2,i&1);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void MainWindow::createToolBox()
|
||||||
|
{
|
||||||
|
if(buttonGroup!=0) delete(buttonGroup);
|
||||||
|
if(toolBox!=0) delete(toolBox);
|
||||||
|
buttonGroup = new QButtonGroup;
|
||||||
|
buttonGroup->setExclusive(false);
|
||||||
|
connect(buttonGroup, SIGNAL(buttonClicked(int)),
|
||||||
|
this, SLOT(buttonGroupClicked(int)));
|
||||||
|
|
||||||
|
QGridLayout *layout = new QGridLayout;
|
||||||
|
|
||||||
|
addLibrariesButtons(layout);
|
||||||
|
|
||||||
|
QToolButton *textButton = new QToolButton;
|
||||||
|
textButton->setCheckable(true);
|
||||||
|
buttonGroup->addButton(textButton, InsertTextButton);
|
||||||
|
textButton->setIcon(QIcon(QPixmap(":/images/textpointer.png")
|
||||||
|
.scaled(30, 30)));
|
||||||
|
textButton->setIconSize(QSize(50, 50));
|
||||||
|
QGridLayout *textLayout = new QGridLayout;
|
||||||
|
textLayout->addWidget(textButton, 0, 0, Qt::AlignHCenter);
|
||||||
|
textLayout->addWidget(new QLabel(tr("Text")), 1, 0, Qt::AlignCenter);
|
||||||
|
QWidget *textWidget = new QWidget;
|
||||||
|
textWidget->setLayout(textLayout);
|
||||||
|
layout->addWidget(textWidget, 0, 0);
|
||||||
|
|
||||||
|
layout->setRowStretch(3, 10);
|
||||||
|
layout->setColumnStretch(2, 10);
|
||||||
|
|
||||||
|
QWidget *itemWidget = new QWidget;
|
||||||
|
itemWidget->setLayout(layout);
|
||||||
|
|
||||||
|
toolBox = new QToolBox;
|
||||||
|
toolBox->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Ignored));
|
||||||
|
toolBox->setMinimumWidth(itemWidget->sizeHint().width());
|
||||||
|
toolBox->addItem(itemWidget, tr("Basic Flowchart Shapes"));
|
||||||
|
//toolBox->addItem(backgroundWidget, tr("Backgrounds"));
|
||||||
|
|
||||||
|
//Add tool box to window
|
||||||
|
QHBoxLayout *newLayout = new QHBoxLayout;
|
||||||
|
newLayout->addWidget(toolBox);
|
||||||
|
view = new QGraphicsView(scene);
|
||||||
|
newLayout->addWidget(view);
|
||||||
|
|
||||||
|
QWidget *widget = new QWidget;
|
||||||
|
widget->setLayout(newLayout);
|
||||||
|
|
||||||
|
setCentralWidget(widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::createActions()
|
||||||
|
{
|
||||||
|
toFrontAction = new QAction(QIcon(":/images/bringtofront.png"),
|
||||||
|
tr("Bring to &Front"), this);
|
||||||
|
toFrontAction->setShortcut(tr("Ctrl+F"));
|
||||||
|
toFrontAction->setStatusTip(tr("Bring item to front"));
|
||||||
|
connect(toFrontAction, SIGNAL(triggered()),
|
||||||
|
this, SLOT(bringToFront()));
|
||||||
|
|
||||||
|
sendBackAction = new QAction(QIcon(":/images/sendtoback.png"),
|
||||||
|
tr("Send to &Back"), this);
|
||||||
|
sendBackAction->setShortcut(tr("Ctrl+B"));
|
||||||
|
sendBackAction->setStatusTip(tr("Send item to back"));
|
||||||
|
connect(sendBackAction, SIGNAL(triggered()),
|
||||||
|
this, SLOT(sendToBack()));
|
||||||
|
|
||||||
|
deleteAction = new QAction(QIcon(":/images/delete.png"),
|
||||||
|
tr("&Delete"), this);
|
||||||
|
deleteAction->setShortcut(tr("Ctrl+Delete"));
|
||||||
|
deleteAction->setStatusTip(tr("Delete item from diagram"));
|
||||||
|
connect(deleteAction, SIGNAL(triggered()),
|
||||||
|
this, SLOT(deleteItem()));
|
||||||
|
|
||||||
|
|
||||||
|
newAction = new QAction(QIcon(":/images/new.png"),tr("&New"),this);
|
||||||
|
newAction->setShortcuts(QKeySequence::New);
|
||||||
|
newAction->setStatusTip("New diagram");
|
||||||
|
connect(newAction,SIGNAL(triggered()),this,SLOT(newDiagram()));
|
||||||
|
|
||||||
|
saveAction = new QAction(QIcon(":/images/save.png"),tr("&Save"),this);
|
||||||
|
saveAction->setShortcuts(QKeySequence::Save);
|
||||||
|
saveAction->setStatusTip("Save current diagram");
|
||||||
|
connect(saveAction,SIGNAL(triggered()),this,SLOT(saveDiagram()));
|
||||||
|
|
||||||
|
saveAsAction = new QAction(QIcon(":/images/save_as.png"),
|
||||||
|
tr("Save &As..."),this);
|
||||||
|
saveAsAction->setShortcuts(QKeySequence::SaveAs);
|
||||||
|
saveAsAction->setStatusTip("Save current diagram with another name");
|
||||||
|
connect(saveAsAction,SIGNAL(triggered()),this,SLOT(saveAsDiagram()));
|
||||||
|
|
||||||
|
openAction = new QAction(QIcon(":/images/open.png"),tr("&Open"),this);
|
||||||
|
openAction->setShortcuts(QKeySequence::Open);
|
||||||
|
openAction->setStatusTip("Open diagram");
|
||||||
|
connect(openAction,SIGNAL(triggered()),this,SLOT(openDiagram()));
|
||||||
|
|
||||||
|
exportImgAction = new QAction(tr("&Export to ..."),this);
|
||||||
|
exportImgAction->setStatusTip("Export current diagram to picture");
|
||||||
|
connect(exportImgAction,SIGNAL(triggered()),this,SLOT(exportDiagram()));
|
||||||
|
|
||||||
|
exitAction = new QAction(tr("E&xit"), this);
|
||||||
|
exitAction->setShortcuts(QKeySequence::Quit);
|
||||||
|
exitAction->setStatusTip(tr("Quit diagram editor"));
|
||||||
|
connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
|
||||||
|
|
||||||
|
boldAction = new QAction(QIcon(":/images/bold.png"),tr("Bold"), this);
|
||||||
|
boldAction->setCheckable(true);
|
||||||
|
boldAction->setShortcut(tr("Ctrl+B"));
|
||||||
|
connect(boldAction, SIGNAL(triggered()),
|
||||||
|
this, SLOT(handleFontChange()));
|
||||||
|
|
||||||
|
italicAction = new QAction(QIcon(":/images/italic.png"),
|
||||||
|
tr("Italic"), this);
|
||||||
|
italicAction->setCheckable(true);
|
||||||
|
italicAction->setShortcut(tr("Ctrl+I"));
|
||||||
|
connect(italicAction, SIGNAL(triggered()),
|
||||||
|
this, SLOT(handleFontChange()));
|
||||||
|
|
||||||
|
underlineAction = new QAction(QIcon(":/images/underline.png"),
|
||||||
|
tr("Underline"), this);
|
||||||
|
underlineAction->setCheckable(true);
|
||||||
|
underlineAction->setShortcut(tr("Ctrl+U"));
|
||||||
|
connect(underlineAction, SIGNAL(triggered()),
|
||||||
|
this, SLOT(handleFontChange()));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
libraryAction = new QAction(tr("&Library..."),this);
|
||||||
|
connect(libraryAction, SIGNAL(triggered()),
|
||||||
|
this, SLOT(libraryForm()));
|
||||||
|
|
||||||
|
optionsAction = new QAction(tr("&Options"),this);
|
||||||
|
optionsAction->setShortcuts(QKeySequence::Preferences);
|
||||||
|
connect(optionsAction, SIGNAL(triggered()),
|
||||||
|
this, SLOT(optionsForm()));
|
||||||
|
|
||||||
|
aboutAction = new QAction(tr("A&bout"), this);
|
||||||
|
aboutAction->setShortcut(tr("Ctrl+B"));
|
||||||
|
connect(aboutAction, SIGNAL(triggered()),
|
||||||
|
this, SLOT(about()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::createMenus()
|
||||||
|
{
|
||||||
|
fileMenu = menuBar()->addMenu(tr("&File"));
|
||||||
|
fileMenu->addAction(newAction);
|
||||||
|
fileMenu->addAction(openAction);
|
||||||
|
fileMenu->addSeparator();
|
||||||
|
fileMenu->addAction(saveAction);
|
||||||
|
fileMenu->addAction(saveAsAction);
|
||||||
|
fileMenu->addAction(exportImgAction);
|
||||||
|
fileMenu->addSeparator();
|
||||||
|
fileMenu->addAction(exitAction);
|
||||||
|
|
||||||
|
itemMenu = menuBar()->addMenu(tr("&Item"));
|
||||||
|
itemMenu->addAction(deleteAction);
|
||||||
|
itemMenu->addSeparator();
|
||||||
|
itemMenu->addAction(toFrontAction);
|
||||||
|
itemMenu->addAction(sendBackAction);
|
||||||
|
|
||||||
|
preferencesMenu= menuBar()->addMenu(tr("&Preferences"));
|
||||||
|
preferencesMenu->addAction(libraryAction);
|
||||||
|
preferencesMenu->addAction(optionsAction);
|
||||||
|
|
||||||
|
aboutMenu = menuBar()->addMenu(tr("&Help"));
|
||||||
|
aboutMenu->addAction(aboutAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::createToolbars()
|
||||||
|
{
|
||||||
|
fileToolBar = addToolBar(tr("File"));
|
||||||
|
fileToolBar->addAction(newAction);
|
||||||
|
fileToolBar->addAction(openAction);
|
||||||
|
fileToolBar->addAction(saveAction);
|
||||||
|
|
||||||
|
editToolBar = addToolBar(tr("Edit"));
|
||||||
|
editToolBar->addAction(deleteAction);
|
||||||
|
editToolBar->addAction(toFrontAction);
|
||||||
|
editToolBar->addAction(sendBackAction);
|
||||||
|
|
||||||
|
fontCombo = new QFontComboBox();
|
||||||
|
fontSizeCombo = new QComboBox();
|
||||||
|
connect(fontCombo, SIGNAL(currentFontChanged(QFont)),
|
||||||
|
this, SLOT(currentFontChanged(QFont)));
|
||||||
|
|
||||||
|
fontSizeCombo = new QComboBox;
|
||||||
|
fontSizeCombo->setEditable(true);
|
||||||
|
for (int i = 8; i < 30; i = i + 2)
|
||||||
|
fontSizeCombo->addItem(QString().setNum(i));
|
||||||
|
QIntValidator *validator = new QIntValidator(2, 64, this);
|
||||||
|
fontSizeCombo->setValidator(validator);
|
||||||
|
connect(fontSizeCombo, SIGNAL(currentIndexChanged(QString)),
|
||||||
|
this, SLOT(fontSizeChanged(QString)));
|
||||||
|
|
||||||
|
fontColorToolButton = new QToolButton;
|
||||||
|
fontColorToolButton->setPopupMode(QToolButton::MenuButtonPopup);
|
||||||
|
fontColorToolButton->setMenu(createColorMenu(SLOT(textColorChanged()),
|
||||||
|
Qt::black));
|
||||||
|
textAction = fontColorToolButton->menu()->defaultAction();
|
||||||
|
fontColorToolButton->setIcon(createColorToolButtonIcon(
|
||||||
|
":/images/textpointer.png", Qt::black));
|
||||||
|
fontColorToolButton->setAutoFillBackground(true);
|
||||||
|
connect(fontColorToolButton, SIGNAL(clicked()),
|
||||||
|
this, SLOT(textButtonTriggered()));
|
||||||
|
|
||||||
|
fillColorToolButton = new QToolButton;
|
||||||
|
fillColorToolButton->setPopupMode(QToolButton::MenuButtonPopup);
|
||||||
|
fillColorToolButton->setMenu(createColorMenu(SLOT(itemColorChanged()),
|
||||||
|
Qt::white));
|
||||||
|
fillAction = fillColorToolButton->menu()->defaultAction();
|
||||||
|
fillColorToolButton->setIcon(createColorToolButtonIcon(
|
||||||
|
":/images/floodfill.png", Qt::white));
|
||||||
|
connect(fillColorToolButton, SIGNAL(clicked()),
|
||||||
|
this, SLOT(fillButtonTriggered()));
|
||||||
|
|
||||||
|
lineColorToolButton = new QToolButton;
|
||||||
|
lineColorToolButton->setPopupMode(QToolButton::MenuButtonPopup);
|
||||||
|
lineColorToolButton->setMenu(createColorMenu(SLOT(lineColorChanged()),
|
||||||
|
Qt::black));
|
||||||
|
lineAction = lineColorToolButton->menu()->defaultAction();
|
||||||
|
lineColorToolButton->setIcon(createColorToolButtonIcon(
|
||||||
|
":/images/linecolor.png", Qt::black));
|
||||||
|
connect(lineColorToolButton, SIGNAL(clicked()),
|
||||||
|
this, SLOT(lineButtonTriggered()));
|
||||||
|
|
||||||
|
textToolBar = addToolBar(tr("Font"));
|
||||||
|
textToolBar->addWidget(fontCombo);
|
||||||
|
textToolBar->addWidget(fontSizeCombo);
|
||||||
|
textToolBar->addAction(boldAction);
|
||||||
|
textToolBar->addAction(italicAction);
|
||||||
|
textToolBar->addAction(underlineAction);
|
||||||
|
|
||||||
|
colorToolBar = addToolBar(tr("Color"));
|
||||||
|
colorToolBar->addWidget(fontColorToolButton);
|
||||||
|
colorToolBar->addWidget(fillColorToolButton);
|
||||||
|
colorToolBar->addWidget(lineColorToolButton);
|
||||||
|
|
||||||
|
QToolButton *pointerButton = new QToolButton;
|
||||||
|
pointerButton->setCheckable(true);
|
||||||
|
pointerButton->setChecked(true);
|
||||||
|
pointerButton->setIcon(QIcon(":/images/pointer.png"));
|
||||||
|
QToolButton *linePointerButton = new QToolButton;
|
||||||
|
linePointerButton->setCheckable(true);
|
||||||
|
linePointerButton->setIcon(QIcon(":/images/linepointer.png"));
|
||||||
|
|
||||||
|
pointerTypeGroup = new QButtonGroup;
|
||||||
|
pointerTypeGroup->addButton(pointerButton, int(DiagramScene::MoveItem));
|
||||||
|
pointerTypeGroup->addButton(linePointerButton,
|
||||||
|
int(DiagramScene::InsertLine));
|
||||||
|
connect(pointerTypeGroup, SIGNAL(buttonClicked(int)),
|
||||||
|
this, SLOT(pointerGroupClicked(int)));
|
||||||
|
|
||||||
|
sceneScaleCombo = new QComboBox;
|
||||||
|
QStringList scales;
|
||||||
|
scales << tr("50%") << tr("75%") << tr("100%") << tr("125%") << tr("150%");
|
||||||
|
sceneScaleCombo->addItems(scales);
|
||||||
|
sceneScaleCombo->setCurrentIndex(2);
|
||||||
|
connect(sceneScaleCombo, SIGNAL(currentIndexChanged(QString)),
|
||||||
|
this, SLOT(sceneScaleChanged(QString)));
|
||||||
|
|
||||||
|
pointerToolbar = addToolBar(tr("Pointer type"));
|
||||||
|
pointerToolbar->addWidget(pointerButton);
|
||||||
|
pointerToolbar->addWidget(linePointerButton);
|
||||||
|
pointerToolbar->addWidget(sceneScaleCombo);
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget *MainWindow::createCellWidget(QString text, QDomElement *customItem)
|
||||||
|
{
|
||||||
|
DiagramItem item(itemMenu,text,customItem);
|
||||||
|
QIcon icon(item.image());
|
||||||
|
|
||||||
|
QToolButton *button = new QToolButton;
|
||||||
|
button->setText(text);
|
||||||
|
button->setIcon(icon);
|
||||||
|
button->setIconSize(QSize(50, 50));
|
||||||
|
button->setCheckable(true);
|
||||||
|
buttonGroup->addButton(button, buttonIdByName.value(text));
|
||||||
|
|
||||||
|
QGridLayout *layout = new QGridLayout;
|
||||||
|
layout->addWidget(button, 0, 0, Qt::AlignHCenter);
|
||||||
|
layout->addWidget(new QLabel(text), 1, 0, Qt::AlignCenter);
|
||||||
|
|
||||||
|
QWidget *widget = new QWidget;
|
||||||
|
widget->setLayout(layout);
|
||||||
|
|
||||||
|
return widget;
|
||||||
|
}
|
||||||
|
|
||||||
|
QMenu *MainWindow::createColorMenu(const char *slot, QColor defaultColor)
|
||||||
|
{
|
||||||
|
QList<QColor> colors;
|
||||||
|
colors << Qt::black << Qt::white << Qt::magenta
|
||||||
|
<< Qt::cyan << Qt::red << Qt::blue << Qt::yellow << Qt::green
|
||||||
|
<< Qt::darkMagenta << Qt::darkCyan << Qt::darkRed << Qt::darkBlue
|
||||||
|
<< Qt::darkYellow << Qt::darkGreen << Qt::darkGray;
|
||||||
|
|
||||||
|
QStringList names;
|
||||||
|
names << tr("Black") << tr("White") << tr("Magenta") << tr("Cyan")
|
||||||
|
<< tr("Red") << tr("Blue") << tr("Yellow") << tr("Green")
|
||||||
|
<< tr("Dark Magenta") << tr("Dark Cyan") << tr("Dark Red")
|
||||||
|
<< tr("Dark Blue") << tr("Dark Yellow") << tr("Dark Green")
|
||||||
|
<< tr("Dark Gray") ;
|
||||||
|
|
||||||
|
QMenu *colorMenu = new QMenu;
|
||||||
|
for (int i = 0; i < colors.count(); ++i) {
|
||||||
|
QAction *action = new QAction(names.at(i), this);
|
||||||
|
action->setData(colors.at(i));
|
||||||
|
action->setIcon(createColorIcon(colors.at(i)));
|
||||||
|
connect(action, SIGNAL(triggered()),
|
||||||
|
this, slot);
|
||||||
|
colorMenu->addAction(action);
|
||||||
|
if (colors.at(i) == defaultColor) {
|
||||||
|
colorMenu->setDefaultAction(action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return colorMenu;
|
||||||
|
}
|
||||||
|
|
||||||
|
QIcon MainWindow::createColorToolButtonIcon(const QString &imageFile,
|
||||||
|
QColor color)
|
||||||
|
{
|
||||||
|
QPixmap pixmap(50, 80);
|
||||||
|
pixmap.fill(Qt::transparent);
|
||||||
|
QPainter painter(&pixmap);
|
||||||
|
QPixmap image(imageFile);
|
||||||
|
QRect target(0, 0, 50, 60);
|
||||||
|
QRect source(0, 0, 42, 42);
|
||||||
|
painter.fillRect(QRect(0, 60, 50, 80), color);
|
||||||
|
painter.drawPixmap(target, image, source);
|
||||||
|
|
||||||
|
return QIcon(pixmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
QIcon MainWindow::createColorIcon(QColor color)
|
||||||
|
{
|
||||||
|
QPixmap pixmap(20, 20);
|
||||||
|
QPainter painter(&pixmap);
|
||||||
|
painter.setPen(Qt::NoPen);
|
||||||
|
painter.fillRect(QRect(0, 0, 20, 20), color);
|
||||||
|
|
||||||
|
return QIcon(pixmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
int MainWindow::newDiagram(QString filePath)
|
||||||
|
{
|
||||||
|
saveIfNeeded();
|
||||||
|
scene->cleanScene();
|
||||||
|
libraryList.clear(); //or set defaults
|
||||||
|
domElementsByName.clear(); //or set defaults
|
||||||
|
buttonIdByName.clear();//or set defaults
|
||||||
|
scene->setLibList(libraryList);
|
||||||
|
updateLibraries();
|
||||||
|
myFilePath="";
|
||||||
|
|
||||||
|
if(filePath=="")
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
myFilePath=filePath;
|
||||||
|
if(!scene->fromXmlFormat(parseDocument(myFilePath)))
|
||||||
|
newDiagram();
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDomDocument MainWindow::parseDocument(QString filePath)
|
||||||
|
{
|
||||||
|
QDomDocument document;
|
||||||
|
QFile file(filePath);
|
||||||
|
if(file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
|
{
|
||||||
|
bool parsing=document.setContent(&file);
|
||||||
|
file.close();
|
||||||
|
if(!parsing)
|
||||||
|
{
|
||||||
|
QMessageBox::warning(this,"Operation failed","Failed to parse file, "
|
||||||
|
"wrong format or encoding.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
QMessageBox::critical(this,"Error","Could not open file for read.");
|
||||||
|
|
||||||
|
return document;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int MainWindow::saveIfNeeded()
|
||||||
|
{
|
||||||
|
if(myFilePath!="" || scene->items().count()>0)
|
||||||
|
{}//TODO save opened or modified diagram
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int MainWindow::openDiagram()
|
||||||
|
{
|
||||||
|
QString
|
||||||
|
filePath = QFileDialog::getOpenFileName(this,"Open",
|
||||||
|
currentDir(),"Diagram for SIE code generator (*.sie)");
|
||||||
|
|
||||||
|
if(filePath.isEmpty())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if(!QFileInfo(filePath).isReadable())
|
||||||
|
{
|
||||||
|
QMessageBox::critical(this,"Error","File is not readable "
|
||||||
|
" or not exists.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
newDiagram(filePath);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int MainWindow::saveDiagram()
|
||||||
|
{
|
||||||
|
if(myFilePath=="")
|
||||||
|
{
|
||||||
|
saveAsDiagram();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if(!QFileInfo(myFilePath).isWritable() && QFileInfo(myFilePath).exists())
|
||||||
|
{
|
||||||
|
QMessageBox::critical(this,"Error","File is not writable.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
QFile file(myFilePath);
|
||||||
|
if(file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||||
|
{
|
||||||
|
scene->setLibList(libraryList);
|
||||||
|
QDomDocument document = scene->toXmlFormat();
|
||||||
|
QTextStream out(&file);
|
||||||
|
out.setCodec("UTF-8");
|
||||||
|
out << document.toString(4);
|
||||||
|
file.close();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
QMessageBox::critical(this,"Error","Could not open file for write.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int MainWindow::saveAsDiagram()
|
||||||
|
{
|
||||||
|
QString filePath = QFileDialog::getSaveFileName(this,"Save as...",
|
||||||
|
currentDir(),"Diagram for SIE code generator (*.sie)");
|
||||||
|
|
||||||
|
if(!filePath.isEmpty())
|
||||||
|
{
|
||||||
|
myFilePath = filePath;
|
||||||
|
saveDiagram();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int MainWindow::exportDiagram()
|
||||||
|
{
|
||||||
|
QString picturePath = QFileDialog::getSaveFileName(this,"Export",
|
||||||
|
currentDir(),"Portable Network Graphics (*.png)");
|
||||||
|
|
||||||
|
if(picturePath.isEmpty()) return 0;
|
||||||
|
|
||||||
|
if(!QFileInfo(picturePath).isWritable() && QFileInfo(picturePath).exists())
|
||||||
|
{
|
||||||
|
QMessageBox::critical(this,"Error","File is not writable.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
scene->setDawGrid(0);
|
||||||
|
QSize sizeScene= scene->sceneRect().size().toSize();
|
||||||
|
QImage img(sizeScene,QImage::Format_ARGB32_Premultiplied);
|
||||||
|
QPainter p(&img);
|
||||||
|
scene->render(&p,
|
||||||
|
scene->sceneRect(),
|
||||||
|
scene->itemsBoundingRect(),
|
||||||
|
Qt::KeepAspectRatio);
|
||||||
|
p.end();
|
||||||
|
img.save(picturePath, "png");
|
||||||
|
scene->setDawGrid(1); //TODO : set correct value
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int MainWindow::libraryForm()
|
||||||
|
{
|
||||||
|
if(!libDialog)
|
||||||
|
{
|
||||||
|
createLibraryDialog();
|
||||||
|
}
|
||||||
|
libDialog->setModal(1);
|
||||||
|
libUi->listLib->clear();
|
||||||
|
libUi->listLib->addItems(libraryList);
|
||||||
|
libDialog->setWindowTitle(tr("Library paths..."));
|
||||||
|
QStringList oldLibraryList=libraryList;
|
||||||
|
libDialog->exec();
|
||||||
|
|
||||||
|
if (libDialog->result() == QDialog::Rejected)
|
||||||
|
libraryList = oldLibraryList;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
scene->setLibList(libraryList);
|
||||||
|
updateLibraries();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::createLibraryDialog()
|
||||||
|
{
|
||||||
|
libDialog = new QDialog(this);
|
||||||
|
libUi = new Ui_libraryDialog;
|
||||||
|
libUi->setupUi(libDialog);
|
||||||
|
|
||||||
|
connect(libUi->addLib,SIGNAL(clicked()),this,SLOT(addLibPath()));
|
||||||
|
connect(libUi->delLib,SIGNAL(clicked()),this,SLOT(delLibPath()));
|
||||||
|
connect(libUi->editLib,SIGNAL(clicked()),this,SLOT(editLibPath()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::addLibPath()
|
||||||
|
{
|
||||||
|
QString
|
||||||
|
filePath = QFileDialog::getOpenFileName(this,"Open",
|
||||||
|
currentDir(),"Custom block for SIE code generator (*.die)");
|
||||||
|
|
||||||
|
if(filePath.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(!QFileInfo(filePath).isReadable())
|
||||||
|
{
|
||||||
|
QMessageBox::critical(this,"Error","File is not readable "
|
||||||
|
" or not exists.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(libUi->listLib->findItems(filePath,Qt::MatchExactly).count()==0)
|
||||||
|
{
|
||||||
|
QDir myCurrentDir = this->currentDir();
|
||||||
|
QString relativePath=myCurrentDir.relativeFilePath(filePath);
|
||||||
|
libraryList.append(relativePath);
|
||||||
|
libUi->listLib->addItem(relativePath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
QMessageBox::information(this,"Information","Library already exist.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::delLibPath()
|
||||||
|
{
|
||||||
|
QList<QListWidgetItem *> selected = libUi->listLib->selectedItems();
|
||||||
|
if(selected.count()>0)
|
||||||
|
{
|
||||||
|
libraryList.removeOne(selected.at(0)->text());
|
||||||
|
libUi->listLib->clear();
|
||||||
|
libUi->listLib->addItems(libraryList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::editLibPath()
|
||||||
|
{
|
||||||
|
QList<QListWidgetItem *> selected = libUi->listLib->selectedItems();
|
||||||
|
if(selected.count()>0)
|
||||||
|
{
|
||||||
|
callexternapp("block_editor/blockeditor",selected.at(0)->text());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int MainWindow::updateLibraries()
|
||||||
|
{
|
||||||
|
libraryList=scene->getLibList();
|
||||||
|
createToolBox();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int MainWindow::optionsForm()
|
||||||
|
{
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString MainWindow::callexternapp(QString xexecFile, QString xexecParm)
|
||||||
|
{
|
||||||
|
QEventLoop cxaw;
|
||||||
|
callexternappT cxat;
|
||||||
|
connect(&cxat, SIGNAL(finished()), &cxaw, SLOT(quit()));
|
||||||
|
cxat.execFile = xexecFile;
|
||||||
|
cxat.execParm = xexecParm;
|
||||||
|
cxat.start();
|
||||||
|
cxaw.exec();
|
||||||
|
return cxat.retnValu;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
220
Software/sie_cg/mainwindow.h
Normal file
@ -0,0 +1,220 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
** All rights reserved.
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
|
**
|
||||||
|
** $QT_BEGIN_LICENSE:LGPL$
|
||||||
|
** Commercial Usage
|
||||||
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||||
|
** accordance with the Qt Commercial License Agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Nokia gives you certain additional
|
||||||
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3.0 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU General Public License version 3.0 requirements will be
|
||||||
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||||
|
**
|
||||||
|
** If you have questions regarding the use of this file, please contact
|
||||||
|
** Nokia at qt-info@nokia.com.
|
||||||
|
** $QT_END_LICENSE$
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef MAINWINDOW_H
|
||||||
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QtXml>
|
||||||
|
#include <QtGui>
|
||||||
|
#include <QHash>
|
||||||
|
|
||||||
|
#include "diagramitem.h"
|
||||||
|
#include "diagramscene.h"
|
||||||
|
#include "diagramtextitem.h"
|
||||||
|
#include "lineitem.h"
|
||||||
|
#include "arrow.h"
|
||||||
|
#include "ui_librarydialog.h"
|
||||||
|
|
||||||
|
class DiagramScene;
|
||||||
|
class Ui_libraryDialog;
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QAction;
|
||||||
|
class QToolBox;
|
||||||
|
class QSpinBox;
|
||||||
|
class QComboBox;
|
||||||
|
class QFontComboBox;
|
||||||
|
class QButtonGroup;
|
||||||
|
class QLineEdit;
|
||||||
|
class QGraphicsTextItem;
|
||||||
|
class QFont;
|
||||||
|
class QToolButton;
|
||||||
|
class QAbstractButton;
|
||||||
|
class QGraphicsView;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
class MainWindow : public QMainWindow
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
MainWindow();
|
||||||
|
QString filePath() const
|
||||||
|
{ return myFilePath;}
|
||||||
|
QString currentDir() const
|
||||||
|
{ return QDir::currentPath();}
|
||||||
|
|
||||||
|
int updateLibraries();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void backgroundButtonGroupClicked(QAbstractButton *button);
|
||||||
|
void buttonGroupClicked(int id);
|
||||||
|
void deleteItem();
|
||||||
|
void pointerGroupClicked(int id);
|
||||||
|
void bringToFront();
|
||||||
|
void sendToBack();
|
||||||
|
void itemInserted(DiagramItem *item);
|
||||||
|
void textInserted(QGraphicsTextItem *item);
|
||||||
|
void currentFontChanged(const QFont &font);
|
||||||
|
void fontSizeChanged(const QString &size);
|
||||||
|
void sceneScaleChanged(const QString &scale);
|
||||||
|
void textColorChanged();
|
||||||
|
void itemColorChanged();
|
||||||
|
void lineColorChanged();
|
||||||
|
void textButtonTriggered();
|
||||||
|
void fillButtonTriggered();
|
||||||
|
void lineButtonTriggered();
|
||||||
|
void handleFontChange();
|
||||||
|
void itemSelected(QGraphicsItem *item);
|
||||||
|
void about();
|
||||||
|
|
||||||
|
int newDiagram(QString pathFile="");
|
||||||
|
int openDiagram();
|
||||||
|
int saveDiagram();
|
||||||
|
int saveAsDiagram();
|
||||||
|
int exportDiagram();
|
||||||
|
|
||||||
|
int libraryForm();
|
||||||
|
void addLibPath();
|
||||||
|
void delLibPath();
|
||||||
|
void editLibPath();
|
||||||
|
|
||||||
|
int optionsForm();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
int saveIfNeeded();
|
||||||
|
void addLibrariesButtons(QGridLayout *layout);
|
||||||
|
QDomDocument parseDocument(QString filePath);
|
||||||
|
void createLibraryDialog();
|
||||||
|
void createToolBox();
|
||||||
|
void createActions();
|
||||||
|
void createMenus();
|
||||||
|
void createToolbars();
|
||||||
|
void sendTo(bool value);
|
||||||
|
QWidget *createBackgroundCellWidget(const QString &text,
|
||||||
|
const QString &image);
|
||||||
|
QWidget *createCellWidget(QString text, QDomElement *customItem);
|
||||||
|
|
||||||
|
QMenu *createColorMenu(const char *slot, QColor defaultColor);
|
||||||
|
QIcon createColorToolButtonIcon(const QString &image, QColor color);
|
||||||
|
QIcon createColorIcon(QColor color);
|
||||||
|
|
||||||
|
DiagramScene *scene;
|
||||||
|
QGraphicsView *view;
|
||||||
|
|
||||||
|
QAction *newAction;
|
||||||
|
QAction *saveAction;
|
||||||
|
QAction *saveAsAction;
|
||||||
|
QAction *openAction;
|
||||||
|
QAction *exportImgAction;
|
||||||
|
|
||||||
|
QAction *exitAction;
|
||||||
|
QAction *addAction;
|
||||||
|
QAction *deleteAction;
|
||||||
|
|
||||||
|
QAction *libraryAction;
|
||||||
|
QAction *optionsAction;
|
||||||
|
|
||||||
|
QAction *toFrontAction;
|
||||||
|
QAction *sendBackAction;
|
||||||
|
QAction *aboutAction;
|
||||||
|
|
||||||
|
QMenu *fileMenu;
|
||||||
|
QMenu *itemMenu;
|
||||||
|
QMenu *preferencesMenu;
|
||||||
|
QMenu *aboutMenu;
|
||||||
|
|
||||||
|
QToolBar *fileToolBar;
|
||||||
|
QToolBar *textToolBar;
|
||||||
|
QToolBar *editToolBar;
|
||||||
|
QToolBar *colorToolBar;
|
||||||
|
QToolBar *pointerToolbar;
|
||||||
|
|
||||||
|
QComboBox *sceneScaleCombo;
|
||||||
|
QComboBox *itemColorCombo;
|
||||||
|
QComboBox *textColorCombo;
|
||||||
|
QComboBox *fontSizeCombo;
|
||||||
|
QFontComboBox *fontCombo;
|
||||||
|
|
||||||
|
QToolBox *toolBox;
|
||||||
|
QButtonGroup *buttonGroup;
|
||||||
|
QButtonGroup *pointerTypeGroup;
|
||||||
|
QButtonGroup *backgroundButtonGroup;
|
||||||
|
QToolButton *fontColorToolButton;
|
||||||
|
QToolButton *fillColorToolButton;
|
||||||
|
QToolButton *lineColorToolButton;
|
||||||
|
QAction *boldAction;
|
||||||
|
QAction *underlineAction;
|
||||||
|
QAction *italicAction;
|
||||||
|
QAction *textAction;
|
||||||
|
QAction *fillAction;
|
||||||
|
QAction *lineAction;
|
||||||
|
QString myFilePath;
|
||||||
|
|
||||||
|
QDialog *libDialog;
|
||||||
|
Ui_libraryDialog *libUi;
|
||||||
|
QStringList libraryList;
|
||||||
|
QHash<QString , QDomElement*> domElementsByName;
|
||||||
|
QHash<QString , int> buttonIdByName;
|
||||||
|
static QString callexternapp(QString xexecFile, QString xexecParm);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class callexternappT : public QThread
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QString execFile;
|
||||||
|
QString execParm;
|
||||||
|
QString retnValu;
|
||||||
|
void run()
|
||||||
|
{
|
||||||
|
QProcess lnexternapp;
|
||||||
|
lnexternapp.start(QString("%1 %2").arg(execFile).arg(execParm));
|
||||||
|
lnexternapp.waitForFinished(-1);
|
||||||
|
retnValu = QString(lnexternapp.readAll());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
69
Software/sie_cg/moc_librarydialog.cpp
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
** Meta object code from reading C++ file 'librarydialog.h'
|
||||||
|
**
|
||||||
|
** Created: Wed Oct 20 10:39:37 2010
|
||||||
|
** by: The Qt Meta Object Compiler version 62 (Qt 4.6.2)
|
||||||
|
**
|
||||||
|
** WARNING! All changes made in this file will be lost!
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#include "librarydialog.h"
|
||||||
|
#if !defined(Q_MOC_OUTPUT_REVISION)
|
||||||
|
#error "The header file 'librarydialog.h' doesn't include <QObject>."
|
||||||
|
#elif Q_MOC_OUTPUT_REVISION != 62
|
||||||
|
#error "This file was generated using the moc from 4.6.2. It"
|
||||||
|
#error "cannot be used with the include files from this version of Qt."
|
||||||
|
#error "(The moc has changed too much.)"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
QT_BEGIN_MOC_NAMESPACE
|
||||||
|
static const uint qt_meta_data_libraryDialog[] = {
|
||||||
|
|
||||||
|
// content:
|
||||||
|
4, // revision
|
||||||
|
0, // classname
|
||||||
|
0, 0, // classinfo
|
||||||
|
0, 0, // methods
|
||||||
|
0, 0, // properties
|
||||||
|
0, 0, // enums/sets
|
||||||
|
0, 0, // constructors
|
||||||
|
0, // flags
|
||||||
|
0, // signalCount
|
||||||
|
|
||||||
|
0 // eod
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char qt_meta_stringdata_libraryDialog[] = {
|
||||||
|
"libraryDialog\0"
|
||||||
|
};
|
||||||
|
|
||||||
|
const QMetaObject libraryDialog::staticMetaObject = {
|
||||||
|
{ &QDialog::staticMetaObject, qt_meta_stringdata_libraryDialog,
|
||||||
|
qt_meta_data_libraryDialog, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef Q_NO_DATA_RELOCATION
|
||||||
|
const QMetaObject &libraryDialog::getStaticMetaObject() { return staticMetaObject; }
|
||||||
|
#endif //Q_NO_DATA_RELOCATION
|
||||||
|
|
||||||
|
const QMetaObject *libraryDialog::metaObject() const
|
||||||
|
{
|
||||||
|
return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *libraryDialog::qt_metacast(const char *_clname)
|
||||||
|
{
|
||||||
|
if (!_clname) return 0;
|
||||||
|
if (!strcmp(_clname, qt_meta_stringdata_libraryDialog))
|
||||||
|
return static_cast<void*>(const_cast< libraryDialog*>(this));
|
||||||
|
return QDialog::qt_metacast(_clname);
|
||||||
|
}
|
||||||
|
|
||||||
|
int libraryDialog::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
|
||||||
|
{
|
||||||
|
_id = QDialog::qt_metacall(_c, _id, _a);
|
||||||
|
if (_id < 0)
|
||||||
|
return _id;
|
||||||
|
return _id;
|
||||||
|
}
|
||||||
|
QT_END_MOC_NAMESPACE
|
BIN
Software/sie_cg/moc_librarydialog.o
Normal file
41
Software/sie_cg/test.sie
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<!--
|
||||||
|
File for SIE Code Generator.
|
||||||
|
**WARNING**If you are going to edit this file note that:
|
||||||
|
In order to segmentation faults prevention the load process
|
||||||
|
is started loading the libraries, then items and finally arrows.
|
||||||
|
Arrows depend of items, and items depend of libraries!!!!
|
||||||
|
-->
|
||||||
|
<Diagram>
|
||||||
|
<Libraries>
|
||||||
|
<Library Dir="block_editor/test_block1.die"/>
|
||||||
|
<Library Dir="block_editor/test_block2.die"/>
|
||||||
|
<Library Dir="block_editor/test_block3.die"/>
|
||||||
|
</Libraries>
|
||||||
|
<DiagramItems>
|
||||||
|
<DiagramItem x="2780" y="2540" z="500" type="Test Block 2" ID="0" color="#0000ff">
|
||||||
|
<diagramValues/>
|
||||||
|
</DiagramItem>
|
||||||
|
<DiagramItem x="2510" y="2440" z="500" type="Test Block 1" ID="1" color="#808080">
|
||||||
|
<diagramValues>
|
||||||
|
<diagramValue value="0.001" ID="1"/>
|
||||||
|
</diagramValues>
|
||||||
|
</DiagramItem>
|
||||||
|
<DiagramItem x="2230" y="2550" z="500" type="Test Block 3" ID="2" color="#ff0000">
|
||||||
|
<diagramValues/>
|
||||||
|
</DiagramItem>
|
||||||
|
</DiagramItems>
|
||||||
|
<Arrows>
|
||||||
|
<Arrow end-ID="1" end-Owner="0" start-x="140" start-y="0" start-Owner="1" ID="0" start-ID="3" end-x="-30" end-y="0" color="#808080">
|
||||||
|
<arrowCorners>
|
||||||
|
<arrowCorner x="2700" y="2440"/>
|
||||||
|
<arrowCorner x="2699.5" y="2539.5"/>
|
||||||
|
</arrowCorners>
|
||||||
|
</Arrow>
|
||||||
|
<Arrow end-ID="4" end-Owner="1" start-x="60" start-y="0" start-Owner="2" ID="1" start-ID="0" end-x="-120" end-y="0" color="#808080">
|
||||||
|
<arrowCorners>
|
||||||
|
<arrowCorner x="2340" y="2550"/>
|
||||||
|
<arrowCorner x="2340" y="2440"/>
|
||||||
|
</arrowCorners>
|
||||||
|
</Arrow>
|
||||||
|
</Arrows>
|
||||||
|
</Diagram>
|