mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-16 10:08:36 +03:00
- covering Qt warnings for compilation under MSVC 2013 and greater - avoid warning about 'M_PI'(and others) redefinition warning of math.h: includes of QtWidgets should follow after other includes.
175 lines
5.1 KiB
C++
175 lines
5.1 KiB
C++
/****************************************************************************
|
|
**
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
|
** Contact: http://www.qt-project.org/legal
|
|
**
|
|
** This file is part of the examples of the Qt Toolkit.
|
|
**
|
|
** $QT_BEGIN_LICENSE:BSD$
|
|
** You may use this file under the terms of the BSD license as follows:
|
|
**
|
|
** "Redistribution and use in source and binary forms, with or without
|
|
** modification, are permitted provided that the following conditions are
|
|
** met:
|
|
** * Redistributions of source code must retain the above copyright
|
|
** notice, this list of conditions and the following disclaimer.
|
|
** * Redistributions in binary form must reproduce the above copyright
|
|
** notice, this list of conditions and the following disclaimer in
|
|
** the documentation and/or other materials provided with the
|
|
** distribution.
|
|
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
|
|
** of its contributors may be used to endorse or promote products derived
|
|
** from this software without specific prior written permission.
|
|
**
|
|
**
|
|
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
|
**
|
|
** $QT_END_LICENSE$
|
|
**
|
|
****************************************************************************/
|
|
|
|
#include <Standard_WarningsDisable.hxx>
|
|
#include <QGraphicsScene>
|
|
#include <QGraphicsSceneMouseEvent>
|
|
#include <QPainter>
|
|
#include <QStyleOption>
|
|
#include <Standard_WarningsRestore.hxx>
|
|
|
|
#include "edge.h"
|
|
#include "node.h"
|
|
#include "graphwidget.h"
|
|
|
|
#include <TFunction_IFunction.hxx>
|
|
#include <TFunction_GraphNode.hxx>
|
|
#include <TDataStd_Name.hxx>
|
|
#include <TDataStd_Tick.hxx>
|
|
|
|
Node::Node(GraphWidget *graphWidget)
|
|
: graph(graphWidget)
|
|
{
|
|
setFlag(ItemIsMovable);
|
|
setZValue(1);
|
|
}
|
|
|
|
void Node::setFunction(const TDF_Label& func)
|
|
{
|
|
myFunction = func;
|
|
}
|
|
|
|
const TDF_Label& Node::getFunction() const
|
|
{
|
|
return myFunction;
|
|
}
|
|
|
|
void Node::addEdge(Edge *edge)
|
|
{
|
|
edgeList << edge;
|
|
edge->adjust();
|
|
}
|
|
|
|
QList<Edge *> Node::edges() const
|
|
{
|
|
return edgeList;
|
|
}
|
|
|
|
QRectF Node::boundingRect() const
|
|
{
|
|
qreal adjust = 2;
|
|
return QRectF(-15 - adjust, -15 - adjust,
|
|
33 + adjust, 33 + adjust);
|
|
}
|
|
|
|
QPainterPath Node::shape() const
|
|
{
|
|
QPainterPath path;
|
|
path.addEllipse(-15, -15, 30, 30);
|
|
return path;
|
|
}
|
|
|
|
void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
|
|
{
|
|
painter->setPen(Qt::NoPen);
|
|
painter->setBrush(Qt::darkGray);
|
|
painter->drawEllipse(-12, -12, 30, 30);
|
|
|
|
QColor light_color(Qt::yellow);
|
|
TFunction_IFunction iFunc(myFunction);
|
|
Handle(TFunction_GraphNode) graphNode = iFunc.GetGraphNode();
|
|
TFunction_ExecutionStatus status = graphNode->GetStatus();
|
|
switch (status)
|
|
{
|
|
case TFunction_ES_WrongDefinition:
|
|
case TFunction_ES_Failed:
|
|
light_color = Qt::red;
|
|
break;
|
|
case TFunction_ES_NotExecuted:
|
|
light_color = Qt::green;
|
|
break;
|
|
case TFunction_ES_Executing:
|
|
light_color = Qt::yellow;
|
|
break;
|
|
case TFunction_ES_Succeeded:
|
|
light_color = Qt::blue;
|
|
break;
|
|
}
|
|
if (myFunction.IsAttribute(TDataStd_Tick::GetID()))
|
|
light_color = Qt::white;
|
|
QColor dark_color = light_color.dark(150);
|
|
|
|
QRadialGradient gradient(-3, -3, 10);
|
|
if (option->state & QStyle::State_Sunken) {
|
|
gradient.setCenter(3, 3);
|
|
gradient.setFocalPoint(3, 3);
|
|
gradient.setColorAt(1, light_color.light(120));
|
|
gradient.setColorAt(0, dark_color.light(120));
|
|
} else {
|
|
gradient.setColorAt(0, light_color);
|
|
gradient.setColorAt(1, dark_color);
|
|
}
|
|
painter->setBrush(gradient);
|
|
painter->setPen(QPen(Qt::black, 0));
|
|
painter->drawEllipse(-15, -15, 30, 30);
|
|
|
|
QString s;
|
|
Handle(TDataStd_Name) n;
|
|
if (myFunction.FindAttribute(TDataStd_Name::GetID(), n))
|
|
s = TCollection_AsciiString(n->Get()).ToCString();
|
|
painter->drawText(-7, 3, s);
|
|
}
|
|
|
|
QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value)
|
|
{
|
|
switch (change) {
|
|
case ItemPositionChange:
|
|
foreach (Edge *edge, edgeList)
|
|
edge->adjust();
|
|
break;
|
|
default:
|
|
break;
|
|
};
|
|
|
|
return QGraphicsItem::itemChange(change, value);
|
|
}
|
|
|
|
void Node::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
{
|
|
update();
|
|
QGraphicsItem::mousePressEvent(event);
|
|
}
|
|
|
|
void Node::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
{
|
|
update();
|
|
QGraphicsItem::mouseReleaseEvent(event);
|
|
}
|