Ticket #1010: scrollwidgets.diff

File scrollwidgets.diff, 17.9 KB (added by leo@…, 14 years ago)
  • libs/libmyth/lcddevice.h

     
    6060  public:
    6161    LCDTextItem() {}
    6262    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")
    6465    {
    6566        itemRow = row;
    6667        itemAlignment = align;
    6768        itemText = text;
    6869        itemScreen = screen;
     70        itemWidget = widget;
    6971        itemScrollable = scroll;
    7072    }
    7173
     
    7577    TEXT_ALIGNMENT getAlignment() { return itemAlignment; }
    7678    QString getText() { return itemText; }
    7779    QString getScreen() { return itemScreen; }
     80    QString getWidget() { return itemWidget; }
    7881    int getScroll() { return itemScrollable; }
    7982
    8083    void setRow(unsigned int value) { itemRow = value; }
    8184    void setAlignment(TEXT_ALIGNMENT value) { itemAlignment = value; }
    8285    void setText(QString value) { itemText = value; }
    8386    void setScreen(QString value) { itemScreen = value; }
     87    void setWidget(QString value) { itemWidget = value; }
    8488    void setScrollable(bool value) { itemScrollable = value; }
    8589
    8690  private:
     
    8892    TEXT_ALIGNMENT itemAlignment;
    8993    QString itemText;
    9094    QString itemScreen;
     95    QString itemWidget;
    9196    bool itemScrollable;
    9297};
    9398
  • programs/mythlcdserver/lcdprocclient.cpp

     
    5858
    5959    timeFlash = false;
    6060    scrollingText = "";
    61     scrollWidget = "";
    62     scrollRow = 0;
    6361    progress = 0.0;
    6462    generic_progress = 0.0;
    6563    volume_level = 0.0;
     
    6866    lcdMenuItems = new QPtrList<LCDMenuItem>;
    6967    lcdMenuItems->setAutoDelete(true);
    7068
     69    lcdTextItems = new QPtrList<LCDTextItem>;
     70    lcdTextItems->setAutoDelete(true);
     71
    7172    timeTimer = new QTimer(this);
    7273    connect(timeTimer, SIGNAL(timeout()), this, SLOT(outputTime()));   
    7374   
    74     scrollTimer = new QTimer(this);
    75     connect(scrollTimer, SIGNAL(timeout()), this, SLOT(scrollText()));
     75    scrollWTimer = new QTimer(this);
     76    connect(scrollWTimer, SIGNAL(timeout()), this, SLOT(scrollWidgets()));
    7677   
    77     preScrollTimer = new QTimer(this);
    78     connect(preScrollTimer, SIGNAL(timeout()), this,
    79             SLOT(beginScrollingText()));
     78    preScrollWTimer = new QTimer(this);
     79    connect(preScrollWTimer, SIGNAL(timeout()), this,
     80            SLOT(beginScrollingWidgets()));
    8081   
    8182    popMenuTimer = new QTimer(this);
    8283    connect(popMenuTimer, SIGNAL(timeout()), this, SLOT(unPopMenu()));
     
    162163    return connected;
    163164}
    164165
    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 
    181166void LCDProcClient::sendToServer(const QString &someText)
    182167{
    183168    // Check the socket, make sure the connection is still up
     
    431416    // The Music Screen
    432417    sendToServer("screen_add Music");
    433418    setPriority("Music", LOW);
    434     sendToServer("widget_add Music topWidget string");
     419    sendToServer("widget_add Music topWidget1 string");
     420    sendToServer("widget_add Music topWidget2 string");
    435421    sendToServer("widget_add Music timeWidget string");
    436422    sendToServer("widget_add Music infoWidget string");
    437423    sendToServer("widget_add Music progressBar hbar");
     
    706692    socket->close();
    707693}
    708694
    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 
    722695void LCDProcClient::scrollList()
    723696{
    724697    if (scrollListItems.count() == 0)
     
    755728    }
    756729
    757730    timeTimer->stop();
    758     preScrollTimer->stop();
    759     scrollTimer->stop();
     731    preScrollWTimer->stop();
     732    scrollWTimer->stop();
    760733    popMenuTimer->stop();
    761734    menuScrollTimer->stop();
    762735    menuPreScrollTimer->stop();
     
    788761    QPtrListIterator<LCDTextItem> it( *textItems );
    789762    LCDTextItem *curItem;
    790763    QString num;
    791 
    792764    unsigned int counter = 1;
    793765
    794766    // Do the definable scrolling in here.
    795     // Use asignScrollingText(curItem->getText(), "textWidget" + num);
     767    // Use asignScrollingWidgets(curItem->getText(), "textWidget" + num);
    796768    // When scrolling is set, alignment has no effect
    797769    while ((curItem = it.current()) != 0 && counter < lcdHeight)
    798770    {
     
    800772        num.setNum(curItem->getRow());
    801773
    802774        if (curItem->getScroll())
    803             assignScrollingText(curItem->getText(), curItem->getScreen(),
     775            assignScrollingWidgets(curItem->getText(), curItem->getScreen(),
    804776                                "textWidget" + num, curItem->getRow());
    805777        else
    806778        {
     
    883855    sendToServer(aString);
    884856}
    885857
    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 size
    890     // 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 text
    899         outputCenteredText(theScreen, theText, theWidget, theRow);
    900  
    901         scrollTimer->stop();
    902         preScrollTimer->stop();
    903     }
    904     else
    905     {
    906         // Setup for scrolling
    907         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 
    916858void LCDProcClient::assignScrollingList(QStringList theList, QString theScreen,
    917859                              QString theWidget, int theRow)
    918860{
     
    926868    scrollListTimer->start(LCD_SCROLLLIST_TIME, FALSE);
    927869}
    928870
     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
     878void 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
     888void 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
     936void LCDProcClient::beginScrollingWidgets()
     937{
     938    scrollPosition = lcdWidth;
     939    preScrollWTimer->stop();
     940    scrollWTimer->start(400, false);
     941}
     942
     943void 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
    929977void LCDProcClient::startMusic(QString artist, QString album, QString track)
    930978{
     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
    931999    QString aString;
    9321000    music_progress = 0.0f;
    933     if (lcd_showmusic)
    934       setPriority("Music", HIGH);
    9351001    aString = artist;
    9361002    if (lcd_showmusic_items == "ArtistAlbumTitle") {
    9371003        aString += " [";
    9381004        aString += album;
    9391005        aString += "] ";
    940     } else {
     1006    } else if (lcdHeight < 4) {
    9411007        aString += " - ";
    9421008    }
    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.
    9441021    activeScreen = "Music";
    945     assignScrollingText(aString, "Music");
     1022    if (lcd_showmusic)
     1023      setPriority("Music", HIGH);
    9461024}
    9471025
    9481026void LCDProcClient::startChannel(QString channum, QString title, QString subtitle)
     
    9651043    else
    9661044    {
    9671045        aString = channum;
    968         assignScrollingText(aString, "Channel", "topWidget", 1);
     1046        lcdTextItems->clear();
     1047        assignScrollingWidgets(aString, "Channel", "topWidget", 1);
    9691048        aString = title;
    9701049        if (subtitle.length() > 0)
    9711050        {
     
    9731052            aString += subtitle;
    9741053            aString += "'";
    9751054        }
    976         assignScrollingText(aString, "Channel", "botWidget", 2);
     1055        assignScrollingWidgets(aString, "Channel", "botWidget", 2);
     1056        formatScrollingWidgets();
    9771057    }
    9781058       
    9791059    progress = 0.0;
     
    10141094    // Todo, make scrolling definable in LCDTextItem
    10151095    ++it;
    10161096
    1017     assignScrollingText(curItem->getText(), "Generic", "textWidget1", curItem->getRow());
    10181097
     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
    10191109    outputGeneric();
    10201110
    10211111    // Pop off the first item so item one isn't written twice
    10221112    if (textItems->removeFirst() != 0)
    10231113        outputText(textItems);
     1114    formatScrollingWidgets();
    10241115}
    10251116
    10261117void LCDProcClient::startMenu(QPtrList<LCDMenuItem> *menuItems, QString app_name,
     
    16281719        setPriority("Time", LOW);
    16291720       
    16301721        timeTimer->stop();
    1631         scrollTimer->stop();
     1722        scrollWTimer->stop();
    16321723        scrollListTimer->stop();
    16331724        listTime = LCD_RECSTATUS_TIME;
    16341725        isTimeVisible = false;
     
    16411732        setPriority("RecStatus", LOW);
    16421733
    16431734        timeTimer->start(1000, FALSE);
    1644         scrollTimer->stop();
     1735        scrollWTimer->stop();
    16451736        scrollListTimer->stop();
    16461737        recStatusTimer->start(LCD_TIME_TIME, FALSE);
    16471738
     
    17831874
    17841875void LCDProcClient::outputMusic()
    17851876{
    1786     outputCenteredText("Music", music_time, "timeWidget", 2);
     1877    int info_width = 0;
    17871878
     1879    // See startMusic() for a discription of the Music screen contents
     1880
     1881    outputCenteredText("Music", music_time, "timeWidget",
     1882                                lcdHeight < 4 ? 2 : 3);
     1883
    17881884    if (lcdHeight > 2)
    17891885    {
    1790         QString props;
    1791         QString shuffle = "      ";
    1792         QString repeat  = "      ";
     1886        QString aString;
     1887        QString shuffle = "";
     1888        QString repeat  = "";
    17931889
    17941890        if (music_shuffle == 1)
    17951891        {
    1796             shuffle = "Shfl ?";
     1892            shuffle = "S:? ";
    17971893        }
    17981894        else if (music_shuffle == 2)
    17991895        {
    1800             shuffle = "Shfl i";         
     1896            shuffle = "S:i ";
    18011897        }
    18021898
    18031899        if (music_repeat == 1)
    18041900        {
    1805             repeat = "Rpt 1";
     1901            repeat = "R:1 ";
    18061902        }
    18071903        else if (music_repeat == 2)
    18081904        {
    1809             repeat = "Rpt *";         
     1905            repeat = "R:* ";
    18101906        }
    18111907
    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());
    18131910
    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);
    18161916
    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));
    18231924        sendToServer(aString);
     1925
    18241926    }
    18251927}
    18261928
     
    21272229    if  (activeScreen == "Time" || activeScreen == "RecStatus")
    21282230        startTime();         
    21292231}
     2232/* vim: set expandtab tabstop=4 shiftwidth=4: */
  • programs/mythlcdserver/lcdprocclient.h

     
    8080    void outputRecStatus();       
    8181    void scrollMenuText();         // Scroll the menu items if need be
    8282    void beginScrollingMenuText(); // But only after a bit of time has gone by
    83     void scrollText();             // Scroll the topline text
    84     void beginScrollingText();     // But only after a bit of time has gone by
    8583    void unPopMenu();              // Remove the Pop Menu display
    8684    void scrollList();             // display a list line by line
    8785    void updateRecordingList(void);
    8886    void removeStartupMessage(void);
     87    void beginScrollingWidgets(void);
     88    void scrollWidgets(void);
    8989         
    9090  private:
    9191    void outputCenteredText(QString theScreen, QString theText,
     
    110110    void setHeartbeat (const QString &screen, bool onoff);
    111111
    112112    void init();
    113     void assignScrollingText(QString theText, QString theScreen,
    114                              QString theWidget = "topWidget", int theRox = 1);
    115113    void assignScrollingList(QStringList theList, QString theScreen,
    116114                             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);
    117120                             
    118121    void startTime();
    119122    void startMusic(QString artist, QString album, QString track);
     
    128131
    129132    QSocket *socket;
    130133    QTimer *timeTimer;
    131     QTimer *scrollTimer;
    132     QTimer *preScrollTimer;
     134    QTimer *scrollWTimer;
     135    QTimer *preScrollWTimer;
    133136    QTimer *menuScrollTimer;
    134137    QTimer *menuPreScrollTimer;
    135138    QTimer *popMenuTimer;
     
    183186    int music_repeat;
    184187    int music_shuffle;
    185188
     189    QPtrList<LCDTextItem> *lcdTextItems;
    186190    QString scrollingText;
    187     QString scrollScreen, scrollWidget;
    188     int scrollRow;
     191    QString scrollScreen;
    189192    unsigned int scrollPosition;
    190193    QString timeformat;
    191194