Permalink
Browse files

GraphWidget/GraphScene improvements and FirstRunDialog

GraphWidget now allows for mouse panning while holding shift
GraphWidget allows for zooming via Ctrl+"0", Ctrl+"+" and Ctrl+"-"
GraphScene allows selecting all elements with Ctrl+A
Added some stubs to Node and NodeItem for marked nodes
Generalised the background colour selection to reduce the number of
settings required
Started on a FirstRunDialog which explains graph editing concepts one at
a time
  • Loading branch information...
aelliott committed Apr 17, 2013
1 parent 403b591 commit 56562439fa3adc9f611cb6c921ae920b2d725c2b
@@ -36,6 +36,7 @@ SET(GPDeveloper_HPP_SRCS
src/developer/conditioneditor.hpp
src/developer/conditionhighlighter.hpp
src/developer/edit.hpp
src/developer/firstrundialog.hpp
src/developer/gpfile.hpp
src/developer/graph.hpp
src/developer/graphedit.hpp
@@ -79,6 +80,7 @@ SET(GPDeveloper_UI_SRCS
src/developer/preferences/toolchainpreferences.ui
src/developer/aboutdialog.ui
src/developer/edit.ui
src/developer/firstrundialog.ui
src/developer/graphedit.ui
src/developer/importgraphdialog.ui
src/developer/importprogramdialog.ui
@@ -53,7 +53,7 @@ int CodeEditor::gutterWidth() const
// Add another char width as padding
++characters;
int gWidth = 3 + fontMetrics().width(QString(characters, QChar('9')));
int gWidth = 4 + fontMetrics().width(QString(characters, QChar('9')));
Q_ASSERT(gWidth > 0);
@@ -112,7 +112,7 @@ void CodeEditor::drawGutter(QPaintEvent *event)
if (block.isVisible() && bottom >= event->rect().top())
{
QString numberString = QVariant(number + 1).toString();
painter.drawText(0, top, _gutter->width()-3,
painter.drawText(0, top, _gutter->width()-4,
fontMetrics().height(), Qt::AlignRight, numberString);
}
@@ -70,7 +70,8 @@ HEADERS += \
importruledialog.hpp \
importgraphdialog.hpp \
openprojectprogressdialog.hpp \
list.hpp
list.hpp \
firstrundialog.hpp
FORMS += \
welcome.ui \
@@ -101,7 +102,8 @@ FORMS += \
importprogramdialog.ui \
importruledialog.ui \
importgraphdialog.ui \
openprojectprogressdialog.ui
openprojectprogressdialog.ui \
firstrundialog.ui
RESOURCES += \
icons.qrc \
@@ -166,7 +168,8 @@ SOURCES += \
importruledialog.cpp \
importgraphdialog.cpp \
openprojectprogressdialog.cpp \
list.cpp
list.cpp \
firstrundialog.cpp
OTHER_FILES += \
templates/newproject.gpp \
@@ -185,7 +188,8 @@ OTHER_FILES += \
templates/example_program.gpx \
templates/newprogram.gpx \
templates/example_graph.gpg \
templates/example_graph_rhs.gpg
templates/example_graph_rhs.gpg \
templates/example_large_graph.dot
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../libgp/release/ -llibgp -L"C:\Program Files (x86)\OGDF\lib" -llibOGDF -lpsapi
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../libgp/debug/ -llibgp -L"C:\Program Files (x86)\OGDF\lib" -llibOGDF -lpsapi
@@ -0,0 +1,201 @@
/*!
* \file
*/
#include "firstrundialog.hpp"
#include "ui_firstrundialog.h"
#include <QFile>
#include "graphview/graphwidget.hpp"
#include "graph.hpp"
namespace Developer
{
FirstRunDialog::FirstRunDialog(QWidget *parent)
: QDialog(parent)
, _ui(new Ui::FirstRunDialog)
, _initialGraph(0)
, _editingGraph(0)
, _largeGraph(0)
, _rhsGraph(0)
, _page(0)
, _previousPage(0)
, _nodeCount(0)
, _edgeCount(0)
, _addingNodesLock(false)
, _addingEdgesLock(false)
, _deletingElementsLock(false)
, _editingRhsLock(false)
{
_ui->setupUi(this);
// Load the help stylesheet and apply it to this widget
QFile fp(":/stylesheets/helpdialog.css");
fp.open(QIODevice::ReadOnly | QIODevice::Text);
QString style = fp.readAll();
setStyleSheet(style);
setPage(0);
}
FirstRunDialog::~FirstRunDialog()
{
delete _ui;
}
void FirstRunDialog::back()
{
_previousPage = _page;
setPage(_page-1);
}
void FirstRunDialog::next()
{
_previousPage = _page;
setPage(_page+1);
}
void FirstRunDialog::setPage(int page)
{
_page = page;
_ui->stackedWidget->setCurrentIndex(page);
switch(page)
{
case 7: // RHS graphs
if(_previousPage == 6)
{
_rhsGraph = new Graph(":/templates/example_graph_rhs.gpg");
_ui->graphWidget->setGraph(_rhsGraph);
_ui->graphWidget->setLinkedGraph(_initialGraph);
}
_ui->backButton->setEnabled(true);
_ui->nextButton->setVisible(false);
_ui->beginButton->setEnabled(_editingRhsLock);
_ui->beginButton->setVisible(true);
break;
case 6: // large graphs
if(_previousPage == 5)
_largeGraph = new Graph(":/templates/example_large_graph.dot");
if(_previousPage == 7)
_ui->graphWidget->setLinkedGraph(0);
_ui->graphWidget->setGraph(_largeGraph);
_ui->backButton->setEnabled(true);
_ui->nextButton->setVisible(true);
_ui->nextButton->setEnabled(true);
_ui->beginButton->setVisible(false);
break;
case 5: // deleting elements
if(_previousPage == 6)
_ui->graphWidget->setGraph(_editingGraph);
_nodeCount = 0;
_edgeCount = 0;
_ui->backButton->setEnabled(true);
_ui->nextButton->setEnabled(_deletingElementsLock);
_ui->beginButton->setVisible(false);
break;
case 4: // selecting elements
case 3: // editing elements
_ui->backButton->setEnabled(true);
_ui->nextButton->setEnabled(true);
_ui->beginButton->setVisible(false);
break;
case 2: // adding edges
_edgeCount = 0;
_ui->backButton->setEnabled(true);
_ui->nextButton->setEnabled(_addingEdgesLock);
_ui->beginButton->setVisible(false);
break;
case 1: // adding nodes
if(_previousPage == 0)
{
_nodeCount = 0;
_editingGraph = new Graph();
connect(_editingGraph, SIGNAL(nodeAdded(Node*)),
this, SLOT(nodeAdded()));
connect(_editingGraph, SIGNAL(nodeRemoved(QString)),
this, SLOT(nodeRemoved()));
connect(_editingGraph, SIGNAL(edgeAdded(Edge*)),
this, SLOT(edgeAdded()));
connect(_editingGraph, SIGNAL(edgeRemoved(QString)),
this, SLOT(edgeRemoved()));
_ui->graphWidget->setGraph(_editingGraph);
}
_ui->backButton->setEnabled(true);
_ui->nextButton->setEnabled(_addingNodesLock);
_ui->beginButton->setVisible(false);
break;
case 0: // introduction
default:
if(_initialGraph == 0)
_initialGraph = new Graph(":/templates/example_graph.gpg");
_ui->graphWidget->setGraph(_initialGraph);
_ui->backButton->setEnabled(false);
_ui->nextButton->setEnabled(true);
_ui->beginButton->setVisible(false);
break;
}
}
void FirstRunDialog::nodeAdded()
{
if(_page == 1)
{
// We are counting nodes up to three
++_nodeCount;
_ui->nodeCount->setText(QVariant(_nodeCount).toString());
if(_nodeCount > 2)
{
_addingNodesLock = true;
_ui->nextButton->setEnabled(true);
}
}
}
void FirstRunDialog::nodeRemoved()
{
if(_page == 5)
{
++_nodeCount;
_ui->nodeDeleteCount->setText(QVariant(_nodeCount).toString());
if(_nodeCount > 2 && _edgeCount > 2)
{
_deletingElementsLock = true;
_ui->nextButton->setEnabled(true);
}
}
}
void FirstRunDialog::edgeAdded()
{
if(_page == 2)
{
// We are counting edges up to three
++_edgeCount;
_ui->edgeCount->setText(QVariant(_edgeCount).toString());
if(_edgeCount > 2)
{
_addingEdgesLock = true;
_ui->nextButton->setEnabled(true);
}
}
}
void FirstRunDialog::edgeRemoved()
{
if(_page == 5)
{
++_edgeCount;
_ui->edgeDeleteCount->setText(QVariant(_edgeCount).toString());
if(_nodeCount > 2 && _edgeCount > 2)
{
_deletingElementsLock = true;
_ui->nextButton->setEnabled(true);
}
}
}
}
@@ -0,0 +1,53 @@
/*!
* \file
*/
#ifndef FIRSTRUNDIALOG_HPP
#define FIRSTRUNDIALOG_HPP
#include <QDialog>
namespace Ui {
class FirstRunDialog;
}
namespace Developer {
class Graph;
class FirstRunDialog : public QDialog
{
Q_OBJECT
public:
explicit FirstRunDialog(QWidget *parent = 0);
~FirstRunDialog();
public slots:
void next();
void back();
void setPage(int page);
void nodeAdded();
void nodeRemoved();
void edgeAdded();
void edgeRemoved();
private:
Ui::FirstRunDialog *_ui;
Graph *_initialGraph;
Graph *_editingGraph;
Graph *_largeGraph;
Graph *_rhsGraph;
int _page;
int _previousPage;
int _nodeCount;
int _edgeCount;
bool _addingNodesLock;
bool _addingEdgesLock;
bool _deletingElementsLock;
bool _editingRhsLock;
};
}
#endif // FIRSTRUNDIALOG_HPP
Oops, something went wrong.

0 comments on commit 5656243

Please sign in to comment.