CMS 3D CMS Logo

IgControlCentre.cc

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** Form implementation generated from reading ui file 'Iguana/GLBrowsers/src/IgControlCentre.ui'
00003 **
00004 ** Created: Fri Oct 31 14:27:53 2003
00005 **      by: The User Interface Compiler ($Id: IgControlCentre.cc,v 1.3 2007/10/23 12:49:30 serkan Exp $)
00006 **
00007 ** WARNING! All changes made in this file will be lost!
00008 ****************************************************************************/
00009 
00010 #include "Iguana/GLBrowsers/interface/IgControlCentre.h"
00011 #include "Iguana/Studio/interface/IgQtAppHelp.h"
00012 #include "Iguana/GLBrowsers/interface/IgControlCategory.h"
00013 
00014 #include <qvariant.h>
00015 #include <qpushbutton.h>
00016 #include <qlayout.h>
00017 #include <qiconview.h>
00018 #include <qpoint.h>
00019 #include <qwhatsthis.h>
00020 #include <qsizepolicy.h>
00021 #include <qevent.h>
00022 /*
00023  *  Constructs a IgControlCentre as a child of 'parent', with the
00024  *  name 'name' and widget flags set to 'f'.
00025  *
00026  *  The dialog will by default be modeless, unless you set 'modal' to
00027  *  TRUE to construct a modal dialog.
00028  */
00029 IgControlCentre::IgControlCentre(QWidget* parent, const char* name, bool modal, WFlags fl )
00030     : QDialog( parent, name, modal, fl ),
00031       IgControlCentreLayout (0),
00032       m_layout1 (0),
00033       m_layout2 (0),
00034       m_current (0),
00035       m_iconView (0),
00036       m_updateOnWindowActive (false),
00037       m_focusChanged (false)
00038 {
00039     if ( !name )
00040       setName( m_name );
00041     
00042     m_name = "IGUANA Control Centre";
00043     m_baseName = "";
00044     
00045     setFocusPolicy (QWidget::StrongFocus);
00046     IgControlCentreLayout = new QGridLayout( this, 1, 1, 11, 6, "IgControlCentreLayout");
00047 
00048     m_layout2 = new QGridLayout( 0, 1, 1, 0, 6, "m_layout2"); 
00049 
00050     m_iconView = new QIconView (0, "m_iconView");
00051     m_iconView->setSelectionMode (QIconView::Single);
00052     m_iconView->setAutoArrange (true);
00053     m_iconView->setResizeMode (QIconView::Adjust);
00054     
00055     m_layout2->addWidget(m_iconView , 0, 0 );
00056 
00057     m_layout1 = new QHBoxLayout( 0, 0, 6, "m_layout1"); 
00058 
00059     m_back = new QPushButton( this, "m_back" );
00060     m_back->setAutoDefault( false );
00061     m_back->setEnabled ( false );
00062     m_back->setFixedSize (QSize(45, 22));
00063     m_layout1->addWidget( m_back );
00064     QSpacerItem* spacer0 = new QSpacerItem( 50, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00065     m_layout1->addItem( spacer0 );
00066 
00067     m_close = new QPushButton( this, "m_close" );
00068     m_close->setAutoDefault( false );
00069     m_close->setFixedSize (QSize(45, 22));
00070     m_layout1->addWidget( m_close );
00071     QSpacerItem* spacer = new QSpacerItem( 50, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00072     m_layout1->addItem( spacer );
00073 
00074     m_revert = new QPushButton( this, "m_revert" );
00075     m_revert->setAutoDefault( false );
00076     m_revert->setEnabled( false );
00077     m_revert->setFixedSize (QSize(45, 22));
00078     m_layout1->addWidget( m_revert );
00079     QSpacerItem* spacer_2 = new QSpacerItem( 50, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00080     m_layout1->addItem( spacer_2 );
00081 
00082     m_apply = new QPushButton( this, "m_apply" );
00083     m_apply->setAutoDefault( false );
00084     m_apply->setEnabled( false );
00085     m_apply->setFixedSize (QSize(45, 22));
00086     m_layout1->addWidget( m_apply );
00087     QSpacerItem* spacer_3 = new QSpacerItem( 50, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00088     m_layout1->addItem( spacer_3 );
00089 
00090     m_help = new QPushButton( this, "m_help" );
00091     m_help->setAutoDefault( false );
00092     m_help->setFixedSize (QSize(45, 22));
00093     m_layout1->addWidget( m_help );
00094 
00095     m_layout2->addLayout( m_layout1, 1, 0 );
00096 
00097     IgControlCentreLayout->addLayout( m_layout2, 0, 0 );
00098     languageChange();
00099     clearWState( WState_Polished );
00100     setSizeGripEnabled (true);
00101 
00102     // signals and slots connections
00103     connect (m_back, SIGNAL(clicked ()), this, SLOT(back ()));
00104     connect (m_close, SIGNAL(clicked ()), this, SLOT(close ()));
00105     connect (m_apply, SIGNAL(clicked ()), this, SLOT(apply ()));
00106     connect (m_revert, SIGNAL(clicked ()), this, SLOT(revert ()));
00107     connect (m_help, SIGNAL(clicked ()), this, SLOT(help ()));
00108     connect (m_iconView, SIGNAL (doubleClicked (QIconViewItem *)),
00109              this,       SLOT (selectIconItem (QIconViewItem *)));
00110     connect (m_iconView, SIGNAL (returnPressed (QIconViewItem *)),
00111              this,       SLOT (selectIconItem (QIconViewItem *)));
00112 }
00113 
00114 /*
00115  *  Destroys the object and frees any allocated resources
00116  */
00117 IgControlCentre::~IgControlCentre()
00118 {
00119     // no need to delete child widgets, Qt does it all for us
00120     while (! m_categories.empty ())
00121     {
00122         delete m_categories.begin ()->second.first;
00123         m_categories.erase (m_categories.begin ());
00124     }
00125     deleteIconViewArch (&m_iconViewArch);
00126 }
00127 
00128 void
00129 IgControlCentre::deleteIconViewArch (IconViewArch *toplevel)
00130 {
00131     while (!toplevel->empty ()){
00132        IconViewArch::iterator itr = toplevel->begin ();
00133        if (itr->second.first != 0)
00134        {
00135          deleteIconViewArch (static_cast<IconViewArch *>(itr->second.first));
00136          delete static_cast<IconViewArch *>(itr->second.first);
00137        }
00138        toplevel->erase (itr);
00139     }
00140 }
00141 
00142 /*
00143  *  Sets the strings of the subwidgets using the current
00144  *  language.
00145  */
00146 void IgControlCentre::languageChange()
00147 {
00148     setCaption( tr( m_name ) );
00149     m_back->setText( tr( "&Back" ) );
00150     m_back->setAccel( QKeySequence( tr( "Alt+P" ) ) );
00151     QWhatsThis::add( m_back, tr( "Go to the previous panel of the control centre." ) );
00152     m_close->setText( tr( "&Close" ) );
00153     m_close->setAccel( QKeySequence( tr( "Alt+C" ) ) );
00154     QWhatsThis::add( m_close, tr( "Close the Control Centre." ) );
00155     m_revert->setText( tr( "&Revert" ) );
00156     m_revert->setAccel( QKeySequence( tr( "Alt+R" ) ) );
00157     QWhatsThis::add( m_revert, tr( "Revert the changes made via GUI which are not yet applied. <br>\n"
00158 "When track changes option is not available or if available and <br>\n"
00159 "enabled then changes made via GUI will automatically be applied <br>\n"
00160 "and one can not revert those changes." ) );
00161     m_apply->setText( tr( "&Apply" ) );
00162     m_apply->setAccel( QKeySequence( tr( "Alt+A" ) ) );
00163     QWhatsThis::add( m_apply, tr( "Apply the changes made via GUI which are not yet applied.<br>\n"
00164 "When track changes option is not available or if available and<br>\n"
00165 "enabled then changes made via GUI will automatically be applied." ) );
00166     m_help->setText( tr( "&Help" ) );
00167     m_help->setAccel( QKeySequence( tr( "Alt+H" ) ) );
00168     QWhatsThis::add( m_help, tr( "Get the help.\n"));
00169 }
00170 
00172 void
00173 IgControlCentre::show (void)
00174 {
00175     static bool firstTime=true;
00176     if(!isShown())
00177     {
00178       QString old (m_baseName);
00179       m_baseName = "qqqqqq";      
00180       updateControlCentre (old);
00181       m_updateOnWindowActive=false;
00182       m_focusChanged = false;
00183       if (firstTime)
00184       {
00185         resize(QSize(600, 400).expandedTo (minimumSizeHint ()));
00186         firstTime = false;
00187       }
00188       QWidget::show ();
00189     }
00190     else
00191     {
00192       setActiveWindow ();
00193       raise();    
00194     }
00195 }
00196 
00198 void
00199 IgControlCentre::hide (void)
00200 {
00201     if (m_current)
00202     {
00203       QString name = m_baseName;
00204       back ();
00205       m_baseName =  name;
00206     }
00207     QWidget::hide ();
00208 }
00209 
00212 void 
00213 IgControlCentre::apply (void)
00214 {
00215     ASSERT (m_current);
00216     m_current->apply ();
00217 }
00218 
00221 void 
00222 IgControlCentre::revert (void)
00223 {
00224     ASSERT (m_current);
00225     m_current->revert ();
00226 }
00227 
00229 void 
00230 IgControlCentre::help (void)
00231 {
00232     QString url ("");
00233     if (m_current)
00234       url = m_current->getHelpURL ();
00235     if (url.isEmpty ())
00236       url = "https://iguana.web.cern.ch/iguana/snapshot/help/control_centre.html";
00237     IgQtAppHelp::netscape (url);
00238 }
00239 
00242 void 
00243 IgControlCentre::back (void)
00244 { 
00245     int index = m_baseName.findRev ("/");
00246     if (index != -1)
00247       showIconView (m_baseName.left(index));
00248     else
00249       showIconView ("");
00250 }
00251 
00252 void
00253 IgControlCentre::updateControlCentre (QString name)
00254 {
00255     if (name.length ()
00256         && m_categories.find (name) != m_categories.end ())
00257     {
00258       if (m_categories [name].second == true)
00259         showCategory (m_categories [name].first);
00260       else
00261       {
00262         m_baseName = name;
00263         back ();
00264       }
00265       return;
00266     }
00267     showIconView (name);
00268 }
00269 
00270 void 
00271 IgControlCentre::hideCategory (void)
00272 {
00273     if(!m_current) return;
00274     disconnect (m_current, SIGNAL(dirty()), 
00275                 this, SLOT(dirtyCategory()));
00276     disconnect (m_current, SIGNAL(clean()), 
00277                this, SLOT(cleanCategory()));
00278     m_current->hide ();
00279     m_current->panel ()->reparent ((QWidget*)(0), QPoint(0,0));
00280     m_layout2->remove (m_current->panel ());
00281     m_current = 0;
00282 }
00283 
00284 void
00285 IgControlCentre::showCategory (IgControlCategory *category)
00286 {
00287     m_baseName = category->name ();
00288     if (m_current == category) return;
00289     hideCategory ();
00290     hideIconView ();
00291     m_current = category;
00292     connect (m_current, SIGNAL(dirty()), 
00293              this, SLOT(dirtyCategory()));
00294     connect (m_current, SIGNAL(clean()), 
00295              this, SLOT(cleanCategory()));
00296     m_current->panel ()->reparent (this, QPoint(0,0));
00297     m_layout2->addWidget(m_current->panel (), 0, 0);
00298     m_current->panel ()->show();
00299     m_back->setEnabled (true);
00300     if (m_baseName.length () > 20)
00301       setCaption(tr(m_name + " [..." + m_baseName.right (17) + "]"));
00302     else
00303       setCaption(tr(m_name + " [" + m_baseName + "]"));
00304     m_current->show ();
00305 }
00306 
00307 void
00308 IgControlCentre::addIconViewItems (QString name)
00309 {
00310   if (m_baseName == name && m_iconView->count() != 0) return;
00311   QString newBase ("");
00312   IconViewArch *toplevel = &m_iconViewArch;
00313  
00314   if (name != "")
00315   {  
00316     int index = name.find ("/");
00317     while (index != -1)
00318     {
00319       unsigned int length = name.length ();
00320       std::pair<void*, bool> item = (*toplevel)[name.left (index)];
00321       if (item.second == true)
00322       {
00323         toplevel=static_cast<IconViewArch *>(item.first);
00324         if(newBase == "")
00325           newBase = name.left (index);
00326         else
00327           newBase = newBase+ "/" + name.left (index);
00328 
00329         name = name.right (length - index - 1);
00330         index = name.find ("/");
00331       }
00332       else
00333       {
00334         index = -1;
00335         name = name.left (index);
00336       }
00337     }
00338     if ((*toplevel)[name].second == true)
00339     {
00340       toplevel=static_cast<IconViewArch *>((*toplevel)[name].first);
00341       
00342       if (newBase == "")
00343         newBase = name;
00344       else
00345         newBase = newBase+ "/" + name;
00346     }
00347   }
00348   
00349   if (newBase == "")
00350     m_back->setEnabled (false);
00351   else
00352     m_back->setEnabled (true);
00353 
00354   m_baseName = newBase;
00355   m_iconViewList.clear ();
00356   m_iconView->clear ();
00357   IconViewArch::iterator itr;
00358   
00359   for(itr = toplevel->begin (); itr != toplevel->end (); itr++)
00360   {
00361     if (itr->second.second == true)
00362     {
00363       if (itr->second.first)
00364         m_iconViewList.push_back (new QIconViewItem (m_iconView,
00365                                                      itr->first));
00366       else
00367       {
00368         QString cat (itr->first);
00369         if (!m_baseName.isEmpty ())
00370           cat = m_baseName + "/" + cat;
00371         QPixmap icon (m_categories[cat].first->getIcon ());
00372         if (icon.isNull ())
00373           m_iconViewList.push_back (new QIconViewItem (m_iconView, itr->first));
00374         else
00375           m_iconViewList.push_back (new QIconViewItem (m_iconView,
00376                                                        itr->first,
00377                                                        icon));
00378       }
00379     }
00380   }
00381   m_iconView->arrangeItemsInGrid ();
00382 
00383   if (m_baseName.length ())
00384   {
00385     if (m_baseName.length () > 20)
00386       setCaption(tr(m_name + " [..." + m_baseName.right (17) + "]"));
00387     else
00388       setCaption(tr(m_name + " [" + m_baseName + "]"));
00389   }
00390 }
00391 
00392 void
00393 IgControlCentre::showIconView (QString name)
00394 {
00395     addIconViewItems (name);
00396     if (!m_iconView->isShown ())
00397     {
00398       hideCategory ();
00399       m_iconView->reparent (this, QPoint(0,0));
00400       m_layout2->addWidget (m_iconView , 0, 0 );
00401       cleanCategory ();
00402       setCaption(tr(m_name));
00403       m_iconView->show ();
00404       m_iconView->arrangeItemsInGrid ();
00405     }
00406 }
00407 
00408 void
00409 IgControlCentre::hideIconView (void)
00410 {
00411     if (!m_iconView->isShown ()) return;
00412     m_iconView->reparent (0, QPoint(0,0));
00413     m_layout2->remove (m_iconView);
00414     m_iconView->hide ();
00415 }
00416 
00420 bool
00421 IgControlCentre::hasCategory (const IgControlCategory *category)
00422 {
00423     CategoryMap::iterator itr;
00424     for(itr = m_categories.begin (); itr != m_categories.end (); itr++)
00425     {
00426       if (itr->second.first == category)
00427         return true;
00428     }
00429     return false;
00430 }
00431 
00437 void
00438 IgControlCentre::addCategory (IgControlCategory *category)
00439 { 
00440     ASSERT (category);
00441     ASSERT (!hasCategory (category));
00442     
00443     QString name = category->name ();
00444     unsigned int length = name.length ();
00445     
00446     ASSERT (length);
00447     ASSERT (m_categories.find (name) == m_categories.end ());
00448     ASSERT ((name.left(1) != "/") && (name.right(1) != "/"));
00449     
00450     std::pair<IgControlCategory *, bool> c(category, true);
00451     m_categories[name]=c;
00452     
00453     int index = name.find ("/");
00454     IconViewArch *toplevel = &m_iconViewArch;
00455     while (index != -1)
00456     {
00457       length = length -1;
00458       
00459       QString sname = name.left(index);
00460       length = length-index;
00461       name = name.right (length);
00462       if (toplevel->find(sname) != toplevel->end ())
00463         toplevel = static_cast<IconViewArch *>((*toplevel)[sname].first);
00464       else
00465       {
00466         IconViewArch *child = new IconViewArch;
00467         std::pair<void *, bool> c(child, true);
00468         (*toplevel)[sname] = c;
00469         toplevel=child;
00470       }
00471       index = name.find ("/");
00472     }
00473     std::pair<void *, bool> c1(0, true);
00474     (*toplevel)[name] = c1;
00475 }
00476 
00477 void
00478 IgControlCentre::removeCategory (QString name, IconViewArch *toplevel)
00479 {
00480     int index = name.find ("/");
00481     if (index != -1)
00482     {
00483       QString sname = name.left(index);
00484       name = name.right (name.length() - index - 1);
00485       removeCategory (name, static_cast<IconViewArch *>((*toplevel)[sname].first));
00486       name = sname;
00487     }
00488     if ((*toplevel)[name].first == 0)
00489       toplevel->erase (name);
00490     else if (static_cast<IconViewArch *>((*toplevel)[name].first)->size () == 0)
00491     {
00492         delete static_cast<IconViewArch *>((*toplevel)[name].first);
00493         toplevel->erase (name);
00494     }
00495 }
00496 
00502 void
00503 IgControlCentre::removeCategory (IgControlCategory *category)
00504 {    
00505     ASSERT (category);
00506     ASSERT (hasCategory (category));
00507     if (m_current == category)
00508       back ();
00509     m_categories.erase (category->name ());
00510     removeCategory (category->name (), &m_iconViewArch);
00511 }
00512 
00518 void
00519 IgControlCentre::selectCategory (IgControlCategory *category)
00520 {
00521     if (category)
00522     {
00523       ASSERT (hasCategory (category));
00524       if (m_categories [category->name ()].second == true)
00525       {
00526         showCategory (category);
00527         return;
00528       }
00529     }
00530     back ();
00531 }
00532 
00533 void
00534 IgControlCentre::selectCategory (const QString& name)
00535 {
00536     updateControlCentre (name);
00537 }
00538 
00539 void
00540 IgControlCentre::enableCategory (QString name, IconViewArch *toplevel, bool state /*= true */)
00541 {
00542     int index = name.find ("/");
00543     if (index != -1)
00544     {
00545       QString sname = name.left(index);
00546       name = name.right (name.length() - index - 1);
00547       enableCategory (name, static_cast<IconViewArch *>((*toplevel)[sname].first), state);
00548       name = sname;
00549     }
00550     m_focusChanged = true;
00551     
00552     if ((*toplevel)[name].first == 0 || state)
00553       (*toplevel)[name].second = state;
00554     else
00555     {
00556       ASSERT (toplevel->size ());
00557       IconViewArch::iterator itr;
00558   
00559       IconViewArch *tmpmap = static_cast<IconViewArch *>((*toplevel)[name].first);
00560       for(itr = tmpmap->begin (); itr != tmpmap->end (); itr++)
00561       {
00562         if (itr->second.second == true)
00563         {
00564           (*toplevel)[name].second = true;
00565           return;
00566         }
00567       }
00568       (*toplevel)[name].second = false;
00569     }
00570 }
00571 
00572 void
00573 IgControlCentre::enableCategory (IgControlCategory *category, bool state /*= true */)
00574 {
00575     ASSERT (m_categories.size ());
00576     ASSERT (category && hasCategory (category));
00577     ASSERT (m_categories.find (category->name ()) != m_categories.end ());
00578     m_categories[category->name ()].second = state;
00579     enableCategory (category->name (), &m_iconViewArch, state);
00580 }
00581 
00582 void
00583 IgControlCentre::selectIconItem (QIconViewItem* item)
00584 {
00585     ASSERT (item);
00586     if (m_baseName == "")
00587       updateControlCentre (item->text ());
00588     else
00589       updateControlCentre (m_baseName + "/" + item->text ());
00590 }
00591 
00592 
00596 
00598 void
00599 IgControlCentre::dirtyCategory (void)
00600 {
00601     m_apply->setEnabled (true);
00602     m_revert->setEnabled (true);
00603 }
00604 
00607 void
00608 IgControlCentre::cleanCategory (void)
00609 {
00610     m_apply->setEnabled (false);
00611     m_revert->setEnabled (false);
00612 }
00613 
00614 QIconView *
00615 IgControlCentre::iconView (void)
00616 {
00617     return m_iconView;    
00618 }
00622 void
00623 IgControlCentre::windowActivationChange  (bool oldActive)
00624 {  
00625     QDialog::windowActivationChange (oldActive);
00626     if (isActiveWindow() && m_updateOnWindowActive)
00627     {
00628       if(m_current && m_categories [m_current->name ()].second == true)
00629       {
00630         m_current->focusIn ();
00631       }
00632       else if (m_focusChanged)
00633       {
00634         m_focusChanged = false;
00635         QString old (m_baseName);
00636         m_baseName = "qqqqqq";
00637         updateControlCentre (old);
00638       }
00639       else if(m_current)
00640       {
00641         m_current->focusIn ();
00642       }
00643       m_updateOnWindowActive = false;
00644     }
00645     else if (!isActiveWindow())
00646     {
00647       m_updateOnWindowActive = false;
00648       if ( m_current && m_categories [m_current->name ()].second == true)
00649         m_current->focusOut ();
00650     }
00651     else
00652       m_updateOnWindowActive = false;
00653 }
00654 
00655 void
00656 IgControlCentre::updateOnWindowActive (void)
00657 { m_updateOnWindowActive = true; }

Generated on Tue Jun 9 17:38:38 2009 for CMSSW by  doxygen 1.5.4