File indexing completed on 2025-01-19 04:24:07
0001 /**************************************************************************************** 0002 * Copyright (c) 2010 Daniel Faust <hessijames@gmail.com> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #include "LabelOverlayButton.h" 0018 0019 #include <KIconEffect> 0020 #include <KIconLoader> 0021 0022 #include <QPainter> 0023 0024 0025 LabelOverlayButton::LabelOverlayButton( QGraphicsItem *parent ) 0026 : QGraphicsItem( parent ), 0027 m_iconEffect( 0 ), 0028 m_size( 8 ) 0029 { 0030 setAcceptHoverEvents( true ); 0031 0032 m_iconEffect = new KIconEffect(); 0033 } 0034 0035 LabelOverlayButton::~LabelOverlayButton() 0036 { 0037 if( m_iconEffect ) 0038 delete m_iconEffect; 0039 } 0040 0041 void 0042 LabelOverlayButton::setPixmap( const QPixmap& pixmap ) 0043 { 0044 m_pixmap = pixmap; 0045 0046 if( isUnderMouse() ) 0047 m_scaledPixmap = m_iconEffect->apply( m_pixmap.scaledToHeight( m_size, Qt::SmoothTransformation ), KIconLoader::Desktop, KIconLoader::ActiveState ); 0048 else 0049 m_scaledPixmap = m_pixmap.scaledToHeight( m_size, Qt::SmoothTransformation ); 0050 } 0051 0052 QPixmap 0053 LabelOverlayButton::pixmap() 0054 { 0055 return m_pixmap; 0056 } 0057 0058 void 0059 LabelOverlayButton::setSize( int size ) 0060 { 0061 m_size = size; 0062 0063 if( isUnderMouse() ) 0064 m_scaledPixmap = m_iconEffect->apply( m_pixmap.scaledToHeight( m_size, Qt::SmoothTransformation ), KIconLoader::Desktop, KIconLoader::ActiveState ); 0065 else 0066 m_scaledPixmap = m_pixmap.scaledToHeight( m_size, Qt::SmoothTransformation ); 0067 } 0068 0069 int 0070 LabelOverlayButton::size() 0071 { 0072 return m_size; 0073 } 0074 0075 void 0076 LabelOverlayButton::updateHoverStatus() 0077 { 0078 if( isUnderMouse() ) 0079 m_scaledPixmap = m_iconEffect->apply( m_pixmap.scaledToHeight( m_size, Qt::SmoothTransformation ), KIconLoader::Desktop, KIconLoader::ActiveState ); 0080 else 0081 m_scaledPixmap = m_pixmap.scaledToHeight( m_size, Qt::SmoothTransformation ); 0082 } 0083 0084 void 0085 LabelOverlayButton::hoverEnterEvent( QGraphicsSceneHoverEvent *event ) 0086 { 0087 Q_UNUSED( event ) 0088 0089 m_scaledPixmap = m_iconEffect->apply( m_pixmap.scaledToHeight( m_size, Qt::SmoothTransformation ), KIconLoader::Desktop, KIconLoader::ActiveState ); 0090 update(); 0091 } 0092 0093 void 0094 LabelOverlayButton::hoverLeaveEvent( QGraphicsSceneHoverEvent *event ) 0095 { 0096 Q_UNUSED( event ) 0097 0098 m_scaledPixmap = m_pixmap.scaledToHeight( m_size, Qt::SmoothTransformation ); 0099 update(); 0100 } 0101 0102 QRectF 0103 LabelOverlayButton::boundingRect() const 0104 { 0105 return QRectF( QPointF( 0, 0 ), m_scaledPixmap.size() ); 0106 } 0107 0108 void 0109 LabelOverlayButton::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ) 0110 { 0111 Q_UNUSED( option ) 0112 Q_UNUSED( widget ) 0113 0114 painter->drawPixmap( 0, 0, m_scaledPixmap ); 0115 }