bool DrawRectangleTool::keyReleaseEvent(QKeyEvent* event) { if (event->key() == Qt::Key_Control) { ctrl_pressed = false; if (!picked_direction && (!editingInProgress() || (editingInProgress() && angles.size() == 1))) { angle_helper->setActive(false); if (dragging && editingInProgress()) updateRectangle(); } else if (editingInProgress() && angles.size() > 2) { updateRectangle(); } if (picked_direction) picked_direction = false; updateStatusText(); } else if (event->key() == Qt::Key_Shift) { shift_pressed = false; updateHover(false); updateStatusText(); } else return false; return true; }
void DrawRectangleTool::updateHover(bool mouse_down) { if (shift_pressed) constrained_pos_map = MapCoordF(snap_helper->snapToObject(cur_pos_map, cur_map_widget)); else constrained_pos_map = cur_pos_map; if (!editingInProgress()) { setPreviewPointsPosition(constrained_pos_map); updateDirtyRect(); if (mouse_down && ctrl_pressed) pickDirection(constrained_pos_map, cur_map_widget); else if (!mouse_down) angle_helper->setCenter(constrained_pos_map); } else { hidePreviewPoints(); if (mouse_down && !dragging && (cur_pos - click_pos).manhattanLength() >= Settings::getInstance().getStartDragDistancePx()) { // Start dragging dragging = true; } if (!mouse_down || dragging) updateRectangle(); } }
void DrawRectangleTool::undoLastPoint() { if (angles.size() == 1) { abortDrawing(); return; } deleteClosePoint(); preview_path->deleteCoordinate(preview_path->getCoordinateCount() - 1, false); if (angles.size() == 2) preview_path->deleteCoordinate(preview_path->getCoordinateCount() - 1, false); angles.pop_back(); forward_vector = MapCoordF(1, 0); forward_vector.rotate(-angles[angles.size() - 1]); angle_helper->setCenter(MapCoordF(preview_path->getCoordinate(angles.size() - 1))); updateRectangle(); }
void SelectionPlugin::onMouseDrag( const MouseDragEvent& event ) { EventManager* events = editor->getEventManager(); if( events->getCurrentToolId() != SelectionTool::Select ) return; if( !event.info->leftButton ) return; if( !selections->dragRectangle ) { selections->dragRectangle = createRectangle(); Document* document = editor->getDocument(); if( !document ) return; SceneDocument* sceneDocument = (SceneDocument*) document; sceneDocument->editorScene->entities.add(selections->dragRectangle); } updateRectangle( event, selections->dragRectangle.get() ); }
bool DrawRectangleTool::keyPressEvent(QKeyEvent* event) { if (event->key() == Qt::Key_Return) { if (editingInProgress()) { if (angles.size() <= 1) abortDrawing(); else { constrained_pos_map = MapCoordF(preview_path->getCoordinate(angles.size() - 1)); undoLastPoint(); finishDrawing(); } } } else if (event->key() == Qt::Key_Escape) { if (editingInProgress()) abortDrawing(); } else if (event->key() == Qt::Key_Backspace) { if (editingInProgress()) { undoLastPoint(); updateHover(false); } } else if (event->key() == Qt::Key_Tab) { deactivate(); } else if (event->key() == Qt::Key_Space) { draw_dash_points = !draw_dash_points; updateStatusText(); } else if (event->key() == Qt::Key_Control) { ctrl_pressed = true; if (editingInProgress() && angles.size() == 1) { angle_helper->clearAngles(); angle_helper->addDefaultAnglesDeg(0); angle_helper->setActive(true, MapCoordF(preview_path->getCoordinate(0))); if (dragging) updateRectangle(); } else if (editingInProgress() && angles.size() > 2) { // Try to snap to existing lines updateRectangle(); } updateStatusText(); } else if (event->key() == Qt::Key_Shift) { shift_pressed = true; updateHover(false); updateStatusText(); } else return false; return true; }