aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/icon.h
blob: d6512c9667464fd26151c7016df42d6ad83a619e (plain) (blame)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#ifndef ICONS_H
#define ICONS_H

#include "guiSQLiteStudio_global.h"
#include <QString>
#include <QIcon>
#include <QVariant>

class QMovie;

#define DEF_ICONS(TypeName, ObjName, Defs) \
    struct GUI_API_EXPORT TypeName \
    { \
        Defs \
    }; \
    TypeName ObjName;

#define DEF_ICON(E,N) Icon E = Icon(#E, N);
#define DEF_ICO2(E,Src,Attr) Icon E = Icon::createFrom(#E, Src, Icon::Attr);
#define DEF_ICO3(E,Src) Icon E = Icon::aliasOf(#E, &Src);

class GUI_API_EXPORT Icon
{
    public:
        enum Attributes
        {
            NONE,
            PLUS,
            MINUS,
            EDIT,
            DELETE,
            DENIED,
            INFO,
            WARNING,
            QUESTION,
            ERROR,
            SORT_ASC,
            SORT_DESC
        };

        Icon(const QString& name, const QString& fileName);
        Icon(const Icon& other);
        ~Icon();

        QString getFileName() const;
        QString getName() const;
        QString getPath() const;
        bool isNull() const;
        bool isMovie() const;
        void load();
        QString toImgSrc() const;
        QString toBase64Url() const;
        QByteArray toBase64() const;
        QByteArray toPixmapBytes() const;
        QString toUrl() const;
        QIcon* toQIconPtr() const;
        QIcon toQIcon() const;
        Icon* toIconPtr();
        QPixmap toQPixmap() const;
        QMovie* toQMoviePtr() const;
        QVariant toQVariant() const;
        QIcon* with(Attributes attr);

        operator Icon*();
        operator QIcon() const;
        operator QIcon*() const;
        operator QPixmap() const;
        operator QMovie*() const;
        operator QVariant() const;

        static void init();
        static void loadAll();
        static void reloadAll();
        static Icon& createFrom(const QString& name, Icon* copy, Attributes attr);
        static Icon& aliasOf(const QString& name, Icon* other);
        static QIcon merge(const QIcon& icon, Attributes attr);

    private:
        explicit Icon(const QString& name);

        static QString getIconNameForAttribute(Attributes attr);
        static QIcon mergeAttribute(const QIcon* icon, Attributes attr);

        bool loaded = false;
        bool movie = false;
        QString name;
        Attributes attr = NONE;
        QString fileName;
        QString filePath;
        Icon* copyFrom = nullptr;
        Icon* aliased = nullptr;
        QMovie* movieHandle = nullptr;
        QIcon* iconHandle = nullptr;
        QHash<int,QIcon*> dynamicallyAttributed;

        static QHash<QString,Icon*> instances;
};

GUI_API_EXPORT QDataStream &operator<<(QDataStream &out, const Icon* icon);
GUI_API_EXPORT QDataStream &operator>>(QDataStream &in, const Icon*& icon);

Q_DECLARE_METATYPE(const Icon*)

#endif // ICONS_H