iconpreview.cpp revision 6c3e745a94ef6b25a4ef9f018d350a7535aa45af
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @brief A simple dialog for previewing icon representation.
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm/* Authors:
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * Jon A. Cruz
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * Bob Jamison
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * Other dudes from The Inkscape Organization
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen * Copyright (C) 2004 Bob Jamison
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen * Copyright (C) 2005 Jon A. Cruz
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * Released under GNU GPL, read the file 'COPYING' for more information
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud// takes doc, root, icon, and icon name to produce pixels
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmnamespace UI {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm static IconPreviewPanel &instance = *new IconPreviewPanel();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm//#########################################################################
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm//## E V E N T S
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm//#########################################################################
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm//#########################################################################
072916d0ef7dccd696b59381f50bcf776abccefbjohanengelen//## C O N S T R U C T O R / D E S T R U C T O R
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen//#########################################################################
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud * Constructor
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud UI::Widget::Panel("", "/dialogs/iconpreview", SP_VERB_VIEW_ICON_PREVIEW),
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud Inkscape::Preferences *prefs = Inkscape::Preferences::get();
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen std::vector<Glib::ustring> pref_sizes = prefs->getAllDirs("/iconpreview/sizes/default");
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen for (std::vector<Glib::ustring>::iterator i = pref_sizes.begin(); i != pref_sizes.end(); ++i) {
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen for ( std::vector<int>::iterator it = rawSizes.begin(); it != rawSizes.end(); ++it, ++i ) {
a0334366488989ef25fb812d7030d298c0917c96johanengelen buttons = new Gtk::ToggleToolButton*[numEntries];
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm for ( int i = 0; i < numEntries; i++ ) {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm char *label = g_strdup_printf(_("%d x %d"), sizes[i], sizes[i]);
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk for ( int i = 0; i < numEntries; i++ ) {
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 buttons[i]->signal_clicked().connect( sigc::bind<int>( sigc::mem_fun(*this, &IconPreviewPanel::on_button_clicked), i) );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm //## The Refresh button
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm Gtk::HButtonBox* holder = new Gtk::HButtonBox( Gtk::BUTTONBOX_END );
feb44ad276e996ca244e071f936c61b009bd73f4johanengelen selectionButton = new Gtk::ToggleButton(_("Selection")); // , GTK_RESPONSE_APPLY
feb44ad276e996ca244e071f936c61b009bd73f4johanengelen tips.set_tip((*selectionButton), _("Selection only or whole document"));
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm selectionButton->signal_clicked().connect( sigc::mem_fun(*this, &IconPreviewPanel::modeToggled) );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm gint val = prefs->getBool("/iconpreview/selectionOnly");
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm refreshButton = new Gtk::Button(Gtk::Stock::REFRESH); // , GTK_RESPONSE_APPLY
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm tips.set_tip((*refreshButton), _("Refresh the icons"));
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm refreshButton->signal_clicked().connect( sigc::mem_fun(*this, &IconPreviewPanel::refreshPreview) );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm _getContents()->pack_start(iconBox, Gtk::PACK_EXPAND_WIDGET);
5675f17bbbc00f2c970b4d4966ce55d86775f7a6johanengelen//#########################################################################
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm//## M E T H O D S
46c4893a7458eda6edcd064121bc000634af7a09johanengelen//#########################################################################
46c4893a7458eda6edcd064121bc000634af7a09johanengelen if ( selectionButton && selectionButton->get_active() )
46c4893a7458eda6edcd064121bc000634af7a09johanengelen Inkscape::Selection * sel = sp_desktop_selection(desktop);
46c4893a7458eda6edcd064121bc000634af7a09johanengelen //g_message("found a selection to play with");
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen Inkscape::Preferences *prefs = Inkscape::Preferences::get();
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen prefs->setBool("/iconpreview/selectionOnly", (selectionButton && selectionButton->get_active()));
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm// g_message(" setting up to render '%s' as the icon", id );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm /* Create new arena */
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm /* Create ArenaItem and set transform */
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen unsigned int visionkey = sp_item_display_key_new(1);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm root = sp_item_invoke_show ( SP_ITEM( SP_DOCUMENT_ROOT(doc) ),
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") );
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen sp_item_invoke_hide(SP_ITEM(sp_document_root(doc)), visionkey);
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen Glib::RefPtr<Gdk::Pixbuf> buf = images[hot]->get_pixbuf()->scale_simple( 128, 128, Gdk::INTERP_NEAREST );
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen} //namespace Dialogs
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen} //namespace UI
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen} //namespace Inkscape
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm Local Variables:
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// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :