Allow adding any buttons to BoxContent.
This commit is contained in:
parent
96279cc04d
commit
c468f8b3c6
4 changed files with 111 additions and 88 deletions
|
|
@ -24,6 +24,13 @@ void BoxContent::setTitle(rpl::producer<QString> title) {
|
||||||
getDelegate()->setTitle(std::move(title) | Text::ToWithEntities());
|
getDelegate()->setTitle(std::move(title) | Text::ToWithEntities());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPointer<AbstractButton> BoxContent::addButton(
|
||||||
|
object_ptr<AbstractButton> button) {
|
||||||
|
auto result = QPointer<AbstractButton>(button.data());
|
||||||
|
getDelegate()->addButton(std::move(button));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
QPointer<RoundButton> BoxContent::addButton(
|
QPointer<RoundButton> BoxContent::addButton(
|
||||||
rpl::producer<QString> text,
|
rpl::producer<QString> text,
|
||||||
Fn<void()> clickCallback) {
|
Fn<void()> clickCallback) {
|
||||||
|
|
@ -33,15 +40,69 @@ QPointer<RoundButton> BoxContent::addButton(
|
||||||
getDelegate()->style().button);
|
getDelegate()->style().button);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPointer<RoundButton> BoxContent::addButton(
|
||||||
|
rpl::producer<QString> text,
|
||||||
|
const style::RoundButton &st) {
|
||||||
|
return addButton(std::move(text), nullptr, st);
|
||||||
|
}
|
||||||
|
|
||||||
|
QPointer<RoundButton> BoxContent::addButton(
|
||||||
|
rpl::producer<QString> text,
|
||||||
|
Fn<void()> clickCallback,
|
||||||
|
const style::RoundButton &st) {
|
||||||
|
auto button = object_ptr<RoundButton>(this, std::move(text), st);
|
||||||
|
auto result = QPointer<RoundButton>(button.data());
|
||||||
|
result->setTextTransform(RoundButton::TextTransform::NoTransform);
|
||||||
|
result->setClickedCallback(std::move(clickCallback));
|
||||||
|
getDelegate()->addButton(std::move(button));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPointer<AbstractButton> BoxContent::addLeftButton(
|
||||||
|
object_ptr<AbstractButton> button) {
|
||||||
|
auto result = QPointer<AbstractButton>(button.data());
|
||||||
|
getDelegate()->addLeftButton(std::move(button));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
QPointer<RoundButton> BoxContent::addLeftButton(
|
QPointer<RoundButton> BoxContent::addLeftButton(
|
||||||
rpl::producer<QString> text,
|
rpl::producer<QString> text,
|
||||||
Fn<void()> clickCallback) {
|
Fn<void()> clickCallback) {
|
||||||
return getDelegate()->addLeftButton(
|
return addLeftButton(
|
||||||
std::move(text),
|
std::move(text),
|
||||||
std::move(clickCallback),
|
std::move(clickCallback),
|
||||||
getDelegate()->style().button);
|
getDelegate()->style().button);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPointer<RoundButton> BoxContent::addLeftButton(
|
||||||
|
rpl::producer<QString> text,
|
||||||
|
Fn<void()> clickCallback,
|
||||||
|
const style::RoundButton &st) {
|
||||||
|
auto button = object_ptr<RoundButton>(this, std::move(text), st);
|
||||||
|
const auto result = QPointer<RoundButton>(button.data());
|
||||||
|
result->setTextTransform(RoundButton::TextTransform::NoTransform);
|
||||||
|
result->setClickedCallback(std::move(clickCallback));
|
||||||
|
getDelegate()->addLeftButton(std::move(button));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPointer<AbstractButton> BoxContent::addTopButton(
|
||||||
|
object_ptr<AbstractButton> button) {
|
||||||
|
auto result = QPointer<AbstractButton>(button.data());
|
||||||
|
getDelegate()->addTopButton(std::move(button));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPointer<IconButton> BoxContent::addTopButton(
|
||||||
|
const style::IconButton &st,
|
||||||
|
Fn<void()> clickCallback) {
|
||||||
|
auto button = object_ptr<IconButton>(this, st);
|
||||||
|
const auto result = QPointer<IconButton>(button.data());
|
||||||
|
result->setClickedCallback(std::move(clickCallback));
|
||||||
|
getDelegate()->addTopButton(std::move(button));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void BoxContent::setInner(object_ptr<TWidget> inner) {
|
void BoxContent::setInner(object_ptr<TWidget> inner) {
|
||||||
setInner(std::move(inner), st::boxScroll);
|
setInner(std::move(inner), st::boxScroll);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ inline object_ptr<BoxType> Box(Args &&...args) {
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
|
||||||
|
class AbstractButton;
|
||||||
class RoundButton;
|
class RoundButton;
|
||||||
class IconButton;
|
class IconButton;
|
||||||
class ScrollArea;
|
class ScrollArea;
|
||||||
|
|
@ -60,17 +61,9 @@ public:
|
||||||
virtual void setCloseByOutsideClick(bool close) = 0;
|
virtual void setCloseByOutsideClick(bool close) = 0;
|
||||||
|
|
||||||
virtual void clearButtons() = 0;
|
virtual void clearButtons() = 0;
|
||||||
virtual QPointer<RoundButton> addButton(
|
virtual void addButton(object_ptr<AbstractButton> button) = 0;
|
||||||
rpl::producer<QString> text,
|
virtual void addLeftButton(object_ptr<AbstractButton> button) = 0;
|
||||||
Fn<void()> clickCallback,
|
virtual void addTopButton(object_ptr<AbstractButton> button) = 0;
|
||||||
const style::RoundButton &st) = 0;
|
|
||||||
virtual QPointer<RoundButton> addLeftButton(
|
|
||||||
rpl::producer<QString> text,
|
|
||||||
Fn<void()> clickCallback,
|
|
||||||
const style::RoundButton &st) = 0;
|
|
||||||
virtual QPointer<IconButton> addTopButton(
|
|
||||||
const style::IconButton &st,
|
|
||||||
Fn<void()> clickCallback) = 0;
|
|
||||||
virtual void showLoading(bool show) = 0;
|
virtual void showLoading(bool show) = 0;
|
||||||
virtual void updateButtonsPositions() = 0;
|
virtual void updateButtonsPositions() = 0;
|
||||||
|
|
||||||
|
|
@ -141,40 +134,31 @@ public:
|
||||||
void clearButtons() {
|
void clearButtons() {
|
||||||
getDelegate()->clearButtons();
|
getDelegate()->clearButtons();
|
||||||
}
|
}
|
||||||
|
QPointer<AbstractButton> addButton(object_ptr<AbstractButton> button);
|
||||||
QPointer<RoundButton> addButton(
|
QPointer<RoundButton> addButton(
|
||||||
rpl::producer<QString> text,
|
rpl::producer<QString> text,
|
||||||
Fn<void()> clickCallback = nullptr);
|
Fn<void()> clickCallback = nullptr);
|
||||||
|
QPointer<RoundButton> addButton(
|
||||||
|
rpl::producer<QString> text,
|
||||||
|
const style::RoundButton &st);
|
||||||
|
QPointer<RoundButton> addButton(
|
||||||
|
rpl::producer<QString> text,
|
||||||
|
Fn<void()> clickCallback,
|
||||||
|
const style::RoundButton &st);
|
||||||
|
QPointer<AbstractButton> addLeftButton(
|
||||||
|
object_ptr<AbstractButton> button);
|
||||||
|
QPointer<RoundButton> addLeftButton(
|
||||||
|
rpl::producer<QString> text,
|
||||||
|
Fn<void()> clickCallback = nullptr);
|
||||||
QPointer<RoundButton> addLeftButton(
|
QPointer<RoundButton> addLeftButton(
|
||||||
rpl::producer<QString> text,
|
rpl::producer<QString> text,
|
||||||
Fn<void()> clickCallback = nullptr);
|
Fn<void()> clickCallback,
|
||||||
|
const style::RoundButton& st);
|
||||||
|
QPointer<AbstractButton> addTopButton(
|
||||||
|
object_ptr<AbstractButton> button);
|
||||||
QPointer<IconButton> addTopButton(
|
QPointer<IconButton> addTopButton(
|
||||||
const style::IconButton &st,
|
const style::IconButton &st,
|
||||||
Fn<void()> clickCallback = nullptr) {
|
Fn<void()> clickCallback = nullptr);
|
||||||
return getDelegate()->addTopButton(st, std::move(clickCallback));
|
|
||||||
}
|
|
||||||
QPointer<RoundButton> addButton(
|
|
||||||
rpl::producer<QString> text,
|
|
||||||
const style::RoundButton &st) {
|
|
||||||
return getDelegate()->addButton(std::move(text), nullptr, st);
|
|
||||||
}
|
|
||||||
QPointer<RoundButton> addButton(
|
|
||||||
rpl::producer<QString> text,
|
|
||||||
Fn<void()> clickCallback,
|
|
||||||
const style::RoundButton &st) {
|
|
||||||
return getDelegate()->addButton(
|
|
||||||
std::move(text),
|
|
||||||
std::move(clickCallback),
|
|
||||||
st);
|
|
||||||
}
|
|
||||||
QPointer<RoundButton> addLeftButton(
|
|
||||||
rpl::producer<QString> text,
|
|
||||||
Fn<void()> clickCallback,
|
|
||||||
const style::RoundButton& st) {
|
|
||||||
return getDelegate()->addLeftButton(
|
|
||||||
std::move(text),
|
|
||||||
std::move(clickCallback),
|
|
||||||
st);
|
|
||||||
}
|
|
||||||
void showLoading(bool show) {
|
void showLoading(bool show) {
|
||||||
getDelegate()->showLoading(show);
|
getDelegate()->showLoading(show);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -263,46 +263,35 @@ void BoxLayerWidget::clearButtons() {
|
||||||
_topButton = nullptr;
|
_topButton = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointer<RoundButton> BoxLayerWidget::addButton(
|
void BoxLayerWidget::addButton(object_ptr<AbstractButton> button) {
|
||||||
rpl::producer<QString> text,
|
_buttons.push_back(std::move(button));
|
||||||
Fn<void()> clickCallback,
|
const auto raw = _buttons.back().data();
|
||||||
const style::RoundButton &st) {
|
raw->setParent(this);
|
||||||
_buttons.emplace_back(this, std::move(text), st);
|
raw->show();
|
||||||
auto result = QPointer<RoundButton>(_buttons.back());
|
raw->widthValue(
|
||||||
result->setTextTransform(RoundButton::TextTransform::NoTransform);
|
|
||||||
result->setClickedCallback(std::move(clickCallback));
|
|
||||||
result->show();
|
|
||||||
result->widthValue(
|
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
updateButtonsPositions();
|
updateButtonsPositions();
|
||||||
}, result->lifetime());
|
}, raw->lifetime());
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointer<RoundButton> BoxLayerWidget::addLeftButton(
|
void BoxLayerWidget::addLeftButton(object_ptr<AbstractButton> button) {
|
||||||
rpl::producer<QString> text,
|
_leftButton = std::move(button);
|
||||||
Fn<void()> clickCallback,
|
const auto raw = _leftButton.data();
|
||||||
const style::RoundButton &st) {
|
raw->setParent(this);
|
||||||
_leftButton = object_ptr<RoundButton>(this, std::move(text), st);
|
raw->show();
|
||||||
auto result = QPointer<RoundButton>(_leftButton);
|
raw->widthValue(
|
||||||
result->setTextTransform(RoundButton::TextTransform::NoTransform);
|
|
||||||
result->setClickedCallback(std::move(clickCallback));
|
|
||||||
result->show();
|
|
||||||
result->widthValue(
|
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
updateButtonsPositions();
|
updateButtonsPositions();
|
||||||
}, result->lifetime());
|
}, raw->lifetime());
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointer<IconButton> BoxLayerWidget::addTopButton(const style::IconButton &st, Fn<void()> clickCallback) {
|
void BoxLayerWidget::addTopButton(object_ptr<AbstractButton> button) {
|
||||||
_topButton = base::make_unique_q<IconButton>(this, st);
|
_topButton = base::make_unique_q<AbstractButton>(button.release());
|
||||||
auto result = QPointer<IconButton>(_topButton.get());
|
const auto raw = _topButton.get();
|
||||||
result->setClickedCallback(std::move(clickCallback));
|
raw->setParent(this);
|
||||||
result->show();
|
raw->show();
|
||||||
updateButtonsPositions();
|
updateButtonsPositions();
|
||||||
updateTitlePosition();
|
updateTitlePosition();
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoxLayerWidget::showLoading(bool show) {
|
void BoxLayerWidget::showLoading(bool show) {
|
||||||
|
|
|
||||||
|
|
@ -21,15 +21,12 @@ enum class type : uchar;
|
||||||
} // namespace anim
|
} // namespace anim
|
||||||
|
|
||||||
namespace style {
|
namespace style {
|
||||||
struct RoundButton;
|
|
||||||
struct IconButton;
|
|
||||||
struct Box;
|
struct Box;
|
||||||
} // namespace style
|
} // namespace style
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
|
||||||
class RoundButton;
|
class AbstractButton;
|
||||||
class IconButton;
|
|
||||||
class FlatLabel;
|
class FlatLabel;
|
||||||
|
|
||||||
class BoxLayerWidget : public LayerWidget, public BoxContentDelegate {
|
class BoxLayerWidget : public LayerWidget, public BoxContentDelegate {
|
||||||
|
|
@ -56,17 +53,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearButtons() override;
|
void clearButtons() override;
|
||||||
QPointer<RoundButton> addButton(
|
void addButton(object_ptr<AbstractButton> button) override;
|
||||||
rpl::producer<QString> text,
|
void addLeftButton(object_ptr<AbstractButton> button) override;
|
||||||
Fn<void()> clickCallback,
|
void addTopButton(object_ptr<AbstractButton> button) override;
|
||||||
const style::RoundButton &st) override;
|
|
||||||
QPointer<RoundButton> addLeftButton(
|
|
||||||
rpl::producer<QString> text,
|
|
||||||
Fn<void()> clickCallback,
|
|
||||||
const style::RoundButton &st) override;
|
|
||||||
QPointer<IconButton> addTopButton(
|
|
||||||
const style::IconButton &st,
|
|
||||||
Fn<void()> clickCallback) override;
|
|
||||||
void showLoading(bool show) override;
|
void showLoading(bool show) override;
|
||||||
void updateButtonsPositions() override;
|
void updateButtonsPositions() override;
|
||||||
QPointer<QWidget> outerContainer() override;
|
QPointer<QWidget> outerContainer() override;
|
||||||
|
|
@ -141,9 +130,9 @@ private:
|
||||||
int _titleTop = 0;
|
int _titleTop = 0;
|
||||||
bool _closeByOutsideClick = true;
|
bool _closeByOutsideClick = true;
|
||||||
|
|
||||||
std::vector<object_ptr<RoundButton>> _buttons;
|
std::vector<object_ptr<AbstractButton>> _buttons;
|
||||||
object_ptr<RoundButton> _leftButton = { nullptr };
|
object_ptr<AbstractButton> _leftButton = { nullptr };
|
||||||
base::unique_qptr<IconButton> _topButton = { nullptr };
|
base::unique_qptr<AbstractButton> _topButton = { nullptr };
|
||||||
std::unique_ptr<LoadingProgress> _loadingProgress;
|
std::unique_ptr<LoadingProgress> _loadingProgress;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue