/* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
 * -*- coding: utf-8 -*-
 *
 * Copyright (C) 2025 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
 * the Free Software Foundation, either version 3 of the License, or
 * 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 UKUI4CUSTOMCONTROL_H
#define UKUI4CUSTOMCONTROL_H

#include <QSlider>
#include <QLabel>
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include <QEnterEvent>
#endif
#include <kslider.h>

//文本长自动省略并添加悬浮
class AutoOmitLabel : public QLabel
{
    Q_OBJECT
public:
    explicit AutoOmitLabel(QWidget* = nullptr);
    explicit AutoOmitLabel(const QString&, QWidget* = nullptr);
    ~AutoOmitLabel() = default;

public:
    void setText(const QString&, bool = true);

protected:
    void paintEvent(QPaintEvent*) override;

private:
    QString m_fullText;
};

class UkmediaVolumeSlider : public kdk::KSlider
{
    Q_OBJECT
public:
    UkmediaVolumeSlider(QWidget* = nullptr);
    ~UkmediaVolumeSlider();

Q_SIGNALS:
    void silderPressSignal();

    void silderReleaseSignal();

protected:
    void mousePressEvent(QMouseEvent*) override;

    void mouseReleaseEvent(QMouseEvent*) override;

    void mouseMoveEvent(QMouseEvent*) override;

    void wheelEvent(QWheelEvent*) override;

    void keyReleaseEvent(QKeyEvent*) override;

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
    void enterEvent(QEnterEvent*) override;
#else
    void enterEvent(QEvent*) override;
#endif

    void leaveEvent(QEvent*) override;

private:
    void initStyleOption(QStyleOptionSlider*);

    void updateValue(QMouseEvent*);

private:
    bool m_bMousePress = false;
};

class UkBalanceVolumeSlider : public kdk::KSlider
{
    Q_OBJECT
public:
    UkBalanceVolumeSlider(QWidget* = nullptr);
    ~UkBalanceVolumeSlider();

protected:
    virtual bool eventFilter(QObject*, QEvent*) override;

private:
    void initStyleOption(QStyleOptionSlider*);

    void showTooltip();

};

#endif // UKUI4CUSTOMCONTROL_H
