mirror of
git://projects.qi-hardware.com/nn-usb-fpga.git
synced 2025-04-21 12:27:27 +03:00
First commit for sie code generator project.
This commit is contained in:
356
Software/sie_cg/block_editor/arrow.cpp
Normal file
356
Software/sie_cg/block_editor/arrow.cpp
Normal file
@@ -0,0 +1,356 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial Usage
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtGui>
|
||||
|
||||
#include "arrow.h"
|
||||
#include "lineitem.h"
|
||||
#include <math.h>
|
||||
|
||||
const qreal Pi = 3.14;
|
||||
|
||||
Arrow::Arrow( QPointF startP,QPointF endP,
|
||||
QGraphicsItem *parent, QGraphicsScene *scene)
|
||||
: QGraphicsPathItem(parent, scene)
|
||||
{
|
||||
startPoint=startP;
|
||||
endPoint=endP;
|
||||
arrowSize = 10;
|
||||
moving=0;
|
||||
//setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||
setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||
myColor = Qt::black;
|
||||
setPen(QPen(myColor, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||
//setZValue(0.0);
|
||||
myOwnerScene = scene;
|
||||
lineItem *newLine= new lineItem(QPointF(0,0),QPointF(0,0),this);
|
||||
myOwnerScene->addItem(newLine);
|
||||
addLine(newLine);
|
||||
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
void Arrow::removeLine(lineItem *line)
|
||||
{
|
||||
int index = myLines.indexOf(line);
|
||||
|
||||
if (index != -1){
|
||||
//Adjust the corners
|
||||
if(myLines.count()>1)
|
||||
{
|
||||
if(index==0)
|
||||
{
|
||||
myCorners.removeAt(0);
|
||||
myOwnerScene->removeItem(myCLines.at(0));
|
||||
myCLines.removeAt(0);
|
||||
}
|
||||
else if(index>0)
|
||||
{
|
||||
myCorners.removeAt(index-1);
|
||||
myOwnerScene->removeItem(myCLines.at(index-1));
|
||||
myCLines.removeAt(index-1);
|
||||
}
|
||||
}
|
||||
myLines.removeAt(index);
|
||||
}
|
||||
|
||||
//If lines is empty the arrow is removed
|
||||
if (myLines.count()<3)
|
||||
{
|
||||
removeLines();
|
||||
myOwnerScene->removeItem(this);
|
||||
}
|
||||
}
|
||||
|
||||
void Arrow::removeLines()
|
||||
{
|
||||
foreach (lineItem *line, myLines) {
|
||||
scene()->removeItem(line);
|
||||
delete line;
|
||||
}
|
||||
foreach (lineItem *line, myCLines) {
|
||||
scene()->removeItem(line);
|
||||
delete line;
|
||||
}
|
||||
if(myOwnerScene->items().indexOf(SECLine)!=-1)
|
||||
{
|
||||
scene()->removeItem(SECLine);
|
||||
delete SECLine;
|
||||
}
|
||||
}
|
||||
|
||||
bool Arrow::addLine(lineItem *line)
|
||||
{
|
||||
myLines.append(line);
|
||||
return 1;
|
||||
}
|
||||
|
||||
QRectF Arrow::boundingRect() const
|
||||
{
|
||||
qreal extra = (pen().width() + arrowSize*2) / 2.0;
|
||||
|
||||
return QGraphicsPathItem::boundingRect()
|
||||
.normalized()
|
||||
.adjusted(-extra, -extra, extra, extra);
|
||||
}
|
||||
|
||||
QPainterPath Arrow::shape() const
|
||||
{
|
||||
QPainterPath path = QGraphicsPathItem::shape();
|
||||
return path;
|
||||
}
|
||||
|
||||
void Arrow::updatePosition()
|
||||
{
|
||||
QPainterPath myPath;
|
||||
myPath.moveTo(startPoint);
|
||||
if(!myCorners.isEmpty())
|
||||
foreach(QPointF corner, myCorners){
|
||||
myPath.lineTo(corner);
|
||||
}
|
||||
myPath.lineTo(endPoint);
|
||||
|
||||
setPath(myPath);
|
||||
}
|
||||
|
||||
void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *,
|
||||
QWidget *)
|
||||
{
|
||||
//Update line positions
|
||||
QPen myPen = pen();
|
||||
myPen.setColor(myColor);
|
||||
painter->setPen(myPen);
|
||||
painter->setBrush(myColor);
|
||||
|
||||
QPointF endPos=endPoint;
|
||||
QPointF startPos=startPoint;
|
||||
|
||||
if(myCorners.isEmpty())
|
||||
{
|
||||
myLines.first()->setLine(QLineF(startPos,endPos));
|
||||
}
|
||||
else
|
||||
{
|
||||
myLines.first()->setLine(QLineF(startPos,myCorners.first()));
|
||||
for(int i=0; i<myCorners.count()-1;i++)
|
||||
myLines.at(i+1)->setLine(QLineF(myCorners.at(i),myCorners.at(i+1)));
|
||||
myLines.last()->setLine(QLineF(myCorners.last(),endPos));
|
||||
}
|
||||
|
||||
//Drawing arrow selected
|
||||
for(int i=0; i<myLines.count();i++)
|
||||
{
|
||||
if (isSelected())
|
||||
{
|
||||
painter->setPen(QPen(Qt::gray, 2, Qt::SolidLine));
|
||||
QLineF myLine = myLines.at(i)->line();
|
||||
painter->drawLine(myLine);
|
||||
foreach (lineItem *line, myLines) { line->setColor(Qt::gray);}
|
||||
foreach (lineItem *line, myCLines) { line->setColor(Qt::gray);}
|
||||
if(myOwnerScene->items().indexOf(SECLine)!=-1)
|
||||
SECLine->setColor(Qt::gray);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (lineItem *line, myLines) { line->setColor(myColor);}
|
||||
foreach (lineItem *line, myCLines) { line->setColor(myColor);}
|
||||
if(myOwnerScene->items().indexOf(SECLine)!=-1)
|
||||
SECLine->setColor(myColor);
|
||||
}
|
||||
}
|
||||
setSelectedArrows();
|
||||
}
|
||||
|
||||
void Arrow::setSelectedArrows()
|
||||
{
|
||||
bool anySelected = 0;
|
||||
|
||||
foreach(lineItem *line,myLines){ if(line->isSelected())anySelected=1;}
|
||||
foreach(lineItem *line,myCLines){ if(line->isSelected())anySelected=1;}
|
||||
if(isSelected()) anySelected=1;
|
||||
|
||||
if(anySelected)
|
||||
setVisibleCorners(1);
|
||||
else
|
||||
setVisibleCorners(0);
|
||||
}
|
||||
|
||||
void Arrow::createCorner(QPointF cornerPos, lineItem *inLine)
|
||||
{
|
||||
createCorner(cornerPos,myLines.indexOf(inLine));
|
||||
}
|
||||
|
||||
void Arrow::createCorner(QPointF cornerPos, int index)
|
||||
{
|
||||
if (index != -1)
|
||||
{
|
||||
myCorners.insert(index,cornerPos);
|
||||
lineItem *newLine= new lineItem(cornerPos,cornerPos,this);
|
||||
myOwnerScene->addItem(newLine);
|
||||
newLine->setZValue(this->zValue());
|
||||
addLine(newLine);
|
||||
newLine= new lineItem(cornerPos+QPointF(-0.5,-0.5) ,
|
||||
cornerPos+QPointF(0.5,0.5),this,6,1);
|
||||
myOwnerScene->addItem(newLine);
|
||||
newLine->setZValue(this->zValue()+0.1);
|
||||
myCLines.insert(index,newLine);
|
||||
}
|
||||
updatePosition();
|
||||
}
|
||||
void Arrow::createFirstCorner()
|
||||
{
|
||||
if(myOwnerScene->items().indexOf(SECLine)==-1)
|
||||
{
|
||||
SECLine = new lineItem(startPoint+QPointF(-0.5,-0.5) ,
|
||||
startPoint+QPointF(0.5,0.5),this,6,1);
|
||||
myOwnerScene->addItem(SECLine);
|
||||
SECLine->setVisible(1);
|
||||
SECLine->setZValue(this->zValue()+0.1);
|
||||
}
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
void Arrow::moveCorner(QPointF cornerPos, lineItem *inLine, bool relative)
|
||||
{
|
||||
int index = myCLines.indexOf(inLine);
|
||||
if(relative) cornerPos=mapFromItem(inLine,cornerPos);
|
||||
|
||||
if (index != -1)
|
||||
{
|
||||
myCorners.replace(index,cornerPos);
|
||||
}
|
||||
else if (inLine == SECLine)
|
||||
{
|
||||
startPoint=cornerPos;
|
||||
endPoint=cornerPos;
|
||||
}
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
void Arrow::setVisibleCorners(bool visible)
|
||||
{
|
||||
foreach (lineItem *line, myCLines) {
|
||||
line->setVisible(visible);
|
||||
}
|
||||
if(myOwnerScene->items().indexOf(SECLine)!=-1)
|
||||
{
|
||||
SECLine->setVisible(1);
|
||||
}
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
void Arrow::snapToGrid(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
//TODO implement polygon drag
|
||||
QPointF diffPos= event->scenePos()-previousPos;
|
||||
printf("diff[%f|%f]\n",diffPos.x(),diffPos.y()); fflush(stdout);
|
||||
//Update corners:
|
||||
for(int i=0; i < myCorners.count();i++)
|
||||
{
|
||||
myCLines.at(i)->setLine(QLineF(myCLines.at(i)->line().p1()+diffPos,
|
||||
myCLines.at(i)->line().p2()+diffPos));
|
||||
QPointF itemPos = myCLines.at(i)->line().p1()+QPointF(0.5,0.5);
|
||||
moveCorner(itemPos,myCLines.at(i));
|
||||
}
|
||||
if(myOwnerScene->items().indexOf(SECLine)!=-1)
|
||||
{
|
||||
SECLine->setLine(QLineF(SECLine->line().p1()+diffPos,
|
||||
SECLine->line().p2()+diffPos));
|
||||
QPointF itemPos = SECLine->line().p1()+QPointF(0.5,0.5);
|
||||
moveCorner(itemPos,SECLine);
|
||||
}
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
void Arrow::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
//if(this->isSelected())
|
||||
{
|
||||
previousPos = event->scenePos();
|
||||
moving=1;
|
||||
}
|
||||
QGraphicsPathItem::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void Arrow::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if(moving && isSelected())
|
||||
{
|
||||
snapToGrid(event);
|
||||
previousPos = event->scenePos();
|
||||
}
|
||||
moving=0;
|
||||
QGraphicsPathItem::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
void Arrow::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if(moving && isSelected())
|
||||
{
|
||||
snapToGrid(event);
|
||||
previousPos = event->scenePos();
|
||||
}
|
||||
QGraphicsPathItem::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
QDomElement Arrow::toXml(QDomDocument &document) const
|
||||
{
|
||||
QDomElement diagramArrow = document.createElement("Polygon");
|
||||
//Point list
|
||||
if(!myCorners.isEmpty())
|
||||
{
|
||||
QDomElement arrowCorner;
|
||||
//start point
|
||||
arrowCorner = document.createElement("Point");
|
||||
arrowCorner.setAttribute("x",(startPoint-QPointF(500,500)).x());
|
||||
arrowCorner.setAttribute("y",(startPoint-QPointF(500,500)).y());
|
||||
diagramArrow.appendChild(arrowCorner);
|
||||
//corner points
|
||||
foreach(QPointF corner, myCorners)
|
||||
{
|
||||
arrowCorner = document.createElement("Point");
|
||||
arrowCorner.setAttribute("x",(corner-QPointF(500,500)).x());
|
||||
arrowCorner.setAttribute("y",(corner-QPointF(500,500)).y());
|
||||
diagramArrow.appendChild(arrowCorner);
|
||||
}
|
||||
}
|
||||
return (diagramArrow);
|
||||
}
|
||||
124
Software/sie_cg/block_editor/arrow.h
Normal file
124
Software/sie_cg/block_editor/arrow.h
Normal file
@@ -0,0 +1,124 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial Usage
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef ARROW_H
|
||||
#define ARROW_H
|
||||
|
||||
#include <QGraphicsLineItem>
|
||||
#include <QtXml>
|
||||
#include "diagramtextitem.h"
|
||||
#include "diagramscene.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QGraphicsPolygonItem;
|
||||
class QGraphicsLineItem;
|
||||
class QGraphicsPathItem;
|
||||
class QGraphicsScene;
|
||||
class QRectF;
|
||||
class QGraphicsSceneMouseEvent;
|
||||
class QPainterPath;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class lineItem;
|
||||
class DiagramScene;
|
||||
|
||||
class Arrow : public QGraphicsPathItem
|
||||
{
|
||||
public:
|
||||
enum { Type = UserType + 32 };
|
||||
|
||||
Arrow(QPointF startPoint,QPointF endPoint,
|
||||
QGraphicsItem *parent = 0, QGraphicsScene *scene = 0);
|
||||
|
||||
int type() const
|
||||
{ return Type; }
|
||||
QRectF boundingRect() const;
|
||||
QPainterPath shape() const;
|
||||
void setColor(const QColor &color)
|
||||
{ myColor=color; }
|
||||
|
||||
void removeLine(lineItem *line);
|
||||
void removeLines();
|
||||
bool addLine(lineItem *line);
|
||||
void setStartPoint(QPointF point){startPoint=point;}
|
||||
void setEndPoint(QPointF point){endPoint=point;}
|
||||
|
||||
QPointF getStartPoint(){return startPoint;}
|
||||
QPointF getEndPoint(){return endPoint;}
|
||||
|
||||
void createCorner(QPointF cornerPos, lineItem *inLine);
|
||||
void createCorner(QPointF cornerPos, int index);
|
||||
void moveCorner(QPointF cornerPos, lineItem *inLine, bool relative = 1);
|
||||
|
||||
void setVisibleCorners(bool visible);
|
||||
|
||||
void snapToGrid(QGraphicsSceneMouseEvent *event);
|
||||
|
||||
QDomDocument toXmlFormat();
|
||||
QDomElement toXml(QDomDocument &) const;
|
||||
void createFirstCorner();
|
||||
void setSelectedArrows();
|
||||
|
||||
public slots:
|
||||
void updatePosition();
|
||||
|
||||
protected:
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget = 0);
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||
|
||||
private:
|
||||
QColor myColor;
|
||||
QList<lineItem *> myLines;
|
||||
QList<lineItem *> myCLines;
|
||||
lineItem *SECLine;
|
||||
QPointF startPoint;
|
||||
QPointF endPoint;
|
||||
QList<QPointF> myCorners;
|
||||
QGraphicsScene *myOwnerScene;
|
||||
qreal arrowSize;
|
||||
bool moving;
|
||||
QPointF previousPos;
|
||||
};
|
||||
|
||||
#endif
|
||||
BIN
Software/sie_cg/block_editor/diagramitem.o
Normal file
BIN
Software/sie_cg/block_editor/diagramitem.o
Normal file
Binary file not shown.
430
Software/sie_cg/block_editor/diagramscene.cpp
Normal file
430
Software/sie_cg/block_editor/diagramscene.cpp
Normal file
@@ -0,0 +1,430 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial Usage
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtGui>
|
||||
#include <QHash>
|
||||
#include "diagramscene.h"
|
||||
|
||||
DiagramScene::DiagramScene(QMenu *itemMenu, QObject *parent)
|
||||
: QGraphicsScene(parent)
|
||||
{
|
||||
myItemMenu = itemMenu;
|
||||
myMode = MoveItem;
|
||||
|
||||
line = 0;
|
||||
textItem = 0;
|
||||
myItemColor = Qt::white;
|
||||
myTextColor = Qt::black;
|
||||
myLineColor = Qt::black;
|
||||
snapToGrid=1;
|
||||
myGrid=10;
|
||||
myPolygonPath=0;
|
||||
myCorners=0;
|
||||
|
||||
TitleText = new DiagramTextItem(0,0,1,0xFFF,255,"BLOCK NAME HERE (not visible)",
|
||||
QPointF(250,250));
|
||||
addItem(TitleText);
|
||||
|
||||
}
|
||||
|
||||
void DiagramScene::editorLostFocus(DiagramTextItem *item)
|
||||
{
|
||||
QTextCursor cursor = item->textCursor();
|
||||
cursor.clearSelection();
|
||||
item->setTextCursor(cursor);
|
||||
|
||||
if (item->toPlainText().isEmpty()) {
|
||||
removeItem(item);
|
||||
item->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
void DiagramScene::drawBackground(QPainter *p, const QRectF &r)
|
||||
{
|
||||
p -> save();
|
||||
|
||||
p -> setRenderHint(QPainter::Antialiasing, false);
|
||||
p -> setRenderHint(QPainter::TextAntialiasing, true);
|
||||
p -> setRenderHint(QPainter::SmoothPixmapTransform, false);
|
||||
|
||||
p -> setPen(Qt::NoPen);
|
||||
p -> setBrush(Qt::white);
|
||||
p -> drawRect(r);
|
||||
|
||||
|
||||
p -> setPen(Qt::gray);
|
||||
p -> setBrush(Qt::NoBrush);
|
||||
qreal limite_x = r.x() + r.width();
|
||||
qreal limite_y = r.y() + r.height();
|
||||
|
||||
int g_x = (int)ceil(r.x());
|
||||
while (g_x % myGrid) ++ g_x;
|
||||
int g_y = (int)ceil(r.y());
|
||||
while (g_y % myGrid) ++ g_y;
|
||||
|
||||
QPolygon points;
|
||||
for (int gx = g_x ; gx < limite_x ; gx += myGrid) {
|
||||
for (int gy = g_y ; gy < limite_y ; gy += myGrid) {
|
||||
points << QPoint(gx, gy);
|
||||
}
|
||||
}
|
||||
p -> drawPoints(points);
|
||||
|
||||
p->drawLine(500,0,500,1000);
|
||||
p->drawLine(0,500,1000,500);
|
||||
|
||||
p -> restore();
|
||||
}
|
||||
|
||||
void DiagramScene::doSnapToGrid(QGraphicsSceneMouseEvent *mouseEvent)
|
||||
{
|
||||
if(snapToGrid){
|
||||
mouseEvent->setScenePos(QPointF(
|
||||
int(mouseEvent->scenePos().x()/myGrid)*myGrid,
|
||||
int(mouseEvent->scenePos().y()/myGrid)*myGrid
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
void DiagramScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||
{
|
||||
doSnapToGrid(mouseEvent);
|
||||
QString Text;
|
||||
|
||||
if (mouseEvent->button() != Qt::LeftButton)
|
||||
return;
|
||||
|
||||
switch (myMode)
|
||||
{
|
||||
case InsertText:
|
||||
//TODO: limit text items to 255 maximum
|
||||
if(myTextType<256)
|
||||
if(myTextType & 0b10000000)
|
||||
Text = "IN " +myTypeString;
|
||||
else
|
||||
Text = "OUT " +myTypeString;
|
||||
else
|
||||
Text = myTypeString;
|
||||
|
||||
textItem = new DiagramTextItem(0,0,1,myTextType,0,Text,
|
||||
mouseEvent->scenePos());
|
||||
if(addTextItem(textItem))
|
||||
{
|
||||
textItem->setZValue(1000.0);
|
||||
connect(textItem, SIGNAL(lostFocus(DiagramTextItem*)),
|
||||
this, SLOT(editorLostFocus(DiagramTextItem*)));
|
||||
addItem(textItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete(textItem);
|
||||
QMessageBox::warning(0,"Full","The block can only have only"
|
||||
"255 text items");
|
||||
}
|
||||
emit textInserted(textItem);
|
||||
break;
|
||||
case EditPolygon:
|
||||
if(line == 0 && items().indexOf(myPolygonPath)==-1)
|
||||
{
|
||||
line = new QGraphicsLineItem(QLineF(mouseEvent->scenePos(),
|
||||
mouseEvent->scenePos()));
|
||||
line->setPen(QPen(Qt::blue, 2));
|
||||
line->setZValue(1000.0);
|
||||
addItem(line);
|
||||
}
|
||||
else if(line != 0 && items().indexOf(myPolygonPath)==-1 &&
|
||||
line->line().length()>5)
|
||||
{
|
||||
myPolygonPath = new Arrow(line->line().p1(),line->line().p2(),
|
||||
0,this);
|
||||
QLineF newLine(line->line().p2(),line->line().p2());
|
||||
line->setLine(newLine);
|
||||
}
|
||||
else if(line != 0 && items().indexOf(myPolygonPath)!=-1 &&
|
||||
line->line().length()>5)
|
||||
{
|
||||
myPolygonPath->createCorner(line->line().p1(),myCorners);
|
||||
myPolygonPath->setEndPoint(line->line().p2());
|
||||
myPolygonPath->updatePosition();
|
||||
QLineF newLine(line->line().p2(),line->line().p2());
|
||||
line->setLine(newLine);
|
||||
|
||||
myCorners++;
|
||||
}
|
||||
|
||||
case MoveItem:
|
||||
QGraphicsScene::mousePressEvent(mouseEvent);
|
||||
break;
|
||||
default: ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DiagramScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||
{
|
||||
doSnapToGrid(mouseEvent);
|
||||
if (myMode == EditPolygon && line != 0 )
|
||||
{
|
||||
QLineF newLine(line->line().p1(), mouseEvent->scenePos());
|
||||
line->setLine(newLine);
|
||||
}
|
||||
|
||||
QGraphicsScene::mouseMoveEvent(mouseEvent);
|
||||
|
||||
}
|
||||
|
||||
void DiagramScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||
{
|
||||
doSnapToGrid(mouseEvent);
|
||||
if (myMode == EditPolygon && line != 0 && myCorners>0)
|
||||
{
|
||||
if(myPolygonPath->getStartPoint()!=line->line().p2())
|
||||
myPolygonPath->createCorner(line->line().p2(),myCorners);
|
||||
|
||||
myPolygonPath->setEndPoint(myPolygonPath->getStartPoint());
|
||||
myPolygonPath->createFirstCorner();
|
||||
myPolygonPath->updatePosition();
|
||||
myCorners=0;
|
||||
removeItem(line);
|
||||
line = 0;
|
||||
myMode = MoveItem;
|
||||
emit textInserted(textItem);//Is the same for all buttons
|
||||
}
|
||||
else if (myMode != EditPolygon)
|
||||
{
|
||||
QGraphicsScene::mouseDoubleClickEvent(mouseEvent);
|
||||
}
|
||||
}
|
||||
|
||||
void DiagramScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||
{
|
||||
doSnapToGrid(mouseEvent);
|
||||
if (myMode != EditPolygon && line == 0)
|
||||
QGraphicsScene::mouseReleaseEvent(mouseEvent);
|
||||
}
|
||||
|
||||
bool DiagramScene::isItemChange(int type)
|
||||
{
|
||||
foreach (QGraphicsItem *item, selectedItems()) {
|
||||
if (item->type() == type)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QDomDocument DiagramScene::toXmlFormat()
|
||||
{
|
||||
QDomDocument document;
|
||||
QDomComment initialComments=document.createComment(
|
||||
"File for SIE Code Generator. Custmos Blocks");
|
||||
document.appendChild(initialComments);
|
||||
QDomElement diagram = document.createElement("CustomItem");
|
||||
diagram.setAttribute("BlockName",TitleText->toPlainText());
|
||||
document.appendChild(diagram);
|
||||
//Lists of items
|
||||
QList<DiagramTextItem *> Items;
|
||||
QList<Arrow *> Arrows;
|
||||
foreach(QGraphicsItem *item, items())
|
||||
{
|
||||
if(item->type() == DiagramTextItem::Type)
|
||||
Items.append(qgraphicsitem_cast<DiagramTextItem *>(item));
|
||||
else if(item->type() == Arrow::Type)
|
||||
Arrows.append(qgraphicsitem_cast<Arrow *>(item));
|
||||
}
|
||||
|
||||
if(Arrows.count()>1) {printf("Something is wrong.\n"); fflush(stdout);}
|
||||
|
||||
//Create the XML structure
|
||||
diagram.appendChild(myPolygonPath->toXml(document));
|
||||
|
||||
QDomElement element;
|
||||
if(Items.count()>0)
|
||||
{
|
||||
QDomElement textItems = document.createElement("TextItems");
|
||||
foreach(DiagramTextItem *item, Items)
|
||||
{
|
||||
if(item->styleIO() != 0xFFF)
|
||||
{
|
||||
element = item->toXml(document);
|
||||
element.setAttribute("ID",textItemsByID.key(item));
|
||||
textItems.appendChild(element);
|
||||
}
|
||||
}
|
||||
diagram.appendChild(textItems);
|
||||
}
|
||||
|
||||
return(document);
|
||||
}
|
||||
|
||||
int DiagramScene::fromXmlFormat(QDomDocument document)
|
||||
{
|
||||
//Read items TODO: in future... add multi items on same file
|
||||
QDomNodeList customsItems = document.elementsByTagName("CustomItem");
|
||||
if(!customsItems.at(0).isElement())
|
||||
return -1;
|
||||
//Load the first item in the document
|
||||
QDomElement customItem = customsItems.at(0).toElement();
|
||||
if(customItem.attribute("BlockName")=="")
|
||||
TitleText->setPlainText("Please set Block Name");
|
||||
else
|
||||
TitleText->setPlainText(customItem.attribute("BlockName"));
|
||||
TitleText->updatePosition();
|
||||
for (QDomNode node = customItem.firstChild() ;
|
||||
!node.isNull() ;
|
||||
node = node.nextSibling())
|
||||
{
|
||||
QDomElement element = node.toElement();
|
||||
if(element.tagName()=="Polygon")
|
||||
{
|
||||
QList<QPointF> points;
|
||||
for (QDomNode node = element.firstChild() ;
|
||||
!node.isNull() ;
|
||||
node = node.nextSibling())
|
||||
{
|
||||
QDomElement point = node.toElement();
|
||||
if(point.tagName()!="Point")
|
||||
return -1;
|
||||
points.append(QPointF((QPointF(point.attribute("x").toFloat(),0)
|
||||
+QPointF(500,500)).x(),
|
||||
(QPointF(0,point.attribute("y").toFloat())
|
||||
+QPointF(500,500)).y()));
|
||||
}
|
||||
|
||||
if(points.count()>0)
|
||||
{
|
||||
myPolygonPath = new Arrow(points.at(0),points.at(0),0,this);
|
||||
for(int i=1; i< points.count();i++)
|
||||
{
|
||||
myPolygonPath->createCorner(points.at(i),i-1);
|
||||
}
|
||||
myPolygonPath->createFirstCorner();
|
||||
myPolygonPath->updatePosition();
|
||||
}
|
||||
}
|
||||
else if(element.tagName()=="TextItems")
|
||||
{
|
||||
for (QDomNode node = element.firstChild() ;
|
||||
!node.isNull() ;
|
||||
node = node.nextSibling())
|
||||
{
|
||||
QDomElement textItemE = node.toElement();
|
||||
if(textItemE.tagName()!="TextItem")
|
||||
return -1;
|
||||
|
||||
int myStyleIO = textItemE.attribute("myStyleIO").toInt();
|
||||
int myID = textItemE.attribute("ID").toInt();
|
||||
bool editableItem = textItemE.attribute("editableItem").toInt();
|
||||
QPointF posOffset=
|
||||
QPointF((QPointF(textItemE.attribute("posOffset-x")
|
||||
.toFloat(),0)+QPointF(500,500)).x(),
|
||||
(-QPointF(0,textItemE.attribute("posOffset-y")
|
||||
.toFloat())+QPointF(500,500)).y());
|
||||
QString itemString=textItemE.attribute("text");
|
||||
|
||||
if(myStyleIO==0)
|
||||
{
|
||||
if(!editableItem)
|
||||
myStyleIO=256;
|
||||
else
|
||||
myStyleIO=257;
|
||||
}
|
||||
|
||||
DiagramTextItem * newTextItem =
|
||||
new DiagramTextItem(0,0,1,myStyleIO,myID,itemString,posOffset);
|
||||
newTextItem->setZValue(1000.0);
|
||||
connect(newTextItem, SIGNAL(lostFocus(DiagramTextItem*)),
|
||||
this, SLOT(editorLostFocus(DiagramTextItem*)));
|
||||
addItem(newTextItem);
|
||||
textItemsByID.insert(myID,newTextItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void DiagramScene::cleanScene()
|
||||
{
|
||||
//Lists of items
|
||||
QList<DiagramTextItem *> Items;
|
||||
foreach(QGraphicsItem *item, items())
|
||||
{
|
||||
if(item->type() == DiagramTextItem::Type)
|
||||
Items.append(qgraphicsitem_cast<DiagramTextItem *>(item));
|
||||
}
|
||||
//Remove Diagram Text Items
|
||||
foreach(DiagramTextItem *item, Items)
|
||||
{
|
||||
if(item->styleIO() != 0xFFF)
|
||||
{
|
||||
removeItem(item);
|
||||
delete(item);
|
||||
}
|
||||
}
|
||||
//Remove Polygon Path
|
||||
if(items().indexOf(myPolygonPath)!=-1)
|
||||
{
|
||||
myPolygonPath->removeLines();
|
||||
removeItem(myPolygonPath);
|
||||
delete(myPolygonPath);
|
||||
}
|
||||
TitleText->setPlainText("BLOCK NAME HERE (not visible)");
|
||||
TitleText->updatePosition();
|
||||
}
|
||||
|
||||
int DiagramScene::addTextItem(DiagramTextItem * textItem)
|
||||
{
|
||||
for(int i=0; i<255; i++)
|
||||
{
|
||||
QHash<int,DiagramTextItem *>::iterator iter= textItemsByID.find(i);
|
||||
if(iter==textItemsByID.end())
|
||||
{
|
||||
textItemsByID.insert(i,textItem);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DiagramScene::removeTextItem(DiagramTextItem * textItem)
|
||||
{
|
||||
textItemsByID.remove(textItemsByID.key(textItem));
|
||||
}
|
||||
121
Software/sie_cg/block_editor/diagramscene.h
Normal file
121
Software/sie_cg/block_editor/diagramscene.h
Normal file
@@ -0,0 +1,121 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial Usage
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef DIAGRAMSCENE_H
|
||||
#define DIAGRAMSCENE_H
|
||||
|
||||
#include <QGraphicsScene>
|
||||
#include <QDesktopServices>
|
||||
#include <QtXml>
|
||||
#include "diagramtextitem.h"
|
||||
#include "arrow.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QGraphicsSceneMouseEvent;
|
||||
class QMenu;
|
||||
class QPointF;
|
||||
class QGraphicsLineItem;
|
||||
class QFont;
|
||||
class QGraphicsTextItem;
|
||||
class QColor;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class Arrow;
|
||||
class DiagramTextItem;
|
||||
|
||||
class DiagramScene : public QGraphicsScene
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum Mode { MoveItem , EditPolygon, InsertText };
|
||||
|
||||
DiagramScene(QMenu *itemMenu, QObject *parent = 0);
|
||||
|
||||
QDomDocument toXmlFormat();
|
||||
int fromXmlFormat(QDomDocument xmlDocument);
|
||||
void cleanScene();
|
||||
void setTextType(int type,QString text){myTextType=type;myTypeString=text;}
|
||||
void resetMyPolygon(){myPolygonPath=0;}
|
||||
|
||||
QHash<int,DiagramTextItem*> getTextItemsByID;
|
||||
|
||||
int addTextItem(DiagramTextItem * textItem);
|
||||
void removeTextItem(DiagramTextItem * textItem);
|
||||
|
||||
public slots:
|
||||
void setMode(Mode mode){myMode=mode;}
|
||||
void editorLostFocus(DiagramTextItem *item);
|
||||
|
||||
signals:
|
||||
void textInserted(QGraphicsTextItem *item);
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
|
||||
void drawBackground(QPainter *p, const QRectF &r);
|
||||
|
||||
private:
|
||||
bool isItemChange(int type);
|
||||
void doSnapToGrid(QGraphicsSceneMouseEvent *mouseEvent);
|
||||
QMenu *myItemMenu;
|
||||
Mode myMode;
|
||||
int myTextType;
|
||||
QString myTypeString;
|
||||
bool leftButtonDown;
|
||||
QPointF startPoint;
|
||||
QGraphicsLineItem *line;
|
||||
Arrow *myPolygonPath;
|
||||
QFont myFont;
|
||||
DiagramTextItem *textItem;
|
||||
DiagramTextItem *TitleText;
|
||||
QColor myTextColor;
|
||||
QColor myItemColor;
|
||||
QColor myLineColor;
|
||||
bool snapToGrid;
|
||||
short int myGrid;
|
||||
int myCorners;
|
||||
QHash<int,DiagramTextItem*> textItemsByID;
|
||||
};
|
||||
|
||||
#endif
|
||||
30
Software/sie_cg/block_editor/diagramscene.pro
Normal file
30
Software/sie_cg/block_editor/diagramscene.pro
Normal file
@@ -0,0 +1,30 @@
|
||||
HEADERS = mainwindow.h \
|
||||
diagramscene.h \
|
||||
arrow.h \
|
||||
diagramtextitem.h \
|
||||
lineitem.h
|
||||
SOURCES = mainwindow.cpp \
|
||||
main.cpp \
|
||||
arrow.cpp \
|
||||
diagramtextitem.cpp \
|
||||
diagramscene.cpp \
|
||||
lineitem.cpp
|
||||
RESOURCES = diagramscene.qrc
|
||||
|
||||
TARGET = blockeditor
|
||||
|
||||
# install
|
||||
target.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/diagramscene
|
||||
sources.files = $$SOURCES \
|
||||
$$HEADERS \
|
||||
$$RESOURCES \
|
||||
$$FORMS \
|
||||
diagramscene.pro \
|
||||
images
|
||||
sources.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/diagramscene
|
||||
INSTALLS += target \
|
||||
sources
|
||||
symbian:include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
|
||||
QT += xml \
|
||||
svg \
|
||||
network
|
||||
245
Software/sie_cg/block_editor/diagramscene.pro.user
Normal file
245
Software/sie_cg/block_editor/diagramscene.pro.user
Normal file
@@ -0,0 +1,245 @@
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>RunConfiguration0-BaseEnvironmentBase</variable>
|
||||
<value type="int">2</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>RunConfiguration0-CommandLineArguments</variable>
|
||||
<valuelist type="QVariantList"/>
|
||||
</data>
|
||||
<data>
|
||||
<variable>RunConfiguration0-ProFile</variable>
|
||||
<value type="QString">diagramscene.pro</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>RunConfiguration0-RunConfiguration.name</variable>
|
||||
<value type="QString">diagramscene</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>RunConfiguration0-UseDyldImageSuffix</variable>
|
||||
<value type="bool">false</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>RunConfiguration0-UseTerminal</variable>
|
||||
<value type="bool">false</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>RunConfiguration0-UserEnvironmentChanges</variable>
|
||||
<valuelist type="QVariantList"/>
|
||||
</data>
|
||||
<data>
|
||||
<variable>RunConfiguration0-UserSetName</variable>
|
||||
<value type="bool">false</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>RunConfiguration0-UserSetWorkingDirectory</variable>
|
||||
<value type="bool">false</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>RunConfiguration0-UserWorkingDirectory</variable>
|
||||
<value type="QString"></value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>RunConfiguration0-type</variable>
|
||||
<value type="QString">Qt4ProjectManager.Qt4RunConfiguration</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>activeRunConfiguration</variable>
|
||||
<value type="int">0</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>activebuildconfiguration</variable>
|
||||
<value type="QString">Debug</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>buildConfiguration-Debug</variable>
|
||||
<valuemap type="QVariantMap">
|
||||
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value>
|
||||
<value key="QtVersionId" type="int">0</value>
|
||||
<value key="ToolChain" type="int">0</value>
|
||||
<value key="addQDumper" type=""></value>
|
||||
<value key="buildConfiguration" type="int">2</value>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
<variable>buildConfiguration-Release</variable>
|
||||
<valuemap type="QVariantMap">
|
||||
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Release</value>
|
||||
<value key="QtVersionId" type="int">0</value>
|
||||
<value key="addQDumper" type=""></value>
|
||||
<value key="buildConfiguration" type="int">0</value>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
<variable>buildconfiguration-Debug-buildstep0</variable>
|
||||
<valuemap type="QVariantMap">
|
||||
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value>
|
||||
<valuelist key="abstractProcess.Environment" type="QVariantList">
|
||||
<value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-MI4KrAyPP5,guid=5c5c5e6146195c74b6ad266d4cc07afd</value>
|
||||
<value type="QString">DEFAULTS_PATH=/usr/share/gconf/gnome.default.path</value>
|
||||
<value type="QString">DESKTOP_SESSION=gnome</value>
|
||||
<value type="QString">DISPLAY=:0.0</value>
|
||||
<value type="QString">GDMSESSION=gnome</value>
|
||||
<value type="QString">GDM_KEYBOARD_LAYOUT=es</value>
|
||||
<value type="QString">GDM_LANG=en_US.utf8</value>
|
||||
<value type="QString">GNOME_DESKTOP_SESSION_ID=this-is-deprecated</value>
|
||||
<value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-CFAuJK</value>
|
||||
<value type="QString">GNOME_KEYRING_PID=1516</value>
|
||||
<value type="QString">GTK_MODULES=canberra-gtk-module</value>
|
||||
<value type="QString">HOME=/home/juan64bits</value>
|
||||
<value type="QString">LANG=en_US.utf8</value>
|
||||
<value type="QString">LD_LIBRARY_PATH=/usr/lib/qtcreator</value>
|
||||
<value type="QString">LOGNAME=juan64bits</value>
|
||||
<value type="QString">MANDATORY_PATH=/usr/share/gconf/gnome.mandatory.path</value>
|
||||
<value type="QString">ORBIT_SOCKETDIR=/tmp/orbit-juan64bits</value>
|
||||
<value type="QString">PATH=/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games</value>
|
||||
<value type="QString">PWD=/home/juan64bits</value>
|
||||
<value type="QString">QTDIR=/usr/share/qt4</value>
|
||||
<value type="QString">SESSION_MANAGER=local/Maximus:@/tmp/.ICE-unix/1534,unix/Maximus:/tmp/.ICE-unix/1534</value>
|
||||
<value type="QString">SHELL=/bin/bash</value>
|
||||
<value type="QString">SPEECHD_PORT=7560</value>
|
||||
<value type="QString">SSH_AGENT_PID=1570</value>
|
||||
<value type="QString">SSH_AUTH_SOCK=/tmp/keyring-CFAuJK/ssh</value>
|
||||
<value type="QString">USER=juan64bits</value>
|
||||
<value type="QString">USERNAME=juan64bits</value>
|
||||
<value type="QString">XAUTHORITY=/var/run/gdm/auth-for-juan64bits-V4ry7M/database</value>
|
||||
<value type="QString">XDG_CONFIG_DIRS=/etc/xdg/xdg-gnome:/etc/xdg</value>
|
||||
<value type="QString">XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/</value>
|
||||
<value type="QString">XDG_SESSION_COOKIE=b9a7fbc4d869fc15bd6cdd474bcc9a28-1287682812.550485-1725059380</value>
|
||||
</valuelist>
|
||||
<valuelist key="abstractProcess.arguments" type="QVariantList">
|
||||
<value type="QString">/home/juan64bits/QT/diagramscene/block_editor/diagramscene.pro</value>
|
||||
<value type="QString">-spec</value>
|
||||
<value type="QString">linux-g++</value>
|
||||
<value type="QString">-r</value>
|
||||
<value type="QString">CONFIG+=debug</value>
|
||||
</valuelist>
|
||||
<value key="abstractProcess.command" type="QString">/usr/bin/qmake-qt4</value>
|
||||
<value key="abstractProcess.enabled" type="bool">false</value>
|
||||
<value key="abstractProcess.workingDirectory" type="QString">/home/juan64bits/QT/diagramscene/block_editor</value>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
<variable>buildconfiguration-Debug-buildstep1</variable>
|
||||
<valuemap type="QVariantMap">
|
||||
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value>
|
||||
<valuelist key="abstractProcess.Environment" type="QVariantList">
|
||||
<value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-MI4KrAyPP5,guid=5c5c5e6146195c74b6ad266d4cc07afd</value>
|
||||
<value type="QString">DEFAULTS_PATH=/usr/share/gconf/gnome.default.path</value>
|
||||
<value type="QString">DESKTOP_SESSION=gnome</value>
|
||||
<value type="QString">DISPLAY=:0.0</value>
|
||||
<value type="QString">GDMSESSION=gnome</value>
|
||||
<value type="QString">GDM_KEYBOARD_LAYOUT=es</value>
|
||||
<value type="QString">GDM_LANG=en_US.utf8</value>
|
||||
<value type="QString">GNOME_DESKTOP_SESSION_ID=this-is-deprecated</value>
|
||||
<value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-CFAuJK</value>
|
||||
<value type="QString">GNOME_KEYRING_PID=1516</value>
|
||||
<value type="QString">GTK_MODULES=canberra-gtk-module</value>
|
||||
<value type="QString">HOME=/home/juan64bits</value>
|
||||
<value type="QString">LANG=en_US.utf8</value>
|
||||
<value type="QString">LD_LIBRARY_PATH=/usr/lib/qtcreator</value>
|
||||
<value type="QString">LOGNAME=juan64bits</value>
|
||||
<value type="QString">MANDATORY_PATH=/usr/share/gconf/gnome.mandatory.path</value>
|
||||
<value type="QString">ORBIT_SOCKETDIR=/tmp/orbit-juan64bits</value>
|
||||
<value type="QString">PATH=/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games</value>
|
||||
<value type="QString">PWD=/home/juan64bits</value>
|
||||
<value type="QString">QTDIR=/usr/share/qt4</value>
|
||||
<value type="QString">SESSION_MANAGER=local/Maximus:@/tmp/.ICE-unix/1534,unix/Maximus:/tmp/.ICE-unix/1534</value>
|
||||
<value type="QString">SHELL=/bin/bash</value>
|
||||
<value type="QString">SPEECHD_PORT=7560</value>
|
||||
<value type="QString">SSH_AGENT_PID=1570</value>
|
||||
<value type="QString">SSH_AUTH_SOCK=/tmp/keyring-CFAuJK/ssh</value>
|
||||
<value type="QString">USER=juan64bits</value>
|
||||
<value type="QString">USERNAME=juan64bits</value>
|
||||
<value type="QString">XAUTHORITY=/var/run/gdm/auth-for-juan64bits-V4ry7M/database</value>
|
||||
<value type="QString">XDG_CONFIG_DIRS=/etc/xdg/xdg-gnome:/etc/xdg</value>
|
||||
<value type="QString">XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/</value>
|
||||
<value type="QString">XDG_SESSION_COOKIE=b9a7fbc4d869fc15bd6cdd474bcc9a28-1287682812.550485-1725059380</value>
|
||||
</valuelist>
|
||||
<value key="abstractProcess.IgnoreReturnValue" type="bool">false</value>
|
||||
<valuelist key="abstractProcess.arguments" type="QVariantList">
|
||||
<value type="QString">-w</value>
|
||||
</valuelist>
|
||||
<value key="abstractProcess.command" type="QString">/usr/bin/make</value>
|
||||
<value key="abstractProcess.enabled" type="bool">true</value>
|
||||
<value key="abstractProcess.workingDirectory" type="QString">/home/juan64bits/QT/diagramscene/block_editor</value>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
<variable>buildconfiguration-Debug-cleanstep0</variable>
|
||||
<valuemap type="QVariantMap">
|
||||
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value>
|
||||
<value key="cleanConfig" type="bool">true</value>
|
||||
<valuelist key="makeargs" type="QVariantList">
|
||||
<value type="QString">clean</value>
|
||||
</valuelist>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
<variable>buildconfiguration-Release-buildstep0</variable>
|
||||
<valuemap type="QVariantMap">
|
||||
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Release</value>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
<variable>buildconfiguration-Release-buildstep1</variable>
|
||||
<valuemap type="QVariantMap">
|
||||
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Release</value>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
<variable>buildconfiguration-Release-cleanstep0</variable>
|
||||
<valuemap type="QVariantMap">
|
||||
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Release</value>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
<variable>buildconfigurations</variable>
|
||||
<valuelist type="QVariantList">
|
||||
<value type="QString">Debug</value>
|
||||
<value type="QString">Release</value>
|
||||
</valuelist>
|
||||
</data>
|
||||
<data>
|
||||
<variable>buildstep0</variable>
|
||||
<valuemap type="QVariantMap">
|
||||
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString"></value>
|
||||
<value key="mkspec" type="QString"></value>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
<variable>buildstep1</variable>
|
||||
<valuemap type="QVariantMap">
|
||||
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString"></value>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
<variable>buildsteps</variable>
|
||||
<valuelist type="QVariantList">
|
||||
<value type="QString">trolltech.qt4projectmanager.qmake</value>
|
||||
<value type="QString">trolltech.qt4projectmanager.make</value>
|
||||
</valuelist>
|
||||
</data>
|
||||
<data>
|
||||
<variable>cleanstep0</variable>
|
||||
<valuemap type="QVariantMap">
|
||||
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString"></value>
|
||||
<value key="clean" type="bool">true</value>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
<variable>cleansteps</variable>
|
||||
<valuelist type="QVariantList">
|
||||
<value type="QString">trolltech.qt4projectmanager.make</value>
|
||||
</valuelist>
|
||||
</data>
|
||||
<data>
|
||||
<variable>defaultFileEncoding</variable>
|
||||
<value type="QByteArray">System</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>project</variable>
|
||||
<valuemap type="QVariantMap"/>
|
||||
</data>
|
||||
</qtcreator>
|
||||
28
Software/sie_cg/block_editor/diagramscene.qrc
Normal file
28
Software/sie_cg/block_editor/diagramscene.qrc
Normal file
@@ -0,0 +1,28 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>../images/pointer.png</file>
|
||||
<file>../images/linepointer.png</file>
|
||||
<file>../images/textpointer.png</file>
|
||||
<file>../images/bold.png</file>
|
||||
<file>../images/italic.png</file>
|
||||
<file>../images/underline.png</file>
|
||||
<file>../images/floodfill.png</file>
|
||||
<file>../images/bringtofront.png</file>
|
||||
<file>../images/delete.png</file>
|
||||
<file>../images/sendtoback.png</file>
|
||||
<file>../images/linecolor.png</file>
|
||||
<file>../images/background1.png</file>
|
||||
<file>../images/background2.png</file>
|
||||
<file>../images/background3.png</file>
|
||||
<file>../images/background4.png</file>
|
||||
<file>../images/exit.png</file>
|
||||
<file>../images/new.png</file>
|
||||
<file>../images/no.png</file>
|
||||
<file>../images/open.png</file>
|
||||
<file>../images/save.png</file>
|
||||
<file>../images/save_as.png</file>
|
||||
<file>../images/yes.png</file>
|
||||
<file>../images/zoom_in.png</file>
|
||||
<file>../images/zoom_out.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
165
Software/sie_cg/block_editor/diagramtextitem.cpp
Normal file
165
Software/sie_cg/block_editor/diagramtextitem.cpp
Normal file
@@ -0,0 +1,165 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial Usage
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtGui>
|
||||
|
||||
#include "diagramtextitem.h"
|
||||
#include "diagramscene.h"
|
||||
|
||||
DiagramTextItem::DiagramTextItem(
|
||||
QGraphicsItem *parent, QGraphicsScene *scene,
|
||||
bool editable, int styleIO,
|
||||
unsigned char ID, QString defaultText, QPointF offset)
|
||||
: QGraphicsTextItem(parent, scene)
|
||||
{
|
||||
myOwnerScene=scene;
|
||||
myStyleIO = styleIO;
|
||||
myID=ID;
|
||||
editableItem=editable;
|
||||
setPlainText(defaultText);
|
||||
posOffset=offset;
|
||||
//setFlag(QGraphicsItem::ItemIsMovable,0);
|
||||
if(editable)
|
||||
setFlag(QGraphicsItem::ItemIsSelectable,1);
|
||||
else
|
||||
setFlag(QGraphicsItem::ItemIsFocusable,0);
|
||||
|
||||
updatePosition();
|
||||
moving=0;
|
||||
}
|
||||
|
||||
void DiagramTextItem::updatePosition()
|
||||
{
|
||||
if(myStyleIO>255)
|
||||
setPos(posOffset+QPointF(-boundingRect().width()/2,
|
||||
-boundingRect().height()/2));
|
||||
else if(myStyleIO & 0b10000000)
|
||||
setPos(posOffset+QPointF(0,-boundingRect().height()/2));
|
||||
else //OUT
|
||||
setPos(posOffset+QPointF(-boundingRect().width(),
|
||||
-boundingRect().height()/2));
|
||||
}
|
||||
|
||||
QVariant DiagramTextItem::itemChange(GraphicsItemChange change,
|
||||
const QVariant &value)
|
||||
{
|
||||
if (change == QGraphicsItem::ItemSelectedHasChanged)
|
||||
emit selectedChange(this);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void DiagramTextItem::focusOutEvent(QFocusEvent *event)
|
||||
{
|
||||
if(editableItem)
|
||||
{
|
||||
if(toPlainText()=="") setPlainText("?");
|
||||
//updatePosition();
|
||||
setTextInteractionFlags(Qt::NoTextInteraction);
|
||||
emit lostFocus(this);
|
||||
QGraphicsTextItem::focusOutEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
void DiagramTextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if(editableItem)
|
||||
{
|
||||
if (textInteractionFlags() == Qt::NoTextInteraction)
|
||||
setTextInteractionFlags(Qt::TextEditorInteraction);
|
||||
}
|
||||
QGraphicsTextItem::mouseDoubleClickEvent(event);
|
||||
}
|
||||
|
||||
void DiagramTextItem::snapToGrid(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if(myStyleIO!=0xFFF)
|
||||
setOffset(event->scenePos());
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
void DiagramTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
moving=1;
|
||||
//snapToGrid(event);
|
||||
QGraphicsTextItem::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void DiagramTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
moving=0;
|
||||
QGraphicsTextItem::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
void DiagramTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if(moving)
|
||||
snapToGrid(event);
|
||||
|
||||
QGraphicsTextItem::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
QDomElement DiagramTextItem::toXml(QDomDocument &document) const
|
||||
{
|
||||
QDomElement textItem = document.createElement("TextItem");
|
||||
textItem.setAttribute("text",toPlainText());
|
||||
if(myStyleIO<256)
|
||||
{
|
||||
textItem.setAttribute("myStyleIO",myStyleIO);
|
||||
textItem.setAttribute("editableItem",0);
|
||||
}
|
||||
else if (myStyleIO==256)
|
||||
{
|
||||
textItem.setAttribute("myStyleIO",0);
|
||||
textItem.setAttribute("editableItem",0);
|
||||
}
|
||||
else if (myStyleIO==257)
|
||||
{
|
||||
textItem.setAttribute("myStyleIO",0);
|
||||
textItem.setAttribute("editableItem",1);
|
||||
}
|
||||
textItem.setAttribute("posOffset-x",
|
||||
QPointF(posOffset-QPointF(500,500)).x());
|
||||
textItem.setAttribute("posOffset-y",
|
||||
-QPointF(posOffset-QPointF(500,500)).y());
|
||||
return (textItem);
|
||||
}
|
||||
|
||||
118
Software/sie_cg/block_editor/diagramtextitem.h
Normal file
118
Software/sie_cg/block_editor/diagramtextitem.h
Normal file
@@ -0,0 +1,118 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial Usage
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef DIAGRAMTEXTITEM_H
|
||||
#define DIAGRAMTEXTITEM_H
|
||||
|
||||
#include <QGraphicsTextItem>
|
||||
#include <QPen>
|
||||
#include "diagramscene.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QFocusEvent;
|
||||
class QGraphicsItem;
|
||||
class QGraphicsScene;
|
||||
class QGraphicsSceneMouseEvent;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class DiagramTextItem : public QGraphicsTextItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum { Type = UserType + 3 };
|
||||
|
||||
DiagramTextItem(
|
||||
QGraphicsItem *parent = 0, QGraphicsScene *scene = 0,
|
||||
bool editable =1, int styleIO = 0,
|
||||
unsigned char ID=0, QString defaultText="<text>",
|
||||
QPointF offset=QPointF(0,0));
|
||||
|
||||
int type() const
|
||||
{ return Type;}
|
||||
|
||||
int styleIO()
|
||||
{ return myStyleIO;}
|
||||
|
||||
unsigned char ID()
|
||||
{ return myID;}
|
||||
|
||||
unsigned char textID() const
|
||||
{ return myID;}
|
||||
|
||||
QPointF offset() const
|
||||
{ return posOffset;}
|
||||
|
||||
void setOffset(QPointF offset)
|
||||
{ posOffset=offset;}
|
||||
|
||||
bool isEditable()
|
||||
{ return editableItem;}
|
||||
|
||||
void snapToGrid(QGraphicsSceneMouseEvent *event);
|
||||
|
||||
QDomElement toXml(QDomDocument &document) const;
|
||||
|
||||
public slots:
|
||||
void updatePosition();
|
||||
|
||||
signals:
|
||||
void lostFocus(DiagramTextItem *item);
|
||||
void selectedChange(QGraphicsItem *item);
|
||||
|
||||
protected:
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||
void focusOutEvent(QFocusEvent *event);
|
||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||
|
||||
private:
|
||||
bool editableItem;
|
||||
QPointF posOffset;
|
||||
int myStyleIO;
|
||||
unsigned char myID;
|
||||
QGraphicsScene *myOwnerScene;
|
||||
bool moving;
|
||||
};
|
||||
|
||||
#endif
|
||||
140
Software/sie_cg/block_editor/lineitem.cpp
Normal file
140
Software/sie_cg/block_editor/lineitem.cpp
Normal file
@@ -0,0 +1,140 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial Usage
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtGui>
|
||||
|
||||
#include "lineitem.h"
|
||||
#include <math.h>
|
||||
|
||||
lineItem::lineItem(QPointF startPoint, QPointF endItem, Arrow *ownerArrow,
|
||||
int wt, bool movable, QGraphicsItem *parent, QGraphicsScene *scene)
|
||||
: QGraphicsLineItem(parent, scene)
|
||||
{
|
||||
isMovable=movable;
|
||||
if(isMovable)
|
||||
{
|
||||
setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||
}
|
||||
|
||||
setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||
|
||||
myColor = Qt::black;
|
||||
setPen(QPen(myColor, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||
setLine(QLineF(startPoint,endItem));
|
||||
myOwnerArrow = ownerArrow;
|
||||
pWidth=wt;
|
||||
moveItem=0;
|
||||
}
|
||||
|
||||
QRectF lineItem::boundingRect() const
|
||||
{
|
||||
qreal extra = (pen().width() + 20) / 2.0;
|
||||
|
||||
return QRectF(line().p1(), QSizeF(line().p2().x() - line().p1().x(),
|
||||
line().p2().y() - line().p1().y()))
|
||||
.normalized()
|
||||
.adjusted(-extra, -extra, extra, extra);
|
||||
}
|
||||
|
||||
QPainterPath lineItem::shape() const
|
||||
{
|
||||
QPainterPath path = QGraphicsLineItem::shape();
|
||||
return path;
|
||||
}
|
||||
|
||||
void lineItem::updatePos()
|
||||
{
|
||||
QPointF itemPos = this->line().p1()+QPointF(0.5,0.5);
|
||||
myOwnerArrow->moveCorner(itemPos,this);
|
||||
}
|
||||
|
||||
void lineItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *,
|
||||
QWidget *)
|
||||
{
|
||||
QPen myPen = pen();
|
||||
myPen.setColor(myColor);
|
||||
myPen.setWidth(pWidth);
|
||||
painter->setPen(myPen);
|
||||
painter->setBrush(myColor);
|
||||
|
||||
setLine(line());
|
||||
painter->drawLine(line());
|
||||
|
||||
//Drawing arrow selected
|
||||
if (isSelected()) {
|
||||
painter->setPen(QPen(Qt::gray, pWidth, Qt::SolidLine));
|
||||
QLineF myLine = line();
|
||||
painter->drawLine(myLine);
|
||||
}
|
||||
}
|
||||
|
||||
void lineItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||
{
|
||||
if(!isMovable)
|
||||
{
|
||||
myOwnerArrow->createCorner(mouseEvent->scenePos(),this);
|
||||
}
|
||||
QGraphicsLineItem::mouseDoubleClickEvent(mouseEvent);
|
||||
}
|
||||
|
||||
|
||||
void lineItem::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||
{
|
||||
QGraphicsLineItem::mousePressEvent(mouseEvent);
|
||||
}
|
||||
|
||||
void lineItem::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||
{
|
||||
if(isMovable)
|
||||
{
|
||||
updatePos();
|
||||
}
|
||||
QGraphicsLineItem::mouseMoveEvent(mouseEvent);
|
||||
}
|
||||
|
||||
void lineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||
{
|
||||
if(isMovable)
|
||||
{
|
||||
updatePos();
|
||||
}
|
||||
QGraphicsLineItem::mouseReleaseEvent(mouseEvent);
|
||||
}
|
||||
96
Software/sie_cg/block_editor/lineitem.h
Normal file
96
Software/sie_cg/block_editor/lineitem.h
Normal file
@@ -0,0 +1,96 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial Usage
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef LINEITEM_H
|
||||
#define LINEITEM_H
|
||||
|
||||
#include <QGraphicsLineItem>
|
||||
#include "arrow.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QGraphicsPolygonItem;
|
||||
class QGraphicsLineItem;
|
||||
class QGraphicsScene;
|
||||
class QRectF;
|
||||
class QGraphicsSceneMouseEvent;
|
||||
class QPainterPath;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class lineItem : public QGraphicsLineItem
|
||||
{
|
||||
public:
|
||||
enum { Type = UserType + 4 };
|
||||
|
||||
lineItem(QPointF startPoint, QPointF endItem, Arrow *ownerArrow, int wt=2,
|
||||
bool movable = 0, QGraphicsItem *parent = 0, QGraphicsScene *scene = 0);
|
||||
|
||||
int type() const
|
||||
{ return Type;}
|
||||
QRectF boundingRect() const;
|
||||
QPainterPath shape() const;
|
||||
void setColor(const QColor &color)
|
||||
{ myColor=color; }
|
||||
|
||||
Arrow * myOwner()
|
||||
{ return myOwnerArrow;}
|
||||
|
||||
bool itemIsMovable() {return isMovable;}
|
||||
|
||||
public slots:
|
||||
void updatePos();
|
||||
|
||||
protected:
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget = 0);
|
||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||
|
||||
private:
|
||||
QColor myColor;
|
||||
int pWidth;
|
||||
Arrow *myOwnerArrow;
|
||||
int moveItem;
|
||||
bool isMovable;
|
||||
};
|
||||
|
||||
#endif
|
||||
55
Software/sie_cg/block_editor/main.cpp
Normal file
55
Software/sie_cg/block_editor/main.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial Usage
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtGui>
|
||||
|
||||
#include "mainwindow.h"
|
||||
|
||||
int main(int argv, char *args[])
|
||||
{
|
||||
Q_INIT_RESOURCE(diagramscene);
|
||||
|
||||
QApplication app(argv, args);
|
||||
MainWindow mainWindow;
|
||||
mainWindow.setGeometry(100, 100, 1024, 640);
|
||||
mainWindow.show();
|
||||
return app.exec();
|
||||
}
|
||||
413
Software/sie_cg/block_editor/mainwindow.cpp
Normal file
413
Software/sie_cg/block_editor/mainwindow.cpp
Normal file
@@ -0,0 +1,413 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial Usage
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtGui>
|
||||
#include <QLabel>
|
||||
|
||||
#include "mainwindow.h"
|
||||
|
||||
const int InsertTextButton = 10;
|
||||
|
||||
MainWindow::MainWindow()
|
||||
{
|
||||
createActions();
|
||||
createToolBox();
|
||||
createMenus();
|
||||
|
||||
scene = new DiagramScene(itemMenu);
|
||||
scene->setSceneRect(QRectF(0, 0, 1000, 1000));
|
||||
connect(scene, SIGNAL(textInserted(QGraphicsTextItem*)),
|
||||
this, SLOT(textInserted(QGraphicsTextItem*)));
|
||||
|
||||
createToolbars();
|
||||
|
||||
QHBoxLayout *layout = new QHBoxLayout;
|
||||
layout->addWidget(toolBox);
|
||||
view = new QGraphicsView(scene);
|
||||
layout->addWidget(view);
|
||||
|
||||
QWidget *widget = new QWidget;
|
||||
widget->setLayout(layout);
|
||||
|
||||
setCentralWidget(widget);
|
||||
setWindowTitle(tr("SIE Code Generator (Block Editor)"));
|
||||
setUnifiedTitleAndToolBarOnMac(true);
|
||||
myFilePath = "";
|
||||
|
||||
if(QApplication::argc()>1)
|
||||
{newDiagram(QString(QApplication::argv()[1]));}
|
||||
}
|
||||
|
||||
void MainWindow::deleteItem()
|
||||
{
|
||||
foreach (QGraphicsItem *item, scene->selectedItems())
|
||||
{
|
||||
if (item->type() == Arrow::Type) {
|
||||
qgraphicsitem_cast<Arrow *>(item)->removeLines();
|
||||
scene->removeItem(item);
|
||||
delete(item);
|
||||
}
|
||||
//If line is deleted then is romoved from the arrow owner
|
||||
else if (item->type() == lineItem::Type &&
|
||||
!qgraphicsitem_cast<lineItem *>(item)->itemIsMovable()) {
|
||||
|
||||
qgraphicsitem_cast<lineItem *>(item)->myOwner()->removeLine(
|
||||
qgraphicsitem_cast<lineItem *>(item));
|
||||
qgraphicsitem_cast<lineItem *>(item)->myOwner()->updatePosition();
|
||||
scene->removeItem(item);
|
||||
delete(item);
|
||||
}
|
||||
else if (item->type() == DiagramTextItem::Type) {
|
||||
if(qgraphicsitem_cast<DiagramTextItem *>(item)->styleIO()!=0xFFF)
|
||||
{
|
||||
scene->removeTextItem(qgraphicsitem_cast
|
||||
<DiagramTextItem *>(item));
|
||||
scene->removeItem(item);
|
||||
delete(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::textInserted(QGraphicsTextItem*)
|
||||
{
|
||||
buttonGroup->button(selectedButton)->setChecked(false);
|
||||
scene->setMode(DiagramScene::MoveItem);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::sceneScaleChanged(const QString &scale)
|
||||
{
|
||||
double newScale = scale.left(scale.indexOf(tr("%"))).toDouble() / 100.0;
|
||||
QMatrix oldMatrix = view->matrix();
|
||||
view->resetMatrix();
|
||||
view->translate(oldMatrix.dx(), oldMatrix.dy());
|
||||
view->scale(newScale, newScale);
|
||||
}
|
||||
|
||||
void MainWindow::about()
|
||||
{
|
||||
QMessageBox::question(this, tr("About SIE Code Generator"),
|
||||
tr("TODO <b>:)</b>"));
|
||||
}
|
||||
|
||||
QWidget *MainWindow::createToolButton(int ID, QString type, QIcon icon)
|
||||
{
|
||||
QToolButton *button = new QToolButton;
|
||||
button->setIcon(icon);
|
||||
button->setIconSize(QSize(50, 50));
|
||||
button->setCheckable(true);
|
||||
button->setText(type);
|
||||
buttonGroup->addButton(button,ID);
|
||||
|
||||
QGridLayout *layout = new QGridLayout;
|
||||
layout->addWidget(button, 0, 0, Qt::AlignHCenter);
|
||||
layout->addWidget(new QLabel(type), 1, 0, Qt::AlignCenter);
|
||||
|
||||
QWidget *widget = new QWidget;
|
||||
widget->setLayout(layout);
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
void MainWindow::createToolBox()
|
||||
{
|
||||
buttonGroup = new QButtonGroup;
|
||||
buttonGroup->setExclusive(false);
|
||||
connect(buttonGroup, SIGNAL(buttonClicked(int)),
|
||||
this, SLOT(buttonGroupClicked(int)));
|
||||
|
||||
QGridLayout *layout = new QGridLayout;
|
||||
//INPUTS
|
||||
int i=0;
|
||||
layout->addWidget(createToolButton(129+i,tr("Bool"),
|
||||
QIcon(":/images/background1.png")),++i,0);
|
||||
layout->addWidget(createToolButton(129+i,tr("Char"),
|
||||
QIcon(":/images/background1.png")),++i,0);
|
||||
layout->addWidget(createToolButton(129+i,tr("Integer"),
|
||||
QIcon(":/images/background1.png")),++i,0);
|
||||
layout->addWidget(createToolButton(129+i,tr("Double"),
|
||||
QIcon(":/images/background1.png")),++i,0);
|
||||
layout->addWidget(createToolButton(129+i,tr("Float"),
|
||||
QIcon(":/images/background1.png")),++i,0);
|
||||
|
||||
//OUTPUTS
|
||||
i=0;
|
||||
layout->addWidget(createToolButton(i,tr("Bool"),
|
||||
QIcon(":/images/background3.png")),++i,1);
|
||||
layout->addWidget(createToolButton(i,tr("Char"),
|
||||
QIcon(":/images/background3.png")),++i,1);
|
||||
layout->addWidget(createToolButton(i,tr("Integer"),
|
||||
QIcon(":/images/background3.png")),++i,1);
|
||||
layout->addWidget(createToolButton(i,tr("Double"),
|
||||
QIcon(":/images/background3.png")),++i,1);
|
||||
layout->addWidget(createToolButton(i,tr("Float"),
|
||||
QIcon(":/images/background3.png")),++i,1);
|
||||
|
||||
layout->setRowStretch(3, 10);
|
||||
layout->setColumnStretch(2, 10);
|
||||
QWidget *ioWidget = new QWidget;
|
||||
ioWidget->setLayout(layout);
|
||||
|
||||
layout = new QGridLayout;
|
||||
//Labels
|
||||
layout->addWidget(createToolButton(256,tr("Label"),
|
||||
QIcon(":/images/background4.png")),0,0);
|
||||
//Values
|
||||
layout->addWidget(createToolButton(257,tr("Value"),
|
||||
QIcon(":/images/background4.png")),0,1);
|
||||
|
||||
//Polygon
|
||||
layout->addWidget(createToolButton(258,tr("Polygon"),
|
||||
QIcon(":/images/background2.png")),1,0);
|
||||
|
||||
layout->setRowStretch(3, 10);
|
||||
layout->setColumnStretch(2, 10);
|
||||
QWidget *labelWidget = new QWidget;
|
||||
labelWidget->setLayout(layout);
|
||||
|
||||
|
||||
toolBox = new QToolBox;
|
||||
toolBox->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Ignored));
|
||||
toolBox->setMinimumWidth(labelWidget->sizeHint().width());
|
||||
toolBox->addItem(labelWidget, tr("Basic draw"));
|
||||
toolBox->addItem(ioWidget, tr("Inputs/Outputs"));
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::buttonGroupClicked(int id)
|
||||
{
|
||||
QList<QAbstractButton *> buttons = buttonGroup->buttons();
|
||||
foreach (QAbstractButton *button, buttons)
|
||||
{if (buttonGroup->button(id) != button) button->setChecked(false);}
|
||||
selectedButton=id;
|
||||
|
||||
if(id==258)
|
||||
{ //Polygon edition
|
||||
scene->setMode(DiagramScene::EditPolygon);
|
||||
} else {
|
||||
scene->setMode(DiagramScene::InsertText);
|
||||
}
|
||||
|
||||
scene->setTextType(id,buttonGroup->button(id)->text());
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::createActions()
|
||||
{
|
||||
|
||||
deleteAction = new QAction(QIcon(":/images/delete.png"),
|
||||
tr("&Delete"), this);
|
||||
deleteAction->setShortcut(tr("Ctrl+Delete"));
|
||||
deleteAction->setStatusTip(tr("Delete item from diagram"));
|
||||
connect(deleteAction, SIGNAL(triggered()),
|
||||
this, SLOT(deleteItem()));
|
||||
|
||||
|
||||
newAction = new QAction(QIcon(":/images/new.png"),tr("&New"),this);
|
||||
newAction->setShortcuts(QKeySequence::New);
|
||||
newAction->setStatusTip("New diagram");
|
||||
connect(newAction,SIGNAL(triggered()),this,SLOT(newDiagram()));
|
||||
|
||||
saveAction = new QAction(QIcon(":/images/save.png"),tr("&Save"),this);
|
||||
saveAction->setShortcuts(QKeySequence::Save);
|
||||
saveAction->setStatusTip("Save current diagram");
|
||||
connect(saveAction,SIGNAL(triggered()),this,SLOT(saveDiagram()));
|
||||
|
||||
saveAsAction = new QAction(QIcon(":/images/save_as.png"),
|
||||
tr("Save &As..."),this);
|
||||
saveAsAction->setShortcuts(QKeySequence::SaveAs);
|
||||
saveAsAction->setStatusTip("Save current diagram with another name");
|
||||
connect(saveAsAction,SIGNAL(triggered()),this,SLOT(saveAsDiagram()));
|
||||
|
||||
openAction = new QAction(QIcon(":/images/open.png"),tr("&Open"),this);
|
||||
openAction->setShortcuts(QKeySequence::Open);
|
||||
openAction->setStatusTip("Open diagram");
|
||||
connect(openAction,SIGNAL(triggered()),this,SLOT(openDiagram()));
|
||||
|
||||
exitAction = new QAction(tr("E&xit"), this);
|
||||
exitAction->setShortcuts(QKeySequence::Quit);
|
||||
exitAction->setStatusTip(tr("Quit diagram editor"));
|
||||
connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
|
||||
|
||||
aboutAction = new QAction(tr("A&bout"), this);
|
||||
aboutAction->setShortcut(tr("Ctrl+B"));
|
||||
connect(aboutAction, SIGNAL(triggered()),
|
||||
this, SLOT(about()));
|
||||
}
|
||||
|
||||
void MainWindow::createMenus()
|
||||
{
|
||||
fileMenu = menuBar()->addMenu(tr("&File"));
|
||||
fileMenu->addAction(newAction);
|
||||
fileMenu->addAction(openAction);
|
||||
fileMenu->addSeparator();
|
||||
fileMenu->addAction(saveAction);
|
||||
fileMenu->addAction(saveAsAction);
|
||||
fileMenu->addSeparator();
|
||||
fileMenu->addAction(exitAction);
|
||||
|
||||
itemMenu = menuBar()->addMenu(tr("&Item"));
|
||||
itemMenu->addAction(deleteAction);
|
||||
|
||||
aboutMenu = menuBar()->addMenu(tr("&Help"));
|
||||
aboutMenu->addAction(aboutAction);
|
||||
}
|
||||
|
||||
void MainWindow::createToolbars()
|
||||
{
|
||||
fileToolBar = addToolBar(tr("File"));
|
||||
fileToolBar->addAction(newAction);
|
||||
fileToolBar->addAction(openAction);
|
||||
fileToolBar->addAction(saveAction);
|
||||
|
||||
editToolBar = addToolBar(tr("Edit"));
|
||||
editToolBar->addAction(deleteAction);
|
||||
|
||||
sceneScaleCombo = new QComboBox;
|
||||
QStringList scales;
|
||||
scales << tr("75%") << tr("100%") << tr("125%") << tr("150%") << tr("175%");
|
||||
sceneScaleCombo->addItems(scales);
|
||||
sceneScaleCombo->setCurrentIndex(1);
|
||||
connect(sceneScaleCombo, SIGNAL(currentIndexChanged(QString)),
|
||||
this, SLOT(sceneScaleChanged(QString)));
|
||||
|
||||
editToolBar->addWidget(sceneScaleCombo);
|
||||
}
|
||||
|
||||
bool MainWindow::newDiagram(QString filePath)
|
||||
{
|
||||
saveIfNeeded();
|
||||
scene->cleanScene();
|
||||
myFilePath="";
|
||||
|
||||
if(filePath=="")
|
||||
return 0;
|
||||
|
||||
myFilePath=filePath;
|
||||
QFile file(myFilePath);
|
||||
if(file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
QDomDocument document;
|
||||
bool parsing=document.setContent(&file);
|
||||
file.close();
|
||||
if(!parsing)
|
||||
{
|
||||
QMessageBox::warning(this,"Aborting","Failed to parse file, "
|
||||
"wrong format or encoding.");
|
||||
return 0;
|
||||
}
|
||||
scene->fromXmlFormat(document);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
QMessageBox::critical(this,"Error","Could not open file for read.");
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::saveIfNeeded()
|
||||
{
|
||||
if(myFilePath!="" || scene->items().count()>0)
|
||||
{}//TODO save opened or modified diagram
|
||||
}
|
||||
|
||||
bool MainWindow::openDiagram()
|
||||
{
|
||||
QString
|
||||
filePath = QFileDialog::getOpenFileName(this,"Open",
|
||||
currentDir(),"Custom item for SIE code generator (*.die)");
|
||||
|
||||
if(filePath.isEmpty())
|
||||
return 0;
|
||||
|
||||
if(!QFileInfo(filePath).isReadable())
|
||||
{
|
||||
QMessageBox::critical(this,"Error","File is not readable "
|
||||
" or not exists.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
newDiagram(filePath);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool MainWindow::saveDiagram()
|
||||
{
|
||||
if(myFilePath=="")
|
||||
{
|
||||
saveAsDiagram();
|
||||
return 0;
|
||||
}
|
||||
if(!QFileInfo(myFilePath).isWritable() && QFileInfo(myFilePath).exists())
|
||||
{
|
||||
QMessageBox::critical(this,"Error","File is not writable.");
|
||||
return 0;
|
||||
}
|
||||
QFile file(myFilePath);
|
||||
if(file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
{
|
||||
QDomDocument document = scene->toXmlFormat();
|
||||
QTextStream out(&file);
|
||||
out.setCodec("UTF-8");
|
||||
out << document.toString(4);
|
||||
file.close();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
QMessageBox::critical(this,"Error","Could not open file for write.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool MainWindow::saveAsDiagram()
|
||||
{
|
||||
QString filePath = QFileDialog::getSaveFileName(this,"Save as...",
|
||||
currentDir(),"Custom item for SIE code generator (*.die)");
|
||||
|
||||
if(!filePath.isEmpty())
|
||||
{
|
||||
myFilePath = filePath;
|
||||
saveDiagram();
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
136
Software/sie_cg/block_editor/mainwindow.h
Normal file
136
Software/sie_cg/block_editor/mainwindow.h
Normal file
@@ -0,0 +1,136 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial Usage
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QDir>
|
||||
#include <QtXml>
|
||||
|
||||
#include "diagramscene.h"
|
||||
#include "diagramtextitem.h"
|
||||
#include "lineitem.h"
|
||||
#include "arrow.h"
|
||||
|
||||
class DiagramScene;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QAction;
|
||||
class QToolBox;
|
||||
class QSpinBox;
|
||||
class QComboBox;
|
||||
class QFontComboBox;
|
||||
class QButtonGroup;
|
||||
class QLineEdit;
|
||||
class QGraphicsTextItem;
|
||||
class QFont;
|
||||
class QToolButton;
|
||||
class QAbstractButton;
|
||||
class QGraphicsView;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow();
|
||||
QString filePath() const
|
||||
{ return myFilePath;}
|
||||
QString currentDir() const
|
||||
{ return QDir::currentPath();}
|
||||
|
||||
void saveIfNeeded();
|
||||
|
||||
private slots:
|
||||
void deleteItem();
|
||||
void sceneScaleChanged(const QString &scale);
|
||||
void about();
|
||||
bool newDiagram(QString pathFile="");
|
||||
bool openDiagram();
|
||||
bool saveDiagram();
|
||||
bool saveAsDiagram();
|
||||
void buttonGroupClicked(int id);
|
||||
void textInserted(QGraphicsTextItem*);
|
||||
|
||||
private:
|
||||
void createToolBox();
|
||||
void createActions();
|
||||
void createMenus();
|
||||
void createToolbars();
|
||||
QWidget *createToolButton(int ID, QString type,QIcon icon);
|
||||
|
||||
DiagramScene *scene;
|
||||
QGraphicsView *view;
|
||||
|
||||
QAction *newAction;
|
||||
QAction *saveAction;
|
||||
QAction *saveAsAction;
|
||||
QAction *openAction;
|
||||
|
||||
QAction *exitAction;
|
||||
QAction *addAction;
|
||||
QAction *deleteAction;
|
||||
|
||||
QAction *aboutAction;
|
||||
|
||||
QMenu *fileMenu;
|
||||
QMenu *itemMenu;
|
||||
QMenu *aboutMenu;
|
||||
|
||||
QToolBar *fileToolBar;
|
||||
QToolBar *editToolBar;
|
||||
|
||||
QToolBox *toolBox;
|
||||
|
||||
QComboBox *sceneScaleCombo;
|
||||
|
||||
QButtonGroup *buttonGroup;
|
||||
|
||||
int selectedButton;
|
||||
|
||||
QString myFilePath;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
18
Software/sie_cg/block_editor/test_block1.die
Normal file
18
Software/sie_cg/block_editor/test_block1.die
Normal file
@@ -0,0 +1,18 @@
|
||||
<!--File for SIE Code Generator. Custmos Blocks-->
|
||||
<CustomItem BlockName="Test Block 1">
|
||||
<Polygon>
|
||||
<Point x="-120" y="0"/>
|
||||
<Point x="-70" y="-50"/>
|
||||
<Point x="90" y="-50"/>
|
||||
<Point x="140" y="0"/>
|
||||
<Point x="90" y="50"/>
|
||||
<Point x="-70" y="50"/>
|
||||
</Polygon>
|
||||
<TextItems>
|
||||
<TextItem myStyleIO="0" posOffset-y="-30" editableItem="0" ID="0" text="Value" posOffset-x="-40"/>
|
||||
<TextItem myStyleIO="0" posOffset-y="-30" editableItem="1" ID="1" text="0.001" posOffset-x="40"/>
|
||||
<TextItem myStyleIO="2" posOffset-y="-0" editableItem="0" ID="3" text="OUT Char " posOffset-x="140"/>
|
||||
<TextItem myStyleIO="130" posOffset-y="-0" editableItem="0" ID="4" text=" IN Bool" posOffset-x="-120"/>
|
||||
<TextItem myStyleIO="0" posOffset-y="30" editableItem="0" ID="2" text="Test Block 1" posOffset-x="0"/>
|
||||
</TextItems>
|
||||
</CustomItem>
|
||||
15
Software/sie_cg/block_editor/test_block2.die
Normal file
15
Software/sie_cg/block_editor/test_block2.die
Normal file
@@ -0,0 +1,15 @@
|
||||
<!--File for SIE Code Generator. Custmos Blocks-->
|
||||
<CustomItem BlockName="Test Block 2">
|
||||
<Polygon>
|
||||
<Point x="-50" y="-20"/>
|
||||
<Point x="-30" y="0"/>
|
||||
<Point x="-50" y="20"/>
|
||||
<Point x="30" y="20"/>
|
||||
<Point x="60" y="0"/>
|
||||
<Point x="40" y="-20"/>
|
||||
</Polygon>
|
||||
<TextItems>
|
||||
<TextItem myStyleIO="130" posOffset-y="-0" editableItem="0" ID="1" text=" IN Bool" posOffset-x="-30"/>
|
||||
<TextItem myStyleIO="0" posOffset-y="30" editableItem="0" ID="0" text="Test Block 2" posOffset-x="-10"/>
|
||||
</TextItems>
|
||||
</CustomItem>
|
||||
15
Software/sie_cg/block_editor/test_block3.die
Normal file
15
Software/sie_cg/block_editor/test_block3.die
Normal file
@@ -0,0 +1,15 @@
|
||||
<!--File for SIE Code Generator. Custmos Blocks-->
|
||||
<CustomItem BlockName="Test Block 3">
|
||||
<Polygon>
|
||||
<Point x="-30" y="0"/>
|
||||
<Point x="-50" y="20"/>
|
||||
<Point x="50" y="20"/>
|
||||
<Point x="70" y="0"/>
|
||||
<Point x="50" y="-20"/>
|
||||
<Point x="-50" y="-20"/>
|
||||
</Polygon>
|
||||
<TextItems>
|
||||
<TextItem myStyleIO="0" posOffset-y="30" editableItem="0" ID="1" text="Test Block 3" posOffset-x="0"/>
|
||||
<TextItem myStyleIO="1" posOffset-y="-0" editableItem="0" ID="0" text="OUT Bool " posOffset-x="60"/>
|
||||
</TextItems>
|
||||
</CustomItem>
|
||||
29
Software/sie_cg/block_editor/test_block4.die
Normal file
29
Software/sie_cg/block_editor/test_block4.die
Normal file
@@ -0,0 +1,29 @@
|
||||
<!--File for SIE Code Generator. Custmos Blocks-->
|
||||
<CustomItem BlockName="BLOCK NAME HERE (not visible)">
|
||||
<Polygon>
|
||||
<Point x="-60" y="100"/>
|
||||
<Point x="100" y="100"/>
|
||||
<Point x="100" y="60"/>
|
||||
<Point x="50" y="60"/>
|
||||
<Point x="50" y="20"/>
|
||||
<Point x="100" y="20"/>
|
||||
<Point x="100" y="-10"/>
|
||||
<Point x="100" y="-20"/>
|
||||
<Point x="50" y="-20"/>
|
||||
<Point x="50" y="-40"/>
|
||||
<Point x="50" y="-60"/>
|
||||
<Point x="100" y="-60"/>
|
||||
<Point x="100" y="-100"/>
|
||||
<Point x="-60" y="-100"/>
|
||||
<Point x="-60" y="-20"/>
|
||||
<Point x="-100" y="-20"/>
|
||||
<Point x="-100" y="20"/>
|
||||
<Point x="-60" y="20"/>
|
||||
</Polygon>
|
||||
<TextItems>
|
||||
<TextItem myStyleIO="1" posOffset-y="-80" editableItem="0" ID="8" text="OUT Bool" posOffset-x="100"/>
|
||||
<TextItem myStyleIO="1" posOffset-y="-0" editableItem="0" ID="1" text="OUT Bool" posOffset-x="100"/>
|
||||
<TextItem myStyleIO="1" posOffset-y="80" editableItem="0" ID="6" text="OUT Bool" posOffset-x="100"/>
|
||||
<TextItem myStyleIO="130" posOffset-y="-0" editableItem="0" ID="5" text="IN Bool" posOffset-x="-100"/>
|
||||
</TextItems>
|
||||
</CustomItem>
|
||||
Reference in New Issue
Block a user