From 41f5a87c803ce87b580d5010edd26f27395524b4 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 23 Dec 2015 15:19:32 +0300 Subject: [PATCH] improved video, audio overview, fixed files overview --- Telegram/Resources/style.txt | 9 ++++ Telegram/SourceFiles/history.cpp | 71 +++++++++++++------------ Telegram/SourceFiles/history.h | 8 +-- Telegram/SourceFiles/historywidget.cpp | 19 ++++--- Telegram/SourceFiles/layout.cpp | 43 +++++++++------ Telegram/SourceFiles/mainwidget.cpp | 6 ++- Telegram/SourceFiles/mediaview.cpp | 20 +++---- Telegram/SourceFiles/overviewwidget.cpp | 4 +- 8 files changed, 104 insertions(+), 76 deletions(-) diff --git a/Telegram/Resources/style.txt b/Telegram/Resources/style.txt index ceb7d273fc..7e31296ddb 100644 --- a/Telegram/Resources/style.txt +++ b/Telegram/Resources/style.txt @@ -1184,6 +1184,15 @@ mediaUnreadSize: 7px; mediaUnreadSkip: 5px; mediaUnreadTop: 6px; +mediaInStyle: textStyle(defaultTextStyle) { + linkFg: mediaInFg; + linkFgDown: mediaInFg; +} +mediaInStyleSelected: textStyle(defaultTextStyle) { + linkFg: mediaInFgSelected; + linkFgDown: mediaInFgSelected; +} + msgFileRedColor: #e47272; msgFileYellowColor: #efc274; msgFileGreenColor: #61b96e; diff --git a/Telegram/SourceFiles/history.cpp b/Telegram/SourceFiles/history.cpp index 54c9cd4734..f298431bbe 100644 --- a/Telegram/SourceFiles/history.cpp +++ b/Telegram/SourceFiles/history.cpp @@ -1325,6 +1325,7 @@ HistoryItem *History::createItem(HistoryBlock *block, const MTPMessage &msg, boo case mtpc_message: msgId = msg.c_message().vid.v; break; case mtpc_messageService: msgId = msg.c_messageService().vid.v; break; } + if (!msgId) return 0; HistoryItem *existing = App::histItemById(channelId(), msgId); if (existing) { @@ -4613,12 +4614,12 @@ HistoryGif::~HistoryGif() { } HistorySticker::HistorySticker(DocumentData *document) : HistoryMedia() -, pixw(1) -, pixh(1) -, data(document) { - data->thumb->load(); - if (!data->sticker()->alt.isEmpty()) { - _emoji = data->sticker()->alt; +, _pixw(1) +, _pixh(1) +, _data(document) { + _data->thumb->load(); + if (!_data->sticker()->alt.isEmpty()) { + _emoji = _data->sticker()->alt; int32 elen = 0; if (EmojiPtr e = emojiFromText(_emoji.constData(), _emoji.constEnd(), elen)) { _emoji = emojiString(e); @@ -4627,20 +4628,20 @@ HistorySticker::HistorySticker(DocumentData *document) : HistoryMedia() } void HistorySticker::initDimensions(const HistoryItem *parent) { - pixw = data->dimensions.width(); - pixh = data->dimensions.height(); - if (pixw > st::maxStickerSize) { - pixh = (st::maxStickerSize * pixh) / pixw; - pixw = st::maxStickerSize; + _pixw = _data->dimensions.width(); + _pixh = _data->dimensions.height(); + if (_pixw > st::maxStickerSize) { + _pixh = (st::maxStickerSize * _pixh) / _pixw; + _pixw = st::maxStickerSize; } - if (pixh > st::maxStickerSize) { - pixw = (st::maxStickerSize * pixw) / pixh; - pixh = st::maxStickerSize; + 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)); + if (_pixw < 1) _pixw = 1; + if (_pixh < 1) _pixh = 1; + _maxw = qMax(_pixw, int16(st::minPhotoSize)); + _minh = qMax(_pixh, int16(st::minPhotoSize)); if (const HistoryReply *reply = toHistoryReply(parent)) { _maxw += st::msgReplyPadding.left() + reply->replyToWidth(); } @@ -4651,7 +4652,7 @@ void HistorySticker::draw(Painter &p, const HistoryItem *parent, const QRect &r, if (_width < st::msgPadding.left() + st::msgPadding.right() + 1) return; bool out = parent->out(), fromChannel = parent->fromChannel(), outbg = out && !fromChannel, hovered, pressed; - bool already = !data->already().isEmpty(), hasdata = !data->data.isEmpty(); + bool already = !_data->already().isEmpty(), hasdata = !_data->data.isEmpty(); int32 usew = _maxw, usex = 0; const HistoryReply *reply = toHistoryReply(parent); @@ -4664,27 +4665,27 @@ void HistorySticker::draw(Painter &p, const HistoryItem *parent, const QRect &r, } if (rtl()) usex = _width - usex - usew; - if (!already && !hasdata && !data->loader && data->status == FileReady) { - data->save(QString()); + if (!already && !hasdata && !_data->loader && _data->status == FileReady) { + _data->save(QString()); } - if (data->sticker()->img->isNull() && (already || hasdata)) { + if (_data->sticker()->img->isNull() && (already || hasdata)) { if (already) { - data->sticker()->img = ImagePtr(data->already()); + _data->sticker()->img = ImagePtr(_data->already()); } else { - data->sticker()->img = ImagePtr(data->data); + _data->sticker()->img = ImagePtr(_data->data); } } if (selected) { - if (data->sticker()->img->isNull()) { - p.drawPixmap(QPoint(usex + (usew - pixw) / 2, (_minh - pixh) / 2), data->thumb->pixBlurredColored(st::msgStickerOverlay, pixw, pixh)); + if (_data->sticker()->img->isNull()) { + p.drawPixmap(QPoint(usex + (usew - _pixw) / 2, (_minh - _pixh) / 2), _data->thumb->pixBlurredColored(st::msgStickerOverlay, _pixw, _pixh)); } else { - p.drawPixmap(QPoint(usex + (usew - pixw) / 2, (_minh - pixh) / 2), data->sticker()->img->pixColored(st::msgStickerOverlay, pixw, pixh)); + p.drawPixmap(QPoint(usex + (usew - _pixw) / 2, (_minh - _pixh) / 2), _data->sticker()->img->pixColored(st::msgStickerOverlay, _pixw, _pixh)); } } else { - if (data->sticker()->img->isNull()) { - p.drawPixmap(QPoint(usex + (usew - pixw) / 2, (_minh - pixh) / 2), data->thumb->pixBlurred(pixw, pixh)); + if (_data->sticker()->img->isNull()) { + p.drawPixmap(QPoint(usex + (usew - _pixw) / 2, (_minh - _pixh) / 2), _data->thumb->pixBlurred(_pixw, _pixh)); } else { - p.drawPixmap(QPoint(usex + (usew - pixw) / 2, (_minh - pixh) / 2), data->sticker()->img->pix(pixw, pixh)); + p.drawPixmap(QPoint(usex + (usew - _pixw) / 2, (_minh - _pixh) / 2), _data->sticker()->img->pix(_pixw, _pixh)); } } @@ -4744,18 +4745,18 @@ const QString HistorySticker::inHistoryText() const { } void HistorySticker::regItem(HistoryItem *item) { - App::regDocumentItem(data, item); + App::regDocumentItem(_data, item); } void HistorySticker::unregItem(HistoryItem *item) { - App::unregDocumentItem(data, item); + App::unregDocumentItem(_data, item); } void HistorySticker::updateFrom(const MTPMessageMedia &media, HistoryItem *parent, bool allowEmitResize) { if (media.type() == mtpc_messageMediaDocument) { - App::feedDocument(media.c_messageMediaDocument().vdocument, data); - if (!data->data.isEmpty()) { - Local::writeStickerImage(mediaKey(mtpToLocationType(mtpc_inputDocumentFileLocation), data->dc, data->id), data->data); + App::feedDocument(media.c_messageMediaDocument().vdocument, _data); + if (!_data->data.isEmpty()) { + Local::writeStickerImage(mediaKey(mtpToLocationType(mtpc_inputDocumentFileLocation), _data->dc, _data->id), _data->data); } } } diff --git a/Telegram/SourceFiles/history.h b/Telegram/SourceFiles/history.h index 7f435f5ad9..05b5bbb01c 100644 --- a/Telegram/SourceFiles/history.h +++ b/Telegram/SourceFiles/history.h @@ -1673,8 +1673,8 @@ public: const QString inDialogsText() const; const QString inHistoryText() const; - DocumentData *document() { - return data; + DocumentData *getDocument() { + return _data; } void regItem(HistoryItem *item); @@ -1691,8 +1691,8 @@ public: private: - int16 pixw, pixh; - DocumentData *data; + int16 _pixw, _pixh; + DocumentData *_data; QString _emoji; }; diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index 7c1d55d96c..52bf0ce535 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -941,10 +941,12 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { _menu->addAction(lang(lng_context_reply_msg), _widget, SLOT(onReplyToMessage())); } if (item && !isUponSelected && !_contextMenuLnk) { - if (HistorySticker *sticker = dynamic_cast(msg ? msg->getMedia() : 0)) { - DocumentData *doc = sticker->document(); - if (doc && doc->sticker() && doc->sticker()->set.type() != mtpc_inputStickerSetEmpty) { - _menu->addAction(lang(doc->sticker()->setInstalled() ? lng_context_pack_info : lng_context_pack_add), _widget, SLOT(onStickerPackInfo())); + if (HistoryMedia *media = (msg ? msg->getMedia() : 0)) { + if (media->type() == MediaTypeSticker) { + DocumentData *doc = media->getDocument(); + if (doc && doc->sticker() && doc->sticker()->set.type() != mtpc_inputStickerSetEmpty) { + _menu->addAction(lang(doc->sticker()->setInstalled() ? lng_context_pack_info : lng_context_pack_add), _widget, SLOT(onStickerPackInfo())); + } } } QString contextMenuText = item->selectedText(FullSelection); @@ -6236,10 +6238,11 @@ void HistoryWidget::onReplyForwardPreviewCancel() { } void HistoryWidget::onStickerPackInfo() { - if (HistoryMessage *item = dynamic_cast(App::contextItem())) { - if (HistorySticker *sticker = dynamic_cast(item->getMedia())) { - if (sticker->document() && sticker->document()->sticker() && sticker->document()->sticker()->set.type() != mtpc_inputStickerSetEmpty) { - App::main()->stickersBox(sticker->document()->sticker()->set); + if (HistoryMedia *media = (App::contextItem() ? App::contextItem()->getMedia() : 0)) { + if (media->type() == MediaTypeSticker) { + DocumentData *doc = media->getDocument(); + if (doc && doc->sticker() && doc->sticker()->set.type() != mtpc_inputStickerSetEmpty) { + App::main()->stickersBox(doc->sticker()->set); } } } diff --git a/Telegram/SourceFiles/layout.cpp b/Telegram/SourceFiles/layout.cpp index 4e81b245d4..cebbcf2dc4 100644 --- a/Telegram/SourceFiles/layout.cpp +++ b/Telegram/SourceFiles/layout.cpp @@ -437,15 +437,17 @@ void LayoutOverviewVideo::paint(Painter &p, const QRect &clip, uint32 selection, p.fillRect(QRect(0, 0, _width, _height), st::overviewPhotoSelectOverlay); } - if (clip.intersects(QRect(0, _height - st::normalFont->height, _width, st::normalFont->height))) { - int32 statusX = st::msgDateImgPadding.x(), statusY = _height - st::normalFont->height - st::msgDateImgPadding.y(); - int32 statusW = st::normalFont->width(_statusText) + 2 * st::msgDateImgPadding.x(); - int32 statusH = st::normalFont->height + 2 * st::msgDateImgPadding.y(); - statusX = _width - statusW + statusX; - p.fillRect(rtlrect(statusX - st::msgDateImgPadding.x(), statusY - st::msgDateImgPadding.y(), statusW, statusH, _width), selected ? st::msgDateImgBgSelected : st::msgDateImgBg); - p.setFont(st::normalFont); - p.setPen(st::white); - p.drawTextLeft(statusX, statusY, _width, _statusText, statusW - 2 * st::msgDateImgPadding.x()); + if (!selected && !context->selecting && !already) { + if (clip.intersects(QRect(0, _height - st::normalFont->height, _width, st::normalFont->height))) { + int32 statusX = st::msgDateImgPadding.x(), statusY = _height - st::normalFont->height - st::msgDateImgPadding.y(); + int32 statusW = st::normalFont->width(_statusText) + 2 * st::msgDateImgPadding.x(); + int32 statusH = st::normalFont->height + 2 * st::msgDateImgPadding.y(); + statusX = _width - statusW + statusX; + p.fillRect(rtlrect(statusX - st::msgDateImgPadding.x(), statusY - st::msgDateImgPadding.y(), statusW, statusH, _width), selected ? st::msgDateImgBgSelected : st::msgDateImgBg); + p.setFont(st::normalFont); + p.setPen(st::white); + p.drawTextLeft(statusX, statusY, _width, _statusText, statusW - 2 * st::msgDateImgPadding.x()); + } } if (clip.intersects(QRect(0, 0, _width, st::normalFont->height))) { int32 statusX = st::msgDateImgPadding.x(), statusY = st::msgDateImgPadding.y(); @@ -536,7 +538,9 @@ LayoutOverviewAudio::LayoutOverviewAudio(AudioData *audio, HistoryItem *parent) , _data(audio) { setLinks(new AudioOpenLink(_data), new AudioSaveLink(_data), new AudioCancelLink(_data)); updateName(); - _details.setText(st::normalFont, lng_date_and_duration(lt_date, textcmdLink(1, langDateTime(date(_data->date))), lt_duration, formatDurationText(_data->duration)), _defaultOptions); + QString d = textcmdLink(1, textRichPrepare(langDateTime(date(_data->date)))); + TextParseOptions opts = { TextParseRichText, 0, 0, Qt::LayoutDirectionAuto }; + _details.setText(st::normalFont, lng_date_and_duration(lt_date, d, lt_duration, formatDurationText(_data->duration)), opts); _details.setLink(1, TextLinkPtr(new MessageLink(parent))); } @@ -622,8 +626,15 @@ void LayoutOverviewAudio::paint(Painter &p, const QRect &clip, uint32 selection, } if (clip.intersects(rtlrect(nameleft, statustop, namewidth, st::normalFont->height, _width))) { - p.setPen(selected ? st::msgInDateFgSelected : st::mediaInFg); - _details.drawLeftElided(p, nameleft, statustop, namewidth, _width); + p.setFont(st::normalFont); + p.setPen(selected ? st::mediaInFgSelected : st::mediaInFg); + if (_statusSize == FileStatusSizeLoaded || _statusSize == FileStatusSizeReady) { + textstyleSet(&(selected ? st::mediaInStyleSelected : st::mediaInStyle)); + _details.drawLeftElided(p, nameleft, statustop, namewidth, _width); + textstyleRestore(); + } else { + p.drawTextLeft(nameleft, statustop, _width, _statusText); + } } } @@ -645,9 +656,11 @@ void LayoutOverviewAudio::getState(TextLinkPtr &link, HistoryCursorState &cursor return; } if (rtlrect(nameleft, statustop, _width - nameleft - nameright, st::normalFont->height, _width).contains(x, y)) { - bool inText = false; - _details.getStateLeft(link, inText, x - nameleft, y - statustop, _width, _width); - cursor = inText ? HistoryInTextCursorState : HistoryDefaultCursorState; + if (_statusSize == FileStatusSizeLoaded || _statusSize == FileStatusSizeReady) { + bool inText = false; + _details.getStateLeft(link, inText, x - nameleft, y - statustop, _width, _width); + cursor = inText ? HistoryInTextCursorState : HistoryDefaultCursorState; + } } } diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 14e06c5eeb..6a4e91f6ee 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -619,8 +619,10 @@ void MainWidget::finishForwarding(History *hist, bool broadcast) { FullMsgId newId(peerToChannel(hist->peer->id), clientMsgId()); HistoryMessage *msg = static_cast(_toForward.cbegin().value()); hist->addNewForwarded(newId.msg, date(MTP_int(unixtime())), fromChannelName ? 0 : MTP::authedId(), msg); - if (HistorySticker *sticker = dynamic_cast(msg->getMedia())) { - App::main()->incrementSticker(sticker->document()); + if (HistoryMedia *media = msg->getMedia()) { + if (media->type() == MediaTypeSticker) { + App::main()->incrementSticker(media->getDocument()); + } } App::historyRegRandom(randomId, newId); } diff --git a/Telegram/SourceFiles/mediaview.cpp b/Telegram/SourceFiles/mediaview.cpp index 465d3a6e42..9a43c33129 100644 --- a/Telegram/SourceFiles/mediaview.cpp +++ b/Telegram/SourceFiles/mediaview.cpp @@ -1503,12 +1503,12 @@ void MediaView::moveToNext(int32 delta) { _canDelete = item->canDelete(); delete _gif; _gif = 0; - if (item->getMedia()) { - switch (item->getMedia()->type()) { + if (HistoryMedia *media = item->getMedia()) { + switch (media->type()) { case MediaTypePhoto: displayPhoto(static_cast(item->getMedia())->photo(), item); preloadData(delta); break; - case MediaTypeDocument: displayDocument(static_cast(item->getMedia())->getDocument(), item); preloadData(delta); break; - case MediaTypeGif: displayDocument(static_cast(item->getMedia())->getDocument(), item); preloadData(delta); break; - case MediaTypeSticker: displayDocument(static_cast(item->getMedia())->document(), item); preloadData(delta); break; + case MediaTypeDocument: + case MediaTypeGif: + case MediaTypeSticker: displayDocument(media->getDocument(), item); preloadData(delta); break; } } else { displayDocument(0, item); @@ -1554,9 +1554,9 @@ void MediaView::preloadData(int32 delta) { if (HistoryMedia *media = item->getMedia()) { switch (media->type()) { case MediaTypePhoto: static_cast(media)->photo()->full->load(); break; - case MediaTypeDocument: static_cast(media)->getDocument()->thumb->load(); break; + case MediaTypeDocument: case MediaTypeGif: static_cast(media)->getDocument()->thumb->load(); break; - case MediaTypeSticker: static_cast(media)->document()->sticker()->img->load(); break; + case MediaTypeSticker: static_cast(media)->getDocument()->sticker()->img->load(); break; } } } @@ -1578,9 +1578,9 @@ void MediaView::preloadData(int32 delta) { if (HistoryMedia *media = item->getMedia()) { switch (media->type()) { case MediaTypePhoto: static_cast(media)->photo()->forget(); break; - case MediaTypeDocument: static_cast(media)->getDocument()->forget(); break; - case MediaTypeGif: static_cast(media)->getDocument()->forget(); break; - case MediaTypeSticker: static_cast(media)->document()->forget(); break; + case MediaTypeDocument: + case MediaTypeGif: + case MediaTypeSticker: media->getDocument()->forget(); break; } } } diff --git a/Telegram/SourceFiles/overviewwidget.cpp b/Telegram/SourceFiles/overviewwidget.cpp index bd61ab203d..74f5ae7245 100644 --- a/Telegram/SourceFiles/overviewwidget.cpp +++ b/Telegram/SourceFiles/overviewwidget.cpp @@ -1939,9 +1939,9 @@ LayoutMediaItem *OverviewInner::getItemLayout(HistoryItem *item) { } } } else if (_type == OverviewDocuments || _type == OverviewAudioDocuments) { - if (media && media->type() == MediaTypeDocument) { + if (media && (media->type() == MediaTypeDocument || media->type() == MediaTypeGif)) { if ((i = _layoutItems.constFind(item)) == _layoutItems.cend()) { - i = _layoutItems.insert(item, new LayoutOverviewDocument(static_cast(media)->getDocument(), item)); + i = _layoutItems.insert(item, new LayoutOverviewDocument(media->getDocument(), item)); i.value()->initDimensions(); } }