/*! * \brief Using a path based on the node string, set the currently * selected node * * \param route List defining the path using node strings starting at the root node * * \return True if successful */ bool MythUIButtonTree::SetNodeByString(QStringList route) { if (!m_rootNode) { DoSetCurrentNode(NULL); return false; } MythGenericTree *foundNode = m_rootNode; bool foundit = false; if (!route.isEmpty()) { if (route[0] == m_rootNode->getString()) { if (route.size() > 1) { for (int i = 1; i < route.size(); i ++) { MythGenericTree *node = foundNode->getChildByName(route[i]); if (node) { node->becomeSelectedChild(); foundNode = node; foundit = true; } else { node = foundNode->getChildAt(0); if (node) { node->becomeSelectedChild(); foundNode = node; } break; } } } else foundit = true; } } DoSetCurrentNode(foundNode); m_currentDepth = qMax(0, (int)(foundNode->currentDepth() - m_depthOffset - m_numLists)); m_activeListID = qMin(foundNode->currentDepth() - m_depthOffset - 1, (int)(m_numLists - 1)); SetTreeState(true); return foundit; }
/*! * \brief Remove the item from the tree * * \param item Item to be removed * \param deleteNode Also delete the node from the tree? Modifies the tree. * * \return True if successful */ void MythUIButtonTree::RemoveItem(MythUIButtonListItem *item, bool deleteNode) { if (!item || !m_rootNode) return; MythGenericTree *node = qVariantValue<MythGenericTree *>(item->GetData()); if (node && node->getParent()) { DoSetCurrentNode(node->getParent()); if (deleteNode) node->getParent()->deleteNode(node); else node->SetVisible(false); } MythUIButtonList *list = item->parent(); list->RemoveItem(item); if (list->IsEmpty()) { if (m_currentDepth > 0) m_currentDepth--; else if (m_activeListID > 1) m_activeListID--; SetTreeState(true); } }
/*! * \brief Handle a list item being clicked * * \param item The list item */ void MythUIButtonTree::handleClick(MythUIButtonListItem *item) { if (!item) return; MythGenericTree *node = qVariantValue<MythGenericTree*> (item->GetData()); if (DoSetCurrentNode(node)) emit itemClicked(item); }
/*! * \brief Using a path based on the node IDs, set the currently * selected node * * \param route List defining the path using node IDs starting at the root node * * \return True if successful */ bool MythUIButtonTree::SetNodeById(QList<int> route) { MythGenericTree *node = m_rootNode->findNode(route); if (node && node->isSelectable()) { DoSetCurrentNode(node); SetTreeState(); return true; } return false; }
/*! * \brief Handle a list item receiving focus * * \param item The list item */ void MythUIButtonTree::handleSelect(MythUIButtonListItem *item) { if (!item) return; MythUIButtonList *list = item->parent(); QString name = list->objectName(); // New list is automatically selected so we just need to deselect the old // list if (m_activeList) m_activeList->Deselect(); m_activeListID = name.section(' ',2,2).toInt(); m_activeList = list; MythGenericTree *node = qVariantValue<MythGenericTree*> (item->GetData()); DoSetCurrentNode(node); SetTreeState(); }
/*! * \brief Update the widget following a change */ void MythUIButtonTree::SetTreeState(bool refreshAll) { if (!m_initialized) Init(); if (!m_rootNode) return; if (!m_currentNode) DoSetCurrentNode(m_rootNode->getSelectedChild()); QList<MythGenericTree *> route = m_currentNode->getRoute(); // Sanity Checks if (m_depthOffset >= route.size()) m_depthOffset = 0; 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; m_oldDepth = m_currentDepth; m_visibleLists = 0; uint listid = 0; while (listid < m_buttonlists.count()) { MythUIButtonList *list = m_buttonlists.at(listid); list->SetVisible(false); list->SetActive(false); MythGenericTree *selectedNode = NULL; if (node) selectedNode = node->getSelectedChild(true); if (refreshAll || m_activeListID < listid) { if (!UpdateList(list, node)) { listid++; continue; } } if (m_active && (listid == m_activeListID)) { m_activeList = list; list->SetActive(true); DoSetCurrentNode(selectedNode); emit itemSelected(list->GetItemCurrent()); } listid++; list->SetVisible(true); m_visibleLists++; node = selectedNode; } }