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