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

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

Go to the documentation of this file.
00001 // Class QTextEdit 
00002 // Text edit widget
00003 // Filename QTextEdit.cpp
00004 // FaPra 2003-2004, A5,  Alexander Kramer
00005 
00006 
00007 #include "QTextEdit.h"
00008 #include <iostream>
00009 using namespace std;
00010 
00011 // ----------------------------------------------------------
00012 
00013 //! draws itself with OpenGL. Here is the OpenGL drawing code
00014 void QTextEdit::draw( QEvent*  e )
00015 {
00016   if (Enabled)
00017   {
00018     if (Owner->getFocusPath() == this)
00019     {
00020       LookAndFeel->getHighlightColor()->setAsCurrent();
00021     }
00022     else
00023     {
00024       LookAndFeel->getBackGroundColor()->setAsCurrent();
00025     }
00026     glBegin(GL_POLYGON);
00027     LookAndFeel->drawRect(0,0,Width,Height);
00028     glEnd();
00029     LookAndFeel->drawBevel(0,0,Width,Height,bsDown);
00030   }
00031   else
00032   {
00033     LookAndFeel->getBackGroundColor()->setAsCurrent();
00034     glBegin(GL_POLYGON);
00035     LookAndFeel->drawRect(0,0,Width,Height);
00036     glEnd();
00037     LookAndFeel->drawBevel(0,0,Width,Height,bsDisabled);
00038   }
00039 
00040   glTranslatef(1,1,0);
00041   Font->drawInternal(Text.c_str(),-1);
00042 
00043   // draw cursor, the current position is almost right,
00044   // because the drawInternal has adjusted MV matrix
00045 
00046   if (getFocused())
00047   {
00048      glColor3f(0.0,0.0,0.0);
00049      glLineWidth(2);
00050      glBegin(GL_LINES);
00051      glVertex2i(2,1);
00052      glVertex2i(2,Height-2);
00053      glEnd();
00054      glLineWidth(1);
00055   }
00056 } // end of draw()
00057 
00058 //! layout the children widgets. This method is called every time the size is changed. Have to be overwritten for respond on size changes
00059 void QTextEdit::layout()
00060 {
00061 } // end of layout()
00062 
00063 //! 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
00064 bool QTextEdit::canDrag( QEvent*  e )
00065 {
00066  return false;
00067 } // end of canDrag()
00068 
00069 //! processing mouse/keyboard events which are in widgets region. Mouse coordinates are relative to Owner
00070 bool QTextEdit::processEvent( QEvent*  e )
00071 {
00072 
00073   if ((e->getType() == etKeyboard))
00074   {
00075      e->print();
00076      char key = (char)e->getKey();
00077 
00078      if ((key == 8) && (Text.length()>0))
00079      {
00080        Text = Text.substr(0,Text.length()-1);
00081      }
00082      else if (key >= 32)
00083      {
00084       string newText = Text + key;
00085       setText(newText);
00086      }
00087   }
00088 
00089  return false;
00090 } // end of processEvent()
00091 
00092 //! processing mouse events which are in Owner widget region. Mouse coordinates are relative to Owner
00093 bool QTextEdit::processMouseOwner( QEvent*  e )
00094 {
00095  return false;
00096 } // end of processMouseOwner()
00097 
00098 //! called if a child is added/removed
00099 void QTextEdit::childrenChanged()
00100 {
00101 } // end of childrenChanged()
00102 
00103 //! defines whether control can have keyboard focus. Should return true if Widget wants to get keyboard focus
00104 bool QTextEdit::canFocus( QEvent*  e )
00105 {
00106  return true;
00107 } // end of canFocus()
00108 
00109 //! initialization code
00110 void QTextEdit::Init()
00111 {
00112   Font->copyFrom(LookAndFeel->getFont());
00113   Width = 100;
00114   Height = 20;
00115 } // end of Init()
00116 
00117 //! clean up code
00118 void QTextEdit::CleanUp()
00119 {
00120 } // end of CleanUp()
00121 
00122 //! getter method for CursorPos
00123 int QTextEdit::getCursorPos()
00124 {
00125 return CursorPos;
00126 } // end of getCursorPos()
00127 
00128 //! setter method for CursorPos
00129 void QTextEdit::setCursorPos( int  newValue )
00130 {
00131 CursorPos = newValue;
00132 } // end of setCursorPos()
00133 
00134 //! getter method for Text
00135 string QTextEdit::getText()
00136 {
00137 return Text;
00138 } // end of getText()
00139 
00140 //! setter method for Text
00141 void QTextEdit::setText( string  newValue )
00142 {
00143   if (Font->getTextWidth(newValue.c_str())+6 < Width)
00144   {
00145      Text = newValue;
00146   }
00147 } // end of setText()
00148 
00149 //! getter method for Font
00150 QFont* QTextEdit::getFont()
00151 {
00152 return Font;
00153 } // end of getFont()
00154 
00155 // WARNING : The implementation of this method will be automatically generated with code generator.
00156 // To prevent this add '//KEEP' at the first line of the implementation.(first line after '{')
00157 //! prints itself to the cout
00158 void QTextEdit::print()
00159 {
00160 cout << "Class : QTextEdit" << endl;
00161 cout << "CursorPos = " << CursorPos << endl;
00162 cout << "Text = " << Text << endl;
00163 } // end of print()
00164 
00165 // WARNING : The implementation of this method will be automatically generated with code generator.
00166 // To prevent this add '//KEEP' at the first line of the implementation.(first line after '{')
00167 //! Constructor
00168  QTextEdit::QTextEdit( QWidget*  aOwner ):QWidget(aOwner)
00169 {
00170 CursorPos = 0;
00171 Font = new QFont;
00172 Init();
00173 layout();
00174 } // end of QTextEdit()
00175 
00176 // WARNING : The implementation of this method will be automatically generated with code generator.
00177 // To prevent this add '//KEEP' at the first line of the implementation.(first line after '{')
00178 //! Destructor
00179  QTextEdit::~QTextEdit()
00180 {
00181 delete Font;
00182 CleanUp();
00183 } // end of ~QTextEdit()
00184 
00185 // end of implementation of QTextEdit
00186 
00187 

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