2021-02-05 05:44:04 +00:00
|
|
|
/*
|
|
|
|
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 "editor/photo_editor_controls.h"
|
|
|
|
|
2021-02-05 08:58:10 +00:00
|
|
|
#include "ui/cached_round_corners.h"
|
2021-02-05 09:24:26 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
|
|
|
#include "styles/style_editor.h"
|
|
|
|
|
2021-02-05 05:44:04 +00:00
|
|
|
namespace Editor {
|
|
|
|
|
2021-02-05 08:58:10 +00:00
|
|
|
class HorizontalContainer final : public Ui::RpWidget {
|
|
|
|
public:
|
|
|
|
HorizontalContainer(not_null<Ui::RpWidget*> parent);
|
|
|
|
|
|
|
|
void updateChildrenPosition();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
HorizontalContainer::HorizontalContainer(not_null<Ui::RpWidget*> parent)
|
2021-02-05 05:44:04 +00:00
|
|
|
: RpWidget(parent) {
|
|
|
|
}
|
|
|
|
|
2021-02-05 08:58:10 +00:00
|
|
|
void HorizontalContainer::updateChildrenPosition() {
|
|
|
|
auto left = 0;
|
|
|
|
auto height = 0;
|
|
|
|
for (auto child : RpWidget::children()) {
|
|
|
|
if (child->isWidgetType()) {
|
|
|
|
const auto widget = static_cast<QWidget*>(child);
|
|
|
|
widget->move(left, 0);
|
|
|
|
left += widget->width();
|
|
|
|
height = std::max(height, widget->height());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resize(left, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
PhotoEditorControls::PhotoEditorControls(
|
|
|
|
not_null<Ui::RpWidget*> parent,
|
|
|
|
bool doneControls)
|
|
|
|
: RpWidget(parent)
|
2021-02-05 09:24:26 +00:00
|
|
|
, _buttonsContainer(base::make_unique_q<HorizontalContainer>(this))
|
|
|
|
, _rotateButton(base::make_unique_q<Ui::IconButton>(
|
|
|
|
_buttonsContainer,
|
|
|
|
st::photoEditorRotateButton))
|
|
|
|
, _flipButton(base::make_unique_q<Ui::IconButton>(
|
2021-02-13 04:29:31 +00:00
|
|
|
_buttonsContainer,
|
|
|
|
st::photoEditorFlipButton))
|
|
|
|
, _paintModeButton(base::make_unique_q<Ui::IconButton>(
|
2021-02-05 09:24:26 +00:00
|
|
|
_buttonsContainer,
|
2021-02-13 05:52:36 +00:00
|
|
|
st::photoEditorPaintModeButton)) {
|
2021-02-05 08:58:10 +00:00
|
|
|
|
|
|
|
_buttonsContainer->updateChildrenPosition();
|
|
|
|
|
2021-02-05 09:24:26 +00:00
|
|
|
paintRequest(
|
|
|
|
) | rpl::start_with_next([=](const QRect &clip) {
|
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
Ui::FillRoundRect(
|
|
|
|
p,
|
|
|
|
_buttonsContainer->geometry(),
|
|
|
|
st::mediaviewSaveMsgBg,
|
|
|
|
Ui::MediaviewSaveCorners);
|
|
|
|
|
|
|
|
}, lifetime());
|
|
|
|
|
2021-02-05 08:58:10 +00:00
|
|
|
sizeValue(
|
|
|
|
) | rpl::start_with_next([=](const QSize &size) {
|
|
|
|
|
|
|
|
_buttonsContainer->moveToLeft(
|
|
|
|
(size.width() - _buttonsContainer->width()) / 2,
|
|
|
|
0);
|
|
|
|
|
|
|
|
}, lifetime());
|
|
|
|
|
|
|
|
}
|
2021-02-07 23:10:30 +00:00
|
|
|
|
|
|
|
rpl::producer<int> PhotoEditorControls::rotateRequests() const {
|
|
|
|
return _rotateButton->clicks() | rpl::map([] { return 90; });
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<> PhotoEditorControls::flipRequests() const {
|
|
|
|
return _flipButton->clicks() | rpl::to_empty;
|
|
|
|
}
|
|
|
|
|
2021-02-13 04:29:31 +00:00
|
|
|
rpl::producer<> PhotoEditorControls::paintModeRequests() const {
|
|
|
|
return _paintModeButton->clicks() | rpl::to_empty;
|
|
|
|
}
|
|
|
|
|
2021-02-05 05:44:04 +00:00
|
|
|
} // namespace Editor
|