From 78d245c02c15099629fb68618fd4f780513d230c Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 3 Apr 2017 19:46:24 +0300 Subject: [PATCH] Improve positioning of chat helper panels. --- Telegram/SourceFiles/historywidget.cpp | 8 +-- .../inline_bots/inline_results_widget.cpp | 51 +++++++------------ .../inline_bots/inline_results_widget.h | 11 +--- Telegram/SourceFiles/stickers/emoji_panel.cpp | 23 ++------- Telegram/SourceFiles/stickers/emoji_panel.h | 5 -- Telegram/SourceFiles/stickers/stickers.style | 5 +- 6 files changed, 27 insertions(+), 76 deletions(-) diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index 446288a71..f8bfe4681 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -6546,7 +6546,7 @@ void HistoryWidget::moveFieldControls() { if (_inlineResults) { _inlineResults->moveBottom(_field->y() - st::historySendPadding); } - _emojiPanel->moveBottom(_field->y() - st::historySendPadding); + _emojiPanel->moveBottom(buttonsBottom); auto fullWidthButtonRect = QRect(0, bottom - _botStart->height(), width(), _botStart->height()); _botStart->setGeometry(fullWidthButtonRect); @@ -7215,12 +7215,6 @@ void HistoryWidget::updateControlsGeometry() { updateHistoryDownPosition(); - _emojiPanel->setMinTop(0); - _emojiPanel->setMinBottom(_attachEmoji->height()); - if (_inlineResults) { - _inlineResults->setMinTop(0); - _inlineResults->setMinBottom(_attachEmoji->height()); - } if (_membersDropdown) { _membersDropdown->setMaxHeight(countMembersDropdownHeightMax()); } diff --git a/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp b/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp index 001570377..2070ad9c4 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp @@ -46,7 +46,7 @@ constexpr auto kInlineBotRequestDelay = 400; } // namespace Inner::Inner(QWidget *parent) : TWidget(parent) { - setMaxHeight(st::emojiPanMaxHeight - st::emojiCategory.height); + resize(st::emojiPanWidth - st::emojiScroll.width - st::buttonRadius, st::emojiPanMinHeight); setMouseTracking(true); setAttribute(Qt::WA_OpaquePaintEvent); @@ -75,16 +75,15 @@ void Inner::setVisibleTopBottom(int visibleTop, int visibleBottom) { } } -int Inner::countHeight(bool plain) { +int Inner::countHeight() { auto result = st::stickerPanPadding; - auto minLastH = plain ? 0 : (_maxHeight - st::stickerPanPadding); if (_switchPmButton) { result += _switchPmButton->height() + st::inlineResultsSkip; } for (int i = 0, l = _rows.count(); i < l; ++i) { result += _rows[i].height; } - return qMax(minLastH, result) + st::stickerPanPadding; + return result + st::stickerPanPadding; } Inner::~Inner() = default; @@ -437,7 +436,7 @@ int Inner::refreshInlineRows(UserData *bot, const CacheEntry *entry, bool result inlineRowFinalize(row, sumWidth, true); } - int32 h = countHeight(); + auto h = countHeight(); if (h != height()) resize(width(), h); update(); @@ -544,7 +543,7 @@ bool Inner::inlineItemVisible(const ItemBase *layout) { top += _rows.at(i).height; } - return (top < _visibleTop + _maxHeight) && (top + _rows[row].items[col]->height() > _visibleTop); + return (top < _visibleBottom) && (top + _rows[row].items[col]->height() > _visibleTop); } void Inner::updateSelected() { @@ -698,28 +697,18 @@ Widget::Widget(QWidget *parent) : TWidget(parent) setAttribute(Qt::WA_OpaquePaintEvent, false); } -void Widget::setMinTop(int minTop) { - _minTop = minTop; - updateContentHeight(); -} - -void Widget::setMinBottom(int minBottom) { - _minBottom = minBottom; - updateContentHeight(); -} - void Widget::moveBottom(int bottom) { _bottom = bottom; updateContentHeight(); } void Widget::updateContentHeight() { - auto wantedBottom = countBottom(); - auto maxContentHeight = wantedBottom - st::emojiPanMargins.top() - st::emojiPanMargins.bottom(); - auto contentHeight = qMin(_contentMaxHeight, maxContentHeight); - auto resultTop = wantedBottom - st::emojiPanMargins.bottom() - contentHeight - st::emojiPanMargins.top(); - accumulate_max(resultTop, _minTop); - auto hs = contentHeight; + auto addedHeight = innerPadding().top() + innerPadding().bottom(); + auto wantedContentHeight = qRound(st::emojiPanHeightRatio * _bottom) - addedHeight; + auto contentHeight = snap(wantedContentHeight, st::emojiPanMinHeight, st::emojiPanMaxHeight); + accumulate_min(contentHeight, _bottom - addedHeight); + accumulate_min(contentHeight, _contentMaxHeight); + auto resultTop = _bottom - addedHeight - contentHeight; if (contentHeight == _contentHeight) { move(x(), resultTop); return; @@ -730,13 +719,15 @@ void Widget::updateContentHeight() { resize(QRect(0, 0, innerRect().width(), _contentHeight).marginsAdded(innerPadding()).size()); _height = height(); - move(x(), resultTop); + moveToLeft(0, resultTop); if (was > _contentHeight) { _scroll->resize(_scroll->width(), _contentHeight); - _inner->setMaxHeight(_contentHeight); + auto scrollTop = _scroll->scrollTop(); + _inner->setVisibleTopBottom(scrollTop, scrollTop + _contentHeight); } else { - _inner->setMaxHeight(_contentHeight); + auto scrollTop = _scroll->scrollTop(); + _inner->setVisibleTopBottom(scrollTop, scrollTop + _contentHeight); _scroll->resize(_scroll->width(), _contentHeight); } @@ -793,12 +784,7 @@ void Widget::paintContent(Painter &p) { p.fillRect(myrtlrect(inner.x(), sidesTop, st::buttonRadius, sidesHeight), st::emojiPanBg); } -int Widget::countBottom() const { - return _bottom; -} - void Widget::moveByBottom() { - moveToLeft(0, y()); updateContentHeight(); } @@ -906,7 +892,6 @@ void Widget::showStarted() { if (isHidden()) { recountContentMaxHeight(); _inner->preloadImages(); - moveByBottom(); show(); App::wnd()->enableGifPauseReason(Window::GifPauseReason::InlineResults); startShowAnimation(); @@ -1095,7 +1080,7 @@ int Widget::showInlineRows(bool newResults) { _scroll->scrollToY(0); } - bool hidden = isHidden(); + auto hidden = isHidden(); if (!hidden && !clear) { recountContentMaxHeight(); } @@ -1115,7 +1100,7 @@ int Widget::showInlineRows(bool newResults) { } void Widget::recountContentMaxHeight() { - _contentMaxHeight = qMin(_inner->countHeight(true), st::emojiPanMaxHeight); + _contentMaxHeight = _inner->countHeight(); updateContentHeight(); } diff --git a/Telegram/SourceFiles/inline_bots/inline_results_widget.h b/Telegram/SourceFiles/inline_bots/inline_results_widget.h index a67e8be53..80e1a1e64 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_widget.h +++ b/Telegram/SourceFiles/inline_bots/inline_results_widget.h @@ -60,8 +60,6 @@ class Inner : public TWidget, public Context, private base::Subscriber { public: Inner(QWidget *parent); - void setMaxHeight(int maxHeight); - void hideFinish(bool completely); void clearSelection(); @@ -78,7 +76,7 @@ public: void inlineItemRepaint(const ItemBase *layout) override; bool inlineItemVisible(const ItemBase *layout) override; - int countHeight(bool plain = false); + int countHeight(); void setResultSelectedCallback(base::lambda callback) { _resultSelectedCallback = std::move(callback); @@ -113,8 +111,6 @@ private: void refreshSwitchPmButton(const CacheEntry *entry); - int32 _maxHeight; - int _visibleTop = 0; int _visibleBottom = 0; @@ -164,8 +160,6 @@ class Widget : public TWidget, private MTP::Sender { public: Widget(QWidget *parent); - void setMinTop(int minTop); - void setMinBottom(int minBottom); void moveBottom(int bottom); void hideFast(); @@ -199,7 +193,6 @@ private slots: void onEmptyInlineRows(); private: - int countBottom() const; void moveByBottom(); void paintContent(Painter &p); @@ -235,8 +228,6 @@ private: bool refreshInlineRows(int *added = nullptr); void inlineResultsDone(const MTPmessages_BotResults &result); - int _minTop = 0; - int _minBottom = 0; int _contentMaxHeight = 0; int _contentHeight = 0; bool _horizontal = false; diff --git a/Telegram/SourceFiles/stickers/emoji_panel.cpp b/Telegram/SourceFiles/stickers/emoji_panel.cpp index 8d3ecfd49..aa8925d9d 100644 --- a/Telegram/SourceFiles/stickers/emoji_panel.cpp +++ b/Telegram/SourceFiles/stickers/emoji_panel.cpp @@ -353,27 +353,16 @@ EmojiPanel::EmojiPanel(QWidget *parent) : TWidget(parent) hideChildren(); } -void EmojiPanel::setMinTop(int minTop) { - _minTop = minTop; - updateContentHeight(); -} - -void EmojiPanel::setMinBottom(int minBottom) { - _minBottom = minBottom; - updateContentHeight(); -} - void EmojiPanel::moveBottom(int bottom) { _bottom = bottom; updateContentHeight(); } void EmojiPanel::updateContentHeight() { - auto wantedBottom = countBottom(); - auto maxContentHeight = wantedBottom - st::emojiPanMargins.top() - st::emojiPanMargins.bottom() - marginTop() - marginBottom(); - auto contentHeight = qMin(_contentMaxHeight, maxContentHeight); - auto resultTop = wantedBottom - st::emojiPanMargins.bottom() - marginBottom() - contentHeight - marginTop() - st::emojiPanMargins.top(); - accumulate_max(resultTop, _minTop); + auto addedHeight = innerPadding().top() + marginTop() + marginBottom() + innerPadding().bottom(); + auto wantedContentHeight = qRound(st::emojiPanHeightRatio * _bottom) - addedHeight; + auto contentHeight = snap(wantedContentHeight, st::emojiPanMinHeight, st::emojiPanMaxHeight); + auto resultTop = _bottom - addedHeight - contentHeight; if (contentHeight == _contentHeight) { move(x(), resultTop); return; @@ -505,10 +494,6 @@ int EmojiPanel::marginBottom() const { return st::emojiCategory.height; } -int EmojiPanel::countBottom() const { - return (parentWidget()->height() - _minBottom); -} - void EmojiPanel::moveByBottom() { moveToRight(0, y()); updateContentHeight(); diff --git a/Telegram/SourceFiles/stickers/emoji_panel.h b/Telegram/SourceFiles/stickers/emoji_panel.h index b9945a196..579cc84fe 100644 --- a/Telegram/SourceFiles/stickers/emoji_panel.h +++ b/Telegram/SourceFiles/stickers/emoji_panel.h @@ -48,8 +48,6 @@ class EmojiPanel : public TWidget { public: EmojiPanel(QWidget *parent); - void setMinTop(int minTop); - void setMinBottom(int minBottom); void moveBottom(int bottom); void hideFast(); @@ -141,7 +139,6 @@ private: int marginTop() const; int marginBottom() const; - int countBottom() const; void moveByBottom(); void paintSlideFrame(Painter &p, TimeMs ms); void paintContent(Painter &p); @@ -200,8 +197,6 @@ private: gsl::not_null stickers() const; gsl::not_null gifs() const; - int _minTop = 0; - int _minBottom = 0; int _contentMaxHeight = 0; int _contentHeight = 0; diff --git a/Telegram/SourceFiles/stickers/stickers.style b/Telegram/SourceFiles/stickers/stickers.style index 977df49a8..1deb068a0 100644 --- a/Telegram/SourceFiles/stickers/stickers.style +++ b/Telegram/SourceFiles/stickers/stickers.style @@ -109,7 +109,6 @@ stickersSettingsUnreadPosition: point(4px, 5px); emojiPanMargins: margins(10px, 10px, 10px, 10px); - emojiTabs: SettingsSlider(defaultTabsSlider) { rippleRoundRadius: buttonRadius; } @@ -152,7 +151,9 @@ emojiPanAnimation: PanelAnimation(defaultPanelAnimation) { emojiPanPadding: 12px; emojiPanSize: size(45px, 41px); emojiPanWidth: 345px; -emojiPanMaxHeight: 720px; +emojiPanMinHeight: 278px; +emojiPanMaxHeight: 640px; +emojiPanHeightRatio: 0.75; emojiPanShowDuration: 200; emojiPanDuration: 200; emojiPanHover: windowBgOver;