mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added ability to drag'n'drop videos in SendFilesBox.
This commit is contained in:
parent
2576312cd4
commit
b71062561a
4 changed files with 30 additions and 26 deletions
|
@ -91,25 +91,6 @@ auto ListFromMimeData(not_null<const QMimeData*> data) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto CheckMimeData(not_null<const QMimeData*> data, bool isAlbum) {
|
|
||||||
if (data->urls().size() > 1) {
|
|
||||||
return false;
|
|
||||||
} else if (data->hasImage()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isAlbum && data->hasUrls()) {
|
|
||||||
const auto url = data->urls().front();
|
|
||||||
if (url.isLocalFile()) {
|
|
||||||
using namespace Core;
|
|
||||||
const auto info = QFileInfo(Platform::File::UrlToLocal(url));
|
|
||||||
return IsMimeAcceptedForAlbum(MimeTypeForFile(info).name());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
EditCaptionBox::EditCaptionBox(
|
EditCaptionBox::EditCaptionBox(
|
||||||
|
@ -663,7 +644,7 @@ void EditCaptionBox::prepare() {
|
||||||
if (action == Ui::InputField::MimeAction::Check) {
|
if (action == Ui::InputField::MimeAction::Check) {
|
||||||
if (!data->hasText() && !_isAllowedEditMedia) {
|
if (!data->hasText() && !_isAllowedEditMedia) {
|
||||||
return false;
|
return false;
|
||||||
} else if (CheckMimeData(data, _isAlbum)) {
|
} else if (Storage::ValidateDragData(data, _isAlbum)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return data->hasText();
|
return data->hasText();
|
||||||
|
@ -766,7 +747,9 @@ void EditCaptionBox::setupEmojiPanel() {
|
||||||
|
|
||||||
void EditCaptionBox::setupDragArea() {
|
void EditCaptionBox::setupDragArea() {
|
||||||
auto enterFilter = [=](not_null<const QMimeData*> data) {
|
auto enterFilter = [=](not_null<const QMimeData*> data) {
|
||||||
return !_isAllowedEditMedia ? false : CheckMimeData(data, _isAlbum);
|
return !_isAllowedEditMedia
|
||||||
|
? false
|
||||||
|
: Storage::ValidateDragData(data, _isAlbum);
|
||||||
};
|
};
|
||||||
// Avoid both drag areas appearing at one time.
|
// Avoid both drag areas appearing at one time.
|
||||||
auto computeState = [=](const QMimeData *data) {
|
auto computeState = [=](const QMimeData *data) {
|
||||||
|
|
|
@ -1865,12 +1865,13 @@ void SendFilesBox::prepare() {
|
||||||
void SendFilesBox::setupDragArea() {
|
void SendFilesBox::setupDragArea() {
|
||||||
// Avoid both drag areas appearing at one time.
|
// Avoid both drag areas appearing at one time.
|
||||||
auto computeState = [=](const QMimeData *data) {
|
auto computeState = [=](const QMimeData *data) {
|
||||||
|
using DragState = Storage::MimeDataState;
|
||||||
const auto state = Storage::ComputeMimeDataState(data);
|
const auto state = Storage::ComputeMimeDataState(data);
|
||||||
return (state == Storage::MimeDataState::PhotoFiles)
|
return (state == DragState::PhotoFiles)
|
||||||
? Storage::MimeDataState::Image
|
? DragState::Image
|
||||||
: (state == Storage::MimeDataState::Files)
|
: (state == DragState::Files
|
||||||
// Temporary enable drag'n'drop only for images. TODO.
|
&& !Storage::ValidateDragData(data, true))
|
||||||
? Storage::MimeDataState::None
|
? DragState::None
|
||||||
: state;
|
: state;
|
||||||
};
|
};
|
||||||
const auto areas = DragArea::SetupDragAreaToContainer(
|
const auto areas = DragArea::SetupDragAreaToContainer(
|
||||||
|
|
|
@ -140,6 +140,25 @@ void PrepareAlbum(PreparedList &result, int previewWidth) {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
bool ValidateDragData(not_null<const QMimeData*> data, bool isAlbum) {
|
||||||
|
if (data->urls().size() > 1) {
|
||||||
|
return false;
|
||||||
|
} else if (data->hasImage()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isAlbum && data->hasUrls()) {
|
||||||
|
const auto url = data->urls().front();
|
||||||
|
if (url.isLocalFile()) {
|
||||||
|
using namespace Core;
|
||||||
|
const auto info = QFileInfo(Platform::File::UrlToLocal(url));
|
||||||
|
return IsMimeAcceptedForAlbum(MimeTypeForFile(info).name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool ValidateThumbDimensions(int width, int height) {
|
bool ValidateThumbDimensions(int width, int height) {
|
||||||
return (width > 0)
|
return (width > 0)
|
||||||
&& (height > 0)
|
&& (height > 0)
|
||||||
|
|
|
@ -79,6 +79,7 @@ struct PreparedList {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool ValidateDragData(not_null<const QMimeData*> data, bool isAlbum);
|
||||||
bool ValidateThumbDimensions(int width, int height);
|
bool ValidateThumbDimensions(int width, int height);
|
||||||
PreparedList PrepareMediaList(const QList<QUrl> &files, int previewWidth);
|
PreparedList PrepareMediaList(const QList<QUrl> &files, int previewWidth);
|
||||||
PreparedList PrepareMediaList(const QStringList &files, int previewWidth);
|
PreparedList PrepareMediaList(const QStringList &files, int previewWidth);
|
||||||
|
|
Loading…
Add table
Reference in a new issue