1 /***************************************************************************
2 * Copyright (C) 2007 David Cuadrado *
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 "mainwindow.h"
23 #include <drawing/paintarea.h>
24 #include <drawing/photogram.h>
26 #include <dcore/algorithm.h>
27 #include <dcore/debug.h>
29 #include <dgui/iconloader.h>
30 #include <dgui/commandhistory.h>
32 #include <model/project.h>
33 #include <model/scene.h>
34 #include <model/layer.h>
35 #include <model/frame.h>
36 #include <model/object.h>
38 #include <model/command/manager.h>
40 #include <item/rect.h>
42 #include <gui/drawingactions.h>
44 #include <QDockWidget>
45 #include <QGridLayout>
49 #include "commandobserver.h"
51 MainWindow::MainWindow(QWidget
*parent
)
54 m_project
= new YAMF::Model::Project(this);
55 m_project
->commandManager()->setObserver(new CommandObserver());
57 YAMF::Model::Scene
*scn
= m_project
->createScene();
58 YAMF::Model::Layer
*lyr
= scn
->createLayer();
59 /*YAMF::Model::Frame *frm = */lyr
->createFrame();
62 m_view
= new YAMF::Drawing::View(m_project
);
63 YAMF::Drawing::PaintArea
*paintarea
= m_view
->paintArea();
64 paintarea
->setDragMode(QGraphicsView::RubberBandDrag
);
66 paintarea
->setCurrentFrame(0, 0, 0);
68 setCentralWidget(m_view
);
70 YAMF::Gui::DrawingActions
*toolbar
= new YAMF::Gui::DrawingActions(paintarea
);
71 toolbar
->addAction(tr("Add shape"), this, SLOT(addShape()));
73 addToolBar( toolbar
);
77 MainWindow::~MainWindow()
82 void MainWindow::addShape()
84 if( YAMF::Model::Frame
*frame
= m_view
->paintArea()->currentFrame())
86 YAMF::Item::Rect
*rect
= new YAMF::Item::Rect
;
88 rect
->setFlags(QGraphicsItem::ItemIsSelectable
| QGraphicsItem::ItemIsMovable
);
89 rect
->setRect(QRect(0,0,DCore::Algorithm::random(200)+10,DCore::Algorithm::random(200)+10));
91 rect
->setPos(DCore::Algorithm::random((int)m_view
->paintArea()->drawingRect().width())+10, DCore::Algorithm::random((int)m_view
->paintArea()->drawingRect().height())+10);
93 rect
->setBrush(DCore::Algorithm::randomColor());