mirror of
https://github.com/obsproject/obs-studio.git
synced 2026-08-28 17:42:28 +08:00
e8f6143769
Co-Authored-By: derrod <rodney@rodney.io>
122 lines
3.3 KiB
C++
122 lines
3.3 KiB
C++
/******************************************************************************
|
|
Copyright (C) 2023 by Dennis Sädtler <dennis@obsproject.com>
|
|
|
|
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 2 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 <http://www.gnu.org/licenses/>.
|
|
******************************************************************************/
|
|
|
|
#pragma once
|
|
|
|
#include <QWidget>
|
|
#include <QEvent>
|
|
#include <QBrush>
|
|
#include <QPropertyAnimation>
|
|
#include <QPainter>
|
|
#include <QMouseEvent>
|
|
#include <QAbstractButton>
|
|
#include <QStyleOptionButton>
|
|
#include <QAccessibleWidget>
|
|
|
|
#include "OBSIdianWidget.hpp"
|
|
|
|
class OBSToggleSwitch : public QAbstractButton, public OBSIdianUtils {
|
|
Q_OBJECT
|
|
Q_PROPERTY(int xpos MEMBER xPos WRITE setPos)
|
|
Q_PROPERTY(QColor background MEMBER backgroundInactive DESIGNABLE true)
|
|
Q_PROPERTY(QColor background_hover MEMBER backgroundInactiveHover DESIGNABLE true)
|
|
Q_PROPERTY(QColor background_checked MEMBER backgroundActive DESIGNABLE true)
|
|
Q_PROPERTY(QColor background_checked_hover MEMBER backgroundActiveHover DESIGNABLE true)
|
|
Q_PROPERTY(QColor handleColor MEMBER handleColor DESIGNABLE true)
|
|
Q_PROPERTY(int handleSize MEMBER handleSize DESIGNABLE true)
|
|
Q_PROPERTY(float blend MEMBER blend WRITE setBlend DESIGNABLE false)
|
|
|
|
public:
|
|
OBSToggleSwitch(QWidget *parent = nullptr);
|
|
OBSToggleSwitch(bool defaultState, QWidget *parent = nullptr);
|
|
|
|
QSize sizeHint() const override;
|
|
|
|
void setPos(int x)
|
|
{
|
|
xPos = x;
|
|
update();
|
|
}
|
|
|
|
void setBlend(float newBlend)
|
|
{
|
|
blend = newBlend;
|
|
update();
|
|
}
|
|
|
|
void setDelayed(bool state);
|
|
bool isDelayed() { return delayed; }
|
|
|
|
void setStatus(bool status);
|
|
void setPending(bool pending);
|
|
|
|
public slots:
|
|
void click();
|
|
|
|
signals:
|
|
void pendingChecked();
|
|
void pendingUnchecked();
|
|
|
|
protected:
|
|
void changeEvent(QEvent *event) override;
|
|
void paintEvent(QPaintEvent *) override;
|
|
void showEvent(QShowEvent *) override;
|
|
void enterEvent(QEnterEvent *) override;
|
|
void leaveEvent(QEvent *) override;
|
|
void keyReleaseEvent(QKeyEvent *) override;
|
|
void mouseReleaseEvent(QMouseEvent *) override;
|
|
|
|
void focusInEvent(QFocusEvent *e) override
|
|
{
|
|
OBSIdianUtils::showKeyFocused(e);
|
|
QAbstractButton::focusInEvent(e);
|
|
}
|
|
|
|
void focusOutEvent(QFocusEvent *e) override
|
|
{
|
|
OBSIdianUtils::hideKeyFocused(e);
|
|
QAbstractButton::focusOutEvent(e);
|
|
}
|
|
|
|
private slots:
|
|
void onClicked(bool checked);
|
|
|
|
private:
|
|
int xPos;
|
|
int onPos;
|
|
int offPos;
|
|
int margin;
|
|
|
|
float blend = 0.0f;
|
|
|
|
bool delayed = false;
|
|
bool pendingStatus = false;
|
|
|
|
void animateHandlePosition();
|
|
|
|
void updateBackgroundColor();
|
|
QColor backgroundInactive;
|
|
QColor backgroundInactiveHover;
|
|
QColor backgroundActive;
|
|
QColor backgroundActiveHover;
|
|
QColor handleColor;
|
|
int handleSize = 18;
|
|
|
|
QPropertyAnimation *animHandle = nullptr;
|
|
QPropertyAnimation *animBgColor = nullptr;
|
|
};
|