void QtUtil :: Grid3DView :: keyReleaseEvent (QKeyEvent * e) { switch (e -> key ()) { case Qt :: Key_Shift: if (0 == m_drag_info .di && 0 == m_drag_info .dk) { m_drag_info = DragInfo (); QWidget :: keyReleaseEvent (e); update (); return; } drag (to_global (m_drag_info .di, m_drag_info .dk)); m_drag_info = DragInfo (); break; case Qt :: Key_Up: case Qt :: Key_Down: if (false == m_drag_info .dragging) { QWidget :: keyReleaseEvent (e); return; } m_drag_info .dk = 0; update (); break; case Qt :: Key_Left: case Qt :: Key_Right: if (false == m_drag_info .dragging) { QWidget :: keyReleaseEvent (e); return; } m_drag_info .di = 0; update (); break; }; e -> accept (); }
RestrictedDragPolicy::DragInfo ClipToolController::MoveClipPointPart::doStartDrag(const InputState& inputState) { if (inputState.mouseButtons() != MouseButtons::MBLeft || inputState.modifierKeys() != ModifierKeys::MKNone) return DragInfo(); Vec3 initialPoint; if (!m_callback->tool()->beginDragPoint(inputState.pickResult(), initialPoint)) return DragInfo(); DragRestricter* restricter = m_callback->createDragRestricter(inputState, initialPoint); DragSnapper* snapper = m_callback->createDragSnapper(inputState); return DragInfo(restricter, snapper, initialPoint); }
RestrictedDragPolicy::DragInfo ClipToolController::AddClipPointPart::doStartDrag(const InputState& inputState) { if (inputState.mouseButtons() != MouseButtons::MBLeft || inputState.modifierKeys() != ModifierKeys::MKNone) return DragInfo(); Vec3 initialPoint; if (!m_callback->addClipPoint(inputState, initialPoint)) return DragInfo(); m_secondPointSet = false; DragRestricter* restricter = m_callback->createDragRestricter(inputState, initialPoint); DragSnapper* snapper = m_callback->createDragSnapper(inputState); return DragInfo(restricter, snapper, initialPoint); }
Simulation::Simulation() : coordinateSystem(sf::Rect<float>(-10, 7.5, 20, -15)), dragInfo(DragInfo()), _dragging(false) { mySolver.myEval = this; }
DragInfo doStartDrag(const InputState& inputState) { if (!inputState.modifierKeysDown(ModifierKeys::MKShift)) return DragInfo(); if (!m_tool->polyhedron().polygon()) return DragInfo(); m_oldPolyhedron = m_tool->polyhedron(); const Polyhedron3::FaceHit hit = m_oldPolyhedron.pickFace(inputState.pickRay()); const Vec3 origin = inputState.pickRay().pointAtDistance(hit.distance); const Vec3 direction = hit.face->normal(); const Line3 line(origin, direction); m_dragDir = line.direction; return DragInfo(new LineDragRestricter(line), new NoDragSnapper(), origin); }
DragInfo doStartDrag(const InputState& inputState) { if (inputState.modifierKeysDown(ModifierKeys::MKShift)) return DragInfo(); const Model::PickResult& pickResult = inputState.pickResult(); const Model::Hit& hit = pickResult.query().pickable().type(Model::Brush::BrushHit).occluded().first(); if (!hit.isMatch()) return DragInfo(); m_oldPolyhedron = m_tool->polyhedron(); const Model::BrushFace* face = Model::hitToFace(hit); m_plane = face->boundary(); m_initialPoint = hit.hitPoint(); updatePolyhedron(m_initialPoint); SurfaceDragRestricter* restricter = new SurfaceDragRestricter(); restricter->setPickable(true); restricter->setType(Model::Brush::BrushHit); restricter->setOccluded(true); return DragInfo(restricter, new NoDragSnapper(), m_initialPoint); }
void QtUtil :: Grid3DView :: keyPressEvent (QKeyEvent * e) { const bool ctrl = e -> modifiers () & Qt :: ControlModifier; const int MOVE = ctrl ? 1 + m_width / 2 : 1; auto quick_drag = [&] () { auto delta = to_global (m_drag_info .di, m_drag_info .dk); drag (delta); auto p = m_position + delta; set_position (p .x, p .y, p .z); m_drag_info = DragInfo (); m_drag_info .dragging = true; }; switch (e -> key ()) { case Qt :: Key_Shift: m_drag_info .dragging = true; QWidget :: keyPressEvent (e); return; case Qt :: Key_Equal: set_width (m_width + 1); break; case Qt :: Key_Minus: set_width (m_width - 1); break; case Qt :: Key_Up: if (m_drag_info .dragging) { m_drag_info .dk = 1; if (ctrl) quick_drag (); update (); } else move_k (MOVE); break; case Qt :: Key_Down: if (m_drag_info .dragging) { m_drag_info .dk = -1; if (ctrl) quick_drag (); update (); } else move_k (-MOVE); break; case Qt :: Key_Right: if (m_drag_info .dragging) { m_drag_info .di = 1; if (ctrl) quick_drag (); update (); } else move_i (MOVE); break; case Qt :: Key_Left: if (m_drag_info .dragging) { m_drag_info .di = -1; if (ctrl) quick_drag (); update (); } else move_i (-MOVE); break; case Qt :: Key_PageUp: move_m (MOVE); break; case Qt :: Key_PageDown: move_m (-MOVE); break; default: QWidget :: keyPressEvent (e); return; }; e -> accept (); }