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
 
 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
 
QPoint lastPos
 

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

bool isDragging () const
 
QStyleOptionViewItem optionForIndex (const QModelIndex &index) const
 
void setDraggingFlag (bool flag=true)
 
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 50 of file NodeView.cpp.

Member Typedef Documentation

◆ Model

typedef KisNodeModel NodeView::Model
private

Definition at line 151 of file NodeView.h.

Member Enumeration Documentation

◆ ColumnIndex

Enumerator
DEFAULT_COL 
VISIBILITY_COL 
SELECTED_COL 

Definition at line 41 of file NodeView.h.

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

Constructor & Destructor Documentation

◆ NodeView()

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

Create a new NodeView.

Definition at line 70 of file NodeView.cpp.

71 : QTreeView(parent)
72 , m_draggingFlag(false)
73 , d(new Private(this))
74{
75 setItemDelegate(&d->delegate);
76
77 setMouseTracking(true);
78 setSelectionBehavior(SelectRows);
79 setDefaultDropAction(Qt::MoveAction);
80 setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
81 setSelectionMode(QAbstractItemView::ExtendedSelection);
82 setRootIsDecorated(false);
83
84 header()->hide();
85 setDragEnabled(true);
86 setDragDropMode(QAbstractItemView::DragDrop);
87 setAcceptDrops(true);
88 setDropIndicatorShown(true);
89
90 {
91 QScroller *scroller = KisKineticScroller::createPreconfiguredScroller(this);
92 if (scroller) {
93 connect(scroller, SIGNAL(stateChanged(QScroller::State)),
94 this, SLOT(slotScrollerStateChanged(QScroller::State)));
95 }
96 }
97}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
Private *const d
Definition NodeView.h:154
void slotScrollerStateChanged(QScroller::State state)
Definition NodeView.cpp:528
bool m_draggingFlag
Definition NodeView.h:148
KRITAWIDGETUTILS_EXPORT QScroller * createPreconfiguredScroller(QAbstractScrollArea *target)

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

◆ ~NodeView()

NodeView::~NodeView ( )
override

Definition at line 99 of file NodeView.cpp.

100{
101 delete d;
102}

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 129 of file NodeView.cpp.

130{
132 for (int i = 0, n = list.count(); i < n; ++i) {
133 if (list.at(i).isMutable) {
134 PropertyAction *a = new PropertyAction(i, list.at(i), index, menu);
135 connect(a, SIGNAL(toggled(bool,QPersistentModelIndex,int)),
136 this, SLOT(slotActionToggled(bool,QPersistentModelIndex,int)));
137 menu->addAction(a);
138 }
139 }
140}
@ PropertiesRole
A list of properties the part has.
void slotActionToggled(bool on, const QPersistentModelIndex &index, int property)
Definition NodeView.cpp:340

References connect(), KisNodeModel::PropertiesRole, and slotActionToggled().

◆ contextMenuEvent()

void NodeView::contextMenuEvent ( QContextMenuEvent * event)
overrideprotected

Definition at line 291 of file NodeView.cpp.

292{
293 QTreeView::contextMenuEvent(e);
294 QModelIndex i = indexAt(e->pos());
295 if (model())
296 i = model()->buddy(i);
297 showContextMenu(e->globalPos(), i);
298}
virtual void showContextMenu(const QPoint &globalPos, const QModelIndex &index)
Definition NodeView.cpp:300
QModelIndex indexAt(const QPoint &point) const override
Definition NodeView.cpp:206

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 367 of file NodeView.cpp.

368{
369 const QModelIndexList selectedIndexes = selectionModel()->selectedIndexes();
370 Q_ASSERT(!selectedIndexes.isEmpty());
371
372 const int itemCount = selectedIndexes.count();
373
374 // If more than one item is dragged, align the items inside a
375 // rectangular grid. The maximum grid size is limited to 4 x 4 items.
376 int xCount = 2;
377 int size = 96;
378 if (itemCount > 9) {
379 xCount = 4;
381 }
382 else if (itemCount > 4) {
383 xCount = 3;
385 }
386 else if (itemCount < xCount) {
387 xCount = itemCount;
388 }
389
390 int yCount = itemCount / xCount;
391 if (itemCount % xCount != 0) {
392 ++yCount;
393 }
394
395 if (yCount > xCount) {
396 yCount = xCount;
397 }
398
399 // Draw the selected items into the grid cells
400 QPixmap dragPixmap(xCount * size + xCount - 1, yCount * size + yCount - 1);
401 dragPixmap.fill(Qt::transparent);
402
403 QPainter painter(&dragPixmap);
404 int x = 0;
405 int y = 0;
406 Q_FOREACH (const QModelIndex &selectedIndex, selectedIndexes) {
407 const QImage img = selectedIndex.data(int(KisNodeModel::BeginThumbnailRole) + size).value<QImage>();
408 painter.drawPixmap(x, y, QPixmap::fromImage(img.scaled(QSize(size, size), Qt::KeepAspectRatio, Qt::SmoothTransformation)));
409
410 x += size + 1;
411 if (x >= dragPixmap.width()) {
412 x = 0;
413 y += size + 1;
414 }
415 if (y >= dragPixmap.height()) {
416 break;
417 }
418 }
419
420 return dragPixmap;
421}
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 305 of file NodeView.cpp.

306{
307 QTreeView::currentChanged(current, previous);
308 if (current != previous) {
309 Q_ASSERT(!current.isValid() || current.model() == model());
310 KisSignalsBlocker blocker(this);
311 model()->setData(current, true, KisNodeModel::ActiveRole);
312 }
313}
@ 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 468 of file NodeView.cpp.

469{
470 QSize size(visualRect(model()->index(0, 0, QModelIndex())).width(), visualRect(model()->index(0, 0, QModelIndex())).height());
471 int scrollBarValue = verticalScrollBar()->value();
472
473 QPoint cursorPosition = QWidget::mapFromGlobal(QCursor::pos());
474
475 int numberRow = (cursorPosition.y() + scrollBarValue) / size.height();
476
477 //If cursor is at the half button of the page then the move action is performed after the slide, otherwise it is
478 //performed before the page
479 if (abs((cursorPosition.y() + scrollBarValue) - size.height()*numberRow) > (size.height()/2)) {
480 numberRow++;
481 }
482
483 if (numberRow > model()->rowCount(QModelIndex())) {
484 numberRow = model()->rowCount(QModelIndex());
485 }
486
487 return numberRow;
488}
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 315 of file NodeView.cpp.

316{
317 QTreeView::dataChanged(topLeft, bottomRight);
318
319 for (int x = topLeft.row(); x <= bottomRight.row(); ++x) {
320 for (int y = topLeft.column(); y <= bottomRight.column(); ++y) {
321 QModelIndex index = topLeft.sibling(x, y);
322 if (index.data(KisNodeModel::ActiveRole).toBool()) {
323 if (currentIndex() != index) {
324 setCurrentIndex(index);
325 }
326
327 return;
328 }
329 }
330 }
331}

References KisNodeModel::ActiveRole.

◆ dragEnterEvent()

void NodeView::dragEnterEvent ( QDragEnterEvent * e)
override

Definition at line 490 of file NodeView.cpp.

491{
493
494 QVariant data = QVariant::fromValue(
495 static_cast<void*>(const_cast<QMimeData*>(ev->mimeData())));
496 model()->setData(QModelIndex(), data, KisNodeModel::DropEnabled);
497
498 QTreeView::dragEnterEvent(ev);
499}
#define DRAG_WHILE_DRAG_WORKAROUND_START()
Definition NodeView.cpp:45

References DRAG_WHILE_DRAG_WORKAROUND_START, and KisNodeModel::DropEnabled.

◆ dragLeaveEvent()

void NodeView::dragLeaveEvent ( QDragLeaveEvent * e)
override

Definition at line 507 of file NodeView.cpp.

508{
509 QTreeView::dragLeaveEvent(e);
511}
#define DRAG_WHILE_DRAG_WORKAROUND_STOP()
Definition NodeView.cpp:46

References DRAG_WHILE_DRAG_WORKAROUND_STOP.

◆ dragMoveEvent()

void NodeView::dragMoveEvent ( QDragMoveEvent * ev)
override

Definition at line 501 of file NodeView.cpp.

502{
504 QTreeView::dragMoveEvent(ev);
505}

References DRAG_WHILE_DRAG_WORKAROUND_START.

◆ drawBranches()

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

Definition at line 448 of file NodeView.cpp.

450{
451#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
452 QStyleOptionViewItem option = viewOptions();
453#else
454 QStyleOptionViewItem option;
455 initViewItemOption(&option);
456#endif
457 option.rect = rect;
458 // This is not really a job for an item delegate, but the logic was already there
459 d->delegate.drawBranches(painter, option, index);
460}

References d.

◆ dropEvent()

void NodeView::dropEvent ( QDropEvent * ev)
override

Definition at line 462 of file NodeView.cpp.

463{
464 QTreeView::dropEvent(ev);
466}

References DRAG_WHILE_DRAG_WORKAROUND_STOP.

◆ indexAt()

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

Definition at line 206 of file NodeView.cpp.

207{
209
210 QModelIndex index = QTreeView::indexAt(point);
211 if (!index.isValid()) {
212 // Middle is a good position for both LTR and RTL layouts
213 // First reset x, then get the x in the middle
214 index = QTreeView::indexAt(point - QPoint(point.x(), 0) + QPoint(width() / 2, 0));
215 }
216
217 return index;
218}

◆ isDragging()

bool NodeView::isDragging ( ) const
private

Permit to know if a slide is dragging

Returns
boolean

Definition at line 513 of file NodeView.cpp.

514{
515 return m_draggingFlag;
516}

References m_draggingFlag.

◆ optionForIndex()

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

Definition at line 347 of file NodeView.cpp.

348{
349#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
350 QStyleOptionViewItem option = viewOptions();
351#else
352 QStyleOptionViewItem option;
353 initViewItemOption(&option);
354#endif
355 option.rect = visualRect(index);
356 if (index == currentIndex())
357 option.state |= QStyle::State_HasFocus;
358 return option;
359}

◆ paintEvent()

void NodeView::paintEvent ( QPaintEvent * event)
override

Definition at line 442 of file NodeView.cpp.

443{
444 event->accept();
445 QTreeView::paintEvent(event);
446}

◆ Private()

NodeView::Private ( NodeView * _q)
inline

Definition at line 53 of file NodeView.cpp.

54 : delegate(_q, _q)
55#ifdef DRAG_WHILE_DRAG_WORKAROUND
56 , isDragging(false)
57#endif
58 {
59 }
NodeDelegate delegate
Definition NodeView.cpp:60
bool isDragging() const
Definition NodeView.cpp:513

◆ resizeEvent()

void NodeView::resizeEvent ( QResizeEvent * event)
override

Definition at line 423 of file NodeView.cpp.

424{
426 header()->setStretchLastSection(false);
427
428 int otherColumnsWidth = scm.visibilityColumnWidth();
429
430 // if layer box is enabled subtract its width from the "Default col".
431 if (KisConfig(false).useLayerSelectionCheckbox()) {
432 otherColumnsWidth += scm.selectedButtonColumnWidth();
433 }
434 header()->resizeSection(DEFAULT_COL, event->size().width() - otherColumnsWidth);
435 header()->resizeSection(SELECTED_COL, scm.selectedButtonColumnWidth());
436 header()->resizeSection(VISIBILITY_COL, scm.visibilityColumnWidth());
437
438 setIndentation(scm.indentation());
439 QTreeView::resizeEvent(event);
440}

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 333 of file NodeView.cpp.

334{
335 QTreeView::selectionChanged(selected, deselected);
336 // XXX: selectedIndexes() does not include hidden (collapsed) items, is this really intended?
337 Q_EMIT selectionChanged(selectedIndexes());
338}
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

Qt has a bug: when we Ctrl+click on an item, the item's selections gets toggled on mouse press, whereas usually it is done on mouse release. Therefore the user cannot do a Ctrl+D&D with the default configuration. This code fixes the problem by manually returning QItemSelectionModel::NoUpdate flag when the user clicks on an item and returning QItemSelectionModel::Toggle on release.

Qt 5.6 has a bug: it reads global modifiers, not the ones passed from event. So if you paste an item using Ctrl+V it'll select multiple layers for you

Definition at line 151 of file NodeView.cpp.

153{
164 if (event &&
165 (event->type() == QEvent::MouseButtonPress ||
166 event->type() == QEvent::MouseButtonRelease) &&
167 index.isValid()) {
168
169 const QMouseEvent *mevent = static_cast<const QMouseEvent*>(event);
170
171 if (mevent->button() == Qt::RightButton &&
172 selectionModel()->selectedIndexes().contains(index)) {
173
174 // Allow calling context menu for multiple layers
175 return QItemSelectionModel::NoUpdate;
176 }
177
178 if (event->type() == QEvent::MouseButtonPress &&
179 (mevent->modifiers() & Qt::ControlModifier)) {
180
181 return QItemSelectionModel::NoUpdate;
182 }
183
184 if (event->type() == QEvent::MouseButtonRelease &&
185 (mevent->modifiers() & Qt::ControlModifier)) {
186
187 // Select the entire row, otherwise we only get updates for DEFAULT_COL and then we have to
188 // manually sync its state with SELECTED_COL.
189 return QItemSelectionModel::Toggle | QItemSelectionModel::Rows;
190 }
191 }
192
198 Qt::KeyboardModifiers globalModifiers = QApplication::keyboardModifiers();
199 if (!event && globalModifiers != Qt::NoModifier) {
200 return QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows;
201 }
202
203 return QAbstractItemView::selectionCommand(index, event);
204}

◆ setDraggingFlag()

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

Setter for the dragging flag

Parameters
flagboolean

Definition at line 518 of file NodeView.cpp.

519{
520 m_draggingFlag = flag;
521}

References m_draggingFlag.

◆ setModel()

void NodeView::setModel ( QAbstractItemModel * model)
override

Definition at line 104 of file NodeView.cpp.

105{
106 QTreeView::setModel(model);
107
108 if (!this->model()->inherits("KisNodeModel") && !this->model()->inherits("KisNodeFilterProxyModel")) {
109 qWarning() << "NodeView may not work with" << model->metaObject()->className();
110 }
111 if (this->model()->columnCount() != 3) {
112 qWarning() << "NodeView: expected 2 model columns, got " << this->model()->columnCount();
113 }
114
115 if (header()->sectionPosition(VISIBILITY_COL) != 0 || header()->sectionPosition(SELECTED_COL) != 1) {
116 header()->moveSection(VISIBILITY_COL, 0);
117 header()->moveSection(SELECTED_COL, 1);
118 }
119
120 KisConfig cfg(true);
121 if (!cfg.useLayerSelectionCheckbox()) {
122 header()->hideSection(SELECTED_COL);
123 }
124
125 // the default may be too large for our visibility icon
126 header()->setMinimumSectionSize(KisNodeViewColorScheme::instance()->visibilityColumnWidth());
127}
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 300 of file NodeView.cpp.

301{
302 Q_EMIT contextMenuRequested(globalPos, index);
303}
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 340 of file NodeView.cpp.

341{
343 list[num].state = on;
344 const_cast<QAbstractItemModel*>(index.model())->setData(index, QVariant::fromValue(list), KisNodeModel::PropertiesRole);
345}

References KisNodeModel::PropertiesRole.

◆ slotConfigurationChanged

void NodeView::slotConfigurationChanged ( )
slot

Definition at line 532 of file NodeView.cpp.

533{
534 setIndentation(KisNodeViewColorScheme::instance()->indentation());
536 d->delegate.slotConfigChanged();
537}
void updateSelectedCheckboxColumn()
Definition NodeView.cpp:539

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

◆ slotScrollerStateChanged

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

Definition at line 528 of file NodeView.cpp.

528 {
530}
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 523 of file NodeView.cpp.

524{
525 d->delegate.slotUpdateIcon();
526}

References d.

◆ startDrag()

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

Definition at line 361 of file NodeView.cpp.

362{
364 QTreeView::startDrag(supportedActions);
365}

References DRAG_WHILE_DRAG_WORKAROUND_START.

◆ toggleSolo()

void NodeView::toggleSolo ( const QModelIndex & index)

Definition at line 147 of file NodeView.cpp.

147 {
148 d->delegate.toggleSolo(index);
149}

References d.

◆ updateNode()

void NodeView::updateNode ( const QModelIndex & index)

Definition at line 142 of file NodeView.cpp.

143{
144 dataChanged(index, index);
145}
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles=QVector< int >()) override
Definition NodeView.cpp:315

References dataChanged().

◆ updateSelectedCheckboxColumn()

void NodeView::updateSelectedCheckboxColumn ( )
private

Definition at line 539 of file NodeView.cpp.

540{
541 KisConfig cfg(false);
542 if (cfg.useLayerSelectionCheckbox() == !header()->isSectionHidden(SELECTED_COL)) {
543 return;
544 }
545 header()->setSectionHidden(SELECTED_COL, !cfg.useLayerSelectionCheckbox());
546 // add/subtract width based on SELECTED_COL section's visibility
547 header()->resizeSection(DEFAULT_COL,
548 size().width()
549 + (cfg.useLayerSelectionCheckbox() ? header()->sectionSize(SELECTED_COL)
550 : -header()->sectionSize(SELECTED_COL)));
551}

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

◆ viewportEvent()

bool NodeView::viewportEvent ( QEvent * event)
overrideprotected

Definition at line 220 of file NodeView.cpp.

221{
222 if (model()) {
223 switch(e->type()) {
224 case QEvent::MouseButtonPress: {
226
227 const QPoint pos = static_cast<QMouseEvent*>(e)->pos();
228 d->lastPos = pos;
229
230 if (!indexAt(pos).isValid()) {
231 return QTreeView::viewportEvent(e);
232 }
233 QModelIndex index = model()->buddy(indexAt(pos));
234 if (d->delegate.editorEvent(e, model(), optionForIndex(index), index)) {
235 return true;
236 }
237 } break;
238 case QEvent::Leave: {
239 QEvent e(QEvent::Leave);
240 d->delegate.editorEvent(&e, model(), optionForIndex(d->hovered), d->hovered);
241 d->hovered = QModelIndex();
242 } break;
243 case QEvent::MouseMove: {
244#ifdef DRAG_WHILE_DRAG_WORKAROUND
245 if (d->isDragging) {
246 return false;
247 }
248#endif
249
250 const QPoint pos = static_cast<QMouseEvent*>(e)->pos();
251 QModelIndex hovered = indexAt(pos);
252 if (hovered != d->hovered) {
253 if (d->hovered.isValid()) {
254 QEvent e(QEvent::Leave);
255 d->delegate.editorEvent(&e, model(), optionForIndex(d->hovered), d->hovered);
256 }
257 if (hovered.isValid()) {
258 QEvent e(QEvent::Enter);
259 d->delegate.editorEvent(&e, model(), optionForIndex(hovered), hovered);
260 }
261 d->hovered = hovered;
262 }
263 /* This is a workaround for a bug in QTreeView that immediately begins a dragging action
264 when the mouse lands on the decoration/icon of a different index and moves 1 pixel or more */
265 Qt::MouseButtons buttons = static_cast<QMouseEvent*>(e)->buttons();
266 if ((Qt::LeftButton | Qt::MiddleButton) & buttons) {
267 if ((pos - d->lastPos).manhattanLength() > qApp->startDragDistance()) {
268 return QTreeView::viewportEvent(e);
269 }
270 return true;
271 }
272 } break;
273 case QEvent::ToolTip: {
274 const QPoint pos = static_cast<QHelpEvent*>(e)->pos();
275 if (!indexAt(pos).isValid()) {
276 return QTreeView::viewportEvent(e);
277 }
278 QModelIndex index = model()->buddy(indexAt(pos));
279 return d->delegate.editorEvent(e, model(), optionForIndex(index), index);
280 } break;
281 case QEvent::Resize: {
282 scheduleDelayedItemsLayout();
283 break;
284 }
285 default: break;
286 }
287 }
288 return QTreeView::viewportEvent(e);
289}
QStyleOptionViewItem optionForIndex(const QModelIndex &index) const
Definition NodeView.cpp:347
QPersistentModelIndex hovered
Definition NodeView.cpp:61
QString buttons(const T &ev)

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

Member Data Documentation

◆ d

Private* const NodeView::d
private

Definition at line 154 of file NodeView.h.

◆ delegate

NodeDelegate NodeView::delegate

Definition at line 60 of file NodeView.cpp.

◆ hovered

QPersistentModelIndex NodeView::hovered

Definition at line 61 of file NodeView.cpp.

◆ lastPos

QPoint NodeView::lastPos

Definition at line 62 of file NodeView.cpp.

◆ m_draggingFlag

bool NodeView::m_draggingFlag
private

Definition at line 148 of file NodeView.h.


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