Warning, file /education/parley/src/practice/statustogglebutton.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2010 Daniel Laidig <laidig@kde.org> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #include "statustogglebutton.h" 0007 0008 #include <QMouseEvent> 0009 0010 using namespace Practice; 0011 0012 void StatusToggleButton::setPixmaps(const QPixmap &defaultPixmap, const QPixmap &hoverPixmap, const QPixmap &pressedPixmap) 0013 { 0014 if (m_current == 1) { 0015 setPixmap(hoverPixmap); 0016 } else { 0017 setPixmap(defaultPixmap); 0018 } 0019 m_defaultPixmap = defaultPixmap; 0020 m_hoverPixmap = hoverPixmap; 0021 m_pressedPixmap = pressedPixmap; 0022 } 0023 0024 void StatusToggleButton::mousePressEvent(QMouseEvent *e) 0025 { 0026 if (e->button() == Qt::LeftButton) { 0027 this->setFadingEnabled(false); 0028 setPixmap(m_pressedPixmap); 0029 } 0030 } 0031 0032 void StatusToggleButton::mouseReleaseEvent(QMouseEvent *e) 0033 { 0034 if (!m_defaultPixmap.isNull() && e->button() == Qt::LeftButton) { 0035 Q_EMIT clicked(); 0036 if (m_current == 1) { 0037 setPixmap(m_hoverPixmap); 0038 } else { 0039 setPixmap(m_defaultPixmap); 0040 } 0041 } 0042 this->setFadingEnabled(true); 0043 } 0044 0045 void StatusToggleButton::enterEvent(QEvent *) 0046 { 0047 m_current = 1; 0048 setPixmap(m_hoverPixmap); 0049 } 0050 0051 void StatusToggleButton::leaveEvent(QEvent *) 0052 { 0053 m_current = 0; 0054 setPixmap(m_defaultPixmap); 0055 }