/*
 * Copyright (C) 2025 KylinSoftCo., 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, 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 <http://www.gnu.org/licenses/>.
 *
 **/

#ifndef QT_MATRIX_COMPAT_H
#define QT_MATRIX_COMPAT_H

#include <QTransform>
#include <QPixmap>

#if QT_VERSION_MAJOR == 6
    // Qt6中使用QTransform替代QMatrix
    typedef QTransform QMatrix;
    
    // 为了保持API兼容性，提供一些QMatrix特有的方法
    namespace QtMatrixCompat {
        // QMatrix的rotate方法在QTransform中对应rotate
        inline void rotateMatrix(QTransform& matrix, qreal angle) {
            matrix.rotate(angle);
        }
        
        // QMatrix的scale方法在QTransform中对应scale
        inline void scaleMatrix(QTransform& matrix, qreal sx, qreal sy) {
            matrix.scale(sx, sy);
        }
        
        // QMatrix的translate方法在QTransform中对应translate
        inline void translateMatrix(QTransform& matrix, qreal dx, qreal dy) {
            matrix.translate(dx, dy);
        }
    }
#else
    // Qt5中直接使用QMatrix
    #include <QMatrix>
    
    // 为了保持一致性，提供相同的命名空间
    namespace QtMatrixCompat {
        inline void rotateMatrix(QMatrix& matrix, qreal angle) {
            matrix.rotate(angle);
        }
        
        inline void scaleMatrix(QMatrix& matrix, qreal sx, qreal sy) {
            matrix.scale(sx, sy);
        }
        
        inline void translateMatrix(QMatrix& matrix, qreal dx, qreal dy) {
            matrix.translate(dx, dy);
        }
    }
#endif

// 提供QPixmap::transformed的兼容性处理
namespace QtPixmapCompat {
    inline QPixmap transformedPixmap(const QPixmap& pixmap, const QMatrix& matrix, Qt::TransformationMode mode = Qt::FastTransformation) {
#if QT_VERSION_MAJOR == 6
        // 在Qt6中，QMatrix实际上是QTransform
        return pixmap.transformed(static_cast<const QTransform&>(matrix), mode);
#else
        // 在Qt5中，直接使用QMatrix
        return pixmap.transformed(matrix, mode);
#endif
    }
}

#endif // QT_MATRIX_COMPAT_H
