disabled scrolling when scrollbar is invisible

This commit is contained in:
fourtf 2017-02-06 18:31:25 +01:00
parent 33ba35471f
commit 5673efa0db
4 changed files with 41 additions and 32 deletions

View file

@ -1,6 +1,8 @@
#ifndef EMOTES_H #ifndef EMOTES_H
#define EMOTES_H #define EMOTES_H
#define GIF_FRAME_LENGTH 33
#include "concurrentmap.h" #include "concurrentmap.h"
#include "messages/lazyloadedimage.h" #include "messages/lazyloadedimage.h"
#include "twitchemotevalue.h" #include "twitchemotevalue.h"
@ -89,7 +91,7 @@ public:
if (!gifUpdateTimerInitiated) { if (!gifUpdateTimerInitiated) {
gifUpdateTimerInitiated = true; gifUpdateTimerInitiated = true;
gifUpdateTimer.setInterval(33); gifUpdateTimer.setInterval(GIF_FRAME_LENGTH);
gifUpdateTimer.start(); gifUpdateTimer.start();
} }

View file

@ -22,6 +22,7 @@ LazyLoadedImage::LazyLoadedImage(const QString &url, qreal scale,
: currentPixmap(NULL) : currentPixmap(NULL)
, allFrames() , allFrames()
, currentFrame(0) , currentFrame(0)
, currentFrameOffset(0)
, url(url) , url(url)
, name(name) , name(name)
, tooltip(tooltip) , tooltip(tooltip)
@ -39,6 +40,7 @@ LazyLoadedImage::LazyLoadedImage(QPixmap *image, qreal scale,
: currentPixmap(image) : currentPixmap(image)
, allFrames() , allFrames()
, currentFrame(0) , currentFrame(0)
, currentFrameOffset(0)
, url() , url()
, name(name) , name(name)
, tooltip(tooltip) , tooltip(tooltip)
@ -103,12 +105,21 @@ LazyLoadedImage::loadImage()
void void
LazyLoadedImage::gifUpdateTimout() LazyLoadedImage::gifUpdateTimout()
{ {
if (this->currentFrame >= this->allFrames.size() - 1) { this->currentFrameOffset += GIF_FRAME_LENGTH;
this->currentFrame = 0;
this->currentPixmap = this->allFrames.at(0).image; while (true) {
} else { if (this->currentFrameOffset >
this->currentPixmap = this->allFrames.at(++this->currentFrame).image; this->allFrames.at(this->currentFrame).duration) {
this->currentFrameOffset -=
this->allFrames.at(this->currentFrame).duration;
this->currentFrame =
(this->currentFrame + 1) % this->allFrames.size();
} else {
break;
}
} }
this->currentPixmap = this->allFrames[this->currentFrame].image;
} }
} }
} }

View file

@ -95,12 +95,13 @@ public:
private: private:
struct FrameData { struct FrameData {
QPixmap *image; QPixmap *image;
float duration; int duration;
}; };
QPixmap *currentPixmap; QPixmap *currentPixmap;
std::vector<FrameData> allFrames; std::vector<FrameData> allFrames;
int currentFrame; int currentFrame;
int currentFrameOffset;
QString url; QString url;
QString name; QString name;

View file

@ -49,33 +49,26 @@ ChatWidgetView::layoutMessages()
int start = this->scrollbar.getCurrentValue(); int start = this->scrollbar.getCurrentValue();
if (messages.getLength() <= start) { // layout the visible messages in the view
// The scrollbar wants to show more values than we can offer if (messages.getLength() > start) {
int y = -(messages[start].get()->getHeight() *
(fmod(this->scrollbar.getCurrentValue(), 1)));
// just return for now for (int i = start; i < messages.getLength(); ++i) {
return false; auto messagePtr = messages[i];
auto message = messagePtr.get();
redraw |= message->layout(this->width(), true);
// Lower start value to the last message y += message->getHeight();
// start = messages.getLength() - 1;
}
int y = -(messages[start].get()->getHeight() * if (y >= height()) {
(fmod(this->scrollbar.getCurrentValue(), 1))); break;
}
for (int i = start; i < messages.getLength(); ++i) {
auto messagePtr = messages[i];
auto message = messagePtr.get();
redraw |= message->layout(this->width(), true);
y += message->getHeight();
if (y >= height()) {
break;
} }
} }
// layout the messages at the bottom to determine the scrollbar thumb size
int h = this->height() - 8; int h = this->height() - 8;
for (int i = messages.getLength() - 1; i >= 0; i--) { for (int i = messages.getLength() - 1; i >= 0; i--) {
@ -236,11 +229,13 @@ ChatWidgetView::paintEvent(QPaintEvent *)
void void
ChatWidgetView::wheelEvent(QWheelEvent *event) ChatWidgetView::wheelEvent(QWheelEvent *event)
{ {
this->scrollbar.setDesiredValue( if (this->scrollbar.isVisible()) {
this->scrollbar.getDesiredValue() - this->scrollbar.setDesiredValue(
event->delta() / 10.0 * this->scrollbar.getDesiredValue() -
Settings::getInstance().mouseScrollMultiplier.get(), event->delta() / 10.0 *
true); Settings::getInstance().mouseScrollMultiplier.get(),
true);
}
} }
} }
} }