1
0
Эх сурвалжийг харах

Merge pull request #1814 from torresam/rename-autoselect

UI: Autoselect text on scene/source rename
Jim 6 жил өмнө
parent
commit
b5cc26a918

+ 1 - 0
UI/source-tree.cpp

@@ -259,6 +259,7 @@ void SourceTreeItem::EnterEditMode()
 	setFocusPolicy(Qt::StrongFocus);
 	boxLayout->removeWidget(label);
 	editor = new QLineEdit(label->text());
+	editor->selectAll();
 	editor->installEventFilter(this);
 	boxLayout->insertWidget(1, editor);
 	setFocusProxy(editor);

+ 16 - 0
UI/window-basic-main.cpp

@@ -258,6 +258,8 @@ OBSBasic::OBSBasic(QWidget *parent)
 	ui->scenes->setAttribute(Qt::WA_MacShowFocusRect, false);
 	ui->sources->setAttribute(Qt::WA_MacShowFocusRect, false);
 
+	ui->scenes->setItemDelegate(new SceneRenameDelegate(ui->scenes));
+
 	auto displayResize = [this]() {
 		struct obs_video_info ovi;
 
@@ -7192,3 +7194,17 @@ bool OBSBasic::ReplayBufferActive()
 		return false;
 	return outputHandler->ReplayBufferActive();
 }
+
+SceneRenameDelegate::SceneRenameDelegate(QObject *parent)
+	: QStyledItemDelegate(parent)
+{
+}
+
+void SceneRenameDelegate::setEditorData(QWidget *editor,
+		const QModelIndex &index) const
+{
+	QStyledItemDelegate::setEditorData(editor, index);
+	QLineEdit *lineEdit = qobject_cast<QLineEdit*>(editor);
+	if (lineEdit)
+		lineEdit->selectAll();
+}

+ 10 - 0
UI/window-basic-main.hpp

@@ -21,6 +21,7 @@
 #include <QAction>
 #include <QWidgetAction>
 #include <QSystemTrayIcon>
+#include <QStyledItemDelegate>
 #include <obs.hpp>
 #include <vector>
 #include <memory>
@@ -816,3 +817,12 @@ public:
 private:
 	std::unique_ptr<Ui::OBSBasic> ui;
 };
+
+class SceneRenameDelegate : public QStyledItemDelegate {
+	Q_OBJECT
+
+public:
+	SceneRenameDelegate(QObject *parent);
+	virtual void setEditorData(QWidget *editor, const QModelIndex &index)
+		const override;
+};