Преглед на файлове

UI: Show a message in the empty source list

Colin Edwards преди 6 години
родител
ревизия
ff72e9efc3
променени са 6 файла, в които са добавени 91 реда и са изтрити 0 реда
  1. 1 0
      UI/data/locale/en-US.ini
  2. 11 0
      UI/data/themes/Dark/no_sources.svg
  3. 11 0
      UI/forms/images/no_sources.svg
  4. 1 0
      UI/forms/obs.qrc
  5. 58 0
      UI/source-tree.cpp
  6. 9 0
      UI/source-tree.hpp

+ 1 - 0
UI/data/locale/en-US.ini

@@ -903,6 +903,7 @@ FinalScene.Text="There needs to be at least one scene."
 NoSources.Title="No Sources"
 NoSources.Text="It looks like you haven't added any video sources yet, so you will only be outputting a blank screen. Are you sure you want to do this?"
 NoSources.Text.AddSource="You can add sources by clicking the + icon under the Sources box in the main window at any time."
+NoSources.Label="You don't have any sources.\nClick the + button below,\nor right click here to add one."
 
 # Scene item color selection
 ChangeBG="Set Color"

Файловите разлики са ограничени, защото са твърде много
+ 11 - 0
UI/data/themes/Dark/no_sources.svg


Файловите разлики са ограничени, защото са твърде много
+ 11 - 0
UI/forms/images/no_sources.svg


+ 1 - 0
UI/forms/obs.qrc

@@ -3,6 +3,7 @@
     <file>images/mute.png</file>
     <file>images/unmute.png</file>
     <file>images/refresh.png</file>
+    <file>images/no_sources.svg</file>
     <file>images/configuration21_16.png</file>
     <file>images/configuration21_16_2x.png</file>
     <file>images/invisible_mask.png</file>

+ 58 - 0
UI/source-tree.cpp

@@ -5,6 +5,7 @@
 #include "visibility-checkbox.hpp"
 #include "locked-checkbox.hpp"
 #include "expand-checkbox.hpp"
+#include "platform.hpp"
 
 #include <obs-frontend-api.h>
 #include <obs.h>
@@ -915,6 +916,10 @@ SourceTree::SourceTree(QWidget *parent_) : QListView(parent_)
 		"*[bgColor=\"8\"]{background-color:rgba(255,255,255,33%);}"));
 
 	setMouseTracking(true);
+
+	UpdateNoSourcesMessage();
+	connect(App(), &OBSApp::StyleChanged,
+			this, &SourceTree::UpdateNoSourcesMessage);
 }
 
 void SourceTree::ResetWidgets()
@@ -1429,3 +1434,56 @@ void SourceTree::AddGroup()
 {
 	GetStm()->AddGroup();
 }
+
+void SourceTree::UpdateNoSourcesMessage()
+{
+	std::string darkPath;
+	GetDataFilePath("themes/Dark/no_sources.svg", darkPath);
+
+	QColor color = palette().text().color();
+	bool lightTheme = (color.redF() < 0.5);
+	QString file = lightTheme
+		? ":res/images/no_sources.svg"
+		: darkPath.c_str();
+	iconNoSources.load(file);
+
+	QTextOption opt(Qt::AlignHCenter);
+	opt.setWrapMode(QTextOption::WordWrap);
+	textNoSources.setTextOption(opt);
+	textNoSources.setText(QTStr("NoSources.Label").replace("\n", "<br/>"));
+
+	textPrepared = false;
+}
+
+void SourceTree::paintEvent(QPaintEvent *event)
+{
+	SourceTreeModel *stm = GetStm();
+	if (stm && !stm->items.count()) {
+		QPainter p(viewport());
+
+		if (!textPrepared) {
+			textNoSources.prepare(QTransform(), p.font());
+			textPrepared = true;
+		}
+
+		QRectF iconRect = iconNoSources.viewBoxF();
+
+		QSizeF iconSize = iconRect.size();
+		QSizeF textSize = textNoSources.size();
+		QSizeF thisSize = size();
+
+		qreal totalHeight = textSize.height() + iconSize.height();
+
+		qreal x = thisSize.width() / 2.0 - textSize.width() / 2.0;
+		qreal y = thisSize.height() / 2.0 - totalHeight / 2.0;
+		p.drawStaticText(x, y, textNoSources);
+
+		x = thisSize.width() / 2.0 - iconSize.width() / 2.0;
+		y += textSize.height();
+		iconRect.moveTo(x, y);
+
+		iconNoSources.render(&p, iconRect);
+	} else {
+		QListView::paintEvent(event);
+	}
+}

+ 9 - 0
UI/source-tree.hpp

@@ -5,6 +5,8 @@
 #include <QPointer>
 #include <QListView>
 #include <QCheckBox>
+#include <QStaticText>
+#include <QSvgRenderer>
 #include <QAbstractListModel>
 
 class QLabel;
@@ -133,6 +135,12 @@ class SourceTree : public QListView {
 	friend class SourceTreeModel;
 	friend class SourceTreeItem;
 
+	bool textPrepared = false;
+	QStaticText textNoSources;
+	QSvgRenderer iconNoSources;
+
+	void UpdateNoSourcesMessage();
+
 	void ResetWidgets();
 	void UpdateWidget(const QModelIndex &idx, obs_sceneitem_t *item);
 	void UpdateWidgets(bool force = false);
@@ -177,6 +185,7 @@ protected:
 	virtual void dropEvent(QDropEvent *event) override;
 	virtual void mouseMoveEvent(QMouseEvent *event) override;
 	virtual void leaveEvent(QEvent *event) override;
+	virtual void paintEvent(QPaintEvent *event) override;
 
 	virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override;
 };

Някои файлове не бяха показани, защото твърде много файлове са промени