Added initial edit message header to scheduled section.
This commit is contained in:
parent
42e0994581
commit
12ad1190ff
|
@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "base/call_delayed.h"
|
||||
#include "base/qt_signal_producer.h"
|
||||
#include "history/history.h"
|
||||
#include "main/main_session.h"
|
||||
#include "chat_helpers/tabbed_panel.h"
|
||||
#include "chat_helpers/tabbed_section.h"
|
||||
#include "chat_helpers/tabbed_selector.h"
|
||||
|
@ -29,6 +30,82 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
namespace HistoryView {
|
||||
|
||||
class FieldHeader : public Ui::RpWidget {
|
||||
public:
|
||||
FieldHeader(QWidget *parent, not_null<Data::Session*> data);
|
||||
|
||||
void editMessage(FullMsgId edit);
|
||||
|
||||
bool isDisplayed() const;
|
||||
bool isEditingMessage() const;
|
||||
rpl::producer<FullMsgId> editMsgId() const;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
|
||||
private:
|
||||
void updateControlsGeometry(QSize size);
|
||||
|
||||
rpl::variable<FullMsgId> _editMsgId;
|
||||
|
||||
const not_null<Data::Session*> _data;
|
||||
const not_null<Ui::IconButton*> _cancel;
|
||||
|
||||
};
|
||||
|
||||
FieldHeader::FieldHeader(QWidget *parent, not_null<Data::Session*> data)
|
||||
: RpWidget(parent)
|
||||
, _data(data)
|
||||
, _cancel(Ui::CreateChild<Ui::IconButton>(this, st::historyReplyCancel)) {
|
||||
resize(QSize(parent->width(), st::historyReplyHeight));
|
||||
|
||||
sizeValue(
|
||||
) | rpl::start_with_next([=](QSize size) {
|
||||
updateControlsGeometry(size);
|
||||
}, lifetime());
|
||||
|
||||
_editMsgId.value(
|
||||
) | rpl::start_with_next([=] {
|
||||
isDisplayed() ? show() : hide();
|
||||
}, lifetime());
|
||||
}
|
||||
|
||||
void FieldHeader::paintEvent(QPaintEvent *e) {
|
||||
Painter p(this);
|
||||
|
||||
p.fillRect(rect(), st::historyComposeAreaBg);
|
||||
|
||||
st::historyEditIcon.paint(p, st::historyReplyIconPosition, width());
|
||||
|
||||
p.setPen(st::historyReplyNameFg);
|
||||
p.setFont(st::msgServiceNameFont);
|
||||
p.drawTextLeft(
|
||||
st::historyReplySkip,
|
||||
st::msgReplyPadding.top(),
|
||||
width(),
|
||||
tr::lng_edit_message(tr::now));
|
||||
}
|
||||
|
||||
bool FieldHeader::isDisplayed() const {
|
||||
return isEditingMessage();
|
||||
}
|
||||
|
||||
bool FieldHeader::isEditingMessage() const {
|
||||
return !!_editMsgId.current();
|
||||
}
|
||||
|
||||
void FieldHeader::updateControlsGeometry(QSize size) {
|
||||
_cancel->moveToRight(0, 0);
|
||||
}
|
||||
|
||||
void FieldHeader::editMessage(FullMsgId id) {
|
||||
_editMsgId = id;
|
||||
}
|
||||
|
||||
rpl::producer<FullMsgId> FieldHeader::editMsgId() const {
|
||||
return _editMsgId.value();
|
||||
}
|
||||
|
||||
ComposeControls::ComposeControls(
|
||||
not_null<QWidget*> parent,
|
||||
not_null<Window::SessionController*> window,
|
||||
|
@ -49,7 +126,10 @@ ComposeControls::ComposeControls(
|
|||
_wrap.get(),
|
||||
st::historyComposeField,
|
||||
Ui::InputField::Mode::MultiLine,
|
||||
tr::lng_message_ph())) {
|
||||
tr::lng_message_ph()))
|
||||
, _header(std::make_unique<FieldHeader>(
|
||||
_wrap.get(),
|
||||
&_window->session().data())) {
|
||||
init();
|
||||
}
|
||||
|
||||
|
@ -199,6 +279,11 @@ void ComposeControls::init() {
|
|||
) | rpl::start_with_next([=](QRect clip) {
|
||||
paintBackground(clip);
|
||||
}, _wrap->lifetime());
|
||||
|
||||
_header->editMsgId(
|
||||
) | rpl::start_with_next([=] {
|
||||
updateHeight();
|
||||
}, _wrap->lifetime());
|
||||
}
|
||||
|
||||
void ComposeControls::initField() {
|
||||
|
@ -312,6 +397,11 @@ void ComposeControls::updateControlsGeometry(QSize size) {
|
|||
left,
|
||||
size.height() - _field->height() - st::historySendPadding);
|
||||
|
||||
_header->resizeToWidth(size.width());
|
||||
_header->moveToLeft(
|
||||
0,
|
||||
_field->y() - _header->height() - st::historySendPadding);
|
||||
|
||||
auto right = st::historySendRight;
|
||||
_send->moveToRight(right, buttonsTop);
|
||||
right += _send->width();
|
||||
|
@ -408,8 +498,14 @@ void ComposeControls::toggleTabbedSelectorMode() {
|
|||
}
|
||||
|
||||
void ComposeControls::updateHeight() {
|
||||
const auto height = _field->height() + 2 * st::historySendPadding;
|
||||
const auto height = _field->height()
|
||||
+ (_header->isDisplayed() ? _header->height() : 0)
|
||||
+ 2 * st::historySendPadding;
|
||||
_wrap->resize(_wrap->width(), height);
|
||||
}
|
||||
|
||||
void ComposeControls::editMessage(FullMsgId edit) {
|
||||
_header->editMessage(std::move(edit));
|
||||
}
|
||||
|
||||
} // namespace HistoryView
|
||||
|
|
|
@ -45,6 +45,8 @@ struct SectionShow;
|
|||
|
||||
namespace HistoryView {
|
||||
|
||||
class FieldHeader;
|
||||
|
||||
class ComposeControls final {
|
||||
public:
|
||||
enum class Mode {
|
||||
|
@ -90,6 +92,8 @@ public:
|
|||
void showStarted();
|
||||
void showFinished();
|
||||
|
||||
void editMessage(FullMsgId edit);
|
||||
|
||||
[[nodiscard]] TextWithTags getTextWithAppliedMarkdown() const;
|
||||
void clear();
|
||||
void hidePanelsAnimated();
|
||||
|
@ -125,6 +129,9 @@ private:
|
|||
std::unique_ptr<InlineBots::Layout::Widget> _inlineResults;
|
||||
std::unique_ptr<ChatHelpers::TabbedPanel> _tabbedPanel;
|
||||
|
||||
friend class FieldHeader;
|
||||
const std::unique_ptr<FieldHeader> _header;
|
||||
|
||||
rpl::event_stream<> _cancelRequests;
|
||||
rpl::event_stream<not_null<DocumentData*>> _fileChosen;
|
||||
rpl::event_stream<not_null<PhotoData*>> _photoChosen;
|
||||
|
|
|
@ -477,11 +477,15 @@ bool AddEditMessageAction(
|
|||
if (!item) {
|
||||
return;
|
||||
}
|
||||
if (!item->media() || !item->media()->allowsEditCaption()) {
|
||||
return;
|
||||
if (const auto media = item->media()) {
|
||||
if (media->allowsEditCaption()) {
|
||||
Ui::show(Box<EditCaptionBox>(
|
||||
App::wnd()->sessionController(),
|
||||
item));
|
||||
}
|
||||
} else {
|
||||
list->editMessageRequestNotify(item->fullId());
|
||||
}
|
||||
|
||||
Ui::show(Box<EditCaptionBox>(App::wnd()->sessionController(), item));
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -2550,6 +2550,14 @@ QPoint ListWidget::mapPointToItem(
|
|||
return point - QPoint(0, itemTop(view));
|
||||
}
|
||||
|
||||
rpl::producer<FullMsgId> ListWidget::editMessageRequested() const {
|
||||
return _requestedToEditMessage.events();
|
||||
}
|
||||
|
||||
void ListWidget::editMessageRequestNotify(FullMsgId item) {
|
||||
_requestedToEditMessage.fire(std::move(item));
|
||||
}
|
||||
|
||||
ListWidget::~ListWidget() = default;
|
||||
|
||||
} // namespace HistoryView
|
||||
|
|
|
@ -181,6 +181,9 @@ public:
|
|||
QPoint tooltipPos() const override;
|
||||
bool tooltipWindowActive() const override;
|
||||
|
||||
rpl::producer<FullMsgId> editMessageRequested() const;
|
||||
void editMessageRequestNotify(FullMsgId item);
|
||||
|
||||
// ElementDelegate interface.
|
||||
Context elementContext() override;
|
||||
std::unique_ptr<Element> elementCreate(
|
||||
|
@ -512,6 +515,8 @@ private:
|
|||
FullMsgId _highlightedMessageId;
|
||||
base::Timer _highlightTimer;
|
||||
|
||||
rpl::event_stream<FullMsgId> _requestedToEditMessage;
|
||||
|
||||
rpl::lifetime _viewerLifetime;
|
||||
|
||||
};
|
||||
|
|
|
@ -130,6 +130,11 @@ ScheduledWidget::ScheduledWidget(
|
|||
_scroll->show();
|
||||
connect(_scroll, &Ui::ScrollArea::scrolled, [=] { onScroll(); });
|
||||
|
||||
_inner->editMessageRequested(
|
||||
) | rpl::start_with_next([=](auto id) {
|
||||
_composeControls->editMessage(id);
|
||||
}, _inner->lifetime());
|
||||
|
||||
setupScrollDownButton();
|
||||
setupComposeControls();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue