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