mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
added separators to the reading lists model/view
This commit is contained in:
parent
56a46f65a0
commit
a0facfce8d
@ -115,3 +115,15 @@ int ReadingListItem::row() const
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ReadingListSeparatorItem::ReadingListSeparatorItem()
|
||||||
|
:ListItem(QList<QVariant>())
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QIcon ReadingListSeparatorItem::getIcon() const
|
||||||
|
{
|
||||||
|
return QIcon();
|
||||||
|
}
|
||||||
|
@ -11,7 +11,7 @@ public:
|
|||||||
int columnCount();
|
int columnCount();
|
||||||
virtual QIcon getIcon() const = 0;
|
virtual QIcon getIcon() const = 0;
|
||||||
QVariant data(int column) const;
|
QVariant data(int column) const;
|
||||||
protected:
|
|
||||||
QList<QVariant> itemData;
|
QList<QVariant> itemData;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -51,4 +51,13 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//------------------------------------------------------
|
||||||
|
|
||||||
|
class ReadingListSeparatorItem : public ListItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ReadingListSeparatorItem();
|
||||||
|
QIcon getIcon() const;
|
||||||
|
};
|
||||||
|
|
||||||
#endif // READING_LIST_ITEM_H
|
#endif // READING_LIST_ITEM_H
|
||||||
|
@ -2,19 +2,28 @@
|
|||||||
|
|
||||||
#include "reading_list_item.h"
|
#include "reading_list_item.h"
|
||||||
|
|
||||||
|
#include "QsLog.h"
|
||||||
|
|
||||||
ReadingListModel::ReadingListModel(QObject *parent) :
|
ReadingListModel::ReadingListModel(QObject *parent) :
|
||||||
QAbstractItemModel(parent),rootItem(0)
|
QAbstractItemModel(parent),rootItem(0)
|
||||||
{
|
{
|
||||||
|
separator1 = new ReadingListSeparatorItem;
|
||||||
|
separator2 = new ReadingListSeparatorItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ReadingListModel::rowCount(const QModelIndex &parent) const
|
int ReadingListModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
if(!parent.isValid()) //TOP
|
if(!parent.isValid()) //TOP
|
||||||
return specialLists.count() + labels.count() + rootItem->childCount();
|
{
|
||||||
|
int separatorsCount = labels.isEmpty()?1:2;
|
||||||
|
return specialLists.count() + labels.count() + rootItem->childCount() + separatorsCount;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ListItem * item = static_cast<ListItem*>(parent.internalPointer());
|
ListItem * item = static_cast<ListItem*>(parent.internalPointer());
|
||||||
|
|
||||||
|
QLOG_DEBUG() << item->itemData;
|
||||||
|
|
||||||
if(typeid(*item) == typeid(ReadingListItem))
|
if(typeid(*item) == typeid(ReadingListItem))
|
||||||
{
|
{
|
||||||
ReadingListItem * item = static_cast<ReadingListItem*>(parent.internalPointer());
|
ReadingListItem * item = static_cast<ReadingListItem*>(parent.internalPointer());
|
||||||
@ -27,6 +36,12 @@ int ReadingListModel::rowCount(const QModelIndex &parent) const
|
|||||||
|
|
||||||
int ReadingListModel::columnCount(const QModelIndex &parent) const
|
int ReadingListModel::columnCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
|
if(parent.isValid())
|
||||||
|
{
|
||||||
|
ListItem * item = static_cast<ListItem*>(parent.internalPointer());
|
||||||
|
if(typeid(*item) == typeid(ReadingListSeparatorItem))
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
/*if (parent.isValid())
|
/*if (parent.isValid())
|
||||||
return static_cast<ListItem*>(parent.internalPointer())->columnCount();
|
return static_cast<ListItem*>(parent.internalPointer())->columnCount();
|
||||||
@ -41,6 +56,9 @@ QVariant ReadingListModel::data(const QModelIndex &index, int role) const
|
|||||||
|
|
||||||
ListItem * item = static_cast<ListItem*>(index.internalPointer());
|
ListItem * item = static_cast<ListItem*>(index.internalPointer());
|
||||||
|
|
||||||
|
if(typeid(*item) == typeid(ReadingListSeparatorItem))
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
if (role == Qt::DecorationRole)
|
if (role == Qt::DecorationRole)
|
||||||
{
|
{
|
||||||
return QVariant(item->getIcon());
|
return QVariant(item->getIcon());
|
||||||
@ -57,6 +75,10 @@ Qt::ItemFlags ReadingListModel::flags(const QModelIndex &index) const
|
|||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
ListItem * item = static_cast<ListItem*>(index.internalPointer());
|
||||||
|
if(typeid(*item) == typeid(ReadingListSeparatorItem))
|
||||||
|
return 0;
|
||||||
|
|
||||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled;
|
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,14 +97,23 @@ QModelIndex ReadingListModel::index(int row, int column, const QModelIndex &pare
|
|||||||
|
|
||||||
if(!parent.isValid())
|
if(!parent.isValid())
|
||||||
{
|
{
|
||||||
|
int separatorsCount = labels.isEmpty()?1:2;
|
||||||
|
|
||||||
if(row >= 0 && row < specialLists.count())
|
if(row >= 0 && row < specialLists.count())
|
||||||
return createIndex(row, column, specialLists.at(row));
|
return createIndex(row, column, specialLists.at(row));
|
||||||
|
|
||||||
if(row >= specialLists.count() && row < specialLists.count() + labels.count())
|
if(row == specialLists.count())
|
||||||
return createIndex(row,column,labels.at(row-specialLists.count()));
|
return createIndex(row,column,separator1);
|
||||||
|
|
||||||
if(row >= specialLists.count() + labels.count())
|
if(row > specialLists.count() && row <= specialLists.count() + labels.count())
|
||||||
return createIndex(row,column,rootItem->child(row - (specialLists.count() + labels.count())));
|
return createIndex(row,column,labels.at(row-specialLists.count()-1));
|
||||||
|
|
||||||
|
if(separatorsCount == 2)
|
||||||
|
if(row == specialLists.count() + labels.count() + 1)
|
||||||
|
return createIndex(row,column,separator2);
|
||||||
|
|
||||||
|
if(row >= specialLists.count() + labels.count() + separatorsCount)
|
||||||
|
return createIndex(row,column,rootItem->child(row - (specialLists.count() + labels.count() + separatorsCount)));
|
||||||
|
|
||||||
} else //sublist
|
} else //sublist
|
||||||
{
|
{
|
||||||
@ -146,6 +177,8 @@ void ReadingListModel::setupModelData(QString path)
|
|||||||
specialLists << new SpecialListItem(QList<QVariant>() /*<< 0*/ << "Favorites");
|
specialLists << new SpecialListItem(QList<QVariant>() /*<< 0*/ << "Favorites");
|
||||||
specialLists << new SpecialListItem(QList<QVariant>() /*<< 1*/ << "Reading");
|
specialLists << new SpecialListItem(QList<QVariant>() /*<< 1*/ << "Reading");
|
||||||
|
|
||||||
|
//separator
|
||||||
|
|
||||||
//setup labels
|
//setup labels
|
||||||
labels << new LabelItem(QList<QVariant>() /*<< 0*/ << "Oh Oh" << "red");
|
labels << new LabelItem(QList<QVariant>() /*<< 0*/ << "Oh Oh" << "red");
|
||||||
labels << new LabelItem(QList<QVariant>() /*<< 1*/ << "lalala" << "orange");
|
labels << new LabelItem(QList<QVariant>() /*<< 1*/ << "lalala" << "orange");
|
||||||
@ -160,6 +193,8 @@ void ReadingListModel::setupModelData(QString path)
|
|||||||
labels << new LabelItem(QList<QVariant>() /*<< 10*/ << "ainsss" << "light");
|
labels << new LabelItem(QList<QVariant>() /*<< 10*/ << "ainsss" << "light");
|
||||||
labels << new LabelItem(QList<QVariant>() /*<< 11*/ << "put a smile on my face" << "dark");
|
labels << new LabelItem(QList<QVariant>() /*<< 11*/ << "put a smile on my face" << "dark");
|
||||||
|
|
||||||
|
//separator
|
||||||
|
|
||||||
//setup root item
|
//setup root item
|
||||||
rootItem = new ReadingListItem(QList<QVariant>() /*<< 0*/ << "ROOT" << "atr");
|
rootItem = new ReadingListItem(QList<QVariant>() /*<< 0*/ << "ROOT" << "atr");
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
class LabelItem;
|
class LabelItem;
|
||||||
class SpecialListItem;
|
class SpecialListItem;
|
||||||
class ReadingListItem;
|
class ReadingListItem;
|
||||||
|
class ReadingListSeparatorItem;
|
||||||
|
|
||||||
class ReadingListModel : public QAbstractItemModel
|
class ReadingListModel : public QAbstractItemModel
|
||||||
{
|
{
|
||||||
@ -49,6 +50,10 @@ private:
|
|||||||
ReadingListItem * rootItem; //
|
ReadingListItem * rootItem; //
|
||||||
QMap<unsigned long long int, ReadingListItem *> items; //lists relationship
|
QMap<unsigned long long int, ReadingListItem *> items; //lists relationship
|
||||||
|
|
||||||
|
//separators
|
||||||
|
ReadingListSeparatorItem * separator1;
|
||||||
|
ReadingListSeparatorItem * separator2;
|
||||||
|
|
||||||
QString _databasePath;
|
QString _databasePath;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,60 @@
|
|||||||
#include "yacreader_reading_lists_view.h"
|
#include "yacreader_reading_lists_view.h"
|
||||||
|
|
||||||
|
#include "reading_list_item.h"
|
||||||
|
|
||||||
YACReaderReadingListsView::YACReaderReadingListsView(QWidget *parent)
|
YACReaderReadingListsView::YACReaderReadingListsView(QWidget *parent)
|
||||||
:YACReaderTreeView(parent)
|
:YACReaderTreeView(parent)
|
||||||
{
|
{
|
||||||
|
setItemDelegate(new YACReaderReadingListsViewItemDeletegate(this));
|
||||||
|
setUniformRowHeights(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
|
||||||
|
YACReaderReadingListsViewItemDeletegate::YACReaderReadingListsViewItemDeletegate(QObject *parent)
|
||||||
|
:QStyledItemDelegate(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void YACReaderReadingListsViewItemDeletegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
ListItem * item = static_cast<ListItem*>(index.internalPointer());
|
||||||
|
|
||||||
|
if(typeid(*item) == typeid(ReadingListSeparatorItem))
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize YACReaderReadingListsViewItemDeletegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
ListItem * item = static_cast<ListItem*>(index.internalPointer());
|
||||||
|
|
||||||
|
if(typeid(*item) == typeid(ReadingListSeparatorItem))
|
||||||
|
{
|
||||||
|
QSize newSize = QStyledItemDelegate::sizeHint(option, index);
|
||||||
|
|
||||||
|
newSize.setHeight(7);
|
||||||
|
|
||||||
|
return newSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
return QStyledItemDelegate::sizeHint(option, index);
|
||||||
}
|
}
|
||||||
|
@ -12,4 +12,14 @@ public:
|
|||||||
explicit YACReaderReadingListsView(QWidget * parent = 0);
|
explicit YACReaderReadingListsView(QWidget * parent = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class YACReaderReadingListsViewItemDeletegate: public QStyledItemDelegate
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit YACReaderReadingListsViewItemDeletegate(QObject *parent = 0);
|
||||||
|
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||||
|
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // YACREADER_READING_LISTS_VIEW_H
|
#endif // YACREADER_READING_LISTS_VIEW_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user