コード例 #1
0
        void HandleIconButtonClicked(object sender, EventArgs args)
        {
            var dialog = new EditTagIconDialog(db, tag, this);

            var response = (ResponseType)dialog.Run();

            if (response == ResponseType.Ok)
            {
                if (dialog.ThemeIconName != null)
                {
                    tag.ThemeIconName = dialog.ThemeIconName;
                }
                else
                {
                    tag.ThemeIconName = null;
                    tag.Icon          = dialog.PreviewPixbuf;
                }
            }
            else if (response == (ResponseType)1)
            {
                tag.Icon = null;
            }

            if (tag.Icon != null && ColorManagement.Profiles.TryGetValue(Preferences.Get <string> (Preferences.COLOR_MANAGEMENT_DISPLAY_PROFILE), out var screen_profile))
            {
                icon_image.Pixbuf = tag.Icon.Copy();
                ColorManagement.ApplyProfile(icon_image.Pixbuf, screen_profile);
            }
            else
            {
                icon_image.Pixbuf = tag.Icon;
            }

            dialog.Destroy();
        }
コード例 #2
0
ファイル: PhotoImageView.cs プロジェクト: f-spot/f-spot-xplat
 protected override void ApplyColorTransform(Pixbuf pixbuf)
 {
     if (ColorManagement.Profiles.TryGetValue(Preferences.Get <string> (Preferences.COLOR_MANAGEMENT_DISPLAY_PROFILE), out var screen_profile))
     {
         ColorManagement.ApplyProfile(pixbuf, screen_profile);
     }
 }
コード例 #3
0
ファイル: TagView.cs プロジェクト: f-spot/f-spot-xplat
        public void DrawTags()
        {
            if (tags == null)
            {
                return;
            }

            SetSizeRequest((thumbnail_size + TAG_ICON_VSPACING) * tags.Length,
                           thumbnail_size);

            int tag_x = Allocation.X;
            int tag_y = Allocation.Y + (Allocation.Height - thumbnail_size) / 2;

            string[] names = new string[tags.Length];
            int      i     = 0;

            foreach (var t in tags)
            {
                names[i++] = t.Name;

                Pixbuf icon = t.Icon;

                var category = t.Category;
                while (icon == null && category != null)
                {
                    icon     = category.Icon;
                    category = category.Category;
                }

                if (icon == null)
                {
                    continue;
                }

                Pixbuf scaled_icon;
                if (icon.Width == thumbnail_size)
                {
                    scaled_icon = icon;
                }
                else
                {
                    scaled_icon = icon.ScaleSimple(thumbnail_size, thumbnail_size, InterpType.Bilinear);
                }
                if (ColorManagement.Profiles.TryGetValue(Preferences.Get <string> (Preferences.COLOR_MANAGEMENT_DISPLAY_PROFILE), out var screen_profile))
                {
                    ColorManagement.ApplyProfile(scaled_icon, screen_profile);
                }

                scaled_icon.RenderToDrawable(GdkWindow, Style.WhiteGC,
                                             0, 0, tag_x, tag_y, thumbnail_size, thumbnail_size,
                                             RgbDither.None, tag_x, tag_y);
                tag_x += thumbnail_size + TAG_ICON_VSPACING;
            }

            TooltipText = string.Join(", ", names);
        }
コード例 #4
0
ファイル: SlideShow.cs プロジェクト: f-spot/f-spot-xplat
        void LoadNext()
        {
            if (next != null)
            {
                next = null;
            }

            if (item == null || item.Current == null)
            {
                return;
            }

            using (var img = App.Instance.Container.Resolve <IImageFileFactory>().Create(item.Current.DefaultVersion.Uri))
            {
                try
                {
                    using (var pb = img.Load())
                    {
                        double scale = Math.Min((double)Allocation.Width / (double)pb.Width, (double)Allocation.Height / (double)pb.Height);
                        int    w     = (int)(pb.Width * scale);
                        int    h     = (int)(pb.Height * scale);

                        //if (w > 0 && h > 0)
                        //	next = pb.ScaleSimple ((int)(pb.Width * scale), (int)(pb.Height * scale), InterpType.Bilinear);
                    }
                    if (ColorManagement.Profiles.TryGetValue(Preferences.Get <string>(Preferences.COLOR_MANAGEMENT_DISPLAY_PROFILE), out var screen_profile))
                    {
                        ColorManagement.ApplyProfile(next, screen_profile);
                    }
                    loadRetries = 0;
                }
                catch (Exception)
                {
                    next = PixbufUtils.ErrorPixbuf;
                    if (++loadRetries < 10)
                    {
                        item.MoveNext(true);
                    }
                    else
                    {
                        loadRetries = 0;
                    }
                }
            }
        }
コード例 #5
0
#pragma warning restore 649

        public EditTagDialog(Db db, Tag t, Gtk.Window parent_window) : base("EditTagDialog.ui", "edit_tag_dialog")
        {
            this.db      = db;
            tag          = t;
            TransientFor = parent_window;

            orig_name           = TagName = t.Name;
            tag_name_entry.Text = t.Name;

            icon_image.Pixbuf = t.Icon;
            if (icon_image.Pixbuf != null && ColorManagement.Profiles.TryGetValue(Preferences.Get <string> (Preferences.COLOR_MANAGEMENT_DISPLAY_PROFILE), out var screen_profile))
            {
                icon_image.Pixbuf = icon_image.Pixbuf.Copy();
                ColorManagement.ApplyProfile(icon_image.Pixbuf, screen_profile);
            }
            PopulateCategoryOptionMenu(t);

            tag_name_entry.GrabFocus();

            category_option_menu.Changed += HandleTagNameEntryChanged;
        }
コード例 #6
0
        // FIXME Cache the GCs?
        protected virtual void DrawPhoto(int cell_num, Rectangle cell_area, Rectangle expose_area, bool selected, bool focussed)
        {
            if (!cell_area.Intersect(expose_area, out expose_area))
            {
                return;
            }

            IPhoto photo = Collection [cell_num];

            PixbufCache.CacheEntry entry = Cache.Lookup(photo.DefaultVersion.Uri);
            if (entry == null)
            {
                Cache.Request(photo.DefaultVersion.Uri, cell_num, ThumbnailWidth, ThumbnailHeight);
            }
            else
            {
                entry.Data = cell_num;
            }

            StateType cell_state = selected ? (HasFocus ? StateType.Selected : StateType.Active) : State;

            if (cell_state != State)
            {
                Style.PaintBox(Style, BinWindow, cell_state,
                               ShadowType.Out, expose_area, this, "IconView",
                               cell_area.X, cell_area.Y,
                               cell_area.Width - 1, cell_area.Height - 1);
            }

            var focus = Rectangle.Inflate(cell_area, -3, -3);

            if (HasFocus && focussed)
            {
                Style.PaintFocus(Style, BinWindow,
                                 cell_state, expose_area,
                                 this, null,
                                 focus.X, focus.Y,
                                 focus.Width, focus.Height);
            }

            var region       = Rectangle.Zero;
            var image_bounds = Rectangle.Inflate(cell_area, -CELL_BORDER_WIDTH, -CELL_BORDER_WIDTH);
            int expansion    = ThrobExpansion(cell_num, selected);

            Pixbuf thumbnail = null;

            if (entry != null)
            {
                thumbnail = entry.ShallowCopyPixbuf();
            }

            var draw = Rectangle.Zero;

            if (Rectangle.Inflate(image_bounds, expansion + 1, expansion + 1).Intersect(expose_area, out image_bounds) && thumbnail != null)
            {
                PixbufUtils.Fit(thumbnail, ThumbnailWidth, ThumbnailHeight,
                                true, out region.Width, out region.Height);

                region.X = (int)(cell_area.X + (cell_area.Width - region.Width) / 2);
                region.Y = (int)cell_area.Y + ThumbnailHeight - region.Height + CELL_BORDER_WIDTH;

                if (Math.Abs(region.Width - thumbnail.Width) > 1 &&
                    Math.Abs(region.Height - thumbnail.Height) > 1)
                {
                    Cache.Reload(entry, cell_num, thumbnail.Width, thumbnail.Height);
                }

                region = Rectangle.Inflate(region, expansion, expansion);
                Pixbuf temp_thumbnail;
                region.Width  = Math.Max(1, region.Width);
                region.Height = Math.Max(1, region.Height);

                if (Math.Abs(region.Width - thumbnail.Width) > 1 &&
                    Math.Abs(region.Height - thumbnail.Height) > 1)
                {
                    if (region.Width < thumbnail.Width && region.Height < thumbnail.Height)
                    {
                        /*
                         * temp_thumbnail = PixbufUtils.ScaleDown (thumbnail,
                         *      region.Width, region.Height);
                         */
                        temp_thumbnail = thumbnail.ScaleSimple(region.Width, region.Height,
                                                               InterpType.Bilinear);


                        lock (entry) {
                            if (entry.Reload && expansion == 0 && !entry.IsDisposed)
                            {
                                entry.SetPixbufExtended(temp_thumbnail.ShallowCopy(), false);
                                entry.Reload = true;
                            }
                        }
                    }
                    else
                    {
                        temp_thumbnail = thumbnail.ScaleSimple(region.Width, region.Height,
                                                               InterpType.Bilinear);
                    }
                }
                else
                {
                    temp_thumbnail = thumbnail;
                }

                // FIXME There seems to be a rounding issue between the
                // scaled thumbnail sizes, we avoid this for now by using
                // the actual thumnail sizes here.
                region.Width  = temp_thumbnail.Width;
                region.Height = temp_thumbnail.Height;

                draw = Rectangle.Inflate(region, 1, 1);

                if (!temp_thumbnail.HasAlpha)
                {
                    Style.PaintShadow(Style, BinWindow, cell_state,
                                      ShadowType.Out, expose_area, this,
                                      "IconView",
                                      draw.X, draw.Y,
                                      draw.Width, draw.Height);
                }

                if (region.Intersect(expose_area, out draw))
                {
                    Cms.Profile screen_profile;
                    if (ColorManagement.Profiles.TryGetValue(Preferences.Get <string> (Preferences.COLOR_MANAGEMENT_DISPLAY_PROFILE), out screen_profile))
                    {
                        Pixbuf t = temp_thumbnail.Copy();
                        temp_thumbnail.Dispose();
                        temp_thumbnail = t;
                        ColorManagement.ApplyProfile(temp_thumbnail, screen_profile);
                    }
                    temp_thumbnail.RenderToDrawable(BinWindow, Style.WhiteGC,
                                                    draw.X - region.X,
                                                    draw.Y - region.Y,
                                                    draw.X, draw.Y,
                                                    draw.Width, draw.Height,
                                                    RgbDither.None,
                                                    draw.X, draw.Y);
                }

                if (temp_thumbnail != thumbnail)
                {
                    temp_thumbnail.Dispose();
                }
            }

            if (thumbnail != null)
            {
                thumbnail.Dispose();
            }

            // Render Decorations
            if (DisplayRatings && region.X == draw.X && region.X != 0)
            {
                rating_renderer.Render(BinWindow, this, region, expose_area, cell_state, photo);
            }

            // Render Captions
            Rectangle caption_area = Rectangle.Zero;

            caption_area.Y     = cell_area.Y + CELL_BORDER_WIDTH + ThumbnailHeight + CAPTION_PADDING;
            caption_area.X     = cell_area.X + CELL_BORDER_WIDTH;
            caption_area.Width = cell_area.Width - 2 * CELL_BORDER_WIDTH;

            if (DisplayDates)
            {
                caption_area.Height = date_renderer.GetHeight(this, ThumbnailWidth);
                date_renderer.Render(BinWindow, this, caption_area, expose_area, cell_state, photo);

                caption_area.Y += caption_area.Height;
            }

            if (DisplayFilenames)
            {
                caption_area.Height = filename_renderer.GetHeight(this, ThumbnailWidth);
                filename_renderer.Render(BinWindow, this, caption_area, expose_area, cell_state, photo);

                caption_area.Y += caption_area.Height;
            }

            if (DisplayTags)
            {
                caption_area.Height = tag_renderer.GetHeight(this, ThumbnailWidth);
                tag_renderer.Render(BinWindow, this, caption_area, expose_area, cell_state, photo);

                caption_area.Y += caption_area.Height;
            }
        }
コード例 #7
0
        public EditTagIconDialog(Db db, Tag t, Gtk.Window parent_window) : base("EditTagIconDialog.ui", "edit_tag_icon_dialog")
        {
            TransientFor = parent_window;
            Title        = String.Format(Catalog.GetString("Edit Icon for Tag {0}"), t.Name);

            preview_pixbuf = t.Icon;
            Cms.Profile screen_profile;
            if (preview_pixbuf != null && ColorManagement.Profiles.TryGetValue(Preferences.Get <string> (Preferences.COLOR_MANAGEMENT_DISPLAY_PROFILE), out screen_profile))
            {
                preview_image.Pixbuf = preview_pixbuf.Copy();
                ColorManagement.ApplyProfile(preview_image.Pixbuf, screen_profile);
            }
            else
            {
                preview_image.Pixbuf = preview_pixbuf;
            }

            query = new PhotoQuery(db.Photos);

            if (db.Tags.Hidden != null)
            {
                query.Terms = OrTerm.FromTags(new [] { t });
            }
            else
            {
                query.Terms = new Literal(t);
            }

            image_view = new PhotoImageView(query)
            {
                CropHelpers = false
            };
            image_view.SelectionXyRatio  = 1.0;
            image_view.SelectionChanged += HandleSelectionChanged;
            image_view.PhotoChanged     += HandlePhotoChanged;

            external_photo_chooser = new Gtk.FileChooserButton(Catalog.GetString("Select Photo from file"),
                                                               Gtk.FileChooserAction.Open);

            external_photo_chooser.Filter = new FileFilter();
            external_photo_chooser.Filter.AddPixbufFormats();
            external_photo_chooser.LocalOnly = false;
            external_photo_chooser_hbox.PackStart(external_photo_chooser);
            external_photo_chooser.Show();
            external_photo_chooser.SelectionChanged += HandleExternalFileSelectionChanged;

            photo_scrolled_window.Add(image_view);

            if (query.Count > 0)
            {
                photo_spin_button.Wrap                     = true;
                photo_spin_button.Adjustment.Lower         = 1.0;
                photo_spin_button.Adjustment.Upper         = (double)query.Count;
                photo_spin_button.Adjustment.StepIncrement = 1.0;
                photo_spin_button.ValueChanged            += HandleSpinButtonChanged;

                image_view.Item.Index = 0;
            }
            else
            {
                from_photo_label.Markup = String.Format(Catalog.GetString(
                                                            "\n<b>From Photo</b>\n" +
                                                            " You can use one of your library photos as an icon for this tag.\n" +
                                                            " However, first you must have at least one photo associated\n" +
                                                            " with this tag. Please tag a photo as '{0}' and return here\n" +
                                                            " to use it as an icon."), t.Name);
                photo_scrolled_window.Visible = false;
                photo_label.Visible           = false;
                photo_spin_button.Visible     = false;
            }

            icon_store = new ListStore(typeof(string), typeof(Gdk.Pixbuf));

            icon_view = new Gtk.IconView(icon_store);
            icon_view.PixbufColumn      = 1;
            icon_view.SelectionMode     = SelectionMode.Single;
            icon_view.SelectionChanged += HandleIconSelectionChanged;

            icon_scrolled_window.Add(icon_view);

            icon_view.Show();

            image_view.Show();

            DelayedOperation fill_delay = new DelayedOperation(FillIconView);

            fill_delay.Start();
        }
コード例 #8
0
        public override void Render(Drawable window, Widget widget, Rectangle cell_area, Rectangle expose_area, StateType cell_state, IPhoto photo)
        {
            Tag[]     tags = photo.Tags;
            Rectangle tag_bounds;

            tag_bounds.X      = cell_area.X + (cell_area.Width + tag_icon_hspacing - tags.Length * (tag_icon_size + tag_icon_hspacing)) / 2;
            tag_bounds.Y      = cell_area.Y;       // + cell_area.Height - cell_border_width - tag_icon_size + tag_icon_vspacing;
            tag_bounds.Width  = tag_icon_size;
            tag_bounds.Height = tag_icon_size;


            foreach (var t in tags)
            {
                if (t == null)
                {
                    continue;
                }

                Pixbuf icon = t.Icon;

                Tag tag_iter = t.Category;
                while (icon == null && tag_iter != App.Instance.Database.Tags.RootCategory && tag_iter != null)
                {
                    icon     = tag_iter.Icon;
                    tag_iter = tag_iter.Category;
                }

                if (icon == null)
                {
                    continue;
                }

                if (tag_bounds.Intersect(expose_area, out var region))
                {
                    Pixbuf scaled_icon;
                    if (icon.Width == tag_bounds.Width)
                    {
                        scaled_icon = icon;
                    }
                    else
                    {
                        scaled_icon = icon.ScaleSimple(tag_bounds.Width,
                                                       tag_bounds.Height,
                                                       InterpType.Bilinear);
                    }

                    if (ColorManagement.Profiles.TryGetValue(Preferences.Get <string> (Preferences.COLOR_MANAGEMENT_DISPLAY_PROFILE), out var screen_profile))
                    {
                        ColorManagement.ApplyProfile(scaled_icon, screen_profile);
                    }

                    scaled_icon.RenderToDrawable(window, widget.Style.WhiteGC, region.X - tag_bounds.X, region.Y - tag_bounds.Y,
                                                 region.X, region.Y, region.Width, region.Height, RgbDither.None, region.X, region.Y);

                    if (scaled_icon != icon)
                    {
                        scaled_icon.Dispose();
                    }
                }

                tag_bounds.X += tag_bounds.Width + tag_icon_hspacing;
            }
        }
コード例 #9
0
        protected virtual Pixbuf GetPixbuf(int i, bool highlighted)
        {
            Pixbuf  current = null;
            SafeUri uri     = (selection.Collection [i]).DefaultVersion.Uri;

            try {
                var pixbuf = thumb_cache.Get(uri);
                if (pixbuf != null)
                {
                    current = pixbuf.ShallowCopy();
                }
            } catch (IndexOutOfRangeException) {
                current = null;
            }

            if (current == null)
            {
                var pixbuf = XdgThumbnailSpec.LoadThumbnail(uri, ThumbnailSize.Large, null);
                if (pixbuf == null)
                {
                    ThumbnailLoader.Default.Request(uri, ThumbnailSize.Large, 0);
                    current = FSpot.Core.Global.IconTheme.LoadIcon("gtk-missing-image", ThumbSize, (IconLookupFlags)0);
                }
                else
                {
                    if (SquaredThumbs)
                    {
                        current = PixbufUtils.IconFromPixbuf(pixbuf, ThumbSize);
                    }
                    else
                    {
                        current = pixbuf.ScaleSimple(ThumbSize, ThumbSize, InterpType.Nearest);
                    }
                    pixbuf.Dispose();
                    thumb_cache.Add(uri, current);
                }
            }

            //FIXME: we might end up leaking a pixbuf here
            Cms.Profile screen_profile;
            if (ColorManagement.Profiles.TryGetValue(Preferences.Get <string> (Preferences.COLOR_MANAGEMENT_DISPLAY_PROFILE), out screen_profile))
            {
                Pixbuf t = current.Copy();
                current = t;
                ColorManagement.ApplyProfile(current, screen_profile);
            }

            // Add a four pixel white border around the thumbnail
            // for some reason we cannot use "using" here, it looks like the pixbuf copy is not done properly
            Pixbuf whiteBorder = new Pixbuf(Colorspace.Rgb, true, 8, current.Width, current.Height);

            whiteBorder.Fill(0);
            current.CopyArea(1, 1, current.Width - 8, current.Height - 8, whiteBorder, 4, 4);
            current = whiteBorder;

            if (!highlighted)
            {
                return(current);
            }

            Pixbuf highlight = new Pixbuf(Colorspace.Rgb, true, 8, current.Width, current.Height);

            highlight.Fill(ColorToInt(Style.Light(StateType.Selected)));

            // Add a two pixel highlight around the thumbnail
            current.CopyArea(2, 2, current.Width - 4, current.Height - 4, highlight, 2, 2);

            return(highlight);
        }
コード例 #10
0
#pragma warning restore 649

        public EditTagIconDialog(Db db, Tag t, Gtk.Window parent_window) : base("EditTagIconDialog.ui", "edit_tag_icon_dialog")
        {
            TransientFor = parent_window;
            Title        = Strings.EditIconForTagName(t.Name);

            // FIXME, Icon
            //preview_pixbuf = t.Icon;
            if (preview_pixbuf != null && ColorManagement.Profiles.TryGetValue(Preferences.Get <string> (Preferences.COLOR_MANAGEMENT_DISPLAY_PROFILE), out var screen_profile))
            {
                preview_image.Pixbuf = preview_pixbuf.Copy();
                ColorManagement.ApplyProfile(preview_image.Pixbuf, screen_profile);
            }
            else
            {
                preview_image.Pixbuf = preview_pixbuf;
            }

            query = new PhotoQuery(db.Photos);

            if (db.Tags.Hidden != null)
            {
                query.Terms = OrTerm.FromTags(new[] { t });
            }
            else
            {
                query.Terms = new Literal(t);
            }

            image_view = new PhotoImageView(query)
            {
                CropHelpers = false
            };
            image_view.SelectionXyRatio  = 1.0;
            image_view.SelectionChanged += HandleSelectionChanged;
            image_view.PhotoChanged     += HandlePhotoChanged;

            external_photo_chooser = new Gtk.FileChooserButton(Strings.SelectPhotoFromFile, Gtk.FileChooserAction.Open)
            {
                Filter = new FileFilter()
            };
            external_photo_chooser.Filter.AddPixbufFormats();
            external_photo_chooser.LocalOnly = false;
            external_photo_chooser_hbox.PackStart(external_photo_chooser);
            external_photo_chooser.Show();
            external_photo_chooser.SelectionChanged += HandleExternalFileSelectionChanged;

            photo_scrolled_window.Add(image_view);

            if (query.Count > 0)
            {
                photo_spin_button.Wrap                     = true;
                photo_spin_button.Adjustment.Lower         = 1.0;
                photo_spin_button.Adjustment.Upper         = query.Count;
                photo_spin_button.Adjustment.StepIncrement = 1.0;
                photo_spin_button.ValueChanged            += HandleSpinButtonChanged;

                image_view.Item.Index = 0;
            }
            else
            {
                from_photo_label.Markup       = string.Format($"\n<b>{Strings.FromPhoto}</b>\n{Strings.TagFromPhotoLabelMessage}", t.Name);
                photo_scrolled_window.Visible = false;
                photo_label.Visible           = false;
                photo_spin_button.Visible     = false;
            }

            icon_store = new ListStore(typeof(string), typeof(Gdk.Pixbuf));

            icon_view = new Gtk.IconView(icon_store)
            {
                PixbufColumn  = 1,
                SelectionMode = SelectionMode.Single
            };
            icon_view.SelectionChanged += HandleIconSelectionChanged;

            icon_scrolled_window.Add(icon_view);

            icon_view.Show();

            image_view.Show();

            //var fill_delay = new DelayedOperation (FillIconView);
            //fill_delay.Start ();
        }