ScreenImageMgr.cpp   ScreenImageMgr.cpp 
skipping to change at line 43 skipping to change at line 43
#include <QPixmap> #include <QPixmap>
#include <QString> #include <QString>
#include <QDebug> #include <QDebug>
#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 ScreenImage::ScreenImage(const QString& filename, float x, float y, bool sh
ow, float scale) ow, float scale, float alpha, float fadeDuration)
: tex(NULL) : tex(NULL), maxAlpha(alpha)
{ {
try try
{ {
QString path = StelApp::getInstance().getFileMgr().findFile( QString path = StelFileMgr::findFile("scripts/" + filename);
"scripts/" + filename); QPixmap pm(path);
tex = StelMainGraphicsView::getInstance().scene()->addPixmap tex = StelMainGraphicsView::getInstance().scene()->addPixmap
(QPixmap(path)); (pm.scaled(pm.size()*scale));
if (scale != 1.) tex->setPos(x, y);
tex->scale(scale,scale);
tex->setOffset(x, y);
tex->setVisible(show);
anim = new QGraphicsItemAnimation(); anim = new QGraphicsItemAnimation();
moveTimer = new QTimeLine(0); moveTimer = new QTimeLine();
moveTimer->setCurveShape(QTimeLine::LinearCurve); moveTimer->setCurveShape(QTimeLine::LinearCurve);
anim->setTimeLine(moveTimer); anim->setTimeLine(moveTimer);
anim->setItem(tex); anim->setItem(tex);
fadeTimer = new QTimeLine(0);
fadeTimer = new QTimeLine();
fadeTimer->setCurveShape(QTimeLine::LinearCurve);
setFadeDuration(fadeDuration);
connect(fadeTimer, SIGNAL(valueChanged(qreal)), this, SLOT(s
etOpacity(qreal)));
// set inital displayed state
if (show)
tex->setOpacity(maxAlpha);
else
tex->setOpacity(0.);
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
qWarning() << "Failed to create ScreenImage: " << e.what(); qWarning() << "Failed to create ScreenImage: " << e.what();
} }
} }
ScreenImage::~ScreenImage() ScreenImage::~ScreenImage()
{ {
if (tex!=NULL) if (tex!=NULL)
{ {
delete tex; delete tex;
tex = NULL; tex = NULL;
} }
moveTimer->stop(); moveTimer->stop();
delete anim; anim = NULL; delete anim; anim = NULL;
delete moveTimer; moveTimer = NULL; delete moveTimer; moveTimer = NULL;
fadeTimer->stop();
delete fadeTimer; fadeTimer = NULL;
} }
bool ScreenImage::draw(const StelCore* core) bool ScreenImage::draw(const StelCore* core)
{ {
tex->setVisible(imageFader);
return true; return true;
} }
void ScreenImage::update(double deltaTime) void ScreenImage::update(double deltaTime)
{ {
imageFader.update((int)(deltaTime*1000));
// TODO when we have QT 4.5 - use opacity of QGraphicsItem to set al
pha
} }
void ScreenImage::setFadeDuration(float duration) void ScreenImage::setFadeDuration(float duration)
{ {
imageFader.setDuration(duration); int fadeMs = duration * 1000;
if (fadeMs<=0) fadeMs=1;
fadeTimer->setDuration(fadeMs);
} }
void ScreenImage::setFlagShow(bool b) void ScreenImage::setFlagShow(bool b)
{ {
// TODO don't use this value after QT 4.5 and opacity of QGraphicsIt if (b)
em {
imageFader = b; fadeTimer->setFrameRange(tex->opacity()*fadeTimer->duration(
),fadeTimer->duration());
fadeTimer->setDirection(QTimeLine::Forward);
}
else
{
fadeTimer->setFrameRange(tex->opacity()*fadeTimer->duration(
),0);
fadeTimer->setDirection(QTimeLine::Backward);
}
fadeTimer->start();
} }
bool ScreenImage::getFlagShow(void) bool ScreenImage::getFlagShow(void)
{ {
return imageFader; return (tex->opacity() > 0.);
} }
void ScreenImage::setAlpha(float a, float duration) void ScreenImage::setAlpha(float a)
{ {
imageFader.setMaxValue(a); maxAlpha = a;
if (getFlagShow())
{
fadeTimer->stop();
tex->setOpacity(a);
}
} }
void ScreenImage::setXY(float x, float y, float duration) void ScreenImage::setXY(float x, float y, float duration)
{ {
if (duration<=0.) if (duration<=0.)
{ {
moveTimer->stop(); moveTimer->stop();
tex->setOffset(x, y); tex->setPos(x, y);
} }
else else
{ {
moveTimer->stop(); moveTimer->stop();
int durationMs = duration*1000; moveTimer->setDuration(duration*1000);
moveTimer->setDuration(durationMs); moveTimer->setFrameRange(0,100);
QPointF p(tex->offset()); QPointF p(tex->pos());
if (p == QPointF(x,y)) return;
float sX = p.x(); float sX = p.x();
float sY = p.y(); float sY = p.y();
float eX = x;
float eY = y;
float dX = (x-sX) / 200.; float dX = (x-sX) / 200.;
float dY = (y-sY) / 200.; float dY = (y-sY) / 200.;
for(int i=0; i<200; i++) for(int i=0; i<200; i++)
anim->setPosAt(i/200., QPointF(sX+(dX*i), sY+(dY*i)) anim->setPosAt(i/200., QPointF(sX+(dX*i), (sY+(dY*i)
); )));
anim->setPosAt(200., QPointF(eX, eY)); anim->setPosAt(1.0, QPointF(x, y));
moveTimer->start(); moveTimer->start();
} }
} }
void ScreenImage::addXY(float x, float y, float duration)
{
QPointF currentPos = tex->pos();
setXY(currentPos.x() + x, currentPos.y() + y, duration);
}
int ScreenImage::imageWidth(void)
{
return tex->pixmap().size().width();
}
int ScreenImage::imageHeight(void)
{
return tex->pixmap().size().height();
}
void ScreenImage::setOpacity(qreal alpha)
{
tex->setOpacity(alpha*maxAlpha);
}
////////////////////////// //////////////////////////
// ScreenImageMgr class // // ScreenImageMgr class //
////////////////////////// //////////////////////////
ScreenImageMgr::ScreenImageMgr() ScreenImageMgr::ScreenImageMgr()
{ {
setObjectName("ScreenImageMgr"); setObjectName("ScreenImageMgr");
connect(this, SIGNAL(requestCreateScreenImage(const QString&, const connect(this, SIGNAL(requestCreateScreenImage(const QString&, const
QString&, float, float, float, bool, float)), QString&, float, float, float, bool, float, float)),
this, SLOT(doCreateScreenImage(const QString&, const QString this, SLOT(doCreateScreenImage(const QString&, const QString
&, float, float, float, bool, float))); &, float, float, float, bool, float, float)));
connect(this, SIGNAL(requestSetImageShow(const QString&, bool)), connect(this, SIGNAL(requestSetImageShow(const QString&, bool)),
this, SLOT(doSetImageShow(const QString&, bool))); this, SLOT(doSetImageShow(const QString&, bool)));
connect(this, SIGNAL(requestSetImageAlpha(const QString&, float)),
this, SLOT(doSetImageAlpha(const QString&, float)));
connect(this, SIGNAL(requestSetImageXY(const QString&, float, float, float)), connect(this, SIGNAL(requestSetImageXY(const QString&, float, float, float)),
this, SLOT(doSetImageXY(const QString&, float, float, float) )); this, SLOT(doSetImageXY(const QString&, float, float, float) ));
connect(this, SIGNAL(requestDeleteImage(const QString&)), connect(this, SIGNAL(requestDeleteImage(const QString&)),
this, SLOT(doDeleteImage(const QString&))); this, SLOT(doDeleteImage(const QString&)));
connect(this, SIGNAL(requestDeleteAllImages()), connect(this, SIGNAL(requestDeleteAllImages()),
this, SLOT(doDeleteAllImages())); this, SLOT(doDeleteAllImages()));
} }
ScreenImageMgr::~ScreenImageMgr() ScreenImageMgr::~ScreenImageMgr()
{ {
} }
void ScreenImageMgr::init() void ScreenImageMgr::init()
{ {
} }
skipping to change at line 183 skipping to change at line 227
if (m!=NULL) if (m!=NULL)
m->draw(core); m->draw(core);
} }
void ScreenImageMgr::createScreenImage(const QString& id, void ScreenImageMgr::createScreenImage(const QString& id,
const QString& filename, const QString& filename,
float x, float x,
float y, float y,
float scale, float scale,
bool visible, bool visible,
float alpha) float alpha,
float fadeDuration)
{ {
emit(requestCreateScreenImage(id, filename, x, y, scale, visible, al pha)); emit(requestCreateScreenImage(id, filename, x, y, scale, visible, al pha, fadeDuration));
} }
void ScreenImageMgr::deleteImage(const QString& id) void ScreenImageMgr::deleteImage(const QString& id)
{ {
emit(requestDeleteImage(id)); emit(requestDeleteImage(id));
} }
void ScreenImageMgr::deleteAllImages() void ScreenImageMgr::deleteAllImages()
{ {
emit(requestDeleteAllImages()); emit(requestDeleteAllImages());
skipping to change at line 212 skipping to change at line 257
bool ScreenImageMgr::getShowImage(const QString& id) bool ScreenImageMgr::getShowImage(const QString& id)
{ {
if (allScreenImages.contains(id)) if (allScreenImages.contains(id))
if (allScreenImages[id]!=NULL) if (allScreenImages[id]!=NULL)
return allScreenImages[id]->getFlagShow(); return allScreenImages[id]->getFlagShow();
return false; return false;
} }
int ScreenImageMgr::getImageWidth(const QString& id)
{
if (allScreenImages.contains(id))
if (allScreenImages[id]!=NULL)
return allScreenImages[id]->imageWidth();
return 0;
}
int ScreenImageMgr::getImageHeight(const QString& id)
{
if (allScreenImages.contains(id))
if (allScreenImages[id]!=NULL)
return allScreenImages[id]->imageHeight();
return 0;
}
void ScreenImageMgr::showImage(const QString& id, bool show) void ScreenImageMgr::showImage(const QString& id, bool show)
{ {
emit(requestSetImageShow(id, show)); emit(requestSetImageShow(id, show));
} }
void ScreenImageMgr::setImageAlpha(const QString& id, float alpha)
{
emit(requestSetImageAlpha(id, 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)
{ {
emit(requestSetImageXY(id, x, y, duration)); emit(requestSetImageXY(id, x, y, duration));
} }
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);
skipping to change at line 242 skipping to change at line 310
return StelApp::getInstance().getModuleMgr().getModule("Land scapeMgr")->getCallOrder(actionName)+11; return StelApp::getInstance().getModuleMgr().getModule("Land scapeMgr")->getCallOrder(actionName)+11;
return 0; return 0;
} }
void ScreenImageMgr::doCreateScreenImage(const QString& id, void ScreenImageMgr::doCreateScreenImage(const QString& id,
const QString& filename, const QString& filename,
float x, float x,
float y, float y,
float scale, float scale,
bool visible, bool visible,
float alpha) float alpha,
float fadeDuration)
{ {
// First check to see if there is already an image loaded with the // First check to see if there is already an image loaded with the
// specified ID, and drop it if necessary // specified ID, and drop it if necessary
if (allScreenImages.contains(id)) if (allScreenImages.contains(id))
doDeleteImage(id); doDeleteImage(id);
ScreenImage* i = new ScreenImage(filename, x, y, visible, scale); ScreenImage* i = new ScreenImage(filename, x, y, visible, scale, alp ha, fadeDuration);
if (i==NULL) if (i==NULL)
return; return;
if (visible)
i->setFlagShow(true);
allScreenImages[id] = i; allScreenImages[id] = i;
return; return;
} }
void ScreenImageMgr::doSetImageShow(const QString& id, bool show) void ScreenImageMgr::doSetImageShow(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::doSetImageAlpha(const QString& id, float alpha)
{
if (allScreenImages.contains(id))
if (allScreenImages[id]!=NULL)
allScreenImages[id]->setAlpha(alpha);
}
void ScreenImageMgr::doSetImageXY(const QString& id, float x, float y, floa t duration) void ScreenImageMgr::doSetImageXY(const QString& id, float x, float y, floa t 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::doDeleteImage(const QString& id) void ScreenImageMgr::doDeleteImage(const QString& id)
{ {
if (allScreenImages.contains(id)) if (allScreenImages.contains(id))
 End of changes. 28 change blocks. 
46 lines changed or deleted 119 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/