Ticket #10332: MythUIButtonListItem_enabled-2012-03-08.diff
File MythUIButtonListItem_enabled-2012-03-08.diff, 10.4 KB (added by , 12 years ago) |
---|
-
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) 1503 1503 1504 1504 void MythUIButtonList::SetItemCurrent(MythUIButtonListItem *item) 1505 1505 { 1506 if (!item->isEnabled()) return; 1506 1507 int newIndex = m_itemList.indexOf(item); 1507 1508 SetItemCurrent(newIndex); 1508 1509 } … … void MythUIButtonList::SetItemCurrent(int current, int topPosition) 1515 1516 if (current == -1 || current >= m_itemList.size()) 1516 1517 return; 1517 1518 1519 if (!m_itemList.at(current)->isEnabled()) return; 1520 1518 1521 if (current == m_selPosition && 1519 1522 (topPosition == -1 || topPosition == m_topPosition)) 1520 1523 return; … … bool MythUIButtonList::MoveUp(MovementUnit unit, uint amount) 1902 1905 else if (m_wrapStyle == WrapCaptive) 1903 1906 return true; 1904 1907 1908 findEnabledUp(unit); 1909 1905 1910 break; 1906 1911 1907 1912 case MoveColumn: … … bool MythUIButtonList::MoveUp(MovementUnit unit, uint amount) 1916 1921 m_selPosition = pos + (m_columns - 1); 1917 1922 else if (m_wrapStyle == WrapCaptive) 1918 1923 return true; 1924 findEnabledUp(unit); 1919 1925 1920 1926 break; 1921 1927 … … bool MythUIButtonList::MoveUp(MovementUnit unit, uint amount) 1944 1950 } 1945 1951 else if (m_wrapStyle == WrapCaptive) 1946 1952 return true; 1953 findEnabledUp(unit); 1947 1954 1948 1955 break; 1949 1956 … … bool MythUIButtonList::MoveUp(MovementUnit unit, uint amount) 1952 1959 m_selPosition = qMax(0, m_selPosition - (int)m_itemsVisible); 1953 1960 else 1954 1961 m_selPosition = PageUp(); 1962 findEnabledUp(unit); 1955 1963 1956 1964 break; 1957 1965 1958 1966 case MoveMid: 1959 1967 m_selPosition = (int)(m_itemList.size() / 2); 1968 findEnabledDown(unit); 1960 1969 break; 1961 1970 1962 1971 case MoveMax: 1963 1972 m_selPosition = 0; 1973 findEnabledDown(unit); 1964 1974 break; 1965 1975 1966 1976 case MoveByAmount: … … bool MythUIButtonList::MoveUp(MovementUnit unit, uint amount) 1971 1981 else if (m_wrapStyle > WrapNone) 1972 1982 m_selPosition = m_itemList.size() - 1; 1973 1983 } 1984 findEnabledUp(unit); 1974 1985 1975 1986 break; 1976 1987 } … … bool MythUIButtonList::MoveUp(MovementUnit unit, uint amount) 1988 1999 return true; 1989 2000 } 1990 2001 2002 2003 /** 2004 * If the current item is not enabled, find the next enabled one 2005 */ 2006 void 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 2049 void 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 1991 2112 bool MythUIButtonList::MoveDown(MovementUnit unit, uint amount) 1992 2113 { 1993 2114 int pos = m_selPosition; … … bool MythUIButtonList::MoveDown(MovementUnit unit, uint amount) 2004 2125 m_selPosition = 0; 2005 2126 else if (m_wrapStyle == WrapCaptive) 2006 2127 return true; 2128 findEnabledDown(unit); 2007 2129 2008 2130 break; 2009 2131 … … bool MythUIButtonList::MoveDown(MovementUnit unit, uint amount) 2019 2141 m_selPosition = pos - (m_columns - 1); 2020 2142 else if (m_wrapStyle == WrapCaptive) 2021 2143 return true; 2144 findEnabledDown(unit); 2022 2145 2023 2146 break; 2024 2147 … … bool MythUIButtonList::MoveDown(MovementUnit unit, uint amount) 2039 2162 m_selPosition = (pos % m_columns); 2040 2163 else if (m_wrapStyle == WrapCaptive) 2041 2164 return true; 2042 2165 findEnabledDown(unit); 2043 2166 break; 2044 2167 2045 2168 case MovePage: … … bool MythUIButtonList::MoveDown(MovementUnit unit, uint amount) 2048 2171 m_selPosition + (int)m_itemsVisible); 2049 2172 else 2050 2173 m_selPosition = PageDown(); 2051 2174 findEnabledDown(unit); 2052 2175 break; 2053 2176 2054 2177 case MoveMax: 2055 2178 m_selPosition = m_itemCount - 1; 2179 findEnabledUp(unit); 2056 2180 break; 2057 2181 2058 2182 case MoveByAmount: … … bool MythUIButtonList::MoveDown(MovementUnit unit, uint amount) 2063 2187 else if (m_wrapStyle > WrapNone) 2064 2188 m_selPosition = 0; 2065 2189 } 2190 findEnabledDown(unit); 2066 2191 2067 2192 break; 2068 2193 } … … bool MythUIButtonList::keyPressEvent(QKeyEvent *e) 2406 2531 { 2407 2532 MythUIButtonListItem *item = GetItemCurrent(); 2408 2533 2409 if (item )2534 if (item && item->isEnabled()) 2410 2535 emit itemClicked(item); 2411 2536 } 2412 2537 else if (action == "SEARCH") … … MythUIButtonListItem::MythUIButtonListItem(MythUIButtonList *lbtype, 2929 3054 m_checkable = checkable; 2930 3055 m_state = state; 2931 3056 m_showArrow = showArrow; 3057 m_enabled = true; 3058 2932 3059 m_data = 0; 2933 3060 2934 3061 if (state >= NotChecked) … … MythUIButtonListItem::MythUIButtonListItem(MythUIButtonList *lbtype, 2954 3081 m_checkable = false; 2955 3082 m_state = CantCheck; 2956 3083 m_showArrow = false; 3084 m_enabled = true; 2957 3085 2958 3086 if (m_parent) 2959 3087 m_parent->InsertItem(this, listPosition); … … void MythUIButtonListItem::setDrawArrow(bool flag) 3274 3402 m_showArrow = flag; 3275 3403 } 3276 3404 3405 bool MythUIButtonListItem::isEnabled() const 3406 { 3407 return m_enabled; 3408 } 3409 void MythUIButtonListItem::setEnabled(bool flag) 3410 { 3411 m_enabled = flag; 3412 } 3413 3277 3414 void MythUIButtonListItem::SetData(QVariant data) 3278 3415 { 3279 3416 m_data = data; … … void MythUIButtonListItem::SetToRealButton(MythUIStateType *button, bool selecte 3299 3436 3300 3437 QString state; 3301 3438 3302 if (selected) 3439 if (!m_enabled) 3440 { 3441 state = m_parent->m_active ? "disabledactive" : "disabledinactive"; 3442 } 3443 else if (selected) 3303 3444 { 3304 3445 button->MoveToTop(); 3305 3446 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 74 74 bool checkable() const; 75 75 void setCheckable(bool flag); 76 76 77 bool isEnabled() const; 78 void setEnabled(bool flag); 79 77 80 CheckState state() const; 78 81 void setChecked(CheckState state); 79 82 … … class MUI_PUBLIC MythUIButtonListItem 96 99 CheckState m_state; 97 100 QVariant m_data; 98 101 bool m_showArrow; 102 bool m_enabled; 99 103 100 104 QMap<QString, TextProperties> m_strings; 101 105 QMap<QString, MythImage*> m_images; … … class MUI_PUBLIC MythUIButtonList : public MythUIType 239 243 240 244 bool DoFind(bool doMove, bool searchForward); 241 245 246 void findEnabledUp(MovementUnit unit); 247 void findEnabledDown(MovementUnit unit); 248 242 249 /* methods for subclasses to override */ 243 250 virtual void CalculateVisibleItems(void); 244 251 virtual QPoint GetButtonPosition(int column, int row) const;