2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

fixed Qt 5.5 image scale crash, fixed empty photo in mediaview crash

This commit is contained in:
John Preston
2015-07-15 14:23:59 +03:00
parent d5afafcdd0
commit e193a86eaa
6 changed files with 895 additions and 53 deletions

View File

@@ -225,8 +225,6 @@ void MediaView::updateDocSize() {
}
void MediaView::updateControls() {
if (!_photo && !_doc) return;
if (_doc && _current.isNull() && _currentGif.isNull()) {
if (_doc->loader) {
_docDownload.hide();
@@ -257,13 +255,20 @@ void MediaView::updateControls() {
_docCancel.hide();
}
_saveVisible = ((_photo && _photo->full->loaded()) || (_doc && (!_doc->already(true).isEmpty() || (_current.isNull() && _currentGif.isNull()))));
_saveVisible = ((_photo && _photo->full->loaded()) || (_doc && (!_doc->already(true).isEmpty() || (_current.isNull() && _currentGif.isNull() && (_photo || _doc)))));
_saveNav = myrtlrect(width() - st::mvIconSize.width() * 2, height() - st::mvIconSize.height(), st::mvIconSize.width(), st::mvIconSize.height());
_saveNavIcon = centersprite(_saveNav, st::mvSave);
_moreNav = myrtlrect(width() - st::mvIconSize.width(), height() - st::mvIconSize.height(), st::mvIconSize.width(), st::mvIconSize.height());
_moreNavIcon = centersprite(_moreNav, st::mvMore);
QDateTime d(date(_photo ? _photo->date : _doc->date)), dNow(date(unixtime()));
QDateTime d, dNow(date(unixtime()));
if (_photo) {
d = date(_photo->date);
} else if (_doc) {
d = date(_doc->date);
} else if (HistoryItem *item = App::histItemById(_msgid)) {
d = item->date;
}
if (d.date() == dNow.date()) {
_dateText = lng_mediaview_today(lt_time, d.time().toString(cTimeFormat()));
} else if (d.date().addDays(1) == dNow.date()) {
@@ -280,12 +285,12 @@ void MediaView::updateControls() {
_dateNav = myrtlrect(st::mvTextLeft, height() - st::mvTextTop, st::mvFont->m.width(_dateText), st::mvFont->height);
}
updateHeader();
if (_photo) {
if (_photo || (_history && _overview == OverviewPhotos)) {
_leftNavVisible = (_index > 0) || (_index == 0 && _history && _history->_overview[_overview].size() < _history->_overviewCount[_overview]);
_rightNavVisible = (_index >= 0) && (
(_history && _index + 1 < _history->_overview[_overview].size()) ||
(_user && (_index + 1 < _user->photos.size() || _index + 1 < _user->photosCount)));
} else if (_doc) {
} else if (_history && _overview == OverviewDocuments) {
_leftNavVisible = (_index > 0) || (_index == 0 && _history && _history->_overview[_overview].size() < _history->_overviewCount[_overview]);
_rightNavVisible = (_index >= 0) && _history && (_index + 1 < _history->_overview[_overview].size());
} else {
@@ -792,24 +797,30 @@ void MediaView::displayPhoto(PhotoData *photo, HistoryItem *item) {
}
}
void MediaView::displayDocument(DocumentData *doc, HistoryItem *item) {
void MediaView::displayDocument(DocumentData *doc, HistoryItem *item) { // empty messages shown as docs: doc can be NULL
_doc = doc;
_photo = 0;
_caption = Text();
QString already = _doc->already(true);
if (_doc->sticker() && !_doc->sticker()->img->isNull() && _doc->sticker()->img->loaded()) {
_currentGif.stop();
_current = _doc->sticker()->img->pix();
} else if (!already.isEmpty()) {
QImageReader reader(already);
if (reader.canRead()) {
if (reader.supportsAnimation() && reader.imageCount() > 1) {
_currentGif.start(0, already);
_current = QPixmap();
if (_doc) {
QString already = _doc->already(true);
if (_doc->sticker() && !_doc->sticker()->img->isNull() && _doc->sticker()->img->loaded()) {
_currentGif.stop();
_current = _doc->sticker()->img->pix();
} else if (!already.isEmpty()) {
QImageReader reader(already);
if (reader.canRead()) {
if (reader.supportsAnimation() && reader.imageCount() > 1) {
_currentGif.start(0, already);
_current = QPixmap();
} else {
_currentGif.stop();
QPixmap pix = QPixmap::fromImage(App::readImage(already, 0, false), Qt::ColorOnly);
_current = pix;
}
} else {
_currentGif.stop();
QPixmap pix = QPixmap::fromImage(App::readImage(already, 0, false), Qt::ColorOnly);
_current = pix;
_current = QPixmap();
}
} else {
_currentGif.stop();
@@ -821,10 +832,10 @@ void MediaView::displayDocument(DocumentData *doc, HistoryItem *item) {
}
if (_current.isNull() && _currentGif.isNull()) {
if (_doc->thumb->isNull()) {
if (!_doc || _doc->thumb->isNull()) {
style::sprite thumbs[] = { st::mvDocBlue, st::mvDocGreen, st::mvDocRed, st::mvDocYellow };
style::color colors[] = { st::mvDocBlueColor, st::mvDocGreenColor, st::mvDocRedColor, st::mvDocYellowColor };
QString name = _doc->name.toLower(), mime = _doc->mime.toLower();
QString name = _doc ? _doc->name.toLower() : QString(), mime = _doc ? _doc->mime.toLower() : QString();
if (name.endsWith(qstr(".doc")) ||
name.endsWith(qstr(".txt")) ||
name.endsWith(qstr(".psd")) ||
@@ -879,9 +890,9 @@ void MediaView::displayDocument(DocumentData *doc, HistoryItem *item) {
int32 maxw = st::mvDocSize.width() - st::mvDocBlue.pxWidth() - st::mvDocPadding * 3;
_docName = _doc->name.isEmpty() ? lang(_doc->type == StickerDocument ? lng_in_dlg_sticker : lng_mediaview_doc_image) : _doc->name;
_docName = (!_doc || _doc->name.isEmpty()) ? lang(_doc ? (_doc->type == StickerDocument ? lng_in_dlg_sticker : lng_mediaview_doc_image) : lng_message_empty) : _doc->name;
int32 lastDot = _docName.lastIndexOf('.');
_docExt = (lastDot < 0 || lastDot + 2 > _docName.size()) ? _docName : _docName.mid(lastDot + 1);
_docExt = _doc ? ((lastDot < 0 || lastDot + 2 > _docName.size()) ? _docName : _docName.mid(lastDot + 1)) : QString();
_docNameWidth = st::mvDocNameFont->m.width(_docName);
if (_docNameWidth > maxw) {
_docName = st::mvDocNameFont->m.elidedText(_docName, Qt::ElideMiddle, maxw);
@@ -898,7 +909,7 @@ void MediaView::displayDocument(DocumentData *doc, HistoryItem *item) {
_docRadialFirst = _docRadialLast = _docRadialStart = 0;
float64 prg = _doc->loader ? _doc->loader->currentProgress() : 0;
float64 prg = (_doc && _doc->loader) ? _doc->loader->currentProgress() : 0;
a_docRadial = anim::fvalue(prg, qMax(prg, 0.0001));
// _docSize is updated in updateControls()
@@ -1073,17 +1084,19 @@ void MediaView::paintEvent(QPaintEvent *e) {
}
}
}
} else if (_doc) {
} else {
if (_docRect.intersects(r)) {
p.fillRect(_docRect, st::mvDocBg->b);
if (_docIconRect.intersects(r)) {
icon = true;
if (_doc->thumb->isNull()) {
if (!_doc->already().isEmpty() && (!_docRadialStart || _docRadialOpacity < 1)) {
if (!_doc || _doc->thumb->isNull()) {
if ((!_doc || !_doc->already().isEmpty()) && (!_docRadialStart || _docRadialOpacity < 1)) {
p.drawPixmap(_docIconRect.topLeft(), App::sprite(), _docIcon);
p.setPen(st::mvDocExtColor->p);
p.setFont(st::mvDocExtFont->f);
p.drawText(_docIconRect.x() + (_docIconRect.width() - _docExtWidth) / 2, _docIconRect.y() + st::mvDocExtTop + st::mvDocExtFont->ascent, _docExt);
if (!_docExt.isEmpty()) {
p.drawText(_docIconRect.x() + (_docIconRect.width() - _docExtWidth) / 2, _docIconRect.y() + st::mvDocExtTop + st::mvDocExtFont->ascent, _docExt);
}
} else {
p.fillRect(_docIconRect, _docIconColor->b);
}
@@ -1093,7 +1106,7 @@ void MediaView::paintEvent(QPaintEvent *e) {
}
float64 o = overLevel(OverIcon);
if (_docRadialStart > 0) {
if (_doc && _docRadialStart > 0) {
if (_doc->already().isEmpty() && _docRadialOpacity < 1) {
p.setOpacity((o * 1. + (1 - o) * st::radialDownloadOpacity) * (1 - _docRadialOpacity));
p.drawSpriteCenter(_docIconRect, st::radialDownload);
@@ -1120,7 +1133,7 @@ void MediaView::paintEvent(QPaintEvent *e) {
p.setOpacity(1);
p.setRenderHint(QPainter::HighQualityAntialiasing, false);
} else if (_doc->already().isEmpty()) {
} else if (_doc && _doc->already().isEmpty()) {
p.setOpacity((o * 1. + (1 - o) * st::radialDownloadOpacity));
p.drawSpriteCenter(_docIconRect, st::radialDownload);
}
@@ -1190,7 +1203,7 @@ void MediaView::paintEvent(QPaintEvent *e) {
}
// save button
if (_saveNavIcon.intersects(r)) {
if (_saveVisible && _saveNavIcon.intersects(r)) {
float64 o = overLevel(OverSave);
p.setOpacity((o * st::mvIconOverOpacity + (1 - o) * st::mvIconOpacity) * co);
p.drawPixmap(_saveNavIcon.topLeft(), App::sprite(), st::mvSave);
@@ -1364,7 +1377,7 @@ void MediaView::keyPressEvent(QKeyEvent *e) {
}
void MediaView::moveToNext(int32 delta) {
if (_index < 0 || (!_photo && !_doc) || (_overview == OverviewCount && !_user)) return;
if (_index < 0 || (_history && _overview != OverviewPhotos && _overview != OverviewDocuments) || (_overview == OverviewCount && !_user)) return;
int32 newIndex = _index + delta;
if (_history && _overview != OverviewCount) {
@@ -1372,10 +1385,15 @@ void MediaView::moveToNext(int32 delta) {
_index = newIndex;
if (HistoryItem *item = App::histItemById(_history->_overview[_overview][_index])) {
_msgid = item->id;
switch (item->getMedia()->type()) {
case MediaTypePhoto: displayPhoto(static_cast<HistoryPhoto*>(item->getMedia())->photo(), item); preloadData(delta); break;
case MediaTypeDocument: displayDocument(static_cast<HistoryDocument*>(item->getMedia())->document(), item); preloadData(delta); break;
case MediaTypeSticker: displayDocument(static_cast<HistorySticker*>(item->getMedia())->document(), item); preloadData(delta); break;
if (item->getMedia()) {
switch (item->getMedia()->type()) {
case MediaTypePhoto: displayPhoto(static_cast<HistoryPhoto*>(item->getMedia())->photo(), item); preloadData(delta); break;
case MediaTypeDocument: displayDocument(static_cast<HistoryDocument*>(item->getMedia())->document(), item); preloadData(delta); break;
case MediaTypeSticker: displayDocument(static_cast<HistorySticker*>(item->getMedia())->document(), item); preloadData(delta); break;
}
} else {
displayDocument(0, item);
preloadData(delta);
}
}
}