Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGQMatrixFieldValueLabel.inl

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  *                                                                           *
00016  * This library is free software; you can redistribute it and/or modify it   *
00017  * under the terms of the GNU Library General Public License as published    *
00018  * by the Free Software Foundation, version 2.                               *
00019  *                                                                           *
00020  * This library is distributed in the hope that it will be useful, but       *
00021  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00022  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00023  * Library General Public License for more details.                          *
00024  *                                                                           *
00025  * You should have received a copy of the GNU Library General Public         *
00026  * License along with this library; if not, write to the Free Software       *
00027  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00028  *                                                                           *
00029  *                                                                           *
00030 \*---------------------------------------------------------------------------*/
00031 /*---------------------------------------------------------------------------*\
00032  *                                Changes                                    *
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 

Generated on Thu Aug 25 04:08:59 2005 for OpenSG by  doxygen 1.4.3