00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <cmath>
00023
00024
00025 #include <iostream>
00026 using namespace std;
00027
00028
00029 #include <qevent.h>
00030 #include <qimage.h>
00031 #include <qtimer.h>
00032 #include <qpainter.h>
00033
00034
00035 #include <mythtv/mythcontext.h>
00036 #include <mythtv/util.h>
00037
00038
00039 #include "singleview.h"
00040 #include "constants.h"
00041 #include "galleryutil.h"
00042
00043 #define LOC QString("QtView: ")
00044 #define LOC_ERR QString("QtView, Error: ")
00045
00046 template<typename T> T sq(T val) { return val * val; }
00047
00048 SingleView::SingleView(
00049 ThumbList itemList, int pos,
00050 int slideShow, int sortorder,
00051 MythMainWindow *parent,
00052 const char *name)
00053 : MythDialog(parent, name),
00054 ImageView(itemList, pos, slideShow, sortorder),
00055
00056
00057 m_pixmap(NULL),
00058 m_angle(0),
00059 m_source_loc(0,0),
00060 m_scaleMax(false),
00061
00062
00063 m_info_pixmap(NULL),
00064
00065
00066 m_caption_show(false),
00067 m_caption_pixmap(NULL),
00068 m_caption_restore_pixmap(NULL),
00069 m_caption_timer(new QTimer(this)),
00070
00071
00072 m_effect_pixmap(NULL),
00073 m_effect_painter(NULL),
00074 m_effect_subtype(0),
00075 m_effect_bounds(0,0,0,0),
00076 m_effect_delta0(0,0),
00077 m_effect_delta1(0,0),
00078 m_effect_i(0),
00079 m_effect_j(0),
00080 m_effect_framerate(0),
00081 m_effect_delta2_x(0.0f),
00082 m_effect_delta2_y(0.0f),
00083 m_effect_alpha(0.0f),
00084
00085
00086 m_effect_spiral_tmp0(0,0),
00087 m_effect_spiral_tmp1(0,0),
00088 m_effect_multi_circle_out_delta_alpha(0.0f),
00089 m_effect_milti_circle_out_points(4),
00090 m_effect_circle_out_points(4)
00091 {
00092 m_scaleMax = (gContext->GetNumSetting("GalleryScaleMax", 0) > 0);
00093
00094 m_slideshow_timer = new QTimer(this);
00095 RegisterEffects();
00096
00097
00098
00099 QString transType = gContext->GetSetting("SlideshowTransition");
00100 if (!transType.isEmpty() && m_effect_map.contains(transType))
00101 m_effect_method = m_effect_map[transType];
00102
00103 if (m_effect_method.isEmpty() || transType == "random")
00104 {
00105 m_effect_method = GetRandomEffect();
00106 m_effect_random = true;
00107 }
00108
00109
00110
00111 m_caption_show = gContext->GetNumSetting("GalleryOverlayCaption", 0);
00112 m_caption_show = min(m_slideshow_frame_delay, m_caption_show);
00113
00114 if (m_caption_show)
00115 {
00116 m_caption_pixmap = CreateBackground(QSize(screenwidth, 100));
00117 m_caption_restore_pixmap = new QPixmap(screenwidth, 100);
00118 }
00119
00120
00121
00122 setNoErase();
00123 QString bgtype = gContext->GetSetting("SlideshowBackground");
00124 if (bgtype != "theme" && !bgtype.isEmpty())
00125 setPalette(QPalette(QColor(bgtype)));
00126
00127
00128
00129 connect(m_slideshow_timer, SIGNAL(timeout()), SLOT(SlideTimeout()));
00130 connect(m_caption_timer, SIGNAL(timeout()), SLOT(CaptionTimeout()));
00131
00132
00133
00134 Load();
00135
00136
00137
00138 if (slideShow)
00139 {
00140 m_slideshow_running = true;
00141 m_slideshow_timer->start(m_slideshow_frame_delay_state, true);
00142 gContext->DisableScreensaver();
00143 }
00144 }
00145
00146 SingleView::~SingleView()
00147 {
00148 if (m_effect_painter)
00149 {
00150 if (m_effect_painter->isActive())
00151 m_effect_painter->end();
00152
00153 delete m_effect_painter;
00154 m_effect_painter = NULL;
00155 }
00156
00157 SetPixmap(NULL);
00158
00159 if (m_effect_pixmap)
00160 {
00161 delete m_effect_pixmap;
00162 m_effect_pixmap = NULL;
00163 }
00164
00165 if (m_info_pixmap)
00166 {
00167 delete m_info_pixmap;
00168 m_info_pixmap = NULL;
00169 }
00170
00171
00172 gContext->SaveSetting("GalleryScaleMax", (m_scaleMax ? "1" : "0"));
00173 }
00174
00175 void SingleView::paintEvent(QPaintEvent *)
00176 {
00177 if (m_movieState > 0)
00178 {
00179 if (m_movieState == 1)
00180 {
00181 m_movieState = 2;
00182 ThumbItem *item = m_itemList.at(m_pos);
00183 QString path = QString("\"") + item->GetPath() + "\"";
00184 QString cmd = gContext->GetSetting("GalleryMoviePlayerCmd");
00185 cmd.replace("%s", path);
00186 myth_system(cmd);
00187 if (!m_slideshow_running)
00188 {
00189 reject();
00190 }
00191 }
00192 }
00193 else if (!m_effect_running)
00194 {
00195 QPixmap pix(screenwidth, screenheight);
00196 pix.fill(this, 0, 0);
00197
00198 if (m_pixmap)
00199 {
00200 if (m_pixmap->width() <= screenwidth &&
00201 m_pixmap->height() <= screenheight)
00202 {
00203 bitBlt(&pix,
00204 (screenwidth - m_pixmap->width()) >> 1,
00205 (screenheight - m_pixmap->height()) >> 1,
00206 m_pixmap,0,0,-1,-1,Qt::CopyROP);
00207 }
00208 else
00209 {
00210 bitBlt(&pix, QPoint(0, 0),
00211 m_pixmap, QRect(m_source_loc, pix.size()));
00212 }
00213
00214 if (m_caption_show && !m_caption_timer->isActive())
00215 {
00216 ThumbItem *item = m_itemList.at(m_pos);
00217 if (!item->HasCaption())
00218 item->SetCaption(GalleryUtil::GetCaption(item->GetPath()));
00219
00220 if (item->HasCaption())
00221 {
00222
00223 bitBlt(m_caption_restore_pixmap, QPoint(0, 0), &pix,
00224 QRect(0, screenheight - 100, screenwidth, 100));
00225
00226
00227 bitBlt(&pix, QPoint(0, screenheight - 100),
00228 m_caption_pixmap, QRect(0, 0, screenwidth, 100));
00229
00230
00231 QPainter p(&pix, this);
00232 p.drawText(0, screenheight - 100, screenwidth, 100,
00233 Qt::AlignCenter, item->GetCaption());
00234 p.end();
00235
00236 m_caption_timer->start(m_caption_show * 1000, true);
00237 }
00238 }
00239
00240 if (m_zoom != 1.0f)
00241 {
00242 QPainter p(&pix, this);
00243 p.drawText(screenwidth / 10, screenheight / 10,
00244 QString::number(m_zoom) + "x Zoom");
00245 p.end();
00246 }
00247
00248 if (m_info_show || m_info_show_short)
00249 {
00250 if (!m_info_pixmap)
00251 {
00252 m_info_pixmap = CreateBackground(QSize(
00253 screenwidth - 2 * screenwidth / 10,
00254 screenheight - 2 * screenheight / 10));
00255 }
00256
00257 bitBlt(&pix, QPoint(screenwidth / 10, screenheight / 10),
00258 m_info_pixmap, QRect(0,0,-1,-1), Qt::CopyROP);
00259
00260 QPainter p(&pix, this);
00261 ThumbItem *item = m_itemList.at(m_pos);
00262 QString info = QString::null;
00263 if (item)
00264 {
00265 info = item->GetDescription(GetDescriptionStatus(),
00266 m_image.size(), m_angle);
00267 }
00268
00269 if (!info.isEmpty())
00270 {
00271 p.drawText(screenwidth / 10 + (int)(10 * wmult),
00272 screenheight / 10 + (int)(10 * hmult),
00273 m_info_pixmap->width() - 2 * (int)(10 * wmult),
00274 m_info_pixmap->height() - 2 * (int)(10 * hmult),
00275 Qt::AlignLeft, info);
00276 }
00277 p.end();
00278 }
00279
00280 }
00281
00282 bitBlt(this, QPoint(0,0), &pix, QRect(0,0,-1,-1), Qt::CopyROP);
00283 }
00284 else if (!m_effect_method.isEmpty())
00285 RunEffect(m_effect_method);
00286 }
00287
00288 void SingleView::keyPressEvent(QKeyEvent *e)
00289 {
00290 bool handled = false;
00291
00292 bool wasRunning = m_slideshow_running;
00293 m_slideshow_timer->stop();
00294 m_caption_timer->stop();
00295 m_slideshow_running = false;
00296 gContext->RestoreScreensaver();
00297 m_effect_running = false;
00298 m_slideshow_frame_delay_state = m_slideshow_frame_delay * 1000;
00299 if (m_effect_painter && m_effect_painter->isActive())
00300 m_effect_painter->end();
00301
00302 bool wasInfo = m_info_show;
00303 m_info_show = false;
00304 bool wasInfoShort = m_info_show_short;
00305 m_info_show_short = false;
00306
00307 QStringList actions;
00308 gContext->GetMainWindow()->TranslateKeyPress("Gallery", e, actions);
00309
00310 int scrollX = screenwidth / 10;
00311 int scrollY = screenheight / 10;
00312
00313 for (unsigned int i = 0; i < actions.size() && !handled; i++)
00314 {
00315 QString action = actions[i];
00316 handled = true;
00317
00318 if (action == "LEFT" || action == "UP")
00319 {
00320 m_info_show = wasInfo;
00321 m_slideshow_running = wasRunning;
00322 DisplayPrev(true, true);
00323 }
00324 else if (action == "RIGHT" || action == "DOWN")
00325 {
00326 m_info_show = wasInfo;
00327 m_slideshow_running = wasRunning;
00328 DisplayNext(true, true);
00329 }
00330 else if (action == "ZOOMOUT")
00331 {
00332 if (m_zoom > 0.5f)
00333 {
00334 SetZoom(m_zoom - 0.5f);
00335 if (m_zoom > 1.0)
00336 {
00337 m_source_loc.setY(m_source_loc.y() - (screenheight / 4));
00338 m_source_loc.setX(m_source_loc.x() - (screenwidth / 4));
00339 CheckPosition();
00340 }
00341 else
00342 m_source_loc = QPoint(0, 0);
00343 }
00344 }
00345 else if (action == "ZOOMIN")
00346 {
00347 if (m_zoom < 4.0f)
00348 {
00349 SetZoom(m_zoom + 0.5f);
00350 if (m_zoom > 1.0)
00351 {
00352 m_source_loc.setY(m_source_loc.y() + (screenheight / 4));
00353 m_source_loc.setX(m_source_loc.x() + (screenwidth / 4));
00354 CheckPosition();
00355 }
00356 else
00357 m_source_loc = QPoint(0, 0);
00358 }
00359 }
00360 else if (action == "FULLSIZE")
00361 {
00362 m_source_loc = QPoint(0, 0);
00363 if (m_zoom != 1.0f)
00364 SetZoom(1.0f);
00365 }
00366 else if (action == "SCROLLLEFT")
00367 {
00368 if (m_zoom > 1.0f)
00369 {
00370 m_source_loc.setX(m_source_loc.x() - scrollX);
00371 m_source_loc.setX(
00372 (m_source_loc.x() < 0) ? 0 : m_source_loc.x());
00373 }
00374 }
00375 else if (action == "SCROLLRIGHT")
00376 {
00377 if (m_zoom > 1.0f && m_pixmap)
00378 {
00379 m_source_loc.setX(m_source_loc.x() + scrollX);
00380 m_source_loc.setX(min(m_source_loc.x(),
00381 m_pixmap->width() - screenwidth));
00382 }
00383 }
00384 else if (action == "SCROLLUP")
00385 {
00386 if (m_zoom > 1.0f && m_pixmap)
00387 {
00388 m_source_loc.setY(m_source_loc.y() + scrollY);
00389 m_source_loc.setY(min(m_source_loc.y(),
00390 m_pixmap->height() - screenheight));
00391 }
00392 }
00393 else if (action == "SCROLLDOWN")
00394 {
00395 if (m_zoom > 1.0f)
00396 {
00397 m_source_loc.setY(m_source_loc.y() - scrollY);
00398 m_source_loc.setY(
00399 (m_source_loc.y() < 0) ? 0 : m_source_loc.y());
00400 }
00401 }
00402 else if (action == "RECENTER")
00403 {
00404 if (m_zoom > 1.0f && m_pixmap)
00405 {
00406 m_source_loc = QPoint(
00407 (m_pixmap->width() - screenwidth) >> 1,
00408 (m_pixmap->height() - screenheight) >> 1);
00409 }
00410 }
00411 else if (action == "UPLEFT")
00412 {
00413 if (m_zoom > 1.0f)
00414 {
00415 m_source_loc = QPoint(0,0);
00416 }
00417 }
00418 else if (action == "LOWRIGHT")
00419 {
00420 if (m_zoom > 1.0f && m_pixmap)
00421 {
00422 m_source_loc = QPoint(
00423 m_pixmap->width() - scrollX - screenwidth,
00424 m_pixmap->height() - scrollY - screenheight);
00425 }
00426 }
00427 else if (action == "ROTRIGHT")
00428 {
00429 m_source_loc = QPoint(0, 0);
00430 Rotate(90);
00431 }
00432 else if (action == "ROTLEFT")
00433 {
00434 m_source_loc = QPoint(0, 0);
00435 Rotate(-90);
00436 }
00437 else if (action == "DELETE")
00438 {
00439 ThumbItem *item = m_itemList.at(m_pos);
00440 if (item && GalleryUtil::Delete(item->GetPath()))
00441 {
00442 item->SetPixmap(NULL);
00443 DisplayNext(true, true);
00444 }
00445 m_info_show = wasInfo;
00446 m_slideshow_running = wasRunning;
00447 }
00448 else if (action == "PLAY" || action == "SLIDESHOW" ||
00449 action == "RANDOMSHOW")
00450 {
00451 m_source_loc = QPoint(0, 0);
00452 m_zoom = 1.0f;
00453 m_angle = 0;
00454 m_info_show = wasInfo;
00455 m_info_show_short = true;
00456 m_slideshow_running = !wasRunning;
00457 }
00458 else if (action == "INFO")
00459 {
00460 m_info_show = !wasInfo && !wasInfoShort;
00461 m_slideshow_running = wasRunning;
00462 }
00463 else if (action == "FULLSCREEN")
00464 {
00465 m_scaleMax = !m_scaleMax;
00466 m_source_loc = QPoint(0, 0);
00467 SetZoom(1.0f);
00468 }
00469 else
00470 {
00471 handled = false;
00472 }
00473 }
00474
00475 if (m_slideshow_running || m_info_show_short)
00476 {
00477 m_slideshow_timer->start(m_slideshow_frame_delay_state, true);
00478 }
00479 if (m_slideshow_running)
00480 {
00481 gContext->DisableScreensaver();
00482 }
00483
00484 update();
00485
00486 if (!handled)
00487 MythDialog::keyPressEvent(e);
00488 }
00489
00490 void SingleView::CheckPosition(void)
00491 {
00492 m_source_loc.setX((m_source_loc.x() < 0) ? 0 : m_source_loc.x());
00493 m_source_loc.setY((m_source_loc.y() < 0) ? 0 : m_source_loc.y());
00494 m_source_loc.setX(min(m_source_loc.x(), m_pixmap->width() - screenwidth));
00495 m_source_loc.setY(min(m_source_loc.y(), m_pixmap->height() - screenheight));
00496 }
00497
00498 void SingleView::DisplayNext(bool reset, bool loadImage)
00499 {
00500 if (reset)
00501 {
00502 m_angle = 0;
00503 m_zoom = 1.0f;
00504 m_source_loc = QPoint(0, 0);
00505 }
00506
00507
00508
00509 ThumbItem *item;
00510 int oldpos = m_pos;
00511 while (true)
00512 {
00513 m_pos = m_slideshow_sequence->next();
00514 item = m_itemList.at(m_pos);
00515 if (item)
00516 {
00517 if (QFile::exists(item->GetPath()))
00518 {
00519 break;
00520 }
00521 }
00522 if (m_pos == oldpos)
00523 {
00524
00525 reject();
00526 }
00527 }
00528
00529 if (loadImage)
00530 Load();
00531 }
00532
00533 void SingleView::DisplayPrev(bool reset, bool loadImage)
00534 {
00535 if (reset)
00536 {
00537 m_angle = 0;
00538 m_zoom = 1.0f;
00539 m_source_loc = QPoint(0, 0);
00540 }
00541
00542
00543
00544 int oldpos = m_pos;
00545 while (true)
00546 {
00547 m_pos = m_slideshow_sequence->prev();
00548
00549 ThumbItem *item = m_itemList.at(m_pos);
00550 if (item && QFile::exists(item->GetPath()))
00551 break;
00552
00553 if (m_pos == oldpos)
00554 {
00555
00556 reject();
00557 }
00558 }
00559
00560 if (loadImage)
00561 Load();
00562 }
00563
00564 void SingleView::Load(void)
00565 {
00566 m_movieState = 0;
00567
00568 SetPixmap(NULL);
00569
00570 ThumbItem *item = m_itemList.at(m_pos);
00571 if (!item)
00572 {
00573 VERBOSE(VB_IMPORTANT, LOC_ERR + "No item at "<<m_pos);
00574 return;
00575 }
00576
00577 if (GalleryUtil::isMovie(item->GetPath()))
00578 {
00579 m_movieState = 1;
00580 return;
00581 }
00582
00583 m_image.load(item->GetPath());
00584 if (m_image.isNull())
00585 return;
00586
00587 m_angle = item->GetRotationAngle();
00588 if (m_angle != 0)
00589 {
00590 QWMatrix matrix;
00591 matrix.rotate(m_angle);
00592 m_image = m_image.xForm(matrix);
00593 }
00594
00595 SetZoom(m_zoom);
00596
00597 UpdateLCD(item);
00598 }
00599
00600 void SingleView::Rotate(int angle)
00601 {
00602 m_angle += angle;
00603
00604 m_angle = (m_angle >= 360) ? m_angle - 360 : m_angle;
00605 m_angle = (m_angle < 0) ? m_angle + 360 : m_angle;
00606
00607 ThumbItem *item = m_itemList.at(m_pos);
00608 if (item)
00609 item->SetRotationAngle(m_angle);
00610
00611 if (m_image.isNull())
00612 return;
00613
00614 QWMatrix matrix;
00615 matrix.rotate(angle);
00616 m_image = m_image.xForm(matrix);
00617
00618 SetZoom(m_zoom);
00619 }
00620
00621 void SingleView::SetZoom(float zoom)
00622 {
00623 m_zoom = zoom;
00624
00625 if (m_image.isNull())
00626 return;
00627
00628 QImage img = m_image;
00629
00630 QSize dest = QSize(
00631 (int)(screenwidth * m_zoom), (int)(screenheight * m_zoom));
00632
00633 QSize sz = GalleryUtil::ScaleToDest(m_image.size(), dest, m_scaleMax);
00634 if ((sz.width() > 0) && (sz.height() > 0))
00635 img = m_image.smoothScale(sz);
00636
00637 SetPixmap(new QPixmap(img));
00638 }
00639
00640 void SingleView::SetPixmap(QPixmap *pixmap)
00641 {
00642 if (m_pixmap)
00643 {
00644 delete m_pixmap;
00645 m_pixmap = NULL;
00646 }
00647 m_pixmap = pixmap;
00648 }
00649
00650 QPixmap *SingleView::CreateBackground(const QSize &sz)
00651 {
00652 QImage img(sz.width(), sz.height(), 32);
00653 img.setAlphaBuffer(true);
00654
00655 for (int y = 0; y < img.height(); y++)
00656 {
00657 for (int x = 0; x < img.width(); x++)
00658 {
00659 uint *p = (uint *)img.scanLine(y) + x;
00660 *p = qRgba(0, 0, 0, 150);
00661 }
00662 }
00663
00664 return new QPixmap(img);
00665 }
00666
00667 void SingleView::RegisterEffects(void)
00668 {
00669 m_effect_map.insert("none", "EffectNone");
00670 m_effect_map.insert("chess board", "EffectChessboard");
00671 m_effect_map.insert("melt down", "EffectMeltdown");
00672 m_effect_map.insert("sweep", "EffectSweep");
00673 m_effect_map.insert("noise", "EffectNoise");
00674 m_effect_map.insert("growing", "EffectGrowing");
00675 m_effect_map.insert("incoming edges", "EffectIncomingEdges");
00676 m_effect_map.insert("horizontal lines", "EffectHorizLines");
00677 m_effect_map.insert("vertical lines", "EffectVertLines");
00678 m_effect_map.insert("circle out", "EffectCircleOut");
00679 m_effect_map.insert("multicircle out", "EffectMultiCircleOut");
00680 m_effect_map.insert("spiral in", "EffectSpiralIn");
00681 m_effect_map.insert("blobs", "EffectBlobs");
00682 }
00683
00684 void SingleView::RunEffect(const QString &effect)
00685 {
00686 if (effect == "EffectChessboard")
00687 EffectChessboard();
00688 else if (effect == "EffectMeltdown")
00689 EffectMeltdown();
00690 else if (effect == "EffectSweep")
00691 EffectSweep();
00692 else if (effect == "EffectNoise")
00693 EffectNoise();
00694 else if (effect == "EffectGrowing")
00695 EffectGrowing();
00696 else if (effect == "EffectIncomingEdges")
00697 EffectIncomingEdges();
00698 else if (effect == "EffectHorizLines")
00699 EffectHorizLines();
00700 else if (effect == "EffectVertLines")
00701 EffectVertLines();
00702 else if (effect == "EffectCircleOut")
00703 EffectCircleOut();
00704 else if (effect == "EffectMultiCircleOut")
00705 EffectMultiCircleOut();
00706 else if (effect == "EffectSpiralIn")
00707 EffectSpiralIn();
00708 else if (effect == "EffectBlobs")
00709 EffectBlobs();
00710 else
00711 EffectNone();
00712 }
00713
00714 void SingleView::StartPainter(void)
00715 {
00716 if (!m_effect_painter)
00717 m_effect_painter = new QPainter();
00718
00719 if (m_effect_painter->isActive())
00720 m_effect_painter->end();
00721
00722 QBrush brush;
00723 if (m_effect_pixmap)
00724 brush.setPixmap(*m_effect_pixmap);
00725
00726 m_effect_painter->begin(this);
00727 m_effect_painter->setBrush(brush);
00728 m_effect_painter->setPen(Qt::NoPen);
00729 }
00730
00731 void SingleView::CreateEffectPixmap(void)
00732 {
00733 if (!m_effect_pixmap)
00734 m_effect_pixmap = new QPixmap(screenwidth, screenheight);
00735
00736 m_effect_pixmap->fill(this, 0, 0);
00737
00738 if (m_pixmap)
00739 {
00740 QPoint src_loc((m_effect_pixmap->width() - m_pixmap->width() ) >> 1,
00741 (m_effect_pixmap->height() - m_pixmap->height()) >> 1);
00742 bitBlt(m_effect_pixmap, src_loc,
00743 m_pixmap, QRect(0, 0, -1, -1), Qt::CopyROP);
00744 }
00745 }
00746
00747 void SingleView::EffectNone(void)
00748 {
00749 m_effect_running = false;
00750 m_slideshow_frame_delay_state = -1;
00751 update();
00752 return;
00753 }
00754
00755 void SingleView::EffectChessboard(void)
00756 {
00757 if (m_effect_current_frame == 0)
00758 {
00759 m_effect_delta0 = QPoint(8, 8);
00760
00761 m_effect_j = (width() + m_effect_delta0.x() - 1) / m_effect_delta0.x();
00762 m_effect_delta1 = QPoint(0, 0);
00763 m_effect_framerate = 800 / m_effect_j;
00764
00765
00766
00767 m_effect_bounds = QRect(
00768 m_effect_j * m_effect_delta0.x(), (m_effect_j & 1) ? 0 : m_effect_delta0.y(),
00769 width(), height());
00770 }
00771
00772 if (m_effect_delta1.x() >= m_effect_bounds.width())
00773 {
00774 m_effect_running = false;
00775 m_slideshow_frame_delay_state = -1;
00776 update();
00777 return;
00778 }
00779
00780 m_effect_delta1 = QPoint(m_effect_delta1.x() + m_effect_delta0.x(),
00781 (m_effect_delta1.y()) ? 0 : m_effect_delta0.y());
00782 QPoint t = QPoint(m_effect_bounds.x() - m_effect_delta0.x(),
00783 (m_effect_bounds.y()) ? 0 : m_effect_delta0.y());
00784 m_effect_bounds = QRect(t, m_effect_bounds.size());
00785
00786 for (int y = 0; y < m_effect_bounds.width(); y += (m_effect_delta0.y()<<1))
00787 {
00788 QPoint src0(m_effect_delta1.x(), y + m_effect_delta1.y());
00789 QRect dst0(m_effect_delta1.x(), y + m_effect_delta1.y(),
00790 m_effect_delta0.x(), m_effect_delta0.y());
00791 QPoint src1(m_effect_bounds.x(), y + m_effect_bounds.y());
00792 QRect dst1(m_effect_bounds.x(), y + m_effect_bounds.y(),
00793 m_effect_delta0.x(), m_effect_delta0.y());
00794 bitBlt(this, src0, m_effect_pixmap, dst0, Qt::CopyROP, true);
00795 bitBlt(this, src1, m_effect_pixmap, dst0, Qt::CopyROP, true);
00796 }
00797
00798 m_slideshow_frame_delay_state = m_effect_framerate;
00799
00800 m_effect_current_frame = 1;
00801 }
00802
00803 void SingleView::EffectSweep(void)
00804 {
00805 if (m_effect_current_frame == 0)
00806 {
00807 m_effect_subtype = rand() % 4;
00808 m_effect_delta0 = QPoint(
00809 (kSweepLeftToRight == m_effect_subtype) ? 16 : -16,
00810 (kSweepTopToBottom == m_effect_subtype) ? 16 : -16);
00811 m_effect_bounds = QRect(
00812 (kSweepLeftToRight == m_effect_subtype) ? 0 : width(),
00813 (kSweepTopToBottom == m_effect_subtype) ? 0 : height(),
00814 width(), height());
00815 }
00816
00817 if (kSweepRightToLeft == m_effect_subtype ||
00818 kSweepLeftToRight == m_effect_subtype)
00819 {
00820
00821 if ((kSweepRightToLeft == m_effect_subtype &&
00822 m_effect_bounds.x() < -64) ||
00823 (kSweepLeftToRight == m_effect_subtype &&
00824 m_effect_bounds.x() > m_effect_bounds.width() + 64))
00825 {
00826 m_slideshow_frame_delay_state = -1;
00827 m_effect_running = false;
00828 update();
00829 return;
00830 }
00831
00832 int w, x, i;
00833 for (w = 2, i = 4, x = m_effect_bounds.x(); i > 0;
00834 i--, w <<= 1, x -= m_effect_delta0.x())
00835 {
00836 bitBlt(this, QPoint(x, 0),
00837 m_effect_pixmap, QRect(x, 0, w, m_effect_bounds.height()),
00838 Qt::CopyROP, true);
00839 }
00840
00841 m_effect_bounds.moveLeft(m_effect_bounds.x() + m_effect_delta0.x());
00842 }
00843 else
00844 {
00845
00846 if ((kSweepBottomToTop == m_effect_subtype &&
00847 m_effect_bounds.y() < -64) ||
00848 (kSweepTopToBottom == m_effect_subtype &&
00849 m_effect_bounds.y() > m_effect_bounds.height() + 64))
00850 {
00851 m_slideshow_frame_delay_state = -1;
00852 m_effect_running = false;
00853 update();
00854 return;
00855 }
00856
00857 int h, y, i;
00858 for (h = 2, i = 4, y = m_effect_bounds.y(); i > 0;
00859 i--, h <<= 1, y -= m_effect_delta0.y())
00860 {
00861 bitBlt(this, QPoint(0, y), m_effect_pixmap,
00862 QRect(0, y, m_effect_bounds.width(), h),
00863 Qt::CopyROP, true);
00864 }
00865
00866 m_effect_bounds.moveTop(m_effect_bounds.y() + m_effect_delta0.y());
00867 }
00868
00869 m_slideshow_frame_delay_state = 20;
00870 m_effect_current_frame = 1;
00871 }
00872
00873 void SingleView::EffectGrowing(void)
00874 {
00875 if (m_effect_current_frame == 0)
00876 {
00877 m_effect_bounds = QRect(width() >> 1, height() >> 1, width(), height());
00878 m_effect_i = 0;
00879 m_effect_delta2_x = m_effect_bounds.x() * 0.01f;
00880 m_effect_delta2_y = m_effect_bounds.y() * 0.01f;
00881 }
00882
00883 m_effect_bounds.moveTopLeft(
00884 QPoint((m_effect_bounds.width() >> 1) - (int)(m_effect_i * m_effect_delta2_x),
00885 (m_effect_bounds.height() >> 1) - (int)(m_effect_i * m_effect_delta2_y)));
00886
00887 m_effect_i++;
00888
00889 if (m_effect_bounds.x() < 0 || m_effect_bounds.y() < 0)
00890 {
00891 m_slideshow_frame_delay_state = -1;
00892 m_effect_running = false;
00893 update();
00894 return;
00895 }
00896
00897 QSize dst_sz(m_effect_bounds.width() - (m_effect_bounds.x() << 1),
00898 m_effect_bounds.height() - (m_effect_bounds.y() << 1));
00899
00900 bitBlt(this, m_effect_bounds.topLeft(),
00901 m_effect_pixmap, QRect(m_effect_bounds.topLeft(), dst_sz),
00902 Qt::CopyROP, true);
00903
00904 m_slideshow_frame_delay_state = 20;
00905 m_effect_current_frame = 1;
00906 }
00907
00908 void SingleView::EffectHorizLines(void)
00909 {
00910 static const int iyPos[] = { 0, 4, 2, 6, 1, 5, 3, 7, -1 };
00911
00912 if (m_effect_current_frame == 0)
00913 {
00914 m_effect_bounds.setSize(size());
00915 m_effect_i = 0;
00916 }
00917
00918 if (iyPos[m_effect_i] < 0)
00919 {
00920 m_slideshow_frame_delay_state = -1;
00921 m_effect_running = false;
00922 update();
00923 return;
00924 }
00925
00926 for (int y = iyPos[m_effect_i]; y < m_effect_bounds.height(); y += 8)
00927 {
00928 bitBlt(this, QPoint(0, y),
00929 m_effect_pixmap, QRect(0, y, m_effect_bounds.width(), 1),
00930 Qt::CopyROP, true);
00931 }
00932
00933 m_effect_i++;
00934
00935 if (iyPos[m_effect_i] >= 0)
00936 {
00937 m_slideshow_frame_delay_state = 160;
00938 m_effect_current_frame = 1;
00939 }
00940 else
00941 {
00942 m_slideshow_frame_delay_state = -1;
00943 m_effect_running = false;
00944 update();
00945 return;
00946 }
00947 }
00948
00949 void SingleView::EffectVertLines(void)
00950 {
00951 static const int ixPos[] = { 0, 4, 2, 6, 1, 5, 3, 7, -1 };
00952
00953 if (m_effect_current_frame == 0)
00954 {
00955 m_effect_bounds.setSize(size());
00956 m_effect_i = 0;
00957 }
00958
00959 if (ixPos[m_effect_i] < 0)
00960 {
00961 m_slideshow_frame_delay_state = -1;
00962 m_effect_running = false;
00963 update();
00964 return;
00965 }
00966
00967 for (int x = ixPos[m_effect_i]; x < m_effect_bounds.width(); x += 8)
00968 {
00969 bitBlt(this, QPoint(x, 0),
00970 m_effect_pixmap, QRect(x, 0, 1, m_effect_bounds.height()),
00971 Qt::CopyROP, true);
00972 }
00973
00974 m_effect_i++;
00975
00976 if (ixPos[m_effect_i] >= 0)
00977 {
00978 m_slideshow_frame_delay_state = 160;
00979 m_effect_current_frame = 1;
00980 }
00981 else
00982 {
00983 m_slideshow_frame_delay_state = -1;
00984 m_effect_running = false;
00985 update();
00986 return;
00987 }
00988 }
00989
00990 void SingleView::EffectMeltdown(void)
00991 {
00992 if (m_effect_current_frame == 0)
00993 {
00994 m_effect_bounds.setSize(size());
00995 m_effect_delta0 = QPoint(4, 16);
00996 m_effect_delta1 = QPoint(m_effect_bounds.width() / m_effect_delta0.x(), 0);
00997 m_effect_meltdown_y_disp.resize(m_effect_delta1.x());
00998 }
00999
01000 int x = 0;
01001 bool done = true;
01002 for (int i = 0; i < m_effect_delta1.x(); i++, x += m_effect_delta0.x())
01003 {
01004 int y = m_effect_meltdown_y_disp[i];
01005 if (y >= m_effect_bounds.height())
01006 continue;
01007
01008 done = false;
01009 if ((rand() & 0xF) < 6)
01010 continue;
01011
01012 bitBlt(this, QPoint(x, y),
01013 m_effect_pixmap,
01014 QRect(x, y, m_effect_delta0.x(), m_effect_delta0.y()),
01015 Qt::CopyROP, true);
01016
01017 m_effect_meltdown_y_disp[i] += m_effect_delta0.y();
01018 }
01019
01020 if (done)
01021 {
01022 m_slideshow_frame_delay_state = -1;
01023 m_effect_running = false;
01024 update();
01025 return;
01026 }
01027
01028 m_slideshow_frame_delay_state = 15;
01029 m_effect_current_frame = 1;
01030 }
01031
01032 void SingleView::EffectIncomingEdges(void)
01033 {
01034 if (m_effect_current_frame == 0)
01035 {
01036 m_effect_bounds.setSize(size());
01037 m_effect_delta1 = QPoint(m_effect_bounds.width() >> 1, m_effect_bounds.height() >> 1);
01038 m_effect_delta2_x = m_effect_delta1.x() * 0.01f;
01039 m_effect_delta2_y = m_effect_delta1.y() * 0.01f;
01040 m_effect_i = 0;
01041 m_effect_subtype = rand() & 1;
01042 }
01043
01044 m_effect_bounds.moveTopLeft(QPoint((int)(m_effect_delta2_x * m_effect_i),
01045 (int)(m_effect_delta2_y * m_effect_i)));
01046
01047 if (m_effect_bounds.x() > m_effect_delta1.x() || m_effect_bounds.y() > m_effect_delta1.y())
01048 {
01049 m_slideshow_frame_delay_state = -1;
01050 m_effect_running = false;
01051 update();
01052 return;
01053 }
01054
01055 int x1 = m_effect_bounds.width() - m_effect_bounds.x();
01056 int y1 = m_effect_bounds.height() - m_effect_bounds.y();
01057 m_effect_i++;
01058
01059 if (kIncomingEdgesMoving == m_effect_subtype)
01060 {
01061
01062 bitBlt(this, 0, 0, m_effect_pixmap,
01063 m_effect_delta1.x() - m_effect_bounds.x(),
01064 m_effect_delta1.y() - m_effect_bounds.y(),
01065 m_effect_bounds.x(), m_effect_bounds.y(),
01066 Qt::CopyROP, true);
01067 bitBlt(this, x1, 0, m_effect_pixmap,
01068 m_effect_delta1.x(), m_effect_delta1.y() - m_effect_bounds.y(),
01069 m_effect_bounds.x(), m_effect_bounds.y(),
01070 Qt::CopyROP, true);
01071 bitBlt(this, 0, y1, m_effect_pixmap,
01072 m_effect_delta1.x() - m_effect_bounds.x(), m_effect_delta1.y(),
01073 m_effect_bounds.x(), m_effect_bounds.y(),
01074 Qt::CopyROP, true);
01075 bitBlt(this, x1, y1, m_effect_pixmap,
01076 m_effect_delta1.x(), m_effect_delta1.y(),
01077 m_effect_bounds.x(), m_effect_bounds.y(),
01078 Qt::CopyROP, true);
01079 }
01080 else
01081 {
01082
01083 bitBlt(this, 0, 0,
01084 m_effect_pixmap, 0, 0, m_effect_bounds.x(), m_effect_bounds.y(),
01085 Qt::CopyROP, true);
01086 bitBlt(this, x1, 0,
01087 m_effect_pixmap, x1, 0, m_effect_bounds.x(), m_effect_bounds.y(),
01088 Qt::CopyROP, true);
01089 bitBlt(this, 0, y1,
01090 m_effect_pixmap, 0, y1, m_effect_bounds.x(), m_effect_bounds.y(),
01091 Qt::CopyROP, true);
01092 bitBlt(this, x1, y1,
01093 m_effect_pixmap, x1, y1, m_effect_bounds.x(), m_effect_bounds.y(),
01094 Qt::CopyROP, true);
01095 }
01096
01097 m_slideshow_frame_delay_state = 20;
01098 m_effect_current_frame = 1;
01099 }
01100
01101 void SingleView::EffectMultiCircleOut(void)
01102 {
01103 int x, y, i;
01104 double alpha;
01105
01106 if (m_effect_current_frame == 0)
01107 {
01108 StartPainter();
01109 m_effect_bounds = QRect(width(), height() >> 1,
01110 width(), height());
01111
01112 m_effect_milti_circle_out_points.setPoint(
01113 0, m_effect_bounds.width() >> 1, m_effect_bounds.height() >> 1);
01114 m_effect_milti_circle_out_points.setPoint(
01115 3, m_effect_bounds.width() >> 1, m_effect_bounds.height() >> 1);
01116
01117 m_effect_delta2_y = sqrtf(sq(m_effect_bounds.width()) * 1.0f +
01118 sq(m_effect_bounds.height()) * 0.5f);
01119 m_effect_i = (rand() & 0xf) + 2;
01120 m_effect_multi_circle_out_delta_alpha = M_PI * 2 / m_effect_i;
01121 m_effect_alpha = m_effect_multi_circle_out_delta_alpha;
01122 m_effect_framerate = 10 * m_effect_i;
01123 m_effect_delta2_x = M_PI / 32;
01124 }
01125
01126 if (m_effect_alpha < 0)
01127 {
01128 m_effect_painter->end();
01129
01130 m_slideshow_frame_delay_state = -1;
01131 m_effect_running = false;
01132 update();
01133 return;
01134 }
01135
01136 for (alpha = m_effect_alpha, i = m_effect_i; i >= 0;
01137 i--, alpha += m_effect_multi_circle_out_delta_alpha)
01138 {
01139 x = (m_effect_bounds.width() >> 1) + (int)(m_effect_delta2_y * cos(-alpha));
01140 y = (m_effect_bounds.height() >> 1) + (int)(m_effect_delta2_y * sin(-alpha));
01141
01142 m_effect_bounds.moveTopLeft(
01143 QPoint((m_effect_bounds.width() >> 1) +
01144 (int)(m_effect_delta2_y * cos(-alpha + m_effect_delta2_x)),
01145 (m_effect_bounds.height() >> 1) +
01146 (int)(m_effect_delta2_y * sin(-alpha + m_effect_delta2_x))));
01147
01148 m_effect_milti_circle_out_points.setPoint(1, x, y);
01149 m_effect_milti_circle_out_points.setPoint(2, m_effect_bounds.x(), m_effect_bounds.y());
01150
01151 m_effect_painter->drawPolygon(m_effect_milti_circle_out_points);
01152 }
01153
01154 m_effect_alpha -= m_effect_delta2_x;
01155
01156 m_slideshow_frame_delay_state = m_effect_framerate;
01157 m_effect_current_frame = 1;
01158 }
01159
01160 void SingleView::EffectSpiralIn(void)
01161 {
01162 if (m_effect_current_frame == 0)
01163 {
01164 StartPainter();
01165 m_effect_delta0 = QPoint(width() >> 3, 0);
01166 m_effect_delta1 = QPoint(width() >> 3, height() >> 3);
01167 m_effect_i = 0;
01168 m_effect_j = 16 * 16;
01169 m_effect_bounds = QRect(QPoint(0,0), size());
01170 m_effect_spiral_tmp0 = QPoint(0, m_effect_delta1.y());
01171 m_effect_spiral_tmp1 = QPoint(m_effect_bounds.width() - m_effect_delta1.x(),
01172 m_effect_bounds.height() - m_effect_delta1.y());
01173 }
01174
01175 if (m_effect_i == 0 && m_effect_spiral_tmp0.x() >= m_effect_spiral_tmp1.x())
01176 {
01177 m_effect_painter->end();
01178
01179 m_slideshow_frame_delay_state = -1;
01180 m_effect_running = false;
01181 update();
01182 return;
01183 }
01184
01185 if (m_effect_i == 0 && m_effect_bounds.x() >= m_effect_spiral_tmp1.x())
01186 {
01187
01188 m_effect_i = 1;
01189 m_effect_delta0 = QPoint(0, m_effect_delta1.y());
01190 m_effect_spiral_tmp1.setX(m_effect_spiral_tmp1.x() - m_effect_delta1.x());
01191 }
01192 else if (m_effect_i == 1 && m_effect_bounds.y() >= m_effect_spiral_tmp1.y())
01193 {
01194
01195 m_effect_i = 2;
01196 m_effect_delta0 = QPoint(-m_effect_delta1.x(), 0);
01197 m_effect_spiral_tmp1.setY(m_effect_spiral_tmp1.y() - m_effect_delta1.y());
01198 }
01199 else if (m_effect_i == 2 && m_effect_bounds.x() <= m_effect_spiral_tmp0.x())
01200 {
01201
01202 m_effect_i = 3;
01203 m_effect_delta0 = QPoint(0, -m_effect_delta1.y());
01204 m_effect_spiral_tmp0.setX(m_effect_spiral_tmp0.x() + m_effect_delta1.x());
01205 }
01206 else if (m_effect_i == 3 && m_effect_bounds.y() <= m_effect_spiral_tmp0.y())
01207 {
01208
01209 m_effect_i = 0;
01210 m_effect_delta0 = QPoint(m_effect_delta1.x(), 0);
01211 m_effect_spiral_tmp0.setY(m_effect_spiral_tmp0.y() + m_effect_delta1.y());
01212 }
01213
01214 bitBlt(this, m_effect_bounds.x(), m_effect_bounds.y(), m_effect_pixmap,
01215 m_effect_bounds.x(), m_effect_bounds.y(),
01216 m_effect_delta1.x(), m_effect_delta1.y(),
01217 Qt::CopyROP, true);
01218
01219 m_effect_bounds.moveTopLeft(m_effect_bounds.topLeft() + m_effect_delta0);
01220 m_effect_j--;
01221
01222 m_slideshow_frame_delay_state = 8;
01223 m_effect_current_frame = 1;
01224 }
01225
01226 void SingleView::EffectCircleOut(void)
01227 {
01228 if (m_effect_current_frame == 0)
01229 {
01230 StartPainter();
01231 m_effect_bounds = QRect(QPoint(width(), height() >> 1), size());
01232 m_effect_alpha = 2 * M_PI;
01233
01234 m_effect_circle_out_points.setPoint(
01235 0, m_effect_bounds.width() >> 1, m_effect_bounds.height() >> 1);
01236 m_effect_circle_out_points.setPoint(
01237 3, m_effect_bounds.width() >> 1, m_effect_bounds.height() >> 1);
01238
01239 m_effect_delta2_x = M_PI / 16;
01240 m_effect_delta2_y = sqrtf(sq(m_effect_bounds.width()) * 1.0f +
01241 sq(m_effect_bounds.height()) * 0.5f);
01242 }
01243
01244 if (m_effect_alpha < 0)
01245 {
01246 m_effect_painter->end();
01247
01248 m_slideshow_frame_delay_state = -1;
01249 m_effect_running = false;
01250 update();
01251 return;
01252 }
01253
01254 QPoint tmp = m_effect_bounds.topLeft();
01255
01256 m_effect_bounds.moveTopLeft(
01257 QPoint((m_effect_bounds.width() >> 1) +
01258 (int)(m_effect_delta2_y * cos(m_effect_alpha)),
01259 (m_effect_bounds.height() >> 1) +
01260 (int)(m_effect_delta2_y * sin(m_effect_alpha))));
01261
01262 m_effect_alpha -= m_effect_delta2_x;
01263
01264 m_effect_circle_out_points.setPoint(1, tmp);
01265 m_effect_circle_out_points.setPoint(2, m_effect_bounds.topLeft());
01266
01267 m_effect_painter->drawPolygon(m_effect_circle_out_points);
01268
01269 m_slideshow_frame_delay_state = 20;
01270 m_effect_current_frame = 1;
01271 }
01272
01273 void SingleView::EffectBlobs(void)
01274 {
01275 int r;
01276
01277 if (m_effect_current_frame == 0)
01278 {
01279 StartPainter();
01280 m_effect_alpha = M_PI * 2;
01281 m_effect_bounds.setSize(size());
01282 m_effect_i = 150;
01283 }
01284
01285 if (m_effect_i <= 0)
01286 {
01287 m_effect_painter->end();
01288
01289 m_slideshow_frame_delay_state = -1;
01290 m_effect_running = false;
01291 update();
01292 return;
01293 }
01294
01295 m_effect_bounds.setTopLeft(QPoint(rand() % m_effect_bounds.width(),
01296 rand() % m_effect_bounds.height()));
01297
01298 r = (rand() % 200) + 50;
01299
01300 m_effect_painter->drawEllipse(m_effect_bounds.x() - r,
01301 m_effect_bounds.y() - r, r, r);
01302 m_effect_i--;
01303
01304 m_slideshow_frame_delay_state = 10;
01305 m_effect_current_frame = 1;
01306 }
01307
01308 void SingleView::EffectNoise(void)
01309 {
01310 int x, y, i, w, h, fact, sz;
01311
01312 fact = (rand() % 3) + 1;
01313
01314 w = width() >> fact;
01315 h = height() >> fact;
01316 sz = 1 << fact;
01317
01318 for (i = (w * h) << 1; i > 0; i--)
01319 {
01320 x = (rand() % w) << fact;
01321 y = (rand() % h) << fact;
01322 bitBlt(this, QPoint(x, y),
01323 m_effect_pixmap, QRect(x, y, sz, sz), Qt::CopyROP, true);
01324 }
01325
01326 m_slideshow_frame_delay_state = -1;
01327 m_effect_running = false;
01328 update();
01329 return;
01330 }
01331
01332 void SingleView::SlideTimeout(void)
01333 {
01334 bool wasMovie = false, isMovie = false;
01335 if (m_effect_method.isEmpty())
01336 {
01337 VERBOSE(VB_IMPORTANT, LOC_ERR + "No transition method");
01338 return;
01339 }
01340
01341 if (!m_effect_running)
01342 {
01343 if (m_slideshow_frame_delay_state == -1)
01344 {
01345
01346
01347 m_slideshow_frame_delay_state = m_slideshow_frame_delay * 1000;
01348 m_effect_current_frame = 0;
01349 }
01350 else
01351 {
01352
01353
01354 if (m_slideshow_running)
01355 {
01356 if (m_effect_random)
01357 m_effect_method = GetRandomEffect();
01358
01359 DisplayNext(false, false);
01360
01361 wasMovie = m_movieState > 0;
01362 Load();
01363 isMovie = m_movieState > 0;
01364
01365
01366 if (wasMovie || isMovie)
01367 {
01368 m_slideshow_frame_delay_state = 1;
01369 }
01370 else
01371 {
01372 CreateEffectPixmap();
01373 m_effect_running = true;
01374 m_slideshow_frame_delay_state = 10;
01375 m_effect_current_frame = 0;
01376 }
01377 }
01378 m_info_show_short = false;
01379 }
01380 }
01381
01382 update();
01383
01384 if (m_slideshow_running)
01385 {
01386 m_slideshow_timer->start(m_slideshow_frame_delay_state, true);
01387
01388
01389
01390 if (wasMovie || isMovie)
01391 {
01392 m_slideshow_frame_delay_state = -1;
01393 }
01394 }
01395 }
01396
01397 void SingleView::CaptionTimeout(void)
01398 {
01399 m_caption_timer->stop();
01400 bitBlt(this, QPoint(0, screenheight - 100),
01401 m_caption_restore_pixmap, QRect(0,0,-1,-1), Qt::CopyROP);
01402 }