Browse Source

UI: Add SourceListWidget - QListWidget subclass

The default behavior of QListWidget is to allow double clicks of any
mouse button, but in certain situations/usage cases this can cause
undesirable results.  As an example: when double-clicking with the right
mouse button on an item in the sources list box, it will open up both
the properties window and the context menu.  Not pretty at all.

This subclass filters out double clicks for any mouse button other than
the left mouse button to fix this issue.
HomeWorld 10 years ago
parent
commit
88333b0f47
3 changed files with 27 additions and 0 deletions
  1. 2 0
      obs/CMakeLists.txt
  2. 8 0
      obs/source-list-widget.cpp
  3. 17 0
      obs/source-list-widget.hpp

+ 2 - 0
obs/CMakeLists.txt

@@ -106,6 +106,7 @@ set(obs_SOURCES
 	volume-control.cpp
 	adv-audio-control.cpp
 	vertical-scroll-area.cpp
+	source-list-widget.cpp
 	crash-report.cpp
 	qt-wrappers.cpp)
 
@@ -131,6 +132,7 @@ set(obs_HEADERS
 	volume-control.hpp
 	adv-audio-control.hpp
 	vertical-scroll-area.hpp
+	source-list-widget.hpp
 	qt-display.hpp
 	crash-report.hpp
 	qt-wrappers.hpp)

+ 8 - 0
obs/source-list-widget.cpp

@@ -0,0 +1,8 @@
+#include <QMouseEvent>
+#include "source-list-widget.hpp"
+
+void SourceListWidget::mouseDoubleClickEvent(QMouseEvent *event)
+{
+	if (event->button() == Qt::LeftButton)
+		QListWidget::mouseDoubleClickEvent(event);
+}

+ 17 - 0
obs/source-list-widget.hpp

@@ -0,0 +1,17 @@
+#pragma once
+
+#include <QListWidget>
+
+class QMouseEvent;
+
+class SourceListWidget : public QListWidget {
+	Q_OBJECT
+public:
+	inline SourceListWidget(QWidget *parent = nullptr)
+		: QListWidget(parent)
+	{
+	}
+
+protected:
+	virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
+};