Skip to content

Commit

Permalink
resizing inline results to small heights started, fixed sticker with …
Browse files Browse the repository at this point in the history
…reply display
  • Loading branch information
john-preston committed Jan 1, 2016
1 parent 6236ef7 commit e43ea51
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 20 deletions.
55 changes: 42 additions & 13 deletions Telegram/SourceFiles/dropdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1252,8 +1252,8 @@ void StickerPanInner::setScrollTop(int top) {
updateSelected();
}

int StickerPanInner::countHeight() {
int result = 0, minLastH = _maxHeight - st::stickerPanPadding;
int32 StickerPanInner::countHeight(bool plain) {
int result = 0, minLastH = plain ? 0 : (_maxHeight - st::stickerPanPadding);
if (_showingInlineItems) {
result = st::emojiPanHeader;
for (int i = 0, l = _inlineRows.count(); i < l; ++i) {
Expand Down Expand Up @@ -1876,20 +1876,27 @@ uint64 StickerPanInner::currentSet(int yOffset) const {
return _sets.isEmpty() ? RecentStickerSetId : _sets.back().id;
}

void StickerPanInner::hideInlineRowsPanel() {
clearInlineRows(false);
if (_showingInlineItems) {
_showingSavedGifs = cShowingSavedGifs();
if (_showingSavedGifs) {
refreshSavedGifs();
emit scrollToY(0);
emit scrollUpdated();
} else {
showStickerSet(RecentStickerSetId);
}
}
}

void StickerPanInner::refreshInlineRows(UserData *bot, const InlineResults &results, bool resultsDeleted) {
int32 count = results.size(), until = 0, untilrow = 0, untilcol = 0;
if (!count) {
clearInlineRows(resultsDeleted);
if (_showingInlineItems) {
_showingSavedGifs = cShowingSavedGifs();
if (_showingSavedGifs) {
refreshSavedGifs();
emit scrollToY(0);
emit scrollUpdated();
} else {
showStickerSet(RecentStickerSetId);
}
if (resultsDeleted) {
clearInlineRows(true);
}
emit emptyInlineRows();
return;
}

Expand Down Expand Up @@ -2559,6 +2566,8 @@ EmojiPan::EmojiPan(QWidget *parent) : TWidget(parent)
, _iconSelX(0, 0)
, _iconsStartAnim(0)
, _stickersShown(false)
, _shownFromInlineQuery(false)
, _contentMaxHeight(st::emojiPanMaxHeight)
, _a_slide(animation(this, &EmojiPan::step_slide))
, e_scroll(this, st::emojiScroll)
, e_inner()
Expand Down Expand Up @@ -2620,6 +2629,8 @@ EmojiPan::EmojiPan(QWidget *parent) : TWidget(parent)
connect(&s_inner, SIGNAL(selected(PhotoData*)), this, SIGNAL(photoSelected(PhotoData*)));
connect(&s_inner, SIGNAL(selected(InlineResult*,UserData*)), this, SIGNAL(inlineResultSelected(InlineResult*,UserData*)));

connect(&s_inner, SIGNAL(emptyInlineRows()), this, SLOT(onEmptyInlineRows()));

connect(&s_switch, SIGNAL(clicked()), this, SLOT(onSwitch()));
connect(&e_switch, SIGNAL(clicked()), this, SLOT(onSwitch()));
s_switch.moveToRight(0, 0, st::emojiPanWidth);
Expand Down Expand Up @@ -2648,7 +2659,7 @@ EmojiPan::EmojiPan(QWidget *parent) : TWidget(parent)
}

void EmojiPan::setMaxHeight(int32 h) {
h = qMin(int(st::emojiPanMaxHeight), h);
h = qMin(_contentMaxHeight, h);
int32 he = h - st::rbEmoji.height;
int32 hs = h - (s_inner.showSectionIcons() ? st::rbEmoji.height : 0);
if (h == _maxHeight && he == _maxHeightEmoji && hs == _maxHeightStickers) return;
Expand Down Expand Up @@ -3170,6 +3181,8 @@ void EmojiPan::hideStart() {
}

void EmojiPan::hideAnimated() {
if (_hiding) return;

if (_cache.isNull()) {
QPixmap from = _fromCache, to = _toCache;
_fromCache = _toCache = QPixmap();
Expand Down Expand Up @@ -3219,9 +3232,13 @@ void EmojiPan::showStart() {
e_inner.refreshRecent();
if (s_inner.inlineResultsShown() && refreshInlineRows()) {
_stickersShown = true;
_shownFromInlineQuery = true;
_contentMaxHeight = qMin(s_inner.countHeight(true), int(st::emojiPanMaxHeight));
} else {
s_inner.refreshRecent();
_stickersShown = false;
_shownFromInlineQuery = false;
_contentMaxHeight = st::emojiPanMaxHeight;
}
s_inner.preloadImages();
setMaxHeight(_maxHeight);
Expand Down Expand Up @@ -3706,6 +3723,14 @@ void EmojiPan::onInlineRequest() {
_inlineRequestId = MTP::send(MTPmessages_GetInlineBotResults(_inlineBot->inputUser, MTP_string(_inlineQuery), MTP_string(nextOffset)), rpcDone(&EmojiPan::inlineResultsDone), rpcFail(&EmojiPan::inlineResultsFail));
}

void EmojiPan::onEmptyInlineRows() {
if (_shownFromInlineQuery) {
hideAnimated();
} else {
s_inner.hideInlineRowsPanel();
}
}

bool EmojiPan::refreshInlineRows() {
bool clear = true;
InlineCache::const_iterator i = _inlineCache.constFind(_inlineQuery);
Expand All @@ -3726,6 +3751,10 @@ void EmojiPan::showInlineRows(bool newResults) {
e_switch.moveToRight(0, 0, st::emojiPanWidth);

bool hidden = isHidden();
if (!hidden && _shownFromInlineQuery && !clear) {
_contentMaxHeight = qMax(s_inner.countHeight(true), int(st::emojiPanMaxHeight));
setMaxHeight(_maxHeight);
}
if (clear && !hidden && _stickersShown && s_inner.inlineResultsShown()) {
hideAnimated();
} else if (!clear) {
Expand Down
8 changes: 6 additions & 2 deletions Telegram/SourceFiles/dropdown.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ class StickerPanInner : public TWidget {
void refreshInlineRows(UserData *bot, const InlineResults &results, bool resultsDeleted);
void refreshRecent();
void inlineBotChanged();
void hideInlineRowsPanel();

void fillIcons(QList<StickerIcon> &icons);
void fillPanels(QVector<EmojiPanel*> &panels);
Expand All @@ -364,6 +365,7 @@ class StickerPanInner : public TWidget {
bool inlineResultsShown() const {
return _showingInlineItems && !_showingSavedGifs;
}
int32 countHeight(bool plain = false);

~StickerPanInner() {
clearInlineRows(true);
Expand All @@ -387,6 +389,7 @@ public slots:
void removing(quint64 setId);

void refreshIcons();
void emptyInlineRows();

void switchToEmoji();

Expand All @@ -406,7 +409,6 @@ public slots:

void appendSet(uint64 setId);

int32 countHeight();
void selectEmoji(EmojiPtr emoji);
QRect stickerRect(int tab, int sel);

Expand Down Expand Up @@ -608,6 +610,7 @@ public slots:
void onSaveConfigDelayed(int32 delay);

void onInlineRequest();
void onEmptyInlineRows();

signals:

Expand Down Expand Up @@ -664,7 +667,8 @@ public slots:
anim::ivalue _iconsX, _iconSelX;
uint64 _iconsStartAnim;

bool _stickersShown;
bool _stickersShown, _shownFromInlineQuery;
int32 _contentMaxHeight;
QPixmap _fromCache, _toCache;
anim::ivalue a_fromCoord, a_toCoord;
anim::fvalue a_fromAlpha, a_toAlpha;
Expand Down
10 changes: 5 additions & 5 deletions Telegram/SourceFiles/history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6554,12 +6554,12 @@ int32 HistoryMessage::resize(int32 width) {
if (width < st::msgMinWidth) return _height;

width -= st::msgMargin.left() + st::msgMargin.right();
if (width < st::msgPadding.left() + st::msgPadding.right() + 1) {
width = st::msgPadding.left() + st::msgPadding.right() + 1;
} else if (width > st::msgMaxWidth) {
width = st::msgMaxWidth;
}
if (drawBubble()) {
if (width < st::msgPadding.left() + st::msgPadding.right() + 1) {
width = st::msgPadding.left() + st::msgPadding.right() + 1;
} else if (width > st::msgMaxWidth) {
width = st::msgMaxWidth;
}
bool media = (_media && _media->isDisplayed());
if (width >= _maxw) {
_height = _minh;
Expand Down

0 comments on commit e43ea51

Please sign in to comment.