init
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
This commit is contained in:
112
Telegram/SourceFiles/ui/controls/invite_link_label.cpp
Normal file
112
Telegram/SourceFiles/ui/controls/invite_link_label.cpp
Normal file
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
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/controls/invite_link_label.h"
|
||||
|
||||
#include "ui/painter.h"
|
||||
#include "ui/rp_widget.h"
|
||||
#include "ui/widgets/labels.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/popup_menu.h"
|
||||
#include "styles/style_info.h"
|
||||
|
||||
namespace Ui {
|
||||
|
||||
InviteLinkLabel::InviteLinkLabel(
|
||||
not_null<QWidget*> parent,
|
||||
rpl::producer<QString> text,
|
||||
Fn<base::unique_qptr<PopupMenu>()> createMenu)
|
||||
: _outer(std::in_place, parent) {
|
||||
_outer->resize(_outer->width(), st::inviteLinkFieldHeight);
|
||||
const auto label = CreateChild<FlatLabel>(
|
||||
_outer.get(),
|
||||
std::move(text),
|
||||
createMenu ? st::defaultFlatLabel : st::inviteLinkFieldLabel);
|
||||
label->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
|
||||
const auto button = createMenu
|
||||
? CreateChild<IconButton>(_outer.get(), st::inviteLinkThreeDots)
|
||||
: (IconButton*)(nullptr);
|
||||
|
||||
_outer->widthValue(
|
||||
) | rpl::on_next([=](int width) {
|
||||
const auto margin = st::inviteLinkFieldMargin;
|
||||
const auto labelWidth = width - margin.left() - margin.right();
|
||||
label->resizeToWidth(labelWidth);
|
||||
label->moveToLeft(
|
||||
createMenu
|
||||
? margin.left()
|
||||
: (width - labelWidth) / 2,
|
||||
margin.top());
|
||||
if (button) {
|
||||
button->moveToRight(0, 0);
|
||||
}
|
||||
}, _outer->lifetime());
|
||||
|
||||
_outer->paintRequest(
|
||||
) | rpl::on_next([=] {
|
||||
auto p = QPainter(_outer.get());
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setBrush(st::filterInputInactiveBg);
|
||||
{
|
||||
PainterHighQualityEnabler hq(p);
|
||||
p.drawRoundedRect(
|
||||
_outer->rect(),
|
||||
st::inviteLinkFieldRadius,
|
||||
st::inviteLinkFieldRadius);
|
||||
}
|
||||
}, _outer->lifetime());
|
||||
|
||||
_outer->setCursor(style::cur_pointer);
|
||||
|
||||
if (createMenu) {
|
||||
rpl::merge(
|
||||
button->clicks() | rpl::to_empty,
|
||||
_outer->events(
|
||||
) | rpl::filter([=](not_null<QEvent*> event) {
|
||||
return (event->type() == QEvent::MouseButtonPress)
|
||||
&& (static_cast<QMouseEvent*>(event.get())->button()
|
||||
== Qt::RightButton);
|
||||
}) | rpl::to_empty
|
||||
) | rpl::on_next([=] {
|
||||
if (_menu) {
|
||||
_menu = nullptr;
|
||||
} else if ((_menu = createMenu())) {
|
||||
_menu->popup(QCursor::pos());
|
||||
}
|
||||
}, _outer->lifetime());
|
||||
}
|
||||
}
|
||||
|
||||
object_ptr<RpWidget> InviteLinkLabel::take() {
|
||||
return object_ptr<RpWidget>::fromRaw(_outer.get());
|
||||
}
|
||||
|
||||
rpl::producer<> InviteLinkLabel::clicks() {
|
||||
return _outer->events(
|
||||
) | rpl::filter([=](not_null<QEvent*> event) {
|
||||
return (event->type() == QEvent::MouseButtonPress)
|
||||
&& (static_cast<QMouseEvent*>(event.get())->button()
|
||||
== Qt::LeftButton);
|
||||
}) | rpl::map([=](not_null<QEvent*> event) {
|
||||
return _outer->events(
|
||||
) | rpl::filter([=](not_null<QEvent*> event) {
|
||||
return (event->type() == QEvent::MouseButtonRelease)
|
||||
&& (static_cast<QMouseEvent*>(event.get())->button()
|
||||
== Qt::LeftButton);
|
||||
}) | rpl::take(1) | rpl::filter([=](not_null<QEvent*> event) {
|
||||
return (_outer->rect().contains(
|
||||
static_cast<QMouseEvent*>(event.get())->pos()));
|
||||
});
|
||||
}) | rpl::flatten_latest() | rpl::to_empty;
|
||||
}
|
||||
|
||||
rpl::lifetime &InviteLinkLabel::lifetime() {
|
||||
return _outer->lifetime();
|
||||
}
|
||||
|
||||
} // namespace Ui
|
||||
Reference in New Issue
Block a user