2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-09-02 07:35:12 +00:00

beautiful sticker blur and selection, document and sticker thumbs fixed, sticker emojis in dialog list display done, send image as doc for bad image size done

This commit is contained in:
John Preston
2015-01-05 23:17:33 +03:00
parent 5d54d48f70
commit 476ffca228
27 changed files with 442 additions and 146 deletions

View File

@@ -2147,12 +2147,14 @@ HistoryItem *regItem(HistoryItem *item, bool returnExisting) {
}
HistoryPhoto::HistoryPhoto(const MTPDphoto &photo, int32 width) : HistoryMedia(width)
, pixw(1), pixh(1)
, data(App::feedPhoto(photo))
, openl(new PhotoLink(data)) {
init();
}
HistoryPhoto::HistoryPhoto(PeerData *chat, const MTPDphoto &photo, int32 width) : HistoryMedia(width)
, pixw(1), pixh(1)
, data(App::feedPhoto(photo))
, openl(new PhotoLink(data, chat)) {
init();
@@ -2174,18 +2176,13 @@ void HistoryPhoto::initDimensions(const HistoryItem *parent) {
} else {
thumbh = w; // square chat photo updates
}
_maxw = w;
_height = _minh = thumbh;
if (_maxw < st::minPhotoWidth) {
_maxw = st::minPhotoWidth;
}
if (_height < st::minPhotoHeight) {
_height = st::minPhotoHeight;
}
_maxw = qMax(w, int32(st::minPhotoSize));
_minh = qMax(thumbh, int32(st::minPhotoSize));
_height = resize(w, true, parent);
}
int32 HistoryPhoto::resize(int32 width, bool dontRecountText, const HistoryItem *parent) {
w = qMin(width, _maxw);
pixw = qMin(width, _maxw);
int32 tw = convertScale(data->full->width()), th = convertScale(data->full->height());
if (tw > st::maxMediaSize) {
@@ -2196,22 +2193,20 @@ int32 HistoryPhoto::resize(int32 width, bool dontRecountText, const HistoryItem
tw = (st::maxMediaSize * tw) / th;
th = st::maxMediaSize;
}
_height = th;
if (tw > w) {
_height = (w * _height / tw);
pixh = th;
if (tw > pixw) {
pixh = (pixw * pixh / tw);
} else {
w = tw;
pixw = tw;
}
if (_height > width) {
w = (w * width) / _height;
_height = width;
}
if (w < st::minPhotoWidth) {
w = st::minPhotoWidth;
}
if (_height < st::minPhotoHeight) {
_height = st::minPhotoHeight;
if (pixh > width) {
pixw = (pixw * width) / pixh;
pixh = width;
}
if (pixw < 1) pixw = 1;
if (pixh < 1) pixh = 1;
w = qMax(pixw, int16(st::minPhotoSize));
_height = qMax(pixh, int16(st::minPhotoSize));
return _height;
}
@@ -2281,16 +2276,14 @@ void HistoryPhoto::draw(QPainter &p, const HistoryItem *parent, bool selected, i
bool full = data->full->loaded();
QPixmap pix;
if (full) {
pix = data->full->pixSingle(width);
pix = data->full->pixSingle(pixw, pixh);
} else {
pix = data->thumb->pixBlurredSingle(width);
pix = data->thumb->pixBlurredSingle(pixw, pixh);
}
if (pix.height() >= _height * cIntRetinaFactor()) {
p.drawPixmap(QPoint(0, 0), pix, QRect(0, (pix.height() - _height * cIntRetinaFactor()) / 2, width * cIntRetinaFactor(), _height * cIntRetinaFactor()));
} else {
int32 usewidth = (width * pix.height()) / (_height * cIntRetinaFactor());
p.drawPixmap(QRect(0, 0, width, _height), pix, QRect((width - usewidth) * cIntRetinaFactor() / 2, 0, usewidth * cIntRetinaFactor(), pix.height()));
if (pixw < width || pixh < _height) {
p.fillRect(QRect(0, 0, width, _height), st::black->b);
}
p.drawPixmap(QPoint((width - pixw) / 2, (_height - pixh) / 2), pix);
if (!full) {
uint64 dt = itemAnimations().animate(parent, getms());
int32 cnt = int32(st::photoLoaderCnt), period = int32(st::photoLoaderPeriod), t = dt % period, delta = int32(st::photoLoaderDelta);
@@ -2330,6 +2323,9 @@ void HistoryPhoto::draw(QPainter &p, const HistoryItem *parent, bool selected, i
int32 dateH = _height - dateY - st::msgDateImgDelta;
p.fillRect(dateX, dateY, dateW, dateH, st::msgDateImgBg->b);
if (selected) {
p.fillRect(dateX, dateY, dateW, dateH, textstyleCurrent()->selectOverlay->b);
}
p.setFont(st::msgDateFont->f);
p.setPen(st::msgDateImgColor->p);
p.drawText(dateX + st::msgDateImgPadding.x(), dateY + st::msgDateImgPadding.y() + st::msgDateFont->ascent, time);
@@ -2662,7 +2658,7 @@ void HistoryAudio::draw(QPainter &p, const HistoryItem *parent, bool selected, i
}
p.drawPixmap(QPoint(st::mediaPadding.left(), st::mediaPadding.top()), App::sprite(), img);
if (selected) {
p.fillRect(st::mediaPadding.left(), st::mediaPadding.top(), st::mediaThumbSize, st::mediaThumbSize, (out ? st::msgOutSelectOverlay : st::msgInSelectOverlay)->b);
p.fillRect(st::mediaPadding.left(), st::mediaPadding.top(), st::mediaThumbSize, st::mediaThumbSize, textstyleCurrent()->selectOverlay->b);
}
int32 tleft = st::mediaPadding.left() + st::mediaThumbSize + st::mediaPadding.right();
@@ -2844,7 +2840,7 @@ void HistoryDocument::draw(QPainter &p, const HistoryItem *parent, bool selected
if (width >= animated.w) {
p.drawPixmap(0, 0, animated.frames[animated.frame]);
if (selected) {
p.fillRect(0, 0, animated.w, animated.h, (out ? st::msgOutSelectOverlay : st::msgInSelectOverlay)->b);
p.fillRect(0, 0, animated.w, animated.h, textstyleCurrent()->selectOverlay->b);
}
} else {
bool s = p.renderHints().testFlag(QPainter::SmoothPixmapTransform);
@@ -2854,7 +2850,7 @@ void HistoryDocument::draw(QPainter &p, const HistoryItem *parent, bool selected
p.drawPixmap(QRect(0, 0, width, h), animated.frames[animated.frame]);
if (!s) p.setRenderHint(QPainter::SmoothPixmapTransform, false);
if (selected) {
p.fillRect(0, 0, width, h, (out ? st::msgOutSelectOverlay : st::msgInSelectOverlay)->b);
p.fillRect(0, 0, width, h, textstyleCurrent()->selectOverlay->b);
}
}
return;
@@ -2898,7 +2894,7 @@ void HistoryDocument::draw(QPainter &p, const HistoryItem *parent, bool selected
p.drawPixmap(QPoint(st::mediaPadding.left(), st::mediaPadding.top()), App::sprite(), (out ? st::mediaDocOutImg : st::mediaDocInImg));
}
if (selected) {
p.fillRect(st::mediaPadding.left(), st::mediaPadding.top(), st::mediaThumbSize, st::mediaThumbSize, (out ? st::msgOutSelectOverlay : st::msgInSelectOverlay)->b);
p.fillRect(st::mediaPadding.left(), st::mediaPadding.top(), st::mediaThumbSize, st::mediaThumbSize, textstyleCurrent()->selectOverlay->b);
}
int32 tleft = st::mediaPadding.left() + st::mediaThumbSize + st::mediaPadding.right();
@@ -3058,22 +3054,38 @@ HistoryMedia *HistoryDocument::clone() const {
}
HistorySticker::HistorySticker(DocumentData *document, int32 width) : HistoryMedia(width)
, data(document)
, pixw(1), pixh(1), data(document)
{
data->thumb->load();
updateStickerEmoji();
}
bool HistorySticker::updateStickerEmoji() {
const EmojiStickersMap &stickers(cEmojiStickers());
EmojiStickersMap::const_iterator i = stickers.constFind(data);
QString emoji = (i == stickers.cend()) ? QString() : textEmojiString(i.value());
if (emoji != _emoji) {
_emoji = emoji;
return true;
}
return false;
}
void HistorySticker::initDimensions(const HistoryItem *parent) {
_maxw = data->dimensions.width();
_minh = data->dimensions.height();
if (_maxw > st::msgMinWidth) {
_minh = (st::msgMinWidth * _minh) / _maxw;
_maxw = st::msgMinWidth;
pixw = data->dimensions.width();
pixh = data->dimensions.height();
if (pixw > st::maxStickerSize) {
pixh = (st::maxStickerSize * pixh) / pixw;
pixw = st::maxStickerSize;
}
if (_minh > st::maxMediaSize) {
_maxw = (st::maxMediaSize * _maxw) / _minh;
_minh = st::maxMediaSize;
if (pixh > st::maxStickerSize) {
pixw = (st::maxStickerSize * pixw) / pixh;
pixh = st::maxStickerSize;
}
if (pixw < 1) pixw = 1;
if (pixh < 1) pixh = 1;
_maxw = qMax(pixw, int16(st::minPhotoSize));
_minh = qMax(pixh, int16(st::minPhotoSize));
_height = resize(w, true, parent);
}
@@ -3093,13 +3105,18 @@ void HistorySticker::draw(QPainter &p, const HistoryItem *parent, bool selected,
data->sticker = ImagePtr(data->data);
}
}
if (data->sticker->isNull()) {
p.drawPixmap(0, 0, data->thumb->pix(_maxw));
} else {
p.drawPixmap(0, 0, data->sticker->pix(_maxw));
}
if (selected) {
p.fillRect(0, 0, _maxw, _minh, (out ? st::msgOutSelectOverlay : st::msgInSelectOverlay)->b);
if (data->sticker->isNull()) {
p.drawPixmap(QPoint((_maxw - pixw) / 2, (_minh - pixh) / 2), data->thumb->pixBlurredColored(textstyleCurrent()->selectOverlay, pixw, pixh));
} else {
p.drawPixmap(QPoint((_maxw - pixw) / 2, (_minh - pixh) / 2), data->sticker->pixColored(textstyleCurrent()->selectOverlay, pixw, pixh));
}
} else {
if (data->sticker->isNull()) {
p.drawPixmap(QPoint((_maxw - pixw) / 2, (_minh - pixh) / 2), data->thumb->pixBlurred(pixw, pixh));
} else {
p.drawPixmap(QPoint((_maxw - pixw) / 2, (_minh - pixh) / 2), data->sticker->pix(pixw, pixh));
}
}
// date
@@ -3114,6 +3131,9 @@ void HistorySticker::draw(QPainter &p, const HistoryItem *parent, bool selected,
int32 dateH = _height - dateY - st::msgDateImgDelta;
p.fillRect(dateX, dateY, dateW, dateH, st::msgDateImgBg->b);
if (selected) {
p.fillRect(dateX, dateY, dateW, dateH, textstyleCurrent()->selectOverlay->b);
}
p.setFont(st::msgDateFont->f);
p.setPen(st::msgDateImgColor->p);
p.drawText(dateX + st::msgDateImgPadding.x(), dateY + st::msgDateImgPadding.y() + st::msgDateFont->ascent, time);
@@ -3155,11 +3175,11 @@ int32 HistorySticker::resize(int32 width, bool dontRecountText, const HistoryIte
}
const QString HistorySticker::inDialogsText() const {
return lang(lng_in_dlg_sticker);
return _emoji.isEmpty() ? lang(lng_in_dlg_sticker) : lng_in_dlg_sticker_emoji(lt_emoji, _emoji);
}
const QString HistorySticker::inHistoryText() const {
return qsl("[ ") + lang(lng_in_dlg_sticker) + qsl(" ]");
return qsl("[ ") + inDialogsText() + qsl(" ]");
}
bool HistorySticker::hasPoint(int32 x, int32 y, const HistoryItem *parent, int32 width) const {
@@ -3715,7 +3735,7 @@ int32 HistoryImageLink::fullWidth() const {
case GoogleMapsLink: return st::locationSize.width();
}
}
return st::minPhotoWidth;
return st::minPhotoSize;
}
int32 HistoryImageLink::fullHeight() const {
@@ -3727,22 +3747,22 @@ int32 HistoryImageLink::fullHeight() const {
case GoogleMapsLink: return st::locationSize.height();
}
}
return st::minPhotoHeight;
return st::minPhotoSize;
}
void HistoryImageLink::initDimensions(const HistoryItem *parent) {
int32 tw = convertScale(fullWidth()), th = convertScale(fullHeight());
int32 thumbw = qMax(tw, int32(st::minPhotoWidth)), maxthumbh = thumbw;
int32 thumbw = qMax(tw, int32(st::minPhotoSize)), maxthumbh = thumbw;
int32 thumbh = qRound(th * float64(thumbw) / tw);
if (thumbh > maxthumbh) {
thumbw = qRound(thumbw * float64(maxthumbh) / thumbh);
thumbh = maxthumbh;
if (thumbw < st::minPhotoWidth) {
thumbw = st::minPhotoWidth;
if (thumbw < st::minPhotoSize) {
thumbw = st::minPhotoSize;
}
}
if (thumbh < st::minPhotoHeight) {
thumbh = st::minPhotoHeight;
if (thumbh < st::minPhotoSize) {
thumbh = st::minPhotoSize;
}
if (!w) {
w = thumbw;
@@ -3812,6 +3832,9 @@ void HistoryImageLink::draw(QPainter &p, const HistoryItem *parent, bool selecte
int32 dateH = _height - dateY - st::msgDateImgDelta;
p.fillRect(dateX, dateY, dateW, dateH, st::msgDateImgBg->b);
if (selected) {
p.fillRect(dateX, dateY, dateW, dateH, textstyleCurrent()->selectOverlay->b);
}
p.setFont(st::msgDateFont->f);
p.setPen(st::msgDateImgColor->p);
p.drawText(dateX + st::msgDateImgPadding.x(), dateY + st::msgDateImgPadding.y() + st::msgDateFont->ascent, time);
@@ -3849,11 +3872,11 @@ int32 HistoryImageLink::resize(int32 width, bool dontRecountText, const HistoryI
w = (w * width) / _height;
_height = width;
}
if (w < st::minPhotoWidth) {
w = st::minPhotoWidth;
if (w < st::minPhotoSize) {
w = st::minPhotoSize;
}
if (_height < st::minPhotoHeight) {
_height = st::minPhotoHeight;
if (_height < st::minPhotoSize) {
_height = st::minPhotoSize;
}
return _height;
}
@@ -4000,7 +4023,7 @@ void HistoryMessage::initMedia(const MTPMessageMedia &media, QString &currentTex
}
void HistoryMessage::initMediaFromDocument(DocumentData *doc) {
if (doc->type == StickerDocument && doc->dimensions.width() > 0 && doc->dimensions.height() > 0 && doc->size < StickerInMemory) {
if (doc->type == StickerDocument && doc->dimensions.width() > 0 && doc->dimensions.height() > 0 && doc->dimensions.width() <= StickerMaxSize && doc->dimensions.height() <= StickerMaxSize && doc->size < StickerInMemory) {
_media = new HistorySticker(doc);
} else {
_media = new HistoryDocument(doc);
@@ -4318,6 +4341,15 @@ QString HistoryMessage::notificationText() const {
return msg;
}
void HistoryMessage::updateStickerEmoji() {
if (_media) {
if (_media->updateStickerEmoji()) {
_history->textCachedFor = 0;
if (App::wnd()) App::wnd()->update();
}
}
}
HistoryMessage::~HistoryMessage() {
if (_media) {
_media->unregItem(this);