2021-04-12 16:25:58 +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 "ui/chat/attach/attach_controls.h"
|
|
|
|
|
|
|
|
#include "styles/style_boxes.h"
|
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
|
|
|
|
AttachControls::AttachControls()
|
|
|
|
: _rect(st::sendBoxAlbumGroupRadius, st::roundedBg) {
|
|
|
|
}
|
|
|
|
|
2022-09-16 20:23:27 +00:00
|
|
|
void AttachControls::paint(QPainter &p, int x, int y) {
|
2021-04-12 16:25:58 +00:00
|
|
|
const auto groupWidth = width();
|
|
|
|
const auto groupHeight = height();
|
2021-05-01 17:04:24 +00:00
|
|
|
const auto full = (_type == Type::Full);
|
2021-04-12 16:25:58 +00:00
|
|
|
|
|
|
|
QRect groupRect(x, y, groupWidth, groupHeight);
|
|
|
|
_rect.paint(p, groupRect);
|
|
|
|
|
2021-05-01 17:04:24 +00:00
|
|
|
if (full) {
|
|
|
|
const auto groupHalfWidth = groupWidth / 2;
|
|
|
|
QRect leftRect(x, y, groupHalfWidth, groupHeight);
|
|
|
|
st::sendBoxAlbumGroupButtonMediaEdit.paintInCenter(p, leftRect);
|
|
|
|
QRect rightRect(x + groupHalfWidth, y, groupHalfWidth, groupHeight);
|
|
|
|
st::sendBoxAlbumGroupButtonMediaDelete.paintInCenter(p, rightRect);
|
2021-07-12 14:32:13 +00:00
|
|
|
} else if (_type == Type::EditOnly) {
|
2021-05-01 17:04:24 +00:00
|
|
|
st::sendBoxAlbumButtonMediaEdit.paintInCenter(p, groupRect);
|
|
|
|
}
|
2021-04-12 16:25:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int AttachControls::width() const {
|
2021-05-01 17:04:24 +00:00
|
|
|
return (_type == Type::Full)
|
|
|
|
? st::sendBoxAlbumGroupSize.width()
|
2021-07-12 14:32:13 +00:00
|
|
|
: (_type == Type::EditOnly)
|
|
|
|
? st::sendBoxAlbumSmallGroupSize.width()
|
|
|
|
: 0;
|
2021-04-12 16:25:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int AttachControls::height() const {
|
2021-05-01 17:04:24 +00:00
|
|
|
return (_type == Type::Full)
|
|
|
|
? st::sendBoxAlbumGroupSize.height()
|
2021-07-12 14:32:13 +00:00
|
|
|
: (_type == Type::EditOnly)
|
|
|
|
? st::sendBoxAlbumSmallGroupSize.height()
|
|
|
|
: 0;
|
2021-04-12 16:25:58 +00:00
|
|
|
}
|
|
|
|
|
2021-05-01 17:04:24 +00:00
|
|
|
AttachControls::Type AttachControls::type() const {
|
|
|
|
return _type;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AttachControls::setType(Type type) {
|
|
|
|
if (_type != type) {
|
|
|
|
_type = type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AttachControlsWidget::AttachControlsWidget(
|
|
|
|
not_null<RpWidget*> parent,
|
|
|
|
AttachControls::Type type)
|
2021-04-12 16:25:58 +00:00
|
|
|
: RpWidget(parent)
|
|
|
|
, _edit(base::make_unique_q<AbstractButton>(this))
|
|
|
|
, _delete(base::make_unique_q<AbstractButton>(this)) {
|
2021-05-01 17:04:24 +00:00
|
|
|
_controls.setType(type);
|
|
|
|
|
2021-04-12 16:25:58 +00:00
|
|
|
const auto w = _controls.width();
|
|
|
|
resize(w, _controls.height());
|
|
|
|
|
2021-05-01 17:04:24 +00:00
|
|
|
if (type == AttachControls::Type::Full) {
|
|
|
|
_edit->resize(w / 2, _controls.height());
|
|
|
|
_delete->resize(w / 2, _controls.height());
|
|
|
|
|
|
|
|
_edit->moveToLeft(0, 0, w);
|
|
|
|
_delete->moveToRight(0, 0, w);
|
|
|
|
} else if (type == AttachControls::Type::EditOnly) {
|
|
|
|
_edit->resize(w, _controls.height());
|
|
|
|
_edit->moveToLeft(0, 0, w);
|
|
|
|
}
|
2021-04-12 16:25:58 +00:00
|
|
|
|
|
|
|
paintRequest(
|
|
|
|
) | rpl::start_with_next([=] {
|
2022-09-16 20:23:27 +00:00
|
|
|
auto p = QPainter(this);
|
2021-04-12 16:25:58 +00:00
|
|
|
_controls.paint(p, 0, 0);
|
|
|
|
}, lifetime());
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<> AttachControlsWidget::editRequests() const {
|
|
|
|
return _edit->clicks() | rpl::to_empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<> AttachControlsWidget::deleteRequests() const {
|
|
|
|
return _delete->clicks() | rpl::to_empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Ui
|