Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Layer selection fixes

Luna Lovecraft071d8bdd5ec0
diff --git a/plugins/dockers/layerdocker/NodeDelegate.cpp b/plugins/dockers/layerdocker/NodeDelegate.cpp
index 146a706fd6..b7171c08f9 100644
--- a/plugins/dockers/layerdocker/NodeDelegate.cpp
+++ b/plugins/dockers/layerdocker/NodeDelegate.cpp
@@ -1037,6 +1037,20 @@ NodeDelegate::Private::propForMousePos(const QModelIndex &index, const QPoint &m
bool NodeDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
{
+ //Explicitly handle mouse release events
+ if (event->type() == QEvent::MouseButtonRelease &&index.flags() & Qt::ItemIsEnabled) {
+ //For some reason qt5 doesn't give us which button was released, From my testing i couldn't get a release event on rmb, so we assume that it's lmb
+ QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
+ auto clickedProperty = d->propForMousePos(index, mouseEvent->pos(), option);
+ if (!clickedProperty && mouseEvent->modifiers() == Qt::ControlModifier) {
+ changeSelectionAndCurrentIndex(index);
+ return true;
+ }
+
+ //We only need this event for ctrl clicks, so we just return here
+ return false;
+ }
+
if ((event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonDblClick)
&& (index.flags() & Qt::ItemIsEnabled))
{
@@ -1127,6 +1141,10 @@ bool NodeDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const Q
model->setData(index, true, KisNodeModel::AlternateActiveRole);
return true;
+ } else if (mouseEvent->modifiers() == Qt::ControlModifier) {
+ //Don't do anything here when ctrl is pressed but still pass through the event
+ //If we don't, the internal state of QTreeView WILL break
+ return false;
}
return false;
}
diff --git a/plugins/dockers/layerdocker/NodeView.cpp b/plugins/dockers/layerdocker/NodeView.cpp
index b3a6a889f2..6dc04ee015 100644
--- a/plugins/dockers/layerdocker/NodeView.cpp
+++ b/plugins/dockers/layerdocker/NodeView.cpp
@@ -33,6 +33,9 @@
#include "kis_node_view_color_scheme.h"
+#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
+#define QT6_SHIFT_SELECTION_WORKAROUND
+#endif
#ifdef HAVE_X11
#define DRAG_WHILE_DRAG_WORKAROUND
@@ -54,6 +57,9 @@ public:
: delegate(_q, _q)
#ifdef DRAG_WHILE_DRAG_WORKAROUND
, isDragging(false)
+#endif
+#ifdef QT6_SHIFT_SELECTION_WORKAROUND
+ , shiftClickFix(false)
#endif
{
}
@@ -64,6 +70,9 @@ public:
#ifdef DRAG_WHILE_DRAG_WORKAROUND
bool isDragging;
#endif
+#ifdef QT6_SHIFT_SELECTION_WORKAROUND
+ bool shiftClickFix;
+#endif
};
@@ -148,17 +157,37 @@ void NodeView::toggleSolo(const QModelIndex &index) {
d->delegate.toggleSolo(index);
}
-QItemSelectionModel::SelectionFlags NodeView::selectionCommand(const QModelIndex &index, const QEvent *event) const
-{
- //Block selection on press if ctrl is held
- //This is to allow for a more consistent behaviour with ctrl+dnd
- if (event &&
- event->type() == QEvent::MouseButtonPress ) {
- const QMouseEvent *mevent = static_cast<const QMouseEvent*>(event);
- if (mevent->modifiers() & Qt::ControlModifier)
- return QItemSelectionModel::NoUpdate;
+QItemSelectionModel::SelectionFlags NodeView::selectionCommand(const QModelIndex &index, const QEvent *event) const {
+ //When adding a layer with Shift or Ctrl is held, the selection will expand to add that new layer,
+ //So to avoid that we explicitly select the new layer.
+ if (!event && QApplication::keyboardModifiers() != Qt::NoModifier
+#ifdef QT6_SHIFT_SELECTION_WORKAROUND
+ && !d->shiftClickFix
+#endif
+ ) {
+#ifdef QT6_SHIFT_SELECTION_WORKAROUND
+ d->shiftClickFix = false;
+#endif
+ return QItemSelectionModel::ClearAndSelect;
}
+#ifdef QT6_SHIFT_SELECTION_WORKAROUND
+ //Clear this just in case
+ d->shiftClickFix = false;
+
+ //Qt6 has a bug/feature? where after you do a shift selection it sends a second selection event with the event argument being null
+ //This triggers the logic above, so we explicitly avoid the next null event
+ if (event &&
+ (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::KeyPress) &&
+ QApplication::keyboardModifiers() & Qt::ShiftModifier)
+ d->shiftClickFix = true;
+#endif
+
+ //We still get ctrl click events so we need to ignore those
+ if (event &&
+ event->type() == QEvent::MouseButtonPress && (static_cast<const QMouseEvent*>(event)->modifiers() & Qt::ControlModifier))
+ return QItemSelectionModel::NoUpdate;
+
return QTreeView::selectionCommand(index, event);
}
@@ -194,6 +223,16 @@ bool NodeView::viewportEvent(QEvent *e)
return true;
}
} break;
+ case QEvent::MouseButtonRelease: {
+ const QPoint pos = static_cast<QMouseEvent*>(e)->pos();
+ QModelIndex index = model()->buddy(indexAt(pos));
+ if (!indexAt(pos).isValid()) {
+ return QTreeView::viewportEvent(e);
+ }
+ if (d->delegate.editorEvent(e, model(), optionForIndex(index), index)) {
+ return true;
+ }
+ } break;
case QEvent::Leave: {
QEvent e(QEvent::Leave);
d->delegate.editorEvent(&e, model(), optionForIndex(d->hovered), d->hovered);