1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:28:10 +00:00

LibGUI: Port the drag&drop code to Core::MimeData

This commit is contained in:
Andreas Kling 2020-02-14 13:18:34 +01:00
parent 3cba9c3c25
commit 814d59f462
10 changed files with 59 additions and 53 deletions

View file

@ -26,10 +26,11 @@
#include "QSWidget.h"
#include <AK/URL.h>
#include <LibGfx/Bitmap.h>
#include <LibCore/MimeData.h>
#include <LibGUI/MessageBox.h>
#include <LibGUI/Painter.h>
#include <LibGUI/Window.h>
#include <LibGfx/Bitmap.h>
QSWidget::QSWidget(GUI::Widget* parent)
: GUI::Frame(parent)
@ -130,15 +131,15 @@ void QSWidget::drop_event(GUI::DropEvent& event)
event.accept();
window()->move_to_front();
if (event.data_type() == "url-list") {
auto lines = event.data().split_view('\n');
if (lines.is_empty())
if (event.mime_data().has_urls()) {
auto urls = event.mime_data().urls();
if (urls.is_empty())
return;
if (lines.size() > 1) {
if (urls.size() > 1) {
GUI::MessageBox::show("QuickShow can only open one file at a time!", "One at a time please!", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, window());
return;
}
URL url(lines[0]);
auto url = urls.first();
auto bitmap = Gfx::Bitmap::load_from_file(url.path());
if (!bitmap) {
GUI::MessageBox::show(String::format("Failed to open %s", url.to_string().characters()), "Cannot open image", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, window());