Added checkbox to send photo as file for edit media.

This commit is contained in:
23rd 2019-03-27 13:44:57 +03:00 committed by John Preston
parent 6735605f21
commit 820c7ba84e
3 changed files with 36 additions and 1 deletions

View File

@ -643,6 +643,8 @@ usernameTextStyle: TextStyle(boxTextStyle, passcodeTextStyle) {
}
usernameDefaultFg: windowSubTextFg;
editMediaCheckboxMargins: margins(0px, 15px, 23px, 15px);
downloadPathSkip: 10px;
colorEditWidth: 390px;

View File

@ -35,6 +35,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/text_options.h"
#include "ui/widgets/input_fields.h"
#include "window/window_controller.h"
#include "ui/widgets/checkbox.h"
EditCaptionBox::EditCaptionBox(
QWidget*,
@ -247,6 +248,22 @@ EditCaptionBox::EditCaptionBox(
_field->setInstantReplacesEnabled(Global::ReplaceEmojiValue());
_field->setMarkdownReplacesEnabled(rpl::single(true));
_field->setEditLinkCallback(DefaultEditLinkCallback(_field));
auto r = object_ptr<Ui::SlideWrap<Ui::Checkbox>>(
this,
object_ptr<Ui::Checkbox>(
this,
lang(lng_send_file),
false,
st::defaultBoxCheckbox),
st::editMediaCheckboxMargins);
_wayWrap = r.data();
_wayWrap->toggle(false, anim::type::instant);
r->entity()->checkedChanges(
) | rpl::start_with_next([&](bool checked) {
_asFile = checked;
}, _wayWrap->lifetime());
}
bool EditCaptionBox::emojiFilter(not_null<QEvent*> event) {
@ -345,6 +362,7 @@ void EditCaptionBox::prepare() {
_gifw = _gifh = _gifx = 0;
auto isGif = false;
_wayWrap->toggle(_isImage, anim::type::instant);
using Info = FileMediaInformation;
if (const auto image = base::get_if<Info::Image>(fileMedia)
@ -450,6 +468,9 @@ void EditCaptionBox::setupEmojiPanel() {
void EditCaptionBox::updateBoxSize() {
auto newHeight = st::boxPhotoPadding.top() + st::boxPhotoCaptionSkip + _field->height() + errorTopSkip() + st::normalFont->height;
if (_isImage) {
newHeight += _wayWrap->height() / 2;
}
if (_photo || _animated) {
newHeight += std::max(_thumbh, _gifh);
} else if (_thumbw) {
@ -564,6 +585,14 @@ void EditCaptionBox::paintEvent(QPaintEvent *e) {
void EditCaptionBox::resizeEvent(QResizeEvent *e) {
BoxContent::resizeEvent(e);
if (_isImage) {
_wayWrap->resize(st::sendMediaPreviewSize, _wayWrap->height());
_wayWrap->moveToLeft(
st::boxPhotoPadding.left(),
st::boxPhotoPadding.top() + _thumbh);
}
_field->resize(st::sendMediaPreviewSize, _field->height());
_field->moveToLeft(st::boxPhotoPadding.left(), height() - st::normalFont->height - errorTopSkip() - _field->height());
_emojiToggle->moveToLeft(
@ -620,7 +649,7 @@ void EditCaptionBox::save() {
Auth().api().editMedia(
std::move(_preparedList),
_isImage ? SendMediaType::Photo : SendMediaType::File,
(!_asFile && _isImage) ? SendMediaType::Photo : SendMediaType::File,
_field->getTextWithAppliedMarkdown(),
ApiWrap::SendOptions(item->history()));
closeBox();

View File

@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/abstract_box.h"
#include "storage/storage_media_prepare.h"
#include "ui/wrap/slide_wrap.h"
namespace ChatHelpers {
class TabbedPanel;
@ -25,6 +26,7 @@ class Media;
namespace Ui {
class InputField;
class EmojiButton;
class Checkbox;
} // namespace Ui
namespace Window {
@ -99,6 +101,8 @@ private:
bool _previewCancelled = false;
mtpRequestId _saveRequestId = 0;
bool _asFile = false;
Ui::SlideWrap<Ui::RpWidget> *_wayWrap = nullptr;
QString _newMediaPath;
QString _error;