1 /**************************************************************************
2 * Copyright (C) 2005 by David Cuadrado *
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 <QGraphicsView>
24 #include <QGraphicsSceneMouseEvent>
26 #include <QHBoxLayout>
27 #include <QRadioButton>
29 #include <QButtonGroup>
31 #include <dcore/global.h>
32 #include <dcore/debug.h>
34 #include <dgui/iconloader.h>
35 #include <dgui/action.h>
37 #include <dgraphics/pathhelper.h>
38 #include <dgraphics/algorithm.h>
40 #include "yamf/drawing/paintarea.h"
41 #include "yamf/drawing/brushmanager.h"
42 #include "yamf/drawing/photogram.h"
43 #include "yamf/item/path.h"
44 #include "yamf/item/proxy.h"
45 #include "yamf/item/converter.h"
47 #include "yamf/model/command/changeitembrush.h"
48 #include "yamf/model/command/changeitempen.h"
50 #include "yamf/model/frame.h"
58 struct Fill::Private
{
65 DGui::Action
* action
;
66 QWidget
*configWidget
;
70 Fill::Fill(QObject
*parent
) : AbstractTool(parent
), d(new Private
)
72 d
->action
= new DGui::Action( DGui::IconLoader::self()->load("fill-tool.svg"), tr("Fill"), this);
73 d
->action
->setShortcut( QKeySequence(tr("Ctrl+B")) );
75 d
->configWidget
= new QWidget
;
76 QHBoxLayout
*layout
= new QHBoxLayout(d
->configWidget
);
78 layout
->setSpacing(2);
80 QRadioButton
*fill
= new QRadioButton(tr("Fill"));
81 fill
->setChecked(true);
82 layout
->addWidget(fill
);
84 // QRadioButton *shapefill = new QRadioButton(tr("Shape fill"));
86 QRadioButton
*outlineFill
= new QRadioButton(tr("Outline fill"));
87 layout
->addWidget(outlineFill
);
89 d
->group
.addButton(fill
, Private::Fill
);
90 d
->group
.addButton(outlineFill
, Private::OutlineFill
);
98 void Fill::init(Photogram
*photogram
)
100 foreach(QGraphicsItem
*item
, photogram
->items() )
102 item
->setFlag(QGraphicsItem::ItemIsSelectable
, true);
103 item
->setFlag(QGraphicsItem::ItemIsFocusable
, true);
107 QString
Fill::id() const
112 void Fill::press(const QGraphicsSceneMouseEvent
*input
)
114 PaintArea
*paintArea
= this->paintArea();
115 Photogram
*photogram
= paintArea
->photogram();
117 if(input
->buttons() == Qt::LeftButton
)
119 QGraphicsItem
*item
= photogram
->itemAt(input
->scenePos());
123 if( paintArea
->currentFrame()->logicalIndexOf(item
) > -1 )
125 while( Item::Proxy
*proxy
= qgraphicsitem_cast
<Item::Proxy
*>(item
) )
127 item
= proxy
->item();
130 if( QAbstractGraphicsShapeItem
*shape
= qgraphicsitem_cast
<QAbstractGraphicsShapeItem
*>(item
) )
132 QBrush brush
= paintArea
->brushManager()->mapBrush(item
->sceneBoundingRect(), paintArea
->brushManager()->penBrush());
134 if( d
->group
.checkedId() == Private::Fill
)
136 Command::ChangeItemBrush
*cmd
= new Command::ChangeItemBrush(paintArea
->currentFrame(), photogram
->itemAt(input
->scenePos()), brush
);
137 paintArea
->addCommand(cmd
);
139 else if( d
->group
.checkedId() == Private::OutlineFill
)
141 QPen pen
= shape
->pen();
144 Command::ChangeItemPen
*cmd
= new Command::ChangeItemPen(paintArea
->currentFrame(), photogram
->itemAt(input
->scenePos()), pen
);
145 paintArea
->addCommand(cmd
);
153 void Fill::move(const QGraphicsSceneMouseEvent
*input
)
158 void Fill::release(const QGraphicsSceneMouseEvent
*input
)
162 DGui::Action
* Fill::action() const
167 int Fill::type() const
169 return AbstractTool::Fill
;
172 void Fill::aboutToChangeTool()
176 void Fill::setupConfigBar(QToolBar
*configBar
)
178 configBar
->addWidget(d
->configWidget
)->setVisible(true);
181 QPainterPath
Fill::mapPath(const QPainterPath
&path
, const QPointF
&pos
)
184 tr1
.translate(pos
.x(), pos
.y());
186 QPainterPath p1
= tr1
.map(path
);
187 // p1.closeSubpath();
192 QPainterPath
Fill::mapPath(const QGraphicsPathItem
*item
)
194 return mapPath(item
->path(), item
->pos());