Ticket #10332: MythUIButtonListItem_enabled-2012-03-08.diff

File MythUIButtonListItem_enabled-2012-03-08.diff, 10.4 KB (added by Xavier Hervy <xavier.hervy@…>, 12 years ago)

Fix bug spotted by Mark Kendhal

  • mythtv/libs/libmythui/mythuibuttonlist.cpp

    diff --git a/mythtv/libs/libmythui/mythuibuttonlist.cpp b/mythtv/libs/libmythui/mythuibuttonlist.cpp
    index d2c3f6c..d9b404e 100644
    a b void MythUIButtonList::SetValueByData(QVariant data) 
    15031503
    15041504void MythUIButtonList::SetItemCurrent(MythUIButtonListItem *item)
    15051505{
     1506    if (!item->isEnabled()) return;
    15061507    int newIndex = m_itemList.indexOf(item);
    15071508    SetItemCurrent(newIndex);
    15081509}
    void MythUIButtonList::SetItemCurrent(int current, int topPosition) 
    15151516    if (current == -1 || current >= m_itemList.size())
    15161517        return;
    15171518
     1519    if (!m_itemList.at(current)->isEnabled()) return;
     1520
    15181521    if (current == m_selPosition &&
    15191522        (topPosition == -1 || topPosition == m_topPosition))
    15201523        return;
    bool MythUIButtonList::MoveUp(MovementUnit unit, uint amount) 
    19021905            else if (m_wrapStyle == WrapCaptive)
    19031906                return true;
    19041907
     1908            findEnabledUp(unit);
     1909
    19051910            break;
    19061911
    19071912        case MoveColumn:
    bool MythUIButtonList::MoveUp(MovementUnit unit, uint amount) 
    19161921                m_selPosition = pos + (m_columns - 1);
    19171922            else if (m_wrapStyle == WrapCaptive)
    19181923                return true;
     1924            findEnabledUp(unit);
    19191925
    19201926            break;
    19211927
    bool MythUIButtonList::MoveUp(MovementUnit unit, uint amount) 
    19441950            }
    19451951            else if (m_wrapStyle == WrapCaptive)
    19461952                return true;
     1953            findEnabledUp(unit);
    19471954
    19481955            break;
    19491956
    bool MythUIButtonList::MoveUp(MovementUnit unit, uint amount) 
    19521959                m_selPosition = qMax(0, m_selPosition - (int)m_itemsVisible);
    19531960            else
    19541961                m_selPosition = PageUp();
     1962            findEnabledUp(unit);
    19551963
    19561964            break;
    19571965
    19581966        case MoveMid:
    19591967            m_selPosition = (int)(m_itemList.size() / 2);
     1968            findEnabledDown(unit);
    19601969            break;
    19611970
    19621971        case MoveMax:
    19631972            m_selPosition = 0;
     1973            findEnabledDown(unit);
    19641974            break;
    19651975
    19661976        case MoveByAmount:
    bool MythUIButtonList::MoveUp(MovementUnit unit, uint amount) 
    19711981                else if (m_wrapStyle > WrapNone)
    19721982                    m_selPosition = m_itemList.size() - 1;
    19731983            }
     1984            findEnabledUp(unit);
    19741985
    19751986            break;
    19761987    }
    bool MythUIButtonList::MoveUp(MovementUnit unit, uint amount) 
    19881999    return true;
    19892000}
    19902001
     2002
     2003/**
     2004 * If the current item is not enabled, find the next enabled one
     2005 */
     2006void MythUIButtonList::findEnabledDown(MovementUnit unit)
     2007{
     2008
     2009    if (m_selPosition<0 || m_selPosition >= m_itemList.size()
     2010            || m_itemList.at(m_selPosition)->isEnabled())
     2011        return;
     2012
     2013    LOG(VB_GENERAL, LOG_ERR, QString("MythUIButtonList::findEnabledDown() pos =>%1")
     2014        .arg(m_selPosition));
     2015
     2016    int step = (unit==MoveRow)?m_columns:1;
     2017    if (unit == MoveRow && m_wrapStyle == WrapFlowing)unit=MoveItem;
     2018    if (unit == MoveColumn)
     2019    {
     2020        while ((m_selPosition + 1) % m_columns > 0 && !m_itemList.at(m_selPosition)->isEnabled())
     2021            ++m_selPosition;
     2022
     2023        if (m_itemList.at(m_selPosition)->isEnabled()) return;
     2024        if (m_wrapStyle > WrapNone)
     2025        {
     2026            m_selPosition = m_selPosition - (m_columns - 1);
     2027            while ((m_selPosition + 1) % m_columns > 0 && !m_itemList.at(m_selPosition)->isEnabled())
     2028                ++m_selPosition;
     2029        }
     2030    }
     2031    else
     2032    {
     2033
     2034        while (!m_itemList.at(m_selPosition)->isEnabled()
     2035                &&  (m_selPosition < m_itemList.size() - step))
     2036            m_selPosition+=step;
     2037
     2038        if (!m_itemList.at(m_selPosition)->isEnabled() && m_wrapStyle > WrapNone)
     2039        {
     2040            m_selPosition=(m_selPosition+step)%m_itemList.size();
     2041
     2042            while (!m_itemList.at(m_selPosition)->isEnabled()
     2043                                &&  (m_selPosition < m_itemList.size() - step))
     2044                m_selPosition+=step;
     2045        }
     2046    }
     2047}
     2048
     2049void MythUIButtonList::findEnabledUp(MovementUnit unit)
     2050{
     2051   
     2052    if (m_selPosition<0 || m_selPosition >= m_itemList.size()
     2053            || m_itemList.at(m_selPosition)->isEnabled())
     2054        return;
     2055
     2056
     2057    LOG(VB_GENERAL, LOG_ERR, QString("MythUIButtonList::findEnabledUp() pos =>%1")
     2058        .arg(m_selPosition));
     2059
     2060    int step = (unit==MoveRow)?m_columns:1;
     2061    if (unit == MoveRow && m_wrapStyle == WrapFlowing)unit=MoveItem;
     2062    if (unit == MoveColumn)
     2063    {
     2064        LOG(VB_GENERAL, LOG_ERR, QString("MythUIButtonList::findEnabledUp() 2 pos =>%1")
     2065            .arg(m_selPosition));
     2066/*        while (m_selPosition>0 && (m_selPosition - 1) % m_columns > 0 && !m_itemList.at(m_selPosition)->isEnabled())
     2067        {
     2068            --m_selPosition;
     2069            LOG(VB_GENERAL, LOG_ERR, QString("MythUIButtonList::findEnabledUp() 3 pos =>%1")
     2070                .arg(m_selPosition));
     2071        }*/
     2072
     2073        return;
     2074
     2075        if (m_itemList.at(m_selPosition)->isEnabled()) return;
     2076        if (m_wrapStyle > WrapNone)
     2077        {
     2078            m_selPosition = m_selPosition - (m_columns - 1);
     2079            while ((m_selPosition + 1) % m_columns > 0 && !m_itemList.at(m_selPosition)->isEnabled())
     2080                ++m_selPosition;
     2081        }
     2082       /* while ((m_selPosition + 1) % m_columns > 0 && !m_itemList.at(m_selPosition)->isEnabled())
     2083            ++m_selPosition;
     2084
     2085        if (m_itemList.at(m_selPosition)->isEnabled()) return;
     2086        if (m_wrapStyle > WrapNone)
     2087        {
     2088            m_selPosition = m_selPosition - (m_columns - 1);
     2089            while ((m_selPosition + 1) % m_columns > 0 && !m_itemList.at(m_selPosition)->isEnabled())
     2090                ++m_selPosition;
     2091        }*/
     2092    }
     2093    else
     2094    {
     2095        while (!m_itemList.at(m_selPosition)->isEnabled()
     2096                &&  (m_selPosition - step >= 0 ))
     2097            m_selPosition-=step;
     2098
     2099
     2100        if (!m_itemList.at(m_selPosition)->isEnabled() && m_wrapStyle > WrapNone)
     2101        {
     2102            m_selPosition=m_itemList.size()-1;
     2103
     2104            while (m_selPosition>0 && !m_itemList.at(m_selPosition)->isEnabled()
     2105                                &&  (m_selPosition - step >= 0 ))
     2106                m_selPosition-=step;
     2107        }
     2108    }
     2109}
     2110
     2111
    19912112bool MythUIButtonList::MoveDown(MovementUnit unit, uint amount)
    19922113{
    19932114    int pos = m_selPosition;
    bool MythUIButtonList::MoveDown(MovementUnit unit, uint amount) 
    20042125                m_selPosition = 0;
    20052126            else if (m_wrapStyle == WrapCaptive)
    20062127                return true;
     2128            findEnabledDown(unit);
    20072129
    20082130            break;
    20092131
    bool MythUIButtonList::MoveDown(MovementUnit unit, uint amount) 
    20192141                m_selPosition = pos - (m_columns - 1);
    20202142            else if (m_wrapStyle == WrapCaptive)
    20212143                return true;
     2144            findEnabledDown(unit);
    20222145
    20232146            break;
    20242147
    bool MythUIButtonList::MoveDown(MovementUnit unit, uint amount) 
    20392162                m_selPosition = (pos % m_columns);
    20402163            else if (m_wrapStyle == WrapCaptive)
    20412164                return true;
    2042 
     2165            findEnabledDown(unit);
    20432166            break;
    20442167
    20452168        case MovePage:
    bool MythUIButtonList::MoveDown(MovementUnit unit, uint amount) 
    20482171                                     m_selPosition + (int)m_itemsVisible);
    20492172            else
    20502173                m_selPosition = PageDown();
    2051 
     2174            findEnabledDown(unit);
    20522175            break;
    20532176
    20542177        case MoveMax:
    20552178            m_selPosition = m_itemCount - 1;
     2179            findEnabledUp(unit);
    20562180            break;
    20572181
    20582182        case MoveByAmount:
    bool MythUIButtonList::MoveDown(MovementUnit unit, uint amount) 
    20632187                else if (m_wrapStyle > WrapNone)
    20642188                    m_selPosition = 0;
    20652189            }
     2190            findEnabledDown(unit);
    20662191
    20672192            break;
    20682193    }
    bool MythUIButtonList::keyPressEvent(QKeyEvent *e) 
    24062531        {
    24072532            MythUIButtonListItem *item = GetItemCurrent();
    24082533
    2409             if (item)
     2534            if (item && item->isEnabled())
    24102535                emit itemClicked(item);
    24112536        }
    24122537        else if (action == "SEARCH")
    MythUIButtonListItem::MythUIButtonListItem(MythUIButtonList *lbtype, 
    29293054    m_checkable = checkable;
    29303055    m_state     = state;
    29313056    m_showArrow = showArrow;
     3057    m_enabled   = true;
     3058
    29323059    m_data      = 0;
    29333060
    29343061    if (state >= NotChecked)
    MythUIButtonListItem::MythUIButtonListItem(MythUIButtonList *lbtype, 
    29543081    m_checkable = false;
    29553082    m_state     = CantCheck;
    29563083    m_showArrow = false;
     3084    m_enabled   = true;
    29573085
    29583086    if (m_parent)
    29593087        m_parent->InsertItem(this, listPosition);
    void MythUIButtonListItem::setDrawArrow(bool flag) 
    32743402    m_showArrow = flag;
    32753403}
    32763404
     3405bool MythUIButtonListItem::isEnabled() const
     3406{
     3407    return m_enabled;
     3408}
     3409void MythUIButtonListItem::setEnabled(bool flag)
     3410{
     3411    m_enabled = flag;
     3412}
     3413
    32773414void MythUIButtonListItem::SetData(QVariant data)
    32783415{
    32793416    m_data = data;
    void MythUIButtonListItem::SetToRealButton(MythUIStateType *button, bool selecte 
    32993436
    33003437    QString state;
    33013438
    3302     if (selected)
     3439    if (!m_enabled)
     3440    {
     3441        state = m_parent->m_active ? "disabledactive" : "disabledinactive";
     3442    }
     3443    else if (selected)
    33033444    {
    33043445        button->MoveToTop();
    33053446        state = m_parent->m_active ? "selectedactive" : "selectedinactive";
  • mythtv/libs/libmythui/mythuibuttonlist.h

    diff --git a/mythtv/libs/libmythui/mythuibuttonlist.h b/mythtv/libs/libmythui/mythuibuttonlist.h
    index d42a204..091cd1d 100644
    a b class MUI_PUBLIC MythUIButtonListItem 
    7474    bool checkable() const;
    7575    void setCheckable(bool flag);
    7676
     77    bool isEnabled() const;
     78    void setEnabled(bool flag);
     79
    7780    CheckState state() const;
    7881    void setChecked(CheckState state);
    7982
    class MUI_PUBLIC MythUIButtonListItem 
    9699    CheckState      m_state;
    97100    QVariant        m_data;
    98101    bool            m_showArrow;
     102    bool            m_enabled;
    99103
    100104    QMap<QString, TextProperties> m_strings;
    101105    QMap<QString, MythImage*> m_images;
    class MUI_PUBLIC MythUIButtonList : public MythUIType 
    239243
    240244    bool DoFind(bool doMove, bool searchForward);
    241245
     246    void findEnabledUp(MovementUnit unit);
     247    void findEnabledDown(MovementUnit unit);
     248
    242249    /* methods for subclasses to override */
    243250    virtual void CalculateVisibleItems(void);
    244251    virtual QPoint GetButtonPosition(int column, int row) const;