Ticket #12996: v2-0008-Adjust-GuideGrid-widget-for-the-parent-offsets.patch

File v2-0008-Adjust-GuideGrid-widget-for-the-parent-offsets.patch, 13.8 KB (added by David Hampton <mythtv@…>, 3 years ago)

GuideGrid? widget should account for the parent offsets.

  • mythtv/libs/libmythui/mythuiguidegrid.cpp

    Adjust GuideGrid widget for the parent offsets.
    
    This patches the UI GuideGrid widget to translate drawing positions
    from coordinates that are local to the parent object into global
    coordinates. The parents xoffset/yoffset values were already being
    passed into this widget. These offsets just needed to be passed down
    to the actual drawing functions, and those functions needed to perform
    the additional translation. The lack of these translations has not
    been noticed because all GuideGrids are currently embedded in top
    level windows, so that the parent offsets are always 0/0.
    ---
     mythtv/libs/libmythui/mythuiguidegrid.cpp | 153 ++++++++++++++++++++++++++----
     mythtv/libs/libmythui/mythuiguidegrid.h   |  15 ++-
     2 files changed, 146 insertions(+), 22 deletions(-)
    
    diff --git a/mythtv/libs/libmythui/mythuiguidegrid.cpp b/mythtv/libs/libmythui/mythuiguidegrid.cpp
    index 593b5e5..06026e3 100644
    a b QColor MythUIGuideGrid::calcColor(const QColor &color, int alphaMod) 
    294294    return newColor;
    295295}
    296296
     297/** \fn MythUIGuideGrid::DrawSelf(MythPainter *, int, int, int, QRect)
     298 *  \brief Draws an entire GuideGrid.
     299 *
     300 *  Draw the complete contents of a GuideGrid. This function iterates
     301 *  over all the rows and columns in a guide grid, and calls the
     302 *  appropriate functions to draw the grid items. This is accomplished
     303 *  in three stages. First all the item backgrounds are drawn in
     304 *  appropriate colors for their genre and recoding state, then the
     305 *  background/decorations for the selected item are drawn, and
     306 *  finally all the item texts and recording decorators are drawn on
     307 *  top.
     308 *
     309 *  @note This function does not translate local->global offsets. All
     310 *  of the drawing functions it calls must perform this translation.
     311 *
     312 *  \param p           A pointer to the MythPainter structure that
     313 *                     will be used to render this object onto the screen.
     314 *  \param xoffset     The X offset of the parent. Used to convert local
     315 *                     coordinates to global coordinates.
     316 *  \param yoffset     The Y offset of the parent. Used to convert local
     317 *                     coordinates to global coordinates.
     318 *  \param alphaMod    The alpha (transparency) value for this widget.
     319 *  \param clipRect    Ignored.
     320 */
    297321void MythUIGuideGrid::DrawSelf(MythPainter *p, int xoffset, int yoffset,
    298322                               int alphaMod, QRect clipRect)
    299323{
    void MythUIGuideGrid::DrawSelf(MythPainter *p, int xoffset, int yoffset, 
    306330            UIGTCon *data = *it;
    307331
    308332            if (data->m_recStat == 0)
    309                 drawBackground(p, data, alphaMod);
     333                drawBackground(p, xoffset, yoffset, data, alphaMod);
    310334            else if (data->m_recStat == 1)
    311                 drawBox(p, data, m_recordingColor, alphaMod);
     335                drawBox(p, xoffset, yoffset, data, m_recordingColor, alphaMod);
    312336            else
    313                 drawBox(p, data, m_conflictingColor, alphaMod);
     337                drawBox(p, xoffset, yoffset, data, m_conflictingColor, alphaMod);
    314338        }
    315339    }
    316340
    317     drawCurrent(p, &m_selectedItem, alphaMod);
     341    drawCurrent(p, xoffset, yoffset, &m_selectedItem, alphaMod);
    318342
    319343    for (int i = 0; i < m_rowCount; i++)
    320344    {
    void MythUIGuideGrid::DrawSelf(MythPainter *p, int xoffset, int yoffset, 
    323347        for (; it != m_allData[i].end(); ++it)
    324348        {
    325349            UIGTCon *data = *it;
    326             drawText(p, data, alphaMod);
     350            drawText(p, xoffset, yoffset, data, alphaMod);
    327351
    328352            if (data->m_recType != 0 || data->m_arrow != 0)
    329                 drawRecType(p, data, alphaMod);
     353                drawRecDecoration(p, xoffset, yoffset, data, alphaMod);
    330354        }
    331355    }
    332356}
    333357
    334 void MythUIGuideGrid::drawCurrent(MythPainter *p, UIGTCon *data, int alphaMod)
     358/** \fn MythUIGuideGrid::drawCurrent(MythPainter *, int, int, UIGTCon *, int)
     359 *  \brief Draws selection indication for a GuideGrid item.
     360 *
     361 *  This function is responsible for drawing decoration items that are
     362 *  unique to the currently selected entry. This may be a highlight
     363 *  rectangle around the entry, or special colors to indicate the
     364 *  currently selected entry. The type of decoration drawn depends
     365 *  upon the setting on the local m_SelType variable.
     366 *
     367 *  \param p           A pointer to the MythPainter structure that
     368 *                     will be used to render this object onto the screen.
     369 *  \param xoffset     The X offset of the parent. Used to convert local
     370 *                     coordinates to global coordinates.
     371 *  \param yoffset     The Y offset of the parent. Used to convert local
     372 *                     coordinates to global coordinates.
     373 *  \param data        A pointer to the GuideGrid object to be drawn.
     374 *  \param alphaMod    The alpha (transparency) value for this widget.
     375 */
     376void MythUIGuideGrid::drawCurrent(MythPainter *p, int xoffset, int yoffset, UIGTCon *data, int alphaMod)
    335377{
    336378    int breakin = 2;
    337379    QRect area = data->m_drawArea;
    338     area.translate(m_Area.x(), m_Area.y());
     380    area.translate(m_Area.x(), m_Area.y());     // Adjust within parent
     381    area.translate(xoffset, yoffset);           // Convert to global coordinates
    339382    area.adjust(breakin, breakin, -breakin, -breakin);
    340383    int status = data->m_recStat;
    341384
    void MythUIGuideGrid::drawCurrent(MythPainter *p, UIGTCon *data, int alphaMod) 
    382425    }
    383426}
    384427
    385 void MythUIGuideGrid::drawRecType(MythPainter *p, UIGTCon *data, int alphaMod)
     428/** \fn MythUIGuideGrid::drawRecDecoration(MythPainter *, int, int, UIGTCon *, int)
     429 *  \brief Draws decoration items for a GuideGrid item.
     430 *
     431 *  This function is responsible for drawing the decoration items onto
     432 *  an entry in the GuideGrid. It draws left/right (or up/down) arrows
     433 *  if the program time extends before or after what's visible in the
     434 *  window. If a show is scheduled to record, it also draws the badges
     435 *  that indicates the type of recording.
     436 *
     437 *  \param p           A pointer to the MythPainter structure that
     438 *                     will be used to render this object onto the screen.
     439 *  \param xoffset     The X offset of the parent. Used to convert local
     440 *                     coordinates to global coordinates.
     441 *  \param yoffset     The Y offset of the parent. Used to convert local
     442 *                     coordinates to global coordinates.
     443 *  \param data        A pointer to the GuideGrid object to be drawn.
     444 *  \param alphaMod    The alpha (transparency) value for this widget.
     445 */
     446void MythUIGuideGrid::drawRecDecoration(MythPainter *p, int xoffset, int yoffset, UIGTCon *data, int alphaMod)
    386447{
    387448    int breakin = 1;
    388449    QRect area = data->m_drawArea;
    389     area.translate(m_Area.x(), m_Area.y());
     450    area.translate(m_Area.x(), m_Area.y());     // Adjust within parent
     451    area.translate(xoffset, yoffset);           // Convert to global coordinates
    390452    area.adjust(breakin, breakin, -breakin, -breakin);
    391453
    392454    // draw arrows
    void MythUIGuideGrid::drawRecType(MythPainter *p, UIGTCon *data, int alphaMod) 
    435497    }
    436498}
    437499
    438 void MythUIGuideGrid::drawBox(MythPainter *p, UIGTCon *data, const QColor &color, int alphaMod)
     500/** \fn MythUIGuideGrid::drawBox(MythPainter *, int, int, UIGTCon *, int)
     501 *  \brief Draws the background for a GuideGrid item to be recorded.
     502 *
     503 *  This function is responsible for drawing the background behind all
     504 *  GuideGrid entries that are marked as being part of a recording
     505 *  rule. It draws a simple filled in box with no past/future
     506 *  demarcation.
     507 *
     508 *  \param p           A pointer to the MythPainter structure that
     509 *                     will be used to render this object onto the screen.
     510 *  \param xoffset     The X offset of the parent. Used to convert local
     511 *                     coordinates to global coordinates.
     512 *  \param yoffset     The Y offset of the parent. Used to convert local
     513 *                     coordinates to global coordinates.
     514 *  \param data        A pointer to the GuideGrid object to be drawn.
     515 *  \param alphaMod    The alpha (transparency) value for this widget.
     516 */
     517void MythUIGuideGrid::drawBox(MythPainter *p, int xoffset, int yoffset, UIGTCon *data, const QColor &color, int alphaMod)
    439518{
    440519    int breakin = 1;
    441520    QRect area = data->m_drawArea;
    442     area.translate(m_Area.x(), m_Area.y());
     521    area.translate(m_Area.x(), m_Area.y());     // Adjust within parent
     522    area.translate(xoffset, yoffset);           // Convert to global coordinates
    443523    area.adjust(breakin, breakin, -breakin, -breakin);
    444524
    445525    static const QPen nopen(Qt::NoPen);
    446526    p->DrawRect(area, QBrush(calcColor(color, m_categoryAlpha)), nopen, alphaMod);
    447527}
    448528
    449 void MythUIGuideGrid::drawBackground(MythPainter *p, UIGTCon *data, int alphaMod)
     529/** \fn MythUIGuideGrid::drawBackground(MythPainter *, int, int, UIGTCon *, int)
     530 *  \brief Draws the background for a GuideGrid item that will not be recorded.
     531 *
     532 *  This function is responsible for drawing the background behind all
     533 *  GuideGrid entries that are not marked as being part of a recording
     534 *  rule. It is responsible for drawing the demarcation line in the
     535 *  grid between past and future times. It also chooses the background
     536 *  color appropriate to the genre of the show.
     537 *
     538 *  \param p           A pointer to the MythPainter structure that
     539 *                     will be used to render this object onto the screen.
     540 *  \param xoffset     The X offset of the parent. Used to convert local
     541 *                     coordinates to global coordinates.
     542 *  \param yoffset     The Y offset of the parent. Used to convert local
     543 *                     coordinates to global coordinates.
     544 *  \param data        A pointer to the GuideGrid object to be drawn.
     545 *  \param alphaMod    The alpha (transparency) value for this widget.
     546 */
     547void MythUIGuideGrid::drawBackground(MythPainter *p, int xoffset, int yoffset, UIGTCon *data, int alphaMod)
    450548{
    451549    QColor overColor;
    452550    QRect overArea;
    453551
    454552    int breakin = 1;
    455553    QRect area = data->m_drawArea;
    456     area.translate(m_Area.x(), m_Area.y());
     554    area.translate(m_Area.x(), m_Area.y());     // Adjust within parent
    457555    QColor fillColor;
    458556
    459557    if (m_drawCategoryColors && data->m_categoryColor.isValid())
    void MythUIGuideGrid::drawBackground(MythPainter *p, UIGTCon *data, int alphaMod 
    461559    else
    462560        fillColor = calcColor(m_solidColor, m_categoryAlpha);
    463561
     562    // These calculations are in the parents local coordinates
    464563    if (m_verticalLayout)
    465564    {
    466565        if (m_progPastCol && area.top() < m_progPastCol)
    void MythUIGuideGrid::drawBackground(MythPainter *p, UIGTCon *data, int alphaMod 
    521620        area.setHeight(2);
    522621
    523622    static const QPen nopen(Qt::NoPen);
     623    area.translate(xoffset, yoffset);           // Convert to global coordinates
    524624    p->DrawRect(area, QBrush(fillColor), nopen, alphaMod);
    525625
    526     if (overArea.width() > 0)
     626    if (overArea.width() > 0) {
     627        overArea.translate(xoffset, yoffset);   // Convert to global coordinates
    527628        p->DrawRect(overArea, QBrush(overColor), nopen, alphaMod);
     629    }
    528630}
    529631
    530 void MythUIGuideGrid::drawText(MythPainter *p, UIGTCon *data, int alphaMod)
     632/** \fn MythUIGuideGrid::drawText(MythPainter *, int, int, UIGTCon *, int)
     633 *  \brief Draws text strings for a GuideGrid item.
     634 *
     635 *  This function is responsible for drawing the text onto an entry in
     636 *  the GuideGrid. It is smart enough to leave space for the guide
     637 *  item continuation arrow to be drawn.
     638 *
     639 *  \param p           A pointer to the MythPainter structure that
     640 *                     will be used to render this object onto the screen.
     641 *  \param xoffset     The X offset of the parent. Used to convert local
     642 *                     coordinates to global coordinates.
     643 *  \param yoffset     The Y offset of the parent. Used to convert local
     644 *                     coordinates to global coordinates.
     645 *  \param data        A pointer to the GuideGrid object to be drawn.
     646 *  \param alphaMod    The alpha (transparency) value for this widget.
     647 */
     648void MythUIGuideGrid::drawText(MythPainter *p, int xoffset, int yoffset, UIGTCon *data, int alphaMod)
    531649{
    532650    QString msg = data->m_title;
    533651
    void MythUIGuideGrid::drawText(MythPainter *p, UIGTCon *data, int alphaMod) 
    535653        msg += QString(" (%1)").arg(data->m_category);
    536654
    537655    QRect area = data->m_drawArea;
    538     area.translate(m_Area.x(), m_Area.y());
     656    area.translate(m_Area.x(), m_Area.y());     // Adjust within parent
     657    area.translate(xoffset, yoffset);           // Convert to global coordinates
    539658    area.adjust(m_textOffset.x(), m_textOffset.y(),
    540659                -m_textOffset.x(), -m_textOffset.y());
    541660
  • mythtv/libs/libmythui/mythuiguidegrid.h

    diff --git a/mythtv/libs/libmythui/mythuiguidegrid.h b/mythtv/libs/libmythui/mythuiguidegrid.h
    index 8b50877..7e1d0b8 100644
    a b class MUI_PUBLIC MythUIGuideGrid : public MythUIType 
    9393        int m_recStat;
    9494    };
    9595
    96     void drawBackground(MythPainter *p, UIGTCon *data, int alpaMod);
    97     void drawBox(MythPainter *p, UIGTCon *data, const QColor &color, int alpaMod);
    98     void drawText(MythPainter *p, UIGTCon *data, int alpaMod);
    99     void drawRecType(MythPainter *p, UIGTCon *data, int alpaMod);
    100     void drawCurrent(MythPainter *p, UIGTCon *data, int alpaMod);
     96    void drawBackground(MythPainter *p, int xoffset, int yoffset,
     97                        UIGTCon *data, int alpaMod);
     98    void drawBox(MythPainter *p, int xoffset, int yoffset, UIGTCon *data,
     99                 const QColor &color, int alpaMod);
     100    void drawText(MythPainter *p, int xoffset, int yoffset, UIGTCon *data,
     101                  int alpaMod);
     102    void drawRecDecoration(MythPainter *p, int xoffset, int yoffset,
     103                           UIGTCon *data, int alpaMod);
     104    void drawCurrent(MythPainter *p, int xoffset, int yoffset, UIGTCon *data,
     105                     int alpaMod);
    101106
    102107    QColor calcColor(const QColor &color, int alpha);
    103108