Files
pilotclient/src/blackgui/dropbase.cpp
Roland Winklmeier f4c2939253 Fix BlackGui header includes
* Include only what is used
* Use forward declaration when possible
* Sorted includes

refs #598
2016-05-20 01:31:11 +02:00

60 lines
1.7 KiB
C++

/* Copyright (C) 2015
* swift project Community / Contributors
*
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "blackgui/dropbase.h"
#include "blackgui/guiutility.h"
#include <QMetaType>
#include <QtGlobal>
using namespace BlackMisc;
namespace BlackGui
{
CDropBase::CDropBase()
{ }
void CDropBase::setAcceptedMetaTypeIds(const QList<int> &ids)
{
m_acceptedMetaTypes = ids;
}
void CDropBase::addAcceptedMetaTypeId(int id)
{
m_acceptedMetaTypes.append(id);
}
bool CDropBase::isDropAllowed() const
{
return m_allowDrop;
}
void CDropBase::allowDrop(bool allowed)
{
this->m_allowDrop = allowed;
}
bool CDropBase::acceptDrop(const QMimeData *mime) const
{
Q_ASSERT_X(!this->m_acceptedMetaTypes.isEmpty(), Q_FUNC_INFO, "no accepted meta type ids");
if (m_acceptedMetaTypes.isEmpty()) { return false; }
if (!m_allowDrop || !CGuiUtility::hasSwiftVariantMimeType(mime)) { return false; }
const int metaTypeId = CGuiUtility::metaTypeIdFromSwiftDragAndDropData(mime);
if (metaTypeId == QMetaType::UnknownType) { return false; }
const bool accept = m_acceptedMetaTypes.contains(metaTypeId);
return accept;
}
CVariant CDropBase::toCVariant(const QMimeData *mime) const
{
return CGuiUtility::fromSwiftDragAndDropData(mime);
}
} // ns