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> *
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. *
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. *
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"
24 #include <KApplication>
26 #include <QDesktopWidget>
27 #include <QMouseEvent>
32 PixmapViewer::PixmapViewer( QWidget
*widget
, const QPixmap
&pixmap
)
33 : QScrollArea( widget
)
34 , m_isDragging( false )
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();
57 void PixmapViewer::mouseReleaseEvent(QMouseEvent
*event
)
59 if( Qt::LeftButton
== event
->button() )
61 m_currentPos
= event
->globalPos();
66 void PixmapViewer::mouseMoveEvent(QMouseEvent
*event
)
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"