Ticket #1010: scrollwidgets.diff
File scrollwidgets.diff, 17.9 KB (added by , 20 years ago) |
---|
-
libs/libmyth/lcddevice.h
60 60 public: 61 61 LCDTextItem() {} 62 62 LCDTextItem(unsigned int row, TEXT_ALIGNMENT align, QString text, 63 QString screen = "Generic", bool scroll = false) 63 QString screen = "Generic", bool scroll = false, 64 QString widget = "textWidget") 64 65 { 65 66 itemRow = row; 66 67 itemAlignment = align; 67 68 itemText = text; 68 69 itemScreen = screen; 70 itemWidget = widget; 69 71 itemScrollable = scroll; 70 72 } 71 73 … … 75 77 TEXT_ALIGNMENT getAlignment() { return itemAlignment; } 76 78 QString getText() { return itemText; } 77 79 QString getScreen() { return itemScreen; } 80 QString getWidget() { return itemWidget; } 78 81 int getScroll() { return itemScrollable; } 79 82 80 83 void setRow(unsigned int value) { itemRow = value; } 81 84 void setAlignment(TEXT_ALIGNMENT value) { itemAlignment = value; } 82 85 void setText(QString value) { itemText = value; } 83 86 void setScreen(QString value) { itemScreen = value; } 87 void setWidget(QString value) { itemWidget = value; } 84 88 void setScrollable(bool value) { itemScrollable = value; } 85 89 86 90 private: … … 88 92 TEXT_ALIGNMENT itemAlignment; 89 93 QString itemText; 90 94 QString itemScreen; 95 QString itemWidget; 91 96 bool itemScrollable; 92 97 }; 93 98 -
programs/mythlcdserver/lcdprocclient.cpp
58 58 59 59 timeFlash = false; 60 60 scrollingText = ""; 61 scrollWidget = "";62 scrollRow = 0;63 61 progress = 0.0; 64 62 generic_progress = 0.0; 65 63 volume_level = 0.0; … … 68 66 lcdMenuItems = new QPtrList<LCDMenuItem>; 69 67 lcdMenuItems->setAutoDelete(true); 70 68 69 lcdTextItems = new QPtrList<LCDTextItem>; 70 lcdTextItems->setAutoDelete(true); 71 71 72 timeTimer = new QTimer(this); 72 73 connect(timeTimer, SIGNAL(timeout()), this, SLOT(outputTime())); 73 74 74 scroll Timer = new QTimer(this);75 connect(scroll Timer, SIGNAL(timeout()), this, SLOT(scrollText()));75 scrollWTimer = new QTimer(this); 76 connect(scrollWTimer, SIGNAL(timeout()), this, SLOT(scrollWidgets())); 76 77 77 preScroll Timer = new QTimer(this);78 connect(preScroll Timer, SIGNAL(timeout()), this,79 SLOT(beginScrolling Text()));78 preScrollWTimer = new QTimer(this); 79 connect(preScrollWTimer, SIGNAL(timeout()), this, 80 SLOT(beginScrollingWidgets())); 80 81 81 82 popMenuTimer = new QTimer(this); 82 83 connect(popMenuTimer, SIGNAL(timeout()), this, SLOT(unPopMenu())); … … 162 163 return connected; 163 164 } 164 165 165 void LCDProcClient::beginScrollingText()166 {167 unsigned int i;168 QString aString;169 170 // After the topline text has been on the screen for "a while"171 // start scrolling it.172 173 aString = "";174 for (i = 0; i < lcdWidth; i++)175 scrollingText.prepend(" ");176 177 scrollPosition = lcdWidth;178 scrollTimer->start(400, false);179 }180 181 166 void LCDProcClient::sendToServer(const QString &someText) 182 167 { 183 168 // Check the socket, make sure the connection is still up … … 431 416 // The Music Screen 432 417 sendToServer("screen_add Music"); 433 418 setPriority("Music", LOW); 434 sendToServer("widget_add Music topWidget string"); 419 sendToServer("widget_add Music topWidget1 string"); 420 sendToServer("widget_add Music topWidget2 string"); 435 421 sendToServer("widget_add Music timeWidget string"); 436 422 sendToServer("widget_add Music infoWidget string"); 437 423 sendToServer("widget_add Music progressBar hbar"); … … 706 692 socket->close(); 707 693 } 708 694 709 void LCDProcClient::scrollText()710 {711 if (activeScreen != scrollScreen)712 return;713 714 outputLeftText(scrollScreen, scrollingText.mid(scrollPosition, lcdWidth),715 scrollWidget, scrollRow);716 717 scrollPosition++;718 if (scrollPosition >= scrollingText.length())719 scrollPosition = 0;720 }721 722 695 void LCDProcClient::scrollList() 723 696 { 724 697 if (scrollListItems.count() == 0) … … 755 728 } 756 729 757 730 timeTimer->stop(); 758 preScroll Timer->stop();759 scroll Timer->stop();731 preScrollWTimer->stop(); 732 scrollWTimer->stop(); 760 733 popMenuTimer->stop(); 761 734 menuScrollTimer->stop(); 762 735 menuPreScrollTimer->stop(); … … 788 761 QPtrListIterator<LCDTextItem> it( *textItems ); 789 762 LCDTextItem *curItem; 790 763 QString num; 791 792 764 unsigned int counter = 1; 793 765 794 766 // Do the definable scrolling in here. 795 // Use asignScrolling Text(curItem->getText(), "textWidget" + num);767 // Use asignScrollingWidgets(curItem->getText(), "textWidget" + num); 796 768 // When scrolling is set, alignment has no effect 797 769 while ((curItem = it.current()) != 0 && counter < lcdHeight) 798 770 { … … 800 772 num.setNum(curItem->getRow()); 801 773 802 774 if (curItem->getScroll()) 803 assignScrolling Text(curItem->getText(), curItem->getScreen(),775 assignScrollingWidgets(curItem->getText(), curItem->getScreen(), 804 776 "textWidget" + num, curItem->getRow()); 805 777 else 806 778 { … … 883 855 sendToServer(aString); 884 856 } 885 857 886 void LCDProcClient::assignScrollingText(QString theText, QString theScreen,887 QString theWidget, int theRow)888 {889 // Have to decide what to do with "top line" text given the size890 // of the LCD (as reported by the server)891 892 scrollScreen = theScreen;893 scrollWidget = theWidget;894 scrollRow = theRow;895 896 if (theText.length() <= lcdWidth)897 {898 // This is trivial, just show the text899 outputCenteredText(theScreen, theText, theWidget, theRow);900 901 scrollTimer->stop();902 preScrollTimer->stop();903 }904 else905 {906 // Setup for scrolling907 outputCenteredText(theScreen, theText.left(lcdWidth), theWidget, theRow);908 909 scrollingText = theText;910 scrollPosition = 0;911 scrollTimer->stop();912 preScrollTimer->start(2000, TRUE);913 }914 }915 916 858 void LCDProcClient::assignScrollingList(QStringList theList, QString theScreen, 917 859 QString theWidget, int theRow) 918 860 { … … 926 868 scrollListTimer->start(LCD_SCROLLLIST_TIME, FALSE); 927 869 } 928 870 871 // 872 // Prepare for scrolling one or more text widgets on a single screen. 873 // Notes: 874 // - Before assigning the first text, call: lcdTextItems->clear(); 875 // - After assigning the last text, call: formatScrollingWidgets() 876 // That's it ;-) 877 878 void LCDProcClient::assignScrollingWidgets(QString theText, QString theScreen, 879 QString theWidget, int theRow) 880 { 881 scrollScreen = theScreen; 882 883 // Alignment is not used... 884 lcdTextItems->append(new LCDTextItem(theRow, ALIGN_LEFT, theText, 885 theScreen, true, theWidget)); 886 } 887 888 void LCDProcClient::formatScrollingWidgets() 889 { 890 891 scrollWTimer->stop(); 892 preScrollWTimer->stop(); 893 894 if (lcdTextItems->isEmpty()) 895 return; // Weird... 896 897 unsigned int max_len = 0; 898 QPtrListIterator<LCDTextItem> it(*lcdTextItems); 899 LCDTextItem *curItem; 900 901 // Get the length of the longest item to scroll 902 for(; (curItem = it.current()) != 0; ++it) { 903 if (curItem->getText().length() > max_len) 904 max_len = curItem->getText().length(); 905 } 906 907 // Make all scrollable items the same lenght and do the initial output 908 it.toFirst(); 909 while ((curItem = it.current()) != 0) 910 { 911 ++it; 912 if (curItem->getText().length() > lcdWidth) 913 { 914 QString temp, temp2; 915 temp = temp.fill(QChar(' '), max_len - curItem->getText().length()); 916 temp2 = temp2.fill(QChar(' '), lcdWidth); 917 curItem->setText(temp2 + curItem->getText() + temp); 918 outputLeftText(scrollScreen, 919 curItem->getText().mid(lcdWidth, max_len), 920 curItem->getWidget(), curItem->getRow()); 921 } 922 else { 923 curItem->setScrollable(false); 924 outputCenteredText(scrollScreen, curItem->getText(), 925 curItem->getWidget(), curItem->getRow()); 926 } 927 } 928 929 if (max_len <= lcdWidth) 930 // We're done, no scrolling 931 return; 932 933 preScrollWTimer->start(2000, TRUE); 934 } 935 936 void LCDProcClient::beginScrollingWidgets() 937 { 938 scrollPosition = lcdWidth; 939 preScrollWTimer->stop(); 940 scrollWTimer->start(400, false); 941 } 942 943 void LCDProcClient::scrollWidgets() 944 { 945 if (activeScreen != scrollScreen) 946 return; 947 948 if (lcdTextItems->isEmpty()) 949 return; // Weird... 950 951 QPtrListIterator<LCDTextItem> it(*lcdTextItems); 952 LCDTextItem *curItem; 953 954 unsigned int len = 0; 955 for(; (curItem = it.current()) != 0; ++it) { 956 if (curItem->getScroll()) { 957 // Note that all scrollable items have the same lenght! 958 len = curItem->getText().length(); 959 960 outputLeftText(scrollScreen, 961 curItem->getText().mid(scrollPosition, lcdWidth), 962 curItem->getWidget(), curItem->getRow()); 963 } 964 } 965 if (len == 0) { 966 // Shouldn't happen, but.... 967 cerr << "LCDProcClient::scrollWidgets called without scrollable items" 968 << endl; 969 scrollWTimer->stop(); 970 return; 971 } 972 scrollPosition++; 973 if (scrollPosition >= len) 974 scrollPosition = lcdWidth; 975 } 976 929 977 void LCDProcClient::startMusic(QString artist, QString album, QString track) 930 978 { 979 // Playing music displays: 980 // For 2-line displays: 981 // <ArtistAlbumTitle> 982 // <Elapse/Remaining Time> 983 // For 3-line displays: 984 // <ArtistAlbumTitle> 985 // <Elapse/Remaining Time> 986 // <Info+ProgressBar> 987 // For displays with more than 3 lines: 988 // <ArtistAlbum> 989 // <Title> 990 // <Elapse/Remaining Time> 991 // <Info+ProgressBar> 992 993 // Clear the progressBar and timeWidget before activating the Music 994 // screen. This prevents the display of outdated junk. 995 sendToServer("widget_set Music progressBar 1 1 0"); 996 sendToServer("widget_set Music timeWidget 1 1 \"\""); 997 lcdTextItems->clear(); 998 931 999 QString aString; 932 1000 music_progress = 0.0f; 933 if (lcd_showmusic)934 setPriority("Music", HIGH);935 1001 aString = artist; 936 1002 if (lcd_showmusic_items == "ArtistAlbumTitle") { 937 1003 aString += " ["; 938 1004 aString += album; 939 1005 aString += "] "; 940 } else {1006 } else if (lcdHeight < 4) { 941 1007 aString += " - "; 942 1008 } 943 aString += track; 1009 1010 if (lcdHeight < 4) { 1011 aString += track; 1012 } 1013 else { 1014 assignScrollingWidgets(track, "Music", "topWidget2", 2); 1015 } 1016 assignScrollingWidgets(aString, "Music", "topWidget1", 1); 1017 formatScrollingWidgets(); 1018 1019 // OK, everything is at least somewhat initialised. Activate 1020 // the music screen. 944 1021 activeScreen = "Music"; 945 assignScrollingText(aString, "Music"); 1022 if (lcd_showmusic) 1023 setPriority("Music", HIGH); 946 1024 } 947 1025 948 1026 void LCDProcClient::startChannel(QString channum, QString title, QString subtitle) … … 965 1043 else 966 1044 { 967 1045 aString = channum; 968 assignScrollingText(aString, "Channel", "topWidget", 1); 1046 lcdTextItems->clear(); 1047 assignScrollingWidgets(aString, "Channel", "topWidget", 1); 969 1048 aString = title; 970 1049 if (subtitle.length() > 0) 971 1050 { … … 973 1052 aString += subtitle; 974 1053 aString += "'"; 975 1054 } 976 assignScrollingText(aString, "Channel", "botWidget", 2); 1055 assignScrollingWidgets(aString, "Channel", "botWidget", 2); 1056 formatScrollingWidgets(); 977 1057 } 978 1058 979 1059 progress = 0.0; … … 1014 1094 // Todo, make scrolling definable in LCDTextItem 1015 1095 ++it; 1016 1096 1017 assignScrollingText(curItem->getText(), "Generic", "textWidget1", curItem->getRow());1018 1097 1098 // Weird observations: 1099 // - The first item is always assumed 'scrolling', for this 1100 // item, the scrollable property is ignored... 1101 // - Why output line 1, progressbar, rest of lines? Why not 1102 // all outputlines, progressbar? That way, outputText() can 1103 // just handle the whole thing and the 'pop off' stuff can go. 1104 // 1105 lcdTextItems->clear(); 1106 assignScrollingWidgets(curItem->getText(), "Generic", "textWidget1", 1107 curItem->getRow()); 1108 1019 1109 outputGeneric(); 1020 1110 1021 1111 // Pop off the first item so item one isn't written twice 1022 1112 if (textItems->removeFirst() != 0) 1023 1113 outputText(textItems); 1114 formatScrollingWidgets(); 1024 1115 } 1025 1116 1026 1117 void LCDProcClient::startMenu(QPtrList<LCDMenuItem> *menuItems, QString app_name, … … 1628 1719 setPriority("Time", LOW); 1629 1720 1630 1721 timeTimer->stop(); 1631 scroll Timer->stop();1722 scrollWTimer->stop(); 1632 1723 scrollListTimer->stop(); 1633 1724 listTime = LCD_RECSTATUS_TIME; 1634 1725 isTimeVisible = false; … … 1641 1732 setPriority("RecStatus", LOW); 1642 1733 1643 1734 timeTimer->start(1000, FALSE); 1644 scroll Timer->stop();1735 scrollWTimer->stop(); 1645 1736 scrollListTimer->stop(); 1646 1737 recStatusTimer->start(LCD_TIME_TIME, FALSE); 1647 1738 … … 1783 1874 1784 1875 void LCDProcClient::outputMusic() 1785 1876 { 1786 outputCenteredText("Music", music_time, "timeWidget", 2);1877 int info_width = 0; 1787 1878 1879 // See startMusic() for a discription of the Music screen contents 1880 1881 outputCenteredText("Music", music_time, "timeWidget", 1882 lcdHeight < 4 ? 2 : 3); 1883 1788 1884 if (lcdHeight > 2) 1789 1885 { 1790 QString props;1791 QString shuffle = " 1792 QString repeat = " 1886 QString aString; 1887 QString shuffle = ""; 1888 QString repeat = ""; 1793 1889 1794 1890 if (music_shuffle == 1) 1795 1891 { 1796 shuffle = "S hfl ?";1892 shuffle = "S:? "; 1797 1893 } 1798 1894 else if (music_shuffle == 2) 1799 1895 { 1800 shuffle = "S hfl i";1896 shuffle = "S:i "; 1801 1897 } 1802 1898 1803 1899 if (music_repeat == 1) 1804 1900 { 1805 repeat = "R pt 1";1901 repeat = "R:1 "; 1806 1902 } 1807 1903 else if (music_repeat == 2) 1808 1904 { 1809 repeat = "R pt *";1905 repeat = "R:* "; 1810 1906 } 1811 1907 1812 props.sprintf("%s %s", shuffle.ascii(), repeat.ascii()); 1908 if (shuffle.length() != 0 || repeat.length() != 0) { 1909 aString.sprintf("%s%s", shuffle.ascii(), repeat.ascii()); 1813 1910 1814 outputCenteredText("Music", props, "infoWidget", lcdHeight); 1815 } 1911 info_width = aString.length(); 1912 outputLeftText("Music", aString, "infoWidget", lcdHeight); 1913 } 1914 else 1915 outputLeftText("Music", " ", "infoWidget", lcdHeight); 1816 1916 1817 if (lcdHeight > 3) 1818 { 1819 QString aString; 1820 aString = "widget_set Music progressBar 1 3 "; 1821 aString += QString::number((int)rint(music_progress * lcdWidth * 1822 cellWidth)); 1917 aString = "widget_set Music progressBar "; 1918 aString += QString::number(info_width + 1); 1919 aString += " "; 1920 aString += QString::number(lcdHeight); 1921 aString += " "; 1922 aString += QString::number((int)rint(music_progress * 1923 (lcdWidth - info_width) * cellWidth)); 1823 1924 sendToServer(aString); 1925 1824 1926 } 1825 1927 } 1826 1928 … … 2127 2229 if (activeScreen == "Time" || activeScreen == "RecStatus") 2128 2230 startTime(); 2129 2231 } 2232 /* vim: set expandtab tabstop=4 shiftwidth=4: */ -
programs/mythlcdserver/lcdprocclient.h
80 80 void outputRecStatus(); 81 81 void scrollMenuText(); // Scroll the menu items if need be 82 82 void beginScrollingMenuText(); // But only after a bit of time has gone by 83 void scrollText(); // Scroll the topline text84 void beginScrollingText(); // But only after a bit of time has gone by85 83 void unPopMenu(); // Remove the Pop Menu display 86 84 void scrollList(); // display a list line by line 87 85 void updateRecordingList(void); 88 86 void removeStartupMessage(void); 87 void beginScrollingWidgets(void); 88 void scrollWidgets(void); 89 89 90 90 private: 91 91 void outputCenteredText(QString theScreen, QString theText, … … 110 110 void setHeartbeat (const QString &screen, bool onoff); 111 111 112 112 void init(); 113 void assignScrollingText(QString theText, QString theScreen,114 QString theWidget = "topWidget", int theRox = 1);115 113 void assignScrollingList(QStringList theList, QString theScreen, 116 114 QString theWidget = "topWidget", int theRow = 1); 115 116 // Scroll 1 or more widgets on a screen 117 void assignScrollingWidgets(QString theText, QString theScreen, 118 QString theWidget = "topWidget", int theRow = 1); 119 void formatScrollingWidgets(void); 117 120 118 121 void startTime(); 119 122 void startMusic(QString artist, QString album, QString track); … … 128 131 129 132 QSocket *socket; 130 133 QTimer *timeTimer; 131 QTimer *scroll Timer;132 QTimer *preScroll Timer;134 QTimer *scrollWTimer; 135 QTimer *preScrollWTimer; 133 136 QTimer *menuScrollTimer; 134 137 QTimer *menuPreScrollTimer; 135 138 QTimer *popMenuTimer; … … 183 186 int music_repeat; 184 187 int music_shuffle; 185 188 189 QPtrList<LCDTextItem> *lcdTextItems; 186 190 QString scrollingText; 187 QString scrollScreen, scrollWidget; 188 int scrollRow; 191 QString scrollScreen; 189 192 unsigned int scrollPosition; 190 193 QString timeformat; 191 194