Krita Source Code Documentation
Loading...
Searching...
No Matches
NodeDelegate::Private Class Reference

Public Types

enum  StasisOperation { Record , Review , Restore }
 

Public Member Functions

bool checkImmediateStasis (const QModelIndex &root, const OptionalProperty &clickedProperty)
 
OptionalProperty findProperty (KisBaseNode::PropertyList &props, const OptionalProperty &refProp) const
 
OptionalProperty findVisibilityProperty (KisBaseNode::PropertyList &props) const
 
void getChildrenIndex (QList< QModelIndex > &items, const QModelIndex &index)
 
void getParentsIndex (QList< QModelIndex > &items, const QModelIndex &index)
 
void getSiblingsIndex (QList< QModelIndex > &items, const QModelIndex &index)
 
int numProperties (const QModelIndex &index) const
 
 Private (NodeDelegate *_q)
 
boost::optional< KisBaseNode::PropertypropForMousePos (const QModelIndex &index, const QPoint &mousePos, const QStyleOptionViewItem &option)
 
void resetPropertyStateRecursive (const QModelIndex &root, const OptionalProperty &clickedProperty)
 
void restorePropertyInStasisRecursive (const QModelIndex &root, const OptionalProperty &clickedProperty)
 
QList< OptionalPropertyrightmostProperties (const KisBaseNode::PropertyList &props) const
 
bool stasisIsDirty (const QModelIndex &root, const OptionalProperty &clickedProperty, bool on=false, bool off=false)
 
void toggleProperty (KisBaseNode::PropertyList &props, const OptionalProperty clickedProperty, const Qt::KeyboardModifiers modifier, const QModelIndex &index)
 
void togglePropertyRecursive (const QModelIndex &root, const OptionalProperty &clickedProperty, const QList< QModelIndex > &items, StasisOperation record, bool mode)
 

Public Attributes

QImage checkers
 
QColor checkersColor1
 
QColor checkersColor2
 
QPointer< QWidget > edit
 
NodeDelegateq
 
int rowHeight {-1}
 
QList< QModelIndex > shiftClickedIndexes
 
QRect thumbnailGeometry
 
int thumbnailSize {-1}
 
NodeToolTip tip
 
NodeViewview
 

Detailed Description

Definition at line 41 of file NodeDelegate.cpp.

Member Enumeration Documentation

◆ StasisOperation

Enumerator
Record 
Review 
Restore 

Definition at line 62 of file NodeDelegate.cpp.

Constructor & Destructor Documentation

◆ Private()

NodeDelegate::Private::Private ( NodeDelegate * _q)
inline

Definition at line 44 of file NodeDelegate.cpp.

44: q(_q), view(0), edit(0) { }
QPointer< QWidget > edit

Member Function Documentation

◆ checkImmediateStasis()

bool NodeDelegate::Private::checkImmediateStasis ( const QModelIndex & root,
const OptionalProperty & clickedProperty )

Definition at line 680 of file NodeDelegate.cpp.

681{
682 if (!clickedProperty->canHaveStasis) return false;
683
684 const int rowCount = view->model()->rowCount(root);
685 for (int i = 0; i < rowCount; i++){
686 QModelIndex idx = view->model()->index(i, 0, root);
688 OptionalProperty prop = findProperty(props, clickedProperty);
689
690 if (prop->isInStasis) {
691 return true;
692 }
693 }
694
695 return false;
696}
@ PropertiesRole
A list of properties the part has.
OptionalProperty findProperty(KisBaseNode::PropertyList &props, const OptionalProperty &refProp) const

References KisBaseNode::Property::canHaveStasis, and KisNodeModel::PropertiesRole.

◆ findProperty()

OptionalProperty NodeDelegate::Private::findProperty ( KisBaseNode::PropertyList & props,
const OptionalProperty & refProp ) const

Definition at line 494 of file NodeDelegate.cpp.

495{
496 KisBaseNode::PropertyList::iterator it = props.begin();
497 KisBaseNode::PropertyList::iterator end = props.end();
498 for (; it != end; ++it) {
499 if (it->id == refProp->id) {
500 return &(*it);
501 }
502 }
503
504 return 0;
505}

References KisBaseNode::Property::id.

◆ findVisibilityProperty()

OptionalProperty NodeDelegate::Private::findVisibilityProperty ( KisBaseNode::PropertyList & props) const

Definition at line 507 of file NodeDelegate.cpp.

508{
509 KisBaseNode::PropertyList::iterator it = props.begin();
510 KisBaseNode::PropertyList::iterator end = props.end();
511 for (; it != end; ++it) {
512 if (it->id == KisLayerPropertiesIcons::visible.id()) {
513 return &(*it);
514 }
515 }
516
517 return 0;
518}
QString id() const
Definition KoID.cpp:63

References KoID::id(), and KisLayerPropertiesIcons::visible.

◆ getChildrenIndex()

void NodeDelegate::Private::getChildrenIndex ( QList< QModelIndex > & items,
const QModelIndex & index )

Definition at line 705 of file NodeDelegate.cpp.

706{
707 qint32 childs = view->model()->rowCount(index);
708 QModelIndex child;
709 // STEP 1: Go.
710 for (quint16 i = 0; i < childs; ++i) {
711 child = view->model()->index(i, 0, index);
712 items.append(child);
713 getChildrenIndex(items, child);
714 }
715}
void getChildrenIndex(QList< QModelIndex > &items, const QModelIndex &index)

◆ getParentsIndex()

void NodeDelegate::Private::getParentsIndex ( QList< QModelIndex > & items,
const QModelIndex & index )

Definition at line 698 of file NodeDelegate.cpp.

699{
700 if (!index.isValid()) return;
701 items.append(index);
702 getParentsIndex(items, index.parent());
703}
void getParentsIndex(QList< QModelIndex > &items, const QModelIndex &index)

◆ getSiblingsIndex()

void NodeDelegate::Private::getSiblingsIndex ( QList< QModelIndex > & items,
const QModelIndex & index )

Definition at line 717 of file NodeDelegate.cpp.

718{
719 qint32 numberOfLeaves = view->model()->rowCount(index.parent());
720 QModelIndex item;
721 // STEP 1: Go.
722 for (quint16 i = 0; i < numberOfLeaves; ++i) {
723 item = view->model()->index(i, 0, index.parent());
724 if (item != index) {
725 items.append(item);
726 }
727 }
728}

◆ numProperties()

int NodeDelegate::Private::numProperties ( const QModelIndex & index) const

Definition at line 487 of file NodeDelegate.cpp.

488{
491 return realProps.size();
492}
QList< OptionalProperty > rightmostProperties(const KisBaseNode::PropertyList &props) const

References KisNodeModel::PropertiesRole.

◆ propForMousePos()

boost::optional< KisBaseNode::Property > NodeDelegate::Private::propForMousePos ( const QModelIndex & index,
const QPoint & mousePos,
const QStyleOptionViewItem & option )

Definition at line 1003 of file NodeDelegate.cpp.

1004{
1006
1007 const QRect iconsRect = q->iconsRect(option, index);
1008
1009 const bool iconsClicked = iconsRect.isValid() &&
1010 iconsRect.contains(mousePos);
1011
1012 if (!iconsClicked) return boost::none;
1013
1015 QList<OptionalProperty> realProps = this->rightmostProperties(props);
1016 if (option.direction == Qt::RightToLeft) {
1017 std::reverse(realProps.begin(), realProps.end());
1018 }
1019 const int numProps = realProps.size();
1020
1021 const int iconWidth = scm.iconSize() + 2 * scm.iconMargin() + scm.border();
1022 const int xPos = mousePos.x() - iconsRect.left();
1023 const int clickedIcon = xPos / iconWidth;
1024 const int distToBorder = qMin(xPos % iconWidth, iconWidth - xPos % iconWidth);
1025
1026
1027 if (clickedIcon >= 0 &&
1028 clickedIcon < numProps &&
1029 realProps[clickedIcon] &&
1030 distToBorder > scm.iconMargin()) {
1031
1032 return *realProps[clickedIcon];
1033 }
1034
1035 return boost::none;
1036}
QRect iconsRect(const QStyleOptionViewItem &option, const QModelIndex &index) const

References KisNodeViewColorScheme::border(), KisNodeViewColorScheme::iconMargin(), KisNodeViewColorScheme::iconSize(), NodeDelegate::iconsRect(), and KisNodeModel::PropertiesRole.

◆ resetPropertyStateRecursive()

void NodeDelegate::Private::resetPropertyStateRecursive ( const QModelIndex & root,
const OptionalProperty & clickedProperty )

Definition at line 640 of file NodeDelegate.cpp.

641{
642 if (!clickedProperty->canHaveStasis) return;
643 int rowCount = view->model()->rowCount(root);
644
645 for (int i = 0; i < rowCount; i++) {
646 QModelIndex idx = view->model()->index(i, 0, root);
647 // The entire property list has to be altered because model->setData cannot set individual properties
649 OptionalProperty prop = findProperty(props, clickedProperty);
650
651 if (!prop) continue;
652 prop->isInStasis = false;
653 view->model()->setData(idx, QVariant::fromValue(props), KisNodeModel::PropertiesRole);
654
655 resetPropertyStateRecursive(idx,clickedProperty);
656 }
657}
void resetPropertyStateRecursive(const QModelIndex &root, const OptionalProperty &clickedProperty)

References KisBaseNode::Property::canHaveStasis, and KisNodeModel::PropertiesRole.

◆ restorePropertyInStasisRecursive()

void NodeDelegate::Private::restorePropertyInStasisRecursive ( const QModelIndex & root,
const OptionalProperty & clickedProperty )

Definition at line 659 of file NodeDelegate.cpp.

660{
661 if (!clickedProperty->canHaveStasis) return;
662 int rowCount = view->model()->rowCount(root);
663
664 for (int i = 0; i < rowCount; i++) {
665 QModelIndex idx = view->model()->index(i, 0, root);
667 OptionalProperty prop = findProperty(props, clickedProperty);
668
669 if (prop->isInStasis) {
670 prop->isInStasis = false;
671 prop->state = QVariant(prop->stateInStasis);
672 }
673
674 view->model()->setData(idx, QVariant::fromValue(props), KisNodeModel::PropertiesRole);
675
676 restorePropertyInStasisRecursive(idx, clickedProperty);
677 }
678}
void restorePropertyInStasisRecursive(const QModelIndex &root, const OptionalProperty &clickedProperty)

References KisBaseNode::Property::canHaveStasis, and KisNodeModel::PropertiesRole.

◆ rightmostProperties()

QList< OptionalProperty > NodeDelegate::Private::rightmostProperties ( const KisBaseNode::PropertyList & props) const

Definition at line 430 of file NodeDelegate.cpp.

431{
433 QList<OptionalProperty> prependList;
434 list << OptionalProperty(0);
435 list << OptionalProperty(0);
436 list << OptionalProperty(0);
437
438 KisBaseNode::PropertyList::const_iterator it = props.constBegin();
439 KisBaseNode::PropertyList::const_iterator end = props.constEnd();
440 for (; it != end; ++it) {
441 if (!it->isMutable &&
444 it->id != KisLayerPropertiesIcons::colorOverlay.id()) continue;
445
446 if (it->id == KisLayerPropertiesIcons::visible.id()) {
447 // noop...
448 } else if (it->id == KisLayerPropertiesIcons::locked.id()) {
449 list[0] = OptionalProperty(&(*it));
450 } else if (it->id == KisLayerPropertiesIcons::inheritAlpha.id()) {
451 list[1] = OptionalProperty(&(*it));
452 } else if (it->id == KisLayerPropertiesIcons::alphaLocked.id()) {
453 list[2] = OptionalProperty(&(*it));
454 } else {
455 prependList.prepend(OptionalProperty(&(*it)));
456 }
457 }
458
459 auto putToTheLeft = [] (QList<OptionalProperty> &list, const QString &id) {
460 auto it = std::find_if(list.begin(), list.end(), kismpl::mem_equal_to(&KisBaseNode::Property::id, id));
461 if (it != list.end()) {
462 std::rotate(list.begin(), it, std::next(it));
463 }
464 };
465
466 putToTheLeft(prependList, KisLayerPropertiesIcons::colorOverlay.id());
467 putToTheLeft(prependList, KisLayerPropertiesIcons::layerColorSpaceMismatch.id());
468 putToTheLeft(prependList, KisLayerPropertiesIcons::layerError.id());
469
470 {
471 QMutableListIterator<OptionalProperty> i(prependList);
472 i.toBack();
473 while (i.hasPrevious()) {
474 OptionalProperty val = i.previous();
475
476 int emptyIndex = list.lastIndexOf(nullptr);
477 if (emptyIndex < 0) break;
478
479 list[emptyIndex] = val;
480 i.remove();
481 }
482 }
483
484 return prependList + list;
485}
KisBaseNode::Property * OptionalProperty
auto mem_equal_to(MemTypeNoRef Class::*ptr, MemType &&value)
mem_equal_to is an unary functor that compares a member of the object to a given value
Definition KisMpl.h:233

References KisLayerPropertiesIcons::alphaLocked, KisLayerPropertiesIcons::colorOverlay, KoID::id(), KisBaseNode::Property::id, KisLayerPropertiesIcons::inheritAlpha, KisLayerPropertiesIcons::layerColorSpaceMismatch, KisLayerPropertiesIcons::layerError, KisLayerPropertiesIcons::locked, kismpl::mem_equal_to(), and KisLayerPropertiesIcons::visible.

◆ stasisIsDirty()

bool NodeDelegate::Private::stasisIsDirty ( const QModelIndex & root,
const OptionalProperty & clickedProperty,
bool on = false,
bool off = false )

Definition at line 611 of file NodeDelegate.cpp.

612{
613
614 int rowCount = view->model()->rowCount(root);
615 bool result = false;
616
617 for (int i = 0; i < rowCount; i++) {
618 if (result) break; // return on first find
619 QModelIndex idx = view->model()->index(i, 0, root);
620 // The entire property list has to be altered because model->setData cannot set individual properties
622 OptionalProperty prop = findProperty(props, clickedProperty);
623
624 if (!prop) continue;
625 if (prop->isInStasis) {
626 on = true;
627 } else {
628 off = true;
629 }
630 // stop if both states exist
631 if (on && off) {
632 return true;
633 }
634
635 result = stasisIsDirty(idx,clickedProperty, on, off);
636 }
637 return result;
638}
bool stasisIsDirty(const QModelIndex &root, const OptionalProperty &clickedProperty, bool on=false, bool off=false)

References KisNodeModel::PropertiesRole.

◆ toggleProperty()

void NodeDelegate::Private::toggleProperty ( KisBaseNode::PropertyList & props,
const OptionalProperty clickedProperty,
const Qt::KeyboardModifiers modifier,
const QModelIndex & index )

Definition at line 520 of file NodeDelegate.cpp.

521{
522 QModelIndex root(view->rootIndex());
523
524 if (clickedProperty->id == KisLayerPropertiesIcons::colorOverlay.id()) {
525 // Open the properties dialog for the layer's fast color overlay mask.
526 view->model()->setData(index, QVariant() /* unused */, KisNodeModel::LayerColorOverlayPropertiesRole);
527
528 } else if ((modifier & Qt::ShiftModifier) == Qt::ShiftModifier && clickedProperty->canHaveStasis) {
529 bool mode = true;
530
531 OptionalProperty prop = findProperty(props, clickedProperty);
532
533 // XXX: Change to use NodeProperty
534 int position = shiftClickedIndexes.indexOf(index);
535
537 (position < 0) ? StasisOperation::Review : StasisOperation::Restore;
538
539 shiftClickedIndexes.clear();
540 shiftClickedIndexes.push_back(index);
541
542 QList<QModelIndex> items;
543 if (modifier == (Qt::ControlModifier | Qt::ShiftModifier)) {
544 mode = false; // inverted mode
545 items.insert(0, index); // important!
546 getSiblingsIndex(items, index);
547 } else {
548 getParentsIndex(items, index);
549 getChildrenIndex(items, index);
550 }
551 togglePropertyRecursive(root, clickedProperty, items, record, mode);
552
553 } else {
554 // If we have properties in stasis, we need to cancel stasis to avoid overriding
555 // values in stasis.
556 // IMPORTANT -- we also need to check the first row of nodes to determine
557 // if a stasis is currently active in some cases.
558 const bool hasPropInStasis = (shiftClickedIndexes.count() > 0 || checkImmediateStasis(root, clickedProperty));
559 if (clickedProperty->canHaveStasis && hasPropInStasis) {
560 shiftClickedIndexes.clear();
561
562 restorePropertyInStasisRecursive(root, clickedProperty);
563 } else {
564 shiftClickedIndexes.clear();
565
566 resetPropertyStateRecursive(root, clickedProperty);
567
568 OptionalProperty prop = findProperty(props, clickedProperty);
569 prop->state = !prop->state.toBool();
570 prop->isInStasis = false;
571 view->model()->setData(index, QVariant::fromValue(props), KisNodeModel::PropertiesRole);
572 }
573 }
574}
@ LayerColorOverlayPropertiesRole
void getSiblingsIndex(QList< QModelIndex > &items, const QModelIndex &index)
bool checkImmediateStasis(const QModelIndex &root, const OptionalProperty &clickedProperty)
QList< QModelIndex > shiftClickedIndexes
void togglePropertyRecursive(const QModelIndex &root, const OptionalProperty &clickedProperty, const QList< QModelIndex > &items, StasisOperation record, bool mode)

References KisBaseNode::Property::canHaveStasis, KisLayerPropertiesIcons::colorOverlay, KoID::id(), KisBaseNode::Property::id, KisBaseNode::Property::isInStasis, KisNodeModel::LayerColorOverlayPropertiesRole, KisNodeModel::PropertiesRole, and KisBaseNode::Property::state.

◆ togglePropertyRecursive()

void NodeDelegate::Private::togglePropertyRecursive ( const QModelIndex & root,
const OptionalProperty & clickedProperty,
const QList< QModelIndex > & items,
StasisOperation record,
bool mode )

Definition at line 576 of file NodeDelegate.cpp.

577{
578 int rowCount = view->model()->rowCount(root);
579
580 for (int i = 0; i < rowCount; i++) {
581 QModelIndex idx = view->model()->index(i, 0, root);
582
583 // The entire property list has to be altered because model->setData cannot set individual properties
585 OptionalProperty prop = findProperty(props, clickedProperty);
586
587 if (!prop) continue;
588
589 if (record == StasisOperation::Record) {
590 prop->stateInStasis = prop->state.toBool();
591 }
592 if (record == StasisOperation::Review || record == StasisOperation::Record) {
593 prop->isInStasis = true;
594 if(mode) { //include mode
595 prop->state = (items.contains(idx)) ? QVariant(true) : QVariant(false);
596 } else { // exclude
597 prop->state = (!items.contains(idx))? prop->state :
598 (items.at(0) == idx)? QVariant(true) : QVariant(false);
599 }
600 } else { // restore
601 prop->state = QVariant(prop->stateInStasis);
602 prop->isInStasis = false;
603 }
604
605 view->model()->setData(idx, QVariant::fromValue(props), KisNodeModel::PropertiesRole);
606
607 togglePropertyRecursive(idx,clickedProperty, items, record, mode);
608 }
609}

References KisNodeModel::PropertiesRole.

Member Data Documentation

◆ checkers

QImage NodeDelegate::Private::checkers

Definition at line 52 of file NodeDelegate.cpp.

◆ checkersColor1

QColor NodeDelegate::Private::checkersColor1

Definition at line 53 of file NodeDelegate.cpp.

◆ checkersColor2

QColor NodeDelegate::Private::checkersColor2

Definition at line 54 of file NodeDelegate.cpp.

◆ edit

QPointer<QWidget> NodeDelegate::Private::edit

Definition at line 49 of file NodeDelegate.cpp.

◆ q

NodeDelegate* NodeDelegate::Private::q

Definition at line 46 of file NodeDelegate.cpp.

◆ rowHeight

int NodeDelegate::Private::rowHeight {-1}

Definition at line 58 of file NodeDelegate.cpp.

58{-1};

◆ shiftClickedIndexes

QList<QModelIndex> NodeDelegate::Private::shiftClickedIndexes

Definition at line 60 of file NodeDelegate.cpp.

◆ thumbnailGeometry

QRect NodeDelegate::Private::thumbnailGeometry

Definition at line 56 of file NodeDelegate.cpp.

◆ thumbnailSize

int NodeDelegate::Private::thumbnailSize {-1}

Definition at line 57 of file NodeDelegate.cpp.

57{-1};

◆ tip

NodeToolTip NodeDelegate::Private::tip

Definition at line 50 of file NodeDelegate.cpp.

◆ view

NodeView* NodeDelegate::Private::view

Definition at line 48 of file NodeDelegate.cpp.


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