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

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

Go to the documentation of this file.
00001 // Class QCaptionButton 
00002 // Button with Caption
00003 // Filename QCaptionButton.cpp
00004 // FaPra 2003-2004, A5,  Alexander Kramer
00005 
00006 
00007 #include "QCaptionButton.h"
00008 #include <iostream>
00009 using namespace std;
00010 
00011 // ----------------------------------------------------------
00012 
00013 //! overwrite this to recalculate caption position
00014 void QCaptionButton::updateCaptionPosition()
00015 {
00016  int TextWidth = (int)(Font->getTextWidth(Caption.c_str()));
00017   if (Width < (TextWidth+10))
00018    Width = TextWidth+10;
00019  CaptionPositionX = (Width-TextWidth)/2;
00020 } // end of updateCaptionPosition()
00021 
00022 //! draws itself with OpenGL. Here is the OpenGL drawing code
00023 void QCaptionButton::draw( QEvent*  e )
00024 {
00025 
00026   LookAndFeel->getBackGroundColor()->setAsCurrent();
00027   glBegin(GL_POLYGON);
00028   LookAndFeel->drawRect(0,0,Width,Height);
00029   glEnd();
00030 
00031   LookAndFeel->drawBevel(0,0,Width,Height,State);
00032 
00033   if (getFocused())
00034   {
00035     LookAndFeel->getHighlightColor()->setAsCurrent();
00036     glBegin(GL_LINE_LOOP);
00037     LookAndFeel->drawRect(1,1,Width-2,Height-2);
00038     glEnd();
00039   }
00040 
00041   // drawing all other stuff translated
00042   if (State == bsDown)
00043    glTranslatef(1,1,0);
00044 
00045 
00046   Font->drawAtPos(Caption.c_str(),CaptionPositionX,1,Font->getLengthForWidth(Caption.c_str(),Width));
00047 } // end of draw()
00048 
00049 //! layout the children widgets. This method is called every time the size is changed. Have to be overwritten for respond on size changes
00050 void QCaptionButton::layout()
00051 {
00052  QButton::layout();
00053  updateCaptionPosition();
00054 } // end of layout()
00055 
00056 //! 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
00057 bool QCaptionButton::canDrag( QEvent*  e )
00058 {
00059  return false;
00060 } // end of canDrag()
00061 
00062 //! processing mouse/keyboard events which are in widgets region. Mouse coordinates are relative to Owner
00063 bool QCaptionButton::processEvent( QEvent*  e )
00064 {
00065  return QButton::processEvent(e);
00066 } // end of processEvent()
00067 
00068 //! processing mouse events which are in Owner widget region. Mouse coordinates are relative to Owner
00069 bool QCaptionButton::processMouseOwner( QEvent*  e )
00070 {
00071  return QButton::processMouseOwner(e);
00072 } // end of processMouseOwner()
00073 
00074 //! called if a child is added/removed
00075 void QCaptionButton::childrenChanged()
00076 {
00077 } // end of childrenChanged()
00078 
00079 //! defines whether control can have keyboard focus. Should return true if Widget wants to get keyboard focus
00080 bool QCaptionButton::canFocus( QEvent*  e )
00081 {
00082  return true;
00083 } // end of canFocus()
00084 
00085 //! initialization code
00086 void QCaptionButton::Init()
00087 {
00088   QButton::Init();
00089   Font->copyFrom(LookAndFeel->getFont());
00090   Height = 20;
00091   setCaption("Button");
00092 } // end of Init()
00093 
00094 //! clean up code
00095 void QCaptionButton::CleanUp()
00096 {
00097   QButton::CleanUp();
00098 } // end of CleanUp()
00099 
00100 //! getter method for Caption
00101 string QCaptionButton::getCaption()
00102 {
00103 return Caption;
00104 } // end of getCaption()
00105 
00106 //! setter method for Caption
00107 void QCaptionButton::setCaption( string  newValue )
00108 {
00109  Caption = newValue;
00110  updateCaptionPosition();
00111 } // end of setCaption()
00112 
00113 //! getter method for Font
00114 QFont* QCaptionButton::getFont()
00115 {
00116 return Font;
00117 } // end of getFont()
00118 
00119 // WARNING : The implementation of this method will be automatically generated with code generator.
00120 // To prevent this add '//KEEP' at the first line of the implementation.(first line after '{')
00121 //! prints itself to the cout
00122 void QCaptionButton::print()
00123 {
00124 cout << "Class : QCaptionButton" << endl;
00125 cout << "Caption = " << Caption << endl;
00126 } // end of print()
00127 
00128 // WARNING : The implementation of this method will be automatically generated with code generator.
00129 // To prevent this add '//KEEP' at the first line of the implementation.(first line after '{')
00130 //! Constructor
00131  QCaptionButton::QCaptionButton( QWidget*  aOwner ):QButton(aOwner)
00132 {
00133 Font = new QFont;
00134 Init();
00135 layout();
00136 } // end of QCaptionButton()
00137 
00138 // WARNING : The implementation of this method will be automatically generated with code generator.
00139 // To prevent this add '//KEEP' at the first line of the implementation.(first line after '{')
00140 //! Destructor
00141  QCaptionButton::~QCaptionButton()
00142 {
00143 delete Font;
00144 CleanUp();
00145 } // end of ~QCaptionButton()
00146 
00147 // end of implementation of QCaptionButton
00148 
00149 

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