paperbox r111 - in trunk: . src
- From: markoa svn gnome org
- To: svn-commits-list gnome org
- Subject: paperbox r111 - in trunk: . src
- Date: Sun, 9 Mar 2008 00:33:41 +0000 (GMT)
Author: markoa
Date: Sun Mar 9 00:33:40 2008
New Revision: 111
URL: http://svn.gnome.org/viewvc/paperbox?rev=111&view=rev
Log:
Tag cloud below the text view
Modified:
trunk/ChangeLog
trunk/src/category-editor.cc
trunk/src/category-editor.hh
trunk/src/document-tag-cloud-model.cc
trunk/src/document-tag-cloud-model.hh
Modified: trunk/src/category-editor.cc
==============================================================================
--- trunk/src/category-editor.cc (original)
+++ trunk/src/category-editor.cc Sun Mar 9 00:33:40 2008
@@ -23,18 +23,25 @@
#include <list>
#include <gtkmm/stock.h>
#include <gtkmm-utils/dialog.h>
+#include "browser.hh"
#include "category-editor.hh"
#include "category-editor-model.hh"
#include "dialog-entry.hh"
+#include "document.hh"
+#include "document-tag-cloud-model.hh"
#include "paths.hh"
namespace paperbox {
using std::list;
+ using std::vector;
using boost::shared_ptr;
const int DEFAULT_WIDTH = 500;
- const int DEFAULT_HEIGHT = 375;
+ const int DEFAULT_HEIGHT = 375; // try to keep the ratio 4:3
+
+ const int TAG_FONT_SIZE_MIN = 8;
+ const int TAG_FONT_SIZE_MAX = 14;
CategoryEditor::CategoryEditor(
GtkDialog* cobject,
@@ -44,7 +51,8 @@
glade_(glade),
button_new_(Gtk::Stock::NEW),
button_delete_(Gtk::Stock::DELETE),
- button_save_(Gtk::Stock::SAVE)
+ button_save_(Gtk::Stock::SAVE),
+ initial_tag_load_complete_(false)
{
init_gui();
connect_signals();
@@ -94,12 +102,19 @@
label_category_tags_.set_text("Tags contained:");
hbox_contents_->pack_start(label_category_tags_);
hbox_contents_->pack_start(button_save_, false, false);
+ button_save_.set_sensitive(false);
vbox_right_->pack_start(scroll_window_);
scroll_window_.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
scroll_window_.add(text_view_);
text_view_.set_wrap_mode(Gtk::WRAP_WORD);
+ vbox_right_->pack_start(tag_box_);
+ tag_cloud_model_.reset(
+ new DocumentTagCloudModel(TAG_FONT_SIZE_MIN, TAG_FONT_SIZE_MAX));
+ tag_cloud_.set_model(tag_cloud_model_);
+ tag_box_.pack_start(tag_cloud_, true, true);
+
set_default_size(DEFAULT_WIDTH, DEFAULT_HEIGHT);
show_all_children();
@@ -124,6 +139,11 @@
// monitor text view
text_view_.signal_key_release_event().connect(
sigc::mem_fun(*this, &CategoryEditor::on_key_release_event));
+
+ // get notified about new tags through new documents
+ // TODO: what about signals for tags added/removed?
+ Browser::instance()->signal_new_document().connect(
+ sigc::mem_fun(*this, &CategoryEditor::on_new_document));
}
int
@@ -266,4 +286,40 @@
return true;
}
+ void
+ CategoryEditor::on_new_document(const shared_ptr<Document>& doc)
+ {
+ static_cast<DocumentTagCloudModel*>(
+ tag_cloud_model_.get())->update_tags(doc);
+ }
+
+ void
+ CategoryEditor::load_tags()
+ {
+ vector<shared_ptr<Document> > docs;
+ Browser::instance()->get_all_documents(docs);
+
+ vector<shared_ptr<Document> >::iterator it(docs.begin());
+ vector<shared_ptr<Document> >::iterator end(docs.end());
+ for ( ; it != end; ++it)
+ static_cast<DocumentTagCloudModel*>(
+ tag_cloud_model_.get())->update_tags(*it);
+ }
+
+ bool CategoryEditor::on_expose_event(GdkEventExpose* event)
+ {
+ // we need to wait for the window to be drawn as tag cloud
+ // expects its parent's dimensions to be available
+ if (! initial_tag_load_complete_) {
+ load_tags();
+ initial_tag_load_complete_ = true;
+ }
+
+ Gtk::Widget* child_widget = get_child(); // Gtk::Bin method
+ if (child_widget)
+ propagate_expose(*child_widget, event); // Gtk::Container
+
+ return false;
+ }
+
} // namespace paperbox
Modified: trunk/src/category-editor.hh
==============================================================================
--- trunk/src/category-editor.hh (original)
+++ trunk/src/category-editor.hh Sun Mar 9 00:33:40 2008
@@ -31,11 +31,14 @@
#include <gtkmm/textview.h>
#include <libglademm/xml.h>
#include "category-view.hh"
+#include "tag-cloud.hh"
+#include "tag-cloud-model.hh"
namespace paperbox {
class CategoryEditorData;
class CategoryEditorModel;
+ class Document;
class CategoryEditor : public Gtk::Dialog
{
@@ -53,6 +56,7 @@
void init_gui();
void connect_signals();
+ void load_tags();
void load_categories();
void add_new_row(boost::shared_ptr<CategoryEditorData>& data);
@@ -63,6 +67,9 @@
const Gtk::TreeModel::Path& path,
bool path_selected);
bool on_key_release_event(GdkEventKey* key);
+ void on_new_document(const boost::shared_ptr<Document>& doc);
+
+ virtual bool on_expose_event(GdkEventExpose* event);
Glib::RefPtr<Gnome::Glade::Xml> glade_;
@@ -81,6 +88,12 @@
Gtk::ScrolledWindow scroll_window_;
Gtk::TextView text_view_;
+ // tag cloud
+ Gtk::VBox tag_box_;
+ TagCloud tag_cloud_;
+ boost::shared_ptr<TagCloudModel> tag_cloud_model_;
+ bool initial_tag_load_complete_;
+
// the data model
boost::shared_ptr<CategoryEditorModel> model_;
};
Modified: trunk/src/document-tag-cloud-model.cc
==============================================================================
--- trunk/src/document-tag-cloud-model.cc (original)
+++ trunk/src/document-tag-cloud-model.cc Sun Mar 9 00:33:40 2008
@@ -22,11 +22,13 @@
*/
#include "browser.hh"
+#include "document.hh"
#include "document-tag-cloud-model.hh"
namespace paperbox {
using std::vector;
+ using boost::shared_ptr;
DocumentTagCloudModel::DocumentTagCloudModel(int min_font_size,
int max_font_size)
@@ -62,4 +64,14 @@
TagCloudModel::remove_tag(*it_rem);
}
+ void
+ DocumentTagCloudModel::update_tags(const shared_ptr<Document>& doc)
+ {
+ vector<Glib::ustring> tags = doc->get_tags();
+ vector<Glib::ustring>::iterator it(tags.begin());
+ vector<Glib::ustring>::iterator end(tags.end());
+
+ for ( ; it != end; ++it) add_tag(*it);
+ }
+
} // namespace paperbox
Modified: trunk/src/document-tag-cloud-model.hh
==============================================================================
--- trunk/src/document-tag-cloud-model.hh (original)
+++ trunk/src/document-tag-cloud-model.hh Sun Mar 9 00:33:40 2008
@@ -26,17 +26,22 @@
#include <string>
#include <vector>
+#include <boost/shared_ptr.hpp>
#include <glibmm/ustring.h>
#include "tag-cloud-model.hh"
namespace paperbox {
+ class Document;
+
class DocumentTagCloudModel : public TagCloudModel
{
public:
explicit DocumentTagCloudModel(int min_font_size, int max_font_size);
virtual ~DocumentTagCloudModel();
+ virtual void update_tags(const boost::shared_ptr<Document>& doc);
+
protected:
void on_tags_changed(const std::string& uri,
const std::vector<Glib::ustring>& tags_added,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]