diff --git a/Software/sie_cg/arrow.cpp b/Software/sie_cg/arrow.cpp new file mode 100644 index 0000000..fa4634a --- /dev/null +++ b/Software/sie_cg/arrow.cpp @@ -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 + +#include "arrow.h" +#include + +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; isetLine(QLineF(myCorners.at(i),myCorners.at(i+1))); + myLines.last()->setLine(QLineF(myCorners.last(),endPos)); + } + + //Drawing arrow selected + for(int i=0; isetPen(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 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); +} diff --git a/Software/sie_cg/arrow.h b/Software/sie_cg/arrow.h new file mode 100644 index 0000000..5f8e2aa --- /dev/null +++ b/Software/sie_cg/arrow.h @@ -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 +#include +#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) 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 myLines; + QList myCLines; + QList myCorners; + QGraphicsScene *myOwnerScene; + qreal arrowSize; + bool moving; + QPointF previousPos; +}; + +#endif diff --git a/Software/sie_cg/block_editor/arrow.cpp b/Software/sie_cg/block_editor/arrow.cpp new file mode 100644 index 0000000..edfaef3 --- /dev/null +++ b/Software/sie_cg/block_editor/arrow.cpp @@ -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 + +#include "arrow.h" +#include "lineitem.h" +#include + +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; isetLine(QLineF(myCorners.at(i),myCorners.at(i+1))); + myLines.last()->setLine(QLineF(myCorners.last(),endPos)); + } + + //Drawing arrow selected + for(int i=0; isetPen(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); +} diff --git a/Software/sie_cg/block_editor/arrow.h b/Software/sie_cg/block_editor/arrow.h new file mode 100644 index 0000000..1689157 --- /dev/null +++ b/Software/sie_cg/block_editor/arrow.h @@ -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 +#include +#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 myLines; + QList myCLines; + lineItem *SECLine; + QPointF startPoint; + QPointF endPoint; + QList myCorners; + QGraphicsScene *myOwnerScene; + qreal arrowSize; + bool moving; + QPointF previousPos; +}; + +#endif diff --git a/Software/sie_cg/block_editor/diagramitem.o b/Software/sie_cg/block_editor/diagramitem.o new file mode 100644 index 0000000..cb4c736 Binary files /dev/null and b/Software/sie_cg/block_editor/diagramitem.o differ diff --git a/Software/sie_cg/block_editor/diagramscene.cpp b/Software/sie_cg/block_editor/diagramscene.cpp new file mode 100644 index 0000000..94e2a6d --- /dev/null +++ b/Software/sie_cg/block_editor/diagramscene.cpp @@ -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 +#include +#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 Items; + QList Arrows; + foreach(QGraphicsItem *item, items()) + { + if(item->type() == DiagramTextItem::Type) + Items.append(qgraphicsitem_cast(item)); + else if(item->type() == Arrow::Type) + Arrows.append(qgraphicsitem_cast(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 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 Items; + foreach(QGraphicsItem *item, items()) + { + if(item->type() == DiagramTextItem::Type) + Items.append(qgraphicsitem_cast(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::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)); +} diff --git a/Software/sie_cg/block_editor/diagramscene.h b/Software/sie_cg/block_editor/diagramscene.h new file mode 100644 index 0000000..b93f814 --- /dev/null +++ b/Software/sie_cg/block_editor/diagramscene.h @@ -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 +#include +#include +#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 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 textItemsByID; +}; + +#endif diff --git a/Software/sie_cg/block_editor/diagramscene.pro b/Software/sie_cg/block_editor/diagramscene.pro new file mode 100644 index 0000000..222cc64 --- /dev/null +++ b/Software/sie_cg/block_editor/diagramscene.pro @@ -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 diff --git a/Software/sie_cg/block_editor/diagramscene.pro.user b/Software/sie_cg/block_editor/diagramscene.pro.user new file mode 100644 index 0000000..da71f5d --- /dev/null +++ b/Software/sie_cg/block_editor/diagramscene.pro.user @@ -0,0 +1,245 @@ + + + + RunConfiguration0-BaseEnvironmentBase + 2 + + + RunConfiguration0-CommandLineArguments + + + + RunConfiguration0-ProFile + diagramscene.pro + + + RunConfiguration0-RunConfiguration.name + diagramscene + + + RunConfiguration0-UseDyldImageSuffix + false + + + RunConfiguration0-UseTerminal + false + + + RunConfiguration0-UserEnvironmentChanges + + + + RunConfiguration0-UserSetName + false + + + RunConfiguration0-UserSetWorkingDirectory + false + + + RunConfiguration0-UserWorkingDirectory + + + + RunConfiguration0-type + Qt4ProjectManager.Qt4RunConfiguration + + + activeRunConfiguration + 0 + + + activebuildconfiguration + Debug + + + buildConfiguration-Debug + + Debug + 0 + 0 + + 2 + + + + buildConfiguration-Release + + Release + 0 + + 0 + + + + buildconfiguration-Debug-buildstep0 + + Debug + + DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-MI4KrAyPP5,guid=5c5c5e6146195c74b6ad266d4cc07afd + DEFAULTS_PATH=/usr/share/gconf/gnome.default.path + DESKTOP_SESSION=gnome + DISPLAY=:0.0 + GDMSESSION=gnome + GDM_KEYBOARD_LAYOUT=es + GDM_LANG=en_US.utf8 + GNOME_DESKTOP_SESSION_ID=this-is-deprecated + GNOME_KEYRING_CONTROL=/tmp/keyring-CFAuJK + GNOME_KEYRING_PID=1516 + GTK_MODULES=canberra-gtk-module + HOME=/home/juan64bits + LANG=en_US.utf8 + LD_LIBRARY_PATH=/usr/lib/qtcreator + LOGNAME=juan64bits + MANDATORY_PATH=/usr/share/gconf/gnome.mandatory.path + ORBIT_SOCKETDIR=/tmp/orbit-juan64bits + PATH=/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games + PWD=/home/juan64bits + QTDIR=/usr/share/qt4 + SESSION_MANAGER=local/Maximus:@/tmp/.ICE-unix/1534,unix/Maximus:/tmp/.ICE-unix/1534 + SHELL=/bin/bash + SPEECHD_PORT=7560 + SSH_AGENT_PID=1570 + SSH_AUTH_SOCK=/tmp/keyring-CFAuJK/ssh + USER=juan64bits + USERNAME=juan64bits + XAUTHORITY=/var/run/gdm/auth-for-juan64bits-V4ry7M/database + XDG_CONFIG_DIRS=/etc/xdg/xdg-gnome:/etc/xdg + XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/ + XDG_SESSION_COOKIE=b9a7fbc4d869fc15bd6cdd474bcc9a28-1287682812.550485-1725059380 + + + /home/juan64bits/QT/diagramscene/block_editor/diagramscene.pro + -spec + linux-g++ + -r + CONFIG+=debug + + /usr/bin/qmake-qt4 + false + /home/juan64bits/QT/diagramscene/block_editor + + + + buildconfiguration-Debug-buildstep1 + + Debug + + DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-MI4KrAyPP5,guid=5c5c5e6146195c74b6ad266d4cc07afd + DEFAULTS_PATH=/usr/share/gconf/gnome.default.path + DESKTOP_SESSION=gnome + DISPLAY=:0.0 + GDMSESSION=gnome + GDM_KEYBOARD_LAYOUT=es + GDM_LANG=en_US.utf8 + GNOME_DESKTOP_SESSION_ID=this-is-deprecated + GNOME_KEYRING_CONTROL=/tmp/keyring-CFAuJK + GNOME_KEYRING_PID=1516 + GTK_MODULES=canberra-gtk-module + HOME=/home/juan64bits + LANG=en_US.utf8 + LD_LIBRARY_PATH=/usr/lib/qtcreator + LOGNAME=juan64bits + MANDATORY_PATH=/usr/share/gconf/gnome.mandatory.path + ORBIT_SOCKETDIR=/tmp/orbit-juan64bits + PATH=/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games + PWD=/home/juan64bits + QTDIR=/usr/share/qt4 + SESSION_MANAGER=local/Maximus:@/tmp/.ICE-unix/1534,unix/Maximus:/tmp/.ICE-unix/1534 + SHELL=/bin/bash + SPEECHD_PORT=7560 + SSH_AGENT_PID=1570 + SSH_AUTH_SOCK=/tmp/keyring-CFAuJK/ssh + USER=juan64bits + USERNAME=juan64bits + XAUTHORITY=/var/run/gdm/auth-for-juan64bits-V4ry7M/database + XDG_CONFIG_DIRS=/etc/xdg/xdg-gnome:/etc/xdg + XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/ + XDG_SESSION_COOKIE=b9a7fbc4d869fc15bd6cdd474bcc9a28-1287682812.550485-1725059380 + + false + + -w + + /usr/bin/make + true + /home/juan64bits/QT/diagramscene/block_editor + + + + buildconfiguration-Debug-cleanstep0 + + Debug + true + + clean + + + + + buildconfiguration-Release-buildstep0 + + Release + + + + buildconfiguration-Release-buildstep1 + + Release + + + + buildconfiguration-Release-cleanstep0 + + Release + + + + buildconfigurations + + Debug + Release + + + + buildstep0 + + + + + + + buildstep1 + + + + + + buildsteps + + trolltech.qt4projectmanager.qmake + trolltech.qt4projectmanager.make + + + + cleanstep0 + + + true + + + + cleansteps + + trolltech.qt4projectmanager.make + + + + defaultFileEncoding + System + + + project + + + diff --git a/Software/sie_cg/block_editor/diagramscene.qrc b/Software/sie_cg/block_editor/diagramscene.qrc new file mode 100644 index 0000000..374fc1e --- /dev/null +++ b/Software/sie_cg/block_editor/diagramscene.qrc @@ -0,0 +1,28 @@ + + + ../images/pointer.png + ../images/linepointer.png + ../images/textpointer.png + ../images/bold.png + ../images/italic.png + ../images/underline.png + ../images/floodfill.png + ../images/bringtofront.png + ../images/delete.png + ../images/sendtoback.png + ../images/linecolor.png + ../images/background1.png + ../images/background2.png + ../images/background3.png + ../images/background4.png + ../images/exit.png + ../images/new.png + ../images/no.png + ../images/open.png + ../images/save.png + ../images/save_as.png + ../images/yes.png + ../images/zoom_in.png + ../images/zoom_out.png + + diff --git a/Software/sie_cg/block_editor/diagramtextitem.cpp b/Software/sie_cg/block_editor/diagramtextitem.cpp new file mode 100644 index 0000000..ab59d92 --- /dev/null +++ b/Software/sie_cg/block_editor/diagramtextitem.cpp @@ -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 + +#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); +} + diff --git a/Software/sie_cg/block_editor/diagramtextitem.h b/Software/sie_cg/block_editor/diagramtextitem.h new file mode 100644 index 0000000..bda5886 --- /dev/null +++ b/Software/sie_cg/block_editor/diagramtextitem.h @@ -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 +#include +#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="", + 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 diff --git a/Software/sie_cg/block_editor/lineitem.cpp b/Software/sie_cg/block_editor/lineitem.cpp new file mode 100644 index 0000000..9893bcc --- /dev/null +++ b/Software/sie_cg/block_editor/lineitem.cpp @@ -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 + +#include "lineitem.h" +#include + +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); +} diff --git a/Software/sie_cg/block_editor/lineitem.h b/Software/sie_cg/block_editor/lineitem.h new file mode 100644 index 0000000..682cdab --- /dev/null +++ b/Software/sie_cg/block_editor/lineitem.h @@ -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 +#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 diff --git a/Software/sie_cg/block_editor/main.cpp b/Software/sie_cg/block_editor/main.cpp new file mode 100644 index 0000000..f407824 --- /dev/null +++ b/Software/sie_cg/block_editor/main.cpp @@ -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 + +#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(); +} diff --git a/Software/sie_cg/block_editor/mainwindow.cpp b/Software/sie_cg/block_editor/mainwindow.cpp new file mode 100644 index 0000000..86be657 --- /dev/null +++ b/Software/sie_cg/block_editor/mainwindow.cpp @@ -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 +#include + +#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(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(item)->itemIsMovable()) { + + qgraphicsitem_cast(item)->myOwner()->removeLine( + qgraphicsitem_cast(item)); + qgraphicsitem_cast(item)->myOwner()->updatePosition(); + scene->removeItem(item); + delete(item); + } + else if (item->type() == DiagramTextItem::Type) { + if(qgraphicsitem_cast(item)->styleIO()!=0xFFF) + { + scene->removeTextItem(qgraphicsitem_cast + (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 :)")); +} + +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 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; +} diff --git a/Software/sie_cg/block_editor/mainwindow.h b/Software/sie_cg/block_editor/mainwindow.h new file mode 100644 index 0000000..3728a0a --- /dev/null +++ b/Software/sie_cg/block_editor/mainwindow.h @@ -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 +#include +#include + +#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 diff --git a/Software/sie_cg/block_editor/test_block1.die b/Software/sie_cg/block_editor/test_block1.die new file mode 100644 index 0000000..7f7a8ff --- /dev/null +++ b/Software/sie_cg/block_editor/test_block1.die @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/Software/sie_cg/block_editor/test_block2.die b/Software/sie_cg/block_editor/test_block2.die new file mode 100644 index 0000000..b9c3df7 --- /dev/null +++ b/Software/sie_cg/block_editor/test_block2.die @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/Software/sie_cg/block_editor/test_block3.die b/Software/sie_cg/block_editor/test_block3.die new file mode 100644 index 0000000..870441d --- /dev/null +++ b/Software/sie_cg/block_editor/test_block3.die @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/Software/sie_cg/block_editor/test_block4.die b/Software/sie_cg/block_editor/test_block4.die new file mode 100644 index 0000000..2993401 --- /dev/null +++ b/Software/sie_cg/block_editor/test_block4.die @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/sie_cg/diagramitem.cpp b/Software/sie_cg/diagramitem.cpp new file mode 100644 index 0000000..3a81d4c --- /dev/null +++ b/Software/sie_cg/diagramitem.cpp @@ -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 + +#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 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); +} + diff --git a/Software/sie_cg/diagramitem.h b/Software/sie_cg/diagramitem.h new file mode 100644 index 0000000..cf98f1d --- /dev/null +++ b/Software/sie_cg/diagramitem.h @@ -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 +#include +#include +#include +#include + +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 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 arrows; + QList textItems; + QGraphicsScene *myOwnerScene; + DiagramTextItem *textItem; + QColor myColor; + QDomElement *myDomElement; +}; + +#endif diff --git a/Software/sie_cg/diagramscene.cpp b/Software/sie_cg/diagramscene.cpp new file mode 100644 index 0000000..82582fe --- /dev/null +++ b/Software/sie_cg/diagramscene.cpp @@ -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 +#include +#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(selectedItems().first()); + item->setColor(myLineColor); + update(); + } +} + +void DiagramScene::setTextColor(const QColor &color) +{ + myTextColor = color; + if (isItemChange(DiagramTextItem::Type)) { + DiagramTextItem *item = + qgraphicsitem_cast(selectedItems().first()); + item->setDefaultTextColor(myTextColor); + } +} + +void DiagramScene::setItemColor(const QColor &color) +{ + myItemColor = color; + if (isItemChange(DiagramItem::Type)) { + DiagramItem *item = + qgraphicsitem_cast(selectedItems().first()); + item->setColor(myItemColor); + } +} + +void DiagramScene::setFont(const QFont &font) +{ + myFont = font; + + if (isItemChange(DiagramTextItem::Type)) { + QGraphicsTextItem *item = + qgraphicsitem_cast(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 startItems = items(line->line().p1()); + if (startItems.count() && startItems.first() == line) + startItems.removeFirst(); + QList 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(startItems.first()); + DiagramTextItem *endItem_ = + qgraphicsitem_cast(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 Items; + QList Arrows; + foreach(QGraphicsItem *item, items()) + { + if(item->type() == DiagramItem::Type) + Items.append(qgraphicsitem_cast(item)); + else if(item->type() == Arrow::Type) + Arrows.append(qgraphicsitem_cast(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 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 Items; + QList Arrows; + foreach(QGraphicsItem *item, items()) + { + if(item->type() == DiagramItem::Type) + Items.append(qgraphicsitem_cast(item)); + else if(item->type() == Arrow::Type) + Arrows.append(qgraphicsitem_cast(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(); + } +} diff --git a/Software/sie_cg/diagramscene.h b/Software/sie_cg/diagramscene.h new file mode 100644 index 0000000..bded4e3 --- /dev/null +++ b/Software/sie_cg/diagramscene.h @@ -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 +#include +#include +#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 hash) + {domElementsByName=hash;} + + void setButtonIdByName(QHash 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 domElementsByName; + QHash buttonIdByName; + MainWindow *myOwnerWindow; +}; + +#endif diff --git a/Software/sie_cg/diagramscene.pro b/Software/sie_cg/diagramscene.pro new file mode 100644 index 0000000..995ecc2 --- /dev/null +++ b/Software/sie_cg/diagramscene.pro @@ -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 diff --git a/Software/sie_cg/diagramscene.pro.user b/Software/sie_cg/diagramscene.pro.user new file mode 100644 index 0000000..d1afe0c --- /dev/null +++ b/Software/sie_cg/diagramscene.pro.user @@ -0,0 +1,247 @@ + + + + RunConfiguration0-BaseEnvironmentBase + 2 + + + RunConfiguration0-CommandLineArguments + + + + RunConfiguration0-ProFile + diagramscene.pro + + + RunConfiguration0-RunConfiguration.name + diagramscene + + + RunConfiguration0-UseDyldImageSuffix + false + + + RunConfiguration0-UseTerminal + false + + + RunConfiguration0-UserEnvironmentChanges + + + + RunConfiguration0-UserSetName + false + + + RunConfiguration0-UserSetWorkingDirectory + false + + + RunConfiguration0-UserWorkingDirectory + + + + RunConfiguration0-type + Qt4ProjectManager.Qt4RunConfiguration + + + activeRunConfiguration + 0 + + + activebuildconfiguration + Debug + + + buildConfiguration-Debug + + Debug + 0 + 0 + + 2 + + + + buildConfiguration-Release + + Release + 0 + + 0 + + + + buildconfiguration-Debug-buildstep0 + + Debug + + DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-MI4KrAyPP5,guid=5c5c5e6146195c74b6ad266d4cc07afd + DEFAULTS_PATH=/usr/share/gconf/gnome.default.path + DESKTOP_SESSION=gnome + DISPLAY=:0.0 + GDMSESSION=gnome + GDM_KEYBOARD_LAYOUT=es + GDM_LANG=en_US.utf8 + GNOME_DESKTOP_SESSION_ID=this-is-deprecated + GNOME_KEYRING_CONTROL=/tmp/keyring-CFAuJK + GNOME_KEYRING_PID=1516 + GTK_MODULES=canberra-gtk-module + HOME=/home/juan64bits + LANG=en_US.utf8 + LANGUAGE= + LD_LIBRARY_PATH=/usr/lib/qtcreator + LOGNAME=juan64bits + MANDATORY_PATH=/usr/share/gconf/gnome.mandatory.path + ORBIT_SOCKETDIR=/tmp/orbit-juan64bits + PATH=/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games + PWD=/home/juan64bits + QTDIR=/usr/share/qt4 + SESSION_MANAGER=local/Maximus:@/tmp/.ICE-unix/1534,unix/Maximus:/tmp/.ICE-unix/1534 + SHELL=/bin/bash + SPEECHD_PORT=7560 + SSH_AGENT_PID=1570 + SSH_AUTH_SOCK=/tmp/keyring-CFAuJK/ssh + USER=juan64bits + USERNAME=juan64bits + XAUTHORITY=/var/run/gdm/auth-for-juan64bits-V4ry7M/database + XDG_CONFIG_DIRS=/etc/xdg/xdg-gnome:/etc/xdg + XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/ + XDG_SESSION_COOKIE=b9a7fbc4d869fc15bd6cdd474bcc9a28-1287682812.550485-1725059380 + + + /home/juan64bits/QT/diagramscene/diagramscene.pro + -spec + linux-g++ + -r + CONFIG+=debug + + /usr/bin/qmake-qt4 + false + /home/juan64bits/QT/diagramscene + + + + buildconfiguration-Debug-buildstep1 + + Debug + + DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-MI4KrAyPP5,guid=5c5c5e6146195c74b6ad266d4cc07afd + DEFAULTS_PATH=/usr/share/gconf/gnome.default.path + DESKTOP_SESSION=gnome + DISPLAY=:0.0 + GDMSESSION=gnome + GDM_KEYBOARD_LAYOUT=es + GDM_LANG=en_US.utf8 + GNOME_DESKTOP_SESSION_ID=this-is-deprecated + GNOME_KEYRING_CONTROL=/tmp/keyring-CFAuJK + GNOME_KEYRING_PID=1516 + GTK_MODULES=canberra-gtk-module + HOME=/home/juan64bits + LANG=en_US.utf8 + LANGUAGE= + LD_LIBRARY_PATH=/usr/lib/qtcreator + LOGNAME=juan64bits + MANDATORY_PATH=/usr/share/gconf/gnome.mandatory.path + ORBIT_SOCKETDIR=/tmp/orbit-juan64bits + PATH=/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games + PWD=/home/juan64bits + QTDIR=/usr/share/qt4 + SESSION_MANAGER=local/Maximus:@/tmp/.ICE-unix/1534,unix/Maximus:/tmp/.ICE-unix/1534 + SHELL=/bin/bash + SPEECHD_PORT=7560 + SSH_AGENT_PID=1570 + SSH_AUTH_SOCK=/tmp/keyring-CFAuJK/ssh + USER=juan64bits + USERNAME=juan64bits + XAUTHORITY=/var/run/gdm/auth-for-juan64bits-V4ry7M/database + XDG_CONFIG_DIRS=/etc/xdg/xdg-gnome:/etc/xdg + XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/ + XDG_SESSION_COOKIE=b9a7fbc4d869fc15bd6cdd474bcc9a28-1287682812.550485-1725059380 + + false + + -w + + /usr/bin/make + true + /home/juan64bits/QT/diagramscene + + + + buildconfiguration-Debug-cleanstep0 + + Debug + true + + clean + + + + + buildconfiguration-Release-buildstep0 + + Release + + + + buildconfiguration-Release-buildstep1 + + Release + + + + buildconfiguration-Release-cleanstep0 + + Release + + + + buildconfigurations + + Debug + Release + + + + buildstep0 + + + + + + + buildstep1 + + + + + + buildsteps + + trolltech.qt4projectmanager.qmake + trolltech.qt4projectmanager.make + + + + cleanstep0 + + + true + + + + cleansteps + + trolltech.qt4projectmanager.make + + + + defaultFileEncoding + System + + + project + + + diff --git a/Software/sie_cg/diagramscene.qrc b/Software/sie_cg/diagramscene.qrc new file mode 100644 index 0000000..53ef19b --- /dev/null +++ b/Software/sie_cg/diagramscene.qrc @@ -0,0 +1,28 @@ + + + images/pointer.png + images/linepointer.png + images/textpointer.png + images/bold.png + images/italic.png + images/underline.png + images/floodfill.png + images/bringtofront.png + images/delete.png + images/sendtoback.png + images/linecolor.png + images/background1.png + images/background2.png + images/background3.png + images/background4.png + images/exit.png + images/new.png + images/no.png + images/open.png + images/save.png + images/save_as.png + images/yes.png + images/zoom_in.png + images/zoom_out.png + + diff --git a/Software/sie_cg/diagramtextitem.cpp b/Software/sie_cg/diagramtextitem.cpp new file mode 100644 index 0000000..82248ea --- /dev/null +++ b/Software/sie_cg/diagramtextitem.cpp @@ -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 + +#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); +} diff --git a/Software/sie_cg/diagramtextitem.h b/Software/sie_cg/diagramtextitem.h new file mode 100644 index 0000000..f4ae616 --- /dev/null +++ b/Software/sie_cg/diagramtextitem.h @@ -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 +#include +#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="", + 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 diff --git a/Software/sie_cg/images/background1.png b/Software/sie_cg/images/background1.png new file mode 100644 index 0000000..1afe156 Binary files /dev/null and b/Software/sie_cg/images/background1.png differ diff --git a/Software/sie_cg/images/background2.png b/Software/sie_cg/images/background2.png new file mode 100644 index 0000000..9991ecf Binary files /dev/null and b/Software/sie_cg/images/background2.png differ diff --git a/Software/sie_cg/images/background3.png b/Software/sie_cg/images/background3.png new file mode 100644 index 0000000..396f5f6 Binary files /dev/null and b/Software/sie_cg/images/background3.png differ diff --git a/Software/sie_cg/images/background4.png b/Software/sie_cg/images/background4.png new file mode 100644 index 0000000..7c368ad Binary files /dev/null and b/Software/sie_cg/images/background4.png differ diff --git a/Software/sie_cg/images/bold.png b/Software/sie_cg/images/bold.png new file mode 100644 index 0000000..986e65e Binary files /dev/null and b/Software/sie_cg/images/bold.png differ diff --git a/Software/sie_cg/images/bringtofront.png b/Software/sie_cg/images/bringtofront.png new file mode 100644 index 0000000..9accab9 Binary files /dev/null and b/Software/sie_cg/images/bringtofront.png differ diff --git a/Software/sie_cg/images/delete.png b/Software/sie_cg/images/delete.png new file mode 100644 index 0000000..5a3e49e Binary files /dev/null and b/Software/sie_cg/images/delete.png differ diff --git a/Software/sie_cg/images/exit.png b/Software/sie_cg/images/exit.png new file mode 100644 index 0000000..7f509a4 Binary files /dev/null and b/Software/sie_cg/images/exit.png differ diff --git a/Software/sie_cg/images/floodfill.png b/Software/sie_cg/images/floodfill.png new file mode 100644 index 0000000..54c0dae Binary files /dev/null and b/Software/sie_cg/images/floodfill.png differ diff --git a/Software/sie_cg/images/italic.png b/Software/sie_cg/images/italic.png new file mode 100644 index 0000000..9a438b5 Binary files /dev/null and b/Software/sie_cg/images/italic.png differ diff --git a/Software/sie_cg/images/linecolor.png b/Software/sie_cg/images/linecolor.png new file mode 100644 index 0000000..98a821f Binary files /dev/null and b/Software/sie_cg/images/linecolor.png differ diff --git a/Software/sie_cg/images/linepointer.png b/Software/sie_cg/images/linepointer.png new file mode 100644 index 0000000..66933d4 Binary files /dev/null and b/Software/sie_cg/images/linepointer.png differ diff --git a/Software/sie_cg/images/lower1.png b/Software/sie_cg/images/lower1.png new file mode 100644 index 0000000..5aa3b0a Binary files /dev/null and b/Software/sie_cg/images/lower1.png differ diff --git a/Software/sie_cg/images/new.png b/Software/sie_cg/images/new.png new file mode 100644 index 0000000..2a8a9d6 Binary files /dev/null and b/Software/sie_cg/images/new.png differ diff --git a/Software/sie_cg/images/no.png b/Software/sie_cg/images/no.png new file mode 100644 index 0000000..df2a147 Binary files /dev/null and b/Software/sie_cg/images/no.png differ diff --git a/Software/sie_cg/images/open.png b/Software/sie_cg/images/open.png new file mode 100644 index 0000000..32249f9 Binary files /dev/null and b/Software/sie_cg/images/open.png differ diff --git a/Software/sie_cg/images/pointer.png b/Software/sie_cg/images/pointer.png new file mode 100644 index 0000000..0b0b0aa Binary files /dev/null and b/Software/sie_cg/images/pointer.png differ diff --git a/Software/sie_cg/images/preview.png b/Software/sie_cg/images/preview.png new file mode 100644 index 0000000..1f7befb Binary files /dev/null and b/Software/sie_cg/images/preview.png differ diff --git a/Software/sie_cg/images/raise1.png b/Software/sie_cg/images/raise1.png new file mode 100644 index 0000000..bda2757 Binary files /dev/null and b/Software/sie_cg/images/raise1.png differ diff --git a/Software/sie_cg/images/save.png b/Software/sie_cg/images/save.png new file mode 100644 index 0000000..b1cbaf3 Binary files /dev/null and b/Software/sie_cg/images/save.png differ diff --git a/Software/sie_cg/images/save_as.png b/Software/sie_cg/images/save_as.png new file mode 100644 index 0000000..922f79b Binary files /dev/null and b/Software/sie_cg/images/save_as.png differ diff --git a/Software/sie_cg/images/sendtoback.png b/Software/sie_cg/images/sendtoback.png new file mode 100644 index 0000000..353a808 Binary files /dev/null and b/Software/sie_cg/images/sendtoback.png differ diff --git a/Software/sie_cg/images/textpointer.png b/Software/sie_cg/images/textpointer.png new file mode 100644 index 0000000..b25832c Binary files /dev/null and b/Software/sie_cg/images/textpointer.png differ diff --git a/Software/sie_cg/images/underline.png b/Software/sie_cg/images/underline.png new file mode 100644 index 0000000..9b8209f Binary files /dev/null and b/Software/sie_cg/images/underline.png differ diff --git a/Software/sie_cg/images/yes.png b/Software/sie_cg/images/yes.png new file mode 100644 index 0000000..7cf708b Binary files /dev/null and b/Software/sie_cg/images/yes.png differ diff --git a/Software/sie_cg/images/zoom_in.png b/Software/sie_cg/images/zoom_in.png new file mode 100644 index 0000000..dfb0e41 Binary files /dev/null and b/Software/sie_cg/images/zoom_in.png differ diff --git a/Software/sie_cg/images/zoom_out.png b/Software/sie_cg/images/zoom_out.png new file mode 100644 index 0000000..03571b8 Binary files /dev/null and b/Software/sie_cg/images/zoom_out.png differ diff --git a/Software/sie_cg/librarydialog.o b/Software/sie_cg/librarydialog.o new file mode 100644 index 0000000..91dd398 Binary files /dev/null and b/Software/sie_cg/librarydialog.o differ diff --git a/Software/sie_cg/librarydialog.ui b/Software/sie_cg/librarydialog.ui new file mode 100644 index 0000000..3bb8a00 --- /dev/null +++ b/Software/sie_cg/librarydialog.ui @@ -0,0 +1,99 @@ + + + libraryDialog + + + + 0 + 0 + 333 + 341 + + + + Dialog + + + + + + + + + + + &Add Library + + + + + + + &Remove library + + + + + + + &Edit library + + + + + + + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + rejected() + libraryDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + buttonBox + accepted() + libraryDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + diff --git a/Software/sie_cg/lineitem.cpp b/Software/sie_cg/lineitem.cpp new file mode 100644 index 0000000..48f1a24 --- /dev/null +++ b/Software/sie_cg/lineitem.cpp @@ -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 + +#include "lineitem.h" +#include + +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); +} diff --git a/Software/sie_cg/lineitem.h b/Software/sie_cg/lineitem.h new file mode 100644 index 0000000..b2388ce --- /dev/null +++ b/Software/sie_cg/lineitem.h @@ -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 + +#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 diff --git a/Software/sie_cg/main.cpp b/Software/sie_cg/main.cpp new file mode 100644 index 0000000..070c8b3 --- /dev/null +++ b/Software/sie_cg/main.cpp @@ -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 + +#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(); +} diff --git a/Software/sie_cg/mainwindow.cpp b/Software/sie_cg/mainwindow.cpp new file mode 100644 index 0000000..ccd9f0c --- /dev/null +++ b/Software/sie_cg/mainwindow.cpp @@ -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 +#include + +#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 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 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(item)->removeArrows(); + qgraphicsitem_cast(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(item)->removeLines(); + qgraphicsitem_cast(item)->startItem()->ownerItem() + ->removeArrow(qgraphicsitem_cast(item)); + qgraphicsitem_cast(item)->endItem()->ownerItem() + ->removeArrow(qgraphicsitem_cast(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(item)->itemIsMovable()) { + + qgraphicsitem_cast(item)->myOwner()->removeLine( + qgraphicsitem_cast(item)); + qgraphicsitem_cast(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 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(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(sender()); + fontColorToolButton->setIcon(createColorToolButtonIcon( + ":/images/textpointer.png", + qVariantValue(textAction->data()))); + textButtonTriggered(); +} + +void MainWindow::itemColorChanged() +{ + fillAction = qobject_cast(sender()); + fillColorToolButton->setIcon(createColorToolButtonIcon( + ":/images/floodfill.png", + qVariantValue(fillAction->data()))); + fillButtonTriggered(); +} + +void MainWindow::lineColorChanged() +{ + lineAction = qobject_cast(sender()); + lineColorToolButton->setIcon(createColorToolButtonIcon( + ":/images/linecolor.png", + qVariantValue(lineAction->data()))); + lineButtonTriggered(); +} + +void MainWindow::textButtonTriggered() +{ + scene->setTextColor(qVariantValue(textAction->data())); +} + +void MainWindow::fillButtonTriggered() +{ + scene->setItemColor(qVariantValue(fillAction->data())); +} + +void MainWindow::lineButtonTriggered() +{ + scene->setLineColor(qVariantValue(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(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 :)")); +} + +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 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 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 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; +} + + diff --git a/Software/sie_cg/mainwindow.h b/Software/sie_cg/mainwindow.h new file mode 100644 index 0000000..1503f97 --- /dev/null +++ b/Software/sie_cg/mainwindow.h @@ -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 +#include +#include +#include +#include + +#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 domElementsByName; + QHash 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 diff --git a/Software/sie_cg/moc_librarydialog.cpp b/Software/sie_cg/moc_librarydialog.cpp new file mode 100644 index 0000000..0acca32 --- /dev/null +++ b/Software/sie_cg/moc_librarydialog.cpp @@ -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 ." +#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(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 diff --git a/Software/sie_cg/moc_librarydialog.o b/Software/sie_cg/moc_librarydialog.o new file mode 100644 index 0000000..cceb254 Binary files /dev/null and b/Software/sie_cg/moc_librarydialog.o differ diff --git a/Software/sie_cg/test.sie b/Software/sie_cg/test.sie new file mode 100644 index 0000000..ae0c6b0 --- /dev/null +++ b/Software/sie_cg/test.sie @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +