File indexing completed on 2024-12-22 04:17:25
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 "boxitem.h" 0014 0015 #include <debug.h> 0016 0017 #include <QDebug> 0018 #include <QGraphicsScene> 0019 0020 namespace Kst { 0021 0022 BoxItem::BoxItem(View *parent) 0023 : ViewItem(parent) { 0024 setTypeName(tr("Box", "a box in a picture")); 0025 setBrush(Qt::white); 0026 applyDialogDefaultsStroke(); 0027 applyDialogDefaultsFill(); 0028 applyDialogDefaultsLockPosToData(); 0029 } 0030 0031 0032 BoxItem::~BoxItem() { 0033 } 0034 0035 0036 void BoxItem::paint(QPainter *painter) { 0037 painter->drawRect(rect()); 0038 } 0039 0040 0041 void BoxItem::save(QXmlStreamWriter &xml) { 0042 if (isVisible()) { 0043 xml.writeStartElement("box"); 0044 ViewItem::save(xml); 0045 xml.writeEndElement(); 0046 } 0047 } 0048 0049 0050 void CreateBoxCommand::createItem() { 0051 _item = new BoxItem(_view); 0052 _view->setCursor(Qt::CrossCursor); 0053 0054 CreateCommand::createItem(); 0055 } 0056 0057 0058 BoxItemFactory::BoxItemFactory() 0059 : GraphicsFactory() { 0060 registerFactory("box", this); 0061 } 0062 0063 0064 BoxItemFactory::~BoxItemFactory() { 0065 } 0066 0067 0068 ViewItem* BoxItemFactory::generateGraphics(QXmlStreamReader& xml, ObjectStore *store, View *view, ViewItem *parent) { 0069 BoxItem *rc = 0; 0070 while (!xml.atEnd()) { 0071 bool validTag = true; 0072 if (xml.isStartElement()) { 0073 if (!rc && xml.name().toString() == "box") { 0074 Q_ASSERT(!rc); 0075 rc = new BoxItem(view); 0076 if (parent) { 0077 rc->setParentViewItem(parent); 0078 } 0079 // Add any new specialized BoxItem Properties here. 0080 } else { 0081 Q_ASSERT(rc); 0082 if (!rc->parse(xml, validTag) && validTag) { 0083 ViewItem *i = GraphicsFactory::parse(xml, store, view, rc); 0084 if (!i) { 0085 } 0086 } 0087 } 0088 } else if (xml.isEndElement()) { 0089 if (xml.name().toString() == "box") { 0090 break; 0091 } else { 0092 validTag = false; 0093 } 0094 } 0095 if (!validTag) { 0096 qDebug("invalid Tag\n"); 0097 Debug::self()->log(QObject::tr("Error creating box object from Kst file."), Debug::Warning); 0098 delete rc; 0099 return 0; 0100 } 0101 xml.readNext(); 0102 } 0103 return rc; 0104 } 0105 0106 } 0107 0108 // vim: ts=2 sw=2 et