aboutsummaryrefslogtreecommitdiff
path: root/libs/installer_fomod_plus/installer/ui/UIHelper.h
blob: 1007e7c4751fef926b37831c8adefbb65139284d (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#pragma once

#include <QPushButton>
#include <QVBoxLayout>
#include <QLabel>

#include "FomodViewModel.h"

class HoverEventFilter final : public QObject {
    Q_OBJECT

public:
    explicit HoverEventFilter(const std::shared_ptr<PluginViewModel>& plugin, QObject* parent = nullptr);

signals:
    void hovered(const std::shared_ptr<PluginViewModel>& plugin);

protected:
    bool eventFilter(QObject* obj, QEvent* event) override;

private:
    std::shared_ptr<PluginViewModel> mPlugin;
};

class CtrlClickEventFilter final : public QObject {
    Q_OBJECT

public:
    explicit CtrlClickEventFilter(const std::shared_ptr<PluginViewModel>& plugin,
        const std::shared_ptr<GroupViewModel>& group, QObject* parent = nullptr);

signals:
    void ctrlClicked(bool selected, const std::shared_ptr<GroupViewModel>& group,
        const std::shared_ptr<PluginViewModel>& plugin);

protected:
    bool eventFilter(QObject* obj, QEvent* event) override;

private:
    std::shared_ptr<PluginViewModel> mPlugin;
    std::shared_ptr<GroupViewModel> mGroup;
};


namespace UiConstants {
constexpr int WINDOW_MIN_WIDTH  = 900;
constexpr int WINDOW_MIN_HEIGHT = 600;
}

class UIHelper {
public:
    /*
    --------------------------------------------------------------------------------
                               Widgets & Events
    --------------------------------------------------------------------------------
    */
    static QPushButton* createButton(const QString& text, QWidget* parent);

    static QLabel* createLabel(const QString& text, QWidget* parent);

    static QLabel* createHyperlink(const QString& url, QWidget* parent);

    /*
    --------------------------------------------------------------------------------
                                   Helpers
    --------------------------------------------------------------------------------
    */
    static QString getFullImagePath(const QString& fomodPath, const QString& imagePath);

    static void setGlobalAlignment(QBoxLayout* layout, Qt::Alignment alignment);

    static void reduceLabelPadding(const QLayout* layout);

    /*
    --------------------------------------------------------------------------------
                                   Development
    --------------------------------------------------------------------------------
    */
    static void setDebugBorders(QWidget* widget);
};