00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <iostream>
00023
00024 #include "mythcontext.h"
00025 #include "lcddevice.h"
00026
00027 #include "uilistbtntype.h"
00028
00029 UIListGenericTree::UIListGenericTree(UIListGenericTree *parent,
00030 const QString &name, const QString &action,
00031 int check, QPixmap *image)
00032 : GenericTree(name)
00033 {
00034 m_check = check;
00035 m_action = action;
00036 m_image = image;
00037 m_active = true;
00038
00039 m_physitem = NULL;
00040
00041 if (!action.isEmpty() && !action.isNull())
00042 setSelectable(true);
00043
00044 if (parent)
00045 {
00046 parent->addNode(this);
00047 parent->setDrawArrow(true);
00048 }
00049 }
00050
00051 UIListGenericTree::~UIListGenericTree()
00052 {
00053 }
00054
00055 void UIListGenericTree::RemoveFromParent(void)
00056 {
00057 if (m_physitem)
00058 delete m_physitem;
00059 m_physitem = NULL;
00060
00061 if (getParent())
00062 {
00063 if (getParent()->childCount() == 1)
00064 ((UIListGenericTree *)getParent())->setDrawArrow(false);
00065
00066 getParent()->removeNode(this);
00067 }
00068 }
00069
00070 void UIListGenericTree::setText(const QString &text)
00071 {
00072 setString(text);
00073 if (m_physitem)
00074 m_physitem->setText(text);
00075 }
00076
00077 void UIListGenericTree::setPixmap(QPixmap *pixmap)
00078 {
00079 if (m_physitem)
00080 m_physitem->setPixmap(pixmap);
00081 m_image = pixmap;
00082 }
00083
00084 void UIListGenericTree::setDrawArrow(bool flag)
00085 {
00086 if (m_physitem)
00087 m_physitem->setDrawArrow(flag);
00088 }
00089
00090 void UIListGenericTree::setCheck(int flag)
00091 {
00092 m_check = flag;
00093
00094 if (m_physitem)
00095 {
00096 m_physitem->setCheckable(flag >= 0);
00097 m_physitem->setChecked((UIListBtnTypeItem::CheckState)flag);
00098 }
00099 }
00100
00101 void UIListGenericTree::setActive(bool flag)
00102 {
00103 if (m_physitem)
00104 m_physitem->setOverrideInactive(!flag);
00105 m_active = flag;
00106 }
00107
00108 bool UIListGenericTree::getActive(void)
00109 {
00110 return m_active;
00111 }
00112
00113 bool UIListGenericTree::movePositionUpDown(bool flag)
00114 {
00115 if (getParent())
00116 getParent()->MoveItemUpDown(this, flag);
00117
00118 if (m_physitem)
00119 return m_physitem->moveUpDown(flag);
00120
00121 return false;
00122 }
00123
00125
00126 UIListTreeType::UIListTreeType(const QString &name, const QRect &area,
00127 const QRect &levelsize, int levelspacing,
00128 int order)
00129 : UIType(name)
00130 {
00131 m_totalarea = area;
00132 m_levelsize = levelsize;
00133 m_levelspacing = levelspacing;
00134
00135 levels = 0;
00136 curlevel = -1;
00137
00138 treetop = NULL;
00139 currentpos = NULL;
00140
00141 currentlevel = NULL;
00142
00143 listLevels.setAutoDelete(true);
00144
00145 m_active = NULL;
00146 m_inactive = NULL;
00147 takes_focus = true;
00148
00149 SetItemRegColor(Qt::black,QColor(80,80,80),100);
00150 SetItemSelColor(QColor(82,202,56),QColor(52,152,56),255);
00151
00152 m_spacing = 0;
00153 m_margin = 0;
00154
00155 m_order = order;
00156
00157
00158
00159
00160
00161
00162 list_tree_active = true;
00163 }
00164
00165 UIListTreeType::~UIListTreeType()
00166 {
00167 }
00168
00169 void UIListTreeType::SetItemRegColor(const QColor& beg, const QColor& end,
00170 uint alpha)
00171 {
00172 m_itemRegBeg = beg;
00173 m_itemRegEnd = end;
00174 m_itemRegAlpha = alpha;
00175 }
00176
00177 void UIListTreeType::SetItemSelColor(const QColor& beg, const QColor& end,
00178 uint alpha)
00179 {
00180 m_itemSelBeg = beg;
00181 m_itemSelEnd = end;
00182 m_itemSelAlpha = alpha;
00183 }
00184
00185 void UIListTreeType::SetFontActive(fontProp *font)
00186 {
00187 m_active = font;
00188 }
00189
00190 void UIListTreeType::SetFontInactive(fontProp *font)
00191 {
00192 m_inactive = font;
00193 }
00194
00195 void UIListTreeType::SetSpacing(int spacing)
00196 {
00197 m_spacing = spacing;
00198 }
00199
00200 void UIListTreeType::SetMargin(int margin)
00201 {
00202 m_margin = margin;
00203 }
00204
00205 void UIListTreeType::SetTree(UIListGenericTree *toplevel)
00206 {
00207 if (treetop)
00208 {
00209 listLevels.clear();
00210 currentlevel = NULL;
00211 treetop = NULL;
00212 currentpos = NULL;
00213 levels = 0;
00214 curlevel = -1;
00215 }
00216
00217 levels = - 1;
00218
00219 currentpos = (UIListGenericTree *)toplevel->getChildAt(0);
00220
00221 if (!currentpos)
00222 {
00223
00224
00225
00226
00227
00228 return;
00229 }
00230
00231 treetop = toplevel;
00232
00233 CreateLevel(0);
00234
00235 currentlevel = GetLevel(0);
00236
00237 if (!currentlevel)
00238 {
00239 cerr << "Something is seriously wrong (currentlevel = NULL)\n";
00240 return;
00241 }
00242
00243 FillLevelFromTree(toplevel, currentlevel);
00244
00245 currentlevel->SetVisible(true);
00246 currentlevel->SetActive(true);
00247
00248 currentpos = (UIListGenericTree *)(currentlevel->GetItemFirst()->getData());
00249 curlevel = 0;
00250
00251 emit requestUpdate();
00252 emit itemEntered(this, currentpos);
00253 }
00254
00255 void UIListTreeType::CreateLevel(int level)
00256 {
00257 if (level > levels)
00258 {
00259 int oldlevels = levels + 1;
00260 levels = level;
00261 for (int i = oldlevels; i <= levels; i++)
00262 {
00263 QString levelname = QString("level%1").arg(i + 1);
00264
00265 QRect curlevelarea = m_levelsize;
00266 curlevelarea.moveBy(m_totalarea.x(), m_totalarea.y());
00267 curlevelarea.moveBy((m_levelsize.width() + m_levelspacing) * i, 0);
00268
00269 UIListBtnType *newlevel = new UIListBtnType(levelname, curlevelarea,
00270 m_order, false, true);
00271
00272 newlevel->SetFontActive(m_active);
00273 newlevel->SetFontInactive(m_inactive);
00274 newlevel->SetItemRegColor(m_itemRegBeg, m_itemRegEnd,
00275 m_itemRegAlpha);
00276 newlevel->SetItemSelColor(m_itemSelBeg, m_itemSelEnd,
00277 m_itemSelAlpha);
00278 newlevel->SetSpacing(m_spacing);
00279 newlevel->SetMargin(m_margin);
00280 newlevel->SetParentListTree(this);
00281
00282 listLevels.append(newlevel);
00283 }
00284 }
00285 }
00286
00287 UIListGenericTree *UIListTreeType::GetCurrentPosition(void)
00288 {
00289 return currentpos;
00290 }
00291
00292 void UIListTreeType::Draw(QPainter *p, int order, int context)
00293 {
00294 if (hidden)
00295 {
00296 return;
00297 }
00298
00299 if (m_context != -1 && m_context != context)
00300 return;
00301
00302 if (m_order != order)
00303 return;
00304
00305 QPtrListIterator<UIListBtnType> it(listLevels);
00306 UIListBtnType *child;
00307
00308 int maxx = 0;
00309 while ((child = it.current()) != 0)
00310 {
00311 if (child->IsVisible())
00312 {
00313 maxx = child->GetArea().right();
00314 }
00315 ++it;
00316 }
00317
00318 it.toFirst();
00319 while ((child = it.current()) != 0)
00320 {
00321 if (!child->IsVisible())
00322 {
00323 break;
00324 }
00325
00326 int offset = 0;
00327 if (maxx > m_totalarea.right())
00328 {
00329 offset = -1 * (maxx - m_totalarea.right());
00330 }
00331
00332 child->SetDrawOffset(offset);
00333
00334 if (child->GetArea().right() + offset > m_totalarea.left())
00335 {
00336 child->Draw(p, order, context, list_tree_active);
00337 }
00338 ++it;
00339 }
00340 }
00341
00342 void UIListTreeType::DrawRegion(QPainter *p, QRect &area, int order, int context)
00343 {
00344 if (m_context != -1 && m_context != context)
00345 return;
00346
00347 QPtrListIterator<UIListBtnType> it(listLevels);
00348 UIListBtnType *child;
00349
00350 int maxx = 0;
00351 while ((child = it.current()) != 0)
00352 {
00353 if (child->IsVisible())
00354 maxx = child->GetArea().right();
00355 ++it;
00356 }
00357
00358 it.toFirst();
00359 while ((child = it.current()) != 0)
00360 {
00361 if (!child->IsVisible())
00362 break;
00363
00364 int offset = 0;
00365 if (maxx > m_totalarea.right())
00366 offset = -1 * (maxx - m_totalarea.right());
00367 child->SetDrawOffset(offset);
00368
00369 QRect drawRect = child->GetArea();
00370 drawRect.moveBy(offset, 0);
00371 drawRect.moveBy(m_parent->GetAreaRect().x(),
00372 m_parent->GetAreaRect().y());
00373
00374 if (child->GetArea().right() + offset > m_totalarea.left() &&
00375 drawRect == area)
00376 {
00377 child->SetDrawOffset(0 - child->GetArea().x());
00378 child->Draw(p, order, context, list_tree_active);
00379 child->SetDrawOffset(offset);
00380 }
00381
00382 ++it;
00383 }
00384 }
00385
00386 void UIListTreeType::ClearLevel(UIListBtnType *list)
00387 {
00388 UIListBtnTypeItem *clear = list->GetItemFirst();
00389 while (clear)
00390 {
00391 UIListGenericTree *gt = (UIListGenericTree *)clear->getData();
00392 gt->setItem(NULL);
00393 clear = list->GetItemNext(clear);
00394 }
00395
00396 list->Reset();
00397 }
00398
00399 void UIListTreeType::RefreshCurrentLevel(void)
00400 {
00401 if (currentlevel)
00402 {
00403 QPtrListIterator<UIListBtnTypeItem> it = currentlevel->GetIterator();
00404
00405 UIListBtnTypeItem *item;
00406 while ((item = it.current()))
00407 {
00408 UIListGenericTree *ui = (UIListGenericTree *)item->getData();
00409 ui->setActive(ui->getActive());
00410 ++it;
00411 }
00412 }
00413 }
00414
00415 void UIListTreeType::FillLevelFromTree(UIListGenericTree *item,
00416 UIListBtnType *list)
00417 {
00418 if (!item || !list)
00419 return;
00420
00421 ClearLevel(list);
00422
00423 QPtrList<GenericTree> *itemlist = item->getAllChildren();
00424
00425 QPtrListIterator<GenericTree> it(*itemlist);
00426 GenericTree *child;
00427
00428 while ((child = it.current()) != 0)
00429 {
00430 UIListGenericTree *uichild = (UIListGenericTree *)child;
00431
00432 UIListBtnTypeItem *newitem;
00433
00434 int check = uichild->getCheck();
00435 newitem = new UIListBtnTypeItem(list, child->getString(),
00436 uichild->getImage(), (check >= 0),
00437 (UIListBtnTypeItem::CheckState)check,
00438 (child->childCount() > 0));
00439 newitem->setData(uichild);
00440
00441 uichild->setItem(newitem);
00442
00443 if (!uichild->getActive())
00444 newitem->setOverrideInactive(true);
00445
00446 ++it;
00447 }
00448 }
00449
00450 UIListBtnType *UIListTreeType::GetLevel(int levelnum)
00451 {
00452 if ((uint)levelnum > listLevels.count())
00453 {
00454 cerr << "OOB GetLevel call\n";
00455 return NULL;
00456 }
00457
00458 return listLevels.at(levelnum);
00459 }
00460
00461 void UIListTreeType::SetCurrentPosition(void)
00462 {
00463 if (!currentlevel)
00464 return;
00465
00466 UIListBtnTypeItem *lbt = currentlevel->GetItemCurrent();
00467
00468 if (!lbt)
00469 return;
00470
00471 currentpos = (UIListGenericTree *)(lbt->getData());
00472 emit itemEntered(this, currentpos);
00473 }
00474
00475 void UIListTreeType::Redraw(void)
00476 {
00477 if (!currentlevel)
00478 {
00479 return;
00480 }
00481 if (currentlevel->GetCount() == 0)
00482 MoveLeft();
00483 else
00484 emit requestUpdate();
00485 }
00486
00487 void UIListTreeType::RedrawCurrent(void)
00488 {
00489 if (!currentlevel)
00490 {
00491 return;
00492 }
00493 QRect dr = currentlevel->GetArea();
00494 dr.moveBy(currentlevel->GetDrawOffset(), 0);
00495 dr.moveBy(m_parent->GetAreaRect().x(), m_parent->GetAreaRect().y());
00496
00497 emit requestRegionUpdate(dr);
00498 }
00499
00500 void UIListTreeType::MoveDown(MovementUnit unit)
00501 {
00502 if (!currentlevel)
00503 {
00504 return;
00505 }
00506 currentlevel->MoveDown((UIListBtnType::MovementUnit)unit);
00507 SetCurrentPosition();
00508 RedrawCurrent();
00509 }
00510
00511 void UIListTreeType::MoveDown(int count)
00512 {
00513 if (!currentlevel)
00514 {
00515 return;
00516 }
00517 currentlevel->MoveDown(count);
00518 SetCurrentPosition();
00519 RedrawCurrent();
00520 }
00521
00522 void UIListTreeType::MoveUp(MovementUnit unit)
00523 {
00524 if (!currentlevel)
00525 {
00526 return;
00527 }
00528 currentlevel->MoveUp((UIListBtnType::MovementUnit)unit);
00529 SetCurrentPosition();
00530 RedrawCurrent();
00531 }
00532
00533 void UIListTreeType::MoveUp(int count)
00534 {
00535 if (!currentlevel)
00536 {
00537 return;
00538 }
00539 currentlevel->MoveUp(count);
00540 SetCurrentPosition();
00541 RedrawCurrent();
00542 }
00543
00544 void UIListTreeType::MoveLeft(bool do_refresh)
00545 {
00546 if (!currentlevel)
00547 {
00548 return;
00549 }
00550 if (curlevel > 0)
00551 {
00552 ClearLevel(currentlevel);
00553 currentlevel->SetVisible(false);
00554
00555 curlevel--;
00556
00557 currentlevel = GetLevel(curlevel);
00558 currentlevel->SetActive(true);
00559 SetCurrentPosition();
00560
00561 if (do_refresh)
00562 {
00563 Redraw();
00564 }
00565 }
00566 }
00567
00568 bool UIListTreeType::MoveRight(bool do_refresh)
00569 {
00570 if (!currentpos || !currentlevel)
00571 {
00572 return true;
00573 }
00574 if (currentpos->childCount() > 0)
00575 {
00576 currentlevel->SetActive(false);
00577
00578 curlevel++;
00579
00580 CreateLevel(curlevel);
00581
00582 currentlevel = GetLevel(curlevel);
00583
00584 FillLevelFromTree(currentpos, currentlevel);
00585
00586 currentlevel->SetVisible(true);
00587 currentlevel->SetActive(true);
00588 SetCurrentPosition();
00589
00590 if (do_refresh)
00591 {
00592 Redraw();
00593 }
00594
00595 return true;
00596 }
00597
00598 return false;
00599 }
00600
00601 void UIListTreeType::calculateScreenArea()
00602 {
00603 QRect r = m_totalarea;
00604 r.moveBy(m_parent->GetAreaRect().left(),
00605 m_parent->GetAreaRect().top());
00606 screen_area = r;
00607
00608 }
00609
00610 void UIListTreeType::GoHome()
00611 {
00612
00613 while(curlevel > 0)
00614 {
00615 MoveLeft(false);
00616 }
00617 MoveUp(MoveMax);
00618 Redraw();
00619 }
00620
00621 void UIListTreeType::select()
00622 {
00623 if (currentpos)
00624 {
00625 emit selected(currentpos);
00626 emit itemSelected(this, currentpos);
00627 }
00628 }
00629
00630 QStringList UIListTreeType::getRouteToCurrent()
00631 {
00632
00633
00634
00635
00636
00637 QStringList route_to_current;
00638 if (currentpos)
00639 {
00640 GenericTree *climber = currentpos;
00641 route_to_current.push_front(climber->getString());
00642 while( (climber = climber->getParent()) )
00643 {
00644 route_to_current.push_front(climber->getString());
00645 }
00646 }
00647 return route_to_current;
00648 }
00649
00650 bool UIListTreeType::tryToSetCurrent(QStringList route)
00651 {
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666 while(curlevel > 0)
00667 {
00668 MoveLeft(false);
00669 }
00670
00671
00672
00673
00674
00675 if (route.count() < 2)
00676 {
00677 return false;
00678 }
00679
00680
00681
00682
00683
00684 if (!currentpos || !currentlevel)
00685 {
00686 return false;
00687 }
00688
00689
00690
00691
00692
00693 if (currentpos->getParent()->getString() != route[0])
00694 {
00695 return false;
00696 }
00697
00698
00699
00700
00701
00702 GenericTree *first_child = currentpos->getParent()->getChildByName(route[1]);
00703 if (!first_child)
00704 {
00705 return false;
00706 }
00707 else
00708 {
00709 currentpos = (UIListGenericTree *)first_child;
00710 currentlevel->MoveToNamedPosition(currentpos->getString());
00711 }
00712
00713
00714
00715
00716
00717
00718 bool keep_going = true;
00719 QStringList::Iterator it = route.begin();
00720 ++it;
00721 ++it;
00722 while(keep_going && it != route.end())
00723 {
00724 GenericTree *next_child = currentpos->getChildByName(*it);
00725 if (next_child)
00726 {
00727 MoveRight(false);
00728 currentpos = (UIListGenericTree *)next_child;
00729 if (!currentlevel->MoveToNamedPosition(currentpos->getString()))
00730 {
00731 cerr << "uilistbtntype.o: had problem finding "
00732 << "something it knows is there"
00733 << endl;
00734 keep_going = false;
00735 }
00736 }
00737 else
00738 {
00739 keep_going = false;
00740
00741
00742
00743
00744
00745 MoveRight(false);
00746 }
00747 ++it;
00748 }
00749
00750 return keep_going;
00751 }
00752
00753 bool UIListTreeType::incSearchStart(void)
00754 {
00755 bool res = currentlevel->incSearchStart();
00756
00757 if (res)
00758 {
00759 SetCurrentPosition();
00760 RedrawCurrent();
00761 }
00762 return (res);
00763 }
00764
00765 bool UIListTreeType::incSearchNext(void)
00766 {
00767 bool res = currentlevel->incSearchNext();
00768
00769 if (res)
00770 {
00771 SetCurrentPosition();
00772 RedrawCurrent();
00773 }
00774 return (res);
00775 }
00776
00777 int UIListTreeType::getDepth()
00778 {
00779 return curlevel;
00780 }
00781
00782 void UIListTreeType::setActive(bool x)
00783 {
00784 list_tree_active = x;
00785 Redraw();
00786 }
00787
00788 void UIListTreeType::enter()
00789 {
00790 if (currentpos)
00791 {
00792 emit itemEntered(this, currentpos);
00793 }
00794 }
00795
00796 void UIListTreeType::moveAwayFrom(UIListGenericTree *node)
00797 {
00798 if (!currentpos || !node)
00799 {
00800 return;
00801 }
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811 if (currentpos == node)
00812 {
00813 GenericTree *sibling = node->prevSibling(1);
00814 if (sibling)
00815 {
00816 if (UIListGenericTree *ui_sibling = dynamic_cast<UIListGenericTree*>(sibling) )
00817 {
00818 currentpos = ui_sibling;
00819 return;
00820 }
00821 }
00822 sibling = node->nextSibling(1);
00823 if (sibling)
00824 {
00825 if (UIListGenericTree *ui_sibling = dynamic_cast<UIListGenericTree*>(sibling) )
00826 {
00827 currentpos = ui_sibling;
00828 return;
00829 }
00830 }
00831 currentpos = NULL;
00832 }
00833 }
00834
00835 int UIListTreeType::getNumbItemsVisible()
00836 {
00837 if (!currentlevel)
00838 {
00839 return 0;
00840 }
00841 return (int) currentlevel->GetNumbItemsVisible();
00842 }
00843
00844 bool UIListTreeType::takeFocus()
00845 {
00846 setActive(true);
00847 return UIType::takeFocus();
00848 }
00849
00850 void UIListTreeType::looseFocus()
00851 {
00852 setActive(false);
00853 UIType::looseFocus();
00854 }
00855
00857
00858 UIListBtnType::UIListBtnType(const QString& name, const QRect& area,
00859 int order, bool showArrow, bool showScrollArrows)
00860 : UIType(name)
00861 {
00862 m_parentListTree = NULL;
00863 m_order = order;
00864 m_rect = area;
00865
00866 m_showArrow = showArrow;
00867 m_showScrollArrows = showScrollArrows;
00868
00869 m_active = false;
00870 m_visible = true;
00871 takes_focus = true;
00872 m_showUpArrow = false;
00873 m_showDnArrow = false;
00874
00875 m_itemList.setAutoDelete(false);
00876 m_topItem = 0;
00877 m_selItem = 0;
00878 m_selIterator = new QPtrListIterator<UIListBtnTypeItem>(m_itemList);
00879 m_topIterator = new QPtrListIterator<UIListBtnTypeItem>(m_itemList);
00880 m_selPosition = 0;
00881 m_topPosition = 0;
00882 m_itemCount = 0;
00883 m_incSearch = "";
00884 m_bIncSearchContains = false;
00885
00886 m_initialized = false;
00887 m_clearing = false;
00888 m_itemSpacing = 0;
00889 m_itemMargin = 0;
00890 m_itemHeight = 0;
00891 m_itemsVisible = 0;
00892 m_fontActive = 0;
00893 m_fontInactive = 0;
00894 m_justify = Qt::AlignLeft | Qt::AlignVCenter;
00895
00896 m_xdrawoffset = 0;
00897
00898 SetItemRegColor(Qt::black,QColor(80,80,80),100);
00899 SetItemSelColor(QColor(82,202,56),QColor(52,152,56),255);
00900 }
00901
00902 UIListBtnType::~UIListBtnType()
00903 {
00904 Reset();
00905 delete m_topIterator;
00906 delete m_selIterator;
00907 }
00908
00909 void UIListBtnType::SetItemRegColor(const QColor& beg,
00910 const QColor& end,
00911 uint alpha)
00912 {
00913 m_itemRegBeg = beg;
00914 m_itemRegEnd = end;
00915 m_itemRegAlpha = alpha;
00916 }
00917
00918 void UIListBtnType::SetItemSelColor(const QColor& beg,
00919 const QColor& end,
00920 uint alpha)
00921 {
00922 m_itemSelBeg = beg;
00923 m_itemSelEnd = end;
00924 m_itemSelAlpha = alpha;
00925 }
00926
00927 void UIListBtnType::SetFontActive(fontProp *font)
00928 {
00929 m_fontActive = font;
00930 }
00931
00932 void UIListBtnType::SetFontInactive(fontProp *font)
00933 {
00934 m_fontInactive = font;
00935 }
00936
00937 void UIListBtnType::SetSpacing(int spacing)
00938 {
00939 m_itemSpacing = spacing;
00940 }
00941
00942 void UIListBtnType::SetMargin(int margin)
00943 {
00944 m_itemMargin = margin;
00945 }
00946
00947 void UIListBtnType::SetActive(bool active)
00948 {
00949 m_active = active;
00950 }
00951
00952 void UIListBtnType::Reset()
00953 {
00954 m_clearing = true;
00955
00956 UIListBtnTypeItem* item = 0;
00957 for (item = m_itemList.first(); item; item = m_itemList.next()) {
00958 delete item;
00959 }
00960
00961 m_clearing = false;
00962 m_itemList.clear();
00963
00964 m_topItem = 0;
00965 m_selItem = 0;
00966 m_selPosition = 0;
00967 m_topPosition = 0;
00968 m_itemCount = 0;
00969 m_selIterator->toFirst();
00970 m_topIterator->toFirst();
00971
00972 m_showUpArrow = false;
00973 m_showDnArrow = false;
00974 }
00975
00976 void UIListBtnType::InsertItem(UIListBtnTypeItem *item)
00977 {
00978 UIListBtnTypeItem* lastItem = m_itemList.last();
00979 m_itemList.append(item);
00980
00981 m_itemCount++;
00982
00983 if (m_showScrollArrows && m_itemCount > (int)m_itemsVisible)
00984 m_showDnArrow = true;
00985 else
00986 m_showDnArrow = false;
00987
00988 if (!lastItem)
00989 {
00990 m_topItem = item;
00991 m_selItem = item;
00992 m_selIterator->toFirst();
00993 m_topIterator->toFirst();
00994 m_selPosition = m_topPosition = 0;
00995 emit itemSelected(item);
00996 }
00997 }
00998
00999 void UIListBtnType::RemoveItem(UIListBtnTypeItem *item)
01000 {
01001 if (m_clearing)
01002 return;
01003
01004 if (m_itemList.findRef(item) == -1)
01005 return;
01006
01007 if (item == m_topItem)
01008 {
01009 if (m_topItem != m_itemList.last())
01010 {
01011 ++(*m_topIterator);
01012 ++m_topPosition;
01013 m_topItem = m_topIterator->current();
01014 }
01015 else if (m_topItem != m_itemList.first())
01016 {
01017 --(*m_topIterator);
01018 --m_topPosition;
01019 m_topItem = m_topIterator->current();
01020 }
01021 else
01022 {
01023 m_topItem = NULL;
01024 m_topPosition = 0;
01025 m_topIterator->toFirst();
01026 }
01027 }
01028
01029 if (item == m_selItem)
01030 {
01031 if (m_selItem != m_itemList.last())
01032 {
01033 ++(*m_selIterator);
01034 ++m_selPosition;
01035 m_selItem = m_selIterator->current();
01036 }
01037 else if (m_selItem != m_itemList.first())
01038 {
01039 --(*m_selIterator);
01040 --m_selPosition;
01041 m_selItem = m_selIterator->current();
01042 }
01043 else
01044 {
01045 m_selItem = NULL;
01046 m_selPosition = 0;
01047 m_selIterator->toFirst();
01048 }
01049 }
01050
01051 m_itemList.remove(item);
01052 m_itemCount--;
01053
01054 if (m_topItem != m_itemList.first())
01055 m_showUpArrow = true;
01056 else
01057 m_showUpArrow = false;
01058
01059 if (m_topPosition + (int)m_itemsVisible < m_itemCount)
01060 m_showDnArrow = true;
01061 else
01062 m_showDnArrow = false;
01063
01064 if (m_selItem)
01065 emit itemSelected(m_selItem);
01066 }
01067
01068 void UIListBtnType::SetItemCurrent(UIListBtnTypeItem* item)
01069 {
01070 m_selIterator->toFirst();
01071 UIListBtnTypeItem *cur;
01072 bool found = false;
01073 m_selPosition = 0;
01074 while ((cur = m_selIterator->current()) != 0)
01075 {
01076 if (cur == item)
01077 {
01078 found = true;
01079 break;
01080 }
01081
01082 ++(*m_selIterator);
01083 ++m_selPosition;
01084 }
01085
01086 if (!found)
01087 {
01088 m_selIterator->toFirst();
01089 m_selPosition = 0;
01090 }
01091
01092 m_selItem = item;
01093 m_topItem = m_selItem;
01094 m_topPosition = m_selPosition;
01095 (*m_topIterator) = (*m_selIterator);
01096
01097
01098 int count = m_itemsVisible / 2;
01099
01100 while (count && m_topPosition > 0)
01101 {
01102 --(*m_topIterator);
01103 --m_topPosition;
01104 --count;
01105 }
01106
01107
01108 if (m_topPosition + (int)m_itemsVisible > m_itemCount)
01109 {
01110 while (m_topPosition > 0 && m_topPosition + (int)m_itemsVisible > m_itemCount)
01111 {
01112 --(*m_topIterator);
01113 --m_topPosition;
01114 }
01115 }
01116
01117 if (m_topIterator->current())
01118 m_topItem = m_topIterator->current();
01119 else
01120 {
01121 m_topItem = m_topIterator->toFirst();
01122 m_topPosition = 0;
01123 }
01124
01125 if (m_topItem != m_itemList.first())
01126 m_showUpArrow = true;
01127 else
01128 m_showUpArrow = false;
01129
01130 if (m_topPosition + (int)m_itemsVisible < m_itemCount)
01131 m_showDnArrow = true;
01132 else
01133 m_showDnArrow = false;
01134
01135 emit itemSelected(m_selItem);
01136 }
01137
01138 void UIListBtnType::SetItemCurrent(int current)
01139 {
01140 UIListBtnTypeItem* item = m_itemList.at(current);
01141 if (!item)
01142 item = m_itemList.first();
01143
01144 SetItemCurrent(item);
01145 }
01146
01147 UIListBtnTypeItem* UIListBtnType::GetItemCurrent()
01148 {
01149 return m_selItem;
01150 }
01151
01152 UIListBtnTypeItem* UIListBtnType::GetItemFirst()
01153 {
01154 return m_itemList.first();
01155 }
01156
01157 UIListBtnTypeItem* UIListBtnType::GetItemNext(UIListBtnTypeItem *item)
01158 {
01159 if (m_itemList.findRef(item) == -1)
01160 return 0;
01161
01162 return m_itemList.next();
01163 }
01164
01165 int UIListBtnType::GetCount()
01166 {
01167 return m_itemCount;
01168 }
01169
01170 QPtrListIterator<UIListBtnTypeItem> UIListBtnType::GetIterator(void)
01171 {
01172 return QPtrListIterator<UIListBtnTypeItem>(m_itemList);
01173 }
01174
01175 UIListBtnTypeItem* UIListBtnType::GetItemAt(int pos)
01176 {
01177 return m_itemList.at(pos);
01178 }
01179
01180 int UIListBtnType::GetItemPos(UIListBtnTypeItem* item)
01181 {
01182 return m_itemList.findRef(item);
01183 }
01184
01185 void UIListBtnType::MoveUp(MovementUnit unit)
01186 {
01187 int pos = m_selPosition;
01188 if (pos == -1)
01189 return;
01190
01191 switch (unit)
01192 {
01193 case MoveItem:
01194 if (!m_selIterator->atFirst())
01195 {
01196 --(*m_selIterator);
01197 --m_selPosition;
01198 }
01199 break;
01200 case MovePage:
01201 if (pos > (int)m_itemsVisible)
01202 {
01203 for (int i = 0; i < (int)m_itemsVisible; i++)
01204 {
01205 --(*m_selIterator);
01206 --m_selPosition;
01207 }
01208 break;
01209 }
01210
01211 case MoveMax:
01212 m_selIterator->toFirst();
01213 m_selPosition = 0;
01214 break;
01215 }
01216
01217 if (!m_selIterator->current())
01218 return;
01219
01220 m_selItem = m_selIterator->current();
01221
01222 if (m_selPosition <= m_topPosition)
01223 {
01224 m_topItem = m_selItem;
01225 (*m_topIterator) = (*m_selIterator);
01226 m_topPosition = m_selPosition;
01227 }
01228
01229 if (m_topItem != m_itemList.first())
01230 m_showUpArrow = true;
01231 else
01232 m_showUpArrow = false;
01233
01234 if (m_topPosition + (int)m_itemsVisible < m_itemCount)
01235 m_showDnArrow = true;
01236 else
01237 m_showDnArrow = false;
01238
01239 emit itemSelected(m_selItem);
01240 }
01241
01242 void UIListBtnType::MoveUp(int count)
01243 {
01244 int pos = m_selPosition;
01245 if (pos == -1)
01246 return;
01247
01248 if (pos > count)
01249 {
01250 for (int i = 0; i < count; i++)
01251 {
01252 --(*m_selIterator);
01253 --m_selPosition;
01254 }
01255 }
01256
01257 if (!m_selIterator->current())
01258 return;
01259
01260 m_selItem = m_selIterator->current();
01261
01262 if (m_selPosition <= m_topPosition)
01263 {
01264 m_topItem = m_selItem;
01265 (*m_topIterator) = (*m_selIterator);
01266 m_topPosition = m_selPosition;
01267 }
01268
01269 if (m_topItem != m_itemList.first())
01270 m_showUpArrow = true;
01271 else
01272 m_showUpArrow = false;
01273
01274 if (m_topPosition + (int)m_itemsVisible < m_itemCount)
01275 m_showDnArrow = true;
01276 else
01277 m_showDnArrow = false;
01278
01279 emit itemSelected(m_selItem);
01280 }
01281
01282 void UIListBtnType::MoveDown(MovementUnit unit)
01283 {
01284 int pos = m_selPosition;
01285 if (pos == -1)
01286 return;
01287
01288 switch (unit)
01289 {
01290 case MoveItem:
01291 if (!m_selIterator->atLast())
01292 {
01293 ++(*m_selIterator);
01294 ++m_selPosition;
01295 }
01296 break;
01297 case MovePage:
01298 if ((pos + (int)m_itemsVisible) < m_itemCount - 1)
01299 {
01300 for (int i = 0; i < (int)m_itemsVisible; i++)
01301 {
01302 ++(*m_selIterator);
01303 ++m_selPosition;
01304 }
01305 break;
01306 }
01307
01308 case MoveMax:
01309 m_selIterator->toLast();
01310 m_selPosition = m_itemCount - 1;
01311 break;
01312 }
01313
01314 if (!m_selIterator->current())
01315 return;
01316
01317 m_selItem = m_selIterator->current();
01318
01319 while (m_topPosition + (int)m_itemsVisible < m_selPosition + 1)
01320 {
01321 ++(*m_topIterator);
01322 ++m_topPosition;
01323 }
01324
01325 m_topItem = m_topIterator->current();
01326
01327 if (m_topItem != m_itemList.first())
01328 m_showUpArrow = true;
01329 else
01330 m_showUpArrow = false;
01331
01332 if (m_topPosition + (int)m_itemsVisible < m_itemCount)
01333 m_showDnArrow = true;
01334 else
01335 m_showDnArrow = false;
01336
01337 emit itemSelected(m_selItem);
01338 }
01339
01340 void UIListBtnType::MoveDown(int count)
01341 {
01342 int pos = m_selPosition;
01343 if (pos == -1)
01344 return;
01345
01346 if ((pos + count) < m_itemCount - 1)
01347 {
01348 for (int i = 0; i < count; i++)
01349 {
01350 ++(*m_selIterator);
01351 ++m_selPosition;
01352 }
01353 }
01354
01355 if (!m_selIterator->current())
01356 return;
01357
01358 m_selItem = m_selIterator->current();
01359
01360 while (m_topPosition + (int)m_itemsVisible < m_selPosition + 1)
01361 {
01362 ++(*m_topIterator);
01363 ++m_topPosition;
01364 }
01365
01366 m_topItem = m_topIterator->current();
01367
01368 if (m_topItem != m_itemList.first())
01369 m_showUpArrow = true;
01370 else
01371 m_showUpArrow = false;
01372
01373 if (m_topPosition + (int)m_itemsVisible < m_itemCount)
01374 m_showDnArrow = true;
01375 else
01376 m_showDnArrow = false;
01377
01378 emit itemSelected(m_selItem);
01379 }
01380
01381 bool UIListBtnType::MoveToNamedPosition(const QString &position_name)
01382 {
01383 if (m_selPosition < 0)
01384 {
01385 return false;
01386 }
01387
01388 if (!m_selIterator->toFirst())
01389 {
01390 return false;
01391 }
01392 m_selPosition = 0;
01393
01394 bool found_it = false;
01395 while(m_selIterator->current())
01396 {
01397 if (m_selIterator->current()->text() == position_name)
01398 {
01399 found_it = true;
01400 break;
01401 }
01402 ++(*m_selIterator);
01403 ++m_selPosition;
01404 }
01405
01406 if (!found_it)
01407 {
01408 m_selPosition = -1;
01409 return false;
01410 }
01411
01412 m_selItem = m_selIterator->current();
01413
01414 while (m_topPosition + (int)m_itemsVisible < m_selPosition + 1)
01415 {
01416 ++(*m_topIterator);
01417 ++m_topPosition;
01418 }
01419
01420 m_topItem = m_topIterator->current();
01421
01422 if (m_topItem != m_itemList.first())
01423 m_showUpArrow = true;
01424 else
01425 m_showUpArrow = false;
01426
01427 if (m_topPosition + (int)m_itemsVisible < m_itemCount)
01428 m_showDnArrow = true;
01429 else
01430 m_showDnArrow = false;
01431
01432 return true;
01433 }
01434
01435 bool UIListBtnType::MoveItemUpDown(UIListBtnTypeItem *item, bool flag)
01436 {
01437 if (item != m_selItem)
01438 {
01439 cerr << "Can't move non-selected item\n";
01440 return false;
01441 }
01442
01443 if (item == m_itemList.getFirst() && flag)
01444 return false;
01445 if (item == m_itemList.getLast() && !flag)
01446 return false;
01447
01448 int oldpos = m_selPosition;
01449 int insertat = 0;
01450 bool dolast = false;
01451
01452 if (flag)
01453 {
01454 insertat = m_selPosition - 1;
01455 if (item == m_itemList.getLast())
01456 dolast = true;
01457 else
01458 ++m_selPosition;
01459
01460 if (item == m_topItem)
01461 ++m_topPosition;
01462 }
01463 else
01464 insertat = m_selPosition + 1;
01465
01466 if (m_itemList.current() == item)
01467 {
01468 m_itemList.take();
01469
01470 }
01471 else
01472 m_itemList.take(oldpos);
01473
01474 m_itemList.insert(insertat, item);
01475
01476 if (flag)
01477 {
01478 MoveUp();
01479 if (!dolast)
01480 MoveUp();
01481 }
01482 else
01483 MoveDown();
01484
01485 return true;
01486 }
01487
01488 bool UIListBtnType::incSearchStart(void)
01489 {
01490 MythPopupBox *popup = new MythPopupBox(gContext->GetMainWindow(),
01491 "incserach_popup");
01492
01493 QLabel *caption = popup->addLabel(tr("Search"), MythPopupBox::Large);
01494 caption->setAlignment(Qt::AlignCenter);
01495
01496 MythComboBox *modeCombo = new MythComboBox(false, popup, "mode_combo" );
01497 modeCombo->insertItem(tr("Starts with text"));
01498 modeCombo->insertItem(tr("Contains text"));
01499 popup->addWidget(modeCombo);
01500
01501 MythLineEdit *searchEdit = new MythLineEdit(false, popup, "mode_combo");
01502 searchEdit->setText(m_incSearch);
01503 popup->addWidget(searchEdit);
01504 searchEdit->setFocus();
01505
01506 popup->addButton(tr("Search"));
01507 popup->addButton(tr("Cancel"), popup, SLOT(reject()));
01508
01509 DialogCode res = popup->ExecPopup();
01510
01511 if (kDialogCodeButton0 == res)
01512 {
01513 m_incSearch = searchEdit->text();
01514 m_bIncSearchContains = (modeCombo->currentItem() == 1);
01515 incSearchNext();
01516 }
01517
01518 popup->hide();
01519 popup->deleteLater();
01520
01521 return (kDialogCodeButton0 == res);
01522 }
01523
01524 bool UIListBtnType::incSearchNext(void)
01525 {
01526 if (!m_selItem)
01527 {
01528 return false;
01529 }
01530
01531
01532
01533
01534
01535
01536 QPtrListIterator<UIListBtnTypeItem> it = (*m_selIterator);
01537 ++it;
01538
01539 while (it.current())
01540 {
01541 if (m_bIncSearchContains)
01542 {
01543 if (it.current()->text().find(m_incSearch, 0, false) != -1)
01544 break;
01545 }
01546 else
01547 {
01548 if (it.current()->text().startsWith(m_incSearch, false))
01549 break;
01550 }
01551
01552 ++it;
01553 }
01554
01555
01556
01557 if (!it.current())
01558 {
01559 it.toFirst();
01560
01561 while (it.current())
01562 {
01563
01564
01565 if (it.current() == m_selItem)
01566 {
01567 break;
01568 }
01569
01570 if (m_bIncSearchContains)
01571 {
01572 if (it.current()->text().find(m_incSearch, 0, false) != -1)
01573 break;
01574 }
01575 else
01576 {
01577 if (it.current()->text().startsWith(m_incSearch, false))
01578 break;
01579 }
01580
01581 ++it;
01582 }
01583 }
01584
01585 if (it.current())
01586 {
01587 SetItemCurrent(it.current());
01588 return true;
01589 }
01590
01591 return false;
01592 }
01593
01594 void UIListBtnType::Draw(QPainter *p, int order, int context)
01595 {
01596
01597
01598
01599
01600
01601 Draw(p, order, context, true);
01602 }
01603
01604
01605 void UIListBtnType::Draw(QPainter *p, int order, int context, bool active_on)
01606 {
01607 if (!m_visible || hidden)
01608 return;
01609
01610 if (!m_initialized)
01611 Init();
01612
01613 if (m_order != order)
01614 return;
01615
01616 if (m_context != -1 && m_context != context)
01617 return;
01618
01619
01620 if (class LCD *lcddev = LCD::Get())
01621 {
01622 if (m_active)
01623 {
01624
01625
01626
01627 QPtrList<LCDMenuItem> menuItems;
01628 menuItems.setAutoDelete(true);
01629
01630 QPtrListIterator<UIListBtnTypeItem> it = (*m_selIterator);
01631 uint count = 0;
01632
01633
01634 while (it.current() && count < lcddev->getLCDHeight())
01635 {
01636 --it;
01637 ++count;
01638 }
01639
01640 if (!it.current())
01641 it.toFirst();
01642 count = 0;
01643 while (it.current() && count < lcddev->getLCDHeight() * 2)
01644 {
01645 UIListBtnTypeItem *curItem = it.current();
01646 QString msg = curItem->text();
01647 bool selected;
01648 CHECKED_STATE checkState = NOTCHECKABLE;
01649 if (curItem->checkable())
01650 {
01651 if (curItem->state() == UIListBtnTypeItem::HalfChecked ||
01652 curItem->state() == UIListBtnTypeItem::FullChecked)
01653 checkState = CHECKED;
01654 else
01655 checkState = UNCHECKED;
01656 }
01657
01658 if (curItem == m_selItem)
01659 selected = true;
01660 else
01661 selected = false;
01662
01663 menuItems.append(new LCDMenuItem(selected, checkState, msg));
01664 ++it;
01665 ++count;
01666 }
01667
01668 QString title = "";
01669
01670 if (m_parentListTree && m_parentListTree->getDepth() > 0)
01671 title = "<< ";
01672 else
01673 title = " ";
01674
01675 if ((m_selItem && m_selItem->getDrawArrow()) || m_showArrow)
01676 title += " >>";
01677 else
01678 title += " ";
01679
01680 if (!menuItems.isEmpty())
01681 {
01682 lcddev->switchToMenu(&menuItems, title);
01683 }
01684 }
01685 }
01686
01687 fontProp* font = m_active ? m_fontActive : m_fontInactive;
01688
01689 if (!active_on)
01690 {
01691 font = m_fontInactive;
01692 }
01693
01694 p->setFont(font->face);
01695 p->setPen(font->color);
01696
01697 int x = m_rect.x() + m_xdrawoffset;
01698
01699 int y = m_rect.y();
01700 QPtrListIterator<UIListBtnTypeItem> it = (*m_topIterator);
01701 while (it.current() &&
01702 (y - m_rect.y()) <= (m_contentsRect.height() - m_itemHeight))
01703 {
01704 if (active_on && it.current()->getOverrideInactive())
01705 {
01706 font = m_fontInactive;
01707 p->setFont(font->face);
01708 p->setPen(font->color);
01709 it.current()->setJustification(m_justify);
01710 it.current()->paint(p, font, x, y, active_on);
01711 font = m_active ? m_fontActive : m_fontInactive;;
01712 p->setFont(font->face);
01713 p->setPen(font->color);
01714 }
01715 else
01716 {
01717 it.current()->setJustification(m_justify);
01718 it.current()->paint(p, font, x, y, active_on);
01719 }
01720
01721 y += m_itemHeight + m_itemSpacing;
01722
01723 ++it;
01724 }
01725
01726 if (m_showScrollArrows)
01727 {
01728 if (m_showUpArrow)
01729 p->drawPixmap(x + m_arrowsRect.x(),
01730 m_rect.y() + m_arrowsRect.y(),
01731 m_upArrowActPix);
01732 else
01733 p->drawPixmap(x + m_arrowsRect.x(),
01734 m_rect.y() + m_arrowsRect.y(),
01735 m_upArrowRegPix);
01736 if (m_showDnArrow)
01737 p->drawPixmap(x + m_arrowsRect.x() +
01738 m_upArrowRegPix.width() + m_itemMargin,
01739 m_rect.y() + m_arrowsRect.y(),
01740 m_dnArrowActPix);
01741 else
01742 p->drawPixmap(x + m_arrowsRect.x() +
01743 m_upArrowRegPix.width() + m_itemMargin,
01744 m_rect.y() + m_arrowsRect.y(),
01745 m_dnArrowRegPix);
01746 }
01747
01748 }
01749
01750 void UIListBtnType::Init()
01751 {
01752 QFontMetrics fm(m_fontActive->face);
01753 QSize sz1 = fm.size(Qt::SingleLine, "XXXXX");
01754 fm = QFontMetrics(m_fontInactive->face);
01755 QSize sz2 = fm.size(Qt::SingleLine, "XXXXX");
01756 m_itemHeight = QMAX(sz1.height(), sz2.height()) + (int)(2 * m_itemMargin);
01757
01758 if (m_showScrollArrows)
01759 {
01760 LoadPixmap(m_upArrowRegPix, "uparrow-reg");
01761 LoadPixmap(m_upArrowActPix, "uparrow-sel");
01762 LoadPixmap(m_dnArrowRegPix, "dnarrow-reg");
01763 LoadPixmap(m_dnArrowActPix, "dnarrow-sel");
01764
01765 m_arrowsRect = QRect(0, m_rect.height() - m_upArrowActPix.height() - 1,
01766 m_rect.width(), m_upArrowActPix.height());
01767 }
01768 else
01769 m_arrowsRect = QRect(0, 0, 0, 0);
01770
01771 m_contentsRect = QRect(0, 0, m_rect.width(), m_rect.height() -
01772 m_arrowsRect.height() - 2 * m_itemMargin);
01773
01774 m_itemsVisible = 0;
01775 int y = 0;
01776 while (y <= m_contentsRect.height() - m_itemHeight)
01777 {
01778 y += m_itemHeight + m_itemSpacing;
01779 m_itemsVisible++;
01780 }
01781
01782 LoadPixmap(m_checkNonePix, "check-empty");
01783 LoadPixmap(m_checkHalfPix, "check-half");
01784 LoadPixmap(m_checkFullPix, "check-full");
01785
01786 LoadPixmap(m_arrowPix, "arrow");
01787
01788 QImage img(m_rect.width(), m_itemHeight, 32);
01789 img.setAlphaBuffer(true);
01790
01791 for (int y = 0; y < img.height(); y++)
01792 {
01793 for (int x = 0; x < img.width(); x++)
01794 {
01795 uint *p = (uint *)img.scanLine(y) + x;
01796 *p = qRgba(0, 0, 0, m_itemRegAlpha);
01797 }
01798 }
01799
01800 {
01801 float rstep = float(m_itemRegEnd.red() - m_itemRegBeg.red()) /
01802 float(m_itemHeight);
01803 float gstep = float(m_itemRegEnd.green() - m_itemRegBeg.green()) /
01804 float(m_itemHeight);
01805 float bstep = float(m_itemRegEnd.blue() - m_itemRegBeg.blue()) /
01806 float(m_itemHeight);
01807
01808 m_itemRegPix = QPixmap(img);
01809 QPainter p(&m_itemRegPix);
01810
01811 float r = m_itemRegBeg.red();
01812 float g = m_itemRegBeg.green();
01813 float b = m_itemRegBeg.blue();
01814 for (int y = 0; y < img.height(); y++)
01815 {
01816 QColor c((int)r, (int)g, (int)b);
01817 p.setPen(c);
01818 p.drawLine(0, y, img.width(), y);
01819 r += rstep;
01820 g += gstep;
01821 b += bstep;
01822 }
01823 p.setPen(black);
01824 p.drawLine(0, 0, 0, img.height() - 1);
01825 p.drawLine(0, 0, img.width() - 1, 0);
01826 p.drawLine(0, img.height() - 1, img.width() - 1, img.height() - 1);
01827 p.drawLine(img.width() - 1, 0, img.width() - 1, img.height() - 1);
01828 p.end();
01829 }
01830
01831 {
01832 float rstep = float(m_itemSelEnd.red() - m_itemSelBeg.red()) /
01833 float(m_itemHeight);
01834 float gstep = float(m_itemSelEnd.green() - m_itemSelBeg.green()) /
01835 float(m_itemHeight);
01836 float bstep = float(m_itemSelEnd.blue() - m_itemSelBeg.blue()) /
01837 float(m_itemHeight);
01838
01839 m_itemSelInactPix = QPixmap(img);
01840 QPainter p(&m_itemSelInactPix);
01841
01842 float r = m_itemSelBeg.red();
01843 float g = m_itemSelBeg.green();
01844 float b = m_itemSelBeg.blue();
01845 for (int y = 0; y < img.height(); y++)
01846 {
01847 QColor c((int)r, (int)g, (int)b);
01848 p.setPen(c);
01849 p.drawLine(0, y, img.width(), y);
01850 r += rstep;
01851 g += gstep;
01852 b += bstep;
01853 }
01854 p.setPen(black);
01855 p.drawLine(0, 0, 0, img.height() - 1);
01856 p.drawLine(0, 0, img.width() - 1, 0);
01857 p.drawLine(0, img.height() - 1, img.width() - 1, img.height() - 1);
01858 p.drawLine(img.width() - 1, 0, img.width() - 1, img.height() - 1);
01859 p.end();
01860
01861 img.setAlphaBuffer(false);
01862
01863 m_itemSelActPix = QPixmap(img);
01864 p.begin(&m_itemSelActPix);
01865
01866 r = m_itemSelBeg.red();
01867 g = m_itemSelBeg.green();
01868 b = m_itemSelBeg.blue();
01869 for (int y = 0; y < img.height(); y++)
01870 {
01871 QColor c((int)r, (int)g, (int)b);
01872 p.setPen(c);
01873 p.drawLine(0, y, img.width(), y);
01874 r += rstep;
01875 g += gstep;
01876 b += bstep;
01877 }
01878 p.setPen(black);
01879 p.drawLine(0, 0, 0, img.height() - 1);
01880 p.drawLine(0, 0, img.width() - 1, 0);
01881 p.drawLine(0, img.height() - 1, img.width() - 1, img.height() - 1);
01882 p.drawLine(img.width() - 1, 0, img.width() - 1, img.height() - 1);
01883 p.end();
01884
01885 }
01886
01887 if (m_itemList.count() > m_itemsVisible && m_showScrollArrows)
01888 m_showDnArrow = true;
01889 else
01890 m_showDnArrow = false;
01891
01892 m_initialized = true;
01893 }
01894
01895 void UIListBtnType::LoadPixmap(QPixmap& pix, const QString& fileName)
01896 {
01897 QString file = "lb-" + fileName + ".png";
01898
01899 QPixmap *p = gContext->LoadScalePixmap(file);
01900 if (p)
01901 {
01902 pix = *p;
01903 delete p;
01904 }
01905 }
01906
01907 void UIListBtnType::calculateScreenArea()
01908 {
01909 QRect r = m_rect;
01910 r.moveBy(m_parent->GetAreaRect().left(),
01911 m_parent->GetAreaRect().top());
01912 screen_area = r;
01913 }
01914
01915 bool UIListBtnType::takeFocus()
01916 {
01917 SetActive(true);
01918 return UIType::takeFocus();
01919 }
01920
01921 void UIListBtnType::looseFocus()
01922 {
01923 SetActive(false);
01924 UIType::looseFocus();
01925 }
01926
01928
01929 UIListBtnTypeItem::UIListBtnTypeItem(
01930 UIListBtnType *parent, const QString &text,
01931 QPixmap *pixmap, bool checkable,
01932 CheckState state, bool showArrow) :
01933 m_parent(parent), m_text(QDeepCopy<QString>(text)), m_pixmap(pixmap),
01934 m_checkable(checkable), m_state(state), m_data(NULL),
01935
01936 m_checkRect(0,0,0,0), m_pixmapRect(0,0,0,0),
01937 m_textRect(0,0,0,0), m_arrowRect(0,0,0,0),
01938
01939 m_showArrow(showArrow),
01940
01941 m_overrideInactive(false),
01942 m_justify(Qt::AlignLeft | Qt::AlignVCenter)
01943 {
01944 if (state >= NotChecked)
01945 m_checkable = true;
01946
01947 CalcDimensions();
01948
01949 m_parent->InsertItem(this);
01950 }
01951
01952 void UIListBtnTypeItem::CalcDimensions(void)
01953 {
01954 if (!m_parent->m_initialized)
01955 m_parent->Init();
01956
01957 int margin = m_parent->m_itemMargin;
01958 int width = m_parent->m_rect.width();
01959 int height = m_parent->m_itemHeight;
01960 bool arrow = false;
01961 if (m_parent->m_showArrow || m_showArrow)
01962 arrow = true;
01963
01964 QPixmap& checkPix = m_parent->m_checkNonePix;
01965 QPixmap& arrowPix = m_parent->m_arrowPix;
01966
01967 int cw = checkPix.width();
01968 int ch = checkPix.height();
01969 int aw = arrowPix.width();
01970 int ah = arrowPix.height();
01971 int pw = m_pixmap ? m_pixmap->width() : 0;
01972 int ph = m_pixmap ? m_pixmap->height() : 0;
01973
01974 if (m_checkable)
01975 m_checkRect = QRect(margin, (height - ch)/2, cw, ch);
01976 else
01977 m_checkRect = QRect(0,0,0,0);
01978
01979 if (arrow)
01980 m_arrowRect = QRect(width - aw - margin, (height - ah)/2,
01981 aw, ah);
01982 else
01983 m_arrowRect = QRect(0,0,0,0);
01984
01985 if (m_pixmap)
01986 m_pixmapRect = QRect(m_checkable ? (2*margin + m_checkRect.width()) :
01987 margin, (height - ph)/2,
01988 pw, ph);
01989 else
01990 m_pixmapRect = QRect(0,0,0,0);
01991
01992 m_textRect = QRect(margin +
01993 (m_checkable ? m_checkRect.width() + margin : 0) +
01994 (m_pixmap ? m_pixmapRect.width() + margin : 0),
01995 0,
01996 width - 2*margin -
01997 (m_checkable ? m_checkRect.width() + margin : 0) -
01998 (arrow ? m_arrowRect.width() + margin : 0) -
01999 (m_pixmap ? m_pixmapRect.width() + margin : 0),
02000 height);
02001 }
02002
02003 UIListBtnTypeItem::~UIListBtnTypeItem()
02004 {
02005 if (m_parent)
02006 m_parent->RemoveItem(this);
02007 }
02008
02009 QString UIListBtnTypeItem::text() const
02010 {
02011 return m_text;
02012 }
02013
02014 void UIListBtnTypeItem::setText(const QString &text)
02015 {
02016 m_text = text;
02017 CalcDimensions();
02018 }
02019
02020 const QPixmap* UIListBtnTypeItem::pixmap() const
02021 {
02022 return m_pixmap;
02023 }
02024
02025 void UIListBtnTypeItem::setPixmap(QPixmap *pixmap)
02026 {
02027 m_pixmap = pixmap;
02028 CalcDimensions();
02029 }
02030
02031 bool UIListBtnTypeItem::checkable() const
02032 {
02033 return m_checkable;
02034 }
02035
02036 UIListBtnTypeItem::CheckState UIListBtnTypeItem::state() const
02037 {
02038 return m_state;
02039 }
02040
02041 UIListBtnType* UIListBtnTypeItem::parent() const
02042 {
02043 return m_parent;
02044 }
02045
02046 void UIListBtnTypeItem::setChecked(UIListBtnTypeItem::CheckState state)
02047 {
02048 if (!m_checkable)
02049 return;
02050 m_state = state;
02051 }
02052
02053 void UIListBtnTypeItem::setCheckable(bool flag)
02054 {
02055 m_checkable = flag;
02056 CalcDimensions();
02057 }
02058
02059 void UIListBtnTypeItem::setDrawArrow(bool flag)
02060 {
02061 m_showArrow = flag;
02062 CalcDimensions();
02063 }
02064
02065 void UIListBtnTypeItem::setData(void *data)
02066 {
02067 m_data = data;
02068 }
02069
02070 void *UIListBtnTypeItem::getData()
02071 {
02072 return m_data;
02073 }
02074
02075 void UIListBtnTypeItem::setOverrideInactive(bool flag)
02076 {
02077 m_overrideInactive = flag;
02078 }
02079
02080 bool UIListBtnTypeItem::getOverrideInactive(void)
02081 {
02082 return m_overrideInactive;
02083 }
02084
02085 bool UIListBtnTypeItem::moveUpDown(bool flag)
02086 {
02087 return m_parent->MoveItemUpDown(this, flag);
02088 }
02089
02090 void UIListBtnTypeItem::paint(QPainter *p, fontProp *font, int x, int y, bool active_on)
02091 {
02092 if (this == m_parent->m_selItem)
02093 {
02094 if (m_parent->m_active && !m_overrideInactive && active_on)
02095 {
02096 p->drawPixmap(x, y, m_parent->m_itemSelActPix);
02097 }
02098 else
02099 {
02100 if (active_on)
02101 {
02102 p->drawPixmap(x, y, m_parent->m_itemSelInactPix);
02103 }
02104 else
02105 {
02106 p->drawPixmap(x, y, m_parent->m_itemRegPix);
02107 }
02108 }
02109
02110 if (m_parent->m_showArrow || m_showArrow)
02111 {
02112 QRect ar(m_arrowRect);
02113 ar.moveBy(x,y);
02114 p->drawPixmap(ar, m_parent->m_arrowPix);
02115 }
02116 }
02117 else
02118 {
02119
02120 p->drawPixmap(x, y, m_parent->m_itemRegPix);
02121
02122
02123
02124
02125
02126
02127
02128
02129
02130
02131
02132
02133
02134
02135 }
02136
02137 if (m_checkable)
02138 {
02139 QRect cr(m_checkRect);
02140 cr.moveBy(x, y);
02141
02142 if (m_state == HalfChecked)
02143 p->drawPixmap(cr, m_parent->m_checkHalfPix);
02144 else if (m_state == FullChecked)
02145 p->drawPixmap(cr, m_parent->m_checkFullPix);
02146 else
02147 p->drawPixmap(cr, m_parent->m_checkNonePix);
02148 }
02149
02150 if (m_pixmap)
02151 {
02152 QRect pr(m_pixmapRect);
02153 pr.moveBy(x, y);
02154 p->drawPixmap(pr, *m_pixmap);
02155 }
02156
02157 QRect tr(m_textRect);
02158 tr.moveBy(x,y);
02159 QString text = m_parent->cutDown(m_text, &(font->face), false,
02160 tr.width(), tr.height());
02161 p->drawText(tr, m_justify, text);
02162 }
02163