mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Make UploadedImageModel use loadPixmapFromUrl
This commit is contained in:
parent
6c11b2400a
commit
645cb38893
2 changed files with 19 additions and 29 deletions
|
@ -3,8 +3,10 @@
|
||||||
#include "common/SignalVectorModel.hpp"
|
#include "common/SignalVectorModel.hpp"
|
||||||
#include "messages/Image.hpp"
|
#include "messages/Image.hpp"
|
||||||
#include "singletons/imageuploader/ImageUploader.hpp"
|
#include "singletons/imageuploader/ImageUploader.hpp"
|
||||||
|
#include "singletons/Resources.hpp"
|
||||||
|
#include "util/LoadPixmap.hpp"
|
||||||
|
#include "util/PostToThread.hpp"
|
||||||
#include "util/StandardItemHelper.hpp"
|
#include "util/StandardItemHelper.hpp"
|
||||||
#include "widgets/listview/ImagePtrItemDelegate.hpp"
|
|
||||||
|
|
||||||
#include <qdatetime.h>
|
#include <qdatetime.h>
|
||||||
#include <qlocale.h>
|
#include <qlocale.h>
|
||||||
|
@ -14,13 +16,12 @@
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
UploadedImageModel::UploadedImageModel(QObject *parent)
|
UploadedImageModel::UploadedImageModel(QObject *parent)
|
||||||
: SignalVectorModel<UploadedImage>(4, parent)
|
: SignalVectorModel<UploadedImage>(1, parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
// image, path, delete url
|
|
||||||
|
|
||||||
UploadedImage UploadedImageModel::getItemFromRow(
|
UploadedImage UploadedImageModel::getItemFromRow(
|
||||||
std::vector<QStandardItem *> &row, const UploadedImage &original)
|
std::vector<QStandardItem *> & /* row */, const UploadedImage &original)
|
||||||
{
|
{
|
||||||
return original;
|
return original;
|
||||||
}
|
}
|
||||||
|
@ -28,34 +29,22 @@ UploadedImage UploadedImageModel::getItemFromRow(
|
||||||
void UploadedImageModel::getRowFromItem(const UploadedImage &item,
|
void UploadedImageModel::getRowFromItem(const UploadedImage &item,
|
||||||
std::vector<QStandardItem *> &row)
|
std::vector<QStandardItem *> &row)
|
||||||
{
|
{
|
||||||
row[0]->setData(item.imageLink, ImagePtrItemDelegate::IMAGE_URL_ROLE);
|
row[0]->setData(item.imageLink, Qt::DisplayRole);
|
||||||
row[0]->setData(item.imageLink, UploadedImageModel::DOUBLE_CLICK_LINK_ROLE);
|
row[0]->setData(item.imageLink, UploadedImageModel::DOUBLE_CLICK_LINK_ROLE);
|
||||||
row[0]->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
row[0]->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
||||||
|
|
||||||
auto locale = QLocale::system();
|
loadPixmapFromUrl({item.imageLink},
|
||||||
setStringItem(row[1],
|
[row](const QPixmap &pixmap) {
|
||||||
locale.toString(QDateTime::fromSecsSinceEpoch(item.timestamp),
|
postToThread([pixmap, row]() {
|
||||||
QLocale::ShortFormat),
|
row[0]->setData(pixmap, Qt::DecorationRole);
|
||||||
false);
|
});
|
||||||
|
},
|
||||||
if (item.deletionLink.isNull())
|
{[row]() {
|
||||||
{
|
postToThread([row]() {
|
||||||
setStringItem(row[2], "N/A", false);
|
row[0]->setData(getResources().imageFailedToLoad,
|
||||||
}
|
Qt::DecorationRole);
|
||||||
else
|
});
|
||||||
{
|
}});
|
||||||
setStringItem(row[2], "[Double click to open]", false);
|
|
||||||
row[2]->setData(item.deletionLink, DOUBLE_CLICK_LINK_ROLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.localPath.isNull())
|
|
||||||
{
|
|
||||||
setStringItem(row[3], "n/a", false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setStringItem(row[3], item.localPath, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
|
struct UploadedImage;
|
||||||
class UploadedImageModel : public SignalVectorModel<UploadedImage>
|
class UploadedImageModel : public SignalVectorModel<UploadedImage>
|
||||||
{
|
{
|
||||||
explicit UploadedImageModel(QObject *parent);
|
explicit UploadedImageModel(QObject *parent);
|
||||||
|
|
Loading…
Reference in a new issue