82
82
IconPreviewPanel::IconPreviewPanel() :
83
83
UI::Widget::Panel("", "/dialogs/iconpreview", SP_VERB_VIEW_ICON_PREVIEW),
88
96
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
91
99
std::vector<Glib::ustring> pref_sizes = prefs->getAllDirs("/iconpreview/sizes/default");
92
100
std::vector<int> rawSizes;
94
102
for (std::vector<Glib::ustring>::iterator i = pref_sizes.begin(); i != pref_sizes.end(); ++i) {
95
103
if (prefs->getBool(*i + "/show", true)) {
96
104
int sizeVal = prefs->getInt(*i + "/value", -1);
140
148
Gtk::VBox* magBox = new Gtk::VBox();
142
magBox->pack_start( magnified );
150
Gtk::Frame *magFrame = Gtk::manage(new Gtk::Frame(_("Magnified:")));
151
magFrame->add( magnified );
153
magBox->pack_start( *magFrame, Gtk::PACK_EXPAND_WIDGET );
143
154
magBox->pack_start( magLabel, Gtk::PACK_SHRINK );
146
Gtk::VBox * verts = new Gtk::VBox();
147
for ( int i = 0; i < numEntries; i++ ) {
157
Gtk::VBox *verts = new Gtk::VBox();
158
Gtk::HBox *horiz = 0;
161
for ( int i = numEntries - 1; i >= 0; --i ) {
148
162
pixMem[i] = new guchar[4 * sizes[i] * sizes[i]];
149
163
memset( pixMem[i], 0x00, 4 * sizes[i] * sizes[i] );
154
168
Glib::ustring label(*labels[i]);
155
169
buttons[i] = new Gtk::ToggleToolButton(label);
156
170
buttons[i]->set_active( i == hot );
157
buttons[i]->set_icon_widget(*images[i]);
171
Gtk::Frame *frame = new Gtk::Frame();
172
frame->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
173
frame->add(*images[i]);
174
buttons[i]->set_icon_widget(*Gtk::manage(frame));
159
176
tips.set_tip((*buttons[i]), label);
161
178
buttons[i]->signal_clicked().connect( sigc::bind<int>( sigc::mem_fun(*this, &IconPreviewPanel::on_button_clicked), i) );
164
verts->add(*buttons[i]);
181
Gtk::Alignment *align = Gtk::manage(new Gtk::Alignment(0.5, 0.5, 0, 0));
182
align->add(*buttons[i]);
185
if ((avail == 0) && (previous == 0)) {
186
verts->pack_end(*align, Gtk::PACK_SHRINK);
190
if ((avail < pad) || ((sizes[i] > avail) && (sizes[i] < previous))) {
193
if ((horiz == 0) && (sizes[i] <= previous)) {
196
if (sizes[i] <= avail) {
198
horiz = Gtk::manage(new Gtk::HBox());
200
verts->pack_end(*horiz, Gtk::PACK_SHRINK);
202
horiz->pack_start(*align, Gtk::PACK_EXPAND_WIDGET);
204
avail -= pad; // a little extra for padding
207
verts->pack_end(*align, Gtk::PACK_SHRINK);
167
212
iconBox.pack_start(splitter);
168
213
splitter.pack1( *magBox, true, true );
169
splitter.pack2( *verts, false, false );
172
//## The Refresh button
175
Gtk::HButtonBox* holder = new Gtk::HButtonBox( Gtk::BUTTONBOX_END );
176
_getContents()->pack_end(*holder, false, false);
178
selectionButton = new Gtk::ToggleButton(_("Selection")); // , GTK_RESPONSE_APPLY
179
holder->pack_start( *selectionButton, false, false );
214
Gtk::Frame *actuals = Gtk::manage(new Gtk::Frame(_("Actual Size:")));
215
actuals->add(*verts);
216
splitter.pack2( *actuals, false, false );
219
selectionButton = new Gtk::CheckButton(_("Selection")); // , GTK_RESPONSE_APPLY
220
magBox->pack_start( *selectionButton, Gtk::PACK_SHRINK );
180
221
tips.set_tip((*selectionButton), _("Selection only or whole document"));
181
222
selectionButton->signal_clicked().connect( sigc::mem_fun(*this, &IconPreviewPanel::modeToggled) );
183
224
gint val = prefs->getBool("/iconpreview/selectionOnly");
184
225
selectionButton->set_active( val != 0 );
186
refreshButton = new Gtk::Button(Gtk::Stock::REFRESH); // , GTK_RESPONSE_APPLY
187
holder->pack_end( *refreshButton, false, false );
188
tips.set_tip((*refreshButton), _("Refresh the icons"));
189
refreshButton->signal_clicked().connect( sigc::mem_fun(*this, &IconPreviewPanel::refreshPreview) );
192
_getContents()->pack_start(iconBox, Gtk::PACK_EXPAND_WIDGET);
228
_getContents()->pack_start(iconBox, Gtk::PACK_SHRINK);
194
230
show_all_children();
232
// Connect this up last
233
desktopChangeConn = deskTrack.connectDesktopChanged( sigc::mem_fun(*this, &IconPreviewPanel::setDesktop) );
234
deskTrack.connect(GTK_WIDGET(gobj()));
237
IconPreviewPanel::~IconPreviewPanel()
246
selChangedConn.disconnect();
247
docModConn.disconnect();
248
docReplacedConn.disconnect();
249
desktopChangeConn.disconnect();
250
deskTrack.disconnect();
197
253
//#########################################################################
199
255
//#########################################################################
258
void IconPreviewPanel::setDesktop( SPDesktop* desktop )
260
Panel::setDesktop(desktop);
262
SPDocument *newDoc = (desktop) ? desktop->doc() : 0;
264
if ( desktop != this->desktop ) {
265
docReplacedConn.disconnect();
266
selChangedConn.disconnect();
268
this->desktop = Panel::getDesktop();
269
if ( this->desktop ) {
270
docReplacedConn = this->desktop->connectDocumentReplaced(sigc::hide<0>(sigc::mem_fun(this, &IconPreviewPanel::setDocument)));
271
if (this->desktop->selection) {
272
selChangedConn = desktop->selection->connectChanged(sigc::hide(sigc::mem_fun(this, &IconPreviewPanel::queueRefresh)));
277
deskTrack.setBase(desktop);
280
void IconPreviewPanel::setDocument( SPDocument *document )
282
if (this->document != document) {
283
docModConn.disconnect();
285
this->document = document;
286
if (this->document) {
287
docModConn = this->document->connectModified(sigc::hide(sigc::mem_fun(this, &IconPreviewPanel::queueRefresh)));
202
293
void IconPreviewPanel::refreshPreview()
204
295
SPDesktop *desktop = getDesktop();
297
timer = new Glib::Timer();
299
if (timer->elapsed() < 0.1) {
300
// Do not refresh too quickly
302
} else if ( desktop ) {
207
303
if ( selectionButton && selectionButton->get_active() )
209
305
Inkscape::Selection * sel = sp_desktop_selection(desktop);