From ef811c836c00cc94ce1eaea5c2e77e5278298b18 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Sun, 7 Jul 2013 15:55:33 -0500 Subject: [PATCH] Added new icons, beginning of selection rectangle functionality. --- res/architektonas.qrc | 2 ++ res/group-tool.png | Bin 0 -> 484 bytes res/snap-to-grid-tool.png | Bin 0 -> 1318 bytes src/applicationwindow.cpp | 14 ++++++--- src/container.cpp | 62 ++++++++++++++++++++------------------ src/container.h | 5 +-- src/drawingview.cpp | 31 +++++++++++++++++-- src/drawingview.h | 2 ++ 8 files changed, 76 insertions(+), 40 deletions(-) create mode 100644 res/group-tool.png create mode 100644 res/snap-to-grid-tool.png diff --git a/res/architektonas.qrc b/res/architektonas.qrc index 0ff0ece..f32a316 100644 --- a/res/architektonas.qrc +++ b/res/architektonas.qrc @@ -10,8 +10,10 @@ dimension-tool.png fix-angle.png fix-length.png + group-tool.png generic-tool.png rotate-tool.png + snap-to-grid-tool.png splash.png quit.png zoom-in.png diff --git a/res/group-tool.png b/res/group-tool.png new file mode 100644 index 0000000000000000000000000000000000000000..18d260ba23c0c80a62adfc8a8500ed60bd26a0b9 GIT binary patch literal 484 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=Y)RhkEq5ElTY@uMBKBA(#qacv&7+yP4At!%MWrZ7@z%ZfB(C97XRsOlS<;V zuM0AUGwIy+niTb+fls>EfY)nYL!`s&c^?|&lowoAbKT^{pj1@um$q(F-qFntM;>H% zG4QYWdrV20ONN23fxUq_fWPAj!}~}E83uj^Aol^|2ZjO$iv=@9Dv~s<*RbE|j26

ph!FH1$ySMBV zQq*OSV2humv`$7qwc%>`mfEEXj{L#7=U9{#U%g;m!Je{?y~3!K?UDfF3ibtZ0qx96 zuNY?8J!CX}sNTiemv3*&Ucs^Ot@7FbOw&yFx*k|1m=Jria*f97;sg7$t4=?-`<>HH z(J6Dvip%Pk^9pnIqAir(mQ|kLR56*U!t4t39*YIbFDG?0Ok|nhcX**(!{N&x8aCeM Y-~QfxlGw_C5Kv@!y85}Sb4q9e0Psz@cK`qY literal 0 HcmV?d00001 diff --git a/res/snap-to-grid-tool.png b/res/snap-to-grid-tool.png new file mode 100644 index 0000000000000000000000000000000000000000..33a74037e83e7bb21b12871cea609bf7876f0798 GIT binary patch literal 1318 zcmV+>1=;$EP)S1hYv* zK~#9!?VHPQTSXMce>1*`n>MlYBy|gY08$H07sP6XDx?@8P$ia#H7wYHgjld>Sn zT+jEN$9(5pTj0@-39ZXtk7*$Ykkz|C$zyJo084-+z!G2y*y)y%G8AEk{fx1nG5VMw zC1snJwN4X&?*v|Zi+71|7l1T_0H;$@CgVzFYOVJyW`ZPyQc{M12yhg54|rW^85Jlr zf+AsBMgA)A1#l^@RIVxk$Aq2)4h7G*8i7XQ(n6jvS=yOn5A*D0oP*q8fbZ$&FQicG zRu^>(qrAx_&N9Vw)xP9b!%{%tvWIy(nWmi#tt{c1jFh;9St3l9PNwN#&V24)y18SB z$ly?*S{#O0;Q-g^;to?Bts3kNAs|G7er__rFwb(8J|+p1MdG3nNL(BWgjvF28HWOr zA`*pQ)!Q2-pb!w!#o!e|flDuGPVp@#xJWnu&_ez}$gc%auPH59B1)E?nx$^ri(pF1 z2yhzs02l;X{OrSr<$=$D&*Mtn50Vbp1snkSw+g&*)fM2YTHu>f32F`V>;t$ES1KJu zC71_p12e!1tV#SwG)0JUUIG{ksuaEt`~v&{Oae=Q3n)W|HqVuLUza^Lv;u8Ra|B>E zkWx6Vl$(+=4SWOK1zrRW1MNTvC;|oZJO)I8Rxh9_Dz8xKcW>1Q-&Ez-&s&xiWwfI1apTbbdz_@Ve6b8p#4N zazs4uqv73PTq$MrfdrlhJ~3(0Sp$4U0u+)gJx2WOpm~4+e;hdP0erq%K~y*_5M!D4 zokM_6@b^sNbSquU#UV=5&Rk8zgkD4uA{AJR0OmGZkl{&RwZPdT;0Xh+ z!dXr7Ri%FXNC=$};zn6bD0OhxfKP$n)_^Y&a19tXGI^gFs$|m)#(w8zW;yID0yc9b zmH^IG1HRVw!cQLxaXBGG9ynqI&J1u7n5Y20R6|;TXMk7Cx(G1!rT*^BA0$|$7Z9FD zcAH7SIpAYI;nEG~ho$_wY#+CQ>_(lOxiJzg6GVk~^x}Adwg;E;N`SM~IbX{%aO$K| z!=qA;n8wIc3maF;1u`iq=N}G2cGtD>%_Lx`j&(yW48@hYTxTb#A4X_>8@IQ|EdiDQ zOMoR{6KsUl>8@W(nzc@If3usR5hI5a8wjIhndh5|fbx*8C5;0C ze5>aHfdXldK}$f5c|dS~C%7$k%cg)O;Bl`3UO#C6HD*)55?~3i1Xuzr0hWMfGpC8L cOw_aJe-F&8?S1p!3jhEB07*qoM6N<$f>NzCEC2ui literal 0 HcmV?d00001 diff --git a/src/applicationwindow.cpp b/src/applicationwindow.cpp index 77767f0..4aac209 100644 --- a/src/applicationwindow.cpp +++ b/src/applicationwindow.cpp @@ -398,8 +398,10 @@ void ApplicationWindow::Settings(void) // 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; @@ -407,7 +409,7 @@ void ApplicationWindow::HandleGrouping(void) // 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); @@ -431,16 +433,18 @@ else ((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(); @@ -453,7 +457,7 @@ void ApplicationWindow::CreateActions(void) 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."), @@ -511,7 +515,7 @@ void ApplicationWindow::CreateActions(void) 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... diff --git a/src/container.cpp b/src/container.cpp index cd9b4f5..bd37b77 100644 --- a/src/container.cpp +++ b/src/container.cpp @@ -21,6 +21,7 @@ Container::Container(Vector p1, Object * p/*= NULL*/): Object(p1, p), + isTopLevelContainer(false), dragging(false), draggingHandle1(false), draggingHandle2(false)//, needUpdate(false) { type = OTContainer; @@ -111,6 +112,14 @@ Also: should put the snap logic into the Object base class (as a static method). */ +// 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; @@ -144,8 +153,19 @@ printf("Container::Collided: Deleting object ($%X)\n", *i); } } - // 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; } @@ -162,10 +182,12 @@ printf("Container::Collided: Deleting object ($%X)\n", *i); // objectWasDragged = true; //printf("CONTAINER: PointerMoved()\n"); - for(int i=0; i<(int)objects.size(); i++) + for(std::vector::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??? @@ -196,15 +218,15 @@ about keeping track of old states... /*virtual*/ bool Container::NeedsUpdate(void) { - needUpdate = false; - - for(uint i=0; i::iterator i=objects.begin(); i!=objects.end(); i++) { - if (objects[i]->NeedsUpdate()) - needUpdate = true; + if ((*i)->NeedsUpdate()) + return true; } - return needUpdate; + return false; } @@ -215,14 +237,6 @@ printf("Container: Added object (=$%X). size = %li\n", object, objects.size()); } -#if 0 -/*virtual*/ ObjectType Container::Type(void) -{ - return OTContainer; -} -#endif - - void Container::Delete(Object * objectToDelete) { std::vector::iterator i = objects.begin(); @@ -260,15 +274,6 @@ void Container::DeleteSelectedItems(void) 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::iterator i = objects.begin(); while (i != objects.end()) @@ -277,7 +282,6 @@ printf("Container: Deleting object ($%X)...\n", *i); delete (*i); objects.erase(i); } -#endif } diff --git a/src/container.h b/src/container.h index 8744f64..7e6a14d 100644 --- a/src/container.h +++ b/src/container.h @@ -21,16 +21,13 @@ class Container: public Object 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 *); @@ -39,11 +36,11 @@ class Container: public Object public: std::vector objects; + bool isTopLevelContainer; private: bool dragging; bool draggingHandle1; bool draggingHandle2; -// bool needUpdate; bool objectWasDragged; }; diff --git a/src/drawingview.cpp b/src/drawingview.cpp index 330f733..1c095f4 100644 --- a/src/drawingview.cpp +++ b/src/drawingview.cpp @@ -50,8 +50,11 @@ DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent), // 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); @@ -280,6 +283,15 @@ void DrawingView::paintEvent(QPaintEvent * /*event*/) 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); + } } @@ -295,6 +307,14 @@ void DrawingView::mousePressEvent(QMouseEvent * event) 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) { @@ -309,6 +329,7 @@ void DrawingView::mousePressEvent(QMouseEvent * event) 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) { @@ -352,7 +373,7 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event) //changed... document.PointerMoved(point); - if (document.NeedsUpdate()) + if (document.NeedsUpdate() || selectionInProgress) update(); if (toolAction) @@ -378,6 +399,12 @@ void DrawingView::mouseReleaseEvent(QMouseEvent * event) if (toolAction) toolAction->MouseReleased(); + + if (selectionInProgress) + { + // Select all the stuff inside of selection + selectionInProgress = false; + } } else if (event->button() == Qt::MiddleButton) { diff --git a/src/drawingview.h b/src/drawingview.h index ac7170d..eaf8826 100644 --- a/src/drawingview.h +++ b/src/drawingview.h @@ -54,6 +54,8 @@ class DrawingView: public QWidget bool addLineTool; bool addCircleTool; bool addDimensionTool; + bool selectionInProgress; + QRectF selection; public: Action * toolAction; -- 2.37.2