update
This commit is contained in:
168
idasdk75/plugins/qproject/edge.cpp
Normal file
168
idasdk75/plugins/qproject/edge.cpp
Normal file
@@ -0,0 +1,168 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 <QPainter>
|
||||
|
||||
#include "edge.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
//lint -e1535 member function '' exposes lower access pointer member ''
|
||||
//lint -e1536 member function '' exposes lower access member ''
|
||||
//lint -e1537 const member function '' exposes pointer member '' as pointer to non-const
|
||||
//lint -e1540 non-static pointer data member '' not deallocated nor zeroed by destructor
|
||||
//lint -e2466 '' was used despite being marked as 'unused'
|
||||
|
||||
static const double Pi = 3.14159265358979323846264338327950288419717;
|
||||
static const double TwoPi = 2.0 * Pi;
|
||||
|
||||
Edge::Edge(Node *_sourceNode, Node *_destNode)
|
||||
: arrowSize(10)
|
||||
{
|
||||
setAcceptedMouseButtons(0);
|
||||
source = _sourceNode;
|
||||
dest = _destNode;
|
||||
source->addEdge(this);
|
||||
dest->addEdge(this);
|
||||
adjust();
|
||||
}
|
||||
|
||||
Edge::~Edge()
|
||||
{
|
||||
}
|
||||
|
||||
Node *Edge::sourceNode() const
|
||||
{
|
||||
return source;
|
||||
}
|
||||
|
||||
void Edge::setSourceNode(Node *node)
|
||||
{
|
||||
source = node;
|
||||
adjust();
|
||||
}
|
||||
|
||||
Node *Edge::destNode() const
|
||||
{
|
||||
return dest;
|
||||
}
|
||||
|
||||
void Edge::setDestNode(Node *node)
|
||||
{
|
||||
dest = node;
|
||||
adjust();
|
||||
}
|
||||
|
||||
void Edge::adjust()
|
||||
{
|
||||
if ( !source || !dest )
|
||||
return;
|
||||
|
||||
QRectF srect = source->boundingRect();
|
||||
QRectF drect = dest->boundingRect();
|
||||
|
||||
QLineF line(mapFromItem(source, srect.width() / 2, srect.height() / 2),
|
||||
mapFromItem(dest, drect.width() / 2, drect.height() / 2));
|
||||
qreal length = line.length();
|
||||
|
||||
prepareGeometryChange();
|
||||
|
||||
if ( length > qreal(40.) )
|
||||
{
|
||||
qreal line_angle = line.angle();
|
||||
qreal angle = line_angle > 90. ? fmod(line_angle, 90.0) : line_angle;
|
||||
qreal dist = qMax(angle, 45.0) - qMin(angle, 45.0);
|
||||
dist += 80.0 - dist;
|
||||
QPointF edgeOffset((line.dx() * dist) / length, (line.dy() * dist) / length);
|
||||
sourcePoint = line.p1() + edgeOffset;
|
||||
destPoint = line.p2() - edgeOffset;
|
||||
qreal new_angle = QLineF(sourcePoint, destPoint).angle();
|
||||
if ( qAbs(new_angle - line_angle) > 90. )
|
||||
sourcePoint = destPoint = line.p1();
|
||||
}
|
||||
else
|
||||
{
|
||||
sourcePoint = destPoint = line.p1();
|
||||
}
|
||||
}
|
||||
|
||||
QRectF Edge::boundingRect() const
|
||||
{
|
||||
if ( !source || !dest )
|
||||
return QRectF();
|
||||
|
||||
qreal penWidth = 1;
|
||||
qreal extra = (penWidth + arrowSize) / 2.0;
|
||||
|
||||
QRectF r(sourcePoint, QSizeF(destPoint.x() - sourcePoint.x(),
|
||||
destPoint.y() - sourcePoint.y()));
|
||||
|
||||
return r.normalized().adjusted(-extra, -extra, extra, extra);
|
||||
}
|
||||
|
||||
void Edge::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
|
||||
{
|
||||
if ( !source || !dest )
|
||||
return;
|
||||
|
||||
QLineF line(sourcePoint, destPoint);
|
||||
if ( qFuzzyCompare(line.length(), qreal(0.)) )
|
||||
return;
|
||||
|
||||
// Draw the line itself
|
||||
painter->setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||
painter->drawLine(line);
|
||||
|
||||
// Draw the arrows
|
||||
double angle = ::acos(line.dx() / line.length());
|
||||
if ( line.dy() >= 0 )
|
||||
angle = TwoPi - angle;
|
||||
|
||||
QPointF destArrowP1 = destPoint + QPointF(sin(angle - Pi / 3) * arrowSize,
|
||||
cos(angle - Pi / 3) * arrowSize);
|
||||
QPointF destArrowP2 = destPoint + QPointF(sin(angle - Pi + Pi / 3) * arrowSize,
|
||||
cos(angle - Pi + Pi / 3) * arrowSize);
|
||||
|
||||
painter->setBrush(Qt::black);
|
||||
|
||||
painter->drawPolygon(QPolygonF() << line.p2() << destArrowP1 << destArrowP2);
|
||||
}
|
||||
78
idasdk75/plugins/qproject/edge.h
Normal file
78
idasdk75/plugins/qproject/edge.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 EDGE_H
|
||||
#define EDGE_H
|
||||
|
||||
#include <QGraphicsItem>
|
||||
|
||||
class Node;
|
||||
|
||||
class Edge : public QGraphicsItem
|
||||
{
|
||||
public:
|
||||
Edge(Node *sourceNode, Node *destNode);
|
||||
~Edge();
|
||||
|
||||
Node *sourceNode() const;
|
||||
void setSourceNode(Node *node);
|
||||
|
||||
Node *destNode() const;
|
||||
void setDestNode(Node *node);
|
||||
|
||||
void adjust();
|
||||
|
||||
enum { Type = UserType + 2 };
|
||||
int type() const override { return Type; }
|
||||
|
||||
protected:
|
||||
QRectF boundingRect() const override;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||
|
||||
private:
|
||||
Node *source, *dest;
|
||||
|
||||
QPointF sourcePoint;
|
||||
QPointF destPoint;
|
||||
qreal arrowSize;
|
||||
};
|
||||
|
||||
#endif
|
||||
235
idasdk75/plugins/qproject/graphwidget.cpp
Normal file
235
idasdk75/plugins/qproject/graphwidget.cpp
Normal file
@@ -0,0 +1,235 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 "graphwidget.h"
|
||||
#include "edge.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QGraphicsScene>
|
||||
#include <QWheelEvent>
|
||||
#include <QTime>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
//lint -e429 custodial pointer '' likely not freed nor returned
|
||||
//lint -e665 unparenthesized parameter
|
||||
//lint -e666 expression with side effects passed to repeated parameter
|
||||
//lint -e1524 new in constructor for class '' which has no explicit destructor
|
||||
//lint -e1793 invoking non-const member function
|
||||
|
||||
GraphWidget::GraphWidget()
|
||||
: timerId(0)
|
||||
{
|
||||
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
|
||||
|
||||
QGraphicsScene *_scene = new QGraphicsScene(this);
|
||||
_scene->setItemIndexMethod(QGraphicsScene::NoIndex);
|
||||
_scene->setSceneRect(-400, -400, 800, 800);
|
||||
setScene(_scene);
|
||||
setCacheMode(CacheBackground);
|
||||
setViewportUpdateMode(BoundingRectViewportUpdate);
|
||||
setRenderHint(QPainter::Antialiasing);
|
||||
setTransformationAnchor(AnchorUnderMouse);
|
||||
setResizeAnchor(AnchorViewCenter);
|
||||
|
||||
Node *node1 = new Node(this);
|
||||
Node *node2 = new Node(this);
|
||||
Node *node3 = new Node(this);
|
||||
Node *node4 = new Node(this);
|
||||
centerNode = new Node(this);
|
||||
Node *node6 = new Node(this);
|
||||
Node *node7 = new Node(this);
|
||||
Node *node8 = new Node(this);
|
||||
Node *node9 = new Node(this);
|
||||
_scene->addItem(node1);
|
||||
_scene->addItem(node2);
|
||||
_scene->addItem(node3);
|
||||
_scene->addItem(node4);
|
||||
_scene->addItem(centerNode);
|
||||
_scene->addItem(node6);
|
||||
_scene->addItem(node7);
|
||||
_scene->addItem(node8);
|
||||
_scene->addItem(node9);
|
||||
_scene->addItem(new Edge(centerNode, node1));
|
||||
_scene->addItem(new Edge(centerNode, node2));
|
||||
_scene->addItem(new Edge(centerNode, node3));
|
||||
_scene->addItem(new Edge(centerNode, node4));
|
||||
_scene->addItem(new Edge(centerNode, node6));
|
||||
_scene->addItem(new Edge(centerNode, node7));
|
||||
_scene->addItem(new Edge(centerNode, node8));
|
||||
_scene->addItem(new Edge(centerNode, node9));
|
||||
|
||||
node1->setPos(-100, -100);
|
||||
node2->setPos(0, -100);
|
||||
node3->setPos(100, -100);
|
||||
node4->setPos(-100, 0);
|
||||
centerNode->setPos(0, 0);
|
||||
node6->setPos(100, 0);
|
||||
node7->setPos(-100, 100);
|
||||
node8->setPos(0, 100);
|
||||
node9->setPos(100, 100);
|
||||
|
||||
scale(qreal(0.8), qreal(0.8));
|
||||
setMinimumSize(400, 400);
|
||||
setWindowTitle(tr("Elastic IDA Nodes"));
|
||||
}
|
||||
|
||||
void GraphWidget::itemMoved()
|
||||
{
|
||||
if ( !timerId )
|
||||
timerId = startTimer(10);
|
||||
}
|
||||
|
||||
void GraphWidget::keyPressEvent(QKeyEvent *_event)
|
||||
{
|
||||
switch ( _event->key() )
|
||||
{
|
||||
case Qt::Key_Up:
|
||||
centerNode->moveBy(0, -20);
|
||||
break;
|
||||
case Qt::Key_Down:
|
||||
centerNode->moveBy(0, 20);
|
||||
break;
|
||||
case Qt::Key_Left:
|
||||
centerNode->moveBy(-20, 0);
|
||||
break;
|
||||
case Qt::Key_Right:
|
||||
centerNode->moveBy(20, 0);
|
||||
break;
|
||||
case Qt::Key_Plus:
|
||||
scaleView(qreal(1.2));
|
||||
break;
|
||||
case Qt::Key_Minus:
|
||||
scaleView(1 / qreal(1.2));
|
||||
break;
|
||||
case Qt::Key_Space:
|
||||
case Qt::Key_Enter:
|
||||
foreach ( QGraphicsItem *item, scene()->items() )
|
||||
{
|
||||
if ( qgraphicsitem_cast<Node *>(item) )
|
||||
item->setPos(-150 + qrand() % 300, -150 + qrand() % 300);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
QGraphicsView::keyPressEvent(_event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void GraphWidget::timerEvent(QTimerEvent *_event)
|
||||
{
|
||||
Q_UNUSED(_event);
|
||||
|
||||
QList<Node *> nodes;
|
||||
foreach ( QGraphicsItem *item, scene()->items() )
|
||||
{
|
||||
if ( Node *node = qgraphicsitem_cast<Node *>(item) )
|
||||
nodes << node;
|
||||
}
|
||||
|
||||
foreach ( Node *node, nodes )
|
||||
node->calculateForces();
|
||||
|
||||
bool itemsMoved = false;
|
||||
foreach ( Node *node, nodes )
|
||||
{
|
||||
if ( node->_advance() )
|
||||
itemsMoved = true;
|
||||
}
|
||||
|
||||
if ( !itemsMoved )
|
||||
{
|
||||
killTimer(timerId);
|
||||
timerId = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void GraphWidget::wheelEvent(QWheelEvent *_event)
|
||||
{
|
||||
scaleView(pow((double)2, -_event->delta() / 240.0));
|
||||
}
|
||||
|
||||
void GraphWidget::drawBackground(QPainter *painter, const QRectF &_rect)
|
||||
{
|
||||
Q_UNUSED(_rect);
|
||||
|
||||
// Shadow
|
||||
QRectF _sceneRect = this->sceneRect();
|
||||
QRectF rightShadow(_sceneRect.right(), _sceneRect.top() + 5, 5, _sceneRect.height());
|
||||
QRectF bottomShadow(_sceneRect.left() + 5, _sceneRect.bottom(), _sceneRect.width(), 5);
|
||||
if ( rightShadow.intersects(_rect) || rightShadow.contains(_rect) )
|
||||
painter->fillRect(rightShadow, Qt::darkGray);
|
||||
if ( bottomShadow.intersects(_rect) || bottomShadow.contains(_rect) )
|
||||
painter->fillRect(bottomShadow, Qt::darkGray);
|
||||
|
||||
// Fill
|
||||
QLinearGradient gradient(_sceneRect.topLeft(), _sceneRect.bottomRight());
|
||||
gradient.setColorAt(0, Qt::white);
|
||||
gradient.setColorAt(1, Qt::lightGray);
|
||||
painter->fillRect(_rect.intersected(_sceneRect), gradient);
|
||||
painter->setBrush(Qt::NoBrush);
|
||||
painter->drawRect(_sceneRect);
|
||||
|
||||
// Text
|
||||
QRectF textRect(_sceneRect.left() + 4, _sceneRect.top() + 4,
|
||||
_sceneRect.width() - 4, _sceneRect.height() - 4);
|
||||
QString message(tr("Click and drag the nodes around, and zoom with the mouse "
|
||||
"wheel or the '+' and '-' keys"));
|
||||
|
||||
QFont _font = painter->font();
|
||||
_font.setBold(true);
|
||||
_font.setPointSize(14);
|
||||
painter->setFont(_font);
|
||||
painter->setPen(Qt::lightGray);
|
||||
painter->drawText(textRect.translated(2, 2), message);
|
||||
painter->setPen(Qt::black);
|
||||
painter->drawText(textRect, message);
|
||||
}
|
||||
|
||||
void GraphWidget::scaleView(qreal scaleFactor)
|
||||
{
|
||||
qreal factor = matrix().scale(scaleFactor, scaleFactor).mapRect(QRectF(0, 0, 1, 1)).width();
|
||||
if ( factor < 0.07 || factor > 100 )
|
||||
return;
|
||||
|
||||
scale(scaleFactor, scaleFactor);
|
||||
}
|
||||
73
idasdk75/plugins/qproject/graphwidget.h
Normal file
73
idasdk75/plugins/qproject/graphwidget.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 GRAPHWIDGET_H
|
||||
#define GRAPHWIDGET_H
|
||||
|
||||
#include <QGraphicsView>
|
||||
|
||||
//lint -esym(818, _o, _a) Pointer parameter '' could be declared as pointing to const
|
||||
|
||||
class Node;
|
||||
|
||||
class GraphWidget : public QGraphicsView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GraphWidget();
|
||||
|
||||
void itemMoved();
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent *event) override;
|
||||
void timerEvent(QTimerEvent *event) override;
|
||||
void wheelEvent(QWheelEvent *event) override;
|
||||
void drawBackground(QPainter *painter, const QRectF &rect) override;
|
||||
|
||||
void scaleView(qreal scaleFactor);
|
||||
|
||||
private:
|
||||
int timerId;
|
||||
Node *centerNode;
|
||||
};
|
||||
|
||||
#endif
|
||||
18
idasdk75/plugins/qproject/makefile
Normal file
18
idasdk75/plugins/qproject/makefile
Normal file
@@ -0,0 +1,18 @@
|
||||
PROC=qproject
|
||||
O1=moc_graphwidget
|
||||
O2=graphwidget
|
||||
O3=node
|
||||
O4=edge
|
||||
|
||||
include ../qtplugin.mak
|
||||
|
||||
# MAKEDEP dependency list ------------------
|
||||
$(F)edge$(O) : edge.cpp edge.h node.h
|
||||
$(F)graphwidget$(O): edge.h graphwidget.cpp graphwidget.h node.h
|
||||
$(F)moc_graphwidget$(O): $(F)moc_graphwidget.cpp graphwidget.h
|
||||
$(F)node$(O) : edge.h graphwidget.h node.cpp node.h
|
||||
$(F)qproject$(O): $(I)bitrange.hpp $(I)bytes.hpp $(I)config.hpp $(I)fpro.h \
|
||||
$(I)funcs.hpp $(I)ida.hpp $(I)idp.hpp $(I)kernwin.hpp \
|
||||
$(I)lines.hpp $(I)llong.hpp $(I)loader.hpp $(I)nalt.hpp \
|
||||
$(I)netnode.hpp $(I)pro.h $(I)range.hpp $(I)segment.hpp \
|
||||
$(I)ua.hpp $(I)xref.hpp graphwidget.h qproject.cpp
|
||||
175
idasdk75/plugins/qproject/node.cpp
Normal file
175
idasdk75/plugins/qproject/node.cpp
Normal file
@@ -0,0 +1,175 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 <QGraphicsScene>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QStyleOption>
|
||||
|
||||
#include "edge.h"
|
||||
#include "node.h"
|
||||
#include "graphwidget.h"
|
||||
|
||||
//lint -e665 unparenthesized parameter
|
||||
//lint -e666 expression with side effects passed to repeated parameter
|
||||
//lint -e790 possibly truncated multiplication
|
||||
|
||||
const char html[] =
|
||||
"<span style=\"white-space: pre; font-family: FixedSys; color: blue; background: white\">"
|
||||
"<span style=\"color:navy\">push </span><span style=\"color:green\">0</span>\n"
|
||||
"<span style=\"color:navy\">push [ebp+</span><span style=\"color:green\">argv</span><span style=\"color:navy\">]</span>\n"
|
||||
"<span style=\"color:navy\">call sub_4015B8</span>";
|
||||
|
||||
Node::Node(GraphWidget *graphWidget)
|
||||
: graph(graphWidget)
|
||||
{
|
||||
setFlag(ItemIsMovable);
|
||||
setFlag(ItemIsFocusable);
|
||||
setFlag(ItemIsSelectable);
|
||||
setFlag(ItemSendsGeometryChanges);
|
||||
setCacheMode(DeviceCoordinateCache);
|
||||
setZValue(-1);
|
||||
setHtml(html);
|
||||
}
|
||||
|
||||
void Node::addEdge(Edge *edge)
|
||||
{
|
||||
edgeList << edge;
|
||||
edge->adjust();
|
||||
}
|
||||
|
||||
QList<Edge *> Node::edges() const
|
||||
{
|
||||
return edgeList;
|
||||
}
|
||||
|
||||
void Node::calculateForces()
|
||||
{
|
||||
if ( !scene() || scene()->mouseGrabberItem() == this )
|
||||
{
|
||||
newPos = pos();
|
||||
return;
|
||||
}
|
||||
|
||||
// Sum up all forces pushing this item away
|
||||
qreal xvel = 0;
|
||||
qreal yvel = 0;
|
||||
foreach ( QGraphicsItem *item, scene()->items() )
|
||||
{
|
||||
Node *node = qgraphicsitem_cast<Node *>(item);
|
||||
if ( !node )
|
||||
continue;
|
||||
|
||||
QLineF line(mapFromItem(node, 0, 0), QPointF(0, 0));
|
||||
qreal dx = line.dx();
|
||||
qreal dy = line.dy();
|
||||
double l = 2.0 * (dx * dx + dy * dy);
|
||||
if ( l > 0 )
|
||||
{
|
||||
xvel += (dx * 150.0) / l;
|
||||
yvel += (dy * 150.0) / l;
|
||||
}
|
||||
}
|
||||
|
||||
// Now subtract all forces pulling items together
|
||||
double weight = (edgeList.size() + 1) * 100;
|
||||
foreach ( Edge *edge, edgeList )
|
||||
{
|
||||
QPointF _pos;
|
||||
if ( edge->sourceNode() == this )
|
||||
_pos = mapFromItem(edge->destNode(), 0, 0);
|
||||
else
|
||||
_pos = mapFromItem(edge->sourceNode(), 0, 0);
|
||||
xvel += _pos.x() / weight;
|
||||
yvel += _pos.y() / weight;
|
||||
}
|
||||
|
||||
if ( qAbs(xvel) < 0.1 && qAbs(yvel) < 0.1 )
|
||||
xvel = yvel = 0;
|
||||
|
||||
QRectF sceneRect = scene()->sceneRect();
|
||||
newPos = pos() + QPointF(xvel, yvel);
|
||||
newPos.setX(qMin(qMax(newPos.x(), sceneRect.left() + 10), sceneRect.right() - 10));
|
||||
newPos.setY(qMin(qMax(newPos.y(), sceneRect.top() + 10), sceneRect.bottom() - 10));
|
||||
}
|
||||
|
||||
bool Node::_advance()
|
||||
{
|
||||
if ( newPos == pos() )
|
||||
return false;
|
||||
|
||||
setPos(newPos);
|
||||
return true;
|
||||
}
|
||||
|
||||
QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value)
|
||||
{
|
||||
switch ( change )
|
||||
{
|
||||
case ItemPositionHasChanged:
|
||||
foreach ( Edge *edge, edgeList )
|
||||
edge->adjust();
|
||||
graph->itemMoved();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return QGraphicsTextItem::itemChange(change, value);
|
||||
}
|
||||
|
||||
void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
painter->fillRect(option->rect, Qt::white);
|
||||
QGraphicsTextItem::paint(painter, option, widget);
|
||||
}
|
||||
|
||||
void Node::mousePressEvent(QGraphicsSceneMouseEvent *_event)
|
||||
{
|
||||
update();
|
||||
QGraphicsTextItem::mousePressEvent(_event);
|
||||
}
|
||||
|
||||
void Node::mouseReleaseEvent(QGraphicsSceneMouseEvent *_event)
|
||||
{
|
||||
update();
|
||||
QGraphicsTextItem::mouseReleaseEvent(_event);
|
||||
}
|
||||
81
idasdk75/plugins/qproject/node.h
Normal file
81
idasdk75/plugins/qproject/node.h
Normal file
@@ -0,0 +1,81 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 NODE_H
|
||||
#define NODE_H
|
||||
|
||||
#include <QGraphicsTextItem>
|
||||
#include <QList>
|
||||
|
||||
class Edge;
|
||||
class GraphWidget;
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QGraphicsSceneMouseEvent;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class Node : public QGraphicsTextItem
|
||||
{
|
||||
public:
|
||||
Node(GraphWidget *graphWidget);
|
||||
|
||||
void addEdge(Edge *edge);
|
||||
QList<Edge *> edges() const;
|
||||
|
||||
enum { Type = UserType + 1 };
|
||||
int type() const override { return Type; }
|
||||
|
||||
void calculateForces();
|
||||
bool _advance();
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
|
||||
|
||||
protected:
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
||||
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
|
||||
private:
|
||||
QList<Edge *> edgeList;
|
||||
QPointF newPos;
|
||||
GraphWidget *graph;
|
||||
};
|
||||
|
||||
#endif
|
||||
135
idasdk75/plugins/qproject/qproject.cpp
Normal file
135
idasdk75/plugins/qproject/qproject.cpp
Normal file
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* This is a sample plugin module. It demonstrates how to fully use
|
||||
* the Qt environment in IDA.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <QtGui>
|
||||
#include <QtWidgets>
|
||||
|
||||
#include <ida.hpp>
|
||||
#include <idp.hpp>
|
||||
#include <loader.hpp>
|
||||
#include <kernwin.hpp>
|
||||
|
||||
// include your own widget here
|
||||
#include "graphwidget.h"
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
struct plugin_ctx_t : public plugmod_t, public event_listener_t
|
||||
{
|
||||
TWidget *widget = nullptr;
|
||||
|
||||
plugin_ctx_t()
|
||||
{
|
||||
hook_event_listener(HT_UI, this);
|
||||
}
|
||||
~plugin_ctx_t()
|
||||
{
|
||||
// listeners are uninstalled automatically
|
||||
// when the owner module is unloaded
|
||||
widget = nullptr; // make lint happy
|
||||
}
|
||||
|
||||
virtual bool idaapi run(size_t) override;
|
||||
virtual ssize_t idaapi on_event(ssize_t code, va_list va) override;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
ssize_t idaapi plugin_ctx_t::on_event(ssize_t code, va_list va)
|
||||
{
|
||||
if ( code == ui_widget_visible )
|
||||
{
|
||||
TWidget *l_widget = va_arg(va, TWidget *);
|
||||
if ( l_widget == widget )
|
||||
{
|
||||
// widget is created, create controls
|
||||
|
||||
QWidget *w = (QWidget *) widget;
|
||||
|
||||
QHBoxLayout *mainLayout = new QHBoxLayout();
|
||||
mainLayout->setMargin(0);
|
||||
|
||||
GraphWidget *userWidget = new GraphWidget();
|
||||
|
||||
mainLayout->addWidget(userWidget);
|
||||
|
||||
w->setLayout(mainLayout);
|
||||
//lint -e429 mainLayout not freed
|
||||
}
|
||||
}
|
||||
if ( code == ui_widget_invisible )
|
||||
{
|
||||
TWidget *l_widget = va_arg(va, TWidget *);
|
||||
if ( l_widget == widget )
|
||||
{
|
||||
// widget is closed, destroy objects (if required)
|
||||
widget = nullptr;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
bool idaapi plugin_ctx_t::run(size_t)
|
||||
{
|
||||
TWidget *g_widget = find_widget("Sample Qt Project");
|
||||
if ( g_widget == nullptr )
|
||||
{
|
||||
widget = create_empty_widget("Sample Qt Project");
|
||||
display_widget(widget, WOPN_DP_TAB|WOPN_RESTORE);
|
||||
}
|
||||
else
|
||||
{
|
||||
close_widget(g_widget, WCLS_SAVE);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
static plugmod_t *idaapi init()
|
||||
{
|
||||
if ( !is_idaq() )
|
||||
return nullptr;
|
||||
return new plugin_ctx_t;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
char comment[] = "This is a sample Qt Project plugin.";
|
||||
|
||||
char help[] =
|
||||
"A sample plugin module\n"
|
||||
"\n"
|
||||
"This module shows you how to use fully the Qt environment in IDA.";
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// This is the preferred name of the plugin module in the menu system
|
||||
// The preferred name may be overridden in plugins.cfg file
|
||||
|
||||
char wanted_name[] = "Qt Project Sample";
|
||||
|
||||
|
||||
// This is the preferred hotkey for the plugin module
|
||||
// The preferred hotkey may be overridden in plugins.cfg file
|
||||
|
||||
char wanted_hotkey[] = "";
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// PLUGIN DESCRIPTION BLOCK
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
plugin_t PLUGIN =
|
||||
{
|
||||
IDP_INTERFACE_VERSION,
|
||||
PLUGIN_MULTI, // The plugin can work with multiple idbs in parallel
|
||||
init, // initialize
|
||||
nullptr,
|
||||
nullptr,
|
||||
comment, // long comment about the plugin
|
||||
help, // multiline help about the plugin
|
||||
wanted_name, // the preferred short name of the plugin
|
||||
wanted_hotkey, // the preferred hotkey to run the plugin
|
||||
};
|
||||
Reference in New Issue
Block a user