00001
00012 #ifdef _MSC_VER
00013 #include "msdevstudio/MSconfig.h"
00014 #endif
00015
00016 #include "QtGroupView.h"
00017 #include "DrawBorder.h"
00018
00019 #include "qpainter.h"
00020
00021
00022
00023
00024
00025 #include <cassert>
00026 #include <iostream>
00027
00028
00029 using std::vector;
00030
00031 using namespace hippodraw;
00032
00033 QtGroupView::QtGroupView ( )
00034 :GroupViewBase (),
00035 QtViewImp (),
00036 #if QT_VERSION < 0x040000
00037 QCanvasRectangle ( 0 )
00038 #else
00039 Q3CanvasRectangle ( 0 )
00040 #endif
00041 {
00042 }
00043
00044
00045 QtGroupView::QtGroupView ( const std::vector < ViewBase * > & inViews )
00046 :GroupViewBase ( inViews ),
00047 QtViewImp (),
00048 #if QT_VERSION < 0x040000
00049 QCanvasRectangle ( 0 )
00050 #else
00051 Q3CanvasRectangle ( 0 )
00052 #endif
00053 {
00054 }
00055
00056 QtGroupView::~QtGroupView ()
00057 {
00058 vector < ViewBase * >::const_iterator first = mViews.begin();
00059 for ( ; first != mViews.end(); ++first ) {
00060
00061 delete (*first);
00062 }
00063 }
00064
00065
00066 void QtGroupView::setDrawRect ( float x, float y, float w, float h )
00067 {
00068
00069
00070
00071 m_is_drawing=true;
00072
00073 setX ( x );
00074 setY ( y );
00075
00076 int iw = static_cast< int > ( w );
00077 int ih = static_cast< int > ( h );
00078 setSize ( iw, ih );
00079
00080 m_is_drawing=false;
00081
00082 if ( m_position.size() == 0 ) return;
00083
00084
00085 vector < ViewBase * >::const_iterator first = mViews.begin();
00086 for ( unsigned int i = 0; first != mViews.end(); ++first, i=i+4 ) {
00087 QtView * qtview = dynamic_cast < QtView * > ( *first );
00088
00089 qtview->setDrawRect ( x+w*m_position[i],
00090 y+h*m_position[i+1],
00091 w*m_position[i+2],
00092 h*m_position[i+3] );
00093 }
00094 }
00095
00096 void QtGroupView::setDrawRect ( const QRect & rect )
00097 {
00098 setDrawRect ( rect.x (), rect.y (), rect.width (), rect. height () );
00099 }
00100
00101 Rect QtGroupView::getDrawRect () const
00102 {
00103 return Rect ( x(), y(), width(), height() );
00104 }
00105
00106
00107 void QtGroupView::draw ( QPainter & painter )
00108
00109 {
00110
00111
00112 m_is_drawing = true;
00113
00114 const QColor color ( "black" );
00115 painter.setPen ( color );
00116 m_painter = & painter;
00117
00118 if ( isSelected () )
00119 {
00120 DrawBorder * border = DrawBorder::instance();
00121 border->setView (this);
00122 border->draw();
00123 }
00124 m_is_drawing = false;
00125 }
00126
00127
00128
00129
00130 void
00131 QtGroupView::
00132 fillPickedPoint ( double dx, double dy,
00133 std::vector < double > & picked ) const
00134 {
00135 }
00136
00137 int QtGroupView::toCanvasX ( double dx ) const
00138 {
00139 return static_cast < int > ( x() + dx );
00140 }
00141
00142 int QtGroupView::toCanvasY ( double dy ) const
00143 {
00144 return static_cast < int > ( y() + dy );
00145 }
00146
00147
00148 int QtGroupView::toViewX ( double datX ) const
00149 {
00150 return 0;
00151
00152 }
00153
00154 int QtGroupView::toViewY ( double datY ) const
00155 {
00156 return 0;
00157
00158 }
00159
00160 void QtGroupView::moveBy ( double dx, double dy )
00161 {
00162 #if QT_VERSION < 0x040000
00163 QCanvasRectangle::moveBy ( dx, dy );
00164 #else
00165 Q3CanvasRectangle::moveBy (dx, dy);
00166 #endif
00167
00168 if ( m_is_drawing == true ) return;
00169
00170 vector < ViewBase * >::const_iterator first = mViews.begin();
00171 for ( ; first != mViews.end(); ++first ) {
00172 QtView * qtview = dynamic_cast < QtView * > ( *first );
00173 qtview->moveBy ( dx, dy );
00174 }
00175 }
00176
00177 void QtGroupView::setPositions()
00178 {
00179
00180
00181 vector < ViewBase * >::const_iterator first = mViews.begin();
00182 for ( ; first != mViews.end(); ++first ) {
00183 QtView * qtview = dynamic_cast < QtView * > ( *first );
00184 m_position.push_back( (qtview->x()-x())/width() );
00185 m_position.push_back( (qtview->y()-y())/height() );
00186 m_position.push_back( ((double)(qtview->width()))/width() );
00187 m_position.push_back( ((double)(qtview->height()))/height() );
00188 }
00189 }
00190