Main Page   Namespace List   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

/cygdrive/d/Eigene Dateien/!DProcs/code_gen/QWindow.cpp

Go to the documentation of this file.
00001 // Class QWindow 
00002 // Widget which is a GUI-Window.
00003 // Filename QWindow.cpp
00004 // FaPra 2003-2004, A5,  Alexander Kramer
00005 
00006 
00007 #include "QWindow.h"
00008 #include <iostream>
00009 using namespace std;
00010 
00011 // ----------------------------------------------------------
00012 
00013 #include "QWindow_Handlers.h"
00014 //! draws frame
00015 void QWindow::drawFrame()
00016 {
00017 
00018   const int border = TitleBarBorder;
00019 
00020   int fleft = 0;
00021   int ftop  = 0;
00022 
00023   int fwidth = Width;
00024   int fheight = Height;
00025 
00026   // draw client region - fill with the background color
00027   LookAndFeel->getBackGroundColor()->setAsCurrent();
00028   glBegin(GL_POLYGON);
00029   LookAndFeel->drawRect(fleft,ftop,Width,Height);
00030   glEnd();
00031 
00032   // draw up bevel and down bevel to simulate round frame
00033   LookAndFeel->drawBevel(fleft,ftop,fwidth,fheight,bsUp);
00034   LookAndFeel->drawBevel(fleft+border,ftop+border,fwidth-2*border,fheight-2*border,bsDown);
00035 
00036   // check if window is in focus path. If so sets color of the title bar and font to bold
00037   // (Highlighting of the active window)
00038   if (Owner->getFocusPath() == this)
00039    {
00040      TitleBarColor->setAsCurrent();
00041      Font->setBold(true);
00042    }
00043   else
00044    {
00045      TitleBarColorInactive->setAsCurrent();
00046      Font->setBold(false);
00047    }
00048 
00049   // draw window title bar
00050   glBegin(GL_POLYGON);
00051   LookAndFeel->drawRect(fleft+border,ftop+border,fwidth-2*border,TitleBarHeight);
00052   glEnd();
00053 
00054   // draw window title bar caption
00055   int maxLen = Font->getLengthForWidth(Caption.c_str(),MaximizeButton->getLeft()-(fleft+border+2));
00056   Font->drawAtPos(Caption.c_str(),fleft+border+2,ftop+border+2,maxLen);
00057 
00058   // sets font to normal
00059   Font->setBold(false);
00060 
00061   // If window is resizable, draw a kind of triangle in the right bottom corner
00062   if (Resizable)
00063   {
00064      glColor3f(1,1,1);
00065      glBegin(GL_LINES);
00066      glVertex2i(fwidth-border,fheight-12);
00067      glVertex2i(fwidth-12,fheight-border);
00068 
00069      glVertex2i(fwidth-border,fheight-8);
00070      glVertex2i(fwidth-8,fheight-border);
00071 
00072      glEnd();
00073   }
00074 
00075 
00076   // check if window is currently resizing or dragging and draw nice looking info about position/size
00077   if (Resizing)
00078   {
00079      char buf[101];
00080      snprintf(buf,100,"resize to %dx%d",Width,Height);
00081      drawCoordInfos(fwidth+10,fheight-10,buf);
00082   }
00083   else
00084   if (Dragging)
00085   {
00086      char buf[101];
00087      snprintf(buf,100,"move to (%d,%d)",Left,Top);
00088      drawCoordInfos(fleft+5,ftop-25,buf);
00089   }
00090 
00091 } // end of drawFrame()
00092 
00093 //! draws info about size/position. Semi transparent rectangle with window font 
00094 void QWindow::drawCoordInfos( int  x , int  y , const  char*  Text )
00095 {
00096   float textwidth = Font->getTextWidth(Text);
00097   glEnable(GL_BLEND);
00098   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00099   glColor4f(0.2,0.2,0.2,0.5);
00100   glBegin(GL_POLYGON);
00101   LookAndFeel->drawRect(x-5,y-2,textwidth+10,Font->getSize()+5);
00102   glEnd();
00103   glDisable(GL_BLEND);
00104   Font->drawAtPos(Text,x,y,-1);
00105 } // end of drawCoordInfos()
00106 
00107 //! draws close button
00108 void QWindow::drawCloseButton()
00109 {
00110 
00111   // need this to modulate the texture
00112   glColor4f(1,1,1,1);
00113 
00114   LookAndFeel->drawCloseButton(CloseButton->getState() == bsDown,
00115      CloseButton->getWidth(), CloseButton->getHeight());
00116 } // end of drawCloseButton()
00117 
00118 //! draws maximize button
00119 void QWindow::drawMaximizeButton()
00120 {
00121 
00122   // need this to modulate the texture
00123   glColor4f(1,1,1,1);
00124 
00125   LookAndFeel->drawMaximizeButton(MaximizeButton->getState() == bsDown,
00126     MaximizeButton->getWidth(),  MaximizeButton->getHeight());
00127 } // end of drawMaximizeButton()
00128 
00129 //! maximize / restore window. If window is maximized, restore its size/position, else maximize its size 
00130 void QWindow::maximize()
00131 {
00132   if (Maximized)
00133   {
00134      setLeft(OldLeft);
00135      setTop(OldTop);
00136      setWidth(OldWidth);
00137      setHeight(OldHeight);
00138      Maximized = false;
00139   }
00140   else
00141   {
00142     OldLeft = Left;
00143     OldTop = Top;
00144     OldWidth = Width;
00145     OldHeight = Height;
00146     setLeft(0);
00147     setTop(0);
00148     setWidth(Owner->getWidth() - Owner->getClientBorderLeft() - Owner->getClientBorderRight());
00149     setHeight(Owner->getHeight() - Owner->getClientBorderTop() - Owner->getClientBorderBottom());
00150     Maximized = true;
00151   }
00152 } // end of maximize()
00153 
00154 //! draws itself with OpenGL. Here is the OpenGL drawing code
00155 void QWindow::draw( QEvent*  e )
00156 {
00157    drawFrame();
00158 
00159 } // end of draw()
00160 
00161 //! layout the children widgets. This method is called every time the size is changed. Have to be overwritten for respond on size changes
00162 void QWindow::layout()
00163 {
00164   CloseButton->setLeft(Width - CloseButton->getWidth()-TitleBarBorder-3);
00165   MaximizeButton->setLeft(CloseButton->getLeft() - MaximizeButton->getWidth()-3);
00166 } // end of layout()
00167 
00168 //! have to return true if widget should be dragged with mouse. This method is overwritten in sub classes. If returns true, widget will be dragged
00169 bool QWindow::canDrag( QEvent*  e )
00170 {
00171 
00172  return   (e->getY() - Top) < TitleBarHeight; 
00173 } // end of canDrag()
00174 
00175 //! processing mouse/keyboard events which are in widgets region. Mouse coordinates are relative to Owner
00176 bool QWindow::processEvent( QEvent*  e )
00177 {
00178       
00179  if ( Resizable &&
00180      (e->getButton() == mbLeft) &&
00181      (e->getType() == etMouseDown) &&
00182      ((Width + Left - e->getX()) < 10) &&
00183      ((Height + Top - e->getY()) < 10)
00184    )
00185  {
00186    ResizeStartX = (Width - e->getX());
00187    ResizeStartY = (Height - e->getY());
00188    Resizing = true;
00189    return true;
00190  }
00191  return false;
00192 } // end of processEvent()
00193 
00194 //! processing mouse events which are in Owner widget region. Mouse coordinates are relative to Owner
00195 bool QWindow::processMouseOwner( QEvent*  e )
00196 {
00197 
00198  if (
00199       (e->getButton() == mbLeft) &&
00200       (e->getType() == etMouseMotion)
00201      )
00202  {
00203    if (Resizing)
00204    {
00205 
00206       int newWidth = ResizeStartX + e->getX();
00207       int newHeight = ResizeStartY + e->getY();
00208 
00209       if (newWidth < MinResizeWidth) newWidth = MinResizeWidth;
00210       if (newHeight < MinResizeHeight) newHeight = MinResizeHeight;
00211 
00212       if (Owner)
00213       {
00214          if (newWidth < Owner->getWidth() - Left)
00215            setWidth(newWidth);
00216          else
00217            setWidth( Owner->getWidth() - Left);
00218 
00219          if (newHeight < Owner->getHeight() - Top)
00220            setHeight(newHeight);
00221          else
00222            setHeight( Owner->getHeight() - Top);
00223       }
00224       else
00225       {
00226          setWidth(newWidth);
00227          setHeight(newHeight);
00228       }
00229 
00230    }
00231  }
00232  else
00233   Resizing = false;
00234 
00235  return false;
00236 } // end of processMouseOwner()
00237 
00238 //! called if a child is added/removed
00239 void QWindow::childrenChanged()
00240 {
00241 } // end of childrenChanged()
00242 
00243 //! defines whether control can have keyboard focus. Should return true if Widget wants to get keyboard focus
00244 bool QWindow::canFocus( QEvent*  e )
00245 {
00246  return true;
00247 } // end of canFocus()
00248 
00249 //! initialization code
00250 void QWindow::Init()
00251 {
00252   Caption = "Window";
00253 
00254   TitleBarColor->set(0.0, 0.0, 0.9, 1.0);
00255   TitleBarColorInactive->set(0.2,0.2,0.25,1.0);
00256 
00257   Font->getColor()->set(1,1,1,1);
00258   Font->setSize(16);
00259 
00260 
00261   CloseButton->onClick = CloseButtonHandler;
00262   CloseButton->onCustomDraw = drawCloseButtonHandler;
00263   CloseButton->setHeight(TitleBarHeight-4);
00264   CloseButton->setWidth (CloseButton->getHeight());
00265   CloseButton->setTop(TitleBarBorder+2);
00266 
00267   MaximizeButton->onClick = MaximizeButtonHandler;
00268   MaximizeButton->onCustomDraw = drawMaximizeButtonHandler;
00269   MaximizeButton->setHeight(CloseButton->getHeight());
00270   MaximizeButton->setWidth(CloseButton->getWidth());
00271   MaximizeButton->setTop(CloseButton->getTop());
00272 
00273   ClientBorderTop = TitleBarBorder+TitleBarHeight+2;
00274   ClientBorderLeft = TitleBarBorder+1;
00275   ClientBorderRight = TitleBarBorder+1;
00276   ClientBorderBottom = TitleBarBorder+1;
00277 
00278   MinWidth = MinResizeWidth;
00279   MinHeight = MinResizeHeight;
00280 
00281 } // end of Init()
00282 
00283 //! clean up code
00284 void QWindow::CleanUp()
00285 {
00286 
00287 } // end of CleanUp()
00288 
00289 //! getter method for TitleBarHeight
00290 int QWindow::getTitleBarHeight()
00291 {
00292 return TitleBarHeight;
00293 } // end of getTitleBarHeight()
00294 
00295 //! setter method for TitleBarHeight
00296 void QWindow::setTitleBarHeight( int  newValue )
00297 {
00298 TitleBarHeight = newValue;
00299 } // end of setTitleBarHeight()
00300 
00301 //! getter method for TitleBarBorder
00302 int QWindow::getTitleBarBorder()
00303 {
00304 return TitleBarBorder;
00305 } // end of getTitleBarBorder()
00306 
00307 //! setter method for TitleBarBorder
00308 void QWindow::setTitleBarBorder( int  newValue )
00309 {
00310 TitleBarBorder = newValue;
00311 } // end of setTitleBarBorder()
00312 
00313 //! getter method for Caption
00314 string QWindow::getCaption()
00315 {
00316 return Caption;
00317 } // end of getCaption()
00318 
00319 //! setter method for Caption
00320 void QWindow::setCaption( string  newValue )
00321 {
00322 Caption = newValue;
00323 } // end of setCaption()
00324 
00325 //! getter method for MinResizeWidth
00326 int QWindow::getMinResizeWidth()
00327 {
00328 return MinResizeWidth;
00329 } // end of getMinResizeWidth()
00330 
00331 //! setter method for MinResizeWidth
00332 void QWindow::setMinResizeWidth( int  newValue )
00333 {
00334 MinResizeWidth = newValue;
00335 } // end of setMinResizeWidth()
00336 
00337 //! getter method for MinResizeHeight
00338 int QWindow::getMinResizeHeight()
00339 {
00340 return MinResizeHeight;
00341 } // end of getMinResizeHeight()
00342 
00343 //! setter method for MinResizeHeight
00344 void QWindow::setMinResizeHeight( int  newValue )
00345 {
00346 MinResizeHeight = newValue;
00347 } // end of setMinResizeHeight()
00348 
00349 //! getter method for Maximized
00350 bool QWindow::getMaximized()
00351 {
00352 return Maximized;
00353 } // end of getMaximized()
00354 
00355 //! setter method for Maximized
00356 void QWindow::setMaximized( bool  newValue )
00357 {
00358 Maximized = newValue;
00359 } // end of setMaximized()
00360 
00361 //! getter method for Resizable
00362 bool QWindow::getResizable()
00363 {
00364 return Resizable;
00365 } // end of getResizable()
00366 
00367 //! setter method for Resizable
00368 void QWindow::setResizable( bool  newValue )
00369 {
00370 Resizable = newValue;
00371 } // end of setResizable()
00372 
00373 //! getter method for CloseButton
00374 QButton* QWindow::getCloseButton()
00375 {
00376 return CloseButton;
00377 } // end of getCloseButton()
00378 
00379 //! getter method for MaximizeButton
00380 QButton* QWindow::getMaximizeButton()
00381 {
00382 return MaximizeButton;
00383 } // end of getMaximizeButton()
00384 
00385 //! getter method for Font
00386 QFont* QWindow::getFont()
00387 {
00388 return Font;
00389 } // end of getFont()
00390 
00391 //! getter method for TitleBarColor
00392 QColor* QWindow::getTitleBarColor()
00393 {
00394 return TitleBarColor;
00395 } // end of getTitleBarColor()
00396 
00397 //! getter method for TitleBarColorInactive
00398 QColor* QWindow::getTitleBarColorInactive()
00399 {
00400 return TitleBarColorInactive;
00401 } // end of getTitleBarColorInactive()
00402 
00403 // WARNING : The implementation of this method will be automatically generated with code generator.
00404 // To prevent this add '//KEEP' at the first line of the implementation.(first line after '{')
00405 //! prints itself to the cout
00406 void QWindow::print()
00407 {
00408 cout << "Class : QWindow" << endl;
00409 cout << "TitleBarHeight = " << TitleBarHeight << endl;
00410 cout << "TitleBarBorder = " << TitleBarBorder << endl;
00411 cout << "Caption = " << Caption << endl;
00412 cout << "MinResizeWidth = " << MinResizeWidth << endl;
00413 cout << "MinResizeHeight = " << MinResizeHeight << endl;
00414 cout << "Maximized = " << Maximized << endl;
00415 cout << "Resizable = " << Resizable << endl;
00416 cout << "CloseButton = " << CloseButton << endl;
00417 cout << "MaximizeButton = " << MaximizeButton << endl;
00418 } // end of print()
00419 
00420 // WARNING : The implementation of this method will be automatically generated with code generator.
00421 // To prevent this add '//KEEP' at the first line of the implementation.(first line after '{')
00422 //! Constructor
00423  QWindow::QWindow( QWidget*  aOwner ):QWidget(aOwner)
00424 {
00425 Resizing = false;
00426 OldLeft = 0;
00427 OldTop = 0;
00428 OldWidth = 0;
00429 OldHeight = 0;
00430 ResizeStartX = 0;
00431 ResizeStartY = 0;
00432 TitleBarHeight = 23;
00433 TitleBarBorder = 2;
00434 MinResizeWidth = 60;
00435 MinResizeHeight = 40;
00436 Maximized = false;
00437 Resizable = true;
00438 CloseButton = new QButton(this);
00439 MaximizeButton = new QButton(this);
00440 Font = new QFont;
00441 TitleBarColor = new QColor;
00442 TitleBarColorInactive = new QColor;
00443 Init();
00444 layout();
00445 } // end of QWindow()
00446 
00447 // WARNING : The implementation of this method will be automatically generated with code generator.
00448 // To prevent this add '//KEEP' at the first line of the implementation.(first line after '{')
00449 //! Destructor
00450  QWindow::~QWindow()
00451 {
00452 delete TitleBarColorInactive;
00453 delete TitleBarColor;
00454 delete Font;
00455 CleanUp();
00456 } // end of ~QWindow()
00457 
00458 // end of implementation of QWindow
00459 
00460 

Generated on Thu Mar 18 18:33:48 2004 for miniQT by doxygen1.2.18