2016-06-17 18:18:01 +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-06-17 18:18:01 +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-06-17 18:18:01 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2016-10-26 16:43:13 +00:00
|
|
|
#include "styles/style_widgets.h"
|
2016-11-09 13:40:51 +00:00
|
|
|
#include "ui/effects/panel_animation.h"
|
2016-06-20 11:31:12 +00:00
|
|
|
|
2016-06-17 18:18:01 +00:00
|
|
|
namespace Ui {
|
|
|
|
|
2016-11-16 10:44:06 +00:00
|
|
|
class ScrollArea;
|
|
|
|
|
2016-06-17 18:18:01 +00:00
|
|
|
class InnerDropdown : public TWidget {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2016-10-26 16:43:13 +00:00
|
|
|
InnerDropdown(QWidget *parent, const style::InnerDropdown &st = st::defaultInnerDropdown);
|
2016-06-17 18:18:01 +00:00
|
|
|
|
2017-05-26 14:36:59 +00:00
|
|
|
template <typename Widget>
|
|
|
|
QPointer<Widget> setOwnedWidget(object_ptr<Widget> widget) {
|
|
|
|
auto result = doSetOwnedWidget(std::move(widget));
|
|
|
|
return QPointer<Widget>(static_cast<Widget*>(result.data()));
|
|
|
|
}
|
2016-06-17 18:18:01 +00:00
|
|
|
|
|
|
|
bool overlaps(const QRect &globalRect) {
|
2016-11-09 13:40:51 +00:00
|
|
|
if (isHidden() || _a_show.animating() || _a_opacity.animating()) return false;
|
2016-06-17 18:18:01 +00:00
|
|
|
|
|
|
|
return rect().marginsRemoved(_st.padding).contains(QRect(mapFromGlobal(globalRect.topLeft()), globalRect.size()));
|
|
|
|
}
|
|
|
|
|
2017-07-22 08:35:18 +00:00
|
|
|
void setAutoHiding(bool autoHiding) {
|
|
|
|
_autoHiding = autoHiding;
|
|
|
|
}
|
2016-06-20 11:31:12 +00:00
|
|
|
void setMaxHeight(int newMaxHeight);
|
2016-10-26 16:43:13 +00:00
|
|
|
void resizeToContent();
|
2016-06-20 11:31:12 +00:00
|
|
|
|
2016-06-17 18:18:01 +00:00
|
|
|
void otherEnter();
|
|
|
|
void otherLeave();
|
2016-10-26 16:43:13 +00:00
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
void setShowStartCallback(Fn<void()> callback) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_showStartCallback = std::move(callback);
|
2016-11-16 12:06:02 +00:00
|
|
|
}
|
2018-06-04 15:35:11 +00:00
|
|
|
void setHideStartCallback(Fn<void()> callback) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_hideStartCallback = std::move(callback);
|
2016-11-16 12:06:02 +00:00
|
|
|
}
|
2018-06-04 15:35:11 +00:00
|
|
|
void setHiddenCallback(Fn<void()> callback) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_hiddenCallback = std::move(callback);
|
2016-11-05 08:36:24 +00:00
|
|
|
}
|
|
|
|
|
2016-10-26 16:43:13 +00:00
|
|
|
bool isHiding() const {
|
2016-11-09 13:40:51 +00:00
|
|
|
return _hiding && _a_opacity.animating();
|
2016-10-26 16:43:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum class HideOption {
|
|
|
|
Default,
|
|
|
|
IgnoreShow,
|
|
|
|
};
|
2017-07-22 08:35:18 +00:00
|
|
|
void showAnimated();
|
|
|
|
void setOrigin(PanelAnimation::Origin origin);
|
|
|
|
void showAnimated(PanelAnimation::Origin origin);
|
2016-10-26 16:43:13 +00:00
|
|
|
void hideAnimated(HideOption option = HideOption::Default);
|
2017-09-30 19:20:40 +00:00
|
|
|
void finishAnimating();
|
2017-07-22 08:35:18 +00:00
|
|
|
void showFast();
|
|
|
|
void hideFast();
|
2016-10-26 16:43:13 +00:00
|
|
|
|
2016-06-17 18:18:01 +00:00
|
|
|
protected:
|
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
2017-02-11 11:24:37 +00:00
|
|
|
void enterEventHook(QEvent *e) override;
|
|
|
|
void leaveEventHook(QEvent *e) override;
|
2016-06-17 18:18:01 +00:00
|
|
|
bool eventFilter(QObject *obj, QEvent *e) override;
|
|
|
|
|
2016-10-26 16:43:13 +00:00
|
|
|
int resizeGetHeight(int newWidth) override;
|
2016-06-17 18:18:01 +00:00
|
|
|
|
|
|
|
private slots:
|
2016-10-26 16:43:13 +00:00
|
|
|
void onHideAnimated() {
|
|
|
|
hideAnimated();
|
|
|
|
}
|
2016-06-17 18:18:01 +00:00
|
|
|
void onWindowActiveChanged();
|
|
|
|
void onScroll();
|
2016-10-26 16:43:13 +00:00
|
|
|
void onWidgetHeightUpdated() {
|
|
|
|
resizeToContent();
|
|
|
|
}
|
2016-06-17 18:18:01 +00:00
|
|
|
|
|
|
|
private:
|
2017-05-26 14:36:59 +00:00
|
|
|
QPointer<TWidget> doSetOwnedWidget(object_ptr<TWidget> widget);
|
2016-11-09 13:40:51 +00:00
|
|
|
QImage grabForPanelAnimation();
|
|
|
|
void startShowAnimation();
|
|
|
|
void startOpacityAnimation(bool hiding);
|
|
|
|
void prepareCache();
|
|
|
|
|
2016-10-26 16:43:13 +00:00
|
|
|
class Container;
|
2016-11-09 13:40:51 +00:00
|
|
|
void showAnimationCallback();
|
|
|
|
void opacityAnimationCallback();
|
2016-06-17 18:18:01 +00:00
|
|
|
|
2016-10-26 16:43:13 +00:00
|
|
|
void hideFinished();
|
|
|
|
void showStarted();
|
2016-06-17 18:18:01 +00:00
|
|
|
|
2016-06-20 11:31:12 +00:00
|
|
|
void updateHeight();
|
|
|
|
|
|
|
|
const style::InnerDropdown &_st;
|
2016-06-17 18:18:01 +00:00
|
|
|
|
2016-11-09 13:40:51 +00:00
|
|
|
PanelAnimation::Origin _origin = PanelAnimation::Origin::TopLeft;
|
2017-02-21 13:45:56 +00:00
|
|
|
std::unique_ptr<PanelAnimation> _showAnimation;
|
2016-12-07 13:32:25 +00:00
|
|
|
Animation _a_show;
|
2016-06-17 18:18:01 +00:00
|
|
|
|
2017-07-22 08:35:18 +00:00
|
|
|
bool _autoHiding = true;
|
2016-11-09 13:40:51 +00:00
|
|
|
bool _hiding = false;
|
2016-06-17 18:18:01 +00:00
|
|
|
QPixmap _cache;
|
2016-12-07 13:32:25 +00:00
|
|
|
Animation _a_opacity;
|
2016-06-17 18:18:01 +00:00
|
|
|
|
|
|
|
QTimer _hideTimer;
|
2016-10-26 16:43:13 +00:00
|
|
|
bool _ignoreShowEvents = false;
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void()> _showStartCallback;
|
|
|
|
Fn<void()> _hideStartCallback;
|
|
|
|
Fn<void()> _hiddenCallback;
|
2016-06-17 18:18:01 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<Ui::ScrollArea> _scroll;
|
2016-06-17 18:18:01 +00:00
|
|
|
|
2016-06-20 11:31:12 +00:00
|
|
|
int _maxHeight = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-10-26 16:43:13 +00:00
|
|
|
class InnerDropdown::Container : public TWidget {
|
2016-06-20 11:31:12 +00:00
|
|
|
public:
|
2017-05-26 14:36:59 +00:00
|
|
|
Container(QWidget *parent, object_ptr<TWidget> child, const style::InnerDropdown &st);
|
2016-06-20 11:31:12 +00:00
|
|
|
|
2016-10-26 16:43:13 +00:00
|
|
|
void resizeToContent();
|
2016-06-20 11:31:12 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
int resizeGetHeight(int newWidth) override;
|
2017-09-13 16:57:44 +00:00
|
|
|
void visibleTopBottomUpdated(
|
|
|
|
int visibleTop,
|
|
|
|
int visibleBottom) override;
|
2016-06-20 11:31:12 +00:00
|
|
|
|
|
|
|
private:
|
2017-05-26 14:36:59 +00:00
|
|
|
object_ptr<TWidget> _child;
|
2017-05-26 16:03:41 +00:00
|
|
|
const style::InnerDropdown &_st;
|
2016-06-20 11:31:12 +00:00
|
|
|
|
2016-06-17 18:18:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Ui
|