//
// Created by Krad on 2021/12/16.
//

#ifndef GUI_ROLLINGMESSAGEWIDGET_H
#define GUI_ROLLINGMESSAGEWIDGET_H

#include <QWidget>
#include <QMutex>
class QThread;
class QLabel;
class QTimerEvent;
class RollingMessageWidget:public QWidget {
    struct WarnMessage{
        int innerId;
        QString msg;
        /**
         * 优先级，默认为0，-1不显示，1代表插入优先显示
         */
        int priority;
        QString toString(){
            return QString("{innerId:%1, msg:%2, priority:%3}").arg(innerId).arg(msg).arg(priority);
        }
    };
Q_OBJECT
public:
    explicit RollingMessageWidget(QWidget *parent = nullptr);
    void setMessageList(const QStringList& message);
    void updateMessagePriority(int innerIndex, int priority);

protected:
    void timerEvent(QTimerEvent* event) override ;
    void showEvent(QShowEvent *event) override ;
    QString getNextMessage();
private:
    int timerId =  -1;
    int waitPriorityCount = 0;
    int waitStep = 0;
    int rollStep = 0;
    bool needRolling = false;
    bool rolling = false;
    QLabel* label_current = nullptr;
    QLabel* label_next = nullptr;
    QList<WarnMessage> messages;
    QMutex locker;
    bool init = false;
    int ROLL_DISTANCE=2000;
};


#endif //GUI_ROLLINGMESSAGEWIDGET_H
