chalk

imageviewer.cpp
1/***************************************************************************
2 * Copyright (C) 2005 Eyal Lotem <eyal.lotem@gmail.com> *
3 * Copyright (C) 2005 Alexandre Oliveira <aleprj@gmail.com> *
4 * Copyright (C) 2006 Cyrille Berger <cberger@cberger.net> *
5 * *
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. *
10 * *
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. *
15 * *
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 "imageviewer.h"
22
23#include <tqlabel.h>
24#include <tqpainter.h>
25#include <tqimage.h>
26#include <tqcursor.h>
27
28#include <tdeapplication.h>
29#include <kdebug.h>
30#include <kis_cursor.h>
31
32ImageViewer::ImageViewer(TQWidget *widget, const char * name)
33 : TQScrollView(widget, name)
34 , m_isDragging(false)
35 , m_image(TQPixmap())
36{
37 m_label = new TQLabel( viewport());
38 setSizePolicy(TQSizePolicy::MinimumExpanding, TQSizePolicy::MinimumExpanding);
39 setCursor(KisCursor::handCursor());
40 addChild(m_label);
41}
42
43void ImageViewer::setImage(TQImage & image)
44{
45 m_image = TQPixmap(image);
46 m_label->setPixmap(m_image);
47 resizeContents( m_image.width(), m_image.height() );
48 repaintContents(false);
49}
50
51void ImageViewer::contentsMousePressEvent(TQMouseEvent *event)
52{
53 if(TQt::LeftButton == event->button()) {
54 setCursor(KisCursor::closedHandCursor());
55 m_currentPos = event->globalPos();
56 m_isDragging = true;
57 }
58}
59
60void ImageViewer::contentsMouseReleaseEvent(TQMouseEvent *event)
61{
62 if(TQt::LeftButton == event->button()) {
63 setCursor(KisCursor::handCursor());
64 m_currentPos = event->globalPos();
65 m_isDragging = false;
66 }
67}
68
69void ImageViewer::contentsMouseMoveEvent(TQMouseEvent *event)
70{
71 if(m_isDragging) {
72 TQPoint delta = m_currentPos - event->globalPos();
73 scrollBy(delta.x(), delta.y());
74 m_currentPos = event->globalPos();
75 }
76}
77
78#include "imageviewer.moc"