Ticket #3506: reuse_button_images.2.diff

File reuse_button_images.2.diff, 5.1 KB (added by stuartm, 17 years ago)

Added the same prevention of duplicates for title icons

  • mythtv/libs/libmythui/myththemedmenu.cpp

     
    135135    bool buttoncenter;
    136136
    137137    QMap<QString, MythImage *> titleIcons;
     138    QMap<QString, MythImage *> m_loadedImages;
    138139    QString titleText;
    139140    QPoint titlePos;
    140141
     
    834835        {
    835836            if (info.tagName() == "image")
    836837            {
     838
    837839                QString titlepath = dir + getFirstText(info);
    838                 QImage *tmppix = gContext->LoadScaleImage(titlepath);
    839840
    840                 if (!tmppix)
    841                     continue;
    842 
    843841                QString name = info.attribute("mode", "");
    844842                if (name != "")
    845843                {
    846                     titleIcons[name] = MythImage::FromQImage(&tmppix);
     844                    MythImage *icon;
     845                    QImage *tmppix;
     846
     847                    if (m_loadedImages[titlepath])
     848                    {
     849                        icon = m_loadedImages[titlepath];
     850                        icon->UpRef();
     851                    }
     852                    else
     853                    {
     854                        tmppix = gContext->LoadScaleImage(titlepath);
     855
     856                        if (!tmppix)
     857                            continue;
     858
     859                        icon = MythImage::FromQImage(&tmppix);
     860                        m_loadedImages.insert(titlepath, icon);
     861                    }
     862
     863                    titleIcons[name] = icon;
    847864                }
    848865                else
    849866                {
     
    952969    bool hasicon = false;
    953970
    954971    QString name = "";
    955     QImage *image = NULL;
    956     QImage *activeimage = NULL;
    957     QImage *watermark = NULL;
     972    QImage *tmpimg = NULL;
     973    MythImage *image = NULL;
     974    MythImage *activeimage = NULL;
     975    MythImage *watermark = NULL;
    958976    QPoint offset;
    959977
    960978    name = element.attribute("name", "");
     
    963981
    964982    for (QDomNode child = element.firstChild(); !child.isNull();
    965983         child = child.nextSibling())
    966     {   
     984    {
    967985        QDomElement info = child.toElement();
    968986        if (!info.isNull())
    969987        {
    970988            if (info.tagName() == "image")
    971989            {
    972                 QString imagepath = dir + getFirstText(info);
    973                 image = gContext->LoadScaleImage(imagepath);
     990                QString imagepath = dir + getFirstText(info);
     991
     992                if (m_loadedImages[imagepath])
     993                {
     994                    image = m_loadedImages[imagepath];
     995                    image->UpRef();
     996                }
     997                else
     998                {
     999                    tmpimg = gContext->LoadScaleImage(imagepath);
     1000                    image = MythImage::FromQImage(&tmpimg);
     1001                    m_loadedImages.insert(imagepath, image);
     1002                }
     1003
    9741004                if (image)
    9751005                    hasicon = true;
    9761006            }
    9771007            else if (info.tagName() == "activeimage")
    9781008            {
    9791009                QString imagepath = dir + getFirstText(info);
    980                 activeimage = gContext->LoadScaleImage(imagepath);
     1010
     1011                if (m_loadedImages[imagepath])
     1012                {
     1013                    activeimage = m_loadedImages[imagepath];
     1014                    activeimage->UpRef();
     1015                }
     1016                else
     1017                {
     1018                    tmpimg = gContext->LoadScaleImage(imagepath);
     1019                    activeimage = MythImage::FromQImage(&tmpimg);
     1020                    m_loadedImages.insert(imagepath, activeimage);
     1021                }
    9811022            }
    9821023            else if (info.tagName() == "offset")
    9831024            {
     
    9871028            else if (info.tagName() == "watermarkimage")
    9881029            {
    9891030                QString imagepath = dir + getFirstText(info);
    990                 watermark = gContext->LoadScaleImage(imagepath);
    991             }   
     1031
     1032                if (m_loadedImages[imagepath])
     1033                {
     1034                    watermark = m_loadedImages[imagepath];
     1035                    watermark->UpRef();
     1036                }
     1037                else
     1038                {
     1039                    tmpimg = gContext->LoadScaleImage(imagepath);
     1040                    watermark = MythImage::FromQImage(&tmpimg);
     1041                    m_loadedImages.insert(imagepath, watermark);
     1042                }
     1043            }
    9921044            else
    9931045            {
    9941046                VERBOSE(VB_GENERAL, QString("MythThemedMenuPrivate: Unknown tag %1 "
     
    10211073    ButtonIcon newbutton;
    10221074
    10231075    newbutton.name = name;
    1024     newbutton.icon = MythImage::FromQImage(&image);
     1076    newbutton.icon = image;
    10251077    newbutton.offset = offset;
    1026     newbutton.activeicon = MythImage::FromQImage(&activeimage);
     1078    newbutton.activeicon = activeimage;
    10271079
    10281080    if (watermark)
    10291081    {
     
    10341086            watermarkRect.setHeight(watermark->height());
    10351087    }
    10361088
    1037     newbutton.watermark = MythImage::FromQImage(&watermark);
     1089    newbutton.watermark = watermark;
    10381090
    10391091    allButtonIcons[name] = newbutton;
     1092
     1093    if (tmpimg)
     1094        delete tmpimg;
    10401095}
    10411096
    10421097void MythThemedMenuState::setDefaults(void)