[settings] Add group title support
authorAlwinEsch <alwin.esch@web.de>
Fri, 3 Apr 2015 09:33:17 +0000 (11:33 +0200)
committerAlwinEsch <alwin.esch@web.de>
Mon, 6 Apr 2015 13:33:29 +0000 (15:33 +0200)
xbmc/settings/SettingControl.cpp
xbmc/settings/SettingControl.h
xbmc/settings/Settings.cpp
xbmc/settings/dialogs/GUIDialogSettingsBase.cpp
xbmc/settings/dialogs/GUIDialogSettingsBase.h
xbmc/settings/windows/GUIControlSettings.cpp
xbmc/settings/windows/GUIControlSettings.h

index ba4db06..fc25556 100644 (file)
@@ -47,6 +47,8 @@ ISettingControl* CSettingControlCreator::CreateControl(const std::string &contro
     return new CSettingControlSlider();
   else if (StringUtils::EqualsNoCase(controlType, "range"))
     return new CSettingControlRange();
+  else if (StringUtils::EqualsNoCase(controlType, "title"))
+    return new CSettingControlTitle();
 
   return NULL;
 }
@@ -319,3 +321,21 @@ bool CSettingControlRange::SetFormat(const std::string &format)
 
   return true;
 }
+
+bool CSettingControlTitle::Deserialize(const TiXmlNode *node, bool update /* = false */)
+{
+  if (!ISettingControl::Deserialize(node, update))
+    return false;
+
+  std::string strTmp;
+  if (XMLUtils::GetString(node, SETTING_XML_ATTR_SEPARATOR_POSITION, strTmp))
+  {
+    if (!StringUtils::EqualsNoCase(strTmp, "top") && !StringUtils::EqualsNoCase(strTmp, "bottom"))
+      CLog::Log(LOGWARNING, "CSettingControlTitle: error reading \"value\" attribute of <%s>", SETTING_XML_ATTR_SEPARATOR_POSITION);
+    else
+      m_separatorBelowLabel = StringUtils::EqualsNoCase(strTmp, "bottom");
+  }
+  XMLUtils::GetBoolean(node, SETTING_XML_ATTR_HIDE_SEPARATOR, m_separatorHidden);
+
+  return true;
+}
index a763a58..f1f0491 100644 (file)
@@ -32,6 +32,8 @@
 #define SETTING_XML_ELM_CONTROL_FORMATVALUE  "value"
 #define SETTING_XML_ATTR_SHOW_MORE           "more"
 #define SETTING_XML_ATTR_SHOW_DETAILS        "details"
+#define SETTING_XML_ATTR_SEPARATOR_POSITION  "separatorposition"
+#define SETTING_XML_ATTR_HIDE_SEPARATOR      "hideseparator"
 
 class CVariant;
 
@@ -254,3 +256,27 @@ protected:
   int m_valueFormatLabel;
   std::string m_valueFormat;
 };
+
+class CSettingControlTitle : public ISettingControl
+{
+public:
+  CSettingControlTitle()
+    : m_separatorHidden(false),
+      m_separatorBelowLabel(true)
+  { }
+  virtual ~CSettingControlTitle() { }
+
+  // implementation of ISettingControl
+  virtual std::string GetType() const { return "title"; }
+  virtual bool Deserialize(const TiXmlNode *node, bool update = false);
+  virtual bool SetFormat(const std::string &format) { return true; }
+
+  bool IsSeparatorHidden() const { return m_separatorHidden; }
+  void SetSeparatorHidden(bool hidden) { m_separatorHidden = hidden; }
+  bool IsSeparatorBelowLabel() const { return m_separatorBelowLabel; }
+  void SetSeparatorBelowLabel(bool below) { m_separatorBelowLabel = below; }
+
+protected:
+  bool m_separatorHidden;
+  bool m_separatorBelowLabel;
+};
index a81fa93..39e974f 100644 (file)
@@ -505,6 +505,7 @@ void CSettings::InitializeControls()
   m_settingsManager->RegisterSettingControl("list", this);
   m_settingsManager->RegisterSettingControl("slider", this);
   m_settingsManager->RegisterSettingControl("range", this);
+  m_settingsManager->RegisterSettingControl("title", this);
 }
 
 void CSettings::InitializeVisibility()
index 588ad4d..0a3a152 100644 (file)
@@ -26,6 +26,7 @@
 #include "guilib/GUIControlGroupList.h"
 #include "guilib/GUIEditControl.h"
 #include "guilib/GUIImage.h"
+#include "guilib/GUILabelControl.h"
 #include "guilib/GUIRadioButtonControl.h"
 #include "guilib/GUISettingsSliderControl.h"
 #include "guilib/GUISpinControlEx.h"
@@ -56,6 +57,7 @@ using namespace std;
 #define CONTROL_DEFAULT_SEPARATOR       11
 #define CONTROL_DEFAULT_EDIT            12
 #define CONTROL_DEFAULT_SLIDER          13
+#define CONTROL_DEFAULT_SETTING_LABEL   14
 
 CGUIDialogSettingsBase::CGUIDialogSettingsBase(int windowId, const std::string &xmlFile)
     : CGUIDialog(windowId, xmlFile),
@@ -69,6 +71,7 @@ CGUIDialogSettingsBase::CGUIDialogSettingsBase(int windowId, const std::string &
       m_pOriginalButton(NULL),
       m_pOriginalEdit(NULL),
       m_pOriginalImage(NULL),
+      m_pOriginalGroupTitle(NULL),
       m_newOriginalEdit(false),
       m_delayedTimer(this),
       m_confirmed(false)
@@ -351,6 +354,7 @@ void CGUIDialogSettingsBase::SetupControls(bool createSettings /* = true */)
   m_pOriginalButton = dynamic_cast<CGUIButtonControl *>(GetControl(CONTROL_DEFAULT_BUTTON));
   m_pOriginalImage = dynamic_cast<CGUIImage *>(GetControl(CONTROL_DEFAULT_SEPARATOR));
   m_pOriginalEdit = dynamic_cast<CGUIEditControl *>(GetControl(CONTROL_DEFAULT_EDIT));
+  m_pOriginalGroupTitle = dynamic_cast<CGUILabelControl *>(GetControl(CONTROL_DEFAULT_SETTING_LABEL));
 
   if (!m_pOriginalEdit && m_pOriginalButton)
   {
@@ -365,6 +369,7 @@ void CGUIDialogSettingsBase::SetupControls(bool createSettings /* = true */)
   if (m_pOriginalCategoryButton) m_pOriginalCategoryButton->SetVisible(false);
   if (m_pOriginalEdit) m_pOriginalEdit->SetVisible(false);
   if (m_pOriginalImage) m_pOriginalImage->SetVisible(false);
+  if (m_pOriginalGroupTitle) m_pOriginalGroupTitle->SetVisible(false);
 
   if (m_pOriginalCategoryButton != NULL)
   {
@@ -513,9 +518,18 @@ std::set<std::string> CGUIDialogSettingsBase::CreateSettings()
     if (settings.size() <= 0)
       continue;
 
+    const CSettingControlTitle *title = dynamic_cast<CSettingControlTitle *>((*groupIt)->GetControl());
+    bool hideSeparator = title ? title->IsSeparatorHidden() : false;
+    bool separatorBelowGroupLabel = title ? title->IsSeparatorBelowLabel() : false;
     if (first)
       first = false;
-    else
+    else if (!separatorBelowGroupLabel && !hideSeparator)
+      AddSeparator(group->GetWidth(), iControlID);
+
+    if ((*groupIt)->GetLabel() > 0)
+      AddLabel(group->GetWidth(), iControlID, (*groupIt)->GetLabel());
+
+    if (separatorBelowGroupLabel && !hideSeparator)
       AddSeparator(group->GetWidth(), iControlID);
 
     for (SettingList::const_iterator settingIt = settings.begin(); settingIt != settings.end(); ++settingIt)
@@ -685,6 +699,20 @@ CGUIControl* CGUIDialogSettingsBase::AddSeparator(float width, int &iControlID)
   return AddSettingControl(pControl, BaseSettingControlPtr(new CGUIControlSeparatorSetting((CGUIImage *)pControl, iControlID)), width, iControlID);
 }
 
+CGUIControl* CGUIDialogSettingsBase::AddLabel(float width, int &iControlID, int label)
+{
+  if (m_pOriginalGroupTitle == NULL)
+    return NULL;
+
+  CGUIControl *pControl = new CGUILabelControl(*m_pOriginalGroupTitle);
+  if (pControl == NULL)
+    return NULL;
+
+  ((CGUILabelControl *)pControl)->SetLabel(GetLocalizedString(label));
+
+  return AddSettingControl(pControl, BaseSettingControlPtr(new CGUIControlGroupTitleSetting((CGUILabelControl *)pControl, iControlID)), width, iControlID);
+}
+
 CGUIControl* CGUIDialogSettingsBase::AddSettingControl(CGUIControl *pControl, BaseSettingControlPtr pSettingControl, float width, int &iControlID)
 {
   if (pControl == NULL)
index d7f3961..c3e37c2 100644 (file)
@@ -49,6 +49,7 @@ class CGUIEditControl;
 class CGUIButtonControl;
 class CGUIRadioButtonControl;
 class CGUISettingsSliderControl;
+class CGUILabelControl;
 
 class CSetting;
 class CSettingAction;
@@ -148,6 +149,7 @@ protected:
   BaseSettingControlPtr GetSettingControl(int controlId);
   
   CGUIControl* AddSeparator(float width, int &iControlID);
+  CGUIControl* AddLabel(float width, int &iControlID, int label);
 
   std::vector<CSettingCategory*> m_categories;
   std::vector<BaseSettingControlPtr> m_settingControls;
@@ -164,6 +166,7 @@ protected:
   CGUIButtonControl *m_pOriginalButton;
   CGUIEditControl *m_pOriginalEdit;
   CGUIImage *m_pOriginalImage;
+  CGUILabelControl *m_pOriginalGroupTitle;
   bool m_newOriginalEdit;
   
   BaseSettingControlPtr m_delayedSetting; ///< Current delayed setting \sa CBaseSettingControl::SetDelayed()
index bbe856c..8ceda71 100644 (file)
@@ -31,6 +31,7 @@
 #include "dialogs/GUIDialogSlider.h"
 #include "guilib/GUIEditControl.h"
 #include "guilib/GUIImage.h"
+#include "guilib/GUILabelControl.h"
 #include "guilib/GUIRadioButtonControl.h"
 #include "guilib/GUISettingsSliderControl.h"
 #include "guilib/GUISpinControlEx.h"
@@ -1145,3 +1146,16 @@ CGUIControlSeparatorSetting::CGUIControlSeparatorSetting(CGUIImage *pImage, int
 
 CGUIControlSeparatorSetting::~CGUIControlSeparatorSetting()
 { }
+
+CGUIControlGroupTitleSetting::CGUIControlGroupTitleSetting(CGUILabelControl *pLabel, int id)
+  : CGUIControlBaseSetting(id, NULL)
+{
+  m_pLabel = pLabel;
+  if (m_pLabel == NULL)
+    return;
+
+  m_pLabel->SetID(id);
+}
+
+CGUIControlGroupTitleSetting::~CGUIControlGroupTitleSetting()
+{ }
index 78b332b..1355bf0 100644 (file)
@@ -30,6 +30,7 @@ class CGUIEditControl;
 class CGUIButtonControl;
 class CGUIRadioButtonControl;
 class CGUISettingsSliderControl;
+class CGUILabelControl;
 
 class CSetting;
 class CSettingControlSlider;
@@ -224,3 +225,17 @@ public:
 private:
   CGUIImage *m_pImage;
 };
+
+class CGUIControlGroupTitleSetting : public CGUIControlBaseSetting
+{
+public:
+  CGUIControlGroupTitleSetting(CGUILabelControl* pLabel, int id);
+  virtual ~CGUIControlGroupTitleSetting();
+
+  virtual CGUIControl* GetControl() { return (CGUIControl*)m_pLabel; }
+  virtual bool OnClick() { return false; }
+  virtual void Update() {}
+  virtual void Clear() { m_pLabel = NULL; }
+private:
+  CGUILabelControl *m_pLabel;
+};