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