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

UI: Fix alignment of status bar message

The status bar message was not vertically aligned properly to
other widgets in the status bar. We have to implement our own
message system here, as the default status bar in Qt has hardcoded
paddings.
cg2121 2 жил өмнө
parent
commit
b19f922747

+ 42 - 9
UI/forms/StatusBarWidget.ui

@@ -36,17 +36,50 @@
     <number>0</number>
    </property>
    <item>
-    <spacer name="horizontalSpacer_11">
-     <property name="orientation">
-      <enum>Qt::Horizontal</enum>
+    <widget class="QFrame" name="messageFrame">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
      </property>
-     <property name="sizeHint" stdset="0">
-      <size>
-       <width>2</width>
-       <height>2</height>
-      </size>
+     <property name="styleSheet">
+      <string notr="true">border: none;</string>
      </property>
-    </spacer>
+     <property name="frameShape">
+      <enum>QFrame::NoFrame</enum>
+     </property>
+     <property name="frameShadow">
+      <enum>QFrame::Plain</enum>
+     </property>
+     <layout class="QHBoxLayout" name="horizontalLayout_9">
+      <property name="leftMargin">
+       <number>0</number>
+      </property>
+      <property name="topMargin">
+       <number>0</number>
+      </property>
+      <property name="rightMargin">
+       <number>0</number>
+      </property>
+      <property name="bottomMargin">
+       <number>0</number>
+      </property>
+      <item>
+       <widget class="QLabel" name="message">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Ignored" vsizetype="Maximum">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="text">
+         <string>Message</string>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
    </item>
    <item>
     <widget class="QFrame" name="delayFrame">

+ 23 - 1
UI/window-basic-status-bar.cpp

@@ -55,12 +55,19 @@ OBSBasicStatusBar::OBSBasicStatusBar(QWidget *parent)
 	statusWidget->ui->issuesFrame->hide();
 	statusWidget->ui->kbps->hide();
 
-	addPermanentWidget(statusWidget);
+	addPermanentWidget(statusWidget, 1);
 	setMinimumHeight(statusWidget->height());
 
 	UpdateIcons();
 	connect(App(), &OBSApp::StyleChanged, this,
 		&OBSBasicStatusBar::UpdateIcons);
+
+	messageTimer = new QTimer(this);
+	messageTimer->setSingleShot(true);
+	connect(messageTimer, &QTimer::timeout, this,
+		&OBSBasicStatusBar::clearMessage);
+
+	clearMessage();
 }
 
 void OBSBasicStatusBar::Activate()
@@ -606,3 +613,18 @@ void OBSBasicStatusBar::UpdateIcons()
 		statusWidget->ui->recordIcon->setPixmap(
 			recordingInactivePixmap);
 }
+
+void OBSBasicStatusBar::showMessage(const QString &message, int timeout)
+{
+	messageTimer->stop();
+
+	statusWidget->ui->message->setText(message);
+
+	if (timeout)
+		messageTimer->start(timeout);
+}
+
+void OBSBasicStatusBar::clearMessage()
+{
+	statusWidget->ui->message->setText("");
+}

+ 4 - 0
UI/window-basic-status-bar.hpp

@@ -72,6 +72,7 @@ private:
 	float lastCongestion = 0.0f;
 
 	QPointer<QTimer> refreshTimer;
+	QPointer<QTimer> messageTimer;
 
 	obs_output_t *GetOutput();
 
@@ -90,6 +91,9 @@ private:
 public slots:
 	void UpdateCPUUsage();
 
+	void clearMessage();
+	void showMessage(const QString &message, int timeout = 0);
+
 private slots:
 	void Reconnect(int seconds);
 	void ReconnectSuccess();