1
0
Fork 0

GUI: small usability updates in the graph

This commit is contained in:
mrexodia 2015-12-17 20:29:20 +01:00
parent eb7d19549c
commit d3d986a83d
7 changed files with 114 additions and 4 deletions

View File

@ -0,0 +1,12 @@
#include "QGraphScene.h"
QGraphScene::QGraphScene(QWidget* parent) : QGraphicsScene(parent)
{
}
void QGraphScene::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
{
QWidget* parent = (QWidget*)this->parent();
parent->setWindowTitle(QString().sprintf("x:%f, y:%f", event->scenePos().x(), event->scenePos().y()));
QGraphicsScene::mouseMoveEvent(event);
}

View File

@ -0,0 +1,21 @@
#ifndef QGRAPHSCENE_H
#define QGRAPHSCENE_H
#include <QWidget>
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
class QGraphScene : public QGraphicsScene
{
Q_OBJECT
public:
explicit QGraphScene(QWidget* parent = 0);
void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
signals:
public slots:
};
#endif // QGRAPHSCENE_H

View File

@ -4,6 +4,7 @@
#include "Tree.h"
#include "GraphEdge.h"
#include "GraphNode.h"
#include "QGraphScene.h"
#include <ogdf/fileformats/GraphIO.h>
#include <ogdf/layered/SugiyamaLayout.h>
@ -72,7 +73,7 @@ void GraphView::setupGraph()
SL.setLayout(OHL);
SL.call(GA);
QGraphicsScene* scene = new QGraphicsScene(this);
QGraphScene* scene = new QGraphScene(this);
//draw widget contents (nodes)
forall_nodes(v, G)

View File

@ -15,10 +15,21 @@
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QGraphicsView" name="graphicsView"/>
<widget class="QGraphView" name="graphicsView">
<property name="dragMode">
<enum>QGraphicsView::ScrollHandDrag</enum>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QGraphView</class>
<extends>QGraphicsView</extends>
<header>QGraphView.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,39 @@
#include "QGraphView.h"
#include <QTimeLine>
QGraphView::QGraphView(QWidget* parent)
: QGraphicsView(parent)
{
}
void QGraphView::wheelEvent(QWheelEvent* event)
{
int numDegrees = event->delta() / 8;
int numSteps = numDegrees / 15; // see QWheelEvent documentation
_numScheduledScalings += numSteps;
if (_numScheduledScalings * numSteps < 0) // if user moved the wheel in another direction, we reset previously scheduled scalings
_numScheduledScalings = numSteps;
QTimeLine *anim = new QTimeLine(350, this);
anim->setUpdateInterval(20);
connect(anim, SIGNAL (valueChanged(qreal)), SLOT (scalingTime(qreal)));
connect(anim, SIGNAL (finished()), SLOT (animFinished()));
anim->start();
}
void QGraphView::scalingTime(qreal x)
{
qreal factor = 1.0 + qreal(_numScheduledScalings) / 300.0;
scale(factor, factor);
}
void QGraphView::animFinished()
{
if (_numScheduledScalings > 0)
_numScheduledScalings--;
else
_numScheduledScalings++;
sender()->~QObject();
}

22
src/gui/Src/QGraphView.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef QGRAPHVIEW_H
#define QGRAPHVIEW_H
#include <QGraphicsView>
#include <QWheelEvent>
class QGraphView : public QGraphicsView
{
Q_OBJECT
public:
explicit QGraphView(QWidget* parent = nullptr);
void wheelEvent(QWheelEvent* event);
private slots:
void scalingTime(qreal x);
void animFinished();
private:
int _numScheduledScalings;
};
#endif // QGRAPHVIEW_H

View File

@ -146,7 +146,9 @@ SOURCES += \
Src/Gui/NotesManager.cpp \
Src/Gui/NotepadView.cpp \
Src/Gui/CPUMultiDump.cpp \
Src/Gui/GraphView.cpp
Src/Gui/GraphView.cpp \
Src/Graph/QGraphScene.cpp \
Src/QGraphView.cpp
HEADERS += \
@ -234,7 +236,9 @@ HEADERS += \
Src/Graph/GraphNode.h \
Src/Graph/Node.h \
Src/Graph/Tree.h \
Src/Gui/GraphView.h
Src/Gui/GraphView.h \
Src/Graph/QGraphScene.h \
Src/QGraphView.h
FORMS += \
Src/Gui/MainWindow.ui \