mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Make it possible to drag a handle between handlers
Make it possible to drag a handle between handlers, this way the configuration of the dive is more acurate and easyer to make. I'v discovered a problem where it's a bit hard to 'grab' the handler, investigating it now. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
		
							parent
							
								
									603d2f5cb3
								
							
						
					
					
						commit
						20ec98f2a5
					
				
					 2 changed files with 26 additions and 33 deletions
				
			
		| 
						 | 
					@ -22,8 +22,7 @@ bool handlerLessThenMinutes(DiveHandler *d1, DiveHandler *d2){
 | 
				
			||||||
	return d1->sec < d2->sec;
 | 
						return d1->sec < d2->sec;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent), activeDraggedHandler(0),
 | 
					DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent), activeDraggedHandler(0)
 | 
				
			||||||
	lastValidPos(0.0, 0.0)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	fill_profile_color();
 | 
						fill_profile_color();
 | 
				
			||||||
	setBackgroundBrush(profile_color[BACKGROUND].at(0));
 | 
						setBackgroundBrush(profile_color[BACKGROUND].at(0));
 | 
				
			||||||
| 
						 | 
					@ -185,7 +184,6 @@ void DivePlannerGraphics::mouseDoubleClickEvent(QMouseEvent* event)
 | 
				
			||||||
	item->setPos(QPointF(xpos, ypos));
 | 
						item->setPos(QPointF(xpos, ypos));
 | 
				
			||||||
	scene()->addItem(item);
 | 
						scene()->addItem(item);
 | 
				
			||||||
	handles << item;
 | 
						handles << item;
 | 
				
			||||||
	qSort(handles.begin(), handles.end(), handlerLessThenMinutes);
 | 
					 | 
				
			||||||
	createDecoStops();
 | 
						createDecoStops();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -193,6 +191,7 @@ void DivePlannerGraphics::createDecoStops()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	qDeleteAll(lines);
 | 
						qDeleteAll(lines);
 | 
				
			||||||
	lines.clear();
 | 
						lines.clear();
 | 
				
			||||||
 | 
						qSort(handles.begin(), handles.end(), handlerLessThenMinutes);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// This needs to be done in the following steps:
 | 
						// This needs to be done in the following steps:
 | 
				
			||||||
	// Get the user-input and calculate the dive info
 | 
						// Get the user-input and calculate the dive info
 | 
				
			||||||
| 
						 | 
					@ -340,33 +339,9 @@ void DivePlannerGraphics::mouseMoveEvent(QMouseEvent* event)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DivePlannerGraphics::moveActiveHandler(const QPointF& pos)
 | 
					void DivePlannerGraphics::moveActiveHandler(const QPointF& pos)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int idx = handles.indexOf(activeDraggedHandler);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	double xpos = timeLine->posAtValue(rint(timeLine->valueAt(pos)));
 | 
						double xpos = timeLine->posAtValue(rint(timeLine->valueAt(pos)));
 | 
				
			||||||
	double ypos = depthLine->posAtValue(rint(depthLine->valueAt(pos)));
 | 
						double ypos = depthLine->posAtValue(rint(depthLine->valueAt(pos)));
 | 
				
			||||||
	QPointF newPos(xpos, ypos);
 | 
						activeDraggedHandler->setPos(QPointF(xpos, ypos));
 | 
				
			||||||
	// do not allow it to move between handlers.
 | 
					 | 
				
			||||||
	if (handles.count() > 1) {
 | 
					 | 
				
			||||||
		if (idx == 0 ) { // first
 | 
					 | 
				
			||||||
			if (newPos.x() < handles[1]->x()) {
 | 
					 | 
				
			||||||
				activeDraggedHandler->setPos(newPos);
 | 
					 | 
				
			||||||
				lastValidPos = newPos;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		} else if (idx == handles.count()-1) { // last
 | 
					 | 
				
			||||||
			if (newPos.x() > handles[idx-1]->x()) {
 | 
					 | 
				
			||||||
				activeDraggedHandler->setPos(newPos);
 | 
					 | 
				
			||||||
				lastValidPos = newPos;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		} else { // middle
 | 
					 | 
				
			||||||
			if (newPos.x() > handles[idx-1]->x() && newPos.x() < handles[idx+1]->x()) {
 | 
					 | 
				
			||||||
				activeDraggedHandler->setPos(newPos);
 | 
					 | 
				
			||||||
				lastValidPos = newPos;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		activeDraggedHandler->setPos(newPos);
 | 
					 | 
				
			||||||
		lastValidPos = newPos;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	qDeleteAll(lines);
 | 
						qDeleteAll(lines);
 | 
				
			||||||
	lines.clear();
 | 
						lines.clear();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -393,6 +368,7 @@ void DivePlannerGraphics::mousePressEvent(QMouseEvent* event)
 | 
				
			||||||
		if (DiveHandler *h = qgraphicsitem_cast<DiveHandler*>(item)) {
 | 
							if (DiveHandler *h = qgraphicsitem_cast<DiveHandler*>(item)) {
 | 
				
			||||||
			activeDraggedHandler = h;
 | 
								activeDraggedHandler = h;
 | 
				
			||||||
			activeDraggedHandler->setBrush(Qt::red);
 | 
								activeDraggedHandler->setBrush(Qt::red);
 | 
				
			||||||
 | 
								originalHandlerPos = activeDraggedHandler->pos();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	QGraphicsView::mousePressEvent(event);
 | 
						QGraphicsView::mousePressEvent(event);
 | 
				
			||||||
| 
						 | 
					@ -401,9 +377,26 @@ void DivePlannerGraphics::mousePressEvent(QMouseEvent* event)
 | 
				
			||||||
void DivePlannerGraphics::mouseReleaseEvent(QMouseEvent* event)
 | 
					void DivePlannerGraphics::mouseReleaseEvent(QMouseEvent* event)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (activeDraggedHandler) {
 | 
						if (activeDraggedHandler) {
 | 
				
			||||||
		activeDraggedHandler->sec = rint(timeLine->valueAt(lastValidPos)) * 60;
 | 
							QPointF mappedPos = mapToScene(event->pos());
 | 
				
			||||||
		activeDraggedHandler->mm = rint(depthLine->valueAt(lastValidPos)) * 1000;
 | 
							int minutes = rint(timeLine->valueAt(mappedPos));
 | 
				
			||||||
 | 
							int meters = rint(depthLine->valueAt(mappedPos));
 | 
				
			||||||
 | 
							double xpos = timeLine->posAtValue(minutes);
 | 
				
			||||||
 | 
							double ypos = depthLine->posAtValue(meters);
 | 
				
			||||||
 | 
							Q_FOREACH(DiveHandler* handler, handles){
 | 
				
			||||||
 | 
								if (xpos == handler->pos().x() && handler != activeDraggedHandler){
 | 
				
			||||||
 | 
									qDebug() << "There's already an point at that place.";
 | 
				
			||||||
 | 
									//TODO: Move this later to a KMessageWidget.
 | 
				
			||||||
 | 
									activeDraggedHandler->setPos(originalHandlerPos);
 | 
				
			||||||
 | 
									activeDraggedHandler = NULL;
 | 
				
			||||||
 | 
									return;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							activeDraggedHandler->sec = rint(timeLine->valueAt(mappedPos)) * 60;
 | 
				
			||||||
 | 
							activeDraggedHandler->mm = rint(depthLine->valueAt(mappedPos)) * 1000;
 | 
				
			||||||
		activeDraggedHandler->setBrush(QBrush(Qt::white));
 | 
							activeDraggedHandler->setBrush(QBrush(Qt::white));
 | 
				
			||||||
 | 
							activeDraggedHandler->setPos(QPointF(xpos, ypos));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		createDecoStops();
 | 
							createDecoStops();
 | 
				
			||||||
		activeDraggedHandler = 0;
 | 
							activeDraggedHandler = 0;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -73,7 +73,6 @@ protected:
 | 
				
			||||||
	bool isPointOutOfBoundaries(const QPointF& point);
 | 
						bool isPointOutOfBoundaries(const QPointF& point);
 | 
				
			||||||
	void deleteTemporaryDivePlan(struct divedatapoint* dp);
 | 
						void deleteTemporaryDivePlan(struct divedatapoint* dp);
 | 
				
			||||||
	qreal fromPercent(qreal percent, Qt::Orientation orientation);
 | 
						qreal fromPercent(qreal percent, Qt::Orientation orientation);
 | 
				
			||||||
 | 
					 | 
				
			||||||
private slots:
 | 
					private slots:
 | 
				
			||||||
	void increaseTime();
 | 
						void increaseTime();
 | 
				
			||||||
	void increaseDepth();
 | 
						void increaseDepth();
 | 
				
			||||||
| 
						 | 
					@ -96,8 +95,9 @@ private:
 | 
				
			||||||
	/* This is the handler that's being dragged. */
 | 
						/* This is the handler that's being dragged. */
 | 
				
			||||||
	DiveHandler *activeDraggedHandler;
 | 
						DiveHandler *activeDraggedHandler;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// helper to save the positions where the drag-handler is valid.
 | 
						// When we start to move the handler, this pos is saved.
 | 
				
			||||||
	QPointF lastValidPos;
 | 
						// so we can revert it later.
 | 
				
			||||||
 | 
						QPointF originalHandlerPos;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* this is the background of the dive, the blue-gradient. */
 | 
						/* this is the background of the dive, the blue-gradient. */
 | 
				
			||||||
	QGraphicsPolygonItem *diveBg;
 | 
						QGraphicsPolygonItem *diveBg;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue