Skip to content

Commit

Permalink
Started implementation of middle click drag: see myscene.cpp for wher…
Browse files Browse the repository at this point in the history
…e we currently are. Slack message explains confusion - mouseDownViewCenter when mapped to scene coordinates appears to just be giving the centre of the scene, rather than mapping the viewport centre to scene coordinates as I expected. Suspect I'm missing something obvious
  • Loading branch information
RussellGarwood committed Apr 29, 2020
1 parent e79e261 commit f43f9d0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions SPIERSedit/src/mainview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void mainview::wheelEvent(QWheelEvent *event)
{
//event->ignore();
AppMainWindow->MouseZoom(event->delta());

}

/**
Expand Down
30 changes: 29 additions & 1 deletion SPIERSedit/src/myscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

myscene *scene;
int Counter2;
int dx, dy;
QPointF mouseDownViewCenter;


myscene::myscene() : QGraphicsScene()
Expand All @@ -39,6 +41,7 @@ myscene::myscene() : QGraphicsScene()

void myscene::DoMouse(int x, int y, int PressedButton)
{

if (x != LastMouseX || y != LastMouseY) // an actual move
{

Expand Down Expand Up @@ -80,6 +83,20 @@ void myscene::DoMouse(int x, int y, int PressedButton)
return;
}

if (PressedButton == 3 && button == 0)
{
Counter2 = 0;
button = 3;
dx = LastMouseX;
dy = LastMouseY;

mouseDownViewCenter = mainwin->graphicsView->mapToScene(mainwin->graphicsView->viewport()->rect().center());
qDebug() << mouseDownViewCenter << mainwin->graphicsView->viewport()->rect().center();

DoAction(LastMouseX, LastMouseY);
return;
}

//catch button swaps
if (PressedButton == 1 && button == 2)
{
Expand Down Expand Up @@ -126,6 +143,16 @@ void myscene::DoAction(int x, int y)
ChangeFlag = true;
MouseUp();
}
else if (button == 3)
{
//Translate here

//int xmove = dx - x;
// qDebug() << dx << x << xmove << mouseDownViewCenter;
//mainwin->graphicsView->centerOn(mouseDownView.x() + xmove, mouseDownView.y());
//mainwin->graphicsView->show();
// mainwin->graphicsView->horizontalScrollBar()->setValue(newX);
}
else
{
//CurrentMode; //0=bright, 1=masks, 2=curves, 3=lock, 4=segment, 5=recalc
Expand Down Expand Up @@ -175,14 +202,14 @@ void myscene::DoAction(int x, int y)
else Brush.segment(LastMouseX, LastMouseY, 0);
break;
case 5:

if (tabwidget->currentIndex() < 2 || RangeSelectedOnly)
Brush.recalc(LastMouseX, LastMouseY, CurrentSegment);
else
//all segs
for (int i = 0; i < SegmentCount; i++) if (Segments[i]->Activated) Brush.recalc(LastMouseX, LastMouseY, i);
break;
}

ChangeFlag = true;
}
}
Expand All @@ -199,6 +226,7 @@ void myscene::mousePressEvent(QGraphicsSceneMouseEvent *event )
int but = 0;
if (event->button() == Qt::LeftButton) but = 1;
if (event->button() == Qt::RightButton) but = 2;
if (event->button() == Qt::MiddleButton) but = 3;

DoMouse(x, y, but);
return;
Expand Down

0 comments on commit f43f9d0

Please sign in to comment.