2015-04-02 10:33:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
2015-10-03 13:16:42 +00:00
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2015-04-02 10:33:19 +00:00
|
|
|
*/
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/abstract_box.h"
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2016-11-08 14:43:10 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2016-12-13 17:07:56 +00:00
|
|
|
#include "ui/effects/widget_fade_wrap.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2016-11-16 10:44:06 +00:00
|
|
|
#include "ui/widgets/scroll_area.h"
|
2017-05-17 14:32:36 +00:00
|
|
|
#include "ui/widgets/labels.h"
|
2015-04-02 10:33:19 +00:00
|
|
|
#include "mainwidget.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "mainwindow.h"
|
2015-10-11 08:37:24 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxLayerTitleShadow::BoxLayerTitleShadow(QWidget *parent) : Ui::PlainShadow(parent, st::boxLayerTitleShadow) {
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 15:21:05 +00:00
|
|
|
QPointer<Ui::RoundButton> BoxContent::addButton(base::lambda<QString()> textFactory, base::lambda<void()> clickCallback) {
|
|
|
|
return addButton(std::move(textFactory), std::move(clickCallback), st::defaultBoxButton);
|
2016-11-19 14:47:28 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 15:21:05 +00:00
|
|
|
QPointer<Ui::RoundButton> BoxContent::addLeftButton(base::lambda<QString()> textFactory, base::lambda<void()> clickCallback) {
|
|
|
|
return getDelegate()->addLeftButton(std::move(textFactory), std::move(clickCallback), st::defaultBoxButton);
|
2016-11-19 14:47:28 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void BoxContent::setInner(object_ptr<TWidget> inner) {
|
2017-02-21 13:45:56 +00:00
|
|
|
setInner(std::move(inner), st::boxLayerScroll);
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BoxContent::setInner(object_ptr<TWidget> inner, const style::ScrollArea &st) {
|
|
|
|
if (inner) {
|
|
|
|
getDelegate()->setLayerType(true);
|
2016-12-22 13:30:27 +00:00
|
|
|
_scroll.create(this, st);
|
|
|
|
_scroll->setGeometryToLeft(0, _innerTopSkip, width(), 0);
|
2017-02-21 13:45:56 +00:00
|
|
|
_scroll->setOwnedWidget(std::move(inner));
|
2016-12-22 13:30:27 +00:00
|
|
|
if (_topShadow) {
|
|
|
|
_topShadow->raise();
|
|
|
|
_bottomShadow->raise();
|
|
|
|
} else {
|
2016-12-13 17:07:56 +00:00
|
|
|
_topShadow.create(this, object_ptr<BoxLayerTitleShadow>(this));
|
2016-12-20 13:03:51 +00:00
|
|
|
_bottomShadow.create(this, object_ptr<BoxLayerTitleShadow>(this));
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
2017-07-10 16:13:40 +00:00
|
|
|
if (!_preparing) {
|
|
|
|
// We didn't set dimensions yet, this will be called from finishPrepare();
|
|
|
|
finishScrollCreate();
|
|
|
|
}
|
2015-04-02 10:33:19 +00:00
|
|
|
} else {
|
2016-12-13 17:07:56 +00:00
|
|
|
getDelegate()->setLayerType(false);
|
|
|
|
_scroll.destroyDelayed();
|
|
|
|
_topShadow.destroyDelayed();
|
|
|
|
_bottomShadow.destroyDelayed();
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-10 16:13:40 +00:00
|
|
|
void BoxContent::finishPrepare() {
|
|
|
|
_preparing = false;
|
|
|
|
if (_scroll) {
|
|
|
|
finishScrollCreate();
|
|
|
|
}
|
|
|
|
setInnerFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BoxContent::finishScrollCreate() {
|
|
|
|
Expects(_scroll != nullptr);
|
|
|
|
updateScrollAreaGeometry();
|
|
|
|
connect(_scroll, SIGNAL(scrolled()), this, SLOT(onScroll()));
|
|
|
|
connect(_scroll, SIGNAL(innerResized()), this, SLOT(onInnerResize()));
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void BoxContent::onScrollToY(int top, int bottom) {
|
|
|
|
if (_scroll) {
|
|
|
|
_scroll->scrollToY(top, bottom);
|
|
|
|
}
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void BoxContent::onDraggingScrollDelta(int delta) {
|
|
|
|
_draggingScrollDelta = _scroll ? delta : 0;
|
|
|
|
if (_draggingScrollDelta) {
|
|
|
|
if (!_draggingScrollTimer) {
|
|
|
|
_draggingScrollTimer.create(this);
|
|
|
|
_draggingScrollTimer->setSingleShot(false);
|
|
|
|
connect(_draggingScrollTimer, SIGNAL(timeout()), this, SLOT(onDraggingScrollTimer()));
|
|
|
|
}
|
|
|
|
_draggingScrollTimer->start(15);
|
|
|
|
} else {
|
|
|
|
_draggingScrollTimer.destroy();
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BoxContent::onDraggingScrollTimer() {
|
|
|
|
auto delta = (_draggingScrollDelta > 0) ? qMin(_draggingScrollDelta * 3 / 20 + 1, int32(MaxScrollSpeed)) : qMax(_draggingScrollDelta * 3 / 20 - 1, -int32(MaxScrollSpeed));
|
|
|
|
_scroll->scrollToY(_scroll->scrollTop() + delta);
|
|
|
|
}
|
|
|
|
|
2016-12-20 13:03:51 +00:00
|
|
|
void BoxContent::updateInnerVisibleTopBottom() {
|
2016-12-21 15:05:58 +00:00
|
|
|
if (auto widget = static_cast<TWidget*>(_scroll ? _scroll->widget() : nullptr)) {
|
2016-12-20 13:03:51 +00:00
|
|
|
auto top = _scroll->scrollTop();
|
|
|
|
widget->setVisibleTopBottom(top, top + _scroll->height());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 15:05:58 +00:00
|
|
|
void BoxContent::updateShadowsVisibility() {
|
|
|
|
if (!_scroll) return;
|
2016-12-20 13:03:51 +00:00
|
|
|
|
2016-12-21 15:05:58 +00:00
|
|
|
auto top = _scroll->scrollTop();
|
|
|
|
if (top > 0 || _innerTopSkip > 0) {
|
|
|
|
_topShadow->showAnimated();
|
|
|
|
} else {
|
|
|
|
_topShadow->hideAnimated();
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
2016-12-21 15:05:58 +00:00
|
|
|
if (top < _scroll->scrollTopMax()) {
|
|
|
|
_bottomShadow->showAnimated();
|
|
|
|
} else {
|
|
|
|
_bottomShadow->hideAnimated();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BoxContent::onScroll() {
|
|
|
|
updateInnerVisibleTopBottom();
|
|
|
|
updateShadowsVisibility();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BoxContent::onInnerResize() {
|
|
|
|
updateInnerVisibleTopBottom();
|
|
|
|
updateShadowsVisibility();
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void BoxContent::setInnerTopSkip(int innerTopSkip, bool scrollBottomFixed) {
|
|
|
|
if (_innerTopSkip != innerTopSkip) {
|
|
|
|
auto delta = innerTopSkip - _innerTopSkip;
|
|
|
|
_innerTopSkip = innerTopSkip;
|
|
|
|
if (_scroll) {
|
|
|
|
auto scrollTopWas = _scroll->scrollTop();
|
|
|
|
updateScrollAreaGeometry();
|
|
|
|
if (scrollBottomFixed) {
|
|
|
|
_scroll->scrollToY(scrollTopWas + delta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void BoxContent::setInnerVisible(bool scrollAreaVisible) {
|
|
|
|
if (_scroll) {
|
|
|
|
_scroll->setVisible(scrollAreaVisible);
|
|
|
|
}
|
2016-11-08 14:43:10 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
QPixmap BoxContent::grabInnerCache() {
|
|
|
|
auto isTopShadowVisible = !_topShadow->isHidden();
|
|
|
|
auto isBottomShadowVisible = !_bottomShadow->isHidden();
|
|
|
|
if (isTopShadowVisible) _topShadow->hide();
|
|
|
|
if (isBottomShadowVisible) _bottomShadow->hide();
|
|
|
|
auto result = myGrab(this, _scroll->geometry());
|
|
|
|
if (isTopShadowVisible) _topShadow->show();
|
|
|
|
if (isBottomShadowVisible) _bottomShadow->show();
|
2017-02-21 14:37:53 +00:00
|
|
|
return result;
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
2016-11-08 14:43:10 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void BoxContent::resizeEvent(QResizeEvent *e) {
|
|
|
|
if (_scroll) {
|
|
|
|
updateScrollAreaGeometry();
|
|
|
|
}
|
|
|
|
}
|
2015-10-06 19:49:23 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void BoxContent::updateScrollAreaGeometry() {
|
|
|
|
auto newScrollHeight = height() - _innerTopSkip;
|
|
|
|
auto changed = (_scroll->height() != newScrollHeight);
|
|
|
|
_scroll->setGeometryToLeft(0, _innerTopSkip, width(), newScrollHeight);
|
|
|
|
_topShadow->entity()->resize(width(), st::lineWidth);
|
|
|
|
_topShadow->moveToLeft(0, _innerTopSkip);
|
2016-12-20 13:03:51 +00:00
|
|
|
_bottomShadow->entity()->resize(width(), st::lineWidth);
|
2016-12-13 17:07:56 +00:00
|
|
|
_bottomShadow->moveToLeft(0, height() - st::lineWidth);
|
|
|
|
if (changed) {
|
2016-12-20 13:03:51 +00:00
|
|
|
updateInnerVisibleTopBottom();
|
|
|
|
|
|
|
|
auto top = _scroll->scrollTop();
|
2017-03-15 15:10:18 +00:00
|
|
|
_topShadow->toggleFast(top > 0 || _innerTopSkip > 0);
|
|
|
|
_bottomShadow->toggleFast(top < _scroll->scrollTopMax());
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
}
|
2015-10-06 19:49:23 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<TWidget> BoxContent::doTakeInnerWidget() {
|
|
|
|
return _scroll->takeWidget<TWidget>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BoxContent::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
if (testAttribute(Qt::WA_OpaquePaintEvent)) {
|
2017-02-21 13:45:56 +00:00
|
|
|
for (auto rect : e->region().rects()) {
|
2016-12-13 17:07:56 +00:00
|
|
|
p.fillRect(rect, st::boxBg);
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
2015-10-06 19:49:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-07 18:10:49 +00:00
|
|
|
AbstractBox::AbstractBox(QWidget *parent, Window::Controller *controller, object_ptr<BoxContent> content) : LayerWidget(parent)
|
|
|
|
, _controller(controller)
|
2017-02-21 13:45:56 +00:00
|
|
|
, _content(std::move(content)) {
|
2017-05-30 15:21:05 +00:00
|
|
|
subscribe(Lang::Current().updated(), [this] { refreshLang(); });
|
2016-12-13 17:07:56 +00:00
|
|
|
_content->setParent(this);
|
|
|
|
_content->setDelegate(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractBox::setLayerType(bool layerType) {
|
|
|
|
_layerType = layerType;
|
2017-05-17 14:32:36 +00:00
|
|
|
updateTitlePosition();
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int AbstractBox::titleHeight() const {
|
|
|
|
return _layerType ? st::boxLayerTitleHeight : st::boxTitleHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AbstractBox::buttonsHeight() const {
|
|
|
|
auto padding = _layerType ? st::boxLayerButtonPadding : st::boxButtonPadding;
|
|
|
|
return padding.top() + st::defaultBoxButton.height + padding.bottom();
|
|
|
|
}
|
|
|
|
|
|
|
|
int AbstractBox::buttonsTop() const {
|
|
|
|
auto padding = _layerType ? st::boxLayerButtonPadding : st::boxButtonPadding;
|
|
|
|
return height() - padding.bottom() - st::defaultBoxButton.height;
|
|
|
|
}
|
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
void AbstractBox::paintEvent(QPaintEvent *e) {
|
2016-11-19 14:47:28 +00:00
|
|
|
Painter p(this);
|
2016-12-13 17:07:56 +00:00
|
|
|
auto clip = e->rect();
|
|
|
|
auto paintTopRounded = clip.intersects(QRect(0, 0, width(), st::boxRadius));
|
|
|
|
auto paintBottomRounded = clip.intersects(QRect(0, height() - st::boxRadius, width(), st::boxRadius));
|
|
|
|
if (paintTopRounded || paintBottomRounded) {
|
2017-05-24 12:20:50 +00:00
|
|
|
auto parts = qFlags(RectPart::None);
|
|
|
|
if (paintTopRounded) parts |= RectPart::FullTop;
|
|
|
|
if (paintBottomRounded) parts |= RectPart::FullBottom;
|
2016-12-13 17:07:56 +00:00
|
|
|
App::roundRect(p, rect(), st::boxBg, BoxCorners, nullptr, parts);
|
|
|
|
}
|
|
|
|
auto other = e->region().intersected(QRect(0, st::boxRadius, width(), height() - 2 * st::boxRadius));
|
|
|
|
if (!other.isEmpty()) {
|
2017-02-21 13:45:56 +00:00
|
|
|
for (auto rect : other.rects()) {
|
2016-12-13 17:07:56 +00:00
|
|
|
p.fillRect(rect, st::boxBg);
|
|
|
|
}
|
|
|
|
}
|
2017-05-17 14:32:36 +00:00
|
|
|
if (!_additionalTitle.isEmpty() && clip.intersects(QRect(0, 0, width(), titleHeight()))) {
|
|
|
|
paintAdditionalTitle(p);
|
2016-11-19 14:47:28 +00:00
|
|
|
}
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2017-05-17 14:32:36 +00:00
|
|
|
void AbstractBox::paintAdditionalTitle(Painter &p) {
|
|
|
|
p.setFont(st::boxLayerTitleAdditionalFont);
|
|
|
|
p.setPen(st::boxTitleAdditionalFg);
|
|
|
|
p.drawTextLeft(_titleLeft + (_title ? _title->width() : 0) + st::boxLayerTitleAdditionalSkip, _titleTop + st::boxTitleFont->ascent - st::boxLayerTitleAdditionalFont->ascent, width(), _additionalTitle);
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void AbstractBox::parentResized() {
|
|
|
|
auto newHeight = countRealHeight();
|
|
|
|
auto parentSize = parentWidget()->size();
|
|
|
|
setGeometry((parentSize.width() - width()) / 2, (parentSize.height() - newHeight) / 2, width(), newHeight);
|
|
|
|
update();
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 15:21:05 +00:00
|
|
|
void AbstractBox::setTitle(base::lambda<TextWithEntities()> titleFactory) {
|
|
|
|
_titleFactory = std::move(titleFactory);
|
|
|
|
refreshTitle();
|
2017-05-17 14:32:36 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 15:21:05 +00:00
|
|
|
void AbstractBox::refreshTitle() {
|
2016-12-13 17:07:56 +00:00
|
|
|
auto wasTitle = hasTitle();
|
2017-05-30 15:21:05 +00:00
|
|
|
if (_titleFactory) {
|
2017-05-17 14:32:36 +00:00
|
|
|
if (!_title) {
|
|
|
|
_title.create(this, st::boxTitle);
|
|
|
|
}
|
2017-05-30 15:21:05 +00:00
|
|
|
_title->setMarkedText(_titleFactory());
|
2017-05-17 14:32:36 +00:00
|
|
|
updateTitlePosition();
|
|
|
|
} else {
|
|
|
|
_title.destroy();
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
if (wasTitle != hasTitle()) {
|
|
|
|
updateSize();
|
2015-11-24 11:23:14 +00:00
|
|
|
}
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 15:21:05 +00:00
|
|
|
void AbstractBox::setAdditionalTitle(base::lambda<QString()> additionalFactory) {
|
|
|
|
_additionalTitleFactory = std::move(additionalFactory);
|
|
|
|
refreshAdditionalTitle();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractBox::refreshAdditionalTitle() {
|
|
|
|
_additionalTitle = _additionalTitleFactory ? _additionalTitleFactory() : QString();
|
2017-05-17 14:32:36 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2017-05-30 15:21:05 +00:00
|
|
|
void AbstractBox::refreshLang() {
|
|
|
|
refreshTitle();
|
|
|
|
refreshAdditionalTitle();
|
|
|
|
InvokeQueued(this, [this] { updateButtonsPositions(); });
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
bool AbstractBox::hasTitle() const {
|
2017-05-17 14:32:36 +00:00
|
|
|
return (_title != nullptr) || !_additionalTitle.isEmpty();
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractBox::updateSize() {
|
|
|
|
setDimensions(width(), _maxContentHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractBox::updateButtonsPositions() {
|
2017-02-21 13:45:56 +00:00
|
|
|
if (!_buttons.empty() || _leftButton) {
|
2016-12-13 17:07:56 +00:00
|
|
|
auto padding = _layerType ? st::boxLayerButtonPadding : st::boxButtonPadding;
|
|
|
|
auto right = padding.right();
|
|
|
|
auto top = buttonsTop();
|
|
|
|
if (_leftButton) {
|
|
|
|
_leftButton->moveToLeft(right, top);
|
|
|
|
}
|
|
|
|
for_const (auto &button, _buttons) {
|
|
|
|
button->moveToRight(right, top);
|
|
|
|
right += button->width() + padding.left();
|
|
|
|
}
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
|
|
|
|
2017-05-17 14:32:36 +00:00
|
|
|
void AbstractBox::updateTitlePosition() {
|
|
|
|
_titleLeft = _layerType ? st::boxLayerTitlePosition.x() : st::boxTitlePosition.x();
|
|
|
|
_titleTop = _layerType ? st::boxLayerTitlePosition.y() : st::boxTitlePosition.y();
|
|
|
|
if (_title) {
|
|
|
|
_title->resizeToWidth(qMin(_title->naturalWidth(), width() - _titleLeft * 2));
|
|
|
|
_title->moveToLeft(_titleLeft, _titleTop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void AbstractBox::clearButtons() {
|
|
|
|
for (auto &button : base::take(_buttons)) {
|
|
|
|
button.destroy();
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
_leftButton.destroy();
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 15:21:05 +00:00
|
|
|
QPointer<Ui::RoundButton> AbstractBox::addButton(base::lambda<QString()> textFactory, base::lambda<void()> clickCallback, const style::RoundButton &st) {
|
|
|
|
_buttons.push_back(object_ptr<Ui::RoundButton>(this, std::move(textFactory), st));
|
2016-12-13 17:07:56 +00:00
|
|
|
auto result = QPointer<Ui::RoundButton>(_buttons.back());
|
2017-02-21 13:45:56 +00:00
|
|
|
result->setClickedCallback(std::move(clickCallback));
|
2016-12-13 17:07:56 +00:00
|
|
|
result->show();
|
|
|
|
updateButtonsPositions();
|
|
|
|
return result;
|
2016-11-08 14:43:10 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 15:21:05 +00:00
|
|
|
QPointer<Ui::RoundButton> AbstractBox::addLeftButton(base::lambda<QString()> textFactory, base::lambda<void()> clickCallback, const style::RoundButton &st) {
|
|
|
|
_leftButton = object_ptr<Ui::RoundButton>(this, std::move(textFactory), st);
|
2016-12-13 17:07:56 +00:00
|
|
|
auto result = QPointer<Ui::RoundButton>(_leftButton);
|
2017-02-21 13:45:56 +00:00
|
|
|
result->setClickedCallback(std::move(clickCallback));
|
2016-12-13 17:07:56 +00:00
|
|
|
result->show();
|
|
|
|
updateButtonsPositions();
|
|
|
|
return result;
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void AbstractBox::setDimensions(int newWidth, int maxHeight) {
|
|
|
|
_maxContentHeight = maxHeight;
|
|
|
|
|
|
|
|
auto fullHeight = countFullHeight();
|
|
|
|
if (width() != newWidth || _fullHeight != fullHeight) {
|
|
|
|
_fullHeight = fullHeight;
|
|
|
|
if (parentWidget()) {
|
|
|
|
auto oldGeometry = geometry();
|
|
|
|
resize(newWidth, countRealHeight());
|
|
|
|
auto newGeometry = geometry();
|
|
|
|
auto parentHeight = parentWidget()->height();
|
|
|
|
if (newGeometry.top() + newGeometry.height() + st::boxVerticalMargin > parentHeight) {
|
|
|
|
auto newTop = qMax(parentHeight - int(st::boxVerticalMargin) - newGeometry.height(), (parentHeight - newGeometry.height()) / 2);
|
|
|
|
if (newTop != newGeometry.top()) {
|
|
|
|
move(newGeometry.left(), newTop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
parentWidget()->update(oldGeometry.united(geometry()).marginsAdded(st::boxRoundShadow.extend));
|
|
|
|
} else {
|
|
|
|
resize(newWidth, 0);
|
|
|
|
}
|
|
|
|
}
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
int AbstractBox::countRealHeight() const {
|
|
|
|
return qMin(_fullHeight, parentWidget()->height() - 2 * st::boxVerticalMargin);
|
2016-10-20 19:48:35 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
int AbstractBox::countFullHeight() const {
|
|
|
|
return contentTop() + _maxContentHeight + buttonsHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
int AbstractBox::contentTop() const {
|
|
|
|
return hasTitle() ? titleHeight() : (_noContentMargin ? 0 : st::boxTopMargin);
|
2016-10-20 19:48:35 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void AbstractBox::resizeEvent(QResizeEvent *e) {
|
|
|
|
updateButtonsPositions();
|
2017-05-17 14:32:36 +00:00
|
|
|
updateTitlePosition();
|
2016-12-13 17:07:56 +00:00
|
|
|
|
|
|
|
auto top = contentTop();
|
|
|
|
_content->resize(width(), height() - top - buttonsHeight());
|
|
|
|
_content->moveToLeft(0, top);
|
|
|
|
|
|
|
|
LayerWidget::resizeEvent(e);
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void AbstractBox::keyPressEvent(QKeyEvent *e) {
|
|
|
|
if (e->key() == Qt::Key_Escape) {
|
|
|
|
closeBox();
|
|
|
|
} else {
|
|
|
|
LayerWidget::keyPressEvent(e);
|
|
|
|
}
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|