yacreader/YACReaderLibrary/yacreader_reading_lists_view.cpp
2014-12-11 15:53:33 +01:00

63 lines
2.2 KiB
C++

#include "yacreader_reading_lists_view.h"
#include "reading_list_item.h"
#include "reading_list_model.h"
YACReaderReadingListsView::YACReaderReadingListsView(QWidget *parent)
:YACReaderTreeView(parent)
{
setItemDelegate(new YACReaderReadingListsViewItemDeletegate(this));
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();
}
void YACReaderReadingListsView::dragMoveEvent(QDragMoveEvent *event)
{
YACReaderTreeView::dragMoveEvent(event);
QModelIndex destinationIndex = indexAt(event->pos());
if(model()->canDropMimeData(event->mimeData(), event->proposedAction(), destinationIndex.row(), destinationIndex.column(), destinationIndex.parent()))
event->acceptProposedAction();
}
//----------------------------------------------------------------------
YACReaderReadingListsViewItemDeletegate::YACReaderReadingListsViewItemDeletegate(QObject *parent)
:QStyledItemDelegate(parent)
{
}
void YACReaderReadingListsViewItemDeletegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
ReadingListModel::TypeList typeList = (ReadingListModel::TypeList)index.data(ReadingListModel::TypeListsRole).toInt();
if(typeList == ReadingListModel::Separator)
{
return;
}
QStyledItemDelegate::paint(painter, option, index);
}
QSize YACReaderReadingListsViewItemDeletegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
ReadingListModel::TypeList typeList = (ReadingListModel::TypeList)index.data(ReadingListModel::TypeListsRole).toInt();
if(typeList == ReadingListModel::Separator)
{
QSize newSize = QStyledItemDelegate::sizeHint(option, index);
newSize.setHeight(7);
return newSize;
}
return QStyledItemDelegate::sizeHint(option, index);
}