Changeset View
Changeset View
Standalone View
Standalone View
plugins/assistants/RulerAssistant/kis_ruler_assistant_tool.cc
Show First 20 Lines • Show All 227 Lines • ▼ Show 20 Line(s) | 219 | } else if (m_handleDrag == assistant->bottomMiddle()) { | |||
---|---|---|---|---|---|
228 | m_newAssistant->addHandle(m_selectedNode2); | 228 | m_newAssistant->addHandle(m_selectedNode2); | ||
229 | m_newAssistant->addHandle(m_selectedNode1); | 229 | m_newAssistant->addHandle(m_selectedNode1); | ||
230 | m_dragEnd = event->point; | 230 | m_dragEnd = event->point; | ||
231 | m_handleDrag = 0; | 231 | m_handleDrag = 0; | ||
232 | m_canvas->updateCanvas(); // TODO update only the relevant part of the canvas | 232 | m_canvas->updateCanvas(); // TODO update only the relevant part of the canvas | ||
233 | return; | 233 | return; | ||
234 | } | 234 | } | ||
235 | m_snapIsRadial = false; | 235 | m_snapIsRadial = false; | ||
236 | } else if (m_handleDrag && assistant->handles().size()>1 && (assistant->id() == "ruler" || | 236 | } | ||
237 | else if (m_handleDrag && assistant->handles().size()>1 && (assistant->id() == "ruler" || | ||||
237 | assistant->id() == "parallel ruler" || | 238 | assistant->id() == "parallel ruler" || | ||
238 | assistant->id() == "infinite ruler" || | 239 | assistant->id() == "infinite ruler" || | ||
239 | assistant->id() == "spline")){ | 240 | assistant->id() == "spline")){ | ||
240 | if (m_handleDrag == assistant->handles()[0]) { | 241 | if (m_handleDrag == assistant->handles()[0]) { | ||
241 | m_dragStart = *assistant->handles()[1]; | 242 | m_dragStart = *assistant->handles()[1]; | ||
242 | } else if (m_handleDrag == assistant->handles()[1]) { | 243 | } else if (m_handleDrag == assistant->handles()[1]) { | ||
243 | m_dragStart = *assistant->handles()[0]; | 244 | m_dragStart = *assistant->handles()[0]; | ||
244 | } else if(assistant->handles().size()==4){ | 245 | } else if(assistant->handles().size()==4){ | ||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | 285 | Q_FOREACH (KisPaintingAssistantSP assistant, m_canvas->paintingAssistantsDecoration()->assistants()) { | |||
295 | 296 | | |||
296 | 297 | | |||
297 | QRectF deleteRect(iconDeletePosition, QSizeF(16, 16)); | 298 | QRectF deleteRect(iconDeletePosition, QSizeF(16, 16)); | ||
298 | QRectF visibleRect(iconSnapPosition, QSizeF(16, 16)); | 299 | QRectF visibleRect(iconSnapPosition, QSizeF(16, 16)); | ||
299 | QRectF moveRect(iconMovePosition, QSizeF(32, 32)); | 300 | QRectF moveRect(iconMovePosition, QSizeF(32, 32)); | ||
300 | 301 | | |||
301 | if (moveRect.contains(mousePos)) { | 302 | if (moveRect.contains(mousePos)) { | ||
302 | m_assistantDrag = assistant; | 303 | m_assistantDrag = assistant; | ||
303 | m_mousePosition = event->point; | 304 | m_cursorStart = event->point; | ||
305 | m_currentAdjustment = QPointF(); | ||||
304 | m_internalMode = MODE_EDITING; | 306 | m_internalMode = MODE_EDITING; | ||
305 | return; | 307 | return; | ||
306 | } | 308 | } | ||
307 | if (deleteRect.contains(mousePos)) { | 309 | if (deleteRect.contains(mousePos)) { | ||
308 | removeAssistant(assistant); | 310 | removeAssistant(assistant); | ||
309 | if(m_canvas->paintingAssistantsDecoration()->assistants().isEmpty()) { | 311 | if(m_canvas->paintingAssistantsDecoration()->assistants().isEmpty()) { | ||
310 | m_internalMode = MODE_CREATION; | 312 | m_internalMode = MODE_CREATION; | ||
311 | } | 313 | } | ||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | 355 | { | |||
354 | if (m_handleDrag) { | 356 | if (m_handleDrag) { | ||
355 | *m_handleDrag = event->point; | 357 | *m_handleDrag = event->point; | ||
356 | //ported from the gradient tool... we need to think about this more in the future. | 358 | //ported from the gradient tool... we need to think about this more in the future. | ||
357 | if (event->modifiers() == Qt::ShiftModifier && m_snapIsRadial) { | 359 | if (event->modifiers() == Qt::ShiftModifier && m_snapIsRadial) { | ||
358 | QLineF dragRadius = QLineF(m_dragStart, event->point); | 360 | QLineF dragRadius = QLineF(m_dragStart, event->point); | ||
359 | dragRadius.setLength(m_radius.length()); | 361 | dragRadius.setLength(m_radius.length()); | ||
360 | *m_handleDrag = dragRadius.p2(); | 362 | *m_handleDrag = dragRadius.p2(); | ||
361 | } else if (event->modifiers() == Qt::ShiftModifier ) { | 363 | } else if (event->modifiers() == Qt::ShiftModifier ) { | ||
362 | *m_handleDrag = straightLine(event->point, m_dragStart); | 364 | QPointF move = snapToClosestAxis(event->point - m_dragStart); | ||
365 | *m_handleDrag = m_dragStart + move; | ||||
363 | } else { | 366 | } else { | ||
364 | *m_handleDrag = snapToGuide(event, QPointF(), false); | 367 | *m_handleDrag = snapToGuide(event, QPointF(), false); | ||
365 | } | 368 | } | ||
366 | m_handleDrag->uncache(); | 369 | m_handleDrag->uncache(); | ||
367 | 370 | | |||
368 | m_handleCombine = 0; | 371 | m_handleCombine = 0; | ||
369 | if (!(event->modifiers() & Qt::ShiftModifier)) { | 372 | if (!(event->modifiers() & Qt::ShiftModifier)) { | ||
370 | double minDist = 49.0; | 373 | double minDist = 49.0; | ||
371 | QPointF mousePos = m_canvas->viewConverter()->documentToView(event->point); | 374 | QPointF mousePos = m_canvas->viewConverter()->documentToView(event->point); | ||
372 | Q_FOREACH (const KisPaintingAssistantHandleSP handle, m_handles) { | 375 | Q_FOREACH (const KisPaintingAssistantHandleSP handle, m_handles) { | ||
373 | if (handle == m_handleDrag) continue; | 376 | if (handle == m_handleDrag) continue; | ||
374 | double dist = norm2(mousePos - m_canvas->viewConverter()->documentToView(*handle)); | 377 | double dist = norm2(mousePos - m_canvas->viewConverter()->documentToView(*handle)); | ||
375 | if (dist < minDist) { | 378 | if (dist < minDist) { | ||
376 | minDist = dist; | 379 | minDist = dist; | ||
377 | m_handleCombine = handle; | 380 | m_handleCombine = handle; | ||
378 | } | 381 | } | ||
379 | } | 382 | } | ||
380 | } | 383 | } | ||
381 | m_canvas->updateCanvas(); | 384 | m_canvas->updateCanvas(); | ||
382 | } else if (m_assistantDrag) { | 385 | } else if (m_assistantDrag) { | ||
383 | QPointF adjust = snapToGuide(event, QPointF(), false) - m_mousePosition; | 386 | QPointF newAdjustment = snapToGuide(event, QPointF(), false) - m_cursorStart; | ||
387 | if (event->modifiers() == Qt::ShiftModifier ) { | ||||
388 | newAdjustment = snapToClosestAxis(newAdjustment); | ||||
389 | } | ||||
384 | Q_FOREACH (KisPaintingAssistantHandleSP handle, m_assistantDrag->handles()) { | 390 | Q_FOREACH (KisPaintingAssistantHandleSP handle, m_assistantDrag->handles()) { | ||
385 | *handle += adjust; | 391 | *handle += (newAdjustment - m_currentAdjustment); | ||
386 | | ||||
387 | } | 392 | } | ||
388 | if (m_assistantDrag->id()== "vanishing point"){ | 393 | if (m_assistantDrag->id()== "vanishing point"){ | ||
389 | Q_FOREACH (KisPaintingAssistantHandleSP handle, m_assistantDrag->sideHandles()) { | 394 | Q_FOREACH (KisPaintingAssistantHandleSP handle, m_assistantDrag->sideHandles()) { | ||
390 | *handle += adjust; | 395 | *handle += (newAdjustment - m_currentAdjustment); | ||
391 | | ||||
392 | } | 396 | } | ||
393 | } | 397 | } | ||
394 | m_mousePosition = snapToGuide(event, QPointF(), false); | 398 | m_currentAdjustment = newAdjustment; | ||
395 | m_canvas->updateCanvas(); | 399 | m_canvas->updateCanvas(); | ||
396 | 400 | | |||
397 | } else { | 401 | } else { | ||
398 | event->ignore(); | 402 | event->ignore(); | ||
399 | } | 403 | } | ||
400 | 404 | | |||
401 | bool wasHiglightedNode = m_higlightedNode != 0; | 405 | bool wasHiglightedNode = m_higlightedNode != 0; | ||
402 | QPointF mousep = m_canvas->viewConverter()->documentToView(event->point); | 406 | QPointF mousep = m_canvas->viewConverter()->documentToView(event->point); | ||
▲ Show 20 Lines • Show All 162 Lines • ▼ Show 20 Line(s) | 568 | } else if (m_newAssistant && m_internalMode == MODE_DRAGGING_TRANSLATING_TWONODES) { | |||
565 | QPointF translate = event->point - m_dragEnd;; | 569 | QPointF translate = event->point - m_dragEnd;; | ||
566 | m_dragEnd = event->point; | 570 | m_dragEnd = event->point; | ||
567 | m_selectedNode1.data()->operator =(QPointF(m_selectedNode1.data()->x(),m_selectedNode1.data()->y()) + translate); | 571 | m_selectedNode1.data()->operator =(QPointF(m_selectedNode1.data()->x(),m_selectedNode1.data()->y()) + translate); | ||
568 | m_selectedNode2.data()->operator = (QPointF(m_selectedNode2.data()->x(),m_selectedNode2.data()->y()) + translate); | 572 | m_selectedNode2.data()->operator = (QPointF(m_selectedNode2.data()->x(),m_selectedNode2.data()->y()) + translate); | ||
569 | m_canvas->updateCanvas(); | 573 | m_canvas->updateCanvas(); | ||
570 | } | 574 | } | ||
571 | } | 575 | } | ||
572 | 576 | | |||
573 | QPointF KisRulerAssistantTool::straightLine(QPointF point, QPointF compare) | | |||
574 | { | | |||
575 | QPointF comparison = point - compare; | | |||
576 | QPointF result; | | |||
577 | | ||||
578 | if (fabs(comparison.x()) > fabs(comparison.y())) { | | |||
579 | result.setX(point.x()); | | |||
580 | result.setY(compare.y()); | | |||
581 | } else { | | |||
582 | result.setX(compare.x()); | | |||
583 | result.setY(point.y()); | | |||
584 | } | | |||
585 | | ||||
586 | return result; | | |||
587 | } | | |||
588 | | ||||
589 | void KisRulerAssistantTool::paint(QPainter& _gc, const KoViewConverter &_converter) | 577 | void KisRulerAssistantTool::paint(QPainter& _gc, const KoViewConverter &_converter) | ||
590 | { | 578 | { | ||
591 | 579 | | |||
592 | QPixmap iconDelete = KisIconUtils::loadIcon("dialog-cancel").pixmap(16, 16); | 580 | QPixmap iconDelete = KisIconUtils::loadIcon("dialog-cancel").pixmap(16, 16); | ||
593 | QPixmap iconSnapOn = KisIconUtils::loadIcon("visible").pixmap(16, 16); | 581 | QPixmap iconSnapOn = KisIconUtils::loadIcon("visible").pixmap(16, 16); | ||
594 | QPixmap iconSnapOff = KisIconUtils::loadIcon("novisible").pixmap(16, 16); | 582 | QPixmap iconSnapOff = KisIconUtils::loadIcon("novisible").pixmap(16, 16); | ||
595 | QPixmap iconMove = KisIconUtils::loadIcon("transform-move").pixmap(32, 32); | 583 | QPixmap iconMove = KisIconUtils::loadIcon("transform-move").pixmap(32, 32); | ||
596 | QColor handlesColor(0, 0, 0, 125); | 584 | QColor handlesColor(0, 0, 0, 125); | ||
▲ Show 20 Lines • Show All 322 Lines • Show Last 20 Lines |