mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-24 04:32:15 -04:00
Loader widget is shown while catalog is being downloaded
Added a new widget (KiwixLoader) which is displayed when the catalog is being downloaded.
This commit is contained in:
parent
3431fd38da
commit
3abb4b4b4c
@ -39,6 +39,7 @@ SOURCES += \
|
|||||||
src/contenttypefilter.cpp \
|
src/contenttypefilter.cpp \
|
||||||
src/findinpagebar.cpp \
|
src/findinpagebar.cpp \
|
||||||
src/kiwixconfirmbox.cpp \
|
src/kiwixconfirmbox.cpp \
|
||||||
|
src/kiwixloader.cpp \
|
||||||
src/node.cpp \
|
src/node.cpp \
|
||||||
src/suggestionlistworker.cpp \
|
src/suggestionlistworker.cpp \
|
||||||
src/thumbnaildownloader.cpp \
|
src/thumbnaildownloader.cpp \
|
||||||
@ -78,6 +79,7 @@ HEADERS += \
|
|||||||
src/contenttypefilter.h \
|
src/contenttypefilter.h \
|
||||||
src/findinpagebar.h \
|
src/findinpagebar.h \
|
||||||
src/kiwixconfirmbox.h \
|
src/kiwixconfirmbox.h \
|
||||||
|
src/kiwixloader.h \
|
||||||
src/node.h \
|
src/node.h \
|
||||||
src/suggestionlistworker.h \
|
src/suggestionlistworker.h \
|
||||||
src/thumbnaildownloader.h \
|
src/thumbnaildownloader.h \
|
||||||
|
@ -60,6 +60,7 @@ ContentManager::ContentManager(Library* library, kiwix::Downloader* downloader,
|
|||||||
});
|
});
|
||||||
connect(&m_remoteLibraryManager, &OpdsRequestManager::requestReceived, this, &ContentManager::updateRemoteLibrary);
|
connect(&m_remoteLibraryManager, &OpdsRequestManager::requestReceived, this, &ContentManager::updateRemoteLibrary);
|
||||||
connect(mp_view->getView(), SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onCustomContextMenu(const QPoint &)));
|
connect(mp_view->getView(), SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onCustomContextMenu(const QPoint &)));
|
||||||
|
connect(this, &ContentManager::pendingRequest, mp_view, &ContentManagerView::showLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QMap<QString, QVariant>> ContentManager::getBooksList()
|
QList<QMap<QString, QVariant>> ContentManager::getBooksList()
|
||||||
|
@ -23,6 +23,9 @@ ContentManagerView::ContentManagerView(QWidget *parent)
|
|||||||
searcher->setPlaceholderText(gt("search-files"));
|
searcher->setPlaceholderText(gt("search-files"));
|
||||||
searcher->setStyleSheet(styleSheet);
|
searcher->setStyleSheet(styleSheet);
|
||||||
|
|
||||||
|
loader = new KiwixLoader(mp_ui->loading);
|
||||||
|
mp_ui->stackedWidget->setCurrentIndex(0);
|
||||||
|
|
||||||
QIcon searchIcon = QIcon(":/icons/search.svg");
|
QIcon searchIcon = QIcon(":/icons/search.svg");
|
||||||
searcher->addAction(searchIcon, QLineEdit::LeadingPosition);
|
searcher->addAction(searchIcon, QLineEdit::LeadingPosition);
|
||||||
|
|
||||||
@ -46,3 +49,13 @@ ContentManagerView::~ContentManagerView()
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ContentManagerView::showLoader(bool show)
|
||||||
|
{
|
||||||
|
mp_ui->stackedWidget->setCurrentIndex(show);
|
||||||
|
if (show) {
|
||||||
|
loader->startAnimation();
|
||||||
|
} else {
|
||||||
|
loader->stopAnimation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include "ui_contentmanagerview.h"
|
#include "ui_contentmanagerview.h"
|
||||||
|
#include "kiwixloader.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class contentmanagerview;
|
class contentmanagerview;
|
||||||
@ -18,8 +19,12 @@ public:
|
|||||||
QTreeView* getView() { return mp_ui->m_view; }
|
QTreeView* getView() { return mp_ui->m_view; }
|
||||||
QLineEdit* &getSearcher() { return mp_ui->searcher; }
|
QLineEdit* &getSearcher() { return mp_ui->searcher; }
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void showLoader(bool show);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::contentmanagerview *mp_ui;
|
Ui::contentmanagerview *mp_ui;
|
||||||
|
KiwixLoader *loader;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONTENTMANAGERVIEW_H
|
#endif // CONTENTMANAGERVIEW_H
|
||||||
|
@ -13,16 +13,34 @@
|
|||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Form</string>
|
<string>Form</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item row="0" column="0">
|
<item>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<widget class="QStackedWidget" name="stackedWidget">
|
||||||
<item>
|
<property name="currentIndex">
|
||||||
<widget class="QLineEdit" name="searcher"/>
|
<number>1</number>
|
||||||
</item>
|
</property>
|
||||||
<item>
|
<widget class="QWidget" name="contents">
|
||||||
<widget class="QTreeView" name="m_view"/>
|
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||||
</item>
|
<item>
|
||||||
</layout>
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="searcher"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QTreeView" name="m_view"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="loading">
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QWidget" name="widget" native="true"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
75
src/kiwixloader.cpp
Normal file
75
src/kiwixloader.cpp
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
#include "kiwixloader.h"
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QPainterPath>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QSizePolicy>
|
||||||
|
|
||||||
|
KiwixLoader::KiwixLoader(QWidget *parent)
|
||||||
|
: QWidget(parent), m_timer(nullptr)
|
||||||
|
{
|
||||||
|
setFixedSize(parent->width(), parent->height());
|
||||||
|
m_timer = new QTimer(this);
|
||||||
|
connect(m_timer, &QTimer::timeout, this, &KiwixLoader::updateAnimation);
|
||||||
|
}
|
||||||
|
|
||||||
|
KiwixLoader::~KiwixLoader()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void KiwixLoader::stopAnimation()
|
||||||
|
{
|
||||||
|
m_timer->stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void KiwixLoader::startAnimation()
|
||||||
|
{
|
||||||
|
m_timer->start(20);
|
||||||
|
}
|
||||||
|
|
||||||
|
void createArc(QPainter &painter, int startAngle, int spanAngle, QRect rectangle, QPen pen)
|
||||||
|
{
|
||||||
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
|
int arcX = rectangle.x();
|
||||||
|
int arcY = rectangle.y();
|
||||||
|
int arcW = rectangle.width();
|
||||||
|
int arcH = rectangle.height();
|
||||||
|
QPainterPath path;
|
||||||
|
path.moveTo(arcX + arcW, arcY + arcH/2);
|
||||||
|
path.arcTo(rectangle, startAngle, spanAngle);
|
||||||
|
painter.strokePath(path, pen);
|
||||||
|
}
|
||||||
|
|
||||||
|
void KiwixLoader::paintEvent(QPaintEvent *event)
|
||||||
|
{
|
||||||
|
QPainter painter(this);
|
||||||
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
|
|
||||||
|
int width = 100;
|
||||||
|
int height = 100;
|
||||||
|
setFixedSize(this->parentWidget()->width(), this->parentWidget()->height());
|
||||||
|
int centerX = this->parentWidget()->width()/2 - width;
|
||||||
|
int centerY = this->parentWidget()->height()/2 - height;
|
||||||
|
|
||||||
|
QPen pen;
|
||||||
|
pen.setWidth(5);
|
||||||
|
painter.setPen(pen);
|
||||||
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
|
|
||||||
|
QRect rectangle(centerX, centerY, width, height);
|
||||||
|
|
||||||
|
pen.setColor("#eaecf0");
|
||||||
|
createArc(painter, 0, 360, rectangle, pen);
|
||||||
|
|
||||||
|
int startAngle = 0;
|
||||||
|
int spanAngle = -progress;
|
||||||
|
pen.setColor("#3366cc");
|
||||||
|
createArc(painter, startAngle, spanAngle, rectangle, pen);
|
||||||
|
}
|
||||||
|
|
||||||
|
void KiwixLoader::updateAnimation()
|
||||||
|
{
|
||||||
|
progress += 10;
|
||||||
|
if (progress == 360)
|
||||||
|
progress = 0;
|
||||||
|
update();
|
||||||
|
}
|
28
src/kiwixloader.h
Normal file
28
src/kiwixloader.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#ifndef KIWIXLOADER_H
|
||||||
|
#define KIWIXLOADER_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
class KiwixLoader : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit KiwixLoader(QWidget *parent = nullptr);
|
||||||
|
~KiwixLoader();
|
||||||
|
void startAnimation();
|
||||||
|
void stopAnimation();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void updateAnimation();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QTimer *m_timer;
|
||||||
|
int progress = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // KIWIXLOADER_H
|
Loading…
x
Reference in New Issue
Block a user