ScreenImageMgr.cpp   ScreenImageMgr.cpp 
/* /*
* Stellarium * Stellarium
* This file Copyright (C) 2008 Matthew Gates * This file Copyright (C) 2008 Matthew Gates
* Parts copyright (C) 2016 Georg Zotti (added size transitions)
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
skipping to change at line 46 skipping to change at line 47
#include <QMap> #include <QMap>
#include <QTimeLine> #include <QTimeLine>
#include <QGraphicsItemAnimation> #include <QGraphicsItemAnimation>
/////////////////////// ///////////////////////
// ScreenImage class // // ScreenImage class //
/////////////////////// ///////////////////////
ScreenImage::ScreenImage(const QString& filename, float x, float y, bool sh ow, float scale, float alpha, float fadeDuration) ScreenImage::ScreenImage(const QString& filename, float x, float y, bool sh ow, float scale, float alpha, float fadeDuration)
: tex(NULL), maxAlpha(alpha) : tex(NULL), maxAlpha(alpha)
{ {
QPixmap pm(filename); QPixmap pixmap(filename);
tex = StelMainView::getInstance().scene()->addPixmap(pm.scaled(pm.si tex = StelMainView::getInstance().scene()->addPixmap(pixmap.scaled(p
ze()*scale)); ixmap.size()*scale));
tex->setPos(x, y); tex->setPos(x, y);
anim = new QGraphicsItemAnimation(); anim = new QGraphicsItemAnimation();
moveTimer = new QTimeLine(); moveTimer = new QTimeLine();
moveTimer->setCurveShape(QTimeLine::LinearCurve); moveTimer->setCurveShape(QTimeLine::LinearCurve);
anim->setTimeLine(moveTimer); anim->setTimeLine(moveTimer);
anim->setItem(tex); anim->setItem(tex);
scaleAnim = new QGraphicsItemAnimation();
scaleTimer = new QTimeLine();
scaleTimer->setCurveShape(QTimeLine::LinearCurve);
scaleAnim->setTimeLine(scaleTimer);
scaleAnim->setItem(tex);
// we must configure the end for proper rescaling
scaleAnim->setScaleAt(0., 1., 1.);
scaleAnim->setScaleAt(1., 1., 1.);
fadeTimer = new QTimeLine(); fadeTimer = new QTimeLine();
fadeTimer->setCurveShape(QTimeLine::LinearCurve); fadeTimer->setCurveShape(QTimeLine::LinearCurve);
setFadeDuration(fadeDuration); setFadeDuration(fadeDuration);
connect(fadeTimer, SIGNAL(valueChanged(qreal)), this, SLOT(setOpacit y(qreal))); connect(fadeTimer, SIGNAL(valueChanged(qreal)), this, SLOT(setOpacit y(qreal)));
// set inital displayed state // set inital displayed state
if (show) if (show)
tex->setOpacity(maxAlpha); tex->setOpacity(maxAlpha);
else else
tex->setOpacity(0.); tex->setOpacity(0.);
} }
ScreenImage::~ScreenImage() ScreenImage::~ScreenImage()
{ {
moveTimer->stop();
scaleTimer->stop();
fadeTimer->stop();
delete anim; anim = NULL;
delete scaleAnim; scaleAnim = NULL;
delete moveTimer; moveTimer = NULL;
delete scaleTimer; scaleTimer = NULL;
delete fadeTimer; fadeTimer = NULL;
if (tex!=NULL) if (tex!=NULL)
{ {
delete tex; delete tex;
tex = NULL; tex = NULL;
} }
moveTimer->stop();
delete anim; anim = NULL;
delete moveTimer; moveTimer = NULL;
} }
bool ScreenImage::draw(const StelCore*) bool ScreenImage::draw(const StelCore*)
{ {
return true; return true;
} }
void ScreenImage::update(double) void ScreenImage::update(double)
{ {
} }
void ScreenImage::setFadeDuration(float duration) void ScreenImage::setFadeDuration(float duration)
{ {
int fadeMs = duration * 1000; fadeTimer->setDuration(qMax(1, (int)(duration*1000)));
if (fadeMs<=0) fadeMs=1;
fadeTimer->setDuration(fadeMs);
} }
void ScreenImage::setFlagShow(bool b) void ScreenImage::setFlagShow(bool b)
{ {
if (b) if (b)
{ {
fadeTimer->setFrameRange(tex->opacity()*fadeTimer->duration( ),fadeTimer->duration()); fadeTimer->setFrameRange(tex->opacity()*fadeTimer->duration( ),fadeTimer->duration());
fadeTimer->setDirection(QTimeLine::Forward); fadeTimer->setDirection(QTimeLine::Forward);
} }
else else
skipping to change at line 172 skipping to change at line 185
int ScreenImage::imageHeight(void) int ScreenImage::imageHeight(void)
{ {
return tex->pixmap().size().height(); return tex->pixmap().size().height();
} }
void ScreenImage::setOpacity(qreal alpha) void ScreenImage::setOpacity(qreal alpha)
{ {
tex->setOpacity(alpha*maxAlpha); tex->setOpacity(alpha*maxAlpha);
} }
void ScreenImage::setScale(float scaleX, float scaleY, float duration)
{
scaleTimer->stop();
// Set a least a tiny duration to allow running the "animation"
scaleTimer->setDuration(qMax(0.001f, duration)*1000);
scaleTimer->setFrameRange(0,100);
tex->setTransformationMode(Qt::SmoothTransformation);
// reconfigure the animation which may have halted at 1 after a prev
ious run, so the current scale is at position 1.
scaleAnim->setScaleAt(0., scaleAnim->horizontalScaleAt(1.), scaleAni
m->verticalScaleAt(1.));
scaleAnim->setScaleAt(1., scaleX, scaleY);
scaleTimer->start();
}
float ScreenImage::imageScaleX()
{
return scaleAnim->horizontalScaleAt(1.);
}
float ScreenImage::imageScaleY()
{
return scaleAnim->verticalScaleAt(1.);
}
////////////////////////// //////////////////////////
// ScreenImageMgr class // // ScreenImageMgr class //
////////////////////////// //////////////////////////
ScreenImageMgr::ScreenImageMgr() ScreenImageMgr::ScreenImageMgr()
{ {
setObjectName("ScreenImageMgr"); setObjectName("ScreenImageMgr");
} }
ScreenImageMgr::~ScreenImageMgr() ScreenImageMgr::~ScreenImageMgr()
{ {
skipping to change at line 214 skipping to change at line 253
if (!path.isEmpty()) if (!path.isEmpty())
{ {
ScreenImage* i = new ScreenImage(path, x, y, visible, scale, alpha, fadeDuration); ScreenImage* i = new ScreenImage(path, x, y, visible, scale, alpha, fadeDuration);
if (i==NULL) if (i==NULL)
return; return;
allScreenImages[id] = i; allScreenImages[id] = i;
} }
else else
{ {
qWarning() << "Failed to create ScreenImage: file not exists "; qWarning() << "Failed to create ScreenImage" << id << ": fil e not found: " << filename;
} }
} }
void ScreenImageMgr::deleteImage(const QString& id) void ScreenImageMgr::deleteImage(const QString& id)
{ {
if (allScreenImages.contains(id)) if (allScreenImages.contains(id))
{ {
if (allScreenImages[id]!=NULL) if (allScreenImages[id]!=NULL)
{ {
delete allScreenImages[id]; delete allScreenImages[id];
skipping to change at line 273 skipping to change at line 312
} }
int ScreenImageMgr::getImageHeight(const QString& id) int ScreenImageMgr::getImageHeight(const QString& id)
{ {
if (allScreenImages.contains(id)) if (allScreenImages.contains(id))
if (allScreenImages[id]!=NULL) if (allScreenImages[id]!=NULL)
return allScreenImages[id]->imageHeight(); return allScreenImages[id]->imageHeight();
return 0; return 0;
} }
float ScreenImageMgr::getImageScaleX(const QString& id)
{
if (allScreenImages.contains(id))
if (allScreenImages[id]!=NULL)
return allScreenImages[id]->imageScaleX();
return 0;
}
float ScreenImageMgr::getImageScaleY(const QString& id)
{
if (allScreenImages.contains(id))
if (allScreenImages[id]!=NULL)
return allScreenImages[id]->imageScaleY();
return 0;
}
void ScreenImageMgr::showImage(const QString& id, bool show) void ScreenImageMgr::showImage(const QString& id, bool show)
{ {
if (allScreenImages.contains(id)) if (allScreenImages.contains(id))
if (allScreenImages[id]!=NULL) if (allScreenImages[id]!=NULL)
allScreenImages[id]->setFlagShow(show); allScreenImages[id]->setFlagShow(show);
} }
void ScreenImageMgr::setImageAlpha(const QString& id, float alpha) void ScreenImageMgr::setImageAlpha(const QString& id, float alpha)
{ {
if (allScreenImages.contains(id)) if (allScreenImages.contains(id))
if (allScreenImages[id]!=NULL) if (allScreenImages[id]!=NULL)
allScreenImages[id]->setAlpha(alpha); allScreenImages[id]->setAlpha(alpha);
} }
void ScreenImageMgr::setImageXY(const QString& id, float x, float y, float duration) void ScreenImageMgr::setImageXY(const QString& id, float x, float y, float duration)
{ {
if (allScreenImages.contains(id)) if (allScreenImages.contains(id))
if (allScreenImages[id]!=NULL) if (allScreenImages[id]!=NULL)
allScreenImages[id]->setXY(x,y, duration); allScreenImages[id]->setXY(x, y, duration);
}
void ScreenImageMgr::addImageXY(const QString& id, float x, float y, float
duration)
{
if (allScreenImages.contains(id))
if (allScreenImages[id]!=NULL)
allScreenImages[id]->addXY(x, y, duration);
}
void ScreenImageMgr::setImageScale(const QString& id, float scaleX, float s
caleY, float duration)
{
if (allScreenImages.contains(id))
if (allScreenImages[id]!=NULL)
allScreenImages[id]->setScale(scaleX, scaleY, durati
on);
} }
void ScreenImageMgr::update(double deltaTime) void ScreenImageMgr::update(double deltaTime)
{ {
foreach(ScreenImage* m, allScreenImages) foreach(ScreenImage* m, allScreenImages)
if (m!=NULL) if (m!=NULL)
m->update(deltaTime); m->update(deltaTime);
} }
double ScreenImageMgr::getCallOrder(StelModuleActionName actionName) const double ScreenImageMgr::getCallOrder(StelModuleActionName actionName) const
 End of changes. 10 change blocks. 
11 lines changed or deleted 85 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/