Ticket #599: caption.diff

File caption.diff, 11.3 KB (added by herman@…, 18 years ago)
  • mythgallery/galleryutil.h

     
    2525{
    2626
    2727 public:
    28         static bool isImage(const char* filePath);
    29         static bool isMovie(const char* filePath);
    30         static long getNaturalRotation(const char* filePath);
     28    static bool isImage(const char* filePath);
     29    static bool isMovie(const char* filePath);
     30    static long getNaturalRotation(const char* filePath);
    3131
     32    static QString getCaption(const QString &filePath);
     33
    3234    static bool loadDirectory(ThumbList& itemList,
    3335                              const QString& dir, bool recurse,
    3436                              ThumbDict *itemDict, ThumbGenerator* thumbGen);
  • mythgallery/singleview.cpp

     
    8484    if (!m_delay)
    8585        m_delay = 2;
    8686
     87    // ----------------------------------------------------------------
     88
     89    m_showcaption = gContext->GetNumSetting("GalleryOverlayCaption", 0);
     90    if(m_showcaption > m_delay)
     91        m_showcaption = m_delay;
     92
     93    if(m_showcaption)
     94    {
     95        m_captionBgPix = createBg(screenwidth, 100);
     96        m_captionbackup = new QPixmap(screenwidth, 100);
     97    }
     98
    8799    // --------------------------------------------------------------------
    88100
    89101    setNoErase();
     
    113125    m_painter = 0;
    114126    mIntArray = 0;
    115127
    116     m_timer = new QTimer(this);
    117     connect(m_timer, SIGNAL(timeout()), SLOT(slotTimeOut()));
     128    m_sstimer = new QTimer(this);
     129    connect(m_sstimer, SIGNAL(timeout()), SLOT(slotSlideTimeOut()));
    118130
     131    m_ctimer = new QTimer(this);
     132    connect(m_ctimer, SIGNAL(timeout()), SLOT(slotCaptionTimeOut()));
     133
    119134    // --------------------------------------------------------------------
    120135
    121136    if(slideShow > 1)
     
    123138    loadImage();
    124139    if (slideShow) {
    125140        m_running = true;
    126         m_timer->start(m_tmout, true);
     141        m_sstimer->start(m_tmout, true);
    127142        gContext->DisableScreensaver();
    128143    }
    129144}
     
    183198                bitBlt(&pix, 0, 0, m_pixmap, m_sx, m_sy,
    184199                       pix.width(), pix.height());
    185200
     201            if(m_showcaption && !m_ctimer->isActive())
     202            {
     203                ThumbItem* item = m_itemList.at(m_pos);
     204                if(item->caption == "")
     205                    item->caption = GalleryUtil::getCaption(item->path);
     206
     207                if(item->caption != "") {
     208
     209                    // Store actual background to restore later
     210                    bitBlt(m_captionbackup, 0, 0, &pix,
     211                           0, screenheight - 100, screenwidth, 100);
     212
     213                    // Blit semi-transparent background into place
     214                    bitBlt(&pix, 0, screenheight - 100, m_captionBgPix,
     215                           0, 0, screenwidth, 100);
     216
     217                    // Draw caption
     218                    QPainter p(&pix, this);
     219                    p.drawText(0, screenheight - 100,
     220                               screenwidth, 100,
     221                               Qt::AlignCenter, item->caption);
     222                    p.end();
     223
     224                    m_ctimer->start(m_showcaption * 1000, true);
     225                }
     226            }
     227
    186228            if (m_zoom != 1) {
    187229                QPainter p(&pix, this);
    188230                p.drawText(screenwidth / 10, screenheight / 10,
     
    193235            if (m_info) {
    194236
    195237                if (!m_infoBgPix)
    196                     createInfoBg();
     238                    m_infoBgPix = createBg(screenwidth-2*screenwidth/10,
     239                                           screenheight-2*screenheight/10);
    197240
    198241                bitBlt(&pix, screenwidth/10, screenheight/10,
    199242                       m_infoBgPix,0,0,-1,-1,Qt::CopyROP);
     
    240283    bool handled = false;
    241284
    242285    bool wasRunning = m_running;
    243     m_timer->stop();
     286    m_sstimer->stop();
     287    m_ctimer->stop();
    244288    m_running = false;
    245289    gContext->RestoreScreensaver();
    246290    m_effectRunning = false;
     
    406450    }
    407451
    408452    if (m_running) {
    409         m_timer->start(m_tmout, true);
     453        m_sstimer->start(m_tmout, true);
    410454        gContext->DisableScreensaver();
    411455    }
    412456
     
    525569    }
    526570}
    527571
    528 
    529 void SingleView::createInfoBg()
     572QPixmap *SingleView::createBg(int width, int height)
    530573{
    531     QImage img(screenwidth-2*screenwidth/10,
    532                screenheight-2*screenheight/10,32);
     574    QImage img(width, height, 32);
    533575    img.setAlphaBuffer(true);
    534576
    535577    for (int y = 0; y < img.height(); y++)
     
    537579        for (int x = 0; x < img.width(); x++)
    538580        {
    539581            uint *p = (uint *)img.scanLine(y) + x;
    540             *p = qRgba(0, 0, 0, 120);
     582            *p = qRgba(0, 0, 0, 150);
    541583        }
    542584    }
    543585
    544     m_infoBgPix = new QPixmap(img);
     586    return new QPixmap(img);
    545587}
    546588
    547589void SingleView::registerEffects()
     
    11621204
    11631205
    11641206
    1165 void SingleView::slotTimeOut()
     1207void SingleView::slotSlideTimeOut()
    11661208{
    11671209    if (!m_effectMethod) {
    11681210        std::cerr << "SingleView: No transition method"
     
    12101252    }
    12111253
    12121254    update();
    1213     m_timer->start(m_tmout, true);
     1255    m_sstimer->start(m_tmout, true);
    12141256}
     1257
     1258void SingleView::slotCaptionTimeOut()
     1259{
     1260    m_ctimer->stop();
     1261    bitBlt(this,0,screenheight - 100,m_captionbackup,0,0,-1,-1,Qt::CopyROP);
     1262}
  • mythgallery/gallerysettings.cpp

     
    3636    gc->setLabel(QObject::tr("Command run to display movie files"));
    3737    gc->setValue("mplayer -fs %s");
    3838    gc->setHelpText(QObject::tr("This command is executed whenever a movie "
    39                                             "file is selected"));
     39                    "file is selected"));
    4040    return gc;
    4141};
    4242
     43static HostSpinBox *MythGalleryOverlayCaption()
     44{
     45    HostSpinBox *gc = new HostSpinBox("GalleryOverlayCaption", 0, 600, 1);
     46    gc->setLabel(QObject::tr("Overlay caption"));
     47    gc->setValue(0);
     48    gc->setHelpText(QObject::tr("This is the number of seconds to show a caption "
     49                    "on top of a full size picture."));
     50    return gc;
     51};
     52
    4353static HostLineEdit *MythGalleryImportDirs()
    4454{
    4555    HostLineEdit *gc = new HostLineEdit("GalleryImportDirs");
     
    170180        addTarget("0", regularConfig);
    171181
    172182#else
    173        
     183        addChild(MythGalleryOverlayCaption());
    174184        addChild(SlideshowTransition());
    175185        addChild(SlideshowBackground());
    176186       
  • mythgallery/singleview.h

     
    5757    bool          m_info;
    5858    QPixmap      *m_infoBgPix;
    5959
     60    int           m_showcaption;
     61    QPixmap      *m_captionBgPix;
     62    QPixmap      *m_captionbackup;
     63    QTimer       *m_ctimer;
     64
    6065    int           m_tmout;
    6166    int           m_delay;
    6267    bool          m_effectRunning;
    6368    bool          m_running;
    6469    int           m_slideShow;
    65     QTimer       *m_timer;
     70    QTimer       *m_sstimer;
    6671    QPixmap      *m_effectPix;
    6772    QPainter     *m_painter;
    6873   
     
    8691    void  loadImage();
    8792    void  rotate(int angle);
    8893    void  zoom();
    89     void  createInfoBg();
     94    QPixmap *createBg(int width, int height);
    9095
    9196    void  registerEffects();
    9297    EffectMethod getRandomEffect();
     
    109114
    110115private slots:
    111116
    112      void  slotTimeOut();
     117    void  slotSlideTimeOut();
     118    void  slotCaptionTimeOut();
    113119};
    114120
    115121#endif /* SINGLEVIEW_H */
  • mythgallery/iconview.cpp

     
    8787
    8888    m_thumbGen = new ThumbGenerator(this, (int)(m_thumbW-10*wmult),
    8989                                    (int)(m_thumbH-10*hmult));
    90    
     90
     91    m_showcaption = gContext->GetNumSetting("GalleryOverlayCaption", 0);
     92
    9193    m_currRow = 0;
    9294    m_currCol = 0;
    9395    m_lastRow = 0;
     
    158160        if (ttype) {
    159161            ThumbItem* item = m_itemList.at(m_currRow * m_nCols +
    160162                                            m_currCol);
    161             ttype->SetText(item ? item->name : QString(""));
     163
     164            if(item->caption == "" && m_showcaption)
     165                item->caption = GalleryUtil::getCaption(item->path);
     166            if(item->caption == "")
     167                item->caption = item->name;
     168
     169            ttype->SetText(item ? item->caption : QString(""));
    162170        }
    163171       
    164172        container->Draw(&p, 0, 0);
  • mythgallery/iconview.h

     
    3939    ThumbItem() {
    4040        pixmap = 0;
    4141        name   = "";
     42        caption= "";
    4243        path   = "";
    4344        isDir  = false;
    4445    }
     
    5354
    5455    QPixmap *pixmap;
    5556    QString  name;
     57    QString  caption;
    5658    QString  path;
    5759    bool     isDir;
    5860};
     
    136138    int                 m_thumbH;
    137139
    138140    ThumbGenerator     *m_thumbGen;
     141    int                 m_showcaption;
    139142
    140143    typedef void (IconView::*Action)();
    141144};
  • mythgallery/galleryutil.cpp

     
    201201
    202202    return isGallery;
    203203}
     204
     205QString GalleryUtil::getCaption(const QString& filePath)
     206{
     207    QString caption("");
     208
     209    try
     210    {
     211#ifdef EXIF_SUPPORT
     212        char *exifvalue = new char[1024];
     213        ExifData *data = exif_data_new_from_file (filePath);
     214        if (data)
     215        {
     216            for (int i = 0; i < EXIF_IFD_COUNT; i++)
     217            {
     218                ExifEntry *entry = exif_content_get_entry (data->ifd[i],
     219                                                    EXIF_TAG_USER_COMMENT);
     220                if (entry)
     221                {
     222#if NEW_LIB_EXIF
     223                    exif_entry_get_value(entry, exifvalue, 1023);
     224                    caption = exifvalue;
     225#else           
     226                    caption = exif_entry_get_value(entry);
     227#endif         
     228                    // Found one, done
     229                    if(!caption.isEmpty())
     230                       break;
     231                }
     232
     233                entry = exif_content_get_entry (data->ifd[i],
     234                                                EXIF_TAG_IMAGE_DESCRIPTION);
     235                if (entry)
     236                {
     237#if NEW_LIB_EXIF
     238                    exif_entry_get_value(entry, exifvalue, 1023);
     239                    caption = exifvalue;
     240#else           
     241                    caption = exif_entry_get_value(entry);
     242#endif         
     243                    // Found one, done
     244                    if(!caption.isEmpty())
     245                       break;
     246                }
     247            }
     248            exif_data_free(data);
     249        }
     250        else
     251        {
     252           std::cerr << "Could not load exif data from " << filePath << std::endl;
     253        }
     254       
     255        delete [] exifvalue;
     256#endif // EXIF_SUPPORT
     257    }
     258    catch (...)
     259    {
     260        std::cerr << "GalleryUtil: Failed to extract EXIF headers from "
     261        << filePath << std::endl;
     262    }
     263
     264    return caption;
     265}