2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Use both thumbnails in photos and documents.

Fixes #5602.
This commit is contained in:
John Preston
2019-01-25 18:37:28 +04:00
parent a70e72f75d
commit a1baa23a52
56 changed files with 1358 additions and 878 deletions

View File

@@ -561,7 +561,7 @@ void FieldAutocompleteInner::paintEvent(QPaintEvent *e) {
App::roundRect(p, QRect(tl, st::stickerPanSize), st::emojiPanHover, StickerHoverCorners);
}
document->checkStickerThumb();
document->checkStickerSmall();
float64 coef = qMin((st::stickerPanSize.width() - st::buttonRadius * 2) / float64(document->dimensions.width()), (st::stickerPanSize.height() - st::buttonRadius * 2) / float64(document->dimensions.height()));
if (coef > 1) coef = 1;
@@ -569,7 +569,7 @@ void FieldAutocompleteInner::paintEvent(QPaintEvent *e) {
if (w < 1) w = 1;
if (h < 1) h = 1;
QPoint ppos = pos + QPoint((st::stickerPanSize.width() - w) / 2, (st::stickerPanSize.height() - h) / 2);
if (const auto image = document->getStickerThumb()) {
if (const auto image = document->getStickerSmall()) {
p.drawPixmapLeft(ppos, width(), image->pix(document->stickerSetOrigin(), w, h));
}
}

View File

@@ -352,11 +352,10 @@ void GifsListWidget::selectInlineResult(int row, int column) {
auto item = _rows[row].items[column];
if (const auto photo = item->getPhoto()) {
if (photo->medium->loaded() || photo->thumb->loaded()) {
if (photo->thumbnail()->loaded()) {
_photoChosen.fire_copy(photo);
} else if (!photo->medium->loading()) {
photo->thumb->loadEvenCancelled(Data::FileOrigin());
photo->medium->loadEvenCancelled(Data::FileOrigin());
} else if (!photo->thumbnail()->loading()) {
photo->thumbnail()->loadEvenCancelled(Data::FileOrigin());
}
} else if (const auto document = item->getDocument()) {
if (document->loaded()) {

View File

@@ -259,8 +259,8 @@ void StickersListWidget::Footer::enumerateVisibleIcons(Callback callback) {
void StickersListWidget::Footer::preloadImages() {
enumerateVisibleIcons([](const StickerIcon &icon, int x) {
if (auto sticker = icon.sticker) {
sticker->thumb->load(sticker->stickerSetOrigin());
if (const auto sticker = icon.sticker) {
sticker->loadThumbnail(sticker->stickerSetOrigin());
}
});
}
@@ -631,10 +631,12 @@ void StickersListWidget::Footer::paintSetIcon(
int x) const {
if (icon.sticker) {
const auto origin = icon.sticker->stickerSetOrigin();
icon.sticker->thumb->load(origin);
auto pix = icon.sticker->thumb->pix(origin, icon.pixw, icon.pixh);
if (const auto thumb = icon.sticker->thumbnail()) {
thumb->load(origin);
auto pix = thumb->pix(origin, icon.pixw, icon.pixh);
p.drawPixmapLeft(x + (st::stickerIconWidth - icon.pixw) / 2, _iconsTop + (st::emojiFooterHeight - icon.pixh) / 2, width(), pix);
p.drawPixmapLeft(x + (st::stickerIconWidth - icon.pixw) / 2, _iconsTop + (st::emojiFooterHeight - icon.pixh) / 2, width(), pix);
}
} else if (icon.megagroup) {
icon.megagroup->paintUserpicLeft(p, x + (st::stickerIconWidth - st::stickerGroupCategorySize) / 2, _iconsTop + (st::emojiFooterHeight - st::stickerGroupCategorySize) / 2, width(), st::stickerGroupCategorySize);
} else {
@@ -753,7 +755,9 @@ void StickersListWidget::readVisibleSets() {
int count = qMin(set.pack.size(), _columnCount);
int loaded = 0;
for (int j = 0; j < count; ++j) {
if (set.pack[j]->thumb->loaded() || set.pack[j]->loaded()) {
if (!set.pack[j]->hasThumbnail()
|| set.pack[j]->thumbnail()->loaded()
|| set.pack[j]->loaded()) {
++loaded;
}
}
@@ -1339,14 +1343,14 @@ void StickersListWidget::paintSticker(Painter &p, Set &set, int y, int index, bo
App::roundRect(p, QRect(tl, _singleSize), st::emojiPanHover, StickerHoverCorners);
}
document->checkStickerThumb();
document->checkStickerSmall();
auto coef = qMin((_singleSize.width() - st::buttonRadius * 2) / float64(document->dimensions.width()), (_singleSize.height() - st::buttonRadius * 2) / float64(document->dimensions.height()));
if (coef > 1) coef = 1;
auto w = qMax(qRound(coef * document->dimensions.width()), 1);
auto h = qMax(qRound(coef * document->dimensions.height()), 1);
auto ppos = pos + QPoint((_singleSize.width() - w) / 2, (_singleSize.height() - h) / 2);
if (const auto image = document->getStickerThumb()) {
if (const auto image = document->getStickerSmall()) {
if (image->loaded()) {
p.drawPixmapLeft(
ppos,
@@ -1786,7 +1790,7 @@ void StickersListWidget::preloadImages() {
const auto document = sets[i].pack[j];
if (!document || !document->sticker()) continue;
document->checkStickerThumb();
document->checkStickerSmall();
}
if (k > _columnCount * (_columnCount + 1)) break;
}
@@ -2047,7 +2051,10 @@ void StickersListWidget::fillIcons(QList<StickerIcon> &icons) {
}
auto s = _mySets[i].pack[0];
auto availw = st::stickerIconWidth - 2 * st::stickerIconPadding, availh = st::emojiFooterHeight - 2 * st::stickerIconPadding;
auto thumbw = s->thumb->width(), thumbh = s->thumb->height(), pixw = 1, pixh = 1;
const auto size = s->hasThumbnail()
? s->thumbnail()->size()
: QSize();
auto thumbw = size.width(), thumbh = size.height(), pixw = 1, pixh = 1;
if (availw * thumbh > availh * thumbw) {
pixh = availh;
pixw = (pixh * thumbw) / thumbh;