mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Make the plot and handle movement stick to an 'Grid'
Make the plot and the handle stick to a grid, the grid is defined by the integers in the rulers, so a time of 10,2 is converted to 10, and will put the point at 10. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
parent
c9159da43a
commit
01d1a49d94
2 changed files with 25 additions and 16 deletions
|
@ -1,4 +1,5 @@
|
||||||
#include "diveplanner.h"
|
#include "diveplanner.h"
|
||||||
|
#include <cmath>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include "ui_diveplanner.h"
|
#include "ui_diveplanner.h"
|
||||||
|
@ -19,7 +20,7 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent)
|
||||||
|
|
||||||
timeLine = new Ruler();
|
timeLine = new Ruler();
|
||||||
timeLine->setMinimum(0);
|
timeLine->setMinimum(0);
|
||||||
timeLine->setMaximum(60);
|
timeLine->setMaximum(20);
|
||||||
timeLine->setTickInterval(10);
|
timeLine->setTickInterval(10);
|
||||||
timeLine->setLine( 10, 90, 99, 90);
|
timeLine->setLine( 10, 90, 99, 90);
|
||||||
timeLine->setOrientation(Qt::Horizontal);
|
timeLine->setOrientation(Qt::Horizontal);
|
||||||
|
@ -28,7 +29,7 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent)
|
||||||
|
|
||||||
depthLine = new Ruler();
|
depthLine = new Ruler();
|
||||||
depthLine->setMinimum(0);
|
depthLine->setMinimum(0);
|
||||||
depthLine->setMaximum(400);
|
depthLine->setMaximum(10);
|
||||||
depthLine->setTickInterval(10);
|
depthLine->setTickInterval(10);
|
||||||
depthLine->setLine( 10, 1, 10, 90);
|
depthLine->setLine( 10, 1, 10, 90);
|
||||||
depthLine->setOrientation(Qt::Vertical);
|
depthLine->setOrientation(Qt::Vertical);
|
||||||
|
@ -57,7 +58,10 @@ void DivePlannerGraphics::mouseDoubleClickEvent(QMouseEvent* event)
|
||||||
DiveHandler *item = new DiveHandler ();
|
DiveHandler *item = new DiveHandler ();
|
||||||
item->setRect(-5,-5,10,10);
|
item->setRect(-5,-5,10,10);
|
||||||
item->setFlag(QGraphicsItem::ItemIgnoresTransformations);
|
item->setFlag(QGraphicsItem::ItemIgnoresTransformations);
|
||||||
item->setPos( mappedPos );
|
|
||||||
|
double xpos = timeLine->posAtValue(rint(timeLine->valueAt(mappedPos)));
|
||||||
|
double ypos = depthLine->posAtValue(rint(depthLine->valueAt(mappedPos)));
|
||||||
|
item->setPos( QPointF(xpos, ypos));
|
||||||
scene()->addItem(item);
|
scene()->addItem(item);
|
||||||
handles << item;
|
handles << item;
|
||||||
|
|
||||||
|
@ -164,41 +168,46 @@ void DivePlannerGraphics::mouseMoveEvent(QMouseEvent* event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DivePlannerGraphics::moveActiveHandler(QPointF pos)
|
void DivePlannerGraphics::moveActiveHandler(const QPointF& pos)
|
||||||
{
|
{
|
||||||
int idx = handles.indexOf(activeDraggedHandler);
|
int idx = handles.indexOf(activeDraggedHandler);
|
||||||
|
|
||||||
|
double xpos = timeLine->posAtValue(rint(timeLine->valueAt(pos)));
|
||||||
|
double ypos = depthLine->posAtValue(rint(depthLine->valueAt(pos)));
|
||||||
|
|
||||||
|
QPointF newPos(xpos, ypos);
|
||||||
bool moveLines = false;;
|
bool moveLines = false;;
|
||||||
// do not allow it to move between handlers.
|
// do not allow it to move between handlers.
|
||||||
if (handles.count() > 1){
|
if (handles.count() > 1){
|
||||||
if (idx == 0 ){ // first
|
if (idx == 0 ){ // first
|
||||||
if (pos.x() < handles[1]->x()){
|
if (newPos.x() < handles[1]->x()){
|
||||||
activeDraggedHandler->setPos(pos);
|
activeDraggedHandler->setPos(newPos);
|
||||||
moveLines = true;
|
moveLines = true;
|
||||||
}
|
}
|
||||||
}else if (idx == handles.count()-1){ // last
|
}else if (idx == handles.count()-1){ // last
|
||||||
if (pos.x() > handles[idx-1]->x()){
|
if (newPos.x() > handles[idx-1]->x()){
|
||||||
activeDraggedHandler->setPos(pos);
|
activeDraggedHandler->setPos(newPos);
|
||||||
moveLines = true;
|
moveLines = true;
|
||||||
}
|
}
|
||||||
}else{ // middle
|
}else{ // middle
|
||||||
if (pos.x() > handles[idx-1]->x() && pos.x() < handles[idx+1]->x()){
|
if (newPos.x() > handles[idx-1]->x() && newPos.x() < handles[idx+1]->x()){
|
||||||
activeDraggedHandler->setPos(pos);
|
activeDraggedHandler->setPos(newPos);
|
||||||
moveLines = true;
|
moveLines = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
activeDraggedHandler->setPos(pos);
|
activeDraggedHandler->setPos(newPos);
|
||||||
moveLines = true;
|
moveLines = true;
|
||||||
}
|
}
|
||||||
if (moveLines){
|
if (moveLines){
|
||||||
if (activeDraggedHandler->from){
|
if (activeDraggedHandler->from){
|
||||||
QLineF f = activeDraggedHandler->from->line();
|
QLineF f = activeDraggedHandler->from->line();
|
||||||
activeDraggedHandler->from->setLine(f.x1(), f.y1(), pos.x(), pos.y());
|
activeDraggedHandler->from->setLine(f.x1(), f.y1(), newPos.x(), newPos.y());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activeDraggedHandler->to){
|
if (activeDraggedHandler->to){
|
||||||
QLineF f = activeDraggedHandler->to->line();
|
QLineF f = activeDraggedHandler->to->line();
|
||||||
activeDraggedHandler->to->setLine(pos.x(), pos.y(), f.x2(), f.y2());
|
activeDraggedHandler->to->setLine(newPos.x(), newPos.y(), f.x2(), f.y2());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(activeDraggedHandler == handles.last()){
|
if(activeDraggedHandler == handles.last()){
|
||||||
|
@ -208,7 +217,7 @@ void DivePlannerGraphics::moveActiveHandler(QPointF pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DivePlannerGraphics::isPointOutOfBoundaries(QPointF point)
|
bool DivePlannerGraphics::isPointOutOfBoundaries(const QPointF& point)
|
||||||
{
|
{
|
||||||
double xpos = timeLine->valueAt(point);
|
double xpos = timeLine->valueAt(point);
|
||||||
double ypos = depthLine->valueAt(point);
|
double ypos = depthLine->valueAt(point);
|
||||||
|
|
|
@ -51,11 +51,11 @@ protected:
|
||||||
|
|
||||||
void clear_generated_deco();
|
void clear_generated_deco();
|
||||||
void create_deco_stop();
|
void create_deco_stop();
|
||||||
bool isPointOutOfBoundaries(QPointF point);
|
bool isPointOutOfBoundaries(const QPointF& point);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void moveActiveHandler(QPointF pos);
|
void moveActiveHandler(const QPointF& pos);
|
||||||
QList<QGraphicsLineItem*> lines;
|
QList<QGraphicsLineItem*> lines;
|
||||||
QList<DiveHandler *> handles;
|
QList<DiveHandler *> handles;
|
||||||
QGraphicsLineItem *verticalLine;
|
QGraphicsLineItem *verticalLine;
|
||||||
|
|
Loading…
Add table
Reference in a new issue