vnote/src/widgets/attachmentdragdropareaindicator.cpp
Le Tan 6dce8e65a7
add Chinese translations (#1615)
* add Chinese translations

* remove widgets_zh_CN.ts and update qt_zh_CN.ts

* refine
2020-12-21 21:12:19 +08:00

47 lines
1.4 KiB
C++

#include "attachmentdragdropareaindicator.h"
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QMimeData>
#include <QFileInfo>
#include "viewwindow.h"
#include <buffer/buffer.h>
#include <utils/pathutils.h>
#include <utils/urldragdroputils.h>
#include <vnotex.h>
using namespace vnotex;
AttachmentDragDropAreaIndicator::AttachmentDragDropAreaIndicator(ViewWindow *p_viewWindow)
: m_viewWindow(p_viewWindow)
{
}
bool AttachmentDragDropAreaIndicator::handleDragEnterEvent(QDragEnterEvent *p_event)
{
if (isAccepted(p_event)) {
p_event->acceptProposedAction();
return true;
}
return false;
}
bool AttachmentDragDropAreaIndicator::handleDropEvent(QDropEvent *p_event)
{
return UrlDragDropUtils::handleDropEvent(p_event, [this](const QStringList &p_files) {
auto buffer = m_viewWindow->getBuffer();
Q_ASSERT(buffer && buffer->isAttachmentSupported());
auto files = buffer->addAttachment(QString(), p_files);
if (!files.isEmpty()) {
VNoteX::getInst().showStatusMessageShort(
ViewWindow::tr("Attached %n file(s)", "", files.size()));
}
});
}
bool AttachmentDragDropAreaIndicator::isAccepted(const QDragEnterEvent *p_event)
{
return p_event->mimeData()->hasFormat(QStringLiteral("text/uri-list"));
}