00001
00002
00003
00004
00005
00006
00007 #include "QTextEdit.h"
00008
00009
00010 #include <iostream>
00011 using namespace std;
00012
00013
00014
00015
00016
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
00047
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 }
00060
00061
00062 void QTextEdit::layout()
00063 {
00064 }
00065
00066
00067 bool QTextEdit::canDrag( QEvent* e )
00068 {
00069 return false;
00070 }
00071
00072
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 }
00094
00095
00096 bool QTextEdit::processMouseOwner( QEvent* e )
00097 {
00098 return false;
00099 }
00100
00101
00102 void QTextEdit::childrenChanged()
00103 {
00104 }
00105
00106
00107 bool QTextEdit::canFocus( QEvent* e )
00108 {
00109 return true;
00110 }
00111
00112
00113 void QTextEdit::Init()
00114 {
00115 Font->copyFrom(LookAndFeel->getFont());
00116 Width = 100;
00117 Height = 20;
00118 }
00119
00120
00121 void QTextEdit::CleanUp()
00122 {
00123 }
00124
00125
00126 int QTextEdit::getCursorPos()
00127 {
00128 return CursorPos;
00129 }
00130
00131
00132 void QTextEdit::setCursorPos( int newValue )
00133 {
00134 CursorPos = newValue;
00135 }
00136
00137
00138 string QTextEdit::getText()
00139 {
00140 return Text;
00141 }
00142
00143
00144 void QTextEdit::setText( string newValue )
00145 {
00146 if (Font->getTextWidth(newValue.c_str())+6 < Width)
00147 {
00148 Text = newValue;
00149 }
00150 }
00151
00152
00153 QFont* QTextEdit::getFont()
00154 {
00155 return Font;
00156 }
00157
00158
00159
00160
00161 void QTextEdit::print()
00162 {
00163 cout << "Class : QTextEdit" << endl;
00164 cout << "CursorPos = " << CursorPos << endl;
00165 cout << "Text = " << Text << endl;
00166 }
00167
00168
00169
00170
00171 QTextEdit::QTextEdit( QWidget* aOwner ):QWidget(aOwner)
00172 {
00173 CursorPos = 0;
00174 Font = new QFont;
00175 Init();
00176 layout();
00177 }
00178
00179
00180
00181
00182 QTextEdit::~QTextEdit()
00183 {
00184 delete Font;
00185 CleanUp();
00186 }
00187
00188
00189
00190