84 lines
3.0 KiB
C++
84 lines
3.0 KiB
C++
#include "elescroll.h"
|
|
#include <QJsonObject>
|
|
#include <QPainter>
|
|
#include <complex>
|
|
|
|
EleScroll::EleScroll(QWidget *parent, QString dirPre, const JValue &map) : QWidget{parent} {
|
|
img.load(dirPre + map["id"].toString());
|
|
auto effStr = map["effect"].toString();
|
|
if(effStr.isEmpty() || effStr=="no") return;
|
|
double effDurD = map["effectSpeed"].toInt()/2;
|
|
if(effDurD==0) return;
|
|
auto interva = round(effDurD / 16.666666666666666666);
|
|
if(interva==0) interva = 1;
|
|
interval = interva * 16.666666666666666666;
|
|
step = round(interval / effDurD);
|
|
if(step==0) step = 1;
|
|
int idx = effStr.lastIndexOf(' ');
|
|
if(idx > -1) {
|
|
effect = effStr.at(idx+1).toLatin1();
|
|
if(effect=='l') end = -(img.width()-step);
|
|
else if(effect=='r') end = img.width()-step;
|
|
else if(effect=='t') end = -(img.height()-step);
|
|
else if(effect=='b') end = img.height()-step;
|
|
}
|
|
}
|
|
EleScroll::EleScroll(QWidget *parent, QString imgPath, char effect, double effDur) : QWidget{parent}, effect(effect) {
|
|
img.load(imgPath);
|
|
if(effect==0) return;
|
|
if(effDur==0) return;
|
|
auto interva = round(effDur / 16.666666666666666666);
|
|
if(interva==0) interva = 1;
|
|
interval = interva * 16.666666666666666666;
|
|
step = round(interval / effDur);
|
|
if(step==0) step = 1;
|
|
if(effect=='l') end = -(img.width()-step);
|
|
else if(effect=='r') end = img.width()-step;
|
|
else if(effect=='t') end = -(img.height()-step);
|
|
else if(effect=='b') end = img.height()-step;
|
|
}
|
|
|
|
void EleScroll::paintEvent(QPaintEvent *) {
|
|
paint(this);
|
|
}
|
|
void EleScroll::paint(QPaintDevice *that) {
|
|
if(img.isNull()) return;
|
|
if(timerId==0 && effect!=0 && interval!=0) timerId = startTimer(round(interval), Qt::PreciseTimer);
|
|
QPainter painter(that);
|
|
painter.setRenderHints(QPainter::Antialiasing|QPainter::SmoothPixmapTransform);
|
|
if(effect=='l') {
|
|
painter.drawPixmap(cur, 0, img);
|
|
painter.drawPixmap(cur+img.width(), 0, img);
|
|
} else if(effect=='r') {
|
|
painter.drawPixmap(cur, 0, img);
|
|
painter.drawPixmap(cur-img.width(), 0, img);
|
|
} else if(effect=='t') {
|
|
painter.drawPixmap(0, cur, img);
|
|
painter.drawPixmap(0, cur+img.height(), img);
|
|
} else if(effect=='b') {
|
|
painter.drawPixmap(0, cur, img);
|
|
painter.drawPixmap(0, cur-img.height(), img);
|
|
} else painter.drawPixmap(0, 0, img);
|
|
}
|
|
|
|
void EleScroll::timerEvent(QTimerEvent *) {
|
|
if(isVisible()) {
|
|
if(effect=='t' || effect=='l') {
|
|
if(cur <= end) cur -= end;
|
|
else cur -= step;
|
|
} else if(effect=='b' || effect=='r') {
|
|
if(cur >= end) cur -= end;
|
|
else cur += step;
|
|
}
|
|
update();
|
|
for(auto split : splits) split->update();
|
|
} else if(timerId!=0) {
|
|
killTimer(timerId);
|
|
timerId = cur = 0;
|
|
}
|
|
}
|
|
|
|
void EleSplitScroll::paintEvent(QPaintEvent *) {
|
|
scroll->paint(this);
|
|
}
|