[niepce] New widget to override tab in the TextView. Use it in the text metadata



commit 87f67504f75b56b1f4e0d690922b79023d4e84f1
Author: Hub Figuiere <hub figuiere net>
Date:   Sat Nov 12 21:48:57 2011 -0800

    New widget to override tab in the TextView.
    Use it in the text metadata

 src/fwk/toolkit/Makefile.am               |    1 +
 src/fwk/toolkit/metadatawidget.cpp        |   63 ++++++++++++++++++++++++++++-
 src/fwk/toolkit/metadatawidget.hpp        |    2 +
 src/fwk/toolkit/widgets/notabtextview.cpp |   48 ++++++++++++++++++++++
 src/fwk/toolkit/widgets/notabtextview.hpp |   46 +++++++++++++++++++++
 5 files changed, 158 insertions(+), 2 deletions(-)
---
diff --git a/src/fwk/toolkit/Makefile.am b/src/fwk/toolkit/Makefile.am
index 10850f5..e31bfe2 100644
--- a/src/fwk/toolkit/Makefile.am
+++ b/src/fwk/toolkit/Makefile.am
@@ -35,6 +35,7 @@ libniepceframework_a_SOURCES = configuration.hpp configuration.cpp \
 	widgets/toolboxitemwidget.hpp widgets/toolboxitemwidget.cpp \
 	widgets/editablehscale.hpp widgets/editablehscale.cpp \
 	widgets/dock.cpp widgets/dock.hpp \
+	widgets/notabtextview.hpp widgets/notabtextview.cpp \
 	dockable.hpp dockable.cpp \
 	metadatawidget.hpp metadatawidget.cpp \
 	undo.hpp undo.cpp \
diff --git a/src/fwk/toolkit/metadatawidget.cpp b/src/fwk/toolkit/metadatawidget.cpp
index 5fb0c48..1ae41ef 100644
--- a/src/fwk/toolkit/metadatawidget.cpp
+++ b/src/fwk/toolkit/metadatawidget.cpp
@@ -25,6 +25,7 @@
 #include <glibmm/i18n.h>
 #include <gtkmm/label.h>
 #include <gtkmm/entry.h>
+#include <gtkmm/textview.h>
 
 #include "fwk/base/debug.hpp"
 #include "fwk/base/autoflag.hpp"
@@ -32,6 +33,7 @@
 #include "fwk/utils/exempi.hpp"
 #include "fwk/utils/stringutils.hpp"
 #include "fwk/toolkit/widgets/ratinglabel.hpp"
+#include "fwk/toolkit/widgets/notabtextview.hpp"
 
 // remove
 #include "engine/db/properties.hpp"
@@ -69,6 +71,10 @@ void MetaDataWidget::clear_widget(std::pair<const PropertyIndex, Gtk::Widget *>
         e->set_text("");
         return;
     }
+    Gtk::TextView * tv = dynamic_cast<Gtk::TextView*>(p.second);
+    if(tv) {
+        tv->get_buffer()->set_text("");
+    }
     fwk::RatingLabel * rl = dynamic_cast<fwk::RatingLabel*>(p.second);
     if(rl) {
         rl->set_rating(0);
@@ -128,7 +134,10 @@ void MetaDataWidget::add_data(const MetaDataFormat * current,
         labelw->set_alignment(0.0f, 0.5f);
         labelw->set_use_markup(true);
 
-        if(current->type == META_DT_STAR_RATING) {
+        switch(current->type)
+        {
+        case META_DT_STAR_RATING:
+        {
             fwk::RatingLabel * r = Gtk::manage(new fwk::RatingLabel(0, !current->readonly));
             if(!current->readonly) {
                 r->signal_changed.connect(
@@ -138,8 +147,29 @@ void MetaDataWidget::add_data(const MetaDataFormat * current,
                         current->id));
             }
             w = r;
+            break;
         }
-        else {
+        case META_DT_TEXT:
+        {
+            if(current->readonly) {
+                Gtk::Label * l = Gtk::manage(new Gtk::Label());
+                l->set_alignment(0.0f, 0.5f);
+                w = l;
+            }
+            else {
+                Gtk::TextView * e = Gtk::manage(new NoTabTextView());
+                e->set_editable(true);
+                e->set_wrap_mode(Gtk::WRAP_WORD);
+                e->signal_focus_out_event().connect(
+                    sigc::bind(
+                        sigc::mem_fun(*this, 
+                                      &MetaDataWidget::on_text_changed),
+                        e->get_buffer(), current->id));
+                w = e;
+            }
+            break;
+        }
+        default:
             if(current->readonly) {
                 Gtk::Label * l = Gtk::manage(new Gtk::Label());
                 l->set_alignment(0.0f, 0.5f);
@@ -154,6 +184,7 @@ void MetaDataWidget::add_data(const MetaDataFormat * current,
                         e, current->id));
                 w = e;
             }
+            break;
         }
 
         m_table.resize(n_row + 1, 2);
@@ -192,6 +223,22 @@ void MetaDataWidget::add_data(const MetaDataFormat * current,
         }
         break;
     }
+    case META_DT_TEXT:
+    {
+        try {
+            AutoFlag flag(m_update);
+            if(current->readonly) {
+                static_cast<Gtk::Label*>(w)->set_text(boost::get<std::string>(value));
+            }
+            else {
+                static_cast<Gtk::TextView*>(w)->get_buffer()->set_text(boost::get<std::string>(value));
+            }
+        }
+        catch(...) {
+            DBG_OUT("conversion of '%u' to int failed", current->id);
+        }
+        break;
+    }
     default:
         try {
             AutoFlag flag(m_update);
@@ -220,6 +267,18 @@ bool MetaDataWidget::on_str_changed(GdkEventFocus*, Gtk::Entry *e,
     return true;
 }
 
+bool MetaDataWidget::on_text_changed(GdkEventFocus*, 
+                                     Glib::RefPtr<Gtk::TextBuffer> b, 
+                                     fwk::PropertyIndex prop)
+{
+    if(m_update) {
+        return true;
+    }
+    emit_metadata_changed(prop, 
+                          fwk::PropertyValue(b->get_text()));
+    return true;
+}
+
 void MetaDataWidget::on_int_changed(int value, fwk::PropertyIndex prop)
 {
     if(m_update) {
diff --git a/src/fwk/toolkit/metadatawidget.hpp b/src/fwk/toolkit/metadatawidget.hpp
index b73ac23..56c74b9 100644
--- a/src/fwk/toolkit/metadatawidget.hpp
+++ b/src/fwk/toolkit/metadatawidget.hpp
@@ -25,6 +25,7 @@
 #include <string>
 
 #include <gtkmm/table.h>
+#include <gtkmm/textview.h>
 
 #include "fwk/base/propertybag.hpp"
 #include "fwk/toolkit/widgets/toolboxitemwidget.hpp"
@@ -75,6 +76,7 @@ public:
     sigc::signal<void, const fwk::PropertyBag &, const fwk::PropertyBag &> signal_metadata_changed;
 protected:
     bool on_str_changed(GdkEventFocus*, Gtk::Entry *, fwk::PropertyIndex prop);
+    bool on_text_changed(GdkEventFocus*, Glib::RefPtr<Gtk::TextBuffer> b, fwk::PropertyIndex prop);
     void on_int_changed(int, fwk::PropertyIndex prop);
 private:
     void clear_widget(std::pair<const PropertyIndex, Gtk::Widget *> & p);
diff --git a/src/fwk/toolkit/widgets/notabtextview.cpp b/src/fwk/toolkit/widgets/notabtextview.cpp
new file mode 100644
index 0000000..d1ef6f2
--- /dev/null
+++ b/src/fwk/toolkit/widgets/notabtextview.cpp
@@ -0,0 +1,48 @@
+/*
+ * niepce - fwk/toolkit/widgets/notabtextview.cpp
+ *
+ * Copyright (C) 2011 Hubert Figuiere
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+
+#include "fwk/base/debug.hpp"
+
+#include "notabtextview.hpp"
+
+
+namespace fwk {
+
+bool NoTabTextView::on_key_press_event(GdkEventKey *event)
+{
+    if(event->keyval == GDK_KEY_Tab) {
+        get_parent()->child_focus(Gtk::DIR_TAB_FORWARD);
+        return true;
+    }
+    return Gtk::TextView::on_key_press_event(event);
+}
+
+
+}
+/*
+  Local Variables:
+  mode:c++
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0))
+  indent-tabs-mode:nil
+  fill-column:80
+  End:
+*/
diff --git a/src/fwk/toolkit/widgets/notabtextview.hpp b/src/fwk/toolkit/widgets/notabtextview.hpp
new file mode 100644
index 0000000..3b13b8b
--- /dev/null
+++ b/src/fwk/toolkit/widgets/notabtextview.hpp
@@ -0,0 +1,46 @@
+/*
+ * niepce - fwk/toolkit/widgets/notabtextview.cpp
+ *
+ * Copyright (C) 2011 Hubert Figuiere
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __FWK_WIDGET_NOTABTEXTVIEW_H__
+#define __FWK_WIDGET_NOTABTEXTVIEW_H__
+
+#include <gtkmm/textview.h>
+
+namespace fwk {
+
+/** a Gtk::TextView widget that disallow tab*/
+class NoTabTextView
+    : public Gtk::TextView
+{
+    virtual bool on_key_press_event(GdkEventKey *event);
+};
+
+}
+
+#endif
+/*
+  Local Variables:
+  mode:c++
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0))
+  indent-tabs-mode:nil
+  fill-column:80
+  End:
+*/



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