modify abstracttool iface
[yamf.git] / yamf / tools / colorpicker / colorpicker.cpp
blob0db3202a249ea298f269946535497dd89e02d135
1 /***************************************************************************
2 * Copyright (C) 2007 Jorge Cuadrado *
3 * kuadrosxx@gmail.com *
4 * *
5 * This library is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU Lesser General Public *
7 * License as published by the Free Software Foundation; either *
8 * version 2.1 of the License, or (at your option) any later version. *
9 * *
10 * This library 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 GNU *
13 * Lesser General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU Lesser General Public *
16 * License along with this library; if not, write to the Free Software *
17 * Foundation, Inc., *
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
21 #include "colorpicker.h"
23 #include <QPointF>
24 #include <QKeySequence>
25 #include <QPainterPath>
26 #include <QMatrix>
27 #include <QGraphicsView>
28 #include <QGraphicsSceneMouseEvent>
29 #include <QToolBar>
30 #include <QHBoxLayout>
31 #include <QSpinBox>
32 #include <QLabel>
34 #include <QImage>
36 #include <QGraphicsItem>
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>
49 namespace YAMF {
51 namespace Drawing {
53 namespace Tool {
55 struct ColorPicker::Private
57 DGui::Action *action;
59 QImage image;
62 /**
63 * Construye la herramienta.
65 ColorPicker::ColorPicker(QObject *parent) : Drawing::AbstractTool(parent), d(new Private)
67 d->action = new DGui::Action( DGui::IconLoader::self()->load("color-picker.svg"), tr("Color Picker"), this);
71 /**
72 * Destructor.
74 ColorPicker::~ColorPicker()
76 delete d;
79 /**
80 * @~spanish
81 * Inicializa la herramienta, evita que los items dentro de el fotograma se puedan mover o seleccionar
83 void ColorPicker::init(Photogram *photogram)
85 foreach(QGraphicsView * view, photogram->views())
87 view->setDragMode ( QGraphicsView::NoDrag );
89 if ( QGraphicsScene *photogram = qobject_cast<QGraphicsScene *>(view->scene()) )
91 foreach(QGraphicsItem *item, photogram->items() )
93 item->setFlag(QGraphicsItem::ItemIsSelectable, false);
94 item->setFlag(QGraphicsItem::ItemIsMovable, false);
103 * @~spanish
104 * Retorna el id de la herramienta
106 QString ColorPicker::id() const
108 return tr("ColorPicker");
112 * @~spanish
113 * Función sobrecargada para implementar la selección del color.
115 void ColorPicker::press(const QGraphicsSceneMouseEvent *input)
117 PaintArea *paintArea = this->paintArea();
118 QRectF rect = paintArea->photogram()->sceneRect();
119 d->image = QImage( rect.size().toSize(), QImage::Format_ARGB32_Premultiplied );
120 d->image.fill(0);
121 QPainter painter(&d->image);
122 paintArea->photogram()->render(&painter);
124 if(rect.contains(input->scenePos().toPoint()))
126 paintArea->brushManager()->setBrush(QBrush(d->image.pixel(input->scenePos().toPoint())));
132 * @~spanish
133 * Función sobrecargada para implementar la selección del color.
135 void ColorPicker::move(const QGraphicsSceneMouseEvent *input)
137 PaintArea *paintArea = this->paintArea();
138 QRectF rect = paintArea->photogram()->sceneRect();
139 if(input->buttons() == Qt::LeftButton)
141 if(rect.contains(input->scenePos().toPoint()))
143 paintArea->brushManager()->setBrush(QBrush(d->image.pixel(input->scenePos().toPoint())));
150 * @~spanish
151 * Función sobrecargada para implementar la selección del color.
153 void ColorPicker::release(const QGraphicsSceneMouseEvent *input)
158 * @~spanish
159 * Retorna la acción que representa la herramienta.
161 DGui::Action *ColorPicker::action() const
163 return d->action;
167 * @~spanish
168 * Retorna que la herramienta es de tipo Brush.
170 int ColorPicker::type() const
172 return AbstractTool::Brush;
175 void ColorPicker::aboutToChangeTool()
180 void ColorPicker::setupConfigBar(QToolBar *configBar)