2020-11-16 18:01:03 +01:00
|
|
|
/****************************************************************************
|
|
|
|
** Modern Linbo GUI
|
|
|
|
** Copyright (C) 2020 Dorian Zedler <dorian@itsblue.de>
|
|
|
|
**
|
|
|
|
** This program is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU Affero General Public License
|
|
|
|
** along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-11-16 00:31:28 +01:00
|
|
|
#include "../headers/qmodernpushbutton.h"
|
|
|
|
|
2020-11-16 18:01:03 +01:00
|
|
|
QModernPushButton::QModernPushButton(QString icon, QWidget* parent) : QAbstractButton(parent)
|
2020-11-16 00:31:28 +01:00
|
|
|
{
|
|
|
|
this->svgWidget = new QSvgWidget(this);
|
|
|
|
this->svgWidget->load(QString(icon));
|
2020-11-16 18:01:03 +01:00
|
|
|
this->setMouseTracking(true);
|
|
|
|
|
|
|
|
this->overlayHoveredWidget = new QSvgWidget(this->svgWidget);
|
|
|
|
this->overlayHoveredEffect = new QGraphicsOpacityEffect(this);
|
|
|
|
this->overlayHoveredEffect->setOpacity(0);
|
|
|
|
this->overlayHoveredWidget->setGraphicsEffect(this->overlayHoveredEffect);
|
2020-11-16 00:31:28 +01:00
|
|
|
|
2020-11-16 18:01:03 +01:00
|
|
|
this->overlayPressedWidget = new QSvgWidget(this->svgWidget);
|
|
|
|
this->overlayPressedWidget->load(QString(":svgIcons/overlayPressed.svg"));
|
|
|
|
this->overlayPressedEffect = new QGraphicsOpacityEffect(this);
|
|
|
|
this->overlayPressedEffect->setOpacity(0);
|
|
|
|
this->overlayPressedWidget->setGraphicsEffect(this->overlayPressedEffect);
|
2020-11-16 00:31:28 +01:00
|
|
|
|
|
|
|
this->overlayCheckedWidget = new QSvgWidget(this->svgWidget);
|
|
|
|
this->overlayCheckedWidget->load(QString(":svgIcons/overlayChecked.svg"));
|
|
|
|
this->overlayCheckedEffect = new QGraphicsOpacityEffect(this);
|
|
|
|
this->overlayCheckedEffect->setOpacity(0);
|
|
|
|
this->overlayCheckedWidget->setGraphicsEffect(this->overlayCheckedEffect);
|
|
|
|
|
|
|
|
connect(this, SIGNAL(toggled(bool)), this, SLOT(handleToggled(bool)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void QModernPushButton::handleToggled(bool checked) {
|
|
|
|
int startValue = 1;
|
|
|
|
if(checked) {
|
|
|
|
startValue = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPropertyAnimation *animation = new QPropertyAnimation(this->overlayCheckedEffect, "opacity");
|
|
|
|
animation->setDuration(400);
|
|
|
|
animation->setStartValue(startValue);
|
|
|
|
animation->setEndValue(1-startValue);
|
|
|
|
animation->setEasingCurve(QEasingCurve(QEasingCurve::InOutQuad));
|
|
|
|
animation->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QModernPushButton::resizeEvent(QResizeEvent *event) {
|
|
|
|
this->svgWidget->setGeometry(QRect(0, 0, event->size().width(), event->size().height()));
|
|
|
|
|
|
|
|
// make border width match button size
|
|
|
|
QFile file(":svgIcons/overlayNormal.svg");
|
|
|
|
file.open(QFile::ReadOnly);
|
|
|
|
QString overlayNormalString = file.readAll();
|
2020-11-16 18:01:03 +01:00
|
|
|
//overlayNormalString.replace("stroke-width:15px", "stroke-width:" + QString::number(500/event->size().width() * 5) + "px");
|
|
|
|
this->overlayHoveredWidget->load(overlayNormalString.toUtf8());
|
|
|
|
this->overlayHoveredWidget->setGeometry(QRect(0, 0, event->size().width(), event->size().height()));
|
2020-11-16 00:31:28 +01:00
|
|
|
|
|
|
|
this->overlayCheckedWidget->setGeometry(QRect(0, 0, event->size().width(), event->size().height()));
|
|
|
|
}
|
2020-11-16 18:01:03 +01:00
|
|
|
|
|
|
|
void QModernPushButton::paintEvent(QPaintEvent *e) {
|
|
|
|
Q_UNUSED(e)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QModernPushButton::keyPressEvent(QKeyEvent *e) {
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
return QAbstractButton::keyPressEvent(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QModernPushButton::keyReleaseEvent(QKeyEvent *e) {
|
|
|
|
// TODO
|
|
|
|
return QAbstractButton::keyReleaseEvent(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QModernPushButton::enterEvent(QEvent *e) {
|
|
|
|
this->overlayHoveredEffect->setOpacity(1);
|
|
|
|
return QAbstractButton::enterEvent(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QModernPushButton::leaveEvent(QEvent *e) {
|
|
|
|
this->overlayHoveredEffect->setOpacity(0);
|
|
|
|
return QAbstractButton::leaveEvent(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QModernPushButton::mousePressEvent(QMouseEvent *e) {
|
|
|
|
this->overlayPressedEffect->setOpacity(1);
|
|
|
|
return QAbstractButton::mousePressEvent(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QModernPushButton::mouseReleaseEvent(QMouseEvent *e) {
|
|
|
|
this->overlayPressedEffect->setOpacity(0);
|
|
|
|
return QAbstractButton::mouseReleaseEvent(e);
|
|
|
|
}
|