diff --git a/src/contentmanager.cpp b/src/contentmanager.cpp index 8109294..2f49c3b 100644 --- a/src/contentmanager.cpp +++ b/src/contentmanager.cpp @@ -14,6 +14,7 @@ #include "contentmanagermodel.h" #include #include +#include ContentManager::ContentManager(Library* library, kiwix::Downloader* downloader, QObject *parent) : QObject(parent), @@ -29,6 +30,18 @@ ContentManager::ContentManager(Library* library, kiwix::Downloader* downloader, managerModel->setBooksData(booksList); mp_view->setModel(managerModel); mp_view->show(); + + auto header = mp_view->header(); + header->setSectionResizeMode(0, QHeaderView::Fixed); + header->setSectionResizeMode(1, QHeaderView::Stretch); + header->setSectionResizeMode(2, QHeaderView::Fixed); + header->setSectionResizeMode(3, QHeaderView::Fixed); + header->setSectionResizeMode(4, QHeaderView::Fixed); + header->setStretchLastSection(false); + header->setSectionsClickable(true); + header->setHighlightSections(true); + mp_view->setWordWrap(true); + setCurrentLanguage(QLocale().name().split("_").at(0)); connect(mp_library, &Library::booksChanged, this, [=]() {emit(this->booksChanged());}); connect(this, &ContentManager::filterParamsChanged, this, &ContentManager::updateLibrary); @@ -43,7 +56,7 @@ QList> ContentManager::getBooksList() { const auto bookIds = getBookIds(); QList> bookList; - QStringList keys = {"title", "tags", "date", "id", "size"}; + QStringList keys = {"title", "tags", "date", "id", "size", "description"}; auto app = KiwixApp::instance(); std::shared_ptr archive; QIcon bookIcon; diff --git a/src/contentmanagermodel.cpp b/src/contentmanagermodel.cpp index 8f4df44..9a1a84e 100644 --- a/src/contentmanagermodel.cpp +++ b/src/contentmanagermodel.cpp @@ -134,8 +134,18 @@ void ContentManagerModel::setupNodes() auto description = bookItem["description"].toString(); auto icon = bookItem["icon"]; const auto temp = new Node({icon, name, date, size, content, id}, rootNode); + const auto tempsTemp = new Node({"", description, "", "", "", ""}, temp, true); + temp->appendChild(tempsTemp); rootNode->appendChild(temp); } endResetModel(); } +bool ContentManagerModel::hasChildren(const QModelIndex &parent) const +{ + Node *item = static_cast(parent.internalPointer()); + if (item) + return !item->isAdditonal(); + return true; +} + diff --git a/src/contentmanagermodel.h b/src/contentmanagermodel.h index 9241c82..994f456 100644 --- a/src/contentmanagermodel.h +++ b/src/contentmanagermodel.h @@ -26,6 +26,7 @@ public: int columnCount(const QModelIndex &parent = QModelIndex()) const override; void setBooksData(const QList>& data); void setupNodes(); + bool hasChildren(const QModelIndex &parent) const override; private: QList> m_data; diff --git a/src/node.cpp b/src/node.cpp index 47b1cb5..c409fd0 100644 --- a/src/node.cpp +++ b/src/node.cpp @@ -1,7 +1,7 @@ #include "node.h" -Node::Node(const QList &data, Node *parent) - : m_itemData(data), m_parentItem(parent) +Node::Node(const QList &data, Node *parent, bool isAdditional) + : m_itemData(data), m_parentItem(parent), m_isAdditonal(isAdditional) {} Node::~Node() diff --git a/src/node.h b/src/node.h index 91676e1..cf03ea4 100644 --- a/src/node.h +++ b/src/node.h @@ -7,7 +7,7 @@ class Node { public: - explicit Node(const QList &data, Node *parentNode = nullptr); + explicit Node(const QList &data, Node *parentItem = nullptr, bool isAdditional = false); ~Node(); void appendChild(Node *child); Node *child(int row); @@ -16,11 +16,13 @@ public: QVariant data(int column) const; int row() const; Node *parentItem(); + bool isAdditonal() const { return m_isAdditonal; } private: QList m_itemData; Node *m_parentItem; QList m_childItems; + bool m_isAdditonal; };