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 Steet, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
20 #include "pixmapviewer.h"
21 #include <kapplication.h>
25 #include <QMouseEvent>
26 #include <QDesktopWidget>
28 PixmapViewer::PixmapViewer(QWidget
*widget
, const QPixmap
&pixmap
)
29 : Q3ScrollView(widget
, 0, Qt::WNoAutoErase
)
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
),
39 QRect(clipx
, clipy
, clipw
, cliph
));
42 void PixmapViewer::contentsMousePressEvent(QMouseEvent
*event
) {
43 if(Qt::LeftButton
== event
->button()) {
44 m_currentPos
= event
->globalPos();
49 void PixmapViewer::contentsMouseReleaseEvent(QMouseEvent
*event
) {
50 if(Qt::LeftButton
== event
->button()) {
51 m_currentPos
= event
->globalPos();
56 void PixmapViewer::contentsMouseMoveEvent(QMouseEvent
*event
) {
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"