You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ovdCIntegerSettingView.cpp 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "ovdCIntegerSettingView.h"
  2. #include "../ovd_base.h"
  3. namespace OpenViBE {
  4. namespace Designer {
  5. namespace Setting {
  6. static void OnButtonSettingIntegerUpPressed(GtkButton* /*button*/, gpointer data) { static_cast<CIntegerSettingView*>(data)->adjustValue(1); }
  7. static void OnButtonSettingIntegerDownPressed(GtkButton* /*button*/, gpointer data) { static_cast<CIntegerSettingView*>(data)->adjustValue(-1); }
  8. static void OnInsertion(GtkEntry* /*entry*/, gpointer data) { static_cast<CIntegerSettingView*>(data)->onChange(); }
  9. CIntegerSettingView::CIntegerSettingView(Kernel::IBox& box, const size_t index, CString& builderName, const Kernel::IKernelContext& ctx)
  10. : CAbstractSettingView(box, index, builderName, "settings_collection-hbox_setting_integer"), m_kernelCtx(ctx)
  11. {
  12. GtkWidget* settingWidget = CAbstractSettingView::getEntryFieldWidget();
  13. std::vector<GtkWidget*> widgets;
  14. CAbstractSettingView::extractWidget(settingWidget, widgets);
  15. m_entry = GTK_ENTRY(widgets[0]);
  16. g_signal_connect(G_OBJECT(m_entry), "changed", G_CALLBACK(OnInsertion), this);
  17. g_signal_connect(G_OBJECT(widgets[1]), "clicked", G_CALLBACK(OnButtonSettingIntegerUpPressed), this);
  18. g_signal_connect(G_OBJECT(widgets[2]), "clicked", G_CALLBACK(OnButtonSettingIntegerDownPressed), this);
  19. CAbstractSettingView::initializeValue();
  20. }
  21. void CIntegerSettingView::getValue(CString& value) const { value = CString(gtk_entry_get_text(m_entry)); }
  22. void CIntegerSettingView::setValue(const CString& value)
  23. {
  24. m_onValueSetting = true;
  25. gtk_entry_set_text(m_entry, value);
  26. m_onValueSetting = false;
  27. }
  28. void CIntegerSettingView::adjustValue(const int amount)
  29. {
  30. const int64_t value = m_kernelCtx.getConfigurationManager().expandAsInteger(gtk_entry_get_text(m_entry), 0) + amount;
  31. const std::string res = std::to_string(value);
  32. getBox().setSettingValue(getSettingIndex(), res.c_str());
  33. setValue(res.c_str());
  34. }
  35. void CIntegerSettingView::onChange()
  36. {
  37. if (!m_onValueSetting)
  38. {
  39. const gchar* value = gtk_entry_get_text(m_entry);
  40. getBox().setSettingValue(getSettingIndex(), value);
  41. }
  42. }
  43. } // namespace Setting
  44. } // namespace Designer
  45. } // namespace OpenViBE