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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
#ifndef MODINFODIALOGIMAGES_H
#define MODINFODIALOGIMAGES_H
#include "modinfodialogtab.h"
#include "filterwidget.h"
#include <QScrollArea>
class ImagesTab;
class ImagesScrollArea : public QScrollArea
{
Q_OBJECT;
public:
using QScrollArea::QScrollArea;
void setTab(ImagesTab* tab);
protected:
void resizeEvent(QResizeEvent* e) override;
private:
ImagesTab* m_tab = nullptr;
};
class ImagesThumbnails : public QWidget
{
Q_OBJECT;
public:
using QWidget::QWidget;
void setTab(ImagesTab* tab);
protected:
void paintEvent(QPaintEvent* e) override;
void mousePressEvent(QMouseEvent* e) override;
bool event(QEvent* e) override;
private:
ImagesTab* m_tab = nullptr;
};
class ScalableImage : public QWidget
{
Q_OBJECT;
public:
ScalableImage(QString path={});
void setImage(const QString& path);
void setImage(QImage image);
void clear();
bool hasHeightForWidth() const;
int heightForWidth(int w) const;
protected:
void paintEvent(QPaintEvent* e) override;
private:
QString m_path;
QImage m_original, m_scaled;
int m_border;
};
class ImagesTab : public ModInfoDialogTab
{
Q_OBJECT;
friend class ImagesScrollArea;
friend class ImagesThumbnails;
public:
ImagesTab(
OrganizerCore& oc, PluginContainer& plugin,
QWidget* parent, Ui::ModInfoDialog* ui, int id);
void clear() override;
bool feedFile(const QString& rootPath, const QString& fullPath) override;
void update() override;
private:
struct File
{
QString path;
QImage original, thumbnail;
bool failed = false;
File(QString path)
: path(std::move(path))
{
}
};
struct PaintContext
{
QPainter painter;
int thumbSize;
QRect topRect;
PaintContext(QWidget* w)
: painter(w), thumbSize(0)
{
}
};
ScalableImage* m_image;
std::vector<File> m_files;
std::vector<File*> m_filteredFiles;
std::vector<QString> m_supportedFormats;
int m_margins, m_padding, m_border;
const File* m_selection;
FilterWidget m_filter;
void getSupportedFormats();
void select(const File* file);
void scrollAreaResized(const QSize& s);
void paintThumbnails(QPaintEvent* e);
void thumbnailsMouseEvent(QMouseEvent* e);
void showTooltip(QHelpEvent* e);
void onExplore();
void onFilterChanged();
int calcThumbSize(int availableWidth) const;
int calcWidgetHeight(int availableWidth) const;
QRect calcTopThumbRect(int thumbSize) const;
std::pair<std::size_t, std::size_t> calcVisibleRange(
int top, int bottom, int thumbSize) const;
QRect calcBorderRect(const QRect& topRect, int thumbSize, std::size_t i) const;
QRect calcImageRect(const QRect& topRect, int thumbSize, std::size_t i) const;
QSize calcScaledImageSize(
const QSize& originalSize, const QSize& imageSize) const;
void paintThumbnail(PaintContext& cx, std::size_t i);
void paintThumbnailBorder(PaintContext& cx, std::size_t i);
void paintThumbnailImage(PaintContext& cx, std::size_t i);
const File* fileAtPos(const QPoint& p) const;
std::size_t fileCount() const;
const File* getFile(std::size_t i) const;
File* getFile(std::size_t i);
void filterImages();
bool needsReload(const File& file, const QSize& imageSize) const;
void reload(File& file, const QSize& imageSize);
void resizeWidget();
};
#endif // MODINFODIALOGIMAGES_H
|