File indexing completed on 2024-05-05 03:50:46
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2013 Mohammed Nafees <nafees.technocool@gmail.com> 0004 // 0005 0006 #include "NavigationButton.h" 0007 0008 #include <QPainter> 0009 #include <QMouseEvent> 0010 0011 namespace Marble 0012 { 0013 0014 NavigationButton::NavigationButton( QWidget *parent ) 0015 : QAbstractButton( parent ), 0016 m_iconMode( QIcon::Normal ) 0017 { 0018 // nothing to do 0019 } 0020 0021 void NavigationButton::mousePressEvent ( QMouseEvent *mouseEvent ) 0022 { 0023 if ( isEnabled() ) { 0024 if ( mouseEvent->button() == Qt::LeftButton ) { 0025 m_iconMode = QIcon::Selected; 0026 } 0027 } 0028 emit repaintNeeded(); 0029 } 0030 0031 void NavigationButton::mouseReleaseEvent ( QMouseEvent * ) 0032 { 0033 if ( isEnabled() ) { 0034 m_iconMode = QIcon::Active; 0035 emit clicked(); 0036 } 0037 emit repaintNeeded(); 0038 } 0039 0040 void NavigationButton::enterEvent(QEvent *) 0041 { 0042 if ( isEnabled() ) { 0043 m_iconMode = QIcon::Active; 0044 } 0045 emit repaintNeeded(); 0046 } 0047 0048 void NavigationButton::leaveEvent( QEvent * ) 0049 { 0050 if ( isEnabled() ) { 0051 m_iconMode = QIcon::Normal; 0052 } 0053 emit repaintNeeded(); 0054 } 0055 0056 void NavigationButton::changeEvent( QEvent *e ) 0057 { 0058 if ( e->type() == QEvent::EnabledChange ) { 0059 m_iconMode = isEnabled() ? QIcon::Normal : QIcon::Disabled; 0060 } 0061 emit repaintNeeded(); 0062 } 0063 0064 void NavigationButton::paintEvent( QPaintEvent * ) 0065 { 0066 QPainter painter( this ); 0067 painter.drawPixmap( 0, 0, icon().pixmap( iconSize(), m_iconMode ) ); 0068 } 0069 0070 } 0071 0072 #include "moc_NavigationButton.cpp"