2015-04-02 10:33:19 +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.
|
2015-04-02 10:33:19 +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
|
2015-04-02 10:33:19 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-09-30 18:26:45 +00:00
|
|
|
#include "window/layer_widget.h"
|
2017-09-13 16:57:44 +00:00
|
|
|
#include "ui/rp_widget.h"
|
2017-09-30 18:26:45 +00:00
|
|
|
|
|
|
|
namespace style {
|
|
|
|
struct RoundButton;
|
|
|
|
struct ScrollArea;
|
|
|
|
} // namespace style
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2016-10-31 12:29:26 +00:00
|
|
|
namespace Ui {
|
2016-12-13 17:07:56 +00:00
|
|
|
class RoundButton;
|
2016-11-08 14:43:10 +00:00
|
|
|
class IconButton;
|
2016-11-16 10:44:06 +00:00
|
|
|
class ScrollArea;
|
2017-05-17 14:32:36 +00:00
|
|
|
class FlatLabel;
|
2017-09-30 18:26:45 +00:00
|
|
|
class FadeShadow;
|
2016-10-31 12:29:26 +00:00
|
|
|
} // namespace Ui
|
|
|
|
|
2018-04-16 17:02:40 +00:00
|
|
|
class BoxContent;
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
class BoxContentDelegate {
|
|
|
|
public:
|
|
|
|
virtual void setLayerType(bool layerType) = 0;
|
2018-06-04 15:35:11 +00:00
|
|
|
virtual void setTitle(Fn<TextWithEntities()> titleFactory) = 0;
|
|
|
|
virtual void setAdditionalTitle(Fn<QString()> additionalFactory) = 0;
|
2018-06-06 11:51:27 +00:00
|
|
|
virtual void setCloseByOutsideClick(bool close) = 0;
|
2016-12-13 17:07:56 +00:00
|
|
|
|
|
|
|
virtual void clearButtons() = 0;
|
2018-06-04 15:35:11 +00:00
|
|
|
virtual QPointer<Ui::RoundButton> addButton(Fn<QString()> textFactory, Fn<void()> clickCallback, const style::RoundButton &st) = 0;
|
|
|
|
virtual QPointer<Ui::RoundButton> addLeftButton(Fn<QString()> textFactory, Fn<void()> clickCallback, const style::RoundButton &st) = 0;
|
2016-12-13 17:07:56 +00:00
|
|
|
virtual void updateButtonsPositions() = 0;
|
|
|
|
|
2018-04-16 17:02:40 +00:00
|
|
|
virtual void showBox(
|
|
|
|
object_ptr<BoxContent> box,
|
|
|
|
LayerOptions options,
|
|
|
|
anim::type animated) = 0;
|
2016-12-13 17:07:56 +00:00
|
|
|
virtual void setDimensions(int newWidth, int maxHeight) = 0;
|
|
|
|
virtual void setNoContentMargin(bool noContentMargin) = 0;
|
|
|
|
virtual bool isBoxShown() const = 0;
|
|
|
|
virtual void closeBox() = 0;
|
|
|
|
|
2018-04-16 17:02:40 +00:00
|
|
|
template <typename BoxType>
|
|
|
|
QPointer<BoxType> show(
|
|
|
|
object_ptr<BoxType> content,
|
|
|
|
LayerOptions options = LayerOption::KeepOther,
|
|
|
|
anim::type animated = anim::type::normal) {
|
|
|
|
auto result = QPointer<BoxType>(content.data());
|
|
|
|
showBox(std::move(content), options, animated);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
};
|
|
|
|
|
2017-09-13 16:57:44 +00:00
|
|
|
class BoxContent : public Ui::RpWidget, protected base::Subscriber {
|
2015-04-02 10:33:19 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent() {
|
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isBoxShown() const {
|
|
|
|
return getDelegate()->isBoxShown();
|
|
|
|
}
|
|
|
|
void closeBox() {
|
|
|
|
getDelegate()->closeBox();
|
|
|
|
}
|
2016-04-21 17:57:29 +00:00
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
void setTitle(Fn<QString()> titleFactory) {
|
2017-05-30 15:21:05 +00:00
|
|
|
if (titleFactory) {
|
|
|
|
getDelegate()->setTitle([titleFactory] { return TextWithEntities { titleFactory(), EntitiesInText() }; });
|
|
|
|
} else {
|
2018-06-04 15:35:11 +00:00
|
|
|
getDelegate()->setTitle(Fn<TextWithEntities()>());
|
2017-05-30 15:21:05 +00:00
|
|
|
}
|
2017-05-17 14:32:36 +00:00
|
|
|
}
|
2018-06-04 15:35:11 +00:00
|
|
|
void setTitle(Fn<TextWithEntities()> titleFactory) {
|
2017-05-30 15:21:05 +00:00
|
|
|
getDelegate()->setTitle(std::move(titleFactory));
|
2017-05-17 14:32:36 +00:00
|
|
|
}
|
2018-06-04 15:35:11 +00:00
|
|
|
void setAdditionalTitle(Fn<QString()> additional) {
|
2017-05-30 15:21:05 +00:00
|
|
|
getDelegate()->setAdditionalTitle(std::move(additional));
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
2018-06-06 11:51:27 +00:00
|
|
|
void setCloseByEscape(bool close) {
|
|
|
|
_closeByEscape = close;
|
|
|
|
}
|
|
|
|
void setCloseByOutsideClick(bool close) {
|
|
|
|
getDelegate()->setCloseByOutsideClick(close);
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
|
2017-11-10 17:15:37 +00:00
|
|
|
void scrollToWidget(not_null<QWidget*> widget);
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void clearButtons() {
|
|
|
|
getDelegate()->clearButtons();
|
|
|
|
}
|
2018-06-04 15:35:11 +00:00
|
|
|
QPointer<Ui::RoundButton> addButton(Fn<QString()> textFactory, Fn<void()> clickCallback);
|
|
|
|
QPointer<Ui::RoundButton> addLeftButton(Fn<QString()> textFactory, Fn<void()> clickCallback);
|
|
|
|
QPointer<Ui::RoundButton> addButton(Fn<QString()> textFactory, Fn<void()> clickCallback, const style::RoundButton &st) {
|
2017-05-30 15:21:05 +00:00
|
|
|
return getDelegate()->addButton(std::move(textFactory), std::move(clickCallback), st);
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
void updateButtonsGeometry() {
|
|
|
|
getDelegate()->updateButtonsPositions();
|
|
|
|
}
|
|
|
|
|
2017-03-13 15:40:21 +00:00
|
|
|
virtual void setInnerFocus() {
|
|
|
|
setFocus();
|
|
|
|
}
|
2017-08-13 16:09:14 +00:00
|
|
|
|
2018-03-29 19:49:31 +00:00
|
|
|
rpl::producer<> boxClosing() const {
|
|
|
|
return _boxClosingStream.events();
|
|
|
|
}
|
|
|
|
void notifyBoxClosing() {
|
|
|
|
_boxClosingStream.fire({});
|
|
|
|
}
|
2017-03-13 15:40:21 +00:00
|
|
|
|
|
|
|
void setDelegate(BoxContentDelegate *newDelegate) {
|
|
|
|
_delegate = newDelegate;
|
2017-07-10 16:13:40 +00:00
|
|
|
_preparing = true;
|
2017-03-13 15:40:21 +00:00
|
|
|
prepare();
|
2017-07-10 16:13:40 +00:00
|
|
|
finishPrepare();
|
2017-03-13 15:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void onScrollToY(int top, int bottom = -1);
|
|
|
|
|
|
|
|
void onDraggingScrollDelta(int delta);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void prepare() = 0;
|
|
|
|
|
|
|
|
void setLayerType(bool layerType) {
|
|
|
|
getDelegate()->setLayerType(layerType);
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void setNoContentMargin(bool noContentMargin) {
|
|
|
|
if (_noContentMargin != noContentMargin) {
|
|
|
|
_noContentMargin = noContentMargin;
|
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent, !_noContentMargin);
|
|
|
|
}
|
|
|
|
getDelegate()->setNoContentMargin(noContentMargin);
|
|
|
|
}
|
|
|
|
void setDimensions(int newWidth, int maxHeight) {
|
|
|
|
getDelegate()->setDimensions(newWidth, maxHeight);
|
|
|
|
}
|
|
|
|
void setInnerTopSkip(int topSkip, bool scrollBottomFixed = false);
|
2018-04-28 14:06:59 +00:00
|
|
|
void setInnerBottomSkip(int bottomSkip);
|
2016-12-13 17:07:56 +00:00
|
|
|
|
|
|
|
template <typename Widget>
|
2018-04-28 14:06:59 +00:00
|
|
|
QPointer<Widget> setInnerWidget(
|
|
|
|
object_ptr<Widget> inner,
|
|
|
|
const style::ScrollArea &st,
|
|
|
|
int topSkip = 0,
|
|
|
|
int bottomSkip = 0) {
|
2016-12-13 17:07:56 +00:00
|
|
|
auto result = QPointer<Widget>(inner.data());
|
|
|
|
setInnerTopSkip(topSkip);
|
2018-04-28 14:06:59 +00:00
|
|
|
setInnerBottomSkip(bottomSkip);
|
2017-02-21 13:45:56 +00:00
|
|
|
setInner(std::move(inner), st);
|
2016-12-13 17:07:56 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Widget>
|
2018-04-28 14:06:59 +00:00
|
|
|
QPointer<Widget> setInnerWidget(
|
|
|
|
object_ptr<Widget> inner,
|
|
|
|
int topSkip = 0,
|
|
|
|
int bottomSkip = 0) {
|
2016-12-13 17:07:56 +00:00
|
|
|
auto result = QPointer<Widget>(inner.data());
|
|
|
|
setInnerTopSkip(topSkip);
|
2018-04-28 14:06:59 +00:00
|
|
|
setInnerBottomSkip(bottomSkip);
|
2017-02-21 13:45:56 +00:00
|
|
|
setInner(std::move(inner));
|
2016-12-13 17:07:56 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Widget>
|
|
|
|
object_ptr<Widget> takeInnerWidget() {
|
|
|
|
return static_object_cast<Widget>(doTakeInnerWidget());
|
|
|
|
}
|
|
|
|
|
|
|
|
void setInnerVisible(bool scrollAreaVisible);
|
|
|
|
QPixmap grabInnerCache();
|
|
|
|
|
2016-08-16 16:53:10 +00:00
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
2018-06-06 11:51:27 +00:00
|
|
|
void keyPressEvent(QKeyEvent *e) override;
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2018-04-16 17:02:40 +00:00
|
|
|
not_null<BoxContentDelegate*> getDelegate() const {
|
|
|
|
return _delegate;
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
private slots:
|
|
|
|
void onScroll();
|
2016-12-21 15:05:58 +00:00
|
|
|
void onInnerResize();
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void onDraggingScrollTimer();
|
2015-04-02 10:33:19 +00:00
|
|
|
|
|
|
|
private:
|
2017-07-10 16:13:40 +00:00
|
|
|
void finishPrepare();
|
|
|
|
void finishScrollCreate();
|
2016-12-13 17:07:56 +00:00
|
|
|
void setInner(object_ptr<TWidget> inner);
|
|
|
|
void setInner(object_ptr<TWidget> inner, const style::ScrollArea &st);
|
|
|
|
void updateScrollAreaGeometry();
|
2016-12-20 13:03:51 +00:00
|
|
|
void updateInnerVisibleTopBottom();
|
2016-12-21 15:05:58 +00:00
|
|
|
void updateShadowsVisibility();
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<TWidget> doTakeInnerWidget();
|
|
|
|
|
|
|
|
BoxContentDelegate *_delegate = nullptr;
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2017-07-10 16:13:40 +00:00
|
|
|
bool _preparing = false;
|
2016-12-13 17:07:56 +00:00
|
|
|
bool _noContentMargin = false;
|
2018-06-06 11:51:27 +00:00
|
|
|
bool _closeByEscape = true;
|
2016-12-13 17:07:56 +00:00
|
|
|
int _innerTopSkip = 0;
|
2018-04-28 14:06:59 +00:00
|
|
|
int _innerBottomSkip = 0;
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<Ui::ScrollArea> _scroll = { nullptr };
|
2017-09-30 18:26:45 +00:00
|
|
|
object_ptr<Ui::FadeShadow> _topShadow = { nullptr };
|
|
|
|
object_ptr<Ui::FadeShadow> _bottomShadow = { nullptr };
|
2016-11-22 09:48:13 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<QTimer> _draggingScrollTimer = { nullptr };
|
|
|
|
int _draggingScrollDelta = 0;
|
2016-08-16 16:53:10 +00:00
|
|
|
|
2018-03-29 19:49:31 +00:00
|
|
|
rpl::event_stream<> _boxClosingStream;
|
|
|
|
|
2015-10-11 08:37:24 +00:00
|
|
|
};
|
|
|
|
|
2017-09-30 18:26:45 +00:00
|
|
|
class AbstractBox
|
|
|
|
: public Window::LayerWidget
|
|
|
|
, public BoxContentDelegate
|
|
|
|
, protected base::Subscriber {
|
2015-10-11 08:37:24 +00:00
|
|
|
public:
|
2018-04-16 17:02:40 +00:00
|
|
|
AbstractBox(
|
|
|
|
not_null<Window::LayerStackWidget*> layer,
|
|
|
|
object_ptr<BoxContent> content);
|
2016-11-08 14:43:10 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void parentResized() override;
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void setLayerType(bool layerType) override;
|
2018-06-04 15:35:11 +00:00
|
|
|
void setTitle(Fn<TextWithEntities()> titleFactory) override;
|
|
|
|
void setAdditionalTitle(Fn<QString()> additionalFactory) override;
|
2018-04-16 17:02:40 +00:00
|
|
|
void showBox(
|
|
|
|
object_ptr<BoxContent> box,
|
|
|
|
LayerOptions options,
|
|
|
|
anim::type animated) override;
|
2016-04-21 17:57:29 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void clearButtons() override;
|
2018-06-04 15:35:11 +00:00
|
|
|
QPointer<Ui::RoundButton> addButton(Fn<QString()> textFactory, Fn<void()> clickCallback, const style::RoundButton &st) override;
|
|
|
|
QPointer<Ui::RoundButton> addLeftButton(Fn<QString()> textFactory, Fn<void()> clickCallback, const style::RoundButton &st) override;
|
2016-12-13 17:07:56 +00:00
|
|
|
void updateButtonsPositions() override;
|
|
|
|
|
|
|
|
void setDimensions(int newWidth, int maxHeight) override;
|
|
|
|
|
|
|
|
void setNoContentMargin(bool noContentMargin) override {
|
|
|
|
if (_noContentMargin != noContentMargin) {
|
|
|
|
_noContentMargin = noContentMargin;
|
|
|
|
updateSize();
|
|
|
|
}
|
|
|
|
}
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
bool isBoxShown() const override {
|
|
|
|
return !isHidden();
|
|
|
|
}
|
|
|
|
void closeBox() override {
|
|
|
|
closeLayer();
|
|
|
|
}
|
|
|
|
|
2018-06-06 11:51:27 +00:00
|
|
|
void setCloseByOutsideClick(bool close) override;
|
|
|
|
bool closeByOutsideClick() const override;
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
protected:
|
|
|
|
void keyPressEvent(QKeyEvent *e) override;
|
2016-09-06 12:28:37 +00:00
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
2016-12-13 17:07:56 +00:00
|
|
|
void paintEvent(QPaintEvent *e) override;
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void doSetInnerFocus() override {
|
|
|
|
_content->setInnerFocus();
|
|
|
|
}
|
|
|
|
void closeHook() override {
|
2018-03-29 19:49:31 +00:00
|
|
|
_content->notifyBoxClosing();
|
2016-09-06 12:28:37 +00:00
|
|
|
}
|
2015-04-02 10:33:19 +00:00
|
|
|
|
|
|
|
private:
|
2017-05-17 14:32:36 +00:00
|
|
|
void paintAdditionalTitle(Painter &p);
|
|
|
|
void updateTitlePosition();
|
2017-05-30 15:21:05 +00:00
|
|
|
void refreshTitle();
|
|
|
|
void refreshAdditionalTitle();
|
|
|
|
void refreshLang();
|
2016-10-20 19:48:35 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
bool hasTitle() const;
|
|
|
|
int titleHeight() const;
|
|
|
|
int buttonsHeight() const;
|
|
|
|
int buttonsTop() const;
|
|
|
|
int contentTop() const;
|
|
|
|
int countFullHeight() const;
|
|
|
|
int countRealHeight() const;
|
|
|
|
void updateSize();
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2018-04-16 17:02:40 +00:00
|
|
|
not_null<Window::LayerStackWidget*> _layer;
|
2016-12-13 17:07:56 +00:00
|
|
|
int _fullHeight = 0;
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
bool _noContentMargin = false;
|
|
|
|
int _maxContentHeight = 0;
|
|
|
|
object_ptr<BoxContent> _content;
|
|
|
|
|
2017-05-17 14:32:36 +00:00
|
|
|
object_ptr<Ui::FlatLabel> _title = { nullptr };
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<TextWithEntities()> _titleFactory;
|
2016-12-13 17:07:56 +00:00
|
|
|
QString _additionalTitle;
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<QString()> _additionalTitleFactory;
|
2017-05-17 14:32:36 +00:00
|
|
|
int _titleLeft = 0;
|
|
|
|
int _titleTop = 0;
|
2016-12-13 17:07:56 +00:00
|
|
|
bool _layerType = false;
|
2018-06-06 11:51:27 +00:00
|
|
|
bool _closeByOutsideClick = true;
|
2016-12-13 17:07:56 +00:00
|
|
|
|
2017-02-21 13:45:56 +00:00
|
|
|
std::vector<object_ptr<Ui::RoundButton>> _buttons;
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<Ui::RoundButton> _leftButton = { nullptr };
|
2015-10-11 08:37:24 +00:00
|
|
|
|
|
|
|
};
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
class BoxContentDivider : public Ui::RpWidget {
|
2017-08-05 20:01:20 +00:00
|
|
|
public:
|
|
|
|
BoxContentDivider(QWidget *parent);
|
2018-03-31 01:45:40 +00:00
|
|
|
BoxContentDivider(QWidget *parent, int height);
|
2017-08-05 20:01:20 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2015-10-11 08:37:24 +00:00
|
|
|
enum CreatingGroupType {
|
|
|
|
CreatingGroupNone,
|
|
|
|
CreatingGroupGroup,
|
|
|
|
CreatingGroupChannel,
|
2015-10-03 10:09:09 +00:00
|
|
|
};
|