Author: tian
Date: Tue Mar 29 23:41:17 2016
New Revision: 2276

URL: http://svn.gna.org/viewcvs/gcstar?rev=2276&view=rev
Log:
Fixed issue with pictures not immediately shown (with a hack) and simplified 
the layout

Modified:
    trunk/gcstar/lib/gcstar/GCGraphicComponents/GCPictureWidgets.pm

Modified: trunk/gcstar/lib/gcstar/GCGraphicComponents/GCPictureWidgets.pm
URL: 
http://svn.gna.org/viewcvs/gcstar/trunk/gcstar/lib/gcstar/GCGraphicComponents/GCPictureWidgets.pm?rev=2276&r1=2275&r2=2276&view=diff
==============================================================================
--- trunk/gcstar/lib/gcstar/GCGraphicComponents/GCPictureWidgets.pm     
(original)
+++ trunk/gcstar/lib/gcstar/GCGraphicComponents/GCPictureWidgets.pm     Tue Mar 
29 23:41:17 2016
@@ -90,6 +90,7 @@
         if ($self->{immediate})
         {
             $self->setPicture;
+            $placer->placeImg if $placer;
         }
         else
         {
@@ -200,7 +201,6 @@
     {
         my $self = shift;
         $self->SUPER::setChanged;
-        print "NOTIFY : ",$self->{watcher},"\n";
         $self->{watcher}->notifyImgChange($self) if $self->{watcher};   
     }
     
@@ -241,14 +241,21 @@
         my ($self) = @_;
         my ($picWidth, $picHeight) = $self->{img}->getSize;
         my ($buttonWidth, $buttonHeight) = ($self->allocation->width, 
$self->allocation->height);
-        my $x = ($buttonWidth - $picWidth - $GCUtils::margin)/ 2;
-        my $y = ($buttonHeight -$picHeight - $GCUtils::margin)/ 2;
+        my $x = int(($buttonWidth - $picWidth - $GCUtils::margin)/ 2);
+        my $y = int(($buttonHeight -$picHeight - $GCUtils::margin)/ 2);
 
         # Don't allow negative positions, can happen when button has not been 
allocated a width/height yet
         $x = 0 if ($x < 0);
         $y = 0 if ($y < 0);
-        #print "";
-        $self->{layout}->move($self->{img}, $x, $y);
+        if ($self->{img}->parent)
+        {   
+            $self->{layout}->move($self->{img}, $x, $y);
+        }
+        else
+        {
+            $self->{layout}->put($self->{img}, $x, $y);
+            $self->show_all;
+        }
     }
 
     sub changeState
@@ -524,7 +531,7 @@
 
         $self->{layout} = new Gtk2::Fixed;
         $self->{layout}->put($img, 0, 0);
-        $self->add($self->{layout});
+         $self->add($self->{layout});
         
         $self->{img} = $img;
         $self->{default} = $default;
@@ -826,10 +833,10 @@
     package GCImageListWidget;
     
         use Glib::Object::Subclass
-                Gtk2::HBox::
+                Gtk2::VBox::
     ;
     
-    @GCImageListWidget::ISA = ('Gtk2::HBox', 'GCGraphicComponent');
+    @GCImageListWidget::ISA = ('Gtk2::VBox', 'GCGraphicComponent');
     
     
     
@@ -848,14 +855,14 @@
         
                my $hboxActions = new Gtk2::HBox(0,0);
 
-        $self->{box} = new Gtk2::VBox(0,0);
+        #$self->{box} = new Gtk2::VBox(0,0);
 
         # If list belongs to an expander, set box size to a reasonable size
-        $self->{box}->{signalHandler} = 
$self->{box}->signal_connect('size-allocate' => sub {
+        $self->{signalHandler} = $self->signal_connect('size-allocate' => sub {
             if (($self->{realParent}) && 
($self->{realParent}->isa('GCExpander')))
             {
                 my $width = $self->allocation->width - ( 2 * $GCUtils::margin) 
;
-                $self->{box}->set_size_request(($width >= -1) ? $width : -1 , 
-1);
+                $self->set_size_request(($width >= -1) ? $width : -1 , -1);
                 return 0;
             }
         });
@@ -867,7 +874,9 @@
         $scroll->set_shadow_type('etched-in');
         $scroll->set_size_request(-1, 120);
         $scroll->add_with_viewport($self->{list});
-        $self->{box}->pack_start($scroll, 1, 1, 2);
+        $self->pack_start($scroll, 1, 1, 2);
+        
+        
         if (!$readonly)
         {
             $self->{addButton} = GCButton->newFromStock('gtk-add', 0);
@@ -875,7 +884,7 @@
                 $self->addImage;
                 $self->show_all;
                 $self->setChanged;
-                
+                $self->forceDisplay;                
             });
             $self->{removeButton} = GCButton->newFromStock('gtk-remove', 0);
             $hboxActions->pack_start($self->{addButton}, 0, 0, 6);
@@ -891,7 +900,7 @@
             $hboxActions->pack_start($self->{removeButton}, 1, 0, 6);
             $hboxActions->pack_start($self->{clearButton}, 1, 0, 6);
         }
-        $self->{box}->pack_start($hboxActions, 0, 0, 6)
+        $self->pack_start($hboxActions, 0, 0, 6)
             if $readonly < 2;
 
         $self->{removeButton}->signal_connect('clicked' => sub {
@@ -916,12 +925,23 @@
         });
         
 
-        $self->pack_start($self->{box},1,$self->{readonly},0);
+        #$self->pack_start($self->{box},1,$self->{readonly},0);
         
 
 
         bless ($self, $class);
         return $self;
+    }
+
+    sub forceDisplay
+    {
+        my $self = shift;
+        #FIXME Without this hack, the pictures are not initially shown until 
something is done
+        #It seems to force a refresh
+        Glib::Timeout->add(100, sub {
+            $self->{list}->signal_emit('size-allocate', 
Gtk2::Gdk::Rectangle->new(0,0,$self->{list}->allocation->width,$self->{list}->allocation->height));
+            return 0;
+        });
     }
 
     sub activateStateTracking
@@ -947,7 +967,7 @@
     sub expand
     {
         my $self = shift;
-        $self->set_child_packing($self->{box},1,1,0,'start');
+        $self->set_child_packing($self,1,1,0,'start');
     }
 
     sub addImage
@@ -956,7 +976,7 @@
         my $img = new GCItemImage($self->{parent}->{options}, 
                                   $self->{parent},
                                   0,
-                                  3000,
+                                  300,
                                   300);
         my $isCover = 0;
         my $widget = new GCImageButton($self->{parent}, $img, $isCover, 
$self->{default});
@@ -967,35 +987,11 @@
         my ($lineWhereToAdd, $colWhereToAdd) = (0,0);
         my @children = $self->{list}->get_children;
         my $nbChildren = scalar @children;
-        if (($nbChildren % $self->{itemsPerRow}) == 0)
-        {
-            
-        }
         $lineWhereToAdd = int($nbChildren / $self->{itemsPerRow});
         $colWhereToAdd = $nbChildren % $self->{itemsPerRow};
         $self->{list}->attach($widget, $colWhereToAdd, $colWhereToAdd + 1, 
$lineWhereToAdd, $lineWhereToAdd + 1,
                               ['fill', 'expand'], ['fill'], 0, 0);
 
-#        my @children = $self->{list}->get_children;
-#        use Data::Dumper;
-#        print "CHILDREN ",," :: ",Dumper(\@children),"\n";
-#        my $lastHBox = 0;
-#        if (scalar @children)
-#        {
-#            $lastHBox = $children[-1];
-#        }
-#        print "GOT ",$lastHBox,"\n";
-#        my @hboxChildren = 0;
-#        @hboxChildren = $lastHBox->get_children if $lastHBox;
-#        print "SCALAR ",scalar @hboxChildren,"\n" if $lastHBox;
-#        if (!$lastHBox || ((scalar @hboxChildren) == $self->{itemsPerRow}))
-#        {
-#            print "Compared ", scalar $lastHBox->get_children," with 
",$self->{itemsPerRow},"\n" if $lastHBox;
-#            $lastHBox = new Gtk2::HBox(0,0);
-#            $self->{list}->pack_start($lastHBox,0,0,0);
-#        }
-#
-#        $lastHBox->pack_start($widget,1,1,0);
 
 
 
@@ -1043,15 +1039,14 @@
         my $self = shift;
 #        my $formated = shift;
 
-        print "GETVALUE\n";
         my @value;
+        #get_children doesn't return items in order. It seems to be in reverse 
order
+        #but to be sure, we just compute its rank in the array based on 
coordinates.
         for my $img($self->{list}->get_children)
         {
-            #print "GOT $img\n";
-            push @value, [$img->getValue];
-        }
-        
-        print "Value : ",Dumper(\@value),"\n";
+            my ($x, $y) = $self->{list}->child_get($img, qw(left-attach 
top-attach));
+            $value[($y * $self->{itemsPerRow}) + $x] = [$img->getValue];
+        }
         
         return \@value;
 
@@ -1114,10 +1109,9 @@
         for my $imgPath(@{$value})
         {
             my $img = $self->addImage;
-            use Data::Dumper;
-            print "IMG : $imgPath : ",Dumper($imgPath),"\n";
             $img->setValue($imgPath->[0]);
         }
+        $self->forceDisplay;
         $self->show_all;
     }
     
@@ -1128,7 +1122,6 @@
         
         for my $img($self->{list}->get_children)
         {
-            #print "GOT $img\n";
             $self->{list}->remove($img);
             $img->destroy;
         }        


_______________________________________________
GCstar-commits mailing list
[email protected]
https://mail.gna.org/listinfo/gcstar-commits

Reply via email to