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

OSGQFieldValueLabel.cpp

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  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 #include "OSGQFieldValueLabel.h"
00040 #include "OSGQFieldView_qt.h"
00041 
00042 #include <qpainter.h>
00043 #include <qpalette.h>
00044 #include <qrect.h>
00045 
00046 OSG_USING_NAMESPACE
00047 
00048 #ifdef __sgi
00049 #pragma set woff 1174
00050 #endif
00051 
00052 namespace
00053 {
00054     static Char8 cvsid_cpp[] = "@(#)$Id: OSGQFieldValueLabel.cpp,v 1.1 2003/05/07 14:03:40 neumannc Exp $";
00055     static Char8 cvsid_hpp[] = OSGQFIELDVALUELABEL_HEADER_CVSID;
00056     static Char8 cvsid_inl[] = OSGQFIELDVALUELABEL_INLINE_CVSID;
00057 }
00058 
00059 #ifdef __sgi
00060 #pragma reset woff 1174
00061 #endif
00062 
00066 QFieldValueLabelBase::QFieldValueLabelBase(QFieldViewBase *pView, 
00067                                            UInt32          uiIndex)
00068     : _pView  (pView),
00069       _uiIndex(uiIndex)
00070 {
00071 }
00072 
00076 QFieldValueLabelBase::~QFieldValueLabelBase(void)
00077 {
00078 }
00079 
00080 void
00081 QFieldValueLabelBase::setIndex(UInt32 uiIndex)
00082 {
00083     _uiIndex = uiIndex;
00084 
00085     valueChanged();
00086 }
00087 
00088 //***************************************************************************
00089 // QGenericFieldValueLabel
00090 //***************************************************************************
00091 
00095 QGenericFieldValueLabel::QGenericFieldValueLabel(QFieldViewBase *pView,
00096                                                  UInt32          uiIndex)
00097     : Inherited    (pView, uiIndex),
00098       _strCachedVal(              ),
00099       _cachedSize  (              ),
00100       _bCacheValid (false         )
00101 {
00102 }
00103 
00107 QFieldValueLabelBase *
00108 QGenericFieldValueLabel::create(QFieldViewBase *pView, UInt32 uiIndex)
00109 {
00110     return new QGenericFieldValueLabel(pView, uiIndex);
00111 }
00112 
00116 QGenericFieldValueLabel::~QGenericFieldValueLabel(void)
00117 {
00118 }
00119 
00123 void
00124 QGenericFieldValueLabel::paint(QPainter *pPainter, const QColorGroup &colGrp,
00125                                                    const QRect       &rect)
00126 {
00127     if(!rect.isValid())
00128         return;
00129 
00130     pPainter->save();
00131 
00132     pPainter->setPen  (colGrp.text());
00133     pPainter->setBrush(colGrp.base());
00134 
00135     if( (rect.width() < sizeHint().width())   || 
00136         (rect.height() < sizeHint().height())   )
00137     {
00138         pPainter->drawRect(rect);
00139 
00140         pPainter->drawText(rect, AlignVCenter, getCachedValue());
00141     }
00142     else
00143     {
00144         QRect rectText(rect.x()    +4, rect.y()     +4, 
00145                        rect.width()-8, rect.height()-8 );
00146 
00147         pPainter->drawRect(rect);
00148 
00149         pPainter->drawText(rectText, AlignVCenter, getCachedValue());
00150     }
00151 
00152     pPainter->restore();
00153 }
00154 
00158 QSize
00159 QGenericFieldValueLabel::sizeHint(void)
00160 {
00161     return QSize(getCachedSize().width()  + 8,
00162                  getCachedSize().height() + 8);
00163 }
00164 
00168 QSize
00169 QGenericFieldValueLabel::minimumSizeHint(void)
00170 {
00171     return getCachedSize();
00172 }
00173 
00177 void
00178 QGenericFieldValueLabel::valueChanged(void)
00179 {
00180     _bCacheValid = false;
00181 }
00182 
00183 const QString &
00184 QGenericFieldValueLabel::getCachedValue(void)
00185 {
00186     updateCache();
00187 
00188     return _strCachedVal;
00189 }
00190 
00191 const QSize &
00192 QGenericFieldValueLabel::getCachedSize(void)
00193 {
00194     updateCache();
00195 
00196     return _cachedSize;
00197 }
00198 
00203 void
00204 QGenericFieldValueLabel::updateCache(void)
00205 {
00206     if(_bCacheValid)
00207         return;
00208 
00209     if(getIndex() >= getFieldPtr()->getSize())
00210     {
00211         _strCachedVal = "";
00212         _cachedSize   = QSize(10, getFieldView()->fontMetrics().height());
00213         _bCacheValid  = true;
00214 
00215         return;
00216     }
00217 
00218     std::string strTemp;
00219 
00220     getFieldPtr()->getValueByStr(strTemp, getIndex());
00221     
00222     _strCachedVal = strTemp.c_str();
00223     
00224     _cachedSize   = QSize(getFieldView()->fontMetrics().width (_strCachedVal),
00225                           getFieldView()->fontMetrics().height(             ));
00226     
00227     _bCacheValid = true;
00228 }

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