#ifndef LOADINGWIDGET_H
#define LOADINGWIDGET_H

#include <QStackedWidget>
#include <QWidget>

class QLabel;
class QMovie;

class LoadingWidget : public QWidget {
    Q_OBJECT
   public:
    static void init(QStackedWidget* stackedWidget);
    // 获取全局实例
    static LoadingWidget* instance();

    // 显示加载 (可选parent，不传则居中于屏幕)
    static void showLoading(QWidget* parent = nullptr, const QString& text = "Loading...");

    // 隐藏加载
    static void hideLoading();

   protected:
    void resizeEvent(QResizeEvent* event) override;

   private:
    explicit LoadingWidget(QWidget* parent = nullptr);
    static LoadingWidget* m_instance;

    void updatePosition();
    void initUI();

    QLabel* m_loadingLabel;
    QLabel* m_textLabel;
    QMovie* m_movie;
};

#endif  // LOADINGWIDGET_H
