Skip to content

Commit

Permalink
Allow special or default values in Spinboxes outside their normal ran…
Browse files Browse the repository at this point in the history
…ge and display an optional label. Fixes #10393

Signed-off-by: Stuart Morgan <smorgan@mythtv.org>
  • Loading branch information
xavierh authored and stuartm committed Oct 8, 2012
1 parent 9d5aabc commit a1a6877
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
35 changes: 35 additions & 0 deletions mythtv/libs/libmythui/mythuispinbox.cpp
Expand Up @@ -83,6 +83,41 @@ void MythUISpinBox::SetRange(int low, int high, int step, uint pageMultiple)
CalculateArrowStates();
}


/**
* \brief Add a special label for a value of the spinbox, it does not need to be in the range
*
* \param label The text displayed
* \param value The value associated to this label
*/
void MythUISpinBox::AddSelection(int value, const QString &label)
{
MythUIButtonListItem *item;
if (!label.isEmpty())
{
item = GetItemByData(value);
if (item)
item->SetText(label);
return;
}

int insertPos=-1;

for (int pos = 0; pos < m_itemList.size(); pos++)
{
item = m_itemList.at(pos);
if (item->GetData().toInt() > value)
{
insertPos = pos;
break;
}
}

item = new MythUIButtonListItem(this,
label.isEmpty() ? QString(value) : label,
qVariantFromValue(value), insertPos);
}

/**
* \copydoc MythUIType::ParseElement()
*/
Expand Down
1 change: 1 addition & 0 deletions mythtv/libs/libmythui/mythuispinbox.h
Expand Up @@ -24,6 +24,7 @@ class MUI_PUBLIC MythUISpinBox : public MythUIButtonList

void SetValue(int val) { SetValueByData(val); }
void SetValue(const QString &val) { SetValueByData(val.toInt()); }
void AddSelection (int value, const QString &label = "");
QString GetValue(void) const { return GetDataValue().toString(); }
int GetIntValue(void) const { return GetDataValue().toInt(); }

Expand Down

0 comments on commit a1a6877

Please sign in to comment.