Allow boxes that don't hide by escape / click.

This commit is contained in:
John Preston 2018-06-06 14:51:27 +03:00
parent e47d110f28
commit 16f3ca87f5
5 changed files with 46 additions and 5 deletions

View File

@ -32,8 +32,8 @@ QPointer<Ui::RoundButton> BoxContent::addLeftButton(
Fn<QString()> textFactory, Fn<QString()> textFactory,
Fn<void()> clickCallback) { Fn<void()> clickCallback) {
return getDelegate()->addLeftButton( return getDelegate()->addLeftButton(
std::move(textFactory), std::move(textFactory),
std::move(clickCallback), std::move(clickCallback),
st::defaultBoxButton); st::defaultBoxButton);
} }
@ -190,6 +190,14 @@ void BoxContent::resizeEvent(QResizeEvent *e) {
} }
} }
void BoxContent::keyPressEvent(QKeyEvent *e) {
if (e->key() == Qt::Key_Escape && !_closeByEscape) {
e->accept();
} else {
RpWidget::keyPressEvent(e);
}
}
void BoxContent::updateScrollAreaGeometry() { void BoxContent::updateScrollAreaGeometry() {
auto newScrollHeight = height() - _innerTopSkip - _innerBottomSkip; auto newScrollHeight = height() - _innerTopSkip - _innerBottomSkip;
auto changed = (_scroll->height() != newScrollHeight); auto changed = (_scroll->height() != newScrollHeight);
@ -316,6 +324,14 @@ void AbstractBox::setAdditionalTitle(Fn<QString()> additionalFactory) {
refreshAdditionalTitle(); refreshAdditionalTitle();
} }
void AbstractBox::setCloseByOutsideClick(bool close) {
_closeByOutsideClick = close;
}
bool AbstractBox::closeByOutsideClick() const {
return _closeByOutsideClick;
}
void AbstractBox::refreshAdditionalTitle() { void AbstractBox::refreshAdditionalTitle() {
_additionalTitle = _additionalTitleFactory ? _additionalTitleFactory() : QString(); _additionalTitle = _additionalTitleFactory ? _additionalTitleFactory() : QString();
update(); update();

View File

@ -30,6 +30,7 @@ public:
virtual void setLayerType(bool layerType) = 0; virtual void setLayerType(bool layerType) = 0;
virtual void setTitle(Fn<TextWithEntities()> titleFactory) = 0; virtual void setTitle(Fn<TextWithEntities()> titleFactory) = 0;
virtual void setAdditionalTitle(Fn<QString()> additionalFactory) = 0; virtual void setAdditionalTitle(Fn<QString()> additionalFactory) = 0;
virtual void setCloseByOutsideClick(bool close) = 0;
virtual void clearButtons() = 0; virtual void clearButtons() = 0;
virtual QPointer<Ui::RoundButton> addButton(Fn<QString()> textFactory, Fn<void()> clickCallback, const style::RoundButton &st) = 0; virtual QPointer<Ui::RoundButton> addButton(Fn<QString()> textFactory, Fn<void()> clickCallback, const style::RoundButton &st) = 0;
@ -85,6 +86,12 @@ public:
void setAdditionalTitle(Fn<QString()> additional) { void setAdditionalTitle(Fn<QString()> additional) {
getDelegate()->setAdditionalTitle(std::move(additional)); getDelegate()->setAdditionalTitle(std::move(additional));
} }
void setCloseByEscape(bool close) {
_closeByEscape = close;
}
void setCloseByOutsideClick(bool close) {
getDelegate()->setCloseByOutsideClick(close);
}
void scrollToWidget(not_null<QWidget*> widget); void scrollToWidget(not_null<QWidget*> widget);
@ -178,6 +185,7 @@ protected:
void resizeEvent(QResizeEvent *e) override; void resizeEvent(QResizeEvent *e) override;
void paintEvent(QPaintEvent *e) override; void paintEvent(QPaintEvent *e) override;
void keyPressEvent(QKeyEvent *e) override;
not_null<BoxContentDelegate*> getDelegate() const { not_null<BoxContentDelegate*> getDelegate() const {
return _delegate; return _delegate;
@ -203,6 +211,7 @@ private:
bool _preparing = false; bool _preparing = false;
bool _noContentMargin = false; bool _noContentMargin = false;
bool _closeByEscape = true;
int _innerTopSkip = 0; int _innerTopSkip = 0;
int _innerBottomSkip = 0; int _innerBottomSkip = 0;
object_ptr<Ui::ScrollArea> _scroll = { nullptr }; object_ptr<Ui::ScrollArea> _scroll = { nullptr };
@ -256,6 +265,9 @@ public:
closeLayer(); closeLayer();
} }
void setCloseByOutsideClick(bool close) override;
bool closeByOutsideClick() const override;
protected: protected:
void keyPressEvent(QKeyEvent *e) override; void keyPressEvent(QKeyEvent *e) override;
void resizeEvent(QResizeEvent *e) override; void resizeEvent(QResizeEvent *e) override;
@ -298,6 +310,7 @@ private:
int _titleLeft = 0; int _titleLeft = 0;
int _titleTop = 0; int _titleTop = 0;
bool _layerType = false; bool _layerType = false;
bool _closeByOutsideClick = true;
std::vector<object_ptr<Ui::RoundButton>> _buttons; std::vector<object_ptr<Ui::RoundButton>> _buttons;
object_ptr<Ui::RoundButton> _leftButton = { nullptr }; object_ptr<Ui::RoundButton> _leftButton = { nullptr };

View File

@ -659,10 +659,14 @@ void Messenger::forceLogOut(const TextWithEntities &explanation) {
const auto box = Ui::show(Box<InformBox>( const auto box = Ui::show(Box<InformBox>(
explanation, explanation,
lang(lng_passcode_logout))); lang(lng_passcode_logout)));
box->setCloseByEscape(false);
box->setCloseByOutsideClick(false);
connect(box, &QObject::destroyed, [=] { connect(box, &QObject::destroyed, [=] {
InvokeQueued(this, [=] { crl::on_main(this, [=] {
resetAuthorizationKeys(); if (AuthSession::Exists()) {
loggedOut(); resetAuthorizationKeys();
loggedOut();
}
}); });
}); });
} }

View File

@ -357,6 +357,11 @@ void LayerStackWidget::keyPressEvent(QKeyEvent *e) {
void LayerStackWidget::mousePressEvent(QMouseEvent *e) { void LayerStackWidget::mousePressEvent(QMouseEvent *e) {
if (_hideByBackgroundClick) { if (_hideByBackgroundClick) {
if (const auto layer = currentLayer()) {
if (!layer->closeByOutsideClick()) {
return;
}
}
hideCurrent(anim::type::normal); hideCurrent(anim::type::normal);
} }
} }

View File

@ -49,6 +49,9 @@ public:
const SectionShow &params) { const SectionShow &params) {
return false; return false;
} }
virtual bool closeByOutsideClick() const {
return true;
}
protected: protected:
void closeLayer() { void closeLayer() {