Fix list index out of bounds crash on loading of .pls playlists, thanks to Tim Beaule...
[amarok.git] / src / PixmapViewer.cpp
blob2f1920e90c8729827b78ec74302924f53acc527c
1 /***************************************************************************
2 * Copyright (C) 2005 Eyal Lotem <eyal.lotem@gmail.com> *
3 * Copyright (C) 2005 Alexandre Oliveira <aleprj@gmail.com> *
4 * Copyright (C) 2007 Seb Ruiz <ruiz@kde.org> *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20 ***************************************************************************/
21 #include "PixmapViewer.h"
22 #include "debug.h"
24 #include <KApplication>
26 #include <QDesktopWidget>
27 #include <QMouseEvent>
28 #include <QLabel>
29 #include <QPixmap>
30 #include <QScrollBar>
32 PixmapViewer::PixmapViewer( QWidget *widget, const QPixmap &pixmap )
33 : QScrollArea( widget )
34 , m_isDragging( false )
35 , m_pixmap( pixmap )
37 resize( m_pixmap.width(), m_pixmap.height() );
39 QLabel *imageLabel = new QLabel();
40 imageLabel->setBackgroundRole( QPalette::Base );
41 imageLabel->setScaledContents( true );
42 imageLabel->setPixmap( pixmap );
44 setBackgroundRole( QPalette::Dark );
45 setWidget( imageLabel );
48 void PixmapViewer::mousePressEvent(QMouseEvent *event)
50 if( Qt::LeftButton == event->button() )
52 m_currentPos = event->globalPos();
53 m_isDragging = true;
57 void PixmapViewer::mouseReleaseEvent(QMouseEvent *event)
59 if( Qt::LeftButton == event->button() )
61 m_currentPos = event->globalPos();
62 m_isDragging = false;
66 void PixmapViewer::mouseMoveEvent(QMouseEvent *event)
68 if( m_isDragging )
70 QPoint delta = m_currentPos - event->globalPos();
71 horizontalScrollBar()->setValue( horizontalScrollBar()->value() + delta.x() );
72 verticalScrollBar()->setValue( verticalScrollBar()->value() + delta.y() );
73 m_currentPos = event->globalPos();
77 QSize PixmapViewer::sizeHint() const
79 return size().boundedTo( KApplication::desktop()->size() );
82 #include "PixmapViewer.moc"