~ubuntu-branches/ubuntu/precise/inkscape/precise-updates

« back to all changes in this revision

Viewing changes to src/ui/widget/page-sizer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alex Valavanis
  • Date: 2010-09-12 19:44:58 UTC
  • mfrom: (1.1.12 upstream) (45.1.3 maverick)
  • Revision ID: james.westby@ubuntu.com-20100912194458-4sjwmbl7dlsrk5dc
Tags: 0.48.0-1ubuntu1
* Merge with Debian unstable (LP: #628048, LP: #401567, LP: #456248, 
  LP: #463602, LP: #591986)
* debian/control: 
  - Ubuntu maintainers
  - Promote python-lxml, python-numpy, python-uniconvertor to Recommends.
  - Demote pstoedit to Suggests (universe package).
  - Suggests ttf-dejavu instead of ttf-bitstream-vera (LP: #513319)
* debian/rules:
  - Run intltool-update on build (Ubuntu-specific).
  - Add translation domain to .desktop files (Ubuntu-specific).
* debian/dirs:
  - Add usr/share/pixmaps.  Allow inkscape.xpm installation
* drop 50-poppler-API.dpatch (now upstream)
* drop 51-paste-in-unwritable-directory.dpatch (now upstream) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
# include <config.h>
19
19
#endif
20
20
 
 
21
#include <cmath>
 
22
#include <gtkmm.h>
 
23
#include <string>
21
24
#include <string.h>
22
25
#include <vector>
23
 
#include <string>
24
 
 
25
 
#include <cmath>
26
 
#include <gtkmm.h>
27
 
#include "ui/widget/button.h"
28
 
 
29
 
#include "ui/widget/scalar-unit.h"
30
 
 
31
 
#include "helper/units.h"
32
 
#include "inkscape.h"
33
 
#include "verbs.h"
 
26
 
34
27
#include "desktop-handles.h"
35
28
#include "document.h"
36
29
#include "desktop.h"
 
30
#include "helper/action.h"
 
31
#include "helper/units.h"
 
32
#include "inkscape.h"
37
33
#include "page-sizer.h"
38
 
#include "helper/action.h"
 
34
#include "sp-namedview.h"
39
35
#include "sp-root.h"
 
36
#include "ui/widget/button.h"
 
37
#include "ui/widget/scalar-unit.h"
 
38
#include "verbs.h"
 
39
#include "xml/node.h"
 
40
#include "xml/repr.h"
40
41
 
41
42
using std::pair;
42
43
 
188
189
    { "Business Card (US)",             2,     3.5,  SP_UNIT_IN },
189
190
    { "Business Card (Europe)",        55,    85,    SP_UNIT_MM },
190
191
    { "Business Card (Aus/NZ)",        55,    90,    SP_UNIT_MM },
 
192
 
 
193
    // Start Arch Series List
 
194
 
 
195
 
 
196
    { "Arch A",         9,    12,    SP_UNIT_IN },  // 229 x 305 mm
 
197
    { "Arch B",        12,    18,    SP_UNIT_IN },  // 305 x 457 mm
 
198
    { "Arch C",        18,    24,    SP_UNIT_IN },  // 457 x 610 mm
 
199
    { "Arch D",        24,    36,    SP_UNIT_IN },  // 610 x 914 mm
 
200
    { "Arch E",        36,    48,    SP_UNIT_IN },  // 914 x 1219 mm
 
201
    { "Arch E1",       30,    42,    SP_UNIT_IN },  // 762 x 1067 mm
 
202
 
 
203
    /*
 
204
     * The above list of Arch sizes were taken from the following site:
 
205
     * http://en.wikipedia.org/wiki/Paper_size
 
206
     * Further detail can be found at http://www.ansi.org
 
207
     * Sizes are assumed to be arbitrary rounding to MM unless shown to be otherwise
 
208
     * No conflicting information was found regarding sizes in MM
 
209
     * September 2009 - DAK
 
210
     */
 
211
 
191
212
    { NULL,                     0,    0, SP_UNIT_PX },
192
213
};
193
214
 
209
230
      _dimensionUnits( _("U_nits:"), "units", _wr ),
210
231
      _dimensionWidth( _("_Width:"), _("Width of paper"), "width", _dimensionUnits, _wr ),
211
232
      _dimensionHeight( _("_Height:"), _("Height of paper"), "height", _dimensionUnits, _wr ),
 
233
      _marginTop( _("T_op margin:"), _("Top margin"), "fit-margin-top", _wr ),
 
234
      _marginLeft( _("L_eft:"), _("Left margin"), "fit-margin-left", _wr),
 
235
      _marginRight( _("Ri_ght:"), _("Right margin"), "fit-margin-right", _wr),
 
236
      _marginBottom( _("Botto_m:"), _("Bottom margin"), "fit-margin-bottom", _wr),
 
237
      
212
238
      _widgetRegistry(&_wr)
213
239
{
214
240
    //# Set up the Paper Size combo box
253
279
    //    _paperSizeListSelection->select(iter);
254
280
 
255
281
 
256
 
    pack_start (_paperSizeListBox, true, true, 0);
257
 
    _paperSizeListLabel.set_label(_("P_age size:"));
258
 
    _paperSizeListLabel.set_use_underline();
259
 
    _paperSizeListBox.pack_start (_paperSizeListLabel, false, false, 0);
260
 
    _paperSizeListLabel.set_mnemonic_widget (_paperSizeList);
261
 
    _paperSizeListBox.pack_start (_paperSizeListScroller, true, true, 0);
 
282
    pack_start (_paperSizeListScroller, true, true, 0);
262
283
 
263
284
    //## Set up orientation radio buttons
264
285
    pack_start (_orientationBox, false, false, 0);
265
 
    _orientationLabel.set_label(_("Page orientation:"));
 
286
    _orientationLabel.set_label(_("Orientation:"));
266
287
    _orientationBox.pack_start(_orientationLabel, false, false, 0);
267
288
    _landscapeButton.set_use_underline();
268
289
    _landscapeButton.set_label(_("_Landscape"));
279
300
    //## Set up custom size frame
280
301
    _customFrame.set_label(_("Custom size"));
281
302
    pack_start (_customFrame, false, false, 0);
282
 
    _customTable.resize(2, 2);
283
 
    _customTable.set_border_width (4);
284
 
    _customTable.set_row_spacings (4);
285
 
    _customTable.set_col_spacings (4);
286
 
    _customTable.attach(_dimensionWidth, 0,1,0,1);
287
 
    _customTable.attach(_dimensionUnits, 1,2,0,1);
288
 
    _customTable.attach(_dimensionHeight, 0,1,1,2);
289
 
    _customTable.attach(_fitPageButton,              1,2,1,2);
290
 
    _customFrame.add(_customTable);
291
 
 
 
303
    _customFrame.add(_customDimTable);
 
304
 
 
305
    _customDimTable.resize(3, 2);
 
306
    _customDimTable.set_border_width(4);
 
307
    _customDimTable.set_row_spacings(4);
 
308
    _customDimTable.set_col_spacings(4);
 
309
    _customDimTable.attach(_dimensionWidth,        0,1, 0,1);
 
310
    _customDimTable.attach(_dimensionUnits,        1,2, 0,1);
 
311
    _customDimTable.attach(_dimensionHeight,       0,1, 1,2);
 
312
    _customDimTable.attach(_fitPageMarginExpander, 0,2, 2,3);
 
313
    
 
314
    _dimTabOrderGList = NULL;
 
315
    _dimTabOrderGList = g_list_append(_dimTabOrderGList, _dimensionWidth.gobj());
 
316
    _dimTabOrderGList = g_list_append(_dimTabOrderGList, _dimensionHeight.gobj());
 
317
    _dimTabOrderGList = g_list_append(_dimTabOrderGList, _dimensionUnits.gobj());
 
318
    _dimTabOrderGList = g_list_append(_dimTabOrderGList, _fitPageMarginExpander.gobj());
 
319
    Glib::ListHandle<Widget *> dimFocusChain(_dimTabOrderGList, Glib::OWNERSHIP_NONE);
 
320
    _customDimTable.set_focus_chain(dimFocusChain);    
 
321
 
 
322
    //## Set up fit page expander
 
323
    _fitPageMarginExpander.set_use_underline();
 
324
    _fitPageMarginExpander.set_label(_("Resi_ze page to content..."));
 
325
    _fitPageMarginExpander.add(_marginTable);
 
326
    
 
327
    //## Set up margin settings
 
328
    _marginTable.resize(4, 2);
 
329
    _marginTable.set_border_width(4);
 
330
    _marginTable.set_row_spacings(4);
 
331
    _marginTable.set_col_spacings(4);
 
332
    _marginTable.attach(_marginTopAlign,     0,2, 0,1);
 
333
    _marginTable.attach(_marginLeftAlign,    0,1, 1,2);
 
334
    _marginTable.attach(_marginRightAlign,   1,2, 1,2);
 
335
    _marginTable.attach(_marginBottomAlign,  0,2, 2,3);
 
336
    _marginTable.attach(_fitPageButtonAlign, 0,2, 3,4);
 
337
    
 
338
    _marginTopAlign.set(0.5, 0.5, 0.0, 1.0);
 
339
    _marginTopAlign.add(_marginTop);
 
340
    _marginLeftAlign.set(0.0, 0.5, 0.0, 1.0);
 
341
    _marginLeftAlign.add(_marginLeft);
 
342
    _marginRightAlign.set(1.0, 0.5, 0.0, 1.0);
 
343
    _marginRightAlign.add(_marginRight);
 
344
    _marginBottomAlign.set(0.5, 0.5, 0.0, 1.0);
 
345
    _marginBottomAlign.add(_marginBottom);
 
346
    
 
347
    _fitPageButtonAlign.set(0.5, 0.5, 0.0, 1.0);
 
348
    _fitPageButtonAlign.add(_fitPageButton);
292
349
    _fitPageButton.set_use_underline();
293
 
    _fitPageButton.set_label(_("_Fit page to selection"));
 
350
    _fitPageButton.set_label(_("_Resize page to drawing or selection"));
294
351
    _tips.set_tip(_fitPageButton, _("Resize the page to fit the current selection, or the entire drawing if there is no selection"));
 
352
 
295
353
}
296
354
 
297
355
 
300
358
 */
301
359
PageSizer::~PageSizer()
302
360
{
 
361
    g_list_free(_dimTabOrderGList);
303
362
}
304
363
 
305
364
 
323
382
/**
324
383
 * Set document dimensions (if not called by Doc prop's update()) and
325
384
 * set the PageSizer's widgets and text entries accordingly. If
326
 
 * 'chageList' is true, then adjust the paperSizeList to show the closest
 
385
 * 'changeList' is true, then adjust the paperSizeList to show the closest
327
386
 * standard page size.
328
387
 *
329
388
 * \param w, h given in px
388
447
    _called = false;
389
448
}
390
449
 
 
450
/**
 
451
 * Updates the scalar widgets for the fit margins.  (Just changes the value
 
452
 * of the ui widgets to match the xml).
 
453
 */
 
454
void 
 
455
PageSizer::updateFitMarginsUI(Inkscape::XML::Node *nv_repr)
 
456
{
 
457
    double value = 0.0;
 
458
    if (sp_repr_get_double(nv_repr, "fit-margin-top", &value)) {
 
459
        _marginTop.setValue(value);
 
460
    }
 
461
    if (sp_repr_get_double(nv_repr, "fit-margin-left", &value)) {
 
462
        _marginLeft.setValue(value);
 
463
    }
 
464
    if (sp_repr_get_double(nv_repr, "fit-margin-right", &value)) {
 
465
        _marginRight.setValue(value);
 
466
    }
 
467
    if (sp_repr_get_double(nv_repr, "fit-margin-bottom", &value)) {
 
468
        _marginBottom.setValue(value);
 
469
    }
 
470
}
 
471
 
391
472
 
392
473
/**
393
474
 * Returns an iterator pointing to a row in paperSizeListStore which
434
515
 
435
516
 
436
517
/**
437
 
 * Tell the desktop to change the page size
 
518
 * Tell the desktop to fit the page size to the selection or drawing.
438
519
 */
439
520
void
440
521
PageSizer::fire_fit_canvas_to_selection_or_drawing()
443
524
    if (!dt) {
444
525
        return;
445
526
    }
 
527
    SPDocument *doc;
 
528
    SPNamedView *nv;
 
529
    Inkscape::XML::Node *nv_repr;
 
530
    if ((doc = sp_desktop_document(SP_ACTIVE_DESKTOP))
 
531
            && (nv = sp_document_namedview(doc, 0))
 
532
            && (nv_repr = SP_OBJECT_REPR(nv))) {
 
533
        sp_repr_set_svg_double(nv_repr, "fit-margin-top", _marginTop.getValue());
 
534
        sp_repr_set_svg_double(nv_repr, "fit-margin-left", _marginLeft.getValue());
 
535
        sp_repr_set_svg_double(nv_repr, "fit-margin-right", _marginRight.getValue());
 
536
        sp_repr_set_svg_double(nv_repr, "fit-margin-bottom", _marginBottom.getValue());
 
537
    }
446
538
    Verb *verb = Verb::get( SP_VERB_FIT_CANVAS_TO_SELECTION_OR_DRAWING );
447
539
    if (verb) {
448
540
        SPAction *action = verb->get_action(dt);
449
 
        if (action)
 
541
        if (action) {
450
542
            sp_action_perform(action, NULL);
 
543
        }
451
544
    }
452
545
}
453
546