CMS 3D CMS Logo

IgQtAppToolBarService.cc

Go to the documentation of this file.
00001 //<<<<<< INCLUDES                                                       >>>>>>
00002 
00003 #include "Iguana/Studio/interface/IgQtAppToolBarService.h"
00004 #include "Iguana/Studio/interface/IgQtAppContextService.h"
00005 #include "Iguana/Studio/interface/IgQtCallbacks.h"
00006 #include "Iguana/Framework/interface/IgState.h"
00007 #include <classlib/utils/DebugAids.h>
00008 #include <qtoolbutton.h>
00009 #include <qmainwindow.h>
00010 #include <qtoolbar.h>
00011 #include <qiconset.h>
00012 #include <qtooltip.h>
00013 
00014 //<<<<<< PRIVATE DEFINES                                                >>>>>>
00015 //<<<<<< PRIVATE CONSTANTS                                              >>>>>>
00016 //<<<<<< PRIVATE TYPES                                                  >>>>>>
00017 //<<<<<< PRIVATE VARIABLE DEFINITIONS                                   >>>>>>
00018 //<<<<<< PUBLIC VARIABLE DEFINITIONS                                    >>>>>>
00019 //<<<<<< CLASS STRUCTURE INITIALIZATION                                 >>>>>>
00020 
00021 IG_DEFINE_STATE_ELEMENT (IgQtAppToolBarService, "Services/Qt/Tool Bar");
00022 
00023 //<<<<<< PRIVATE FUNCTION DEFINITIONS                                   >>>>>>
00024 //<<<<<< PUBLIC FUNCTION DEFINITIONS                                    >>>>>>
00025 //<<<<<< MEMBER FUNCTION DEFINITIONS                                    >>>>>>
00026 
00027 IgQtAppToolBarService::IgQtAppToolBarService (IgState *state,
00028                                               QWidget *mainWindow)
00029     : m_state (state),
00030       m_mainWindow (mainWindow)
00031 {
00032     ASSERT (state);
00033     ASSERT (mainWindow);
00034     state->put (s_key, this);
00035 }
00036 
00037 IgQtAppToolBarService::~IgQtAppToolBarService (void)
00038 {
00039     ASSERT (m_state);
00040     ASSERT (m_mainWindow);
00041     m_state->detach (s_key);
00042 }
00043 
00044 QToolBar *
00045 IgQtAppToolBarService::toolBar (const int id,
00046                                 const std::string &label)
00047 {
00048     if (m_toolBarMap[id] == 0)
00049     {
00050         QToolBar *bar = new QToolBar (static_cast<QMainWindow *>(m_mainWindow),
00051                                       label.c_str ());
00052         bar->setCaption (label.c_str ());
00053         m_toolBarMap[id] = bar; 
00054     }
00055     return m_toolBarMap[id];    
00056 }
00057 
00058 
00059 
00060 QToolButton *
00061 IgQtAppToolBarService::toolBarButton (IgState *state,
00062                                       const int barId,
00063                                       const int buttonId,
00064                                       const QIconSet &iconSet,
00065                                       const std::string &name,
00066                                       QObject *target,
00067                                       const char *slot,
00068                                       const char *signal)
00069 {
00070     std::string realSignal (signal);
00071     std::string realSlot (slot);
00072     
00073     if (realSignal == "")
00074       realSignal  = SIGNAL (clicked ());
00075 
00076     // FIXME: toolbar must already exists otherwise the name is set to
00077     // ""    
00078     QToolBar *toolBar = this->toolBar (barId, std::string (""));
00079 
00080     // FIXME: Ugly way of having unique ids...  
00081     QToolButton *button = 0;
00082     if (m_toolButtonMap[barId * 10000 + buttonId] == 0)
00083     {
00084         button = new QToolButton (toolBar);
00085         button->setIconSet (iconSet);
00086         
00087         m_toolButtonMap[barId * 10000 + buttonId] = button;
00088         QToolTip::add (button, name.c_str ());
00089     }
00090     else
00091       button = m_toolButtonMap[barId * 10000 + buttonId];
00092     
00093     IgQtAppContextService *service = IgQtAppContextService::get (state);
00094     if (realSlot != "")
00095     {
00096         service->add (qtConnectionCallback, 
00097                       createQtConnection (button, 
00098                                           realSignal.c_str (), 
00099                                           target,
00100                                           slot));
00101         service->add (qtShowHideCallback, button); 
00102     }
00103     else
00104       service->add (qtShowHideCallback, button, false); 
00105 
00106     return button;
00107 }
00108 
00109 QToolButton *
00110 IgQtAppToolBarService::getToolBarButton (const int barId,
00111                                          const int buttonId)
00112 {
00113     if (m_toolButtonMap.find(barId * 10000 + buttonId) !=
00114         m_toolButtonMap.end ())
00115       return m_toolButtonMap [barId * 10000 + buttonId];
00116     else
00117       return 0;
00118 }

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