File indexing completed on 2024-12-22 04:17:30
0001 /*************************************************************************** 0002 * * 0003 * copyright : (C) 2007 The University of Toronto * 0004 * netterfield@astro.utoronto.ca * 0005 * * 0006 * This program is free software; you can redistribute it and/or modify * 0007 * it under the terms of the GNU General Public License as published by * 0008 * the Free Software Foundation; either version 2 of the License, or * 0009 * (at your option) any later version. * 0010 * * 0011 ***************************************************************************/ 0012 0013 #include "ellipseitem.h" 0014 0015 #include <QDebug> 0016 #include <QGraphicsItem> 0017 #include <QGraphicsScene> 0018 0019 #include <debug.h> 0020 0021 namespace Kst { 0022 0023 EllipseItem::EllipseItem(View *parent) 0024 : ViewItem(parent) { 0025 setTypeName(tr("Ellipse", "an ellipse in a picture")); 0026 setBrush(Qt::white); 0027 applyDialogDefaultsStroke(); 0028 applyDialogDefaultsFill(); 0029 applyDialogDefaultsLockPosToData(); 0030 } 0031 0032 0033 EllipseItem::~EllipseItem() { 0034 } 0035 0036 0037 void EllipseItem::save(QXmlStreamWriter &xml) { 0038 if (isVisible()) { 0039 xml.writeStartElement("ellipse"); 0040 ViewItem::save(xml); 0041 xml.writeEndElement(); 0042 } 0043 } 0044 0045 0046 QPainterPath EllipseItem::itemShape() const { 0047 QPainterPath path; 0048 path.addEllipse(rect()); 0049 return path; 0050 } 0051 0052 0053 void EllipseItem::paint(QPainter *painter) { 0054 const qreal w = pen().widthF(); 0055 painter->drawEllipse(rect().adjusted(w, w, -w, -w)); 0056 } 0057 0058 0059 void CreateEllipseCommand::createItem() { 0060 _item = new EllipseItem(_view); 0061 _view->setCursor(Qt::CrossCursor); 0062 0063 CreateCommand::createItem(); 0064 } 0065 0066 0067 EllipseItemFactory::EllipseItemFactory() 0068 : GraphicsFactory() { 0069 registerFactory("ellipse", this); 0070 } 0071 0072 0073 EllipseItemFactory::~EllipseItemFactory() { 0074 } 0075 0076 0077 ViewItem* EllipseItemFactory::generateGraphics(QXmlStreamReader& xml, ObjectStore *store, View *view, ViewItem *parent) { 0078 EllipseItem *rc = 0; 0079 while (!xml.atEnd()) { 0080 bool validTag = true; 0081 if (xml.isStartElement()) { 0082 if (!rc && xml.name().toString() == "ellipse") { 0083 Q_ASSERT(!rc); 0084 rc = new EllipseItem(view); 0085 if (parent) { 0086 rc->setParentViewItem(parent); 0087 // Add any new specialized BoxItem Properties here. 0088 } 0089 } else { 0090 Q_ASSERT(rc); 0091 if (!rc->parse(xml, validTag) && validTag) { 0092 ViewItem *i = GraphicsFactory::parse(xml, store, view, rc); 0093 if (!i) { 0094 } 0095 } 0096 } 0097 } else if (xml.isEndElement()) { 0098 if (xml.name().toString() == "ellipse") { 0099 break; 0100 } else { 0101 validTag = false; 0102 } 0103 } 0104 if (!validTag) { 0105 qDebug("invalid Tag\n"); 0106 Debug::self()->log(QObject::tr("Error creating ellipse object from Kst file."), Debug::Warning); 0107 delete rc; 0108 return 0; 0109 } 0110 xml.readNext(); 0111 } 0112 return rc; 0113 } 0114 0115 } 0116 0117 // vim: ts=2 sw=2 et