krita

imageviewer.cc

00001 /***************************************************************************
00002  *   Copyright (C) 2005 Eyal Lotem <eyal.lotem@gmail.com>                  *
00003  *   Copyright (C) 2005 Alexandre Oliveira <aleprj@gmail.com>              *
00004  *   Copyright (C) 2006 Cyrille Berger <cberger@cberger.net>               *
00005  *                                                                         *
00006  *   This program is free software; you can redistribute it and/or modify  *
00007  *   it under the terms of the GNU General Public License as published by  *
00008  *   the Free Software Foundation; either version 2 of the License, or     *
00009  *   (at your option) any later version.                                   *
00010  *                                                                         *
00011  *   This program is distributed in the hope that it will be useful,       *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU General Public License for more details.                          *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU General Public License     *
00017  *   along with this program; if not, write to the                         *
00018  *   Free Software Foundation, Inc.,                                       *
00019  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.          *
00020  ***************************************************************************/
00021 #include "imageviewer.h"
00022 
00023 #include <qlabel.h>
00024 #include <qpainter.h>
00025 #include <qimage.h>
00026 #include <qcursor.h>
00027 
00028 #include <kapplication.h>
00029 #include <kdebug.h>
00030 #include <kis_cursor.h>
00031 
00032 ImageViewer::ImageViewer(QWidget *widget, const char * name)
00033     : QScrollView(widget, name)
00034     , m_isDragging(false)
00035     , m_image(QPixmap())
00036 {
00037     m_label = new QLabel( viewport());
00038     setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
00039     setCursor(KisCursor::handCursor());
00040     addChild(m_label);
00041 }
00042 
00043 void ImageViewer::setImage(QImage & image)
00044 {
00045     m_image = QPixmap(image);
00046     m_label->setPixmap(m_image);
00047     resizeContents( m_image.width(), m_image.height() );
00048     repaintContents(false);
00049 }
00050 
00051 void ImageViewer::contentsMousePressEvent(QMouseEvent *event)
00052 {
00053     if(LeftButton == event->button()) {
00054         setCursor(KisCursor::closedHandCursor());
00055         m_currentPos = event->globalPos();
00056         m_isDragging = true;
00057     }
00058 }
00059 
00060 void ImageViewer::contentsMouseReleaseEvent(QMouseEvent *event)
00061 {
00062     if(LeftButton == event->button()) {
00063         setCursor(KisCursor::handCursor());
00064         m_currentPos = event->globalPos();
00065         m_isDragging = false;
00066     }
00067 }
00068 
00069 void ImageViewer::contentsMouseMoveEvent(QMouseEvent *event)
00070 {
00071     if(m_isDragging) {
00072         QPoint delta = m_currentPos - event->globalPos();
00073         scrollBy(delta.x(), delta.y());
00074         m_currentPos = event->globalPos();
00075     }
00076 }
00077 
00078 #include "imageviewer.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys