Skip to content

Commit 4fb01de

Browse files
committed
Super hacky implementation, closes #1135
1 parent 91a7361 commit 4fb01de

File tree

5 files changed

+33
-12
lines changed

5 files changed

+33
-12
lines changed

src/Interface/Application/Connection.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include <QtGui>
3232
#include <boost/bind.hpp>
3333
#include <Interface/Application/Connection.h>
34-
#include <Interface/Application/Utility.h>
3534
#include <Interface/Application/Port.h>
3635
#include <Interface/Application/GuiLogger.h>
3736
#include <Interface/Application/MainWindowCollaborators.h>

src/Interface/Application/ModuleProxyWidget.cc

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,10 @@ ModuleProxyWidget::ModuleProxyWidget(ModuleWidget* module, QGraphicsItem* parent
126126
setAcceptDrops(true);
127127

128128
connect(module, SIGNAL(noteUpdated(const Note&)), this, SLOT(updateNote(const Note&)));
129-
connect(module, SIGNAL(requestModuleVisible()), this, SLOT(ensureVisible()));
129+
connect(module, SIGNAL(requestModuleVisible()), this, SLOT(ensureThisVisible()));
130130
connect(module, SIGNAL(deleteMeLater()), this, SLOT(deleteLater()));
131+
132+
stackDepth_ = 0;
131133
}
132134

133135
ModuleProxyWidget::~ModuleProxyWidget()
@@ -139,7 +141,12 @@ void ModuleProxyWidget::createStartupNote()
139141
module_->createStartupNote();
140142
}
141143

142-
void ModuleProxyWidget::ensureVisible()
144+
void ModuleProxyWidget::ensureThisVisible()
145+
{
146+
ensureItemVisible(this);
147+
}
148+
149+
void ModuleProxyWidget::ensureItemVisible(QGraphicsItem* item)
143150
{
144151
auto views = scene()->views();
145152
if (!views.isEmpty())
@@ -149,7 +156,7 @@ void ModuleProxyWidget::ensureVisible()
149156
{
150157
return; // the call below led to a crash when too zoomed in to fit a module.
151158
}
152-
views[0]->ensureVisible(this);
159+
views[0]->ensureVisible(item);
153160
}
154161
}
155162

@@ -211,6 +218,7 @@ static int snapTo(int oldPos)
211218

212219
void ModuleProxyWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
213220
{
221+
stackDepth_ = 0;
214222
auto taggingOn = data(TagLayerKey).toBool();
215223
if (taggingOn)
216224
return;
@@ -246,15 +254,25 @@ void ModuleProxyWidget::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
246254
{
247255
if (PortWidget* p = qobject_cast<PortWidget*>(pressedSubWidget_))
248256
{
249-
p->doMouseMove(event->buttons(), mapToScene(event->pos()));
257+
auto conn = p->doMouseMove(event->buttons(), mapToScene(event->pos()));
258+
if (conn)
259+
{
260+
stackDepth_++;
261+
if (stackDepth_ > 1)
262+
return;
263+
ensureItemVisible(conn);
264+
}
265+
stackDepth_ = 0;
250266
return;
251267
}
252268
if (grabbedByWidget_)
253269
{
254270
return;
255271
}
256-
ensureVisible();
272+
if (stackDepth_ == 0)
273+
ensureThisVisible();
257274
QGraphicsItem::mouseMoveEvent(event);
275+
stackDepth_ = 0;
258276
}
259277

260278
bool ModuleProxyWidget::isSubwidget(QWidget* alienWidget) const

src/Interface/Application/ModuleProxyWidget.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ namespace SCIRun
7070
virtual void setNoteGraphicsContext() override;
7171
private Q_SLOTS:
7272
void updateNote(const Note& note);
73-
void ensureVisible();
73+
void ensureThisVisible();
7474
private:
75+
void ensureItemVisible(QGraphicsItem* item);
7576
bool isSubwidget(QWidget* alienWidget) const;
7677
void updatePressedSubWidget(QGraphicsSceneMouseEvent* event);
7778
void addPort();
@@ -82,6 +83,7 @@ namespace SCIRun
8283
QPointF position_;
8384
QPointF cachedPosition_;
8485
bool doHighlight_;
86+
int stackDepth_;
8587
};
8688

8789
// arbitrary values

src/Interface/Application/Port.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,18 +257,19 @@ void PortWidget::mouseMoveEvent(QMouseEvent* event)
257257
doMouseMove(event->buttons(), event->pos());
258258
}
259259

260-
void PortWidget::doMouseMove(Qt::MouseButtons buttons, const QPointF& pos)
260+
QGraphicsItem* PortWidget::doMouseMove(Qt::MouseButtons buttons, const QPointF& pos)
261261
{
262262
if (buttons & Qt::LeftButton && (!isConnected() || !isInput()))
263263
{
264264
int distance = (pos - startPos_).manhattanLength();
265265
if (distance >= QApplication::startDragDistance())
266-
dragImpl(pos);
266+
return dragImpl(pos);
267267
}
268268
else
269269
{
270270
//qDebug() << "mouse move sth else";
271271
}
272+
return nullptr;
272273
}
273274

274275
void PortWidget::mouseReleaseEvent(QMouseEvent* event)
@@ -432,7 +433,7 @@ bool PortWidget::isFullInputPort() const
432433
return isInput() && !connections_.empty();
433434
}
434435

435-
void PortWidget::dragImpl(const QPointF& endPos)
436+
QGraphicsItem* PortWidget::dragImpl(const QPointF& endPos)
436437
{
437438
if (!currentConnection_)
438439
{
@@ -468,6 +469,7 @@ void PortWidget::dragImpl(const QPointF& endPos)
468469
minPotential->highlight(true);
469470
}
470471
}
472+
return dynamic_cast<QGraphicsItem*>(currentConnection_);
471473
}
472474

473475
template <typename Func, typename Pred>

src/Interface/Application/Port.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class PortWidget : public PortWidgetBase, public NeedsScenePositionProvider
131131
bool isFullInputPort() const;
132132

133133
void doMousePress(Qt::MouseButton button, const QPointF& pos);
134-
void doMouseMove(Qt::MouseButtons buttons, const QPointF& pos);
134+
QGraphicsItem* doMouseMove(Qt::MouseButtons buttons, const QPointF& pos);
135135
void doMouseRelease(Qt::MouseButton button, const QPointF& pos, Qt::KeyboardModifiers modifiers);
136136

137137
SCIRun::Dataflow::Networks::PortDataDescriber getPortDataDescriber() const { return portDataDescriber_; }
@@ -160,7 +160,7 @@ public Q_SLOTS:
160160
template <typename Func, typename Pred>
161161
static void forEachPort(Func func, Pred pred);
162162

163-
void dragImpl(const QPointF& endPos);
163+
QGraphicsItem* dragImpl(const QPointF& endPos);
164164
void makeConnection(const QPointF& pos);
165165
void tryConnectPort(const QPointF& pos, PortWidget* port, double threshold);
166166
bool matches(const SCIRun::Dataflow::Networks::ConnectionDescription& cd) const;

0 commit comments

Comments
 (0)