00001
00002
00003 #include "Iguana/GLBrowsers/interface/Ig3DMBoolControl.h"
00004 #include "Iguana/GLBrowsers/interface/IgControlCategory.h"
00005 #include <classlib/utils/DebugAids.h>
00006 #include <qlayout.h>
00007 #include <qlabel.h>
00008 #include <qwhatsthis.h>
00009 #include <qcombobox.h>
00010 #include <qcheckbox.h>
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 Ig3DMBoolControl::Ig3DMBoolControl (IgControlCategory *pane,
00023 QString label)
00024 : Ig3DFieldControl (pane),
00025 m_value (0),
00026 m_indexs (0),
00027 m_values (1, SbBool (""))
00028 {
00029 ASSERT (pane);
00030 ASSERT (pane->bodyArea ());
00031 ASSERT (pane->bodyLayout ());
00032
00033 QWidget *area = pane->bodyArea ();
00034 int row = gridRows ();
00035
00036 ASSERT (row >= 0);
00037
00038
00039 QWidget *vlab = makeIndentedLabel (label, area);
00040 addGridWidget (vlab, row, 0);
00041 QWhatsThis::add (vlab, "Bool values");
00042
00043 m_value = new QWidget(area);
00044 QHBoxLayout *l = new QHBoxLayout (m_value, 0, 5);
00045 l->addItem ( new QSpacerItem( 50, 20, QSizePolicy::Expanding,
00046 QSizePolicy::Minimum ));
00047
00048 m_indexs = new QComboBox (m_value);
00049 l->addWidget (m_indexs);
00050 m_indexs->insertItem ("0");
00051 m_indexs->setCurrentItem (0);
00052 m_indexs->hide ();
00053 QWhatsThis::add (m_indexs, "Select the index");
00054 l->addItem ( new QSpacerItem( 50, 20, QSizePolicy::Expanding,
00055 QSizePolicy::Minimum ));
00056
00057 m_checkBox = new QCheckBox ("", area);
00058 QWhatsThis::add (m_checkBox, "Bool values");
00059 l->addWidget (m_checkBox);
00060
00061 addGridWidget (makeSpacedBox (area, m_value), row, 1);
00062
00063
00064 connect (m_indexs, SIGNAL (activated (int)),
00065 this, SLOT (newIndex (int)));
00066 connect (m_checkBox, SIGNAL (toggled (bool)),
00067 this, SLOT (valueChanged(bool)));
00068 connect (this, SIGNAL (editable (bool)),
00069 m_value, SLOT (setEnabled (bool)));
00070 connect (this, SIGNAL (editable (bool)),
00071 vlab, SLOT (setEnabled (bool)));
00072 }
00073
00075 SoMFBool *
00076 Ig3DMBoolControl::field (void) const
00077 { return static_cast<SoMFBool *> (Ig3DFieldControl::field ()); }
00078
00079 void
00080 Ig3DMBoolControl::setField (SoMFBool *field)
00081 { Ig3DFieldControl::setField (field); }
00082
00083 const SbBool*
00084 Ig3DMBoolControl::fieldValue (void) const
00085 { ASSERT (field ()); return field ()->getValues (0); }
00086
00087 QWidget*
00088 Ig3DMBoolControl::widget(void) const
00089 { return m_value; }
00090
00092 const SbBool*
00093 Ig3DMBoolControl::value (void) const
00094 { return &(m_values[0]); }
00095
00096 void
00097 Ig3DMBoolControl::resize (unsigned int size)
00098 {
00099 ASSERT (size);
00100 int sizeDiff = size - m_values.size ();
00101 if (sizeDiff == 0) return;
00102
00103 m_values.resize (size);
00104 if (sizeDiff > 0)
00105 {
00106 for (unsigned int i = size - sizeDiff; i < size; i++)
00107 m_indexs->insertItem (QString::number (i));
00108 }
00109 else {
00110 for (unsigned int i = size - sizeDiff - 1 ; i >= size; i--)
00111 m_indexs->removeItem (i);
00112 }
00113
00114 if (size > 1)
00115 m_indexs->show ();
00116 else
00117 m_indexs->hide ();
00118 }
00119
00120 void
00121 Ig3DMBoolControl::setValue (unsigned int size, const SbBool* newval)
00122 {
00123 int index = m_indexs->currentItem ();
00124 if (index < 0)
00125 index = 0;
00126
00127 resize (size);
00128 for (unsigned int i = 0; i < size; i++)
00129 m_values [i] = newval [i];
00130
00131 m_indexs->setCurrentItem (index);
00132 m_checkBox->setChecked (newval [index]);
00133 setDirty ();
00134 }
00135
00136 void
00137 Ig3DMBoolControl::valueChanged (bool newval)
00138 {
00139 m_values[m_indexs->currentItem ()] = newval;
00140 setDirty ();
00141 }
00142
00143 void
00144 Ig3DMBoolControl::updateValue (void)
00145 { setValue (static_cast<SoMFBool *>(field())->getNum (), fieldValue ()); }
00146
00147 void
00148 Ig3DMBoolControl::applyValue (void)
00149 { field ()->setValues (0, int(m_values.size ()), value ()); }
00150
00151 void
00152 Ig3DMBoolControl::newIndex (int index)
00153 { m_checkBox->setChecked (m_values[index]); }