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 {
|
|
|
|
public:
|
|
|
|
|
|
|
|
SaveMsgLink(MediaView *view) : _view(view) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void onClick(Qt::MouseButton button) const {
|
|
|
|
if (button == Qt::LeftButton) {
|
|
|
|
_view->showSaveMsgFile();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
MediaView *_view;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-09-29 02:47:30 +00:00
|
|
|
MediaView::MediaView() : TWidget(App::wnd()),
|
2014-10-17 12:57:14 +00:00
|
|
|
_photo(0), _doc(0), _availBottom(0), _leftNavVisible(false), _rightNavVisible(false), _animStarted(getms()),
|
|
|
|
_maxWidth(0), _maxHeight(0), _width(0), _x(0), _y(0), _w(0), _h(0), _xStart(0), _yStart(0),
|
2014-12-15 15:55:45 +00:00
|
|
|
_zoom(0), _zoomToScreen(0), _pressed(false), _dragging(0), _full(-1), _history(0), _peer(0), _user(0), _from(0), _index(-1), _msgid(0),
|
2014-10-17 12:57:14 +00:00
|
|
|
_loadRequest(0), _over(OverNone), _down(OverNone), _lastAction(-st::medviewDeltaFromLastAction, -st::medviewDeltaFromLastAction),
|
|
|
|
_close(this, st::medviewClose),
|
|
|
|
_save(this, st::medviewSaveAs, lang(lng_mediaview_save)),
|
|
|
|
_forward(this, st::medviewForward, lang(lng_mediaview_forward)),
|
|
|
|
_delete(this, st::medviewDelete, lang(lng_mediaview_delete)),
|
|
|
|
_overview(this, st::medviewOverview, lang(lng_mediaview_single_photo)),
|
|
|
|
_menu(0), _receiveMouse(true), _touchPress(false), _touchMove(false), _touchRightButton(false),
|
|
|
|
_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)));
|
|
|
|
|
2014-12-15 15:55:45 +00:00
|
|
|
_transparentBrush = QBrush(App::sprite().copy(st::medviewTransparentBrush));
|
|
|
|
|
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);
|
2014-08-06 14:40:21 +00:00
|
|
|
hide();
|
2014-08-11 09:03:45 +00:00
|
|
|
|
|
|
|
connect(&_close, SIGNAL(clicked()), this, SLOT(onClose()));
|
2014-10-17 12:57:14 +00:00
|
|
|
connect(&_save, SIGNAL(clicked()), this, SLOT(onDownload()));
|
2014-08-11 09:03:45 +00:00
|
|
|
connect(&_forward, SIGNAL(clicked()), this, SLOT(onForward()));
|
|
|
|
connect(&_delete, SIGNAL(clicked()), this, SLOT(onDelete()));
|
2014-10-17 12:57:14 +00:00
|
|
|
connect(&_overview, SIGNAL(clicked()), this, SLOT(onOverview()));
|
|
|
|
|
|
|
|
_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()));
|
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);
|
2014-10-17 12:57:14 +00:00
|
|
|
_avail = QDesktopWidget().screenGeometry(wndCenter);
|
|
|
|
if (_avail != geometry()) {
|
|
|
|
setGeometry(_avail);
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
2014-10-17 12:57:14 +00:00
|
|
|
_avail.moveTo(0, 0);
|
|
|
|
_availBottom = _avail.height() - st::medviewBottomBar;
|
|
|
|
_maxWidth = _avail.width() - 2 * st::medviewNavBarWidth - st::medviewPolaroid.left() - st::medviewPolaroid.right();
|
|
|
|
_maxHeight = _avail.height() - st::medviewBottomBar - st::medviewPolaroid.top() - st::medviewPolaroid.bottom();
|
|
|
|
_leftNav = QRect(0, 0, st::medviewNavBarWidth, _availBottom);
|
|
|
|
_rightNav = QRect(width() - st::medviewNavBarWidth, 0, st::medviewNavBarWidth + (cRetina() ? 1 : 0), _availBottom);
|
|
|
|
|
|
|
|
_bottomBar = QRect(0, _availBottom, width(), height() - _availBottom);
|
|
|
|
|
|
|
|
_close.move(width() - ((_close.width() + st::medviewNavBarWidth) / 2), (st::medviewNavBarWidth - _close.width()) / 2);
|
|
|
|
_save.move(width() - _save.width() - ((st::medviewBottomBar - _save.height()) / 2), _availBottom + ((st::medviewBottomBar - _save.height()) / 2));
|
|
|
|
_forward.move(_save.x() - _forward.width() - ((st::medviewBottomBar - _forward.height()) / 2), _availBottom + ((st::medviewBottomBar - _forward.height()) / 2));
|
|
|
|
_delete.move(_forward.isHidden() ? _save.x() : _forward.x() - _delete.width() - ((st::medviewBottomBar - _delete.height()) / 2), _availBottom + ((st::medviewBottomBar - _delete.height()) / 2));
|
|
|
|
_overview.move(((st::medviewBottomBar - _overview.height()) / 2), _availBottom + ((st::medviewBottomBar - _overview.height()) / 2));
|
|
|
|
|
|
|
|
_saveMsg.moveTo((width() - _saveMsg.width()) / 2, (_availBottom - st::medviewPolaroid.bottom() - _saveMsg.height() + st::medviewPolaroid.top()) / 2);
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::mediaOverviewUpdated(PeerData *peer) {
|
2014-10-07 17:57:57 +00:00
|
|
|
if (!_photo) return;
|
2014-08-11 09:03:45 +00:00
|
|
|
if (_history && _history->peer == peer) {
|
|
|
|
_index = -1;
|
2014-08-15 11:19:32 +00:00
|
|
|
for (int i = 0, l = _history->_overview[OverviewPhotos].size(); i < l; ++i) {
|
|
|
|
if (_history->_overview[OverviewPhotos].at(i) == _msgid) {
|
2014-08-11 09:03:45 +00:00
|
|
|
_index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateControls();
|
2014-08-15 11:19:32 +00:00
|
|
|
preloadPhotos(0);
|
2014-08-11 09:03:45 +00:00
|
|
|
} else if (_user == peer) {
|
|
|
|
_index = -1;
|
|
|
|
for (int i = 0, l = _user->photos.size(); i < l; ++i) {
|
|
|
|
if (_user->photos.at(i) == _photo) {
|
|
|
|
_index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateControls();
|
2014-08-15 11:19:32 +00:00
|
|
|
preloadPhotos(0);
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::changingMsgId(HistoryItem *row, MsgId newId) {
|
|
|
|
if (row->id == _msgid) {
|
|
|
|
_msgid = newId;
|
|
|
|
}
|
|
|
|
mediaOverviewUpdated(row->history()->peer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::updateControls() {
|
2014-10-07 17:57:57 +00:00
|
|
|
if (!_photo && !_doc) return;
|
2014-08-11 09:03:45 +00:00
|
|
|
|
|
|
|
_close.show();
|
2014-10-07 18:38:22 +00:00
|
|
|
if ((_photo && _photo->full->loaded()) || (_doc && !_doc->already(true).isEmpty())) {
|
2014-08-11 09:03:45 +00:00
|
|
|
_save.show();
|
|
|
|
} else {
|
|
|
|
_save.hide();
|
|
|
|
}
|
|
|
|
if (_history) {
|
|
|
|
HistoryItem *item = App::histItemById(_msgid);
|
|
|
|
if (dynamic_cast<HistoryMessage*>(item)) {
|
|
|
|
_forward.show();
|
2014-10-17 12:57:14 +00:00
|
|
|
_delete.move(_forward.x() - _delete.width() - ((st::medviewBottomBar - _delete.height()) / 2), _availBottom + ((st::medviewBottomBar - _delete.height()) / 2));
|
2014-08-11 09:03:45 +00:00
|
|
|
} else {
|
|
|
|
_forward.hide();
|
2014-10-17 12:57:14 +00:00
|
|
|
_delete.move(_save.x() - _delete.width() - ((st::medviewBottomBar - _delete.height()) / 2), _availBottom + ((st::medviewBottomBar - _delete.height()) / 2));
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
_delete.show();
|
|
|
|
} else {
|
|
|
|
_forward.hide();
|
2014-10-07 17:57:57 +00:00
|
|
|
if (_photo && ((App::self() && App::self()->photoId == _photo->id) || (_photo->chat && _photo->chat->photoId == _photo->id))) {
|
2014-08-11 09:03:45 +00:00
|
|
|
_delete.show();
|
2014-10-17 12:57:14 +00:00
|
|
|
_delete.move(_save.x() - _delete.width() - ((st::medviewBottomBar - _delete.height()) / 2), _availBottom + ((st::medviewBottomBar - _delete.height()) / 2));
|
2014-08-11 09:03:45 +00:00
|
|
|
} else {
|
|
|
|
_delete.hide();
|
|
|
|
}
|
|
|
|
}
|
2014-10-07 17:57:57 +00:00
|
|
|
QDateTime d(date(_photo ? _photo->date : _doc->date)), dNow(date(unixtime()));
|
2014-08-11 09:03:45 +00:00
|
|
|
if (d.date() == dNow.date()) {
|
|
|
|
_dateText = lang(lng_status_lastseen_today).replace(qsl("{time}"), d.time().toString(qsl("hh:mm")));
|
|
|
|
} else if (d.date().addDays(1) == dNow.date()) {
|
|
|
|
_dateText = lang(lng_status_lastseen_yesterday).replace(qsl("{time}"), d.time().toString(qsl("hh:mm")));
|
|
|
|
} else {
|
|
|
|
_dateText = lang(lng_status_lastseen_date_time).replace(qsl("{date}"), d.date().toString(qsl("dd.MM.yy"))).replace(qsl("{time}"), d.time().toString(qsl("hh:mm")));
|
|
|
|
}
|
2014-10-17 12:57:14 +00:00
|
|
|
_fromName.setText(st::medviewNameFont, _from->name);
|
2014-08-11 09:03:45 +00:00
|
|
|
updateHeader();
|
2014-10-07 17:57:57 +00:00
|
|
|
_leftNavVisible = _photo && (_index > 0 || (_index == 0 && _history && _history->_overview[OverviewPhotos].size() < _history->_overviewCount[OverviewPhotos]));
|
|
|
|
_rightNavVisible = _photo && (_index >= 0 && (
|
2014-08-15 11:19:32 +00:00
|
|
|
(_history && _index + 1 < _history->_overview[OverviewPhotos].size()) ||
|
2014-08-11 09:03:45 +00:00
|
|
|
(_user && (_index + 1 < _user->photos.size() || _index + 1 < _user->photosCount))));
|
|
|
|
updateOver(mapFromGlobal(QCursor::pos()));
|
2014-10-17 12:57:14 +00:00
|
|
|
updatePolaroid();
|
2014-08-11 09:03:45 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MediaView::animStep(float64 msp) {
|
|
|
|
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;
|
|
|
|
default: break;
|
|
|
|
}
|
2014-10-17 12:57:14 +00:00
|
|
|
float64 dt = float64(ms - start) / st::medviewOverview.duration;
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return !_animations.isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaView::~MediaView() {
|
|
|
|
delete _menu;
|
|
|
|
}
|
|
|
|
|
2014-10-17 12:57:14 +00:00
|
|
|
void MediaView::showSaveMsgFile() {
|
|
|
|
psShowInFolder(_saveMsgFilename);
|
|
|
|
}
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
void MediaView::onClose() {
|
|
|
|
if (App::wnd()) App::wnd()->layerHidden();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::onSave() {
|
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()) {
|
|
|
|
_save.hide();
|
|
|
|
return;
|
|
|
|
}
|
2014-10-17 12:57:14 +00:00
|
|
|
|
|
|
|
psBringToBack(this);
|
|
|
|
bool gotName = filedialogGetSaveFile(file, lang(lng_save_photo), qsl("JPEG Image (*.jpg);;All files (*.*)"), cur);
|
|
|
|
psShowOverAll(this);
|
|
|
|
if (gotName) {
|
2014-10-07 17:57:57 +00:00
|
|
|
if (!file.isEmpty() && file != cur) {
|
|
|
|
QFile(cur).copy(file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} 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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-17 12:57:14 +00:00
|
|
|
void MediaView::onDownload() {
|
|
|
|
if (cAskDownloadPath()) {
|
|
|
|
return onSave();
|
|
|
|
}
|
|
|
|
|
|
|
|
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()) {
|
|
|
|
_save.hide();
|
|
|
|
} 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()) {
|
|
|
|
_save.hide();
|
|
|
|
} 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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-07 17:57:57 +00:00
|
|
|
void MediaView::onShowInFolder() {
|
|
|
|
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()) {
|
|
|
|
onClose();
|
|
|
|
if (App::main()) {
|
|
|
|
App::contextItem(item);
|
|
|
|
App::main()->forwardLayer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::onDelete() {
|
|
|
|
onClose();
|
|
|
|
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() {
|
|
|
|
onClose();
|
|
|
|
if (_history->peer) App::main()->showMediaOverview(_history->peer, OverviewPhotos);
|
|
|
|
}
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
void MediaView::onCopy() {
|
2014-10-07 17:57:57 +00:00
|
|
|
if (_doc) {
|
|
|
|
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();
|
|
|
|
setCursor(style::cur_default);
|
|
|
|
|
|
|
|
_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) {
|
|
|
|
for (int i = 0, l = _history->_overview[OverviewPhotos].size(); i < l; ++i) {
|
|
|
|
if (_history->_overview[OverviewPhotos].at(i) == _msgid) {
|
|
|
|
_index = i;
|
|
|
|
break;
|
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
|
2014-08-21 12:18:56 +00:00
|
|
|
if (_history->_overviewCount[OverviewPhotos] < 0) {
|
|
|
|
loadPhotosBack();
|
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
showPhoto(photo);
|
|
|
|
preloadPhotos(0);
|
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;
|
2014-08-11 09:03:45 +00:00
|
|
|
if (_user) {
|
|
|
|
if (_user->photos.isEmpty() && _user->photosCount < 0 && _user->photoId) {
|
|
|
|
_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) {
|
|
|
|
loadPhotosBack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
showPhoto(photo);
|
|
|
|
preloadPhotos(0);
|
|
|
|
}
|
|
|
|
|
2014-10-10 12:46:20 +00:00
|
|
|
void MediaView::showDocument(DocumentData *doc, QPixmap pix, 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;
|
|
|
|
_msgid = context ? context->id : 0;
|
|
|
|
_index = -1;
|
|
|
|
_loadRequest = 0;
|
|
|
|
_over = OverNone;
|
|
|
|
_pressed = false;
|
|
|
|
_dragging = 0;
|
|
|
|
setCursor(style::cur_default);
|
|
|
|
if (!_animations.isEmpty()) {
|
|
|
|
_animations.clear();
|
|
|
|
anim::stop(this);
|
|
|
|
}
|
|
|
|
if (!_animOpacities.isEmpty()) _animOpacities.clear();
|
|
|
|
|
2014-10-10 12:46:20 +00:00
|
|
|
_current = pix;
|
2014-10-07 17:57:57 +00:00
|
|
|
_current.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
_doc = doc;
|
|
|
|
_down = OverNone;
|
|
|
|
if (isHidden()) {
|
|
|
|
moveToScreen();
|
|
|
|
}
|
|
|
|
_w = _current.width() / cIntRetinaFactor();
|
|
|
|
_h = _current.height() / cIntRetinaFactor();
|
|
|
|
_width = _w;
|
2014-12-15 15:55:45 +00:00
|
|
|
if (_w > 0 && _h > 0) {
|
|
|
|
_zoomToScreen = float64(_avail.width()) / _w;
|
|
|
|
if (_h * _zoomToScreen > (_avail.height() - st::medviewBottomBar)) {
|
|
|
|
_zoomToScreen = float64(_avail.height() - st::medviewBottomBar) / _h;
|
|
|
|
}
|
|
|
|
if (_zoomToScreen >= 1.) {
|
|
|
|
_zoomToScreen -= 1.;
|
|
|
|
} else {
|
|
|
|
_zoomToScreen = 1. - (1. / _zoomToScreen);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_zoomToScreen = 0;
|
|
|
|
}
|
|
|
|
if ((_w > _avail.width()) || (_h > (_avail.height() - st::medviewBottomBar))) {
|
|
|
|
_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 = (_avail.width() - _w) / 2;
|
|
|
|
_y = (_avail.height() - st::medviewBottomBar - _h) / 2;
|
2014-10-07 17:57:57 +00:00
|
|
|
_from = App::user(_doc->user);
|
|
|
|
_full = 1;
|
|
|
|
updateControls();
|
|
|
|
if (isHidden()) {
|
|
|
|
psUpdateOverlayed(this);
|
|
|
|
show();
|
2014-10-17 12:57:14 +00:00
|
|
|
psShowOverAll(this);
|
2014-10-07 17:57:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
void MediaView::showPhoto(PhotoData *photo) {
|
2014-08-06 14:40:21 +00:00
|
|
|
_photo = photo;
|
2014-10-07 17:57:57 +00:00
|
|
|
_doc = 0;
|
|
|
|
_zoom = 0;
|
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();
|
|
|
|
_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();
|
|
|
|
}
|
2014-08-06 14:40:21 +00:00
|
|
|
if (_w > _maxWidth) {
|
2014-10-07 17:57:57 +00:00
|
|
|
_h = qRound(_h * _maxWidth / float64(_w));
|
2014-08-06 14:40:21 +00:00
|
|
|
_w = _maxWidth;
|
|
|
|
}
|
2014-10-07 17:57:57 +00:00
|
|
|
if (_h > _maxHeight) {
|
|
|
|
_w = qRound(_w * _maxHeight / float64(_h));
|
|
|
|
_h = _maxHeight;
|
2014-08-06 14:40:21 +00:00
|
|
|
}
|
2014-10-17 12:57:14 +00:00
|
|
|
_x = (_avail.width() - _w) / 2;
|
|
|
|
_y = st::medviewPolaroid.top() + (_avail.height() - st::medviewPolaroid.top() - st::medviewPolaroid.bottom() - st::medviewBottomBar - _h) / 2;
|
2014-10-07 17:57:57 +00:00
|
|
|
_width = _w;
|
2014-08-11 09:03:45 +00:00
|
|
|
_from = App::user(_photo->user);
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::paintEvent(QPaintEvent *e) {
|
|
|
|
QPainter p(this);
|
2014-08-11 09:03:45 +00:00
|
|
|
QRect r(e->rect());
|
|
|
|
|
2014-08-11 09:06:16 +00:00
|
|
|
QPainter::CompositionMode m = p.compositionMode();
|
|
|
|
p.setCompositionMode(QPainter::CompositionMode_Source);
|
2014-08-11 09:16:47 +00:00
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
// main bg
|
2014-10-17 12:57:14 +00:00
|
|
|
QRect r_bg(st::medviewNavBarWidth, 0, _avail.width() - 2 * st::medviewNavBarWidth, _avail.height() - st::medviewBottomBar);
|
|
|
|
if (r_bg.intersects(r)) p.fillRect(r_bg.intersected(r), st::medviewBG->b);
|
|
|
|
if (_bottomBar.intersects(r)) p.fillRect(_bottomBar.intersected(r), st::medviewBottomBG->b);
|
2014-08-11 09:03:45 +00:00
|
|
|
|
2014-08-11 09:16:47 +00:00
|
|
|
// left nav bar bg
|
|
|
|
if (_leftNav.intersects(r)) {
|
|
|
|
if (_leftNavVisible) {
|
2014-10-17 12:57:14 +00:00
|
|
|
p.fillRect(_leftNav.intersected(r), overColor(st::medviewBG->c, 1, st::black->c, overLevel(OverLeftNav) * st::medviewNavBGOpacity));
|
2014-08-11 09:16:47 +00:00
|
|
|
} else {
|
2014-10-17 12:57:14 +00:00
|
|
|
p.fillRect(_leftNav.intersected(r), st::medviewBG->c);
|
2014-08-11 09:16:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// right nav bar
|
|
|
|
if (_rightNav.intersects(r)) {
|
|
|
|
if (_rightNavVisible) {
|
2014-10-17 12:57:14 +00:00
|
|
|
p.fillRect(_rightNav.intersected(r), overColor(st::medviewBG->c, 1, st::black->c, overLevel(OverRightNav) * st::medviewNavBGOpacity));
|
2014-08-11 09:16:47 +00:00
|
|
|
float64 o = overLevel(OverRightNav);
|
|
|
|
} else {
|
2014-10-17 12:57:14 +00:00
|
|
|
p.fillRect(_rightNav.intersected(r), st::medviewBG->b);
|
2014-08-11 09:16:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-11 09:06:16 +00:00
|
|
|
p.setCompositionMode(m);
|
2014-08-06 14:40:21 +00:00
|
|
|
p.setOpacity(1);
|
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);
|
|
|
|
_current = _photo->medium->pixBlurredNoCache(w, h);
|
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);
|
|
|
|
_current = _photo->thumb->pixBlurredNoCache(w, h);
|
2014-10-07 17:57:57 +00:00
|
|
|
if (cRetina()) _current.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_photo || !_current.isNull()) {
|
|
|
|
QRect imgRect(_x, _y, _w, _h);
|
|
|
|
if (imgRect.intersects(r)) {
|
2014-12-15 15:55:45 +00:00
|
|
|
if (_current.hasAlpha()) {
|
|
|
|
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);
|
2014-10-07 17:57:57 +00:00
|
|
|
p.drawPixmap(QRect(_x, _y, _w, _h), _current);
|
|
|
|
if (!was) p.setRenderHint(QPainter::SmoothPixmapTransform, false);
|
|
|
|
} else {
|
|
|
|
p.drawPixmap(_x, _y, _current);
|
|
|
|
}
|
2014-10-17 12:57:14 +00:00
|
|
|
}
|
2014-12-15 15:55:45 +00:00
|
|
|
if (!_doc && _polaroidOut.intersects(r)) {
|
2014-10-17 12:57:14 +00:00
|
|
|
// polaroid
|
|
|
|
p.fillRect(_polaroidOut.x(), _polaroidOut.y(), _polaroidIn.x() - _polaroidOut.x(), _polaroidOut.height(), st::white->b);
|
|
|
|
p.fillRect(_polaroidIn.x() + _polaroidIn.width(), _polaroidOut.y(), _polaroidOut.x() + _polaroidOut.width() - _polaroidIn.x() - _polaroidIn.width(), _polaroidOut.height(), st::white->b);
|
|
|
|
p.fillRect(_polaroidIn.x(), _polaroidOut.y(), _polaroidIn.width(), _polaroidIn.y() - _polaroidOut.y(), st::white->b);
|
|
|
|
p.fillRect(_polaroidIn.x(), _polaroidIn.y() + _polaroidIn.height(), _polaroidIn.width(), _polaroidOut.y() + _polaroidOut.height() - _polaroidIn.y() - _polaroidIn.height(), st::white->b);
|
|
|
|
}
|
|
|
|
if (imgRect.intersects(r)) {
|
|
|
|
uint64 ms = 0;
|
2014-12-15 15:55:45 +00:00
|
|
|
if (!_doc && imgRect.intersects(_leftNav)) {
|
2014-10-17 12:57:14 +00:00
|
|
|
p.fillRect(imgRect.intersected(_leftNav), _leftNavVisible ? overColor(st::medviewBG->c, 1, st::black->c, overLevel(OverLeftNav) * st::medviewNavBGOpacity) : st::medviewBG->c);
|
2014-10-07 17:57:57 +00:00
|
|
|
}
|
2014-12-15 15:55:45 +00:00
|
|
|
if (!_doc && imgRect.intersects(_rightNav)) {
|
2014-10-17 12:57:14 +00:00
|
|
|
p.fillRect(imgRect.intersected(_rightNav), _rightNavVisible ? overColor(st::medviewBG->c, 1, st::black->c, overLevel(OverRightNav) * st::medviewNavBGOpacity) : st::medviewBG->c);
|
2014-10-07 17:57:57 +00:00
|
|
|
}
|
2014-10-17 12:57:14 +00:00
|
|
|
if (imgRect.intersects(_bottomBar)) {
|
|
|
|
p.fillRect(imgRect.intersected(_bottomBar), st::medviewBG->b);
|
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);
|
|
|
|
|
2014-10-17 12:57:14 +00:00
|
|
|
int32 x = (_avail.width() - st::mediaviewLoader.width()) / 2;
|
|
|
|
int32 y = st::medviewPolaroid.top() + (_availBottom - st::medviewPolaroid.top() - st::medviewPolaroid.bottom() - 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());
|
|
|
|
p.setBrush(st::medviewSaveMsg->b);
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.drawRoundedRect(_saveMsg, st::medviewSaveMsgRadius, st::medviewSaveMsgRadius);
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
|
2014-10-17 12:57:14 +00:00
|
|
|
// disabled download button
|
|
|
|
if (_save.isHidden()) {
|
|
|
|
p.fillRect(_save.geometry(), st::medviewSaveAs.bgColor->b);
|
|
|
|
p.setOpacity(st::medviewSaveAsDisabledOpacity);
|
|
|
|
p.setPen(st::medviewSaveAs.color->p);
|
|
|
|
p.setFont(st::medviewSaveAs.font->f);
|
|
|
|
p.drawPixmap(_save.geometry().topLeft() + st::medviewSaveAs.iconPos, App::sprite(), st::medviewSaveAs.icon);
|
|
|
|
p.drawText(_save.geometry().topLeft() + st::medviewSaveAs.textPos + QPoint(0, st::medviewSaveAs.font->ascent), lang(lng_mediaview_save));
|
|
|
|
p.setOpacity(1);
|
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
|
2014-10-17 12:57:14 +00:00
|
|
|
// left nav arrow
|
2014-08-11 09:03:45 +00:00
|
|
|
if (_leftNavVisible) {
|
2014-10-17 12:57:14 +00:00
|
|
|
QPoint p_left((st::medviewNavBarWidth - st::medviewLeft.pxWidth()) / 2, (height() - st::medviewBottomBar - st::medviewLeft.pxHeight()) / 2);
|
2014-08-11 09:03:45 +00:00
|
|
|
if (QRect(p_left.x(), p_left.y(), st::medviewLeft.pxWidth(), st::medviewLeft.pxHeight()).intersects(r)) {
|
2014-08-11 09:16:47 +00:00
|
|
|
float64 o = overLevel(OverLeftNav);
|
|
|
|
p.setOpacity(o * st::medviewDarkNav + (1 - o) * st::medviewLightNav);
|
2014-08-11 09:03:45 +00:00
|
|
|
p.drawPixmap(p_left, App::sprite(), st::medviewLeft);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-17 12:57:14 +00:00
|
|
|
// right nav arrow
|
2014-08-11 09:03:45 +00:00
|
|
|
if (_rightNavVisible) {
|
2014-10-17 12:57:14 +00:00
|
|
|
QPoint p_right(width() - (st::medviewNavBarWidth + st::medviewRight.pxWidth()) / 2, (height() - st::medviewBottomBar - st::medviewRight.pxHeight()) / 2);
|
2014-08-11 09:03:45 +00:00
|
|
|
if (QRect(p_right.x(), p_right.y(), st::medviewRight.pxWidth(), st::medviewRight.pxHeight()).intersects(r)) {
|
2014-08-11 09:16:47 +00:00
|
|
|
float64 o = overLevel(OverRightNav);
|
|
|
|
p.setOpacity(o * st::medviewDarkNav + (1 - o) * st::medviewLightNav);
|
2014-08-11 09:03:45 +00:00
|
|
|
p.drawPixmap(p_right, App::sprite(), st::medviewRight);
|
|
|
|
}
|
|
|
|
}
|
2014-08-06 14:40:21 +00:00
|
|
|
p.setOpacity(1);
|
2014-10-07 17:57:57 +00:00
|
|
|
|
|
|
|
// header
|
2014-10-17 12:57:14 +00:00
|
|
|
if (_overview.isHidden()) {
|
|
|
|
QRect r_header(_overview.x(), _overview.y(), st::medviewHeaderFont->m.width(_header) - st::medviewOverview.width, _overview.height());
|
|
|
|
if (r_header.intersects(r)) {
|
|
|
|
p.setOpacity(st::medviewOverview.opacity);
|
|
|
|
p.setPen(st::medviewOverview.color->p);
|
|
|
|
p.setFont(st::medviewOverview.font->f);
|
|
|
|
p.drawPixmap(_overview.geometry().topLeft() + (_photo ? st::medviewPhotoSpritePos : st::medviewDocumentSpritePos), App::sprite(), _photo ? st::medviewPhotoSprite : st::medviewDocumentSprite);
|
|
|
|
p.drawText(r_header.topLeft() + st::medviewOverview.textPos + QPoint(0, st::medviewHeaderFont->ascent), _header);
|
|
|
|
p.setOpacity(1);
|
|
|
|
}
|
|
|
|
}
|
2014-10-07 17:57:57 +00:00
|
|
|
|
|
|
|
// name
|
2014-12-15 15:55:45 +00:00
|
|
|
if (_doc) {
|
|
|
|
float64 o = overLevel(OverName);
|
|
|
|
p.setOpacity(st::medviewOverview.overOpacity * o + st::medviewOverview.opacity * (1 - o));
|
|
|
|
p.setPen(st::white->p);
|
|
|
|
} else {
|
|
|
|
p.setPen(st::medviewNameColor->p);
|
|
|
|
}
|
2014-10-17 12:57:14 +00:00
|
|
|
if (_over == OverName) _fromName.replaceFont(st::medviewNameFont->underline());
|
|
|
|
if (_nameNav.intersects(r)) _fromName.drawElided(p, _nameNav.left(), _nameNav.top(), _nameNav.width());
|
|
|
|
if (_over == OverName) _fromName.replaceFont(st::medviewNameFont);
|
2014-10-07 17:57:57 +00:00
|
|
|
|
|
|
|
// date
|
2014-12-15 15:55:45 +00:00
|
|
|
if (_doc) {
|
|
|
|
float64 o = overLevel(OverDate);
|
|
|
|
p.setOpacity(st::medviewOverview.overOpacity * o + st::medviewOverview.opacity * (1 - o));
|
|
|
|
p.setPen(st::white->p);
|
|
|
|
} else {
|
|
|
|
p.setPen(st::medviewDateColor->p);
|
|
|
|
}
|
2014-10-07 17:57:57 +00:00
|
|
|
p.setFont((_over == OverDate ? st::medviewDateFont->underline() : st::medviewDateFont)->f);
|
|
|
|
if (_dateNav.intersects(r)) p.drawText(_dateNav.left(), _dateNav.top() + st::medviewDateFont->ascent, _dateText);
|
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) {
|
|
|
|
onClose();
|
|
|
|
} else if (e == QKeySequence::Save || e == QKeySequence::SaveAs) {
|
|
|
|
onSave();
|
|
|
|
} else if (e->key() == Qt::Key_Copy || (e->key() == Qt::Key_C && e->modifiers().testFlag(Qt::ControlModifier))) {
|
|
|
|
onCopy();
|
|
|
|
} else if (e->key() == Qt::Key_Left) {
|
|
|
|
moveToPhoto(-1);
|
|
|
|
} else if (e->key() == Qt::Key_Right) {
|
|
|
|
moveToPhoto(1);
|
2014-10-07 17:57:57 +00:00
|
|
|
} else if (e->modifiers().testFlag(Qt::ControlModifier) && (e->key() == Qt::Key_Plus || e->key() == Qt::Key_Equal || e->key() == Qt::Key_Minus || e->key() == Qt::Key_Underscore || e->key() == Qt::Key_0)) {
|
|
|
|
int32 newZoom = _zoom;
|
|
|
|
if (e->key() == Qt::Key_Plus || e->key() == Qt::Key_Equal) {
|
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;
|
2014-12-15 15:55:45 +00:00
|
|
|
_y = (_doc ? 0 : st::medviewPolaroid.top()) - ((_current.height() / cIntRetinaFactor()) / 2);
|
|
|
|
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
|
|
|
}
|
|
|
|
_x += _avail.width() / 2;
|
2014-12-15 15:55:45 +00:00
|
|
|
_y += (_avail.height() - st::medviewBottomBar - (_doc ? 0 : (st::medviewPolaroid.top() + st::medviewPolaroid.bottom()))) / 2;
|
2014-10-17 12:57:14 +00:00
|
|
|
updatePolaroid();
|
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;
|
2014-10-07 17:57:57 +00:00
|
|
|
_w = _current.width() / cIntRetinaFactor();
|
|
|
|
_h = _current.height() / cIntRetinaFactor();
|
2014-12-15 15:55:45 +00:00
|
|
|
if (z >= 0) {
|
|
|
|
nx = (_x - _avail.width() / 2.) / (z + 1);
|
|
|
|
ny = (_y - _avail.height() / 2.) / (z + 1);
|
2014-10-07 17:57:57 +00:00
|
|
|
} else {
|
2014-12-15 15:55:45 +00:00
|
|
|
nx = (_x - _avail.width() / 2.) * (-z + 1);
|
|
|
|
ny = (_y - _avail.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));
|
|
|
|
_x = qRound(nx * (z + 1) + _avail.width() / 2.);
|
|
|
|
_y = qRound(ny * (z + 1) + _avail.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));
|
|
|
|
_x = qRound(nx / (-z + 1) + _avail.width() / 2.);
|
|
|
|
_y = qRound(ny / (-z + 1) + _avail.height() / 2.);
|
2014-10-07 17:57:57 +00:00
|
|
|
}
|
|
|
|
snapXY();
|
|
|
|
update();
|
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::moveToPhoto(int32 delta) {
|
2014-10-07 17:57:57 +00:00
|
|
|
if (_index < 0 || !_photo) return;
|
2014-08-11 09:03:45 +00:00
|
|
|
|
|
|
|
int32 newIndex = _index + delta;
|
|
|
|
if (_history) {
|
2014-08-15 11:19:32 +00:00
|
|
|
if (newIndex >= 0 && newIndex < _history->_overview[OverviewPhotos].size()) {
|
2014-08-11 09:03:45 +00:00
|
|
|
_index = newIndex;
|
2014-08-15 11:19:32 +00:00
|
|
|
if (HistoryItem *item = App::histItemById(_history->_overview[OverviewPhotos][_index])) {
|
2014-08-11 09:03:45 +00:00
|
|
|
_msgid = item->id;
|
|
|
|
HistoryPhoto *photo = dynamic_cast<HistoryPhoto*>(item->getMedia());
|
|
|
|
if (photo) {
|
|
|
|
showPhoto(photo->photo());
|
|
|
|
preloadPhotos(delta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (delta < 0 && _index < MediaOverviewStartPerPage) {
|
|
|
|
loadPhotosBack();
|
|
|
|
}
|
|
|
|
} else if (_user) {
|
|
|
|
if (newIndex >= 0 && newIndex < _user->photos.size()) {
|
|
|
|
_index = newIndex;
|
|
|
|
showPhoto(_user->photos[_index]);
|
|
|
|
preloadPhotos(delta);
|
|
|
|
}
|
|
|
|
if (delta > 0 && _index > _user->photos.size() - MediaOverviewStartPerPage) {
|
|
|
|
loadPhotosBack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::preloadPhotos(int32 delta) {
|
2014-10-07 17:57:57 +00:00
|
|
|
if (_index < 0 || !_photo) 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);
|
|
|
|
if (_history) {
|
|
|
|
for (int32 i = from; i <= to; ++i) {
|
2014-08-15 11:19:32 +00:00
|
|
|
if (i >= 0 && i < _history->_overview[OverviewPhotos].size() && i != _index) {
|
|
|
|
if (HistoryItem *item = App::histItemById(_history->_overview[OverviewPhotos][i])) {
|
2014-08-11 09:03:45 +00:00
|
|
|
HistoryPhoto *photo = dynamic_cast<HistoryPhoto*>(item->getMedia());
|
|
|
|
if (photo) {
|
|
|
|
photo->photo()->full->load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-15 11:19:32 +00:00
|
|
|
if (forget >= 0 && forget < _history->_overview[OverviewPhotos].size() && forget != _index) {
|
|
|
|
if (HistoryItem *item = App::histItemById(_history->_overview[OverviewPhotos][forget])) {
|
|
|
|
HistoryMedia *media = item->getMedia();
|
|
|
|
if (media && media->type() == MediaTypePhoto) {
|
|
|
|
static_cast<HistoryPhoto*>(media)->photo()->forget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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;
|
2014-10-17 12:57:14 +00:00
|
|
|
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) {
|
|
|
|
moveToPhoto(-1);
|
|
|
|
_lastAction = e->pos();
|
|
|
|
} else if (_over == OverRightNav && _index >= 0) {
|
|
|
|
moveToPhoto(1);
|
|
|
|
_lastAction = e->pos();
|
|
|
|
} else if (_over == OverName) {
|
|
|
|
_down = OverName;
|
|
|
|
} else if (_over == OverDate) {
|
|
|
|
_down = OverDate;
|
|
|
|
} else if (!_bottomBar.contains(e->pos()) && (!_saveMsg.contains(e->pos()) || !_saveMsgStarted)) {
|
|
|
|
_pressed = true;
|
|
|
|
_dragging = 0;
|
|
|
|
setCursor(style::cur_default);
|
|
|
|
_mStart = e->pos();
|
|
|
|
_xStart = _x;
|
|
|
|
_yStart = _y;
|
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-07 17:57:57 +00:00
|
|
|
void MediaView::snapXY() {
|
2014-12-15 15:55:45 +00:00
|
|
|
int32 xmin = _avail.width() - _w - (_doc ? 0 : (st::medviewNavBarWidth + st::medviewPolaroid.right())), xmax = _doc ? 0 : (st::medviewPolaroid.left() + st::medviewNavBarWidth);
|
|
|
|
int32 ymin = _avail.height() - _h - (_doc ? 0 : st::medviewPolaroid.bottom()) - st::medviewBottomBar, ymax = (_doc ? 0 : st::medviewPolaroid.top());
|
2014-10-17 12:57:14 +00:00
|
|
|
if (xmin > (_avail.width() - _w) / 2) xmin = (_avail.width() - _w) / 2;
|
|
|
|
if (xmax < (_avail.width() - _w) / 2) xmax = (_avail.width() - _w) / 2;
|
2014-12-15 15:55:45 +00:00
|
|
|
if (ymin > (_avail.height() - _h - st::medviewBottomBar - (_doc ? 0 : (st::medviewPolaroid.bottom() - st::medviewPolaroid.top()))) / 2) ymin = (_avail.height() - _h - st::medviewBottomBar - (_doc ? 0 : (st::medviewPolaroid.bottom() - st::medviewPolaroid.top()))) / 2;
|
|
|
|
if (ymax < (_avail.height() - _h - st::medviewBottomBar - (_doc ? 0 : (st::medviewPolaroid.bottom() - st::medviewPolaroid.top()))) / 2) ymax = (_avail.height() - _h - st::medviewBottomBar - (_doc ? 0 : (st::medviewPolaroid.bottom() - st::medviewPolaroid.top()))) / 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-10-17 12:57:14 +00:00
|
|
|
updatePolaroid();
|
2014-10-07 17:57:57 +00:00
|
|
|
}
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
void MediaView::mouseMoveEvent(QMouseEvent *e) {
|
|
|
|
updateOver(e->pos());
|
|
|
|
if (_lastAction.x() >= 0 && (e->pos() - _lastAction).manhattanLength() >= st::medviewDeltaFromLastAction) {
|
|
|
|
_lastAction = QPoint(-st::medviewDeltaFromLastAction, -st::medviewDeltaFromLastAction);
|
|
|
|
}
|
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) {
|
2014-12-15 15:55:45 +00:00
|
|
|
if (_w > _avail.width() - (_doc ? 0 : (2 * st::medviewNavBarWidth + st::medviewPolaroid.left() + st::medviewPolaroid.right())) || _h > _avail.height() - (_doc ? 0 : (st::medviewPolaroid.top() + st::medviewPolaroid.bottom())) - st::medviewBottomBar) {
|
2014-10-07 17:57:57 +00:00
|
|
|
setCursor(style::cur_sizeall);
|
|
|
|
} else {
|
|
|
|
setCursor(style::cur_default);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_dragging > 0) {
|
|
|
|
_x = _xStart + (e->pos() - _mStart).x();
|
|
|
|
_y = _yStart + (e->pos() - _mStart).y();
|
|
|
|
snapXY();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MediaView::updateOverState(OverState newState) {
|
|
|
|
bool result = true;
|
|
|
|
if (_over != newState) {
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
anim::start(this);
|
|
|
|
if (newState != OverNone) update();
|
|
|
|
} 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));
|
|
|
|
}
|
|
|
|
anim::start(this);
|
|
|
|
setCursor(style::cur_pointer);
|
|
|
|
} else {
|
|
|
|
setCursor(style::cur_default);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::updateOver(const QPoint &pos) {
|
2014-10-17 12:57:14 +00:00
|
|
|
TextLinkPtr lnk;
|
|
|
|
bool inText;
|
2014-10-17 13:24:17 +00:00
|
|
|
if (_saveMsgStarted) {
|
|
|
|
_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());
|
|
|
|
}
|
2014-10-17 12:57:14 +00:00
|
|
|
if (lnk != textlnkOver()) {
|
|
|
|
textlnkOver(lnk);
|
|
|
|
setCursor((textlnkOver() || textlnkDown()) ? style::cur_pointer : style::cur_default);
|
|
|
|
updateImage();
|
|
|
|
}
|
|
|
|
|
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)) {
|
|
|
|
if (!updateOverState(OverLeftNav)) {
|
|
|
|
update(_leftNav);
|
|
|
|
}
|
|
|
|
} else if (_rightNavVisible && _rightNav.contains(pos)) {
|
|
|
|
if (!updateOverState(OverRightNav)) {
|
|
|
|
update(_rightNav);
|
|
|
|
}
|
|
|
|
} else if (_nameNav.contains(pos)) {
|
|
|
|
if (!updateOverState(OverName)) {
|
|
|
|
update(_nameNav);
|
|
|
|
}
|
|
|
|
} else if (_msgid && _dateNav.contains(pos)) {
|
|
|
|
if (!updateOverState(OverDate)) {
|
|
|
|
update(_dateNav);
|
|
|
|
}
|
|
|
|
} else if (_over != OverNone) {
|
|
|
|
if (_over == OverLeftNav) {
|
|
|
|
update(_leftNav);
|
|
|
|
} else if (_over == OverRightNav) {
|
|
|
|
update(_rightNav);
|
|
|
|
} else if (_over == OverName) {
|
|
|
|
update(_nameNav);
|
|
|
|
} else if (_over == OverDate) {
|
|
|
|
update(_dateNav);
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
if (App::wnd()) {
|
|
|
|
onClose();
|
|
|
|
if (App::main()) App::main()->showPeerProfile(_from);
|
|
|
|
}
|
|
|
|
} else if (_over == OverDate && _down == OverDate && _msgid) {
|
|
|
|
HistoryItem *item = App::histItemById(_msgid);
|
|
|
|
if (item) {
|
|
|
|
if (App::wnd()) {
|
|
|
|
onClose();
|
|
|
|
if (App::main()) App::main()->showPeer(item->history()->peer->id, _msgid, false, true);
|
|
|
|
}
|
|
|
|
}
|
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);
|
|
|
|
} else if ((e->pos() - _lastAction).manhattanLength() >= st::medviewDeltaFromLastAction) {
|
|
|
|
onClose();
|
|
|
|
}
|
|
|
|
_pressed = false;
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
_down = OverNone;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::contextMenuEvent(QContextMenuEvent *e) {
|
2014-10-07 17:57:57 +00:00
|
|
|
if (_photo && _photo->full->loaded() && (e->reason() != QContextMenuEvent::Mouse || QRect(_x, _y, _w, _h).contains(e->pos()))) {
|
2014-08-11 09:03:45 +00:00
|
|
|
if (_menu) {
|
|
|
|
_menu->deleteLater();
|
|
|
|
_menu = 0;
|
|
|
|
}
|
2014-09-29 02:47:30 +00:00
|
|
|
_menu = new ContextMenu(this);
|
2014-08-11 09:03:45 +00:00
|
|
|
_menu->addAction(lang(lng_context_save_image), this, SLOT(onSave()))->setEnabled(true);
|
|
|
|
_menu->addAction(lang(lng_context_copy_image), this, SLOT(onCopy()))->setEnabled(true);
|
|
|
|
_menu->addAction(lang(lng_context_close_image), this, SLOT(onClose()))->setEnabled(true);
|
|
|
|
if (_msgid) {
|
|
|
|
_menu->addAction(lang(lng_context_forward_image), this, SLOT(onForward()))->setEnabled(true);
|
|
|
|
_menu->addAction(lang(lng_context_delete_image), this, SLOT(onDelete()))->setEnabled(true);
|
|
|
|
} else if ((App::self() && App::self()->photoId == _photo->id) || (_photo->chat && _photo->chat->photoId == _photo->id)) {
|
|
|
|
_menu->addAction(lang(lng_context_delete_image), this, SLOT(onDelete()))->setEnabled(true);
|
|
|
|
}
|
2014-09-29 02:47:30 +00:00
|
|
|
_menu->deleteOnHide();
|
2014-08-11 09:03:45 +00:00
|
|
|
connect(_menu, SIGNAL(destroyed(QObject*)), this, SLOT(onMenuDestroy(QObject*)));
|
|
|
|
_menu->popup(e->globalPos());
|
|
|
|
e->accept();
|
2014-10-07 17:57:57 +00:00
|
|
|
} else if (_doc && (e->reason() != QContextMenuEvent::Mouse || QRect(_x, _y, _w, _h).contains(e->pos()))) {
|
|
|
|
if (_menu) {
|
|
|
|
_menu->deleteLater();
|
|
|
|
_menu = 0;
|
|
|
|
}
|
|
|
|
_menu = new ContextMenu(this);
|
|
|
|
if (!_doc->already(true).isEmpty()) {
|
|
|
|
_menu->addAction(lang(cPlatform() == dbipMac ? lng_context_show_in_finder : lng_context_show_in_folder), this, SLOT(onShowInFolder()))->setEnabled(true);
|
|
|
|
}
|
|
|
|
_menu->addAction(lang(lng_context_save_document), this, SLOT(onSave()))->setEnabled(true);
|
|
|
|
_menu->addAction(lang(lng_context_close_file), this, SLOT(onClose()))->setEnabled(true);
|
|
|
|
if (_msgid) {
|
|
|
|
_menu->addAction(lang(lng_context_forward_file), this, SLOT(onForward()))->setEnabled(true);
|
|
|
|
_menu->addAction(lang(lng_context_delete_file), this, SLOT(onDelete()))->setEnabled(true);
|
|
|
|
}
|
|
|
|
_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);
|
|
|
|
if (d.x() * d.x() > d.y() * d.y() && (d.x() > st::medviewSwipeDistance || d.x() < -st::medviewSwipeDistance)) {
|
2014-08-11 09:49:18 +00:00
|
|
|
moveToPhoto(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
|
|
|
}
|
|
|
|
}
|
|
|
|
return QWidget::event(e);
|
|
|
|
}
|
|
|
|
|
2014-08-15 11:19:32 +00:00
|
|
|
void MediaView::hide() {
|
2014-08-15 11:53:58 +00:00
|
|
|
QWidget::hide();
|
2014-08-15 11:19:32 +00:00
|
|
|
_close.clearState();
|
|
|
|
_save.clearState();
|
|
|
|
_forward.clearState();
|
|
|
|
_delete.clearState();
|
2014-10-17 12:57:14 +00:00
|
|
|
_overview.clearState();
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
void MediaView::loadPhotosBack() {
|
2014-10-07 17:57:57 +00:00
|
|
|
if (_loadRequest || _index < 0 || !_photo) return;
|
2014-08-11 09:03:45 +00:00
|
|
|
|
2014-08-15 11:19:32 +00:00
|
|
|
if (_history && _history->_overviewCount[OverviewPhotos] != 0) {
|
|
|
|
if (App::main()) App::main()->loadMediaBack(_history->peer, OverviewPhotos);
|
2014-08-11 09:03:45 +00:00
|
|
|
} else if (_user && _user->photosCount != 0) {
|
|
|
|
int32 limit = (_index < MediaOverviewStartPerPage && _user->photos.size() > MediaOverviewStartPerPage) ? SearchPerPage : MediaOverviewStartPerPage;
|
|
|
|
_loadRequest = MTP::send(MTPphotos_GetUserPhotos(_user->inputUser, MTP_int(_user->photos.size()), MTP_int(0), MTP_int(limit)), rpcDone(&MediaView::userPhotosLoaded, _user));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
if (App::wnd()) App::wnd()->mediaOverviewUpdated(u);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaView::updateHeader() {
|
2014-10-07 17:57:57 +00:00
|
|
|
if (!_photo) {
|
2014-10-17 12:57:14 +00:00
|
|
|
_header = _doc ? _doc->name : QString();
|
|
|
|
if (_header.isEmpty()) _header = lang(lng_mediaview_doc_image);
|
|
|
|
if (!_overview.isHidden()) _overview.hide();
|
2014-10-07 17:57:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-11 09:03:45 +00:00
|
|
|
int32 index = _index, count = 0;
|
|
|
|
if (_history) {
|
2014-08-15 11:19:32 +00:00
|
|
|
count = _history->_overviewCount[OverviewPhotos] ? _history->_overviewCount[OverviewPhotos] : _history->_overview[OverviewPhotos].size();
|
|
|
|
if (index >= 0) index += count - _history->_overview[OverviewPhotos].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) {
|
|
|
|
_header = lang(lng_mediaview_n_of_count).replace(qsl("{n}"), QString::number(index + 1)).replace(qsl("{count}"), QString::number(count));
|
2014-10-17 12:57:14 +00:00
|
|
|
_overview.setText(_header);
|
|
|
|
if (_history) {
|
|
|
|
if (_overview.isHidden()) _overview.show();
|
|
|
|
} else {
|
|
|
|
if (!_overview.isHidden()) _overview.hide();
|
|
|
|
}
|
2014-08-11 09:03:45 +00:00
|
|
|
} else if (_user) {
|
|
|
|
_header = lang(lng_mediaview_profile_photo);
|
2014-10-17 12:57:14 +00:00
|
|
|
if (!_overview.isHidden()) _overview.hide();
|
2014-08-11 09:03:45 +00:00
|
|
|
} else if (_peer) {
|
|
|
|
_header = lang(lng_mediaview_group_photo);
|
2014-10-17 12:57:14 +00:00
|
|
|
if (!_overview.isHidden()) _overview.hide();
|
2014-08-11 09:03:45 +00:00
|
|
|
} else {
|
|
|
|
_header = lang(lng_mediaview_single_photo);
|
2014-10-17 12:57:14 +00:00
|
|
|
if (!_overview.isHidden()) _overview.hide();
|
2014-08-11 09:03:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-17 12:57:14 +00:00
|
|
|
void MediaView::updatePolaroid() {
|
2014-12-15 15:55:45 +00:00
|
|
|
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;
|
2014-10-17 12:57:14 +00:00
|
|
|
|
2014-12-15 15:55:45 +00:00
|
|
|
int32 nameWidth = _fromName.maxWidth(), maxWidth = width() - 2 * minus1, dateWidth = st::medviewDateFont->m.width(_dateText);
|
|
|
|
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 {
|
|
|
|
int32 pminw = qMin(st::medviewPolaroidMin.width(), int(_avail.width() - 2 * st::medviewNavBarWidth));
|
2014-10-17 12:57:14 +00:00
|
|
|
|
2014-12-15 15:55:45 +00:00
|
|
|
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;
|
2014-10-17 12:57:14 +00:00
|
|
|
|
2014-12-15 15:55:45 +00:00
|
|
|
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;
|
2014-10-17 12:57:14 +00:00
|
|
|
|
2014-12-15 15:55:45 +00:00
|
|
|
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);
|
2014-10-17 12:57:14 +00:00
|
|
|
|
2014-12-15 15:55:45 +00:00
|
|
|
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();
|
|
|
|
}
|