mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 14:45:14 +00:00
Started a special LayerWidget: Settings::Widget.
Also added some missing calls to parent event handlers in boxes.
This commit is contained in:
@@ -21,6 +21,92 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
||||
#include "stdafx.h"
|
||||
#include "settings/settings_widget.h"
|
||||
|
||||
#include "settings/settings_inner_widget.h"
|
||||
#include "settings/settings_fixed_bar.h"
|
||||
#include "styles/style_settings.h"
|
||||
#include "ui/scrollarea.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
namespace Settings {
|
||||
|
||||
Widget::Widget() : LayerWidget()
|
||||
, _scroll(this, st::setScroll)
|
||||
, _inner(this)
|
||||
, _fixedBar(this)
|
||||
, _fixedBarShadow1(this, st::settingsFixedBarShadowBg1)
|
||||
, _fixedBarShadow2(this, st::settingsFixedBarShadowBg2) {
|
||||
_scroll->setOwnedWidget(_inner);
|
||||
setAttribute(Qt::WA_OpaquePaintEvent);
|
||||
|
||||
_fixedBar->move(0, 0);
|
||||
_fixedBarShadow1->move(0, _fixedBar->y() + st::settingsFixedBarHeight);
|
||||
_fixedBarShadow2->move(0, _fixedBarShadow1->y() + st::lineWidth);
|
||||
}
|
||||
|
||||
void Widget::parentResized() {
|
||||
int windowWidth = App::wnd()->width();
|
||||
int newWidth = st::settingsMaxWidth;
|
||||
int newContentLeft = st::settingsMaxPadding;
|
||||
if (windowWidth <= st::settingsMaxWidth) {
|
||||
newWidth = windowWidth;
|
||||
newContentLeft = st::settingsMinPadding;
|
||||
if (windowWidth > st::wndMinWidth) {
|
||||
// Width changes from st::wndMinWidth to st::settingsMaxWidth.
|
||||
// Padding changes from st::settingsMinPadding to st::settingsMaxPadding.
|
||||
newContentLeft += ((newWidth - st::wndMinWidth) * (st::settingsMaxPadding - st::settingsMinPadding)) / (st::settingsMaxWidth - st::wndMinWidth);
|
||||
}
|
||||
} else if (windowWidth < st::settingsMaxWidth + 2 * st::settingsMargin) {
|
||||
newWidth = windowWidth - 2 * st::settingsMargin;
|
||||
newContentLeft = st::settingsMinPadding;
|
||||
if (windowWidth > st::wndMinWidth) {
|
||||
// Width changes from st::wndMinWidth to st::settingsMaxWidth.
|
||||
// Padding changes from st::settingsMinPadding to st::settingsMaxPadding.
|
||||
newContentLeft += ((newWidth - st::wndMinWidth) * (st::settingsMaxPadding - st::settingsMinPadding)) / (st::settingsMaxWidth - st::wndMinWidth);
|
||||
}
|
||||
}
|
||||
|
||||
// Widget height depends on InnerWidget height, so we
|
||||
// resize it here, not in the resizeEvent() handler.
|
||||
_inner->resizeToWidth(newWidth, newContentLeft);
|
||||
|
||||
int windowHeight = App::wnd()->height();
|
||||
int maxHeight = st::settingsFixedBarHeight + _inner->height();
|
||||
int newHeight = maxHeight;
|
||||
if (newHeight > windowHeight || newWidth >= windowWidth) {
|
||||
newHeight = windowHeight;
|
||||
}
|
||||
|
||||
if (_contentLeft != newContentLeft) {
|
||||
_contentLeft = newContentLeft;
|
||||
}
|
||||
|
||||
setGeometry((App::wnd()->width() - newWidth) / 2, (App::wnd()->height() - newHeight) / 2, newWidth, newHeight);
|
||||
update();
|
||||
}
|
||||
|
||||
void Widget::paintEvent(QPaintEvent *e) {
|
||||
Painter p(this);
|
||||
p.fillRect(rect(), st::windowBg);
|
||||
}
|
||||
|
||||
void Widget::resizeEvent(QResizeEvent *e) {
|
||||
if (!width() || !height()) {
|
||||
return;
|
||||
}
|
||||
|
||||
_fixedBar->resizeToWidth(width());
|
||||
_fixedBarShadow1->resize(width(), st::lineWidth);
|
||||
_fixedBarShadow2->resize(width(), st::lineWidth);
|
||||
|
||||
QSize scrollSize(width(), height() - _fixedBar->height());
|
||||
if (_scroll->size() != scrollSize) {
|
||||
_scroll->resize(scrollSize);
|
||||
}
|
||||
|
||||
if (!_scroll->isHidden()) {
|
||||
int scrollTop = _scroll->scrollTop();
|
||||
_inner->setVisibleTopBottom(scrollTop, scrollTop + _scroll->height());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Settings
|
||||
|
Reference in New Issue
Block a user