superkaramba
textfield.cpp
Go to the documentation of this file.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 00013 #include <QFontMetrics> 00014 00015 TextField::TextField() 00016 { 00017 setFontSize(12); 00018 setColor(QColor(192, 192, 192)); 00019 setBGColor(QColor(0, 0, 0)); 00020 setFont("Helvetica"); 00021 setAlignment(Qt::AlignLeft); 00022 setFixedPitch(false); 00023 setShadow(0); 00024 } 00025 00026 TextField::~TextField() 00027 {} 00028 00029 TextField::TextField(const TextField& def) 00030 { 00031 setFontSize(def.getFontSize()); 00032 00033 setColor(def.getColor()); 00034 setBGColor(def.getBGColor()); 00035 00036 setFont(def.getFont()); 00037 setAlignment(def.getAlignment()); 00038 setFixedPitch(def.getFixedPitch()); 00039 setShadow(def.getShadow()); 00040 } 00041 00042 TextField& TextField::operator=(const TextField& rhs) 00043 { 00044 if (this == &rhs) 00045 return *this; 00046 00047 setFontSize(rhs.getFontSize()); 00048 00049 setColor(rhs.getColor()); 00050 setBGColor(rhs.getBGColor()); 00051 00052 setFont(rhs.getFont()); 00053 setAlignment(rhs.getAlignment()); 00054 setFixedPitch(rhs.getFixedPitch()); 00055 setShadow(rhs.getShadow()); 00056 00057 return *this; 00058 } 00059 00060 void TextField::setColor(QColor clr) 00061 { 00062 color = clr; 00063 } 00064 00065 QColor TextField::getColor() const 00066 { 00067 return color; 00068 } 00069 00070 void TextField::setBGColor(QColor clr) 00071 { 00072 bgColor = clr; 00073 } 00074 00075 QColor TextField::getBGColor() const 00076 { 00077 return bgColor; 00078 } 00079 00080 00081 void TextField::setFont(const QString &f) 00082 { 00083 font.setFamily(f); 00084 lineHeight = QFontMetrics(font).height(); 00085 } 00086 00087 00088 QString TextField::getFont() const 00089 { 00090 return font.family(); 00091 } 00092 00093 void TextField::setFontSize(int size) 00094 { 00095 font.setPointSize(size); 00096 lineHeight = QFontMetrics(font).height(); 00097 } 00098 00099 int TextField::getFontSize() const 00100 { 00101 return font.pointSize(); 00102 } 00103 00104 void TextField::setAlignment(const QString &align) 00105 { 00106 QString a = align.toUpper(); 00107 if (a == "LEFT" || a.isEmpty()) 00108 alignment = Qt::AlignLeft; 00109 if (a == "RIGHT") 00110 alignment = Qt::AlignRight; 00111 if (a == "CENTER") 00112 alignment = Qt::AlignHCenter; 00113 } 00114 00115 void TextField::setAlignment(int af) 00116 { 00117 alignment = af; 00118 } 00119 00120 int TextField::getAlignment() const 00121 { 00122 return alignment; 00123 } 00124 00125 QString TextField::getAlignmentAsString() const 00126 { 00127 if (alignment == Qt::AlignHCenter) 00128 return "CENTER"; 00129 else if (alignment == Qt::AlignRight) 00130 return "RIGHT"; 00131 else 00132 return "LEFT"; 00133 } 00134 00135 void TextField::setFixedPitch(bool fp) 00136 { 00137 font.setFixedPitch(fp); 00138 } 00139 00140 bool TextField::getFixedPitch() const 00141 { 00142 return font.fixedPitch(); 00143 } 00144 00145 void TextField::setShadow(int s) 00146 { 00147 shadow = s; 00148 } 00149 00150 int TextField::getShadow() const 00151 { 00152 return shadow; 00153 } 00154 00155 int TextField::getLineHeight() const 00156 { 00157 return lineHeight; 00158 }
KDE 4.0 API Reference