浏览代码

UI: Allow drag & drop reorder of property lists

Clayton Groeneveld 5 年之前
父节点
当前提交
29b2f11e7a
共有 2 个文件被更改,包括 22 次插入0 次删除
  1. 20 0
      UI/properties-view.cpp
  2. 2 0
      UI/properties-view.hpp

+ 20 - 0
UI/properties-view.cpp

@@ -594,6 +594,13 @@ void OBSPropertiesView::AddEditableList(obs_property_t *prop,
 
 	WidgetInfo *info = new WidgetInfo(this, prop, list);
 
+	list->setDragDropMode(QAbstractItemView::InternalMove);
+	connect(list->model(),
+		SIGNAL(rowsMoved(QModelIndex, int, int, QModelIndex, int)),
+		info,
+		SLOT(EditListReordered(const QModelIndex &, int, int,
+				       const QModelIndex &, int)));
+
 	QVBoxLayout *sideLayout = new QVBoxLayout();
 	NewButton(sideLayout, info, "addIconSmall", &WidgetInfo::EditListAdd);
 	NewButton(sideLayout, info, "removeIconSmall",
@@ -1774,6 +1781,19 @@ void WidgetInfo::GroupChanged(const char *setting)
 						  : true);
 }
 
+void WidgetInfo::EditListReordered(const QModelIndex &parent, int start,
+				   int end, const QModelIndex &destination,
+				   int row)
+{
+	UNUSED_PARAMETER(parent);
+	UNUSED_PARAMETER(start);
+	UNUSED_PARAMETER(end);
+	UNUSED_PARAMETER(destination);
+	UNUSED_PARAMETER(row);
+
+	EditableListChanged();
+}
+
 void WidgetInfo::EditableListChanged()
 {
 	const char *setting = obs_property_name(property);

+ 2 - 0
UI/properties-view.hpp

@@ -58,6 +58,8 @@ public slots:
 	void EditListEdit();
 	void EditListUp();
 	void EditListDown();
+	void EditListReordered(const QModelIndex &parent, int start, int end,
+			       const QModelIndex &destination, int row);
 };
 
 /* ------------------------------------------------------------------------- */