#ifndef BUBBLETIP_H
#define BUBBLETIP_H

#include <QLabel>
#include <QPropertyAnimation>
#include <QQueue>
#include <QTimer>
#include <QWidget>

class BubbleTip : public QWidget
{
    Q_OBJECT

public:
    enum Position { Top, Bottom, Left, Right, Center };
    enum Type { Info, Success, Warning, Error, Default };

    static void showTip(QWidget* target,
                        const QString& text,
                        Position position = Bottom,
                        int duration = 0,
                        Type type = Default,
                        QWidget* parent = nullptr);
    static void hideAll();

private:
    explicit BubbleTip(QWidget* target,
                       const QString& text,
                       Position position,
                       int duration,
                       Type type,
                       QWidget* parent = nullptr);

    void paintEvent(QPaintEvent* event) override;
    bool eventFilter(QObject* watched, QEvent* event) override;

    void updatePosition();
    void startShowAnimation();
    void startHideAnimation();
    void adjustFollowingTips();
    static void adjustTipsForTarget(QWidget* target);

private:
    QWidget* m_target;
    Position m_position;
    Type m_type;
    QLabel* m_label;
    QTimer* m_timer;
    int m_verticalOffset; // 新增：垂直偏移量

    static QQueue<BubbleTip*> m_queue;
    static QMap<QWidget*, QMap<BubbleTip::Position, QQueue<BubbleTip*>>> m_targetMap;
};

#endif // BUBBLETIP_H
