Krita Source Code Documentation
Loading...
Searching...
No Matches
KisGuidesManager::Private Struct Reference

Public Types

typedef QPair< Qt::Orientation, int > GuideHandle
 

Public Member Functions

QPointF alignToPixels (const QPointF docPoint)
 
QAction * createShortenedAction (const QString &text, const QString &parentId, QObject *parent)
 
void createUndoCommandIfNeeded ()
 
void deleteGuide (const GuideHandle &h)
 
GuideHandle findGuide (const QPointF &docPos)
 
Qt::MouseButton getButtonFromEvent (QEvent *event)
 
QPointF getDocPointFromEvent (QEvent *event)
 
qreal guideValue (const GuideHandle &h)
 
void initDragStart (const GuideHandle &guide, const QPointF &dragStart, qreal guideValue, bool snapToStart)
 
bool isGuideValid (const GuideHandle &h)
 
bool mouseMoveHandler (const QPointF &docPos, Qt::KeyboardModifiers modifiers)
 
bool mouseReleaseHandler (const QPointF &docPos)
 
bool needsUndoCommand ()
 
 Private (KisGuidesManager *_q)
 
void setGuideValue (const GuideHandle &h, qreal value)
 
void syncAction (const QString &actionName, bool value)
 
bool updateCursor (const QPointF &docPos, bool forceDisableCursor=false)
 
void updateSnappingStatus (const KisGuidesConfig &value)
 

Public Attributes

GuideHandle currentGuide
 
bool cursorSwitched
 
KisGuidesDecorationdecoration
 
QPointF dragPointerOffset
 
QPointF dragStartDoc
 
qreal dragStartGuidePos
 
KisGuidesConfig guidesConfig
 
const GuideHandle invalidGuide
 
QCursor oldCursor
 
KisGuidesConfig oldGuidesConfig
 
KisGuidesManagerq
 
bool shouldSetModified
 
KisSnapConfig snapConfig
 
QPointer< KisViewview
 
KisSignalAutoConnectionsStore viewConnections
 

Detailed Description

Definition at line 32 of file kis_guides_manager.cpp.

Member Typedef Documentation

◆ GuideHandle

typedef QPair<Qt::Orientation, int> KisGuidesManager::Private::GuideHandle

Definition at line 51 of file kis_guides_manager.cpp.

Constructor & Destructor Documentation

◆ Private()

KisGuidesManager::Private::Private ( KisGuidesManager * _q)
inline

Member Function Documentation

◆ alignToPixels()

QPointF KisGuidesManager::Private::alignToPixels ( const QPointF docPoint)

Definition at line 519 of file kis_guides_manager.cpp.

520{
521 KisCanvas2 *canvas = view->canvasBase();
522 const KisCoordinatesConverter *converter = canvas->coordinatesConverter();
523 QPoint imagePoint = converter->documentToImage(docPoint).toPoint();
524 return converter->imageToDocument(imagePoint);
525}
KisCoordinatesConverter * coordinatesConverter
_Private::Traits< T >::Result documentToImage(const T &obj) const
_Private::Traits< T >::Result imageToDocument(const T &obj) const

References KisCanvas2::coordinatesConverter, KisCoordinatesConverter::documentToImage(), and KisCoordinatesConverter::imageToDocument().

◆ createShortenedAction()

QAction * KisGuidesManager::Private::createShortenedAction ( const QString & text,
const QString & parentId,
QObject * parent )

Definition at line 755 of file kis_guides_manager.cpp.

756{
757 KisActionManager *actionManager = view->viewManager()->actionManager();
758 QAction *action = 0;
759 KisAction *parentAction = 0;
760
761 action = new QAction(text, parent);
762 action->setCheckable(true);
763 parentAction = actionManager->actionByName(parentId);
764 action->setChecked(parentAction->isChecked());
765 connect(action, SIGNAL(toggled(bool)), parentAction, SLOT(setChecked(bool)));
766
767 return action;
768}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
A KisActionManager class keeps track of KisActions. These actions are always associated with the GUI....
KisAction * actionByName(const QString &name) const

References KisActionManager::actionByName(), KisViewManager::actionManager(), connect(), and KisActionManager::viewManager.

◆ createUndoCommandIfNeeded()

void KisGuidesManager::Private::createUndoCommandIfNeeded ( )

Definition at line 190 of file kis_guides_manager.cpp.

191{
192 KisDocument *doc = view ? view->document() : 0;
193 if (doc && needsUndoCommand()) {
195 view->canvasBase()->addCommand(cmd);
196 }
197}

◆ deleteGuide()

void KisGuidesManager::Private::deleteGuide ( const GuideHandle & h)

Definition at line 457 of file kis_guides_manager.cpp.

458{
459 if (h.first == Qt::Horizontal) {
461 guides.removeAt(h.second);
463 } else {
465 guides.removeAt(h.second);
467 }
468}
void setHorizontalGuideLines(const QList< qreal > &lines)
Set the positions of the horizontal guide lines.
const QList< qreal > & verticalGuideLines() const
Returns the list of vertical guide lines.
void setVerticalGuideLines(const QList< qreal > &lines)
Set the positions of the vertical guide lines.
const QList< qreal > & horizontalGuideLines() const
Returns the list of horizontal guide lines.

◆ findGuide()

KisGuidesManager::Private::GuideHandle KisGuidesManager::Private::findGuide ( const QPointF & docPos)

Definition at line 399 of file kis_guides_manager.cpp.

400{
401 const int snapRadius = 16;
402 const KoViewConverter *converter = view->canvasBase()->viewConverter();
403 const QPointF docPosView = converter->documentToView(docPos);
404
405 GuideHandle nearestGuide = invalidGuide;
406 qreal nearestRadius = std::numeric_limits<int>::max();
407
408
409 for (int i = 0; i < guidesConfig.horizontalGuideLines().size(); i++) {
410 const QPointF guideCoord = {0, guidesConfig.horizontalGuideLines()[i]};
411 const qreal guide = converter->documentToView(guideCoord).y();
412 const qreal radius = qAbs(docPosView.y() - guide);
413 if (radius < snapRadius && radius < nearestRadius) {
414 nearestGuide = GuideHandle(Qt::Horizontal, i);
415 nearestRadius = radius;
416 }
417 }
418
419 for (int i = 0; i < guidesConfig.verticalGuideLines().size(); i++) {
420 const QPointF guideCoord = {guidesConfig.verticalGuideLines()[i], 0};
421 const qreal guide = converter->documentToView(guideCoord).x();
422 const qreal radius = qAbs(docPosView.x() - guide);
423 if (radius < snapRadius && radius < nearestRadius) {
424 nearestGuide = GuideHandle(Qt::Vertical, i);
425 nearestRadius = radius;
426 }
427 }
428
429 return nearestGuide;
430}
virtual QPointF documentToView(const QPointF &documentPoint) const
int size(const Forest< T > &forest)
Definition KisForest.h:1232
QPair< Qt::Orientation, int > GuideHandle

References KoViewConverter::documentToView().

◆ getButtonFromEvent()

Qt::MouseButton KisGuidesManager::Private::getButtonFromEvent ( QEvent * event)

Definition at line 629 of file kis_guides_manager.cpp.

630{
631 Qt::MouseButton button = Qt::NoButton;
632
633 if (event->type() == QEvent::MouseMove ||
634 event->type() == QEvent::MouseButtonPress ||
635 event->type() == QEvent::MouseButtonRelease) {
636
637 QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
638 button = mouseEvent->button();
639
640 } else if (event->type() == QEvent::TabletMove ||
641 event->type() == QEvent::TabletPress ||
642 event->type() == QEvent::TabletRelease) {
643
644 QTabletEvent *tabletEvent = static_cast<QTabletEvent*>(event);
645 button = tabletEvent->button();
646 }
647
648 return button;
649}
QString button(const QWheelEvent &ev)

References button().

◆ getDocPointFromEvent()

QPointF KisGuidesManager::Private::getDocPointFromEvent ( QEvent * event)

Definition at line 597 of file kis_guides_manager.cpp.

598{
599 QPointF result;
600
601 KisCanvas2 *canvas = view->canvasBase();
602 const KisCoordinatesConverter *converter = canvas->coordinatesConverter();
603
604 if (event->type() == QEvent::Enter) {
605 QEnterEvent *enterEvent = static_cast<QEnterEvent*>(event);
606 result = alignToPixels(converter->widgetToDocument(enterEvent->pos()));
607 } else if (event->type() == QEvent::MouseMove ||
608 event->type() == QEvent::MouseButtonPress ||
609 event->type() == QEvent::MouseButtonRelease) {
610
611 QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
612 result = alignToPixels(converter->widgetToDocument(mouseEvent->pos()));
613
614 } else if (event->type() == QEvent::TabletMove ||
615 event->type() == QEvent::TabletPress ||
616 event->type() == QEvent::TabletRelease) {
617
618 QTabletEvent *tabletEvent = static_cast<QTabletEvent*>(event);
619 result = alignToPixels(converter->widgetToDocument(tabletEvent->pos()));
620 } else {
621 // we shouldn't silently return QPointF(0,0), higher level code may
622 // snap to some unexpected guide
623 KIS_SAFE_ASSERT_RECOVER_NOOP(0 && "event type is not supported!");
624 }
625
626 return result;
627}
_Private::Traits< T >::Result widgetToDocument(const T &obj) const
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130
QPointF alignToPixels(const QPointF docPoint)

References KisCanvas2::coordinatesConverter, KIS_SAFE_ASSERT_RECOVER_NOOP, and KisCoordinatesConverter::widgetToDocument().

◆ guideValue()

qreal KisGuidesManager::Private::guideValue ( const GuideHandle & h)

Definition at line 437 of file kis_guides_manager.cpp.

438{
439 return h.first == Qt::Horizontal ?
442}

◆ initDragStart()

void KisGuidesManager::Private::initDragStart ( const GuideHandle & guide,
const QPointF & dragStart,
qreal guideValue,
bool snapToStart )

Definition at line 496 of file kis_guides_manager.cpp.

500{
501 currentGuide = guide;
502 dragStartDoc = dragStart;
505 guide.first == Qt::Horizontal ?
506 QPointF(0, dragStartGuidePos - dragStartDoc.y()) :
507 QPointF(dragStartGuidePos - dragStartDoc.x(), 0);
508
509 KoSnapGuide *snapGuide = view->canvasBase()->snapGuide();
510 snapGuide->reset();
511
512 if (snapToStart) {
514 strategy->addLine(guide.first, guideValue);
515 snapGuide->addCustomSnapStrategy(strategy);
516 }
517}
void addLine(Qt::Orientation orientation, qreal pos)
bool addCustomSnapStrategy(KoSnapStrategy *customStrategy)
void reset()
Resets the snap guide.
qreal guideValue(const GuideHandle &h)

References KoSnapGuide::addCustomSnapStrategy(), KisSnapLineStrategy::addLine(), and KoSnapGuide::reset().

◆ isGuideValid()

bool KisGuidesManager::Private::isGuideValid ( const GuideHandle & h)

Definition at line 432 of file kis_guides_manager.cpp.

433{
434 return h.second >= 0;
435}

◆ mouseMoveHandler()

bool KisGuidesManager::Private::mouseMoveHandler ( const QPointF & docPos,
Qt::KeyboardModifiers modifiers )

Definition at line 527 of file kis_guides_manager.cpp.

528{
530 KoSnapGuide *snapGuide = view->canvasBase()->snapGuide();
531 const QPointF snappedPos = snapGuide->snap(docPos, dragPointerOffset, modifiers);
532 const QPointF offset = snappedPos - dragStartDoc;
533 const qreal newValue = dragStartGuidePos +
534 (currentGuide.first == Qt::Horizontal ?
535 offset.y() : offset.x());
536
537 setGuideValue(currentGuide, newValue);
539
540 const KisCoordinatesConverter *converter = view->canvasBase()->coordinatesConverter();
541 if(currentGuide.first == Qt::Horizontal) {
542 view->canvasBase()->viewManager()->showFloatingMessage(
543 i18n("Y: %1 px", converter->documentToImage(docPos).toPoint().y()), QIcon(), 1000
544 , KisFloatingMessage::High, Qt::AlignLeft | Qt::TextWordWrap | Qt::AlignVCenter);
545 }
546 else {
547 view->canvasBase()->viewManager()->showFloatingMessage(
548 i18n("X: %1 px", converter->documentToImage(docPos).toPoint().x()), QIcon(), 1000
549 , KisFloatingMessage::High, Qt::AlignLeft | Qt::TextWordWrap | Qt::AlignVCenter);
550 }
551 }
552
553 return updateCursor(docPos);
554}
void setGuidesConfigImpl(const KisGuidesConfig &value, bool emitModified=true)
QPointF snap(const QPointF &mousePosition, Qt::KeyboardModifiers modifiers)
snaps the mouse position, returns if mouse was snapped
bool isGuideValid(const GuideHandle &h)
bool updateCursor(const QPointF &docPos, bool forceDisableCursor=false)
void setGuideValue(const GuideHandle &h, qreal value)

References KisCoordinatesConverter::documentToImage(), KisFloatingMessage::High, and KoSnapGuide::snap().

◆ mouseReleaseHandler()

bool KisGuidesManager::Private::mouseReleaseHandler ( const QPointF & docPos)

When we delete a guide, it might happen that we are deleting the last guide. Therefore we should eat the corresponding event so that the event filter would stop the filter processing.

Definition at line 556 of file kis_guides_manager.cpp.

557{
558 bool result = false;
559 KisCanvas2 *canvas = view->canvasBase();
560 const KisCoordinatesConverter *converter = canvas->coordinatesConverter();
561
563 const QRectF docRect = converter->imageRectInDocumentPixels();
564 // TODO: enable work rect after we fix painting guides
565 // outside canvas in openGL mode
566 const QRectF workRect = KisAlgebra2D::blowRect(docRect, 0 /*0.2*/);
567 if (!workRect.contains(docPos)) {
570
577 result = true;
578 }
579
581 dragStartDoc = QPointF();
582 dragPointerOffset = QPointF();
584
585 KoSnapGuide *snapGuide = view->canvasBase()->snapGuide();
586 snapGuide->reset();
587
589 }
590
593
594 return updateCursor(docPos) | result;
595}
Rect blowRect(const Rect &rect, qreal coeff)
void updateSnappingStatus(const KisGuidesConfig &value)
void deleteGuide(const GuideHandle &h)

References KisAlgebra2D::blowRect(), KisCanvas2::coordinatesConverter, KisCoordinatesConverter::imageRectInDocumentPixels(), and KoSnapGuide::reset().

◆ needsUndoCommand()

bool KisGuidesManager::Private::needsUndoCommand ( )

Definition at line 185 of file kis_guides_manager.cpp.

186{
188}
bool hasSamePositionAs(const KisGuidesConfig &rhs) const

◆ setGuideValue()

void KisGuidesManager::Private::setGuideValue ( const GuideHandle & h,
qreal value )

Definition at line 444 of file kis_guides_manager.cpp.

445{
446 if (h.first == Qt::Horizontal) {
448 guides[h.second] = value;
450 } else {
452 guides[h.second] = value;
454 }
455}
float value(const T *src, size_t ch)

References value().

◆ syncAction()

void KisGuidesManager::Private::syncAction ( const QString & actionName,
bool value )

Definition at line 176 of file kis_guides_manager.cpp.

177{
178 KisActionManager *actionManager = view->viewManager()->actionManager();
179 KisAction *action = actionManager->actionByName(actionName);
181 KisSignalsBlocker b(action);
182 action->setChecked(value);
183}
#define KIS_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:75

References KisActionManager::actionByName(), KIS_ASSERT_RECOVER_RETURN, value(), and view.

◆ updateCursor()

bool KisGuidesManager::Private::updateCursor ( const QPointF & docPos,
bool forceDisableCursor = false )

Definition at line 470 of file kis_guides_manager.cpp.

471{
472 KisCanvas2 *canvas = view->canvasBase();
473
474 const GuideHandle guide = findGuide(docPos);
475 const bool guideValid = isGuideValid(guide) && !forceDisableCursor;
476
477 if (guideValid && !cursorSwitched) {
478 oldCursor = canvas->canvasWidget()->cursor();
479 }
480
481 if (guideValid) {
482 cursorSwitched = true;
483 QCursor newCursor = guide.first == Qt::Horizontal ?
484 Qt::SizeVerCursor : Qt::SizeHorCursor;
485 canvas->canvasWidget()->setCursor(newCursor);
486 }
487
488 if (!guideValid && cursorSwitched) {
489 canvas->canvasWidget()->setCursor(oldCursor);
490 cursorSwitched = false;
491 }
492
493 return guideValid;
494}
KisAbstractCanvasWidget * canvasWidget
GuideHandle findGuide(const QPointF &docPos)

References KisCanvas2::canvasWidget.

◆ updateSnappingStatus()

void KisGuidesManager::Private::updateSnappingStatus ( const KisGuidesConfig & value)

Definition at line 217 of file kis_guides_manager.cpp.

218{
219 if (!view) return;
220
221 KoSnapGuide *snapGuide = view->canvasBase()->snapGuide();
222 KisSnapLineStrategy *guidesSnap = 0;
223
224 if (value.snapToGuides()) {
226 guidesSnap->setHorizontalLines(value.horizontalGuideLines());
227 guidesSnap->setVerticalLines(value.verticalGuideLines());
228 }
229
232
241
243}
bool orthogonal() const
bool node() const
bool toPixel() const
bool imageBounds() const
bool boundingBox() const
void saveStaticData() const
bool intersection() const
bool extension() const
bool imageCenter() const
void setVerticalLines(const QList< qreal > &lines)
void setHorizontalLines(const QList< qreal > &lines)
@ DocumentBoundsSnapping
Definition KoSnapGuide.h:57
@ DocumentCenterSnapping
Definition KoSnapGuide.h:58
@ IntersectionSnapping
Definition KoSnapGuide.h:53
@ BoundingBoxSnapping
Definition KoSnapGuide.h:55
void enableSnapStrategy(Strategy type, bool value)
void overrideSnapStrategy(Strategy type, KoSnapStrategy *strategy)

References KoSnapGuide::BoundingBoxSnapping, KoSnapGuide::DocumentBoundsSnapping, KoSnapGuide::DocumentCenterSnapping, KoSnapGuide::enableSnapStrategy(), KoSnapGuide::ExtensionSnapping, KoSnapGuide::GuideLineSnapping, KoSnapGuide::IntersectionSnapping, KoSnapGuide::NodeSnapping, KoSnapGuide::OrthogonalSnapping, KoSnapGuide::overrideSnapStrategy(), KoSnapGuide::PixelSnapping, KisSnapLineStrategy::setHorizontalLines(), KisSnapLineStrategy::setVerticalLines(), and value().

Member Data Documentation

◆ currentGuide

GuideHandle KisGuidesManager::Private::currentGuide

Definition at line 78 of file kis_guides_manager.cpp.

◆ cursorSwitched

bool KisGuidesManager::Private::cursorSwitched

Definition at line 80 of file kis_guides_manager.cpp.

◆ decoration

KisGuidesDecoration* KisGuidesManager::Private::decoration

Definition at line 45 of file kis_guides_manager.cpp.

◆ dragPointerOffset

QPointF KisGuidesManager::Private::dragPointerOffset

Definition at line 84 of file kis_guides_manager.cpp.

◆ dragStartDoc

QPointF KisGuidesManager::Private::dragStartDoc

Definition at line 83 of file kis_guides_manager.cpp.

◆ dragStartGuidePos

qreal KisGuidesManager::Private::dragStartGuidePos

Definition at line 85 of file kis_guides_manager.cpp.

◆ guidesConfig

KisGuidesConfig KisGuidesManager::Private::guidesConfig

Definition at line 46 of file kis_guides_manager.cpp.

◆ invalidGuide

const GuideHandle KisGuidesManager::Private::invalidGuide

Definition at line 58 of file kis_guides_manager.cpp.

◆ oldCursor

QCursor KisGuidesManager::Private::oldCursor

Definition at line 81 of file kis_guides_manager.cpp.

◆ oldGuidesConfig

KisGuidesConfig KisGuidesManager::Private::oldGuidesConfig

Definition at line 47 of file kis_guides_manager.cpp.

◆ q

KisGuidesManager* KisGuidesManager::Private::q

Definition at line 43 of file kis_guides_manager.cpp.

◆ shouldSetModified

bool KisGuidesManager::Private::shouldSetModified

Definition at line 89 of file kis_guides_manager.cpp.

◆ snapConfig

KisSnapConfig KisGuidesManager::Private::snapConfig

Definition at line 48 of file kis_guides_manager.cpp.

◆ view

QPointer<KisView> KisGuidesManager::Private::view

Definition at line 49 of file kis_guides_manager.cpp.

◆ viewConnections

KisSignalAutoConnectionsStore KisGuidesManager::Private::viewConnections

Definition at line 87 of file kis_guides_manager.cpp.


The documentation for this struct was generated from the following file: