aboutsummaryrefslogtreecommitdiff
path: root/qdeduper/imageitem.hpp
blob: ec8e789ac2f61965fbc29e2cbe0daafae1b7c922 (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
//Chris Xiong 2022
//License: MPL-2.0
#ifndef IMAGEITEM_HPP
#define IMAGEITEM_HPP

#include <QStandardItem>
#include <QAbstractItemDelegate>
#include <QAbstractItemModel>
#include <QStyleOptionViewItem>
#include <QModelIndex>

class ImageItem : public QStandardItem
{
public:
    enum ImageItemRoles
    {
        path_role = Qt::ItemDataRole::UserRole + 0x1000,
        dimension_role,
        file_size_role,
        hotkey_role,
        database_id_role,
        default_order_role,
        pixelcnt_role
    };
    ImageItem(QString fn, QString dispn, QKeySequence hotkey, size_t dbid, size_t ord, double pxratio = 1.0);

    QString path() const;
    size_t database_id() const;
    size_t default_order() const;
    QKeySequence hotkey() const;
    void set_hotkey(QKeySequence hk);
};

class ImageItemDelegate : public QAbstractItemDelegate
{
    Q_OBJECT
private:
    const static int MARGIN = 3;
    const static int BORDER = 3;
    const static int HKPADD = 4;
    const static int LINESP = 4;
    const static int HKSHDS = 2;
    int vw = -1;
    int hh = -1;
    int min_height = 64;
    bool singlemode = false;
    bool show_hotkey = true;
    QAbstractItemModel *im = nullptr;
public:
    void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
    QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
    void resize();
    void set_scrollbar_margins(int vw, int hh);
    void set_min_height(int mh);

    void set_single_item_mode(bool enabled);
    bool is_single_item_mode();

    void set_show_hotkey(bool show);

    void set_model(QAbstractItemModel *m);
Q_SIGNALS:
    void sizeHintChanged(const QModelIndex &index);
};

#endif