00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include <OSGQFieldView_qt.h>
00042
00043 #include <OSGField.h>
00044 #include <OSGSField.h>
00045 #include <OSGMField.h>
00046 #include <OSGBaseTypes.h>
00047 #include <OSGBaseFunctions.h>
00048 #include <OSGMathFieldDataType.h>
00049
00050 #include <qpainter.h>
00051 #include <qrect.h>
00052 #include <qpalette.h>
00053
00054 OSG_BEGIN_NAMESPACE
00055
00056 template <class MatrixTypeT>
00057 QMatrixFieldValueLabel<MatrixTypeT>::QMatrixFieldValueLabel(
00058 QFieldViewBase *pView, UInt32 uiIndex)
00059 : Inherited (pView, uiIndex),
00060 _cachedSize ( ),
00061 _bCacheValid(false )
00062 {
00063 }
00064
00065 template <class MatrixTypeT>
00066 QMatrixFieldValueLabel<MatrixTypeT>::~QMatrixFieldValueLabel(void)
00067 {
00068 }
00069
00070 template <class MatrixTypeT>
00071 QFieldValueLabelBase *
00072 QMatrixFieldValueLabel<MatrixTypeT>::create(QFieldViewBase *pView,
00073 UInt32 uiIndex)
00074 {
00075 return (new QMatrixFieldValueLabel<MatrixType>(pView, uiIndex));
00076 }
00077
00078 template <class MatrixTypeT>
00079 void
00080 QMatrixFieldValueLabel<MatrixTypeT>::paint(
00081 QPainter *pPainter, const QColorGroup &colGrp, const QRect &rect)
00082 {
00083 QRect drawRect(0, 0, rect.width()/4, rect.height()/4);
00084
00085 pPainter->save();
00086
00087 pPainter->setBrush(colGrp.base());
00088
00089 pPainter->translate(rect.x(), rect.y());
00090
00091 for(UInt32 row = 0; row < 4; ++row)
00092 {
00093 pPainter->save();
00094
00095 for(UInt32 col = 0; col < 4; ++col)
00096 {
00097 pPainter->setPen (colGrp.background());
00098 pPainter->drawRect(drawRect );
00099 pPainter->setPen (colGrp.text() );
00100
00101 pPainter->drawText (drawRect, AlignVCenter,
00102 getCachedValue(row, col));
00103 pPainter->translate(rect.width()/4, 0 );
00104 }
00105
00106 pPainter->restore ( );
00107 pPainter->translate(0, rect.height() / 4);
00108 }
00109
00110 pPainter->restore();
00111 }
00112
00113 template <class MatrixTypeT>
00114 QSize
00115 QMatrixFieldValueLabel<MatrixTypeT>::sizeHint(void)
00116 {
00117 return QSize(getCachedSize().width() + 8,
00118 getCachedSize().height() + 8 );
00119 }
00120
00121 template <class MatrixTypeT>
00122 QSize
00123 QMatrixFieldValueLabel<MatrixTypeT>::minimumSizeHint(void)
00124 {
00125 return getCachedSize();
00126 }
00127
00128 template <class MatrixTypeT>
00129 void
00130 QMatrixFieldValueLabel<MatrixTypeT>::valueChanged(void)
00131 {
00132 _bCacheValid = false;
00133 }
00134
00135 template <class MatrixTypeT>
00136 const QString &
00137 QMatrixFieldValueLabel<MatrixTypeT>::getCachedValue(UInt32 uiRow, UInt32 uiCol)
00138 {
00139 updateCache();
00140
00141 return _strCachedValues[4 * uiRow + uiCol];
00142 }
00143
00144 template <class MatrixTypeT>
00145 const QSize &
00146 QMatrixFieldValueLabel<MatrixTypeT>::getCachedSize(void)
00147 {
00148 updateCache();
00149
00150 return _cachedSize;
00151 }
00152
00153 template <class MatrixTypeT>
00154 void
00155 QMatrixFieldValueLabel<MatrixTypeT>::updateCache(void)
00156 {
00157 typedef TypeTraits<ValueType> TTraits;
00158
00159 if(_bCacheValid)
00160 return;
00161
00162 if(getIndex() >= getFieldPtr()->getSize())
00163 {
00164 SWARNING << "QMatrixFieldValueLabel<>::updateCache(): "
00165 << "getIndex >= getFieldPtr()->getSize()" << endLog;
00166
00167 for(UInt32 i = 0; i < 16; ++i)
00168 {
00169 _strCachedValues[i] = "";
00170 }
00171
00172 _cachedSize.setWidth (4 * 10 );
00173 _cachedSize.setHeight(getFieldView()->fontMetrics().height());
00174
00175 _bCacheValid = true;
00176
00177 return;
00178 }
00179
00180 Int32 widthOfCol [4] = { 0, 0, 0, 0 };
00181
00182 if(getFieldPtr()->getCardinality() == FieldType::SINGLE_FIELD)
00183 {
00184 SField<MatrixType> *pSF =
00185 dynamic_cast<SField<MatrixType> *>(getFieldPtr());
00186
00187 for(UInt32 row = 0; row < 4; ++row)
00188 {
00189 for(UInt32 col = 0; col < 4; ++col)
00190 {
00191 _strCachedValues[4 * row + col] =
00192 TTraits::putToString(
00193 pSF->getValue().getValues()[4 * col + row]
00194 ).c_str();
00195
00196 widthOfCol[col] = osgMax(widthOfCol[col],
00197 getFieldView()->fontMetrics().width(
00198 _strCachedValues[4 * row + col]));
00199 }
00200 }
00201 }
00202 else
00203 {
00204 MField<MatrixType> *pMF =
00205 dynamic_cast<MField<MatrixType> *>(getFieldPtr());
00206
00207 for(UInt32 row = 0; row < 4; ++row)
00208 {
00209 for(UInt32 col = 0; col < 4; ++col)
00210 {
00211 _strCachedValues[4 * row + col] =
00212 TTraits::putToString(
00213 (*pMF)[getIndex()].getValues()[4 * col + row]
00214 ).c_str();
00215
00216 widthOfCol[col] = osgMax(widthOfCol[col],
00217 getFieldView()->fontMetrics().width(
00218 _strCachedValues[4 * row + col]));
00219 }
00220 }
00221 }
00222
00223 _cachedSize.setWidth ( widthOfCol[0] + widthOfCol[1] +
00224 widthOfCol[2] + widthOfCol[3] );
00225 _cachedSize.setHeight(4 * getFieldView()->fontMetrics().height());
00226
00227 _bCacheValid = true;
00228 }
00229
00230 OSG_END_NAMESPACE
00231
00232 #define OSGQMATRIXFIELDVALUELABEL_INLINE_CVSID "@(#)$Id: OSGQMatrixFieldValueLabel.inl,v 1.2 2003/05/10 04:21:11 vossg Exp $"
00233