mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
Enable dropping content on the FolderContentView
This commit is contained in:
parent
b8daaad1ad
commit
13d0984784
@ -5,6 +5,8 @@
|
||||
#include "yacreader_global.h"
|
||||
#include "yacreader_global_gui.h"
|
||||
#include "yacreader_tool_bar_stretch.h"
|
||||
#include "comic.h"
|
||||
#include "comic_files_manager.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
|
||||
@ -164,6 +166,7 @@ FolderContentView::FolderContentView(QAction *toogleRecentVisibilityAction, QWid
|
||||
ctxt->setContextProperty("showCurrentComic", QVariant(false));
|
||||
|
||||
ctxt->setContextProperty("openHelper", this);
|
||||
ctxt->setContextProperty("dropManager", this);
|
||||
ctxt->setContextProperty("contextMenuHelper", this);
|
||||
|
||||
view->setSource(QUrl("qrc:/qml/FolderContentView.qml"));
|
||||
@ -290,10 +293,31 @@ void FolderContentView::showEvent(QShowEvent *event)
|
||||
setCoversSize(coverSize);
|
||||
}
|
||||
|
||||
void FolderContentView::dragEnterEvent(QDragEnterEvent *event)
|
||||
bool FolderContentView::canDropUrls(const QList<QUrl> &urls, Qt::DropAction action)
|
||||
{
|
||||
if (action == Qt::CopyAction) {
|
||||
QString currentPath;
|
||||
foreach (QUrl url, urls) {
|
||||
// comics or folders are accepted, folders' content is validate in dropEvent (avoid any lag before droping)
|
||||
currentPath = url.toLocalFile();
|
||||
if (Comic::fileIsComic(currentPath) || QFileInfo(currentPath).isDir())
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void FolderContentView::dropEvent(QDropEvent *event)
|
||||
bool FolderContentView::canDropFormats(const QString &formats)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void FolderContentView::droppedFiles(const QList<QUrl> &urls, Qt::DropAction action)
|
||||
{
|
||||
bool validAction = action == Qt::CopyAction; // TODO add move
|
||||
|
||||
if (validAction) {
|
||||
QList<QPair<QString, QString>> droppedFiles = ComicFilesManager::getDroppedFiles(urls);
|
||||
emit copyComicsToCurrentFolder(droppedFiles);
|
||||
}
|
||||
}
|
||||
|
@ -48,6 +48,9 @@ protected slots:
|
||||
void openComicFromContinueReadingList(int index);
|
||||
void requestedFolderContextMenu(QPoint point, int index);
|
||||
void requestedContinueReadingComicContextMenu(QPoint point, int index);
|
||||
bool canDropUrls(const QList<QUrl> &urls, Qt::DropAction action);
|
||||
bool canDropFormats(const QString &formats);
|
||||
void droppedFiles(const QList<QUrl> &urls, Qt::DropAction action);
|
||||
|
||||
protected:
|
||||
QQuickWidget *view;
|
||||
@ -56,10 +59,6 @@ protected:
|
||||
std::unique_ptr<ComicModel> comicModel;
|
||||
FolderModel *folderModel;
|
||||
|
||||
// Drop to import
|
||||
void dragEnterEvent(QDragEnterEvent *event) override;
|
||||
void dropEvent(QDropEvent *event) override;
|
||||
|
||||
private:
|
||||
QSettings *settings;
|
||||
QToolBar *toolbar;
|
||||
|
@ -185,46 +185,6 @@ Rectangle {
|
||||
grid.contentX = grid.originX
|
||||
}
|
||||
|
||||
DropArea {
|
||||
anchors.fill: parent
|
||||
|
||||
onEntered: {
|
||||
if(drag.hasUrls)
|
||||
{
|
||||
if(dropManager.canDropUrls(drag.urls, drag.action))
|
||||
{
|
||||
drag.accepted = true;
|
||||
}else
|
||||
drag.accepted = false;
|
||||
}
|
||||
else if (dropManager.canDropFormats(drag.formats)) {
|
||||
drag.accepted = true;
|
||||
} else
|
||||
drag.accepted = false;
|
||||
}
|
||||
|
||||
onDropped: {
|
||||
if(drop.hasUrls && dropManager.canDropUrls(drop.urls, drop.action))
|
||||
{
|
||||
dropManager.droppedFiles(drop.urls, drop.action);
|
||||
}
|
||||
else{
|
||||
if (dropManager.canDropFormats(drop.formats))
|
||||
{
|
||||
var destItem = grid.itemAt(drop.x,drop.y + grid.contentY);
|
||||
var destLocalX = grid.mapToItem(destItem,drop.x,drop.y + grid.contentY).x
|
||||
var realIndex = grid.indexAt(drop.x,drop.y + grid.contentY);
|
||||
|
||||
if(realIndex === -1)
|
||||
realIndex = grid.count - 1;
|
||||
|
||||
var destIndex = destLocalX < (grid.cellWidth / 2) ? realIndex : realIndex + 1;
|
||||
dropManager.droppedComicsForResortingAt(drop.getDataAsString(), destIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
property Component continueReadingView: Component {
|
||||
id: continueReadingView
|
||||
Rectangle {
|
||||
@ -462,6 +422,46 @@ Rectangle {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DropArea {
|
||||
anchors.fill: parent
|
||||
|
||||
onEntered: drag => {
|
||||
if(drag.hasUrls)
|
||||
{
|
||||
if(dropManager.canDropUrls(drag.urls, drag.action))
|
||||
{
|
||||
drag.accepted = true;
|
||||
}else
|
||||
drag.accepted = false;
|
||||
}
|
||||
else if (dropManager.canDropFormats(drag.formats)) {
|
||||
drag.accepted = true;
|
||||
} else
|
||||
drag.accepted = false;
|
||||
}
|
||||
|
||||
onDropped: drop => {
|
||||
if(drop.hasUrls && dropManager.canDropUrls(drop.urls, drop.action))
|
||||
{
|
||||
dropManager.droppedFiles(drop.urls, drop.action);
|
||||
}
|
||||
else{
|
||||
if (dropManager.canDropFormats(drop.formats))
|
||||
{
|
||||
var destItem = grid.itemAt(drop.x,drop.y + grid.contentY);
|
||||
var destLocalX = grid.mapToItem(destItem,drop.x,drop.y + grid.contentY).x
|
||||
var realIndex = grid.indexAt(drop.x,drop.y + grid.contentY);
|
||||
|
||||
if(realIndex === -1)
|
||||
realIndex = grid.count - 1;
|
||||
|
||||
var destIndex = destLocalX < (grid.cellWidth / 2) ? realIndex : realIndex + 1;
|
||||
dropManager.droppedComicsForResortingAt("", destIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -187,46 +187,6 @@ Rectangle {
|
||||
grid.contentX = grid.originX
|
||||
}
|
||||
|
||||
DropArea {
|
||||
anchors.fill: parent
|
||||
|
||||
onEntered: {
|
||||
if(drag.hasUrls)
|
||||
{
|
||||
if(dropManager.canDropUrls(drag.urls, drag.action))
|
||||
{
|
||||
drag.accepted = true;
|
||||
}else
|
||||
drag.accepted = false;
|
||||
}
|
||||
else if (dropManager.canDropFormats(drag.formats)) {
|
||||
drag.accepted = true;
|
||||
} else
|
||||
drag.accepted = false;
|
||||
}
|
||||
|
||||
onDropped: {
|
||||
if(drop.hasUrls && dropManager.canDropUrls(drop.urls, drop.action))
|
||||
{
|
||||
dropManager.droppedFiles(drop.urls, drop.action);
|
||||
}
|
||||
else{
|
||||
if (dropManager.canDropFormats(drop.formats))
|
||||
{
|
||||
var destItem = grid.itemAt(drop.x,drop.y + grid.contentY);
|
||||
var destLocalX = grid.mapToItem(destItem,drop.x,drop.y + grid.contentY).x
|
||||
var realIndex = grid.indexAt(drop.x,drop.y + grid.contentY);
|
||||
|
||||
if(realIndex === -1)
|
||||
realIndex = grid.count - 1;
|
||||
|
||||
var destIndex = destLocalX < (grid.cellWidth / 2) ? realIndex : realIndex + 1;
|
||||
dropManager.droppedComicsForResortingAt(drop.getDataAsString(), destIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
property Component continueReadingView: Component {
|
||||
id: continueReadingView
|
||||
Rectangle {
|
||||
@ -472,6 +432,46 @@ Rectangle {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DropArea {
|
||||
anchors.fill: parent
|
||||
|
||||
onEntered: drag => {
|
||||
if(drag.hasUrls)
|
||||
{
|
||||
if(dropManager.canDropUrls(drag.urls, drag.action))
|
||||
{
|
||||
drag.accepted = true;
|
||||
}else
|
||||
drag.accepted = false;
|
||||
}
|
||||
else if (dropManager.canDropFormats(drag.formats)) {
|
||||
drag.accepted = true;
|
||||
} else
|
||||
drag.accepted = false;
|
||||
}
|
||||
|
||||
onDropped: drop => {
|
||||
if(drop.hasUrls && dropManager.canDropUrls(drop.urls, drop.action))
|
||||
{
|
||||
dropManager.droppedFiles(drop.urls, drop.action);
|
||||
}
|
||||
else{
|
||||
if (dropManager.canDropFormats(drop.formats))
|
||||
{
|
||||
var destItem = grid.itemAt(drop.x,drop.y + grid.contentY);
|
||||
var destLocalX = grid.mapToItem(destItem,drop.x,drop.y + grid.contentY).x
|
||||
var realIndex = grid.indexAt(drop.x,drop.y + grid.contentY);
|
||||
|
||||
if(realIndex === -1)
|
||||
realIndex = grid.count - 1;
|
||||
|
||||
var destIndex = destLocalX < (grid.cellWidth / 2) ? realIndex : realIndex + 1;
|
||||
dropManager.droppedComicsForResortingAt("", destIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -67,6 +67,20 @@ QWidget *YACReaderContentViewsManager::containerWidget()
|
||||
|
||||
void YACReaderContentViewsManager::updateCurrentContentView()
|
||||
{
|
||||
libraryWindow->comicsModel->reload();
|
||||
|
||||
if (comicsViewStack->currentWidget() == folderContentView && libraryWindow->comicsModel->rowCount() > 0) {
|
||||
comicsView->reloadContent();
|
||||
showComicsView();
|
||||
return;
|
||||
}
|
||||
|
||||
if (comicsViewStack->currentWidget() == comicsView && libraryWindow->comicsModel->rowCount() == 0) {
|
||||
showFolderContentView();
|
||||
folderContentView->reloadContent();
|
||||
return;
|
||||
}
|
||||
|
||||
if (comicsViewStack->currentWidget() == comicsView) {
|
||||
comicsView->reloadContent();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user