FigureEditor.cxx
Go to the documentation of this file.
1 
15 #ifdef _MSC_VER
16 #include "msdevstudio/MSconfig.h"
17 #endif
18 
19 // for MEMFUN1_DEFECT
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23 
24 #include "FigureEditor.h"
25 
26 #include "QtGroupView.h"
27 #include "CanvasWindow.h"
28 #include "PickTable.h"
29 #include "plotters/PlotterBase.h"
30 
31 #include <qapplication.h>
32 #include <qclipboard.h>
33 #include <qcursor.h>
34 #include <qimage.h>
35 
36 #if QT_VERSION < 0x040000
37 #include <qdragobject.h>
38 #include <qwmatrix.h>
39 #include <qpaintdevicemetrics.h>
40 #else
41 // Added by the Qt porting tool:
42 #include <q3dragobject.h>
43 #include <QtGui/QMouseEvent>
44 #include <QtGui/QPixmap>
45 #include <QtGui/QResizeEvent>
46 #include <QtGui/QPrintDialog>
47 #include <qmatrix.h>
48 #include <q3paintdevicemetrics.h>
49 #endif
50 
51 #include <qpainter.h>
52 #include <qprinter.h>
53 #include <qsettings.h>
54 #include <qstatusbar.h>
55 
56 #include <algorithm>
57 #include <functional>
58 
59 #include <cmath>
60 #include <cctype>
61 
62 #include <cassert>
63 
64 using std::abs;
65 using std::bind2nd;
66 using std::for_each;
67 using std::mem_fun;
68 using std::string;
69 using std::transform;
70 using std::vector;
71 
72 
78 static QPrinter::PageSize indexToPageSize[] =
79  { QPrinter::A4, QPrinter::B5, QPrinter::Letter,
80  QPrinter::Legal, QPrinter::Executive,
81  QPrinter::A0, QPrinter::A1, QPrinter::A2, QPrinter::A3,
82  QPrinter::A5, QPrinter::A6, QPrinter::A7, QPrinter::A8,
83  QPrinter::A9, QPrinter::B0, QPrinter::B1,
84  QPrinter::B10, QPrinter::B2, QPrinter::B3, QPrinter::B4,
85  QPrinter::B6, QPrinter::B7, QPrinter::B8, QPrinter::B9,
86  QPrinter::C5E, QPrinter::Comm10E,
87  QPrinter::DLE, QPrinter::Folio, QPrinter::Ledger,
88  QPrinter::Tabloid, QPrinter::Custom, QPrinter::NPageSize };
89 
95 static QPrinter::Orientation indexToOrientation[] = { QPrinter::Portrait,
96  QPrinter::Landscape };
97 
103 static QPrinter::ColorMode indexToColorMode[] = { QPrinter::GrayScale,
104  QPrinter::Color };
105 
106 using namespace hippodraw;
107 
109 QString FigureEditor::s_app_key ( "/HippoDraw/" );
110 QString FigureEditor::s_registry ( "/Trolltech" );
111 
112 FigureEditor::
113 #if QT_VERSION < 0x040000
114 FigureEditor ( QCanvas * c, QWidget * parent,
115  const char * name, Qt::WFlags f)
116  : QCanvasView ( c, parent, name, f ),
117 #else
118 FigureEditor ( Q3Canvas * c, QWidget * parent,
119  const char * name, Qt::WFlags f)
120  : Q3CanvasView ( c, parent, name, f ),
121 #endif
122  m_scale_factor ( 1.0 ),
123  m_printer_bounds ( false ),
124  m_ignore_margin ( false ),
125  m_rightItem ( 0 )
126 {
127  m_zoom_mode = false ;
128 
129  m_canvas = canvas ();
130  m_canvas->setUpdatePeriod ( 30 );
131 
132  if ( s_printer == 0 )
133  {
134  initPrinter ();
135  }
136 
137  calcPrinterMetrics ( s_printer );
138 
139  m_canvas->resize ( m_apage_w, m_apage_h );
140 
141  //Printer Page margin is not visible by default
142  QSettings settings;
143  settings.insertSearchPath ( QSettings::Windows, s_registry );
144  int pb = settings.readNumEntry ( s_app_key + "Canvas/Margin", 0 );
145  bool yes = ( pb == 1 ) ? true : false;
146  showPrinterMargins ( yes );
147  }
148 
149 
150 void
153 {
154  s_printer = new QPrinter ( );
155 
156  QSettings settings;
157  settings.insertSearchPath ( QSettings::Windows, s_registry );
158 
159  const int pagesize
160  = settings.readNumEntry ( s_app_key + "Printer/PageSize",
161  QPrinter::Letter );
162  assert( pagesize < QPrinter::NPageSize );
163  QPrinter::PageSize size = indexToPageSize [ pagesize ];
164 
165  const int orientation
166  = settings.readNumEntry( s_app_key + "Printer/Orientation",
167  QPrinter::Portrait );
168  assert( orientation == 0 || orientation == 1 );
169  QPrinter::Orientation orient = indexToOrientation [ orientation ];
170 
171  const int color
172  = settings.readNumEntry( s_app_key + "Printer/ColorMode",
173  QPrinter::Color );
174  assert( color == 0 || color == 1 );
175  QPrinter::ColorMode colorMode = indexToColorMode[color];
176 
177  s_printer->setOrientation ( orient );
178  s_printer->setPageSize ( size );
179  s_printer->setFullPage ( true );
180  s_printer->setColorMode ( colorMode );
181 }
182 
183 void
185 setAppKey ( const std::string & appkey )
186 {
187  s_app_key = appkey.c_str();
188 }
189 
190 void
193 {
194 
195  if ( m_printer_bounds == false && on == true ) // No margin exists. Draw 'em
196  {
197  m_printer_bounds = true;
198 
199  int height = m_canvas -> height();
200  int y = 0;
201  while ( y < height )
202  {
203  addPageMargin ( 0, y );
204  y += m_apage_h;
205  }
206 
207  }
208  else if( m_printer_bounds == true && on == false ) // Margins exist delete it
209  {
210  m_printer_bounds = false;
211 
212 #if QT_VERSION < 0x040000
213  QCanvasItemList itemList = m_canvas -> allItems ();
214 
216  iter = itemList.begin();
217 
218  while( iter != itemList.end() )
219  {
220  QCanvasItem * item = *iter++;
221  QtView * view = dynamic_cast < QtView * > ( item );
222 
223  if ( view == 0 ) // it is a printer page border
224  {
225  QCanvasRectangle * rect
226  = dynamic_cast< QCanvasRectangle * >( item );
227  assert( rect );
228  delete rect;
229  }
230  }
231 #else
232  Q3CanvasItemList itemList = m_canvas -> allItems ();
233 
234  Q3ValueListIterator< Q3CanvasItem * > iter;
235  iter = itemList.begin();
236 
237  while( iter != itemList.end() )
238  {
239  Q3CanvasItem * item = *iter++;
240  QtView * view = dynamic_cast < QtView * > ( item );
241 
242  if ( view == 0 ) // it is a printer page border
243  {
244  Q3CanvasRectangle * rect
245  = dynamic_cast< Q3CanvasRectangle * >( item );
246  assert( rect );
247  delete rect;
248  }
249  }
250 #endif
251  }
252 }
253 
254 void
256 addPageMargin ( int x, int y )
257 {
258 
259  if ( m_printer_bounds == true )
260  {
261 #if QT_VERSION < 0x040000
262  QCanvasRectangle * rect
263  = new QCanvasRectangle ( x, y, m_upage_w, m_upage_h, m_canvas );
264 #else
265  Q3CanvasRectangle * rect
266  = new Q3CanvasRectangle ( x, y, m_upage_w, m_upage_h, m_canvas );
267 #endif
268 
269  int dx = ( m_apage_w - m_upage_w ) / 2;
270  int dy = ( m_apage_h - m_upage_h ) / 2;
271  rect ->moveBy ( dx, dy );
272 
273  QColor color ( "lightGray" );
274  QPen pen ( color, 1, Qt::DashLine );
275  rect -> setPen ( pen );
276 
277  rect -> show ();
278  }
279 }
280 
284 void
287 {
288  QString name = s_printer->printerName();
289  if ( name.isNull() )
290  {
291  if( s_printer -> orientation() == QPrinter::Portrait )
292  {
293  m_upage_w = 720; // dimensions of letter size
294  m_upage_h = 990; // HP printer in portrait mode
295  m_apage_w = 816;
296  m_apage_h = 1054;
297  }
298  else
299  {
300  m_upage_h = 720; // dimensions of letter size
301  m_upage_w = 990; // HP printer in landscape mode
302  m_apage_h = 816;
303  m_apage_w = 1054;
304  }
305  }
306  else
307  {
308 #if QT_VERSION < 0x040000
309  QPaintDeviceMetrics metrics ( device );
310 #else
311  Q3PaintDeviceMetrics metrics ( device );
312 #endif
313  int dpix = metrics.logicalDpiX ();
314  int dpiy = metrics.logicalDpiY ();
315 
316  m_apage_w = metrics.widthMM ();
317  m_apage_h = metrics.heightMM ();
318 
319  m_apage_w = static_cast < int > ( m_apage_w * dpix / 25.4 );
320  m_apage_h = static_cast < int > ( m_apage_h * dpiy / 25.4 );
321 
322  if( s_printer -> orientation() == QPrinter::Landscape )
323  std::swap( m_apage_w, m_apage_h );
324 
325  QSize margins = s_printer -> margins ();
326  m_upage_w = m_apage_w - 2 * margins.width ();
327  m_upage_h = m_apage_h - 2 * margins.height ();
328  }
329 }
330 
332 {
333  return ( m_selected_list.size() == 1 );
334 }
335 
336 #if QT_VERSION < 0x040000
337 QCanvasItem *
338 #else
339 Q3CanvasItem *
340 #endif
342 selectedItem () const
343 {
344  if ( isSingleItemSelected() )
345  {
346  return m_selected_list[0];
347  }
348  else
349  {
350  return 0;
351  }
352 }
353 
354 #if QT_VERSION < 0x040000
355 std::vector < QCanvasItem * > &
356 #else
357 std::vector < Q3CanvasItem * > &
358 #endif
361 {
362  return m_selected_list;
363 }
364 
365 void
366 FigureEditor::
367 #if QT_VERSION < 0x040000
368 addSelectedItem ( QCanvasItem * item )
369 #else
370 addSelectedItem ( Q3CanvasItem * item )
371 #endif
372 {
373 
374  if ( ! item->isSelected() )
375  {
376  m_selected_list.push_back ( item );
377  setSelectedFlags();
378  }
379 
380 }
381 
382 void
383 FigureEditor::
384 #if QT_VERSION < 0x040000
385 removeSelectedItem ( QCanvasItem * item )
386 {
387  if ( item->isSelected() ) {
388  vector < QCanvasItem * > ::iterator last
389 #else
390 removeSelectedItem ( Q3CanvasItem * item )
391 {
392  if ( item->isSelected() ) {
393  vector < Q3CanvasItem * > ::iterator last
394 #endif
395  = std::remove ( m_selected_list.begin(),
396  m_selected_list.end(), item );
397  m_selected_list.erase ( last, m_selected_list.end() );
398  setSelectedFlags();
399  }
400 }
401 
403 {
404 #ifdef ITERATOR_MEMBER_DEFECT
405  std::
406 #endif
407 #if QT_VERSION < 0x040000
408  vector < QCanvasItem * > ::const_iterator first
409  = m_selected_list.begin();
410  QCanvasItem * item = *first++;
411 #else
412  vector < Q3CanvasItem * > ::const_iterator first
413  = m_selected_list.begin();
414  Q3CanvasItem * item = *first++;
415 #endif
416  QRect rect = item->boundingRect();
417 
418  while ( first != m_selected_list.end() ) {
419  item = *first++;
420  QRect r = item->boundingRect ();
421  rect |= r;
422  }
423 
424  return rect;
425 }
426 
427 double
429 maximumZ () const
430 {
431  /* This is only used to determine if the view is a text view */
432  QtView* view = NULL;
433 
434 #if QT_VERSION < 0x040000
435  vector < QCanvasItem * > ::const_iterator first = m_items.begin();
436  double max_z = (*first) -> z ();
437 
438  /* Get z()-100 for text plotter */
439  view = dynamic_cast<QtView*> (*first);
440  if (view && view->isTextView())
441  max_z -= 100;
442 
443  first++;
444 
445 
446  while ( first != m_items.end () ) {
447  QCanvasItem * item = *first;
448 #else
449  vector < Q3CanvasItem * > ::const_iterator first = m_items.begin();
450  double max_z = (*first) -> z ();
451 
452  /* z()-100 for text */
453  view = dynamic_cast<QtView*> (*first);
454  if (view && view->isTextView())
455  max_z -= 100;
456 
457  first++;
458 
459  while ( first != m_items.end () ) {
460  Q3CanvasItem * item = *first;
461 #endif
462  double z = item -> z ();
463 
464  /* z()-100 for text */
465  view = dynamic_cast<QtView*> (item);
466  if (view && view->isTextView())
467  z -= 100;
468 
469 
470  first++;
471 
472  max_z = std::max ( max_z, z );
473  }
474 
475  return max_z;
476 }
477 
478 void
481 {
482 #if QT_VERSION < 0x040000
483  vector < QCanvasItem * > ::iterator first = m_items.begin();
484  while ( first != m_items.end() ) {
485  QCanvasItem * item = *first++;
486 #else
487  vector < Q3CanvasItem * > ::iterator first = m_items.begin();
488  while ( first != m_items.end() ) {
489  Q3CanvasItem * item = *first++;
490 #endif
491  if ( item->isSelected() ) continue;
492  item->setVisible ( yes );
493  }
494 }
495 
496 void
497 FigureEditor::
498 #if QT_VERSION < 0x040000
500 {
501  vector < QCanvasItem * > ::iterator first = m_items.begin ();
502  while ( first != m_items.end () ) {
503  QCanvasItem * item = *first++;
504 #else
505 setCollidingSelected ( const Q3CanvasItem * target )
506 {
507  vector < Q3CanvasItem * > ::iterator first = m_items.begin ();
508  while ( first != m_items.end () ) {
509  Q3CanvasItem * item = *first++;
510 #endif
511  if ( item != target ) {
512  if ( item -> collidesWith ( target ) ) {
513  if ( item -> selected () == false ) {
514  item -> setSelected ( true );
515  m_selected_list.push_back ( item );
516  }
517  }
518  }
519  }
520 }
521 
522 void
524 setSelectedItems ( bool state )
525 {
526 #ifdef ITERATOR_MEMBER_DEFECT
527  std::
528 #endif
529 #if QT_VERSION < 0x040000
530  vector < QCanvasItem * > ::iterator first = m_selected_list.begin();
531  while ( first != m_selected_list.end() ) {
532  QCanvasItem * item = *first++;
533 #else
534  vector < Q3CanvasItem * > ::iterator first = m_selected_list.begin();
535  while ( first != m_selected_list.end() ) {
536  Q3CanvasItem * item = *first++;
537 #endif
538  item->setSelected ( state );
539  }
540 }
541 
543 {
544  if ( m_selected_list.empty () == true ) return;
545 
546  setSelectedItems ( false );
547 
548  m_selected_list.clear();
549 }
550 
551 void
553 setAllSelected ( bool yes )
554 {
555 #if QT_VERSION < 0x040000
556 #ifdef MEMFUN1_DEFECT
557  for_each ( m_items.begin(), m_items.end(),
558  bind2nd ( mem_fun1 ( &QCanvasItem::setSelected ), yes ) );
559 #else
560  for_each ( m_items.begin(), m_items.end(),
561  bind2nd ( mem_fun ( &QCanvasItem::setSelected ), yes ) );
562 #endif
563 #else
564 #ifdef MEMFUN1_DEFECT
565  for_each ( m_items.begin(), m_items.end(),
566  bind2nd ( mem_fun1 ( &Q3CanvasItem::setSelected ), yes ) );
567 #else
568  for_each ( m_items.begin(), m_items.end(),
569  bind2nd ( mem_fun ( &Q3CanvasItem::setSelected ), yes ) );
570 #endif
571 #endif
572  if (yes) {
574  }
575 }
576 
578 {
579 
580  // Set all selected flags to false.
581  setAllSelected ( false );
582 
583  // Set all selected flags to true from m_selected_list.
584 #if QT_VERSION < 0x040000
585  vector < QCanvasItem * > :: iterator first = m_selected_list.begin();
586  while ( first != m_selected_list.end() ) {
587  QCanvasItem * item = *first++;
588 #else
589  vector < Q3CanvasItem * > :: iterator first = m_selected_list.begin();
590  while ( first != m_selected_list.end() ) {
591  Q3CanvasItem * item = *first++;
592 #endif
593  item->setSelected ( true );
594  }
595 }
596 
597 void
600 {
601  CanvasEvent * ce = dynamic_cast < CanvasEvent * > ( event );
602  if ( ce != 0 ) {
603 #if QT_VERSION < 0x040000
604  const QCanvasItem * item = ce -> item ();
605 #else
606  const Q3CanvasItem * item = ce -> item ();
607 #endif
608  makeVisible ( item );
609  }
610 }
611 void
612  FigureEditor::
613 #if QT_VERSION < 0x040000
614  makeVisible ( const QCanvasItem * item )
615 #else
616  makeVisible ( const Q3CanvasItem * item )
617 #endif
618 {
619  if ( item != 0 ) {
620  QRect rect = item->boundingRect ();
621  int x = 0, y = 0, w = 0, h = 0;
622  rect.rect( & x, & y, & w, & h );
623 #if QT_VERSION < 0x040000
624  QCanvasView::ensureVisible ( x, y, w, h );
625 #else
626  Q3CanvasView::ensureVisible ( x, y, w, h );
627 #endif
628  }
629 }
630 
631 void
632 FigureEditor::
633 #if QT_VERSION < 0x040000
635 #else
636 setSelectedItem ( Q3CanvasItem * item )
637 #endif
638 {
639 
640  m_selected_list.clear ();
641  setSelectedFlags ();
642  addSelectedItem ( item );
643 
644  double z = maximumZ ();
645 
646  /* SetZ for text plotter */
647  const QtView* view = dynamic_cast<const QtView*> (item);
648  if (view && view->isTextView())
649  item->setZ( z + 101.0); // ensures it is on top of other text plotters
650  else
651  item -> setZ ( z + 1.0 ); // ensures it is on top
652 
653  notifyObservers ();
654 }
655 
656 void
657 FigureEditor::
658 #if QT_VERSION < 0x040000
659 ensureVisible ( const QCanvasItem * item )
660 #else
661 ensureVisible ( const Q3CanvasItem * item )
662 #endif
663 {
664 #ifdef _MSC_VER
665 CanvasEvent * event = new CanvasEvent ( item );
666 qApp -> postEvent ( this, event );
667 #else
668  makeVisible ( item );
669 #endif
670 }
671 
672 void
674 setLocked ( bool yes )
675 {
676 #if QT_VERSION < 0x040000
677  // here
678  const vector < QCanvasItem * > & items = getSelectedItems ();
679  if ( items.empty () ) return; // shouldn't be called
680 
681 #ifdef MEMFUN_DEFECT
682  vector < QCanvasItem * >:: const_iterator first = items.begin ();
683  while ( first != items.end () ) {
684  QCanvasItem * item = *first++;
685  item->setActive ( yes );
686  }
687 #else
688 #ifdef MEMFUN1_DEFECT
689  for_each ( items.begin(), items.end(),
690  bind2nd ( mem_fun1 ( &QCanvasItem::setActive ), yes ) );
691 #else
692  for_each ( items.begin(), items.end(),
693  bind2nd ( mem_fun ( &QCanvasItem::setActive ), yes ) );
694 #endif
695 #endif
696  // here
697 #else
698  // here
699  const vector < Q3CanvasItem * > & items = getSelectedItems ();
700  if ( items.empty () ) return; // shouldn't be called
701 
702 #ifdef MEMFUN_DEFECT
703  vector < Q3CanvasItem * >:: const_iterator first = items.begin ();
704  while ( first != items.end () ) {
705  Q3CanvasItem * item = *first++;
706  item->setActive ( yes );
707  }
708 #else
709 #ifdef MEMFUN1_DEFECT
710  for_each ( items.begin(), items.end(),
711  bind2nd ( mem_fun1 ( &Q3CanvasItem::setActive ), yes ) );
712 #else
713  for_each ( items.begin(), items.end(),
714  bind2nd ( mem_fun ( &Q3CanvasItem::setActive ), yes ) );
715 #endif
716 #endif
717  // here
718 #endif
719 }
720 
724 void
725 FigureEditor::
726 #if QT_VERSION < 0x040000
728 #else
729 placeGraphOnSelected ( Q3CanvasRectangle * view )
730 #endif
731 {
732 
733  if ( !isSingleItemSelected() ) return;
734 
735 #if QT_VERSION < 0x040000
736  QCanvasItem * sel_item = selectedItem ();
737 #else
738  Q3CanvasItem * sel_item = selectedItem ();
739 #endif
740  QRect rect = sel_item->boundingRect ();
741 
742  view->setX ( rect.x() );
743  view->setY ( rect.y() );
744  view->setSize ( rect.width(), rect.height () );
745 
746  view->setCanvas ( m_canvas );
747  m_items.push_back ( view );
748  view->setSelected ( true );
749 
750  view->show ();
751 }
752 
757 {
758  // If both Shift and Control buttons are down, then error, do nothing.
759 
760 #if QT_VERSION < 0x040000
761  if ( e->state() == Qt::ShiftButton &&
762  e->state() == Qt::ControlButton ) return;
763 #else
764  if ( ( e -> modifiers () & Qt::ShiftModifier ) &&
765  ( e -> modifiers() & Qt::ControlModifier ) ) return;
766 #endif
767 
768  QPoint p = inverseWorldMatrix().map(e->pos());
769 #if QT_VERSION < 0x040000
771  QCanvasItemList::Iterator it = l.begin(); // for MS VC++
772  QCanvasItem * selItem = 0;
773 #else
774  Q3CanvasItemList l = m_canvas->collisions ( p );
775  Q3CanvasItemList::Iterator it = l.begin(); // for MS VC++
776  Q3CanvasItem * selItem = 0;
777 #endif
778  for ( ; it!=l.end(); ++it) {
779  selItem = *it;
780 #if QT_VERSION < 0x040000
781  vector < QCanvasItem * > ::const_iterator first
782 #else
783  vector < Q3CanvasItem * > ::const_iterator first
784 #endif
785  = std::find ( m_items.begin (), m_items.end (), selItem );
786  if ( first != m_items.end () ) { // only accept views
787  m_moving_start = p;
788  m_zoom_start = p;
789  break;
790  }
791  else {
792  selItem = 0;
793  }
794  }
795 
796  if ( selItem == 0 ) {
797  // There was no display where the click occurred. Ignore the click if
798  // its control click, else clear the selected list.
799 #if QT_VERSION < 0x040000
800  if ( e->state() != Qt::ControlButton ) {
801 #else
802  if ( ( e -> modifiers() & Qt::ControlModifier ) == 0 ) {
803 #endif
804  m_selected_list.clear();
806  whereClicked();
807  m_rightItem = 0;
808  return;
809  }
810  else {
811  return;
812  }
813  }
814 
815  // If control key is down, then add the current item to the vector, else
816  // clear the vector and then add the current item to the vector.
817 
818  if (e->button() == Qt::LeftButton)
819  {
820 
821  // Shift click is used to select multiple items when not in zoom mode.
822 
823 #if QT_VERSION < 0x040000
824  if (( e->state() == Qt::ShiftButton ) && (!getZoomMode()))
825 #else
826  if (( e -> modifiers () & Qt::ShiftModifier ) &&( !getZoomMode()))
827 #endif
828  {
829  if ( selItem -> isSelected () ) {
830  removeSelectedItem ( selItem );
831  }
832  else {
833  addSelectedItem ( selItem );
834  }
835  }
836 #if QT_VERSION < 0x040000
837  else if ( e->state() == Qt::ControlButton )
838 #else
839  else if ( e -> modifiers() & Qt::ControlModifier )
840 #endif
841  {
842  m_selected_list.clear();
844  addSelectedItem ( selItem );
845 
846  controlMousePressEvent (); // handled by derived class
847 
848  whereClicked ();
849  }
850 
851  else
852  { // neither shift nor control
853 #if QT_VERSION < 0x040000
854  vector < QCanvasItem * > ::const_iterator first
855 #else
856  vector < Q3CanvasItem * > ::const_iterator first
857 #endif
858  = std::find ( m_selected_list.begin (), m_selected_list.end (),
859  selItem );
860  // Selected plot. Drag to move or click to select signal plot.
861  if ( first != m_selected_list.end () )
862  {
863  m_mouse_down = p;
864  m_isMouseDown = true;
865  m_preSelected = selItem;
866  whereClicked();
867  return;
868  }
869 
870  // Not selected. Select the plot when mouse down.
871  else
872  {
873  setSelectedItem ( selItem );
874  whereClicked();
875  }
876  }
877  }
878 
879 
884  if ( e->button() == Qt::RightButton ||
885  e->state() == Qt::RightButton )
886  {
887  double z = maximumZ ();
888 
889  /* SetZ for text plotter */
890  const QtView* view = dynamic_cast<const QtView*> (selItem);
891  if (view && view->isTextView())
892  selItem->setZ( z + 101.0); // ensures it is on top of other text plotters
893  else
894  selItem -> setZ ( z + 1.0 ); // ensures it is on top
895 
896  m_rightItem = selItem;
897  }
898 }
899 
900 
901 
903 {
904 
906 
907  if ( !isSingleItemSelected() ) return;
908 
910 
911 #if QT_VERSION < 0x040000
912  QCanvasRectangle * rect
913  = dynamic_cast <QCanvasRectangle *> ( selectedItem() );
914 #else
915  Q3CanvasRectangle * rect
916  = dynamic_cast <Q3CanvasRectangle *> ( selectedItem() );
917 #endif
918 
919  // The margin around the point where a click will be registered.
920  int clickMargin = 10;
921 
923 
924  if ( ( p.x() < rect->x() + clickMargin ) &&
925  ( p.y() < rect->y() + clickMargin ) )
926  {
928  }
929 
930  if ( ( p.x() < ( rect->x() + (rect->width() / 2) + clickMargin ) ) &&
931  ( p.x() > ( rect->x() + (rect->width() / 2) - clickMargin ) ) &&
932  ( p.y() < rect->y() + clickMargin ) )
933  {
935  }
936 
937  if ( ( p.x() > ( rect->x() + rect->width() - clickMargin ) ) &&
938  ( p.y() < rect->y() + clickMargin ) )
939  {
941  }
942 
943  if ( ( p.x() < rect->x() + clickMargin ) &&
944  ( p.y() < ( rect->y() + (rect->height() / 2) + clickMargin ) ) &&
945  ( p.y() > ( rect->y() + (rect->height() / 2) - clickMargin ) ) )
946  {
948  }
949 
950  if ( ( p.x() > ( rect->x() + rect->width() - clickMargin ) ) &&
951  ( p.y() < ( rect->y() + (rect->height() / 2) + clickMargin ) ) &&
952  ( p.y() > ( rect->y() + (rect->height() / 2) - clickMargin ) ) )
953  {
955  }
956 
957  if ( ( p.x() < rect->x() + clickMargin ) &&
958  ( p.y() > rect->y() + rect->height() - clickMargin ) )
959  {
961  }
962 
963  if ( ( p.x() < ( rect->x() + (rect->width() / 2) + clickMargin ) ) &&
964  ( p.x() > ( rect->x() + (rect->width() / 2) - clickMargin ) ) &&
965  ( p.y() > rect->y() + rect->height() - clickMargin ) )
966  {
968  }
969 
970  if ( ( p.x() > ( rect->x() + rect->width() - clickMargin ) ) &&
971  ( p.y() > ( rect->y() + rect->height() - clickMargin ) ) )
972  {
974  }
975 
976 }
977 
978 void
979 FigureEditor::
980 #if QT_VERSION < 0x040000
982 {
983  vector < QCanvasItem * > ::iterator last
984 #else
985 removeFromItemList ( Q3CanvasItem * item )
986 {
987  vector < Q3CanvasItem * > ::iterator last
988 #endif
989  = std::remove ( m_items.begin (), m_items.end (), item );
990  m_items.erase ( last, m_items.end () );
991 }
992 
993 void
994 FigureEditor::
995 #if QT_VERSION < 0x040000
997 #else
998 addToItemList ( Q3CanvasItem * item )
999 #endif
1000 {
1001  item->setCanvas ( m_canvas );
1002  m_items.push_back ( item );
1003 }
1004 
1005 void
1006 FigureEditor::
1007 #if QT_VERSION < 0x040000
1008 remove ( QCanvasItem * item )
1009 #else
1010 remove ( Q3CanvasItem * item )
1011 #endif
1012 {
1013  removeSelectedItem ( item );
1014  //m_selected_list.clear();
1015  removeFromItemList ( item );
1016 
1017  //item->hide();
1018  //m_canvas->update();
1019  delete item;
1020 }
1021 
1022 void
1023 FigureEditor::
1024 #if QT_VERSION < 0x040000
1025 hide ( QCanvasItem * item )
1026 #else
1027 hide ( Q3CanvasItem * item )
1028 #endif
1029 {
1030  m_selected_list.clear();
1031  removeFromItemList ( item );
1032 
1033  item->hide();
1034  //m_canvas->update();
1035  //delete item;
1036 }
1037 
1039 {
1040 #if QT_VERSION < 0x040000
1041  vector < QCanvasItem * >:: iterator it = m_items.begin();
1042 #else
1043  vector < Q3CanvasItem * >:: iterator it = m_items.begin();
1044 #endif
1045  for ( ; it != m_items.end(); ++it ) {
1046  if ( *it ) delete *it;
1047  }
1048 
1049  m_items.clear();
1050  m_selected_list.clear();
1051 }
1052 
1060 void
1062 contentsMouseMoveEvent ( QMouseEvent * e, double aspect )
1063 {
1064  // Zoom mode is processed in CanvasView class.
1065  if ( getZoomMode() ) return;
1066 
1067  // Right button movement is processed by CanvasView class.
1068 
1069  QPoint p = inverseWorldMatrix().map(e->pos());
1070 
1071  if ( m_whereClicked == invalid ) return;
1072  if ( !isSingleItemSelected() ) return;
1073 
1074 #if QT_VERSION < 0x040000
1075  QCanvasItem * selItem = selectedItem();
1076  QCanvasRectangle * rect
1077  = dynamic_cast <QCanvasRectangle *> ( selItem );
1078 #else
1079  Q3CanvasItem * selItem = selectedItem();
1080  Q3CanvasRectangle * rect
1081  = dynamic_cast <Q3CanvasRectangle *> ( selItem );
1082 #endif
1083 
1084  QtView * view = dynamic_cast < QtView * > ( selItem );
1085  QtGroupView * gv = dynamic_cast < QtGroupView * > (selItem);
1086 
1087  float p_x = p.x ();
1088  float p_y = p.y ();
1089 
1090  float d_x = m_moving_start.x() - p_x;
1091  float d_y = m_moving_start.y() - p_y;
1092 
1093  float new_x = rect -> x();
1094  float new_y = rect -> y();
1095  float new_w = rect -> width ();
1096  float new_h = rect -> height ();
1097 
1098  switch ( m_whereClicked )
1099  {
1100 
1101 
1102  case none: // Move the selected view and all target text plotters
1103  if ( ! (getZoomMode() ) ) {
1104  if (view) movePlotterWithText(selItem, p.x()-m_moving_start.x(), p.y()-m_moving_start.y());
1105  if (gv) selItem->moveBy(p.x()-m_moving_start.x(), p.y()-m_moving_start.y());
1106  }
1107  break;
1108 
1109  case upper_left:
1110 
1111  new_x = p_x;
1112  new_y = p_y;
1113  new_w += d_x;
1114  new_h += d_y;
1115  if ( aspect > 0 ) {
1116  new_h += d_x;
1117  new_w = new_h * aspect;
1118  }
1119  new_w = std::max ( new_w, 20.0f );
1120  new_h = std::max ( new_h, 20.0f );
1121 
1122  if (view) view -> setDrawRect ( new_x, new_y, new_w, new_h );
1123  if (gv) gv -> setDrawRect ( new_x, new_y, new_w, new_h );
1124 
1125  rect->setEnabled ( true );
1126  break;
1127 
1128  case upper_middle:
1129 
1130  // new_x unchanged
1131  new_y = p_y;
1132  // new_w = unchanged
1133  new_h += d_y;
1134 
1135  if ( aspect > 0 ) {
1136  new_w += aspect * d_y;
1137  new_x -= 0.5 * aspect * d_y;
1138  }
1139 
1140  new_w = std::max ( new_w, 20.0f );
1141  new_h = std::max ( new_h, 20.0f );
1142 
1143  if (view) view -> setDrawRect ( new_x, p_y, new_w, new_h );
1144  if (gv) gv -> setDrawRect ( new_x, p_y, new_w, new_h );
1145 
1146  rect->setEnabled ( true );
1147  break;
1148 
1149  case upper_right:
1150 
1151  // new_x unchanged
1152  new_y = p_y;
1153  new_w -= d_x;
1154  new_h += d_y;
1155  if ( aspect > 0 ) {
1156  new_h -= d_x;
1157  new_w = aspect * new_h;
1158  }
1159 
1160  new_w = std::max ( new_w, 20.0f );
1161  new_h = std::max ( new_h, 20.0f );
1162 
1163  if (view) view -> setDrawRect ( new_x, new_y, new_w, new_h );
1164  if (gv) gv->setDrawRect ( new_x, new_y, new_w, new_h );
1165 
1166  rect->setEnabled ( true );
1167  break;
1168 
1169  case middle_left:
1170 
1171  new_x = p_x;
1172  // new_y unchanged
1173  new_w += d_x;
1174  // new_h unchanged
1175 
1176  if ( aspect > 0 ) {
1177  new_h += d_x / aspect;
1178  new_w = new_h * aspect;
1179  }
1180 
1181  new_w = std::max ( new_w, 20.0f );
1182  new_h = std::max ( new_h, 20.0f );
1183 
1184  if (view) view -> setDrawRect ( new_x, new_y, new_w, new_h );
1185  if (gv) gv -> setDrawRect ( new_x, new_y, new_w, new_h );
1186 
1187  rect->setEnabled ( true );
1188  break;
1189 
1190  case middle_right:
1191 
1192  // new_x unchanged
1193  // new_y unchanged
1194  new_w -= d_x;
1195  // new_h unchanged
1196 
1197  if ( aspect > 0 ) {
1198  new_h -= d_x / aspect;
1199  new_w = new_h * aspect;
1200  }
1201 
1202  new_w = std::max ( new_w, 20.0f );
1203  new_h = std::max ( new_h, 20.0f );
1204 
1205  if (view) view -> setDrawRect ( new_x, new_y, new_w, new_h );
1206  if (gv) gv -> setDrawRect ( new_x, new_y, new_w, new_h );
1207 
1208  rect->setEnabled ( true );
1209  break;
1210 
1211  case lower_left:
1212 
1213  new_x = p_x;
1214  // new_y unchanged
1215  new_w += d_x;
1216  new_h-= d_y;
1217 
1218  if ( aspect > 0 ) {
1219  new_h += d_x;
1220  new_y -= d_x;
1221  new_w = new_h * aspect;
1222  }
1223 
1224  new_w = std::max ( new_w, 20.0f );
1225  new_h = std::max ( new_h, 20.0f );
1226 
1227  if (view) view -> setDrawRect ( new_x, new_y, new_w, new_h );
1228  if (gv) gv -> setDrawRect ( new_x, new_y, new_w, new_h );
1229 
1230  rect->setEnabled ( true );
1231  break;
1232 
1233  case lower_middle:
1234 
1235  // new_x unchanged
1236  // new_y unchanged
1237  // new_w unchanged
1238  new_h -= d_y;
1239 
1240  if ( aspect > 0 ) {
1241  new_w = new_h * aspect;
1242  new_x += 0.5 * aspect * d_y;
1243  }
1244  new_w = std::max ( new_w, 20.0f );
1245  new_h = std::max ( new_h, 20.0f );
1246 
1247  if (view) view -> setDrawRect ( new_x, new_y, new_w, new_h );
1248  if (gv) gv -> setDrawRect ( new_x, new_y, new_w, new_h );
1249 
1250  rect->setEnabled ( true );
1251  break;
1252 
1253  case lower_right:
1254 
1255  // new_x unchanged
1256  // new_y unchanged
1257  new_w -= d_x;
1258  new_h -= d_y;
1259 
1260  if ( aspect > 0 ) {
1261  new_h -= d_x;
1262  new_w = aspect * new_h;
1263  new_y += d_x;
1264  }
1265  new_w = std::max ( new_w, 20.0f );
1266  new_h = std::max ( new_h, 20.0f );
1267 
1268  if (view) view -> setDrawRect ( new_x, new_y, new_w, new_h );
1269  if (gv) gv -> setDrawRect ( new_x, new_y, new_w, new_h );
1270 
1271  rect->setEnabled ( true );
1272  break;
1273 
1274  default:
1275 
1276  break;
1277 
1278  }
1279 
1280  m_moving_start = p;
1281 
1282  m_canvas->update();
1283 
1284 }
1285 
1286 
1287 
1290 void
1293 {
1294  if (!m_isMouseDown) return;
1295 
1296  QPoint p = inverseWorldMatrix().map(e->pos());
1297 
1298  // Mouse has not moved, process as a click.
1299  if ( p==m_mouse_down ) {
1301  m_isMouseDown = false;
1302  }
1303 
1304 }
1305 
1306 
1307 void
1308 FigureEditor::
1309 #if QT_VERSION < 0x040000
1311 #else
1312 placeGraph ( Q3CanvasRectangle * item )
1313 #endif
1314 {
1315  item -> setX ( 0 );
1316  item -> setY ( 0 );
1317 
1318  int margin_x = 0;
1319  int margin_y = 0;
1320  int max_width = 0;
1321 
1322  if ( m_ignore_margin == false ) {
1323  margin_x = ( m_apage_w - m_upage_w ) / 2;
1324  margin_y = ( m_apage_h - m_upage_h ) / 2;
1325  max_width = m_apage_w - margin_x;
1326  }
1327  else {
1328  max_width = m_canvas -> width ();
1329  }
1330 
1331  if ( item -> x () < margin_x ) item -> setX ( margin_x + 1 );
1332  if ( item -> y () < margin_y ) item -> setY ( margin_y + 1 );
1333 
1334  if ( m_items.empty () ) return;
1335 
1336  double deltax = 1.05 * item -> width ();
1337  double deltay = 1.05 * item -> height ();
1338 
1339  while ( true ) {
1340  if ( m_ignore_margin == false ) {
1341  QRect brect = item->boundingRect ();
1342  int top = brect.top () / m_apage_h;
1343  int bot = brect.bottom () / m_apage_h;
1344  if ( top != bot ) { // across page boundary
1345  int new_y = bot * m_apage_h;
1346  new_y += ( m_apage_h - m_upage_h ) / 2;
1347  item->setY ( new_y ); // beginning next actual page
1348  }
1349  }
1350 
1351 #if QT_VERSION < 0x040000
1352  vector < QCanvasItem * >:: iterator it = m_items.begin();
1353 #else
1354  vector < Q3CanvasItem * >:: iterator it = m_items.begin();
1355 #endif
1356  bool collides = false;
1357 
1358  for ( ; it != m_items.end(); ++it ) {
1359  if ( (*it)->collidesWith ( item ) ) {
1360  collides = true;
1361  break;
1362  }
1363  }
1364 
1365  if ( !collides ) break;
1366  if ( item -> x() + deltax + item -> width () < max_width ) {
1367  item -> moveBy ( deltax, 0 ); // move across
1368  }
1369  else {
1370  item -> setX ( margin_x + 1 );
1371  item -> moveBy ( 0, deltay ); // move down
1372  }
1373 
1374  } // while true
1375 
1376 }
1377 
1378 void
1379 FigureEditor::
1380 #if QT_VERSION < 0x040000
1381 add ( QCanvasItem * item )
1382 #else
1383 add ( Q3CanvasItem * item )
1384 #endif
1385 {
1386  resizeCanvasToFit ( item );
1387 
1388  item->setCanvas ( m_canvas );
1389  m_items.push_back ( item );
1390  item->setSelected ( false );
1391 
1392  item->show ();
1393  QRect area = item -> boundingRect ();
1394  m_canvas -> setChanged ( area );
1395  m_canvas -> update();
1396 }
1397 
1400 void
1401 FigureEditor::
1402 #if QT_VERSION < 0x040000
1403 paste ( QCanvasItem * item )
1404 #else
1405 paste ( Q3CanvasItem * item )
1406 #endif
1407 {
1408  add ( item );
1409 #if QT_VERSION < 0x040000
1410  QCanvasItemList items = item->collisions ( true );
1411 #else
1412  Q3CanvasItemList items = item->collisions ( true );
1413 #endif
1414  unsigned int count = items.count ();
1415  if ( count > 1 ) {
1416 
1417  item->moveBy ( 10., 10. );
1418  }
1419 }
1420 
1421 void
1422 FigureEditor::
1423 #if QT_VERSION < 0x040000
1425 #else
1426 resizeCanvasToFit ( Q3CanvasItem * item )
1427 #endif
1428 {
1429  QRect brect = item->boundingRect ();
1430  QPoint p = brect.bottomRight ();
1431  if ( ! m_canvas->onCanvas ( p ) )
1432  {
1433  int new_w = m_canvas->width ();
1434  int old_h = m_canvas->height();
1435  int new_h = old_h + m_apage_h;
1436  m_canvas->resize ( new_w, new_h );
1437  addPageMargin ( 0, old_h );
1438  }
1439 }
1440 
1441 void
1443 scaleBy ( double factor )
1444 {
1445  m_apage_w = static_cast < int > ( factor * m_apage_w );
1446  m_apage_h = static_cast < int > ( factor * m_apage_h );
1447  m_upage_w = static_cast < int > ( factor * m_upage_w );
1448  m_upage_h = static_cast < int > ( factor * m_upage_h );
1449 
1450  m_canvas -> resize ( m_apage_w, m_apage_h );
1451  resizeContents ( m_apage_w, m_apage_h );
1452 
1453  m_scale_factor = factor;
1454 
1455  if( m_printer_bounds == true )
1456  {
1457  showPrinterMargins ( false ); // Delete old ones ( if any )
1458  showPrinterMargins ( true ); // Redraw new ones ( if needed )
1459  }
1460 }
1461 
1462 void
1465 {
1466 #if QT_VERSION < 0x040000
1467  QWMatrix matrix = worldMatrix ();
1468 #else
1469  QMatrix matrix = worldMatrix ();
1470 #endif
1471  matrix.scale( 4./3., 4./3. );
1472 
1473  setWorldMatrix ( matrix );
1474 }
1475 
1479 void
1482 {
1483 #if QT_VERSION < 0x040000
1484  QWMatrix matrix = worldMatrix ();
1485 #else
1486  QMatrix matrix = worldMatrix ();
1487 #endif
1488  matrix.scale( 3./4., 3./4. );
1489 
1490  setWorldMatrix ( matrix );
1491 }
1492 
1493 void
1496 {
1497 #if QT_VERSION < 0x040000
1498  QWMatrix matrix = worldMatrix ();
1499 #else
1500  QMatrix matrix = worldMatrix ();
1501 #endif
1502  matrix.reset();
1503 
1504  setWorldMatrix ( matrix );
1505 }
1506 
1507 void
1510 {
1511  QSettings settings;
1512  settings.insertSearchPath ( QSettings::Windows, s_registry );
1513 
1514  QPrinter::PageSize page_size = s_printer -> pageSize ();
1515  settings.writeEntry ( s_app_key + "Printer/PageSize", page_size );
1516 
1517 }
1518 
1519 void
1522 {
1523  #if QT_VERSION < 0x040000
1524  bool yes = s_printer -> setup ( this );
1525 // if ( yes == false ) return;
1526 #else
1527  QPrintDialog dialog ( s_printer, this );
1528  bool yes = ( dialog.exec () == QDialog::Accepted );
1529 #endif
1530 
1531  if ( yes ) {
1533  }
1534 
1535 }
1536 
1539 void
1542 {
1543  bool yes = s_printer->setup ( this );
1544  if ( yes == false ) return;
1545 
1546  print ( s_printer );
1547 
1548 }
1549 
1550 void
1552 print ( const std::string & filename )
1553 {
1554  const QString name = filename.c_str();
1555  s_printer -> setOutputFileName ( name );
1556  s_printer -> setOutputToFile ( true );
1557 
1558  print ( s_printer );
1559 }
1560 
1561 void
1563 print ( QPrinter * printer )
1564 {
1565  setSelectedItems ( false ); // hide border
1566  QPainter painter;
1567  bool ok = painter.begin ( printer );
1568  assert ( ok );
1569 
1570  calcPrinterMetrics ( painter.device () );
1571  double scale = 1.0 / m_scale_factor;
1572  painter.scale ( scale, scale );
1573  int page_y = 0;
1574  int trans_y = static_cast < int > ( m_apage_h * m_scale_factor );
1575 
1576  while ( page_y < m_canvas->height() ) {
1577  const QRect clip ( 0, page_y, m_apage_w, m_apage_h );
1578 #if QT_VERSION < 0x040000
1579  QCanvasItemList items = m_canvas->collisions ( clip );
1580 #else
1581  Q3CanvasItemList items = m_canvas->collisions ( clip );
1582 #endif
1583 
1584  if ( items.empty () ) {
1585  page_y += m_apage_h;
1586  painter.translate ( 0, - trans_y );
1587  continue;
1588  }
1589 
1590  if ( page_y != 0 ) printer->newPage();
1591  page_y += m_apage_h;
1592 
1593  bool dbuf = false;
1594 
1595  m_canvas->drawArea ( clip, & painter, dbuf );
1596  painter.translate ( 0, - trans_y );
1597  }
1598 
1599  painter.end();
1600  setSelectedItems ( true ); // hide border
1601 }
1602 
1603 void
1606 {
1607  const QSize & w_size = e->size();
1608 
1609  // need to specify type for vs.net compiler
1610  int new_w = std::max<int> ( w_size.width (), m_canvas->width () );
1611  int new_h = std::max<int> ( w_size.height (), m_canvas->height () );
1612 
1613  m_canvas->resize ( new_w, new_h );
1614 
1615  updateScrollBars ();
1616 }
1617 
1618 void
1621 {
1622  int old_y = m_canvas->height ();
1623  m_canvas->resize ( m_canvas->width(), old_y + m_apage_h );
1624  addPageMargin ( 0, old_y );
1625 
1626  updateScrollBars ();
1627 }
1628 
1629 void
1631 saveSelectedAsPixmap ( const std::string & filename )
1632 {
1633  QRect rect = getSelectedBounds ();
1634  setSelectedItems ( false ); // hide for pixmap
1635  saveAreaAsPixmap ( rect, filename );
1636  setSelectedItems ( true ); // restore
1637 }
1638 
1639 QPixmap *
1641 createPixmap ( const QRect & rect ) const
1642 {
1643  QPixmap * pixmap = new QPixmap ( rect.width(), rect.height() );
1644  QPainter painter;
1645 
1646  painter.begin ( pixmap );
1647  painter.translate ( -rect.x(), -rect.y() );
1648  m_canvas->drawArea ( rect, & painter );
1649  painter.end ();
1650 
1651  return pixmap;
1652 }
1653 
1654 void
1656 saveAreaAsPixmap ( const QRect & rect, const std::string & filename )
1657 {
1658  QPixmap * pixmap = createPixmap ( rect );
1659 
1660  QString fn ( filename.c_str() );
1661  string::size_type i = filename.find_last_of ( '.' );
1662  string suffix ( filename.substr ( i + 1 ) );
1663  transform ( suffix.begin(), suffix.end(),
1664  suffix.begin(), toupper );
1665  if ( suffix == "JPG" ) suffix = "JPEG";
1666 
1667  pixmap -> save ( fn, suffix.c_str() );
1668 
1669  delete pixmap;
1670 }
1671 
1672 QImage
1674 createImage ( const QRect & rect ) const
1675 {
1676  QPixmap * pixmap = createPixmap ( rect );
1677  QImage image = pixmap -> convertToImage ();
1678 
1679  return image;
1680 }
1681 
1682 void
1685 {
1686  QRect rect = getSelectedBounds ();
1687  QImage image = createImage ( rect );
1688 #if QT_VERSION < 0x040000
1689  QImageDrag * image_drag = new QImageDrag ( image );
1690 #else
1691  Q3ImageDrag * image_drag = new Q3ImageDrag ( image );
1692 #endif
1694  cb -> setData ( image_drag );
1695 }
1696 
1699 void
1701 setZoomMode ( bool flag )
1702 {
1703  m_zoom_mode = flag;
1704  if ( flag ) {
1705  QApplication::setOverrideCursor( QCursor ( Qt::CrossCursor ) );
1706  QWidget * view_port = viewport ();
1707  view_port -> setMouseTracking ( TRUE );
1708  }
1709  else {
1711  QWidget * view_port = viewport ();
1712  view_port -> setMouseTracking ( FALSE );
1713  }
1714 }
1715 
1716 void
1719 {
1721 }
1722 
1723 void
1726 {
1727  if ( m_zoom_mode == true ) {
1728  QApplication::setOverrideCursor ( QCursor ( Qt::CrossCursor ) );
1729  }
1730 }
1731 
1732 bool
1734 getZoomMode ( ) const
1735 {
1736  return m_zoom_mode;
1737 }
1738 
1739 const QString &
1741 getAppKey () const
1742 {
1743  return s_app_key;
1744 }
1745 
1746 const QString &
1748 getRegistry () const
1749 {
1750  return s_registry;
1751 }
1752 
1753 #if QT_VERSION < 0x040000
1754 QCanvasItem *
1755 #else
1756 Q3CanvasItem *
1757 #endif
1759 {
1760  return m_rightItem;
1761 }
1762 
1763 void
1766 {
1767  if (getZoomMode()) return;
1768 
1769  QPoint p = inverseWorldMatrix().map(e->pos());
1770 
1771 #if QT_VERSION < 0x040000
1772  vector < QCanvasItem * >::iterator it = m_selected_list.begin();
1773 #else
1774  vector < Q3CanvasItem * >::iterator it = m_selected_list.begin();
1775 #endif
1776 
1777  while ( it != m_selected_list.end() )
1778  {
1779  movePlotterWithText ( *it, p.x()-m_moving_start.x(), p.y()-m_moving_start.y());
1780  it++;
1781  }
1782  m_moving_start = p;
1783 
1784  m_canvas->update();
1785 }
1786 
1787 void
1788 FigureEditor::
1789 #if QT_VERSION < 0X040000
1790 movePlotterWithText( QCanvasItem * item, float dx, float dy )
1791 #else
1792 movePlotterWithText ( Q3CanvasItem * item, float dx, float dy )
1793 #endif
1794 {
1795 
1796 #if QT_VERSION < 0x040000
1797  QCanvasItemList item_list = m_canvas->allItems();
1798  QCanvasItemList::Iterator it = item_list.begin();
1799 #else
1800  Q3CanvasItemList item_list = m_canvas->allItems();
1801  Q3CanvasItemList::Iterator it = item_list.begin();
1802 #endif
1803 
1804  QtView * xyview = dynamic_cast < QtView * > ( item );
1805  PlotterBase * xyplotter = xyview->getPlotter();
1806 
1807  /* Move the selected plotter */
1808  item->moveBy(dx,dy);
1809 
1810  /* Move all child text plotters */
1811  for ( ; it !=item_list.end(); ++it ) {
1812  const QtView * view = dynamic_cast < const QtView * > ( *it);
1813  if (view!=0){
1814  PlotterBase * plotter = view->getPlotter();
1815  if ( (plotter->isTextPlotter()) && (plotter->getParentPlotter()==xyplotter) ){
1816  (*it)->moveBy(dx,dy);
1817  }
1818  }
1819  }
1820 }
1821 
1822 

Generated for HippoDraw Class Library by doxygen