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 
unsigned int i
std::vector< double > m_position
A vector containing the percentage position information for every views.
Definition: QtGroupView.h:60
virtual Rect getDrawRect() const
Gets the drawing rectangle.
int toCanvasY(double dy) const
Converts coordinate from view space to canvas space.
static DrawBorder * instance()
Returns the pointer to the singleton instance.
Definition: DrawBorder.cxx:39
void draw()
Does the actual drawing in the view.
Definition: DrawBorder.cxx:57
QPainter * m_painter
The current Qt QPainter object.
Definition: QtViewImp.h:76
setPen(const QPen &pen)
int toViewY(double datY) const
Converts the data space coordinate Y to the view space coordinate Y.
x() const
y() const
This is the abstract base class for a group view.
Definition: GroupViewBase.h:27
int toCanvasX(double dx) const
Converts coordinate from view space to canvas space.
void setView(ViewBase *view)
Sets the View object.
Definition: DrawBorder.cxx:47
else
Definition: CanvasView.cxx:879
DrawBorder class interface.
setSize(int width, int height)
The class of derived from ViewBase for drawing to the screen and PostScript generation using Qt toolk...
Definition: QtViewImp.h:47
int toViewX(double datX) const
Converts the data space coordinate X to the view space coordinate X.
bool m_is_drawing
A flag set true when drawing has stared.
Definition: QtGroupView.h:56
virtual ~QtGroupView()
Copy constructor.
Definition: QtGroupView.cxx:56
void setPositions()
Set the positions in percentage of every views.
QtGroupView()
The constructor.
Definition: QtGroupView.cxx:33
Class representing a rectangle.
Definition: Rectangle.h:34
virtual void draw(QPainter &)
Re-implement the draw() method in QCanvasItem.
The class of derived from ViewBase and QCanvasRectangle for drawing on a QCanvas. ...
Definition: QtView.h:41
A singleton class to draw the border with knobies around the selected display.
Definition: DrawBorder.h:23
width() const
hippodraw::QtGroupView class interface
if(ok==false) return
void setDrawRect(const QRect &rect)
Sets the drawing rectangle in the paint device space.
Definition: QtView.cxx:200
virtual void fillPickedPoint(double x, double y, std::vector< double > &picked) const
Fills the picked point vector.
virtual void moveBy(double dx, double dy)
Re-implement the moveBy() method so that all views in the group will move.
void setDrawRect(float x, float y, float w, float h)
Sets the drawing rectangle in the paint device space.
Definition: QtGroupView.cxx:66
std::vector< ViewBase * > mViews
A vector that keeps all view in the same group view.
Definition: GroupViewBase.h:31

Generated for HippoDraw Class Library by doxygen