From de84b7708ed1b24bc33015373996790b6f3275c1 Mon Sep 17 00:00:00 2001 From: cg2121 Date: Fri, 2 Feb 2024 13:01:01 -0600 Subject: [PATCH] Use newest scene tree from main OBS --- src/scene-tree.cpp | 34 ++++++++++++++-------------------- src/scene-tree.hpp | 2 ++ 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/scene-tree.cpp b/src/scene-tree.cpp index 6b4f34d..f5386e1 100644 --- a/src/scene-tree.cpp +++ b/src/scene-tree.cpp @@ -1,4 +1,3 @@ -#include "obs.hpp" #include "scene-tree.hpp" #include @@ -6,6 +5,7 @@ #include #include #include +#include SceneTree::SceneTree(QWidget *parent_) : QListWidget(parent_) { @@ -79,7 +79,7 @@ void SceneTree::resizeEvent(QResizeEvent *event) } int wid = contentsRect().width() - scrollWid - 1; - int items = (int)ceil((float)wid / maxWidth); + int items = (int)std::ceil((float)wid / maxWidth); int itemWidth = wid / items; setGridSize(QSize(itemWidth, itemHeight)); @@ -89,7 +89,6 @@ void SceneTree::resizeEvent(QResizeEvent *event) } } else { setGridSize(QSize()); - setSpacing(1); for (int i = 0; i < count(); i++) { item(i)->setData(Qt::SizeHintRole, QVariant()); } @@ -126,16 +125,12 @@ void SceneTree::dropEvent(QDropEvent *event) float wid = contentsRect().width() - scrollWid - 1; -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) QPoint point = event->position().toPoint(); -#else - QPoint point = event->pos(); -#endif - int x = (float)point.x() / wid * ceil(wid / maxWidth); + int x = (float)point.x() / wid * std::ceil(wid / maxWidth); int y = (point.y() + firstItemY) / itemHeight; - int r = x + y * ceil(wid / maxWidth); + int r = x + y * std::ceil(wid / maxWidth); QListWidgetItem *item = takeItem(selectedIndexes()[0].row()); insertItem(r, item); @@ -171,16 +166,12 @@ void SceneTree::RepositionGrid(QDragMoveEvent *event) float wid = contentsRect().width() - scrollWid - 1; if (event) { -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) QPoint point = event->position().toPoint(); -#else - QPoint point = event->pos(); -#endif - int x = (float)point.x() / wid * ceil(wid / maxWidth); + int x = (float)point.x() / wid * std::ceil(wid / maxWidth); int y = (point.y() + firstItemY) / itemHeight; - int r = x + y * ceil(wid / maxWidth); + int r = x + y * std::ceil(wid / maxWidth); int orig = selectedIndexes()[0].row(); for (int i = 0; i < count(); i++) { @@ -195,8 +186,8 @@ void SceneTree::RepositionGrid(QDragMoveEvent *event) (i > orig && i > r ? 1 : 0) - (i > orig && i == r ? 2 : 0); - int xPos = (i + off) % (int)ceil(wid / maxWidth); - int yPos = (i + off) / (int)ceil(wid / maxWidth); + int xPos = (i + off) % (int)std::ceil(wid / maxWidth); + int yPos = (i + off) / (int)std::ceil(wid / maxWidth); QSize g = gridSize(); QPoint position(xPos * g.width(), yPos * g.height()); @@ -211,8 +202,8 @@ void SceneTree::RepositionGrid(QDragMoveEvent *event) QModelIndex index = indexFromItem(wItem); - int xPos = i % (int)ceil(wid / maxWidth); - int yPos = i / (int)ceil(wid / maxWidth); + int xPos = i % (int)std::ceil(wid / maxWidth); + int yPos = i / (int)std::ceil(wid / maxWidth); QSize g = gridSize(); QPoint position(xPos * g.width(), yPos * g.height()); @@ -247,10 +238,13 @@ void SceneTree::rowsInserted(const QModelIndex &parent, int start, int end) QListWidget::rowsInserted(parent, start, end); } +#if QT_VERSION < QT_VERSION_CHECK(6, 4, 3) // Workaround for QTBUG-105870. Remove once that is solved upstream. void SceneTree::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) { - if (selected.count() == 0 && deselected.count() > 0) + if (selected.count() == 0 && deselected.count() > 0 && + !property("clearing").toBool()) setCurrentRow(deselected.indexes().front().row()); } +#endif diff --git a/src/scene-tree.hpp b/src/scene-tree.hpp index b80918f..0950f12 100644 --- a/src/scene-tree.hpp +++ b/src/scene-tree.hpp @@ -38,9 +38,11 @@ class SceneTree : public QListWidget { virtual void dragLeaveEvent(QDragLeaveEvent *event) override; virtual void rowsInserted(const QModelIndex &parent, int start, int end) override; +#if QT_VERSION < QT_VERSION_CHECK(6, 4, 3) virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override; +#endif signals: void scenesReordered();