Skip to content

Commit 3bace4a

Browse files
committed
frontend: Improve spin box UX
1 parent 9a4632e commit 3bace4a

File tree

8 files changed

+315
-10
lines changed

8 files changed

+315
-10
lines changed

frontend/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ if(NOT TARGET OBS::bpm)
2626
add_subdirectory("${CMAKE_SOURCE_DIR}/shared/bpm" bpm)
2727
endif()
2828

29+
if(NOT TARGET OBS::qt-clamped-doublespinbox)
30+
add_subdirectory(
31+
"${CMAKE_SOURCE_DIR}/shared/qt/clamped-doublespinbox" clamped-doublespinbox)
32+
endif()
33+
2934
add_executable(obs-studio)
3035
add_executable(OBS::studio ALIAS obs-studio)
3136

@@ -40,6 +45,7 @@ target_link_libraries(
4045
OBS::frontend-api
4146
OBS::json11
4247
OBS::bpm
48+
OBS::qt-clamped-doublespinbox
4349
)
4450

4551
include(cmake/ui-components.cmake)

frontend/dialogs/OBSBasicTransform.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "OBSBasicTransform.hpp"
22

33
#include <widgets/OBSBasic.hpp>
4+
#include "ClampedDoubleSpinBox.hpp"
45

56
#include "moc_OBSBasicTransform.cpp"
67

frontend/forms/OBSBasicTransform.ui

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
<number>0</number>
8989
</property>
9090
<item>
91-
<widget class="QDoubleSpinBox" name="positionX">
91+
<widget class="ClampedDoubleSpinBox" name="positionX">
9292
<property name="minimumSize">
9393
<size>
9494
<width>120</width>
@@ -119,7 +119,7 @@
119119
</widget>
120120
</item>
121121
<item>
122-
<widget class="QDoubleSpinBox" name="positionY">
122+
<widget class="ClampedDoubleSpinBox" name="positionY">
123123
<property name="minimumSize">
124124
<size>
125125
<width>120</width>
@@ -163,7 +163,7 @@
163163
</widget>
164164
</item>
165165
<item row="1" column="1">
166-
<widget class="QDoubleSpinBox" name="rotation">
166+
<widget class="ClampedDoubleSpinBox" name="rotation">
167167
<property name="sizePolicy">
168168
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
169169
<horstretch>0</horstretch>
@@ -231,7 +231,7 @@
231231
<number>0</number>
232232
</property>
233233
<item>
234-
<widget class="QDoubleSpinBox" name="sizeX">
234+
<widget class="ClampedDoubleSpinBox" name="sizeX">
235235
<property name="minimumSize">
236236
<size>
237237
<width>120</width>
@@ -265,7 +265,7 @@
265265
</widget>
266266
</item>
267267
<item>
268-
<widget class="QDoubleSpinBox" name="sizeY">
268+
<widget class="ClampedDoubleSpinBox" name="sizeY">
269269
<property name="minimumSize">
270270
<size>
271271
<width>120</width>
@@ -531,7 +531,7 @@
531531
<number>0</number>
532532
</property>
533533
<item>
534-
<widget class="QDoubleSpinBox" name="boundsWidth">
534+
<widget class="ClampedDoubleSpinBox" name="boundsWidth">
535535
<property name="enabled">
536536
<bool>false</bool>
537537
</property>
@@ -565,7 +565,7 @@
565565
</widget>
566566
</item>
567567
<item>
568-
<widget class="QDoubleSpinBox" name="boundsHeight">
568+
<widget class="ClampedDoubleSpinBox" name="boundsHeight">
569569
<property name="enabled">
570570
<bool>false</bool>
571571
</property>
@@ -852,6 +852,13 @@
852852
</item>
853853
</layout>
854854
</widget>
855+
<customwidgets>
856+
<customwidget>
857+
<class>ClampedDoubleSpinBox</class>
858+
<extends>QDoubleSpinBox</extends>
859+
<header>ClampedDoubleSpinBox.hpp</header>
860+
</customwidget>
861+
</customwidgets>
855862
<resources/>
856863
<connections>
857864
<connection>

shared/properties-view/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ if(NOT TARGET OBS::qt-icon-label)
2828
add_subdirectory("${CMAKE_SOURCE_DIR}/shared/qt/icon-label" "${CMAKE_BINARY_DIR}/shared/qt/icon-label")
2929
endif()
3030

31+
if(NOT TARGET OBS::qt-clamped-doublespinbox)
32+
add_subdirectory(
33+
"${CMAKE_SOURCE_DIR}/shared/qt/clamped-doublespinbox"
34+
"${CMAKE_BINARY_DIR}/shared/qt/clamped-doublespinbox"
35+
)
36+
endif()
37+
3138
add_library(properties-view INTERFACE)
3239
add_library(OBS::properties-view ALIAS properties-view)
3340

@@ -51,6 +58,7 @@ target_link_libraries(
5158
OBS::libobs
5259
OBS::qt-wrappers
5360
OBS::qt-plain-text-edit
61+
OBS::qt-clamped-doublespinbox
5462
OBS::qt-vertical-scroll-area
5563
OBS::qt-slider-ignorewheel
5664
OBS::qt-icon-label

shared/properties-view/properties-view.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <QObject>
2626
#include <QDesktopServices>
2727
#include <QUuid>
28+
#include "ClampedDoubleSpinBox.hpp"
2829
#include "double-slider.hpp"
2930
#include "spinbox-ignorewheel.hpp"
3031
#include "moc_properties-view.cpp"
@@ -479,7 +480,7 @@ void OBSPropertiesView::AddFloat(obs_property_t *prop, QFormLayout *layout, QLab
479480

480481
const char *name = obs_property_name(prop);
481482
double val = obs_data_get_double(settings, name);
482-
QDoubleSpinBox *spin = new QDoubleSpinBox();
483+
ClampedDoubleSpinBox *spin = new ClampedDoubleSpinBox();
483484

484485
if (!obs_property_enabled(prop))
485486
spin->setEnabled(false);
@@ -512,8 +513,12 @@ void OBSPropertiesView::AddFloat(obs_property_t *prop, QFormLayout *layout, QLab
512513
slider->setOrientation(Qt::Horizontal);
513514
subLayout->addWidget(slider);
514515

515-
connect(slider, &DoubleSlider::doubleValChanged, spin, &QDoubleSpinBox::setValue);
516-
connect(spin, &QDoubleSpinBox::valueChanged, slider, &DoubleSlider::setDoubleVal);
516+
connect(slider, &DoubleSlider::doubleValChanged, spin, [spin](double value) { spin->setValue(value); });
517+
connect(spin, &QDoubleSpinBox::valueChanged, slider, [slider](double value) {
518+
bool wasBlocked = slider->blockSignals(true);
519+
slider->setDoubleVal(value);
520+
slider->blockSignals(wasBlocked);
521+
});
517522
}
518523

519524
connect(spin, &QDoubleSpinBox::valueChanged, info, &WidgetInfo::ControlChanged);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cmake_minimum_required(VERSION 3.28...3.30)
2+
3+
find_package(Qt6 REQUIRED Core Widgets)
4+
5+
add_library(qt-clamped-doublespinbox INTERFACE)
6+
add_library(OBS::qt-clamped-doublespinbox ALIAS qt-clamped-doublespinbox)
7+
8+
target_sources(qt-clamped-doublespinbox INTERFACE ClampedDoubleSpinBox.cpp ClampedDoubleSpinBox.hpp)
9+
target_include_directories(qt-clamped-doublespinbox INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}")
10+
11+
target_link_libraries(qt-clamped-doublespinbox INTERFACE Qt::Core Qt::Widgets)

0 commit comments

Comments
 (0)