forked from telegramdesktop/tdesktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsection_widget.cpp
139 lines (118 loc) · 3.46 KB
/
section_widget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "window/section_widget.h"
#include <rpl/range.h>
#include "application.h"
#include "mainwidget.h"
#include "window/section_memento.h"
#include "window/window_slide_animation.h"
#include "window/themes/window_theme.h"
namespace Window {
SectionWidget::SectionWidget(
QWidget *parent,
not_null<Window::Controller*> controller)
: AbstractSectionWidget(parent, controller) {
}
void SectionWidget::setGeometryWithTopMoved(
const QRect &newGeometry,
int topDelta) {
_topDelta = topDelta;
bool willBeResized = (size() != newGeometry.size());
if (geometry() != newGeometry) {
auto weak = make_weak(this);
setGeometry(newGeometry);
if (!weak) {
return;
}
}
if (!willBeResized) {
resizeEvent(nullptr);
}
_topDelta = 0;
}
void SectionWidget::showAnimated(
SlideDirection direction,
const SectionSlideParams ¶ms) {
if (_showAnimation) return;
showChildren();
auto myContentCache = grabForShowAnimation(params);
hideChildren();
showAnimatedHook(params);
_showAnimation = std::make_unique<SlideAnimation>();
_showAnimation->setDirection(direction);
_showAnimation->setRepaintCallback([this] { update(); });
_showAnimation->setFinishedCallback([this] { showFinished(); });
_showAnimation->setPixmaps(
params.oldContentCache,
myContentCache);
_showAnimation->setTopBarShadow(params.withTopBarShadow);
_showAnimation->setWithFade(params.withFade);
_showAnimation->start();
show();
}
std::unique_ptr<SectionMemento> SectionWidget::createMemento() {
return nullptr;
}
void SectionWidget::showFast() {
show();
showFinished();
}
void SectionWidget::PaintBackground(QWidget *widget, QPaintEvent *event) {
Painter p(widget);
auto clip = event->rect();
auto fill = QRect(0, 0, widget->width(), App::main()->height());
auto fromy = App::main()->backgroundFromY();
auto x = 0, y = 0;
auto cached = App::main()->cachedBackground(fill, x, y);
if (cached.isNull()) {
if (Window::Theme::Background()->tile()) {
auto &pix = Window::Theme::Background()->pixmapForTiled();
auto left = clip.left();
auto top = clip.top();
auto right = clip.left() + clip.width();
auto bottom = clip.top() + clip.height();
auto w = pix.width() / cRetinaFactor();
auto h = pix.height() / cRetinaFactor();
auto sx = qFloor(left / w);
auto sy = qFloor((top - fromy) / h);
auto cx = qCeil(right / w);
auto cy = qCeil((bottom - fromy) / h);
for (auto i = sx; i < cx; ++i) {
for (auto j = sy; j < cy; ++j) {
p.drawPixmap(QPointF(i * w, fromy + j * h), pix);
}
}
} else {
PainterHighQualityEnabler hq(p);
auto &pix = Window::Theme::Background()->pixmap();
QRect to, from;
Window::Theme::ComputeBackgroundRects(fill, pix.size(), to, from);
to.moveTop(to.top() + fromy);
p.drawPixmap(to, pix, from);
}
} else {
p.drawPixmap(x, fromy + y, cached);
}
}
void SectionWidget::paintEvent(QPaintEvent *e) {
if (_showAnimation) {
Painter p(this);
_showAnimation->paintContents(p, e->rect());
}
}
void SectionWidget::showFinished() {
_showAnimation.reset();
if (isHidden()) return;
showChildren();
showFinishedHook();
setInnerFocus();
}
rpl::producer<int> SectionWidget::desiredHeight() const {
return rpl::single(height());
}
SectionWidget::~SectionWidget() = default;
} // namespace Window