Ticket #6139: buttonlistfix.diff
File buttonlistfix.diff, 14.0 KB (added by , 15 years ago) |
---|
-
libs/libmythui/mythuibuttonlist.h
143 143 uint ItemWidth(void) const { return m_itemWidth; } 144 144 uint ItemHeight(void) const { return m_itemHeight; } 145 145 146 bool MoveItemUpDown(MythUIButtonListItem *item, bool flag);146 bool MoveItemUpDown(MythUIButtonListItem *item, bool up); 147 147 148 148 void SetAllChecked(MythUIButtonListItem::CheckState state); 149 149 … … 221 221 bool m_needsUpdate; 222 222 bool m_clearing; 223 223 224 MythUIButtonListItem* m_topItem;225 MythUIButtonListItem* m_selItem;226 227 224 int m_selPosition; 228 225 int m_topPosition; 229 226 int m_itemCount; 227 bool m_keepSelAtBottom; 230 228 231 229 QList<MythUIButtonListItem*> m_itemList; 232 230 -
libs/libmythui/mythuibuttonlist.cpp
43 43 m_active = false; 44 44 m_drawFromBottom = false; 45 45 46 m_topItem = 0;47 m_selItem = 0;48 46 m_selPosition = 0; 49 47 m_topPosition = 0; 50 48 m_itemCount = 0; … … 118 116 119 117 m_clearing = false; 120 118 121 m_topItem = NULL;122 m_selItem = NULL;123 119 m_selPosition = 0; 124 120 m_topPosition = 0; 125 121 m_itemCount = 0; … … 150 146 { 151 147 int button = 0; 152 148 149 // set topitem, top position 150 if (m_selPosition < 0 || m_selPosition > m_itemList.size()) 151 { 152 if (m_wrapStyle > WrapNone) 153 m_selPosition = m_itemList.size() - 1; 154 else 155 m_selPosition = 0; 156 } 157 158 switch (m_scrollStyle) 159 { 160 case ScrollCenter: 161 m_topPosition = qMax(m_selPosition - (int)((float)m_itemsVisible / 2), 0); 162 break; 163 case ScrollFree: 164 { 165 int adjust = 0; 166 if (m_topPosition == -1 || m_keepSelAtBottom) 167 { 168 if (m_topPosition == -1) 169 m_topPosition = 0; 170 if (m_layout == LayoutHorizontal) 171 adjust = 1 - m_itemsVisible; 172 else 173 adjust = m_columns - m_itemsVisible; 174 m_keepSelAtBottom = false; 175 } 176 177 if (m_selPosition < m_topPosition || 178 m_topPosition + (int)m_itemsVisible <= m_selPosition) 179 { 180 if (m_layout == LayoutHorizontal) 181 m_topPosition = m_selPosition + adjust; 182 else 183 m_topPosition = (m_selPosition + adjust) / 184 (m_columns * m_columns); 185 } 186 187 m_topPosition = qMax(m_topPosition, 0); 188 break; 189 } 190 } 191 153 192 QList<MythUIButtonListItem*>::iterator it = m_itemList.begin() + m_topPosition; 154 193 155 194 if (m_scrollStyle == ScrollCenter) … … 157 196 if (m_selPosition <= (int)(m_itemsVisible/2)) 158 197 { 159 198 button = (m_itemsVisible / 2) - m_selPosition; 160 if (m_wrapStyle == WrapItems && button > 0) 199 if (m_wrapStyle == WrapItems && button > 0 && 200 m_itemCount >= (int)m_itemsVisible) 161 201 { 162 202 it = m_itemList.end() - button; 163 203 button = 0; … … 182 222 if (it < m_itemList.begin()) 183 223 it = m_itemList.begin(); 184 224 225 int curItem = GetItemPos(*it); 185 226 while (it < m_itemList.end() && button < (int)m_itemsVisible) 186 227 { 187 228 realButton = m_ButtonList[button]; 188 229 buttonItem = *it; 189 230 190 if (!realButton || ! 231 if (!realButton || !buttonItem) 191 232 break; 192 233 193 234 bool selected = false; 194 if (!seenSelected && ( buttonItem == m_selItem))235 if (!seenSelected && (curItem == m_selPosition)) 195 236 { 196 237 seenSelected = true; 197 238 selected = true; … … 201 242 buttonItem->SetToRealButton(realButton, selected); 202 243 realButton->SetVisible(true); 203 244 204 if ((m_wrapStyle == WrapItems) && (it == (m_itemList.end()-1))) 245 if (m_wrapStyle == WrapItems && it == (m_itemList.end()-1) && 246 m_itemCount >= (int)m_itemsVisible) 247 { 205 248 it = m_itemList.begin(); 249 curItem = 0; 250 } 206 251 else 252 { 207 253 ++it; 254 ++curItem; 255 } 256 208 257 button++; 209 258 } 210 259 … … 223 272 } 224 273 else 225 274 { 226 if (m_top Item != m_itemList.first())275 if (m_topPosition != 0) 227 276 m_upArrow->DisplayState(MythUIStateType::Full); 228 277 else 229 278 m_upArrow->DisplayState(MythUIStateType::Off); … … 244 293 245 294 if (wasEmpty) 246 295 { 247 m_topItem = item;248 m_selItem = item;249 296 m_selPosition = m_topPosition = 0; 250 251 297 emit itemSelected(item); 252 298 } 253 299 … … 263 309 if (curIndex == -1) 264 310 return; 265 311 266 if (item == m_topItem) 312 if (curIndex == m_topPosition && 313 m_topPosition > 0 && 314 m_topPosition == m_itemCount - 1) 267 315 { 268 if (m_topItem != m_itemList.last()) 269 { 270 m_topItem = *(m_itemList.begin() + m_topPosition + 1); 271 } 272 else if (m_topItem != m_itemList.first()) 273 { 274 --m_topPosition; 275 m_topItem = *(m_itemList.begin() + m_topPosition); 276 } 277 else 278 { 279 m_topItem = NULL; 280 m_topPosition = 0; 281 } 316 m_topPosition--; 282 317 } 283 318 284 if (item == m_selItem) 319 if (curIndex == m_selPosition && 320 m_selPosition > 0 && 321 m_selPosition == m_itemCount - 1) 285 322 { 286 if (m_selItem != m_itemList.last()) 287 { 288 m_selItem = *(m_itemList.begin() + m_selPosition + 1); 289 } 290 else if (m_selItem != m_itemList.first()) 291 { 292 --m_selPosition; 293 m_selItem = *(m_itemList.begin() + m_selPosition); 294 } 295 else 296 { 297 m_selItem = NULL; 298 m_selPosition = 0; 299 } 323 m_selPosition--; 300 324 } 301 325 302 326 m_itemList.removeAt(curIndex); … … 304 328 305 329 Update(); 306 330 307 if (m_sel Item)308 emit itemSelected(m_ selItem);331 if (m_selPosition < m_itemCount) 332 emit itemSelected(m_itemList.at(m_selPosition)); 309 333 } 310 334 311 335 void MythUIButtonList::SetValueByData(QVariant data) … … 326 350 327 351 void MythUIButtonList::SetItemCurrent(MythUIButtonListItem* item) 328 352 { 353 int newIndex = m_itemList.indexOf(item); 354 SetItemCurrent(newIndex); 355 } 356 357 void MythUIButtonList::SetItemCurrent(int current) 358 { 329 359 if (!m_initialized) 330 360 Init(); 331 361 332 if ( m_selItem == item)362 if (current == -1 || current >= m_itemList.size()) 333 363 return; 334 364 335 m_selPosition = m_itemList.indexOf(item); 365 if (current == m_selPosition) 366 return; 336 367 337 if (m_selPosition == -1) 338 m_selPosition = 0; 339 340 m_selItem = m_itemList.at(m_selPosition); 341 368 m_selPosition = current; 342 369 if (m_itemsVisible == 0) 343 370 return; 344 371 345 m_topPosition = 0;372 m_topPosition = -1; 346 373 347 switch (m_scrollStyle)348 {349 case ScrollCenter :350 while (m_topPosition + (int)((float)m_itemsVisible/2) <351 m_selPosition)352 ++m_topPosition;353 break;354 case ScrollFree :355 if (m_topPosition + (int)m_itemsVisible <= m_selPosition)356 {357 if (m_layout == LayoutHorizontal)358 m_topPosition = m_selPosition - m_itemsVisible + 1;359 else360 m_topPosition = (m_selPosition - m_itemsVisible + m_columns)361 / m_columns * m_columns;362 363 m_topPosition = qMax(0, m_topPosition);364 }365 break;366 }367 368 m_topItem = m_itemList.at(m_topPosition);369 370 374 Update(); 371 375 372 emit itemSelected( m_selItem);376 emit itemSelected(GetItemCurrent()); 373 377 } 374 378 375 void MythUIButtonList::SetItemCurrent(int current)376 {377 if (current >= m_itemList.size())378 return;379 380 MythUIButtonListItem* item = m_itemList.at(current);381 if (!item && !m_itemList.empty())382 item = m_itemList[0];383 384 if (item)385 SetItemCurrent(item);386 }387 388 379 MythUIButtonListItem* MythUIButtonList::GetItemCurrent() const 389 380 { 390 return m_ selItem;381 return m_itemList.at(m_selPosition); 391 382 } 392 383 393 384 int MythUIButtonList::GetIntValue() 394 385 { 395 if (GetItemCurrent()) 396 return GetItemCurrent()->GetText().toInt(); 386 MythUIButtonListItem *item = GetItemCurrent(); 387 if (item) 388 return item->GetText().toInt(); 397 389 398 390 return 0; 399 391 } 400 392 401 393 QString MythUIButtonList::GetValue() 402 394 { 403 if (GetItemCurrent()) 404 return GetItemCurrent()->GetText(); 395 MythUIButtonListItem *item = GetItemCurrent(); 396 if (item) 397 return item->GetText(); 405 398 406 399 return QString(); 407 400 } … … 511 504 break; 512 505 } 513 506 514 if ( m_selPosition < 0 || m_selPosition >= m_itemList.size())507 if (pos != m_selPosition) 515 508 { 516 if (m_wrapStyle > WrapNone) 517 m_selPosition = m_itemList.size() - 1; 518 else 519 m_selPosition = 0; 509 Update(); 510 emit itemSelected(GetItemCurrent()); 520 511 } 521 512 522 m_selItem = m_itemList.at(m_selPosition);523 524 switch (m_scrollStyle)525 {526 case ScrollCenter :527 m_topPosition = qMax(m_selPosition - (int)((float)m_itemsVisible/2), 0);528 m_topItem = m_itemList.at(m_topPosition);529 break;530 case ScrollFree :531 if (m_selPosition < m_topPosition ||532 m_topPosition + (int)m_itemsVisible <= m_selPosition)533 {534 if (m_layout == LayoutHorizontal)535 m_topPosition = m_selPosition;536 else537 m_topPosition = m_selPosition / m_columns * m_columns;538 }539 break;540 }541 542 m_topItem = m_itemList.at(m_topPosition);543 544 Update();545 546 if (pos != m_selPosition)547 emit itemSelected(m_selItem);548 549 513 return true; 550 514 } 551 515 … … 591 555 break; 592 556 } 593 557 594 if (m_selPosition < 0) 595 m_selPosition = 0; 596 597 if (m_selPosition >= m_itemList.size()) 598 m_selPosition = m_itemList.size()-1; 599 600 m_selItem = m_itemList.at(m_selPosition); 601 602 switch (m_scrollStyle) 558 if (pos != m_selPosition) 603 559 { 604 case ScrollCenter : 605 while (m_topPosition + (int)((float)m_itemsVisible/2) < 606 m_selPosition) 607 ++m_topPosition; 608 break; 609 case ScrollFree : 610 if (m_topPosition + (int)m_itemsVisible <= m_selPosition || 611 m_topPosition > m_selPosition) 612 { 613 if (m_layout == LayoutHorizontal) 614 m_topPosition = m_selPosition - m_itemsVisible + 1; 615 else 616 m_topPosition = (m_selPosition - m_itemsVisible + m_columns) 617 / m_columns * m_columns; 618 619 m_topPosition = std::max(0, m_topPosition); 620 } 621 break; 560 m_keepSelAtBottom = true; 561 Update(); 562 emit itemSelected(GetItemCurrent()); 622 563 } 623 564 624 m_topItem = m_itemList.at(m_topPosition);625 626 Update();627 628 if (pos != m_selPosition)629 emit itemSelected(m_selItem);630 631 565 return true; 632 566 } 633 567 … … 656 590 if (!found_it || m_selPosition == selectedPosition) 657 591 return false; 658 592 659 m_selPosition = selectedPosition; 660 m_selItem = m_itemList.at(m_selPosition); 661 662 m_topPosition = 0; 663 664 switch (m_scrollStyle) 665 { 666 case ScrollCenter : 667 while (m_topPosition + (int)((float)m_itemsVisible/2) < 668 m_selPosition) 669 ++m_topPosition; 670 break; 671 case ScrollFree : 672 if (m_topPosition + (int)m_itemsVisible <= m_selPosition) 673 { 674 if (m_layout == LayoutHorizontal) 675 m_topPosition = m_selPosition - m_itemsVisible + 1; 676 else 677 m_topPosition = (m_selPosition - m_itemsVisible + m_columns) 678 / m_columns * m_columns; 679 680 m_topPosition = qMax(0, m_topPosition); 681 } 682 break; 683 } 684 685 m_topItem = m_itemList.at(m_topPosition); 686 687 Update(); 688 689 emit itemSelected(m_selItem); 690 593 SetItemCurrent(selectedPosition); 691 594 return true; 692 595 } 693 596 694 bool MythUIButtonList::MoveItemUpDown(MythUIButtonListItem *item, bool flag)597 bool MythUIButtonList::MoveItemUpDown(MythUIButtonListItem *item, bool up) 695 598 { 696 if (item != m_selItem) 697 { 599 if (GetItemCurrent() != item) 698 600 return false; 699 } 700 701 if (item == m_itemList.first() && flag) 601 if (item == m_itemList.first() && up) 702 602 return false; 703 if (item == m_itemList.last() && ! flag)603 if (item == m_itemList.last() && !up) 704 604 return false; 705 605 706 606 int oldpos = m_selPosition; 707 607 int insertat = 0; 708 608 bool dolast = false; 709 609 710 if ( flag)610 if (up) 711 611 { 712 612 insertat = m_selPosition - 1; 713 613 if (item == m_itemList.last()) … … 715 615 else 716 616 ++m_selPosition; 717 617 718 if (item == m_ topItem)618 if (item == m_itemList.at(m_topPosition)) 719 619 ++m_topPosition; 720 620 } 721 621 else 722 622 insertat = m_selPosition + 1; 723 623 724 624 m_itemList.removeAt(oldpos); 725 726 625 m_itemList.insert(insertat, item); 727 626 728 if ( flag)627 if (up) 729 628 { 730 629 MoveUp(); 731 630 if (!dolast) … … 1076 975 m_wrapStyle = lb->m_wrapStyle; 1077 976 1078 977 m_clearing = false; 1079 m_topItem = m_selItem = NULL;1080 1081 978 m_selPosition = m_topPosition = m_itemCount = 0; 1082 979 1083 980 MythUIType::CopyFrom(base);