mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 15:43:55 +02:00
Added drag'n'drop area to SendFilesBox for images.
This commit is contained in:
parent
4eaba39a7c
commit
e0750f7b87
2 changed files with 39 additions and 1 deletions
|
@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "chat_helpers/tabbed_panel.h"
|
#include "chat_helpers/tabbed_panel.h"
|
||||||
#include "chat_helpers/tabbed_selector.h"
|
#include "chat_helpers/tabbed_selector.h"
|
||||||
#include "confirm_box.h"
|
#include "confirm_box.h"
|
||||||
|
#include "history/history_drag_area.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"
|
||||||
|
@ -333,7 +334,7 @@ AlbumThumb::AlbumThumb(
|
||||||
- st::sendMediaFileThumbSize
|
- st::sendMediaFileThumbSize
|
||||||
// Right buttons.
|
// Right buttons.
|
||||||
- st::sendBoxAlbumGroupButtonFile.width * 2
|
- st::sendBoxAlbumGroupButtonFile.width * 2
|
||||||
- st::sendBoxAlbumGroupEditInternalSkip
|
- st::sendBoxAlbumGroupEditInternalSkip * 2
|
||||||
- st::sendBoxAlbumGroupSkipRight;
|
- st::sendBoxAlbumGroupSkipRight;
|
||||||
const auto filepath = file.path;
|
const auto filepath = file.path;
|
||||||
if (filepath.isEmpty()) {
|
if (filepath.isEmpty()) {
|
||||||
|
@ -1858,6 +1859,40 @@ void SendFilesBox::prepare() {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
updateLeftButtonVisibility();
|
updateLeftButtonVisibility();
|
||||||
|
setupDragArea();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SendFilesBox::setupDragArea() {
|
||||||
|
// Avoid both drag areas appearing at one time.
|
||||||
|
auto computeState = [=](const QMimeData *data) {
|
||||||
|
const auto state = Storage::ComputeMimeDataState(data);
|
||||||
|
return (state == Storage::MimeDataState::PhotoFiles)
|
||||||
|
? Storage::MimeDataState::Image
|
||||||
|
: (state == Storage::MimeDataState::Files)
|
||||||
|
// Temporary enable drag'n'drop only for images. TODO.
|
||||||
|
? Storage::MimeDataState::None
|
||||||
|
: state;
|
||||||
|
};
|
||||||
|
const auto areas = DragArea::SetupDragAreaToContainer(
|
||||||
|
this,
|
||||||
|
[=](not_null<const QMimeData*> d) { return canAddFiles(d); },
|
||||||
|
[=](bool f) { _caption->setAcceptDrops(f); },
|
||||||
|
[=] { updateControlsGeometry(); },
|
||||||
|
std::move(computeState));
|
||||||
|
|
||||||
|
const auto droppedCallback = [=](bool compress) {
|
||||||
|
return [=](const QMimeData *data) {
|
||||||
|
addFiles(data);
|
||||||
|
Window::ActivateWindow(_controller);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
areas.document->setDroppedCallback(droppedCallback(false));
|
||||||
|
areas.photo->setDroppedCallback(droppedCallback(true));
|
||||||
|
_albumChanged.events(
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
areas.document->raise();
|
||||||
|
areas.photo->raise();
|
||||||
|
}, lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendFilesBox::updateLeftButtonVisibility() {
|
void SendFilesBox::updateLeftButtonVisibility() {
|
||||||
|
@ -1875,6 +1910,7 @@ void SendFilesBox::refreshAllAfterAlbumChanges() {
|
||||||
preparePreview();
|
preparePreview();
|
||||||
captionResized();
|
captionResized();
|
||||||
updateLeftButtonVisibility();
|
updateLeftButtonVisibility();
|
||||||
|
_albumChanged.fire({});
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendFilesBox::openDialogToAddFileToAlbum() {
|
void SendFilesBox::openDialogToAddFileToAlbum() {
|
||||||
|
|
|
@ -115,6 +115,7 @@ private:
|
||||||
void sendScheduled();
|
void sendScheduled();
|
||||||
void captionResized();
|
void captionResized();
|
||||||
|
|
||||||
|
void setupDragArea();
|
||||||
void setupTitleText();
|
void setupTitleText();
|
||||||
void updateBoxSize();
|
void updateBoxSize();
|
||||||
void updateControlsGeometry();
|
void updateControlsGeometry();
|
||||||
|
@ -163,6 +164,7 @@ private:
|
||||||
std::shared_ptr<Ui::RadioenumGroup<SendFilesWay>> _sendWay;
|
std::shared_ptr<Ui::RadioenumGroup<SendFilesWay>> _sendWay;
|
||||||
|
|
||||||
rpl::variable<int> _footerHeight = 0;
|
rpl::variable<int> _footerHeight = 0;
|
||||||
|
rpl::event_stream<> _albumChanged;
|
||||||
|
|
||||||
QWidget *_preview = nullptr;
|
QWidget *_preview = nullptr;
|
||||||
AlbumPreview *_albumPreview = nullptr;
|
AlbumPreview *_albumPreview = nullptr;
|
||||||
|
|
Loading…
Add table
Reference in a new issue