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

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

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