aboutsummaryrefslogtreecommitdiff
path: root/libs/installer_fomod_plus/installer/ui/ScaleLabel.h
blob: f4fb5f2541b530759604273f61a710ff7fe50129 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#pragma once

// Taken from https://github.com/ModOrganizer2/modorganizer-installer_fomod/blob/master/src/scalelabel.h
#include <QLabel>
#include <QMouseEvent>
#include <QMovie>


class ScaleLabel final : public QLabel {
    Q_OBJECT

public:
    explicit ScaleLabel(QWidget* parent = nullptr) : QLabel(parent)
    {
        setCursor(Qt::PointingHandCursor);
    }

    void setScalableResource(const QString& path);
    void setStatic(bool isStatic);
    [[nodiscard]] bool hasResource() const { return mHasResource; }

signals:
    void clicked();

protected:
    void mousePressEvent(QMouseEvent* event) override
    {
        if (event->button() == Qt::LeftButton) {
            emit clicked();
        }
        QLabel::mousePressEvent(event);
    }

    void resizeEvent(QResizeEvent* event) override;
    void showEvent(QShowEvent* event) override;

private:
    void setScalableMovie(const QString& path);
    void setScalableImage(const QString& path);

    QImage mUnscaledImage;
    QSize mOriginalMovieSize;
    bool mHasResource = false;
    bool misStatic    = false;
};