mirror of https://github.com/procxx/kepka.git
Redesigned edit media button. Slightly refactored.
- Added minimal height of thumbs. - Removed unused _statusw.
This commit is contained in:
parent
25e0e4b5d3
commit
92d10fd34c
|
@ -163,7 +163,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_pinned_unpin" = "Unpin";
|
"lng_pinned_unpin" = "Unpin";
|
||||||
"lng_pinned_notify" = "Notify all members";
|
"lng_pinned_notify" = "Notify all members";
|
||||||
|
|
||||||
"lng_edit_media" = "Edit media";
|
|
||||||
"lng_edit_media_album_error" = "This file cannot be saved as a part of an album.";
|
"lng_edit_media_album_error" = "This file cannot be saved as a part of an album.";
|
||||||
"lng_edit_media_invalid_file" = "Sorry, no way to use this file.";
|
"lng_edit_media_invalid_file" = "Sorry, no way to use this file.";
|
||||||
|
|
||||||
|
|
|
@ -595,6 +595,23 @@ backgroundScroll: ScrollArea(boxLayerScroll) {
|
||||||
deltab: 10px;
|
deltab: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
editMediaButtonSize: 29px;
|
||||||
|
editMediaButtonSkip: 8px;
|
||||||
|
editMediaButtonFileSkipRight: 1px;
|
||||||
|
editMediaButtonFileSkipTop: 7px;
|
||||||
|
|
||||||
|
editMediaButtonIconFile: icon {{ "settings_edit", menuIconFg }};
|
||||||
|
editMediaButtonIconPhoto: icon {{ "settings_edit", msgServiceFg }};
|
||||||
|
editMediaButton: IconButton {
|
||||||
|
width: editMediaButtonSize;
|
||||||
|
height: editMediaButtonSize;
|
||||||
|
|
||||||
|
icon: editMediaButtonIconPhoto;
|
||||||
|
|
||||||
|
rippleAreaSize: editMediaButtonSize;
|
||||||
|
ripple: defaultRippleAnimation;
|
||||||
|
}
|
||||||
|
|
||||||
calendarTitleHeight: boxTitleHeight;
|
calendarTitleHeight: boxTitleHeight;
|
||||||
calendarPrevious: IconButton {
|
calendarPrevious: IconButton {
|
||||||
width: calendarTitleHeight;
|
width: calendarTitleHeight;
|
||||||
|
|
|
@ -174,8 +174,17 @@ EditCaptionBox::EditCaptionBox(
|
||||||
if (!tw || !th) {
|
if (!tw || !th) {
|
||||||
tw = th = 1;
|
tw = th = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Edit media button takes place on thumb preview
|
||||||
|
// And its height can be greater than height of thumb.
|
||||||
|
const auto minThumbHeight = st::editMediaButtonSize
|
||||||
|
+ st::editMediaButtonSkip * 2;
|
||||||
|
const auto minThumbWidth = minThumbHeight * tw / th;
|
||||||
|
|
||||||
if (thumbWidth < st::sendMediaPreviewSize) {
|
if (thumbWidth < st::sendMediaPreviewSize) {
|
||||||
thumbWidth = (thumbWidth > 20) ? thumbWidth : 20;
|
thumbWidth = (thumbWidth > minThumbWidth)
|
||||||
|
? thumbWidth
|
||||||
|
: minThumbWidth;
|
||||||
} else {
|
} else {
|
||||||
thumbWidth = st::sendMediaPreviewSize;
|
thumbWidth = st::sendMediaPreviewSize;
|
||||||
}
|
}
|
||||||
|
@ -211,7 +220,7 @@ EditCaptionBox::EditCaptionBox(
|
||||||
_thumb = App::pixmapFromImageInPlace(_thumb.toImage().scaled(
|
_thumb = App::pixmapFromImageInPlace(_thumb.toImage().scaled(
|
||||||
_thumbw * cIntRetinaFactor(),
|
_thumbw * cIntRetinaFactor(),
|
||||||
_thumbh * cIntRetinaFactor(),
|
_thumbh * cIntRetinaFactor(),
|
||||||
Qt::IgnoreAspectRatio,
|
Qt::KeepAspectRatio,
|
||||||
Qt::SmoothTransformation));
|
Qt::SmoothTransformation));
|
||||||
_thumb.setDevicePixelRatio(cRetinaFactor());
|
_thumb.setDevicePixelRatio(cRetinaFactor());
|
||||||
};
|
};
|
||||||
|
@ -397,9 +406,20 @@ void EditCaptionBox::updateEditPreview() {
|
||||||
_thumbh = _thumb.height() / cIntRetinaFactor();
|
_thumbh = _thumb.height() / cIntRetinaFactor();
|
||||||
_thumbx = (st::boxWideWidth - _thumbw) / 2;
|
_thumbx = (st::boxWideWidth - _thumbw) / 2;
|
||||||
}
|
}
|
||||||
|
updateEditMediaButton();
|
||||||
captionResized();
|
captionResized();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditCaptionBox::updateEditMediaButton() {
|
||||||
|
const auto icon = _doc
|
||||||
|
? &st::editMediaButtonIconFile
|
||||||
|
: &st::editMediaButtonIconPhoto;
|
||||||
|
const auto color = _doc ? &st::windowBgRipple : &st::callFingerprintBg;
|
||||||
|
_editMedia->setIconOverride(icon);
|
||||||
|
_editMedia->setRippleColorOverride(color);
|
||||||
|
_editMedia->setForceRippled(!_doc, anim::type::instant);
|
||||||
|
}
|
||||||
|
|
||||||
void EditCaptionBox::createEditMediaButton() {
|
void EditCaptionBox::createEditMediaButton() {
|
||||||
const auto callback = [=](FileDialog::OpenResult &&result) {
|
const auto callback = [=](FileDialog::OpenResult &&result) {
|
||||||
if (result.paths.isEmpty() && result.remoteContent.isEmpty()) {
|
if (result.paths.isEmpty() && result.remoteContent.isEmpty()) {
|
||||||
|
@ -494,11 +514,15 @@ void EditCaptionBox::createEditMediaButton() {
|
||||||
crl::guard(this, callback));
|
crl::guard(this, callback));
|
||||||
};
|
};
|
||||||
|
|
||||||
_editMediaClicks.events() | rpl::start_with_next([=] {
|
_editMediaClicks.events(
|
||||||
buttonCallback();
|
) | rpl::start_with_next(
|
||||||
}, lifetime());
|
buttonCallback,
|
||||||
|
lifetime());
|
||||||
|
|
||||||
addButton(langFactory(lng_edit_media), buttonCallback);
|
// Create edit media button.
|
||||||
|
_editMedia.create(this, st::editMediaButton);
|
||||||
|
updateEditMediaButton();
|
||||||
|
_editMedia->setClickedCallback(buttonCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditCaptionBox::prepare() {
|
void EditCaptionBox::prepare() {
|
||||||
|
@ -702,11 +726,8 @@ void EditCaptionBox::paintEvent(QPaintEvent *e) {
|
||||||
nameright = 0;
|
nameright = 0;
|
||||||
statustop = st::msgFileStatusTop - st::msgFilePadding.top();
|
statustop = st::msgFileStatusTop - st::msgFilePadding.top();
|
||||||
}
|
}
|
||||||
const auto namewidth = w - nameleft - 0;
|
const auto editButton = _editMedia->width() + st::editMediaButtonSkip;
|
||||||
if (namewidth > _statusw) {
|
const auto namewidth = w - nameleft - editButton;
|
||||||
//w -= (namewidth - _statusw);
|
|
||||||
//namewidth = _statusw;
|
|
||||||
}
|
|
||||||
const auto x = (width() - w) / 2, y = st::boxPhotoPadding.top();
|
const auto x = (width() - w) / 2, y = st::boxPhotoPadding.top();
|
||||||
|
|
||||||
// App::roundRect(p, x, y, w, h, st::msgInBg, MessageInCorners, &st::msgInShadow);
|
// App::roundRect(p, x, y, w, h, st::msgInBg, MessageInCorners, &st::msgInShadow);
|
||||||
|
@ -746,6 +767,16 @@ void EditCaptionBox::paintEvent(QPaintEvent *e) {
|
||||||
p.setPen(st::boxTextFgError);
|
p.setPen(st::boxTextFgError);
|
||||||
p.drawTextLeft(_field->x(), _field->y() + _field->height() + errorTopSkip(), width(), _error);
|
p.drawTextLeft(_field->x(), _field->y() + _field->height() + errorTopSkip(), width(), _error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_isAllowedEditMedia) {
|
||||||
|
_editMedia->moveToRight(
|
||||||
|
st::boxPhotoPadding.right() + (_doc
|
||||||
|
? st::editMediaButtonFileSkipRight
|
||||||
|
: st::editMediaButtonSkip),
|
||||||
|
st::boxPhotoPadding.top() + (_doc
|
||||||
|
? st::editMediaButtonFileSkipTop
|
||||||
|
: st::editMediaButtonSkip));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditCaptionBox::resizeEvent(QResizeEvent *e) {
|
void EditCaptionBox::resizeEvent(QResizeEvent *e) {
|
||||||
|
@ -866,9 +897,6 @@ void EditCaptionBox::setName(QString nameString, qint64 size) {
|
||||||
nameString,
|
nameString,
|
||||||
Ui::NameTextOptions());
|
Ui::NameTextOptions());
|
||||||
_status = formatSizeText(size);
|
_status = formatSizeText(size);
|
||||||
_statusw = std::max(
|
|
||||||
_name.maxWidth(),
|
|
||||||
st::normalFont->width(_status));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditCaptionBox::keyPressEvent(QKeyEvent *e) {
|
void EditCaptionBox::keyPressEvent(QKeyEvent *e) {
|
||||||
|
|
|
@ -27,6 +27,7 @@ class Media;
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class InputField;
|
class InputField;
|
||||||
class EmojiButton;
|
class EmojiButton;
|
||||||
|
class IconButton;
|
||||||
class Checkbox;
|
class Checkbox;
|
||||||
} // namespace Ui
|
} // namespace Ui
|
||||||
|
|
||||||
|
@ -67,6 +68,7 @@ private:
|
||||||
void setName(QString nameString, qint64 size);
|
void setName(QString nameString, qint64 size);
|
||||||
bool fileFromClipboard(not_null<const QMimeData*> data);
|
bool fileFromClipboard(not_null<const QMimeData*> data);
|
||||||
void updateEditPreview();
|
void updateEditPreview();
|
||||||
|
void updateEditMediaButton();
|
||||||
|
|
||||||
int errorTopSkip() const;
|
int errorTopSkip() const;
|
||||||
|
|
||||||
|
@ -100,7 +102,6 @@ private:
|
||||||
int _thumbh = 0;
|
int _thumbh = 0;
|
||||||
Text _name;
|
Text _name;
|
||||||
QString _status;
|
QString _status;
|
||||||
int _statusw = 0;
|
|
||||||
bool _isAudio = false;
|
bool _isAudio = false;
|
||||||
bool _isImage = false;
|
bool _isImage = false;
|
||||||
|
|
||||||
|
@ -113,11 +114,12 @@ private:
|
||||||
bool _previewCancelled = false;
|
bool _previewCancelled = false;
|
||||||
mtpRequestId _saveRequestId = 0;
|
mtpRequestId _saveRequestId = 0;
|
||||||
|
|
||||||
bool _asFile = false;
|
object_ptr<Ui::IconButton> _editMedia = nullptr;
|
||||||
Ui::SlideWrap<Ui::RpWidget> *_wayWrap = nullptr;
|
Ui::SlideWrap<Ui::RpWidget> *_wayWrap = nullptr;
|
||||||
QString _newMediaPath;
|
QString _newMediaPath;
|
||||||
bool _isAllowedEditMedia = false;
|
bool _isAllowedEditMedia = false;
|
||||||
bool _isAlbum = false;
|
bool _isAlbum = false;
|
||||||
|
bool _asFile = false;
|
||||||
rpl::event_stream<> _editMediaClicks;
|
rpl::event_stream<> _editMediaClicks;
|
||||||
|
|
||||||
QString _error;
|
QString _error;
|
||||||
|
|
Loading…
Reference in New Issue