QtGroupView.cxx
Go to the documentation of this file.
1 
12 #ifdef _MSC_VER
13 #include "msdevstudio/MSconfig.h"
14 #endif
15 
16 #include "QtGroupView.h"
17 #include "DrawBorder.h"
18 
19 #include "qpainter.h"
20 //#if QT_VERSION < 0x040000
21 //#else
22 //#include <QPaintEngine>
23 //#endif
24 
25 #include <cassert>
26 #include <iostream>
27 
28 
29 using std::vector;
30 
31 using namespace hippodraw;
32 
34  :GroupViewBase (),
35  QtViewImp (),
36 #if QT_VERSION < 0x040000
37  QCanvasRectangle ( 0 )
38 #else
39  Q3CanvasRectangle ( 0 )
40 #endif
41 {
42 }
43 
44 
45 QtGroupView::QtGroupView ( const std::vector < ViewBase * > & inViews )
46  :GroupViewBase ( inViews ),
47  QtViewImp (),
48 #if QT_VERSION < 0x040000
49  QCanvasRectangle ( 0 )
50 #else
51  Q3CanvasRectangle ( 0 )
52 #endif
53 {
54 }
55 
57 {
58  vector < ViewBase * >::const_iterator first = mViews.begin();
59  for ( ; first != mViews.end(); ++first ) {
60  //QtView * qtview = dynamic_cast < QtView * > ( *first );
61  delete (*first);
62  }
63 }
64 
65 
66 void QtGroupView::setDrawRect ( float x, float y, float w, float h )
67 {
68  // setX() and setY() will call moveBy()
69  // set this flag to true so that the overridden moveBy() will not
70  // move the views.
71  m_is_drawing=true;
72 
73  setX ( x );
74  setY ( y );
75 
76  int iw = static_cast< int > ( w );
77  int ih = static_cast< int > ( h );
78  setSize ( iw, ih );
79 
80  m_is_drawing=false;
81 
82  if ( m_position.size() == 0 ) return; // first time to set draw rect.
83 
84  // set draw rectangle for every views.
85  vector < ViewBase * >::const_iterator first = mViews.begin();
86  for ( unsigned int i = 0; first != mViews.end(); ++first, i=i+4 ) {
87  QtView * qtview = dynamic_cast < QtView * > ( *first );
88 
89  qtview->setDrawRect ( x+w*m_position[i],
90  y+h*m_position[i+1],
91  w*m_position[i+2],
92  h*m_position[i+3] );
93  }
94 }
95 
96 void QtGroupView::setDrawRect ( const QRect & rect )
97 {
98  setDrawRect ( rect.x (), rect.y (), rect.width (), rect. height () );
99 }
100 
102 {
103  return Rect ( x(), y(), width(), height() );
104 }
105 
106 
107 void QtGroupView::draw ( QPainter & painter )
108 
109 {
110  // only draw the border
111 
112  m_is_drawing = true;
113 
114  const QColor color ( "black" );
115  painter.setPen ( color );
116  m_painter = & painter;
117 
118  if ( isSelected () )
119  {
120  DrawBorder * border = DrawBorder::instance();
121  border->setView (this);
122  border->draw();
123  }
124  m_is_drawing = false;
125 }
126 
127 
128 
129 // Abstract methods from QtViewImp class.
130 void
132 fillPickedPoint ( double dx, double dy,
133  std::vector < double > & picked ) const
134 {
135 }
136 
137 int QtGroupView::toCanvasX ( double dx ) const
138 {
139  return static_cast < int > ( x() + dx );
140 }
141 
142 int QtGroupView::toCanvasY ( double dy ) const
143 {
144  return static_cast < int > ( y() + dy );
145 }
146 
147 
148 int QtGroupView::toViewX ( double datX ) const
149 {
150  return 0;
151  //return static_cast< int > ( x() + userToMarginX ( datX ) );
152 }
153 
154 int QtGroupView::toViewY ( double datY ) const
155 {
156  return 0;
157  //return static_cast< int > ( y() + userToInvertedMarginY ( datY ) );
158 }
159 
160 void QtGroupView::moveBy ( double dx, double dy )
161 {
162 #if QT_VERSION < 0x040000
163  QCanvasRectangle::moveBy ( dx, dy );
164 #else
165  Q3CanvasRectangle::moveBy (dx, dy);
166 #endif
167 
168  if ( m_is_drawing == true ) return;
169 
170  vector < ViewBase * >::const_iterator first = mViews.begin();
171  for ( ; first != mViews.end(); ++first ) {
172  QtView * qtview = dynamic_cast < QtView * > ( *first );
173  qtview->moveBy ( dx, dy );
174  }
175 }
176 
178 {
179 
180  // Is it OK to convert int to double?
181  vector < ViewBase * >::const_iterator first = mViews.begin();
182  for ( ; first != mViews.end(); ++first ) {
183  QtView * qtview = dynamic_cast < QtView * > ( *first );
184  m_position.push_back( (qtview->x()-x())/width() );
185  m_position.push_back( (qtview->y()-y())/height() );
186  m_position.push_back( ((double)(qtview->width()))/width() );
187  m_position.push_back( ((double)(qtview->height()))/height() );
188  }
189 }
190 

Generated for HippoDraw Class Library by doxygen