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

OSGQPointFieldValueLabel.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 
00048 #include <qpainter.h>
00049 #include <qrect.h>
00050 #include <qpalette.h>
00051 
00052 OSG_BEGIN_NAMESPACE
00053 
00054 template <class PointTypeT>
00055 QPointFieldValueLabel<PointTypeT>::QPointFieldValueLabel(
00056     QFieldViewBase *pView, UInt32 uiIndex)
00057     : Inherited   (pView, uiIndex),
00058       _cachedSize (              ),
00059       _bCacheValid(false         )
00060 {
00061 }
00062 
00063 template <class PointTypeT>
00064 QPointFieldValueLabel<PointTypeT>::~QPointFieldValueLabel(void)
00065 {
00066 }
00067 
00068 template <class PointTypeT>
00069 QFieldValueLabelBase *
00070 QPointFieldValueLabel<PointTypeT>::create(QFieldViewBase *pView, 
00071                                           UInt32          uiIndex)
00072 {
00073     return new QPointFieldValueLabel<PointTypeT>(pView, uiIndex);
00074 }
00075 
00076 template <class PointTypeT>
00077 void
00078 QPointFieldValueLabel<PointTypeT>::paint(
00079     QPainter *pPainter, const QColorGroup &colGrp, const QRect &rect)
00080 {
00081     QRect drawRect(0, 0, rect.width()/PointType::_iSize, rect.height());
00082 
00083     pPainter->save();
00084 
00085     pPainter->setBrush(colGrp.base());
00086 
00087     pPainter->translate(rect.x(), rect.y());
00088 
00089     for(UInt32 i=0; i < PointType::_iSize; ++i)
00090     {
00091         pPainter->setPen  (colGrp.background());
00092         pPainter->drawRect(drawRect           );
00093         pPainter->setPen  (colGrp.text()      );  
00094 
00095         pPainter->drawText(drawRect, AlignVCenter, getCachedValue(i));
00096 
00097         pPainter->translate(rect.width()/PointType::_iSize, 0);
00098     }
00099 
00100     pPainter->restore();
00101 }
00102 
00103 template <class PointTypeT>
00104 QSize
00105 QPointFieldValueLabel<PointTypeT>::sizeHint(void)
00106 {
00107     return QSize(getCachedSize().width()  + 8,
00108                  getCachedSize().height() + 8 );
00109 }
00110 
00111 template <class PointTypeT>
00112 QSize
00113 QPointFieldValueLabel<PointTypeT>::minimumSizeHint(void)
00114 {
00115     return getCachedSize();
00116 }
00117 
00118 template <class PointTypeT>
00119 void
00120 QPointFieldValueLabel<PointTypeT>::valueChanged(void)
00121 {
00122     _bCacheValid = false;
00123 }
00124 
00125 template <class PointTypeT>
00126 const QString &
00127 QPointFieldValueLabel<PointTypeT>::getCachedValue(UInt32 uiCoordinate)
00128 {
00129     updateCache();
00130 
00131     return _strCachedValues[uiCoordinate];
00132 }
00133 
00134 template <class PointTypeT>
00135 const QSize &
00136 QPointFieldValueLabel<PointTypeT>::getCachedSize(void)
00137 {
00138     updateCache();
00139 
00140     return _cachedSize;
00141 }
00142 
00143 template <class PointTypeT>
00144 void
00145 QPointFieldValueLabel<PointTypeT>::updateCache(void)
00146 {
00147     typedef TypeTraits<ValueType> TTraits;
00148 
00149     if(_bCacheValid)
00150         return;
00151 
00152     _cachedSize.setWidth (0                                     );
00153     _cachedSize.setHeight(getFieldView()->fontMetrics().height());
00154 
00155     if(getIndex() >= getFieldPtr()->getSize())
00156     {
00157         SWARNING << "QPointFieldValueLabel<>::updateCache(): "
00158                  << "getIndex >= getFieldPtr()->getSize()" << endLog;
00159 
00160         for(UInt32 i = 0; i < PointType::_iSize; ++i)
00161         {
00162             _strCachedValues[i] = "";
00163             _cachedSize.setWidth(_cachedSize.width() + 10);
00164         }
00165         
00166         _bCacheValid = true;
00167 
00168         return;
00169     }    
00170 
00171     if(getFieldPtr()->getCardinality() == FieldType::SINGLE_FIELD)
00172     {
00173         SField<PointType> *pSF =
00174             dynamic_cast<SField<PointType> *>(getFieldPtr());
00175 
00176         for(UInt32 i=0; i < PointType::_iSize; ++i)
00177         {
00178             _strCachedValues[i] = 
00179                 TTraits::putToString(
00180                     pSF->getValue().getValues()[i]).c_str();
00181 
00182             _cachedSize.setWidth(_cachedSize.width() + 
00183                                  getFieldView()->fontMetrics().width(
00184                                      _strCachedValues[i]));
00185         }
00186     }
00187     else
00188     {
00189         MField<PointType> *pMF =
00190             dynamic_cast<MField<PointType> *>(getFieldPtr());
00191 
00192         for(UInt32 i=0; i < PointType::_iSize; ++i)
00193         {
00194             _strCachedValues[i] =
00195                 TTraits::putToString(
00196                     (*pMF)[getIndex()].getValues()[i]).c_str();
00197 
00198             _cachedSize.setWidth(_cachedSize.width() + 
00199                                  getFieldView()->fontMetrics().width(
00200                                      _strCachedValues[i]));
00201         }
00202     }
00203 
00204     _bCacheValid = true;
00205 }
00206 
00207 OSG_END_NAMESPACE
00208 
00209 #define OSGQPOINTFIELDVALUELABEL_INLINE_CVSID "@(#)$Id: OSGQPointFieldValueLabel.inl,v 1.2 2003/05/10 05:28:28 vossg Exp $"

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