summaryrefslogtreecommitdiffstats
path: root/src/display/canvas-temporary-item-list.cpp
diff options
context:
space:
mode:
authorJohan B. C. Engelen <jbc.engelen@swissonline.ch>2008-03-02 13:38:15 +0000
committerjohanengelen <johanengelen@users.sourceforge.net>2008-03-02 13:38:15 +0000
commitacae310d49358ac8de885fa8692caf5e4067574c (patch)
treeb19affe735ea558718e378184a11031bbe44c328 /src/display/canvas-temporary-item-list.cpp
parentwarning cleanup (diff)
downloadinkscape-acae310d49358ac8de885fa8692caf5e4067574c.tar.gz
inkscape-acae310d49358ac8de885fa8692caf5e4067574c.zip
NEW: temporary on-canvas indicators
(bzr r4918)
Diffstat (limited to 'src/display/canvas-temporary-item-list.cpp')
-rw-r--r--src/display/canvas-temporary-item-list.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/display/canvas-temporary-item-list.cpp b/src/display/canvas-temporary-item-list.cpp
new file mode 100644
index 000000000..5b92e1828
--- /dev/null
+++ b/src/display/canvas-temporary-item-list.cpp
@@ -0,0 +1,83 @@
+/** \file
+ * Provides a class that can contain active TemporaryItem's on a desktop
+ * Code inspired by message-stack.cpp
+ *
+ * Authors:
+ * Johan Engelen
+ *
+ * Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl>
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "display/canvas-temporary-item-list.h"
+
+#include "display/canvas-temporary-item.h"
+
+namespace Inkscape {
+namespace Display {
+
+TemporaryItemList::TemporaryItemList(SPDesktop *desktop)
+ : desktop(desktop)
+{
+
+}
+
+TemporaryItemList::~TemporaryItemList()
+{
+ // delete all items in list so the timeouts are removed
+ for ( std::list<TemporaryItem*>::iterator it = itemlist.begin(); it != itemlist.end(); ++it ) {
+ TemporaryItem * tempitem = *it;
+ delete tempitem;
+ }
+ itemlist.clear();
+}
+
+/* Note that TemporaryItem or TemporaryItemList is responsible for deletion and such, so this return pointer can safely be ignored. */
+TemporaryItem *
+TemporaryItemList::add_item(SPCanvasItem *item, guint lifetime)
+{
+ if (lifetime > 100) { // beware of strange things happening due to very short timeouts
+ TemporaryItem * tempitem = new TemporaryItem(item, lifetime);
+ itemlist.push_back(tempitem);
+ tempitem->signal_timeout.connect( sigc::mem_fun(*this, &TemporaryItemList::_item_timeout) );
+ }
+}
+
+void
+TemporaryItemList::delete_item( TemporaryItem * tempitem )
+{
+ // check if the item is in the list, if so, delete it. (in other words, don't wait for the item to delete itself)
+ bool in_list = false;
+ for ( std::list<TemporaryItem*>::iterator it = itemlist.begin(); it != itemlist.end(); ++it ) {
+ if ( *it == tempitem ) {
+ in_list = true;
+ break;
+ }
+ }
+ if (in_list) {
+ itemlist.remove(tempitem);
+ delete tempitem;
+ }
+}
+
+void
+TemporaryItemList::_item_timeout(TemporaryItem * tempitem)
+{
+ itemlist.remove(tempitem);
+ // no need to delete the item, it does that itself after signal_timeout.emit() completes
+}
+
+} //namespace Display
+} /* namespace Inkscape */
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :