mirror of
https://github.com/telegramdesktop/tdesktop
synced 2024-12-28 01:23:09 +00:00
Allow boxes that don't hide by escape / click.
This commit is contained in:
parent
e47d110f28
commit
16f3ca87f5
@ -32,8 +32,8 @@ QPointer<Ui::RoundButton> BoxContent::addLeftButton(
|
||||
Fn<QString()> textFactory,
|
||||
Fn<void()> clickCallback) {
|
||||
return getDelegate()->addLeftButton(
|
||||
std::move(textFactory),
|
||||
std::move(clickCallback),
|
||||
std::move(textFactory),
|
||||
std::move(clickCallback),
|
||||
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() {
|
||||
auto newScrollHeight = height() - _innerTopSkip - _innerBottomSkip;
|
||||
auto changed = (_scroll->height() != newScrollHeight);
|
||||
@ -316,6 +324,14 @@ void AbstractBox::setAdditionalTitle(Fn<QString()> additionalFactory) {
|
||||
refreshAdditionalTitle();
|
||||
}
|
||||
|
||||
void AbstractBox::setCloseByOutsideClick(bool close) {
|
||||
_closeByOutsideClick = close;
|
||||
}
|
||||
|
||||
bool AbstractBox::closeByOutsideClick() const {
|
||||
return _closeByOutsideClick;
|
||||
}
|
||||
|
||||
void AbstractBox::refreshAdditionalTitle() {
|
||||
_additionalTitle = _additionalTitleFactory ? _additionalTitleFactory() : QString();
|
||||
update();
|
||||
|
@ -30,6 +30,7 @@ public:
|
||||
virtual void setLayerType(bool layerType) = 0;
|
||||
virtual void setTitle(Fn<TextWithEntities()> titleFactory) = 0;
|
||||
virtual void setAdditionalTitle(Fn<QString()> additionalFactory) = 0;
|
||||
virtual void setCloseByOutsideClick(bool close) = 0;
|
||||
|
||||
virtual void clearButtons() = 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) {
|
||||
getDelegate()->setAdditionalTitle(std::move(additional));
|
||||
}
|
||||
void setCloseByEscape(bool close) {
|
||||
_closeByEscape = close;
|
||||
}
|
||||
void setCloseByOutsideClick(bool close) {
|
||||
getDelegate()->setCloseByOutsideClick(close);
|
||||
}
|
||||
|
||||
void scrollToWidget(not_null<QWidget*> widget);
|
||||
|
||||
@ -178,6 +185,7 @@ protected:
|
||||
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
void keyPressEvent(QKeyEvent *e) override;
|
||||
|
||||
not_null<BoxContentDelegate*> getDelegate() const {
|
||||
return _delegate;
|
||||
@ -203,6 +211,7 @@ private:
|
||||
|
||||
bool _preparing = false;
|
||||
bool _noContentMargin = false;
|
||||
bool _closeByEscape = true;
|
||||
int _innerTopSkip = 0;
|
||||
int _innerBottomSkip = 0;
|
||||
object_ptr<Ui::ScrollArea> _scroll = { nullptr };
|
||||
@ -256,6 +265,9 @@ public:
|
||||
closeLayer();
|
||||
}
|
||||
|
||||
void setCloseByOutsideClick(bool close) override;
|
||||
bool closeByOutsideClick() const override;
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent *e) override;
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
@ -298,6 +310,7 @@ private:
|
||||
int _titleLeft = 0;
|
||||
int _titleTop = 0;
|
||||
bool _layerType = false;
|
||||
bool _closeByOutsideClick = true;
|
||||
|
||||
std::vector<object_ptr<Ui::RoundButton>> _buttons;
|
||||
object_ptr<Ui::RoundButton> _leftButton = { nullptr };
|
||||
|
@ -659,10 +659,14 @@ void Messenger::forceLogOut(const TextWithEntities &explanation) {
|
||||
const auto box = Ui::show(Box<InformBox>(
|
||||
explanation,
|
||||
lang(lng_passcode_logout)));
|
||||
box->setCloseByEscape(false);
|
||||
box->setCloseByOutsideClick(false);
|
||||
connect(box, &QObject::destroyed, [=] {
|
||||
InvokeQueued(this, [=] {
|
||||
resetAuthorizationKeys();
|
||||
loggedOut();
|
||||
crl::on_main(this, [=] {
|
||||
if (AuthSession::Exists()) {
|
||||
resetAuthorizationKeys();
|
||||
loggedOut();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -357,6 +357,11 @@ void LayerStackWidget::keyPressEvent(QKeyEvent *e) {
|
||||
|
||||
void LayerStackWidget::mousePressEvent(QMouseEvent *e) {
|
||||
if (_hideByBackgroundClick) {
|
||||
if (const auto layer = currentLayer()) {
|
||||
if (!layer->closeByOutsideClick()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
hideCurrent(anim::type::normal);
|
||||
}
|
||||
}
|
||||
|
@ -49,6 +49,9 @@ public:
|
||||
const SectionShow ¶ms) {
|
||||
return false;
|
||||
}
|
||||
virtual bool closeByOutsideClick() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
void closeLayer() {
|
||||
|
Loading…
Reference in New Issue
Block a user