Not crap after all...
[amarok.git] / src / pixmapviewer.cpp
blob19c97cee384c54c0d30c977acac2ed8d109ebc5d
1 /***************************************************************************
2 * Copyright (C) 2005 Eyal Lotem <eyal.lotem@gmail.com> *
3 * Copyright (C) 2005 Alexandre Oliveira <aleprj@gmail.com> *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
20 #include "pixmapviewer.h"
21 #include <kapplication.h>
22 #include <QPainter>
23 #include <QPixmap>
24 //Added by qt3to4:
25 #include <QMouseEvent>
26 #include <QDesktopWidget>
28 PixmapViewer::PixmapViewer(QWidget *widget, const QPixmap &pixmap)
29 : Q3ScrollView(widget, 0, Qt::WNoAutoErase)
30 , m_isDragging(false)
31 , m_pixmap(pixmap)
33 resizeContents( m_pixmap.width(), m_pixmap.height() );
36 void PixmapViewer::drawContents( QPainter * p, int clipx, int clipy, int clipw, int cliph ) {
37 p->drawPixmap(QPoint(clipx, clipy),
38 m_pixmap,
39 QRect(clipx, clipy, clipw, cliph));
42 void PixmapViewer::contentsMousePressEvent(QMouseEvent *event) {
43 if(Qt::LeftButton == event->button()) {
44 m_currentPos = event->globalPos();
45 m_isDragging = true;
49 void PixmapViewer::contentsMouseReleaseEvent(QMouseEvent *event) {
50 if(Qt::LeftButton == event->button()) {
51 m_currentPos = event->globalPos();
52 m_isDragging = false;
56 void PixmapViewer::contentsMouseMoveEvent(QMouseEvent *event) {
57 if(m_isDragging) {
58 QPoint delta = m_currentPos - event->globalPos();
59 scrollBy(delta.x(), delta.y());
60 m_currentPos = event->globalPos();
64 QSize PixmapViewer::maximalSize() {
65 return m_pixmap.size().boundedTo( KApplication::desktop()->size() ) + size() - viewport()->size();
68 #include "pixmapviewer.moc"