textfield.cpp
00001 /*************************************************************************** 00002 * Copyright (C) 2003 by Ralph M. Churchill * 00003 * mrchucho@yahoo.com * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 ***************************************************************************/ 00010 00011 #include "textfield.h" 00012 #include <tqfontmetrics.h> 00013 #include <kdebug.h> 00014 00015 TextField::TextField( ) 00016 { 00017 setFontSize(12); 00018 setColor(TQColor(192, 192, 192)); 00019 setBGColor(TQColor(0, 0, 0)); 00020 setFont("Helvetica"); 00021 setAlignment(TQt::AlignLeft); 00022 setFixedPitch(false); 00023 setShadow(0); 00024 } 00025 00026 TextField::~TextField() 00027 { 00028 } 00029 00030 TextField::TextField( const TextField& def ) 00031 { 00032 setFontSize( def.getFontSize() ); 00033 00034 setColor(def.getColor()); 00035 setBGColor(def.getBGColor()); 00036 00037 setFont( def.getFont() ); 00038 setAlignment( def.getAlignment() ); 00039 setFixedPitch( def.getFixedPitch() ); 00040 setShadow( def.getShadow() ); 00041 } 00042 00043 TextField& TextField::operator=(const TextField& rhs) 00044 { 00045 if( this == &rhs) 00046 return *this; 00047 00048 setFontSize( rhs.getFontSize() ); 00049 00050 setColor(rhs.getColor()); 00051 setBGColor(rhs.getBGColor()); 00052 00053 setFont( rhs.getFont() ); 00054 setAlignment( rhs.getAlignment() ); 00055 setFixedPitch( rhs.getFixedPitch() ); 00056 setShadow( rhs.getShadow() ); 00057 00058 return *this; 00059 } 00060 00061 void TextField::setColor(TQColor clr) 00062 { 00063 color = clr; 00064 } 00065 00066 TQColor TextField::getColor() const 00067 { 00068 return color; 00069 } 00070 00071 void TextField::setBGColor(TQColor clr) 00072 { 00073 bgColor = clr; 00074 } 00075 00076 TQColor TextField::getBGColor() const 00077 { 00078 return bgColor; 00079 } 00080 00081 00082 void TextField::setFont(const TQString &f) 00083 { 00084 font.setFamily(f); 00085 lineHeight = TQFontMetrics(font).height(); 00086 } 00087 00088 00089 TQString TextField::getFont() const 00090 { 00091 return font.family(); 00092 } 00093 00094 void TextField::setFontSize(int size) 00095 { 00096 font.setPointSize(size); 00097 lineHeight = TQFontMetrics(font).height(); 00098 } 00099 00100 int TextField::getFontSize() const 00101 { 00102 return font.pointSize(); 00103 } 00104 00105 void TextField::setAlignment( const TQString &align ) 00106 { 00107 TQString a = align.upper(); 00108 if( a == "LEFT" || a.isEmpty() ) 00109 alignment = TQt::AlignLeft; 00110 if( a == "RIGHT" ) 00111 alignment = TQt::AlignRight; 00112 if( a == "CENTER" ) 00113 alignment = TQt::AlignHCenter; 00114 } 00115 00116 void TextField::setAlignment( int af ) 00117 { 00118 alignment = af; 00119 } 00120 00121 int TextField::getAlignment() const 00122 { 00123 return alignment; 00124 } 00125 00126 TQString TextField::getAlignmentAsString() const 00127 { 00128 if( alignment == TQt::AlignHCenter ) 00129 return "CENTER"; 00130 else if( alignment == TQt::AlignRight ) 00131 return "RIGHT"; 00132 else 00133 return "LEFT"; 00134 } 00135 00136 void TextField::setFixedPitch( bool fp) 00137 { 00138 font.setFixedPitch( fp ); 00139 } 00140 00141 bool TextField::getFixedPitch() const 00142 { 00143 return font.fixedPitch(); 00144 } 00145 00146 void TextField::setShadow ( int s ) 00147 { 00148 shadow = s; 00149 } 00150 00151 int TextField::getShadow() const 00152 { 00153 return shadow; 00154 } 00155 00156 int TextField::getLineHeight() const 00157 { 00158 return lineHeight; 00159 }