fixed gif animations for wide gifs

This commit is contained in:
John Preston 2014-10-10 17:47:39 +04:00
parent 09e2fbaa6b
commit e1adf54b36
5 changed files with 26 additions and 170 deletions

View File

@ -1175,7 +1175,9 @@ namespace App {
}
}
historyItemDetached(item);
if (App::main()) App::main()->itemRemoved(item);
if (App::main() && !App::quiting()) {
App::main()->itemRemoved(item);
}
}
void historyClearMsgs() {

View File

@ -223,7 +223,7 @@ namespace {
}
~AnimatedGif() {
stop();
stop(true);
}
HistoryItem *msg;
@ -2091,16 +2091,6 @@ TextLinkPtr HistoryPhoto::getLink(int32 x, int32 y, const HistoryItem *parent, i
return TextLinkPtr();
}
bool HistoryPhoto::getPhotoCoords(PhotoData *photo, int32 &x, int32 &y, int32 &w) const {
if (data == photo) {
w = this->w;
x = 0;
y = 0;
return true;
}
return false;
}
HistoryMedia *HistoryPhoto::clone() const {
return new HistoryPhoto(*this);
}
@ -2308,16 +2298,6 @@ TextLinkPtr HistoryVideo::getLink(int32 x, int32 y, const HistoryItem *parent, i
return TextLinkPtr();
}
bool HistoryVideo::getVideoCoords(VideoData *video, int32 &x, int32 &y, int32 &w) const {
if (data == video) {
w = this->w;
x = 0;
y = 0;
return true;
}
return false;
}
HistoryMedia *HistoryVideo::clone() const {
return new HistoryVideo(*this);
}
@ -3199,10 +3179,11 @@ void HistoryMessage::draw(QPainter &p, uint32 selection) const {
fromNameUpdated();
_fromVersion = _from->nameVersion;
}
int32 left = _out ? st::msgMargin.right() : st::msgMargin.left(), width = _history->width - st::msgMargin.left() - st::msgMargin.right();
if (width > st::msgMaxWidth) {
if (_out) left += width - st::msgMaxWidth;
width = st::msgMaxWidth;
int32 left = _out ? st::msgMargin.right() : st::msgMargin.left(), width = _history->width - st::msgMargin.left() - st::msgMargin.right(), mwidth = st::msgMaxWidth;
if (_media && _media->maxWidth() > mwidth) mwidth = _media->maxWidth();
if (width > mwidth) {
if (_out) left += width - mwidth;
width = mwidth;
}
if (!_out && _history->peer->chat) {
@ -3304,10 +3285,11 @@ int32 HistoryMessage::resize(int32 width, bool dontRecountText, const HistoryIte
}
bool HistoryMessage::hasPoint(int32 x, int32 y) const {
int32 left = _out ? st::msgMargin.right() : st::msgMargin.left(), width = _history->width - st::msgMargin.left() - st::msgMargin.right();
if (width > st::msgMaxWidth) {
if (_out) left += width - st::msgMaxWidth;
width = st::msgMaxWidth;
int32 left = _out ? st::msgMargin.right() : st::msgMargin.left(), width = _history->width - st::msgMargin.left() - st::msgMargin.right(), mwidth = st::msgMaxWidth;
if (_media && _media->maxWidth() > mwidth) mwidth = _media->maxWidth();
if (width > mwidth) {
if (_out) left += width - mwidth;
width = mwidth;
}
if (!_out && _history->peer->chat) { // from user left photo
@ -3330,10 +3312,11 @@ void HistoryMessage::getState(TextLinkPtr &lnk, bool &inText, int32 x, int32 y)
inText = false;
lnk = TextLinkPtr();
int32 left = _out ? st::msgMargin.right() : st::msgMargin.left(), width = _history->width - st::msgMargin.left() - st::msgMargin.right();
if (width > st::msgMaxWidth) {
if (_out) left += width - st::msgMaxWidth;
width = st::msgMaxWidth;
int32 left = _out ? st::msgMargin.right() : st::msgMargin.left(), width = _history->width - st::msgMargin.left() - st::msgMargin.right(), mwidth = st::msgMaxWidth;
if (_media && _media->maxWidth() > mwidth) mwidth = _media->maxWidth();
if (width > mwidth) {
if (_out) left += width - mwidth;
width = mwidth;
}
if (!_out && _history->peer->chat) { // from user left photo
@ -3370,6 +3353,7 @@ void HistoryMessage::getSymbol(uint16 &symbol, bool &after, bool &upon, int32 x,
symbol = 0;
after = false;
upon = false;
if (_media) return;
int32 left = _out ? st::msgMargin.right() : st::msgMargin.left(), width = _history->width - st::msgMargin.left() - st::msgMargin.right();
if (width > st::msgMaxWidth) {
@ -3387,9 +3371,6 @@ void HistoryMessage::getSymbol(uint16 &symbol, bool &after, bool &upon, int32 x,
if (_out) left += width - _maxw;
width = _maxw;
}
if (_media) {
return;
}
QRect r(left, st::msgMargin.top(), width, _height - st::msgMargin.top() - st::msgMargin.bottom());
if (!_out && _history->peer->chat) { // from user left name
r.setTop(r.top() + st::msgNameFont->height);
@ -3398,60 +3379,6 @@ void HistoryMessage::getSymbol(uint16 &symbol, bool &after, bool &upon, int32 x,
_text.getSymbol(symbol, after, upon, x - trect.x(), y - trect.y(), trect.width());
}
bool HistoryMessage::getPhotoCoords(PhotoData *photo, int32 &x, int32 &y, int32 &w) const {
int32 left = _out ? st::msgMargin.right() : st::msgMargin.left(), width = _history->width - st::msgMargin.left() - st::msgMargin.right();
if (width > st::msgMaxWidth) {
if (_out) left += width - st::msgMaxWidth;
width = st::msgMaxWidth;
}
if (!_out && _history->peer->chat) {
// width -= st::msgPhotoSkip;
left += st::msgPhotoSkip;
}
if (width < 1) return false;
if (width >= _maxw) {
if (_out) left += width - _maxw;
width = _maxw;
}
if (_media) {
if (_media->getPhotoCoords(photo, x, y, w)) {
x += left;
y += st::msgMargin.top();
return true;
}
}
return false;
}
bool HistoryMessage::getVideoCoords(VideoData *video, int32 &x, int32 &y, int32 &w) const {
int32 left = _out ? st::msgMargin.right() : st::msgMargin.left(), width = _history->width - st::msgMargin.left() - st::msgMargin.right();
if (width > st::msgMaxWidth) {
if (_out) left += width - st::msgMaxWidth;
width = st::msgMaxWidth;
}
if (!_out && _history->peer->chat) {
// width -= st::msgPhotoSkip;
left += st::msgPhotoSkip;
}
if (width < 1) return false;
if (width >= _maxw) {
if (_out) left += width - _maxw;
width = _maxw;
}
if (_media) {
if (_media->getVideoCoords(video, x, y, w)) {
x += left;
y += st::msgMargin.top();
return true;
}
}
return false;
}
void HistoryMessage::drawInDialog(QPainter &p, const QRect &r, bool act, const HistoryItem *&cacheFor, Text &cache) const {
if (cacheFor != this) {
cacheFor = this;
@ -3890,23 +3817,6 @@ void HistoryServiceMsg::getSymbol(uint16 &symbol, bool &after, bool &upon, int32
return _text.getSymbol(symbol, after, upon, x - trect.x(), y - trect.y(), trect.width(), Qt::AlignCenter);
}
bool HistoryServiceMsg::getPhotoCoords(PhotoData *photo, int32 &x, int32 &y, int32 &w) const {
int32 left = st::msgServiceMargin.left(), width = _history->width - st::msgServiceMargin.left() - st::msgServiceMargin.left(), height = _height - st::msgServiceMargin.top() - st::msgServiceMargin.bottom(); // two small margins
if (width < 1) return false;
if (_media) {
height -= st::msgServiceMargin.top() + _media->height();
}
if (_media) {
if (_media->getPhotoCoords(photo, x, y, w)) {
x += st::msgServiceMargin.left() + (width - _media->maxWidth()) / 2;
y += st::msgServiceMargin.top() + height + st::msgServicePadding.top();
return true;
}
}
return false;
}
void HistoryServiceMsg::drawInDialog(QPainter &p, const QRect &r, bool act, const HistoryItem *&cacheFor, Text &cache) const {
if (cacheFor != this) {
cacheFor = this;

View File

@ -1178,12 +1178,6 @@ public:
virtual uint32 adjustSelection(uint16 from, uint16 to, TextSelectType type) const {
return (from << 16) | to;
}
virtual bool getPhotoCoords(PhotoData *photo, int32 &x, int32 &y, int32 &w) const {
return false;
}
virtual bool getVideoCoords(VideoData *video, int32 &x, int32 &y, int32 &w) const {
return false;
}
virtual int32 itemType() const {
return MsgType;
}
@ -1245,12 +1239,6 @@ public:
}
virtual TextLinkPtr getLink(int32 x, int32 y, const HistoryItem *parent, int32 width = -1) const = 0;
virtual void draw(QPainter &p, const HistoryItem *parent, bool selected, int32 width = -1) const = 0;
virtual bool getPhotoCoords(PhotoData *photo, int32 &x, int32 &y, int32 &w) const {
return false;
}
virtual bool getVideoCoords(VideoData *video, int32 &x, int32 &y, int32 &w) const {
return false;
}
virtual bool uploading() const {
return false;
}
@ -1288,7 +1276,6 @@ public:
const QString inDialogsText() const;
bool hasPoint(int32 x, int32 y, const HistoryItem *parent, int32 width = -1) const;
TextLinkPtr getLink(int32 x, int32 y, const HistoryItem *parent, int32 width = -1) const;
bool getPhotoCoords(PhotoData *photo, int32 &x, int32 &y, int32 &w) const;
HistoryMedia *clone() const;
PhotoData *photo() const {
@ -1326,7 +1313,6 @@ public:
const QString inDialogsText() const;
bool hasPoint(int32 x, int32 y, const HistoryItem *parent, int32 width = -1) const;
TextLinkPtr getLink(int32 x, int32 y, const HistoryItem *parent, int32 width = -1) const;
bool getVideoCoords(VideoData *video, int32 &x, int32 &y, int32 &w) const;
bool uploading() const {
return (data->status == FileUploading);
}
@ -1475,8 +1461,6 @@ public:
uint32 adjustSelection(uint16 from, uint16 to, TextSelectType type) const {
return _text.adjustSelection(from, to, type);
}
bool getPhotoCoords(PhotoData *photo, int32 &x, int32 &y, int32 &w) const;
bool getVideoCoords(VideoData *video, int32 &x, int32 &y, int32 &w) const;
void drawInDialog(QPainter &p, const QRect &r, bool act, const HistoryItem *&cacheFor, Text &cache) const;
QString notificationHeader() const;
@ -1563,7 +1547,6 @@ public:
uint32 adjustSelection(uint16 from, uint16 to, TextSelectType type) const {
return _text.adjustSelection(from, to, type);
}
bool getPhotoCoords(PhotoData *photo, int32 &x, int32 &y, int32 &w) const;
void drawInDialog(QPainter &p, const QRect &r, bool act, const HistoryItem *&cacheFor, Text &cache) const;
QString notificationText() const;

View File

@ -463,16 +463,18 @@ void HistoryList::dragActionCancel() {
}
void HistoryList::itemRemoved(HistoryItem *item) {
if (_dragItem == item) {
dragActionCancel();
}
SelectedItems::iterator i = _selected.find(item);
if (i != _selected.cend()) {
_selected.erase(i);
historyWidget->updateTopBarSelection();
}
if (_dragAction == NoDrag) return;
if (_dragItem == item) {
dragActionCancel();
}
onUpdateSelected();
if (_dragSelFrom == item) _dragSelFrom = 0;
@ -836,24 +838,6 @@ void HistoryList::copyContextText() {
}
}
bool HistoryList::getPhotoCoords(PhotoData *photo, int32 &x, int32 &y, int32 &w) const {
HistoryItem *hoveredItem = App::hoveredLinkItem();
if (hoveredItem && hoveredItem->getPhotoCoords(photo, x, y, w)) {
y += height() - hist->height - st::historyPadding + hoveredItem->block()->y + hoveredItem->y;
return true;
}
return false;
}
bool HistoryList::getVideoCoords(VideoData *video, int32 &x, int32 &y, int32 &w) const {
HistoryItem *hoveredItem = App::hoveredItem();
if (hoveredItem && hoveredItem->getVideoCoords(video, x, y, w)) {
y += height() - hist->height - st::historyPadding + hoveredItem->block()->y + hoveredItem->y;
return true;
}
return false;
}
void HistoryList::resizeEvent(QResizeEvent *e) {
onUpdateSelected();
}
@ -3323,24 +3307,6 @@ void HistoryWidget::paintEvent(QPaintEvent *e) {
}
}
bool HistoryWidget::getPhotoCoords(PhotoData *photo, int32 &x, int32 &y, int32 &w) const {
if (_list && _list->getPhotoCoords(photo, x, y, w)) {
x += _list->x();
y += _list->y();
return true;
}
return false;
}
bool HistoryWidget::getVideoCoords(VideoData *video, int32 &x, int32 &y, int32 &w) const {
if (_list && _list->getVideoCoords(video, x, y, w)) {
x += _list->x();
y += _list->y();
return true;
}
return false;
}
QRect HistoryWidget::historyRect() const {
return _scroll.geometry();
}

View File

@ -68,9 +68,6 @@ public:
void updateMsg(const HistoryItem *msg);
bool getPhotoCoords(PhotoData *photo, int32 &x, int32 &y, int32 &w) const;
bool getVideoCoords(VideoData *video, int32 &x, int32 &y, int32 &w) const;
void getSelectionState(int32 &selectedForForward, int32 &selectedForDelete) const;
void clearSelectedItems(bool onlyTextSelection = false);
void fillSelectedItems(SelectedItemSet &sel, bool forDelete = true);
@ -283,8 +280,6 @@ public:
void historyToDown(History *history);
void historyWasRead(bool force = true);
bool getPhotoCoords(PhotoData *photo, int32 &x, int32 &y, int32 &w) const;
bool getVideoCoords(VideoData *video, int32 &x, int32 &y, int32 &w) const;
QRect historyRect() const;
void updateTyping(bool typing = true);