summaryrefslogtreecommitdiffstats
path: root/src/selection.cpp
diff options
context:
space:
mode:
authorMatthew Petroff <matthew@mpetroff.net>2013-07-17 05:13:49 +0000
committerMatthew Petroff <matthew@mpetroff.net>2013-07-17 05:13:49 +0000
commitdd59aa3bb2cab030296a4622e5166f0e3f8d5445 (patch)
treea86612c94d3ddce3edf696ea17fefb58b0accccf /src/selection.cpp
parentTemporary fixes/kludges. (diff)
parentShape calculations. re-introduce grid of a smaller size. (http://article.gman... (diff)
downloadinkscape-dd59aa3bb2cab030296a4622e5166f0e3f8d5445.tar.gz
inkscape-dd59aa3bb2cab030296a4622e5166f0e3f8d5445.zip
Merge from trunk.
(bzr r12380.1.17)
Diffstat (limited to 'src/selection.cpp')
-rw-r--r--src/selection.cpp45
1 files changed, 37 insertions, 8 deletions
diff --git a/src/selection.cpp b/src/selection.cpp
index 564f1fdd3..784219c88 100644
--- a/src/selection.cpp
+++ b/src/selection.cpp
@@ -21,9 +21,8 @@
#endif
#include "macros.h"
#include "inkscape-private.h"
-#include "desktop.h"
-#include "desktop-handles.h"
#include "document.h"
+#include "layer-model.h"
#include "selection.h"
#include <2geom/rect.h>
#include "xml/repr.h"
@@ -42,10 +41,11 @@
namespace Inkscape {
-Selection::Selection(SPDesktop *desktop) :
+Selection::Selection(LayerModel *layers, SPDesktop *desktop) :
_objs(NULL),
_reprs(NULL),
_items(NULL),
+ _layers(layers),
_desktop(desktop),
_selection_context(NULL),
_flags(0),
@@ -55,7 +55,7 @@ Selection::Selection(SPDesktop *desktop) :
Selection::~Selection() {
_clear();
- _desktop = NULL;
+ _layers = NULL;
if (_idle) {
g_source_remove(_idle);
_idle = 0;
@@ -96,7 +96,7 @@ void Selection::_emitModified(guint flags) {
void Selection::_emitChanged(bool persist_selection_context/* = false */) {
if (persist_selection_context) {
if (NULL == _selection_context) {
- _selection_context = desktop()->currentLayer();
+ _selection_context = _layers->currentLayer();
sp_object_ref(_selection_context, NULL);
_context_release_connection = _selection_context->connectRelease(sigc::mem_fun(*this, &Selection::_releaseContext));
}
@@ -139,7 +139,7 @@ void Selection::_clear() {
SPObject *Selection::activeContext() {
if (NULL != _selection_context)
return _selection_context;
- return desktop()->currentLayer();
+ return _layers->currentLayer();
}
bool Selection::includes(SPObject *obj) const {
@@ -358,6 +358,35 @@ SPItem *Selection::singleItem() {
}
}
+SPItem *Selection::smallestItem(Selection::CompareSize compare) {
+ return _sizeistItem(true, compare);
+}
+
+SPItem *Selection::largestItem(Selection::CompareSize compare) {
+ return _sizeistItem(false, compare);
+}
+
+SPItem *Selection::_sizeistItem(bool sml, Selection::CompareSize compare) {
+ GSList const *items = const_cast<Selection *>(this)->itemList();
+ gdouble max = sml ? 1e18 : 0;
+ SPItem *ist = NULL;
+
+ for ( GSList const *i = items; i != NULL ; i = i->next ) {
+ Geom::OptRect obox = SP_ITEM(i->data)->desktopPreferredBounds();
+ if (!obox || obox.isEmpty()) continue;
+ Geom::Rect bbox = *obox;
+
+ gdouble size = compare == 2 ? bbox.area() :
+ (compare == 1 ? bbox.width() : bbox.height());
+ size = sml ? size : size * -1;
+ if (size < max) {
+ max = size;
+ ist = SP_ITEM(i->data);
+ }
+ }
+ return ist;
+}
+
Inkscape::XML::Node *Selection::singleRepr() {
SPObject *obj=single();
return obj ? obj->getRepr() : NULL;
@@ -487,7 +516,7 @@ SPObject *Selection::_objectForXMLNode(Inkscape::XML::Node *repr) const {
g_return_val_if_fail(repr != NULL, NULL);
gchar const *id = repr->attribute("id");
g_return_val_if_fail(id != NULL, NULL);
- SPObject *object=sp_desktop_document(_desktop)->getObjectById(id);
+ SPObject *object=_layers->getDocument()->getObjectById(id);
g_return_val_if_fail(object != NULL, NULL);
return object;
}
@@ -496,7 +525,7 @@ guint Selection::numberOfLayers() {
GSList const *items = const_cast<Selection *>(this)->itemList();
GSList *layers = NULL;
for (GSList const *iter = items; iter != NULL; iter = iter->next) {
- SPObject *layer = desktop()->layerForObject(SP_OBJECT(iter->data));
+ SPObject *layer = _layers->layerForObject(SP_OBJECT(iter->data));
if (g_slist_find (layers, layer) == NULL) {
layers = g_slist_prepend (layers, layer);
}