mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-22 03:26:05 -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/findinpagebar.cpp \
|
||||
src/kiwixconfirmbox.cpp \
|
||||
src/kiwixloader.cpp \
|
||||
src/node.cpp \
|
||||
src/suggestionlistworker.cpp \
|
||||
src/thumbnaildownloader.cpp \
|
||||
@ -78,6 +79,7 @@ HEADERS += \
|
||||
src/contenttypefilter.h \
|
||||
src/findinpagebar.h \
|
||||
src/kiwixconfirmbox.h \
|
||||
src/kiwixloader.h \
|
||||
src/node.h \
|
||||
src/suggestionlistworker.h \
|
||||
src/thumbnaildownloader.h \
|
||||
|
@ -60,6 +60,7 @@ ContentManager::ContentManager(Library* library, kiwix::Downloader* downloader,
|
||||
});
|
||||
connect(&m_remoteLibraryManager, &OpdsRequestManager::requestReceived, this, &ContentManager::updateRemoteLibrary);
|
||||
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()
|
||||
|
@ -23,6 +23,9 @@ ContentManagerView::ContentManagerView(QWidget *parent)
|
||||
searcher->setPlaceholderText(gt("search-files"));
|
||||
searcher->setStyleSheet(styleSheet);
|
||||
|
||||
loader = new KiwixLoader(mp_ui->loading);
|
||||
mp_ui->stackedWidget->setCurrentIndex(0);
|
||||
|
||||
QIcon searchIcon = QIcon(":/icons/search.svg");
|
||||
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 "ui_contentmanagerview.h"
|
||||
#include "kiwixloader.h"
|
||||
|
||||
namespace Ui {
|
||||
class contentmanagerview;
|
||||
@ -18,8 +19,12 @@ public:
|
||||
QTreeView* getView() { return mp_ui->m_view; }
|
||||
QLineEdit* &getSearcher() { return mp_ui->searcher; }
|
||||
|
||||
public slots:
|
||||
void showLoader(bool show);
|
||||
|
||||
private:
|
||||
Ui::contentmanagerview *mp_ui;
|
||||
KiwixLoader *loader;
|
||||
};
|
||||
|
||||
#endif // CONTENTMANAGERVIEW_H
|
||||
|
@ -13,16 +13,34 @@
|
||||
<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>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QStackedWidget" name="stackedWidget">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="contents">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<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>
|
||||
</layout>
|
||||
</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