Ticket #599: caption.diff
File caption.diff, 11.3 KB (added by , 18 years ago) |
---|
-
mythgallery/galleryutil.h
25 25 { 26 26 27 27 public: 28 29 30 28 static bool isImage(const char* filePath); 29 static bool isMovie(const char* filePath); 30 static long getNaturalRotation(const char* filePath); 31 31 32 static QString getCaption(const QString &filePath); 33 32 34 static bool loadDirectory(ThumbList& itemList, 33 35 const QString& dir, bool recurse, 34 36 ThumbDict *itemDict, ThumbGenerator* thumbGen); -
mythgallery/singleview.cpp
84 84 if (!m_delay) 85 85 m_delay = 2; 86 86 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 87 99 // -------------------------------------------------------------------- 88 100 89 101 setNoErase(); … … 113 125 m_painter = 0; 114 126 mIntArray = 0; 115 127 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())); 118 130 131 m_ctimer = new QTimer(this); 132 connect(m_ctimer, SIGNAL(timeout()), SLOT(slotCaptionTimeOut())); 133 119 134 // -------------------------------------------------------------------- 120 135 121 136 if(slideShow > 1) … … 123 138 loadImage(); 124 139 if (slideShow) { 125 140 m_running = true; 126 m_ timer->start(m_tmout, true);141 m_sstimer->start(m_tmout, true); 127 142 gContext->DisableScreensaver(); 128 143 } 129 144 } … … 183 198 bitBlt(&pix, 0, 0, m_pixmap, m_sx, m_sy, 184 199 pix.width(), pix.height()); 185 200 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 186 228 if (m_zoom != 1) { 187 229 QPainter p(&pix, this); 188 230 p.drawText(screenwidth / 10, screenheight / 10, … … 193 235 if (m_info) { 194 236 195 237 if (!m_infoBgPix) 196 createInfoBg(); 238 m_infoBgPix = createBg(screenwidth-2*screenwidth/10, 239 screenheight-2*screenheight/10); 197 240 198 241 bitBlt(&pix, screenwidth/10, screenheight/10, 199 242 m_infoBgPix,0,0,-1,-1,Qt::CopyROP); … … 240 283 bool handled = false; 241 284 242 285 bool wasRunning = m_running; 243 m_timer->stop(); 286 m_sstimer->stop(); 287 m_ctimer->stop(); 244 288 m_running = false; 245 289 gContext->RestoreScreensaver(); 246 290 m_effectRunning = false; … … 406 450 } 407 451 408 452 if (m_running) { 409 m_ timer->start(m_tmout, true);453 m_sstimer->start(m_tmout, true); 410 454 gContext->DisableScreensaver(); 411 455 } 412 456 … … 525 569 } 526 570 } 527 571 528 529 void SingleView::createInfoBg() 572 QPixmap *SingleView::createBg(int width, int height) 530 573 { 531 QImage img(screenwidth-2*screenwidth/10, 532 screenheight-2*screenheight/10,32); 574 QImage img(width, height, 32); 533 575 img.setAlphaBuffer(true); 534 576 535 577 for (int y = 0; y < img.height(); y++) … … 537 579 for (int x = 0; x < img.width(); x++) 538 580 { 539 581 uint *p = (uint *)img.scanLine(y) + x; 540 *p = qRgba(0, 0, 0, 1 20);582 *p = qRgba(0, 0, 0, 150); 541 583 } 542 584 } 543 585 544 m_infoBgPix =new QPixmap(img);586 return new QPixmap(img); 545 587 } 546 588 547 589 void SingleView::registerEffects() … … 1162 1204 1163 1205 1164 1206 1165 void SingleView::slot TimeOut()1207 void SingleView::slotSlideTimeOut() 1166 1208 { 1167 1209 if (!m_effectMethod) { 1168 1210 std::cerr << "SingleView: No transition method" … … 1210 1252 } 1211 1253 1212 1254 update(); 1213 m_ timer->start(m_tmout, true);1255 m_sstimer->start(m_tmout, true); 1214 1256 } 1257 1258 void 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
36 36 gc->setLabel(QObject::tr("Command run to display movie files")); 37 37 gc->setValue("mplayer -fs %s"); 38 38 gc->setHelpText(QObject::tr("This command is executed whenever a movie " 39 39 "file is selected")); 40 40 return gc; 41 41 }; 42 42 43 static 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 43 53 static HostLineEdit *MythGalleryImportDirs() 44 54 { 45 55 HostLineEdit *gc = new HostLineEdit("GalleryImportDirs"); … … 170 180 addTarget("0", regularConfig); 171 181 172 182 #else 173 183 addChild(MythGalleryOverlayCaption()); 174 184 addChild(SlideshowTransition()); 175 185 addChild(SlideshowBackground()); 176 186 -
mythgallery/singleview.h
57 57 bool m_info; 58 58 QPixmap *m_infoBgPix; 59 59 60 int m_showcaption; 61 QPixmap *m_captionBgPix; 62 QPixmap *m_captionbackup; 63 QTimer *m_ctimer; 64 60 65 int m_tmout; 61 66 int m_delay; 62 67 bool m_effectRunning; 63 68 bool m_running; 64 69 int m_slideShow; 65 QTimer *m_ timer;70 QTimer *m_sstimer; 66 71 QPixmap *m_effectPix; 67 72 QPainter *m_painter; 68 73 … … 86 91 void loadImage(); 87 92 void rotate(int angle); 88 93 void zoom(); 89 void createInfoBg();94 QPixmap *createBg(int width, int height); 90 95 91 96 void registerEffects(); 92 97 EffectMethod getRandomEffect(); … … 109 114 110 115 private slots: 111 116 112 void slotTimeOut(); 117 void slotSlideTimeOut(); 118 void slotCaptionTimeOut(); 113 119 }; 114 120 115 121 #endif /* SINGLEVIEW_H */ -
mythgallery/iconview.cpp
87 87 88 88 m_thumbGen = new ThumbGenerator(this, (int)(m_thumbW-10*wmult), 89 89 (int)(m_thumbH-10*hmult)); 90 90 91 m_showcaption = gContext->GetNumSetting("GalleryOverlayCaption", 0); 92 91 93 m_currRow = 0; 92 94 m_currCol = 0; 93 95 m_lastRow = 0; … … 158 160 if (ttype) { 159 161 ThumbItem* item = m_itemList.at(m_currRow * m_nCols + 160 162 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("")); 162 170 } 163 171 164 172 container->Draw(&p, 0, 0); -
mythgallery/iconview.h
39 39 ThumbItem() { 40 40 pixmap = 0; 41 41 name = ""; 42 caption= ""; 42 43 path = ""; 43 44 isDir = false; 44 45 } … … 53 54 54 55 QPixmap *pixmap; 55 56 QString name; 57 QString caption; 56 58 QString path; 57 59 bool isDir; 58 60 }; … … 136 138 int m_thumbH; 137 139 138 140 ThumbGenerator *m_thumbGen; 141 int m_showcaption; 139 142 140 143 typedef void (IconView::*Action)(); 141 144 }; -
mythgallery/galleryutil.cpp
201 201 202 202 return isGallery; 203 203 } 204 205 QString 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 }