iconpreview.cpp revision 6c3e745a94ef6b25a4ef9f018d350a7535aa45af
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm/** @file
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @brief A simple dialog for previewing icon representation.
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm */
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm/* Authors:
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * Jon A. Cruz
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * Bob Jamison
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * Other dudes from The Inkscape Organization
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm *
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen * Copyright (C) 2004 Bob Jamison
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen * Copyright (C) 2005 Jon A. Cruz
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm *
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * Released under GNU GPL, read the file 'COPYING' for more information
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm */
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#ifdef HAVE_CONFIG_H
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm# include <config.h>
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#endif
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include "iconpreview.h"
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include <gtk/gtk.h>
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include <glib/gmem.h>
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include <gtk/gtkdialog.h> //for GTK_RESPONSE* types
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include <glibmm/i18n.h>
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include <gtkmm/buttonbox.h>
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include <gtkmm/stock.h>
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include "preferences.h"
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include "inkscape.h"
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen#include "document.h"
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen#include "desktop-handles.h"
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen#include "selection.h"
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen#include "desktop.h"
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include "display/nr-arena.h"
8c39cbeab9949a0a7d6ae66b768a7352019e42f8johanengelen#include "sp-root.h"
072916d0ef7dccd696b59381f50bcf776abccefbjohanengelen#include "xml/repr.h"
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraudextern "C" {
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud// takes doc, root, icon, and icon name to produce pixels
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmguchar *
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmsp_icon_doc_icon( SPDocument *doc, NRArenaItem *root,
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm const gchar *name, unsigned int psize );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm}
8d9f5d586a04809427ce1df284a5720112177991cilix
70eb1fc448cb08acf3468f80fa2296c03b32afd2cilixnamespace Inkscape {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmnamespace UI {
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelennamespace Dialogs {
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmIconPreviewPanel&
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmIconPreviewPanel::getInstance()
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm{
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm static IconPreviewPanel &instance = *new IconPreviewPanel();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
072916d0ef7dccd696b59381f50bcf776abccefbjohanengelen instance.refreshPreview();
8c39cbeab9949a0a7d6ae66b768a7352019e42f8johanengelen
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud return instance;
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud}
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm//#########################################################################
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm//## E V E N T S
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm//#########################################################################
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmvoid IconPreviewPanel::on_button_clicked(int which)
8d9f5d586a04809427ce1df284a5720112177991cilix{
8d9f5d586a04809427ce1df284a5720112177991cilix if ( hot != which ) {
70eb1fc448cb08acf3468f80fa2296c03b32afd2cilix buttons[hot]->set_active( false );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm hot = which;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm updateMagnify();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm _getContents()->queue_draw();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
8c39cbeab9949a0a7d6ae66b768a7352019e42f8johanengelen
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm//#########################################################################
072916d0ef7dccd696b59381f50bcf776abccefbjohanengelen//## C O N S T R U C T O R / D E S T R U C T O R
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen//#########################################################################
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen/**
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud * Constructor
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen */
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraudIconPreviewPanel::IconPreviewPanel() :
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud UI::Widget::Panel("", "/dialogs/iconpreview", SP_VERB_VIEW_ICON_PREVIEW),
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen hot(1),
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud refreshButton(0),
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud selectionButton(0)
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen{
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud Inkscape::Preferences *prefs = Inkscape::Preferences::get();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm numEntries = 0;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen std::vector<Glib::ustring> pref_sizes = prefs->getAllDirs("/iconpreview/sizes/default");
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm std::vector<int> rawSizes;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen for (std::vector<Glib::ustring>::iterator i = pref_sizes.begin(); i != pref_sizes.end(); ++i) {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm if (prefs->getBool(*i + "/show", true)) {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm int sizeVal = prefs->getInt(*i + "/value", -1);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm if (sizeVal > 0) {
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen rawSizes.push_back(sizeVal);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
8d9f5d586a04809427ce1df284a5720112177991cilix if ( !rawSizes.empty() ) {
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen numEntries = rawSizes.size();
8d9f5d586a04809427ce1df284a5720112177991cilix sizes = new int[numEntries];
70eb1fc448cb08acf3468f80fa2296c03b32afd2cilix int i = 0;
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen for ( std::vector<int>::iterator it = rawSizes.begin(); it != rawSizes.end(); ++it, ++i ) {
70eb1fc448cb08acf3468f80fa2296c03b32afd2cilix sizes[i] = *it;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm if ( numEntries < 1 )
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm numEntries = 5;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm sizes = new int[numEntries];
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm sizes[0] = 16;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm sizes[1] = 24;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm sizes[2] = 32;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm sizes[3] = 48;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm sizes[4] = 128;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
46c4893a7458eda6edcd064121bc000634af7a09johanengelen pixMem = new guchar*[numEntries];
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm images = new Gtk::Image*[numEntries];
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm labels = new Glib::ustring*[numEntries];
a0334366488989ef25fb812d7030d298c0917c96johanengelen buttons = new Gtk::ToggleToolButton*[numEntries];
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm for ( int i = 0; i < numEntries; i++ ) {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm char *label = g_strdup_printf(_("%d x %d"), sizes[i], sizes[i]);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm labels[i] = new Glib::ustring(label);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm g_free(label);
eaa9bdc7bf7b73397e536edd47490d84e4420bd8bryce pixMem[i] = 0;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm images[i] = 0;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm magLabel.set_label( *labels[hot] );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm Gtk::VBox* magBox = new Gtk::VBox();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk magBox->pack_start( magnified );
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk magBox->pack_start( magLabel, Gtk::PACK_SHRINK );
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk Gtk::VBox * verts = new Gtk::VBox();
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk for ( int i = 0; i < numEntries; i++ ) {
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk pixMem[i] = new guchar[4 * sizes[i] * sizes[i]];
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm memset( pixMem[i], 0x00, 4 * sizes[i] * sizes[i] );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm GdkPixbuf *pb = gdk_pixbuf_new_from_data( pixMem[i], GDK_COLORSPACE_RGB, TRUE, 8, sizes[i], sizes[i], sizes[i] * 4, /*(GdkPixbufDestroyNotify)g_free*/NULL, NULL );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm GtkImage* img = GTK_IMAGE( gtk_image_new_from_pixbuf( pb ) );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm images[i] = Glib::wrap(img);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm Glib::ustring label(*labels[i]);
5675f17bbbc00f2c970b4d4966ce55d86775f7a6johanengelen buttons[i] = new Gtk::ToggleToolButton(label);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm buttons[i]->set_active( i == hot );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm buttons[i]->set_icon_widget(*images[i]);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm tips.set_tip((*buttons[i]), label);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm buttons[i]->signal_clicked().connect( sigc::bind<int>( sigc::mem_fun(*this, &IconPreviewPanel::on_button_clicked), i) );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm verts->add(*buttons[i]);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
5675f17bbbc00f2c970b4d4966ce55d86775f7a6johanengelen
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm iconBox.pack_start(splitter);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm splitter.pack1( *magBox, true, true );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm splitter.pack2( *verts, false, false );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
5675f17bbbc00f2c970b4d4966ce55d86775f7a6johanengelen
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm //## The Refresh button
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm Gtk::HButtonBox* holder = new Gtk::HButtonBox( Gtk::BUTTONBOX_END );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm _getContents()->pack_end(*holder, false, false);
ab5f33e91458710ed8dd2b2a1b3a53e4227d4856johanengelen
feb44ad276e996ca244e071f936c61b009bd73f4johanengelen selectionButton = new Gtk::ToggleButton(_("Selection")); // , GTK_RESPONSE_APPLY
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm holder->pack_start( *selectionButton, false, false );
feb44ad276e996ca244e071f936c61b009bd73f4johanengelen tips.set_tip((*selectionButton), _("Selection only or whole document"));
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm selectionButton->signal_clicked().connect( sigc::mem_fun(*this, &IconPreviewPanel::modeToggled) );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm gint val = prefs->getBool("/iconpreview/selectionOnly");
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm selectionButton->set_active( val != 0 );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm refreshButton = new Gtk::Button(Gtk::Stock::REFRESH); // , GTK_RESPONSE_APPLY
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm holder->pack_end( *refreshButton, false, false );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm tips.set_tip((*refreshButton), _("Refresh the icons"));
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm refreshButton->signal_clicked().connect( sigc::mem_fun(*this, &IconPreviewPanel::refreshPreview) );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm _getContents()->pack_start(iconBox, Gtk::PACK_EXPAND_WIDGET);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm show_all_children();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
5675f17bbbc00f2c970b4d4966ce55d86775f7a6johanengelen//#########################################################################
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm//## M E T H O D S
46c4893a7458eda6edcd064121bc000634af7a09johanengelen//#########################################################################
46c4893a7458eda6edcd064121bc000634af7a09johanengelen
46c4893a7458eda6edcd064121bc000634af7a09johanengelen
46c4893a7458eda6edcd064121bc000634af7a09johanengelenvoid IconPreviewPanel::refreshPreview()
46c4893a7458eda6edcd064121bc000634af7a09johanengelen{
46c4893a7458eda6edcd064121bc000634af7a09johanengelen SPDesktop *desktop = getDesktop();
46c4893a7458eda6edcd064121bc000634af7a09johanengelen if ( desktop ) {
46c4893a7458eda6edcd064121bc000634af7a09johanengelen
46c4893a7458eda6edcd064121bc000634af7a09johanengelen if ( selectionButton && selectionButton->get_active() )
46c4893a7458eda6edcd064121bc000634af7a09johanengelen {
46c4893a7458eda6edcd064121bc000634af7a09johanengelen Inkscape::Selection * sel = sp_desktop_selection(desktop);
46c4893a7458eda6edcd064121bc000634af7a09johanengelen if ( sel ) {
46c4893a7458eda6edcd064121bc000634af7a09johanengelen //g_message("found a selection to play with");
46c4893a7458eda6edcd064121bc000634af7a09johanengelen
46c4893a7458eda6edcd064121bc000634af7a09johanengelen GSList const *items = sel->itemList();
46c4893a7458eda6edcd064121bc000634af7a09johanengelen SPObject *target = 0;
46c4893a7458eda6edcd064121bc000634af7a09johanengelen while ( items && !target ) {
46c4893a7458eda6edcd064121bc000634af7a09johanengelen SPItem* item = SP_ITEM( items->data );
46c4893a7458eda6edcd064121bc000634af7a09johanengelen SPObject * obj = SP_OBJECT(item);
46c4893a7458eda6edcd064121bc000634af7a09johanengelen gchar const *id = SP_OBJECT_ID( obj );
46c4893a7458eda6edcd064121bc000634af7a09johanengelen if ( id ) {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm target = obj;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm items = g_slist_next(items);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm if ( target ) {
5675f17bbbc00f2c970b4d4966ce55d86775f7a6johanengelen renderPreview(target);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm else
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm SPObject *target = desktop->currentRoot();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm if ( target ) {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm renderPreview(target);
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen }
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen }
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen }
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelenvoid IconPreviewPanel::modeToggled()
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen{
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen Inkscape::Preferences *prefs = Inkscape::Preferences::get();
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen prefs->setBool("/iconpreview/selectionOnly", (selectionButton && selectionButton->get_active()));
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen refreshPreview();
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen}
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmvoid IconPreviewPanel::renderPreview( SPObject* obj )
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen{
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm SPDocument * doc = SP_OBJECT_DOCUMENT(obj);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm gchar * id = SP_OBJECT_ID(obj);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm// g_message(" setting up to render '%s' as the icon", id );
0fc5ce7045233dae7e15fdc86774370f1b1d73cbjohanengelen
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm NRArenaItem *root = NULL;
0fc5ce7045233dae7e15fdc86774370f1b1d73cbjohanengelen
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm /* Create new arena */
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen NRArena *arena = NRArena::create();
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm /* Create ArenaItem and set transform */
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen unsigned int visionkey = sp_item_display_key_new(1);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm root = sp_item_invoke_show ( SP_ITEM( SP_DOCUMENT_ROOT(doc) ),
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm arena, visionkey, SP_ITEM_SHOW_DISPLAY );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm for ( int i = 0; i < numEntries; i++ ) {
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen guchar * px = sp_icon_doc_icon( doc, root, id, sizes[i] );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm// g_message( " size %d %s", sizes[i], (px ? "worked" : "failed") );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm if ( px ) {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm memcpy( pixMem[i], px, sizes[i] * sizes[i] * 4 );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm g_free( px );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm px = 0;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm } else {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm memset( pixMem[i], 0, sizes[i] * sizes[i] * 4 );
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm images[i]->queue_draw();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen updateMagnify();
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen sp_item_invoke_hide(SP_ITEM(sp_document_root(doc)), visionkey);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm nr_object_unref((NRObject *) arena);
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelenvoid IconPreviewPanel::updateMagnify()
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen{
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen Glib::RefPtr<Gdk::Pixbuf> buf = images[hot]->get_pixbuf()->scale_simple( 128, 128, Gdk::INTERP_NEAREST );
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen magLabel.set_label( *labels[hot] );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm magnified.set( buf );
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen magnified.queue_draw();
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen magnified.get_parent()->queue_draw();
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen}
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen} //namespace Dialogs
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen} //namespace UI
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen} //namespace Inkscape
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen/*
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm Local Variables:
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen mode:c++
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen c-file-style:"stroustrup"
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm indent-tabs-mode:nil
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm fill-column:99
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm End:
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm*/
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen