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.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2014-12-01 10:47:38 +00:00
|
|
|
Copyright (c) 2014 John Preston, https://desktop.telegram.org
|
2014-08-06 14:40:21 +00:00
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "lang.h"
|
|
|
|
|
|
|
|
#include "mediaview.h"
|
2014-08-11 09:03:45 +00:00
|
|
|
#include "mainwidget.h"
|
2014-08-06 14:40:21 +00:00
|
|
|
#include "window.h"
|
2014-08-11 09:03:45 +00:00
|
|
|
#include "application.h"
|
|
|
|
#include "gui/filedialog.h"
|
2014-08-06 14:40:21 +00:00
|
|
|
|
2014-10-17 12:57:14 +00:00
|
|
|
namespace {
|
|
|
|
class SaveMsgLink : public ITextLink {
|
2015-06-27 13:02:00 +00:00
|
|
|
TEXT_LINK_CLASS(SaveMsgLink)
|
|
|
|
|
2014-10-17 12:57:14 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
SaveMsgLink(MediaView *view) : _view(view) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void onClick(Qt::MouseButton button) const {
|
|
|
|
if (button == Qt::LeftButton) {
|
|
|
|
_view->showSaveMsgFile();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
MediaView *_view;
|
|
|
|
};
|
2015-05-20 19:28:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
TextParseOptions _captionTextOptions = {
|
|
|
|
TextParseLinks | TextParseMentions | TextParseHashtags | TextParseMultiline | TextParseRichText, // flags
|
|
|
|
0, // maxw
|
|
|
|
0, // maxh
|
|
|
|
Qt::LayoutDirectionAuto, // dir
|
|
|
|
};
|
2014-10-17 12:57:14 +00:00
|
|
|
}
|
|
|
|
|
2014-09-29 02:47:30 +00:00
|
|
|
MediaView::MediaView() : TWidget(App::wnd()),
|
2015-04-11 10:04:10 +00:00
|
|
|
_photo(0), _doc(0), _overview(OverviewCount),
|
|
|
|
_leftNavVisible(false), _rightNavVisible(false), _saveVisible(false), _headerHasLink(false), _animStarted(getms()),
|
|
|
|
_width(0), _x(0), _y(0), _w(0), _h(0), _xStart(0), _yStart(0),
|
|
|
|
_zoom(0), _zoomToScreen(0), _pressed(false), _dragging(0), _full(-1),
|
|
|
|
_docNameWidth(0), _docSizeWidth(0),
|
|
|
|
_docThumbx(0), _docThumby(0), _docThumbw(0),
|
2015-04-19 10:29:19 +00:00
|
|
|
_docRadialFirst(0), _docRadialStart(0), _docRadialLast(0), _docRadialOpacity(1), a_docRadialStart(0, 1),
|
|
|
|
_docDownload(this, lang(lng_media_download), st::mvDocLink),
|
|
|
|
_docSaveAs(this, lang(lng_mediaview_save_as), st::mvDocLink),
|
|
|
|
_docCancel(this, lang(lng_cancel), st::mvDocLink),
|
2015-04-11 10:04:10 +00:00
|
|
|
_history(0), _peer(0), _user(0), _from(0), _index(-1), _msgid(0),
|
|
|
|
_loadRequest(0), _over(OverNone), _down(OverNone), _lastAction(-st::mvDeltaFromLastAction, -st::mvDeltaFromLastAction), _ignoringDropdown(false),
|
|
|
|
_controlsState(ControlsShown), _controlsAnimStarted(0),
|
2015-04-19 19:01:45 +00:00
|
|
|
_menu(0), _dropdown(this, st::mvDropdown), _receiveMouse(true), _touchPress(false), _touchMove(false), _touchRightButton(false),
|
2014-10-17 12:57:14 +00:00
|
|
|
_saveMsgStarted(0), _saveMsgOpacity(0)
|
|
|
|
{
|
|
|
|
TextCustomTagsMap custom;
|
|
|
|
custom.insert(QChar('c'), qMakePair(textcmdStartLink(1), textcmdStopLink()));
|
|
|
|
_saveMsgText.setRichText(st::medviewSaveMsgFont, lang(lng_mediaview_saved), _textDlgOptions, custom);
|
|
|
|
_saveMsg = QRect(0, 0, _saveMsgText.maxWidth() + st::medviewSaveMsgPadding.left() + st::medviewSaveMsgPadding.right(), st::medviewSaveMsgFont->height + st::medviewSaveMsgPadding.top() + st::medviewSaveMsgPadding.bottom());
|
|
|
|
_saveMsgText.setLink(1, TextLinkPtr(new SaveMsgLink(this)));
|
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
_transparentBrush = QBrush(App::sprite().copy(st::mvTransparentBrush));
|
|
|
|
_docRadialPen = QPen(st::white->p);
|
|
|
|
_docRadialPen.setWidth(st::radialLine);
|
2014-12-15 15:55:45 +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();
|
|
|
|
|
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
|
|
|
|
2015-04-19 10:29:19 +00:00
|
|
|
connect(&_currentGif, SIGNAL(updated()), this, SLOT(onGifUpdated()));
|
|
|
|
|
|
|
|
_btns.push_back(_btnSaveCancel = _dropdown.addButton(new IconedButton(this, st::mvButton, lang(lng_cancel))));
|
|
|
|
connect(_btnSaveCancel, SIGNAL(clicked()), this, SLOT(onSaveCancel()));
|
2015-04-11 10:04:10 +00:00
|
|
|
_btns.push_back(_btnToMessage = _dropdown.addButton(new IconedButton(this, st::mvButton, lang(lng_context_to_msg))));
|
|
|
|
connect(_btnToMessage, SIGNAL(clicked()), this, SLOT(onToMessage()));
|
|
|
|
_btns.push_back(_btnShowInFolder = _dropdown.addButton(new IconedButton(this, st::mvButton, lang(cPlatform() == dbipMac ? lng_context_show_in_finder : lng_context_show_in_folder))));
|
|
|
|
connect(_btnShowInFolder, SIGNAL(clicked()), this, SLOT(onShowInFolder()));
|
|
|
|
_btns.push_back(_btnCopy = _dropdown.addButton(new IconedButton(this, st::mvButton, lang(lng_mediaview_copy))));
|
|
|
|
connect(_btnCopy, SIGNAL(clicked()), this, SLOT(onCopy()));
|
|
|
|
_btns.push_back(_btnForward = _dropdown.addButton(new IconedButton(this, st::mvButton, lang(lng_mediaview_forward))));
|
|
|
|
connect(_btnForward, SIGNAL(clicked()), this, SLOT(onForward()));
|
|
|
|
_btns.push_back(_btnDelete = _dropdown.addButton(new IconedButton(this, st::mvButton, lang(lng_mediaview_delete))));
|
|
|
|
connect(_btnDelete, SIGNAL(clicked()), this, SLOT(onDelete()));
|
|
|
|
_btns.push_back(_btnSaveAs = _dropdown.addButton(new IconedButton(this, st::mvButton, lang(lng_mediaview_save_as))));
|
2015-04-19 10:29:19 +00:00
|
|
|
connect(_btnSaveAs, SIGNAL(clicked()), this, SLOT(onSaveAs()));
|
2015-04-11 10:04:10 +00:00
|
|
|
_btns.push_back(_btnViewAll = _dropdown.addButton(new IconedButton(this, st::mvButton, lang(lng_mediaview_photos_all))));
|
|
|
|
connect(_btnViewAll, SIGNAL(clicked()), this, SLOT(onOverview()));
|
|
|
|
|
|
|
|
_dropdown.hide();
|
|
|
|
connect(&_dropdown, SIGNAL(hiding()), this, SLOT(onDropdownHiding()));
|
|
|
|
|
|
|
|
_controlsHideTimer.setSingleShot(true);
|
|
|
|
connect(&_controlsHideTimer, SIGNAL(timeout()), this, SLOT(onHideControls()));
|
2015-04-19 10:29:19 +00:00
|
|
|
|
|
|
|
connect(&_docDownload, SIGNAL(clicked()), this, SLOT(onDownload()));
|
|
|
|
connect(&_docSaveAs, SIGNAL(clicked()), this, SLOT(onSaveAs()));
|
|
|
|
connect(&_docCancel, SIGNAL(clicked()), this, SLOT(onSaveCancel()));
|
2014-08-06 14:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::moveToScreen() {
|
|
|
|
QPoint wndCenter(App::wnd()->x() + App::wnd()->width() / 2, App::wnd()->y() + App::wnd()->height() / 2);
|
2015-04-11 10:04:10 +00:00
|
|
|
QRect avail = App::app() ? App::app()->desktop()->screenGeometry(wndCenter) : QDesktopWidget().screenGeometry(wndCenter);
|
|
|
|
if (avail != geometry()) {
|
|
|
|
setGeometry(avail);
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 navSkip = 2 * st::mvControlMargin + st::mvControlSize;
|
2015-07-03 08:47:16 +00:00
|
|
|
_closeNav = myrtlrect(width() - st::mvControlMargin - st::mvControlSize, st::mvControlMargin, st::mvControlSize, st::mvControlSize);
|
2015-04-19 19:01:45 +00:00
|
|
|
_closeNavIcon = centersprite(_closeNav, st::mvClose);
|
2015-07-03 08:47:16 +00:00
|
|
|
_leftNav = myrtlrect(st::mvControlMargin, navSkip, st::mvControlSize, height() - 2 * navSkip);
|
2015-04-19 19:01:45 +00:00
|
|
|
_leftNavIcon = centersprite(_leftNav, st::mvLeft);
|
2015-07-03 08:47:16 +00:00
|
|
|
_rightNav = myrtlrect(width() - st::mvControlMargin - st::mvControlSize, navSkip, st::mvControlSize, height() - 2 * navSkip);
|
2015-04-19 19:01:45 +00:00
|
|
|
_rightNavIcon = centersprite(_rightNav, st::mvRight);
|
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
|
|
|
}
|
|
|
|
|
2015-07-03 08:47:16 +00:00
|
|
|
void MediaView::mediaOverviewUpdated(PeerData *peer, MediaOverviewType type) {
|
2015-04-11 10:04:10 +00:00
|
|
|
if (!_photo && !_doc) return;
|
2015-07-03 08:47:16 +00:00
|
|
|
if (_history && _history->peer == peer && type == _overview) {
|
2014-08-11 09:03:45 +00:00
|
|
|
_index = -1;
|
2015-04-11 10:04:10 +00:00
|
|
|
for (int i = 0, l = _history->_overview[_overview].size(); i < l; ++i) {
|
|
|
|
if (_history->_overview[_overview].at(i) == _msgid) {
|
2014-08-11 09:03:45 +00:00
|
|
|
_index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateControls();
|
2015-04-11 10:04:10 +00:00
|
|
|
preloadData(0);
|
2015-07-03 08:47:16 +00:00
|
|
|
} else if (_user == peer && type == 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-04-19 10:29:19 +00:00
|
|
|
void MediaView::documentUpdated(DocumentData *doc) {
|
|
|
|
if (_doc && _doc == doc && _current.isNull() && _currentGif.isNull()) {
|
|
|
|
if ((_doc->loader && _docCancel.isHidden()) || (!_doc->loader && !_docCancel.isHidden())) {
|
|
|
|
updateControls();
|
|
|
|
} else if (_doc->loader) {
|
|
|
|
updateDocSize();
|
|
|
|
update(_docRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::onGifUpdated() {
|
|
|
|
update(_x, _y, _w, _h);
|
|
|
|
}
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
void MediaView::changingMsgId(HistoryItem *row, MsgId newId) {
|
|
|
|
if (row->id == _msgid) {
|
|
|
|
_msgid = newId;
|
|
|
|
}
|
2015-07-03 08:47:16 +00:00
|
|
|
mediaOverviewUpdated(row->history()->peer, _overview);
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
|
2015-04-19 10:29:19 +00:00
|
|
|
void MediaView::updateDocSize() {
|
|
|
|
if (!_doc || !_current.isNull() || !_currentGif.isNull()) return;
|
|
|
|
|
|
|
|
if (_doc->loader) {
|
|
|
|
quint64 ready = _doc->loader->currentOffset(), total = _doc->size;
|
|
|
|
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");
|
|
|
|
} else {
|
|
|
|
qint64 readyKb = (ready / 1024), totalKb = (total / 1024);
|
|
|
|
readyStr = QString::number(readyKb);
|
|
|
|
totalStr = QString::number(totalKb);
|
|
|
|
mb = qsl("KB");
|
|
|
|
}
|
|
|
|
_docSize = lng_media_save_progress(lt_ready, readyStr, lt_total, totalStr, lt_mb, mb);
|
|
|
|
} else {
|
|
|
|
_docSize = formatSizeText(_doc->size);
|
|
|
|
}
|
|
|
|
_docSizeWidth = st::mvFont->m.width(_docSize);
|
|
|
|
int32 maxw = st::mvDocSize.width() - st::mvDocBlue.pxWidth() - st::mvDocPadding * 3;
|
|
|
|
if (_docSizeWidth > maxw) {
|
|
|
|
_docSize = st::mvFont->m.elidedText(_docSize, Qt::ElideRight, maxw);
|
|
|
|
_docSizeWidth = st::mvFont->m.width(_docSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
void MediaView::updateControls() {
|
2015-04-19 10:29:19 +00:00
|
|
|
if (_doc && _current.isNull() && _currentGif.isNull()) {
|
|
|
|
if (_doc->loader) {
|
|
|
|
_docDownload.hide();
|
|
|
|
_docSaveAs.hide();
|
|
|
|
_docCancel.moveToLeft(_docRect.x() + 2 * st::mvDocPadding + st::mvDocBlue.pxWidth(), _docRect.y() + st::mvDocPadding + st::mvDocLinksTop, width());
|
|
|
|
_docCancel.show();
|
|
|
|
if (!_docRadialFirst) _docRadialFirst = _docRadialLast = _docRadialStart = getms();
|
|
|
|
if (!animating()) anim::start(this);
|
2015-04-19 19:01:45 +00:00
|
|
|
anim::step(this);
|
2015-04-19 10:29:19 +00:00
|
|
|
} else {
|
|
|
|
if (_doc->already(true).isEmpty()) {
|
|
|
|
_docDownload.moveToLeft(_docRect.x() + 2 * st::mvDocPadding + st::mvDocBlue.pxWidth(), _docRect.y() + st::mvDocPadding + st::mvDocLinksTop, width());
|
|
|
|
_docDownload.show();
|
|
|
|
_docSaveAs.moveToLeft(_docRect.x() + 2.5 * st::mvDocPadding + st::mvDocBlue.pxWidth() + _docDownload.width(), _docRect.y() + st::mvDocPadding + st::mvDocLinksTop, width());
|
|
|
|
_docSaveAs.show();
|
|
|
|
_docCancel.hide();
|
|
|
|
} else {
|
|
|
|
_docDownload.hide();
|
|
|
|
_docSaveAs.moveToLeft(_docRect.x() + 2 * st::mvDocPadding + st::mvDocBlue.pxWidth(), _docRect.y() + st::mvDocPadding + st::mvDocLinksTop, width());
|
|
|
|
_docSaveAs.show();
|
|
|
|
_docCancel.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateDocSize();
|
|
|
|
} else {
|
|
|
|
_docDownload.hide();
|
|
|
|
_docSaveAs.hide();
|
|
|
|
_docCancel.hide();
|
|
|
|
}
|
|
|
|
|
2015-07-15 11:23:59 +00:00
|
|
|
_saveVisible = ((_photo && _photo->full->loaded()) || (_doc && (!_doc->already(true).isEmpty() || (_current.isNull() && _currentGif.isNull() && (_photo || _doc)))));
|
2015-07-03 08:47:16 +00:00
|
|
|
_saveNav = myrtlrect(width() - st::mvIconSize.width() * 2, height() - st::mvIconSize.height(), st::mvIconSize.width(), st::mvIconSize.height());
|
2015-04-19 19:01:45 +00:00
|
|
|
_saveNavIcon = centersprite(_saveNav, st::mvSave);
|
2015-07-03 08:47:16 +00:00
|
|
|
_moreNav = myrtlrect(width() - st::mvIconSize.width(), height() - st::mvIconSize.height(), st::mvIconSize.width(), st::mvIconSize.height());
|
2015-04-19 19:01:45 +00:00
|
|
|
_moreNavIcon = centersprite(_moreNav, st::mvMore);
|
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);
|
|
|
|
} else if (HistoryItem *item = App::histItemById(_msgid)) {
|
|
|
|
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) {
|
|
|
|
_fromName.setText(st::mvFont, _from->name);
|
2015-07-03 08:47:16 +00:00
|
|
|
_nameNav = myrtlrect(st::mvTextLeft, height() - st::mvTextTop, qMin(_fromName.maxWidth(), width() / 3), st::mvFont->height);
|
|
|
|
_dateNav = myrtlrect(st::mvTextLeft + _nameNav.width() + st::mvTextSkip, height() - st::mvTextTop, st::mvFont->m.width(_dateText), st::mvFont->height);
|
2015-04-11 10:04:10 +00:00
|
|
|
} else {
|
|
|
|
_nameNav = QRect();
|
2015-07-03 08:47:16 +00:00
|
|
|
_dateNav = myrtlrect(st::mvTextLeft, height() - st::mvTextTop, st::mvFont->m.width(_dateText), st::mvFont->height);
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
updateHeader();
|
2015-07-15 11:23:59 +00:00
|
|
|
if (_photo || (_history && _overview == OverviewPhotos)) {
|
2015-04-11 10:04:10 +00:00
|
|
|
_leftNavVisible = (_index > 0) || (_index == 0 && _history && _history->_overview[_overview].size() < _history->_overviewCount[_overview]);
|
|
|
|
_rightNavVisible = (_index >= 0) && (
|
|
|
|
(_history && _index + 1 < _history->_overview[_overview].size()) ||
|
|
|
|
(_user && (_index + 1 < _user->photos.size() || _index + 1 < _user->photosCount)));
|
2015-07-15 11:23:59 +00:00
|
|
|
} else if (_history && _overview == OverviewDocuments) {
|
2015-04-11 10:04:10 +00:00
|
|
|
_leftNavVisible = (_index > 0) || (_index == 0 && _history && _history->_overview[_overview].size() < _history->_overviewCount[_overview]);
|
|
|
|
_rightNavVisible = (_index >= 0) && _history && (_index + 1 < _history->_overview[_overview].size());
|
|
|
|
} else {
|
|
|
|
_leftNavVisible = _rightNavVisible = false;
|
|
|
|
}
|
2015-05-20 19:28:24 +00:00
|
|
|
if (!_caption.isEmpty()) {
|
|
|
|
int32 skipw = qMax(_dateNav.left() + _dateNav.width(), _headerNav.left() + _headerNav.width());
|
|
|
|
int32 maxw = qMin(qMax(width() - 2 * skipw - st::mvCaptionPadding.left() - st::mvCaptionPadding.right() - 2 * st::mvCaptionMargin.width(), int(st::msgMinWidth)), _caption.maxWidth());
|
|
|
|
int32 maxh = qMin(_caption.countHeight(maxw), int(height() / 4 - st::mvCaptionPadding.top() - st::mvCaptionPadding.bottom() - 2 * st::mvCaptionMargin.height()));
|
|
|
|
_captionRect = QRect((width() - maxw) / 2, height() - maxh - st::mvCaptionPadding.bottom() - st::mvCaptionMargin.height(), maxw, maxh);
|
|
|
|
} else {
|
|
|
|
_captionRect = QRect();
|
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
updateOver(mapFromGlobal(QCursor::pos()));
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
void MediaView::updateDropdown() {
|
2015-04-19 10:29:19 +00:00
|
|
|
_btnSaveCancel->setVisible(_doc && _doc->loader);
|
2015-04-11 10:04:10 +00:00
|
|
|
_btnToMessage->setVisible(_msgid > 0);
|
|
|
|
_btnShowInFolder->setVisible(_doc && !_doc->already(true).isEmpty());
|
|
|
|
_btnSaveAs->setVisible(true);
|
|
|
|
_btnCopy->setVisible((_doc && !_current.isNull()) || (_photo && _photo->full->loaded()));
|
|
|
|
_btnForward->setVisible(_msgid > 0);
|
2015-07-24 08:37:17 +00:00
|
|
|
_btnDelete->setVisible(_msgid > 0 || (_photo && App::self() && App::self()->photoId == _photo->id) || (_photo && _photo->chat && _photo->chat->photoId == _photo->id));
|
2015-04-11 10:04:10 +00:00
|
|
|
_btnViewAll->setVisible((_overview != OverviewCount) && _history);
|
|
|
|
_btnViewAll->setText(lang(_doc ? lng_mediaview_files_all : lng_mediaview_photos_all));
|
|
|
|
_dropdown.updateButtons();
|
|
|
|
_dropdown.moveToRight(0, height() - _dropdown.height(), width());
|
|
|
|
}
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
bool MediaView::animStep(float64 msp) {
|
2015-04-11 10:04:10 +00:00
|
|
|
bool result = false;
|
2014-08-11 09:03:45 +00:00
|
|
|
uint64 ms = getms();
|
|
|
|
for (Showing::iterator i = _animations.begin(); i != _animations.end();) {
|
|
|
|
int64 start = i.value();
|
|
|
|
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;
|
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
float64 dt = float64(ms - start) / st::mvFadeDuration;
|
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) {
|
|
|
|
float64 dt = float64(ms - _controlsAnimStarted) / (_controlsState == ControlsShowing ? st::mvShowDuration : st::mvHideDuration);
|
|
|
|
if (dt >= 1) {
|
|
|
|
a_cOpacity.finish();
|
|
|
|
_controlsState = (_controlsState == ControlsShowing ? ControlsShown : ControlsHidden);
|
|
|
|
setCursor(_controlsState == ControlsHidden ? Qt::BlankCursor : (_over == OverNone ? style::cur_default : style::cur_pointer));
|
|
|
|
} else {
|
|
|
|
a_cOpacity.update(dt, anim::linear);
|
|
|
|
}
|
2015-05-20 19:28:24 +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::mvCaptionPadding);
|
2015-04-19 19:01:45 +00:00
|
|
|
update(toUpdate);
|
2015-04-11 10:04:10 +00:00
|
|
|
if (dt < 1) result = true;
|
|
|
|
}
|
|
|
|
if (_doc && _docRadialStart > 0) {
|
2015-04-19 10:29:19 +00:00
|
|
|
float64 prg = _doc->loader ? qMax(_doc->loader->currentProgress(), 0.0001) : (_doc->status == FileFailed ? 0 : (_doc->already().isEmpty() ? 0 : 1));
|
2015-04-11 10:04:10 +00:00
|
|
|
if (prg != a_docRadial.to()) {
|
|
|
|
a_docRadial.start(prg);
|
|
|
|
_docRadialStart = _docRadialLast;
|
|
|
|
}
|
|
|
|
_docRadialLast = ms;
|
|
|
|
|
2015-04-19 10:29:19 +00:00
|
|
|
float64 dt = float64(ms - _docRadialStart), fulldt = float64(ms - _docRadialFirst);
|
|
|
|
_docRadialOpacity = qMin(fulldt / st::radialDuration, 1.);
|
2015-04-11 10:04:10 +00:00
|
|
|
if (_doc->loader) {
|
|
|
|
a_docRadial.update(1. - (st::radialDuration / (st::radialDuration + dt)), anim::linear);
|
|
|
|
result = true;
|
|
|
|
} else if (dt >= st::radialDuration) {
|
|
|
|
a_docRadial.update(1, anim::linear);
|
|
|
|
result = true;
|
2015-04-19 10:29:19 +00:00
|
|
|
_docRadialFirst = _docRadialLast = _docRadialStart = 0;
|
|
|
|
a_docRadial = anim::fvalue(0, 0);
|
|
|
|
if (!_doc->already().isEmpty() && _doc->size < MediaViewImageSizeLimit) {
|
|
|
|
QString fname(_doc->already(true));
|
|
|
|
QImageReader reader(fname);
|
|
|
|
if (reader.canRead()) {
|
|
|
|
displayDocument(_doc, App::histItemById(_msgid));
|
|
|
|
}
|
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
} else {
|
2015-04-19 10:29:19 +00:00
|
|
|
float64 r = dt / st::radialDuration;
|
|
|
|
a_docRadial.update(r, anim::linear);
|
2015-04-11 10:04:10 +00:00
|
|
|
result = true;
|
2015-04-19 10:29:19 +00:00
|
|
|
_docRadialOpacity *= 1 - r;
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
2015-04-19 10:29:19 +00:00
|
|
|
float64 fromstart = fulldt / st::radialPeriod;
|
2015-04-11 10:04:10 +00:00
|
|
|
a_docRadialStart.update(fromstart - qFloor(fromstart), anim::linear);
|
2015-04-19 10:29:19 +00:00
|
|
|
update(_docIconRect);
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
|
|
|
return result || !_animations.isEmpty();
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MediaView::~MediaView() {
|
|
|
|
delete _menu;
|
|
|
|
}
|
|
|
|
|
2014-10-17 12:57:14 +00:00
|
|
|
void MediaView::showSaveMsgFile() {
|
|
|
|
psShowInFolder(_saveMsgFilename);
|
|
|
|
}
|
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
void MediaView::close() {
|
2014-08-11 09:03:45 +00:00
|
|
|
if (App::wnd()) App::wnd()->layerHidden();
|
|
|
|
}
|
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
void MediaView::activateControls() {
|
|
|
|
_controlsHideTimer.start(int(st::mvWaitHide));
|
|
|
|
if (_controlsState == ControlsHiding || _controlsState == ControlsHidden) {
|
|
|
|
_controlsState = ControlsShowing;
|
|
|
|
_controlsAnimStarted = getms();
|
|
|
|
a_cOpacity.start(1);
|
2015-04-19 19:01:45 +00:00
|
|
|
if (!animating()) anim::start(this);
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::onHideControls(bool force) {
|
|
|
|
if (!force && !_dropdown.isHidden()) return;
|
|
|
|
if (_controlsState == ControlsHiding || _controlsState == ControlsHidden) return;
|
|
|
|
_controlsState = ControlsHiding;
|
|
|
|
_controlsAnimStarted = getms();
|
|
|
|
a_cOpacity.start(0);
|
2015-04-19 19:01:45 +00:00
|
|
|
if (!animating()) anim::start(this);
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::onDropdownHiding() {
|
|
|
|
setFocus();
|
|
|
|
_ignoringDropdown = true;
|
|
|
|
_lastMouseMovePos = mapFromGlobal(QCursor::pos());
|
|
|
|
updateOver(_lastMouseMovePos);
|
|
|
|
_ignoringDropdown = false;
|
|
|
|
if (!_controlsHideTimer.isActive()) {
|
|
|
|
onHideControls(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::onToMessage() {
|
|
|
|
if (_menu) _menu->fastHide();
|
|
|
|
if (HistoryItem *item = _msgid ? App::histItemById(_msgid) : 0) {
|
|
|
|
if (App::wnd()) {
|
|
|
|
close();
|
2015-07-17 19:17:37 +00:00
|
|
|
if (App::main()) App::main()->showPeerHistory(item->history()->peer->id, _msgid);
|
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) {
|
2014-10-17 12:57:14 +00:00
|
|
|
QString cur = _doc->already(true);
|
2014-10-07 17:57:57 +00:00
|
|
|
if (cur.isEmpty()) {
|
2015-04-19 10:29:19 +00:00
|
|
|
if (_current.isNull() && _currentGif.isNull()) {
|
|
|
|
DocumentSaveLink::doSave(_doc, true);
|
|
|
|
updateControls();
|
|
|
|
} else {
|
|
|
|
_saveVisible = false;
|
|
|
|
update(_saveNav);
|
|
|
|
}
|
|
|
|
updateOver(_lastMouseMovePos);
|
2014-10-07 17:57:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-10-17 12:57:14 +00:00
|
|
|
|
2015-04-19 10:29:19 +00:00
|
|
|
QFileInfo alreadyInfo(cur);
|
|
|
|
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 = qsl("All files (*.*)");
|
|
|
|
} else {
|
|
|
|
filter = mimeType.filterString() + qsl(";;All files (*.*)");
|
|
|
|
}
|
|
|
|
|
2014-10-17 12:57:14 +00:00
|
|
|
psBringToBack(this);
|
2015-04-19 10:29:19 +00:00
|
|
|
file = saveFileName(lang(lng_save_file), filter, qsl("doc"), name, true, alreadyDir);
|
2014-10-17 12:57:14 +00:00
|
|
|
psShowOverAll(this);
|
2015-04-19 10:29:19 +00:00
|
|
|
if (!file.isEmpty() && file != cur) {
|
|
|
|
QFile(cur).copy(file);
|
2014-10-07 17:57:57 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!_photo || !_photo->full->loaded()) return;
|
2014-08-11 09:03:45 +00:00
|
|
|
|
2014-10-17 12:57:14 +00:00
|
|
|
psBringToBack(this);
|
|
|
|
bool gotName = filedialogGetSaveFile(file, lang(lng_save_photo), qsl("JPEG Image (*.jpg);;All files (*.*)"), filedialogDefaultName(qsl("photo"), qsl(".jpg")));
|
|
|
|
psShowOverAll(this);
|
|
|
|
if (gotName) {
|
2014-10-07 17:57:57 +00:00
|
|
|
if (!file.isEmpty()) {
|
|
|
|
_photo->full->pix().toImage().save(file, "JPG");
|
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-19 10:29:19 +00:00
|
|
|
void MediaView::onDocClick() {
|
|
|
|
QString fname = _doc->already(true);
|
|
|
|
if (fname.isEmpty()) {
|
|
|
|
if (_doc->loader) {
|
|
|
|
onSaveCancel();
|
|
|
|
} else {
|
|
|
|
onDownload();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
psOpenFile(fname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-17 12:57:14 +00:00
|
|
|
void MediaView::onDownload() {
|
|
|
|
if (cAskDownloadPath()) {
|
2015-04-19 10:29:19 +00:00
|
|
|
return onSaveAs();
|
2014-10-17 12:57:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString path;
|
|
|
|
if (cDownloadPath().isEmpty()) {
|
|
|
|
path = psDownloadPath();
|
|
|
|
} else if (cDownloadPath() == qsl("tmp")) {
|
|
|
|
path = cTempDir();
|
|
|
|
} else {
|
|
|
|
path = cDownloadPath();
|
|
|
|
}
|
|
|
|
QString toName;
|
|
|
|
if (_doc) {
|
|
|
|
QString cur = _doc->already(true);
|
|
|
|
if (cur.isEmpty()) {
|
2015-04-19 10:29:19 +00:00
|
|
|
if (_current.isNull() && _currentGif.isNull()) {
|
|
|
|
DocumentSaveLink::doSave(_doc);
|
|
|
|
updateControls();
|
|
|
|
} else {
|
|
|
|
_saveVisible = false;
|
|
|
|
update(_saveNav);
|
|
|
|
}
|
|
|
|
updateOver(_lastMouseMovePos);
|
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 = filedialogNextFilename(_doc->name, cur, path);
|
|
|
|
if (toName != cur && !QFile(cur).copy(toName)) {
|
|
|
|
toName = QString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!_photo || !_photo->full->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() {
|
|
|
|
if (_doc && _doc->loader) {
|
|
|
|
_doc->loader->cancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-07 17:57:57 +00:00
|
|
|
void MediaView::onShowInFolder() {
|
2015-04-11 10:04:10 +00:00
|
|
|
if (!_doc) return;
|
2014-10-07 17:57:57 +00:00
|
|
|
QString already(_doc->already(true));
|
|
|
|
if (!already.isEmpty()) psShowInFolder(already);
|
|
|
|
}
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
void MediaView::onForward() {
|
|
|
|
HistoryItem *item = App::histItemById(_msgid);
|
|
|
|
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();
|
2014-08-11 09:03:45 +00:00
|
|
|
if (!_msgid) {
|
|
|
|
if (App::self() && _photo && App::self()->photoId == _photo->id) {
|
|
|
|
App::app()->peerClearPhoto(App::self()->id);
|
|
|
|
} else if (_photo->chat && _photo->chat->photoId == _photo->id) {
|
|
|
|
App::app()->peerClearPhoto(_photo->chat->id);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
HistoryItem *item = App::histItemById(_msgid);
|
|
|
|
if (item) {
|
|
|
|
App::contextItem(item);
|
|
|
|
App::main()->deleteLayer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-17 12:57:14 +00:00
|
|
|
void MediaView::onOverview() {
|
2015-04-11 10:04:10 +00:00
|
|
|
if (_menu) _menu->fastHide();
|
|
|
|
if (!_history || _overview == OverviewCount) {
|
|
|
|
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() {
|
2015-04-11 10:04:10 +00:00
|
|
|
if (!_dropdown.isHidden()) {
|
|
|
|
_dropdown.ignoreShow();
|
|
|
|
_dropdown.hideStart();
|
|
|
|
}
|
2014-10-07 17:57:57 +00:00
|
|
|
if (_doc) {
|
2015-04-19 10:29:19 +00:00
|
|
|
if (_current.isNull()) return;
|
|
|
|
|
2014-10-07 17:57:57 +00:00
|
|
|
QApplication::clipboard()->setPixmap(_current);
|
|
|
|
} else {
|
|
|
|
if (!_photo || !_photo->full->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) {
|
2014-08-15 11:19:32 +00:00
|
|
|
_history = context ? context->history() : 0;
|
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();
|
|
|
|
anim::stop(this);
|
|
|
|
}
|
|
|
|
if (!_animOpacities.isEmpty()) _animOpacities.clear();
|
|
|
|
|
|
|
|
_index = -1;
|
2014-08-15 11:19:32 +00:00
|
|
|
_msgid = context ? context->id : 0;
|
2014-10-17 12:57:14 +00:00
|
|
|
_photo = photo;
|
2014-08-21 12:18:56 +00:00
|
|
|
if (_history) {
|
2015-04-11 10:04:10 +00:00
|
|
|
_overview = OverviewPhotos;
|
|
|
|
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) {
|
|
|
|
_history = 0;
|
|
|
|
_peer = context;
|
|
|
|
_user = context->chat ? 0 : 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();
|
|
|
|
anim::stop(this);
|
|
|
|
}
|
|
|
|
if (!_animOpacities.isEmpty()) _animOpacities.clear();
|
|
|
|
|
|
|
|
_msgid = 0;
|
|
|
|
_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
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
_history = context ? context->history() : 0;
|
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();
|
|
|
|
anim::stop(this);
|
|
|
|
}
|
|
|
|
if (!_animOpacities.isEmpty()) _animOpacities.clear();
|
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
_index = -1;
|
|
|
|
_msgid = context ? context->id : 0;
|
|
|
|
if (_history) {
|
|
|
|
_overview = OverviewDocuments;
|
|
|
|
|
|
|
|
for (int i = 0, l = _history->_overview[_overview].size(); i < l; ++i) {
|
|
|
|
if (_history->_overview[_overview].at(i) == _msgid) {
|
|
|
|
_index = i;
|
|
|
|
break;
|
|
|
|
}
|
2014-12-15 15:55:45 +00:00
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
|
|
|
|
if (_history->_overviewCount[_overview] < 0) {
|
|
|
|
loadBack();
|
2014-12-15 15:55:45 +00:00
|
|
|
}
|
2014-10-07 17:57:57 +00:00
|
|
|
}
|
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) {
|
2014-08-06 14:40:21 +00:00
|
|
|
_photo = photo;
|
2014-10-07 17:57:57 +00:00
|
|
|
_doc = 0;
|
|
|
|
_zoom = 0;
|
2015-04-11 10:04:10 +00:00
|
|
|
|
2015-05-20 19:28:24 +00:00
|
|
|
_caption = Text();
|
|
|
|
if (HistoryMessage *itemMsg = item ? item->toHistoryMessage() : 0) {
|
|
|
|
if (HistoryPhoto *photoMsg = dynamic_cast<HistoryPhoto*>(itemMsg->getMedia())) {
|
|
|
|
_caption.setText(st::mvCaptionFont, photoMsg->captionForClone().original(0, 0xFFFF), _captionTextOptions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-15 15:55:45 +00:00
|
|
|
_zoomToScreen = 0;
|
2014-08-11 09:03:45 +00:00
|
|
|
MTP::clearLoaderPriorities();
|
2014-08-17 07:37:24 +00:00
|
|
|
_full = -1;
|
2014-08-11 09:03:45 +00:00
|
|
|
_current = QPixmap();
|
2015-04-19 10:29:19 +00:00
|
|
|
_currentGif.stop();
|
2014-08-11 09:03:45 +00:00
|
|
|
_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) {
|
|
|
|
if (HistoryForwarded *fwd = item->toHistoryForwarded()) {
|
|
|
|
_from = fwd->fromForwarded();
|
2015-04-04 20:01:34 +00:00
|
|
|
} else {
|
2015-08-12 18:01:32 +00:00
|
|
|
_from = item->from();
|
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
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
updateControls();
|
2014-11-22 09:45:04 +00:00
|
|
|
_photo->full->load();
|
2014-08-06 14:40:21 +00:00
|
|
|
if (isHidden()) {
|
2014-09-29 02:47:30 +00:00
|
|
|
psUpdateOverlayed(this);
|
2014-08-06 14:40:21 +00:00
|
|
|
show();
|
2014-10-17 12:57:14 +00:00
|
|
|
psShowOverAll(this);
|
2014-08-06 14:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-15 11:23:59 +00:00
|
|
|
void MediaView::displayDocument(DocumentData *doc, HistoryItem *item) { // empty messages shown as docs: doc can be NULL
|
2015-04-11 10:04:10 +00:00
|
|
|
_doc = doc;
|
2015-07-15 11:23:59 +00:00
|
|
|
_photo = 0;
|
2015-02-19 11:30:16 +00:00
|
|
|
|
2015-05-20 19:28:24 +00:00
|
|
|
_caption = Text();
|
2015-07-15 11:23:59 +00:00
|
|
|
if (_doc) {
|
|
|
|
QString already = _doc->already(true);
|
|
|
|
if (_doc->sticker() && !_doc->sticker()->img->isNull() && _doc->sticker()->img->loaded()) {
|
|
|
|
_currentGif.stop();
|
|
|
|
_current = _doc->sticker()->img->pix();
|
|
|
|
} else if (!already.isEmpty()) {
|
|
|
|
QImageReader reader(already);
|
|
|
|
if (reader.canRead()) {
|
|
|
|
if (reader.supportsAnimation() && reader.imageCount() > 1) {
|
|
|
|
_currentGif.start(0, already);
|
|
|
|
_current = QPixmap();
|
|
|
|
} else {
|
|
|
|
_currentGif.stop();
|
|
|
|
QPixmap pix = QPixmap::fromImage(App::readImage(already, 0, false), Qt::ColorOnly);
|
|
|
|
_current = pix;
|
|
|
|
}
|
2015-04-19 10:29:19 +00:00
|
|
|
} else {
|
|
|
|
_currentGif.stop();
|
2015-07-15 11:23:59 +00:00
|
|
|
_current = QPixmap();
|
2015-04-19 10:29:19 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_currentGif.stop();
|
|
|
|
_current = QPixmap();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_currentGif.stop();
|
|
|
|
_current = QPixmap();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_current.isNull() && _currentGif.isNull()) {
|
2015-07-15 11:23:59 +00:00
|
|
|
if (!_doc || _doc->thumb->isNull()) {
|
2015-04-11 10:04:10 +00:00
|
|
|
style::sprite thumbs[] = { st::mvDocBlue, st::mvDocGreen, st::mvDocRed, st::mvDocYellow };
|
2015-06-02 11:22:00 +00:00
|
|
|
style::color colors[] = { st::mvDocBlueColor, st::mvDocGreenColor, st::mvDocRedColor, st::mvDocYellowColor };
|
2015-07-15 11:23:59 +00:00
|
|
|
QString name = _doc ? _doc->name.toLower() : QString(), mime = _doc ? _doc->mime.toLower() : QString();
|
2015-06-27 13:02:00 +00:00
|
|
|
if (name.endsWith(qstr(".doc")) ||
|
|
|
|
name.endsWith(qstr(".txt")) ||
|
|
|
|
name.endsWith(qstr(".psd")) ||
|
|
|
|
mime.startsWith(qstr("text/"))
|
2015-04-11 10:04:10 +00:00
|
|
|
) {
|
|
|
|
_docIcon = thumbs[0];
|
2015-06-02 11:22:00 +00:00
|
|
|
_docIconColor = colors[0];
|
2015-04-11 10:04:10 +00:00
|
|
|
} else if (
|
2015-06-27 13:02:00 +00:00
|
|
|
name.endsWith(qstr(".xls")) ||
|
|
|
|
name.endsWith(qstr(".csv"))
|
2015-04-11 10:04:10 +00:00
|
|
|
) {
|
|
|
|
_docIcon = thumbs[1];
|
2015-06-02 11:22:00 +00:00
|
|
|
_docIconColor = colors[1];
|
2015-04-11 10:04:10 +00:00
|
|
|
} else if (
|
2015-06-27 13:02:00 +00:00
|
|
|
name.endsWith(qstr(".pdf")) ||
|
|
|
|
name.endsWith(qstr(".ppt")) ||
|
|
|
|
name.endsWith(qstr(".key"))
|
2015-04-11 10:04:10 +00:00
|
|
|
) {
|
|
|
|
_docIcon = thumbs[2];
|
2015-06-02 11:22:00 +00:00
|
|
|
_docIconColor = colors[2];
|
2015-04-11 10:04:10 +00:00
|
|
|
} else if (
|
2015-06-27 13:02:00 +00:00
|
|
|
name.endsWith(qstr(".zip")) ||
|
|
|
|
name.endsWith(qstr(".rar")) ||
|
|
|
|
name.endsWith(qstr(".ai")) ||
|
|
|
|
name.endsWith(qstr(".mp3")) ||
|
|
|
|
name.endsWith(qstr(".mov")) ||
|
|
|
|
name.endsWith(qstr(".avi"))
|
2015-04-11 10:04:10 +00:00
|
|
|
) {
|
|
|
|
_docIcon = thumbs[3];
|
2015-06-02 11:22:00 +00:00
|
|
|
_docIconColor = colors[3];
|
2015-04-11 10:04:10 +00:00
|
|
|
} else {
|
|
|
|
int ext = name.lastIndexOf('.');
|
|
|
|
QChar ch = (ext >= 0 && ext + 1 < name.size()) ? name.at(ext + 1) : (name.isEmpty() ? (mime.isEmpty() ? '0' : mime.at(0)) : name.at(0));
|
|
|
|
_docIcon = thumbs[ch.unicode() % 4];
|
2015-06-02 11:22:00 +00:00
|
|
|
_docIconColor = colors[ch.unicode() % 4];
|
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) {
|
|
|
|
_docThumbw = (tw * st::mvDocBlue.pxHeight()) / th;
|
|
|
|
_docThumbx = (_docThumbw - st::mvDocBlue.pxWidth()) / 2;
|
|
|
|
_docThumby = 0;
|
|
|
|
} else {
|
|
|
|
_docThumbw = st::mvDocBlue.pxWidth();
|
|
|
|
_docThumbx = 0;
|
|
|
|
_docThumby = ((th * _docThumbw) / tw - st::mvDocBlue.pxHeight()) / 2;
|
|
|
|
}
|
2014-08-11 09:16:47 +00:00
|
|
|
}
|
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
int32 maxw = st::mvDocSize.width() - st::mvDocBlue.pxWidth() - st::mvDocPadding * 3;
|
|
|
|
|
2015-07-15 11:23:59 +00:00
|
|
|
_docName = (!_doc || _doc->name.isEmpty()) ? lang(_doc ? (_doc->type == StickerDocument ? lng_in_dlg_sticker : lng_mediaview_doc_image) : lng_message_empty) : _doc->name;
|
2015-04-19 10:29:19 +00:00
|
|
|
int32 lastDot = _docName.lastIndexOf('.');
|
2015-07-15 11:23:59 +00:00
|
|
|
_docExt = _doc ? ((lastDot < 0 || lastDot + 2 > _docName.size()) ? _docName : _docName.mid(lastDot + 1)) : QString();
|
2015-04-19 10:29:19 +00:00
|
|
|
_docNameWidth = st::mvDocNameFont->m.width(_docName);
|
2015-04-11 10:04:10 +00:00
|
|
|
if (_docNameWidth > maxw) {
|
2015-04-19 10:29:19 +00:00
|
|
|
_docName = st::mvDocNameFont->m.elidedText(_docName, Qt::ElideMiddle, maxw);
|
|
|
|
_docNameWidth = st::mvDocNameFont->m.width(_docName);
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
|
|
|
|
2015-04-19 10:29:19 +00:00
|
|
|
int32 extmaxw = (st::mvDocBlue.pxWidth() - st::mvDocExtPadding * 2);
|
|
|
|
|
|
|
|
_docExtWidth = st::mvDocExtFont->m.width(_docExt);
|
|
|
|
if (_docExtWidth > extmaxw) {
|
|
|
|
_docExt = st::mvDocNameFont->m.elidedText(_docExt, Qt::ElideMiddle, extmaxw);
|
|
|
|
_docExtWidth = st::mvDocNameFont->m.width(_docExt);
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
|
|
|
|
2015-04-19 10:29:19 +00:00
|
|
|
_docRadialFirst = _docRadialLast = _docRadialStart = 0;
|
|
|
|
|
2015-07-15 11:23:59 +00:00
|
|
|
float64 prg = (_doc && _doc->loader) ? _doc->loader->currentProgress() : 0;
|
2015-04-19 10:29:19 +00:00
|
|
|
a_docRadial = anim::fvalue(prg, qMax(prg, 0.0001));
|
|
|
|
// _docSize is updated in updateControls()
|
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
_docRect = QRect((width() - st::mvDocSize.width()) / 2, (height() - st::mvDocSize.height()) / 2, st::mvDocSize.width(), st::mvDocSize.height());
|
2015-07-03 08:47:16 +00:00
|
|
|
_docIconRect = myrtlrect(_docRect.x() + st::mvDocPadding, _docRect.y() + st::mvDocPadding, st::mvDocBlue.pxWidth(), st::mvDocBlue.pxHeight());
|
2015-04-19 10:29:19 +00:00
|
|
|
} else if (!_current.isNull()) {
|
2015-04-11 10:04:10 +00:00
|
|
|
_current.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
_w = _current.width() / cIntRetinaFactor();
|
|
|
|
_h = _current.height() / cIntRetinaFactor();
|
2015-04-19 10:29:19 +00:00
|
|
|
} else {
|
2015-05-21 12:08:05 +00:00
|
|
|
_w = _currentGif.w / cIntRetinaFactor();
|
|
|
|
_h = _currentGif.h / cIntRetinaFactor();
|
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;
|
|
|
|
}
|
|
|
|
if ((_w > width()) || (_h > height())) {
|
|
|
|
_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;
|
2015-08-12 18:01:32 +00:00
|
|
|
if (HistoryForwarded *fwd = item->toHistoryForwarded()) {
|
|
|
|
_from = fwd->fromForwarded();
|
2015-04-11 10:04:10 +00:00
|
|
|
} else {
|
2015-08-12 18:01:32 +00:00
|
|
|
_from = item->from();
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
|
|
|
_full = 1;
|
|
|
|
updateControls();
|
|
|
|
if (isHidden()) {
|
|
|
|
psUpdateOverlayed(this);
|
|
|
|
show();
|
|
|
|
psShowOverAll(this);
|
2014-08-11 09:16:47 +00:00
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
2014-08-11 09:16:47 +00:00
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
void MediaView::paintEvent(QPaintEvent *e) {
|
2015-04-19 19:01:45 +00:00
|
|
|
// uint64 ms = getms();
|
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
QRect r(e->rect());
|
2015-04-19 19:01:45 +00:00
|
|
|
QRegion region(e->region());
|
|
|
|
QVector<QRect> rs(region.rects());
|
|
|
|
if (rs.size() > 1) {
|
|
|
|
int a = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
bool name = false, icon = false;
|
|
|
|
|
|
|
|
p.setClipRegion(region);
|
2015-04-11 10:04:10 +00:00
|
|
|
|
|
|
|
// main bg
|
|
|
|
QPainter::CompositionMode m = p.compositionMode();
|
|
|
|
p.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
p.setOpacity(st::mvBgOpacity);
|
2015-04-19 19:01:45 +00:00
|
|
|
for (int i = 0, l = region.rectCount(); i < l; ++i) {
|
|
|
|
p.fillRect(rs.at(i), st::mvBgColor->b);
|
|
|
|
}
|
2014-08-11 09:06:16 +00:00
|
|
|
p.setCompositionMode(m);
|
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();
|
2014-10-07 17:57:57 +00:00
|
|
|
if (_full <= 0 && _photo->full->loaded()) {
|
2014-10-17 12:57:14 +00:00
|
|
|
int32 h = int((_photo->full->height() * (qreal(w) / qreal(_photo->full->width()))) + 0.9999);
|
|
|
|
_current = _photo->full->pixNoCache(w, h, true);
|
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);
|
2015-05-20 19:28:24 +00:00
|
|
|
_current = _photo->medium->pixNoCache(w, h, true, true);
|
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);
|
2015-05-20 19:28:24 +00:00
|
|
|
_current = _photo->thumb->pixNoCache(w, h, true, true);
|
2014-10-07 17:57:57 +00:00
|
|
|
if (cRetina()) _current.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
}
|
|
|
|
}
|
2015-04-19 10:29:19 +00:00
|
|
|
p.setOpacity(1);
|
|
|
|
if (_photo || !_current.isNull() || !_currentGif.isNull()) {
|
2014-10-07 17:57:57 +00:00
|
|
|
QRect imgRect(_x, _y, _w, _h);
|
2015-05-21 12:08:05 +00:00
|
|
|
const QPixmap *toDraw = _currentGif.isNull() ? &_current : &_currentGif.current(_currentGif.w, _currentGif.h, false);
|
2014-10-07 17:57:57 +00:00
|
|
|
if (imgRect.intersects(r)) {
|
2015-06-30 21:07:05 +00:00
|
|
|
if (toDraw->hasAlpha() && (!_doc || !_doc->sticker() || _doc->sticker()->img->isNull())) {
|
2014-12-15 15:55:45 +00:00
|
|
|
p.fillRect(imgRect, _transparentBrush);
|
|
|
|
}
|
2014-10-07 17:57:57 +00:00
|
|
|
if (_zoom) {
|
|
|
|
bool was = (p.renderHints() & QPainter::SmoothPixmapTransform);
|
2014-10-17 12:57:14 +00:00
|
|
|
if (!was) p.setRenderHint(QPainter::SmoothPixmapTransform, true);
|
2015-04-19 10:29:19 +00:00
|
|
|
p.drawPixmap(QRect(_x, _y, _w, _h), *toDraw);
|
2014-10-07 17:57:57 +00:00
|
|
|
if (!was) p.setRenderHint(QPainter::SmoothPixmapTransform, false);
|
|
|
|
} else {
|
2015-04-19 10:29:19 +00:00
|
|
|
p.drawPixmap(_x, _y, *toDraw);
|
2014-10-07 17:57:57 +00:00
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
|
2014-10-17 12:57:14 +00:00
|
|
|
uint64 ms = 0;
|
2014-10-07 17:57:57 +00:00
|
|
|
if (_full < 1) {
|
2014-10-17 12:57:14 +00:00
|
|
|
ms = getms();
|
|
|
|
uint64 dt = ms - _animStarted;
|
2014-10-07 17:57:57 +00:00
|
|
|
int32 cnt = int32(st::photoLoaderCnt), period = int32(st::photoLoaderPeriod), t = dt % period, delta = int32(st::photoLoaderDelta);
|
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
int32 x = (width() - st::mediaviewLoader.width()) / 2;
|
|
|
|
int32 y = (height() - st::mediaviewLoader.height()) / 2;
|
2014-10-07 17:57:57 +00:00
|
|
|
p.fillRect(x, y, st::mediaviewLoader.width(), st::mediaviewLoader.height(), st::photoLoaderBg->b);
|
2014-10-17 12:57:14 +00:00
|
|
|
|
2014-10-07 17:57:57 +00:00
|
|
|
x += (st::mediaviewLoader.width() - cnt * st::mediaviewLoaderPoint.width() - (cnt - 1) * st::mediaviewLoaderSkip) / 2;
|
|
|
|
y += (st::mediaviewLoader.height() - st::mediaviewLoaderPoint.height()) / 2;
|
|
|
|
QColor c(st::white->c);
|
|
|
|
QBrush b(c);
|
|
|
|
for (int32 i = 0; i < cnt; ++i) {
|
|
|
|
t -= delta;
|
|
|
|
while (t < 0) t += period;
|
|
|
|
|
|
|
|
float64 alpha = (t >= st::photoLoaderDuration1 + st::photoLoaderDuration2) ? 0 : ((t > st::photoLoaderDuration1 ? ((st::photoLoaderDuration1 + st::photoLoaderDuration2 - t) / st::photoLoaderDuration2) : (t / st::photoLoaderDuration1)));
|
|
|
|
c.setAlphaF(st::photoLoaderAlphaMin + alpha * (1 - st::photoLoaderAlphaMin));
|
|
|
|
b.setColor(c);
|
|
|
|
p.fillRect(x + i * (st::mediaviewLoaderPoint.width() + st::mediaviewLoaderSkip), y, st::mediaviewLoaderPoint.width(), st::mediaviewLoaderPoint.height(), b);
|
|
|
|
}
|
2014-10-17 12:57:14 +00:00
|
|
|
_saveMsgUpdater.start(AnimationTimerDelta);
|
|
|
|
}
|
|
|
|
if (_saveMsgStarted) {
|
|
|
|
if (!ms) ms = getms();
|
|
|
|
float64 dt = float64(ms) - _saveMsgStarted, hidingDt = dt - st::medviewSaveMsgShowing - st::medviewSaveMsgShown;
|
|
|
|
if (dt < st::medviewSaveMsgShowing + st::medviewSaveMsgShown + st::medviewSaveMsgHiding) {
|
|
|
|
if (hidingDt >= 0 && _saveMsgOpacity.to() > 0.5) {
|
|
|
|
_saveMsgOpacity.start(0);
|
|
|
|
}
|
|
|
|
float64 progress = (hidingDt >= 0) ? (hidingDt / st::medviewSaveMsgHiding) : (dt / st::medviewSaveMsgShowing);
|
|
|
|
_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());
|
2015-05-20 19:28:24 +00:00
|
|
|
App::roundRect(p, _saveMsg, st::medviewSaveMsg, MediaviewSaveCorners);
|
2014-10-17 12:57:14 +00:00
|
|
|
p.drawPixmap(_saveMsg.topLeft() + st::medviewSaveMsgCheckPos, App::sprite(), st::medviewSaveMsgCheck);
|
|
|
|
|
|
|
|
p.setPen(st::white->p);
|
|
|
|
textstyleSet(&st::medviewSaveAsTextStyle);
|
|
|
|
_saveMsgText.draw(p, _saveMsg.x() + st::medviewSaveMsgPadding.left(), _saveMsg.y() + st::medviewSaveMsgPadding.top(), _saveMsg.width() - st::medviewSaveMsgPadding.left() - st::medviewSaveMsgPadding.right());
|
|
|
|
textstyleRestore();
|
|
|
|
p.setOpacity(1);
|
|
|
|
}
|
|
|
|
if (_full >= 1) {
|
2014-10-17 13:24:17 +00:00
|
|
|
uint64 nextFrame = (dt < st::medviewSaveMsgShowing || hidingDt >= 0) ? int(AnimationTimerDelta) : (st::medviewSaveMsgShowing + st::medviewSaveMsgShown + 1 - dt);
|
2014-10-17 12:57:14 +00:00
|
|
|
_saveMsgUpdater.start(nextFrame);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_saveMsgStarted = 0;
|
|
|
|
}
|
2014-10-07 17:57:57 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-15 11:23:59 +00:00
|
|
|
} else {
|
2015-04-11 10:04:10 +00:00
|
|
|
if (_docRect.intersects(r)) {
|
|
|
|
p.fillRect(_docRect, st::mvDocBg->b);
|
2015-04-19 10:29:19 +00:00
|
|
|
if (_docIconRect.intersects(r)) {
|
2015-04-19 19:01:45 +00:00
|
|
|
icon = true;
|
2015-07-15 11:23:59 +00:00
|
|
|
if (!_doc || _doc->thumb->isNull()) {
|
|
|
|
if ((!_doc || !_doc->already().isEmpty()) && (!_docRadialStart || _docRadialOpacity < 1)) {
|
2015-06-02 11:22:00 +00:00
|
|
|
p.drawPixmap(_docIconRect.topLeft(), App::sprite(), _docIcon);
|
2015-04-19 10:29:19 +00:00
|
|
|
p.setPen(st::mvDocExtColor->p);
|
|
|
|
p.setFont(st::mvDocExtFont->f);
|
2015-07-15 11:23:59 +00:00
|
|
|
if (!_docExt.isEmpty()) {
|
|
|
|
p.drawText(_docIconRect.x() + (_docIconRect.width() - _docExtWidth) / 2, _docIconRect.y() + st::mvDocExtTop + st::mvDocExtFont->ascent, _docExt);
|
|
|
|
}
|
2015-06-02 11:22:00 +00:00
|
|
|
} else {
|
|
|
|
p.fillRect(_docIconRect, _docIconColor->b);
|
2015-04-19 10:29:19 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int32 rf(cIntRetinaFactor());
|
|
|
|
p.drawPixmap(_docIconRect.topLeft(), _doc->thumb->pix(_docThumbw), QRect(_docThumbx * rf, _docThumby * rf, st::mvDocBlue.pxWidth() * rf, st::mvDocBlue.pxHeight() * rf));
|
|
|
|
}
|
|
|
|
|
|
|
|
float64 o = overLevel(OverIcon);
|
2015-07-15 11:23:59 +00:00
|
|
|
if (_doc && _docRadialStart > 0) {
|
2015-04-19 10:29:19 +00:00
|
|
|
if (_doc->already().isEmpty() && _docRadialOpacity < 1) {
|
|
|
|
p.setOpacity((o * 1. + (1 - o) * st::radialDownloadOpacity) * (1 - _docRadialOpacity));
|
|
|
|
p.drawSpriteCenter(_docIconRect, st::radialDownload);
|
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
|
2015-04-19 10:29:19 +00:00
|
|
|
p.setRenderHint(QPainter::HighQualityAntialiasing);
|
2015-04-11 10:04:10 +00:00
|
|
|
|
2015-04-19 10:29:19 +00:00
|
|
|
QRect inner(QPoint(_docIconRect.x() + ((_docIconRect.width() - st::radialSize.width()) / 2), _docIconRect.y() + ((_docIconRect.height() - st::radialSize.height()) / 2)), st::radialSize);
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.setBrush(st::black->b);
|
|
|
|
p.setOpacity(_docRadialOpacity * st::radialBgOpacity);
|
|
|
|
p.drawEllipse(inner);
|
2015-04-11 10:04:10 +00:00
|
|
|
|
2015-04-19 10:29:19 +00:00
|
|
|
p.setOpacity((o * 1. + (1 - o) * st::radialCancelOpacity) * _docRadialOpacity);
|
|
|
|
p.drawSpriteCenter(_docIconRect, st::radialCancel);
|
2015-04-11 10:04:10 +00:00
|
|
|
|
2015-04-19 10:29:19 +00:00
|
|
|
QRect arc(inner.marginsRemoved(QMargins(st::radialLine, st::radialLine, st::radialLine, st::radialLine)));
|
2015-04-11 10:04:10 +00:00
|
|
|
|
2015-04-19 10:29:19 +00:00
|
|
|
p.setOpacity(_docRadialOpacity);
|
|
|
|
p.setPen(_docRadialPen);
|
2015-04-11 10:04:10 +00:00
|
|
|
|
2015-04-22 11:21:45 +00:00
|
|
|
int len = 16 + a_docRadial.current() * 5744;
|
2015-04-19 10:29:19 +00:00
|
|
|
p.drawArc(arc, 1440 - a_docRadialStart.current() * 5760 - len, len);
|
|
|
|
|
|
|
|
p.setOpacity(1);
|
|
|
|
p.setRenderHint(QPainter::HighQualityAntialiasing, false);
|
2015-07-15 11:23:59 +00:00
|
|
|
} else if (_doc && _doc->already().isEmpty()) {
|
2015-04-19 10:29:19 +00:00
|
|
|
p.setOpacity((o * 1. + (1 - o) * st::radialDownloadOpacity));
|
|
|
|
p.drawSpriteCenter(_docIconRect, st::radialDownload);
|
|
|
|
}
|
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;
|
2015-04-19 10:29:19 +00:00
|
|
|
p.setPen(st::mvDocNameColor->p);
|
|
|
|
p.setFont(st::mvDocNameFont->f);
|
|
|
|
p.drawTextLeft(_docRect.x() + 2 * st::mvDocPadding + st::mvDocBlue.pxWidth(), _docRect.y() + st::mvDocPadding + st::mvDocNameTop, width(), _docName, _docNameWidth);
|
2015-04-11 10:04:10 +00:00
|
|
|
|
2015-04-19 10:29:19 +00:00
|
|
|
p.setPen(st::mvDocSizeColor->p);
|
|
|
|
p.setFont(st::mvFont->f);
|
|
|
|
p.drawTextLeft(_docRect.x() + 2 * st::mvDocPadding + st::mvDocBlue.pxWidth(), _docRect.y() + st::mvDocPadding + st::mvDocSizeTop, width(), _docSize, _docSizeWidth);
|
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
2014-10-17 12:57:14 +00:00
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
float64 co = a_cOpacity.current();
|
|
|
|
if (co > 0) {
|
|
|
|
// left nav bar
|
|
|
|
if (_leftNav.intersects(r) && _leftNavVisible) {
|
2014-08-11 09:16:47 +00:00
|
|
|
float64 o = overLevel(OverLeftNav);
|
2015-04-11 10:04:10 +00:00
|
|
|
if (o > 0) {
|
|
|
|
p.setOpacity(o * st::mvControlBgOpacity * co);
|
2015-04-19 19:01:45 +00:00
|
|
|
for (int i = 0, l = region.rectCount(); i < l; ++i) {
|
|
|
|
QRect fill(_leftNav.intersected(rs.at(i)));
|
|
|
|
if (!fill.isEmpty()) p.fillRect(fill, st::black->b);
|
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
2015-04-19 19:01:45 +00:00
|
|
|
if (_leftNavIcon.intersects(r)) {
|
2015-04-11 10:04:10 +00:00
|
|
|
p.setOpacity((o * st::mvIconOverOpacity + (1 - o) * st::mvIconOpacity) * co);
|
2015-04-19 19:01:45 +00:00
|
|
|
p.drawPixmap(_leftNavIcon.topLeft(), App::sprite(), st::mvLeft);
|
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) {
|
2014-08-11 09:16:47 +00:00
|
|
|
float64 o = overLevel(OverRightNav);
|
2015-04-11 10:04:10 +00:00
|
|
|
if (o > 0) {
|
|
|
|
p.setOpacity(o * st::mvControlBgOpacity * co);
|
2015-04-19 19:01:45 +00:00
|
|
|
for (int i = 0, l = region.rectCount(); i < l; ++i) {
|
|
|
|
QRect fill(_rightNav.intersected(rs.at(i)));
|
|
|
|
if (!fill.isEmpty()) p.fillRect(fill, st::black->b);
|
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
2015-04-19 19:01:45 +00:00
|
|
|
if (_rightNavIcon.intersects(r)) {
|
2015-04-11 10:04:10 +00:00
|
|
|
p.setOpacity((o * st::mvIconOverOpacity + (1 - o) * st::mvIconOpacity) * co);
|
2015-04-19 19:01:45 +00:00
|
|
|
p.drawPixmap(_rightNavIcon.topLeft(), App::sprite(), st::mvRight);
|
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)) {
|
|
|
|
float64 o = overLevel(OverClose);
|
|
|
|
if (o > 0) {
|
|
|
|
p.setOpacity(o * st::mvControlBgOpacity * co);
|
2015-04-19 19:01:45 +00:00
|
|
|
for (int i = 0, l = region.rectCount(); i < l; ++i) {
|
|
|
|
QRect fill(_closeNav.intersected(rs.at(i)));
|
|
|
|
if (!fill.isEmpty()) p.fillRect(fill, st::black->b);
|
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
2015-04-19 19:01:45 +00:00
|
|
|
if (_closeNavIcon.intersects(r)) {
|
2015-04-11 10:04:10 +00:00
|
|
|
p.setOpacity((o * st::mvIconOverOpacity + (1 - o) * st::mvIconOpacity) * co);
|
2015-04-19 19:01:45 +00:00
|
|
|
p.drawPixmap(_closeNavIcon.topLeft(), App::sprite(), st::mvClose);
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// save button
|
2015-07-15 11:23:59 +00:00
|
|
|
if (_saveVisible && _saveNavIcon.intersects(r)) {
|
2015-04-11 10:04:10 +00:00
|
|
|
float64 o = overLevel(OverSave);
|
2015-04-19 19:01:45 +00:00
|
|
|
p.setOpacity((o * st::mvIconOverOpacity + (1 - o) * st::mvIconOpacity) * co);
|
|
|
|
p.drawPixmap(_saveNavIcon.topLeft(), App::sprite(), st::mvSave);
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// more area
|
2015-04-19 19:01:45 +00:00
|
|
|
if (_moreNavIcon.intersects(r)) {
|
2015-04-11 10:04:10 +00:00
|
|
|
float64 o = overLevel(OverMore);
|
2015-04-19 19:01:45 +00:00
|
|
|
p.setOpacity((o * st::mvIconOverOpacity + (1 - o) * st::mvIconOpacity) * co);
|
|
|
|
p.drawPixmap(_moreNavIcon.topLeft(), App::sprite(), st::mvMore);
|
2014-10-17 12:57:14 +00:00
|
|
|
}
|
2014-10-07 17:57:57 +00:00
|
|
|
|
2014-12-15 15:55:45 +00:00
|
|
|
p.setPen(st::white->p);
|
2015-04-11 10:04:10 +00:00
|
|
|
p.setFont(st::mvThickFont->f);
|
|
|
|
|
|
|
|
// header
|
|
|
|
if (_headerNav.intersects(r)) {
|
|
|
|
float64 o = _headerHasLink ? overLevel(OverHeader) : 0;
|
|
|
|
p.setOpacity((o * st::mvIconOverOpacity + (1 - o) * st::mvIconOpacity) * co);
|
|
|
|
p.drawText(_headerNav.left(), _headerNav.top() + st::mvThickFont->ascent, _headerText);
|
|
|
|
|
|
|
|
if (o > 0) {
|
|
|
|
p.setOpacity(o * co);
|
|
|
|
p.drawLine(_headerNav.left(), _headerNav.top() + st::mvThickFont->ascent + 1, _headerNav.right(), _headerNav.top() + st::mvThickFont->ascent + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p.setFont(st::mvFont->f);
|
|
|
|
|
|
|
|
// name
|
|
|
|
if (_from && _nameNav.intersects(r)) {
|
|
|
|
float64 o = overLevel(OverName);
|
|
|
|
p.setOpacity((o * st::mvIconOverOpacity + (1 - o) * st::mvIconOpacity) * 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);
|
|
|
|
p.drawLine(_nameNav.left(), _nameNav.top() + st::mvFont->ascent + 1, _nameNav.right(), _nameNav.top() + st::mvFont->ascent + 1);
|
|
|
|
}
|
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);
|
2015-04-11 10:04:10 +00:00
|
|
|
p.setOpacity((o * st::mvIconOverOpacity + (1 - o) * st::mvIconOpacity) * co);
|
|
|
|
p.drawText(_dateNav.left(), _dateNav.top() + st::mvFont->ascent, _dateText);
|
|
|
|
|
|
|
|
if (o > 0) {
|
|
|
|
p.setOpacity(o * co);
|
|
|
|
p.drawLine(_dateNav.left(), _dateNav.top() + st::mvFont->ascent + 1, _dateNav.right(), _dateNav.top() + st::mvFont->ascent + 1);
|
|
|
|
}
|
2015-01-02 14:55:24 +00:00
|
|
|
}
|
2015-05-20 19:28:24 +00:00
|
|
|
|
|
|
|
// caption
|
|
|
|
if (!_caption.isEmpty()) {
|
|
|
|
QRect outer(_captionRect.marginsAdded(st::mvCaptionPadding));
|
|
|
|
if (outer.intersects(r)) {
|
|
|
|
p.setOpacity(co);
|
|
|
|
p.setBrush(st::mvCaptionBg->b);
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.drawRoundedRect(outer, st::mvCaptionRadius, st::mvCaptionRadius);
|
|
|
|
if (_captionRect.intersects(r)) {
|
|
|
|
textstyleSet(&st::medviewSaveAsTextStyle);
|
|
|
|
p.setPen(st::white->p);
|
|
|
|
_caption.drawElided(p, _captionRect.x(), _captionRect.y(), _captionRect.width(), _captionRect.height() / st::mvCaptionFont->height);
|
|
|
|
textstyleRestore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-12-15 15:55:45 +00:00
|
|
|
}
|
2014-08-06 14:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::keyPressEvent(QKeyEvent *e) {
|
2014-08-11 09:03:45 +00:00
|
|
|
if (!_menu && e->key() == Qt::Key_Escape) {
|
2015-04-11 10:04:10 +00:00
|
|
|
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) {
|
|
|
|
if (_doc && !_doc->loader && _current.isNull() && _currentGif.isNull()) {
|
|
|
|
onDocClick();
|
|
|
|
}
|
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);
|
2014-12-16 16:46:54 +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)) {
|
2014-10-07 17:57:57 +00:00
|
|
|
int32 newZoom = _zoom;
|
2014-12-16 16:46:54 +00:00
|
|
|
if (e->key() == Qt::Key_Plus || e->key() == Qt::Key_Equal || e->key() == Qt::Key_Asterisk || e->key() == ']') {
|
2014-12-15 15:55:45 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2014-10-07 17:57:57 +00:00
|
|
|
} else if (e->key() == Qt::Key_Minus || e->key() == Qt::Key_Underscore) {
|
2014-12-15 15:55:45 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2014-10-07 17:57:57 +00:00
|
|
|
} else {
|
2014-12-15 15:55:45 +00:00
|
|
|
if (_zoom == 0) {
|
|
|
|
if (qFloor(_zoomToScreen) == qCeil(_zoomToScreen) && qRound(_zoomToScreen) >= -MaxZoomLevel && qRound(_zoomToScreen) <= MaxZoomLevel) {
|
|
|
|
newZoom = qRound(_zoomToScreen);
|
|
|
|
} else {
|
|
|
|
newZoom = ZoomToScreenLevel;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
newZoom = 0;
|
|
|
|
}
|
2014-10-17 12:57:14 +00:00
|
|
|
_x = -_width / 2;
|
2015-05-21 12:08:05 +00:00
|
|
|
_y = -(((_currentGif.isNull() ? _current.height() : _currentGif.h) / cIntRetinaFactor()) / 2);
|
2014-12-15 15:55:45 +00:00
|
|
|
float64 z = (_zoom == ZoomToScreenLevel) ? _zoomToScreen : _zoom;
|
|
|
|
if (z >= 0) {
|
|
|
|
_x = qRound(_x * (z + 1));
|
|
|
|
_y = qRound(_y * (z + 1));
|
2014-10-07 17:57:57 +00:00
|
|
|
} else {
|
2014-12-15 15:55:45 +00:00
|
|
|
_x = qRound(_x / (-z + 1));
|
|
|
|
_y = qRound(_y / (-z + 1));
|
2014-10-07 17:57:57 +00:00
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
_x += width() / 2;
|
|
|
|
_y += height() / 2;
|
2014-10-07 17:57:57 +00:00
|
|
|
update();
|
|
|
|
}
|
2014-12-15 15:55:45 +00:00
|
|
|
if (newZoom != ZoomToScreenLevel) {
|
|
|
|
while ((newZoom < 0 && (-newZoom + 1) > _w) || (-newZoom + 1) > _h) {
|
|
|
|
++newZoom;
|
|
|
|
}
|
2014-10-07 17:57:57 +00:00
|
|
|
}
|
|
|
|
if (_zoom != newZoom) {
|
2014-12-15 15:55:45 +00:00
|
|
|
float64 nx, ny, z = (_zoom == ZoomToScreenLevel) ? _zoomToScreen : _zoom;
|
2015-05-21 12:08:05 +00:00
|
|
|
_w = (_currentGif.isNull() ? _current.width() : _currentGif.w) / cIntRetinaFactor();
|
|
|
|
_h = (_currentGif.isNull() ? _current.height() : _currentGif.h) / cIntRetinaFactor();
|
2014-12-15 15:55:45 +00:00
|
|
|
if (z >= 0) {
|
2015-04-11 10:04:10 +00:00
|
|
|
nx = (_x - width() / 2.) / (z + 1);
|
|
|
|
ny = (_y - height() / 2.) / (z + 1);
|
2014-10-07 17:57:57 +00:00
|
|
|
} else {
|
2015-04-11 10:04:10 +00:00
|
|
|
nx = (_x - width() / 2.) * (-z + 1);
|
|
|
|
ny = (_y - height() / 2.) * (-z + 1);
|
2014-10-07 17:57:57 +00:00
|
|
|
}
|
|
|
|
_zoom = newZoom;
|
2014-12-15 15:55:45 +00:00
|
|
|
z = (_zoom == ZoomToScreenLevel) ? _zoomToScreen : _zoom;
|
|
|
|
if (z > 0) {
|
|
|
|
_w = qRound(_w * (z + 1));
|
|
|
|
_h = qRound(_h * (z + 1));
|
2015-04-11 10:04:10 +00:00
|
|
|
_x = qRound(nx * (z + 1) + width() / 2.);
|
|
|
|
_y = qRound(ny * (z + 1) + height() / 2.);
|
2014-10-07 17:57:57 +00:00
|
|
|
} else {
|
2014-12-15 15:55:45 +00:00
|
|
|
_w = qRound(_w / (-z + 1));
|
|
|
|
_h = qRound(_h / (-z + 1));
|
2015-04-11 10:04:10 +00:00
|
|
|
_x = qRound(nx / (-z + 1) + width() / 2.);
|
|
|
|
_y = qRound(ny / (-z + 1) + height() / 2.);
|
2014-10-07 17:57:57 +00:00
|
|
|
}
|
|
|
|
snapXY();
|
|
|
|
update();
|
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
void MediaView::moveToNext(int32 delta) {
|
2015-07-15 11:23:59 +00:00
|
|
|
if (_index < 0 || (_history && _overview != OverviewPhotos && _overview != OverviewDocuments) || (_overview == OverviewCount && !_user)) return;
|
2014-08-11 09:03:45 +00:00
|
|
|
|
|
|
|
int32 newIndex = _index + delta;
|
2015-04-11 10:04:10 +00:00
|
|
|
if (_history && _overview != OverviewCount) {
|
|
|
|
if (newIndex >= 0 && newIndex < _history->_overview[_overview].size()) {
|
2014-08-11 09:03:45 +00:00
|
|
|
_index = newIndex;
|
2015-04-11 10:04:10 +00:00
|
|
|
if (HistoryItem *item = App::histItemById(_history->_overview[_overview][_index])) {
|
2014-08-11 09:03:45 +00:00
|
|
|
_msgid = item->id;
|
2015-07-15 11:23:59 +00:00
|
|
|
if (item->getMedia()) {
|
|
|
|
switch (item->getMedia()->type()) {
|
|
|
|
case MediaTypePhoto: displayPhoto(static_cast<HistoryPhoto*>(item->getMedia())->photo(), item); preloadData(delta); break;
|
|
|
|
case MediaTypeDocument: displayDocument(static_cast<HistoryDocument*>(item->getMedia())->document(), item); preloadData(delta); break;
|
|
|
|
case MediaTypeSticker: displayDocument(static_cast<HistorySticker*>(item->getMedia())->document(), item); preloadData(delta); break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
displayDocument(0, item);
|
|
|
|
preloadData(delta);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
void MediaView::preloadData(int32 delta) {
|
2015-04-19 19:01:45 +00:00
|
|
|
if (_index < 0 || (!_user && _overview == OverviewCount)) return;
|
2014-08-11 09:03:45 +00:00
|
|
|
|
2014-08-15 11:19:32 +00:00
|
|
|
int32 from = _index + (delta ? delta : -1), to = _index + (delta ? delta * MediaOverviewPreloadCount : 1), forget = _index - delta * 2;
|
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) {
|
2014-08-11 09:03:45 +00:00
|
|
|
for (int32 i = from; i <= to; ++i) {
|
2015-04-11 10:04:10 +00:00
|
|
|
if (i >= 0 && i < _history->_overview[_overview].size() && i != _index) {
|
|
|
|
if (HistoryItem *item = App::histItemById(_history->_overview[_overview][i])) {
|
|
|
|
if (HistoryMedia *media = item->getMedia()) {
|
|
|
|
switch (media->type()) {
|
|
|
|
case MediaTypePhoto: static_cast<HistoryPhoto*>(media)->photo()->full->load(); break;
|
|
|
|
case MediaTypeDocument: static_cast<HistoryDocument*>(media)->document()->thumb->load(); break;
|
2015-06-30 21:07:05 +00:00
|
|
|
case MediaTypeSticker: static_cast<HistorySticker*>(media)->document()->sticker()->img->load(); break;
|
2015-04-11 10:04:10 +00:00
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
if (forget >= 0 && forget < _history->_overview[_overview].size() && forget != _index) {
|
|
|
|
if (HistoryItem *item = App::histItemById(_history->_overview[_overview][forget])) {
|
|
|
|
if (HistoryMedia *media = item->getMedia()) {
|
|
|
|
switch (media->type()) {
|
|
|
|
case MediaTypePhoto: static_cast<HistoryPhoto*>(media)->photo()->forget(); break;
|
|
|
|
case MediaTypeDocument: static_cast<HistoryDocument*>(media)->document()->forget(); break;
|
|
|
|
case MediaTypeSticker: static_cast<HistorySticker*>(media)->document()->forget(); break;
|
|
|
|
}
|
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) {
|
|
|
|
if (i >= 0 && i < _user->photos.size() && i != _index) {
|
|
|
|
_user->photos[i]->thumb->load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int32 i = from; i <= to; ++i) {
|
|
|
|
if (i >= 0 && i < _user->photos.size() && i != _index) {
|
|
|
|
_user->photos[i]->full->load();
|
|
|
|
}
|
|
|
|
}
|
2014-08-15 11:19:32 +00:00
|
|
|
if (forget >= 0 && forget < _user->photos.size() && forget != _index) {
|
|
|
|
_user->photos[forget]->forget();
|
|
|
|
}
|
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
|
|
|
|
|
|
|
if (textlnkDown() != textlnkOver()) {
|
|
|
|
textlnkDown(textlnkOver());
|
|
|
|
}
|
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;
|
2014-10-17 12:57:14 +00:00
|
|
|
if (!textlnkDown()) {
|
|
|
|
if (_over == OverLeftNav && _index >= 0) {
|
2015-04-11 10:04:10 +00:00
|
|
|
moveToNext(-1);
|
2014-10-17 12:57:14 +00:00
|
|
|
_lastAction = e->pos();
|
|
|
|
} else if (_over == OverRightNav && _index >= 0) {
|
2015-04-11 10:04:10 +00:00
|
|
|
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;
|
|
|
|
} else if (!_saveMsg.contains(e->pos()) || !_saveMsgStarted) {
|
2014-10-17 12:57:14 +00:00
|
|
|
_pressed = true;
|
|
|
|
_dragging = 0;
|
|
|
|
setCursor(style::cur_default);
|
|
|
|
_mStart = e->pos();
|
|
|
|
_xStart = _x;
|
|
|
|
_yStart = _y;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
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) {
|
2015-04-11 10:04:10 +00:00
|
|
|
bool moved = (e->pos() != _lastMouseMovePos);
|
|
|
|
_lastMouseMovePos = e->pos();
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
updateOver(e->pos());
|
2015-04-11 10:04:10 +00:00
|
|
|
if (_lastAction.x() >= 0 && (e->pos() - _lastAction).manhattanLength() >= st::mvDeltaFromLastAction) {
|
|
|
|
_lastAction = QPoint(-st::mvDeltaFromLastAction, -st::mvDeltaFromLastAction);
|
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();
|
|
|
|
}
|
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
if (moved) activateControls();
|
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) {
|
|
|
|
QTimer::singleShot(0, this, SLOT(onDropdown()));
|
|
|
|
}
|
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 {
|
|
|
|
_animOpacities.insert(_over, anim::fvalue(1, 0));
|
|
|
|
}
|
2015-04-19 19:01:45 +00:00
|
|
|
if (!animating()) anim::start(this);
|
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 {
|
|
|
|
_animOpacities.insert(_over, anim::fvalue(0, 1));
|
|
|
|
}
|
2015-04-19 19:01:45 +00:00
|
|
|
if (!animating()) anim::start(this);
|
2014-08-11 09:03:45 +00:00
|
|
|
setCursor(style::cur_pointer);
|
|
|
|
} else {
|
|
|
|
setCursor(style::cur_default);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-04-19 19:01:45 +00:00
|
|
|
void MediaView::updateOver(QPoint pos) {
|
2014-10-17 12:57:14 +00:00
|
|
|
TextLinkPtr lnk;
|
|
|
|
bool inText;
|
2015-05-20 19:28:24 +00:00
|
|
|
|
|
|
|
if (_saveMsgStarted && _saveMsg.contains(pos)) {
|
2014-10-17 13:24:17 +00:00
|
|
|
_saveMsgText.getState(lnk, inText, pos.x() - _saveMsg.x() - st::medviewSaveMsgPadding.left(), pos.y() - _saveMsg.y() - st::medviewSaveMsgPadding.top(), _saveMsg.width() - st::medviewSaveMsgPadding.left() - st::medviewSaveMsgPadding.right());
|
2015-05-20 19:28:24 +00:00
|
|
|
} else if (_captionRect.contains(pos)) {
|
|
|
|
_caption.getState(lnk, inText, pos.x() - _captionRect.x(), pos.y() - _captionRect.y(), _captionRect.width());
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|
2014-10-17 12:57:14 +00:00
|
|
|
if (lnk != textlnkOver()) {
|
|
|
|
textlnkOver(lnk);
|
|
|
|
setCursor((textlnkOver() || textlnkDown()) ? style::cur_pointer : style::cur_default);
|
2015-05-20 19:28:24 +00:00
|
|
|
update(QRegion(_saveMsg) + _captionRect);
|
2014-10-17 12:57:14 +00:00
|
|
|
}
|
|
|
|
|
2014-10-07 17:57:57 +00:00
|
|
|
if (_pressed || _dragging) return;
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
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);
|
2015-04-19 10:29:19 +00:00
|
|
|
} else if (_doc && _current.isNull() && _currentGif.isNull() && _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);
|
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());
|
2014-10-17 12:57:14 +00:00
|
|
|
if (textlnkDown() && textlnkOver() == textlnkDown()) {
|
|
|
|
textlnkDown()->onClick(e->button());
|
|
|
|
}
|
|
|
|
textlnkDown(TextLinkPtr());
|
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();
|
2014-08-11 09:03:45 +00:00
|
|
|
if (App::main()) App::main()->showPeerProfile(_from);
|
|
|
|
}
|
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();
|
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);
|
2015-04-19 10:29:19 +00:00
|
|
|
} else if ((e->pos() - _lastAction).manhattanLength() >= st::mvDeltaFromLastAction && (!_doc || !_current.isNull() || !_currentGif.isNull() || !_docRect.contains(e->pos()))) {
|
2015-04-11 10:04:10 +00:00
|
|
|
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;
|
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
_menu = new ContextMenu(this, st::mvDropdown, st::mvContextButton);
|
|
|
|
updateDropdown();
|
|
|
|
for (int32 i = 0, l = _btns.size(); i < l; ++i) {
|
|
|
|
if (!_btns.at(i)->isHidden()) _menu->addAction(_btns.at(i)->getText(), _btns.at(i), SIGNAL(clicked()))->setEnabled(true);
|
2014-10-07 17:57:57 +00:00
|
|
|
}
|
|
|
|
_menu->deleteOnHide();
|
|
|
|
connect(_menu, SIGNAL(destroyed(QObject*)), this, SLOT(onMenuDestroy(QObject*)));
|
|
|
|
_menu->popup(e->globalPos());
|
|
|
|
e->accept();
|
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);
|
2015-04-11 10:04:10 +00:00
|
|
|
if (d.x() * d.x() > d.y() * d.y() && (d.x() > st::mvSwipeDistance || d.x() < -st::mvSwipeDistance)) {
|
|
|
|
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
|
|
|
}
|
|
|
|
return QWidget::event(e);
|
|
|
|
}
|
|
|
|
|
2014-08-15 11:19:32 +00:00
|
|
|
void MediaView::hide() {
|
2015-04-11 10:04:10 +00:00
|
|
|
_controlsHideTimer.stop();
|
|
|
|
_controlsState = ControlsShown;
|
|
|
|
a_cOpacity = anim::fvalue(1, 1);
|
2014-08-15 11:53:58 +00:00
|
|
|
QWidget::hide();
|
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;
|
|
|
|
}
|
|
|
|
_receiveMouse = false;
|
|
|
|
QTimer::singleShot(0, this, SLOT(receiveMouse()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::receiveMouse() {
|
|
|
|
_receiveMouse = true;
|
|
|
|
}
|
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
void MediaView::onDropdown() {
|
|
|
|
updateDropdown();
|
|
|
|
_dropdown.ignoreShow(false);
|
|
|
|
_dropdown.showStart();
|
|
|
|
_dropdown.setFocus();
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
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() {
|
|
|
|
for (int i = 0, l = _history->_overview[_overview].size(); i < l; ++i) {
|
|
|
|
if (_history->_overview[_overview].at(i) == _msgid) {
|
|
|
|
_index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-03 08:47:16 +00:00
|
|
|
if (_history->_overviewCount[_overview] < 0 || (!_index && _history->_overviewCount[_overview] > 0)) {
|
2015-04-11 10:04:10 +00:00
|
|
|
loadBack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::loadBack() {
|
|
|
|
if (_loadRequest || _index < 0 || (_overview == OverviewCount && !_user)) return;
|
2014-08-11 09:03:45 +00:00
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
if (_history && _overview != OverviewCount && _history->_overviewCount[_overview] != 0) {
|
|
|
|
if (App::main()) App::main()->loadMediaBack(_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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::userPhotosLoaded(UserData *u, const MTPphotos_Photos &photos, mtpRequestId req) {
|
|
|
|
if (req == _loadRequest) {
|
|
|
|
_loadRequest = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QVector<MTPPhoto> *v = 0;
|
|
|
|
switch (photos.type()) {
|
|
|
|
case mtpc_photos_photos: {
|
|
|
|
const MTPDphotos_photos &d(photos.c_photos_photos());
|
|
|
|
App::feedUsers(d.vusers);
|
|
|
|
v = &d.vphotos.c_vector().v;
|
|
|
|
u->photosCount = 0;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case mtpc_photos_photosSlice: {
|
|
|
|
const MTPDphotos_photosSlice &d(photos.c_photos_photosSlice());
|
|
|
|
App::feedUsers(d.vusers);
|
|
|
|
u->photosCount = d.vcount.v;
|
|
|
|
v = &d.vphotos.c_vector().v;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
default: return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (v->isEmpty()) {
|
|
|
|
u->photosCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (QVector<MTPPhoto>::const_iterator i = v->cbegin(), e = v->cend(); i != e; ++i) {
|
|
|
|
PhotoData *photo = App::feedPhoto(*i);
|
|
|
|
photo->thumb->load();
|
|
|
|
u->photos.push_back(photo);
|
|
|
|
}
|
2015-07-03 08:47:16 +00:00
|
|
|
if (App::wnd()) App::wnd()->mediaOverviewUpdated(u, OverviewCount);
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::updateHeader() {
|
|
|
|
int32 index = _index, count = 0;
|
|
|
|
if (_history) {
|
2015-04-11 10:04:10 +00:00
|
|
|
if (_overview != OverviewCount) {
|
|
|
|
count = _history->_overviewCount[_overview] ? _history->_overviewCount[_overview] : _history->_overview[_overview].size();
|
|
|
|
if (index >= 0) index += count - _history->_overview[_overview].size();
|
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
} else if (_user) {
|
|
|
|
count = _user->photosCount ? _user->photosCount : _user->photos.size();
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
} 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
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
_headerHasLink = (_overview != OverviewCount) && _history;
|
|
|
|
int32 hwidth = st::mvThickFont->m.width(_headerText);
|
|
|
|
if (hwidth > width() / 3) {
|
|
|
|
hwidth = width() / 3;
|
|
|
|
_headerText = st::mvThickFont->m.elidedText(_headerText, Qt::ElideMiddle, hwidth);
|
|
|
|
}
|
2015-07-03 08:47:16 +00:00
|
|
|
_headerNav = myrtlrect(st::mvTextLeft, height() - st::mvHeaderTop, hwidth, st::mvThickFont->height);
|
2014-10-17 12:57:14 +00:00
|
|
|
}
|
2015-04-11 10:04:10 +00:00
|
|
|
//
|
|
|
|
//void MediaView::updatePolaroid() {
|
|
|
|
// if (_doc) {
|
|
|
|
// _polaroidIn = _polaroidOut = QRect(0, 0, _avail.width(), _avail.height() - st::medviewBottomBar);
|
|
|
|
// int32 minus1 = width() - _delete.x(), minus2 = _overview.x() + st::medviewHeaderFont->m.width(_header) - st::medviewOverview.width;
|
|
|
|
// if (minus2 > minus1) minus1 = minus2;
|
|
|
|
//
|
|
|
|
// int32 dateWidth = st::medviewDateFont->m.width(_dateText), maxWidth = width() - 2 * minus1;
|
|
|
|
// if (_from) {
|
|
|
|
// int32 nameWidth = _fromName.maxWidth();
|
|
|
|
// if (maxWidth < dateWidth) {
|
|
|
|
// maxWidth = dateWidth;
|
|
|
|
// }
|
|
|
|
// if (nameWidth > maxWidth) {
|
|
|
|
// nameWidth = maxWidth;
|
|
|
|
// }
|
|
|
|
// _nameNav = QRect((_avail.width() - nameWidth) / 2, _avail.y() + _avail.height() - ((st::medviewPolaroid.bottom() + st::medviewBottomBar) / 2) + st::medviewNameTop, nameWidth, st::medviewNameFont->height);
|
|
|
|
// _dateNav = QRect((_avail.width() - dateWidth) / 2, _avail.y() + _avail.height() - ((st::medviewPolaroid.bottom() + st::medviewBottomBar) / 2) + st::medviewDateTop, dateWidth, st::medviewDateFont->height);
|
|
|
|
// } else {
|
|
|
|
// _nameNav = QRect(_avail.x() - 1, _avail.y() - 1, 0, 0);
|
|
|
|
// _dateNav = QRect((_avail.width() - dateWidth) / 2, _avail.y() + _avail.height() - ((st::medviewPolaroid.bottom() + st::medviewBottomBar) / 2) + ((st::medviewNameTop + st::medviewDateTop) / 2), dateWidth, st::medviewDateFont->height);
|
|
|
|
// }
|
|
|
|
// } else {
|
|
|
|
// int32 pminw = qMin(st::medviewPolaroidMin.width(), int(_avail.width() - 2 * st::medviewNavBarWidth));
|
|
|
|
//
|
|
|
|
// int32 pl = _x - st::medviewPolaroid.left(), plw = st::medviewPolaroid.left();
|
|
|
|
// if (pl < st::medviewNavBarWidth) pl = st::medviewNavBarWidth;
|
|
|
|
// int32 pr = _x + _w + st::medviewPolaroid.right(), prw = st::medviewPolaroid.right();
|
|
|
|
// if (pr > _avail.width() - st::medviewNavBarWidth) pr = _avail.width() - st::medviewNavBarWidth;
|
|
|
|
//
|
|
|
|
// if (_w + st::medviewPolaroid.left() + st::medviewPolaroid.right() < pminw) {
|
|
|
|
// pl = (_avail.width() - pminw) / 2;
|
|
|
|
// plw = _x - pl;
|
|
|
|
// pr = pl + pminw;
|
|
|
|
// prw = pr - (_x + _w);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// int32 pminh = qMin(st::medviewPolaroidMin.height(), int(_avail.height() - st::medviewBottomBar));
|
|
|
|
//
|
|
|
|
// int32 pt = _y - st::medviewPolaroid.top(), pth = st::medviewPolaroid.top();
|
|
|
|
// if (pt < 0) pt = 0;
|
|
|
|
// int32 pb = _y + _h + st::medviewPolaroid.bottom(), pbh = st::medviewPolaroid.bottom();
|
|
|
|
// if (pb > _avail.height() - st::medviewBottomBar) pb = _avail.height() - st::medviewBottomBar;
|
|
|
|
//
|
|
|
|
// if (_h + st::medviewPolaroid.top() + st::medviewPolaroid.bottom() < pminh) {
|
|
|
|
// pt = (_avail.height() - st::medviewBottomBar - pminh) / 2;
|
|
|
|
// pth = _y - pt;
|
|
|
|
// pb = pt + pminh;
|
|
|
|
// pbh = pb - (_y + _h);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// _polaroidOut = QRect(pl, pt, pr - pl, pb - pt);
|
|
|
|
// _polaroidIn = QRect(pl + plw, pt + pth, pr - pl - prw - plw, pb - pt - pbh - pth);
|
|
|
|
//
|
|
|
|
// int32 nameWidth = _fromName.maxWidth(), maxWidth = _polaroidOut.width() - st::medviewPolaroid.left() - st::medviewPolaroid.right(), dateWidth = st::medviewDateFont->m.width(_dateText);
|
|
|
|
// if (nameWidth > maxWidth) {
|
|
|
|
// nameWidth = maxWidth;
|
|
|
|
// }
|
|
|
|
// _nameNav = QRect(_polaroidIn.x() + ((_polaroidIn.width() - nameWidth) / 2), _polaroidOut.y() + _polaroidOut.height() - st::medviewPolaroid.bottom() + st::medviewNameTop, nameWidth, st::medviewNameFont->height);
|
|
|
|
// _dateNav = QRect(_polaroidIn.x() + ((_polaroidIn.width() - dateWidth) / 2), _polaroidOut.y() + _polaroidOut.height() - st::medviewPolaroid.bottom() + st::medviewDateTop, dateWidth, st::medviewDateFont->height);
|
|
|
|
// }
|
|
|
|
//}
|
2014-10-17 12:57:14 +00:00
|
|
|
|
|
|
|
QColor MediaView::overColor(const QColor &a, float64 ca, const QColor &b, float64 cb) {
|
|
|
|
QColor res;
|
|
|
|
float64 o = a.alphaF() * ca + b.alphaF() * cb - a.alphaF() * ca * b.alphaF() * cb;
|
|
|
|
float64 ka = (o > 0.001) ? (a.alphaF() * ca * (1 - (b.alphaF() * cb)) / o) : 0;
|
|
|
|
float64 kb = (o > 0.001) ? (b.alphaF() * cb / o) : 0;
|
|
|
|
res.setRedF(a.redF() * ka + b.redF() * kb);
|
|
|
|
res.setGreenF(a.greenF() * ka + b.greenF() * kb);
|
|
|
|
res.setBlueF(a.blueF() * ka + b.blueF() * kb);
|
|
|
|
res.setAlphaF(o);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
float64 MediaView::overLevel(OverState control) {
|
|
|
|
ShowingOpacities::const_iterator i = _animOpacities.constFind(control);
|
|
|
|
return (i == _animOpacities.cend()) ? (_over == control ? 1 : 0) : i->current();
|
|
|
|
}
|