[mythtv] Window manager (program guide not getting focus)

Michael Kedl mythtv-dev@snowman.net
29 Dec 2002 23:24:01 -0500


--=-+YEgKIpnscuqiI/fIMR8
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Myth 0.7
RedHat 8.0
KDE
X drivers that came with RedHat 8; so I don't think its gatos

Here is a guidegrid.cpp to try.

Mike


On Sat, 2002-12-28 at 01:03, Kevin Bowen wrote:
> Ok, isaac was (of course) correct about themes.txt, so the gui size
> issue is taken care of, but I'm pretty much stumped on the EPG issue.
> Could you possibly give me a quick rundown of your setup so as to help
> me figure out where my problem is? i.e. what myth version are you
> running, on what linux distro, with what window manager? Do you have the
> gatos drivers installed for your radeon?
> 
> On Fri, 2002-12-27 at 09:55, Michael Kedl wrote:
> > I replied a few weeks ago to the list on how to fix this.
> > And since you have the same video card I'm assuming my fix will work for
> > you.
> > 
> > If you resize the epg background window to 100 taller than it is now,
> > the video will not cover the window in such a way that it must be in
> > front.
> > 
> > I can't remember the exact line of code, but search the archive for
> > posts by me in the last month or so.
> > 
> > Mike
> > 
> > On Fri, 2002-12-27 at 12:35, Kevin Bowen wrote:
> > > For as long as I've been experimenting with Myth, I've been having the
> > > problem of the EPG not being visible (it comes up in another window and
> > > grabs the input focus, but it doesn't overlay on the viewer... I had heard
> > > this mentioned on the list before and the answer given was to not use myth
> > > under gnome or KDE, to instead use a more lightweight window manager like
> > > FVWM... well I finally got around to installing FVWM, and the behavior is
> > > unchanged. Any other ideas for what might be causing this? Also (not sure if
> > > its related) the frontend doesnt stretch to fullscreen, it just sits in the
> > > top-left 800x600 of the screen (video does go fullscreen, just not the UI).
> > > I'm running redhat 8 with a radeon 7500 (with stock drivers, no gatos...
> > > could that be the issue?).
> > > 
> > > Kevin Bowen
> > > 
> > > _______________________________________________
> > > mythtv-dev mailing list
> > > mythtv-dev@snowman.net
> > > http://www.snowman.net/mailman/listinfo/mythtv-dev
> > > 
> > 
> > 
> > _______________________________________________
> > mythtv-dev mailing list
> > mythtv-dev@snowman.net
> > http://www.snowman.net/mailman/listinfo/mythtv-dev
> 
> 
> _______________________________________________
> mythtv-dev mailing list
> mythtv-dev@snowman.net
> http://www.snowman.net/mailman/listinfo/mythtv-dev
> 


--=-+YEgKIpnscuqiI/fIMR8
Content-Disposition: attachment; filename=guidegrid.cpp
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-c++; name=guidegrid.cpp; charset=ISO-8859-1

#include <qapplication.h>
#include <qpainter.h>
#include <qfont.h>
#include <qsqldatabase.h>
#include <qsqlquery.h>
#include <qaccel.h>
#include <math.h>
#include <qcursor.h>
#include <qapplication.h>
#include <qimage.h>

#include <iostream>
using namespace std;

#include "mythcontext.h"
#include "guidegrid.h"
#include "infodialog.h"
#include "infostructs.h"
#include "programinfo.h"
#include "settings.h"

using namespace libmyth;

GuideGrid::GuideGrid(MythContext *context, const QString &channel,=20
                     QWidget *parent, const char *name)
         : QDialog(parent, name)
{
    m_context =3D context;
    m_settings =3D context->settings();

    m_context->GetScreenSettings(screenwidth, wmult, screenheight, hmult);

//kedl    setGeometry(0, 0, screenwidth, screenheight);
//kedl    setFixedSize(QSize(screenwidth, screenheight));
    setGeometry(0, 0, 800, 700);
    setFixedSize(QSize(800, 700));

    setCursor(QCursor(Qt::BlankCursor));

    usetheme =3D m_settings->GetNumSetting("ThemeQt");
    showtitle =3D m_settings->GetNumSetting("EPGShowTitle");
    showIcon =3D m_settings->GetNumSetting("EPGShowChannelIcon");

    m_context->ThemeWidget(this, screenwidth, screenheight, wmult, hmult);

    bgcolor =3D paletteBackgroundColor();
    fgcolor =3D paletteForegroundColor();

    int timefontsize =3D m_settings->GetNumSetting("EPGTimeFontSize");
    if (timefontsize =3D=3D 0)=20
        timefontsize =3D 13;
    m_timeFont =3D new QFont("Arial", (int)(timefontsize * hmult), QFont::B=
old);

    int chanfontsize =3D m_settings->GetNumSetting("EPGChanFontSize");
    if (chanfontsize =3D=3D 0)=20
        chanfontsize =3D 13;
    m_chanFont =3D new QFont("Arial", (int)(chanfontsize * hmult), QFont::B=
old);

    chanfontsize =3D m_settings->GetNumSetting("EPGChanCallsignFontSize");
    if (chanfontsize =3D=3D 0)
        chanfontsize =3D 11;
    m_chanCallsignFont =3D new QFont("Arial", (int)(chanfontsize * hmult),=20
                                   QFont::Bold);

    int progfontsize =3D m_settings->GetNumSetting("EPGProgFontSize");
    if (progfontsize =3D=3D 0)=20
        progfontsize =3D 13;
    m_progFont =3D new QFont("Arial", (int)(progfontsize * hmult), QFont::B=
old);

    int titlefontsize =3D m_settings->GetNumSetting("EPGTitleFontSize");
    if (titlefontsize =3D=3D 0)=20
        titlefontsize =3D 19;
    m_titleFont =3D new QFont("Arial", (int)(titlefontsize * hmult), QFont:=
:Bold);

    m_originalStartTime =3D QDateTime::currentDateTime();

    int secsoffset =3D -((m_originalStartTime.time().minute() % 30) * 60 +
                        m_originalStartTime.time().second());
    m_currentStartTime =3D m_originalStartTime.addSecs(secsoffset);
    m_currentStartChannel =3D 0;
    m_startChanStr =3D channel;

    m_currentRow =3D 0;
    m_currentCol =3D 0;

    for (int y =3D 0; y < DISPLAY_CHANS; y++)
        m_programs[y] =3D NULL;

    for (int x =3D 0; x < DISPLAY_TIMES; x++)
    {
        m_timeInfos[x] =3D NULL;
        for (int y =3D 0; y < DISPLAY_CHANS; y++)
            m_programInfos[y][x] =3D NULL;
    }

    //QTime clock =3D QTime::currentTime();
    //clock.start();
    fillTimeInfos();
    //int filltime =3D clock.elapsed();
    //clock.restart();
    fillChannelInfos();
    //int fillchannels =3D clock.elapsed();
    //clock.restart();
    fillProgramInfos();
    //int fillprogs =3D clock.elapsed();

    //cout << filltime << " " << fillchannels << " " << fillprogs << endl;

    QAccel *accel =3D new QAccel(this);
    accel->connectItem(accel->insertItem(Key_Left), this, SLOT(cursorLeft()=
));
    accel->connectItem(accel->insertItem(Key_Right), this, SLOT(cursorRight=
()));
    accel->connectItem(accel->insertItem(Key_Down), this, SLOT(cursorDown()=
));
    accel->connectItem(accel->insertItem(Key_Up), this, SLOT(cursorUp()));

    accel->connectItem(accel->insertItem(Key_A), this, SLOT(cursorLeft()));
    accel->connectItem(accel->insertItem(Key_D), this, SLOT(cursorRight()))=
;
    accel->connectItem(accel->insertItem(Key_S), this, SLOT(cursorDown()));
    accel->connectItem(accel->insertItem(Key_W), this, SLOT(cursorUp()));

    accel->connectItem(accel->insertItem(Key_Home), this, SLOT(dayLeft()));
    accel->connectItem(accel->insertItem(Key_End), this, SLOT(dayRight()));
    accel->connectItem(accel->insertItem(CTRL + Key_Left), this,=20
                       SLOT(pageLeft()));
    accel->connectItem(accel->insertItem(CTRL + Key_Right), this,=20
                       SLOT(pageRight()));
    accel->connectItem(accel->insertItem(Key_PageUp), this, SLOT(pageUp()))=
;
    accel->connectItem(accel->insertItem(Key_PageDown), this, SLOT(pageDown=
()));

    accel->connectItem(accel->insertItem(Key_C), this, SLOT(escape()));
    accel->connectItem(accel->insertItem(Key_Escape), this, SLOT(escape()))=
;
    accel->connectItem(accel->insertItem(Key_Enter), this, SLOT(enter()));
    accel->connectItem(accel->insertItem(Key_M), this, SLOT(enter()));

    accel->connectItem(accel->insertItem(Key_I), this, SLOT(displayInfo()))=
;
    accel->connectItem(accel->insertItem(Key_Space), this, SLOT(displayInfo=
()));

    connect(this, SIGNAL(killTheApp()), this, SLOT(accept()));

    selectState =3D false;
    showInfo =3D false;

    WFlags flags =3D getWFlags();
    flags |=3D WRepaintNoErase;
    setWFlags(flags);

    showFullScreen();
    setActiveWindow();
    raise();
    setFocus();
}

GuideGrid::~GuideGrid()
{
    for (int x =3D 0; x < DISPLAY_TIMES; x++)
    {
        if (m_timeInfos[x])
            delete m_timeInfos[x];
    }

    for (int y =3D 0; y < DISPLAY_CHANS; y++)
    {
        if (m_programs[y])
            delete m_programs[y];
    }

    m_channelInfos.clear();

    delete m_timeFont;
    delete m_chanFont;
    delete m_chanCallsignFont;
    delete m_progFont;
    delete m_titleFont;
}

QString GuideGrid::getLastChannel(void)
{
    unsigned int chanNum =3D m_currentRow + m_currentStartChannel;
    if (chanNum >=3D m_channelInfos.size())
        chanNum -=3D m_channelInfos.size();

    if (selectState)
        return m_channelInfos[chanNum].chanstr;
    return 0;
}

void GuideGrid::fillChannelInfos()
{
    m_channelInfos.clear();

    QString thequery;
    QSqlQuery query;

    QString ordering =3D m_settings->GetSetting("ChannelSorting");
    if (ordering =3D=3D "")
        ordering =3D "channum + 0";
   =20
    thequery =3D "SELECT channum,callsign,icon,chanid FROM channel "
               "ORDER BY " + ordering;
    query.exec(thequery);
   =20
    bool set =3D false;
   =20
    if (query.isActive() && query.numRowsAffected() > 0)
    {
        while (query.next())
        {
            ChannelInfo val;
            val.callsign =3D query.value(1).toString();
            if (val.callsign =3D=3D QString::null)
                val.callsign =3D "";
            val.iconpath =3D query.value(2).toString();
            if (val.iconpath =3D=3D QString::null)
                val.iconpath =3D "";
            val.chanstr =3D query.value(0).toString();
            if (val.chanstr =3D=3D QString::null)
                val.chanstr =3D "";
            val.chanid =3D query.value(3).toInt();
            val.icon =3D NULL;
       =20
            if (val.chanstr =3D=3D m_startChanStr && !set)
            {
                m_currentStartChannel =3D m_channelInfos.size();
                set =3D true;
            }
	=09
            m_channelInfos.push_back(val);
        }
    }
    else
    {
        cerr << "You don't have any channels defined in the database\n";
        cerr << "This isn't going to work.\n";
    }
}

void GuideGrid::fillTimeInfos()
{
    for (int x =3D 0; x < DISPLAY_TIMES; x++)
    {
        if (m_timeInfos[x])
            delete m_timeInfos[x];
        m_timeInfos[x] =3D NULL;
    }

    QDateTime t =3D m_currentStartTime;

    for (int x =3D 0; x < DISPLAY_TIMES; x++)
    {
        TimeInfo *timeinfo =3D new TimeInfo;

        int mins =3D t.time().minute();
        mins =3D 5 * (mins / 5);
        if (mins % 30 =3D=3D 0)
        {
            int hour =3D t.time().hour();
            timeinfo->hour =3D hour;
            timeinfo->min =3D mins;

            QString timeformat =3D m_settings->GetSetting("TimeFormat");
            if (timeformat =3D=3D "")
                timeformat =3D "h:mm AP";

            timeinfo->usertime =3D QTime(hour, mins).toString(timeformat);

            m_timeInfos[x] =3D timeinfo;
        }

        t =3D t.addSecs(5 * 60);
    }
    m_currentEndTime =3D t;
}

void GuideGrid::fillProgramInfos(void)
{
    for (int y =3D 0; y < DISPLAY_CHANS; y++)
    {
        fillProgramRowInfos(y);
    }
}

void GuideGrid::fillProgramRowInfos(unsigned int row)
{
    QPtrList<ProgramInfo> *proglist;
    ProgramInfo *program;

    proglist =3D m_programs[row];
    if (proglist)
    {
        for (program =3D proglist->first(); program; program =3D proglist->=
next())
        {
            delete program;
        }
        delete proglist;
    }

    for (int x =3D 0; x < DISPLAY_TIMES; x++)
    {
        m_programInfos[row][x] =3D NULL;
    }

    int chanNum =3D row + m_currentStartChannel;
    if (chanNum >=3D (int)m_channelInfos.size())
        chanNum -=3D (int)m_channelInfos.size();
    if (chanNum < 0)
        chanNum =3D 0;

    if (m_channelInfos[chanNum].chanstr !=3D "")
    {
        m_programs[row] =3D proglist =3D new QPtrList<ProgramInfo>;

        QString chanid =3D QString("%1").arg(m_channelInfos[chanNum].chanid=
);

        char temp[16];
        sprintf(temp, "%4d%02d%02d%02d%02d00",
                m_currentStartTime.date().year(),
                m_currentStartTime.date().month(),
                m_currentStartTime.date().day(),
                m_currentStartTime.time().hour(),
                m_currentStartTime.time().minute());
        QString starttime =3D temp;
        sprintf(temp, "%4d%02d%02d%02d%02d00",
                m_currentEndTime.date().year(),
                m_currentEndTime.date().month(),
                m_currentEndTime.date().day(),
                m_currentEndTime.time().hour(),
                m_currentEndTime.time().minute());
        QString endtime =3D temp;

        GetProgramRangeDateTime(proglist, chanid, starttime, endtime);

        QDateTime ts =3D m_currentStartTime;

        program =3D proglist->first();
        ProgramInfo *proginfo =3D NULL;
        QPtrList<ProgramInfo> unknownlist;
        bool unknown =3D false;

        for (int x =3D 0; x < DISPLAY_TIMES; x++)
        {
            if (program && (ts >=3D (*program).endts))
            {
                program =3D proglist->next();
            }

            if ((!program) || (ts < (*program).startts))
            {
                if (unknown)
                {
                    proginfo->spread++;
                    proginfo->endts =3D proginfo->endts.addSecs(5 * 60);
                }
                else
                {
                    proginfo =3D new ProgramInfo;
                    unknownlist.append(proginfo);
                    proginfo->title =3D m_settings->GetSetting("UnknownTitl=
e");
                    proginfo->category =3D=20
                                      m_settings->GetSetting("UnknownCatego=
ry");
                    proginfo->startCol =3D x;
                    proginfo->spread =3D 1;
                    proginfo->startts =3D ts;
                    proginfo->endts =3D proginfo->startts.addSecs(5 * 60);
                    unknown =3D true;
                }
            }
            else
            {
                if (proginfo =3D=3D &*program)
                {
                    proginfo->spread++;
                }
                else
                {
                    proginfo =3D &*program;
                    proginfo->startCol =3D x;
                    proginfo->spread =3D 1;
                    unknown =3D false;
                }
            }
            m_programInfos[row][x] =3D proginfo;
            ts =3D ts.addSecs(5 * 60);
        }

        for (proginfo =3D unknownlist.first(); proginfo;=20
             proginfo =3D unknownlist.next())
        {
            proglist->append(proginfo);
        }
    }
}

void GuideGrid::paintEvent(QPaintEvent *e)
{
    QRect r =3D e->rect();
    QPainter p(this);

    if (showInfo)
    {
    }
    else
    {
        if (r.intersects(dateRect()))
            paintDate(&p);
        if (r.intersects(channelRect()))
            paintChannels(&p);
        if (r.intersects(timeRect()))
            paintTimes(&p);
        if (r.intersects(programRect()))
            paintPrograms(&p);
        if (showtitle && r.intersects(titleRect()))
            paintTitle(&p);
    }
}

void GuideGrid::paintDate(QPainter *p)
{
    QRect dr =3D dateRect();
    QPixmap pix(dr.size());
    pix.fill(this, dr.topLeft());

    QPainter tmp(&pix);
    tmp.setBrush(fgcolor);
    tmp.setPen(QPen(fgcolor, (int)(2 * wmult)));
    tmp.setFont(*m_timeFont);

    QString date =3D m_currentStartTime.toString("ddd");
    QFontMetrics lfm(*m_timeFont);
    int datewidth =3D lfm.width(date);
    int dateheight =3D lfm.height();

    tmp.drawText((dr.width() - datewidth) / 2,
                 (dr.height() - dateheight) / 2 + dateheight / 3, date);

    date =3D m_currentStartTime.toString("MMM d");
    datewidth =3D lfm.width(date);

    tmp.drawText((dr.width() - datewidth) / 2,
                 (dr.height() - dateheight) / 2 + dateheight * 4 / 3, date)=
;

    tmp.drawLine(0, dr.height() - 1, dr.right(), dr.height() - 1);
    tmp.drawLine(dr.width() - 1, 0, dr.width() - 1, dr.height());

    tmp.end();

    p->drawPixmap(dr.topLeft(), pix);
}

void GuideGrid::paintChannels(QPainter *p)
{
    QRect cr =3D channelRect();
    QPixmap pix(cr.size());
    pix.fill(this, cr.topLeft());

    QPainter tmp(&pix);
    tmp.setBrush(fgcolor);
    tmp.setPen(QPen(fgcolor, (int)(2 * wmult)));
    tmp.setFont(*m_chanFont);

    int ydifference =3D cr.height() / DISPLAY_CHANS;

    for (unsigned int y =3D 0; y < DISPLAY_CHANS; y++)
    {
        unsigned int chanNumber =3D y + m_currentStartChannel;
        if (chanNumber >=3D m_channelInfos.size())
            chanNumber -=3D m_channelInfos.size();
 =20
        if (m_channelInfos[chanNumber].chanstr =3D=3D "")
            break;

        ChannelInfo *chinfo =3D &(m_channelInfos[chanNumber]);
        if (chinfo->iconpath !=3D "none" && chinfo->iconpath !=3D "" && sho=
wIcon)
        {
            if (!chinfo->icon)
                chinfo->LoadIcon(m_context);
            if (chinfo->icon)
            {
                int yoffset =3D (int)(4 * hmult);
                tmp.drawPixmap((cr.width() - chinfo->icon->width()) / 2,=20
                               ydifference * y + yoffset, *(chinfo->icon));
            }
        }

        tmp.setFont(*m_chanFont);
        QFontMetrics lfm(*m_chanFont);
        int width =3D lfm.width(chinfo->chanstr);
        int bheight =3D lfm.height();
      =20
        int yoffset =3D 0;
        if (showIcon)
            yoffset =3D (int)(43 * hmult);=20
        tmp.drawText((cr.width() - width) / 2,=20
                     ydifference * y + yoffset + bheight, chinfo->chanstr);

        tmp.setFont(*m_chanCallsignFont);
        QFontMetrics fm(*m_chanCallsignFont);
        width =3D fm.width(chinfo->callsign);
        int height =3D fm.height();
        tmp.drawText((cr.width() - width) / 2,=20
                     ydifference * y + yoffset + bheight + height,=20
                     chinfo->callsign);

        tmp.drawLine(0, ydifference * (y + 1), cr.right(),=20
                     ydifference * (y + 1));
    }

    tmp.drawLine(cr.right(), 0, cr.right(), DISPLAY_CHANS * ydifference);

    tmp.end();
   =20
    p->drawPixmap(cr.topLeft(), pix);
}

void GuideGrid::paintTimes(QPainter *p)
{
    QRect tr =3D timeRect();
    QPixmap pix(tr.size());
    pix.fill(this, tr.topLeft());

    QPainter tmp(&pix);
    tmp.setBrush(fgcolor);
    tmp.setPen(QPen(fgcolor, (int)(2 * wmult)));
    tmp.setFont(*m_timeFont);

    int xdifference =3D (int)(tr.width() / DISPLAY_TIMES);=20

    for (int x =3D 0; x < DISPLAY_TIMES; x++)
    {
        if (m_timeInfos[x])
        {
            tmp.drawLine((x + 6) * xdifference, 0, (x + 6) * xdifference,=20
                         tr.bottom());
        }
    }

    for (int x =3D 0; x < DISPLAY_TIMES; x++)
    {
        if (m_timeInfos[x])
        {
            TimeInfo *tinfo =3D m_timeInfos[x];

            QFontMetrics fm(*m_timeFont);
            int width =3D fm.width(tinfo->usertime);
            int height =3D fm.height();

            int xpos =3D (x * xdifference) + (xdifference * 6 - width) / 2;=
=20
            tmp.drawText(xpos, (tr.bottom() - height) / 2 + height,=20
                         tinfo->usertime);
        }
    }

    tmp.drawLine(0, tr.height() - 1, tr.right(), tr.height() - 1);

    tmp.end();

    p->drawPixmap(tr.topLeft(), pix);
}

QBrush GuideGrid::getBGColor(const QString &category)
{
    QBrush br =3D QBrush(bgcolor);
  =20
    if (!usetheme)
        return br;

    QString cat =3D "Cat_" + category;

    QString color =3D m_settings->GetSetting(cat);
    if (color !=3D "")
    {
        br =3D QBrush(color);
    }

    return br;
}

QRgb blendColors(QRgb source, QRgb add, int alpha)
{
    int sred =3D qRed(source);
    int sgreen =3D qGreen(source);
    int sblue =3D qBlue(source);

    int tmp1 =3D (qRed(add) - sred) * alpha;
    int tmp2 =3D sred + ((tmp1 + (tmp1 >> 8) + 0x80) >> 8);
    sred =3D tmp2 & 0xff;

    tmp1 =3D (qGreen(add) - sgreen) * alpha;
    tmp2 =3D sgreen + ((tmp1 + (tmp1 >> 8) + 0x80) >> 8);
    sgreen =3D tmp2 & 0xff;

    tmp1 =3D (qBlue(add) - sblue) * alpha;
    tmp2 =3D sblue + ((tmp1 + (tmp1 >> 8) + 0x80) >> 8);
    sblue =3D tmp2 & 0xff;

    return qRgb(sred, sgreen, sblue);
}


void GuideGrid::paintPrograms(QPainter *p)
{
    QRect pr =3D programRect();
    QPixmap pix(pr.size());
    pix.fill(this, pr.topLeft());

    QImage bgimage =3D pix.convertToImage();

    QPainter tmp(&pix);
    tmp.setPen(QPen(fgcolor, (int)(2 * wmult)));

    tmp.setFont(*m_progFont);

    int ydifference =3D pr.height() / DISPLAY_CHANS;
    int xdifference =3D pr.width() / DISPLAY_TIMES;

    for (int y =3D 1; y < DISPLAY_CHANS + 1; y++)
    {
        int ypos =3D ydifference * y;
        tmp.drawLine(0, ypos, pr.right(), ypos);
    }

    float tmpwmult =3D wmult;
    if (tmpwmult < 1)
        tmpwmult =3D 1;
    float tmphmult =3D hmult;
    if (tmphmult < 1)
        tmphmult =3D 1;
=20
    for (int y =3D 0; y < DISPLAY_CHANS; y++)
    {
        unsigned int chanNum =3D y + m_currentStartChannel;
        if (chanNum >=3D m_channelInfos.size())
            chanNum -=3D m_channelInfos.size();

        if (m_channelInfos[chanNum].chanstr =3D=3D "")
            break;

        QDateTime lastprog;
        for (int x =3D 0; x < DISPLAY_TIMES; x++)
        {
            ProgramInfo *pginfo =3D m_programInfos[y][x];

            if (pginfo->recordtype =3D=3D kUnknown)
                pginfo->GetProgramRecordingStatus();

            int spread =3D 1;
            if (pginfo->startts !=3D lastprog)
            {
                QFontMetrics fm(*m_progFont);
                int height =3D fm.height();

                if (pginfo->spread !=3D -1)
                {
                    spread =3D pginfo->spread;
                }
                else
                {
                    for (int z =3D x + 1; z < DISPLAY_TIMES; z++)
                    {
                        if (m_programInfos[y][z]->startts =3D=3D pginfo->st=
artts)
                            spread++;
                    }
                    pginfo->spread =3D spread;
                    pginfo->startCol =3D x;

                    for (int z =3D x + 1; z < x + spread; z++)
                    {
                        m_programInfos[y][z]->spread =3D spread;
                        m_programInfos[y][z]->startCol =3D x;
                        m_programInfos[y][z]->recordtype =3D pginfo->record=
type;
                    }
                }

                QBrush br =3D getBGColor(pginfo->category);

                if (br !=3D QBrush(bgcolor))
                {
                    QRgb blendcolor =3D br.color().rgb();

                    int startx =3D (int)(x * xdifference + 1 * tmpwmult);
                    int endx =3D (int)((x + spread) * xdifference - 2 * tmp=
wmult);
                    int starty =3D (int)(ydifference * y + 1 * tmphmult);
                    int endy =3D (int)(ydifference * (y + 1) - 2 * tmphmult=
);
=20
                    if (x =3D=3D 0)
                        startx--;
                    if (y =3D=3D 0)
                        starty--;

                    if (startx < 0)
                        startx =3D 0;
                    if (starty < 0)
                        starty =3D 0;
                    if (endx > pr.right())
                        endx =3D pr.right();
                    if (endy > pr.bottom())
                        endy =3D pr.bottom();

                    unsigned int *data =3D NULL;
                  =20
                    for (int tmpy =3D starty; tmpy <=3D endy; tmpy++)
                    {
                        data =3D (unsigned int *)bgimage.scanLine(tmpy);
                        for (int tmpx =3D startx; tmpx <=3D endx; tmpx++)
                        {
                            QRgb pixelcolor =3D data[tmpx];
                            data[tmpx] =3D blendColors(pixelcolor, blendcol=
or,=20
                                                     96);
                        }
                    }
                    tmp.drawImage(startx, starty, bgimage, startx, starty,=20
                                  endx - startx + 1,=20
                                  endy - starty + 1);
                }

                int maxwidth =3D (int)(spread * xdifference - (10 * wmult))=
;

                QString info =3D pginfo->title;
                if (pginfo->category !=3D "" && pginfo->title !=3D "" && us=
etheme)
                    info +=3D " (" + pginfo->category + ")";
               =20
                int startx =3D (int)(x * xdifference + 7 * wmult);
                tmp.drawText(startx,
                             (int)(height / 8 + y * ydifference + 1 * hmult=
),=20
                             maxwidth, ydifference - height / 8,
                             AlignLeft | WordBreak,
                             info);

                tmp.setPen(QPen(fgcolor, (int)(2 * wmult)));

                startx =3D (int)((x + spread) * xdifference);=20
                tmp.drawLine(startx, ydifference * y, startx,=20
                             ydifference * (y + 1));

                if (pginfo->recordtype > kNotRecording)
                {
                    tmp.setPen(QPen(red, (int)(2 * wmult)));
                    QString text;

                    if (pginfo->recordtype =3D=3D kSingleRecord)
                        text =3D "R";
                    else if (pginfo->recordtype =3D=3D kTimeslotRecord)
                        text =3D "T";
                    else if (pginfo->recordtype =3D=3D kChannelRecord)
                        text =3D "C";
                    else if (pginfo->recordtype =3D=3D kAllRecord)=20
                        text =3D "A";

                    int width =3D fm.width(text);

                    startx =3D (int)((x + spread) * xdifference - width * 1=
.5);=20
                    tmp.drawText(startx, (y + 1) * ydifference - height,
                                 (int)(width * 1.5), height, AlignLeft, tex=
t);
           =20
                    tmp.setPen(QPen(fgcolor, (int)(2 * wmult)));
                }

                if (m_currentRow =3D=3D (int)y)
                {
                    if ((m_currentCol >=3D x) && (m_currentCol < (x + sprea=
d)))
                    {
                        tmp.setPen(QPen(red, (int)(3.75 * wmult)));

                        int ystart =3D 1;
                        int rectheight =3D (int)(ydifference - 3 * tmphmult=
);
                        if (y !=3D 0)
                        {
                            ystart =3D (int)(ydifference * y + 2 * tmphmult=
);
                            rectheight =3D (int)(ydifference - 4 * tmphmult=
);
                        }

                        int xstart =3D 1;
                        if (x !=3D 0)
                            xstart =3D (int)(x * xdifference + 2 * tmpwmult=
);
                        int xend =3D (int)(xdifference * spread - 4 * tmpwm=
ult);
                        if (x =3D=3D 0)
                            xend +=3D (int)(1 * tmpwmult);
		=09
                        tmp.drawRect(xstart, ystart, xend, rectheight);
                        tmp.setPen(QPen(fgcolor, (int)(2 * wmult)));
                    }
                }
            }
            lastprog =3D pginfo->startts;
        }
    }

    tmp.end();

    p->drawPixmap(pr.topLeft(), pix);
}

void GuideGrid::paintTitle(QPainter *p)
{
    QRect tr =3D titleRect();
    QPixmap pix(tr.size());
    pix.fill(this, tr.topLeft());

    QPainter tmp(&pix);
    tmp.setBrush(fgcolor);
    tmp.setPen(QPen(fgcolor, (int)(2 * wmult)));
    tmp.setFont(*m_titleFont);

    ProgramInfo *pginfo =3D m_programInfos[m_currentRow][m_currentCol];
    QFontMetrics lfm(*m_titleFont);
    int titleheight =3D lfm.height();

    QString info =3D pginfo->title;
    if (pginfo->category !=3D "" && usetheme)
       info +=3D " (" + pginfo->category + ")";

    tmp.drawText((tr.height() - titleheight) / 2 ,=20
                 (tr.height() - titleheight) / 2 + titleheight,
                 info);

    tmp.end();
   =20
    p->drawPixmap(tr.topLeft(), pix);
}

QRect GuideGrid::fullRect() const
{
    QRect r(0, 0, (int)(800 * wmult), (int)(600 * hmult));=20
    return r;
}

QRect GuideGrid::dateRect() const
{
    QRect r(0, 0, programRect().left(), programRect().top());
    return r;
}

QRect GuideGrid::channelRect() const
{
    QRect r(0, dateRect().height(), dateRect().width(), programRect().heigh=
t());
    return r;
}

QRect GuideGrid::timeRect() const
{
    QRect r(dateRect().width(), 0, programRect().width(), dateRect().height=
());
    return r;
}

QRect GuideGrid::programRect() const
{
    // Change only these numbers to adjust the size of the visible regions

    unsigned int min_dateheight =3D 50;  // also min_timeheight
    unsigned int min_datewidth =3D 74;   // also min_chanwidth
    unsigned int titleheight =3D showtitle ? 40 : 0;

    unsigned int programheight =3D (int)((600 - min_dateheight - titleheigh=
t) *=20
                                       wmult);
    programheight =3D DISPLAY_CHANS * (int)(programheight / DISPLAY_CHANS);

    unsigned int programwidth =3D (int)((800 - min_datewidth) * hmult);
    programwidth =3D DISPLAY_TIMES * (int)(programwidth / DISPLAY_TIMES);

    QRect r((int)(800 * wmult) - programwidth,=20
            (int)(600 * hmult) - programheight - titleheight,
            programwidth, programheight);

    return r;
}

QRect GuideGrid::titleRect() const
{
    QRect r(0, programRect().bottom() + 1, fullRect().width(),=20
            fullRect().height() - programRect().bottom());
    return r;
}

void GuideGrid::cursorLeft()
{
    int startCol =3D m_programInfos[m_currentRow][m_currentCol]->startCol;

    m_currentCol =3D startCol - 1;

    if (m_currentCol < 0)
    {
        m_currentCol =3D 0;
        emit scrollLeft();
    }
    else
    {
        update(programRect());
        if (showtitle)
            update(titleRect());
    }
}

void GuideGrid::cursorRight()
{
    int spread =3D m_programInfos[m_currentRow][m_currentCol]->spread;
    int startCol =3D m_programInfos[m_currentRow][m_currentCol]->startCol;

    m_currentCol =3D startCol + spread;

    if (m_currentCol > DISPLAY_TIMES - 1)
    {
        m_currentCol =3D DISPLAY_TIMES - 1;
        emit scrollRight();
    }
    else
    {
        update(programRect());
        if (showtitle)
            update(titleRect());
    }
}

void GuideGrid::cursorDown()
{
    m_currentRow++;

    if (m_currentRow > DISPLAY_CHANS - 1)
    {
        m_currentRow =3D DISPLAY_CHANS - 1;
        emit scrollDown();
    }
    else
    {
        update(programRect());
        if (showtitle)
            update(titleRect());
    }
}

void GuideGrid::cursorUp()
{
    m_currentRow--;

    if (m_currentRow < 0)
    {
        m_currentRow =3D 0;
        emit scrollUp();
    }
    else
    {
        update(programRect());
        if (showtitle)
            update(titleRect());
    }
}

void GuideGrid::scrollLeft()
{
    bool updatedate =3D false;

    QDateTime t =3D m_currentStartTime;

    t =3D m_currentStartTime.addSecs(-30 * 60);

    if (t.date().day() !=3D m_currentStartTime.date().day())
        updatedate =3D true;

    m_currentStartTime =3D t;

    fillTimeInfos();
    fillProgramInfos();

    update(timeRect());
    if (updatedate)=20
        update(dateRect());
    update(programRect());
    if (showtitle)
        update(titleRect());
}

void GuideGrid::scrollRight()
{
    bool updatedate =3D false;

    QDateTime t =3D m_currentStartTime;
    t =3D m_currentStartTime.addSecs(30 * 60);

    if (t.date().day() !=3D m_currentStartTime.date().day())
        updatedate =3D true;

    m_currentStartTime =3D t;

    fillTimeInfos();
    fillProgramInfos();

    update(timeRect());
    if (updatedate)
        update(dateRect());
    update(programRect());
    if (showtitle)
        update(titleRect());
}

void GuideGrid::setStartChannel(int newStartChannel)
{
    if (newStartChannel <=3D 0)
        m_currentStartChannel =3D newStartChannel + m_channelInfos.size();
    else if (newStartChannel >=3D (int) m_channelInfos.size())
        m_currentStartChannel =3D newStartChannel - m_channelInfos.size();
    else
        m_currentStartChannel =3D newStartChannel;
}

void GuideGrid::scrollDown()
{
    setStartChannel(m_currentStartChannel + 1);

    QPtrList<ProgramInfo> *proglist =3D m_programs[0];
    for (int y =3D 0; y < DISPLAY_CHANS - 1; y++)
    {
        m_programs[y] =3D m_programs[y + 1];
        for (int x =3D 0; x < DISPLAY_TIMES; x++)
        {
            m_programInfos[y][x] =3D m_programInfos[y + 1][x];
        }
    }=20
    m_programs[DISPLAY_CHANS - 1] =3D proglist;
    fillProgramRowInfos(DISPLAY_CHANS - 1);

    update(channelRect());
    update(programRect());
    if (showtitle)
        update(titleRect());
}

void GuideGrid::scrollUp()
{
    setStartChannel(m_currentStartChannel - 1);

    QPtrList<ProgramInfo> *proglist =3D m_programs[DISPLAY_CHANS - 1];
    for (int y =3D DISPLAY_CHANS - 1; y > 0; y--)
    {
        m_programs[y] =3D m_programs[y - 1];
        for (int x =3D 0; x < DISPLAY_TIMES; x++)
        {
            m_programInfos[y][x] =3D m_programInfos[y - 1][x];
        }
    }=20
    m_programs[0] =3D proglist;
    fillProgramRowInfos(0);

    update(channelRect());
    update(programRect());
    if (showtitle)
        update(titleRect());
}

void GuideGrid::dayLeft()
{
    m_currentStartTime =3D m_currentStartTime.addSecs(-24 * 60 * 60);

    fillTimeInfos();
    fillProgramInfos();

    update(dateRect());
    update(timeRect());
    update(programRect());
    if (showtitle)
        update(titleRect());
}

void GuideGrid::dayRight()
{
    m_currentStartTime =3D m_currentStartTime.addSecs(24 * 60 * 60);

    fillTimeInfos();
    fillProgramInfos();

    update(dateRect());
    update(timeRect());
    update(programRect());
    if (showtitle)
        update(titleRect());
}

void GuideGrid::pageLeft()
{
    bool updatedate =3D false;

    QDateTime t =3D m_currentStartTime;

    t =3D m_currentStartTime.addSecs(-5 * 60 * DISPLAY_TIMES);

    if (t.date().day() !=3D m_currentStartTime.date().day())
        updatedate =3D true;

    m_currentStartTime =3D t;

    fillTimeInfos();
    fillProgramInfos();

    update(timeRect());
    if (updatedate)
        update(dateRect());
    update(programRect());
    if (showtitle)
        update(titleRect());
}

void GuideGrid::pageRight()
{
    bool updatedate =3D false;

    QDateTime t =3D m_currentStartTime;

    t =3D m_currentStartTime.addSecs(5 * 60 * DISPLAY_TIMES);

    if (t.date().day() !=3D m_currentStartTime.date().day())
        updatedate =3D true;

    m_currentStartTime =3D t;

    fillTimeInfos();
    fillProgramInfos();

    update(timeRect());
    if (updatedate)
        update(dateRect());
    update(programRect());
    if (showtitle)
        update(titleRect());
}

void GuideGrid::pageDown()
{
    setStartChannel(m_currentStartChannel + DISPLAY_CHANS);

    fillProgramInfos();

    update(channelRect());
    update(programRect());
    if (showtitle)
        update(titleRect());
}

void GuideGrid::pageUp()
{
    setStartChannel(m_currentStartChannel - DISPLAY_CHANS);

    fillProgramInfos();

    update(channelRect());
    update(programRect());
    if (showtitle)
        update(titleRect());
}

void GuideGrid::enter()
{
    unsetCursor();
    selectState =3D 1;
    emit killTheApp();
}

void GuideGrid::escape()
{
    unsetCursor();
    emit killTheApp();
}

void GuideGrid::displayInfo()
{
    showInfo =3D 1;

    ProgramInfo *pginfo =3D m_programInfos[m_currentRow][m_currentCol];

    if (pginfo)
    {
        InfoDialog diag(m_context, pginfo, this, "Program Info");
        diag.setCaption("BLAH!!!");
        diag.exec();
    }

    showInfo =3D 0;

    pginfo->GetProgramRecordingStatus();

    int startcol =3D pginfo->startCol;
    int spread =3D pginfo->spread;
    RecordingType rectype =3D pginfo->recordtype;

    for (int i =3D 0; i < spread; i++)
    {
        m_programInfos[m_currentRow][startcol + i]->recordtype =3D rectype;
    }

    setActiveWindow();
    setFocus();

    update(programRect());
}

--=-+YEgKIpnscuqiI/fIMR8--