Krita Source Code Documentation
Loading...
Searching...
No Matches
NodeView Class Reference

#include <NodeView.h>

+ Inheritance diagram for NodeView:

Classes

class  PropertyAction
 

Public Types

enum  ColumnIndex { DEFAULT_COL = 0 , VISIBILITY_COL = 1 , SELECTED_COL = 2 }
 

Public Slots

void slotConfigurationChanged ()
 
void slotScrollerStateChanged (QScroller::State state)
 
void slotUpdateIcons ()
 called with a theme change to refresh icon colors
 

Signals

void contextMenuRequested (const QPoint &globalPos, const QModelIndex &index)
 
void selectionChanged (const QModelIndexList &)
 

Public Member Functions

void addPropertyActions (QMenu *menu, const QModelIndex &index)
 
void dragEnterEvent (QDragEnterEvent *e) override
 
void dragLeaveEvent (QDragLeaveEvent *e) override
 
void dragMoveEvent (QDragMoveEvent *ev) override
 
void drawBranches (QPainter *painter, const QRect &rect, const QModelIndex &index) const override
 
void dropEvent (QDropEvent *ev) override
 
void mousePressEvent (QMouseEvent *e) override
 
 NodeView (QWidget *parent=0)
 
void paintEvent (QPaintEvent *event) override
 
 Private (NodeView *_q)
 
void resizeEvent (QResizeEvent *event) override
 
void setModel (QAbstractItemModel *model) override
 
void toggleSolo (const QModelIndex &index)
 
void updateNode (const QModelIndex &index)
 
 ~NodeView () override
 

Public Attributes

NodeDelegate delegate
 
QPersistentModelIndex hovered
 
bool ignoreDataChanged = false
 
QPoint lastPos
 
bool shiftClickFix
 

Protected Slots

void currentChanged (const QModelIndex &current, const QModelIndex &previous) override
 
void dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles=QVector< int >()) override
 
void selectionChanged (const QItemSelection &selected, const QItemSelection &deselected) override
 

Protected Member Functions

void contextMenuEvent (QContextMenuEvent *event) override
 
QPixmap createDragPixmap () const
 
int cursorPageIndex () const
 
QModelIndex indexAt (const QPoint &point) const override
 
QItemSelectionModel::SelectionFlags selectionCommand (const QModelIndex &index, const QEvent *event) const override
 
virtual void showContextMenu (const QPoint &globalPos, const QModelIndex &index)
 
void startDrag (Qt::DropActions supportedActions) override
 
bool viewportEvent (QEvent *event) override
 

Private Types

typedef KisNodeModel Model
 

Private Slots

void slotActionToggled (bool on, const QPersistentModelIndex &index, int property)
 

Private Member Functions

std::optional< QModelIndex > getActiveItem ()
 
bool isDragging () const
 
QStyleOptionViewItem optionForIndex (const QModelIndex &index) const
 
void setDraggingFlag (bool flag=true)
 
void setExclusiveActiveItem (QModelIndex index)
 
void updateSelectedCheckboxColumn ()
 
- Private Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Private Attributes

Private *const d
 
bool m_draggingFlag
 
- Private Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Detailed Description

A widget displaying the Krita nodes (layers, masks, local selections, etc.)

This class is designed as a Qt model-view widget.

The Qt documentation explains the design and terminology for these classes: https://doc.qt.io/qt-5/model-view-programming.html

This widget should work correctly in your Qt designer .ui file.

Definition at line 53 of file NodeView.cpp.

Member Typedef Documentation

◆ Model

typedef KisNodeModel NodeView::Model
private

Definition at line 154 of file NodeView.h.

Member Enumeration Documentation

◆ ColumnIndex

Enumerator
DEFAULT_COL 
VISIBILITY_COL 
SELECTED_COL 

Definition at line 42 of file NodeView.h.

42 {
43 DEFAULT_COL = 0,
45 SELECTED_COL = 2,
46 };
@ SELECTED_COL
Definition NodeView.h:45
@ VISIBILITY_COL
Definition NodeView.h:44
@ DEFAULT_COL
Definition NodeView.h:43

Constructor & Destructor Documentation

◆ NodeView()

NodeView::NodeView ( QWidget * parent = 0)
explicit

Create a new NodeView.

Definition at line 80 of file NodeView.cpp.

81 : QTreeView(parent)
82 , m_draggingFlag(false)
83 , d(new Private(this))
84{
85 setItemDelegate(&d->delegate);
86
87 setMouseTracking(true);
88 setSelectionBehavior(SelectRows);
89 setDefaultDropAction(Qt::MoveAction);
90 setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
91 setSelectionMode(QAbstractItemView::ExtendedSelection);
92 setRootIsDecorated(false);
93
94 header()->hide();
95 setDragEnabled(true);
96 setDragDropMode(QAbstractItemView::DragDrop);
97 setAcceptDrops(true);
98 setDropIndicatorShown(true);
99
100 {
101 QScroller *scroller = KisKineticScroller::createPreconfiguredScroller(this);
102 if (scroller) {
103 connect(scroller, SIGNAL(stateChanged(QScroller::State)),
104 this, SLOT(slotScrollerStateChanged(QScroller::State)));
105 }
106 }
107}
Private *const d
Definition NodeView.h:157
void slotScrollerStateChanged(QScroller::State state)
Definition NodeView.cpp:552
bool m_draggingFlag
Definition NodeView.h:151
KRITAWIDGETUTILS_EXPORT QScroller * createPreconfiguredScroller(QAbstractScrollArea *target)

References KisKineticScroller::createPreconfiguredScroller(), d, and slotScrollerStateChanged().

◆ ~NodeView()

NodeView::~NodeView ( )
override

Definition at line 109 of file NodeView.cpp.

110{
111 delete d;
112}

References d.

Member Function Documentation

◆ addPropertyActions()

void NodeView::addPropertyActions ( QMenu * menu,
const QModelIndex & index )

Add toggle actions for all the properties associated with the current document section associated with the model index to the specified menu.

For instance, if a document section can be locked and visible, the menu will be expanded with locked and visible toggle actions.

For instance

NodeView * nodeView;
QModelIndex index = getCurrentNode();
QMenu menu;
if (index.isValid()) {
sectionView->addPropertyActions(&menu, index);
} else {
menu.addAction(...); // Something to create a new document section, for example.
}
Parameters
menuA pointer to the menu that will be expanded with the toggle actions
indexThe model index associated with the document section that may or may not provide a number of toggle actions.

Definition at line 139 of file NodeView.cpp.

140{
142 for (int i = 0, n = list.count(); i < n; ++i) {
143 if (list.at(i).isMutable) {
144 PropertyAction *a = new PropertyAction(i, list.at(i), index, menu);
145 connect(a, SIGNAL(toggled(bool,QPersistentModelIndex,int)),
146 this, SLOT(slotActionToggled(bool,QPersistentModelIndex,int)));
147 menu->addAction(a);
148 }
149 }
150}
@ PropertiesRole
A list of properties the part has.
void slotActionToggled(bool on, const QPersistentModelIndex &index, int property)
Definition NodeView.cpp:350

References KisNodeModel::PropertiesRole, and slotActionToggled().

◆ contextMenuEvent()

void NodeView::contextMenuEvent ( QContextMenuEvent * event)
overrideprotected

Definition at line 296 of file NodeView.cpp.

297{
298 QTreeView::contextMenuEvent(e);
299 QModelIndex i = indexAt(e->pos());
300 if (model())
301 i = model()->buddy(i);
302 showContextMenu(e->globalPos(), i);
303}
virtual void showContextMenu(const QPoint &globalPos, const QModelIndex &index)
Definition NodeView.cpp:305
QModelIndex indexAt(const QPoint &point) const override
Definition NodeView.cpp:195

References indexAt(), and showContextMenu().

◆ contextMenuRequested

void NodeView::contextMenuRequested ( const QPoint & globalPos,
const QModelIndex & index )
signal

Emitted whenever the user clicks with the secondary mouse button on an item. It is up to the application to design the contents of the context menu and show it.

◆ createDragPixmap()

QPixmap NodeView::createDragPixmap ( ) const
protected

Definition at line 377 of file NodeView.cpp.

378{
379 const QModelIndexList selectedIndexes = selectionModel()->selectedIndexes();
380 Q_ASSERT(!selectedIndexes.isEmpty());
381
382 const int itemCount = selectedIndexes.count();
383
384 // If more than one item is dragged, align the items inside a
385 // rectangular grid. The maximum grid size is limited to 4 x 4 items.
386 int xCount = 2;
387 int size = 96;
388 if (itemCount > 9) {
389 xCount = 4;
391 }
392 else if (itemCount > 4) {
393 xCount = 3;
395 }
396 else if (itemCount < xCount) {
397 xCount = itemCount;
398 }
399
400 int yCount = itemCount / xCount;
401 if (itemCount % xCount != 0) {
402 ++yCount;
403 }
404
405 if (yCount > xCount) {
406 yCount = xCount;
407 }
408
409 // Draw the selected items into the grid cells
410 QPixmap dragPixmap(xCount * size + xCount - 1, yCount * size + yCount - 1);
411 dragPixmap.fill(Qt::transparent);
412
413 QPainter painter(&dragPixmap);
414 int x = 0;
415 int y = 0;
416 Q_FOREACH (const QModelIndex &selectedIndex, selectedIndexes) {
417 const QImage img = selectedIndex.data(int(KisNodeModel::BeginThumbnailRole) + size).value<QImage>();
418 painter.drawPixmap(x, y, QPixmap::fromImage(img.scaled(QSize(size, size), Qt::KeepAspectRatio, Qt::SmoothTransformation)));
419
420 x += size + 1;
421 if (x >= dragPixmap.width()) {
422 x = 0;
423 y += size + 1;
424 }
425 if (y >= dragPixmap.height()) {
426 break;
427 }
428 }
429
430 return dragPixmap;
431}
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References KisNodeModel::BeginThumbnailRole, KisIconUtils::SizeHuge, and KisIconUtils::SizeLarge.

◆ currentChanged

void NodeView::currentChanged ( const QModelIndex & current,
const QModelIndex & previous )
overrideprotectedslot

Definition at line 310 of file NodeView.cpp.

311{
312 QTreeView::currentChanged(current, previous);
313 if (current != previous) {
314 Q_ASSERT(!current.isValid() || current.model() == model());
315 KisSignalsBlocker blocker(this);
316 model()->setData(current, true, KisNodeModel::ActiveRole);
317 }
318}
@ ActiveRole
Whether the section is the active one.

References KisNodeModel::ActiveRole.

◆ cursorPageIndex()

int NodeView::cursorPageIndex ( ) const
protected

Calculates the index of the nearest item to the cursor position

Definition at line 478 of file NodeView.cpp.

479{
480 QSize size(visualRect(model()->index(0, 0, QModelIndex())).width(), visualRect(model()->index(0, 0, QModelIndex())).height());
481 int scrollBarValue = verticalScrollBar()->value();
482
483 QPoint cursorPosition = QWidget::mapFromGlobal(QCursor::pos());
484
485 int numberRow = (cursorPosition.y() + scrollBarValue) / size.height();
486
487 //If cursor is at the half button of the page then the move action is performed after the slide, otherwise it is
488 //performed before the page
489 if (abs((cursorPosition.y() + scrollBarValue) - size.height()*numberRow) > (size.height()/2)) {
490 numberRow++;
491 }
492
493 if (numberRow > model()->rowCount(QModelIndex())) {
494 numberRow = model()->rowCount(QModelIndex());
495 }
496
497 return numberRow;
498}
Point abs(const Point &pt)

◆ dataChanged

void NodeView::dataChanged ( const QModelIndex & topLeft,
const QModelIndex & bottomRight,
const QVector< int > & roles = QVector<int>() )
overrideprotectedslot

Definition at line 320 of file NodeView.cpp.

321{
322 QTreeView::dataChanged(topLeft, bottomRight);
323
324 if (d->ignoreDataChanged){
325 d->ignoreDataChanged = false;
326 return;
327 }
328
329 for (int x = topLeft.row(); x <= bottomRight.row(); ++x) {
330 for (int y = topLeft.column(); y <= bottomRight.column(); ++y) {
331 QModelIndex index = topLeft.sibling(x, y);
332 if (index.data(KisNodeModel::ActiveRole).toBool()) {
333 if (currentIndex() != index) {
334 setCurrentIndex(index);
335 }
336
337 return;
338 }
339 }
340 }
341}

References KisNodeModel::ActiveRole, and d.

◆ dragEnterEvent()

void NodeView::dragEnterEvent ( QDragEnterEvent * e)
override

Definition at line 500 of file NodeView.cpp.

501{
503
504 QVariant data = QVariant::fromValue(
505 static_cast<void*>(const_cast<QMimeData*>(ev->mimeData())));
506 model()->setData(QModelIndex(), data, KisNodeModel::DropEnabled);
507
508 QTreeView::dragEnterEvent(ev);
509}
#define DRAG_WHILE_DRAG_WORKAROUND_START()
Definition NodeView.cpp:48

References DRAG_WHILE_DRAG_WORKAROUND_START, and KisNodeModel::DropEnabled.

◆ dragLeaveEvent()

void NodeView::dragLeaveEvent ( QDragLeaveEvent * e)
override

Definition at line 517 of file NodeView.cpp.

518{
519 QTreeView::dragLeaveEvent(e);
521}
#define DRAG_WHILE_DRAG_WORKAROUND_STOP()
Definition NodeView.cpp:49

References DRAG_WHILE_DRAG_WORKAROUND_STOP.

◆ dragMoveEvent()

void NodeView::dragMoveEvent ( QDragMoveEvent * ev)
override

Definition at line 511 of file NodeView.cpp.

512{
514 QTreeView::dragMoveEvent(ev);
515}

References DRAG_WHILE_DRAG_WORKAROUND_START.

◆ drawBranches()

void NodeView::drawBranches ( QPainter * painter,
const QRect & rect,
const QModelIndex & index ) const
override

Definition at line 458 of file NodeView.cpp.

460{
461#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
462 QStyleOptionViewItem option = viewOptions();
463#else
464 QStyleOptionViewItem option;
465 initViewItemOption(&option);
466#endif
467 option.rect = rect;
468 // This is not really a job for an item delegate, but the logic was already there
469 d->delegate.drawBranches(painter, option, index);
470}

References d.

◆ dropEvent()

void NodeView::dropEvent ( QDropEvent * ev)
override

Definition at line 472 of file NodeView.cpp.

473{
474 QTreeView::dropEvent(ev);
476}

References DRAG_WHILE_DRAG_WORKAROUND_STOP.

◆ getActiveItem()

std::optional< QModelIndex > NodeView::getActiveItem ( )
private

Definition at line 577 of file NodeView.cpp.

578{
579 QAbstractItemModel* mdl = model();
580
581 int rows = mdl->rowCount();
582 int clmns = mdl->columnCount();
583
584 for (int i = 0; i < rows; i++) {
585 for (int j = 0; j < clmns; j++) {
586 auto index = mdl->index(i, j);
587 if (mdl->data(index, KisNodeModel::ActiveRole).toBool()){
588 return index;
589 }
590 }
591 }
592
593 return {};
594}

References KisNodeModel::ActiveRole.

◆ indexAt()

QModelIndex NodeView::indexAt ( const QPoint & point) const
overrideprotected

Definition at line 195 of file NodeView.cpp.

196{
198
199 QModelIndex index = QTreeView::indexAt(point);
200 if (!index.isValid()) {
201 // Middle is a good position for both LTR and RTL layouts
202 // First reset x, then get the x in the middle
203 index = QTreeView::indexAt(point - QPoint(point.x(), 0) + QPoint(width() / 2, 0));
204 }
205
206 return index;
207}

◆ isDragging()

bool NodeView::isDragging ( ) const
private

Permit to know if a slide is dragging

Returns
boolean

Definition at line 537 of file NodeView.cpp.

538{
539 return m_draggingFlag;
540}

References m_draggingFlag.

◆ mousePressEvent()

void NodeView::mousePressEvent ( QMouseEvent * e)
override

Definition at line 523 of file NodeView.cpp.

523 {
524 if (!(e->modifiers() & Qt::ControlModifier)) {
525 QTreeView::mousePressEvent(e);
526 return;
527 }
528
529 std::optional<QModelIndex> ind = getActiveItem();
530 QTreeView::mousePressEvent(e);
531
532 if (ind.has_value()) {
533 setExclusiveActiveItem(ind.value());
534 }
535}
void setExclusiveActiveItem(QModelIndex index)
Definition NodeView.cpp:596
std::optional< QModelIndex > getActiveItem()
Definition NodeView.cpp:577

References getActiveItem(), and setExclusiveActiveItem().

◆ optionForIndex()

QStyleOptionViewItem NodeView::optionForIndex ( const QModelIndex & index) const
private

Definition at line 357 of file NodeView.cpp.

358{
359#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
360 QStyleOptionViewItem option = viewOptions();
361#else
362 QStyleOptionViewItem option;
363 initViewItemOption(&option);
364#endif
365 option.rect = visualRect(index);
366 if (index == currentIndex())
367 option.state |= QStyle::State_HasFocus;
368 return option;
369}

◆ paintEvent()

void NodeView::paintEvent ( QPaintEvent * event)
override

Definition at line 452 of file NodeView.cpp.

453{
454 event->accept();
455 QTreeView::paintEvent(event);
456}

◆ Private()

NodeView::Private ( NodeView * _q)
inline

Definition at line 56 of file NodeView.cpp.

57 : delegate(_q, _q)
58#ifdef DRAG_WHILE_DRAG_WORKAROUND
59 , isDragging(false)
60#endif
61#ifdef QT6_SHIFT_SELECTION_WORKAROUND
62 , shiftClickFix(false)
63#endif
64 {
65 }
NodeDelegate delegate
Definition NodeView.cpp:66
bool isDragging() const
Definition NodeView.cpp:537
bool shiftClickFix
Definition NodeView.cpp:74

◆ resizeEvent()

void NodeView::resizeEvent ( QResizeEvent * event)
override

Definition at line 433 of file NodeView.cpp.

434{
436 header()->setStretchLastSection(false);
437
438 int otherColumnsWidth = scm.visibilityColumnWidth();
439
440 // if layer box is enabled subtract its width from the "Default col".
441 if (KisConfig(false).useLayerSelectionCheckbox()) {
442 otherColumnsWidth += scm.selectedButtonColumnWidth();
443 }
444 header()->resizeSection(DEFAULT_COL, event->size().width() - otherColumnsWidth);
445 header()->resizeSection(SELECTED_COL, scm.selectedButtonColumnWidth());
446 header()->resizeSection(VISIBILITY_COL, scm.visibilityColumnWidth());
447
448 setIndentation(scm.indentation());
449 QTreeView::resizeEvent(event);
450}

References DEFAULT_COL, KisNodeViewColorScheme::indentation(), SELECTED_COL, KisNodeViewColorScheme::selectedButtonColumnWidth(), VISIBILITY_COL, and KisNodeViewColorScheme::visibilityColumnWidth().

◆ selectionChanged [1/2]

void NodeView::selectionChanged ( const QItemSelection & selected,
const QItemSelection & deselected )
overrideprotectedslot

Definition at line 343 of file NodeView.cpp.

344{
345 QTreeView::selectionChanged(selected, deselected);
346 // XXX: selectedIndexes() does not include hidden (collapsed) items, is this really intended?
347 Q_EMIT selectionChanged(selectedIndexes());
348}
void selectionChanged(const QModelIndexList &)

References selectionChanged().

◆ selectionChanged [2/2]

void NodeView::selectionChanged ( const QModelIndexList & )
signal

◆ selectionCommand()

QItemSelectionModel::SelectionFlags NodeView::selectionCommand ( const QModelIndex & index,
const QEvent * event ) const
overrideprotected

Definition at line 161 of file NodeView.cpp.

161 {
162 //When adding a layer with Shift or Ctrl is held, the selection will expand to add that new layer,
163 //So to avoid that we explicitly select the new layer.
164 if (!event && QApplication::keyboardModifiers() != Qt::NoModifier
166 && !d->shiftClickFix
167#endif
168 ) {
169#ifdef QT6_SHIFT_SELECTION_WORKAROUND
170 d->shiftClickFix = false;
171#endif
172 return QItemSelectionModel::ClearAndSelect;
173 }
174
175#ifdef QT6_SHIFT_SELECTION_WORKAROUND
176 //Clear this just in case
177 d->shiftClickFix = false;
178
179 //Qt6 has a bug/feature? where after you do a shift selection it sends a second selection event with the event argument being null
180 //This triggers the logic above, so we explicitly avoid the next null event
181 if (event &&
182 (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::KeyPress) &&
183 QApplication::keyboardModifiers() & Qt::ShiftModifier)
184 d->shiftClickFix = true;
185#endif
186
187 //We still get ctrl click events so we need to ignore those
188 if (event &&
189 event->type() == QEvent::MouseButtonPress && (static_cast<const QMouseEvent*>(event)->modifiers() & Qt::ControlModifier))
190 return QItemSelectionModel::NoUpdate;
191
192 return QTreeView::selectionCommand(index, event);
193}
#define QT6_SHIFT_SELECTION_WORKAROUND
Definition NodeView.cpp:37

References d, and QT6_SHIFT_SELECTION_WORKAROUND.

◆ setDraggingFlag()

void NodeView::setDraggingFlag ( bool flag = true)
private

Setter for the dragging flag

Parameters
flagboolean

Definition at line 542 of file NodeView.cpp.

543{
544 m_draggingFlag = flag;
545}

References m_draggingFlag.

◆ setExclusiveActiveItem()

void NodeView::setExclusiveActiveItem ( QModelIndex index)
private

Definition at line 596 of file NodeView.cpp.

597{
598 QAbstractItemModel* mdl = model();
599
600 int rows = mdl->rowCount();
601 int clmns = mdl->columnCount();
602
603 for (int i = 0; i < rows; i++) {
604 for (int j = 0; j < clmns; j++) {
605 QModelIndex ind = mdl->index(i, j);
606
607 //Suppress the data changed event, so that it doesn't mess with the selection
608 d->ignoreDataChanged = true;
609 mdl->setData(ind, false, KisNodeModel::ActiveRole);
610 }
611 }
612
613 d->ignoreDataChanged = true;
614 mdl->setData(index, true, KisNodeModel::ActiveRole);
615}

References KisNodeModel::ActiveRole, and d.

◆ setModel()

void NodeView::setModel ( QAbstractItemModel * model)
override

Definition at line 114 of file NodeView.cpp.

115{
116 QTreeView::setModel(model);
117
118 if (!this->model()->inherits("KisNodeModel") && !this->model()->inherits("KisNodeFilterProxyModel")) {
119 qWarning() << "NodeView may not work with" << model->metaObject()->className();
120 }
121 if (this->model()->columnCount() != 3) {
122 qWarning() << "NodeView: expected 2 model columns, got " << this->model()->columnCount();
123 }
124
125 if (header()->sectionPosition(VISIBILITY_COL) != 0 || header()->sectionPosition(SELECTED_COL) != 1) {
126 header()->moveSection(VISIBILITY_COL, 0);
127 header()->moveSection(SELECTED_COL, 1);
128 }
129
130 KisConfig cfg(true);
131 if (!cfg.useLayerSelectionCheckbox()) {
132 header()->hideSection(SELECTED_COL);
133 }
134
135 // the default may be too large for our visibility icon
136 header()->setMinimumSectionSize(KisNodeViewColorScheme::instance()->visibilityColumnWidth());
137}
static KisNodeViewColorScheme * instance()

References KisNodeViewColorScheme::instance(), SELECTED_COL, KisConfig::useLayerSelectionCheckbox(), and VISIBILITY_COL.

◆ showContextMenu()

void NodeView::showContextMenu ( const QPoint & globalPos,
const QModelIndex & index )
protectedvirtual

Definition at line 305 of file NodeView.cpp.

306{
307 Q_EMIT contextMenuRequested(globalPos, index);
308}
void contextMenuRequested(const QPoint &globalPos, const QModelIndex &index)

References contextMenuRequested().

◆ slotActionToggled

void NodeView::slotActionToggled ( bool on,
const QPersistentModelIndex & index,
int property )
privateslot

Definition at line 350 of file NodeView.cpp.

351{
353 list[num].state = on;
354 const_cast<QAbstractItemModel*>(index.model())->setData(index, QVariant::fromValue(list), KisNodeModel::PropertiesRole);
355}

References KisNodeModel::PropertiesRole.

◆ slotConfigurationChanged

void NodeView::slotConfigurationChanged ( )
slot

Definition at line 556 of file NodeView.cpp.

557{
558 setIndentation(KisNodeViewColorScheme::instance()->indentation());
560 d->delegate.slotConfigChanged();
561}
void updateSelectedCheckboxColumn()
Definition NodeView.cpp:563

References d, KisNodeViewColorScheme::instance(), and updateSelectedCheckboxColumn().

◆ slotScrollerStateChanged

void NodeView::slotScrollerStateChanged ( QScroller::State state)
slot

Definition at line 552 of file NodeView.cpp.

552 {
554}
KRITAWIDGETUTILS_EXPORT void updateCursor(QWidget *source, QScroller::State state)

References KisKineticScroller::updateCursor().

◆ slotUpdateIcons

void NodeView::slotUpdateIcons ( )
slot

called with a theme change to refresh icon colors

Definition at line 547 of file NodeView.cpp.

548{
549 d->delegate.slotUpdateIcon();
550}

References d.

◆ startDrag()

void NodeView::startDrag ( Qt::DropActions supportedActions)
overrideprotected

Definition at line 371 of file NodeView.cpp.

372{
374 QTreeView::startDrag(supportedActions);
375}

References DRAG_WHILE_DRAG_WORKAROUND_START.

◆ toggleSolo()

void NodeView::toggleSolo ( const QModelIndex & index)

Definition at line 157 of file NodeView.cpp.

157 {
158 d->delegate.toggleSolo(index);
159}

References d.

◆ updateNode()

void NodeView::updateNode ( const QModelIndex & index)

Definition at line 152 of file NodeView.cpp.

153{
154 dataChanged(index, index);
155}
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles=QVector< int >()) override
Definition NodeView.cpp:320

References dataChanged().

◆ updateSelectedCheckboxColumn()

void NodeView::updateSelectedCheckboxColumn ( )
private

Definition at line 563 of file NodeView.cpp.

564{
565 KisConfig cfg(false);
566 if (cfg.useLayerSelectionCheckbox() == !header()->isSectionHidden(SELECTED_COL)) {
567 return;
568 }
569 header()->setSectionHidden(SELECTED_COL, !cfg.useLayerSelectionCheckbox());
570 // add/subtract width based on SELECTED_COL section's visibility
571 header()->resizeSection(DEFAULT_COL,
572 size().width()
573 + (cfg.useLayerSelectionCheckbox() ? header()->sectionSize(SELECTED_COL)
574 : -header()->sectionSize(SELECTED_COL)));
575}

References DEFAULT_COL, SELECTED_COL, and KisConfig::useLayerSelectionCheckbox().

◆ viewportEvent()

bool NodeView::viewportEvent ( QEvent * event)
overrideprotected

Definition at line 209 of file NodeView.cpp.

210{
211 if (model()) {
212 switch(e->type()) {
213 case QEvent::MouseButtonPress: {
215
216 const QPoint pos = static_cast<QMouseEvent*>(e)->pos();
217 d->lastPos = pos;
218
219 if (!indexAt(pos).isValid()) {
220 return QTreeView::viewportEvent(e);
221 }
222 QModelIndex index = model()->buddy(indexAt(pos));
223 if (d->delegate.editorEvent(e, model(), optionForIndex(index), index)) {
224 return true;
225 }
226 } break;
227 case QEvent::MouseButtonRelease: {
228 const QPoint pos = static_cast<QMouseEvent*>(e)->pos();
229 QModelIndex index = model()->buddy(indexAt(pos));
230 if (!indexAt(pos).isValid()) {
231 return QTreeView::viewportEvent(e);
232 }
233 if (d->delegate.editorEvent(e, model(), optionForIndex(index), index)) {
234 //Sometimes 2 items become active, to prevent that we explicitly turn off all but the first active item
235 std::optional<QModelIndex> active_ind = getActiveItem();
236 if (active_ind.has_value()) {
237 setExclusiveActiveItem(active_ind.value());
238 }
239 return true;
240 }
241 } break;
242 case QEvent::Leave: {
243 QEvent e(QEvent::Leave);
244 d->delegate.editorEvent(&e, model(), optionForIndex(d->hovered), d->hovered);
245 d->hovered = QModelIndex();
246 } break;
247 case QEvent::MouseMove: {
248#ifdef DRAG_WHILE_DRAG_WORKAROUND
249 if (d->isDragging) {
250 return false;
251 }
252#endif
253
254 const QPoint pos = static_cast<QMouseEvent*>(e)->pos();
255 QModelIndex hovered = indexAt(pos);
256 if (hovered != d->hovered) {
257 if (d->hovered.isValid()) {
258 QEvent e(QEvent::Leave);
259 d->delegate.editorEvent(&e, model(), optionForIndex(d->hovered), d->hovered);
260 }
261 if (hovered.isValid()) {
262 QEvent e(QEvent::Enter);
263 d->delegate.editorEvent(&e, model(), optionForIndex(hovered), hovered);
264 }
265 d->hovered = hovered;
266 }
267 /* This is a workaround for a bug in QTreeView that immediately begins a dragging action
268 when the mouse lands on the decoration/icon of a different index and moves 1 pixel or more */
269 Qt::MouseButtons buttons = static_cast<QMouseEvent*>(e)->buttons();
270 if ((Qt::LeftButton | Qt::MiddleButton) & buttons) {
271 if ((pos - d->lastPos).manhattanLength() > qApp->startDragDistance()) {
272 return QTreeView::viewportEvent(e);
273 }
274 return true;
275 }
276 } break;
277 case QEvent::ToolTip: {
278 const QPoint pos = static_cast<QHelpEvent*>(e)->pos();
279 if (!indexAt(pos).isValid()) {
280 return QTreeView::viewportEvent(e);
281 }
282 QModelIndex index = model()->buddy(indexAt(pos));
283 return d->delegate.editorEvent(e, model(), optionForIndex(index), index);
284 } break;
285 case QEvent::Resize: {
286 scheduleDelayedItemsLayout();
287 break;
288 }
289 default: break;
290 }
291 }
292
293 return QTreeView::viewportEvent(e);
294}
QStyleOptionViewItem optionForIndex(const QModelIndex &index) const
Definition NodeView.cpp:357
QPersistentModelIndex hovered
Definition NodeView.cpp:67
QString buttons(const T &ev)

References buttons(), d, DRAG_WHILE_DRAG_WORKAROUND_STOP, getActiveItem(), hovered, indexAt(), optionForIndex(), and setExclusiveActiveItem().

Member Data Documentation

◆ d

Private* const NodeView::d
private

Definition at line 157 of file NodeView.h.

◆ delegate

NodeDelegate NodeView::delegate

Definition at line 66 of file NodeView.cpp.

◆ hovered

QPersistentModelIndex NodeView::hovered

Definition at line 67 of file NodeView.cpp.

◆ ignoreDataChanged

bool NodeView::ignoreDataChanged = false

Definition at line 76 of file NodeView.cpp.

◆ lastPos

QPoint NodeView::lastPos

Definition at line 68 of file NodeView.cpp.

◆ m_draggingFlag

bool NodeView::m_draggingFlag
private

Definition at line 151 of file NodeView.h.

◆ shiftClickFix

bool NodeView::shiftClickFix

Definition at line 74 of file NodeView.cpp.


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