mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-07-26 07:23:02 +02:00
Added initial edit message header to scheduled section.
This commit is contained in:
parent
42e0994581
commit
12ad1190ff
6 changed files with 131 additions and 6 deletions
|
@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "base/call_delayed.h"
|
#include "base/call_delayed.h"
|
||||||
#include "base/qt_signal_producer.h"
|
#include "base/qt_signal_producer.h"
|
||||||
#include "history/history.h"
|
#include "history/history.h"
|
||||||
|
#include "main/main_session.h"
|
||||||
#include "chat_helpers/tabbed_panel.h"
|
#include "chat_helpers/tabbed_panel.h"
|
||||||
#include "chat_helpers/tabbed_section.h"
|
#include "chat_helpers/tabbed_section.h"
|
||||||
#include "chat_helpers/tabbed_selector.h"
|
#include "chat_helpers/tabbed_selector.h"
|
||||||
|
@ -29,6 +30,82 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
namespace HistoryView {
|
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(
|
ComposeControls::ComposeControls(
|
||||||
not_null<QWidget*> parent,
|
not_null<QWidget*> parent,
|
||||||
not_null<Window::SessionController*> window,
|
not_null<Window::SessionController*> window,
|
||||||
|
@ -49,7 +126,10 @@ ComposeControls::ComposeControls(
|
||||||
_wrap.get(),
|
_wrap.get(),
|
||||||
st::historyComposeField,
|
st::historyComposeField,
|
||||||
Ui::InputField::Mode::MultiLine,
|
Ui::InputField::Mode::MultiLine,
|
||||||
tr::lng_message_ph())) {
|
tr::lng_message_ph()))
|
||||||
|
, _header(std::make_unique<FieldHeader>(
|
||||||
|
_wrap.get(),
|
||||||
|
&_window->session().data())) {
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,6 +279,11 @@ void ComposeControls::init() {
|
||||||
) | rpl::start_with_next([=](QRect clip) {
|
) | rpl::start_with_next([=](QRect clip) {
|
||||||
paintBackground(clip);
|
paintBackground(clip);
|
||||||
}, _wrap->lifetime());
|
}, _wrap->lifetime());
|
||||||
|
|
||||||
|
_header->editMsgId(
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
updateHeight();
|
||||||
|
}, _wrap->lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComposeControls::initField() {
|
void ComposeControls::initField() {
|
||||||
|
@ -312,6 +397,11 @@ void ComposeControls::updateControlsGeometry(QSize size) {
|
||||||
left,
|
left,
|
||||||
size.height() - _field->height() - st::historySendPadding);
|
size.height() - _field->height() - st::historySendPadding);
|
||||||
|
|
||||||
|
_header->resizeToWidth(size.width());
|
||||||
|
_header->moveToLeft(
|
||||||
|
0,
|
||||||
|
_field->y() - _header->height() - st::historySendPadding);
|
||||||
|
|
||||||
auto right = st::historySendRight;
|
auto right = st::historySendRight;
|
||||||
_send->moveToRight(right, buttonsTop);
|
_send->moveToRight(right, buttonsTop);
|
||||||
right += _send->width();
|
right += _send->width();
|
||||||
|
@ -408,8 +498,14 @@ void ComposeControls::toggleTabbedSelectorMode() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComposeControls::updateHeight() {
|
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);
|
_wrap->resize(_wrap->width(), height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ComposeControls::editMessage(FullMsgId edit) {
|
||||||
|
_header->editMessage(std::move(edit));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace HistoryView
|
} // namespace HistoryView
|
||||||
|
|
|
@ -45,6 +45,8 @@ struct SectionShow;
|
||||||
|
|
||||||
namespace HistoryView {
|
namespace HistoryView {
|
||||||
|
|
||||||
|
class FieldHeader;
|
||||||
|
|
||||||
class ComposeControls final {
|
class ComposeControls final {
|
||||||
public:
|
public:
|
||||||
enum class Mode {
|
enum class Mode {
|
||||||
|
@ -90,6 +92,8 @@ public:
|
||||||
void showStarted();
|
void showStarted();
|
||||||
void showFinished();
|
void showFinished();
|
||||||
|
|
||||||
|
void editMessage(FullMsgId edit);
|
||||||
|
|
||||||
[[nodiscard]] TextWithTags getTextWithAppliedMarkdown() const;
|
[[nodiscard]] TextWithTags getTextWithAppliedMarkdown() const;
|
||||||
void clear();
|
void clear();
|
||||||
void hidePanelsAnimated();
|
void hidePanelsAnimated();
|
||||||
|
@ -125,6 +129,9 @@ private:
|
||||||
std::unique_ptr<InlineBots::Layout::Widget> _inlineResults;
|
std::unique_ptr<InlineBots::Layout::Widget> _inlineResults;
|
||||||
std::unique_ptr<ChatHelpers::TabbedPanel> _tabbedPanel;
|
std::unique_ptr<ChatHelpers::TabbedPanel> _tabbedPanel;
|
||||||
|
|
||||||
|
friend class FieldHeader;
|
||||||
|
const std::unique_ptr<FieldHeader> _header;
|
||||||
|
|
||||||
rpl::event_stream<> _cancelRequests;
|
rpl::event_stream<> _cancelRequests;
|
||||||
rpl::event_stream<not_null<DocumentData*>> _fileChosen;
|
rpl::event_stream<not_null<DocumentData*>> _fileChosen;
|
||||||
rpl::event_stream<not_null<PhotoData*>> _photoChosen;
|
rpl::event_stream<not_null<PhotoData*>> _photoChosen;
|
||||||
|
|
|
@ -477,11 +477,15 @@ bool AddEditMessageAction(
|
||||||
if (!item) {
|
if (!item) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!item->media() || !item->media()->allowsEditCaption()) {
|
if (const auto media = item->media()) {
|
||||||
return;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2550,6 +2550,14 @@ QPoint ListWidget::mapPointToItem(
|
||||||
return point - QPoint(0, itemTop(view));
|
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;
|
ListWidget::~ListWidget() = default;
|
||||||
|
|
||||||
} // namespace HistoryView
|
} // namespace HistoryView
|
||||||
|
|
|
@ -181,6 +181,9 @@ public:
|
||||||
QPoint tooltipPos() const override;
|
QPoint tooltipPos() const override;
|
||||||
bool tooltipWindowActive() const override;
|
bool tooltipWindowActive() const override;
|
||||||
|
|
||||||
|
rpl::producer<FullMsgId> editMessageRequested() const;
|
||||||
|
void editMessageRequestNotify(FullMsgId item);
|
||||||
|
|
||||||
// ElementDelegate interface.
|
// ElementDelegate interface.
|
||||||
Context elementContext() override;
|
Context elementContext() override;
|
||||||
std::unique_ptr<Element> elementCreate(
|
std::unique_ptr<Element> elementCreate(
|
||||||
|
@ -512,6 +515,8 @@ private:
|
||||||
FullMsgId _highlightedMessageId;
|
FullMsgId _highlightedMessageId;
|
||||||
base::Timer _highlightTimer;
|
base::Timer _highlightTimer;
|
||||||
|
|
||||||
|
rpl::event_stream<FullMsgId> _requestedToEditMessage;
|
||||||
|
|
||||||
rpl::lifetime _viewerLifetime;
|
rpl::lifetime _viewerLifetime;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -130,6 +130,11 @@ ScheduledWidget::ScheduledWidget(
|
||||||
_scroll->show();
|
_scroll->show();
|
||||||
connect(_scroll, &Ui::ScrollArea::scrolled, [=] { onScroll(); });
|
connect(_scroll, &Ui::ScrollArea::scrolled, [=] { onScroll(); });
|
||||||
|
|
||||||
|
_inner->editMessageRequested(
|
||||||
|
) | rpl::start_with_next([=](auto id) {
|
||||||
|
_composeControls->editMessage(id);
|
||||||
|
}, _inner->lifetime());
|
||||||
|
|
||||||
setupScrollDownButton();
|
setupScrollDownButton();
|
||||||
setupComposeControls();
|
setupComposeControls();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue