1 /***************************************************************************
2 * *
3 * copyright : (C) 2007 The University of Toronto *
4 * netterfield@astro.utoronto.ca *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 ***************************************************************************/
12
13 #include "ellipseitem.h"
14
15 #include <QDebug>
16 #include <QGraphicsItem>
17 #include <QGraphicsScene>
18
19 #include <debug.h>
20
21 namespace Kst {
22
EllipseItem(View * parent)23 EllipseItem::EllipseItem(View *parent)
24 : ViewItem(parent) {
25 setTypeName(tr("Ellipse", "an ellipse in a picture"));
26 setBrush(Qt::white);
27 applyDialogDefaultsStroke();
28 applyDialogDefaultsFill();
29 applyDialogDefaultsLockPosToData();
30 }
31
32
~EllipseItem()33 EllipseItem::~EllipseItem() {
34 }
35
36
save(QXmlStreamWriter & xml)37 void EllipseItem::save(QXmlStreamWriter &xml) {
38 if (isVisible()) {
39 xml.writeStartElement("ellipse");
40 ViewItem::save(xml);
41 xml.writeEndElement();
42 }
43 }
44
45
itemShape() const46 QPainterPath EllipseItem::itemShape() const {
47 QPainterPath path;
48 path.addEllipse(rect());
49 return path;
50 }
51
52
paint(QPainter * painter)53 void EllipseItem::paint(QPainter *painter) {
54 const qreal w = pen().widthF();
55 painter->drawEllipse(rect().adjusted(w, w, -w, -w));
56 }
57
58
createItem()59 void CreateEllipseCommand::createItem() {
60 _item = new EllipseItem(_view);
61 _view->setCursor(Qt::CrossCursor);
62
63 CreateCommand::createItem();
64 }
65
66
EllipseItemFactory()67 EllipseItemFactory::EllipseItemFactory()
68 : GraphicsFactory() {
69 registerFactory("ellipse", this);
70 }
71
72
~EllipseItemFactory()73 EllipseItemFactory::~EllipseItemFactory() {
74 }
75
76
generateGraphics(QXmlStreamReader & xml,ObjectStore * store,View * view,ViewItem * parent)77 ViewItem* EllipseItemFactory::generateGraphics(QXmlStreamReader& xml, ObjectStore *store, View *view, ViewItem *parent) {
78 EllipseItem *rc = 0;
79 while (!xml.atEnd()) {
80 bool validTag = true;
81 if (xml.isStartElement()) {
82 if (!rc && xml.name().toString() == "ellipse") {
83 Q_ASSERT(!rc);
84 rc = new EllipseItem(view);
85 if (parent) {
86 rc->setParentViewItem(parent);
87 // Add any new specialized BoxItem Properties here.
88 }
89 } else {
90 Q_ASSERT(rc);
91 if (!rc->parse(xml, validTag) && validTag) {
92 ViewItem *i = GraphicsFactory::parse(xml, store, view, rc);
93 if (!i) {
94 }
95 }
96 }
97 } else if (xml.isEndElement()) {
98 if (xml.name().toString() == "ellipse") {
99 break;
100 } else {
101 validTag = false;
102 }
103 }
104 if (!validTag) {
105 qDebug("invalid Tag\n");
106 Debug::self()->log(QObject::tr("Error creating ellipse object from Kst file."), Debug::Warning);
107 delete rc;
108 return 0;
109 }
110 xml.readNext();
111 }
112 return rc;
113 }
114
115 }
116
117 // vim: ts=2 sw=2 et
118