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