Skip to content

Commit

Permalink
Use newest scene tree from main OBS
Browse files Browse the repository at this point in the history
  • Loading branch information
cg2121 committed Feb 2, 2024
1 parent f7c69ba commit de84b77
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
34 changes: 14 additions & 20 deletions src/scene-tree.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "obs.hpp"
#include "scene-tree.hpp"

#include <QSizePolicy>
#include <QScrollBar>
#include <QDropEvent>
#include <QPushButton>
#include <QTimer>
#include <cmath>

SceneTree::SceneTree(QWidget *parent_) : QListWidget(parent_)
{
Expand Down Expand Up @@ -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));
Expand All @@ -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());
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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++) {
Expand All @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/scene-tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit de84b77

Please sign in to comment.