1 /***************************************************************************
2 * Copyright (C) 2005 Eyal Lotem <eyal.lotem@gmail.com> *
3 * Copyright (C) 2005 Alexandre Oliveira <aleprj@gmail.com> *
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. *
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. *
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 Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
20 #include "pixmapviewer.h"
22 #include <KApplication>
24 #include <QDesktopWidget>
25 #include <QMouseEvent>
30 PixmapViewer::PixmapViewer(QWidget
*widget
, const QPixmap
&pixmap
)
31 : Q3ScrollView(widget
, 0, Qt::WNoAutoErase
)
35 resizeContents( m_pixmap
.width(), m_pixmap
.height() );
38 void PixmapViewer::drawContents( QPainter
* p
, int clipx
, int clipy
, int clipw
, int cliph
) {
39 p
->drawPixmap(QPoint(clipx
, clipy
),
41 QRect(clipx
, clipy
, clipw
, cliph
));
44 void PixmapViewer::contentsMousePressEvent(QMouseEvent
*event
) {
45 if(Qt::LeftButton
== event
->button()) {
46 m_currentPos
= event
->globalPos();
51 void PixmapViewer::contentsMouseReleaseEvent(QMouseEvent
*event
) {
52 if(Qt::LeftButton
== event
->button()) {
53 m_currentPos
= event
->globalPos();
58 void PixmapViewer::contentsMouseMoveEvent(QMouseEvent
*event
) {
60 QPoint delta
= m_currentPos
- event
->globalPos();
61 scrollBy(delta
.x(), delta
.y());
62 m_currentPos
= event
->globalPos();
66 QSize
PixmapViewer::maximalSize() {
67 return m_pixmap
.size().boundedTo( KApplication::desktop()->size() ) + size() - viewport()->size();
70 #include "pixmapviewer.moc"