mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 05:26:45 +08:00
* utility functions * style changes / renamings / slots -> normal functions * extra flag to enable file drop (and changed signatures) * split view load function into 2 parts, one can use passed file parameter
58 lines
1.7 KiB
C++
58 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>
|
|
#include <QUrl>
|
|
|
|
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::acceptDrop(const QMimeData *mime) const
|
|
{
|
|
if (!mime) { return false; }
|
|
if (!m_allowDrop) { return false; }
|
|
if (m_acceptedMetaTypes.isEmpty()) { return false; }
|
|
|
|
if (m_acceptJsonFile && CGuiUtility::isMimeRepresentingReadableJsonFile(mime))
|
|
{
|
|
// further checks could go here
|
|
return true;
|
|
}
|
|
|
|
if (!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
|