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
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
class BoxContentDelegate {
|
|
|
|
public:
|
|
|
|
virtual void setLayerType(bool layerType) = 0;
|
2017-05-30 15:21:05 +00:00
|
|
|
virtual void setTitle(base::lambda<TextWithEntities()> titleFactory) = 0;
|
|
|
|
virtual void setAdditionalTitle(base::lambda<QString()> additionalFactory) = 0;
|
2016-12-13 17:07:56 +00:00
|
|
|
|
|
|
|
virtual void clearButtons() = 0;
|
2017-05-30 15:21:05 +00:00
|
|
|
virtual QPointer<Ui::RoundButton> addButton(base::lambda<QString()> textFactory, base::lambda<void()> clickCallback, const style::RoundButton &st) = 0;
|
|
|
|
virtual QPointer<Ui::RoundButton> addLeftButton(base::lambda<QString()> textFactory, base::lambda<void()> clickCallback, const style::RoundButton &st) = 0;
|
2016-12-13 17:07:56 +00:00
|
|
|
virtual void updateButtonsPositions() = 0;
|
|
|
|
|
|
|
|
virtual void setDimensions(int newWidth, int maxHeight) = 0;
|
|
|
|
virtual void setNoContentMargin(bool noContentMargin) = 0;
|
|
|
|
virtual bool isBoxShown() const = 0;
|
|
|
|
virtual void closeBox() = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2017-05-30 15:21:05 +00:00
|
|
|
void setTitle(base::lambda<QString()> titleFactory) {
|
|
|
|
if (titleFactory) {
|
|
|
|
getDelegate()->setTitle([titleFactory] { return TextWithEntities { titleFactory(), EntitiesInText() }; });
|
|
|
|
} else {
|
|
|
|
getDelegate()->setTitle(base::lambda<TextWithEntities()>());
|
|
|
|
}
|
2017-05-17 14:32:36 +00:00
|
|
|
}
|
2017-05-30 15:21:05 +00:00
|
|
|
void setTitle(base::lambda<TextWithEntities()> titleFactory) {
|
|
|
|
getDelegate()->setTitle(std::move(titleFactory));
|
2017-05-17 14:32:36 +00:00
|
|
|
}
|
2017-05-30 15:21:05 +00:00
|
|
|
void setAdditionalTitle(base::lambda<QString()> additional) {
|
|
|
|
getDelegate()->setAdditionalTitle(std::move(additional));
|
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();
|
|
|
|
}
|
2017-05-30 15:21:05 +00:00
|
|
|
QPointer<Ui::RoundButton> addButton(base::lambda<QString()> textFactory, base::lambda<void()> clickCallback);
|
|
|
|
QPointer<Ui::RoundButton> addLeftButton(base::lambda<QString()> textFactory, base::lambda<void()> clickCallback);
|
|
|
|
QPointer<Ui::RoundButton> addButton(base::lambda<QString()> textFactory, base::lambda<void()> clickCallback, const style::RoundButton &st) {
|
|
|
|
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;
|
2015-04-02 10:33:19 +00:00
|
|
|
|
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 *getDelegate() const {
|
2017-04-07 18:10:49 +00:00
|
|
|
Expects(_delegate != nullptr);
|
2016-12-13 17:07:56 +00:00
|
|
|
return _delegate;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
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-06 16:23:09 +00:00
|
|
|
AbstractBox(QWidget *parent, 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;
|
2017-05-30 15:21:05 +00:00
|
|
|
void setTitle(base::lambda<TextWithEntities()> titleFactory) override;
|
|
|
|
void setAdditionalTitle(base::lambda<QString()> additionalFactory) override;
|
2016-04-21 17:57:29 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void clearButtons() override;
|
2017-05-30 15:21:05 +00:00
|
|
|
QPointer<Ui::RoundButton> addButton(base::lambda<QString()> textFactory, base::lambda<void()> clickCallback, const style::RoundButton &st) override;
|
|
|
|
QPointer<Ui::RoundButton> addLeftButton(base::lambda<QString()> textFactory, base::lambda<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();
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
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 };
|
2017-05-30 15:21:05 +00:00
|
|
|
base::lambda<TextWithEntities()> _titleFactory;
|
2016-12-13 17:07:56 +00:00
|
|
|
QString _additionalTitle;
|
2017-05-30 15:21:05 +00:00
|
|
|
base::lambda<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;
|
|
|
|
|
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
|
|
|
};
|