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 ***************************************************************************/
24 #include <QKeySequence>
25 #include <QGraphicsPathItem>
26 #include <QPainterPath>
28 #include <QGraphicsLineItem>
29 #include <QGraphicsView>
31 #include <QGraphicsSceneMouseEvent>
34 #include <QHBoxLayout>
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>
55 struct Polygons::Private
57 YAMF::Item::Polygon
*item
;
61 QDoubleSpinBox
*start
;
62 QWidget
*configWidget
;
67 * Construye la herramienta para dibujar poligonos.
69 Polygons::Polygons(QObject
*parent
): AbstractTool(parent
), d(new Private
)
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
);
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
);
101 Polygons::~Polygons()
103 delete d
->configWidget
;
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);
130 * Retorna el id de la herramienta
132 QString
Polygons::id() const
134 return tr("Polygons");
139 * Función sobrecargada para implementar la creación de los poligonos.
141 void Polygons::press(const QGraphicsSceneMouseEvent
*input
, PaintArea
*const paintArea
)
143 if(input
->buttons() == Qt::LeftButton
)
145 d
->item
= new Item::Polygon(d
->corners
->value());
147 d
->item
->setPen( paintArea
->brushManager()->pen() );
148 d
->item
->setBrush( paintArea
->brushManager()->brush() );
149 d
->item
->setStart(d
->start
->value());
150 d
->position
= input
->scenePos();
151 paintArea
->currentFrame()->addItem(d
->item
);
157 * Función sobrecargada para implementar la creación de los poligonos.
159 void Polygons::move(const QGraphicsSceneMouseEvent
*input
, PaintArea
*const paintArea
)
161 if(input
->buttons() == Qt::LeftButton
)
163 QRectF
rect( d
->position
, d
->item
->mapFromScene(input
->scenePos()));
164 d
->item
->setRect(rect
);
169 * Función sobrecargada para implementar la creación de los poligonos.
171 void Polygons::release(const QGraphicsSceneMouseEvent
*input
, PaintArea
*const paintArea
)
177 * Retorna la acción que representa la herramienta.
179 DGui::Action
*Polygons::action() const
186 * Retorna que la herramienta es de tipo Brush.
188 int Polygons::type() const
190 return AbstractTool::Brush
;
193 void Polygons::aboutToChangeTool()
199 * Asigna la interfaz gráfica para configurar el numero de vertices del poligono y donde empieza.
201 void Polygons::setupConfigBar(QToolBar
*configBar
)
203 configBar
->addWidget(d
->configWidget
)->setVisible(true);
209 void Polygons::onChangeStart(double start
)
213 d
->item
->setStart(start
);