mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
added custom drag to comic table view, drops are accepted in lists view
This commit is contained in:
parent
4531e31d05
commit
e2e908302e
@ -186,6 +186,17 @@ QModelIndex ReadingListModel::parent(const QModelIndex &index) const
|
|||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ReadingListModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
return data->formats().contains("application/yacreaderlibrary-comics-ids");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ReadingListModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
|
||||||
|
{
|
||||||
|
QLOG_DEBUG() << "drop mimedata into row = " << row << "column column = " << column << "parent" << parent;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void ReadingListModel::setupReadingListsData(QString path)
|
void ReadingListModel::setupReadingListsData(QString path)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
|
@ -38,6 +38,8 @@ public:
|
|||||||
QModelIndex index(int row, int column,
|
QModelIndex index(int row, int column,
|
||||||
const QModelIndex &parent = QModelIndex()) const;
|
const QModelIndex &parent = QModelIndex()) const;
|
||||||
QModelIndex parent(const QModelIndex &index) const;
|
QModelIndex parent(const QModelIndex &index) const;
|
||||||
|
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const;
|
||||||
|
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
|
||||||
|
|
||||||
//Convenience methods
|
//Convenience methods
|
||||||
void setupReadingListsData(QString path);
|
void setupReadingListsData(QString path);
|
||||||
|
@ -10,6 +10,14 @@ YACReaderReadingListsView::YACReaderReadingListsView(QWidget *parent)
|
|||||||
setUniformRowHeights(false);
|
setUniformRowHeights(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void YACReaderReadingListsView::dragEnterEvent(QDragEnterEvent *event)
|
||||||
|
{
|
||||||
|
YACReaderTreeView::dragEnterEvent(event);
|
||||||
|
|
||||||
|
QModelIndex destinationIndex = indexAt(event->pos());
|
||||||
|
if(model()->canDropMimeData(event->mimeData(), event->proposedAction(), destinationIndex.row(), destinationIndex.column(), destinationIndex.parent()))
|
||||||
|
event->acceptProposedAction();
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
|
||||||
@ -28,19 +36,6 @@ void YACReaderReadingListsViewItemDeletegate::paint(QPainter *painter, const QSt
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*if(!item->data(FolderModel::Completed).toBool())
|
|
||||||
{
|
|
||||||
painter->save();
|
|
||||||
#ifdef Q_OS_MAC
|
|
||||||
painter->setBrush(QBrush(QColor(85,95,127)));
|
|
||||||
#else
|
|
||||||
painter->setBrush(QBrush(QColor(237,197,24)));
|
|
||||||
#endif
|
|
||||||
painter->setPen(QPen(QBrush(),0));
|
|
||||||
painter->drawRect(0,option.rect.y(),2,option.rect.height());
|
|
||||||
painter->restore();
|
|
||||||
}*/
|
|
||||||
|
|
||||||
QStyledItemDelegate::paint(painter, option, index);
|
QStyledItemDelegate::paint(painter, option, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,10 @@ class YACReaderReadingListsView : public YACReaderTreeView
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit YACReaderReadingListsView(QWidget * parent = 0);
|
explicit YACReaderReadingListsView(QWidget * parent = 0);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
//Drop to import
|
||||||
|
void dragEnterEvent(QDragEnterEvent *event);
|
||||||
};
|
};
|
||||||
|
|
||||||
class YACReaderReadingListsViewItemDeletegate: public QStyledItemDelegate
|
class YACReaderReadingListsViewItemDeletegate: public QStyledItemDelegate
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
|
|
||||||
|
#include "QsLog.h"
|
||||||
|
|
||||||
#include "comic_item.h"
|
#include "comic_item.h"
|
||||||
|
|
||||||
YACReaderTableView::YACReaderTableView(QWidget *parent) :
|
YACReaderTableView::YACReaderTableView(QWidget *parent) :
|
||||||
@ -70,12 +72,14 @@ YACReaderTableView::YACReaderTableView(QWidget *parent) :
|
|||||||
showDeletingProgressAnimation = new QPropertyAnimation(deletingProgress,"pos");
|
showDeletingProgressAnimation = new QPropertyAnimation(deletingProgress,"pos");
|
||||||
showDeletingProgressAnimation->setDuration(150);*/
|
showDeletingProgressAnimation->setDuration(150);*/
|
||||||
|
|
||||||
//drag
|
//drag: if the default drag is enabled there is no way for setting a custom image
|
||||||
setDragEnabled(true);
|
//TODO report bug/suggestion
|
||||||
|
//setDragEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void YACReaderTableView::mouseMoveEvent(QMouseEvent *event)
|
void YACReaderTableView::mouseMoveEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
|
|
||||||
QModelIndex mi = indexAt(event->pos());
|
QModelIndex mi = indexAt(event->pos());
|
||||||
if(mi.isValid())
|
if(mi.isValid())
|
||||||
{
|
{
|
||||||
@ -110,7 +114,7 @@ void YACReaderTableView::mouseMoveEvent(QMouseEvent *event)
|
|||||||
performDrag();
|
performDrag();
|
||||||
}
|
}
|
||||||
|
|
||||||
QTableView::mouseMoveEvent(event);
|
|
||||||
}
|
}
|
||||||
void YACReaderTableView::mousePressEvent(QMouseEvent * event)
|
void YACReaderTableView::mousePressEvent(QMouseEvent * event)
|
||||||
{
|
{
|
||||||
@ -149,6 +153,7 @@ void YACReaderTableView::leaveEvent(QEvent * event)
|
|||||||
|
|
||||||
void YACReaderTableView::performDrag()
|
void YACReaderTableView::performDrag()
|
||||||
{
|
{
|
||||||
|
QLOG_DEBUG() << "performDrag";
|
||||||
QDrag *drag = new QDrag(this);
|
QDrag *drag = new QDrag(this);
|
||||||
drag->setMimeData(model()->mimeData(selectionModel()->selectedRows()));
|
drag->setMimeData(model()->mimeData(selectionModel()->selectedRows()));
|
||||||
drag->setPixmap(QPixmap(":/images/openInYACReader.png")); //TODO add better image
|
drag->setPixmap(QPixmap(":/images/openInYACReader.png")); //TODO add better image
|
||||||
|
Loading…
x
Reference in New Issue
Block a user