1 /***************************************************************************
2 * Copyright (C) 2007 Jorge Cuadrado *
3 * kuadrosxx@gmail.com *
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. *
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. *
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 *
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
21 #include "colorpicker.h"
24 #include <QKeySequence>
25 #include <QPainterPath>
27 #include <QGraphicsView>
28 #include <QGraphicsSceneMouseEvent>
30 #include <QHBoxLayout>
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>
55 struct ColorPicker::Private
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);
74 ColorPicker::~ColorPicker()
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);
104 * Retorna el id de la herramienta
106 QString
ColorPicker::id() const
108 return tr("ColorPicker");
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
);
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())));
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())));
151 * Función sobrecargada para implementar la selección del color.
153 void ColorPicker::release(const QGraphicsSceneMouseEvent
*input
)
159 * Retorna la acción que representa la herramienta.
161 DGui::Action
*ColorPicker::action() const
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
)