#include <QtGui>
#include "dimension.h"
+#include "painter.h"
Container::Container(Vector p1, Object * p/*= NULL*/): Object(p1, p),
dragging(false), draggingHandle1(false), draggingHandle2(false)//, needUpdate(false)
{
+ type = OTContainer;
}
{
// Use overloaded assignment operator
*this = copy;
+ type = OTContainer;
}
/*virtual*/ void Container::Draw(Painter * painter)
{
- for(int i=0; i<(int)objects.size(); i++)
+ QRectF boundary;
+
+ for(std::vector<Object *>::iterator i=objects.begin(); i!=objects.end(); i++)
+// for(int i=0; i<(int)objects.size(); i++)
{
+#if 0
//printf("Container: About to draw (object = $%X)\n", objects[i]);
objects[i]->Draw(painter);
+ bounds = bounds.united(objects[i].RectangularExtents());
+#else
+ (*i)->Draw(painter);
+ boundary = boundary.united((*i)->Extents());
+#endif
+ }
+
+ if (state == OSSelected)
+ {
+ painter->SetPen(QPen(Qt::magenta, 2.0, Qt::DashLine));
+ painter->SetBrush(QBrush(Qt::NoBrush));
+ painter->DrawRect(boundary);
}
}
}
+#if 0
+/*virtual*/ ObjectType Container::Type(void)
+{
+ return OTContainer;
+}
+#endif
+
+
+void Container::Delete(Object * objectToDelete)
+{
+#if 0
+ //this is wrong
+ for(unsigned int i=0; i<objects.size(); i++)
+ {
+ if (objects[i] == objectToDelete)
+ {
+ objects.erase(i);
+ delete objectToDelete;
+ return;
+ }
+ }
+#else
+ std::vector<Object *>::iterator i = objects.begin();
+
+ while (i != objects.end())
+ {
+ if (*i == objectToDelete)
+ {
+ objects.erase(i);
+ delete objectToDelete;
+ return;
+ }
+
+ i++;
+ }
+#endif
+}
+
+
void Container::Clear(void)
{
// No memory leaks!
}
+void Container::SelectAll(void)
+{
+ for(unsigned int i=0; i<objects.size(); i++)
+ objects[i]->state = OSSelected;
+}
+
+
+void Container::DeselectAll(void)
+{
+ for(unsigned int i=0; i<objects.size(); i++)
+ objects[i]->state = OSInactive;
+}
+
+
+int Container::ItemsSelected(void)
+{
+ int selected = 0;
+
+ for(uint i=0; i<objects.size(); i++)
+ if (objects[i]->state == OSSelected)
+ selected++;
+
+ return selected;
+}
+
+
+/*ObjectType Container::SelectedItemType(unsigned int index)
+{
+ if (index >= objects.size())
+ return OTNone;
+
+ return objects[index]->Type();
+}*/
+
+
+Object * Container::SelectedItem(unsigned int index)
+{
+// if (index >= objects.size())
+// return NULL;
+
+ unsigned int selectedIndex = 0;
+
+ for(std::vector<Object *>::iterator i=objects.begin(); i!=objects.end(); i++)
+ {
+ if ((*i)->state == OSSelected)
+ {
+ if (selectedIndex == index)
+ return *i;
+ else
+ selectedIndex++;
+ }
+ }
+
+ return NULL;
+}
+
+
+void Container::MoveContentsTo(Container * newContainer)
+{
+ // Sanity check
+ if (newContainer == NULL)
+ return;
+
+ // Shuffle the contents of this container to the new one
+ for(unsigned int i=0; i<objects.size(); i++)
+ newContainer->Add(objects[i]);
+
+ // & clear our vector
+ objects.clear();
+}
+
+
+void Container::MoveSelectedContentsTo(Container * newContainer)
+{
+ // Sanity check
+ if (newContainer == NULL)
+ return;
+
+ // Shuffle the contents of this container to the new one
+ for(std::vector<Object *>::iterator i=objects.begin(); i!=objects.end();)
+ {
+ if ((*i)->state != OSSelected)
+ {
+ i++;
+ continue;
+ }
+
+ newContainer->Add(*i);
+ objects.erase(i);
+ }
+}
+
+
/*virtual*/ void Container::Enumerate(FILE * file)
{
// Only put "CONTAINER" markers if *not* the top level container