paperbox r195 - in trunk: . src



Author: markoa
Date: Sat Oct  4 16:41:19 2008
New Revision: 195
URL: http://svn.gnome.org/viewvc/paperbox?rev=195&view=rev

Log:
Display tags as labels on unselected document tiles

Modified:
   trunk/ChangeLog
   trunk/src/document-tile.cc
   trunk/src/document-tile.hh

Modified: trunk/src/document-tile.cc
==============================================================================
--- trunk/src/document-tile.cc	(original)
+++ trunk/src/document-tile.cc	Sat Oct  4 16:41:19 2008
@@ -42,6 +42,8 @@
         Gtk::Util::Tile(doc->get_file_name(), doc->get_author(), false),
         uri_(doc->get_uri()),
         tag_hbox_(false, 4),
+        tag_labels_hbox_(false, 4),
+        tag_links_hbox_(false, 4),
         tag_tools_hbox_(false, 4),
         tags_caption_(_("Tags:")),
         image_add_(Gtk::Stock::ADD, Gtk::ICON_SIZE_MENU),
@@ -49,7 +51,7 @@
     {
         connect_thumbnailer_signals(thumbnailer);
 
-        Gtk::VBox&  content_vbox = get_content_vbox();
+        Gtk::VBox& content_vbox = get_content_vbox();
 
         int page_count = doc->get_page_count();
 
@@ -73,11 +75,17 @@
         button_add_tags_.add(image_add_);
         tag_tools_hbox_.pack_start(button_add_tags_, false, false, 0);
 
+        tag_hbox_.pack_start(tag_labels_hbox_, false, false, 0);
+
         // Build tag links from tag string
         vector<ustring> tags = doc->get_tags();
         vector<ustring> removed(0); // none
         refresh_tag_links(tags, removed);
         pack_tag_links();
+
+        refresh_tag_labels(tags, removed);
+        pack_tag_labels();
+
         content_vbox.pack_start(tag_hbox_, false, false, 0);
 
         connect_signals();
@@ -86,6 +94,7 @@
     DocumentTile::~DocumentTile()
     {
         tag_links_.clear();
+        tag_labels_.clear();
     }
 
     ustring
@@ -151,6 +160,31 @@
         return dynamic_cast<Gtk::Widget*>(widget);
     }
 
+    Gtk::Widget*
+    DocumentTile::get_tag_label(const string& tag)
+    {
+        Gtk::Label* widget = 0;
+        tag_label_map::iterator label_iter = tag_labels_.find(tag);
+
+        if (label_iter != tag_labels_.end()) {
+            widget = static_cast<Gtk::Label*>(label_iter->second.get());
+        } else {
+            widget = new Gtk::Label(tag);
+
+            // lighten up the colour a bit
+            GdkColor color;
+            gdk_color_parse ("DarkSlateGray", &color);
+            gtk_widget_modify_fg (GTK_WIDGET(widget->gobj()),
+                                  GTK_STATE_NORMAL,
+                                  &color);
+            
+            shared_ptr<Gtk::Widget> shared_widget(widget);
+            tag_labels_[tag] = shared_widget;
+        }
+
+        return dynamic_cast<Gtk::Widget*>(widget);
+    }
+
     void
     DocumentTile::refresh_tag_links(const vector<ustring>& tags_added,
                                     const vector<ustring>& tags_removed)
@@ -174,6 +208,30 @@
             }
         }
     }
+    
+    void
+    DocumentTile::refresh_tag_labels(const vector<ustring>& tags_added,
+                                     const vector<ustring>& tags_removed)
+    {
+        {
+            vector<ustring>::const_iterator it(tags_added.begin());
+            vector<ustring>::const_iterator end(tags_added.end());
+
+            for ( ; it != end; ++it)
+                get_tag_label(it->raw()); // create or do nothing
+        }
+
+        {
+            vector<ustring>::const_iterator it(tags_removed.begin());
+            vector<ustring>::const_iterator end(tags_removed.end());
+
+            for ( ; it != end; ++it) {
+                tag_label_map::iterator label_it = tag_labels_.find(it->raw());
+                if (label_it != tag_labels_.end())
+                    tag_labels_.erase(label_it);
+            }
+        }
+    }
 
     void
     DocumentTile::pack_tag_links()
@@ -184,7 +242,7 @@
         for ( ; it != end; ++it) {
             Gtk::Widget* link_widget = it->second.get();
             link_widget->show();
-            tag_hbox_.pack_start(*link_widget, false, false, 0);
+            tag_links_hbox_.pack_start(*link_widget, false, false, 0);
         }
     }
 
@@ -198,7 +256,32 @@
             TagLinkButton* button =
                 static_cast<TagLinkButton*>(it->second.get());
 
-            tag_hbox_.remove(*button);
+            tag_links_hbox_.remove(*button);
+        }
+    }
+    
+    void
+    DocumentTile::pack_tag_labels()
+    {
+        tag_label_map::iterator it(tag_labels_.begin());
+        tag_label_map::iterator end(tag_labels_.end());
+
+        for ( ; it != end; ++it) {
+            Gtk::Widget* label = it->second.get();
+            label->show();
+            tag_labels_hbox_.pack_start(*label, false, false, 0);
+        }
+    }
+
+    void
+    DocumentTile::unpack_tag_labels()
+    {
+        tag_label_map::iterator it(tag_labels_.begin());
+        tag_label_map::iterator end(tag_labels_.end());
+
+        for ( ; it != end; ++it) {
+            Gtk::Label* label = static_cast<Gtk::Label*>(it->second.get());
+            tag_labels_hbox_.remove(*label);
         }
     }
 
@@ -214,15 +297,18 @@
         Gtk::VBox& content_vbox = get_content_vbox();
 
         if (first_boot_) {
-            content_vbox.pack_start(extra_hbox_, false, false, 0);
-            content_vbox.pack_start(time_hbox_, false, false, 0);
+            content_vbox.pack_start(extra_hbox_, false, false);
+            content_vbox.pack_start(time_hbox_, false, false);
 
-            tag_hbox_.pack_start(tag_tools_hbox_, false, false, 0);
+            tag_hbox_.pack_start(tag_links_hbox_, false, false);
+            tag_hbox_.pack_start(tag_tools_hbox_, false, false);
 
-            content_vbox.show_all();
+            //content_vbox.show_all();
             first_boot_ = false;
         }
 
+        tag_links_hbox_.show_all();
+
         content_vbox.reorder_child(extra_hbox_, 2);
         content_vbox.reorder_child(time_hbox_, 3);
         tag_hbox_.reorder_child(tag_tools_hbox_, 0);
@@ -231,6 +317,8 @@
         time_hbox_.show_all();
         tag_tools_hbox_.show_all();
 
+        tag_labels_hbox_.hide();
+
         get_image().set(thumbnail_large_);
     }
 
@@ -241,6 +329,9 @@
         time_hbox_.hide();
         tag_tools_hbox_.hide();
 
+        tag_labels_hbox_.show_all();
+        tag_links_hbox_.hide();
+
         get_image().set(thumbnail_small_);
     }
 
@@ -277,7 +368,7 @@
     }
 
     void
-    DocumentTile::on_taglink(Gtk::LinkButton */*button*/,
+    DocumentTile::on_taglink(Gtk::LinkButton* /* button */,
                              const ustring& uri)
     {
         signal_tag_clicked_.emit(uri);
@@ -302,6 +393,10 @@
         unpack_tag_links();
         refresh_tag_links(tags_added, tags_removed);
         pack_tag_links();
+
+        unpack_tag_labels();
+        refresh_tag_labels(tags_added, tags_removed);
+        pack_tag_labels();
     }
 
     void

Modified: trunk/src/document-tile.hh
==============================================================================
--- trunk/src/document-tile.hh	(original)
+++ trunk/src/document-tile.hh	Sat Oct  4 16:41:19 2008
@@ -38,12 +38,15 @@
 namespace paperbox {
 
     // Definition of the hash map where we'll store dynamically created
-    // tag link widgets. Thus we use one widget per tag.
+    // tag link widgets. We use one widget per tag.
     typedef std::map<std::string,
                      boost::shared_ptr<Gtk::Widget>,
                      std::less<std::string> >
     tag_link_map;
 
+    // The map for tag labels. Again, one label per tag.
+    typedef tag_link_map tag_label_map;
+
     class DocumentTile : public Gtk::Util::Tile
     {
     public:
@@ -68,6 +71,7 @@
         virtual void connect_signals();
 
         virtual Gtk::Widget* get_tag_link(const std::string& tag);
+        virtual Gtk::Widget* get_tag_label(const std::string& tag);
 
         virtual void pack_tag_links();
         virtual void unpack_tag_links();
@@ -76,6 +80,13 @@
             const std::vector<Glib::ustring>& tags_added,
             const std::vector<Glib::ustring>& tags_removed);
 
+        virtual void pack_tag_labels();
+        virtual void unpack_tag_labels();
+
+        virtual void refresh_tag_labels(
+            const std::vector<Glib::ustring>& tags_added,
+            const std::vector<Glib::ustring>& tags_removed);
+
         // Tile overrides
         virtual void on_selected();
         virtual void on_unselected();
@@ -109,12 +120,15 @@
         Gtk::HBox   time_hbox_;
         Gtk::Label  modtime_label_;
         Gtk::HBox   tag_hbox_;
+        Gtk::HBox   tag_labels_hbox_;
+        Gtk::HBox   tag_links_hbox_;
         Gtk::HBox   tag_tools_hbox_;
         Gtk::Label  tags_caption_;
         Gtk::Button button_add_tags_;
         Gtk::Image  image_add_;
 
         tag_link_map tag_links_;
+        tag_label_map tag_labels_;
 
         bool first_boot_;
     };



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]