#ifndef WEEKLYCODEWIDGET_H
#define WEEKLYCODEWIDGET_H

#include <QLabel>
#include <QMutex>
#include <QTimer>

#include "models/downloader.h"

class WeeklyCodeWidget : public QLabel
{
    Q_OBJECT
public:
    explicit WeeklyCodeWidget(QWidget* parent = nullptr);

protected:
    virtual void leaveEvent(QEvent * event) override;
    virtual void enterEvent(QEvent * event) override;
    virtual void paintEvent(QPaintEvent *event) override;
    virtual void mousePressEvent(QMouseEvent *ev) override;
    virtual void mouseReleaseEvent(QMouseEvent *ev) override;

signals:
    void mouseEntered(QString tooltip);
    void mouseLeaved();

public slots:
    void updateCode();

private slots:
    void changeImageSrc(const QString& src);

private:
    QMutex bg_lock;
    QString img_src;
    QPixmap current_bg;

    QByteArray code_data;
    QTimer code_update_timer;
    Downloader code_downloader;

};

#endif // WEEKLYCODEWIDGET_H
