/*
    SPDX-FileCopyrightText: 2010 BetterInbox <contact@betterinbox.com>
    SPDX-FileContributor: Gregory Schlomoff <greg@betterinbox.com>
    SPDX-FileCopyrightText: 2013 Sebastian Kügler <sebas@kde.org>

    SPDX-License-Identifier: MIT
*/

#include "DeclarativeDragDropEvent.h"

DeclarativeDragDropEvent::DeclarativeDragDropEvent(QDropEvent *e, DeclarativeDropArea *parent)
    : QObject(parent)
    , m_x(e->position().x())
    , m_y(e->position().y())
    , m_buttons(e->buttons())
    , m_modifiers(e->modifiers())
    , m_data(nullptr)
    , m_event(e)
{
}

DeclarativeDragDropEvent::DeclarativeDragDropEvent(QDragLeaveEvent *e, DeclarativeDropArea *parent)
    : QObject(parent)
    , m_x(0)
    , m_y(0)
    , m_buttons(Qt::NoButton)
    , m_modifiers(Qt::NoModifier)
    , m_data(nullptr)
    , m_event(nullptr)
{
    Q_UNUSED(e);
}

void DeclarativeDragDropEvent::accept(int action)
{
    m_event->setDropAction(static_cast<Qt::DropAction>(action));
    //     qDebug() << "-----> Accepting event: " << this << m_data.urls() << m_data.text() << m_data.html() << ( m_data.hasColor() ? m_data.color().name() : "
    //     no color");
    m_event->accept();
}

void DeclarativeDragDropEvent::ignore()
{
    m_event->ignore();
}

DeclarativeMimeData *DeclarativeDragDropEvent::mimeData()
{
    if (!m_data && m_event) {
        //         TODO This should be using MimeDataWrapper eventually, although this is an API break,
        //         so will need to be done carefully.
        m_data.reset(new DeclarativeMimeData(m_event->mimeData()));
    }
    return m_data.data();
}

#include "moc_DeclarativeDragDropEvent.cpp"
