~ubuntu-branches/ubuntu/natty/inkscape/natty

« back to all changes in this revision

Viewing changes to src/ui/widget/registered-widget.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:
587
587
}
588
588
 
589
589
/*#########################################
 
590
 * Registered TRANSFORMEDPOINT
 
591
 */
 
592
 
 
593
RegisteredVector::~RegisteredVector()
 
594
{
 
595
    _value_x_changed_connection.disconnect();
 
596
    _value_y_changed_connection.disconnect();
 
597
}
 
598
 
 
599
RegisteredVector::RegisteredVector ( const Glib::ustring& label, const Glib::ustring& tip,
 
600
                        const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in,
 
601
                        SPDocument* doc_in )
 
602
    : RegisteredWidget<Point> (label, tip),
 
603
      _polar_coords(false)
 
604
{
 
605
    init_parent(key, wr, repr_in, doc_in);
 
606
 
 
607
    setRange (-1e6, 1e6);
 
608
    setDigits (2);
 
609
    setIncrements(0.1, 1.0);
 
610
    _value_x_changed_connection = signal_x_value_changed().connect (sigc::mem_fun (*this, &RegisteredVector::on_value_changed));
 
611
    _value_y_changed_connection = signal_y_value_changed().connect (sigc::mem_fun (*this, &RegisteredVector::on_value_changed));
 
612
}
 
613
 
 
614
void
 
615
RegisteredVector::setValue(Geom::Point const & p)
 
616
{
 
617
    if (!_polar_coords) {
 
618
        Point::setValue(p);
 
619
    } else {
 
620
        Geom::Point polar;
 
621
        polar[Geom::X] = atan2(p) *180/M_PI;
 
622
        polar[Geom::Y] = p.length();
 
623
        Point::setValue(polar);
 
624
    }
 
625
}
 
626
 
 
627
void
 
628
RegisteredVector::setValue(Geom::Point const & p, Geom::Point const & origin)
 
629
{
 
630
    RegisteredVector::setValue(p);
 
631
    _origin = origin;
 
632
}
 
633
 
 
634
/**
 
635
 * Changes the widgets text to polar coordinates. The SVG output will still be a normal carthesian vector.
 
636
 * Careful: when calling getValue(), the return value's X-coord will be the angle, Y-value will be the distance/length. 
 
637
 * After changing the coords type (polar/non-polar), the value has to be reset (setValue).
 
638
 */
 
639
void
 
640
RegisteredVector::setPolarCoords(bool polar_coords)
 
641
{
 
642
    _polar_coords = polar_coords;
 
643
    if (polar_coords) {
 
644
        xwidget.setLabelText("Angle:");
 
645
        ywidget.setLabelText("Distance:");
 
646
    } else {
 
647
        xwidget.setLabelText("X:");
 
648
        ywidget.setLabelText("Y:");
 
649
    }
 
650
}
 
651
 
 
652
void
 
653
RegisteredVector::on_value_changed()
 
654
{
 
655
    if (setProgrammatically()) {
 
656
        clearProgrammatically();
 
657
        return;
 
658
    }
 
659
 
 
660
    if (_wr->isUpdating())
 
661
        return;
 
662
 
 
663
    _wr->setUpdating (true);
 
664
 
 
665
    Geom::Point origin = _origin;
 
666
    Geom::Point vector = getValue();
 
667
    if (_polar_coords) {
 
668
        vector = Geom::Point::polar(vector[Geom::X]*M_PI/180, vector[Geom::Y]);
 
669
    }
 
670
 
 
671
    Inkscape::SVGOStringStream os;
 
672
    os << origin << " , " << vector;
 
673
 
 
674
    write_to_xml(os.str().c_str());
 
675
 
 
676
    _wr->setUpdating (false);
 
677
}
 
678
 
 
679
/*#########################################
590
680
 * Registered RANDOM
591
681
 */
592
682