From d1b8c27fd3fff14ef85913b601c160b5c435bdff Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 27 Jun 2013 17:25:50 +0300 Subject: [PATCH] Unify the behavior of value change signals All widgets with such signals now emit them if the value is changed programmatically, but only if it actually changed. --- source/list.cpp | 2 +- source/toggle.cpp | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/source/list.cpp b/source/list.cpp index b969ec0..296709c 100644 --- a/source/list.cpp +++ b/source/list.cpp @@ -117,7 +117,7 @@ void List::set_selected_index(int i) items[sel_index]->set_active(false); if(i<0) sel_index = -1; - else + else if(i!=sel_index) { sel_index = i; items[sel_index]->set_active(true); diff --git a/source/toggle.cpp b/source/toggle.cpp index fe6518d..cb80880 100644 --- a/source/toggle.cpp +++ b/source/toggle.cpp @@ -48,6 +48,8 @@ void Toggle::exclude_siblings() void Toggle::set_value(bool v) { + bool old_value = value; + value = v; if(value) { @@ -57,6 +59,9 @@ void Toggle::set_value(bool v) } else clear_state(ACTIVE); + + if(value!=old_value) + signal_toggled.emit(value); } void Toggle::rebuild_special(const Part &part) @@ -76,10 +81,7 @@ void Toggle::button_release(int x, int y, unsigned btn) if(pressed && btn==1) { if(geom.is_inside_relative(x, y) && (!value || !exclusive)) - { set_value(!value); - signal_toggled.emit(value); - } pressed = false; } -- 2.45.2