~ubuntu-branches/ubuntu/quantal/glom/quantal

« back to all changes in this revision

Viewing changes to glom/utility_widgets/canvas/canvas_line_movable.cc

  • Committer: Bazaar Package Importer
  • Author(s): Iain Lane
  • Date: 2009-01-11 17:12:01 UTC
  • mfrom: (1.1.39 upstream)
  • Revision ID: james.westby@ubuntu.com-20090111171201-0ov9zh1fxfueshxc
Tags: 1.8.5-0ubuntu1
* New upstream release (LP: #256701), fixes LP bugs: 
  + Clear the text in property dialogs for text items (LP: #309147)
  + Don't crash when showing and then hiding the grid (LP: #303453)
  + Temporarily remember the sort order so it is the same when navigating 
    away and back (LP: #303422)
  + Use the list's sort order for the top-level records in the report 
    (LP: #303425)
  + Users/Groups: Disable drag-and-drop for the treeview, because it is
    useless and confusing (LP: #299573)
  + Import: Sort the fields list alphabetically (LP: #306593)
  + delete primary key make unusuable the database (LP: #299549)
  + Spanish translate incomplete (LP: #299556)
  + import date format error (LP: #299591)
  + can't delete data from table list view (LP: #299853)
  + Field definition: default value not saved (LP: #299896)
  + reports crashing (LP: #300054)
  + Year error with date fields (LP: #300057)
  + list view: 2 records added instead of 1 (LP: #300819)
* debian/control: Refreshed dependencies for libglom-dev.
* debian/control: Updated build-deps to match configure checks. goocavnasmm
  build-dep bumped to version without .la files.
* debian/rules: Don't delete the directory containing the templates.
* debian/control, debian/rules, debian/glom-doc.*: Split out
  arch-independent manual and examples into separate package glom-doc, which
  is now recommended by glom (glom will still work if they're not available)
* debian/copyright: Rewritten to new machine-readable format. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Glom
 
2
 *
 
3
 * Copyright (C) 2007 Murray Cumming
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU General Public License as
 
7
 * published by the Free Software Foundation; either version 2 of the
 
8
 * License, or (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful, but
 
11
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
 * General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public
 
16
 * License along with this program; if not, write to the
 
17
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
18
 * Boston, MA 02111-1307, USA.
 
19
 */
 
20
 
 
21
#include "canvas_line_movable.h"
 
22
#include <goocanvasmm/canvas.h>
 
23
#include <gdkmm/cursor.h>
 
24
#include <iostream>
 
25
 
 
26
namespace Glom
 
27
{
 
28
 
 
29
 
 
30
CanvasLineMovable::CanvasLineMovable()
 
31
: Goocanvas::Polyline(0.0, 0.0, 0.0, 0.0),
 
32
  CanvasItemMovable()
 
33
{
 
34
  signal_motion_notify_event().connect(sigc::mem_fun(*this, &CanvasItemMovable::on_motion_notify_event));
 
35
  signal_button_press_event().connect(sigc::mem_fun(*this, &CanvasItemMovable::on_button_press_event));
 
36
  signal_button_release_event().connect(sigc::mem_fun(*this, &CanvasItemMovable::on_button_release_event));
 
37
 
 
38
  signal_enter_notify_event().connect(sigc::mem_fun(*this, &CanvasItemMovable::on_enter_notify_event));
 
39
  signal_leave_notify_event().connect(sigc::mem_fun(*this, &CanvasItemMovable::on_leave_notify_event));
 
40
}
 
41
 
 
42
CanvasLineMovable::~CanvasLineMovable()
 
43
{
 
44
}
 
45
 
 
46
Glib::RefPtr<CanvasLineMovable> CanvasLineMovable::create()
 
47
{
 
48
  return Glib::RefPtr<CanvasLineMovable>(new CanvasLineMovable());
 
49
}
 
50
 
 
51
void CanvasLineMovable::get_xy(double& x, double& y) const
 
52
{
 
53
  Goocanvas::Points points = property_points();
 
54
  points.get_coordinate(0, x, y);
 
55
}
 
56
 
 
57
void CanvasLineMovable::set_xy(double x, double y)
 
58
{
 
59
  //Discover the offset:
 
60
  double old_x = 0;
 
61
  double old_y = 0;
 
62
  Goocanvas::Points old_points = property_points();
 
63
  old_points.get_coordinate(0, old_x, old_y);
 
64
 
 
65
  const double offset_x = x - old_x;
 
66
  const double offset_y = y - old_y;
 
67
 
 
68
  //Apply the offset to all points:
 
69
  const int count = old_points.get_num_points();
 
70
  Goocanvas::Points new_points(count);
 
71
  for(int i = 0; i < count; ++i)
 
72
  {
 
73
    double this_x = 0;
 
74
    double this_y = 0;
 
75
    old_points.get_coordinate(i, this_x, this_y);
 
76
    new_points.set_coordinate(i, this_x + offset_x, this_y + offset_y);
 
77
  }
 
78
    
 
79
  property_points() = new_points;
 
80
}
 
81
 
 
82
void CanvasLineMovable::get_width_height(double& width, double& height) const
 
83
{
 
84
  //width/height still makes sense for a line
 
85
  //(it can be thought of as a diagonal line between two rectangle corners):
 
86
  Goocanvas::Points points = property_points();
 
87
  double x1 = 0;
 
88
  double y1 = 0;
 
89
  points.get_coordinate(0, x1, y1);
 
90
 
 
91
  double x2 = 0;
 
92
  double y2 = 0;
 
93
  points.get_coordinate(1, x2, y2);
 
94
 
 
95
  width = x2 -x1;
 
96
  height = y2 - y1;
 
97
 
 
98
  //std::cout << "CanvasLineMovable::get_width_height(): width=" << width << std::endl;
 
99
}
 
100
 
 
101
void CanvasLineMovable::set_width_height(double width, double height)
 
102
{
 
103
  //width/height still makes sense for a line
 
104
  //(it can be thought of as a diagonal line between two rectangle corners):
 
105
  Goocanvas::Points points = property_points();
 
106
  double x1 = 0;
 
107
  double y1 = 0;
 
108
  points.get_coordinate(0, x1, y1);
 
109
  points.set_coordinate(1, x1+width, y1+height);
 
110
  property_points() = points;
 
111
 
 
112
  //std::cout << "CanvasLineMovable::set_width_height(): end x=" << x1+width << std::endl;
 
113
}
 
114
 
 
115
Goocanvas::Canvas* CanvasLineMovable::get_parent_canvas_widget()
 
116
{
 
117
  return get_canvas();
 
118
}
 
119
 
 
120
} //namespace Glom
 
121