implemented tools: Zoom and Hand
[yamf.git] / yamf / tools / view / zoom.cpp
blob6d0666835c85356d8253ec8e1cc46d676b33eeda
1 /***************************************************************************
2 * Copyright (C) 2007 by Jorge Cuadrado *
3 * kuadrosxx@gmail.com *
4 * *
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. *
9 * *
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. *
14 * *
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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "zoom.h"
23 #include <drawing/photogram.h>
24 #include <drawing/brushmanager.h>
25 #include <drawing/paintarea.h>
26 #include <model/frame.h>
28 #include <dgui/action.h>
29 #include <dgui/iconloader.h>
30 #include <dcore/debug.h>
32 #include <QPointF>
33 #include <QIcon>
34 #include <QKeySequence>
35 #include <QMatrix>
36 #include <QGraphicsLineItem>
37 #include <QGraphicsView>
38 #include <QGraphicsRectItem>
39 #include <QGraphicsSceneMouseEvent>
42 namespace YAMF {
44 namespace Drawing {
46 namespace Tool {
48 struct Zoom::Private
50 QGraphicsRectItem *rect;
51 DGui::Action *action;
54 Zoom::Zoom(QObject *parent) : AbstractTool(parent), d(new Private)
56 d->action = new DGui::Action( DGui::IconLoader::self()->load("system-search.svg"), tr("Zoom"), this);
58 d->rect = new QGraphicsRectItem;
62 Zoom::~Zoom()
64 delete d;
68 void Zoom::init(Photogram *photogram)
73 QString Zoom::id() const
75 return tr("Zoom");
78 void Zoom::press(const QGraphicsSceneMouseEvent *input, PaintArea *const paintArea)
80 if(!paintArea->scene()->items().contains(d->rect))
82 paintArea->scene()->addItem(d->rect);
85 d->rect->setRect(QRectF(input->scenePos(), QSizeF(0,0)));
89 void Zoom::move(const QGraphicsSceneMouseEvent *input, PaintArea *const paintArea)
91 if ( input->buttons() == Qt::LeftButton )
93 paintArea->setDragMode(QGraphicsView::NoDrag);
95 QRectF rect = d->rect->rect();
96 rect.setBottomLeft(input->scenePos());
97 d->rect->setRect(rect);
99 rect = rect.normalized ();
100 if(rect.height() > 10 && rect.width() > 10 )
102 d->rect->setPen(QPen(Qt::black, 2, Qt::DashLine));
104 else
106 d->rect->setPen(QPen(Qt::red, 2, Qt::DashLine));
111 void Zoom::release(const QGraphicsSceneMouseEvent *input, PaintArea *const paintArea)
113 QRectF rect = d->rect->rect();
114 if ( input->button() == Qt::LeftButton )
116 if(rect.normalized().height() > 10 && rect.normalized().width() > 10 )
118 paintArea->scene()->removeItem(d->rect);
119 paintArea->fitInView( rect, Qt::KeepAspectRatio);
122 else if ( input->button() == Qt::RightButton )
124 QRectF visibleRect = paintArea->visibleRegion().boundingRect();
126 paintArea->fitInView( visibleRect.adjusted((rect.width()+50), 0, 0, (rect.height()+50)), Qt::KeepAspectRatio );
130 DGui::Action *Zoom::action() const
132 return d->action;
135 int Zoom::type() const
137 return AbstractTool::View;
140 void Zoom::aboutToChangeTool()
144 void Zoom::photogramChanged(Photogram *const photogram)