120 lines
3.9 KiB
C++
120 lines
3.9 KiB
C++
/****************************************************************************
|
|
** 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/>.
|
|
****************************************************************************/
|
|
|
|
#include "../headers/qmodernpushbutton.h"
|
|
|
|
QModernPushButton::QModernPushButton(QString icon, QWidget* parent) : QAbstractButton(parent)
|
|
{
|
|
this->setMouseTracking(true);
|
|
|
|
QStringList overlays;
|
|
overlays.append(icon);
|
|
overlays.append(":svgIcons/overlayHovered.svg");
|
|
overlays.append(":svgIcons/overlayPressed.svg");
|
|
overlays.append(":svgIcons/overlayChecked.svg");
|
|
|
|
for(QString overlayName : overlays) {
|
|
|
|
QSvgWidget* overlayWidget = new QSvgWidget(this);
|
|
overlayWidget->load(overlayName);
|
|
|
|
QModernPushButtonOverlay* overlay = new QModernPushButtonOverlay(overlayWidget, this);
|
|
this->overlays.append(overlay);
|
|
}
|
|
|
|
this->overlays[0]->setVisible(true);
|
|
this->overlays[1]->setAnimationDuration(200);
|
|
this->overlays[2]->setAnimationDuration(100);
|
|
|
|
connect(this, SIGNAL(toggled(bool)), this, SLOT(handleToggled(bool)));
|
|
}
|
|
|
|
void QModernPushButton::handleToggled(bool checked) {
|
|
if(this->overlays.length() >= 4)
|
|
this->overlays[3]->setVisible(checked);
|
|
}
|
|
|
|
void QModernPushButton::resizeEvent(QResizeEvent *event) {
|
|
// make border width match button size
|
|
//QFile file(":svgIcons/overlayNormal.svg");
|
|
//file.open(QFile::ReadOnly);
|
|
//QString overlayNormalString = file.readAll();
|
|
//overlayNormalString.replace("stroke-width:15px", "stroke-width:" + QString::number(500/event->size().width() * 5) + "px");
|
|
//this->overlayHoveredWidget->load(overlayNormalString.toUtf8());
|
|
|
|
for(QModernPushButtonOverlay* overlay : this->overlays) {
|
|
overlay->widget->setGeometry(QRect(0, 0, event->size().width(), event->size().height()));
|
|
}
|
|
}
|
|
|
|
void QModernPushButton::setVisible(bool visible, bool animated, bool asynchronos) {
|
|
if(this->isVisible() == visible)
|
|
return;
|
|
|
|
if(animated) {
|
|
this->overlays[0]->setVisible(visible);
|
|
}
|
|
else {
|
|
QWidget::setVisible(visible);
|
|
}
|
|
}
|
|
|
|
void QModernPushButton::setVisible(bool visible) {
|
|
QAbstractButton::setVisible(visible);
|
|
}
|
|
|
|
void QModernPushButton::paintEvent(QPaintEvent *e) {
|
|
QWidget::paintEvent(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) {
|
|
|
|
if(this->overlays.length() >= 2)
|
|
this->overlays[1]->setVisible(true);
|
|
return QAbstractButton::enterEvent(e);
|
|
}
|
|
|
|
void QModernPushButton::leaveEvent(QEvent *e) {
|
|
if(this->overlays.length() >= 2)
|
|
this->overlays[1]->setVisible(false);
|
|
return QAbstractButton::leaveEvent(e);
|
|
}
|
|
|
|
void QModernPushButton::mousePressEvent(QMouseEvent *e) {
|
|
if(this->overlays.length() >= 3)
|
|
this->overlays[2]->setVisible(true);
|
|
return QAbstractButton::mousePressEvent(e);
|
|
}
|
|
|
|
void QModernPushButton::mouseReleaseEvent(QMouseEvent *e) {
|
|
if(this->overlays.length() >= 3)
|
|
this->overlays[2]->setVisible(false);
|
|
return QAbstractButton::mouseReleaseEvent(e);
|
|
}
|