modify abstracttool iface
[yamf.git] / yamf / tools / polygons / polygons.cpp
blob725a80b2a92960d839479996157766132b1fffc6
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 "polygons.h"
23 #include <QPointF>
24 #include <QKeySequence>
25 #include <QGraphicsPathItem>
26 #include <QPainterPath>
27 #include <QMatrix>
28 #include <QGraphicsLineItem>
29 #include <QGraphicsView>
31 #include <QGraphicsSceneMouseEvent>
32 #include <QToolBar>
34 #include <QHBoxLayout>
35 #include <QSpinBox>
36 #include <QLabel>
37 #include <dgraphics/algorithm.h>
38 #include <dcore/algorithm.h>
39 #include <dcore/debug.h>
40 #include <dgui/action.h>
41 #include <dgui/iconloader.h>
43 #include <drawing/photogram.h>
44 #include <drawing/brushmanager.h>
45 #include <drawing/paintarea.h>
47 #include <model/frame.h>
48 #include <yamf/item/polygon.h>
51 namespace YAMF {
52 namespace Drawing {
53 namespace Tool {
55 struct Polygons::Private
57 YAMF::Item::Polygon *item;
58 DGui::Action *action;
59 QPointF position;
60 QSpinBox *corners;
61 QDoubleSpinBox *start;
62 QWidget *configWidget;
65 /**
66 * @~spanish
67 * Construye la herramienta para dibujar poligonos.
69 Polygons::Polygons(QObject *parent ): AbstractTool(parent), d(new Private)
71 d->item = 0;
72 d->action = new DGui::Action( DGui::IconLoader::self()->load("draw-polygon.svg"), tr("Polygon"), this);
74 d->corners = new QSpinBox;
75 d->corners->setValue(3);
77 d->start = new QDoubleSpinBox;
78 d->start->setValue(0.0);
79 d->start->setMaximum(1.0);
80 d->start->setSingleStep(0.01);
82 connect(d->start, SIGNAL(valueChanged(double)), this, SLOT(onChangeStart(double)));
84 d->configWidget = new QWidget;
85 QHBoxLayout *layout = new QHBoxLayout(d->configWidget);
86 layout->setMargin(0);
87 layout->setSpacing(2);
89 layout->addWidget(new QLabel(tr("Corners")));
90 layout->addWidget(d->corners);
92 layout->addWidget(new QLabel(tr("Start")));
93 layout->addWidget(d->start);
97 /**
98 * @~spanish
99 * Destructor
101 Polygons::~Polygons()
103 delete d->configWidget;
104 delete d;
108 * @~spanish
109 * Inicializa la herramienta, evita que los items dentro de el fotograma se puedan mover o seleccionar.
111 void Polygons::init(Photogram *photogram)
113 foreach(QGraphicsView * view, photogram->views())
115 view->setDragMode ( QGraphicsView::NoDrag );
117 if ( QGraphicsScene *photogram = qobject_cast<QGraphicsScene *>(view->scene()) )
119 foreach(QGraphicsItem *item, photogram->items() )
121 item->setFlag(QGraphicsItem::ItemIsSelectable, false);
122 item->setFlag(QGraphicsItem::ItemIsMovable, false);
129 * @~spanish
130 * Retorna el id de la herramienta
132 QString Polygons::id() const
134 return tr("Polygons");
138 * @~spanish
139 * Función sobrecargada para implementar la creación de los poligonos.
141 void Polygons::press(const QGraphicsSceneMouseEvent *input)
143 PaintArea *paintArea = this->paintArea();
144 if(input->buttons() == Qt::LeftButton)
146 d->item = new Item::Polygon(d->corners->value());
148 d->item->setPen( paintArea->brushManager()->pen() );
149 d->item->setBrush( paintArea->brushManager()->brush() );
150 d->item->setStart(d->start->value());
151 d->position = input->scenePos();
152 paintArea->currentFrame()->addItem(d->item);
157 * @~spanish
158 * Función sobrecargada para implementar la creación de los poligonos.
160 void Polygons::move(const QGraphicsSceneMouseEvent *input)
162 if(input->buttons() == Qt::LeftButton)
164 QRectF rect( d->position, d->item->mapFromScene(input->scenePos()));
165 d->item->setRect(rect);
169 * @~spanish
170 * Función sobrecargada para implementar la creación de los poligonos.
172 void Polygons::release(const QGraphicsSceneMouseEvent *input)
177 * @~spanish
178 * Retorna la acción que representa la herramienta.
180 DGui::Action *Polygons::action() const
182 return d->action;
186 * @~spanish
187 * Retorna que la herramienta es de tipo Brush.
189 int Polygons::type() const
191 return AbstractTool::Brush;
194 void Polygons::aboutToChangeTool()
199 * @~spanish
200 * Asigna la interfaz gráfica para configurar el numero de vertices del poligono y donde empieza.
202 void Polygons::setupConfigBar(QToolBar *configBar)
204 configBar->addWidget(d->configWidget)->setVisible(true);
208 * @internal
210 void Polygons::onChangeStart(double start)
212 if(d->item)
214 d->item->setStart(start);