test code
This commit is contained in:
+20
-7
@@ -47,9 +47,10 @@ void Image::loadImage()
|
||||
{
|
||||
util::NetworkRequest req(this->getUrl());
|
||||
req.setCaller(this);
|
||||
req.get([lli = this](QNetworkReply * reply) {
|
||||
QByteArray array = reply->readAll();
|
||||
QBuffer buffer(&array);
|
||||
req.setUseQuickLoadCache(true);
|
||||
req.get([lli = this](QByteArray bytes) {
|
||||
QByteArray copy = QByteArray::fromRawData(bytes.constData(), bytes.length());
|
||||
QBuffer buffer(©);
|
||||
buffer.open(QIODevice::ReadOnly);
|
||||
|
||||
QImage image;
|
||||
@@ -63,7 +64,7 @@ void Image::loadImage()
|
||||
|
||||
if (first) {
|
||||
first = false;
|
||||
lli->currentPixmap = pixmap;
|
||||
lli->loadedPixmap = pixmap;
|
||||
}
|
||||
|
||||
chatterino::messages::Image::FrameData data;
|
||||
@@ -78,6 +79,10 @@ void Image::loadImage()
|
||||
lli->animated = true;
|
||||
}
|
||||
|
||||
lli->currentPixmap = lli->loadedPixmap;
|
||||
|
||||
lli->isLoaded = true;
|
||||
|
||||
singletons::EmoteManager::getInstance().incGeneration();
|
||||
|
||||
singletons::WindowManager::getInstance().layoutVisibleChatWidgets();
|
||||
@@ -91,7 +96,7 @@ void Image::loadImage()
|
||||
|
||||
void Image::gifUpdateTimout()
|
||||
{
|
||||
if (animated) {
|
||||
if (this->animated) {
|
||||
this->currentFrameOffset += GIF_FRAME_LENGTH;
|
||||
|
||||
while (true) {
|
||||
@@ -112,9 +117,16 @@ const QPixmap *Image::getPixmap()
|
||||
if (!this->isLoading) {
|
||||
this->isLoading = true;
|
||||
|
||||
loadImage();
|
||||
this->loadImage();
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (this->isLoaded) {
|
||||
return this->currentPixmap;
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
return this->currentPixmap;
|
||||
}
|
||||
|
||||
qreal Image::getScale() const
|
||||
@@ -157,6 +169,7 @@ int Image::getWidth() const
|
||||
if (this->currentPixmap == nullptr) {
|
||||
return 16;
|
||||
}
|
||||
|
||||
return this->currentPixmap->width();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
|
||||
#include <QPixmap>
|
||||
#include <QString>
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
|
||||
namespace chatterino {
|
||||
namespace messages {
|
||||
|
||||
@@ -41,6 +43,7 @@ private:
|
||||
};
|
||||
|
||||
QPixmap *currentPixmap;
|
||||
QPixmap *loadedPixmap;
|
||||
std::vector<FrameData> allFrames;
|
||||
int currentFrame = 0;
|
||||
int currentFrameOffset = 0;
|
||||
@@ -53,7 +56,8 @@ private:
|
||||
bool ishat;
|
||||
qreal scale;
|
||||
|
||||
bool isLoading;
|
||||
bool isLoading = false;
|
||||
std::atomic<bool> isLoaded{false};
|
||||
|
||||
void loadImage();
|
||||
void gifUpdateTimout();
|
||||
|
||||
@@ -79,6 +79,10 @@ int ImageLayoutElement::getSelectionIndexCount()
|
||||
|
||||
void ImageLayoutElement::paint(QPainter &painter)
|
||||
{
|
||||
if (this->image == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const QPixmap *pixmap = this->image->getPixmap();
|
||||
|
||||
if (pixmap != nullptr && !this->image->isAnimated()) {
|
||||
@@ -89,12 +93,18 @@ void ImageLayoutElement::paint(QPainter &painter)
|
||||
|
||||
void ImageLayoutElement::paintAnimated(QPainter &painter, int yOffset)
|
||||
{
|
||||
if (this->image == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->image->isAnimated()) {
|
||||
if (this->image->getPixmap() != nullptr) {
|
||||
auto pixmap = this->image->getPixmap();
|
||||
|
||||
if (pixmap != nullptr) {
|
||||
// fourtf: make it use qreal values
|
||||
QRect rect = this->getRect();
|
||||
rect.moveTop(rect.y() + yOffset);
|
||||
painter.drawPixmap(QRectF(rect), *this->image->getPixmap(), QRectF());
|
||||
painter.drawPixmap(QRectF(rect), *pixmap, QRectF());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,8 +121,8 @@ public:
|
||||
newChunks->at(0) = newFirstChunk;
|
||||
|
||||
this->chunks = newChunks;
|
||||
qDebug() << acceptedItems.size();
|
||||
qDebug() << this->chunks->at(0)->size();
|
||||
// qDebug() << acceptedItems.size();
|
||||
// qDebug() << this->chunks->at(0)->size();
|
||||
|
||||
if (this->chunks->size() == 1) {
|
||||
this->lastChunkEnd += offset;
|
||||
|
||||
@@ -237,7 +237,7 @@ TwitchModerationElement::TwitchModerationElement()
|
||||
void TwitchModerationElement::addToContainer(MessageLayoutContainer &container,
|
||||
MessageElement::Flags _flags)
|
||||
{
|
||||
qDebug() << _flags;
|
||||
// qDebug() << _flags;
|
||||
|
||||
if (_flags & MessageElement::ModeratorTools) {
|
||||
QSize size((int)(container.scale * 16), (int)(container.scale * 16));
|
||||
|
||||
Reference in New Issue
Block a user