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

OSGQFieldView_qt.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 "OSGQFieldView_qt.h"
00040 
00041 #include "OSGQFieldValueLabel.h"
00042 #include "OSGQFieldLabelFactory.h"
00043 #include "OSGQFieldEditor_qt.h"
00044 #include "OSGQFieldEditorFactory.h"
00045 
00046 #include <OSGBaseFunctions.h>
00047 
00048 #include <qpainter.h>
00049 #include <qscrollbar.h>
00050 #include <qrect.h>
00051 #include <qfontmetrics.h>
00052 
00053 OSG_USING_NAMESPACE
00054 
00055 #ifdef __sgi
00056 #pragma set woff 1174
00057 #endif
00058 
00059 namespace
00060 {
00061     static Char8 cvsid_cpp[] = "@(#)$Id: OSGQFieldView_qt.cpp,v 1.2 2003/05/11 10:33:26 dirk Exp $";
00062     static Char8 cvsid_hpp[] = OSGQFIELDVIEWBASE_HEADER_CVSID;
00063     static Char8 cvsid_inl[] = OSGQFIELDVIEWBASE_INLINE_CVSID;
00064 }
00065 
00066 #ifdef __sgi
00067 #pragma reset woff 1174
00068 #endif
00069 
00070 QFieldViewBase::QFieldViewBase(FieldContainerPtr  pFC,          
00071                                UInt32             uiFieldId,
00072                                UInt32             uiAspect,
00073                                QWidget           *parent,    const char  *name)
00074     : Inherited (parent, name),
00075       _pFieldCon(pFC         ),
00076       _uiFieldId(uiFieldId   ),
00077       _uiAspect (uiAspect    )
00078 {
00079 }
00080 
00081 QFieldViewBase::~QFieldViewBase(void)
00082 {
00083 }
00084 
00085 void
00086 QFieldViewBase::setAll(FieldContainerPtr pFC,     UInt32 uiFieldId, 
00087                        UInt32            uiAspect                  )
00088 {
00089     _pFieldCon = pFC;
00090     _uiFieldId = uiFieldId;
00091     _uiAspect  = uiAspect;
00092 }
00093 
00094 void
00095 QFieldViewBase::setFieldContainer(FieldContainerPtr pFC)
00096 {
00097     _pFieldCon = pFC;
00098 }
00099 
00100 
00101 void
00102 QFieldViewBase::setFieldId(UInt32 uiFieldId)
00103 {
00104     _uiFieldId = uiFieldId;
00105 }
00106 
00107 void
00108 QFieldViewBase::setAspect(UInt32 uiAspect)
00109 {
00110     _uiAspect = uiAspect;
00111 }
00112 
00113 //
00114 // QSFFieldView
00115 //
00116 
00117 QSFieldView::QSFieldView(FieldContainerPtr  pFC,          
00118                          UInt32             uiFieldId,
00119                          UInt32             uiAspect,
00120                          QWidget           *parent,   const char   *name      )
00121     : Inherited(pFC, uiFieldId, uiAspect, parent, name),
00122       _pLabel  (NULL                                  ),
00123       _pEditor (NULL                                  )
00124 {
00125     setBackgroundMode(NoBackground);
00126 
00127     initSelf();
00128 }
00129 
00130 QSFieldView::~QSFieldView(void)
00131 {
00132     endEdit();
00133 
00134     delete _pLabel;
00135     delete _pEditor;
00136 }
00137 
00138 void
00139 QSFieldView::setAll(FieldContainerPtr pFC, UInt32 uiFieldId, UInt32 uiAspect)
00140 {
00141     endEdit();
00142 
00143     delete _pLabel;
00144     delete _pEditor;
00145 
00146     Inherited::setAll(pFC, uiFieldId, uiAspect);
00147 
00148     initSelf();
00149 }
00150 
00151 void
00152 QSFieldView::setFieldContainer(FieldContainerPtr pFC)
00153 {
00154     if(pFC == getFieldContainer())
00155         return;
00156 
00157     endEdit();
00158 
00159     delete _pLabel;
00160     delete _pEditor;
00161 
00162     Inherited::setFieldContainer(pFC);
00163 
00164     initSelf();
00165 }
00166 
00167 void
00168 QSFieldView::setFieldId(UInt32 uiFieldId)
00169 {
00170     if(uiFieldId == getFieldId())
00171         return;
00172 
00173     endEdit();
00174 
00175     delete _pLabel;
00176     delete _pEditor;
00177 
00178     Inherited::setFieldId(uiFieldId);
00179 
00180     initSelf();
00181 }
00182 
00183 void
00184 QSFieldView::setAspect(UInt32 uiAspect)
00185 {
00186     if(uiAspect == getAspect())
00187         return;
00188 
00189     endEdit();
00190 
00191     delete _pLabel;
00192     delete _pEditor;
00193 
00194     Inherited::setAspect(uiAspect);
00195 
00196     initSelf();
00197 }
00198 
00199 QSize
00200 QSFieldView::sizeHint(void) const
00201 {
00202     return _pLabel->sizeHint();
00203 }
00204 
00205 QSize
00206 QSFieldView::minimumSizeHint(void) const
00207 {
00208     return _pLabel->minimumSizeHint();
00209 }
00210 
00211 QSizePolicy
00212 QSFieldView::sizePolicy(void) const
00213 {
00214     return QSizePolicy(QSizePolicy::MinimumExpanding, 
00215                        QSizePolicy::Fixed            );
00216 }
00217 
00218 void
00219 QSFieldView::beginEdit(UInt32 uiIndex)
00220 {
00221     if(uiIndex != 0)
00222         return;
00223 
00224     endEdit();
00225 
00226     _pEditor->setIndex(uiIndex);
00227     _pEditor->activate(       );
00228 
00229     update();
00230 }
00231 
00232 void
00233 QSFieldView::endEdit(void)
00234 {
00235     if(_pEditor && _pEditor->getActive())
00236         _pEditor->deactivate();
00237 
00238     update();
00239 }
00240 
00241 void
00242 QSFieldView::mousePressEvent(QMouseEvent *pEvent)
00243 {
00244     emit clicked(getFieldContainer(), getFieldId(), 0, pEvent->button());
00245 }
00246 
00247 void
00248 QSFieldView::mouseDoubleClickEvent(QMouseEvent *pEvent)
00249 {
00250     emit doubleClicked(getFieldContainer(), getFieldId(), 0, pEvent->button());
00251 }
00252 
00253 void
00254 QSFieldView::onEditorDone(void)
00255 {
00256     endEdit();
00257 }
00258 
00259 void
00260 QSFieldView::onFieldUpdated(UInt32 OSG_CHECK_ARG(uiIndex))
00261 {
00262     _pLabel->valueChanged();
00263 }
00264 
00265 void
00266 QSFieldView::paintEvent(QPaintEvent *pEvent)
00267 {
00268     if(_pEditor && _pEditor->getActive())
00269         return;
00270 
00271     QPainter painter;
00272     QRect    rectSelf = rect();
00273 
00274     painter.begin(this);
00275 
00276     painter.setClipRect(rectSelf.intersect(pEvent->rect()));
00277 
00278     _pLabel->paint(&painter, palette().active(), rectSelf);
00279 
00280     painter.end();
00281 }
00282 
00283 void
00284 QSFieldView::resizeEvent(QResizeEvent *pEvent)
00285 {
00286     if(_pEditor)
00287         _pEditor->resize(pEvent->size());
00288 }
00289 
00290 void
00291 QSFieldView::initSelf(void)
00292 {
00293     _pLabel  = QFieldLabelFactory::the().createLabel  (this, 0);
00294     _pEditor = QFieldEditorFactory::the().createEditor(
00295         0, this, "QSFieldView::_pEditor");
00296 
00297     connect(_pEditor, SIGNAL(editorDone    (void  )),
00298             this,     SLOT  (onEditorDone  (void  )));
00299 
00300     connect(_pEditor, SIGNAL(fieldUpdated  (UInt32)),
00301             this,     SLOT  (onFieldUpdated(UInt32)));
00302 }
00303 
00304 //
00305 // MFieldView
00306 //
00307 
00308 QMFieldView::QMFieldView(FieldContainerPtr  pFC,
00309                          UInt32             uiFieldId,
00310                          UInt32             uiAspect,
00311                          QWidget           *parent,   const char   *name      )
00312     : Inherited        (pFC, uiFieldId, uiAspect, parent, name),
00313       _pScrollbar      (NULL                                  ),
00314       _pEditor         (NULL                                  ),
00315       _poolLabels      (                                      ),
00316       _usedLabels      (                                      ),
00317       _bContentsChanged(true                                  ),
00318       _uiBeginIndex    (0                                     ),
00319       _uiEndIndex      (0                                     )
00320 {
00321     initSelf     ();
00322     initScrollbar();
00323 
00324     connect(_pScrollbar, SIGNAL(valueChanged(int)),
00325             this,        SLOT  (onSBValueChanged(int)));
00326 }
00327 
00328 QMFieldView::~QMFieldView(void)
00329 {
00330     endEdit();
00331 
00332     deleteAllLabels();
00333 }
00334 
00335 void
00336 QMFieldView::setAll(FieldContainerPtr pFC, UInt32 uiFieldId, UInt32 uiAspect)
00337 {
00338     endEdit();
00339 
00340     deleteAllLabels();
00341     delete _pEditor;
00342 
00343     Inherited::setAll(pFC, uiFieldId, uiAspect);
00344 
00345     initSelf     ();
00346     initScrollbar();
00347     
00348     _bContentsChanged = true;
00349 }
00350 
00351 void
00352 QMFieldView::setFieldContainer(FieldContainerPtr pFC)
00353 {
00354     if(pFC == getFieldContainer())
00355         return;
00356 
00357     endEdit();
00358 
00359     deleteAllLabels();
00360     delete _pEditor;
00361 
00362     Inherited::setFieldContainer(pFC);
00363 
00364     initSelf     ();
00365     initScrollbar();
00366 
00367     _bContentsChanged = true;
00368 }
00369 
00370 void
00371 QMFieldView::setFieldId(UInt32 uiFieldId)
00372 {
00373     if(uiFieldId == getFieldId())
00374         return;
00375 
00376     endEdit();
00377 
00378     deleteAllLabels();
00379     delete _pEditor;
00380 
00381     Inherited::setFieldId(uiFieldId);
00382 
00383     initSelf     ();
00384     initScrollbar();
00385 
00386     _bContentsChanged = true;
00387 }
00388 
00389 void
00390 QMFieldView::setAspect(UInt32 uiAspect)
00391 {
00392     if(uiAspect == getAspect())
00393         return;
00394 
00395     endEdit();
00396 
00397     deleteAllLabels();
00398     delete _pEditor;
00399 
00400     Inherited::setAspect(uiAspect);
00401 
00402     initSelf     ();
00403     initScrollbar();
00404 
00405     _bContentsChanged = true;
00406 }
00407 
00408 QSize
00409 QMFieldView::sizeHint(void) const
00410 {
00411     QMFieldView          *pThis         = const_cast<QMFieldView *>(this);
00412     QFieldValueLabelBase *pLabel;
00413     QSize                 labelSize( 0,  0);
00414     QSize                 retSize  (10, 10);
00415     bool                  bReleaseLabel = false;
00416 
00417     if(_usedLabels.size() != 0)
00418     {
00419         pLabel = (*_usedLabels.begin()).second.getLabel();
00420     }
00421     else
00422     {
00423         pLabel        = QFieldLabelFactory::the().createLabel(pThis, 0);
00424         bReleaseLabel = true;
00425     }
00426 
00427     labelSize = pLabel->sizeHint();
00428 
00429     retSize.setHeight(
00430         osgMin<UInt32>(5, getFieldPtr()->getSize()) * labelSize.height());
00431 
00432     retSize.setWidth(
00433         osgMax(retSize.width(), labelSize.width() + _pScrollbar->width()));
00434 
00435     
00436     retSize.setWidth (osgMax(retSize.width(),  10*fontMetrics().width("W")));
00437     
00438     retSize.setHeight(osgMax(retSize.height(),    fontMetrics().height()  ));
00439 
00440     if(bReleaseLabel)
00441         delete pLabel;
00442 
00443     return retSize;
00444 }
00445 
00446 QSize
00447 QMFieldView::minimumSizeHint(void) const
00448 {
00449     return sizeHint();
00450 }
00451 
00452 QSizePolicy
00453 QMFieldView::sizePolicy(void) const
00454 {
00455     return QSizePolicy(QSizePolicy::MinimumExpanding, 
00456                        QSizePolicy::MinimumExpanding );
00457 }
00458 
00459 void
00460 QMFieldView::beginEdit(UInt32 uiIndex)
00461 {
00462     if(uiIndex >= getFieldPtr()->getSize())
00463         return;
00464 
00465     endEdit();
00466 
00467     _pEditor->setIndex(uiIndex);
00468     _pEditor->activate(       );
00469 
00470     update();
00471 }
00472 
00473 void
00474 QMFieldView::endEdit(void)
00475 {
00476     if(_pEditor && _pEditor->getActive())
00477         _pEditor->deactivate();
00478 
00479     update();
00480 }
00481 
00482 void
00483 QMFieldView::paintEvent(QPaintEvent *pEvent)
00484 {
00485     SNOTICE << "QMFieldView::paintEvent()" << endLog;
00486 
00487     QPainter painter;
00488 
00489     painter.begin(this);
00490 
00491     if(_bContentsChanged)
00492         redrawChanged  (pEvent, &painter);
00493     else
00494         redrawUnchanged(pEvent, &painter);
00495 
00496     painter.end();
00497 }
00498 
00499 void
00500 QMFieldView::resizeEvent(QResizeEvent *OSG_CHECK_ARG(pEvent))
00501 {
00502 //    SNOTICE << "QMFieldView::resizeEvent()" << endLog;
00503 
00504     _bContentsChanged = true;
00505 
00506     _pScrollbar->setGeometry(
00507         width() - _pScrollbar->sizeHint().width(), 0,
00508         _pScrollbar->sizeHint().width(),           height());
00509 
00510 //    _pScrollbar->move  (width()-_pScrollbar->sizeHint().width(), 0);
00511 //    _pScrollbar->resize(_pScrollbar->sizeHint().width(),height()); 
00512 }
00513 
00514 void
00515 QMFieldView::wheelEvent(QWheelEvent *pEvent)
00516 {
00517     if(_pScrollbar->isEnabled())
00518     {
00519         _pScrollbar->setValue(
00520             static_cast<int>(-pEvent->delta() / 60) + _pScrollbar->value());
00521     }
00522 }
00523 
00524 void
00525 QMFieldView::mousePressEvent(QMouseEvent *pEvent)
00526 {
00527     bool   bValid  = false;
00528     UInt32 uiIndex = pointToIndex(pEvent->pos(), bValid);
00529     
00530     if(bValid && (uiIndex < getFieldPtr()->getSize()))
00531     {
00532         emit clicked(getFieldContainer(), getFieldId(),
00533                      uiIndex,             pEvent->button());
00534     }
00535 }
00536 
00537 void
00538 QMFieldView::mouseDoubleClickEvent(QMouseEvent *pEvent)
00539 {
00540     bool   bValid  = false;
00541     UInt32 uiIndex = pointToIndex(pEvent->pos(), bValid);
00542 
00543     if(bValid && (uiIndex < getFieldPtr()->getSize()))
00544     {
00545         emit doubleClicked(getFieldContainer(), getFieldId(), 
00546                            uiIndex,             pEvent->button());
00547     }
00548 }
00549 
00550 void
00551 QMFieldView::onEditorDone(void)
00552 {
00553     endEdit();
00554 }
00555 
00556 void
00557 QMFieldView::onFieldUpdated(UInt32 uiIndex)
00558 {
00559     IndexLabelMapIt iterLabel = _usedLabels.find(uiIndex);
00560 
00561     if(iterLabel != _usedLabels.end())
00562         (*iterLabel).second.getLabel()->valueChanged();
00563 }
00564 
00565 void
00566 QMFieldView::onSBValueChanged(int OSG_CHECK_ARG(value))
00567 {
00568     _bContentsChanged = true;
00569     
00570     update();
00571 }
00572 
00573 void
00574 QMFieldView::initSelf(void)
00575 {
00576     _pEditor = QFieldEditorFactory::the().createEditor(
00577         this, "QMFieldView::_pEditor");
00578 
00579     connect(_pEditor, SIGNAL(editorDone    (void  )),
00580             this,     SLOT  (onEditorDone  (void  )));
00581 
00582     connect(_pEditor, SIGNAL(fieldUpdated  (UInt32)),
00583             this,     SLOT  (onFieldUpdated(UInt32)));
00584 }
00585 
00586 void
00587 QMFieldView::initScrollbar(void)
00588 {
00589     if(_pScrollbar == NULL)
00590     {
00591         _pScrollbar = new QScrollBar(Vertical, this, 
00592                                      "QMFieldView::_pScrollbar");
00593     }
00594 
00595     _pScrollbar->setGeometry(
00596         width()-_pScrollbar->sizeHint().width(), 0,
00597         _pScrollbar->sizeHint().width(),         height());
00598 
00599     if(getFieldPtr()->getSize() <= 2)
00600     {
00601         _pScrollbar->hide       ( );
00602         _pScrollbar->setMinValue(0);
00603         _pScrollbar->setMaxValue(0);
00604     }
00605     else
00606     {
00607         _pScrollbar->show       (                            );
00608         _pScrollbar->setMinValue(0                           );
00609         _pScrollbar->setMaxValue(2*getFieldPtr()->getSize()-2);
00610     }
00611 }
00612 
00613 UInt32
00614 QMFieldView::pointToIndex(const QPoint &pos, bool &bValid)
00615 {
00616     IndexLabelMapIt iter = _usedLabels.begin();
00617     IndexLabelMapIt end  = _usedLabels.end();
00618 
00619     for(; iter != end; ++iter)
00620     {
00621         if( ((*iter).second.getRect().top()     <= pos.y()) &&
00622             ((*iter).second.getRect().bottom()  >= pos.y())   )
00623         {
00624             bValid = true;
00625 
00626             return (*iter).first;
00627         }
00628     }
00629 
00630     bValid = false;
00631 
00632     return 0;
00633 }
00634 
00635 QFieldValueLabelBase *
00636 QMFieldView::acquireLabel(UInt32 uiIndex)
00637 {
00638     SNOTICE << "QMFieldView::acquireLabel(" << uiIndex << ")\n";
00639 
00640     QFieldValueLabelBase *retVal    = 0;
00641 
00642     IndexLabelMapIt       iterLabel = _usedLabels.find(uiIndex);
00643 
00644     if(iterLabel != _usedLabels.end())
00645     {
00646         PNOTICE << "from usedLabels: " << iterLabel->second.getLabel()
00647                 << endLog;
00648         
00649         return iterLabel->second.getLabel();
00650     }
00651 
00652     if(!_poolLabels.empty())
00653     {
00654         retVal = _poolLabels.back    ();
00655         
00656         _poolLabels.pop_back();
00657 
00658         PNOTICE << "from pool: " << retVal 
00659                 << "was index "  << retVal->getIndex()
00660                 << endLog;         
00661 
00662         retVal->setIndex(uiIndex);
00663 
00664         return retVal;
00665     }
00666     
00667     retVal = QFieldLabelFactory::the().createLabel(this, uiIndex);
00668 
00669     PNOTICE << "from factory: " << retVal << endLog;
00670 
00671     return retVal;
00672 }
00673 
00674 void
00675 QMFieldView::releaseLabel(QFieldValueLabelBase *pLabel)
00676 {
00677     SNOTICE << "QMFieldView::releaseLabel(" << pLabel << ") "
00678             << "index : "                   << pLabel->getIndex()
00679             << endLog;
00680 
00681     IndexLabelMapIt iterLabel = _usedLabels.find(pLabel->getIndex());
00682 
00683     if(iterLabel == _usedLabels.end())
00684     {
00685         SWARNING << "QMFieldView::releaseLabel: pLabel is not used." 
00686                  << endLog;
00687         return;
00688     }
00689 
00690     _usedLabels.erase    (iterLabel);
00691     _poolLabels.push_back(pLabel   );
00692 }
00693 
00694 void
00695 QMFieldView::releaseAllLabels(void)
00696 {
00697     QFieldValueLabelBase *pLabel;
00698     IndexLabelMapIt       iter = _usedLabels.begin();
00699     IndexLabelMapIt       end  = _usedLabels.end();
00700 
00701     for(; iter != end; ++iter)
00702     {
00703         pLabel = (*iter).second.getLabel();
00704         _poolLabels.push_back(pLabel);
00705     }
00706     _usedLabels.clear();
00707 }
00708 
00709 void
00710 QMFieldView::deleteAllLabels(void)
00711 {
00712     SNOTICE << "QMFieldView::deleteAllLabels():\n";
00713 
00714     QFieldValueLabelBase *pLabel;
00715 
00716     IndexLabelMapIt       usedIter = _usedLabels.begin();
00717     IndexLabelMapIt       usedEnd  = _usedLabels.end();
00718 
00719     PNOTICE << "used <" << _usedLabels.size() << "> ";
00720 
00721     for(; usedIter != usedEnd; ++usedIter)
00722     {
00723         pLabel = (*usedIter).second.getLabel();
00724 
00725         PNOTICE << " iter.first: "       << (*usedIter).first
00726                 << " pLabel->getIndex() " << pLabel->getIndex()
00727                 << " pLabel "            << pLabel
00728                 << "\n";
00729         delete pLabel;
00730     }
00731     _usedLabels.clear();
00732 
00733     PoolLabelListIt poolIter = _poolLabels.begin();
00734     PoolLabelListIt poolEnd  = _poolLabels.end();
00735     
00736     PNOTICE << "pool <" << _poolLabels.size() << "> ";
00737 
00738     for(; poolIter != poolEnd; ++poolIter)
00739     {
00740         pLabel = *poolIter;
00741 
00742         PNOTICE << " pLabel->getIndex() " << pLabel->getIndex()
00743                 << " pLabel "            << pLabel
00744                 << "\n";
00745 
00746         delete pLabel;
00747     }
00748 
00749     _poolLabels.clear();
00750 
00751     PNOTICE << endLog;
00752 }
00753 
00754 void
00755 QMFieldView::redrawUnchanged(QPaintEvent *pEvent, QPainter *pPainter)
00756 {
00757     SNOTICE << "QMFieldView::redrawUnchanged()" << endLog;
00758 
00759     IndexLabelMapIt begin = _usedLabels.begin();
00760     IndexLabelMapIt end   = _usedLabels.end();
00761 
00762     for(; begin != end; ++begin)
00763     {
00764         pPainter->setClipRect(
00765             (*begin).second.getRect().intersect(pEvent->rect()));
00766 
00767         (*begin).second.getLabel()->paint(
00768             pPainter, palette().active(), (*begin).second.getRect());
00769     }
00770 }
00771 
00772 void
00773 QMFieldView::redrawChanged(QPaintEvent *pEvent, QPainter *pPainter)
00774 {
00775     SNOTICE << "QMFieldView::redrawChanged()" << endLog;
00776 
00777     UInt32                currIndex;
00778     Int32                 drawTop;
00779 
00780     QRect                 drawRect;
00781     QSize                 drawSize;
00782 
00783     bool                  doneDraw = false;
00784 
00785     QFieldValueLabelBase *pLabel;
00786 
00787     _uiBeginIndex = _pScrollbar->value()/2;
00788     _uiEndIndex   = _uiBeginIndex;
00789     currIndex     = _uiBeginIndex;
00790 
00791     if(_uiBeginIndex >= getFieldPtr()->getSize())
00792     {
00793         releaseAllLabels();
00794         return;
00795     }
00796 
00797     pLabel   = acquireLabel   (_uiEndIndex++);
00798     drawSize = pLabel->sizeHint(             );
00799     drawTop  = ((_pScrollbar->value() % 2) == 0) ? 0 : -drawSize.height()/2;
00800 
00801     drawRect = QRect(0, drawTop,
00802                      width()-_pScrollbar->width(), 
00803                      osgMin(drawSize.height(), height()            ) );
00804 
00805     while(!doneDraw)
00806     {
00807         pPainter->setClipRect(drawRect.intersect(pEvent->rect()));
00808 
00809         pLabel->paint(pPainter, palette().active(), drawRect);
00810         
00811         _usedLabels[currIndex].setLabel(pLabel  );
00812         _usedLabels[currIndex].setRect (drawRect);
00813               
00814         drawTop += drawRect.height();
00815         
00816         if((_uiEndIndex >= getFieldPtr()->getSize()) ||
00817            (drawTop     >= height()                )   )
00818         {
00819             doneDraw = true;
00820         }
00821         else
00822         {
00823             currIndex = _uiEndIndex++;
00824             pLabel    = acquireLabel    (currIndex);
00825             drawSize  = pLabel->sizeHint(         );
00826 
00827             drawRect  = QRect(0, drawTop,
00828                               width()-_pScrollbar->width(),
00829                               osgMin(drawSize.height(), height()));
00830         }
00831     }
00832 
00833     IndexLabelMapIt   begin = _usedLabels.begin();
00834     IndexLabelMapIt   end   = _usedLabels.end();
00835 
00836     for(; begin != end; ++begin)
00837     {
00838         pLabel = begin->second.getLabel();
00839 
00840         if( (pLabel->getIndex() <  _uiBeginIndex) ||
00841             (pLabel->getIndex() >= _uiEndIndex  )   )
00842         {
00843             releaseLabel(pLabel);
00844 //            _usedLabels.erase(begin);
00845 //            _poolLabels.push_back(pLabel);
00846         }
00847     }
00848 
00849     _bContentsChanged = false;
00850 }
00851 
00852 //
00853 // QMFieldView::LabelInfo
00854 //
00855 
00856 QMFieldView::LabelInfo::LabelInfo(void)
00857     : _pLabel (NULL),
00858       _rectPos(    )
00859 {
00860 }
00861 
00862 QMFieldView::LabelInfo::LabelInfo(QFieldValueLabelBase *pLabel, 
00863                                   const QRect          &rectPos)
00864     : _pLabel (pLabel ),
00865       _rectPos(rectPos)
00866 {
00867 }
00868 
00869 void
00870 QMFieldView::LabelInfo::setLabel(QFieldValueLabelBase *pLabel)
00871 {
00872     _pLabel = pLabel;
00873 }
00874 
00875 QFieldValueLabelBase *
00876 QMFieldView::LabelInfo::getLabel(void) const
00877 {
00878     return _pLabel;
00879 }
00880 
00881 UInt32
00882 QMFieldView::LabelInfo::getIndex(void) const
00883 {
00884     return _pLabel->getIndex();
00885 }
00886 
00887 void
00888 QMFieldView::LabelInfo::setRect(const QRect &rectPos)
00889 {
00890     _rectPos = rectPos;
00891 }
00892 
00893 QRect &
00894 QMFieldView::LabelInfo::getRect(void)
00895 {
00896     return _rectPos;
00897 }
00898 
00899 const QRect &
00900 QMFieldView::LabelInfo::getRect(void) const
00901 {
00902     return _rectPos;
00903 }
00904 
00905 #include "OSGQFieldView_qt_moc.cpp"

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