79
78
connect(m_left, SIGNAL(clicked()), this, SLOT(leftClicked()));
80
79
connect(m_right, SIGNAL(clicked()), this, SLOT(rightClicked()));
81
connect(Animator::self(), SIGNAL(customAnimationFinished(int)),
82
this, SLOT(animationComplete(int)));
85
Scroller::~Scroller() {
86
//avoid possible problems when shutting down while animations
89
Animator::self()->stopCustomAnimation(m_animid);
91
foreach (KIcon * icon, m_feedIcons) {
84
qDeleteAll(m_feedIcons);
96
87
delete m_activeitemlist;
180
doAnimation(QAbstractAnimation::Forward);
192
void Scroller::doAnimation()
184
void Scroller::doAnimation(QAbstractAnimation::Direction direction)
194
186
if (m_list->size() > 1) {
195
if (m_animations && m_animid == 0) {
187
if (m_animations && !m_isAnimating) {
196
188
SingleFeedItem * item = new SingleFeedItem(this);
197
189
item->setFeedData(m_list->at(m_current));
198
190
item->setDisplayExtra(m_hovered);
199
191
item->setZValue(m_itemlist->size() + 1);
201
item->setPos(m_animdirection * size().width(), 0);
193
item->setPos((direction == QAbstractAnimation::Forward? 1 : -1) * size().width(), 0);
202
194
item->setRect(QRect(0, 0, size().width(), size().height()));
203
195
if (!m_itemlist->contains(item)) {
204
196
m_itemlist->append(item);
214
206
time = 400 / queuelength;
215
207
frames = time / 40;
216
m_animid = Animator::self()->customAnimation(frames, time,
217
Animator::LinearCurve,
209
QPropertyAnimation *animation = m_animation.data();
211
animation = new QPropertyAnimation(this, "animate");
212
animation->setStartValue(0.0);
213
animation->setEndValue(1.0);
214
animation->setEasingCurve(QEasingCurve::InOutQuad);
215
m_animation = animation;
216
connect(animation, SIGNAL(finished()), this, SLOT(animationComplete()));
217
} else if (animation->state() == QAbstractAnimation::Running) {
221
animation->setDuration(time);
222
animation->setDirection(direction);
223
if (m_delayedNext > 0 || m_delayedPrev > 0) {
224
animation->start(QAbstractAnimation::KeepWhenStopped);
226
animation->start(QAbstractAnimation::DeleteWhenStopped);
228
m_isAnimating = true;
220
230
m_itemlist->at(m_itemlist->size() - 1)->setFeedData(m_list->at(m_current));
225
void Scroller::animationComplete(int id)
227
bool stillAnimating = false;
228
if (id == m_animid) {
230
m_activeitemlist->takeFirst(); //remove the first item.
231
if (m_delayedNext > 0) {
234
QTimer::singleShot(0, this, SLOT(moveNext()));
235
stillAnimating = true;
236
} else if (m_delayedPrev > 0) {
238
QTimer::singleShot(0, this, SLOT(movePrev()));
239
stillAnimating = true;
235
void Scroller::animationComplete()
237
m_isAnimating = false;
239
m_activeitemlist->takeFirst(); //remove the first item.
240
if (m_delayedNext > 0) {
243
QTimer::singleShot(50, this, SLOT(moveNext()));
244
} else if (m_delayedPrev > 0) {
247
QTimer::singleShot(50, this, SLOT(movePrev()));
248
} else if (m_itemlist->size() > 2) {
249
QTimer::singleShot(0, this, SLOT(clearUnusedItems()));
253
qreal Scroller::animValue() const
255
qreal xPosition = 0.0;
257
foreach (SingleFeedItem *item, *m_activeitemlist) {
258
if (m_current == item->itemNumber()) {
259
xPosition = item->pos().x();
243
if (!stillAnimating && (m_itemlist->size() > 2) &&
244
!Animator::self()->isAnimating()) {
245
QTimer::singleShot(0, this, SLOT(clearUnusedItems()));
249
void Scroller::animate(qreal anim)
267
void Scroller::animate(qreal value)
251
int width = size().width();
269
if (m_animation.isNull()) {
273
const int width = size().width();
274
const bool isForward = m_animation.data()->direction() == QAbstractAnimation::Forward;
252
277
foreach (SingleFeedItem * item, *m_activeitemlist) {
254
278
if (m_current == item->itemNumber()) {
255
left = (m_animdirection * (1-anim) * width);
279
xPosition = (isForward ? 1 * (1-value) : -1 * value) * width;
257
if (m_animdirection == 1) {
258
left = ((-1 * width) + ((1-anim) * width));
260
left = (anim * width);
281
xPosition = (1-value) * width + (isForward ? -1 * width : 0);
263
item->setPos(left, 0);
283
item->setX(xPosition);
412
432
data.time = timestamp;
414
if (!m_feedIcons.contains(icon)) {
415
QPixmap p = QPixmap(icon);
434
KIcon *icon = m_feedIcons.value(iconName);
436
QPixmap p = QPixmap(iconName);
416
437
if (!p.isNull()) {
417
m_feedIcons[icon] = new KIcon(p.scaled(16, 16));
418
data.icon = m_feedIcons[icon];
420
data.icon = m_feedIcons["generic"];
438
icon = new KIcon(p.scaled(16, 16));
439
m_feedIcons.insert(iconName, icon);
446
data.icon = m_feedIcons["generic"];
425
449
data.itemNumber = m_list->size();
426
450
m_list->append(data);
451
475
.arg(m_list->at(i).title);
455
noitems.title = "no items to display";
456
noitems.extrainfo = "no items to display";
457
noitems.text = data["title"].toString();
458
noitems.icon = m_feedIcons["generic"];
460
478
if (m_list->size() < 1) {
480
noitems.title = "no items to display";
481
noitems.extrainfo = "no items to display";
482
noitems.text = data["title"].toString();
483
noitems.icon = m_feedIcons["generic"];
461
485
m_list->append(noitems);