Files
CalibratorLauncher/widgets/appicon.h
2026-01-02 19:20:35 +09:00

75 lines
1.7 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef APPICON_H
#define APPICON_H
#include <QWidget>
#include <QLabel>
#include <QPropertyAnimation>
#include <QGraphicsDropShadowEffect>
struct AppIconData
{
QString id;
QString name;
QString nameEn;
QString icon;
QString color;
QStringList gradient;
QString badge;
QString group; // 分组标识相同group的图标会被框起来
QString description;
QStringList features;
bool warning = false;
};
class AppIcon : public QWidget
{
Q_OBJECT
Q_PROPERTY(qreal scale READ scale WRITE setScale)
public:
explicit AppIcon(const AppIconData &data, QWidget *parent = nullptr);
~AppIcon();
QString appId() const { return m_data.id; }
qreal scale() const { return m_scale; }
void setScale(qreal scale);
signals:
void clicked(const QString &appId);
void longPressed(const QString &appId);
protected:
void paintEvent(QPaintEvent *event) override;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
void enterEvent(QEnterEvent *event) override;
#else
void enterEvent(QEvent *event) override;
#endif
void leaveEvent(QEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void timerEvent(QTimerEvent *event) override;
private:
void setupUI();
void animateScale(qreal targetScale, int duration = 100);
QString generateGradientStyle() const;
QString getIconSymbol(const QString &id) const;
AppIconData m_data;
QLabel *m_iconLabel;
QLabel *m_nameLabel;
QLabel *m_badgeLabel;
QGraphicsDropShadowEffect *m_shadowEffect;
qreal m_scale;
bool m_isPressed;
int m_longPressTimerId;
static constexpr int ICON_SIZE = 96;
static constexpr int BORDER_RADIUS = 20;
static constexpr int LONG_PRESS_DELAY = 500;
};
#endif // APPICON_H