#ifndef WATERMARK_H
#define WATERMARK_H

#include <QDBusAbstractAdaptor>
#include <QDBusConnection>
#include <QDBusInterface>
#include <QDBusReply>
#include <QDebug>
#include <QWidget>

class WaterMark : public QWidget
{
public:
    WaterMark(QWidget *parent = nullptr);
    ~WaterMark();
    enum waterMarkPosition {
        TopLeft,
        TopRight,
        BottomLeft,
        BottomRight,
        CenterTop,
        CenterBottom
    };
    void open();
    void close();
    //    void update(QColor color, int font, waterMarkPosition position);
    void update(int color, int font_size, int position);
    waterMarkPosition position = waterMarkPosition::BottomRight; // 这个地方可以测试
    static QString waterMarkPositionToString(WaterMark::waterMarkPosition pos);
    static waterMarkPosition stringToWaterMarkPosition(const QString &str);
    bool switchModeImmediate();

public Q_SLOTS:
    void switchState(bool changed);
    void getChangedBootMode(qint32 bootMode);

private:
    void calculateScreen();
    // void saveWatermarkToImage(const QString &filePath);
    void saveWatermarkToImage(const QString &filePath, QColor color, int font, WaterMark::waterMarkPosition pos);
    void listenOstreeConfigChange();
    QRect fullScreenGeometry;
    QRect primaryScreenGeometry;
    QString pngFilePath;
    QString configFilePath;
    int fontSize;
    QColor fontColor;
    waterMarkPosition fontPos;
    int fontPosX, fontPosY;
    QDBusInterface *waterMarkInterface;
    void calculateShowPosition(waterMarkPosition position, const QFont &font, QString text);
    bool m_isSwitchModeImmediate = false;
    void initConfig();
    QVariant readConfigFile(const QString &filepath, const QString &group, const QString &key);
    void writeConfigFile(const QString &filepath, const QString &group, const QString &key, const QVariant &value);
};

#endif
