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, NodeView *_view)
 
boost::optional< KisBaseNode::Property > propForMousePos (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< OptionalProperty > rightmostProperties (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
 
NodeDelegate * q
 
int rowHeight {-1}
 
QList< QModelIndex > shiftClickedIndexes
 
QRect thumbnailGeometry
 
int thumbnailSize {-1}
 
NodeToolTip tip
 
NodeView * view
 

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,
NodeView * _view )
inline

Definition at line 44 of file NodeDelegate.cpp.

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

Member Function Documentation

◆ checkImmediateStasis()

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

Definition at line 678 of file NodeDelegate.cpp.

679{
680 if (!clickedProperty->canHaveStasis) return false;
681
682 const int rowCount = view->model()->rowCount(root);
683 for (int i = 0; i < rowCount; i++){
684 QModelIndex idx = view->model()->index(i, 0, root);
686 OptionalProperty prop = findProperty(props, clickedProperty);
687
688 if (prop->isInStasis) {
689 return true;
690 }
691 }
692
693 return false;
694}
@ 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 492 of file NodeDelegate.cpp.

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

References KisBaseNode::Property::id.

◆ findVisibilityProperty()

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

Definition at line 505 of file NodeDelegate.cpp.

506{
507 KisBaseNode::PropertyList::iterator it = props.begin();
508 KisBaseNode::PropertyList::iterator end = props.end();
509 for (; it != end; ++it) {
510 if (it->id == KisLayerPropertiesIcons::visible.id()) {
511 return &(*it);
512 }
513 }
514
515 return 0;
516}
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 703 of file NodeDelegate.cpp.

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

◆ getParentsIndex()

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

Definition at line 696 of file NodeDelegate.cpp.

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

◆ getSiblingsIndex()

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

Definition at line 715 of file NodeDelegate.cpp.

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

◆ numProperties()

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

Definition at line 485 of file NodeDelegate.cpp.

486{
489 return realProps.size();
490}
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 1001 of file NodeDelegate.cpp.

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

639{
640 if (!clickedProperty->canHaveStasis) return;
641 int rowCount = view->model()->rowCount(root);
642
643 for (int i = 0; i < rowCount; i++) {
644 QModelIndex idx = view->model()->index(i, 0, root);
645 // The entire property list has to be altered because model->setData cannot set individual properties
647 OptionalProperty prop = findProperty(props, clickedProperty);
648
649 if (!prop) continue;
650 prop->isInStasis = false;
651 view->model()->setData(idx, QVariant::fromValue(props), KisNodeModel::PropertiesRole);
652
653 resetPropertyStateRecursive(idx,clickedProperty);
654 }
655}
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 657 of file NodeDelegate.cpp.

658{
659 if (!clickedProperty->canHaveStasis) return;
660 int rowCount = view->model()->rowCount(root);
661
662 for (int i = 0; i < rowCount; i++) {
663 QModelIndex idx = view->model()->index(i, 0, root);
665 OptionalProperty prop = findProperty(props, clickedProperty);
666
667 if (prop->isInStasis) {
668 prop->isInStasis = false;
669 prop->state = QVariant(prop->stateInStasis);
670 }
671
672 view->model()->setData(idx, QVariant::fromValue(props), KisNodeModel::PropertiesRole);
673
674 restorePropertyInStasisRecursive(idx, clickedProperty);
675 }
676}
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 428 of file NodeDelegate.cpp.

429{
431 QList<OptionalProperty> prependList;
432 list << OptionalProperty(0);
433 list << OptionalProperty(0);
434 list << OptionalProperty(0);
435
436 KisBaseNode::PropertyList::const_iterator it = props.constBegin();
437 KisBaseNode::PropertyList::const_iterator end = props.constEnd();
438 for (; it != end; ++it) {
439 if (!it->isMutable &&
442 it->id != KisLayerPropertiesIcons::colorOverlay.id()) continue;
443
444 if (it->id == KisLayerPropertiesIcons::visible.id()) {
445 // noop...
446 } else if (it->id == KisLayerPropertiesIcons::locked.id()) {
447 list[0] = OptionalProperty(&(*it));
448 } else if (it->id == KisLayerPropertiesIcons::inheritAlpha.id()) {
449 list[1] = OptionalProperty(&(*it));
450 } else if (it->id == KisLayerPropertiesIcons::alphaLocked.id()) {
451 list[2] = OptionalProperty(&(*it));
452 } else {
453 prependList.prepend(OptionalProperty(&(*it)));
454 }
455 }
456
457 auto putToTheLeft = [] (QList<OptionalProperty> &list, const QString &id) {
458 auto it = std::find_if(list.begin(), list.end(), kismpl::mem_equal_to(&KisBaseNode::Property::id, id));
459 if (it != list.end()) {
460 std::rotate(list.begin(), it, std::next(it));
461 }
462 };
463
464 putToTheLeft(prependList, KisLayerPropertiesIcons::colorOverlay.id());
465 putToTheLeft(prependList, KisLayerPropertiesIcons::layerColorSpaceMismatch.id());
466 putToTheLeft(prependList, KisLayerPropertiesIcons::layerError.id());
467
468 {
469 QMutableListIterator<OptionalProperty> i(prependList);
470 i.toBack();
471 while (i.hasPrevious()) {
472 OptionalProperty val = i.previous();
473
474 int emptyIndex = list.lastIndexOf(nullptr);
475 if (emptyIndex < 0) break;
476
477 list[emptyIndex] = val;
478 i.remove();
479 }
480 }
481
482 return prependList + list;
483}
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 609 of file NodeDelegate.cpp.

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

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

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

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: