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

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

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