2025-08-31 21:08:28 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <QWidget>
|
|
|
|
|
#include <QStringList>
|
|
|
|
|
#include <QMap>
|
|
|
|
|
|
|
|
|
|
class QGridLayout;
|
|
|
|
|
class ImageTileWidget;
|
|
|
|
|
class QLabel;
|
|
|
|
|
|
|
|
|
|
class ImageGridWidget : public QWidget {
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
explicit ImageGridWidget(QWidget* parent = nullptr);
|
|
|
|
|
|
|
|
|
|
void setImages(int index, const QImage& image);
|
|
|
|
|
void setImages(const QString& alias, const QImage& image); // 通过别名设置图像
|
|
|
|
|
void initImages(int count);
|
|
|
|
|
void setSelectedIndex(int index);
|
|
|
|
|
int selectedIndex() const { return m_selectedIndex; }
|
|
|
|
|
|
|
|
|
|
void setExpandedIndex(int index);
|
|
|
|
|
int expandedIndex() const { return m_expandedIndex; }
|
|
|
|
|
|
|
|
|
|
int columnCount() const { return m_columns; }
|
|
|
|
|
int rowCount() const { return m_rows; }
|
|
|
|
|
QSize tileBaseSize() const { return m_sizeNormal; }
|
|
|
|
|
|
|
|
|
|
// 添加设置别名的方法
|
|
|
|
|
void setTileAlias(int index, const QString& alias);
|
|
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
void tileClicked(int index);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void rebuildGrid();
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
void updateTileSizes();
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void resizeEvent(QResizeEvent* event) override;
|
|
|
|
|
|
|
|
|
|
QGridLayout* m_layout {nullptr};
|
|
|
|
|
QStringList m_paths;
|
|
|
|
|
QList<ImageTileWidget*> m_tiles;
|
|
|
|
|
QMap<QString, int> m_aliasMap; // 别名到索引的映射
|
|
|
|
|
int m_selectedIndex {-1};
|
|
|
|
|
int m_expandedIndex {-1};
|
|
|
|
|
int m_columns {0};
|
|
|
|
|
int m_rows {0};
|
|
|
|
|
QSize m_sizeNormal {160,160};
|
|
|
|
|
QSize m_sizeExpanded {400,300};
|
|
|
|
|
QLabel* m_noImageLabel {nullptr}; // Label to show when there are no images
|
|
|
|
|
};
|