1 /***************************************************************************
2 * Copyright (C) 2007 by Jorge Cuadrado *
3 * kuadrosxx@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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
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>
34 #include <QKeySequence>
36 #include <QGraphicsLineItem>
37 #include <QGraphicsView>
38 #include <QGraphicsRectItem>
39 #include <QGraphicsSceneMouseEvent>
50 QGraphicsRectItem
*rect
;
56 * Construye la herramienta.
58 Zoom::Zoom(QObject
*parent
) : AbstractTool(parent
), d(new Private
)
60 d
->action
= new DGui::Action( DGui::IconLoader::self()->load("page-magnifier.svg"), tr("Zoom"), this);
62 d
->rect
= new QGraphicsRectItem
;
63 d
->rect
->setZValue(110);
77 * Inicializa la herramienta, evita que los items dentro de el fotograma se puedan mover o seleccionar.
79 void Zoom::init(Photogram
*photogram
)
81 foreach(QGraphicsView
* view
, photogram
->views())
83 view
->setDragMode ( QGraphicsView::NoDrag
);
85 if ( QGraphicsScene
*photogram
= qobject_cast
<QGraphicsScene
*>(view
->scene()) )
87 foreach(QGraphicsItem
*item
, photogram
->items() )
89 item
->setFlag(QGraphicsItem::ItemIsSelectable
, false);
90 item
->setFlag(QGraphicsItem::ItemIsMovable
, false);
98 * Retorna el id de la herramienta.
100 QString
Zoom::id() const
107 * Función sobrecargada para habilitar la selección del area para ampliar.
109 void Zoom::press(const QGraphicsSceneMouseEvent
*input
)
111 PaintArea
*paintArea
= this->paintArea();
112 if(!paintArea
->scene()->items().contains(d
->rect
))
114 paintArea
->scene()->addItem(d
->rect
);
117 d
->rect
->setRect(QRectF(input
->scenePos(), QSizeF(0,0)));
123 * Función sobrecargada para habilitar la selección del area para ampliar.
125 void Zoom::move(const QGraphicsSceneMouseEvent
*input
)
127 PaintArea
*paintArea
= this->paintArea();
128 if ( input
->buttons() == Qt::LeftButton
)
130 paintArea
->setDragMode(QGraphicsView::NoDrag
);
132 QRectF rect
= d
->rect
->rect();
133 rect
.setBottomLeft(input
->scenePos());
134 d
->rect
->setRect(rect
);
136 rect
= rect
.normalized ();
137 if(rect
.height() > 10 && rect
.width() > 10 )
139 d
->rect
->setPen(QPen(Qt::black
, 2, Qt::DashLine
));
143 d
->rect
->setPen(QPen(Qt::red
, 2, Qt::DashLine
));
150 * Función sobrecargada para habilitar para ampliar el area seleccionada.
152 void Zoom::release(const QGraphicsSceneMouseEvent
*input
)
154 PaintArea
*paintArea
= this->paintArea();
155 QRectF rect
= d
->rect
->rect();
156 if ( input
->button() == Qt::LeftButton
)
158 if(rect
.normalized().height() > 10 && rect
.normalized().width() > 10 )
160 paintArea
->scene()->removeItem(d
->rect
);
161 paintArea
->fitInView( rect
, Qt::KeepAspectRatio
);
164 else if ( input
->button() == Qt::RightButton
)
166 QRectF visibleRect
= paintArea
->visibleRegion().boundingRect();
168 paintArea
->fitInView( visibleRect
.adjusted((rect
.width()+50), 0, 0, (rect
.height()+50)), Qt::KeepAspectRatio
);
174 * Retorna la acción que representa la herramienta.
176 DGui::Action
*Zoom::action() const
183 * Retorna que la herramienta es de tipo View.
185 int Zoom::type() const
187 return AbstractTool::View
;
190 void Zoom::aboutToChangeTool()
194 void Zoom::photogramChanged(Photogram
*const photogram
)