File indexing completed on 2024-12-22 04:39:54

0001 /***************************************************************************
0002  *   Copyright (C) 2005-2008 by Bjoern Erik Nilsen & Fredrik Berg Kjoelstad*
0003  *   bjoern.nilsen@bjoernen.com & fredrikbk@hotmail.com                    *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0019  ***************************************************************************/
0020 #include "scenearrowbutton.h"
0021 
0022 #include "graphics/icons/openscene.xpm"
0023 #include "graphics/icons/closescene.xpm"
0024 
0025 #include <QPainter>
0026 #include <QImage>
0027 #include <QPixmap>
0028 #include <QMouseEvent>
0029 #include <QEvent>
0030 #include <QPaintEvent>
0031 
0032 
0033 SceneArrowButton::SceneArrowButton( QWidget *parent ) : QWidget(parent)
0034 {
0035     this->isOpened = false;
0036     this->iconX = 2;
0037     moveTimer = new QTimer(this);
0038     QObject::connect( moveTimer, SIGNAL(timeout()), this, SLOT(moveIcon()) );
0039 }
0040 
0041 
0042 void SceneArrowButton::setOpened(bool isOpened)
0043 {
0044     this->isOpened = isOpened;
0045     update();
0046 }
0047 
0048 
0049 void SceneArrowButton::paintEvent( QPaintEvent * )
0050 {
0051     QPainter paint( this );
0052     paint.setPen(Qt::gray);
0053     paint.drawRect(0, 0, width(), height());
0054     
0055     QPixmap arrowIcon;
0056     if (isOpened) {
0057         arrowIcon = QPixmap::fromImage( QImage(closescene).scaled(width(), height()) );
0058     }
0059     else {
0060         arrowIcon = QPixmap::fromImage( QImage(openscene).scaled(width(), height()) );
0061     }
0062     paint.drawPixmap(iconX, 0, arrowIcon);
0063 }
0064 
0065 
0066 void SceneArrowButton::moveIcon()
0067 {
0068     this->iconX = (iconX == 0) ? 2 : 0;
0069     update();
0070 }
0071 
0072 
0073 void SceneArrowButton::mouseReleaseEvent( QMouseEvent * e )
0074 {
0075     if (isOpened) {
0076         emit clicked();
0077         moveTimer->stop();
0078         this->iconX = 2;
0079         update();
0080     }
0081     else {
0082         e->ignore();
0083     }
0084 }
0085 
0086 
0087 void SceneArrowButton::enterEvent( QEvent * )
0088 {
0089     if (isOpened) {
0090         moveTimer->start(400);
0091         moveTimer->setSingleShot(false);
0092     }
0093 }
0094 
0095 
0096 void SceneArrowButton::leaveEvent( QEvent * )
0097 {
0098     moveTimer->stop();
0099     this->iconX = 2;
0100     update();
0101 }