[glom] ImageGlom: Size request corrections.



commit adf070558b1097e0a06de4208e63d759c63ff2b1
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Jul 12 13:34:55 2011 +0200

    ImageGlom: Size request corrections.
    
    	* glom/utility_widgets/imageglom.cc: init(): Remove the set_size_request()
    	call which does not seem necessary.
    	Do not call set_image(original) after scale(), because scale() does that,
    	setting the scaled image.
    	This avoids the GtkImage being huge, because GtkImage re-requests the
    	bigger size again when the original is put in it.
    	This is still not ideal. It would be nicer if we could just say "do not
    	make the window bigger than the screen, or do not make this make the
    	window bigger."

 ChangeLog                         |   14 ++++++++++++++
 glom/utility_widgets/imageglom.cc |   35 +++++++++++++++++++++++------------
 2 files changed, 37 insertions(+), 12 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index aafa4a2..073435d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 2011-07-12  Murray Cumming  <murrayc murrayc com>
 
+	ImageGlom: Size request corrections.
+
+	* glom/utility_widgets/imageglom.cc: init(): Remove the set_size_request() 
+	call which does not seem necessary.
+	Do not call set_image(original) after scale(), because scale() does that, 
+	setting the scaled image.
+	This avoids the GtkImage being huge, because GtkImage re-requests the 
+	bigger size again when the original is put in it.
+	This is still not ideal. It would be nicer if we could just say "do not 
+	make the window bigger than the screen, or do not make this make the 
+	window bigger."
+
+2011-07-12  Murray Cumming  <murrayc murrayc com>
+
 	ImageGlom: Use AppInfo instead of gtk_show_uri() for Open.
 
 	* glom/utility_widgets/imageglom.cc: For the case that we have no AppInfo
diff --git a/glom/utility_widgets/imageglom.cc b/glom/utility_widgets/imageglom.cc
index fa66ef9..c240079 100644
--- a/glom/utility_widgets/imageglom.cc
+++ b/glom/utility_widgets/imageglom.cc
@@ -57,7 +57,7 @@ void ImageGlom::init()
 
   setup_menu_usermode();
 
-  m_image.set_size_request(150, 150);
+  //m_image.set_size_request(150, 150);
   m_image.show();
 
   m_frame.set_shadow_type(Gtk::SHADOW_ETCHED_IN); //Without this, the image widget has no borders and is completely invisible when empty.
@@ -152,8 +152,6 @@ bool ImageGlom::get_has_original_data() const
 void ImageGlom::set_pixbuf(const Glib::RefPtr<Gdk::Pixbuf>& pixbuf)
 {
   m_pixbuf_original = pixbuf;
-  m_image.set(m_pixbuf_original);
-
   scale();
 }
 
@@ -166,8 +164,8 @@ void ImageGlom::set_value(const Gnome::Gda::Value& value)
 
   if(pixbuf)
   {
-    set_pixbuf(pixbuf);
     scale();
+    set_pixbuf(pixbuf);
   }
   else
   {
@@ -282,11 +280,26 @@ void ImageGlom::scale()
     const Gtk::Allocation allocation = m_image.get_allocation();
     const int pixbuf_height = pixbuf->get_height();
     const int pixbuf_width = pixbuf->get_width();
-
-    if( (pixbuf_height > allocation.get_height()) ||
-        (pixbuf_width > allocation.get_width()) )
+    
+    int allocation_height = allocation.get_height();
+    int allocation_width = allocation.get_width();
+    
+    //If the Image widget has expanded to be big enough for the original image,
+    //it might be huge. We don't want that.
+    //Scaling it down will reduce how much it requests.
+    if(allocation_width >= 400)
+      allocation_width = 400;
+      
+    if(allocation_height >= 400)
+      allocation_height = 400;
+      
+    std::cout << "pixbuf_height=" << pixbuf_height << ", pixbuf_width=" << pixbuf_width << std::endl;
+    std::cout << "allocation_height=" << allocation.get_height() << ", allocation_width=" << allocation.get_width() << std::endl;
+
+    if( (pixbuf_height >allocation_height ) ||
+        (pixbuf_width > allocation_width) )
     {
-      if(allocation.get_height() > 10 || allocation.get_width() > 10)
+      if(allocation_height > 10 || allocation_width > 10)
       {
         Glib::RefPtr<Gdk::Pixbuf> pixbuf_scaled = Utils::image_scale_keeping_ratio(pixbuf, allocation.get_height(), allocation.get_width());
         if(!pixbuf_scaled)
@@ -295,7 +308,7 @@ void ImageGlom::scale()
         }
         else 
         {
-          //Don't set a new pixbuf if the dimenstions have not changed:
+          //Don't set a new pixbuf if the dimensions have not changed:
           Glib::RefPtr<const Gdk::Pixbuf> pixbuf_in_image;
 
           if(m_image.get_storage_type() == Gtk::IMAGE_PIXBUF) //Prevent warning.
@@ -485,7 +498,6 @@ void ImageGlom::on_menupopup_activate_select_file()
           gda_value_take_binary(m_original_data.gobj(), bin);
 
           m_pixbuf_original = dialog->get_pixbuf();
-          m_image.set(m_pixbuf_original); //Load the image.
           scale();
           signal_edited().emit();
         }
@@ -550,9 +562,8 @@ void ImageGlom::on_clipboard_received_image(const Glib::RefPtr<Gdk::Pixbuf>& pix
     m_original_data = Gnome::Gda::Value();
 
     m_pixbuf_original = pixbuf;
-
-    m_image.set(m_pixbuf_original); //Load the image.
     scale();
+
     signal_edited().emit();
   }
 }



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