#ifndef REPLACEBACKGROUNDWIDGET_H
#define REPLACEBACKGROUNDWIDGET_H

#include <QWidget>
#include <QtDebug>
#include <QImage>
#include <QMessageBox>
#include <QColorDialog>
#include <QPushButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QFrame>
#include <QLabel>
#include <QPalette>
#include <QApplication>
#include <QGraphicsDropShadowEffect>
#include <QtQuickWidgets/QQuickWidget>
#include <QQmlEngine>
#include <QSplitter>
#include <kborderlessbutton.h>
#include "controller/interaction.h"
#include "view/sizedate.h"
#include "global/variable.h"

class ReplaceBackgroundWidget : public QWidget
{
    Q_OBJECT
public:
    explicit ReplaceBackgroundWidget(QWidget *parent = nullptr);

    QLabel *m_showImage;
    QQuickWidget *m_showImageQml = nullptr;

    QWidget *m_leftWidget = nullptr;
    QWidget *m_rightWidget = nullptr;
    QWidget *m_rightTopWidget = nullptr;
    QWidget *m_rightBottomWidget = nullptr;

    QWidget *m_toolWid = nullptr;              //对比+工具栏
    QWidget *m_toolBtnWid = nullptr;          //工具栏按钮
    QWidget *m_zoomWid = nullptr;             //缩、放按钮以及百分比

    QHBoxLayout *m_toolLayout;                //对比+工具栏布局
    QHBoxLayout *m_toolBtnLayout;             //工具栏布局
    QVBoxLayout *m_leftLayout;                //界面左侧布局
    QVBoxLayout *m_rightLayout;               //界面右侧布局
    QVBoxLayout *m_rightTopLayout;            //右侧上面背景更换布局
    QHBoxLayout *m_rightBottomLayout;         //右侧下面保存取消布局
    QHBoxLayout *m_colorCustomLayout;               //颜色label + 自定义布局
    QGridLayout *m_colorBtnLayout;            //颜色按钮布局
    QGridLayout *m_picBtnLayout;              //图片按钮布局
    QHBoxLayout *m_layout;                    //界面整体布局

    QPushButton *m_compare;        //对比
    kdk::KBorderlessButton *m_reduce;         //缩小
    QLabel *m_percentage;                     //百分比
    kdk::KBorderlessButton *m_enlarge;        //放大
    kdk::KBorderlessButton *m_originalSize;   //原尺寸
    kdk::KBorderlessButton *m_adaptiveWidget; //适应窗口
    kdk::KBorderlessButton *m_rotate;         //旋转
    kdk::KBorderlessButton *m_flipH;          //水平翻转
    kdk::KBorderlessButton *m_flipV;          //垂直翻转
    kdk::KBorderlessButton *m_cutImage;       //裁剪

    QLabel *m_bg;                             //背景更换label
    QLabel *m_pureColor;                      //纯色label
    QLabel *m_pic;                            //图片label
    QPushButton *m_customBtn;                 //自定义颜色按钮
    QPushButton *m_transparent;               //透明
    QPushButton *m_white;                     //白
    QPushButton *m_grey;                      //灰
    QPushButton *m_dimGrey;                   //深灰
    QPushButton *m_dark;                      //黑
    QPushButton *m_blue;                      //蓝
    QPushButton *m_red;                       //红
    QPushButton *m_darkOrange;                //深橙
    QPushButton *m_orange;                    //橙
    QPushButton *m_green;                     //绿
    QPushButton *m_purple;                    //紫
    QPushButton *m_pink;                      //粉
    QPushButton *m_addPicBtn;                 //添加图片按钮
    QPushButton *m_pic1;                      //默认图片1
    QPushButton *m_pic2;
    QPushButton *m_pic3;
    QPushButton *m_pic4;
    QPushButton *m_pic5;
    QPushButton *m_saveBtn;                   //保存按钮
    QPushButton *m_cancelBtn;                 //取消按钮

    QString filePath;
    int flag = false;
    QString widRadius = QString("6px");
    QString normalIconPath = QString("sp1");
    QString nowThemeStyle;

    void initLayout();                        //初始化布局
    void initConnect();                       //初始化信号连接
    void setColorBtnStyle();                  //设置纯色按钮样式
    void setBtnIcon();                        //设置按钮图标
    void toolBtnIconSize(QSize size);         //工具栏按钮图标尺寸设置
    void toolButtonSize(QSize size);          //工具栏按钮尺寸设置
    void colorButtonSize(QSize size);         //颜色按钮尺寸设置
    void pictureBtnSize(QSize size);          //图片按钮尺寸设置
    void pictureBtnIconSize(QSize size);      //图片按钮图标尺寸设置
    void platformType();
    void initGsetting();                      //监听主题
    void changeStyle();                       //根据主题改变样式表
    void initQmlObject();                     //初始化qml
    void resizeEvent(QResizeEvent *event);


public Q_SLOTS:
    void startReplaceBackground();            //开始背景更换
    void exitReplaceBackground();             //退出背景更换
    void getReplaceImage(QImage image);       //从后端获取更换完成的图片
    void needSave();                          //备份保存图片
    void reduceImage();                       //缩小图片
    void enlargeImage();                      //放大图片
    void originalSize();                      //原始尺寸
    void adaptiveWidget();                    //适应窗口
    void rotate();                           //逆时针旋转
    void flipH();                             //水平翻转
    void flipV();                             //垂直翻转
    void cutImage();                          //裁剪
    //void showOrigImage();


Q_SIGNALS:
    void toBackShowImageWid();
    void backgroundColor(unsigned b, unsigned g, unsigned r);

};

#endif // REPLACEBACKGROUNDWIDGET_H
