Skip to content

Commit 1eb9587

Browse files
committed
ErrorItem graphics
1 parent 0a7bf0f commit 1eb9587

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

src/Interface/Application/NetworkEditor.cc

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ using namespace SCIRun::Dataflow::Networks;
5959
using namespace SCIRun::Dataflow::Engine;
6060

6161
NetworkEditor::NetworkEditor(boost::shared_ptr<CurrentModuleSelection> moduleSelectionGetter,
62-
boost::shared_ptr<DefaultNotePositionGetter> dnpg, boost::shared_ptr<SCIRun::Gui::DialogErrorControl> dialogErrorControl,
62+
boost::shared_ptr<DefaultNotePositionGetter> dnpg, boost::shared_ptr<SCIRun::Gui::DialogErrorControl> dialogErrorControl,
6363
TagColorFunc tagColor,
6464
QWidget* parent)
6565
: QGraphicsView(parent),
@@ -1208,10 +1208,36 @@ void NetworkEditor::highlightTaggedItem(QGraphicsItem* item, int tagValue)
12081208
}
12091209
}
12101210

1211-
void NetworkEditor::displayError(const QString& msg) const
1211+
ErrorItem::ErrorItem(const QString& text, QGraphicsItem* parent) : QGraphicsTextItem(text, parent)
12121212
{
1213-
qDebug() << "displaying" << msg;
1214-
auto errorItem = scene()->addText(msg);
1213+
setDefaultTextColor(Qt::red);
1214+
}
1215+
1216+
void ErrorItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
1217+
{
1218+
if (event->buttons() & Qt::LeftButton)
1219+
{
1220+
qDebug() << "TODO: go to errored module";
1221+
}
1222+
else if (event->buttons() & Qt::RightButton)
1223+
{
1224+
scene()->removeItem(this);
1225+
}
1226+
}
1227+
1228+
void NetworkEditor::displayError(const QString& msg)
1229+
{
1230+
auto errorItem = new ErrorItem(msg);
1231+
scene()->addItem(errorItem);
1232+
qDebug() << "TODO: get visible view, display relative to lower left corner.";
1233+
qDebug() << "TODO: set timer to fade out after X seconds";
1234+
1235+
auto rect = sceneRect();
1236+
qDebug() << "scene rect:" << rect;
1237+
errorItem->setPos(-100, -100);
1238+
//ensureVisible(errorItem);
1239+
1240+
//rotate(90);
12151241
}
12161242

12171243
NetworkEditor::~NetworkEditor()

src/Interface/Application/NetworkEditor.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#define INTERFACE_APPLICATION_NETWORKEDITOR_H
3131

3232
#include <QGraphicsView>
33+
#include <QGraphicsTextItem>
3334
#ifndef Q_MOC_RUN
3435
#include <boost/shared_ptr.hpp>
3536
#include <map>
@@ -74,7 +75,16 @@ namespace Gui {
7475
{
7576
public:
7677
virtual ~ModuleErrorDisplayer() {}
77-
virtual void displayError(const QString& msg) const = 0;
78+
virtual void displayError(const QString& msg) = 0;
79+
};
80+
81+
class ErrorItem : public QGraphicsTextItem
82+
{
83+
Q_OBJECT
84+
public:
85+
explicit ErrorItem(const QString& text, QGraphicsItem* parent = 0);
86+
protected:
87+
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
7888
};
7989

8090
class ModuleEventProxy : public QObject
@@ -122,7 +132,7 @@ namespace Gui {
122132

123133
public:
124134
explicit NetworkEditor(boost::shared_ptr<CurrentModuleSelection> moduleSelectionGetter, boost::shared_ptr<DefaultNotePositionGetter> dnpg,
125-
boost::shared_ptr<DialogErrorControl> dialogErrorControl,
135+
boost::shared_ptr<DialogErrorControl> dialogErrorControl,
126136
TagColorFunc tagColor = defaultTagColor,
127137
QWidget* parent = 0);
128138
~NetworkEditor();
@@ -156,7 +166,7 @@ namespace Gui {
156166
void enableInputWidgets();
157167

158168
//TODO: this class is getting too big and messy, schedule refactoring
159-
169+
160170
void setBackground(const QBrush& brush);
161171
QBrush background() const;
162172

@@ -174,7 +184,7 @@ namespace Gui {
174184
void tagLayer(bool active, int tag);
175185
bool tagLayerActive() const { return tagLayerActive_; }
176186

177-
virtual void displayError(const QString& msg) const override;
187+
virtual void displayError(const QString& msg) override;
178188

179189
protected:
180190
virtual void dropEvent(QDropEvent* event) override;

0 commit comments

Comments
 (0)