not loaded thumbs are now white, always initDimensions() when media is updated

This commit is contained in:
John Preston 2016-01-09 15:11:23 +08:00
parent a39810a9c5
commit f66c54ee6b
6 changed files with 110 additions and 95 deletions

View File

@ -902,12 +902,12 @@ namespace App {
}
if (HistoryItem *existing = App::histItemById(peerToChannel(peerId), m.vid.v)) {
existing->setText(qs(m.vmessage), m.has_entities() ? entitiesFromMTP(m.ventities.c_vector().v) : EntitiesInText());
existing->updateMedia(m.has_media() ? (&m.vmedia) : 0);
existing->setViewsCount(m.has_views() ? m.vviews.v : -1, false);
existing->initDimensions();
Notify::historyItemResized(existing);
existing->updateMedia(m.has_media() ? (&m.vmedia) : 0, true);
existing->addToOverview(AddToOverviewNew);
existing->setViewsCount(m.has_views() ? m.vviews.v : -1);
if (!existing->detached()) {
App::checkSavedGif(existing);
@ -929,6 +929,8 @@ namespace App {
Local::writeSavedGifs();
if (App::main()) emit App::main()->savedGifsUpdated();
cSetLastSavedGifsUpdate(0);
App::main()->updateStickers();
}
}

View File

@ -311,21 +311,19 @@ void EmojiButton::paintEvent(QPaintEvent *e) {
p.drawPixmap(t, App::sprite(), i);
}
QRect inner(QPoint((width() - st::emojiCircle.width()) / 2, st::emojiCircleTop), st::emojiCircle);
int32 full = 5760;
int32 start = qRound(full * float64(ms % uint64(st::emojiCirclePeriod)) / st::emojiCirclePeriod), part = qRound(full / st::emojiCirclePart);
p.setBrush(Qt::NoBrush);
p.setRenderHint(QPainter::HighQualityAntialiasing);
p.setPen(QPen(st::emojiCircleFg->c, st::emojiCircleLine));
p.setOpacity(a_opacity.current() * _opacity);
p.drawEllipse(inner);
p.setPen(QPen(st::white->c, st::emojiCircleLine));
p.setOpacity(loading);
p.drawArc(inner, (full - start) % full, part);
p.setPen(QPen(st::emojiCircleFg, st::emojiCircleLine));
p.setBrush(Qt::NoBrush);
p.setRenderHint(QPainter::HighQualityAntialiasing);
QRect inner(QPoint((width() - st::emojiCircle.width()) / 2, st::emojiCircleTop), st::emojiCircle);
if (loading > 0) {
int32 full = 5760;
int32 start = qRound(full * float64(ms % uint64(st::emojiCirclePeriod)) / st::emojiCirclePeriod), part = qRound(loading * full / st::emojiCirclePart);
p.drawArc(inner, start, full - part);
} else {
p.drawEllipse(inner);
}
p.setRenderHint(QPainter::HighQualityAntialiasing, false);
}

View File

@ -365,7 +365,7 @@ yi += stride;
#undef update
}
delete[] rgb;
}
}
@ -444,7 +444,7 @@ QPixmap imagePix(QImage img, int32 w, int32 h, bool smooth, bool blurred, bool r
{
QPainter p(&result);
if (w < outerw || h < outerh) {
p.fillRect(0, 0, result.width(), result.height(), st::black->b);
p.fillRect(0, 0, result.width(), result.height(), st::black);
}
p.drawImage((result.width() - img.width()) / (2 * cIntRetinaFactor()), (result.height() - img.height()) / (2 * cIntRetinaFactor()), img);
}
@ -459,7 +459,12 @@ QPixmap imagePix(QImage img, int32 w, int32 h, bool smooth, bool blurred, bool r
QPixmap Image::pixNoCache(int32 w, int32 h, bool smooth, bool blurred, bool rounded, int32 outerw, int32 outerh) const {
if (!loading()) const_cast<Image*>(this)->load();
restore();
if (_data.isNull()) return blank()->pix();
if (_data.isNull()) {
if (h <= 0 && height() > 0) {
h = qRound(width() * w / float64(height()));
}
return blank()->pixNoCache(w, h, smooth, blurred, rounded, outerw, outerh);
}
if (isNull() && outerw > 0 && outerh > 0) {
outerw *= cIntRetinaFactor();
@ -470,7 +475,15 @@ QPixmap Image::pixNoCache(int32 w, int32 h, bool smooth, bool blurred, bool roun
{
QPainter p(&result);
p.fillRect(0, 0, result.width(), result.height(), st::black);
if (w < outerw) {
p.fillRect(0, 0, (outerw - w) / 2, result.height(), st::black);
p.fillRect(((outerw - w) / 2) + w, 0, result.width() - (((outerw - w) / 2) + w), result.height(), st::black);
}
if (h < outerh) {
p.fillRect(qMax(0, (outerw - w) / 2), 0, qMin(result.width(), w), (outerh - h) / 2, st::black);
p.fillRect(qMax(0, (outerw - w) / 2), ((outerh - h) / 2) + h, qMin(result.width(), w), result.height() - (((outerh - h) / 2) + h), st::black);
}
p.fillRect(qMax(0, (outerw - w) / 2), qMax(0, (outerh - h) / 2), qMin(result.width(), w), qMin(result.height(), h), st::white);
}
if (rounded) imageRound(result);

View File

@ -1318,7 +1318,11 @@ HistoryItem *History::createItem(HistoryBlock *block, const MTPMessage &msg, boo
result->attach(block);
}
if (msg.type() == mtpc_message) {
result->updateMedia(msg.c_message().has_media() ? (&msg.c_message().vmedia) : 0, (block ? false : true));
result->updateMedia(msg.c_message().has_media() ? (&msg.c_message().vmedia) : 0);
result->initDimensions();
if (!block) {
Notify::historyItemResized(result);
}
if (applyServiceAction) {
App::checkSavedGif(result);
}
@ -3430,7 +3434,7 @@ void HistoryPhoto::getState(TextLinkPtr &lnk, HistoryCursorState &state, int32 x
}
}
void HistoryPhoto::updateFrom(const MTPMessageMedia &media, HistoryItem *parent, bool allowEmitResize) {
void HistoryPhoto::updateFrom(const MTPMessageMedia &media, HistoryItem *parent) {
if (media.type() == mtpc_messageMediaPhoto) {
const MTPPhoto &photo(media.c_messageMediaPhoto().vphoto);
App::feedPhoto(photo, _data);
@ -3628,9 +3632,7 @@ void HistoryVideo::draw(Painter &p, const HistoryItem *parent, const QRect &r, b
}
QRect rthumb(rtlrect(skipx, skipy, width, height, _width));
QPixmap pix = _data->thumb->pixBlurredSingle(_thumbw, 0, width, height);
p.drawPixmap(rthumb.topLeft(), pix);
p.drawPixmap(rthumb.topLeft(), _data->thumb->pixBlurredSingle(_thumbw, 0, width, height));
if (selected) {
App::roundRect(p, rthumb, textstyleCurrent()->selectOverlay, SelectedOverlayCorners);
}
@ -3929,7 +3931,7 @@ void HistoryAudio::unregItem(HistoryItem *item) {
App::unregAudioItem(_data, item);
}
void HistoryAudio::updateFrom(const MTPMessageMedia &media, HistoryItem *parent, bool allowEmitResize) {
void HistoryAudio::updateFrom(const MTPMessageMedia &media, HistoryItem *parent) {
if (media.type() == mtpc_messageMediaAudio) {
App::feedAudio(media.c_messageMediaAudio().vaudio, _data);
if (!_data->data().isEmpty()) {
@ -3990,18 +3992,6 @@ HistoryDocument::HistoryDocument(DocumentData *document, const QString &caption,
if (!caption.isEmpty()) {
_caption.setText(st::msgFont, caption + parent->skipBlock(), itemTextNoMonoOptions(parent));
}
if (withThumb()) {
_data->thumb->load();
int32 tw = _data->thumb->width(), th = _data->thumb->height();
if (tw > th) {
_thumbw = (tw * st::msgFileThumbSize) / th;
} else {
_thumbw = st::msgFileThumbSize;
}
} else {
_thumbw = 0;
}
}
HistoryDocument::HistoryDocument(const HistoryDocument &other) : HistoryFileMedia()
@ -4021,6 +4011,18 @@ void HistoryDocument::initDimensions(const HistoryItem *parent) {
_caption.setSkipBlock(parent->skipBlockWidth(), parent->skipBlockHeight());
}
if (withThumb()) {
_data->thumb->load();
int32 tw = _data->thumb->width(), th = _data->thumb->height();
if (tw > th) {
_thumbw = (tw * st::msgFileThumbSize) / th;
} else {
_thumbw = st::msgFileThumbSize;
}
} else {
_thumbw = 0;
}
_maxw = st::msgFileMinWidth;
int32 tleft = 0, tright = 0;
@ -4098,12 +4100,8 @@ void HistoryDocument::draw(Painter &p, const HistoryItem *parent, const QRect &r
bottom = st::msgFileThumbPadding.top() + st::msgFileThumbSize + st::msgFileThumbPadding.bottom();
QRect rthumb(rtlrect(st::msgFileThumbPadding.left(), st::msgFileThumbPadding.top(), st::msgFileThumbSize, st::msgFileThumbSize, _width));
if (_data->thumb->loaded()) {
QPixmap thumb = loaded ? _data->thumb->pixSingle(_thumbw, 0, st::msgFileThumbSize, st::msgFileThumbSize) : _data->thumb->pixBlurredSingle(_thumbw, 0, st::msgFileThumbSize, st::msgFileThumbSize);
p.drawPixmap(rthumb.topLeft(), thumb);
} else {
App::roundRect(p, rthumb, st::black, BlackCorners);
}
QPixmap thumb = loaded ? _data->thumb->pixSingle(_thumbw, 0, st::msgFileThumbSize, st::msgFileThumbSize) : _data->thumb->pixBlurredSingle(_thumbw, 0, st::msgFileThumbSize, st::msgFileThumbSize);
p.drawPixmap(rthumb.topLeft(), thumb);
if (selected) {
App::roundRect(p, rthumb, textstyleCurrent()->selectOverlay, SelectedOverlayCorners);
}
@ -4348,7 +4346,7 @@ void HistoryDocument::unregItem(HistoryItem *item) {
App::unregDocumentItem(_data, item);
}
void HistoryDocument::updateFrom(const MTPMessageMedia &media, HistoryItem *parent, bool allowEmitResize) {
void HistoryDocument::updateFrom(const MTPMessageMedia &media, HistoryItem *parent) {
if (media.type() == mtpc_messageMediaDocument) {
App::feedDocument(media.c_messageMediaDocument().vdocument, _data);
}
@ -4689,7 +4687,7 @@ void HistoryGif::unregItem(HistoryItem *item) {
App::unregDocumentItem(_data, item);
}
void HistoryGif::updateFrom(const MTPMessageMedia &media, HistoryItem *parent, bool allowEmitResize) {
void HistoryGif::updateFrom(const MTPMessageMedia &media, HistoryItem *parent) {
if (media.type() == mtpc_messageMediaDocument) {
App::feedDocument(media.c_messageMediaDocument().vdocument, _data);
}
@ -4884,7 +4882,7 @@ void HistorySticker::unregItem(HistoryItem *item) {
App::unregDocumentItem(_data, item);
}
void HistorySticker::updateFrom(const MTPMessageMedia &media, HistoryItem *parent, bool allowEmitResize) {
void HistorySticker::updateFrom(const MTPMessageMedia &media, HistoryItem *parent) {
if (media.type() == mtpc_messageMediaDocument) {
App::feedDocument(media.c_messageMediaDocument().vdocument, _data);
if (!_data->data().isEmpty()) {
@ -5057,14 +5055,12 @@ void HistoryContact::unregItem(HistoryItem *item) {
}
}
void HistoryContact::updateFrom(const MTPMessageMedia &media, HistoryItem *parent, bool allowEmitResize) {
void HistoryContact::updateFrom(const MTPMessageMedia &media, HistoryItem *parent) {
if (media.type() == mtpc_messageMediaContact) {
if (_userId != media.c_messageMediaContact().vuser_id.v) {
unregItem(parent);
_userId = media.c_messageMediaContact().vuser_id.v;
regItem(parent);
parent->initDimensions();
if (allowEmitResize) Notify::historyItemResized(parent);
}
}
}
@ -5887,7 +5883,7 @@ void HistoryImageLink::draw(Painter &p, const HistoryItem *parent, const QRect &
}
p.drawPixmap(QPoint(skipx, skipy), pix);
} else {
App::roundRect(p, skipx, skipy, width, height, st::black, BlackCorners);
App::roundRect(p, skipx, skipy, width, height, st::white, MessageInCorners);
}
if (selected) {
App::roundRect(p, skipx, skipy, width, height, textstyleCurrent()->selectOverlay, SelectedOverlayCorners);
@ -6194,9 +6190,17 @@ void HistoryMessage::initDimensions() {
if (maxw > _maxw) _maxw = maxw;
_minh += _media->minHeight();
}
if (!_media && !displayFromName() && via() && !toHistoryForwarded()) {
if (st::msgPadding.left() + via()->maxWidth + st::msgPadding.right() > _maxw) {
_maxw = st::msgPadding.left() + via()->maxWidth + st::msgPadding.right();
if (!_media) {
if (displayFromName()) {
int32 namew = st::msgPadding.left() + _from->nameText.maxWidth() + st::msgPadding.right();
if (via() && !toHistoryForwarded()) {
namew += st::msgServiceFont->spacew + via()->maxWidth;
}
if (namew > _maxw) _maxw = namew;
} else if (via() && !toHistoryForwarded()) {
if (st::msgPadding.left() + via()->maxWidth + st::msgPadding.right() > _maxw) {
_maxw = st::msgPadding.left() + via()->maxWidth + st::msgPadding.right();
}
}
}
} else {
@ -6204,7 +6208,6 @@ void HistoryMessage::initDimensions() {
_maxw = _media->maxWidth();
_minh = _media->minHeight();
}
fromNameUpdated();
}
void HistoryMessage::countPositionAndSize(int32 &left, int32 &width) const {
@ -6227,13 +6230,12 @@ void HistoryMessage::countPositionAndSize(int32 &left, int32 &width) const {
}
}
void HistoryMessage::fromNameUpdated() const {
if (!_media && displayFromName()) {
int32 namew = st::msgPadding.left() + _from->nameText.maxWidth() + st::msgPadding.right();
void HistoryMessage::fromNameUpdated(int32 width) const {
_fromVersion = _from->nameVersion;
if (drawBubble() && displayFromName()) {
if (via() && !toHistoryForwarded()) {
namew += st::msgServiceFont->spacew + via()->maxWidth;
via()->resize(width - st::msgPadding.left() - st::msgPadding.right() - _from->nameText.maxWidth() - st::msgServiceFont->spacew);
}
if (namew > _maxw) _maxw = namew;
}
}
@ -6287,7 +6289,7 @@ HistoryMedia *HistoryMessage::getMedia(bool inOverview) const {
return _media;
}
void HistoryMessage::setMedia(const MTPMessageMedia *media, bool allowEmitResize) {
void HistoryMessage::setMedia(const MTPMessageMedia *media) {
if ((!_media || _media->isImageLink()) && (!media || media->type() == mtpc_messageMediaEmpty)) return;
bool mediaWasDisplayed = false;
@ -6307,8 +6309,6 @@ void HistoryMessage::setMedia(const MTPMessageMedia *media, bool allowEmitResize
_textWidth = 0;
_textHeight = 0;
}
initDimensions();
if (allowEmitResize) Notify::historyItemResized(this);
}
void HistoryMessage::setText(const QString &text, const EntitiesInText &entities) {
@ -6413,7 +6413,7 @@ void HistoryMessage::drawInfo(Painter &p, int32 right, int32 bottom, int32 width
}
}
void HistoryMessage::setViewsCount(int32 count) {
void HistoryMessage::setViewsCount(int32 count, bool reinit) {
if (_views == count || (count >= 0 && _views > count)) return;
int32 was = _viewsWidth;
@ -6428,8 +6428,10 @@ void HistoryMessage::setViewsCount(int32 count) {
_textWidth = 0;
_textHeight = 0;
}
initDimensions();
Notify::historyItemResized(this);
if (reinit) {
initDimensions();
Notify::historyItemResized(this);
}
}
}
@ -6468,13 +6470,12 @@ void HistoryMessage::draw(Painter &p, const QRect &r, uint32 selection, uint64 m
}
}
if (_from->nameVersion > _fromVersion) {
// fromNameUpdated();
_fromVersion = _from->nameVersion;
}
int32 left = 0, width = 0;
countPositionAndSize(left, width);
if (_from->nameVersion > _fromVersion) {
fromNameUpdated(width);
}
if (displayFromPhoto()) {
p.drawPixmap(left - st::msgPhotoSkip, _height - st::msgMargin.bottom() - st::msgPhotoSize, _from->photo->pixRounded(st::msgPhotoSize));
}
@ -6579,17 +6580,19 @@ int32 HistoryMessage::resize(int32 width) {
}
if (media) _height += _media->resize(width, this);
}
int32 l = 0, w = 0;
countPositionAndSize(l, w);
if (displayFromName()) {
if (emptyText()) {
_height += st::msgPadding.top() + st::msgNameFont->height + st::mediaHeaderSkip;
} else {
_height += st::msgNameFont->height;
}
if (via() && !toHistoryForwarded()) {
via()->resize(width - st::msgPadding.left() - st::msgPadding.right() - _from->nameText.maxWidth() - st::msgServiceFont->spacew);
}
fromNameUpdated(w);
} else if (via() && !toHistoryForwarded()) {
via()->resize(width - st::msgPadding.left() - st::msgPadding.right());
via()->resize(w - st::msgPadding.left() - st::msgPadding.right());
if (emptyText() && !displayFromName()) {
_height += st::msgPadding.top() + st::msgNameFont->height + st::mediaHeaderSkip;
} else {

View File

@ -897,7 +897,7 @@ public:
virtual bool serviceMsg() const {
return false;
}
virtual void updateMedia(const MTPMessageMedia *media, bool allowEmitResize) {
virtual void updateMedia(const MTPMessageMedia *media) {
}
virtual int32 addToOverview(AddToOverviewMethod method) {
return 0;
@ -918,7 +918,7 @@ public:
virtual void drawInfo(Painter &p, int32 right, int32 bottom, int32 width, bool selected, InfoDisplayType type) const {
}
virtual void setViewsCount(int32 count) {
virtual void setViewsCount(int32 count, bool reinit = true) {
}
virtual void setId(MsgId newId);
virtual void setDate(const QDateTime &date) { // for date items
@ -1161,7 +1161,7 @@ public:
virtual void unregItem(HistoryItem *item) {
}
virtual void updateFrom(const MTPMessageMedia &media, HistoryItem *parent, bool allowEmitResize) {
virtual void updateFrom(const MTPMessageMedia &media, HistoryItem *parent) {
}
virtual bool isImageLink() const {
@ -1309,7 +1309,7 @@ public:
return _data;
}
void updateFrom(const MTPMessageMedia &media, HistoryItem *parent, bool allowEmitResize);
void updateFrom(const MTPMessageMedia &media, HistoryItem *parent);
void regItem(HistoryItem *item);
void unregItem(HistoryItem *item);
@ -1451,7 +1451,7 @@ public:
void regItem(HistoryItem *item);
void unregItem(HistoryItem *item);
void updateFrom(const MTPMessageMedia &media, HistoryItem *parent, bool allowEmitResize);
void updateFrom(const MTPMessageMedia &media, HistoryItem *parent);
bool needsBubble(const HistoryItem *parent) const {
return true;
@ -1519,7 +1519,7 @@ public:
void regItem(HistoryItem *item);
void unregItem(HistoryItem *item);
void updateFrom(const MTPMessageMedia &media, HistoryItem *parent, bool allowEmitResize);
void updateFrom(const MTPMessageMedia &media, HistoryItem *parent);
bool hasReplyPreview() const {
return !_data->thumb->isNull();
@ -1611,7 +1611,7 @@ public:
void regItem(HistoryItem *item);
void unregItem(HistoryItem *item);
void updateFrom(const MTPMessageMedia &media, HistoryItem *parent, bool allowEmitResize);
void updateFrom(const MTPMessageMedia &media, HistoryItem *parent);
bool hasReplyPreview() const {
return !_data->thumb->isNull();
@ -1686,7 +1686,7 @@ public:
void regItem(HistoryItem *item);
void unregItem(HistoryItem *item);
void updateFrom(const MTPMessageMedia &media, HistoryItem *parent, bool allowEmitResize);
void updateFrom(const MTPMessageMedia &media, HistoryItem *parent);
bool needsBubble(const HistoryItem *parent) const {
return false;
@ -1745,7 +1745,7 @@ public:
void regItem(HistoryItem *item);
void unregItem(HistoryItem *item);
void updateFrom(const MTPMessageMedia &media, HistoryItem *parent, bool allowEmitResize);
void updateFrom(const MTPMessageMedia &media, HistoryItem *parent);
bool needsBubble(const HistoryItem *parent) const {
return true;
@ -1988,7 +1988,7 @@ public:
void initMedia(const MTPMessageMedia *media, QString &currentText);
void initMediaFromDocument(DocumentData *doc, const QString &caption);
void initDimensions();
void fromNameUpdated() const;
void fromNameUpdated(int32 width) const;
virtual HistoryMessageVia *via() const {
return (_via && !_via->isNull()) ? _via : 0;
@ -2017,7 +2017,7 @@ public:
}
void drawInfo(Painter &p, int32 right, int32 bottom, int32 width, bool selected, InfoDisplayType type) const;
void setViewsCount(int32 count);
void setViewsCount(int32 count, bool reinit = true);
void setId(MsgId newId);
void draw(Painter &p, const QRect &r, uint32 selection, uint64 ms) const;
@ -2047,11 +2047,11 @@ public:
QString notificationHeader() const;
QString notificationText() const;
void updateMedia(const MTPMessageMedia *media, bool allowEmitResize) {
void updateMedia(const MTPMessageMedia *media) {
if (media && _media && _media->type() != MediaTypeWebPage) {
_media->updateFrom(*media, this, allowEmitResize);
_media->updateFrom(*media, this);
} else {
setMedia(media, allowEmitResize);
setMedia(media);
}
}
int32 addToOverview(AddToOverviewMethod method);
@ -2060,7 +2060,7 @@ public:
QString selectedText(uint32 selection) const;
QString inDialogsText() const;
HistoryMedia *getMedia(bool inOverview = false) const;
void setMedia(const MTPMessageMedia *media, bool allowEmitResize);
void setMedia(const MTPMessageMedia *media);
void setText(const QString &text, const EntitiesInText &entities);
QString originalText() const;
EntitiesInText originalEntities() const;

View File

@ -4128,12 +4128,11 @@ void MainWidget::feedUpdates(const MTPUpdates &updates, uint64 randomId) {
feedUpdate(MTP_updateMessageID(d.vid, MTP_long(randomId))); // ignore real date
if (peerId) {
if (HistoryItem *item = App::histItemById(peerToChannel(peerId), d.vid.v)) {
if (!text.isEmpty()) {
item->setText(text, d.has_entities() ? entitiesFromMTP(d.ventities.c_vector().v) : EntitiesInText());
item->initDimensions();
Notify::historyItemResized(item);
}
item->updateMedia(d.has_media() ? (&d.vmedia) : 0, true);
item->setText(text, d.has_entities() ? entitiesFromMTP(d.ventities.c_vector().v) : EntitiesInText());
item->updateMedia(d.has_media() ? (&d.vmedia) : 0);
item->initDimensions();
Notify::historyItemResized(item);
item->addToOverview(AddToOverviewNew);
}
}