mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added counter label of characters limit to send files box.
This commit is contained in:
parent
d1eaf284b1
commit
6de471db17
6 changed files with 64 additions and 8 deletions
|
@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "chat_helpers/tabbed_selector.h"
|
#include "chat_helpers/tabbed_selector.h"
|
||||||
#include "editor/photo_editor_layer_widget.h"
|
#include "editor/photo_editor_layer_widget.h"
|
||||||
#include "history/history_drag_area.h"
|
#include "history/history_drag_area.h"
|
||||||
|
#include "history/view/controls/history_view_characters_limit.h"
|
||||||
#include "history/view/history_view_schedule_box.h"
|
#include "history/view/history_view_schedule_box.h"
|
||||||
#include "core/file_utilities.h"
|
#include "core/file_utilities.h"
|
||||||
#include "core/mime_type.h"
|
#include "core/mime_type.h"
|
||||||
|
@ -48,6 +49,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "lottie/lottie_single_player.h"
|
#include "lottie/lottie_single_player.h"
|
||||||
#include "data/data_document.h"
|
#include "data/data_document.h"
|
||||||
#include "data/data_user.h"
|
#include "data/data_user.h"
|
||||||
|
#include "data/data_peer_values.h" // Data::AmPremiumValue.
|
||||||
#include "data/data_premium_limits.h"
|
#include "data/data_premium_limits.h"
|
||||||
#include "data/stickers/data_stickers.h"
|
#include "data/stickers/data_stickers.h"
|
||||||
#include "data/stickers/data_custom_emoji.h"
|
#include "data/stickers/data_custom_emoji.h"
|
||||||
|
@ -1060,6 +1062,39 @@ void SendFilesBox::setupCaption() {
|
||||||
|
|
||||||
updateCaptionPlaceholder();
|
updateCaptionPlaceholder();
|
||||||
setupEmojiPanel();
|
setupEmojiPanel();
|
||||||
|
|
||||||
|
rpl::single(rpl::empty_value()) | rpl::then(
|
||||||
|
_caption->changes()
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
checkCharsLimitation();
|
||||||
|
}, _caption->lifetime());
|
||||||
|
}
|
||||||
|
|
||||||
|
void SendFilesBox::checkCharsLimitation() {
|
||||||
|
const auto limits = Data::PremiumLimits(&_show->session());
|
||||||
|
const auto caption = (_caption && !_caption->isHidden())
|
||||||
|
? _caption->getTextWithAppliedMarkdown()
|
||||||
|
: TextWithTags();
|
||||||
|
const auto remove = caption.text.size() - limits.captionLengthCurrent();
|
||||||
|
if ((remove > 0) && _emojiToggle) {
|
||||||
|
if (!_charsLimitation) {
|
||||||
|
_charsLimitation = base::make_unique_q<CharactersLimitLabel>(
|
||||||
|
this,
|
||||||
|
_emojiToggle.data(),
|
||||||
|
style::al_top);
|
||||||
|
_charsLimitation->show();
|
||||||
|
Data::AmPremiumValue(
|
||||||
|
&_show->session()
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
checkCharsLimitation();
|
||||||
|
}, _charsLimitation->lifetime());
|
||||||
|
}
|
||||||
|
_charsLimitation->setLeft(remove);
|
||||||
|
} else {
|
||||||
|
if (_charsLimitation) {
|
||||||
|
_charsLimitation = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendFilesBox::setupEmojiPanel() {
|
void SendFilesBox::setupEmojiPanel() {
|
||||||
|
|
|
@ -50,6 +50,10 @@ namespace SendMenu {
|
||||||
enum class Type;
|
enum class Type;
|
||||||
} // namespace SendMenu
|
} // namespace SendMenu
|
||||||
|
|
||||||
|
namespace HistoryView::Controls {
|
||||||
|
class CharactersLimitLabel;
|
||||||
|
} // namespace HistoryView::Controls
|
||||||
|
|
||||||
enum class SendFilesAllow {
|
enum class SendFilesAllow {
|
||||||
OnlyOne = (1 << 0),
|
OnlyOne = (1 << 0),
|
||||||
Photos = (1 << 1),
|
Photos = (1 << 1),
|
||||||
|
@ -221,6 +225,8 @@ private:
|
||||||
void enqueueNextPrepare();
|
void enqueueNextPrepare();
|
||||||
void addPreparedAsyncFile(Ui::PreparedFile &&file);
|
void addPreparedAsyncFile(Ui::PreparedFile &&file);
|
||||||
|
|
||||||
|
void checkCharsLimitation();
|
||||||
|
|
||||||
const std::shared_ptr<ChatHelpers::Show> _show;
|
const std::shared_ptr<ChatHelpers::Show> _show;
|
||||||
const style::ComposeControls &_st;
|
const style::ComposeControls &_st;
|
||||||
const Api::SendType _sendType = Api::SendType();
|
const Api::SendType _sendType = Api::SendType();
|
||||||
|
@ -244,6 +250,8 @@ private:
|
||||||
object_ptr<Ui::EmojiButton> _emojiToggle = { nullptr };
|
object_ptr<Ui::EmojiButton> _emojiToggle = { nullptr };
|
||||||
base::unique_qptr<ChatHelpers::TabbedPanel> _emojiPanel;
|
base::unique_qptr<ChatHelpers::TabbedPanel> _emojiPanel;
|
||||||
base::unique_qptr<QObject> _emojiFilter;
|
base::unique_qptr<QObject> _emojiFilter;
|
||||||
|
using CharactersLimitLabel = HistoryView::Controls::CharactersLimitLabel;
|
||||||
|
base::unique_qptr<CharactersLimitLabel> _charsLimitation;
|
||||||
|
|
||||||
object_ptr<Ui::Checkbox> _groupFiles = { nullptr };
|
object_ptr<Ui::Checkbox> _groupFiles = { nullptr };
|
||||||
object_ptr<Ui::Checkbox> _sendImagesAsPhotos = { nullptr };
|
object_ptr<Ui::Checkbox> _sendImagesAsPhotos = { nullptr };
|
||||||
|
|
|
@ -7319,7 +7319,8 @@ void HistoryWidget::checkCharsLimitation() {
|
||||||
if (!_charsLimitation) {
|
if (!_charsLimitation) {
|
||||||
_charsLimitation = base::make_unique_q<CharactersLimitLabel>(
|
_charsLimitation = base::make_unique_q<CharactersLimitLabel>(
|
||||||
this,
|
this,
|
||||||
_send.get());
|
_send.get(),
|
||||||
|
style::al_bottom);
|
||||||
_charsLimitation->show();
|
_charsLimitation->show();
|
||||||
Data::AmPremiumValue(
|
Data::AmPremiumValue(
|
||||||
&session()
|
&session()
|
||||||
|
|
|
@ -7,20 +7,30 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "history/view/controls/history_view_characters_limit.h"
|
#include "history/view/controls/history_view_characters_limit.h"
|
||||||
|
|
||||||
|
#include "ui/rect.h"
|
||||||
#include "styles/style_chat_helpers.h"
|
#include "styles/style_chat_helpers.h"
|
||||||
|
|
||||||
namespace HistoryView::Controls {
|
namespace HistoryView::Controls {
|
||||||
|
|
||||||
CharactersLimitLabel::CharactersLimitLabel(
|
CharactersLimitLabel::CharactersLimitLabel(
|
||||||
not_null<Ui::RpWidget*> parent,
|
not_null<Ui::RpWidget*> parent,
|
||||||
not_null<Ui::RpWidget*> widgetBelow)
|
not_null<Ui::RpWidget*> widgetToAlign,
|
||||||
|
style::align align)
|
||||||
: Ui::FlatLabel(parent, st::historyCharsLimitationLabel) {
|
: Ui::FlatLabel(parent, st::historyCharsLimitationLabel) {
|
||||||
|
Expects((align == style::al_top) || align == style::al_bottom);
|
||||||
|
const auto w = st::historyCharsLimitationLabel.minWidth;
|
||||||
|
using F = Fn<void(int, const QRect &)>;
|
||||||
|
const auto position = (align == style::al_top)
|
||||||
|
? F([=](int height, const QRect &g) {
|
||||||
|
move(g.x() + (g.width() - w) / 2, rect::bottom(g));
|
||||||
|
})
|
||||||
|
: F([=](int height, const QRect &g) {
|
||||||
|
move(g.x() + (g.width() - w) / 2, g.y() - height);
|
||||||
|
});
|
||||||
rpl::combine(
|
rpl::combine(
|
||||||
Ui::RpWidget::heightValue(),
|
Ui::RpWidget::heightValue(),
|
||||||
widgetBelow->positionValue()
|
widgetToAlign->geometryValue()
|
||||||
) | rpl::start_with_next([=](int height, const QPoint &p) {
|
) | rpl::start_with_next(position, lifetime());
|
||||||
move(p.x(), p.y() - height);
|
|
||||||
}, lifetime());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CharactersLimitLabel::setLeft(int value) {
|
void CharactersLimitLabel::setLeft(int value) {
|
||||||
|
|
|
@ -15,7 +15,8 @@ class CharactersLimitLabel final : public Ui::FlatLabel {
|
||||||
public:
|
public:
|
||||||
CharactersLimitLabel(
|
CharactersLimitLabel(
|
||||||
not_null<Ui::RpWidget*> parent,
|
not_null<Ui::RpWidget*> parent,
|
||||||
not_null<Ui::RpWidget*> widgetBelow);
|
not_null<Ui::RpWidget*> widgetToAlign,
|
||||||
|
style::align align);
|
||||||
|
|
||||||
void setLeft(int value);
|
void setLeft(int value);
|
||||||
|
|
||||||
|
|
|
@ -3322,7 +3322,8 @@ void ComposeControls::checkCharsLimitation() {
|
||||||
using namespace Controls;
|
using namespace Controls;
|
||||||
_charsLimitation = base::make_unique_q<CharactersLimitLabel>(
|
_charsLimitation = base::make_unique_q<CharactersLimitLabel>(
|
||||||
_wrap.get(),
|
_wrap.get(),
|
||||||
_send.get());
|
_send.get(),
|
||||||
|
style::al_bottom);
|
||||||
_charsLimitation->show();
|
_charsLimitation->show();
|
||||||
Data::AmPremiumValue(
|
Data::AmPremiumValue(
|
||||||
&session()
|
&session()
|
||||||
|
|
Loading…
Add table
Reference in a new issue