Permalink
Browse files

Fix bug in buttontree which required right to be pressed twice to mov…

…e deeper into the tree. This occurred because the widget assumed it was browsing from the root node but this was not always the case.
  • Loading branch information...
1 parent 31b500f commit 2aeb87267987b876ea5c4b40a5a26db058e1e1f1 @stuartm stuartm committed Jan 25, 2011
Showing with 25 additions and 21 deletions.
  1. +24 −21 mythtv/libs/libmythui/mythuibuttontree.cpp
  2. +1 −0 mythtv/libs/libmythui/mythuibuttontree.h
@@ -18,9 +18,7 @@ MythUIButtonTree::MythUIButtonTree(MythUIType *parent, const QString &name)
m_numLists = 1;
m_visibleLists = 0;
- // Depth starts at one, not zero because we count from the root node which
- // is never displayed itself
- m_currentDepth = m_oldDepth = 1;
+ m_currentDepth = m_oldDepth = m_depthOffset = 0;
m_rootNode = m_currentNode = NULL;
m_listSpacing = 0;
m_activeList = NULL;
@@ -93,18 +91,18 @@ void MythUIButtonTree::SetTreeState(bool refreshAll)
return;
if (!m_currentNode)
- SetCurrentNode(m_rootNode);
+ SetCurrentNode(m_rootNode->getSelectedChild());
- MythGenericTree *node = m_rootNode;
+ QList<MythGenericTree*> route = m_currentNode->getRoute();
- if (m_currentDepth > 1)
- {
- QList<MythGenericTree*> route = m_currentNode->getRoute();
- if ((int)m_currentDepth > route.size())
- m_currentDepth = 1;
+ // Sanity Checks
+ if (m_depthOffset > route.size())
+ m_depthOffset = 0;
- node = route.at(m_currentDepth - 1);
- }
+ if (((int)m_currentDepth + m_depthOffset) > route.size())
+ m_currentDepth = 0;
+
+ MythGenericTree *node = route.at(m_currentDepth + m_depthOffset);
if (m_currentDepth != m_oldDepth)
refreshAll = true;
@@ -222,14 +220,18 @@ bool MythUIButtonTree::UpdateList(MythUIButtonList *list, MythGenericTree *node)
*/
bool MythUIButtonTree::AssignTree(MythGenericTree *tree)
{
- if (!tree)
+ if (!tree || !tree->visibleChildCount())
return false;
if (m_rootNode)
Reset();
m_rootNode = tree;
- m_currentNode = m_rootNode;
+ m_currentNode = m_rootNode->getSelectedChild();
+ // The node we are given may not be the root node of that tree, we need
+ // to keep track of our depth in the tree so that we can navigate
+ // as though the parent nodes do not exist
+ m_depthOffset = m_rootNode->currentDepth();
SetTreeState(true);
return true;
@@ -242,7 +244,7 @@ void MythUIButtonTree::Reset(void)
{
m_rootNode = m_currentNode = NULL;
m_visibleLists = 0;
- m_currentDepth = m_oldDepth = 1;
+ m_currentDepth = m_oldDepth = 0;
m_activeList = NULL;
m_activeListID = 0;
m_active = true;
@@ -288,7 +290,7 @@ bool MythUIButtonTree::SetNodeByString(QStringList route)
return false;
}
- SetCurrentNode(m_rootNode);
+ MythGenericTree *foundNode = m_rootNode->getChildAt(0);
bool foundit = false;
if (!route.isEmpty())
@@ -299,10 +301,10 @@ bool MythUIButtonTree::SetNodeByString(QStringList route)
{
for(int i = 1; i < route.size(); i ++)
{
- MythGenericTree *node = m_currentNode->getChildByName(route[i]);
+ MythGenericTree *node = foundNode->getChildByName(route[i]);
if (node)
{
- SetCurrentNode(node);
+ foundNode = node;
foundit = true;
}
else
@@ -314,6 +316,7 @@ bool MythUIButtonTree::SetNodeByString(QStringList route)
}
}
+ SetCurrentNode(foundNode);
SetTreeState();
return foundit;
@@ -377,7 +380,7 @@ void MythUIButtonTree::RemoveItem(MythUIButtonListItem *item, bool deleteNode)
if (list->IsEmpty())
{
- if (m_currentDepth > 1)
+ if (m_currentDepth > 0)
m_currentDepth--;
else if (m_activeListID > 1)
m_activeListID--;
@@ -446,7 +449,7 @@ void MythUIButtonTree::SwitchList(bool right)
{
if (m_activeListID > 0)
m_activeListID--;
- else if (m_currentDepth > 1)
+ else if (m_currentDepth > 0)
{
m_currentDepth--;
doUpdate = true;
@@ -555,7 +558,7 @@ bool MythUIButtonTree::keyPressEvent(QKeyEvent *event)
{
SwitchList(true);
}
- else if (action == "ESCAPE" && m_currentDepth > 1)
+ else if (action == "ESCAPE" && m_currentDepth > 0)
{
SwitchList(false);
}
@@ -67,6 +67,7 @@ class MPUBLIC MythUIButtonTree : public MythUIType
uint m_numLists;
uint m_visibleLists;
uint m_currentDepth;
+ int m_depthOffset;
uint m_oldDepth;
QList<MythUIButtonList*> m_buttonlists;
MythUIButtonList *m_listTemplate;

0 comments on commit 2aeb872

Please sign in to comment.