Skip to content

Commit

Permalink
Search books function
Browse files Browse the repository at this point in the history
Added a search book function in the library
  • Loading branch information
juuz0 committed Jun 23, 2023
1 parent 8176c6b commit 68f694c
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 21 deletions.
3 changes: 2 additions & 1 deletion kiwix-desktop.pro
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ SOURCES += \
HEADERS += \
src/contentmanagerdelegate.h \
src/contentmanagermodel.h \
src/contentmanagerview.h \
src/contenttypefilter.h \
src/findinpagebar.h \
src/node.h \
Expand All @@ -93,7 +94,6 @@ HEADERS += \
src/webpage.h \
src/about.h \
src/contentmanager.h \
src/contentmanagerview.h \
src/tabbar.h \
src/contentmanagerside.h \
src/readinglistbar.h \
Expand All @@ -107,6 +107,7 @@ HEADERS += \
src/static_content.h

FORMS += \
src/contentmanagerview.ui \
src/findinpagebar.ui \
ui/mainwindow.ui \
ui/about.ui \
Expand Down
10 changes: 10 additions & 0 deletions resources/css/_contentManager.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ QTreeView::item:has-children {
QTreeView {
font-family: 'Selawik';
padding: 4px;
border: none;
}

QHeaderView::section {
Expand Down Expand Up @@ -60,3 +61,12 @@ QMenu::item:selected {
background-color: #cccccc;
}

QLineEdit {
font-family: 'Selawik';
padding: 4px;
border: 1px solid #cccccc;
color: #666666;
font-size: 16px;
height: 32px;
line-height: 24px;
}
Binary file added resources/icons/placeholder-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 12 additions & 11 deletions src/contentmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ ContentManager::ContentManager(Library* library, kiwix::Downloader* downloader,
auto managerModel = new ContentManagerModel();
const auto booksList = getBooksList();
managerModel->setBooksData(booksList);
mp_view->setModel(managerModel);
mp_view->show();
auto treeView = mp_view->getView();
treeView->setModel(managerModel);
treeView->show();

auto managerDelegate = new ContentManagerDelegate();
mp_view->setItemDelegate(managerDelegate);
treeView->setItemDelegate(managerDelegate);

auto header = mp_view->header();
auto header = treeView->header();
header->setSectionResizeMode(0, QHeaderView::Fixed);
header->setSectionResizeMode(1, QHeaderView::Stretch);
header->setSectionResizeMode(2, QHeaderView::Fixed);
Expand All @@ -45,9 +46,9 @@ ContentManager::ContentManager(Library* library, kiwix::Downloader* downloader,
header->setStretchLastSection(false);
header->setSectionsClickable(true);
header->setHighlightSections(true);
mp_view->setWordWrap(true);
mp_view->resizeColumnToContents(4);
mp_view->setColumnWidth(0, 80);
treeView->setWordWrap(true);
treeView->resizeColumnToContents(4);
treeView->setColumnWidth(0, 80);
// TODO: set width for all columns based on viewport

setCurrentLanguage(QLocale().name().split("_").at(0));
Expand All @@ -58,7 +59,7 @@ ContentManager::ContentManager(Library* library, kiwix::Downloader* downloader,
managerModel->setBooksData(nBookList);
});
connect(&m_remoteLibraryManager, &OpdsRequestManager::requestReceived, this, &ContentManager::updateRemoteLibrary);
connect(mp_view, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onCustomContextMenu(const QPoint &)));
connect(mp_view->getView(), SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onCustomContextMenu(const QPoint &)));
}

QList<QMap<QString, QVariant>> ContentManager::getBooksList()
Expand Down Expand Up @@ -91,8 +92,8 @@ QList<QMap<QString, QVariant>> ContentManager::getBooksList()

void ContentManager::onCustomContextMenu(const QPoint &point)
{
QModelIndex index = mp_view->indexAt(point);
QMenu contextMenu("optionsMenu", mp_view);
QModelIndex index = mp_view->getView()->indexAt(point);
QMenu contextMenu("optionsMenu", mp_view->getView());
Node* bookNode = static_cast<Node*>(index.internalPointer());
const auto id = bookNode->getBookId();

Expand All @@ -118,7 +119,7 @@ void ContentManager::onCustomContextMenu(const QPoint &point)
contextMenu.addAction(&menuDeleteBook);

if (index.isValid()) {
contextMenu.exec(mp_view->viewport()->mapToGlobal(point));
contextMenu.exec(mp_view->getView()->viewport()->mapToGlobal(point));
}
}

Expand Down
27 changes: 23 additions & 4 deletions src/contentmanagerview.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
#include "contentmanagerview.h"
#include <QFile>
#include "kiwixapp.h"
#include <QLineEdit>
#include "ui_contentmanagerview.h"

ContentManagerView::ContentManagerView(QWidget *parent)
: QTreeView(parent)
: QWidget(parent), mp_ui(new Ui::contentmanagerview)
{
setSortingEnabled(true);
mp_ui->setupUi(this);
mp_ui->m_view->setSortingEnabled(true);
QFile file(QString::fromUtf8(":/css/_contentManager.css"));
file.open(QFile::ReadOnly);
QString styleSheet = QString(file.readAll());
setStyleSheet(styleSheet);
setContextMenuPolicy(Qt::CustomContextMenu);
mp_ui->m_view->setStyleSheet(styleSheet);
mp_ui->m_view->setContextMenuPolicy(Qt::CustomContextMenu);

auto searcher = mp_ui->searcher;
searcher->setPlaceholderText(gt("search-files"));
searcher->setStyleSheet(styleSheet);

QIcon searchIcon = QIcon(":/icons/search.svg");
searcher->addAction(searchIcon, QLineEdit::LeadingPosition);

connect(searcher, &QLineEdit::textChanged, [searcher](){
KiwixApp::instance()->getContentManager()->setSearch(searcher->text());
});
}

ContentManagerView::~ContentManagerView()
{

}
19 changes: 14 additions & 5 deletions src/contentmanagerview.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
#ifndef CONTENTMANAGERVIEW_H
#define CONTENTMANAGERVIEW_H

#include <QWebEngineView>
#include <QTreeView>
#include <QWidget>
#include "ui_contentmanagerview.h"

class ContentManagerView : public QTreeView
namespace Ui {
class contentmanagerview;
}

class ContentManagerView : public QWidget
{
Q_OBJECT

public:
ContentManagerView(QWidget *parent = Q_NULLPTR);
explicit ContentManagerView(QWidget *parent = nullptr);
~ContentManagerView();
QTreeView* getView() { return mp_ui->m_view; }
QLineEdit* &getSearcher() { return mp_ui->searcher; }

private:
QTreeView m_view;
Ui::contentmanagerview *mp_ui;
};

#endif // CONTENTMANAGERVIEW_H
31 changes: 31 additions & 0 deletions src/contentmanagerview.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>contentmanagerview</class>
<widget class="QWidget" name="contentmanagerview">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLineEdit" name="searcher"/>
</item>
<item>
<widget class="QTreeView" name="m_view"/>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
1 change: 1 addition & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class MainWindow : public QMainWindow

TabBar* getTabBar();
TopWidget* getTopWidget();
QWidget getMainView();

protected:
void keyPressEvent(QKeyEvent *event);
Expand Down

0 comments on commit 68f694c

Please sign in to comment.