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

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

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