2014-08-06 14:40:21 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2014-12-01 10:47:38 +00:00
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
2014-08-06 14:40:21 +00:00
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
2015-10-03 13:16:42 +00:00
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
2014-08-06 14:40:21 +00:00
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2014-08-06 14:40:21 +00:00
|
|
|
*/
|
|
|
|
#include "mediaview.h"
|
2016-10-28 08:02:45 +00:00
|
|
|
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2014-08-11 09:03:45 +00:00
|
|
|
#include "mainwidget.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "mainwindow.h"
|
2014-08-11 09:03:45 +00:00
|
|
|
#include "application.h"
|
2017-02-28 14:05:30 +00:00
|
|
|
#include "core/file_utilities.h"
|
2016-10-26 16:43:13 +00:00
|
|
|
#include "ui/widgets/popup_menu.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2016-06-24 10:37:29 +00:00
|
|
|
#include "media/media_clip_reader.h"
|
2016-07-11 18:05:46 +00:00
|
|
|
#include "media/view/media_clip_controller.h"
|
|
|
|
#include "styles/style_mediaview.h"
|
2016-10-28 08:02:45 +00:00
|
|
|
#include "styles/style_history.h"
|
2016-07-12 11:38:16 +00:00
|
|
|
#include "media/media_audio.h"
|
2016-09-28 10:15:03 +00:00
|
|
|
#include "history/history_media_types.h"
|
2017-02-03 20:07:26 +00:00
|
|
|
#include "window/themes/window_theme_preview.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "base/task_queue.h"
|
2017-01-01 16:45:20 +00:00
|
|
|
#include "observer_peer.h"
|
2017-03-04 19:36:59 +00:00
|
|
|
#include "auth_session.h"
|
|
|
|
#include "messenger.h"
|
|
|
|
#include "storage/file_download.h"
|
2017-05-12 17:44:18 +00:00
|
|
|
#include "calls/calls_instance.h"
|
2014-08-06 14:40:21 +00:00
|
|
|
|
2014-10-17 12:57:14 +00:00
|
|
|
namespace {
|
|
|
|
|
2016-06-24 10:37:29 +00:00
|
|
|
TextParseOptions _captionTextOptions = {
|
|
|
|
TextParseLinks | TextParseMentions | TextParseHashtags | TextParseMultiline | TextParseRichText, // flags
|
|
|
|
0, // maxw
|
|
|
|
0, // maxh
|
|
|
|
Qt::LayoutDirectionAuto, // dir
|
|
|
|
};
|
|
|
|
TextParseOptions _captionBotOptions = {
|
|
|
|
TextParseLinks | TextParseMentions | TextParseHashtags | TextParseMultiline | TextParseRichText | TextParseBotCommands, // flags
|
|
|
|
0, // maxw
|
|
|
|
0, // maxh
|
|
|
|
Qt::LayoutDirectionAuto, // dir
|
|
|
|
};
|
|
|
|
|
|
|
|
bool typeHasMediaOverview(MediaOverviewType type) {
|
|
|
|
switch (type) {
|
|
|
|
case OverviewPhotos:
|
|
|
|
case OverviewVideos:
|
|
|
|
case OverviewMusicFiles:
|
|
|
|
case OverviewFiles:
|
|
|
|
case OverviewVoiceFiles:
|
|
|
|
case OverviewLinks: return true;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
return false;
|
2014-10-17 12:57:14 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 10:37:29 +00:00
|
|
|
} // namespace
|
|
|
|
|
2016-12-31 15:19:22 +00:00
|
|
|
MediaView::MediaView(QWidget*) : TWidget(nullptr)
|
2017-02-03 20:07:26 +00:00
|
|
|
, _transparentBrush(style::transparentPlaceholderBrush())
|
2015-11-16 16:04:37 +00:00
|
|
|
, _animStarted(getms())
|
2016-10-31 12:29:26 +00:00
|
|
|
, _docDownload(this, lang(lng_media_download), st::mediaviewFileLink)
|
|
|
|
, _docSaveAs(this, lang(lng_mediaview_save_as), st::mediaviewFileLink)
|
|
|
|
, _docCancel(this, lang(lng_cancel), st::mediaviewFileLink)
|
2016-06-21 18:09:48 +00:00
|
|
|
, _radial(animation(this, &MediaView::step_radial))
|
2016-12-23 13:21:01 +00:00
|
|
|
, _lastAction(-st::mediaviewDeltaFromLastAction, -st::mediaviewDeltaFromLastAction)
|
2015-12-08 12:33:37 +00:00
|
|
|
, _a_state(animation(this, &MediaView::step_state))
|
2016-12-31 15:19:22 +00:00
|
|
|
, _dropdown(this, st::mediaviewDropdownMenu)
|
|
|
|
, _dropdownShowTimer(this) {
|
2017-05-30 15:21:05 +00:00
|
|
|
subscribe(Lang::Current().updated(), [this] { refreshLang(); });
|
|
|
|
|
2014-10-17 12:57:14 +00:00
|
|
|
TextCustomTagsMap custom;
|
|
|
|
custom.insert(QChar('c'), qMakePair(textcmdStartLink(1), textcmdStopLink()));
|
2016-12-23 13:21:01 +00:00
|
|
|
_saveMsgText.setRichText(st::mediaviewSaveMsgStyle, lang(lng_mediaview_saved), _textDlgOptions, custom);
|
|
|
|
_saveMsg = QRect(0, 0, _saveMsgText.maxWidth() + st::mediaviewSaveMsgPadding.left() + st::mediaviewSaveMsgPadding.right(), st::mediaviewSaveMsgStyle.font->height + st::mediaviewSaveMsgPadding.top() + st::mediaviewSaveMsgPadding.bottom());
|
2016-11-16 10:44:06 +00:00
|
|
|
_saveMsgText.setLink(1, MakeShared<LambdaClickHandler>([this] { showSaveMsgFile(); }));
|
2014-10-17 12:57:14 +00:00
|
|
|
|
2016-06-22 13:39:54 +00:00
|
|
|
connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(onScreenResized(int)));
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
// While we have one mediaview for all authsessions we have to do this.
|
2017-05-12 17:44:18 +00:00
|
|
|
auto handleAuthSessionChange = [this] {
|
2017-03-10 08:25:38 +00:00
|
|
|
if (AuthSession::Exists()) {
|
|
|
|
subscribe(AuthSession::CurrentDownloaderTaskFinished(), [this] {
|
|
|
|
if (!isHidden()) {
|
|
|
|
updateControls();
|
|
|
|
}
|
|
|
|
});
|
2017-05-12 17:44:18 +00:00
|
|
|
subscribe(AuthSession::Current().calls().currentCallChanged(), [this](Calls::Call *call) {
|
|
|
|
if (call && _clipController && !_videoPaused) {
|
|
|
|
onVideoPauseResume();
|
|
|
|
}
|
|
|
|
});
|
2017-03-10 08:25:38 +00:00
|
|
|
}
|
|
|
|
};
|
2017-05-12 17:44:18 +00:00
|
|
|
subscribe(Messenger::Instance().authSessionChanged(), [handleAuthSessionChange] {
|
|
|
|
handleAuthSessionChange();
|
2016-10-02 13:54:27 +00:00
|
|
|
});
|
2017-05-12 17:44:18 +00:00
|
|
|
handleAuthSessionChange();
|
2017-03-10 08:25:38 +00:00
|
|
|
|
2017-01-01 16:45:20 +00:00
|
|
|
auto observeEvents = Notify::PeerUpdate::Flag::SharedMediaChanged;
|
|
|
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) {
|
|
|
|
mediaOverviewUpdated(update);
|
|
|
|
}));
|
2016-10-02 13:54:27 +00:00
|
|
|
|
2014-08-06 14:40:21 +00:00
|
|
|
setWindowFlags(Qt::FramelessWindowHint | Qt::BypassWindowManagerHint | Qt::Tool | Qt::NoDropShadowWindowHint);
|
|
|
|
moveToScreen();
|
|
|
|
setAttribute(Qt::WA_NoSystemBackground, true);
|
|
|
|
setAttribute(Qt::WA_TranslucentBackground, true);
|
2014-08-11 09:03:45 +00:00
|
|
|
setMouseTracking(true);
|
2015-02-19 11:30:16 +00:00
|
|
|
|
|
|
|
hide();
|
2015-02-19 12:22:59 +00:00
|
|
|
createWinId();
|
2016-06-23 12:02:40 +00:00
|
|
|
if (cPlatform() == dbipWindows) {
|
|
|
|
setWindowState(Qt::WindowFullScreen);
|
|
|
|
}
|
2015-12-31 20:07:41 +00:00
|
|
|
|
2014-10-17 12:57:14 +00:00
|
|
|
_saveMsgUpdater.setSingleShot(true);
|
|
|
|
connect(&_saveMsgUpdater, SIGNAL(timeout()), this, SLOT(updateImage()));
|
2014-08-11 09:03:45 +00:00
|
|
|
|
|
|
|
connect(App::wnd()->windowHandle(), SIGNAL(activeChanged()), this, SLOT(onCheckActive()));
|
|
|
|
|
|
|
|
setAttribute(Qt::WA_AcceptTouchEvents);
|
|
|
|
_touchTimer.setSingleShot(true);
|
|
|
|
connect(&_touchTimer, SIGNAL(timeout()), this, SLOT(onTouchTimer()));
|
2015-04-11 10:04:10 +00:00
|
|
|
|
|
|
|
_controlsHideTimer.setSingleShot(true);
|
|
|
|
connect(&_controlsHideTimer, SIGNAL(timeout()), this, SLOT(onHideControls()));
|
2015-04-19 10:29:19 +00:00
|
|
|
|
2016-11-11 13:46:04 +00:00
|
|
|
connect(_docDownload, SIGNAL(clicked()), this, SLOT(onDownload()));
|
|
|
|
connect(_docSaveAs, SIGNAL(clicked()), this, SLOT(onSaveAs()));
|
|
|
|
connect(_docCancel, SIGNAL(clicked()), this, SLOT(onSaveCancel()));
|
2016-10-26 16:43:13 +00:00
|
|
|
|
2016-11-05 08:36:24 +00:00
|
|
|
_dropdown->setHiddenCallback([this] { dropdownHidden(); });
|
2016-12-31 15:19:22 +00:00
|
|
|
_dropdownShowTimer->setSingleShot(true);
|
|
|
|
connect(_dropdownShowTimer, SIGNAL(timeout()), this, SLOT(onDropdown()));
|
2014-08-06 14:40:21 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 15:21:05 +00:00
|
|
|
void MediaView::refreshLang() {
|
|
|
|
InvokeQueued(this, [this] { updateThemePreviewGeometry(); });
|
|
|
|
}
|
|
|
|
|
2014-08-06 14:40:21 +00:00
|
|
|
void MediaView::moveToScreen() {
|
2015-09-28 14:19:37 +00:00
|
|
|
if (App::wnd() && windowHandle() && App::wnd()->windowHandle() && windowHandle()->screen() != App::wnd()->windowHandle()->screen()) {
|
|
|
|
windowHandle()->setScreen(App::wnd()->windowHandle()->screen());
|
|
|
|
}
|
|
|
|
|
2016-11-05 08:36:24 +00:00
|
|
|
auto wndCenter = App::wnd()->geometry().center();
|
2016-02-08 14:54:55 +00:00
|
|
|
QRect avail = Sandbox::screenGeometry(wndCenter);
|
2015-04-11 10:04:10 +00:00
|
|
|
if (avail != geometry()) {
|
|
|
|
setGeometry(avail);
|
|
|
|
}
|
2015-12-31 20:07:41 +00:00
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
int32 navSkip = 2 * st::mediaviewControlMargin + st::mediaviewControlSize;
|
|
|
|
_closeNav = myrtlrect(width() - st::mediaviewControlMargin - st::mediaviewControlSize, st::mediaviewControlMargin, st::mediaviewControlSize, st::mediaviewControlSize);
|
2016-09-30 16:40:00 +00:00
|
|
|
_closeNavIcon = centerrect(_closeNav, st::mediaviewClose);
|
2016-12-23 13:21:01 +00:00
|
|
|
_leftNav = myrtlrect(st::mediaviewControlMargin, navSkip, st::mediaviewControlSize, height() - 2 * navSkip);
|
2016-09-30 16:40:00 +00:00
|
|
|
_leftNavIcon = centerrect(_leftNav, st::mediaviewLeft);
|
2016-12-23 13:21:01 +00:00
|
|
|
_rightNav = myrtlrect(width() - st::mediaviewControlMargin - st::mediaviewControlSize, navSkip, st::mediaviewControlSize, height() - 2 * navSkip);
|
2016-09-30 16:40:00 +00:00
|
|
|
_rightNavIcon = centerrect(_rightNav, st::mediaviewRight);
|
2015-04-11 10:04:10 +00:00
|
|
|
|
|
|
|
_saveMsg.moveTo((width() - _saveMsg.width()) / 2, (height() - _saveMsg.height()) / 2);
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
|
2017-01-01 16:45:20 +00:00
|
|
|
void MediaView::mediaOverviewUpdated(const Notify::PeerUpdate &update) {
|
|
|
|
if (isHidden() || (!_photo && !_doc)) return;
|
2016-06-21 14:19:24 +00:00
|
|
|
if (_photo && _overview == OverviewChatPhotos && _history && !_history->peer->isUser()) {
|
|
|
|
auto lastChatPhoto = computeLastOverviewChatPhoto();
|
|
|
|
if (_index < 0 && _photo == lastChatPhoto.photo && _photo == _additionalChatPhoto) {
|
2016-06-22 13:39:54 +00:00
|
|
|
auto firstOpened = _firstOpenedPeerPhoto;
|
|
|
|
showPhoto(_photo, lastChatPhoto.item);
|
|
|
|
_firstOpenedPeerPhoto = firstOpened;
|
|
|
|
return;
|
2016-06-21 14:19:24 +00:00
|
|
|
}
|
|
|
|
computeAdditionalChatPhoto(_history->peer, lastChatPhoto.photo);
|
|
|
|
}
|
|
|
|
|
2017-01-01 16:45:20 +00:00
|
|
|
if (_history && (_history->peer == update.peer || (_migrated && _migrated->peer == update.peer)) && (update.mediaTypesMask & (1 << _overview)) && _msgid) {
|
2014-08-11 09:03:45 +00:00
|
|
|
_index = -1;
|
2015-11-16 16:04:37 +00:00
|
|
|
if (_msgmigrated) {
|
|
|
|
for (int i = 0, l = _migrated->overview[_overview].size(); i < l; ++i) {
|
|
|
|
if (_migrated->overview[_overview].at(i) == _msgid) {
|
|
|
|
_index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (int i = 0, l = _history->overview[_overview].size(); i < l; ++i) {
|
|
|
|
if (_history->overview[_overview].at(i) == _msgid) {
|
|
|
|
_index = i;
|
|
|
|
break;
|
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
updateControls();
|
2015-04-11 10:04:10 +00:00
|
|
|
preloadData(0);
|
2017-01-01 16:45:20 +00:00
|
|
|
} else if (_user == update.peer && update.mediaTypesMask & (1 << OverviewCount)) {
|
2015-04-11 10:04:10 +00:00
|
|
|
if (!_photo) return;
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
_index = -1;
|
|
|
|
for (int i = 0, l = _user->photos.size(); i < l; ++i) {
|
|
|
|
if (_user->photos.at(i) == _photo) {
|
|
|
|
_index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateControls();
|
2015-04-11 10:04:10 +00:00
|
|
|
preloadData(0);
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-22 08:01:02 +00:00
|
|
|
bool MediaView::fileShown() const {
|
|
|
|
return !_current.isNull() || gifShown();
|
|
|
|
}
|
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
bool MediaView::fileBubbleShown() const {
|
2016-12-31 13:34:41 +00:00
|
|
|
return (!_photo && !_doc) || (_doc && !fileShown() && !_themePreviewShown);
|
2016-12-23 13:21:01 +00:00
|
|
|
}
|
|
|
|
|
2015-12-22 08:01:02 +00:00
|
|
|
bool MediaView::gifShown() const {
|
|
|
|
if (_gif && _gif->ready()) {
|
|
|
|
if (!_gif->started()) {
|
2017-04-12 20:34:57 +00:00
|
|
|
if (_doc && (_doc->isVideo() || _doc->isRoundVideo()) && _autoplayVideoDocument != _doc && !_gif->videoPaused()) {
|
2016-07-13 11:24:31 +00:00
|
|
|
_gif->pauseResumeVideo();
|
|
|
|
const_cast<MediaView*>(this)->_videoPaused = _gif->videoPaused();
|
|
|
|
}
|
2017-04-12 20:34:57 +00:00
|
|
|
auto rounding = (_doc && _doc->isRoundVideo()) ? ImageRoundRadius::Ellipse : ImageRoundRadius::None;
|
2017-04-02 16:42:18 +00:00
|
|
|
_gif->start(_gif->width() / cIntRetinaFactor(), _gif->height() / cIntRetinaFactor(), _gif->width() / cIntRetinaFactor(), _gif->height() / cIntRetinaFactor(), rounding, ImageRoundCorner::All);
|
2015-12-22 08:01:02 +00:00
|
|
|
const_cast<MediaView*>(this)->_current = QPixmap();
|
2017-04-15 19:51:53 +00:00
|
|
|
updateMixerVideoVolume();
|
|
|
|
Global::RefVideoVolumeChanged().notify();
|
2015-12-22 08:01:02 +00:00
|
|
|
}
|
2016-07-05 17:44:22 +00:00
|
|
|
return true;// _gif->state() != Media::Clip::State::Error;
|
2015-12-22 08:01:02 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-23 19:23:14 +00:00
|
|
|
void MediaView::stopGif() {
|
2016-07-05 17:44:22 +00:00
|
|
|
_gif = nullptr;
|
2016-07-14 11:20:46 +00:00
|
|
|
_videoPaused = _videoStopped = _videoIsSilent = false;
|
|
|
|
_fullScreenVideo = false;
|
2016-07-11 18:05:46 +00:00
|
|
|
_clipController.destroy();
|
2017-01-19 08:24:43 +00:00
|
|
|
disconnect(Media::Player::mixer(), SIGNAL(updated(const AudioMsgId&)), this, SLOT(onVideoPlayProgress(const AudioMsgId&)));
|
2015-12-23 19:23:14 +00:00
|
|
|
}
|
|
|
|
|
2015-04-19 10:29:19 +00:00
|
|
|
void MediaView::documentUpdated(DocumentData *doc) {
|
2016-12-31 13:34:41 +00:00
|
|
|
if (fileBubbleShown() && _doc && _doc == doc) {
|
2016-11-11 13:46:04 +00:00
|
|
|
if ((_doc->loading() && _docCancel->isHidden()) || (!_doc->loading() && !_docCancel->isHidden())) {
|
2015-04-19 10:29:19 +00:00
|
|
|
updateControls();
|
2015-12-24 19:26:28 +00:00
|
|
|
} else if (_doc->loading()) {
|
2015-04-19 10:29:19 +00:00
|
|
|
updateDocSize();
|
|
|
|
update(_docRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
void MediaView::changingMsgId(HistoryItem *row, MsgId newId) {
|
|
|
|
if (row->id == _msgid) {
|
|
|
|
_msgid = newId;
|
|
|
|
}
|
2017-01-01 16:45:20 +00:00
|
|
|
|
|
|
|
// Send a fake update.
|
|
|
|
Notify::PeerUpdate update(row->history()->peer);
|
|
|
|
update.flags |= Notify::PeerUpdate::Flag::SharedMediaChanged;
|
|
|
|
update.mediaTypesMask |= (1 << _overview);
|
|
|
|
mediaOverviewUpdated(update);
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
|
2015-04-19 10:29:19 +00:00
|
|
|
void MediaView::updateDocSize() {
|
2016-12-31 13:34:41 +00:00
|
|
|
if (!_doc || !fileBubbleShown()) return;
|
2015-04-19 10:29:19 +00:00
|
|
|
|
2015-12-24 19:26:28 +00:00
|
|
|
if (_doc->loading()) {
|
|
|
|
quint64 ready = _doc->loadOffset(), total = _doc->size;
|
2015-04-19 10:29:19 +00:00
|
|
|
QString readyStr, totalStr, mb;
|
|
|
|
if (total >= 1024 * 1024) { // more than 1 mb
|
|
|
|
qint64 readyTenthMb = (ready * 10 / (1024 * 1024)), totalTenthMb = (total * 10 / (1024 * 1024));
|
|
|
|
readyStr = QString::number(readyTenthMb / 10) + '.' + QString::number(readyTenthMb % 10);
|
|
|
|
totalStr = QString::number(totalTenthMb / 10) + '.' + QString::number(totalTenthMb % 10);
|
|
|
|
mb = qsl("MB");
|
2015-09-08 12:20:30 +00:00
|
|
|
} else if (total >= 1024) {
|
2015-04-19 10:29:19 +00:00
|
|
|
qint64 readyKb = (ready / 1024), totalKb = (total / 1024);
|
|
|
|
readyStr = QString::number(readyKb);
|
|
|
|
totalStr = QString::number(totalKb);
|
|
|
|
mb = qsl("KB");
|
2015-09-08 12:20:30 +00:00
|
|
|
} else {
|
|
|
|
readyStr = QString::number(ready);
|
|
|
|
totalStr = QString::number(total);
|
|
|
|
mb = qsl("B");
|
2015-04-19 10:29:19 +00:00
|
|
|
}
|
|
|
|
_docSize = lng_media_save_progress(lt_ready, readyStr, lt_total, totalStr, lt_mb, mb);
|
|
|
|
} else {
|
|
|
|
_docSize = formatSizeText(_doc->size);
|
|
|
|
}
|
2016-12-23 13:21:01 +00:00
|
|
|
_docSizeWidth = st::mediaviewFont->width(_docSize);
|
2016-10-31 12:29:26 +00:00
|
|
|
int32 maxw = st::mediaviewFileSize.width() - st::mediaviewFileIconSize - st::mediaviewFilePadding * 3;
|
2015-04-19 10:29:19 +00:00
|
|
|
if (_docSizeWidth > maxw) {
|
2016-12-23 13:21:01 +00:00
|
|
|
_docSize = st::mediaviewFont->elided(_docSize, maxw);
|
|
|
|
_docSizeWidth = st::mediaviewFont->width(_docSize);
|
2015-04-19 10:29:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
void MediaView::updateControls() {
|
2016-12-31 13:34:41 +00:00
|
|
|
if (_doc && fileBubbleShown()) {
|
2015-12-24 19:26:28 +00:00
|
|
|
if (_doc->loading()) {
|
2016-11-11 13:46:04 +00:00
|
|
|
_docDownload->hide();
|
|
|
|
_docSaveAs->hide();
|
|
|
|
_docCancel->moveToLeft(_docRect.x() + 2 * st::mediaviewFilePadding + st::mediaviewFileIconSize, _docRect.y() + st::mediaviewFilePadding + st::mediaviewFileLinksTop);
|
|
|
|
_docCancel->show();
|
2015-04-19 10:29:19 +00:00
|
|
|
} else {
|
2016-03-16 11:54:37 +00:00
|
|
|
if (_doc->loaded(DocumentData::FilePathResolveChecked)) {
|
2016-11-11 13:46:04 +00:00
|
|
|
_docDownload->hide();
|
|
|
|
_docSaveAs->moveToLeft(_docRect.x() + 2 * st::mediaviewFilePadding + st::mediaviewFileIconSize, _docRect.y() + st::mediaviewFilePadding + st::mediaviewFileLinksTop);
|
|
|
|
_docSaveAs->show();
|
|
|
|
_docCancel->hide();
|
2015-04-19 10:29:19 +00:00
|
|
|
} else {
|
2016-11-11 13:46:04 +00:00
|
|
|
_docDownload->moveToLeft(_docRect.x() + 2 * st::mediaviewFilePadding + st::mediaviewFileIconSize, _docRect.y() + st::mediaviewFilePadding + st::mediaviewFileLinksTop);
|
|
|
|
_docDownload->show();
|
|
|
|
_docSaveAs->moveToLeft(_docRect.x() + 2.5 * st::mediaviewFilePadding + st::mediaviewFileIconSize + _docDownload->width(), _docRect.y() + st::mediaviewFilePadding + st::mediaviewFileLinksTop);
|
|
|
|
_docSaveAs->show();
|
|
|
|
_docCancel->hide();
|
2015-04-19 10:29:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
updateDocSize();
|
|
|
|
} else {
|
2016-11-11 13:46:04 +00:00
|
|
|
_docDownload->hide();
|
|
|
|
_docSaveAs->hide();
|
|
|
|
_docCancel->hide();
|
2015-04-19 10:29:19 +00:00
|
|
|
}
|
2016-06-21 18:09:48 +00:00
|
|
|
radialStart();
|
2015-04-19 10:29:19 +00:00
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
updateThemePreviewGeometry();
|
|
|
|
|
2016-03-16 11:54:37 +00:00
|
|
|
_saveVisible = ((_photo && _photo->loaded()) || (_doc && (_doc->loaded(DocumentData::FilePathResolveChecked) || (!fileShown() && (_photo || _doc)))));
|
2016-12-23 13:21:01 +00:00
|
|
|
_saveNav = myrtlrect(width() - st::mediaviewIconSize.width() * 2, height() - st::mediaviewIconSize.height(), st::mediaviewIconSize.width(), st::mediaviewIconSize.height());
|
2016-09-30 16:40:00 +00:00
|
|
|
_saveNavIcon = centerrect(_saveNav, st::mediaviewSave);
|
2016-12-23 13:21:01 +00:00
|
|
|
_moreNav = myrtlrect(width() - st::mediaviewIconSize.width(), height() - st::mediaviewIconSize.height(), st::mediaviewIconSize.width(), st::mediaviewIconSize.height());
|
2016-09-30 16:40:00 +00:00
|
|
|
_moreNavIcon = centerrect(_moreNav, st::mediaviewMore);
|
2015-04-11 10:04:10 +00:00
|
|
|
|
2015-07-15 11:23:59 +00:00
|
|
|
QDateTime d, dNow(date(unixtime()));
|
|
|
|
if (_photo) {
|
|
|
|
d = date(_photo->date);
|
|
|
|
} else if (_doc) {
|
|
|
|
d = date(_doc->date);
|
2015-11-16 16:04:37 +00:00
|
|
|
} else if (HistoryItem *item = App::histItemById(_msgmigrated ? 0 : _channel, _msgid)) {
|
2015-07-15 11:23:59 +00:00
|
|
|
d = item->date;
|
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
if (d.date() == dNow.date()) {
|
2015-02-10 18:55:04 +00:00
|
|
|
_dateText = lng_mediaview_today(lt_time, d.time().toString(cTimeFormat()));
|
2014-08-11 09:03:45 +00:00
|
|
|
} else if (d.date().addDays(1) == dNow.date()) {
|
2015-02-10 18:55:04 +00:00
|
|
|
_dateText = lng_mediaview_yesterday(lt_time, d.time().toString(cTimeFormat()));
|
2014-08-11 09:03:45 +00:00
|
|
|
} else {
|
2015-02-10 18:55:04 +00:00
|
|
|
_dateText = lng_mediaview_date_time(lt_date, d.date().toString(qsl("dd.MM.yy")), lt_time, d.time().toString(cTimeFormat()));
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
if (_from) {
|
2016-12-23 13:21:01 +00:00
|
|
|
_fromName.setText(st::mediaviewTextStyle, (_from->migrateTo() ? _from->migrateTo() : _from)->name, _textNameOptions);
|
|
|
|
_nameNav = myrtlrect(st::mediaviewTextLeft, height() - st::mediaviewTextTop, qMin(_fromName.maxWidth(), width() / 3), st::mediaviewFont->height);
|
|
|
|
_dateNav = myrtlrect(st::mediaviewTextLeft + _nameNav.width() + st::mediaviewTextSkip, height() - st::mediaviewTextTop, st::mediaviewFont->width(_dateText), st::mediaviewFont->height);
|
2015-04-11 10:04:10 +00:00
|
|
|
} else {
|
|
|
|
_nameNav = QRect();
|
2016-12-23 13:21:01 +00:00
|
|
|
_dateNav = myrtlrect(st::mediaviewTextLeft, height() - st::mediaviewTextTop, st::mediaviewFont->width(_dateText), st::mediaviewFont->height);
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
updateHeader();
|
2017-05-18 13:22:57 +00:00
|
|
|
if (_photo || (_history && _overview != OverviewCount)) {
|
2015-11-16 16:04:37 +00:00
|
|
|
_leftNavVisible = (_index > 0) || (_index == 0 && (
|
2015-11-18 13:11:56 +00:00
|
|
|
(!_msgmigrated && _history && _history->overview[_overview].size() < _history->overviewCount(_overview)) ||
|
|
|
|
(_msgmigrated && _migrated && _migrated->overview[_overview].size() < _migrated->overviewCount(_overview)) ||
|
2016-05-20 16:01:06 +00:00
|
|
|
(!_msgmigrated && _history && _migrated && (!_migrated->overview[_overview].isEmpty() || _migrated->overviewCount(_overview) > 0)))) ||
|
|
|
|
(_index < 0 && _photo == _additionalChatPhoto &&
|
2016-06-21 14:19:24 +00:00
|
|
|
((_history && _history->overviewCount(_overview) > 0) ||
|
|
|
|
(_migrated && _history->overviewLoaded(_overview) && _migrated->overviewCount(_overview) > 0))
|
2016-05-20 16:01:06 +00:00
|
|
|
);
|
2015-04-11 10:04:10 +00:00
|
|
|
_rightNavVisible = (_index >= 0) && (
|
2015-11-16 16:04:37 +00:00
|
|
|
(!_msgmigrated && _history && _index + 1 < _history->overview[_overview].size()) ||
|
|
|
|
(_msgmigrated && _migrated && _index + 1 < _migrated->overview[_overview].size()) ||
|
2015-11-18 13:11:56 +00:00
|
|
|
(_msgmigrated && _migrated && _history && (!_history->overview[_overview].isEmpty() || _history->overviewCount(_overview) > 0)) ||
|
2016-05-20 16:01:06 +00:00
|
|
|
(!_msgmigrated && _history && _index + 1 == _history->overview[_overview].size() && _additionalChatPhoto) ||
|
|
|
|
(_msgmigrated && _migrated && _index + 1 == _migrated->overview[_overview].size() && _history->overviewCount(_overview) == 0 && _additionalChatPhoto) ||
|
2015-11-16 16:04:37 +00:00
|
|
|
(!_history && _user && (_index + 1 < _user->photos.size() || _index + 1 < _user->photosCount)));
|
2015-11-18 13:11:56 +00:00
|
|
|
if (_msgmigrated && !_history->overviewLoaded(_overview)) {
|
2015-11-16 16:04:37 +00:00
|
|
|
_leftNavVisible = _rightNavVisible = false;
|
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
} else {
|
|
|
|
_leftNavVisible = _rightNavVisible = false;
|
|
|
|
}
|
2016-07-11 18:05:46 +00:00
|
|
|
|
2015-05-20 19:28:24 +00:00
|
|
|
if (!_caption.isEmpty()) {
|
|
|
|
int32 skipw = qMax(_dateNav.left() + _dateNav.width(), _headerNav.left() + _headerNav.width());
|
2016-12-23 13:21:01 +00:00
|
|
|
int32 maxw = qMin(qMax(width() - 2 * skipw - st::mediaviewCaptionPadding.left() - st::mediaviewCaptionPadding.right() - 2 * st::mediaviewCaptionMargin.width(), int(st::msgMinWidth)), _caption.maxWidth());
|
|
|
|
int32 maxh = qMin(_caption.countHeight(maxw), int(height() / 4 - st::mediaviewCaptionPadding.top() - st::mediaviewCaptionPadding.bottom() - 2 * st::mediaviewCaptionMargin.height()));
|
|
|
|
_captionRect = QRect((width() - maxw) / 2, height() - maxh - st::mediaviewCaptionPadding.bottom() - st::mediaviewCaptionMargin.height(), maxw, maxh);
|
2015-05-20 19:28:24 +00:00
|
|
|
} else {
|
|
|
|
_captionRect = QRect();
|
|
|
|
}
|
2016-07-11 18:05:46 +00:00
|
|
|
if (_clipController) {
|
|
|
|
setClipControllerGeometry();
|
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
updateOver(mapFromGlobal(QCursor::pos()));
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2016-10-26 16:43:13 +00:00
|
|
|
void MediaView::updateActions() {
|
|
|
|
_actions.clear();
|
|
|
|
|
|
|
|
if (_doc && _doc->loading()) {
|
|
|
|
_actions.push_back({ lang(lng_cancel), SLOT(onSaveCancel()) });
|
|
|
|
}
|
|
|
|
if (_msgid > 0) {
|
|
|
|
_actions.push_back({ lang(lng_context_to_msg), SLOT(onToMessage()) });
|
|
|
|
}
|
|
|
|
if (_doc && !_doc->filepath(DocumentData::FilePathResolveChecked).isEmpty()) {
|
|
|
|
_actions.push_back({ lang((cPlatform() == dbipMac || cPlatform() == dbipMacOld) ? lng_context_show_in_finder : lng_context_show_in_folder), SLOT(onShowInFolder()) });
|
|
|
|
}
|
|
|
|
if ((_doc && fileShown()) || (_photo && _photo->loaded())) {
|
|
|
|
_actions.push_back({ lang(lng_mediaview_copy), SLOT(onCopy()) });
|
|
|
|
}
|
|
|
|
if (_canForward) {
|
|
|
|
_actions.push_back({ lang(lng_mediaview_forward), SLOT(onForward()) });
|
|
|
|
}
|
|
|
|
if (_canDelete || (_photo && App::self() && _user == App::self()) || (_photo && _photo->peer && _photo->peer->photoId == _photo->id && (_photo->peer->isChat() || (_photo->peer->isChannel() && _photo->peer->asChannel()->amCreator())))) {
|
|
|
|
_actions.push_back({ lang(lng_mediaview_delete), SLOT(onDelete()) });
|
|
|
|
}
|
|
|
|
_actions.push_back({ lang(lng_mediaview_save_as), SLOT(onSaveAs()) });
|
|
|
|
if (_history && typeHasMediaOverview(_overview)) {
|
|
|
|
_actions.push_back({ lang(_doc ? lng_mediaview_files_all : lng_mediaview_photos_all), SLOT(onOverview()) });
|
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
|
|
|
|
2016-12-01 19:20:33 +00:00
|
|
|
void MediaView::step_state(TimeMs ms, bool timer) {
|
2015-04-11 10:04:10 +00:00
|
|
|
bool result = false;
|
2014-08-11 09:03:45 +00:00
|
|
|
for (Showing::iterator i = _animations.begin(); i != _animations.end();) {
|
2016-12-01 19:20:33 +00:00
|
|
|
TimeMs start = i.value();
|
2014-08-11 09:03:45 +00:00
|
|
|
switch (i.key()) {
|
|
|
|
case OverLeftNav: update(_leftNav); break;
|
|
|
|
case OverRightNav: update(_rightNav); break;
|
|
|
|
case OverName: update(_nameNav); break;
|
|
|
|
case OverDate: update(_dateNav); break;
|
2015-04-11 10:04:10 +00:00
|
|
|
case OverHeader: update(_headerNav); break;
|
|
|
|
case OverClose: update(_closeNav); break;
|
|
|
|
case OverSave: update(_saveNav); break;
|
2015-04-19 10:29:19 +00:00
|
|
|
case OverIcon: update(_docIconRect); break;
|
2015-04-11 10:04:10 +00:00
|
|
|
case OverMore: update(_moreNav); break;
|
2014-08-11 09:03:45 +00:00
|
|
|
default: break;
|
|
|
|
}
|
2016-12-23 13:21:01 +00:00
|
|
|
float64 dt = float64(ms - start) / st::mediaviewFadeDuration;
|
2014-08-11 09:03:45 +00:00
|
|
|
if (dt >= 1) {
|
|
|
|
_animOpacities.remove(i.key());
|
|
|
|
i = _animations.erase(i);
|
|
|
|
} else {
|
|
|
|
_animOpacities[i.key()].update(dt, anim::linear);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
if (_controlsState == ControlsShowing || _controlsState == ControlsHiding) {
|
2016-12-23 13:21:01 +00:00
|
|
|
float64 dt = float64(ms - _controlsAnimStarted) / (_controlsState == ControlsShowing ? st::mediaviewShowDuration : st::mediaviewHideDuration);
|
2015-04-11 10:04:10 +00:00
|
|
|
if (dt >= 1) {
|
|
|
|
a_cOpacity.finish();
|
|
|
|
_controlsState = (_controlsState == ControlsShowing ? ControlsShown : ControlsHidden);
|
2016-07-24 08:53:09 +00:00
|
|
|
updateCursor();
|
2015-04-11 10:04:10 +00:00
|
|
|
} else {
|
|
|
|
a_cOpacity.update(dt, anim::linear);
|
|
|
|
}
|
2016-12-23 13:21:01 +00:00
|
|
|
QRegion toUpdate = QRegion() + (_over == OverLeftNav ? _leftNav : _leftNavIcon) + (_over == OverRightNav ? _rightNav : _rightNavIcon) + (_over == OverClose ? _closeNav : _closeNavIcon) + _saveNavIcon + _moreNavIcon + _headerNav + _nameNav + _dateNav + _captionRect.marginsAdded(st::mediaviewCaptionPadding);
|
2015-04-19 19:01:45 +00:00
|
|
|
update(toUpdate);
|
2015-04-11 10:04:10 +00:00
|
|
|
if (dt < 1) result = true;
|
|
|
|
}
|
2015-12-24 19:26:28 +00:00
|
|
|
if (!result && _animations.isEmpty()) {
|
|
|
|
_a_state.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-24 08:53:09 +00:00
|
|
|
void MediaView::updateCursor() {
|
|
|
|
setCursor(_controlsState == ControlsHidden ? Qt::BlankCursor : (_over == OverNone ? style::cur_default : style::cur_pointer));
|
|
|
|
}
|
|
|
|
|
2016-06-21 18:09:48 +00:00
|
|
|
float64 MediaView::radialProgress() const {
|
|
|
|
if (_doc) {
|
|
|
|
return _doc->progress();
|
|
|
|
} else if (_photo) {
|
|
|
|
return _photo->full->progress();
|
|
|
|
}
|
|
|
|
return 1.;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MediaView::radialLoading() const {
|
|
|
|
if (_doc) {
|
|
|
|
return _doc->loading();
|
|
|
|
} else if (_photo) {
|
|
|
|
return _photo->full->loading();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect MediaView::radialRect() const {
|
|
|
|
if (_doc) {
|
|
|
|
return _docIconRect;
|
|
|
|
} else if (_photo) {
|
|
|
|
return _photoRadialRect;
|
|
|
|
}
|
|
|
|
return QRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::radialStart() {
|
|
|
|
if (radialLoading() && !_radial.animating()) {
|
|
|
|
_radial.start(radialProgress());
|
|
|
|
if (auto shift = radialTimeShift()) {
|
|
|
|
_radial.update(radialProgress(), !radialLoading(), getms() + shift);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-01 19:20:33 +00:00
|
|
|
TimeMs MediaView::radialTimeShift() const {
|
2016-06-21 18:09:48 +00:00
|
|
|
return _photo ? st::radialDuration : 0;
|
|
|
|
}
|
|
|
|
|
2016-12-01 19:20:33 +00:00
|
|
|
void MediaView::step_radial(TimeMs ms, bool timer) {
|
2016-06-21 18:09:48 +00:00
|
|
|
if (!_doc && !_photo) {
|
|
|
|
_radial.stop();
|
2015-12-24 19:26:28 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-10-28 08:02:45 +00:00
|
|
|
auto wasAnimating = _radial.animating();
|
2016-06-21 18:09:48 +00:00
|
|
|
_radial.update(radialProgress(), !radialLoading(), ms + radialTimeShift());
|
2016-10-28 08:02:45 +00:00
|
|
|
if (timer && (wasAnimating || _radial.animating())) {
|
2016-06-21 18:09:48 +00:00
|
|
|
update(radialRect());
|
2015-12-24 19:26:28 +00:00
|
|
|
}
|
2016-11-28 15:45:07 +00:00
|
|
|
if (_doc && _doc->loaded() && _doc->size < App::kImageSizeLimit && (!_radial.animating() || _doc->isAnimation() || _doc->isVideo())) {
|
2017-04-02 16:42:18 +00:00
|
|
|
if (_doc->isVideo() || _doc->isRoundVideo()) {
|
2016-07-19 10:54:43 +00:00
|
|
|
_autoplayVideoDocument = _doc;
|
|
|
|
}
|
2016-06-24 10:37:29 +00:00
|
|
|
if (!_doc->data().isEmpty() && (_doc->isAnimation() || _doc->isVideo())) {
|
2015-12-24 19:26:28 +00:00
|
|
|
displayDocument(_doc, App::histItemById(_msgmigrated ? 0 : _channel, _msgid));
|
|
|
|
} else {
|
2017-04-02 10:25:54 +00:00
|
|
|
auto &location = _doc->location(true);
|
2015-12-24 19:26:28 +00:00
|
|
|
if (location.accessEnable()) {
|
2016-12-23 13:21:01 +00:00
|
|
|
if (_doc->isAnimation() || _doc->isVideo() || _doc->isTheme() || QImageReader(location.name()).canRead()) {
|
2015-12-23 19:23:14 +00:00
|
|
|
displayDocument(_doc, App::histItemById(_msgmigrated ? 0 : _channel, _msgid));
|
2015-04-19 10:29:19 +00:00
|
|
|
}
|
2015-12-24 19:26:28 +00:00
|
|
|
location.accessDisable();
|
2015-04-19 10:29:19 +00:00
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
2015-12-08 12:33:37 +00:00
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
|
2016-08-18 15:35:39 +00:00
|
|
|
void MediaView::zoomIn() {
|
|
|
|
int32 newZoom = _zoom;
|
|
|
|
if (newZoom == ZoomToScreenLevel) {
|
|
|
|
if (qCeil(_zoomToScreen) <= MaxZoomLevel) {
|
|
|
|
newZoom = qCeil(_zoomToScreen);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (newZoom < _zoomToScreen && (newZoom + 1 > _zoomToScreen || (_zoomToScreen > MaxZoomLevel && newZoom == MaxZoomLevel))) {
|
|
|
|
newZoom = ZoomToScreenLevel;
|
|
|
|
} else if (newZoom < MaxZoomLevel) {
|
|
|
|
++newZoom;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
zoomUpdate(newZoom);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::zoomOut() {
|
|
|
|
int32 newZoom = _zoom;
|
|
|
|
if (newZoom == ZoomToScreenLevel) {
|
|
|
|
if (qFloor(_zoomToScreen) >= -MaxZoomLevel) {
|
|
|
|
newZoom = qFloor(_zoomToScreen);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (newZoom > _zoomToScreen && (newZoom - 1 < _zoomToScreen || (_zoomToScreen < -MaxZoomLevel && newZoom == -MaxZoomLevel))) {
|
|
|
|
newZoom = ZoomToScreenLevel;
|
|
|
|
} else if (newZoom > -MaxZoomLevel) {
|
|
|
|
--newZoom;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
zoomUpdate(newZoom);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::zoomReset() {
|
|
|
|
int32 newZoom = _zoom;
|
|
|
|
if (_zoom == 0) {
|
|
|
|
if (qFloor(_zoomToScreen) == qCeil(_zoomToScreen) && qRound(_zoomToScreen) >= -MaxZoomLevel && qRound(_zoomToScreen) <= MaxZoomLevel) {
|
|
|
|
newZoom = qRound(_zoomToScreen);
|
|
|
|
} else {
|
|
|
|
newZoom = ZoomToScreenLevel;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
newZoom = 0;
|
|
|
|
}
|
|
|
|
_x = -_width / 2;
|
|
|
|
_y = -((gifShown() ? _gif->height() : (_current.height() / cIntRetinaFactor())) / 2);
|
|
|
|
float64 z = (_zoom == ZoomToScreenLevel) ? _zoomToScreen : _zoom;
|
|
|
|
if (z >= 0) {
|
|
|
|
_x = qRound(_x * (z + 1));
|
|
|
|
_y = qRound(_y * (z + 1));
|
|
|
|
} else {
|
|
|
|
_x = qRound(_x / (-z + 1));
|
|
|
|
_y = qRound(_y / (-z + 1));
|
|
|
|
}
|
|
|
|
_x += width() / 2;
|
|
|
|
_y += height() / 2;
|
|
|
|
update();
|
|
|
|
zoomUpdate(newZoom);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::zoomUpdate(int32 &newZoom) {
|
|
|
|
if (newZoom != ZoomToScreenLevel) {
|
|
|
|
while ((newZoom < 0 && (-newZoom + 1) > _w) || (-newZoom + 1) > _h) {
|
|
|
|
++newZoom;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setZoomLevel(newZoom);
|
|
|
|
}
|
|
|
|
|
2016-06-26 15:37:47 +00:00
|
|
|
void MediaView::clearData() {
|
|
|
|
if (!isHidden()) {
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
if (!_animations.isEmpty()) {
|
|
|
|
_animations.clear();
|
|
|
|
_a_state.stop();
|
|
|
|
}
|
|
|
|
if (!_animOpacities.isEmpty()) _animOpacities.clear();
|
2016-07-05 17:44:22 +00:00
|
|
|
stopGif();
|
2016-06-26 15:37:47 +00:00
|
|
|
delete _menu;
|
|
|
|
_menu = nullptr;
|
|
|
|
_history = _migrated = nullptr;
|
|
|
|
_peer = _from = nullptr;
|
|
|
|
_user = nullptr;
|
|
|
|
_photo = _additionalChatPhoto = nullptr;
|
|
|
|
_doc = nullptr;
|
2016-07-14 11:20:46 +00:00
|
|
|
_fullScreenVideo = false;
|
2016-06-26 15:37:47 +00:00
|
|
|
_caption.clear();
|
|
|
|
}
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
MediaView::~MediaView() {
|
2016-10-07 16:45:45 +00:00
|
|
|
delete base::take(_menu);
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
|
2016-03-29 17:17:00 +00:00
|
|
|
void MediaView::clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) {
|
|
|
|
setCursor((active || ClickHandler::getPressed()) ? style::cur_pointer : style::cur_default);
|
|
|
|
update(QRegion(_saveMsg) + _captionRect);
|
|
|
|
}
|
2016-07-24 08:53:09 +00:00
|
|
|
|
2016-03-29 17:17:00 +00:00
|
|
|
void MediaView::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) {
|
|
|
|
setCursor((pressed || ClickHandler::getActive()) ? style::cur_pointer : style::cur_default);
|
|
|
|
update(QRegion(_saveMsg) + _captionRect);
|
|
|
|
}
|
|
|
|
|
2014-10-17 12:57:14 +00:00
|
|
|
void MediaView::showSaveMsgFile() {
|
2017-02-28 14:05:30 +00:00
|
|
|
File::ShowInFolder(_saveMsgFilename);
|
2014-10-17 12:57:14 +00:00
|
|
|
}
|
|
|
|
|
2017-04-15 19:51:53 +00:00
|
|
|
void MediaView::updateMixerVideoVolume() const {
|
|
|
|
if (_doc && (_doc->isVideo() || _doc->isRoundVideo())) {
|
|
|
|
Media::Player::mixer()->setVideoVolume(Global::VideoVolume());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
void MediaView::close() {
|
2015-11-01 18:14:30 +00:00
|
|
|
if (_menu) _menu->hideMenu(true);
|
2015-09-16 13:04:08 +00:00
|
|
|
if (App::wnd()) {
|
2015-12-07 18:09:05 +00:00
|
|
|
Ui::hideLayer(true);
|
2015-09-16 13:04:08 +00:00
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
void MediaView::activateControls() {
|
2016-07-14 11:20:46 +00:00
|
|
|
if (!_menu && !_mousePressed) {
|
2016-12-23 13:21:01 +00:00
|
|
|
_controlsHideTimer.start(int(st::mediaviewWaitHide));
|
2016-07-12 14:11:59 +00:00
|
|
|
}
|
2016-07-14 11:20:46 +00:00
|
|
|
if (_fullScreenVideo) {
|
|
|
|
if (_clipController) {
|
|
|
|
_clipController->showAnimated();
|
|
|
|
}
|
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
if (_controlsState == ControlsHiding || _controlsState == ControlsHidden) {
|
|
|
|
_controlsState = ControlsShowing;
|
|
|
|
_controlsAnimStarted = getms();
|
|
|
|
a_cOpacity.start(1);
|
2015-12-08 12:33:37 +00:00
|
|
|
if (!_a_state.animating()) _a_state.start();
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::onHideControls(bool force) {
|
2016-07-14 11:20:46 +00:00
|
|
|
if (!force) {
|
2016-10-26 16:43:13 +00:00
|
|
|
if (!_dropdown->isHidden()
|
2016-07-14 11:20:46 +00:00
|
|
|
|| _menu
|
|
|
|
|| _mousePressed
|
|
|
|
|| (_fullScreenVideo && _clipController && _clipController->geometry().contains(_lastMouseMovePos))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_fullScreenVideo) {
|
|
|
|
if (_clipController) {
|
|
|
|
_clipController->hideAnimated();
|
|
|
|
}
|
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
if (_controlsState == ControlsHiding || _controlsState == ControlsHidden) return;
|
2016-07-14 11:20:46 +00:00
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
_controlsState = ControlsHiding;
|
|
|
|
_controlsAnimStarted = getms();
|
|
|
|
a_cOpacity.start(0);
|
2015-12-08 12:33:37 +00:00
|
|
|
if (!_a_state.animating()) _a_state.start();
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
|
|
|
|
2016-11-05 08:36:24 +00:00
|
|
|
void MediaView::dropdownHidden() {
|
2015-04-11 10:04:10 +00:00
|
|
|
setFocus();
|
|
|
|
_ignoringDropdown = true;
|
|
|
|
_lastMouseMovePos = mapFromGlobal(QCursor::pos());
|
|
|
|
updateOver(_lastMouseMovePos);
|
|
|
|
_ignoringDropdown = false;
|
|
|
|
if (!_controlsHideTimer.isActive()) {
|
|
|
|
onHideControls(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-22 13:39:54 +00:00
|
|
|
void MediaView::onScreenResized(int screen) {
|
|
|
|
if (isHidden()) return;
|
|
|
|
|
|
|
|
bool ignore = false;
|
|
|
|
auto screens = QApplication::screens();
|
|
|
|
if (screen >= 0 && screen < screens.size()) {
|
|
|
|
if (auto screenHandle = windowHandle()->screen()) {
|
|
|
|
if (screens.at(screen) != screenHandle) {
|
|
|
|
ignore = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!ignore) {
|
|
|
|
moveToScreen();
|
|
|
|
auto item = (_msgid ? App::histItemById(_msgmigrated ? 0 : _channel, _msgid) : nullptr);
|
|
|
|
if (_photo) {
|
|
|
|
displayPhoto(_photo, item);
|
|
|
|
} else if (_doc) {
|
|
|
|
displayDocument(_doc, item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
void MediaView::onToMessage() {
|
2015-11-16 16:04:37 +00:00
|
|
|
if (HistoryItem *item = _msgid ? App::histItemById(_msgmigrated ? 0 : _channel, _msgid) : 0) {
|
2015-04-11 10:04:10 +00:00
|
|
|
if (App::wnd()) {
|
|
|
|
close();
|
2015-12-13 11:36:08 +00:00
|
|
|
Ui::showPeerHistoryAtItem(item);
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-19 10:29:19 +00:00
|
|
|
void MediaView::onSaveAs() {
|
2014-10-17 12:57:14 +00:00
|
|
|
QString file;
|
2014-10-07 17:57:57 +00:00
|
|
|
if (_doc) {
|
2015-11-26 17:34:52 +00:00
|
|
|
const FileLocation &location(_doc->location(true));
|
2015-12-24 19:26:28 +00:00
|
|
|
if (!_doc->data().isEmpty() || location.accessEnable()) {
|
2015-11-26 17:34:52 +00:00
|
|
|
QFileInfo alreadyInfo(location.name());
|
|
|
|
QDir alreadyDir(alreadyInfo.dir());
|
|
|
|
QString name = alreadyInfo.fileName(), filter;
|
|
|
|
MimeType mimeType = mimeTypeForName(_doc->mime);
|
|
|
|
QStringList p = mimeType.globPatterns();
|
|
|
|
QString pattern = p.isEmpty() ? QString() : p.front();
|
|
|
|
if (name.isEmpty()) {
|
|
|
|
name = pattern.isEmpty() ? qsl(".unknown") : pattern.replace('*', QString());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pattern.isEmpty()) {
|
|
|
|
filter = QString();
|
|
|
|
} else {
|
2017-02-28 15:43:03 +00:00
|
|
|
filter = mimeType.filterString() + qsl(";;") + FileDialog::AllFilesFilter();
|
2015-11-26 17:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
psBringToBack(this);
|
|
|
|
file = saveFileName(lang(lng_save_file), filter, qsl("doc"), name, true, alreadyDir);
|
|
|
|
psShowOverAll(this);
|
|
|
|
if (!file.isEmpty() && file != location.name()) {
|
2015-12-24 19:26:28 +00:00
|
|
|
if (_doc->data().isEmpty()) {
|
2015-12-23 19:23:14 +00:00
|
|
|
QFile(location.name()).copy(file);
|
|
|
|
} else {
|
|
|
|
QFile f(file);
|
|
|
|
f.open(QIODevice::WriteOnly);
|
2015-12-24 19:26:28 +00:00
|
|
|
f.write(_doc->data());
|
2015-12-23 19:23:14 +00:00
|
|
|
}
|
2015-11-26 17:34:52 +00:00
|
|
|
}
|
|
|
|
|
2015-12-24 19:26:28 +00:00
|
|
|
if (_doc->data().isEmpty()) location.accessDisable();
|
2015-11-26 17:34:52 +00:00
|
|
|
} else {
|
2015-12-22 08:01:02 +00:00
|
|
|
if (!fileShown()) {
|
2016-03-29 17:17:00 +00:00
|
|
|
DocumentSaveClickHandler::doSave(_doc, true);
|
2015-04-19 10:29:19 +00:00
|
|
|
updateControls();
|
|
|
|
} else {
|
|
|
|
_saveVisible = false;
|
|
|
|
update(_saveNav);
|
|
|
|
}
|
|
|
|
updateOver(_lastMouseMovePos);
|
2014-10-07 17:57:57 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-12-25 13:09:14 +00:00
|
|
|
if (!_photo || !_photo->loaded()) return;
|
2014-08-11 09:03:45 +00:00
|
|
|
|
2014-10-17 12:57:14 +00:00
|
|
|
psBringToBack(this);
|
2017-02-28 15:43:03 +00:00
|
|
|
auto filter = qsl("JPEG Image (*.jpg);;") + FileDialog::AllFilesFilter();
|
2017-04-04 09:14:32 +00:00
|
|
|
FileDialog::GetWritePath(lang(lng_save_photo), filter, filedialogDefaultName(qsl("photo"), qsl(".jpg"), QString(), false, _photo->date), base::lambda_guarded(this, [this, photo = _photo](const QString &result) {
|
2017-02-28 15:43:03 +00:00
|
|
|
if (!result.isEmpty() && _photo == photo && photo->loaded()) {
|
|
|
|
photo->full->pix().toImage().save(result, "JPG");
|
2014-10-07 17:57:57 +00:00
|
|
|
}
|
2017-02-28 15:43:03 +00:00
|
|
|
psShowOverAll(this);
|
|
|
|
}), base::lambda_guarded(this, [this] {
|
|
|
|
psShowOverAll(this);
|
|
|
|
}));
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
2015-11-16 16:04:37 +00:00
|
|
|
activateWindow();
|
2016-02-08 14:54:55 +00:00
|
|
|
Sandbox::setActiveWindow(this);
|
2015-11-16 16:04:37 +00:00
|
|
|
setFocus();
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
|
2015-04-19 10:29:19 +00:00
|
|
|
void MediaView::onDocClick() {
|
2015-12-24 19:26:28 +00:00
|
|
|
if (_doc->loading()) {
|
2015-12-23 21:19:57 +00:00
|
|
|
onSaveCancel();
|
2015-04-19 10:29:19 +00:00
|
|
|
} else {
|
2016-10-12 19:34:25 +00:00
|
|
|
DocumentOpenClickHandler::doOpen(_doc, nullptr, ActionOnLoadNone);
|
2016-06-21 18:09:48 +00:00
|
|
|
if (_doc->loading() && !_radial.animating()) {
|
|
|
|
_radial.start(_doc->progress());
|
2015-12-24 19:26:28 +00:00
|
|
|
}
|
2015-04-19 10:29:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-24 10:37:29 +00:00
|
|
|
void MediaView::clipCallback(Media::Clip::Notification notification) {
|
|
|
|
using namespace Media::Clip;
|
|
|
|
|
2015-12-28 21:20:04 +00:00
|
|
|
if (!_gif) return;
|
2015-12-22 08:01:02 +00:00
|
|
|
|
2015-12-28 21:20:04 +00:00
|
|
|
switch (notification) {
|
2016-06-24 10:37:29 +00:00
|
|
|
case NotificationReinit: {
|
2016-07-12 12:28:07 +00:00
|
|
|
if (auto item = App::histItemById(_msgmigrated ? 0 : _channel, _msgid)) {
|
2016-06-24 10:37:29 +00:00
|
|
|
if (_gif->state() == State::Error) {
|
2016-07-26 12:09:40 +00:00
|
|
|
stopGif();
|
|
|
|
updateControls();
|
|
|
|
update();
|
|
|
|
break;
|
2016-07-12 18:04:34 +00:00
|
|
|
} else if (_gif->state() == State::Finished) {
|
|
|
|
_videoPositionMs = _videoDurationMs;
|
2016-07-14 11:20:46 +00:00
|
|
|
_videoStopped = true;
|
2016-07-12 18:04:34 +00:00
|
|
|
updateSilentVideoPlaybackState();
|
|
|
|
} else {
|
2017-04-12 20:34:57 +00:00
|
|
|
_videoIsSilent = _doc && (_doc->isVideo() || _doc->isRoundVideo()) && !_gif->hasAudio();
|
2016-07-12 12:28:07 +00:00
|
|
|
_videoDurationMs = _gif->getDurationMs();
|
|
|
|
_videoPositionMs = _gif->getPositionMs();
|
2016-07-12 18:04:34 +00:00
|
|
|
if (_videoIsSilent) {
|
|
|
|
updateSilentVideoPlaybackState();
|
|
|
|
}
|
2016-07-12 12:28:07 +00:00
|
|
|
}
|
2015-12-22 08:01:02 +00:00
|
|
|
displayDocument(_doc, item);
|
|
|
|
} else {
|
2015-12-23 19:23:14 +00:00
|
|
|
stopGif();
|
2016-07-14 11:20:46 +00:00
|
|
|
updateControls();
|
|
|
|
update();
|
2015-12-22 08:01:02 +00:00
|
|
|
}
|
2015-12-28 21:20:04 +00:00
|
|
|
} break;
|
|
|
|
|
2016-06-24 10:37:29 +00:00
|
|
|
case NotificationRepaint: {
|
2015-12-28 21:20:04 +00:00
|
|
|
if (!_gif->currentDisplayed()) {
|
2016-07-12 18:04:34 +00:00
|
|
|
_videoPositionMs = _gif->getPositionMs();
|
2016-07-12 12:28:07 +00:00
|
|
|
if (_videoIsSilent) {
|
|
|
|
updateSilentVideoPlaybackState();
|
|
|
|
}
|
2015-12-28 21:20:04 +00:00
|
|
|
update(_x, _y, _w, _h);
|
|
|
|
}
|
|
|
|
} break;
|
2015-12-22 08:01:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 17:17:00 +00:00
|
|
|
PeerData *MediaView::ui_getPeerForMouseAction() {
|
|
|
|
return _history ? _history->peer : nullptr;
|
|
|
|
}
|
|
|
|
|
2014-10-17 12:57:14 +00:00
|
|
|
void MediaView::onDownload() {
|
2016-08-27 04:49:18 +00:00
|
|
|
if (Global::AskDownloadPath()) {
|
2015-04-19 10:29:19 +00:00
|
|
|
return onSaveAs();
|
2014-10-17 12:57:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString path;
|
2016-08-27 04:49:18 +00:00
|
|
|
if (Global::DownloadPath().isEmpty()) {
|
2014-10-17 12:57:14 +00:00
|
|
|
path = psDownloadPath();
|
2016-08-27 04:49:18 +00:00
|
|
|
} else if (Global::DownloadPath() == qsl("tmp")) {
|
2014-10-17 12:57:14 +00:00
|
|
|
path = cTempDir();
|
|
|
|
} else {
|
2016-08-27 04:49:18 +00:00
|
|
|
path = Global::DownloadPath();
|
2014-10-17 12:57:14 +00:00
|
|
|
}
|
|
|
|
QString toName;
|
|
|
|
if (_doc) {
|
2015-11-26 17:34:52 +00:00
|
|
|
const FileLocation &location(_doc->location(true));
|
|
|
|
if (location.accessEnable()) {
|
|
|
|
if (!QDir().exists(path)) QDir().mkpath(path);
|
|
|
|
toName = filedialogNextFilename(_doc->name, location.name(), path);
|
|
|
|
if (toName != location.name() && !QFile(location.name()).copy(toName)) {
|
|
|
|
toName = QString();
|
|
|
|
}
|
|
|
|
location.accessDisable();
|
|
|
|
} else {
|
2015-12-22 08:01:02 +00:00
|
|
|
if (!fileShown()) {
|
2016-03-29 17:17:00 +00:00
|
|
|
DocumentSaveClickHandler::doSave(_doc);
|
2015-04-19 10:29:19 +00:00
|
|
|
updateControls();
|
|
|
|
} else {
|
|
|
|
_saveVisible = false;
|
|
|
|
update(_saveNav);
|
|
|
|
}
|
|
|
|
updateOver(_lastMouseMovePos);
|
2014-10-17 12:57:14 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-12-25 13:09:14 +00:00
|
|
|
if (!_photo || !_photo->loaded()) {
|
2015-04-11 10:04:10 +00:00
|
|
|
_saveVisible = false;
|
|
|
|
update(_saveNav);
|
2014-10-17 12:57:14 +00:00
|
|
|
} else {
|
2014-11-24 07:54:06 +00:00
|
|
|
if (!QDir().exists(path)) QDir().mkpath(path);
|
2014-10-17 12:57:14 +00:00
|
|
|
toName = filedialogDefaultName(qsl("photo"), qsl(".jpg"), path);
|
|
|
|
if (!_photo->full->pix().toImage().save(toName, "JPG")) {
|
|
|
|
toName = QString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!toName.isEmpty()) {
|
|
|
|
_saveMsgFilename = toName;
|
|
|
|
_saveMsgStarted = getms();
|
|
|
|
_saveMsgOpacity.start(1);
|
|
|
|
updateImage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-19 10:29:19 +00:00
|
|
|
void MediaView::onSaveCancel() {
|
2015-12-24 19:26:28 +00:00
|
|
|
if (_doc && _doc->loading()) {
|
|
|
|
_doc->cancel();
|
2015-04-19 10:29:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-07 17:57:57 +00:00
|
|
|
void MediaView::onShowInFolder() {
|
2015-04-11 10:04:10 +00:00
|
|
|
if (!_doc) return;
|
2016-03-16 11:54:37 +00:00
|
|
|
|
2017-02-28 14:05:30 +00:00
|
|
|
auto filepath = _doc->filepath(DocumentData::FilePathResolveChecked);
|
2016-03-16 11:54:37 +00:00
|
|
|
if (!filepath.isEmpty()) {
|
2017-02-28 14:05:30 +00:00
|
|
|
File::ShowInFolder(filepath);
|
2016-03-16 11:54:37 +00:00
|
|
|
}
|
2014-10-07 17:57:57 +00:00
|
|
|
}
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
void MediaView::onForward() {
|
2015-11-16 16:04:37 +00:00
|
|
|
HistoryItem *item = App::histItemById(_msgmigrated ? 0 : _channel, _msgid);
|
2014-08-11 09:03:45 +00:00
|
|
|
if (!_msgid || !item) return;
|
|
|
|
|
|
|
|
if (App::wnd()) {
|
2015-04-11 10:04:10 +00:00
|
|
|
close();
|
2014-08-11 09:03:45 +00:00
|
|
|
if (App::main()) {
|
|
|
|
App::contextItem(item);
|
|
|
|
App::main()->forwardLayer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::onDelete() {
|
2015-04-11 10:04:10 +00:00
|
|
|
close();
|
2016-06-22 13:39:54 +00:00
|
|
|
auto deletingPeerPhoto = [this]() {
|
|
|
|
if (!_msgid) return true;
|
|
|
|
if (_photo && _history) {
|
|
|
|
auto lastPhoto = computeLastOverviewChatPhoto();
|
|
|
|
if (lastPhoto.photo == _photo && _history->peer->photoId == _photo->id) {
|
|
|
|
return _firstOpenedPeerPhoto;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (deletingPeerPhoto()) {
|
2016-06-14 16:26:41 +00:00
|
|
|
App::main()->deletePhotoLayer(_photo);
|
|
|
|
} else if (auto item = App::histItemById(_msgmigrated ? 0 : _channel, _msgid)) {
|
|
|
|
App::contextItem(item);
|
|
|
|
App::main()->deleteLayer();
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-17 12:57:14 +00:00
|
|
|
void MediaView::onOverview() {
|
2015-11-01 18:14:30 +00:00
|
|
|
if (_menu) _menu->hideMenu(true);
|
2016-05-20 16:01:06 +00:00
|
|
|
if (!_history || !typeHasMediaOverview(_overview)) {
|
2015-04-11 10:04:10 +00:00
|
|
|
update();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
close();
|
|
|
|
if (_history->peer) App::main()->showMediaOverview(_history->peer, _overview);
|
2014-10-17 12:57:14 +00:00
|
|
|
}
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
void MediaView::onCopy() {
|
2016-10-26 16:43:13 +00:00
|
|
|
_dropdown->hideAnimated(Ui::DropdownMenu::HideOption::IgnoreShow);
|
2014-10-07 17:57:57 +00:00
|
|
|
if (_doc) {
|
2015-10-06 19:49:23 +00:00
|
|
|
if (!_current.isNull()) {
|
|
|
|
QApplication::clipboard()->setPixmap(_current);
|
2015-12-22 08:01:02 +00:00
|
|
|
} else if (gifShown()) {
|
2015-12-31 20:07:41 +00:00
|
|
|
QApplication::clipboard()->setPixmap(_gif->frameOriginal());
|
2015-10-06 19:49:23 +00:00
|
|
|
}
|
2014-10-07 17:57:57 +00:00
|
|
|
} else {
|
2015-12-25 13:09:14 +00:00
|
|
|
if (!_photo || !_photo->loaded()) return;
|
2014-08-11 09:03:45 +00:00
|
|
|
|
2014-10-07 17:57:57 +00:00
|
|
|
QApplication::clipboard()->setPixmap(_photo->full->pix());
|
|
|
|
}
|
2014-08-06 14:40:21 +00:00
|
|
|
}
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
void MediaView::showPhoto(PhotoData *photo, HistoryItem *context) {
|
2016-05-20 16:01:06 +00:00
|
|
|
_history = context ? context->history() : nullptr;
|
2016-06-26 15:37:47 +00:00
|
|
|
_migrated = nullptr;
|
2015-11-16 16:04:37 +00:00
|
|
|
if (_history) {
|
|
|
|
if (_history->peer->migrateFrom()) {
|
|
|
|
_migrated = App::history(_history->peer->migrateFrom()->id);
|
|
|
|
} else if (_history->peer->migrateTo()) {
|
|
|
|
_migrated = _history;
|
|
|
|
_history = App::history(_history->peer->migrateTo()->id);
|
|
|
|
}
|
|
|
|
}
|
2016-05-20 16:01:06 +00:00
|
|
|
_additionalChatPhoto = nullptr;
|
2016-06-22 13:39:54 +00:00
|
|
|
_firstOpenedPeerPhoto = false;
|
2014-08-11 09:03:45 +00:00
|
|
|
_peer = 0;
|
|
|
|
_user = 0;
|
2014-10-17 12:57:14 +00:00
|
|
|
_saveMsgStarted = 0;
|
2014-08-11 09:03:45 +00:00
|
|
|
_loadRequest = 0;
|
|
|
|
_over = OverNone;
|
2014-10-07 17:57:57 +00:00
|
|
|
_pressed = false;
|
|
|
|
_dragging = 0;
|
|
|
|
setCursor(style::cur_default);
|
2014-08-11 09:03:45 +00:00
|
|
|
if (!_animations.isEmpty()) {
|
|
|
|
_animations.clear();
|
2015-12-08 12:33:37 +00:00
|
|
|
_a_state.stop();
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
if (!_animOpacities.isEmpty()) _animOpacities.clear();
|
|
|
|
|
|
|
|
_index = -1;
|
2014-08-15 11:19:32 +00:00
|
|
|
_msgid = context ? context->id : 0;
|
2015-11-16 16:04:37 +00:00
|
|
|
_msgmigrated = context ? (context->history() == _migrated) : false;
|
|
|
|
_channel = _history ? _history->channelId() : NoChannel;
|
2015-09-21 20:57:42 +00:00
|
|
|
_canForward = _msgid > 0;
|
|
|
|
_canDelete = context ? context->canDelete() : false;
|
2014-10-17 12:57:14 +00:00
|
|
|
_photo = photo;
|
2014-08-21 12:18:56 +00:00
|
|
|
if (_history) {
|
2016-05-20 16:01:06 +00:00
|
|
|
if (context && !context->toHistoryMessage()) {
|
|
|
|
_overview = OverviewChatPhotos;
|
|
|
|
if (!_history->peer->isUser()) {
|
|
|
|
computeAdditionalChatPhoto(_history->peer, computeLastOverviewChatPhoto().photo);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_overview = OverviewPhotos;
|
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
findCurrent();
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
|
2015-05-20 19:28:24 +00:00
|
|
|
displayPhoto(photo, context);
|
2015-04-11 10:04:10 +00:00
|
|
|
preloadData(0);
|
|
|
|
activateControls();
|
2014-08-06 14:40:21 +00:00
|
|
|
}
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
void MediaView::showPhoto(PhotoData *photo, PeerData *context) {
|
2016-05-20 16:01:06 +00:00
|
|
|
_history = _migrated = nullptr;
|
|
|
|
_additionalChatPhoto = nullptr;
|
2016-06-22 13:39:54 +00:00
|
|
|
_firstOpenedPeerPhoto = true;
|
2014-08-11 09:03:45 +00:00
|
|
|
_peer = context;
|
2015-09-03 10:48:40 +00:00
|
|
|
_user = context->asUser();
|
2014-10-17 12:57:14 +00:00
|
|
|
_saveMsgStarted = 0;
|
2014-08-11 09:03:45 +00:00
|
|
|
_loadRequest = 0;
|
|
|
|
_over = OverNone;
|
2014-12-15 15:55:45 +00:00
|
|
|
setCursor(style::cur_default);
|
2014-08-11 09:03:45 +00:00
|
|
|
if (!_animations.isEmpty()) {
|
|
|
|
_animations.clear();
|
2015-12-08 12:33:37 +00:00
|
|
|
_a_state.stop();
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
if (!_animOpacities.isEmpty()) _animOpacities.clear();
|
|
|
|
|
|
|
|
_msgid = 0;
|
2015-11-16 16:04:37 +00:00
|
|
|
_msgmigrated = false;
|
2015-09-03 10:48:40 +00:00
|
|
|
_channel = NoChannel;
|
2015-09-07 07:52:37 +00:00
|
|
|
_canForward = _canDelete = false;
|
2014-08-11 09:03:45 +00:00
|
|
|
_index = -1;
|
2014-10-17 12:57:14 +00:00
|
|
|
_photo = photo;
|
2015-04-11 10:04:10 +00:00
|
|
|
_overview = OverviewCount;
|
2014-08-11 09:03:45 +00:00
|
|
|
if (_user) {
|
2015-06-29 22:09:23 +00:00
|
|
|
if (_user->photos.isEmpty() && _user->photosCount < 0 && _user->photoId && _user->photoId != UnknownPeerPhotoId) {
|
2014-08-11 09:03:45 +00:00
|
|
|
_index = 0;
|
|
|
|
}
|
|
|
|
for (int i = 0, l = _user->photos.size(); i < l; ++i) {
|
|
|
|
if (_user->photos.at(i) == photo) {
|
|
|
|
_index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_user->photosCount < 0) {
|
2015-04-11 10:04:10 +00:00
|
|
|
loadBack();
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
2016-05-20 16:01:06 +00:00
|
|
|
} else if ((_history = App::historyLoaded(_peer))) {
|
|
|
|
if (_history->peer->migrateFrom()) {
|
|
|
|
_migrated = App::history(_history->peer->migrateFrom()->id);
|
|
|
|
} else if (_history->peer->migrateTo()) {
|
|
|
|
_migrated = _history;
|
|
|
|
_history = App::history(_history->peer->migrateTo()->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto lastChatPhoto = computeLastOverviewChatPhoto();
|
|
|
|
if (_photo == lastChatPhoto.photo) {
|
2016-06-22 13:39:54 +00:00
|
|
|
showPhoto(_photo, lastChatPhoto.item);
|
|
|
|
_firstOpenedPeerPhoto = true;
|
|
|
|
return;
|
2016-05-20 16:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
computeAdditionalChatPhoto(_history->peer, lastChatPhoto.photo);
|
|
|
|
if (_additionalChatPhoto == _photo) {
|
|
|
|
_overview = OverviewChatPhotos;
|
2016-06-21 14:19:24 +00:00
|
|
|
findCurrent();
|
2016-05-20 16:01:06 +00:00
|
|
|
} else {
|
|
|
|
_additionalChatPhoto = nullptr;
|
|
|
|
_history = _migrated = nullptr;
|
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
2015-05-20 19:28:24 +00:00
|
|
|
displayPhoto(photo, 0);
|
2015-04-11 10:04:10 +00:00
|
|
|
preloadData(0);
|
|
|
|
activateControls();
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
void MediaView::showDocument(DocumentData *doc, HistoryItem *context) {
|
2014-10-07 17:57:57 +00:00
|
|
|
_photo = 0;
|
2016-04-10 18:18:26 +00:00
|
|
|
_history = context ? context->history() : nullptr;
|
2016-06-26 15:37:47 +00:00
|
|
|
_migrated = nullptr;
|
2015-11-16 16:04:37 +00:00
|
|
|
if (_history) {
|
|
|
|
if (_history->peer->migrateFrom()) {
|
|
|
|
_migrated = App::history(_history->peer->migrateFrom()->id);
|
|
|
|
} else if (_history->peer->migrateTo()) {
|
|
|
|
_migrated = _history;
|
|
|
|
_history = App::history(_history->peer->migrateTo()->id);
|
|
|
|
}
|
|
|
|
}
|
2016-05-20 16:01:06 +00:00
|
|
|
_additionalChatPhoto = nullptr;
|
2014-10-17 12:57:14 +00:00
|
|
|
_saveMsgStarted = 0;
|
2014-10-07 17:57:57 +00:00
|
|
|
_peer = 0;
|
|
|
|
_user = 0;
|
|
|
|
_loadRequest = 0;
|
2015-04-11 10:04:10 +00:00
|
|
|
_down = OverNone;
|
2014-10-07 17:57:57 +00:00
|
|
|
_pressed = false;
|
|
|
|
_dragging = 0;
|
|
|
|
setCursor(style::cur_default);
|
|
|
|
if (!_animations.isEmpty()) {
|
|
|
|
_animations.clear();
|
2015-12-08 12:33:37 +00:00
|
|
|
_a_state.stop();
|
2014-10-07 17:57:57 +00:00
|
|
|
}
|
|
|
|
if (!_animOpacities.isEmpty()) _animOpacities.clear();
|
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
_index = -1;
|
|
|
|
_msgid = context ? context->id : 0;
|
2015-11-16 16:04:37 +00:00
|
|
|
_msgmigrated = context ? (context->history() == _migrated) : false;
|
|
|
|
_channel = _history ? _history->channelId() : NoChannel;
|
2015-09-21 20:57:42 +00:00
|
|
|
_canForward = _msgid > 0;
|
|
|
|
_canDelete = context ? context->canDelete() : false;
|
2015-04-11 10:04:10 +00:00
|
|
|
if (_history) {
|
2017-05-18 13:22:57 +00:00
|
|
|
_overview = doc->isGifv() ? OverviewGIFs : doc->isVideo() ? OverviewVideos : OverviewFiles;
|
2015-11-16 16:04:37 +00:00
|
|
|
findCurrent();
|
2014-10-07 17:57:57 +00:00
|
|
|
}
|
2017-04-02 16:42:18 +00:00
|
|
|
if (doc->isVideo() || doc->isRoundVideo()) {
|
2016-07-13 11:24:31 +00:00
|
|
|
_autoplayVideoDocument = doc;
|
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
displayDocument(doc, context);
|
|
|
|
preloadData(0);
|
|
|
|
activateControls();
|
2014-10-07 17:57:57 +00:00
|
|
|
}
|
|
|
|
|
2015-05-20 19:28:24 +00:00
|
|
|
void MediaView::displayPhoto(PhotoData *photo, HistoryItem *item) {
|
2015-12-23 19:23:14 +00:00
|
|
|
stopGif();
|
2016-12-23 13:21:01 +00:00
|
|
|
destroyThemePreview();
|
2016-06-21 18:09:48 +00:00
|
|
|
_doc = nullptr;
|
2016-07-14 11:20:46 +00:00
|
|
|
_fullScreenVideo = false;
|
2015-12-22 08:01:02 +00:00
|
|
|
_photo = photo;
|
2016-06-21 18:09:48 +00:00
|
|
|
_radial.stop();
|
|
|
|
|
|
|
|
_photoRadialRect = QRect(QPoint((width() - st::radialSize.width()) / 2, (height() - st::radialSize.height()) / 2), st::radialSize);
|
2015-12-22 08:01:02 +00:00
|
|
|
|
2014-10-07 17:57:57 +00:00
|
|
|
_zoom = 0;
|
2015-04-11 10:04:10 +00:00
|
|
|
|
2015-05-20 19:28:24 +00:00
|
|
|
_caption = Text();
|
2016-04-10 18:18:26 +00:00
|
|
|
if (HistoryMessage *itemMsg = item ? item->toHistoryMessage() : nullptr) {
|
2015-05-20 19:28:24 +00:00
|
|
|
if (HistoryPhoto *photoMsg = dynamic_cast<HistoryPhoto*>(itemMsg->getMedia())) {
|
2016-12-23 13:21:01 +00:00
|
|
|
_caption.setMarkedText(st::mediaviewCaptionStyle, photoMsg->getCaption(), (item->author()->isUser() && item->author()->asUser()->botInfo) ? _captionBotOptions : _captionTextOptions);
|
2015-05-20 19:28:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-15 15:55:45 +00:00
|
|
|
_zoomToScreen = 0;
|
2017-03-15 16:24:06 +00:00
|
|
|
AuthSession::Current().downloader().clearPriorities();
|
2014-08-17 07:37:24 +00:00
|
|
|
_full = -1;
|
2014-08-11 09:03:45 +00:00
|
|
|
_current = QPixmap();
|
|
|
|
_down = OverNone;
|
2014-11-12 20:18:00 +00:00
|
|
|
_w = convertScale(photo->full->width());
|
|
|
|
_h = convertScale(photo->full->height());
|
2014-08-17 07:37:24 +00:00
|
|
|
if (isHidden()) {
|
|
|
|
moveToScreen();
|
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
if (_w > width()) {
|
|
|
|
_h = qRound(_h * width() / float64(_w));
|
|
|
|
_w = width();
|
2014-08-06 14:40:21 +00:00
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
if (_h > height()) {
|
|
|
|
_w = qRound(_w * height() / float64(_h));
|
|
|
|
_h = height();
|
2014-08-06 14:40:21 +00:00
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
_x = (width() - _w) / 2;
|
|
|
|
_y = (height() - _h) / 2;
|
2014-10-07 17:57:57 +00:00
|
|
|
_width = _w;
|
2015-08-12 18:01:32 +00:00
|
|
|
if (_msgid && item) {
|
2016-02-18 19:12:50 +00:00
|
|
|
_from = item->authorOriginal();
|
2015-04-04 20:01:34 +00:00
|
|
|
} else {
|
2015-08-12 18:01:32 +00:00
|
|
|
_from = _user;
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
2015-12-25 13:09:14 +00:00
|
|
|
_photo->download();
|
2016-10-19 13:31:18 +00:00
|
|
|
displayFinished();
|
2014-08-06 14:40:21 +00:00
|
|
|
}
|
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
void MediaView::destroyThemePreview() {
|
2017-02-03 20:07:26 +00:00
|
|
|
_themePreviewId = 0;
|
2016-12-23 13:21:01 +00:00
|
|
|
_themePreviewShown = false;
|
|
|
|
_themePreview.reset();
|
|
|
|
_themeApply.destroy();
|
|
|
|
_themeCancel.destroy();
|
|
|
|
}
|
|
|
|
|
2015-07-15 11:23:59 +00:00
|
|
|
void MediaView::displayDocument(DocumentData *doc, HistoryItem *item) { // empty messages shown as docs: doc can be NULL
|
2016-12-23 13:21:01 +00:00
|
|
|
auto documentChanged = (!doc || doc != _doc || (item && (item->id != _msgid || (item->history() != (_msgmigrated ? _migrated : _history)))));
|
|
|
|
if (documentChanged || (!doc->isAnimation() && !doc->isVideo())) {
|
2016-07-14 11:20:46 +00:00
|
|
|
_fullScreenVideo = false;
|
2016-07-26 12:09:40 +00:00
|
|
|
_current = QPixmap();
|
2015-12-23 19:23:14 +00:00
|
|
|
stopGif();
|
2016-07-26 12:09:40 +00:00
|
|
|
} else if (gifShown()) {
|
|
|
|
_current = QPixmap();
|
2015-12-22 08:01:02 +00:00
|
|
|
}
|
2016-12-23 13:21:01 +00:00
|
|
|
if (documentChanged || !doc->isTheme()) {
|
|
|
|
destroyThemePreview();
|
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
_doc = doc;
|
2016-04-10 18:18:26 +00:00
|
|
|
_photo = nullptr;
|
2016-06-21 18:09:48 +00:00
|
|
|
_radial.stop();
|
2015-02-19 11:30:16 +00:00
|
|
|
|
2016-07-13 11:24:31 +00:00
|
|
|
if (_autoplayVideoDocument && _doc != _autoplayVideoDocument) {
|
|
|
|
_autoplayVideoDocument = nullptr;
|
|
|
|
}
|
|
|
|
|
2015-05-20 19:28:24 +00:00
|
|
|
_caption = Text();
|
2015-07-15 11:23:59 +00:00
|
|
|
if (_doc) {
|
2015-12-24 19:26:28 +00:00
|
|
|
if (_doc->sticker()) {
|
|
|
|
_doc->checkSticker();
|
|
|
|
if (!_doc->sticker()->img->isNull()) {
|
|
|
|
_current = _doc->sticker()->img->pix();
|
|
|
|
} else {
|
|
|
|
_current = _doc->thumb->pixBlurred(_doc->dimensions.width(), _doc->dimensions.height());
|
2015-12-23 19:23:14 +00:00
|
|
|
}
|
2015-12-24 19:26:28 +00:00
|
|
|
} else {
|
|
|
|
_doc->automaticLoad(item);
|
|
|
|
|
2016-07-11 18:05:46 +00:00
|
|
|
if (_doc->isAnimation() || _doc->isVideo()) {
|
|
|
|
initAnimation();
|
2016-12-23 13:21:01 +00:00
|
|
|
} else if (_doc->isTheme()) {
|
|
|
|
initThemePreview();
|
2016-07-11 18:05:46 +00:00
|
|
|
} else {
|
2017-05-18 20:18:59 +00:00
|
|
|
auto &location = _doc->location(true);
|
2016-07-11 18:05:46 +00:00
|
|
|
if (location.accessEnable()) {
|
2015-12-24 19:26:28 +00:00
|
|
|
if (QImageReader(location.name()).canRead()) {
|
2016-07-13 17:34:57 +00:00
|
|
|
_current = App::pixmapFromImageInPlace(App::readImage(location.name(), 0, false));
|
2015-12-24 19:26:28 +00:00
|
|
|
}
|
2015-12-22 08:01:02 +00:00
|
|
|
}
|
2015-12-24 19:26:28 +00:00
|
|
|
location.accessDisable();
|
2015-04-19 10:29:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-31 12:29:26 +00:00
|
|
|
_docIconRect = QRect((width() - st::mediaviewFileIconSize) / 2, (height() - st::mediaviewFileIconSize) / 2, st::mediaviewFileIconSize, st::mediaviewFileIconSize);
|
2016-12-23 13:21:01 +00:00
|
|
|
if (fileBubbleShown()) {
|
2015-07-15 11:23:59 +00:00
|
|
|
if (!_doc || _doc->thumb->isNull()) {
|
2015-12-21 13:14:29 +00:00
|
|
|
int32 colorIndex = documentColorIndex(_doc, _docExt);
|
2016-12-23 13:21:01 +00:00
|
|
|
_docIconColor = documentColor(colorIndex);
|
2016-09-30 16:40:00 +00:00
|
|
|
const style::icon *(thumbs[]) = { &st::mediaviewFileBlue, &st::mediaviewFileGreen, &st::mediaviewFileRed, &st::mediaviewFileYellow };
|
2015-12-21 13:14:29 +00:00
|
|
|
_docIcon = thumbs[colorIndex];
|
|
|
|
|
2016-10-31 12:29:26 +00:00
|
|
|
int32 extmaxw = (st::mediaviewFileIconSize - st::mediaviewFileExtPadding * 2);
|
|
|
|
_docExtWidth = st::mediaviewFileExtFont->width(_docExt);
|
2015-12-21 13:14:29 +00:00
|
|
|
if (_docExtWidth > extmaxw) {
|
2016-10-31 12:29:26 +00:00
|
|
|
_docExt = st::mediaviewFileNameFont->elided(_docExt, extmaxw, Qt::ElideMiddle);
|
|
|
|
_docExtWidth = st::mediaviewFileNameFont->width(_docExt);
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
2014-08-11 09:16:47 +00:00
|
|
|
} else {
|
2015-04-11 10:04:10 +00:00
|
|
|
_doc->thumb->load();
|
|
|
|
int32 tw = _doc->thumb->width(), th = _doc->thumb->height();
|
|
|
|
if (!tw || !th) {
|
|
|
|
_docThumbx = _docThumby = _docThumbw = 0;
|
|
|
|
} else if (tw > th) {
|
2016-10-31 12:29:26 +00:00
|
|
|
_docThumbw = (tw * st::mediaviewFileIconSize) / th;
|
|
|
|
_docThumbx = (_docThumbw - st::mediaviewFileIconSize) / 2;
|
2015-04-11 10:04:10 +00:00
|
|
|
_docThumby = 0;
|
|
|
|
} else {
|
2016-10-31 12:29:26 +00:00
|
|
|
_docThumbw = st::mediaviewFileIconSize;
|
2015-04-11 10:04:10 +00:00
|
|
|
_docThumbx = 0;
|
2016-10-31 12:29:26 +00:00
|
|
|
_docThumby = ((th * _docThumbw) / tw - st::mediaviewFileIconSize) / 2;
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
2014-08-11 09:16:47 +00:00
|
|
|
}
|
|
|
|
|
2016-10-31 12:29:26 +00:00
|
|
|
int32 maxw = st::mediaviewFileSize.width() - st::mediaviewFileIconSize - st::mediaviewFilePadding * 3;
|
2015-04-11 10:04:10 +00:00
|
|
|
|
2015-12-23 16:48:44 +00:00
|
|
|
if (_doc) {
|
|
|
|
_docName = (_doc->type == StickerDocument) ? lang(lng_in_dlg_sticker) : (_doc->type == AnimatedDocument ? qsl("GIF") : (_doc->name.isEmpty() ? lang(lng_mediaview_doc_image) : _doc->name));
|
|
|
|
} else {
|
|
|
|
_docName = lang(lng_message_empty);
|
|
|
|
}
|
2016-10-31 12:29:26 +00:00
|
|
|
_docNameWidth = st::mediaviewFileNameFont->width(_docName);
|
2015-04-11 10:04:10 +00:00
|
|
|
if (_docNameWidth > maxw) {
|
2016-10-31 12:29:26 +00:00
|
|
|
_docName = st::mediaviewFileNameFont->elided(_docName, maxw, Qt::ElideMiddle);
|
|
|
|
_docNameWidth = st::mediaviewFileNameFont->width(_docName);
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
|
|
|
|
2015-04-19 10:29:19 +00:00
|
|
|
// _docSize is updated in updateControls()
|
|
|
|
|
2016-10-31 12:29:26 +00:00
|
|
|
_docRect = QRect((width() - st::mediaviewFileSize.width()) / 2, (height() - st::mediaviewFileSize.height()) / 2, st::mediaviewFileSize.width(), st::mediaviewFileSize.height());
|
|
|
|
_docIconRect = myrtlrect(_docRect.x() + st::mediaviewFilePadding, _docRect.y() + st::mediaviewFilePadding, st::mediaviewFileIconSize, st::mediaviewFileIconSize);
|
2016-12-23 13:21:01 +00:00
|
|
|
} else if (_themePreviewShown) {
|
|
|
|
updateThemePreviewGeometry();
|
2015-04-19 10:29:19 +00:00
|
|
|
} else if (!_current.isNull()) {
|
2015-04-11 10:04:10 +00:00
|
|
|
_current.setDevicePixelRatio(cRetinaFactor());
|
2015-12-22 08:01:02 +00:00
|
|
|
_w = convertScale(_current.width());
|
|
|
|
_h = convertScale(_current.height());
|
2015-04-19 10:29:19 +00:00
|
|
|
} else {
|
2015-12-22 08:01:02 +00:00
|
|
|
_w = convertScale(_gif->width());
|
|
|
|
_h = convertScale(_gif->height());
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
|
|
|
if (isHidden()) {
|
|
|
|
moveToScreen();
|
|
|
|
}
|
|
|
|
_width = _w;
|
|
|
|
if (_w > 0 && _h > 0) {
|
|
|
|
_zoomToScreen = float64(width()) / _w;
|
|
|
|
if (_h * _zoomToScreen > height()) {
|
|
|
|
_zoomToScreen = float64(height()) / _h;
|
|
|
|
}
|
|
|
|
if (_zoomToScreen >= 1.) {
|
|
|
|
_zoomToScreen -= 1.;
|
2014-08-11 09:16:47 +00:00
|
|
|
} else {
|
2015-04-11 10:04:10 +00:00
|
|
|
_zoomToScreen = 1. - (1. / _zoomToScreen);
|
2014-08-11 09:16:47 +00:00
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
} else {
|
|
|
|
_zoomToScreen = 0;
|
|
|
|
}
|
2016-07-14 11:20:46 +00:00
|
|
|
if ((_w > width()) || (_h > height()) || _fullScreenVideo) {
|
2015-04-11 10:04:10 +00:00
|
|
|
_zoom = ZoomToScreenLevel;
|
|
|
|
if (_zoomToScreen >= 0) {
|
|
|
|
_w = qRound(_w * (_zoomToScreen + 1));
|
|
|
|
_h = qRound(_h * (_zoomToScreen + 1));
|
|
|
|
} else {
|
|
|
|
_w = qRound(_w / (-_zoomToScreen + 1));
|
|
|
|
_h = qRound(_h / (-_zoomToScreen + 1));
|
|
|
|
}
|
|
|
|
snapXY();
|
|
|
|
} else {
|
|
|
|
_zoom = 0;
|
|
|
|
}
|
|
|
|
_x = (width() - _w) / 2;
|
|
|
|
_y = (height() - _h) / 2;
|
2016-04-10 18:18:26 +00:00
|
|
|
if (_msgid && item) {
|
|
|
|
_from = item->authorOriginal();
|
|
|
|
} else {
|
|
|
|
_from = _user;
|
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
_full = 1;
|
2016-10-19 13:31:18 +00:00
|
|
|
displayFinished();
|
|
|
|
}
|
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
void MediaView::updateThemePreviewGeometry() {
|
|
|
|
if (_themePreviewShown) {
|
|
|
|
auto previewRect = QRect((width() - st::themePreviewSize.width()) / 2, (height() - st::themePreviewSize.height()) / 2, st::themePreviewSize.width(), st::themePreviewSize.height());
|
|
|
|
_themePreviewRect = previewRect.marginsAdded(st::themePreviewMargin);
|
|
|
|
if (_themeApply) {
|
2016-12-31 15:19:22 +00:00
|
|
|
auto right = qMax(width() - _themePreviewRect.x() - _themePreviewRect.width(), 0) + st::themePreviewMargin.right();
|
|
|
|
auto bottom = qMin(height(), _themePreviewRect.y() + _themePreviewRect.height());
|
|
|
|
_themeApply->moveToRight(right, bottom - st::themePreviewMargin.bottom() + (st::themePreviewMargin.bottom() - _themeApply->height()) / 2);
|
2016-12-23 13:21:01 +00:00
|
|
|
right += _themeApply->width() + st::themePreviewButtonsSkip;
|
|
|
|
_themeCancel->moveToRight(right, _themeApply->y());
|
|
|
|
}
|
|
|
|
|
|
|
|
// For context menu event.
|
|
|
|
_x = _themePreviewRect.x();
|
|
|
|
_y = _themePreviewRect.y();
|
|
|
|
_w = _themePreviewRect.width();
|
|
|
|
_h = _themePreviewRect.height();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-19 13:31:18 +00:00
|
|
|
void MediaView::displayFinished() {
|
2015-04-11 10:04:10 +00:00
|
|
|
updateControls();
|
|
|
|
if (isHidden()) {
|
|
|
|
psUpdateOverlayed(this);
|
|
|
|
show();
|
|
|
|
psShowOverAll(this);
|
2015-11-16 16:04:37 +00:00
|
|
|
activateWindow();
|
2016-02-08 14:54:55 +00:00
|
|
|
Sandbox::setActiveWindow(this);
|
2015-11-16 16:04:37 +00:00
|
|
|
setFocus();
|
2014-08-11 09:16:47 +00:00
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
2014-08-11 09:16:47 +00:00
|
|
|
|
2017-04-02 16:42:18 +00:00
|
|
|
Images::Options MediaView::videoThumbOptions() const {
|
|
|
|
auto options = Images::Option::Smooth | Images::Option::Blurred;
|
2017-04-12 20:34:57 +00:00
|
|
|
if (_doc && _doc->isRoundVideo()) {
|
2017-04-02 16:42:18 +00:00
|
|
|
options |= Images::Option::Circled;
|
|
|
|
}
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
2016-07-11 18:05:46 +00:00
|
|
|
void MediaView::initAnimation() {
|
2017-04-02 10:25:54 +00:00
|
|
|
Expects(_doc != nullptr);
|
|
|
|
Expects(_doc->isAnimation() || _doc->isVideo());
|
2016-07-11 18:05:46 +00:00
|
|
|
|
|
|
|
auto &location = _doc->location(true);
|
|
|
|
if (!_doc->data().isEmpty()) {
|
|
|
|
createClipReader();
|
|
|
|
} else if (location.accessEnable()) {
|
|
|
|
createClipReader();
|
|
|
|
location.accessDisable();
|
2016-07-19 12:31:48 +00:00
|
|
|
} else if (_doc->dimensions.width() && _doc->dimensions.height()) {
|
2017-04-02 16:42:18 +00:00
|
|
|
auto w = _doc->dimensions.width();
|
|
|
|
auto h = _doc->dimensions.height();
|
|
|
|
_current = _doc->thumb->pixNoCache(w, h, videoThumbOptions(), w / cIntRetinaFactor(), h / cIntRetinaFactor());
|
2016-07-19 12:31:48 +00:00
|
|
|
if (cRetina()) _current.setDevicePixelRatio(cRetinaFactor());
|
2016-07-19 10:54:43 +00:00
|
|
|
} else {
|
2017-04-02 16:42:18 +00:00
|
|
|
_current = _doc->thumb->pixNoCache(_doc->thumb->width(), _doc->thumb->height(), videoThumbOptions(), st::mediaviewFileIconSize, st::mediaviewFileIconSize);
|
2016-07-11 18:05:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::createClipReader() {
|
|
|
|
if (_gif) return;
|
|
|
|
|
2017-04-02 10:25:54 +00:00
|
|
|
Expects(_doc != nullptr);
|
|
|
|
Expects(_doc->isAnimation() || _doc->isVideo());
|
2016-07-11 18:05:46 +00:00
|
|
|
|
|
|
|
if (_doc->dimensions.width() && _doc->dimensions.height()) {
|
2016-07-19 12:31:48 +00:00
|
|
|
int w = _doc->dimensions.width();
|
|
|
|
int h = _doc->dimensions.height();
|
2017-04-02 16:42:18 +00:00
|
|
|
_current = _doc->thumb->pixNoCache(w, h, videoThumbOptions(), w / cIntRetinaFactor(), h / cIntRetinaFactor());
|
2016-07-19 12:31:48 +00:00
|
|
|
if (cRetina()) _current.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
} else {
|
2017-04-02 16:42:18 +00:00
|
|
|
_current = _doc->thumb->pixNoCache(_doc->thumb->width(), _doc->thumb->height(), videoThumbOptions(), st::mediaviewFileIconSize, st::mediaviewFileIconSize);
|
2016-07-11 18:05:46 +00:00
|
|
|
}
|
2017-04-02 16:42:18 +00:00
|
|
|
auto mode = (_doc->isVideo() || _doc->isRoundVideo()) ? Media::Clip::Reader::Mode::Video : Media::Clip::Reader::Mode::Gif;
|
2017-05-18 20:18:59 +00:00
|
|
|
_gif = Media::Clip::MakeReader(_doc, FullMsgId(_channel, _msgid), [this](Media::Clip::Notification notification) {
|
2016-09-26 12:09:59 +00:00
|
|
|
clipCallback(notification);
|
|
|
|
}, mode);
|
2016-07-11 18:05:46 +00:00
|
|
|
|
2016-07-12 12:28:07 +00:00
|
|
|
// Correct values will be set when gif gets inited.
|
2016-07-14 11:20:46 +00:00
|
|
|
_videoPaused = _videoIsSilent = _videoStopped = false;
|
2016-07-12 12:28:07 +00:00
|
|
|
_videoPositionMs = 0ULL;
|
|
|
|
_videoDurationMs = _doc->duration() * 1000ULL;
|
|
|
|
|
2016-07-11 18:05:46 +00:00
|
|
|
createClipController();
|
|
|
|
}
|
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
void MediaView::initThemePreview() {
|
|
|
|
t_assert(_doc && _doc->isTheme());
|
|
|
|
|
|
|
|
auto &location = _doc->location();
|
|
|
|
if (!location.isEmpty() && location.accessEnable()) {
|
|
|
|
_themePreviewShown = true;
|
|
|
|
auto path = _doc->location().name();
|
|
|
|
auto id = _themePreviewId = rand_value<uint64>();
|
2017-02-21 13:45:56 +00:00
|
|
|
auto ready = base::lambda_guarded(this, [this, id](std::unique_ptr<Window::Theme::Preview> result) {
|
2016-12-23 13:21:01 +00:00
|
|
|
if (id != _themePreviewId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_themePreviewId = 0;
|
2017-02-21 13:45:56 +00:00
|
|
|
_themePreview = std::move(result);
|
2016-12-23 13:21:01 +00:00
|
|
|
if (_themePreview) {
|
2017-05-30 15:21:05 +00:00
|
|
|
_themeApply.create(this, langFactory(lng_theme_preview_apply), st::themePreviewApplyButton);
|
2016-12-23 13:21:01 +00:00
|
|
|
_themeApply->show();
|
|
|
|
_themeApply->setClickedCallback([this] {
|
2017-02-21 13:45:56 +00:00
|
|
|
auto preview = std::move(_themePreview);
|
2016-12-23 13:21:01 +00:00
|
|
|
close();
|
2017-02-21 13:45:56 +00:00
|
|
|
Window::Theme::Apply(std::move(preview));
|
2016-12-23 13:21:01 +00:00
|
|
|
});
|
2017-05-30 15:21:05 +00:00
|
|
|
_themeCancel.create(this, langFactory(lng_cancel), st::themePreviewCancelButton);
|
2016-12-23 13:21:01 +00:00
|
|
|
_themeCancel->show();
|
|
|
|
_themeCancel->setClickedCallback([this] { close(); });
|
|
|
|
updateControls();
|
|
|
|
}
|
|
|
|
update();
|
|
|
|
});
|
2017-02-26 11:32:13 +00:00
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
Window::Theme::CurrentData current;
|
|
|
|
current.backgroundId = Window::Theme::Background()->id();
|
2017-01-01 16:45:20 +00:00
|
|
|
current.backgroundImage = Window::Theme::Background()->pixmap();
|
2016-12-23 13:21:01 +00:00
|
|
|
current.backgroundTiled = Window::Theme::Background()->tile();
|
2017-02-26 11:32:13 +00:00
|
|
|
base::TaskQueue::Normal().Put([ready = std::move(ready), path, current]() mutable {
|
2016-12-23 13:21:01 +00:00
|
|
|
auto preview = Window::Theme::GeneratePreview(path, current);
|
2017-02-26 11:32:13 +00:00
|
|
|
base::TaskQueue::Main().Put([ready = std::move(ready), result = std::move(preview)]() mutable {
|
|
|
|
ready(std::move(result));
|
2016-12-23 13:21:01 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
location.accessDisable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-11 18:05:46 +00:00
|
|
|
void MediaView::createClipController() {
|
2017-04-12 20:34:57 +00:00
|
|
|
Expects(_doc != nullptr);
|
2017-04-02 16:42:18 +00:00
|
|
|
if (!_doc->isVideo() && !_doc->isRoundVideo()) return;
|
2016-07-11 18:05:46 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
_clipController.create(this);
|
2016-07-11 18:05:46 +00:00
|
|
|
setClipControllerGeometry();
|
|
|
|
_clipController->show();
|
|
|
|
|
2016-07-13 11:24:31 +00:00
|
|
|
connect(_clipController, SIGNAL(playPressed()), this, SLOT(onVideoPauseResume()));
|
|
|
|
connect(_clipController, SIGNAL(pausePressed()), this, SLOT(onVideoPauseResume()));
|
2016-12-01 19:20:33 +00:00
|
|
|
connect(_clipController, SIGNAL(seekProgress(TimeMs)), this, SLOT(onVideoSeekProgress(TimeMs)));
|
|
|
|
connect(_clipController, SIGNAL(seekFinished(TimeMs)), this, SLOT(onVideoSeekFinished(TimeMs)));
|
2016-07-11 18:05:46 +00:00
|
|
|
connect(_clipController, SIGNAL(volumeChanged(float64)), this, SLOT(onVideoVolumeChanged(float64)));
|
2016-07-14 11:20:46 +00:00
|
|
|
connect(_clipController, SIGNAL(toFullScreenPressed()), this, SLOT(onVideoToggleFullScreen()));
|
|
|
|
connect(_clipController, SIGNAL(fromFullScreenPressed()), this, SLOT(onVideoToggleFullScreen()));
|
2016-07-11 18:05:46 +00:00
|
|
|
|
2017-01-19 08:24:43 +00:00
|
|
|
connect(Media::Player::mixer(), SIGNAL(updated(const AudioMsgId&)), this, SLOT(onVideoPlayProgress(const AudioMsgId&)));
|
2016-07-11 18:05:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::setClipControllerGeometry() {
|
|
|
|
t_assert(_clipController != nullptr);
|
|
|
|
|
|
|
|
int controllerBottom = _captionRect.isEmpty() ? height() : _captionRect.y();
|
|
|
|
_clipController->setGeometry(
|
|
|
|
(width() - _clipController->width()) / 2,
|
2016-12-23 13:21:01 +00:00
|
|
|
controllerBottom - _clipController->height() - st::mediaviewCaptionPadding.bottom() - st::mediaviewCaptionMargin.height(),
|
2016-07-11 18:05:46 +00:00
|
|
|
st::mediaviewControllerSize.width(),
|
|
|
|
st::mediaviewControllerSize.height());
|
|
|
|
myEnsureResized(_clipController);
|
|
|
|
}
|
|
|
|
|
2016-07-13 11:24:31 +00:00
|
|
|
void MediaView::onVideoPauseResume() {
|
2016-07-19 10:54:43 +00:00
|
|
|
if (!_gif) return;
|
|
|
|
|
2016-07-12 18:04:34 +00:00
|
|
|
if (auto item = App::histItemById(_msgmigrated ? 0 : _channel, _msgid)) {
|
|
|
|
if (_gif->state() == Media::Clip::State::Error) {
|
|
|
|
displayDocument(_doc, item);
|
|
|
|
} else if (_gif->state() == Media::Clip::State::Finished) {
|
2016-07-13 17:34:57 +00:00
|
|
|
restartVideoAtSeekPosition(0);
|
2016-07-12 18:04:34 +00:00
|
|
|
} else {
|
2016-07-13 11:24:31 +00:00
|
|
|
_gif->pauseResumeVideo();
|
|
|
|
_videoPaused = _gif->videoPaused();
|
|
|
|
if (_videoIsSilent) {
|
|
|
|
updateSilentVideoPlaybackState();
|
|
|
|
}
|
2016-07-12 18:04:34 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
stopGif();
|
2016-07-14 11:20:46 +00:00
|
|
|
updateControls();
|
|
|
|
update();
|
2016-07-12 18:04:34 +00:00
|
|
|
}
|
2016-07-11 18:05:46 +00:00
|
|
|
}
|
|
|
|
|
2016-12-01 19:20:33 +00:00
|
|
|
void MediaView::restartVideoAtSeekPosition(TimeMs positionMs) {
|
2016-07-13 17:34:57 +00:00
|
|
|
_autoplayVideoDocument = _doc;
|
|
|
|
|
|
|
|
if (_current.isNull()) {
|
2017-04-12 20:34:57 +00:00
|
|
|
auto rounding = (_doc && _doc->isRoundVideo()) ? ImageRoundRadius::Ellipse : ImageRoundRadius::None;
|
2017-04-02 16:42:18 +00:00
|
|
|
_current = _gif->current(_gif->width() / cIntRetinaFactor(), _gif->height() / cIntRetinaFactor(), _gif->width() / cIntRetinaFactor(), _gif->height() / cIntRetinaFactor(), rounding, ImageRoundCorner::All, getms());
|
2016-07-13 17:34:57 +00:00
|
|
|
}
|
2017-05-18 20:18:59 +00:00
|
|
|
_gif = Media::Clip::MakeReader(_doc, FullMsgId(_channel, _msgid), [this](Media::Clip::Notification notification) {
|
2016-09-26 12:09:59 +00:00
|
|
|
clipCallback(notification);
|
|
|
|
}, Media::Clip::Reader::Mode::Video, positionMs);
|
2016-07-13 17:34:57 +00:00
|
|
|
|
|
|
|
// Correct values will be set when gif gets inited.
|
2016-07-14 11:20:46 +00:00
|
|
|
_videoPaused = _videoIsSilent = _videoStopped = false;
|
2016-07-13 17:34:57 +00:00
|
|
|
_videoPositionMs = positionMs;
|
2016-07-11 18:05:46 +00:00
|
|
|
|
2017-01-24 21:24:39 +00:00
|
|
|
Media::Player::TrackState state;
|
|
|
|
state.state = Media::Player::State::Playing;
|
2016-07-13 17:34:57 +00:00
|
|
|
state.position = _videoPositionMs;
|
2017-05-03 13:01:15 +00:00
|
|
|
state.length = _videoDurationMs;
|
2016-07-13 17:34:57 +00:00
|
|
|
state.frequency = _videoFrequencyMs;
|
2016-09-23 16:04:26 +00:00
|
|
|
updateVideoPlaybackState(state);
|
2016-07-11 18:05:46 +00:00
|
|
|
}
|
|
|
|
|
2016-12-01 19:20:33 +00:00
|
|
|
void MediaView::onVideoSeekProgress(TimeMs positionMs) {
|
2016-07-14 11:20:46 +00:00
|
|
|
if (!_videoPaused && !_videoStopped) {
|
2016-07-13 17:34:57 +00:00
|
|
|
onVideoPauseResume();
|
|
|
|
}
|
|
|
|
}
|
2016-07-11 18:05:46 +00:00
|
|
|
|
2016-12-01 19:20:33 +00:00
|
|
|
void MediaView::onVideoSeekFinished(TimeMs positionMs) {
|
2016-07-13 17:34:57 +00:00
|
|
|
restartVideoAtSeekPosition(positionMs);
|
2016-07-11 18:05:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::onVideoVolumeChanged(float64 volume) {
|
2016-07-12 14:11:59 +00:00
|
|
|
Global::SetVideoVolume(volume);
|
2017-04-15 19:51:53 +00:00
|
|
|
updateMixerVideoVolume();
|
2016-10-12 19:34:25 +00:00
|
|
|
Global::RefVideoVolumeChanged().notify();
|
2016-07-11 18:05:46 +00:00
|
|
|
}
|
|
|
|
|
2016-07-14 11:20:46 +00:00
|
|
|
void MediaView::onVideoToggleFullScreen() {
|
|
|
|
if (!_clipController) return;
|
2016-07-11 18:05:46 +00:00
|
|
|
|
2016-07-14 11:20:46 +00:00
|
|
|
_fullScreenVideo = !_fullScreenVideo;
|
|
|
|
if (_fullScreenVideo) {
|
|
|
|
_fullScreenZoomCache = _zoom;
|
|
|
|
setZoomLevel(ZoomToScreenLevel);
|
|
|
|
} else {
|
|
|
|
setZoomLevel(_fullScreenZoomCache);
|
2016-07-24 08:53:09 +00:00
|
|
|
_clipController->showAnimated();
|
2016-07-14 11:20:46 +00:00
|
|
|
}
|
2016-07-11 18:05:46 +00:00
|
|
|
|
2016-07-14 11:20:46 +00:00
|
|
|
_clipController->setInFullScreen(_fullScreenVideo);
|
|
|
|
updateControls();
|
|
|
|
update();
|
2016-07-11 18:05:46 +00:00
|
|
|
}
|
|
|
|
|
2016-07-12 11:38:16 +00:00
|
|
|
void MediaView::onVideoPlayProgress(const AudioMsgId &audioId) {
|
2017-05-18 20:18:59 +00:00
|
|
|
if (!_gif || _gif->audioMsgId() != audioId) {
|
2016-07-12 11:38:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-18 20:18:59 +00:00
|
|
|
auto state = Media::Player::mixer()->currentState(AudioMsgId::Type::Video);
|
|
|
|
if (state.id == _gif->audioMsgId()) {
|
|
|
|
if (state.length) {
|
|
|
|
updateVideoPlaybackState(state);
|
|
|
|
}
|
|
|
|
AuthSession::Current().data().setLastTimeVideoPlayedAt(getms(true));
|
2016-07-13 17:34:57 +00:00
|
|
|
}
|
2016-07-12 12:28:07 +00:00
|
|
|
}
|
|
|
|
|
2017-01-24 21:24:39 +00:00
|
|
|
void MediaView::updateVideoPlaybackState(const Media::Player::TrackState &state) {
|
2016-07-12 11:38:16 +00:00
|
|
|
if (state.frequency) {
|
2017-01-24 21:24:39 +00:00
|
|
|
if (Media::Player::IsStopped(state.state)) {
|
2016-07-14 11:20:46 +00:00
|
|
|
_videoStopped = true;
|
|
|
|
}
|
2016-09-23 16:04:26 +00:00
|
|
|
_clipController->updatePlayback(state);
|
2016-07-12 18:04:34 +00:00
|
|
|
} else { // Audio has stopped already.
|
|
|
|
_videoIsSilent = true;
|
|
|
|
updateSilentVideoPlaybackState();
|
2016-07-12 11:38:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-12 12:28:07 +00:00
|
|
|
void MediaView::updateSilentVideoPlaybackState() {
|
2017-01-24 21:24:39 +00:00
|
|
|
Media::Player::TrackState state;
|
2016-07-12 12:28:07 +00:00
|
|
|
if (_videoPaused) {
|
2017-01-24 21:24:39 +00:00
|
|
|
state.state = Media::Player::State::Paused;
|
2016-07-12 12:28:07 +00:00
|
|
|
} else if (_videoPositionMs == _videoDurationMs) {
|
2017-01-24 21:24:39 +00:00
|
|
|
state.state = Media::Player::State::StoppedAtEnd;
|
2016-07-12 12:28:07 +00:00
|
|
|
} else {
|
2017-01-24 21:24:39 +00:00
|
|
|
state.state = Media::Player::State::Playing;
|
2016-07-12 12:28:07 +00:00
|
|
|
}
|
|
|
|
state.position = _videoPositionMs;
|
2017-05-03 13:01:15 +00:00
|
|
|
state.length = _videoDurationMs;
|
2016-07-12 12:28:07 +00:00
|
|
|
state.frequency = _videoFrequencyMs;
|
|
|
|
updateVideoPlaybackState(state);
|
|
|
|
}
|
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
void MediaView::paintEvent(QPaintEvent *e) {
|
|
|
|
QRect r(e->rect());
|
2015-04-19 19:01:45 +00:00
|
|
|
QRegion region(e->region());
|
|
|
|
QVector<QRect> rs(region.rects());
|
2015-12-22 08:01:02 +00:00
|
|
|
|
2016-12-01 19:20:33 +00:00
|
|
|
auto ms = getms();
|
2015-04-19 19:01:45 +00:00
|
|
|
|
|
|
|
Painter p(this);
|
|
|
|
|
2016-07-19 10:54:43 +00:00
|
|
|
bool name = false;
|
2015-04-19 19:01:45 +00:00
|
|
|
|
|
|
|
p.setClipRegion(region);
|
2015-04-11 10:04:10 +00:00
|
|
|
|
|
|
|
// main bg
|
|
|
|
QPainter::CompositionMode m = p.compositionMode();
|
|
|
|
p.setCompositionMode(QPainter::CompositionMode_Source);
|
2016-07-14 11:20:46 +00:00
|
|
|
if (_fullScreenVideo) {
|
|
|
|
for (int i = 0, l = region.rectCount(); i < l; ++i) {
|
2016-10-31 12:29:26 +00:00
|
|
|
p.fillRect(rs.at(i), st::mediaviewVideoBg);
|
2016-07-14 11:20:46 +00:00
|
|
|
}
|
2017-04-12 20:34:57 +00:00
|
|
|
if (_doc && _doc->isRoundVideo()) {
|
2017-04-02 16:42:18 +00:00
|
|
|
p.setCompositionMode(m);
|
|
|
|
}
|
2016-07-14 11:20:46 +00:00
|
|
|
} else {
|
|
|
|
for (int i = 0, l = region.rectCount(); i < l; ++i) {
|
2016-10-31 12:29:26 +00:00
|
|
|
p.fillRect(rs.at(i), st::mediaviewBg);
|
2016-07-14 11:20:46 +00:00
|
|
|
}
|
|
|
|
p.setCompositionMode(m);
|
2015-04-19 19:01:45 +00:00
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
|
2014-10-07 17:57:57 +00:00
|
|
|
// photo
|
|
|
|
if (_photo) {
|
2014-10-17 12:57:14 +00:00
|
|
|
int32 w = _width * cIntRetinaFactor();
|
2015-12-25 13:09:14 +00:00
|
|
|
if (_full <= 0 && _photo->loaded()) {
|
2014-10-17 12:57:14 +00:00
|
|
|
int32 h = int((_photo->full->height() * (qreal(w) / qreal(_photo->full->width()))) + 0.9999);
|
2016-11-28 15:45:07 +00:00
|
|
|
_current = _photo->full->pixNoCache(w, h, Images::Option::Smooth);
|
2014-10-07 17:57:57 +00:00
|
|
|
if (cRetina()) _current.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
_full = 1;
|
|
|
|
} else if (_full < 0 && _photo->medium->loaded()) {
|
2014-10-17 12:57:14 +00:00
|
|
|
int32 h = int((_photo->full->height() * (qreal(w) / qreal(_photo->full->width()))) + 0.9999);
|
2016-11-28 15:45:07 +00:00
|
|
|
_current = _photo->medium->pixNoCache(w, h, Images::Option::Smooth | Images::Option::Blurred);
|
2014-10-07 17:57:57 +00:00
|
|
|
if (cRetina()) _current.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
_full = 0;
|
|
|
|
} else if (_current.isNull() && _photo->thumb->loaded()) {
|
2014-10-17 12:57:14 +00:00
|
|
|
int32 h = int((_photo->full->height() * (qreal(w) / qreal(_photo->full->width()))) + 0.9999);
|
2016-11-28 15:45:07 +00:00
|
|
|
_current = _photo->thumb->pixNoCache(w, h, Images::Option::Smooth | Images::Option::Blurred);
|
2014-10-07 17:57:57 +00:00
|
|
|
if (cRetina()) _current.setDevicePixelRatio(cRetinaFactor());
|
2015-12-24 19:26:28 +00:00
|
|
|
} else if (_current.isNull()) {
|
|
|
|
_current = _photo->thumb->pix();
|
2014-10-07 17:57:57 +00:00
|
|
|
}
|
|
|
|
}
|
2015-04-19 10:29:19 +00:00
|
|
|
p.setOpacity(1);
|
2015-12-22 08:01:02 +00:00
|
|
|
if (_photo || fileShown()) {
|
2014-10-07 17:57:57 +00:00
|
|
|
QRect imgRect(_x, _y, _w, _h);
|
|
|
|
if (imgRect.intersects(r)) {
|
2017-04-12 20:34:57 +00:00
|
|
|
auto rounding = (_doc && _doc->isRoundVideo()) ? ImageRoundRadius::Ellipse : ImageRoundRadius::None;
|
2017-04-02 16:42:18 +00:00
|
|
|
auto toDraw = _current.isNull() ? _gif->current(_gif->width() / cIntRetinaFactor(), _gif->height() / cIntRetinaFactor(), _gif->width() / cIntRetinaFactor(), _gif->height() / cIntRetinaFactor(), rounding, ImageRoundCorner::None, ms) : _current;
|
2015-12-22 08:01:02 +00:00
|
|
|
if (!_gif && (!_doc || !_doc->sticker() || _doc->sticker()->img->isNull()) && toDraw.hasAlpha()) {
|
2014-12-15 15:55:45 +00:00
|
|
|
p.fillRect(imgRect, _transparentBrush);
|
|
|
|
}
|
2015-12-22 08:01:02 +00:00
|
|
|
if (toDraw.width() != _w * cIntRetinaFactor()) {
|
2016-12-03 12:10:35 +00:00
|
|
|
PainterHighQualityEnabler hq(p);
|
2015-12-22 08:01:02 +00:00
|
|
|
p.drawPixmap(QRect(_x, _y, _w, _h), toDraw);
|
2014-10-07 17:57:57 +00:00
|
|
|
} else {
|
2015-12-22 08:01:02 +00:00
|
|
|
p.drawPixmap(_x, _y, toDraw);
|
2014-10-07 17:57:57 +00:00
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
|
2016-06-21 18:09:48 +00:00
|
|
|
bool radial = false;
|
|
|
|
float64 radialOpacity = 0;
|
|
|
|
if (_radial.animating()) {
|
|
|
|
_radial.step(ms);
|
|
|
|
radial = _radial.animating();
|
|
|
|
radialOpacity = _radial.opacity();
|
2014-10-17 12:57:14 +00:00
|
|
|
}
|
2016-07-19 10:54:43 +00:00
|
|
|
if (_photo) {
|
|
|
|
if (radial) {
|
|
|
|
auto inner = radialRect();
|
2016-06-21 18:09:48 +00:00
|
|
|
|
2016-07-19 10:54:43 +00:00
|
|
|
p.setPen(Qt::NoPen);
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setOpacity(radialOpacity);
|
|
|
|
p.setBrush(st::radialBg);
|
2016-07-19 10:54:43 +00:00
|
|
|
|
2016-12-03 12:10:35 +00:00
|
|
|
{
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.drawEllipse(inner);
|
|
|
|
}
|
2016-06-21 18:09:48 +00:00
|
|
|
|
2016-07-19 10:54:43 +00:00
|
|
|
p.setOpacity(1);
|
|
|
|
QRect arc(inner.marginsRemoved(QMargins(st::radialLine, st::radialLine, st::radialLine, st::radialLine)));
|
2016-10-31 12:29:26 +00:00
|
|
|
_radial.draw(p, arc, st::radialLine, st::radialFg);
|
2016-07-19 10:54:43 +00:00
|
|
|
}
|
|
|
|
} else if (_doc) {
|
|
|
|
paintDocRadialLoading(p, radial, radialOpacity);
|
2016-06-21 18:09:48 +00:00
|
|
|
}
|
|
|
|
|
2014-10-17 12:57:14 +00:00
|
|
|
if (_saveMsgStarted) {
|
2016-06-21 18:09:48 +00:00
|
|
|
auto ms = getms();
|
2016-12-23 13:21:01 +00:00
|
|
|
float64 dt = float64(ms) - _saveMsgStarted, hidingDt = dt - st::mediaviewSaveMsgShowing - st::mediaviewSaveMsgShown;
|
|
|
|
if (dt < st::mediaviewSaveMsgShowing + st::mediaviewSaveMsgShown + st::mediaviewSaveMsgHiding) {
|
2014-10-17 12:57:14 +00:00
|
|
|
if (hidingDt >= 0 && _saveMsgOpacity.to() > 0.5) {
|
|
|
|
_saveMsgOpacity.start(0);
|
|
|
|
}
|
2016-12-23 13:21:01 +00:00
|
|
|
float64 progress = (hidingDt >= 0) ? (hidingDt / st::mediaviewSaveMsgHiding) : (dt / st::mediaviewSaveMsgShowing);
|
2014-10-17 12:57:14 +00:00
|
|
|
_saveMsgOpacity.update(qMin(progress, 1.), anim::linear);
|
2014-10-17 13:24:17 +00:00
|
|
|
if (_saveMsgOpacity.current() > 0) {
|
2014-10-17 12:57:14 +00:00
|
|
|
p.setOpacity(_saveMsgOpacity.current());
|
2016-12-21 15:05:58 +00:00
|
|
|
App::roundRect(p, _saveMsg, st::mediaviewSaveMsgBg, MediaviewSaveCorners);
|
2016-12-23 13:21:01 +00:00
|
|
|
st::mediaviewSaveMsgCheck.paint(p, _saveMsg.topLeft() + st::mediaviewSaveMsgCheckPos, width());
|
2014-10-17 12:57:14 +00:00
|
|
|
|
2016-12-21 15:05:58 +00:00
|
|
|
p.setPen(st::mediaviewSaveMsgFg);
|
2016-12-23 13:21:01 +00:00
|
|
|
p.setTextPalette(st::mediaviewTextPalette);
|
|
|
|
_saveMsgText.draw(p, _saveMsg.x() + st::mediaviewSaveMsgPadding.left(), _saveMsg.y() + st::mediaviewSaveMsgPadding.top(), _saveMsg.width() - st::mediaviewSaveMsgPadding.left() - st::mediaviewSaveMsgPadding.right());
|
|
|
|
p.restoreTextPalette();
|
2014-10-17 12:57:14 +00:00
|
|
|
p.setOpacity(1);
|
|
|
|
}
|
|
|
|
if (_full >= 1) {
|
2016-12-23 13:21:01 +00:00
|
|
|
auto nextFrame = (dt < st::mediaviewSaveMsgShowing || hidingDt >= 0) ? int(AnimationTimerDelta) : (st::mediaviewSaveMsgShowing + st::mediaviewSaveMsgShown + 1 - dt);
|
2014-10-17 12:57:14 +00:00
|
|
|
_saveMsgUpdater.start(nextFrame);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_saveMsgStarted = 0;
|
|
|
|
}
|
2014-10-07 17:57:57 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-23 13:21:01 +00:00
|
|
|
} else if (_themePreviewShown) {
|
|
|
|
paintThemePreview(p, r);
|
2015-07-15 11:23:59 +00:00
|
|
|
} else {
|
2015-04-11 10:04:10 +00:00
|
|
|
if (_docRect.intersects(r)) {
|
2016-10-31 12:29:26 +00:00
|
|
|
p.fillRect(_docRect, st::mediaviewFileBg);
|
2015-04-19 10:29:19 +00:00
|
|
|
if (_docIconRect.intersects(r)) {
|
2015-12-24 19:26:28 +00:00
|
|
|
bool radial = false;
|
|
|
|
float64 radialOpacity = 0;
|
2016-06-21 18:09:48 +00:00
|
|
|
if (_radial.animating()) {
|
|
|
|
_radial.step(ms);
|
|
|
|
radial = _radial.animating();
|
|
|
|
radialOpacity = _radial.opacity();
|
2015-12-24 19:26:28 +00:00
|
|
|
}
|
2015-07-15 11:23:59 +00:00
|
|
|
if (!_doc || _doc->thumb->isNull()) {
|
2016-12-23 13:21:01 +00:00
|
|
|
p.fillRect(_docIconRect, _docIconColor);
|
2016-09-30 16:40:00 +00:00
|
|
|
if ((!_doc || _doc->loaded()) && (!radial || radialOpacity < 1) && _docIcon) {
|
|
|
|
_docIcon->paint(p, _docIconRect.x() + (_docIconRect.width() - _docIcon->width()), _docIconRect.y(), width());
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::mediaviewFileExtFg);
|
|
|
|
p.setFont(st::mediaviewFileExtFont);
|
2015-07-15 11:23:59 +00:00
|
|
|
if (!_docExt.isEmpty()) {
|
2016-10-31 12:29:26 +00:00
|
|
|
p.drawText(_docIconRect.x() + (_docIconRect.width() - _docExtWidth) / 2, _docIconRect.y() + st::mediaviewFileExtTop + st::mediaviewFileExtFont->ascent, _docExt);
|
2015-07-15 11:23:59 +00:00
|
|
|
}
|
2015-04-19 10:29:19 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int32 rf(cIntRetinaFactor());
|
2016-10-31 12:29:26 +00:00
|
|
|
p.drawPixmap(_docIconRect.topLeft(), _doc->thumb->pix(_docThumbw), QRect(_docThumbx * rf, _docThumby * rf, st::mediaviewFileIconSize * rf, st::mediaviewFileIconSize * rf));
|
2015-04-19 10:29:19 +00:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:54:43 +00:00
|
|
|
paintDocRadialLoading(p, radial, radialOpacity);
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
|
|
|
|
2015-04-19 10:29:19 +00:00
|
|
|
if (!_docIconRect.contains(r)) {
|
2015-04-19 19:01:45 +00:00
|
|
|
name = true;
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::mediaviewFileNameFg);
|
|
|
|
p.setFont(st::mediaviewFileNameFont);
|
|
|
|
p.drawTextLeft(_docRect.x() + 2 * st::mediaviewFilePadding + st::mediaviewFileIconSize, _docRect.y() + st::mediaviewFilePadding + st::mediaviewFileNameTop, width(), _docName, _docNameWidth);
|
2015-04-11 10:04:10 +00:00
|
|
|
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::mediaviewFileSizeFg);
|
2016-12-23 13:21:01 +00:00
|
|
|
p.setFont(st::mediaviewFont);
|
2016-10-31 12:29:26 +00:00
|
|
|
p.drawTextLeft(_docRect.x() + 2 * st::mediaviewFilePadding + st::mediaviewFileIconSize, _docRect.y() + st::mediaviewFilePadding + st::mediaviewFileSizeTop, width(), _docSize, _docSizeWidth);
|
2015-04-19 10:29:19 +00:00
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
2014-10-17 12:57:14 +00:00
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
|
2016-07-14 11:20:46 +00:00
|
|
|
float64 co = _fullScreenVideo ? 0. : a_cOpacity.current();
|
2015-04-11 10:04:10 +00:00
|
|
|
if (co > 0) {
|
|
|
|
// left nav bar
|
|
|
|
if (_leftNav.intersects(r) && _leftNavVisible) {
|
2016-09-30 16:40:00 +00:00
|
|
|
auto o = overLevel(OverLeftNav);
|
2015-04-11 10:04:10 +00:00
|
|
|
if (o > 0) {
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setOpacity(o * co);
|
2015-04-19 19:01:45 +00:00
|
|
|
for (int i = 0, l = region.rectCount(); i < l; ++i) {
|
2016-09-30 16:40:00 +00:00
|
|
|
auto fill = _leftNav.intersected(rs.at(i));
|
2016-10-31 12:29:26 +00:00
|
|
|
if (!fill.isEmpty()) p.fillRect(fill, st::mediaviewControlBg);
|
2015-04-19 19:01:45 +00:00
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
2015-04-19 19:01:45 +00:00
|
|
|
if (_leftNavIcon.intersects(r)) {
|
2016-12-23 13:21:01 +00:00
|
|
|
p.setOpacity((o * st::mediaviewIconOverOpacity + (1 - o) * st::mediaviewIconOpacity) * co);
|
2016-09-30 16:40:00 +00:00
|
|
|
st::mediaviewLeft.paintInCenter(p, _leftNavIcon);
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
// right nav bar
|
|
|
|
if (_rightNav.intersects(r) && _rightNavVisible) {
|
2016-09-30 16:40:00 +00:00
|
|
|
auto o = overLevel(OverRightNav);
|
2015-04-11 10:04:10 +00:00
|
|
|
if (o > 0) {
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setOpacity(o * co);
|
2015-04-19 19:01:45 +00:00
|
|
|
for (int i = 0, l = region.rectCount(); i < l; ++i) {
|
2016-09-30 16:40:00 +00:00
|
|
|
auto fill = _rightNav.intersected(rs.at(i));
|
2016-10-31 12:29:26 +00:00
|
|
|
if (!fill.isEmpty()) p.fillRect(fill, st::mediaviewControlBg);
|
2015-04-19 19:01:45 +00:00
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
2015-04-19 19:01:45 +00:00
|
|
|
if (_rightNavIcon.intersects(r)) {
|
2016-12-23 13:21:01 +00:00
|
|
|
p.setOpacity((o * st::mediaviewIconOverOpacity + (1 - o) * st::mediaviewIconOpacity) * co);
|
2016-09-30 16:40:00 +00:00
|
|
|
st::mediaviewRight.paintInCenter(p, _rightNavIcon);
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
2014-10-07 17:57:57 +00:00
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
// close button
|
|
|
|
if (_closeNav.intersects(r)) {
|
2016-09-30 16:40:00 +00:00
|
|
|
auto o = overLevel(OverClose);
|
2015-04-11 10:04:10 +00:00
|
|
|
if (o > 0) {
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setOpacity(o * co);
|
2015-04-19 19:01:45 +00:00
|
|
|
for (int i = 0, l = region.rectCount(); i < l; ++i) {
|
2016-09-30 16:40:00 +00:00
|
|
|
auto fill = _closeNav.intersected(rs.at(i));
|
2016-10-31 12:29:26 +00:00
|
|
|
if (!fill.isEmpty()) p.fillRect(fill, st::mediaviewControlBg);
|
2015-04-19 19:01:45 +00:00
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
2015-04-19 19:01:45 +00:00
|
|
|
if (_closeNavIcon.intersects(r)) {
|
2016-12-23 13:21:01 +00:00
|
|
|
p.setOpacity((o * st::mediaviewIconOverOpacity + (1 - o) * st::mediaviewIconOpacity) * co);
|
2016-09-30 16:40:00 +00:00
|
|
|
st::mediaviewClose.paintInCenter(p, _closeNavIcon);
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// save button
|
2015-07-15 11:23:59 +00:00
|
|
|
if (_saveVisible && _saveNavIcon.intersects(r)) {
|
2016-09-30 16:40:00 +00:00
|
|
|
auto o = overLevel(OverSave);
|
2016-12-23 13:21:01 +00:00
|
|
|
p.setOpacity((o * st::mediaviewIconOverOpacity + (1 - o) * st::mediaviewIconOpacity) * co);
|
2016-09-30 16:40:00 +00:00
|
|
|
st::mediaviewSave.paintInCenter(p, _saveNavIcon);
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// more area
|
2015-04-19 19:01:45 +00:00
|
|
|
if (_moreNavIcon.intersects(r)) {
|
2016-09-30 16:40:00 +00:00
|
|
|
auto o = overLevel(OverMore);
|
2016-12-23 13:21:01 +00:00
|
|
|
p.setOpacity((o * st::mediaviewIconOverOpacity + (1 - o) * st::mediaviewIconOpacity) * co);
|
2016-09-30 16:40:00 +00:00
|
|
|
st::mediaviewMore.paintInCenter(p, _moreNavIcon);
|
2014-10-17 12:57:14 +00:00
|
|
|
}
|
2014-10-07 17:57:57 +00:00
|
|
|
|
2016-12-21 15:05:58 +00:00
|
|
|
p.setPen(st::mediaviewControlFg);
|
2016-12-23 13:21:01 +00:00
|
|
|
p.setFont(st::mediaviewThickFont);
|
2015-04-11 10:04:10 +00:00
|
|
|
|
|
|
|
// header
|
|
|
|
if (_headerNav.intersects(r)) {
|
2016-10-31 12:29:26 +00:00
|
|
|
auto o = _headerHasLink ? overLevel(OverHeader) : 0;
|
2016-12-23 13:21:01 +00:00
|
|
|
p.setOpacity((o * st::mediaviewIconOverOpacity + (1 - o) * st::mediaviewIconOpacity) * co);
|
|
|
|
p.drawText(_headerNav.left(), _headerNav.top() + st::mediaviewThickFont->ascent, _headerText);
|
2015-04-11 10:04:10 +00:00
|
|
|
|
|
|
|
if (o > 0) {
|
|
|
|
p.setOpacity(o * co);
|
2016-12-23 13:21:01 +00:00
|
|
|
p.drawLine(_headerNav.left(), _headerNav.top() + st::mediaviewThickFont->ascent + 1, _headerNav.right(), _headerNav.top() + st::mediaviewThickFont->ascent + 1);
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
p.setFont(st::mediaviewFont);
|
2015-04-11 10:04:10 +00:00
|
|
|
|
|
|
|
// name
|
|
|
|
if (_from && _nameNav.intersects(r)) {
|
|
|
|
float64 o = overLevel(OverName);
|
2016-12-23 13:21:01 +00:00
|
|
|
p.setOpacity((o * st::mediaviewIconOverOpacity + (1 - o) * st::mediaviewIconOpacity) * co);
|
2015-01-02 14:55:24 +00:00
|
|
|
_fromName.drawElided(p, _nameNav.left(), _nameNav.top(), _nameNav.width());
|
2015-04-11 10:04:10 +00:00
|
|
|
|
|
|
|
if (o > 0) {
|
|
|
|
p.setOpacity(o * co);
|
2016-12-23 13:21:01 +00:00
|
|
|
p.drawLine(_nameNav.left(), _nameNav.top() + st::mediaviewFont->ascent + 1, _nameNav.right(), _nameNav.top() + st::mediaviewFont->ascent + 1);
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
2015-01-02 14:55:24 +00:00
|
|
|
}
|
2014-10-07 17:57:57 +00:00
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
// date
|
|
|
|
if (_dateNav.intersects(r)) {
|
2015-01-02 14:55:24 +00:00
|
|
|
float64 o = overLevel(OverDate);
|
2016-12-23 13:21:01 +00:00
|
|
|
p.setOpacity((o * st::mediaviewIconOverOpacity + (1 - o) * st::mediaviewIconOpacity) * co);
|
|
|
|
p.drawText(_dateNav.left(), _dateNav.top() + st::mediaviewFont->ascent, _dateText);
|
2015-04-11 10:04:10 +00:00
|
|
|
|
|
|
|
if (o > 0) {
|
|
|
|
p.setOpacity(o * co);
|
2016-12-23 13:21:01 +00:00
|
|
|
p.drawLine(_dateNav.left(), _dateNav.top() + st::mediaviewFont->ascent + 1, _dateNav.right(), _dateNav.top() + st::mediaviewFont->ascent + 1);
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
2015-01-02 14:55:24 +00:00
|
|
|
}
|
2015-05-20 19:28:24 +00:00
|
|
|
|
|
|
|
// caption
|
|
|
|
if (!_caption.isEmpty()) {
|
2016-12-23 13:21:01 +00:00
|
|
|
QRect outer(_captionRect.marginsAdded(st::mediaviewCaptionPadding));
|
2015-05-20 19:28:24 +00:00
|
|
|
if (outer.intersects(r)) {
|
|
|
|
p.setOpacity(co);
|
2016-12-21 15:05:58 +00:00
|
|
|
p.setBrush(st::mediaviewCaptionBg);
|
2015-05-20 19:28:24 +00:00
|
|
|
p.setPen(Qt::NoPen);
|
2016-12-23 13:21:01 +00:00
|
|
|
p.drawRoundedRect(outer, st::mediaviewCaptionRadius, st::mediaviewCaptionRadius);
|
2015-05-20 19:28:24 +00:00
|
|
|
if (_captionRect.intersects(r)) {
|
2016-12-23 13:21:01 +00:00
|
|
|
p.setTextPalette(st::mediaviewTextPalette);
|
2016-12-21 15:05:58 +00:00
|
|
|
p.setPen(st::mediaviewCaptionFg);
|
2016-12-23 13:21:01 +00:00
|
|
|
_caption.drawElided(p, _captionRect.x(), _captionRect.y(), _captionRect.width(), _captionRect.height() / st::mediaviewCaptionStyle.font->height);
|
|
|
|
p.restoreTextPalette();
|
2015-05-20 19:28:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-12-15 15:55:45 +00:00
|
|
|
}
|
2014-08-06 14:40:21 +00:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:54:43 +00:00
|
|
|
void MediaView::paintDocRadialLoading(Painter &p, bool radial, float64 radialOpacity) {
|
|
|
|
float64 o = overLevel(OverIcon);
|
2016-10-28 08:02:45 +00:00
|
|
|
if (radial || (_doc && !_doc->loaded())) {
|
2016-07-19 10:54:43 +00:00
|
|
|
QRect inner(QPoint(_docIconRect.x() + ((_docIconRect.width() - st::radialSize.width()) / 2), _docIconRect.y() + ((_docIconRect.height() - st::radialSize.height()) / 2)), st::radialSize);
|
2016-10-28 08:02:45 +00:00
|
|
|
|
2016-07-19 10:54:43 +00:00
|
|
|
p.setPen(Qt::NoPen);
|
2016-11-07 11:24:19 +00:00
|
|
|
p.setOpacity(_doc->loaded() ? radialOpacity : 1.);
|
|
|
|
p.setBrush(anim::brush(st::msgDateImgBg, st::msgDateImgBgOver, o));
|
2016-07-19 10:54:43 +00:00
|
|
|
|
2016-12-03 12:10:35 +00:00
|
|
|
{
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.drawEllipse(inner);
|
|
|
|
}
|
2016-07-19 10:54:43 +00:00
|
|
|
|
2016-10-28 08:02:45 +00:00
|
|
|
p.setOpacity(1.);
|
|
|
|
auto icon = ([radial, this]() -> const style::icon* {
|
|
|
|
if (radial || _doc->loading()) {
|
|
|
|
return &st::historyFileInCancel;
|
|
|
|
}
|
|
|
|
return &st::historyFileInDownload;
|
|
|
|
})();
|
|
|
|
if (icon) {
|
|
|
|
icon->paintInCenter(p, inner);
|
|
|
|
}
|
|
|
|
if (radial) {
|
|
|
|
p.setOpacity(1);
|
|
|
|
QRect arc(inner.marginsRemoved(QMargins(st::radialLine, st::radialLine, st::radialLine, st::radialLine)));
|
2016-10-31 12:29:26 +00:00
|
|
|
_radial.draw(p, arc, st::radialLine, st::radialFg);
|
2016-10-28 08:02:45 +00:00
|
|
|
}
|
2016-07-19 10:54:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
void MediaView::paintThemePreview(Painter &p, QRect clip) {
|
|
|
|
auto fill = _themePreviewRect.intersected(clip);
|
|
|
|
if (!fill.isEmpty()) {
|
|
|
|
if (_themePreview) {
|
|
|
|
p.drawPixmapLeft(_themePreviewRect.x(), _themePreviewRect.y(), width(), _themePreview->preview);
|
|
|
|
} else {
|
|
|
|
p.fillRect(fill, st::themePreviewBg);
|
|
|
|
p.setFont(st::themePreviewLoadingFont);
|
|
|
|
p.setPen(st::themePreviewLoadingFg);
|
|
|
|
p.drawText(_themePreviewRect, lang(_themePreviewId ? lng_theme_preview_generating : lng_theme_preview_invalid), QTextOption(style::al_center));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto fillOverlay = [this, &p, clip](QRect fill) {
|
|
|
|
auto clipped = fill.intersected(clip);
|
|
|
|
if (!clipped.isEmpty()) {
|
|
|
|
p.setOpacity(st::themePreviewOverlayOpacity);
|
|
|
|
p.fillRect(clipped, st::themePreviewBg);
|
|
|
|
p.setOpacity(1.);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
auto titleRect = QRect(_themePreviewRect.x(), _themePreviewRect.y(), _themePreviewRect.width(), st::themePreviewMargin.top());
|
|
|
|
if (titleRect.x() < 0) {
|
|
|
|
titleRect = QRect(0, _themePreviewRect.y(), width(), st::themePreviewMargin.top());
|
|
|
|
}
|
|
|
|
if (auto fillTitleRect = (titleRect.y() < 0)) {
|
|
|
|
titleRect.moveTop(0);
|
|
|
|
fillOverlay(titleRect);
|
|
|
|
}
|
|
|
|
titleRect = titleRect.marginsRemoved(QMargins(st::themePreviewMargin.left(), st::themePreviewTitleTop, st::themePreviewMargin.right(), titleRect.height() - st::themePreviewTitleTop - st::themePreviewTitleFont->height));
|
|
|
|
if (titleRect.intersects(clip)) {
|
|
|
|
p.setFont(st::themePreviewTitleFont);
|
|
|
|
p.setPen(st::themePreviewTitleFg);
|
|
|
|
p.drawTextLeft(titleRect.x(), titleRect.y(), width(), lang(lng_theme_preview_title));
|
|
|
|
}
|
|
|
|
|
|
|
|
auto buttonsRect = QRect(_themePreviewRect.x(), _themePreviewRect.y() + _themePreviewRect.height() - st::themePreviewMargin.bottom(), _themePreviewRect.width(), st::themePreviewMargin.bottom());
|
|
|
|
if (auto fillButtonsRect = (buttonsRect.y() + buttonsRect.height() > height())) {
|
|
|
|
buttonsRect.moveTop(height() - buttonsRect.height());
|
|
|
|
fillOverlay(buttonsRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-06 14:40:21 +00:00
|
|
|
void MediaView::keyPressEvent(QKeyEvent *e) {
|
2016-07-14 11:20:46 +00:00
|
|
|
if (_clipController) {
|
|
|
|
auto toggle1 = (e->key() == Qt::Key_F && e->modifiers().testFlag(Qt::ControlModifier));
|
|
|
|
auto toggle2 = (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) && (e->modifiers().testFlag(Qt::AltModifier) || e->modifiers().testFlag(Qt::ControlModifier));
|
|
|
|
if (toggle1 || toggle2) {
|
|
|
|
onVideoToggleFullScreen();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_fullScreenVideo) {
|
|
|
|
if (e->key() == Qt::Key_Escape) {
|
|
|
|
onVideoToggleFullScreen();
|
|
|
|
} else if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return || e->key() == Qt::Key_Space) {
|
|
|
|
onVideoPauseResume();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
if (!_menu && e->key() == Qt::Key_Escape) {
|
2016-07-19 10:54:43 +00:00
|
|
|
if (_doc && _doc->loading()) {
|
|
|
|
onDocClick();
|
|
|
|
} else {
|
|
|
|
close();
|
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
} else if (e == QKeySequence::Save || e == QKeySequence::SaveAs) {
|
2015-04-19 10:29:19 +00:00
|
|
|
onSaveAs();
|
2014-08-11 09:03:45 +00:00
|
|
|
} else if (e->key() == Qt::Key_Copy || (e->key() == Qt::Key_C && e->modifiers().testFlag(Qt::ControlModifier))) {
|
|
|
|
onCopy();
|
2015-04-19 10:29:19 +00:00
|
|
|
} else if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return || e->key() == Qt::Key_Space) {
|
2016-12-23 13:21:01 +00:00
|
|
|
if (_doc && !_doc->loading() && (fileBubbleShown() || !_doc->loaded())) {
|
2015-04-19 10:29:19 +00:00
|
|
|
onDocClick();
|
2017-04-02 16:42:18 +00:00
|
|
|
} else if (_doc && (_doc->isVideo() || _doc->isRoundVideo())) {
|
2016-07-13 11:24:31 +00:00
|
|
|
onVideoPauseResume();
|
2015-04-19 10:29:19 +00:00
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
} else if (e->key() == Qt::Key_Left) {
|
2015-04-11 10:04:10 +00:00
|
|
|
moveToNext(-1);
|
2014-08-11 09:03:45 +00:00
|
|
|
} else if (e->key() == Qt::Key_Right) {
|
2015-04-11 10:04:10 +00:00
|
|
|
moveToNext(1);
|
2016-08-18 15:35:39 +00:00
|
|
|
} else if (e->modifiers().testFlag(Qt::ControlModifier) && (e->key() == Qt::Key_Plus || e->key() == Qt::Key_Equal || e->key() == ']' || e->key() == Qt::Key_Asterisk || e->key() == Qt::Key_Minus || e->key() == Qt::Key_Underscore || e->key() == Qt::Key_0)) {
|
|
|
|
if (e->key() == Qt::Key_Plus || e->key() == Qt::Key_Equal || e->key() == Qt::Key_Asterisk || e->key() == ']') {
|
|
|
|
zoomIn();
|
2014-10-07 17:57:57 +00:00
|
|
|
} else if (e->key() == Qt::Key_Minus || e->key() == Qt::Key_Underscore) {
|
2016-08-18 15:35:39 +00:00
|
|
|
zoomOut();
|
2014-10-07 17:57:57 +00:00
|
|
|
} else {
|
2016-08-18 15:35:39 +00:00
|
|
|
zoomReset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::wheelEvent(QWheelEvent *e) {
|
2016-09-15 11:08:45 +00:00
|
|
|
#ifdef OS_MAC_OLD
|
|
|
|
constexpr auto step = 120;
|
|
|
|
#else // OS_MAC_OLD
|
2016-09-14 16:05:40 +00:00
|
|
|
constexpr auto step = static_cast<int>(QWheelEvent::DefaultDeltasPerStep);
|
2016-09-15 11:08:45 +00:00
|
|
|
#endif // OS_MAC_OLD
|
2016-09-14 16:05:40 +00:00
|
|
|
|
|
|
|
_verticalWheelDelta += e->angleDelta().y();
|
|
|
|
while (qAbs(_verticalWheelDelta) >= step) {
|
|
|
|
if (_verticalWheelDelta < 0) {
|
|
|
|
_verticalWheelDelta += step;
|
|
|
|
if (e->modifiers().testFlag(Qt::ControlModifier)) {
|
|
|
|
zoomOut();
|
|
|
|
} else {
|
2016-09-15 11:08:45 +00:00
|
|
|
#ifndef OS_MAC_OLD
|
2016-09-14 16:05:40 +00:00
|
|
|
if (e->source() == Qt::MouseEventNotSynthesized) {
|
|
|
|
moveToNext(1);
|
|
|
|
}
|
2016-09-15 11:08:45 +00:00
|
|
|
#endif // OS_MAC_OLD
|
2014-10-07 17:57:57 +00:00
|
|
|
}
|
2016-08-18 15:35:39 +00:00
|
|
|
} else {
|
2016-09-14 16:05:40 +00:00
|
|
|
_verticalWheelDelta -= step;
|
|
|
|
if (e->modifiers().testFlag(Qt::ControlModifier)) {
|
|
|
|
zoomIn();
|
|
|
|
} else {
|
2016-09-15 11:08:45 +00:00
|
|
|
#ifndef OS_MAC_OLD
|
2016-09-14 16:05:40 +00:00
|
|
|
if (e->source() == Qt::MouseEventNotSynthesized) {
|
|
|
|
moveToNext(-1);
|
|
|
|
}
|
2016-09-15 11:08:45 +00:00
|
|
|
#endif // OS_MAC_OLD
|
2014-12-15 15:55:45 +00:00
|
|
|
}
|
2014-10-07 17:57:57 +00:00
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-14 11:20:46 +00:00
|
|
|
void MediaView::setZoomLevel(int newZoom) {
|
|
|
|
if (_zoom == newZoom) return;
|
|
|
|
|
|
|
|
float64 nx, ny, z = (_zoom == ZoomToScreenLevel) ? _zoomToScreen : _zoom;
|
|
|
|
_w = gifShown() ? convertScale(_gif->width()) : (convertScale(_current.width()) / cIntRetinaFactor());
|
|
|
|
_h = gifShown() ? convertScale(_gif->height()) : (convertScale(_current.height()) / cIntRetinaFactor());
|
|
|
|
if (z >= 0) {
|
|
|
|
nx = (_x - width() / 2.) / (z + 1);
|
|
|
|
ny = (_y - height() / 2.) / (z + 1);
|
|
|
|
} else {
|
|
|
|
nx = (_x - width() / 2.) * (-z + 1);
|
|
|
|
ny = (_y - height() / 2.) * (-z + 1);
|
|
|
|
}
|
|
|
|
_zoom = newZoom;
|
|
|
|
z = (_zoom == ZoomToScreenLevel) ? _zoomToScreen : _zoom;
|
|
|
|
if (z > 0) {
|
|
|
|
_w = qRound(_w * (z + 1));
|
|
|
|
_h = qRound(_h * (z + 1));
|
|
|
|
_x = qRound(nx * (z + 1) + width() / 2.);
|
|
|
|
_y = qRound(ny * (z + 1) + height() / 2.);
|
|
|
|
} else {
|
|
|
|
_w = qRound(_w / (-z + 1));
|
|
|
|
_h = qRound(_h / (-z + 1));
|
|
|
|
_x = qRound(nx / (-z + 1) + width() / 2.);
|
|
|
|
_y = qRound(ny / (-z + 1) + height() / 2.);
|
|
|
|
}
|
|
|
|
snapXY();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2016-05-20 16:01:06 +00:00
|
|
|
bool MediaView::moveToNext(int32 delta) {
|
|
|
|
if (_index < 0) {
|
|
|
|
if (delta == -1 && _photo == _additionalChatPhoto) {
|
|
|
|
auto lastChatPhoto = computeLastOverviewChatPhoto();
|
|
|
|
if (lastChatPhoto.item) {
|
|
|
|
if (lastChatPhoto.item->history() == _history) {
|
|
|
|
_index = _history->overview[_overview].size() - 1;
|
|
|
|
_msgmigrated = false;
|
|
|
|
} else {
|
|
|
|
_index = _migrated->overview[_overview].size() - 1;
|
|
|
|
_msgmigrated = true;
|
|
|
|
}
|
|
|
|
_msgid = lastChatPhoto.item->id;
|
|
|
|
_channel = _history ? _history->channelId() : NoChannel;
|
|
|
|
_canForward = _msgid > 0;
|
|
|
|
_canDelete = lastChatPhoto.item->canDelete();
|
2016-12-23 13:21:01 +00:00
|
|
|
displayPhoto(lastChatPhoto.photo, lastChatPhoto.item);
|
|
|
|
preloadData(delta);
|
2016-05-20 16:01:06 +00:00
|
|
|
return true;
|
2016-06-21 14:19:24 +00:00
|
|
|
} else if (_history && (_history->overviewCount(OverviewChatPhotos) != 0 || (
|
|
|
|
_migrated && _migrated->overviewCount(OverviewChatPhotos) != 0))) {
|
|
|
|
loadBack();
|
|
|
|
return true;
|
2016-05-20 16:01:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2017-05-18 13:22:57 +00:00
|
|
|
if (_overview == OverviewCount && (_history || !_user)) {
|
2016-05-20 16:01:06 +00:00
|
|
|
return false;
|
2015-11-16 16:04:37 +00:00
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
if (_msgmigrated && !_history->overviewLoaded(_overview)) {
|
2016-05-20 16:01:06 +00:00
|
|
|
return true;
|
2015-11-16 16:04:37 +00:00
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
|
|
|
|
int32 newIndex = _index + delta;
|
2015-04-11 10:04:10 +00:00
|
|
|
if (_history && _overview != OverviewCount) {
|
2015-11-16 16:04:37 +00:00
|
|
|
bool newMigrated = _msgmigrated;
|
|
|
|
if (!newMigrated && newIndex < 0 && _migrated) {
|
|
|
|
newIndex += _migrated->overview[_overview].size();
|
|
|
|
newMigrated = true;
|
|
|
|
} else if (newMigrated && newIndex >= _migrated->overview[_overview].size()) {
|
2015-11-18 13:11:56 +00:00
|
|
|
newIndex -= _migrated->overview[_overview].size() + (_history->overviewCount(_overview) - _history->overview[_overview].size());
|
2015-11-16 16:04:37 +00:00
|
|
|
newMigrated = false;
|
|
|
|
}
|
|
|
|
if (newIndex >= 0 && newIndex < (newMigrated ? _migrated : _history)->overview[_overview].size()) {
|
|
|
|
if (HistoryItem *item = App::histItemById(newMigrated ? 0 : _channel, (newMigrated ? _migrated : _history)->overview[_overview][newIndex])) {
|
|
|
|
_index = newIndex;
|
2014-08-11 09:03:45 +00:00
|
|
|
_msgid = item->id;
|
2015-11-16 16:04:37 +00:00
|
|
|
_msgmigrated = (item->history() == _migrated);
|
|
|
|
_channel = _history ? _history->channelId() : NoChannel;
|
2015-09-21 20:57:42 +00:00
|
|
|
_canForward = _msgid > 0;
|
|
|
|
_canDelete = item->canDelete();
|
2015-12-23 19:23:14 +00:00
|
|
|
stopGif();
|
2016-12-23 13:21:01 +00:00
|
|
|
if (auto media = item->getMedia()) {
|
2015-12-23 12:19:32 +00:00
|
|
|
switch (media->type()) {
|
2015-07-15 11:23:59 +00:00
|
|
|
case MediaTypePhoto: displayPhoto(static_cast<HistoryPhoto*>(item->getMedia())->photo(), item); preloadData(delta); break;
|
2016-02-12 16:35:06 +00:00
|
|
|
case MediaTypeFile:
|
2016-07-12 18:04:34 +00:00
|
|
|
case MediaTypeVideo:
|
2015-12-31 20:07:41 +00:00
|
|
|
case MediaTypeGif:
|
2015-12-23 12:19:32 +00:00
|
|
|
case MediaTypeSticker: displayDocument(media->getDocument(), item); preloadData(delta); break;
|
2015-07-15 11:23:59 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-12-31 13:34:41 +00:00
|
|
|
displayDocument(nullptr, item);
|
2015-07-15 11:23:59 +00:00
|
|
|
preloadData(delta);
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-20 16:01:06 +00:00
|
|
|
} else if (!newMigrated && newIndex == _history->overview[_overview].size() && _additionalChatPhoto) {
|
|
|
|
_index = -1;
|
|
|
|
_msgid = 0;
|
|
|
|
_msgmigrated = false;
|
|
|
|
_canForward = false;
|
|
|
|
_canDelete = false;
|
|
|
|
displayPhoto(_additionalChatPhoto, 0);
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
if (delta < 0 && _index < MediaOverviewStartPerPage) {
|
2015-04-11 10:04:10 +00:00
|
|
|
loadBack();
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
} else if (_user) {
|
|
|
|
if (newIndex >= 0 && newIndex < _user->photos.size()) {
|
|
|
|
_index = newIndex;
|
2015-05-20 19:28:24 +00:00
|
|
|
displayPhoto(_user->photos[_index], 0);
|
2015-04-11 10:04:10 +00:00
|
|
|
preloadData(delta);
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
if (delta > 0 && _index > _user->photos.size() - MediaOverviewStartPerPage) {
|
2015-04-11 10:04:10 +00:00
|
|
|
loadBack();
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-20 16:01:06 +00:00
|
|
|
return true;
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
void MediaView::preloadData(int32 delta) {
|
2016-05-20 16:01:06 +00:00
|
|
|
int indexInOverview = _index;
|
|
|
|
bool indexOfMigratedItem = _msgmigrated;
|
|
|
|
if (_index < 0) {
|
2016-06-26 15:37:47 +00:00
|
|
|
if (_overview != OverviewChatPhotos || !_history) return;
|
2016-05-20 16:01:06 +00:00
|
|
|
indexInOverview = _history->overview[OverviewChatPhotos].size();
|
|
|
|
indexOfMigratedItem = false;
|
|
|
|
}
|
|
|
|
if (!_user && _overview == OverviewCount) return;
|
2014-08-11 09:03:45 +00:00
|
|
|
|
2016-05-20 16:01:06 +00:00
|
|
|
int32 from = indexInOverview + (delta ? delta : -1), to = indexInOverview + (delta ? delta * MediaOverviewPreloadCount : 1);
|
2014-08-11 09:03:45 +00:00
|
|
|
if (from > to) qSwap(from, to);
|
2015-04-11 10:04:10 +00:00
|
|
|
if (_history && _overview != OverviewCount) {
|
2016-05-20 16:01:06 +00:00
|
|
|
int32 forgetIndex = indexInOverview - delta * 2;
|
|
|
|
History *forgetHistory = indexOfMigratedItem ? _migrated : _history;
|
2015-11-22 12:37:48 +00:00
|
|
|
if (_migrated) {
|
2016-05-20 16:01:06 +00:00
|
|
|
if (indexOfMigratedItem && forgetIndex >= _migrated->overview[_overview].size()) {
|
2015-11-22 12:37:48 +00:00
|
|
|
forgetHistory = _history;
|
|
|
|
forgetIndex -= _migrated->overview[_overview].size() + (_history->overviewCount(_overview) - _history->overview[_overview].size());
|
2016-05-20 16:01:06 +00:00
|
|
|
} else if (!indexOfMigratedItem && forgetIndex < 0) {
|
2015-11-22 12:37:48 +00:00
|
|
|
forgetHistory = _migrated;
|
|
|
|
forgetIndex += _migrated->overview[_overview].size();
|
|
|
|
}
|
2015-11-16 16:04:37 +00:00
|
|
|
}
|
2016-05-20 16:01:06 +00:00
|
|
|
if (forgetIndex >= 0 && forgetIndex < forgetHistory->overview[_overview].size() && (forgetHistory != (indexOfMigratedItem ? _migrated : _history) || forgetIndex != indexInOverview)) {
|
2015-11-16 16:04:37 +00:00
|
|
|
if (HistoryItem *item = App::histItemById(forgetHistory->channelId(), forgetHistory->overview[_overview][forgetIndex])) {
|
2015-04-11 10:04:10 +00:00
|
|
|
if (HistoryMedia *media = item->getMedia()) {
|
|
|
|
switch (media->type()) {
|
|
|
|
case MediaTypePhoto: static_cast<HistoryPhoto*>(media)->photo()->forget(); break;
|
2016-02-12 16:35:06 +00:00
|
|
|
case MediaTypeFile:
|
2016-07-12 18:04:34 +00:00
|
|
|
case MediaTypeVideo:
|
2015-12-31 20:07:41 +00:00
|
|
|
case MediaTypeGif:
|
2015-12-24 19:26:28 +00:00
|
|
|
case MediaTypeSticker: media->getDocument()->forget(); break;
|
2015-12-23 19:23:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int32 i = from; i <= to; ++i) {
|
2016-05-20 16:01:06 +00:00
|
|
|
History *previewHistory = indexOfMigratedItem ? _migrated : _history;
|
2015-12-23 19:23:14 +00:00
|
|
|
int32 previewIndex = i;
|
|
|
|
if (_migrated) {
|
2016-05-20 16:01:06 +00:00
|
|
|
if (indexOfMigratedItem && previewIndex >= _migrated->overview[_overview].size()) {
|
2015-12-23 19:23:14 +00:00
|
|
|
previewHistory = _history;
|
|
|
|
previewIndex -= _migrated->overview[_overview].size() + (_history->overviewCount(_overview) - _history->overview[_overview].size());
|
2016-05-20 16:01:06 +00:00
|
|
|
} else if (!indexOfMigratedItem && previewIndex < 0) {
|
2015-12-23 19:23:14 +00:00
|
|
|
previewHistory = _migrated;
|
|
|
|
previewIndex += _migrated->overview[_overview].size();
|
|
|
|
}
|
|
|
|
}
|
2016-05-20 16:01:06 +00:00
|
|
|
if (previewIndex >= 0 && previewIndex < previewHistory->overview[_overview].size() && (previewHistory != (indexOfMigratedItem ? _migrated : _history) || previewIndex != indexInOverview)) {
|
2015-12-23 19:23:14 +00:00
|
|
|
if (HistoryItem *item = App::histItemById(previewHistory->channelId(), previewHistory->overview[_overview][previewIndex])) {
|
|
|
|
if (HistoryMedia *media = item->getMedia()) {
|
|
|
|
switch (media->type()) {
|
2015-12-25 13:09:14 +00:00
|
|
|
case MediaTypePhoto: static_cast<HistoryPhoto*>(media)->photo()->download(); break;
|
2016-02-12 16:35:06 +00:00
|
|
|
case MediaTypeFile:
|
2016-07-12 18:04:34 +00:00
|
|
|
case MediaTypeVideo:
|
2015-12-23 19:23:14 +00:00
|
|
|
case MediaTypeGif: {
|
|
|
|
DocumentData *doc = media->getDocument();
|
|
|
|
doc->thumb->load();
|
2015-12-24 19:26:28 +00:00
|
|
|
doc->automaticLoad(item);
|
2015-12-23 19:23:14 +00:00
|
|
|
} break;
|
|
|
|
case MediaTypeSticker: media->getDocument()->sticker()->img->load(); break;
|
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
2014-08-15 11:19:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
} else if (_user) {
|
|
|
|
for (int32 i = from; i <= to; ++i) {
|
2016-05-20 16:01:06 +00:00
|
|
|
if (i >= 0 && i < _user->photos.size() && i != indexInOverview) {
|
2014-08-11 09:03:45 +00:00
|
|
|
_user->photos[i]->thumb->load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int32 i = from; i <= to; ++i) {
|
2016-05-20 16:01:06 +00:00
|
|
|
if (i >= 0 && i < _user->photos.size() && i != indexInOverview) {
|
2015-12-25 13:09:14 +00:00
|
|
|
_user->photos[i]->download();
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-20 16:01:06 +00:00
|
|
|
int32 forgetIndex = indexInOverview - delta * 2;
|
|
|
|
if (forgetIndex >= 0 && forgetIndex < _user->photos.size() && forgetIndex != indexInOverview) {
|
2015-11-16 16:04:37 +00:00
|
|
|
_user->photos[forgetIndex]->forget();
|
2014-08-15 11:19:32 +00:00
|
|
|
}
|
2014-08-06 14:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::mousePressEvent(QMouseEvent *e) {
|
2014-08-11 09:03:45 +00:00
|
|
|
updateOver(e->pos());
|
|
|
|
if (_menu || !_receiveMouse) return;
|
2015-05-20 19:28:24 +00:00
|
|
|
|
2016-03-29 17:17:00 +00:00
|
|
|
ClickHandler::pressed();
|
2014-08-11 09:03:45 +00:00
|
|
|
|
2014-08-06 14:40:21 +00:00
|
|
|
if (e->button() == Qt::LeftButton) {
|
2014-08-11 09:03:45 +00:00
|
|
|
_down = OverNone;
|
2016-03-29 17:17:00 +00:00
|
|
|
if (!ClickHandler::getPressed()) {
|
2016-05-20 16:01:06 +00:00
|
|
|
if (_over == OverLeftNav && moveToNext(-1)) {
|
2014-10-17 12:57:14 +00:00
|
|
|
_lastAction = e->pos();
|
2016-05-20 16:01:06 +00:00
|
|
|
} else if (_over == OverRightNav && moveToNext(1)) {
|
2014-10-17 12:57:14 +00:00
|
|
|
_lastAction = e->pos();
|
|
|
|
} else if (_over == OverName) {
|
|
|
|
_down = OverName;
|
|
|
|
} else if (_over == OverDate) {
|
|
|
|
_down = OverDate;
|
2015-04-11 10:04:10 +00:00
|
|
|
} else if (_over == OverHeader) {
|
|
|
|
_down = OverHeader;
|
|
|
|
} else if (_over == OverSave) {
|
|
|
|
_down = OverSave;
|
2015-04-19 10:29:19 +00:00
|
|
|
} else if (_over == OverIcon) {
|
|
|
|
_down = OverIcon;
|
2015-04-11 10:04:10 +00:00
|
|
|
} else if (_over == OverMore) {
|
|
|
|
_down = OverMore;
|
|
|
|
} else if (_over == OverClose) {
|
|
|
|
_down = OverClose;
|
2016-07-14 11:20:46 +00:00
|
|
|
} else if (_over == OverVideo) {
|
|
|
|
_down = OverVideo;
|
2015-04-11 10:04:10 +00:00
|
|
|
} else if (!_saveMsg.contains(e->pos()) || !_saveMsgStarted) {
|
2014-10-17 12:57:14 +00:00
|
|
|
_pressed = true;
|
|
|
|
_dragging = 0;
|
2016-07-24 08:53:09 +00:00
|
|
|
updateCursor();
|
2014-10-17 12:57:14 +00:00
|
|
|
_mStart = e->pos();
|
|
|
|
_xStart = _x;
|
|
|
|
_yStart = _y;
|
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
2016-08-18 15:35:39 +00:00
|
|
|
} else if (e->button() == Qt::MiddleButton) {
|
|
|
|
zoomReset();
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
activateControls();
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
|
2016-07-14 11:20:46 +00:00
|
|
|
void MediaView::mouseDoubleClickEvent(QMouseEvent *e) {
|
|
|
|
updateOver(e->pos());
|
|
|
|
|
|
|
|
if (_over == OverVideo) {
|
|
|
|
onVideoToggleFullScreen();
|
|
|
|
onVideoPauseResume();
|
|
|
|
} else {
|
|
|
|
e->ignore();
|
|
|
|
return TWidget::mouseDoubleClickEvent(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-07 17:57:57 +00:00
|
|
|
void MediaView::snapXY() {
|
2015-04-11 10:04:10 +00:00
|
|
|
int32 xmin = width() - _w, xmax = 0;
|
|
|
|
int32 ymin = height() - _h, ymax = 0;
|
|
|
|
if (xmin > (width() - _w) / 2) xmin = (width() - _w) / 2;
|
|
|
|
if (xmax < (width() - _w) / 2) xmax = (width() - _w) / 2;
|
|
|
|
if (ymin > (height() - _h) / 2) ymin = (height() - _h) / 2;
|
|
|
|
if (ymax < (height() - _h) / 2) ymax = (height() - _h) / 2;
|
2014-10-07 17:57:57 +00:00
|
|
|
if (_x < xmin) _x = xmin;
|
|
|
|
if (_x > xmax) _x = xmax;
|
|
|
|
if (_y < ymin) _y = ymin;
|
|
|
|
if (_y > ymax) _y = ymax;
|
|
|
|
}
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
void MediaView::mouseMoveEvent(QMouseEvent *e) {
|
|
|
|
updateOver(e->pos());
|
2016-12-23 13:21:01 +00:00
|
|
|
if (_lastAction.x() >= 0 && (e->pos() - _lastAction).manhattanLength() >= st::mediaviewDeltaFromLastAction) {
|
|
|
|
_lastAction = QPoint(-st::mediaviewDeltaFromLastAction, -st::mediaviewDeltaFromLastAction);
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
2014-10-07 17:57:57 +00:00
|
|
|
if (_pressed) {
|
|
|
|
if (!_dragging && (e->pos() - _mStart).manhattanLength() >= QApplication::startDragDistance()) {
|
|
|
|
_dragging = QRect(_x, _y, _w, _h).contains(_mStart) ? 1 : -1;
|
|
|
|
if (_dragging > 0) {
|
2015-04-11 10:04:10 +00:00
|
|
|
if (_w > width() || _h > height()) {
|
2014-10-07 17:57:57 +00:00
|
|
|
setCursor(style::cur_sizeall);
|
|
|
|
} else {
|
|
|
|
setCursor(style::cur_default);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_dragging > 0) {
|
|
|
|
_x = _xStart + (e->pos() - _mStart).x();
|
|
|
|
_y = _yStart + (e->pos() - _mStart).y();
|
|
|
|
snapXY();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
|
2015-04-19 19:01:45 +00:00
|
|
|
void MediaView::updateOverRect(OverState state) {
|
|
|
|
switch (state) {
|
|
|
|
case OverLeftNav: update(_leftNav); break;
|
|
|
|
case OverRightNav: update(_rightNav); break;
|
|
|
|
case OverName: update(_nameNav); break;
|
|
|
|
case OverDate: update(_dateNav); break;
|
|
|
|
case OverSave: update(_saveNavIcon); break;
|
|
|
|
case OverIcon: update(_docIconRect); break;
|
|
|
|
case OverHeader: update(_headerNav); break;
|
|
|
|
case OverClose: update(_closeNav); break;
|
|
|
|
case OverMore: update(_moreNavIcon); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
bool MediaView::updateOverState(OverState newState) {
|
|
|
|
bool result = true;
|
|
|
|
if (_over != newState) {
|
2015-04-11 10:04:10 +00:00
|
|
|
if (newState == OverMore && !_ignoringDropdown) {
|
2016-12-31 15:19:22 +00:00
|
|
|
_dropdownShowTimer->start(0);
|
|
|
|
} else {
|
|
|
|
_dropdownShowTimer->stop();
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
2015-04-19 19:01:45 +00:00
|
|
|
updateOverRect(_over);
|
|
|
|
updateOverRect(newState);
|
2014-08-11 09:03:45 +00:00
|
|
|
if (_over != OverNone) {
|
|
|
|
_animations[_over] = getms();
|
|
|
|
ShowingOpacities::iterator i = _animOpacities.find(_over);
|
|
|
|
if (i != _animOpacities.end()) {
|
|
|
|
i->start(0);
|
|
|
|
} else {
|
2016-12-05 11:01:08 +00:00
|
|
|
_animOpacities.insert(_over, anim::value(1, 0));
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
2015-12-08 12:33:37 +00:00
|
|
|
if (!_a_state.animating()) _a_state.start();
|
2014-08-11 09:03:45 +00:00
|
|
|
} else {
|
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
_over = newState;
|
|
|
|
if (newState != OverNone) {
|
|
|
|
_animations[_over] = getms();
|
|
|
|
ShowingOpacities::iterator i = _animOpacities.find(_over);
|
|
|
|
if (i != _animOpacities.end()) {
|
|
|
|
i->start(1);
|
|
|
|
} else {
|
2016-12-31 15:19:22 +00:00
|
|
|
_animOpacities.insert(_over, anim::value(0, 1));
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
2015-12-08 12:33:37 +00:00
|
|
|
if (!_a_state.animating()) _a_state.start();
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
2016-07-24 08:53:09 +00:00
|
|
|
updateCursor();
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-04-19 19:01:45 +00:00
|
|
|
void MediaView::updateOver(QPoint pos) {
|
2016-03-29 17:17:00 +00:00
|
|
|
ClickHandlerPtr lnk;
|
|
|
|
ClickHandlerHost *lnkhost = nullptr;
|
2015-05-20 19:28:24 +00:00
|
|
|
if (_saveMsgStarted && _saveMsg.contains(pos)) {
|
2017-06-21 21:38:31 +00:00
|
|
|
auto textState = _saveMsgText.getState(pos - _saveMsg.topLeft() - QPoint(st::mediaviewSaveMsgPadding.left(), st::mediaviewSaveMsgPadding.top()), _saveMsg.width() - st::mediaviewSaveMsgPadding.left() - st::mediaviewSaveMsgPadding.right());
|
2016-04-13 18:29:32 +00:00
|
|
|
lnk = textState.link;
|
2016-03-29 17:17:00 +00:00
|
|
|
lnkhost = this;
|
2015-05-20 19:28:24 +00:00
|
|
|
} else if (_captionRect.contains(pos)) {
|
2017-06-21 21:38:31 +00:00
|
|
|
auto textState = _caption.getState(pos - _captionRect.topLeft(), _captionRect.width());
|
2016-04-13 18:29:32 +00:00
|
|
|
lnk = textState.link;
|
2016-03-29 17:17:00 +00:00
|
|
|
lnkhost = this;
|
2015-05-20 19:28:24 +00:00
|
|
|
}
|
2015-04-19 19:01:45 +00:00
|
|
|
|
|
|
|
// retina
|
|
|
|
if (pos.x() == width()) {
|
|
|
|
pos.setX(pos.x() - 1);
|
|
|
|
}
|
|
|
|
if (pos.y() == height()) {
|
|
|
|
pos.setY(pos.y() - 1);
|
|
|
|
}
|
|
|
|
|
2016-03-29 17:17:00 +00:00
|
|
|
ClickHandler::setActive(lnk, lnkhost);
|
2014-10-17 12:57:14 +00:00
|
|
|
|
2014-10-07 17:57:57 +00:00
|
|
|
if (_pressed || _dragging) return;
|
|
|
|
|
2016-07-14 11:20:46 +00:00
|
|
|
if (_fullScreenVideo) {
|
|
|
|
updateOverState(OverVideo);
|
|
|
|
} else if (_leftNavVisible && _leftNav.contains(pos)) {
|
2015-04-19 19:01:45 +00:00
|
|
|
updateOverState(OverLeftNav);
|
2014-08-11 09:03:45 +00:00
|
|
|
} else if (_rightNavVisible && _rightNav.contains(pos)) {
|
2015-04-19 19:01:45 +00:00
|
|
|
updateOverState(OverRightNav);
|
2014-08-11 09:03:45 +00:00
|
|
|
} else if (_nameNav.contains(pos)) {
|
2015-04-19 19:01:45 +00:00
|
|
|
updateOverState(OverName);
|
2014-08-11 09:03:45 +00:00
|
|
|
} else if (_msgid && _dateNav.contains(pos)) {
|
2015-04-19 19:01:45 +00:00
|
|
|
updateOverState(OverDate);
|
2015-04-11 10:04:10 +00:00
|
|
|
} else if (_headerHasLink && _headerNav.contains(pos)) {
|
2015-04-19 19:01:45 +00:00
|
|
|
updateOverState(OverHeader);
|
2015-04-11 10:04:10 +00:00
|
|
|
} else if (_saveVisible && _saveNav.contains(pos)) {
|
2015-04-19 19:01:45 +00:00
|
|
|
updateOverState(OverSave);
|
2016-12-23 13:21:01 +00:00
|
|
|
} else if (_doc && fileBubbleShown() && _docIconRect.contains(pos)) {
|
2015-04-19 19:01:45 +00:00
|
|
|
updateOverState(OverIcon);
|
2015-04-11 10:04:10 +00:00
|
|
|
} else if (_moreNav.contains(pos)) {
|
2015-04-19 19:01:45 +00:00
|
|
|
updateOverState(OverMore);
|
2015-04-11 10:04:10 +00:00
|
|
|
} else if (_closeNav.contains(pos)) {
|
2015-04-19 19:01:45 +00:00
|
|
|
updateOverState(OverClose);
|
2016-07-19 10:54:43 +00:00
|
|
|
} else if (_doc && fileShown() && QRect(_x, _y, _w, _h).contains(pos)) {
|
2017-04-02 16:42:18 +00:00
|
|
|
if ((_doc->isVideo() || _doc->isRoundVideo()) && _gif) {
|
2016-07-19 10:54:43 +00:00
|
|
|
updateOverState(OverVideo);
|
|
|
|
} else if (!_doc->loaded()) {
|
|
|
|
updateOverState(OverIcon);
|
|
|
|
} else if (_over != OverNone) {
|
|
|
|
updateOverState(OverNone);
|
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
} else if (_over != OverNone) {
|
2014-08-11 09:03:45 +00:00
|
|
|
updateOverState(OverNone);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::mouseReleaseEvent(QMouseEvent *e) {
|
|
|
|
updateOver(e->pos());
|
2016-03-29 17:17:00 +00:00
|
|
|
|
|
|
|
if (ClickHandlerPtr activated = ClickHandler::unpressed()) {
|
|
|
|
App::activateClickHandler(activated, e->button());
|
2015-09-21 20:57:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-03-29 17:17:00 +00:00
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
if (_over == OverName && _down == OverName) {
|
2015-01-02 14:55:24 +00:00
|
|
|
if (App::wnd() && _from) {
|
2015-04-11 10:04:10 +00:00
|
|
|
close();
|
2016-05-19 12:03:51 +00:00
|
|
|
Ui::showPeerProfile(_from);
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
} else if (_over == OverDate && _down == OverDate) {
|
|
|
|
onToMessage();
|
|
|
|
} else if (_over == OverHeader && _down == OverHeader) {
|
|
|
|
onOverview();
|
|
|
|
} else if (_over == OverSave && _down == OverSave) {
|
|
|
|
onDownload();
|
2015-04-19 10:29:19 +00:00
|
|
|
} else if (_over == OverIcon && _down == OverIcon) {
|
|
|
|
onDocClick();
|
2015-04-11 10:04:10 +00:00
|
|
|
} else if (_over == OverMore && _down == OverMore) {
|
|
|
|
QTimer::singleShot(0, this, SLOT(onDropdown()));
|
|
|
|
} else if (_over == OverClose && _down == OverClose) {
|
|
|
|
close();
|
2016-07-14 11:20:46 +00:00
|
|
|
} else if (_over == OverVideo && _down == OverVideo) {
|
|
|
|
onVideoPauseResume();
|
2014-10-07 17:57:57 +00:00
|
|
|
} else if (_pressed) {
|
|
|
|
if (_dragging) {
|
|
|
|
if (_dragging > 0) {
|
|
|
|
_x = _xStart + (e->pos() - _mStart).x();
|
|
|
|
_y = _yStart + (e->pos() - _mStart).y();
|
|
|
|
snapXY();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
_dragging = 0;
|
|
|
|
setCursor(style::cur_default);
|
2016-12-23 13:21:01 +00:00
|
|
|
} else if ((e->pos() - _lastAction).manhattanLength() >= st::mediaviewDeltaFromLastAction) {
|
|
|
|
if (_themePreviewShown) {
|
|
|
|
if (!_themePreviewRect.contains(e->pos())) {
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
} else if (!_doc || fileShown() || !_docRect.contains(e->pos())) {
|
|
|
|
close();
|
|
|
|
}
|
2014-10-07 17:57:57 +00:00
|
|
|
}
|
|
|
|
_pressed = false;
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
_down = OverNone;
|
2015-04-11 10:04:10 +00:00
|
|
|
activateControls();
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::contextMenuEvent(QContextMenuEvent *e) {
|
2015-04-11 10:04:10 +00:00
|
|
|
if (e->reason() != QContextMenuEvent::Mouse || QRect(_x, _y, _w, _h).contains(e->pos())) {
|
2014-10-07 17:57:57 +00:00
|
|
|
if (_menu) {
|
|
|
|
_menu->deleteLater();
|
|
|
|
_menu = 0;
|
|
|
|
}
|
2017-01-11 05:30:51 +00:00
|
|
|
_menu = new Ui::PopupMenu(nullptr, st::mediaviewPopupMenu);
|
2016-10-26 16:43:13 +00:00
|
|
|
updateActions();
|
|
|
|
for_const (auto &action, _actions) {
|
|
|
|
_menu->addAction(action.text, this, action.member)->setEnabled(true);
|
2014-10-07 17:57:57 +00:00
|
|
|
}
|
|
|
|
connect(_menu, SIGNAL(destroyed(QObject*)), this, SLOT(onMenuDestroy(QObject*)));
|
|
|
|
_menu->popup(e->globalPos());
|
|
|
|
e->accept();
|
2016-01-02 00:33:26 +00:00
|
|
|
activateControls();
|
2014-08-06 14:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
|
|
|
|
void MediaView::touchEvent(QTouchEvent *e) {
|
|
|
|
switch (e->type()) {
|
|
|
|
case QEvent::TouchBegin:
|
|
|
|
if (_touchPress || e->touchPoints().isEmpty()) return;
|
|
|
|
_touchTimer.start(QApplication::startDragTime());
|
|
|
|
_touchPress = true;
|
|
|
|
_touchMove = _touchRightButton = false;
|
|
|
|
_touchStart = e->touchPoints().cbegin()->screenPos().toPoint();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QEvent::TouchUpdate:
|
|
|
|
if (!_touchPress || e->touchPoints().isEmpty()) return;
|
|
|
|
if (!_touchMove && (e->touchPoints().cbegin()->screenPos().toPoint() - _touchStart).manhattanLength() >= QApplication::startDragDistance()) {
|
|
|
|
_touchMove = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QEvent::TouchEnd:
|
|
|
|
if (!_touchPress) return;
|
|
|
|
if (!_touchMove && App::wnd()) {
|
|
|
|
Qt::MouseButton btn(_touchRightButton ? Qt::RightButton : Qt::LeftButton);
|
|
|
|
QPoint mapped(mapFromGlobal(_touchStart)), winMapped(App::wnd()->mapFromGlobal(_touchStart));
|
|
|
|
|
|
|
|
QMouseEvent pressEvent(QEvent::MouseButtonPress, mapped, winMapped, _touchStart, btn, Qt::MouseButtons(btn), Qt::KeyboardModifiers());
|
|
|
|
pressEvent.accept();
|
|
|
|
mousePressEvent(&pressEvent);
|
|
|
|
|
|
|
|
QMouseEvent releaseEvent(QEvent::MouseButtonRelease, mapped, winMapped, _touchStart, btn, Qt::MouseButtons(btn), Qt::KeyboardModifiers());
|
|
|
|
mouseReleaseEvent(&releaseEvent);
|
|
|
|
|
|
|
|
if (_touchRightButton) {
|
|
|
|
QContextMenuEvent contextEvent(QContextMenuEvent::Mouse, mapped, _touchStart);
|
|
|
|
contextMenuEvent(&contextEvent);
|
|
|
|
}
|
|
|
|
} else if (_touchMove) {
|
2014-08-11 09:49:18 +00:00
|
|
|
if ((!_leftNavVisible || !_leftNav.contains(mapFromGlobal(_touchStart))) && (!_rightNavVisible || !_rightNav.contains(mapFromGlobal(_touchStart)))) {
|
2014-08-11 09:03:45 +00:00
|
|
|
QPoint d = (e->touchPoints().cbegin()->screenPos().toPoint() - _touchStart);
|
2016-12-23 13:21:01 +00:00
|
|
|
if (d.x() * d.x() > d.y() * d.y() && (d.x() > st::mediaviewSwipeDistance || d.x() < -st::mediaviewSwipeDistance)) {
|
2015-04-11 10:04:10 +00:00
|
|
|
moveToNext(d.x() > 0 ? -1 : 1);
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_touchTimer.stop();
|
|
|
|
_touchPress = _touchMove = _touchRightButton = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QEvent::TouchCancel:
|
|
|
|
_touchPress = false;
|
|
|
|
_touchTimer.stop();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MediaView::event(QEvent *e) {
|
|
|
|
if (e->type() == QEvent::TouchBegin || e->type() == QEvent::TouchUpdate || e->type() == QEvent::TouchEnd || e->type() == QEvent::TouchCancel) {
|
|
|
|
QTouchEvent *ev = static_cast<QTouchEvent*>(e);
|
|
|
|
if (ev->device()->type() == QTouchDevice::TouchScreen) {
|
2014-08-20 05:32:50 +00:00
|
|
|
if (ev->type() != QEvent::TouchBegin || ev->touchPoints().isEmpty() || !childAt(mapFromGlobal(ev->touchPoints().cbegin()->screenPos().toPoint()))) {
|
|
|
|
touchEvent(ev);
|
|
|
|
return true;
|
2014-08-11 09:49:18 +00:00
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
2014-12-22 23:13:45 +00:00
|
|
|
} else if (e->type() == QEvent::Wheel) {
|
|
|
|
QWheelEvent *ev = static_cast<QWheelEvent*>(e);
|
|
|
|
if (ev->phase() == Qt::ScrollBegin) {
|
|
|
|
_accumScroll = ev->angleDelta();
|
|
|
|
} else {
|
|
|
|
_accumScroll += ev->angleDelta();
|
|
|
|
if (ev->phase() == Qt::ScrollEnd) {
|
|
|
|
if (ev->orientation() == Qt::Horizontal) {
|
|
|
|
if (_accumScroll.x() * _accumScroll.x() > _accumScroll.y() * _accumScroll.y() && _accumScroll.x() != 0) {
|
2015-04-11 10:04:10 +00:00
|
|
|
moveToNext(_accumScroll.x() > 0 ? -1 : 1);
|
2014-12-22 23:13:45 +00:00
|
|
|
}
|
|
|
|
_accumScroll = QPoint();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
2016-07-14 11:20:46 +00:00
|
|
|
return TWidget::event(e);
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
|
2016-07-11 18:05:46 +00:00
|
|
|
bool MediaView::eventFilter(QObject *obj, QEvent *e) {
|
2016-07-12 14:11:59 +00:00
|
|
|
auto type = e->type();
|
|
|
|
if ((type == QEvent::MouseMove || type == QEvent::MouseButtonPress || type == QEvent::MouseButtonRelease) && obj->isWidgetType()) {
|
2016-07-11 18:05:46 +00:00
|
|
|
if (isAncestorOf(static_cast<QWidget*>(obj))) {
|
2016-07-12 14:11:59 +00:00
|
|
|
auto mouseEvent = static_cast<QMouseEvent*>(e);
|
|
|
|
auto mousePosition = mapFromGlobal(mouseEvent->globalPos());
|
|
|
|
bool activate = (mousePosition != _lastMouseMovePos);
|
2016-07-11 18:05:46 +00:00
|
|
|
_lastMouseMovePos = mousePosition;
|
2016-07-12 14:11:59 +00:00
|
|
|
if (type == QEvent::MouseButtonPress) {
|
|
|
|
_mousePressed = true;
|
|
|
|
activate = true;
|
|
|
|
} else if (type == QEvent::MouseButtonRelease) {
|
|
|
|
_mousePressed = false;
|
|
|
|
activate = true;
|
|
|
|
}
|
|
|
|
if (activate) activateControls();
|
2016-07-11 18:05:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return TWidget::eventFilter(obj, e);
|
|
|
|
}
|
|
|
|
|
2016-07-24 08:53:09 +00:00
|
|
|
void MediaView::setVisible(bool visible) {
|
|
|
|
if (!visible) {
|
|
|
|
_controlsHideTimer.stop();
|
|
|
|
_controlsState = ControlsShown;
|
2016-12-05 11:01:08 +00:00
|
|
|
a_cOpacity = anim::value(1, 1);
|
2016-07-24 08:53:09 +00:00
|
|
|
}
|
|
|
|
TWidget::setVisible(visible);
|
|
|
|
if (visible) {
|
2017-02-23 10:59:19 +00:00
|
|
|
QCoreApplication::instance()->installEventFilter(this);
|
2016-07-24 08:53:09 +00:00
|
|
|
} else {
|
2017-02-23 10:59:19 +00:00
|
|
|
QCoreApplication::instance()->removeEventFilter(this);
|
2015-12-25 13:09:14 +00:00
|
|
|
|
2016-07-24 08:53:09 +00:00
|
|
|
stopGif();
|
2016-12-23 13:21:01 +00:00
|
|
|
destroyThemePreview();
|
2016-07-24 08:53:09 +00:00
|
|
|
_radial.stop();
|
|
|
|
}
|
2014-08-15 11:19:32 +00:00
|
|
|
}
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
void MediaView::onMenuDestroy(QObject *obj) {
|
|
|
|
if (_menu == obj) {
|
|
|
|
_menu = 0;
|
2016-01-02 00:33:26 +00:00
|
|
|
activateControls();
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
_receiveMouse = false;
|
|
|
|
QTimer::singleShot(0, this, SLOT(receiveMouse()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::receiveMouse() {
|
|
|
|
_receiveMouse = true;
|
|
|
|
}
|
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
void MediaView::onDropdown() {
|
2016-10-26 16:43:13 +00:00
|
|
|
updateActions();
|
|
|
|
_dropdown->clearActions();
|
|
|
|
for_const (auto &action, _actions) {
|
|
|
|
_dropdown->addAction(action.text, this, action.member);
|
|
|
|
}
|
|
|
|
_dropdown->moveToRight(0, height() - _dropdown->height());
|
2016-11-09 13:40:51 +00:00
|
|
|
_dropdown->showAnimated(Ui::PanelAnimation::Origin::BottomRight);
|
2016-10-26 16:43:13 +00:00
|
|
|
_dropdown->setFocus();
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
void MediaView::onCheckActive() {
|
|
|
|
if (App::wnd() && isVisible()) {
|
2014-12-12 16:45:43 +00:00
|
|
|
if (App::wnd()->isActiveWindow() && App::wnd()->hasFocus()) {
|
2014-08-11 09:03:45 +00:00
|
|
|
activateWindow();
|
2016-02-08 14:54:55 +00:00
|
|
|
Sandbox::setActiveWindow(this);
|
2014-08-11 09:03:45 +00:00
|
|
|
setFocus();
|
|
|
|
}
|
2014-08-06 14:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
|
|
|
|
void MediaView::onTouchTimer() {
|
|
|
|
_touchRightButton = true;
|
|
|
|
}
|
|
|
|
|
2014-09-30 14:11:09 +00:00
|
|
|
void MediaView::updateImage() {
|
2014-10-17 12:57:14 +00:00
|
|
|
update(_saveMsg);
|
2014-09-30 14:11:09 +00:00
|
|
|
}
|
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
void MediaView::findCurrent() {
|
2015-11-16 16:04:37 +00:00
|
|
|
if (_msgmigrated) {
|
|
|
|
for (int i = 0, l = _migrated->overview[_overview].size(); i < l; ++i) {
|
|
|
|
if (_migrated->overview[_overview].at(i) == _msgid) {
|
|
|
|
_index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
if (!_history->overviewCountLoaded(_overview)) {
|
2015-11-16 16:04:37 +00:00
|
|
|
loadBack();
|
2015-11-18 13:11:56 +00:00
|
|
|
} else if (_history->overviewLoaded(_overview) && !_migrated->overviewLoaded(_overview)) { // all loaded
|
|
|
|
if (!_migrated->overviewCountLoaded(_overview) || (_index < 2 && _migrated->overviewCount(_overview) > 0)) {
|
2015-11-16 16:04:37 +00:00
|
|
|
loadBack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (int i = 0, l = _history->overview[_overview].size(); i < l; ++i) {
|
|
|
|
if (_history->overview[_overview].at(i) == _msgid) {
|
|
|
|
_index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
if (!_history->overviewLoaded(_overview)) {
|
|
|
|
if (!_history->overviewCountLoaded(_overview) || (_index < 2 && _history->overviewCount(_overview) > 0) || (_index < 1 && _migrated && !_migrated->overviewLoaded(_overview))) {
|
|
|
|
loadBack();
|
|
|
|
}
|
|
|
|
} else if (_index < 1 && _migrated && !_migrated->overviewLoaded(_overview)) {
|
2015-11-16 16:04:37 +00:00
|
|
|
loadBack();
|
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
if (_migrated && !_migrated->overviewCountLoaded(_overview)) {
|
2015-11-16 16:04:37 +00:00
|
|
|
App::main()->preloadOverview(_migrated->peer, _overview);
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::loadBack() {
|
2016-06-21 14:19:24 +00:00
|
|
|
if (_loadRequest || (_overview == OverviewCount && !_user)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_index < 0 && (!_additionalChatPhoto || _photo != _additionalChatPhoto || !_history)) {
|
|
|
|
return;
|
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
|
2015-11-18 13:11:56 +00:00
|
|
|
if (_history && _overview != OverviewCount && (!_history->overviewLoaded(_overview) || (_migrated && !_migrated->overviewLoaded(_overview)))) {
|
2015-11-16 16:04:37 +00:00
|
|
|
if (App::main()) {
|
2015-11-18 13:11:56 +00:00
|
|
|
if (_msgmigrated || (_migrated && _index == 0 && _history->overviewLoaded(_overview))) {
|
2015-11-16 16:04:37 +00:00
|
|
|
App::main()->loadMediaBack(_migrated->peer, _overview);
|
|
|
|
} else {
|
|
|
|
App::main()->loadMediaBack(_history->peer, _overview);
|
2016-05-20 16:01:06 +00:00
|
|
|
if (_migrated && _index == 0 && (_migrated->overviewCount(_overview) < 0 || _migrated->overview[_overview].isEmpty()) && !_migrated->overviewLoaded(_overview)) {
|
2015-11-16 16:04:37 +00:00
|
|
|
App::main()->loadMediaBack(_migrated->peer, _overview);
|
|
|
|
}
|
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
if (_msgmigrated && !_history->overviewCountLoaded(_overview)) {
|
2015-11-16 16:04:37 +00:00
|
|
|
App::main()->preloadOverview(_history->peer, _overview);
|
|
|
|
}
|
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
} else if (_user && _user->photosCount != 0) {
|
|
|
|
int32 limit = (_index < MediaOverviewStartPerPage && _user->photos.size() > MediaOverviewStartPerPage) ? SearchPerPage : MediaOverviewStartPerPage;
|
2015-08-12 18:01:32 +00:00
|
|
|
_loadRequest = MTP::send(MTPphotos_GetUserPhotos(_user->inputUser, MTP_int(_user->photos.size()), MTP_long(0), MTP_int(limit)), rpcDone(&MediaView::userPhotosLoaded, _user));
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-20 16:01:06 +00:00
|
|
|
MediaView::LastChatPhoto MediaView::computeLastOverviewChatPhoto() {
|
|
|
|
LastChatPhoto emptyResult = { nullptr, nullptr };
|
|
|
|
auto lastPhotoInOverview = [&emptyResult](auto history, auto list) -> LastChatPhoto {
|
|
|
|
if (auto item = App::histItemById(history->channelId(), list.back())) {
|
|
|
|
if (auto media = item->getMedia()) {
|
|
|
|
if (media->type() == MediaTypePhoto && !item->toHistoryMessage()) {
|
|
|
|
return { item, static_cast<HistoryPhoto*>(media)->photo() };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return emptyResult;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!_history) return emptyResult;
|
|
|
|
auto &list = _history->overview[OverviewChatPhotos];
|
|
|
|
if (!list.isEmpty()) {
|
|
|
|
return lastPhotoInOverview(_history, list);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_migrated || !_history->overviewLoaded(OverviewChatPhotos)) return emptyResult;
|
|
|
|
auto &migratedList = _migrated->overview[OverviewChatPhotos];
|
|
|
|
if (!migratedList.isEmpty()) {
|
|
|
|
return lastPhotoInOverview(_migrated, migratedList);
|
|
|
|
}
|
|
|
|
return emptyResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::computeAdditionalChatPhoto(PeerData *peer, PhotoData *lastOverviewPhoto) {
|
|
|
|
if (!peer->photoId || peer->photoId == UnknownPeerPhotoId) {
|
|
|
|
_additionalChatPhoto = nullptr;
|
|
|
|
} else if (lastOverviewPhoto && lastOverviewPhoto->id == peer->photoId) {
|
|
|
|
_additionalChatPhoto = nullptr;
|
|
|
|
} else {
|
|
|
|
_additionalChatPhoto = App::photo(peer->photoId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
void MediaView::userPhotosLoaded(UserData *u, const MTPphotos_Photos &photos, mtpRequestId req) {
|
|
|
|
if (req == _loadRequest) {
|
|
|
|
_loadRequest = 0;
|
|
|
|
}
|
|
|
|
|
2017-03-10 19:46:28 +00:00
|
|
|
const QVector<MTPPhoto> *v = nullptr;
|
2014-08-11 09:03:45 +00:00
|
|
|
switch (photos.type()) {
|
|
|
|
case mtpc_photos_photos: {
|
2017-03-10 19:46:28 +00:00
|
|
|
auto &d = photos.c_photos_photos();
|
2014-08-11 09:03:45 +00:00
|
|
|
App::feedUsers(d.vusers);
|
2017-03-10 19:46:28 +00:00
|
|
|
v = &d.vphotos.v;
|
2014-08-11 09:03:45 +00:00
|
|
|
u->photosCount = 0;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case mtpc_photos_photosSlice: {
|
2017-03-10 19:46:28 +00:00
|
|
|
auto &d = photos.c_photos_photosSlice();
|
2014-08-11 09:03:45 +00:00
|
|
|
App::feedUsers(d.vusers);
|
|
|
|
u->photosCount = d.vcount.v;
|
2017-03-10 19:46:28 +00:00
|
|
|
v = &d.vphotos.v;
|
2014-08-11 09:03:45 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
default: return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (v->isEmpty()) {
|
|
|
|
u->photosCount = 0;
|
|
|
|
}
|
|
|
|
|
2017-01-01 16:45:20 +00:00
|
|
|
for (auto i = v->cbegin(), e = v->cend(); i != e; ++i) {
|
|
|
|
auto photo = App::feedPhoto(*i);
|
2014-08-11 09:03:45 +00:00
|
|
|
photo->thumb->load();
|
|
|
|
u->photos.push_back(photo);
|
|
|
|
}
|
2017-01-01 16:45:20 +00:00
|
|
|
Notify::mediaOverviewUpdated(u, OverviewCount);
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::updateHeader() {
|
2015-11-18 13:11:56 +00:00
|
|
|
int32 index = _index, count = 0, addcount = (_migrated && _overview != OverviewCount) ? _migrated->overviewCount(_overview) : 0;
|
2014-08-11 09:03:45 +00:00
|
|
|
if (_history) {
|
2015-04-11 10:04:10 +00:00
|
|
|
if (_overview != OverviewCount) {
|
2016-06-21 14:19:24 +00:00
|
|
|
bool lastOverviewPhotoLoaded = (!_history->overview[_overview].isEmpty() || (
|
|
|
|
_migrated && _history->overviewCount(_overview) == 0 && !_migrated->overview[_overview].isEmpty()));
|
2015-11-18 13:11:56 +00:00
|
|
|
count = _history->overviewCount(_overview);
|
2015-11-16 16:04:37 +00:00
|
|
|
if (addcount >= 0 && count >= 0) {
|
|
|
|
count += addcount;
|
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
if (index >= 0 && (_msgmigrated ? (count >= 0 && addcount >= 0 && _history->overviewLoaded(_overview)) : (count >= 0))) {
|
2015-11-16 16:04:37 +00:00
|
|
|
if (_msgmigrated) {
|
|
|
|
index += addcount - _migrated->overview[_overview].size();
|
|
|
|
} else {
|
|
|
|
index += count - _history->overview[_overview].size();
|
|
|
|
}
|
2016-06-21 14:19:24 +00:00
|
|
|
if (_additionalChatPhoto && lastOverviewPhotoLoaded) {
|
2016-05-20 16:01:06 +00:00
|
|
|
++count;
|
|
|
|
}
|
2016-06-21 14:19:24 +00:00
|
|
|
} else if (index < 0 && _additionalChatPhoto && _photo == _additionalChatPhoto && lastOverviewPhotoLoaded) {
|
2016-05-20 16:01:06 +00:00
|
|
|
// Additional chat photo (not in the list => place it at the end of the list).
|
|
|
|
index = count;
|
|
|
|
++count;
|
2015-11-16 16:04:37 +00:00
|
|
|
} else {
|
|
|
|
count = 0; // unknown yet
|
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
} else if (_user) {
|
|
|
|
count = _user->photosCount ? _user->photosCount : _user->photos.size();
|
|
|
|
}
|
2016-05-20 16:01:06 +00:00
|
|
|
if (index >= 0 && index < count && count > 1) {
|
2015-04-11 10:04:10 +00:00
|
|
|
if (_doc) {
|
|
|
|
_headerText = lng_mediaview_file_n_of_count(lt_file, _doc->name.isEmpty() ? lang(lng_mediaview_doc_image) : _doc->name, lt_n, QString::number(index + 1), lt_count, QString::number(count));
|
2014-10-17 12:57:14 +00:00
|
|
|
} else {
|
2015-04-11 10:04:10 +00:00
|
|
|
_headerText = lng_mediaview_n_of_count(lt_n, QString::number(index + 1), lt_count, QString::number(count));
|
2014-10-17 12:57:14 +00:00
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
} else {
|
2015-04-11 10:04:10 +00:00
|
|
|
if (_doc) {
|
|
|
|
_headerText = _doc->name.isEmpty() ? lang(lng_mediaview_doc_image) : _doc->name;
|
|
|
|
} else if (_user) {
|
|
|
|
_headerText = lang(lng_mediaview_profile_photo);
|
2015-11-03 17:52:37 +00:00
|
|
|
} else if ((_channel && !_history->isMegagroup()) || (_peer && _peer->isChannel() && !_peer->isMegagroup())) {
|
2015-09-21 20:57:42 +00:00
|
|
|
_headerText = lang(lng_mediaview_channel_photo);
|
2015-11-02 22:33:57 +00:00
|
|
|
} else if (_peer) {
|
|
|
|
_headerText = lang(lng_mediaview_group_photo);
|
2015-01-02 14:55:24 +00:00
|
|
|
} else {
|
2015-04-11 10:04:10 +00:00
|
|
|
_headerText = lang(lng_mediaview_single_photo);
|
2014-12-15 15:55:45 +00:00
|
|
|
}
|
2014-10-17 12:57:14 +00:00
|
|
|
}
|
2016-05-20 16:01:06 +00:00
|
|
|
_headerHasLink = _history && typeHasMediaOverview(_overview);
|
2016-12-23 13:21:01 +00:00
|
|
|
int32 hwidth = st::mediaviewThickFont->width(_headerText);
|
2015-04-11 10:04:10 +00:00
|
|
|
if (hwidth > width() / 3) {
|
|
|
|
hwidth = width() / 3;
|
2016-12-23 13:21:01 +00:00
|
|
|
_headerText = st::mediaviewThickFont->elided(_headerText, hwidth, Qt::ElideMiddle);
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
2016-12-23 13:21:01 +00:00
|
|
|
_headerNav = myrtlrect(st::mediaviewTextLeft, height() - st::mediaviewHeaderTop, hwidth, st::mediaviewThickFont->height);
|
2014-10-17 12:57:14 +00:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:54:43 +00:00
|
|
|
float64 MediaView::overLevel(OverState control) const {
|
2017-04-03 14:13:55 +00:00
|
|
|
auto i = _animOpacities.constFind(control);
|
2014-08-11 09:03:45 +00:00
|
|
|
return (i == _animOpacities.cend()) ? (_over == control ? 1 : 0) : i->current();
|
|
|
|
}
|