diff --git a/YACReaderLibrary/db/reading_list_item.cpp b/YACReaderLibrary/db/reading_list_item.cpp index a40f9864..687708ea 100644 --- a/YACReaderLibrary/db/reading_list_item.cpp +++ b/YACReaderLibrary/db/reading_list_item.cpp @@ -115,3 +115,15 @@ int ReadingListItem::row() const return 0; } + + +ReadingListSeparatorItem::ReadingListSeparatorItem() + :ListItem(QList()) +{ + +} + +QIcon ReadingListSeparatorItem::getIcon() const +{ + return QIcon(); +} diff --git a/YACReaderLibrary/db/reading_list_item.h b/YACReaderLibrary/db/reading_list_item.h index 7456f4ef..fdb50e34 100644 --- a/YACReaderLibrary/db/reading_list_item.h +++ b/YACReaderLibrary/db/reading_list_item.h @@ -11,7 +11,7 @@ public: int columnCount(); virtual QIcon getIcon() const = 0; QVariant data(int column) const; -protected: + QList itemData; }; @@ -51,4 +51,13 @@ private: }; +//------------------------------------------------------ + +class ReadingListSeparatorItem : public ListItem +{ +public: + ReadingListSeparatorItem(); + QIcon getIcon() const; +}; + #endif // READING_LIST_ITEM_H diff --git a/YACReaderLibrary/db/reading_list_model.cpp b/YACReaderLibrary/db/reading_list_model.cpp index bcf584c7..c62838f1 100644 --- a/YACReaderLibrary/db/reading_list_model.cpp +++ b/YACReaderLibrary/db/reading_list_model.cpp @@ -2,19 +2,28 @@ #include "reading_list_item.h" +#include "QsLog.h" + ReadingListModel::ReadingListModel(QObject *parent) : QAbstractItemModel(parent),rootItem(0) { + separator1 = new ReadingListSeparatorItem; + separator2 = new ReadingListSeparatorItem; } int ReadingListModel::rowCount(const QModelIndex &parent) const { 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 { ListItem * item = static_cast(parent.internalPointer()); + QLOG_DEBUG() << item->itemData; + if(typeid(*item) == typeid(ReadingListItem)) { ReadingListItem * item = static_cast(parent.internalPointer()); @@ -27,6 +36,12 @@ int ReadingListModel::rowCount(const QModelIndex &parent) const int ReadingListModel::columnCount(const QModelIndex &parent) const { + if(parent.isValid()) + { + ListItem * item = static_cast(parent.internalPointer()); + if(typeid(*item) == typeid(ReadingListSeparatorItem)) + return 0; + } return 1; /*if (parent.isValid()) return static_cast(parent.internalPointer())->columnCount(); @@ -41,6 +56,9 @@ QVariant ReadingListModel::data(const QModelIndex &index, int role) const ListItem * item = static_cast(index.internalPointer()); + if(typeid(*item) == typeid(ReadingListSeparatorItem)) + return QVariant(); + if (role == Qt::DecorationRole) { return QVariant(item->getIcon()); @@ -57,6 +75,10 @@ Qt::ItemFlags ReadingListModel::flags(const QModelIndex &index) const if (!index.isValid()) return 0; + ListItem * item = static_cast(index.internalPointer()); + if(typeid(*item) == typeid(ReadingListSeparatorItem)) + return 0; + 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()) { + int separatorsCount = labels.isEmpty()?1:2; + if(row >= 0 && row < specialLists.count()) return createIndex(row, column, specialLists.at(row)); - if(row >= specialLists.count() && row < specialLists.count() + labels.count()) - return createIndex(row,column,labels.at(row-specialLists.count())); + if(row == specialLists.count()) + return createIndex(row,column,separator1); - if(row >= specialLists.count() + labels.count()) - return createIndex(row,column,rootItem->child(row - (specialLists.count() + labels.count()))); + if(row > specialLists.count() && 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 { @@ -146,6 +177,8 @@ void ReadingListModel::setupModelData(QString path) specialLists << new SpecialListItem(QList() /*<< 0*/ << "Favorites"); specialLists << new SpecialListItem(QList() /*<< 1*/ << "Reading"); + //separator + //setup labels labels << new LabelItem(QList() /*<< 0*/ << "Oh Oh" << "red"); labels << new LabelItem(QList() /*<< 1*/ << "lalala" << "orange"); @@ -160,6 +193,8 @@ void ReadingListModel::setupModelData(QString path) labels << new LabelItem(QList() /*<< 10*/ << "ainsss" << "light"); labels << new LabelItem(QList() /*<< 11*/ << "put a smile on my face" << "dark"); + //separator + //setup root item rootItem = new ReadingListItem(QList() /*<< 0*/ << "ROOT" << "atr"); diff --git a/YACReaderLibrary/db/reading_list_model.h b/YACReaderLibrary/db/reading_list_model.h index 7b473ca0..b72c1c29 100644 --- a/YACReaderLibrary/db/reading_list_model.h +++ b/YACReaderLibrary/db/reading_list_model.h @@ -10,6 +10,7 @@ class LabelItem; class SpecialListItem; class ReadingListItem; +class ReadingListSeparatorItem; class ReadingListModel : public QAbstractItemModel { @@ -49,6 +50,10 @@ private: ReadingListItem * rootItem; // QMap items; //lists relationship + //separators + ReadingListSeparatorItem * separator1; + ReadingListSeparatorItem * separator2; + QString _databasePath; }; diff --git a/YACReaderLibrary/yacreader_reading_lists_view.cpp b/YACReaderLibrary/yacreader_reading_lists_view.cpp index ac5304af..747b4d90 100644 --- a/YACReaderLibrary/yacreader_reading_lists_view.cpp +++ b/YACReaderLibrary/yacreader_reading_lists_view.cpp @@ -1,6 +1,60 @@ #include "yacreader_reading_lists_view.h" +#include "reading_list_item.h" + YACReaderReadingListsView::YACReaderReadingListsView(QWidget *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(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(index.internalPointer()); + + if(typeid(*item) == typeid(ReadingListSeparatorItem)) + { + QSize newSize = QStyledItemDelegate::sizeHint(option, index); + + newSize.setHeight(7); + + return newSize; + } + + return QStyledItemDelegate::sizeHint(option, index); } diff --git a/YACReaderLibrary/yacreader_reading_lists_view.h b/YACReaderLibrary/yacreader_reading_lists_view.h index 064ebd09..a13456b5 100644 --- a/YACReaderLibrary/yacreader_reading_lists_view.h +++ b/YACReaderLibrary/yacreader_reading_lists_view.h @@ -12,4 +12,14 @@ public: 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