mirror of https://github.com/procxx/kepka.git
Added ability to delete and edit files in SendFilesBox.
This commit is contained in:
parent
836df873f0
commit
a1bb9cbb2b
|
@ -522,15 +522,18 @@ sendBoxAlbumGroupSkipTop: 6px;
|
||||||
sendBoxAlbumGroupRadius: 12px;
|
sendBoxAlbumGroupRadius: 12px;
|
||||||
sendBoxAlbumGroupHeight: 25px;
|
sendBoxAlbumGroupHeight: 25px;
|
||||||
|
|
||||||
sendBoxAlbumGroupEditButtonIcon: icon {{ "settings_edit", msgServiceFg }};
|
sendBoxAlbumGroupEditButtonIcon: editMediaButtonIconPhoto;
|
||||||
sendBoxAlbumGroupEditButtonIconPosition: point(4px, -1px);
|
sendBoxAlbumGroupEditButtonIconPosition: point(4px, -1px);
|
||||||
sendBoxAlbumGroupButton: IconButton {
|
|
||||||
width: sendBoxAlbumGroupHeight;
|
sendBoxAlbumGroupButtonFile: IconButton(editMediaButton) {
|
||||||
height: sendBoxAlbumGroupHeight;
|
ripple: RippleAnimation(defaultRippleAnimation) {
|
||||||
|
color: windowBgRipple;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sendBoxAlbumGroupDeleteButtonIcon: icon {{ "history_file_cancel", msgServiceFg}};
|
|
||||||
sendBoxAlbumGroupDeleteButtonIconPosition: point(-3px, 0px);
|
sendBoxAlbumGroupDeleteButtonIconPosition: point(-3px, 0px);
|
||||||
|
sendBoxAlbumGroupDeleteButtonIcon: icon {{ "history_file_cancel", msgServiceFg}};
|
||||||
|
sendBoxAlbumGroupDeleteButtonIconFile: icon {{ "history_file_cancel", menuIconFg, point(6px, 6px) }};
|
||||||
|
|
||||||
// End of SendFilesBox
|
// End of SendFilesBox
|
||||||
|
|
||||||
|
|
|
@ -231,7 +231,10 @@ class AlbumThumb {
|
||||||
public:
|
public:
|
||||||
AlbumThumb(
|
AlbumThumb(
|
||||||
const Storage::PreparedFile &file,
|
const Storage::PreparedFile &file,
|
||||||
const Ui::GroupMediaLayout &layout);
|
const Ui::GroupMediaLayout &layout,
|
||||||
|
QWidget *parent,
|
||||||
|
Fn<void()> editCallback,
|
||||||
|
Fn<void()> deleteCallback);
|
||||||
|
|
||||||
void moveToLayout(const Ui::GroupMediaLayout &layout);
|
void moveToLayout(const Ui::GroupMediaLayout &layout);
|
||||||
void animateLayoutToInitial();
|
void animateLayoutToInitial();
|
||||||
|
@ -258,10 +261,7 @@ public:
|
||||||
void suggestMove(float64 delta, Fn<void()> callback);
|
void suggestMove(float64 delta, Fn<void()> callback);
|
||||||
void finishAnimations();
|
void finishAnimations();
|
||||||
|
|
||||||
void addAlbumThumbButtons(
|
void updateFileRow(int row);
|
||||||
QWidget *parent,
|
|
||||||
Fn<void()> editCallback,
|
|
||||||
Fn<void()> deleteCallback);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QRect countRealGeometry() const;
|
QRect countRealGeometry() const;
|
||||||
|
@ -297,7 +297,10 @@ private:
|
||||||
|
|
||||||
AlbumThumb::AlbumThumb(
|
AlbumThumb::AlbumThumb(
|
||||||
const Storage::PreparedFile &file,
|
const Storage::PreparedFile &file,
|
||||||
const Ui::GroupMediaLayout &layout)
|
const Ui::GroupMediaLayout &layout,
|
||||||
|
QWidget *parent,
|
||||||
|
Fn<void()> editCallback,
|
||||||
|
Fn<void()> deleteCallback)
|
||||||
: _layout(layout)
|
: _layout(layout)
|
||||||
, _fullPreview(file.preview)
|
, _fullPreview(file.preview)
|
||||||
, _shrinkSize(int(std::ceil(st::historyMessageRadius / 1.4)))
|
, _shrinkSize(int(std::ceil(st::historyMessageRadius / 1.4)))
|
||||||
|
@ -338,7 +341,11 @@ AlbumThumb::AlbumThumb(
|
||||||
|
|
||||||
const auto availableFileWidth = st::sendMediaPreviewSize
|
const auto availableFileWidth = st::sendMediaPreviewSize
|
||||||
- st::sendMediaFileThumbSkip
|
- st::sendMediaFileThumbSkip
|
||||||
- st::sendMediaFileThumbSize;
|
- st::sendMediaFileThumbSize
|
||||||
|
// Right buttons.
|
||||||
|
- st::sendBoxAlbumGroupButtonFile.width * 2
|
||||||
|
- st::sendBoxAlbumGroupEditInternalSkip
|
||||||
|
- st::sendBoxAlbumGroupSkipRight;
|
||||||
const auto filepath = file.path;
|
const auto filepath = file.path;
|
||||||
if (filepath.isEmpty()) {
|
if (filepath.isEmpty()) {
|
||||||
_name = filedialogDefaultName(
|
_name = filedialogDefaultName(
|
||||||
|
@ -365,17 +372,45 @@ AlbumThumb::AlbumThumb(
|
||||||
_nameWidth = st::semiboldFont->width(_name);
|
_nameWidth = st::semiboldFont->width(_name);
|
||||||
}
|
}
|
||||||
_statusWidth = st::normalFont->width(_status);
|
_statusWidth = st::normalFont->width(_status);
|
||||||
|
|
||||||
|
_editMedia.create(parent, st::sendBoxAlbumGroupButtonFile);
|
||||||
|
_deleteMedia.create(parent, st::sendBoxAlbumGroupButtonFile);
|
||||||
|
|
||||||
|
const auto duration = st::historyAttach.ripple.hideDuration;
|
||||||
|
_editMedia->setClickedCallback(App::LambdaDelayed(
|
||||||
|
duration,
|
||||||
|
parent,
|
||||||
|
std::move(editCallback)));
|
||||||
|
_deleteMedia->setClickedCallback(App::LambdaDelayed(
|
||||||
|
duration,
|
||||||
|
parent,
|
||||||
|
std::move(deleteCallback)));
|
||||||
|
|
||||||
|
_editMedia->setIconOverride(&st::editMediaButtonIconFile);
|
||||||
|
_deleteMedia->setIconOverride(&st::sendBoxAlbumGroupDeleteButtonIconFile);
|
||||||
|
|
||||||
|
updateFileRow(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AlbumThumb::addAlbumThumbButtons(
|
void AlbumThumb::updateFileRow(int row) {
|
||||||
QWidget *parent,
|
if (row < 0) {
|
||||||
Fn<void()> editCallback,
|
_editMedia->hide();
|
||||||
Fn<void()> deleteCallback) {
|
_deleteMedia->hide();
|
||||||
_editMedia.create(parent, st::sendBoxAlbumGroupButton);
|
return;
|
||||||
_deleteMedia.create(parent, st::sendBoxAlbumGroupButton);
|
}
|
||||||
|
_editMedia->show();
|
||||||
|
_deleteMedia->show();
|
||||||
|
|
||||||
_editMedia->setClickedCallback(std::move(editCallback));
|
const auto fileHeight = st::sendMediaFileThumbSize
|
||||||
_deleteMedia->setClickedCallback(std::move(deleteCallback));
|
+ st::sendMediaFileThumbSkip;
|
||||||
|
|
||||||
|
const auto top = row * fileHeight + st::sendBoxAlbumGroupSkipTop;
|
||||||
|
const auto size = st::editMediaButtonSize;
|
||||||
|
|
||||||
|
auto right = st::sendBoxAlbumGroupSkipRight + size;
|
||||||
|
_deleteMedia->moveToRight(right, top);
|
||||||
|
right += st::sendBoxAlbumGroupEditInternalSkip + size;
|
||||||
|
_editMedia->moveToRight(right, top);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AlbumThumb::resetLayoutAnimation() {
|
void AlbumThumb::resetLayoutAnimation() {
|
||||||
|
@ -1136,6 +1171,7 @@ private:
|
||||||
void prepareThumbs();
|
void prepareThumbs();
|
||||||
void updateSizeAnimated(const std::vector<Ui::GroupMediaLayout> &layout);
|
void updateSizeAnimated(const std::vector<Ui::GroupMediaLayout> &layout);
|
||||||
void updateSize();
|
void updateSize();
|
||||||
|
void updateFileRows();
|
||||||
|
|
||||||
int thumbIndex(AlbumThumb *thumb);
|
int thumbIndex(AlbumThumb *thumb);
|
||||||
AlbumThumb *thumbUnderCursor();
|
AlbumThumb *thumbUnderCursor();
|
||||||
|
@ -1192,6 +1228,7 @@ SendFilesBox::AlbumPreview::AlbumPreview(
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
prepareThumbs();
|
prepareThumbs();
|
||||||
updateSize();
|
updateSize();
|
||||||
|
updateFileRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendFilesBox::AlbumPreview::setSendWay(SendFilesWay way) {
|
void SendFilesBox::AlbumPreview::setSendWay(SendFilesWay way) {
|
||||||
|
@ -1200,9 +1237,18 @@ void SendFilesBox::AlbumPreview::setSendWay(SendFilesWay way) {
|
||||||
_sendWay = way;
|
_sendWay = way;
|
||||||
}
|
}
|
||||||
updateSize();
|
updateSize();
|
||||||
|
updateFileRows();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SendFilesBox::AlbumPreview::updateFileRows() {
|
||||||
|
Expects(_order.size() == _thumbs.size());
|
||||||
|
const auto isFile = (_sendWay == SendFilesWay::Files);
|
||||||
|
for (auto i = 0; i < _order.size(); i++) {
|
||||||
|
_thumbs[i]->updateFileRow(isFile ? _order[i] : -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<int> SendFilesBox::AlbumPreview::takeOrder() {
|
std::vector<int> SendFilesBox::AlbumPreview::takeOrder() {
|
||||||
auto reordered = std::vector<std::unique_ptr<AlbumThumb>>();
|
auto reordered = std::vector<std::unique_ptr<AlbumThumb>>();
|
||||||
reordered.reserve(_thumbs.size());
|
reordered.reserve(_thumbs.size());
|
||||||
|
@ -1244,7 +1290,10 @@ void SendFilesBox::AlbumPreview::prepareThumbs() {
|
||||||
for (auto i = 0; i != count; ++i) {
|
for (auto i = 0; i != count; ++i) {
|
||||||
_thumbs.push_back(std::make_unique<AlbumThumb>(
|
_thumbs.push_back(std::make_unique<AlbumThumb>(
|
||||||
_list.files[i],
|
_list.files[i],
|
||||||
layout[i]));
|
layout[i],
|
||||||
|
this,
|
||||||
|
[=] { changeThumbByIndex(thumbIndex(thumbUnderCursor())); },
|
||||||
|
[=] { deleteThumbByIndex(thumbIndex(thumbUnderCursor())); }));
|
||||||
}
|
}
|
||||||
_thumbsHeight = countLayoutHeight(layout);
|
_thumbsHeight = countLayoutHeight(layout);
|
||||||
_photosHeight = ranges::accumulate(ranges::view::all(
|
_photosHeight = ranges::accumulate(ranges::view::all(
|
||||||
|
@ -1269,13 +1318,19 @@ AlbumThumb *SendFilesBox::AlbumPreview::findThumb(QPoint position) const {
|
||||||
position -= QPoint(contentLeft(), contentTop());
|
position -= QPoint(contentLeft(), contentTop());
|
||||||
|
|
||||||
auto top = 0;
|
auto top = 0;
|
||||||
|
const auto isPhotosWay = (_sendWay == SendFilesWay::Photos);
|
||||||
|
const auto skip = isPhotosWay
|
||||||
|
? st::sendMediaPreviewPhotoSkip
|
||||||
|
: st::sendMediaFileThumbSkip;
|
||||||
auto find = [&](const auto &thumb) {
|
auto find = [&](const auto &thumb) {
|
||||||
if (_sendWay == SendFilesWay::Album) {
|
if (_sendWay == SendFilesWay::Album) {
|
||||||
return thumb->containsPoint(position);
|
return thumb->containsPoint(position);
|
||||||
} else if (_sendWay == SendFilesWay::Photos) {
|
} else if (isPhotosWay || _sendWay == SendFilesWay::Files) {
|
||||||
const auto bottom = top + thumb->photoHeight();
|
const auto bottom = top + (isPhotosWay
|
||||||
|
? thumb->photoHeight()
|
||||||
|
: st::sendMediaFileThumbSize);
|
||||||
const auto isUnderTop = (position.y() > top);
|
const auto isUnderTop = (position.y() > top);
|
||||||
top = bottom + st::sendMediaPreviewPhotoSkip;
|
top = bottom + skip;
|
||||||
return isUnderTop && (position.y() < bottom);
|
return isUnderTop && (position.y() < bottom);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue