2016-09-09 15:52:46 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-09-09 15:52:46 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-09-09 15:52:46 +00:00
|
|
|
*/
|
2017-04-08 14:05:19 +00:00
|
|
|
#include "chat_helpers/tabbed_panel.h"
|
2016-09-09 15:52:46 +00:00
|
|
|
|
2016-11-12 15:02:19 +00:00
|
|
|
#include "ui/widgets/shadow.h"
|
2018-10-23 09:44:42 +00:00
|
|
|
#include "ui/image/image_prepare.h"
|
2019-09-13 12:22:54 +00:00
|
|
|
#include "ui/ui_utility.h"
|
2017-04-08 15:20:12 +00:00
|
|
|
#include "chat_helpers/tabbed_selector.h"
|
2019-06-06 10:21:40 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2017-03-29 14:04:00 +00:00
|
|
|
#include "mainwindow.h"
|
2019-01-21 13:42:21 +00:00
|
|
|
#include "core/application.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "app.h"
|
2018-10-23 09:44:42 +00:00
|
|
|
#include "styles/style_chat_helpers.h"
|
2016-09-09 15:52:46 +00:00
|
|
|
|
2017-03-29 14:04:00 +00:00
|
|
|
namespace ChatHelpers {
|
2016-11-12 15:02:19 +00:00
|
|
|
namespace {
|
|
|
|
|
2017-04-08 15:20:12 +00:00
|
|
|
constexpr auto kHideTimeoutMs = 300;
|
|
|
|
constexpr auto kDelayedHideTimeoutMs = 3000;
|
2016-11-12 15:02:19 +00:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2017-09-16 16:53:41 +00:00
|
|
|
TabbedPanel::TabbedPanel(
|
|
|
|
QWidget *parent,
|
2019-08-16 12:44:20 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<TabbedSelector*> selector)
|
|
|
|
: TabbedPanel(parent, controller, { nullptr }, selector) {
|
2017-04-09 18:06:06 +00:00
|
|
|
}
|
|
|
|
|
2017-09-16 16:53:41 +00:00
|
|
|
TabbedPanel::TabbedPanel(
|
|
|
|
QWidget *parent,
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2017-09-16 16:53:41 +00:00
|
|
|
object_ptr<TabbedSelector> selector)
|
2019-08-16 12:44:20 +00:00
|
|
|
: TabbedPanel(parent, controller, std::move(selector), nullptr) {
|
|
|
|
}
|
|
|
|
|
|
|
|
TabbedPanel::TabbedPanel(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
object_ptr<TabbedSelector> ownedSelector,
|
|
|
|
TabbedSelector *nonOwnedSelector)
|
2017-09-16 16:53:41 +00:00
|
|
|
: RpWidget(parent)
|
2017-04-11 14:02:11 +00:00
|
|
|
, _controller(controller)
|
2019-08-16 12:44:20 +00:00
|
|
|
, _ownedSelector(std::move(ownedSelector))
|
|
|
|
, _selector(nonOwnedSelector ? nonOwnedSelector : _ownedSelector.data())
|
2018-11-22 12:48:50 +00:00
|
|
|
, _heightRatio(st::emojiPanHeightRatio)
|
|
|
|
, _minContentHeight(st::emojiPanMinHeight)
|
|
|
|
, _maxContentHeight(st::emojiPanMaxHeight) {
|
2019-12-09 06:37:02 +00:00
|
|
|
Expects(_selector != nullptr);
|
|
|
|
|
2017-04-09 18:06:06 +00:00
|
|
|
_selector->setParent(this);
|
2017-04-08 15:20:12 +00:00
|
|
|
_selector->setRoundRadius(st::buttonRadius);
|
2019-06-28 11:33:47 +00:00
|
|
|
_selector->setAfterShownCallback([=](SelectorTab tab) {
|
|
|
|
if (tab == SelectorTab::Gifs || tab == SelectorTab::Stickers) {
|
|
|
|
_controller->enableGifPauseReason(
|
|
|
|
Window::GifPauseReason::SavedGifs);
|
2017-04-11 14:02:11 +00:00
|
|
|
}
|
|
|
|
});
|
2019-06-28 11:33:47 +00:00
|
|
|
_selector->setBeforeHidingCallback([=](SelectorTab tab) {
|
|
|
|
if (tab == SelectorTab::Gifs || tab == SelectorTab::Stickers) {
|
|
|
|
_controller->disableGifPauseReason(
|
|
|
|
Window::GifPauseReason::SavedGifs);
|
2017-04-11 14:02:11 +00:00
|
|
|
}
|
|
|
|
});
|
2017-12-22 07:05:20 +00:00
|
|
|
_selector->showRequests(
|
2018-11-22 10:30:48 +00:00
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
showFromSelector();
|
2017-12-22 07:05:20 +00:00
|
|
|
}, lifetime());
|
2016-09-09 15:52:46 +00:00
|
|
|
|
2017-04-08 15:20:12 +00:00
|
|
|
resize(QRect(0, 0, st::emojiPanWidth, st::emojiPanMaxHeight).marginsAdded(innerPadding()).size());
|
2017-03-28 12:30:38 +00:00
|
|
|
|
2017-04-08 15:20:12 +00:00
|
|
|
_contentMaxHeight = st::emojiPanMaxHeight;
|
2017-03-28 12:30:38 +00:00
|
|
|
_contentHeight = _contentMaxHeight;
|
2016-09-09 15:52:46 +00:00
|
|
|
|
2017-04-08 15:20:12 +00:00
|
|
|
_selector->resize(st::emojiPanWidth, _contentHeight);
|
|
|
|
_selector->move(innerRect().topLeft());
|
2016-09-09 15:52:46 +00:00
|
|
|
|
2017-04-08 15:20:12 +00:00
|
|
|
_hideTimer.setCallback([this] { hideByTimerOrLeave(); });
|
2016-09-09 15:52:46 +00:00
|
|
|
|
2018-11-21 18:14:48 +00:00
|
|
|
_selector->checkForHide(
|
|
|
|
) | rpl::start_with_next([=] {
|
2017-04-09 18:06:06 +00:00
|
|
|
if (!rect().contains(mapFromGlobal(QCursor::pos()))) {
|
|
|
|
_hideTimer.callOnce(kDelayedHideTimeoutMs);
|
|
|
|
}
|
2018-11-21 18:14:48 +00:00
|
|
|
}, lifetime());
|
|
|
|
|
|
|
|
_selector->cancelled(
|
|
|
|
) | rpl::start_with_next([=] {
|
2017-04-08 15:20:12 +00:00
|
|
|
hideAnimated();
|
2018-11-21 18:14:48 +00:00
|
|
|
}, lifetime());
|
|
|
|
|
|
|
|
_selector->slideFinished(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
InvokeQueued(this, [=] {
|
2017-04-08 15:20:12 +00:00
|
|
|
if (_hideAfterSlide) {
|
|
|
|
startOpacityAnimation(true);
|
2017-03-28 12:30:38 +00:00
|
|
|
}
|
|
|
|
});
|
2018-11-21 18:14:48 +00:00
|
|
|
}, lifetime());
|
2016-09-09 15:52:46 +00:00
|
|
|
|
2019-04-05 10:13:54 +00:00
|
|
|
macWindowDeactivateEvents(
|
|
|
|
) | rpl::filter([=] {
|
|
|
|
return !isHidden() && !preventAutoHide();
|
|
|
|
}) | rpl::start_with_next([=] {
|
|
|
|
hideAnimated();
|
|
|
|
}, lifetime());
|
|
|
|
|
2016-11-17 11:03:49 +00:00
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent, false);
|
2017-03-28 12:30:38 +00:00
|
|
|
|
|
|
|
hideChildren();
|
2019-08-16 09:32:42 +00:00
|
|
|
hide();
|
2016-09-09 15:52:46 +00:00
|
|
|
}
|
|
|
|
|
2019-08-16 12:44:20 +00:00
|
|
|
not_null<TabbedSelector*> TabbedPanel::selector() const {
|
|
|
|
return _selector;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TabbedPanel::isSelectorStolen() const {
|
|
|
|
return (_selector->parent() != this);
|
|
|
|
}
|
|
|
|
|
2018-11-22 12:48:50 +00:00
|
|
|
void TabbedPanel::moveBottomRight(int bottom, int right) {
|
2019-07-16 08:09:48 +00:00
|
|
|
const auto isNew = (_bottom != bottom || _right != right);
|
2017-01-07 11:55:05 +00:00
|
|
|
_bottom = bottom;
|
2018-11-22 12:48:50 +00:00
|
|
|
_right = right;
|
2019-07-16 08:09:48 +00:00
|
|
|
// If the panel is already shown, update the position.
|
|
|
|
if (!isHidden() && isNew) {
|
|
|
|
moveByBottom();
|
|
|
|
} else {
|
|
|
|
updateContentHeight();
|
|
|
|
}
|
2018-11-22 12:48:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TabbedPanel::setDesiredHeightValues(
|
|
|
|
float64 ratio,
|
|
|
|
int minHeight,
|
|
|
|
int maxHeight) {
|
|
|
|
_heightRatio = ratio;
|
|
|
|
_minContentHeight = minHeight;
|
|
|
|
_maxContentHeight = maxHeight;
|
2016-09-09 15:52:46 +00:00
|
|
|
updateContentHeight();
|
|
|
|
}
|
|
|
|
|
2017-04-08 14:05:19 +00:00
|
|
|
void TabbedPanel::updateContentHeight() {
|
2017-04-08 15:20:12 +00:00
|
|
|
auto addedHeight = innerPadding().top() + innerPadding().bottom();
|
2017-04-15 21:05:57 +00:00
|
|
|
auto marginsHeight = _selector->marginTop() + _selector->marginBottom();
|
|
|
|
auto availableHeight = _bottom - marginsHeight;
|
2018-11-22 12:48:50 +00:00
|
|
|
auto wantedContentHeight = qRound(_heightRatio * availableHeight) - addedHeight;
|
|
|
|
auto contentHeight = marginsHeight + snap(
|
|
|
|
wantedContentHeight,
|
|
|
|
_minContentHeight,
|
|
|
|
_maxContentHeight);
|
2017-04-03 16:46:24 +00:00
|
|
|
auto resultTop = _bottom - addedHeight - contentHeight;
|
2017-03-28 12:30:38 +00:00
|
|
|
if (contentHeight == _contentHeight) {
|
2017-01-07 11:55:05 +00:00
|
|
|
move(x(), resultTop);
|
|
|
|
return;
|
|
|
|
}
|
2016-09-09 15:52:46 +00:00
|
|
|
|
2017-01-07 11:55:05 +00:00
|
|
|
auto was = _contentHeight;
|
|
|
|
_contentHeight = contentHeight;
|
2016-09-09 15:52:46 +00:00
|
|
|
|
2017-04-08 15:20:12 +00:00
|
|
|
resize(QRect(0, 0, innerRect().width(), _contentHeight).marginsAdded(innerPadding()).size());
|
2017-01-07 11:55:05 +00:00
|
|
|
move(x(), resultTop);
|
2016-09-09 15:52:46 +00:00
|
|
|
|
2017-04-08 15:20:12 +00:00
|
|
|
_selector->resize(innerRect().width(), _contentHeight);
|
2016-09-09 15:52:46 +00:00
|
|
|
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2017-04-08 14:05:19 +00:00
|
|
|
void TabbedPanel::paintEvent(QPaintEvent *e) {
|
2016-09-09 15:52:46 +00:00
|
|
|
Painter p(this);
|
|
|
|
|
2016-12-31 13:34:41 +00:00
|
|
|
// This call can finish _a_show animation and destroy _showAnimation.
|
2019-04-02 09:13:30 +00:00
|
|
|
auto opacityAnimating = _a_opacity.animating();
|
2016-12-31 13:34:41 +00:00
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
auto showAnimating = _a_show.animating();
|
2016-11-20 12:54:07 +00:00
|
|
|
if (_showAnimation && !showAnimating) {
|
|
|
|
_showAnimation.reset();
|
2019-12-09 06:37:02 +00:00
|
|
|
if (!opacityAnimating) {
|
2017-04-08 15:20:12 +00:00
|
|
|
showChildren();
|
|
|
|
_selector->afterShown();
|
2016-11-20 12:54:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (showAnimating) {
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(_showAnimation != nullptr);
|
2019-04-02 09:13:30 +00:00
|
|
|
if (auto opacity = _a_opacity.value(_hiding ? 0. : 1.)) {
|
|
|
|
_showAnimation->paintFrame(p, 0, 0, width(), _a_show.value(1.), opacity);
|
2016-11-12 15:02:19 +00:00
|
|
|
}
|
2017-03-28 12:30:38 +00:00
|
|
|
} else if (opacityAnimating) {
|
2019-04-02 09:13:30 +00:00
|
|
|
p.setOpacity(_a_opacity.value(_hiding ? 0. : 1.));
|
2016-11-12 15:02:19 +00:00
|
|
|
p.drawPixmap(0, 0, _cache);
|
2017-03-28 12:30:38 +00:00
|
|
|
} else if (_hiding || isHidden()) {
|
2016-11-12 15:02:19 +00:00
|
|
|
hideFinished();
|
|
|
|
} else {
|
|
|
|
if (!_cache.isNull()) _cache = QPixmap();
|
2017-04-08 15:20:12 +00:00
|
|
|
Ui::Shadow::paint(p, innerRect(), width(), st::emojiPanAnimation.shadow);
|
2016-11-12 15:02:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-08 14:05:19 +00:00
|
|
|
void TabbedPanel::moveByBottom() {
|
2018-11-22 12:48:50 +00:00
|
|
|
const auto right = std::max(parentWidget()->width() - _right, 0);
|
|
|
|
moveToRight(right, y());
|
2017-01-09 13:12:53 +00:00
|
|
|
updateContentHeight();
|
2016-09-09 15:52:46 +00:00
|
|
|
}
|
|
|
|
|
2017-04-08 14:05:19 +00:00
|
|
|
void TabbedPanel::enterEventHook(QEvent *e) {
|
2019-01-21 13:42:21 +00:00
|
|
|
Core::App().registerLeaveSubscription(this);
|
2017-03-28 12:30:38 +00:00
|
|
|
showAnimated();
|
2016-09-09 15:52:46 +00:00
|
|
|
}
|
|
|
|
|
2017-04-08 14:05:19 +00:00
|
|
|
bool TabbedPanel::preventAutoHide() const {
|
2017-04-08 15:20:12 +00:00
|
|
|
return _selector->preventAutoHide();
|
2016-09-09 15:52:46 +00:00
|
|
|
}
|
|
|
|
|
2017-04-08 14:05:19 +00:00
|
|
|
void TabbedPanel::leaveEventHook(QEvent *e) {
|
2019-01-21 13:42:21 +00:00
|
|
|
Core::App().unregisterLeaveSubscription(this);
|
2017-03-27 18:11:51 +00:00
|
|
|
if (preventAutoHide()) {
|
|
|
|
return;
|
|
|
|
}
|
2019-04-02 09:13:30 +00:00
|
|
|
if (_a_show.animating() || _a_opacity.animating()) {
|
2016-11-12 15:02:19 +00:00
|
|
|
hideAnimated();
|
2016-09-09 15:52:46 +00:00
|
|
|
} else {
|
2017-04-08 15:20:12 +00:00
|
|
|
_hideTimer.callOnce(kHideTimeoutMs);
|
2016-09-09 15:52:46 +00:00
|
|
|
}
|
2017-02-11 11:24:37 +00:00
|
|
|
return TWidget::leaveEventHook(e);
|
2016-09-09 15:52:46 +00:00
|
|
|
}
|
|
|
|
|
2017-04-08 14:05:19 +00:00
|
|
|
void TabbedPanel::otherEnter() {
|
2017-03-27 18:11:51 +00:00
|
|
|
showAnimated();
|
2016-09-09 15:52:46 +00:00
|
|
|
}
|
|
|
|
|
2017-04-08 14:05:19 +00:00
|
|
|
void TabbedPanel::otherLeave() {
|
2017-03-28 12:30:38 +00:00
|
|
|
if (preventAutoHide()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
if (_a_opacity.animating()) {
|
2016-11-06 18:08:52 +00:00
|
|
|
hideByTimerOrLeave();
|
2016-09-09 15:52:46 +00:00
|
|
|
} else {
|
2017-04-08 15:20:12 +00:00
|
|
|
_hideTimer.callOnce(0);
|
2016-09-09 15:52:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-08 14:05:19 +00:00
|
|
|
void TabbedPanel::hideFast() {
|
2016-11-12 15:02:19 +00:00
|
|
|
if (isHidden()) return;
|
|
|
|
|
2019-07-05 17:47:27 +00:00
|
|
|
if (_selector && !_selector->isHidden()) {
|
|
|
|
_selector->beforeHiding();
|
|
|
|
}
|
2017-04-08 15:20:12 +00:00
|
|
|
_hideTimer.cancel();
|
2016-11-12 15:02:19 +00:00
|
|
|
_hiding = false;
|
2019-04-02 09:13:30 +00:00
|
|
|
_a_opacity.stop();
|
2016-11-12 15:02:19 +00:00
|
|
|
hideFinished();
|
2016-09-09 15:52:46 +00:00
|
|
|
}
|
|
|
|
|
2017-04-08 14:05:19 +00:00
|
|
|
void TabbedPanel::opacityAnimationCallback() {
|
2016-11-12 15:02:19 +00:00
|
|
|
update();
|
|
|
|
if (!_a_opacity.animating()) {
|
2019-12-09 06:37:02 +00:00
|
|
|
if (_hiding) {
|
2016-11-12 15:02:19 +00:00
|
|
|
_hiding = false;
|
|
|
|
hideFinished();
|
2017-04-08 15:20:12 +00:00
|
|
|
} else if (!_a_show.animating()) {
|
|
|
|
showChildren();
|
|
|
|
_selector->afterShown();
|
2016-09-09 15:52:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-08 14:05:19 +00:00
|
|
|
void TabbedPanel::hideByTimerOrLeave() {
|
2017-03-27 18:11:51 +00:00
|
|
|
if (isHidden() || preventAutoHide()) return;
|
2016-09-09 15:52:46 +00:00
|
|
|
|
2016-11-06 18:08:52 +00:00
|
|
|
hideAnimated();
|
2016-09-09 15:52:46 +00:00
|
|
|
}
|
|
|
|
|
2019-04-30 08:56:21 +00:00
|
|
|
void TabbedPanel::prepareCacheFor(bool hiding) {
|
|
|
|
if (_a_opacity.animating()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-11-12 15:02:19 +00:00
|
|
|
|
|
|
|
auto showAnimation = base::take(_a_show);
|
|
|
|
auto showAnimationData = base::take(_showAnimation);
|
2019-04-30 08:56:21 +00:00
|
|
|
_hiding = false;
|
2017-04-08 15:20:12 +00:00
|
|
|
showChildren();
|
2019-04-30 08:56:21 +00:00
|
|
|
|
2017-12-26 12:41:48 +00:00
|
|
|
_cache = Ui::GrabWidget(this);
|
2019-04-30 08:56:21 +00:00
|
|
|
|
2016-11-12 15:02:19 +00:00
|
|
|
_a_show = base::take(showAnimation);
|
2019-04-30 08:56:21 +00:00
|
|
|
_showAnimation = base::take(showAnimationData);
|
|
|
|
_hiding = hiding;
|
2016-11-12 15:02:19 +00:00
|
|
|
if (_a_show.animating()) {
|
2017-03-28 12:30:38 +00:00
|
|
|
hideChildren();
|
2016-11-12 15:02:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-08 14:05:19 +00:00
|
|
|
void TabbedPanel::startOpacityAnimation(bool hiding) {
|
2017-04-09 18:06:06 +00:00
|
|
|
if (_selector && !_selector->isHidden()) {
|
2017-04-08 15:20:12 +00:00
|
|
|
_selector->beforeHiding();
|
2017-03-31 15:50:02 +00:00
|
|
|
}
|
2019-04-30 08:56:21 +00:00
|
|
|
prepareCacheFor(hiding);
|
2017-03-28 12:30:38 +00:00
|
|
|
hideChildren();
|
2019-04-30 08:56:21 +00:00
|
|
|
_a_opacity.start(
|
|
|
|
[=] { opacityAnimationCallback(); },
|
|
|
|
_hiding ? 1. : 0.,
|
|
|
|
_hiding ? 0. : 1.,
|
|
|
|
st::emojiPanDuration);
|
2016-11-12 15:02:19 +00:00
|
|
|
}
|
|
|
|
|
2017-04-08 14:05:19 +00:00
|
|
|
void TabbedPanel::startShowAnimation() {
|
2016-11-12 15:02:19 +00:00
|
|
|
if (!_a_show.animating()) {
|
2017-04-08 15:20:12 +00:00
|
|
|
auto image = grabForAnimation();
|
2016-11-12 15:02:19 +00:00
|
|
|
|
2017-03-27 18:11:51 +00:00
|
|
|
_showAnimation = std::make_unique<Ui::PanelAnimation>(st::emojiPanAnimation, Ui::PanelAnimation::Origin::BottomRight);
|
2016-12-13 17:07:56 +00:00
|
|
|
auto inner = rect().marginsRemoved(st::emojiPanMargins);
|
2017-02-21 13:45:56 +00:00
|
|
|
_showAnimation->setFinalImage(std::move(image), QRect(inner.topLeft() * cIntRetinaFactor(), inner.size() * cIntRetinaFactor()));
|
2019-09-16 11:14:06 +00:00
|
|
|
_showAnimation->setCornerMasks(Images::CornersMask(ImageRoundRadius::Small));
|
2016-11-12 15:02:19 +00:00
|
|
|
_showAnimation->start();
|
2016-09-09 15:52:46 +00:00
|
|
|
}
|
2017-03-28 12:30:38 +00:00
|
|
|
hideChildren();
|
2016-11-12 15:02:19 +00:00
|
|
|
_a_show.start([this] { update(); }, 0., 1., st::emojiPanShowDuration);
|
|
|
|
}
|
|
|
|
|
2017-04-08 15:20:12 +00:00
|
|
|
QImage TabbedPanel::grabForAnimation() {
|
2017-03-28 12:30:38 +00:00
|
|
|
auto cache = base::take(_cache);
|
|
|
|
auto opacityAnimation = base::take(_a_opacity);
|
|
|
|
auto showAnimationData = base::take(_showAnimation);
|
|
|
|
auto showAnimation = base::take(_a_show);
|
|
|
|
|
2017-04-08 15:20:12 +00:00
|
|
|
showChildren();
|
2017-12-26 12:41:48 +00:00
|
|
|
Ui::SendPendingMoveResizeEvents(this);
|
2017-03-28 12:30:38 +00:00
|
|
|
|
2019-04-26 09:43:57 +00:00
|
|
|
auto result = QImage(
|
|
|
|
size() * cIntRetinaFactor(),
|
|
|
|
QImage::Format_ARGB32_Premultiplied);
|
2016-11-12 15:02:19 +00:00
|
|
|
result.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
result.fill(Qt::transparent);
|
2017-04-09 18:06:06 +00:00
|
|
|
if (_selector) {
|
2019-04-26 09:43:57 +00:00
|
|
|
QPainter p(&result);
|
|
|
|
Ui::RenderWidget(p, _selector, _selector->pos());
|
2017-04-09 18:06:06 +00:00
|
|
|
}
|
2017-03-28 12:30:38 +00:00
|
|
|
|
|
|
|
_a_show = base::take(showAnimation);
|
|
|
|
_showAnimation = base::take(showAnimationData);
|
|
|
|
_a_opacity = base::take(opacityAnimation);
|
|
|
|
_cache = base::take(_cache);
|
|
|
|
|
2017-02-21 14:37:53 +00:00
|
|
|
return result;
|
2016-09-09 15:52:46 +00:00
|
|
|
}
|
|
|
|
|
2017-04-08 14:05:19 +00:00
|
|
|
void TabbedPanel::hideAnimated() {
|
2017-04-09 18:06:06 +00:00
|
|
|
if (isHidden() || _hiding) {
|
|
|
|
return;
|
|
|
|
}
|
2016-09-09 15:52:46 +00:00
|
|
|
|
2017-04-08 15:20:12 +00:00
|
|
|
_hideTimer.cancel();
|
2019-12-09 06:37:02 +00:00
|
|
|
if (_selector->isSliding()) {
|
2017-03-28 12:30:38 +00:00
|
|
|
_hideAfterSlide = true;
|
|
|
|
} else {
|
|
|
|
startOpacityAnimation(true);
|
|
|
|
}
|
2016-09-09 15:52:46 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 18:06:06 +00:00
|
|
|
void TabbedPanel::toggleAnimated() {
|
|
|
|
if (isHidden() || _hiding || _hideAfterSlide) {
|
|
|
|
showAnimated();
|
|
|
|
} else {
|
|
|
|
hideAnimated();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-08 14:05:19 +00:00
|
|
|
void TabbedPanel::hideFinished() {
|
2016-09-09 15:52:46 +00:00
|
|
|
hide();
|
2019-04-02 09:13:30 +00:00
|
|
|
_a_show.stop();
|
2016-11-12 15:02:19 +00:00
|
|
|
_showAnimation.reset();
|
|
|
|
_cache = QPixmap();
|
2016-09-09 15:52:46 +00:00
|
|
|
_hiding = false;
|
2019-12-09 06:37:02 +00:00
|
|
|
_selector->hideFinished();
|
2016-09-09 15:52:46 +00:00
|
|
|
}
|
|
|
|
|
2017-04-08 14:05:19 +00:00
|
|
|
void TabbedPanel::showAnimated() {
|
2017-04-08 15:20:12 +00:00
|
|
|
_hideTimer.cancel();
|
2017-03-28 12:30:38 +00:00
|
|
|
_hideAfterSlide = false;
|
2016-11-12 15:02:19 +00:00
|
|
|
showStarted();
|
|
|
|
}
|
|
|
|
|
2017-04-08 14:05:19 +00:00
|
|
|
void TabbedPanel::showStarted() {
|
2016-09-09 15:52:46 +00:00
|
|
|
if (isHidden()) {
|
2017-04-08 15:20:12 +00:00
|
|
|
_selector->showStarted();
|
2017-01-07 11:55:05 +00:00
|
|
|
moveByBottom();
|
2018-11-22 12:48:50 +00:00
|
|
|
raise();
|
2016-11-12 15:02:19 +00:00
|
|
|
show();
|
|
|
|
startShowAnimation();
|
2016-11-16 10:44:06 +00:00
|
|
|
} else if (_hiding) {
|
|
|
|
startOpacityAnimation(false);
|
2016-11-12 15:02:19 +00:00
|
|
|
}
|
2016-09-09 15:52:46 +00:00
|
|
|
}
|
|
|
|
|
2017-04-08 14:05:19 +00:00
|
|
|
bool TabbedPanel::eventFilter(QObject *obj, QEvent *e) {
|
2016-09-09 15:52:46 +00:00
|
|
|
if (e->type() == QEvent::Enter) {
|
2017-03-28 12:30:38 +00:00
|
|
|
otherEnter();
|
2016-09-09 15:52:46 +00:00
|
|
|
} else if (e->type() == QEvent::Leave) {
|
2017-03-28 12:30:38 +00:00
|
|
|
otherLeave();
|
2016-09-09 15:52:46 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-16 16:53:41 +00:00
|
|
|
void TabbedPanel::showFromSelector() {
|
2016-09-09 15:52:46 +00:00
|
|
|
if (isHidden()) {
|
2017-01-07 11:55:05 +00:00
|
|
|
moveByBottom();
|
2016-11-12 15:02:19 +00:00
|
|
|
startShowAnimation();
|
2016-09-09 15:52:46 +00:00
|
|
|
show();
|
|
|
|
}
|
2017-04-08 15:20:12 +00:00
|
|
|
showChildren();
|
2017-03-27 18:11:51 +00:00
|
|
|
showAnimated();
|
2016-09-09 15:52:46 +00:00
|
|
|
}
|
|
|
|
|
2017-04-08 14:05:19 +00:00
|
|
|
style::margins TabbedPanel::innerPadding() const {
|
2016-12-13 17:07:56 +00:00
|
|
|
return st::emojiPanMargins;
|
2016-11-12 15:02:19 +00:00
|
|
|
}
|
|
|
|
|
2017-04-08 14:05:19 +00:00
|
|
|
QRect TabbedPanel::innerRect() const {
|
2016-11-12 15:02:19 +00:00
|
|
|
return rect().marginsRemoved(innerPadding());
|
|
|
|
}
|
|
|
|
|
2017-04-08 14:05:19 +00:00
|
|
|
bool TabbedPanel::overlaps(const QRect &globalRect) const {
|
2016-12-13 17:07:56 +00:00
|
|
|
if (isHidden() || !_cache.isNull()) return false;
|
|
|
|
|
|
|
|
auto testRect = QRect(mapFromGlobal(globalRect.topLeft()), globalRect.size());
|
|
|
|
auto inner = rect().marginsRemoved(st::emojiPanMargins);
|
|
|
|
return inner.marginsRemoved(QMargins(st::buttonRadius, 0, st::buttonRadius, 0)).contains(testRect)
|
|
|
|
|| inner.marginsRemoved(QMargins(0, st::buttonRadius, 0, st::buttonRadius)).contains(testRect);
|
|
|
|
}
|
|
|
|
|
2019-08-16 12:44:20 +00:00
|
|
|
TabbedPanel::~TabbedPanel() {
|
2019-12-09 06:37:02 +00:00
|
|
|
hideFast();
|
2019-08-16 12:44:20 +00:00
|
|
|
if (!_ownedSelector) {
|
|
|
|
_controller->takeTabbedSelectorOwnershipFrom(this);
|
|
|
|
}
|
|
|
|
}
|
2017-04-09 18:06:06 +00:00
|
|
|
|
2017-03-29 14:04:00 +00:00
|
|
|
} // namespace ChatHelpers
|