/** 
 *	This method tells if the user is doing a valid drag in the window. A valid
 *	drag is started when the user presses down a mouse button in the window and
 *	moves the mouse inside the window without releasing the button. To start
 *	a drag, a client class calls "setDragging" with "true" when it receives a 
 *	Mouse Key Down event, and calls it with "false" when it receives the
 *	Mouse Key Up event top end dragging.
 *	NOTE: this function also updates state variables in case the mouse button
 *	was released outside the client area of the window.
 *
 *	@param key		Mouse button pressed or released
 *	@return 		True if the user is still dragging with the given key,
 *					false otherwise.
 */
bool MouseDragHandler::isDragging( MouseKey key ) const
{
	bool mouseKey = false;

	switch ( key )
	{
	case KEY_LEFTMOUSE:
		mouseKey = 
			updateDragging(
				InputDevices::isKeyDown( KeyEvent::KEY_LEFTMOUSE ),
				draggingLeftMouse_ );
		break;

	case KEY_MIDDLEMOUSE:
		mouseKey = 
			updateDragging(
				InputDevices::isKeyDown( KeyEvent::KEY_MIDDLEMOUSE ),
				draggingMiddleMouse_ );
		break;

	case KEY_RIGHTMOUSE:
		mouseKey = 
			updateDragging(
				InputDevices::isKeyDown( KeyEvent::KEY_RIGHTMOUSE ),
				draggingRightMouse_ );
		break;
	}

	return mouseKey;
}
Пример #2
0
bool TextObjectEditorHelper::mouseMoveEvent(QMouseEvent* event, MapCoordF map_coord, MapWidget* widget)
{
	bool mouse_down = event->buttons() & Qt::LeftButton;
	if (!mouse_down)
	{
		if (object->calcTextPositionAt(map_coord, true) >= 0)
		{
			if (!original_cursor_retrieved)
			{
				original_cursor = widget->cursor();
				original_cursor_retrieved = true;
			}
			widget->setCursor(Qt::IBeamCursor);
		}
		else
			widget->setCursor(original_cursor);
	}
	else
	{
		dragging = true;
		updateDragging(map_coord);
	}
	
	return true;
}
Пример #3
0
bool ScaleTool::mouseReleaseEvent(QMouseEvent* event, MapCoordF map_coord, MapWidget* widget)
{
	Q_UNUSED(widget);
	
	if (event->button() != Qt::LeftButton)
		return false;
	
	if (!scaling)
	{
		scaling_center = map_coord;
		scaling_center_set = true;
	}
	else
	{
		scaling = false;
		updateDragging(map_coord);
		finishEditingSelection(*renderables, *old_renderables, true);
		map()->setObjectsDirty();
		map()->emitSelectionEdited();
	}
	
	updateDirtyRect();
	updateStatusText();
	return true;
}
Пример #4
0
bool CutTool::mouseReleaseEvent(QMouseEvent* event, MapCoordF map_coord, MapWidget* widget)
{
	if (path_tool)
		return path_tool->mouseReleaseEvent(event, map_coord, widget);
	
	if (event->button() != Qt::LeftButton)
		return false;
	
	if (dragging)
	{
		updateDragging(map_coord, widget);
		
		if (dragging_on_line)
		{
			Q_ASSERT(edit_object->getType() == Object::Path);
			splitLine(edit_object, drag_part_index, drag_start_len, drag_end_len);
		}
		
		deletePreviewPath();
		dragging = false;
	}
	else
	{
		PathCoord split_pos;
		if (findEditPoint(split_pos, edit_object, map_coord, (int)Symbol::Line, 0, widget))
		{
			Q_ASSERT(edit_object->getType() == Object::Path);
			splitLine(edit_object, split_pos);
		}
	}
	
	setEditingInProgress(false);
	return true;
}
Пример #5
0
bool TextObjectEditorHelper::mouseReleaseEvent(QMouseEvent* event, MapCoordF map_coord, MapWidget* widget)
{
	Q_UNUSED(widget);
	
	if (event->button() != Qt::LeftButton)
		return false;
	
	if (dragging)
	{
		updateDragging(map_coord);
		dragging = false;
		return true;
	}
	else if (object->calcTextPositionAt(map_coord, true) >= 0)
		return true;

	return false;
}
Пример #6
0
bool PrintTool::mouseMoveEvent(QMouseEvent* event, MapCoordF map_coord, MapWidget* widget)
{
	if (dragging && event->buttons() & Qt::LeftButton)
	{
		if (region == Outside)
		{
			mapWidget()->getMapView()->setPanOffset(event->pos() - click_pos);
		}
		else
		{
			updateDragging(map_coord);
		}
		return true;
	}
	
	mouseMoved(map_coord, widget);
	return false;
}
Пример #7
0
bool ScaleTool::mouseMoveEvent(QMouseEvent* event, MapCoordF map_coord, MapWidget* widget)
{
	Q_UNUSED(widget);
	
	if (!(event->buttons() & Qt::LeftButton))
		return false;
	
	if (scaling)
		updateDragging(map_coord);
	else if ( !scaling && scaling_center_set &&
			  (event->pos() - click_pos).manhattanLength() >= Settings::getInstance().getStartDragDistancePx() )
	{
		// Start scaling
		scaling = true;
		original_scale = (map_coord - scaling_center).length();
		startEditingSelection(*old_renderables);
	}
	return true;
}
Пример #8
0
bool PrintTool::mouseReleaseEvent(QMouseEvent* event, MapCoordF map_coord, MapWidget* widget)
{
	if (dragging && event->button() == Qt::LeftButton)
	{
		if (region == Outside)
		{
			mapWidget()->getMapView()->finishPanning(event->pos() - click_pos);
		}
		else
		{
			updateDragging(map_coord);
		}
		dragging = false;
		region = Unknown; // forces mouseMoved() to update cursor and status
		mouseMoved(map_coord, widget);
		return true;
	}
	
	return false;
}
Пример #9
0
bool MapEditorToolBase::mouseMoveEvent(QMouseEvent* event, MapCoordF map_coord, MapWidget* widget)
{
	auto old_constrained_pos     = constrained_pos;
	auto old_constrained_pos_map = constrained_pos_map;
	
	active_modifiers = Qt::KeyboardModifiers(event->modifiers() | (key_button_bar ? key_button_bar->activeModifiers() : 0));
	cur_pos = event->pos();
	cur_pos_map = map_coord;
	calcConstrainedPositions(widget);
	
	if (event->buttons().testFlag(Qt::LeftButton))
	{
		if (dragging)
		{
			updateDragging();
		}
		else if (dragging_canceled)
		{
			click_pos = cur_pos;
			click_pos_map = cur_pos_map;
			dragging_canceled = false;
		}
		else if ((cur_pos - click_pos).manhattanLength() >= start_drag_distance)
		{
			// Use the actual click and current position to detect dragging, but
			// use the constrained variant of the click position as start of the
			// dragging operation.
			click_pos     = old_constrained_pos;
			click_pos_map = old_constrained_pos_map;
			startDragging();
		}
		return true;
	}
	else
	{
		mouseMove();
		return false;
	}
}
Пример #10
0
bool CutTool::mouseMoveEvent(QMouseEvent* event, MapCoordF map_coord, MapWidget* widget)
{
	if (path_tool)
		return path_tool->mouseMoveEvent(event, map_coord, widget);
	
	bool mouse_down = event->buttons() & Qt::LeftButton;
	if (!mouse_down || dragging)
		updateHoverState(widget->mapToViewport(map_coord), widget);
	
	if (mouse_down)
	{
		if (!dragging && (event->pos() - click_pos).manhattanLength() >= Settings::getInstance().getStartDragDistancePx())
		{
			// Start dragging
			dragging = true;
			dragging_on_line = false;
			setEditingInProgress(true);
			
			PathCoord split_pos;
			if (findEditPoint(split_pos, edit_object, click_pos_map, (int)Symbol::Line, (int)Symbol::Area, widget))
			{
				drag_start_len = split_pos.clen;
				drag_end_len = drag_start_len;
				drag_part_index = edit_object->findPartIndexForIndex(split_pos.index);
				drag_forward = true;
				dragging_on_line = true;
			}
		}
		else if (dragging)
		{
			updateDragging(map_coord, widget);
		}
		return true;
	}
	return false;
}