Ticket #12683: 0002-MythUI-Implement-zoomable-GuideGrids.patch
File 0002-MythUI-Implement-zoomable-GuideGrids.patch, 12.9 KB (added by , 8 years ago) |
---|
-
mythtv/libs/libmythtv/tv_play.cpp
From f1bc6c27d32c0b7f4d8393f284f29476d77e0371 Mon Sep 17 00:00:00 2001 From: Roger Siddons <rsiddons@mythtv.org> Date: Tue, 8 Mar 2016 20:13:34 +0000 Subject: [PATCH 2/2] MythUI: Implement zoomable GuideGrids Theme may define multiple GuideGrid elements by using a zoom level suffix (ie guidegrid0, guidegrid1 etc) When multiple levels are defined new 'Zoom' menu options & key bindings will permit switching between them. diff --git a/mythtv/libs/libmythtv/tv_play.cpp b/mythtv/libs/libmythtv/tv_play.cpp index de89660..e6a51b3 100644
a b void TV::InitKeys(void) 597 597 "Change Group View"), ""); 598 598 REG_KEY("TV Frontend", ACTION_SHOWNEXTGROUP, QT_TRANSLATE_NOOP("MythControls", 599 599 "Show Next Group"), ""); 600 REG_KEY("TV Frontend", ACTION_ZOOMIN, QT_TRANSLATE_NOOP("MythControls", 601 "Zoom In"), ""); 602 REG_KEY("TV Frontend", ACTION_ZOOMOUT, QT_TRANSLATE_NOOP("MythControls", 603 "Zoom Out"), ""); 600 604 601 605 REG_KEY("TV Playback", "BACK", QT_TRANSLATE_NOOP("MythControls", 602 606 "Exit or return to DVD menu"), "Esc"); -
mythtv/programs/mythfrontend/guidegrid.cpp
diff --git a/mythtv/programs/mythfrontend/guidegrid.cpp b/mythtv/programs/mythfrontend/guidegrid.cpp index 37f8d8b..18fcf92 100644
a b using namespace std; 55 55 // mythfrontend 56 56 #include "progfind.h" 57 57 58 #define GUIDEZOOMSETTING "GuideZoomLevel" 59 58 60 QWaitCondition epgIsVisibleCond; 59 61 60 62 #define LOC QString("GuideGrid: ") … … GuideGrid::GuideGrid(MythScreenStack *parent, 518 520 m_updateTimer(new QTimer(this)), 519 521 m_threadPool("GuideGridHelperPool"), 520 522 m_changrpid(changrpid), 523 m_changrpname(), 521 524 m_changrplist(ChannelGroup::GetChannelGroups(false)), 522 525 m_jumpToChannelLock(QMutex::Recursive), 523 526 m_jumpToChannel(NULL), … … GuideGrid::GuideGrid(MythScreenStack *parent, 528 531 m_longdateText(NULL), 529 532 m_jumpToText(NULL), 530 533 m_changroupname(NULL), 531 m_channelImage(NULL) 534 m_channelImage(NULL), 535 m_essentialWidgets(), 536 m_otherWidgets(), 537 m_zoomWidgets(), 538 m_zoomCurrent(0), 539 m_zoomMax(0) 532 540 { 533 541 connect(m_previewVideoRefreshTimer, SIGNAL(timeout()), 534 542 this, SLOT(refreshVideo())); … … GuideGrid::GuideGrid(MythScreenStack *parent, 554 562 m_threadPool.setMaxThreadCount(1); 555 563 } 556 564 565 bool GuideGrid::FindZoomWidgets() 566 { 567 bool ok = true; 568 MythUIType *widget; 569 570 foreach (const QString &name, m_essentialWidgets + m_otherWidgets) 571 { 572 // "0" suffix is optional for backward compatibility 573 widget = this->GetChild(name); 574 if (!widget) 575 widget = this->GetChild(name + "0"); 576 if (widget) 577 { 578 ZoomLevels &zoomWidgets = m_zoomWidgets[name]; 579 580 // find all zoom levels for this widget 581 int zoom = 0; 582 do 583 { 584 LOG(VB_GUI, LOG_DEBUG, QString("Using '%1' for zoom level %2") 585 .arg(widget->objectName()).arg(zoom)); 586 587 zoomWidgets.append(widget); 588 widget->SetVisible(false); 589 590 widget = this->GetChild(name + QString::number(++zoom)); 591 } 592 while (widget); 593 594 // Note max zoom defined by theme 595 m_zoomMax = max(m_zoomMax, --zoom); 596 } 597 else 598 { 599 bool error = m_essentialWidgets.contains(name); 600 ok &= !error; 601 LOG(VB_GENERAL, error ? LOG_ERR : LOG_WARNING, 602 QString("Container '%1' is missing child '%2'") 603 .arg(objectName()).arg(name)); 604 } 605 } 606 return ok; 607 } 608 609 MythUIType* GuideGrid::AssignWidget(const QString &name) 610 { 611 ZoomLevels zoomWidgets = m_zoomWidgets.value(name); 612 if (zoomWidgets.isEmpty()) 613 return NULL; 614 int index = min(m_zoomCurrent, zoomWidgets.size() - 1); 615 return zoomWidgets.at(index); 616 } 617 618 #define REASSIGN_WIDGET(widget, type, name) \ 619 if (widget) \ 620 widget->SetVisible(false); \ 621 widget = dynamic_cast<type*>(AssignWidget(name)); \ 622 if (widget) \ 623 widget->SetVisible(true) 624 625 void GuideGrid::SelectZoomWidgets(int change) 626 { 627 // Constrain to zoom levels supported by theme 628 m_zoomCurrent = min(max(m_zoomCurrent + change, 0), m_zoomMax); 629 630 // Store any requested change, but not constraining adjustments 631 // Thus, changing to a theme with fewer zoom levels will not overwrite the 632 // setting 633 if (change != 0) 634 gCoreContext->SaveSetting(GUIDEZOOMSETTING, m_zoomCurrent); 635 636 // Hide the current widgets, select and show new ones 637 REASSIGN_WIDGET(m_timeList, MythUIButtonList, "timelist"); 638 REASSIGN_WIDGET(m_channelList, MythUIButtonList, "channellist"); 639 REASSIGN_WIDGET(m_guideGrid, MythUIGuideGrid, "guidegrid"); 640 REASSIGN_WIDGET(m_dateText, MythUIText, "datetext"); 641 REASSIGN_WIDGET(m_longdateText, MythUIText, "longdatetext"); 642 REASSIGN_WIDGET(m_changroupname, MythUIText, "channelgroup"); 643 644 // Reset guide characteristics 645 m_channelCount = m_guideGrid->getChannelCount(); 646 m_timeCount = m_guideGrid->getTimeCount() * 6; 647 m_verticalLayout = m_guideGrid->isVerticalLayout(); 648 649 m_currentEndTime = m_currentStartTime.addSecs(m_timeCount * 60 * 5); 650 } 651 557 652 bool GuideGrid::Create() 558 653 { 559 654 QString windowName = "programguide"; … … bool GuideGrid::Create() 564 659 if (!LoadWindowFromXML("schedule-ui.xml", windowName, this)) 565 660 return false; 566 661 567 bool err = false; 568 UIUtilE::Assign(this, m_timeList, "timelist", &err); 569 UIUtilE::Assign(this, m_channelList, "channellist", &err); 570 UIUtilE::Assign(this, m_guideGrid, "guidegrid", &err); 571 UIUtilW::Assign(this, m_dateText, "datetext"); 572 UIUtilW::Assign(this, m_longdateText, "longdatetext"); 573 UIUtilW::Assign(this, m_changroupname, "channelgroup"); 574 UIUtilW::Assign(this, m_channelImage, "channelicon"); 575 UIUtilW::Assign(this, m_jumpToText, "jumptotext"); 662 m_essentialWidgets << "timelist" << "channellist" << "guidegrid"; 663 m_otherWidgets << "channelgroup" << "datetext" << "longdatetext"; 576 664 577 if ( err)665 if (!FindZoomWidgets()) 578 666 { 579 LOG(VB_GENERAL, LOG_ERR, 580 QString("Cannot load screen '%1'").arg(windowName)); 667 LOG(VB_GENERAL, LOG_ERR, QString("Cannot load screen '%1'").arg(windowName)); 581 668 return false; 582 669 } 583 670 671 UIUtilW::Assign(this, m_channelImage, "channelicon"); 672 UIUtilW::Assign(this, m_jumpToText, "jumptotext"); 673 674 m_zoomCurrent = gCoreContext->GetNumSetting(GUIDEZOOMSETTING, 0); 675 676 SelectZoomWidgets(0); 677 584 678 BuildFocusList(); 585 679 586 680 MythUIImage *videoImage = dynamic_cast<MythUIImage *>(GetChild("video")); … … bool GuideGrid::Create() 589 683 else 590 684 m_videoRect = QRect(0,0,0,0); 591 685 592 m_channelCount = m_guideGrid->getChannelCount();593 m_timeCount = m_guideGrid->getTimeCount() * 6;594 m_verticalLayout = m_guideGrid->isVerticalLayout();595 596 m_currentEndTime = m_currentStartTime.addSecs(m_timeCount * 60 * 5);597 598 686 LoadInBackground(); 599 687 return true; 600 688 } … … void GuideGrid::Init(void) 639 727 640 728 updateDateText(); 641 729 642 QStringchangrpname = ChannelGroup::GetChannelGroupName(m_changrpid);730 m_changrpname = ChannelGroup::GetChannelGroupName(m_changrpid); 643 731 644 if (m_changroupname) 645 m_changroupname->SetText(changrpname); 732 UpdateGroupText(); 646 733 647 734 gCoreContext->addListener(this); 648 735 } … … bool GuideGrid::keyPressEvent(QKeyEvent *event) 865 952 generateListings(); 866 953 updateChannels(); 867 954 } 955 else if (action == ACTION_ZOOMIN) 956 Zoom(1); 957 else if (action == ACTION_ZOOMOUT) 958 Zoom(-1); 868 959 else 869 960 handled = false; 870 961 } … … bool GuideGrid::gestureEvent(MythGestureEvent *event) 1003 1094 else 1004 1095 cursorUp(); 1005 1096 break; 1006 1097 1007 1098 case MythGestureEvent::Down: 1008 1099 if (m_verticalLayout) 1009 1100 cursorRight(); … … void GuideGrid::ShowMenu(void) 1125 1216 menuPopup->AddButton(tr("Remove from Channel Group"), NULL, true); 1126 1217 } 1127 1218 1219 if (m_zoomCurrent > 0) 1220 menuPopup->AddButton(tr("Zoom Out")); 1221 1222 if (m_zoomCurrent < m_zoomMax) 1223 menuPopup->AddButton(tr("Zoom In")); 1224 1128 1225 popupStack->AddScreen(menuPopup); 1129 1226 } 1130 1227 else … … void GuideGrid::customEvent(QEvent *event) 1966 2063 { 1967 2064 ShowJumpToTime(); 1968 2065 } 2066 else if (resulttext == tr("Zoom In")) 2067 { 2068 Zoom(1); 2069 } 2070 else if (resulttext == tr("Zoom Out")) 2071 { 2072 Zoom(-1); 2073 } 1969 2074 } 1970 2075 else if (resultid == "recmenu") 1971 2076 { … … void GuideGrid::customEvent(QEvent *event) 2019 2124 updateChannels(); 2020 2125 updateInfo(); 2021 2126 2022 QString changrpname; 2023 changrpname = ChannelGroup::GetChannelGroupName(m_changrpid); 2127 m_changrpname = ChannelGroup::GetChannelGroupName(m_changrpid); 2024 2128 2025 if (m_changroupname) 2026 m_changroupname->SetText(changrpname); 2129 UpdateGroupText(); 2027 2130 } 2028 2131 } 2029 2132 else if (resultid == "jumptotime") … … void GuideGrid::updateDateText(void) 2055 2158 (MythDate::kDateFull | MythDate::kSimplify))); 2056 2159 } 2057 2160 2161 void GuideGrid::UpdateGroupText(void) 2162 { 2163 if (m_changroupname) 2164 m_changroupname->SetText(m_changrpname); 2165 } 2166 2058 2167 void GuideGrid::updateProgramsUI(unsigned int firstRow, unsigned int numRows, 2059 2168 int progPast, 2060 2169 const QVector<ProgramList*> &proglists, … … void GuideGrid::toggleGuideListing() 2253 2362 int oldchangrpid = m_changrpid; 2254 2363 2255 2364 m_changrpid = ChannelGroup::GetNextChannelGroup(m_changrplist, oldchangrpid); 2365 m_changrpname = ChannelGroup::GetChannelGroupName(m_changrpid); 2256 2366 2257 2367 if (oldchangrpid != m_changrpid) 2258 2368 generateListings(); 2259 2369 2260 2370 updateChannels(); 2261 2371 updateInfo(); 2262 2263 QString changrpname = ChannelGroup::GetChannelGroupName(m_changrpid); 2264 2265 if (m_changroupname) 2266 m_changroupname->SetText(changrpname); 2372 UpdateGroupText(); 2267 2373 } 2268 2374 2269 2375 void GuideGrid::generateListings() … … void GuideGrid::ShowJumpToTime(void) 2743 2849 else 2744 2850 delete timedlg; 2745 2851 } 2852 2853 void GuideGrid::Zoom(int direction) 2854 { 2855 ProgramInfo *pginfo = m_programInfos[m_currentRow][m_currentCol]; 2856 if (!pginfo) 2857 return; 2858 2859 // Change widgets 2860 SelectZoomWidgets(direction); 2861 2862 m_channelCount = min(m_guideGrid->getChannelCount(), 2863 max((int)GetChannelCount(), 1)); 2864 2865 // Keep selected channel on-screen 2866 int rowsOffScreen = m_currentRow - m_channelCount + 1; 2867 if (rowsOffScreen > 0) 2868 { 2869 m_currentStartChannel += rowsOffScreen; 2870 m_currentRow -= rowsOffScreen; 2871 } 2872 2873 // Keep selected program on-screen by putting it in first column 2874 QDateTime progStart = pginfo->GetScheduledStartTime(); 2875 if (progStart >= m_currentEndTime) 2876 { 2877 m_currentStartTime = progStart; 2878 m_currentCol = 0; 2879 } 2880 2881 // Redraw 2882 fillTimeInfos(); 2883 fillProgramInfos(); 2884 updateChannels(); 2885 updateDateText(); 2886 UpdateGroupText(); 2887 } -
mythtv/programs/mythfrontend/guidegrid.h
diff --git a/mythtv/programs/mythfrontend/guidegrid.h b/mythtv/programs/mythfrontend/guidegrid.h index f32391b..0af9ac7 100644
a b private: 232 232 ProgramList GetProgramList(uint chanid) const; 233 233 uint GetAlternateChannelIndex(uint chan_idx, bool with_same_channum) const; 234 234 void updateDateText(void); 235 void UpdateGroupText(void); 236 bool FindZoomWidgets(); 237 void SelectZoomWidgets(int change); 238 MythUIType* AssignWidget(const QString &name); 239 void Zoom(int direction); 235 240 236 241 private: 237 242 int m_selectRecThreshold; … … private: 278 283 MThreadPool m_threadPool; 279 284 280 285 int m_changrpid; 286 QString m_changrpname; 281 287 ChannelGroupList m_changrplist; 282 288 283 289 QMutex m_jumpToChannelLock; … … private: 291 297 MythUIText *m_jumpToText; 292 298 MythUIText *m_changroupname; 293 299 MythUIImage *m_channelImage; 300 301 // Zoomable widgets enable different sized grids 302 QStringList m_essentialWidgets, m_otherWidgets; 303 304 typedef QList<MythUIType*> ZoomLevels; 305 QMap<QString, ZoomLevels> m_zoomWidgets; 306 int m_zoomCurrent; // Current zoom level 307 int m_zoomMax; // Max zoom level defined by theme 294 308 }; 295 309 296 310 #endif