<file>dimension-tool.png</file>
<file>fix-angle.png</file>
<file>fix-length.png</file>
+ <file>group-tool.png</file>
<file>generic-tool.png</file>
<file>rotate-tool.png</file>
+ <file>snap-to-grid-tool.png</file>
<file>splash.png</file>
<file>quit.png</file>
<file>zoom-in.png</file>
//
void ApplicationWindow::HandleGrouping(void)
{
+ int itemsSelected = drawing->document.ItemsSelected();
+
// If nothing selected, do nothing
- if (drawing->document.ItemsSelected() == 0)
+ if (itemsSelected == 0)
{
statusBar()->showMessage(tr("No objects selected to make a group from."));
return;
// If it's a group that's selected, ungroup it and leave the objects in a
// selected state
- if (drawing->document.ItemsSelected() == 1)
+ if (itemsSelected == 1)
{
Object * object = drawing->document.SelectedItem(0);
((Container *)object)->SelectAll();
((Container *)object)->MoveContentsTo(&(drawing->document));
drawing->document.Delete(object);
+ statusBar()->showMessage(tr("Objects ungrouped."));
}
// Otherwise, if it's a group of 2 or more objects (which can be groups too)
// group them and select the group
- else if (drawing->document.ItemsSelected() > 1)
+ else if (itemsSelected > 1)
{
Container * container = new Container(Vector(), &(drawing->document));
drawing->document.MoveSelectedContentsTo(container);
drawing->document.Add(container);
container->DeselectAll();
container->state = OSSelected;
+ statusBar()->showMessage(QString(tr("Grouped %1 objects.")).arg(itemsSelected));
}
drawing->update();
QIcon(":/res/quit.png"), QKeySequence(tr("Ctrl+q")));
connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
- snapToGridAct = CreateAction(tr("Snap To &Grid"), tr("Snap To Grid"), tr("Snaps mouse cursor to the visible grid when moving/creating objects."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("S")), true);
+ snapToGridAct = CreateAction(tr("Snap To &Grid"), tr("Snap To Grid"), tr("Snaps mouse cursor to the visible grid when moving/creating objects."), QIcon(":/res/snap-to-grid-tool.png"), QKeySequence(tr("S")), true);
connect(snapToGridAct, SIGNAL(triggered()), this, SLOT(SnapToGridTool()));
fixAngleAct = CreateAction(tr("Fix &Angle"), tr("Fix Angle"), tr("Fixes the angle of an object."),
settingsAct = CreateAction(tr("&Settings"), tr("Settings"), tr("Change certain defaults for Architektonas."), QIcon(":/res/generic-tool.png"), QKeySequence());
connect(settingsAct, SIGNAL(triggered()), this, SLOT(Settings()));
- groupAct = CreateAction(tr("&Group"), tr("Group"), tr("Group/ungroup selected objects."), QIcon(":/res/generic-tool.png"), QKeySequence("g"));
+ groupAct = CreateAction(tr("&Group"), tr("Group"), tr("Group/ungroup selected objects."), QIcon(":/res/group-tool.png"), QKeySequence("g"));
connect(groupAct, SIGNAL(triggered()), this, SLOT(HandleGrouping()));
//Hm. I think we'll have to have separate logic to do the "Radio Group Toolbar" thing...
Container::Container(Vector p1, Object * p/*= NULL*/): Object(p1, p),
+ isTopLevelContainer(false),
dragging(false), draggingHandle1(false), draggingHandle2(false)//, needUpdate(false)
{
type = OTContainer;
*/
+// Need to add checking here for clicking on a member of a group (Container),
+// and checking for if it's a top level container (the DrawingView's document).
+/*
+One approach is to check for the parent of the container: If it's NULL, then it's
+the DrawingView's document. It might be better, though, to set a boolean like
+isTopLevelContainer so that we can do things like edit members of a group without
+having to ungroup them first (like Inkscape).
+*/
/*virtual*/ bool Container::Collided(Vector point)
{
objectWasDragged = false;
}
}
- // Do we decouple the state of the generic container from the objects inside??? Mebbe.
- state = OSInactive;
+ // We check to see if the container we're trying to access is the
+ // DrawingView's document. If so, we ignore the state of the container.
+ // Otherwise, we care about the state of the container. :-)
+ if (isTopLevelContainer)
+ state = OSInactive;
+ else
+ {
+ state = (collision ? OSSelected : OSInactive);
+
+ if (state == OSSelected)
+ DeselectAll();
+ }
+
return collision;
}
// objectWasDragged = true;
//printf("CONTAINER: PointerMoved()\n");
- for(int i=0; i<(int)objects.size(); i++)
+ for(std::vector<Object *>::iterator i=objects.begin(); i!=objects.end(); i++)
+// for(int i=0; i<(int)objects.size(); i++)
{
-// if (objects[i]->GetState() == OSSelected)
- objects[i]->PointerMoved(point);
+//// if (objects[i]->GetState() == OSSelected)
+// objects[i]->PointerMoved(point);
+ (*i)->PointerMoved(point);
}
// Generic container doesn't need this???
/*virtual*/ bool Container::NeedsUpdate(void)
{
- needUpdate = false;
-
- for(uint i=0; i<objects.size(); i++)
+ // Search through objects for one that needs an update; if one is found,
+ // return immediately.
+ for(std::vector<Object *>::iterator i=objects.begin(); i!=objects.end(); i++)
{
- if (objects[i]->NeedsUpdate())
- needUpdate = true;
+ if ((*i)->NeedsUpdate())
+ return true;
}
- return needUpdate;
+ return false;
}
}
-#if 0
-/*virtual*/ ObjectType Container::Type(void)
-{
- return OTContainer;
-}
-#endif
-
-
void Container::Delete(Object * objectToDelete)
{
std::vector<Object *>::iterator i = objects.begin();
void Container::Clear(void)
{
-#if 0
- // No memory leaks!
- while (objects.size() > 0)
- {
-printf("Container: Deleting object ($%X)...\n", objects[0]);
- delete objects[0];
- objects.erase(objects.begin());
- }
-#else
std::vector<Object *>::iterator i = objects.begin();
while (i != objects.end())
delete (*i);
objects.erase(i);
}
-#endif
}
virtual bool NeedsUpdate(void);
virtual void Add(Object *);
virtual void Enumerate(FILE *);
-// virtual ObjectType Type(void);
void Delete(Object *);
void DeleteSelectedItems(void);
void Clear(void);
void SelectAll(void);
void DeselectAll(void);
int ItemsSelected(void);
-// ObjectType SelectedItemType(unsigned int);
Object * SelectedItem(unsigned int);
-// void ReparentContentsTo(Object *);
void MoveContentsTo(Container *);
void MoveSelectedContentsTo(Container *);
public:
std::vector<Object *> objects;
+ bool isTopLevelContainer;
private:
bool dragging;
bool draggingHandle1;
bool draggingHandle2;
-// bool needUpdate;
bool objectWasDragged;
};
// gridSpacing(32.0), collided(false), rotateTool(false), rx(150.0), ry(150.0),
gridSpacing(12.0), collided(false), rotateTool(false), rx(150.0), ry(150.0),
scrollDrag(false), addLineTool(false), addCircleTool(false),
- addDimensionTool(false), toolAction(NULL)
+ addDimensionTool(false),
+ selectionInProgress(false),
+ toolAction(NULL)
{
+ document.isTopLevelContainer = true;
setBackgroundRole(QPalette::Base);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
if (toolAction)
toolAction->Draw(&painter);
+
+ if (selectionInProgress)
+ {
+// painter.SetPen(QPen(Qt::green, 1.0, Qt::SolidLine));
+ painter.SetPen(QPen(QColor(255, 127, 0, 255)));
+// painter.SetBrush(QBrush(Qt::NoBrush));
+ painter.SetBrush(QBrush(QColor(255, 127, 0, 100)));
+ painter.DrawRect(selection);
+ }
}
if (toolAction)
toolAction->MouseDown(point);
+
+ // Didn't hit any object and not using a tool, so do a selection rectangle
+ if (!(collided || toolAction))
+ {
+ selectionInProgress = true;
+ selection.setTopLeft(QPointF(point.x, point.y));
+ selection.setBottomRight(QPointF(point.x, point.y));
+ }
}
else if (event->button() == Qt::MiddleButton)
{
void DrawingView::mouseMoveEvent(QMouseEvent * event)
{
Vector point = Painter::QtToCartesianCoords(Vector(event->x(), event->y()));
+ selection.setBottomRight(QPointF(point.x, point.y));
if (event->buttons() & Qt::MiddleButton)
{
//changed...
document.PointerMoved(point);
- if (document.NeedsUpdate())
+ if (document.NeedsUpdate() || selectionInProgress)
update();
if (toolAction)
if (toolAction)
toolAction->MouseReleased();
+
+ if (selectionInProgress)
+ {
+ // Select all the stuff inside of selection
+ selectionInProgress = false;
+ }
}
else if (event->button() == Qt::MiddleButton)
{
bool addLineTool;
bool addCircleTool;
bool addDimensionTool;
+ bool selectionInProgress;
+ QRectF selection;
public:
Action * toolAction;