/*
 * KWin Style UKUI
 *
 * Copyright (C) 2020, KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 * Authors: Yue Lan <lanyue@kylinos.cn>
 *
 */

#ifndef UKUIDECORATION_H
#define UKUIDECORATION_H

#include <KDecoration2/Decoration>
#include <KPluginFactory>
#include <QFont>

namespace KDecoration2 {
class DecorationButtonGroup;
}

namespace UKUI {

struct ShadowParams {
    ShadowParams()
        : offset(QPoint(0, 0))
        , radius(0)
        , opacity(0) {}

    ShadowParams(const QPoint &offset, int radius, qreal opacity)
        : offset(offset)
        , radius(radius)
        , opacity(opacity) {}

    QPoint offset;
    int radius;
    qreal opacity;
};

struct CompositeShadowParams {
    CompositeShadowParams() = default;

    CompositeShadowParams(
            const QPoint &offset,
            const ShadowParams &shadow1,
            const ShadowParams &shadow2)
        : offset(offset)
        , shadow1(shadow1)
        , shadow2(shadow2) {}

    bool isNone() const {
        return qMax(shadow1.radius, shadow2.radius) == 0;
    }

    QPoint offset;
    ShadowParams shadow1;
    ShadowParams shadow2;
};

enum ThemeProject {
        THEME_PROJECT_UKUI_BASE = 0,
        THEME_PROJECT_LAIKA,
        THEME_PROJECT_MAVIS,
        THEME_PROJECT_XC_TABLET,

        THEME_PROJECT_MAX
};

class Decoration : public KDecoration2::Decoration
{
    Q_OBJECT
public:
    explicit Decoration(QObject *parent = nullptr, const QVariantList &args = QVariantList());

    void init();
    void paint(QPainter *painter, const QRect &repaintRegion) override;

    QColor fontColor() const;
    int themeId(){return m_themeId;}
    ThemeProject getThemeProject() { return m_themeProject; }    
    bool getTabletMode() {return m_bTabletMode;}

    int borderTop() const;
    int buttonWidth() const;
    int buttonHeight() const;
    int leftButtonWidth() const;
    int leftButtonHeight() const;
    int innerButtonBorder() const;
    int buttonMarginTop() const;
    int leftButtonMarginTop() const;
    int buttonSpacing() const;
    int leftButtonSpacing() const;

private:
    int m_borderLeft;
    int m_borderTop;
    int m_tabletBorderTop;          // 平板模式下主界面的标题栏高度
    int m_tabletBorderTopForModal;  // 平板模式下模态窗口的标题栏高度
    int m_borderRight;
    int m_borderBottom;

    int m_buttonWidth;          //按钮宽度
    int m_buttonHeight;         //按钮高度

    int m_innerButtonBorder;    // 三联按钮内边距（当前无用）
    int m_tabletInnerButtonBorder;    // 平板三联按钮内边距

    int m_tabletButtonWidth;          // 平板三联按钮宽度
    int m_tabletButtonHeight;         // 平板三联按钮高度

    int m_leftButtonWidth;      //左侧按钮高度
    int m_leftButtonHeight;     //左侧按钮宽度

    int m_tabletLeftButtonWidth;      // 平板左侧按钮高度
    int m_tabletLeftButtonHeight;     // 平板左侧按钮宽度

    int m_ButtonMarginTop;      //按钮上空白
    int m_leftButtonMarginTop;
    int m_tabletLeftButtonMarginTop;    // 平板左侧按钮上空白
    int m_tabletLeftButtonMarginTopForModal;    // 平板模态窗口左侧按钮上空白
    int m_tabletButtonMarginTop;      // 平板三联按钮上空白
    int m_tabletButtonMarginTopForModal;    // 平板模态窗口三联按钮上空白

    int m_buttonSpacing;        //按钮空隙
    int m_leftButtonSpacing;    //左侧按钮空隙
    int m_tabletButtonSpacing;        // 平板三联按钮空隙
    int m_tabletLeftButtonSpacing;        // 平板左侧三联按钮空隙

    QColor m_fontActiveColor;   //活动字体颜色
    QColor m_fontInactiveColor; //非活动字体颜色

    QColor m_frameActiveColor;
    QColor m_frameInactiveColor;

    QColor m_BorderColor; //边框颜色

    bool m_bTabletMode;
    int m_nleftButtonCout;
    int m_nrightButtonCout;

    int m_themeId;
    ThemeProject m_themeProject;

    KDecoration2::DecorationButtonGroup* m_leftButtons;
    KDecoration2::DecorationButtonGroup* m_rightButtons;

    int m_shadowRadius;
    QFont m_Font;

public Q_SLOTS:
    void updateButtonsGeometry();
    void calculateBorders();
    void calculateLeftButtonCount();
    void calculateRightButtonCout();
    void updateTitleBar();
    void updateShadow(int themeId);
    void themeUpdate(int themeId);
    void updatefont(QFont font);
    void slotSwitchTablet(bool bTabletMode);
};

}

#endif // UKUIDECORATION_H
