/[svn]/qsampler/trunk/src/qsamplerInstrumentListForm.cpp
ViewVC logotype

Diff of /qsampler/trunk/src/qsamplerInstrumentListForm.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2065 by capela, Sat Mar 13 12:44:15 2010 UTC revision 2070 by capela, Mon Mar 15 17:06:46 2010 UTC
# Line 33  Line 33 
33    
34  #include <QHeaderView>  #include <QHeaderView>
35  #include <QMessageBox>  #include <QMessageBox>
36    #include <QContextMenuEvent>
37    
38    
39  namespace QSampler {  namespace QSampler {
# Line 47  InstrumentListForm::InstrumentListForm ( Line 48  InstrumentListForm::InstrumentListForm (
48  {  {
49          m_ui.setupUi(this);          m_ui.setupUi(this);
50    
51            m_pInstrumentListView = new InstrumentListView(this);
52            QMainWindow::setCentralWidget(m_pInstrumentListView);
53    
54          // Setup toolbar widgets.          // Setup toolbar widgets.
55          m_pMapComboBox = new QComboBox(m_ui.instrumentToolbar);          m_pMapComboBox = new QComboBox(m_ui.instrumentToolbar);
56          m_pMapComboBox->setMinimumWidth(120);          m_pMapComboBox->setMinimumWidth(120);
57          m_pMapComboBox->setEnabled(false);          m_pMapComboBox->setEnabled(false);
58          m_pMapComboBox->setToolTip(tr("Instrument Map"));          m_pMapComboBox->setToolTip(tr("Instrument Map"));
59            
60          m_ui.instrumentToolbar->addWidget(m_pMapComboBox);          m_ui.instrumentToolbar->addWidget(m_pMapComboBox);
   
61          m_ui.instrumentToolbar->addSeparator();          m_ui.instrumentToolbar->addSeparator();
62          m_ui.instrumentToolbar->addAction(m_ui.newInstrumentAction);          m_ui.instrumentToolbar->addAction(m_ui.newInstrumentAction);
63          m_ui.instrumentToolbar->addAction(m_ui.editInstrumentAction);          m_ui.instrumentToolbar->addAction(m_ui.editInstrumentAction);
# Line 61  InstrumentListForm::InstrumentListForm ( Line 65  InstrumentListForm::InstrumentListForm (
65          m_ui.instrumentToolbar->addSeparator();          m_ui.instrumentToolbar->addSeparator();
66          m_ui.instrumentToolbar->addAction(m_ui.refreshInstrumentsAction);          m_ui.instrumentToolbar->addAction(m_ui.refreshInstrumentsAction);
67    
         m_pInstrumentListView = new InstrumentListView(this);  
         m_pInstrumentListView->setContextMenuPolicy(Qt::CustomContextMenu);  
         QMainWindow::setCentralWidget(m_pInstrumentListView);  
   
68          QObject::connect(m_pMapComboBox,          QObject::connect(m_pMapComboBox,
69                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
70                  SLOT(activateMap(int)));                  SLOT(activateMap(int)));
71          QObject::connect(          QObject::connect(m_pInstrumentListView->selectionModel(),
72                  m_pInstrumentListView,                  SIGNAL(currentRowChanged(const QModelIndex&,const QModelIndex&)),
                 SIGNAL(customContextMenuRequested(const QPoint&)),  
                 SLOT(contextMenu(const QPoint&)));  
         QObject::connect(  
                 m_pInstrumentListView,  
                 SIGNAL(activated(const QModelIndex&)),  
73                  SLOT(stabilizeForm()));                  SLOT(stabilizeForm()));
74          QObject::connect(          QObject::connect(
75                  m_pInstrumentListView,                  m_pInstrumentListView,
76                  SIGNAL(doubleClicked(const QModelIndex&)),                  SIGNAL(activated(const QModelIndex&)),
77                  SLOT(editInstrument(const QModelIndex&)));                  SLOT(editInstrument(const QModelIndex&)));
78          QObject::connect(          QObject::connect(
79                  m_ui.newInstrumentAction,                  m_ui.newInstrumentAction,
# Line 104  InstrumentListForm::InstrumentListForm ( Line 99  InstrumentListForm::InstrumentListForm (
99    
100  InstrumentListForm::~InstrumentListForm (void)  InstrumentListForm::~InstrumentListForm (void)
101  {  {
         delete m_pInstrumentListView;  
102          delete m_pMapComboBox;          delete m_pMapComboBox;
103            delete m_pInstrumentListView;
104  }  }
105    
106    
# Line 195  void InstrumentListForm::activateMap ( i Line 190  void InstrumentListForm::activateMap ( i
190  }  }
191    
192    
193    void InstrumentListForm::newInstrument (void)
194    {
195            Instrument instrument;
196    
197            InstrumentForm form(this);
198            form.setup(&instrument);
199            if (!form.exec())
200                    return;
201    
202            // Commit...
203            instrument.mapInstrument();
204    
205            // add new item to the table model
206            m_pInstrumentListView->addInstrument(
207                    instrument.map(),
208                    instrument.bank(),
209                    instrument.prog());
210    
211            stabilizeForm();
212    }
213    
214    
215  void InstrumentListForm::editInstrument (void)  void InstrumentListForm::editInstrument (void)
216  {  {
217          editInstrument(m_pInstrumentListView->currentIndex());          editInstrument(m_pInstrumentListView->currentIndex());
# Line 221  void InstrumentListForm::editInstrument Line 238  void InstrumentListForm::editInstrument
238          // Do the edit dance...          // Do the edit dance...
239          InstrumentForm form(this);          InstrumentForm form(this);
240          form.setup(&instrument);          form.setup(&instrument);
         if (form.exec()) {  
                 // Commit...  
                 instrument.mapInstrument();  
                 // Check whether we changed instrument key...  
                 if (instrument.map()  == iMap  &&  
                         instrument.bank() == iBank &&  
                         instrument.prog() == iProg) {  
                         // Just update tree item...  
                         //pItem->update();  
                 } else {  
                         // Unmap old instance...  
                         Instrument(iMap, iBank, iProg).unmapInstrument();  
                         // correct the position of the instrument in the model  
                         m_pInstrumentListView->updateInstrument(pInstrument);  
                 }  
         }  
   
         stabilizeForm();  
 }  
   
   
 void InstrumentListForm::newInstrument (void)  
 {  
         Instrument instrument;  
   
         InstrumentForm form(this);  
         form.setup(&instrument);  
241          if (!form.exec())          if (!form.exec())
242                  return;                  return;
243            
244          // Commit...          // Commit...
245          instrument.mapInstrument();          instrument.mapInstrument();
246    
247          // add new item to the table model          // Check whether we changed instrument key...
248          m_pInstrumentListView->addInstrument(          if (instrument.map()  == iMap  &&
249                  instrument.map(),                  instrument.bank() == iBank &&
250                  instrument.bank(),                  instrument.prog() == iProg) {
251                  instrument.prog());                  // Just update tree item...
252                    m_pInstrumentListView->updateInstrument(pInstrument);
253            } else {
254                    // Unmap old instance...
255                    Instrument(iMap, iBank, iProg).unmapInstrument();
256                    // Correct the position of the instrument in the model
257                    m_pInstrumentListView->resortInstrument(pInstrument);
258            }
259    
260          stabilizeForm();          stabilizeForm();
261  }  }
# Line 316  void InstrumentListForm::stabilizeForm ( Line 313  void InstrumentListForm::stabilizeForm (
313  }  }
314    
315    
316  // Handle custom context menu here...  // Context menu request.
317  void InstrumentListForm::contextMenu ( const QPoint& pos )  void InstrumentListForm::contextMenuEvent (
318  {          QContextMenuEvent *pContextMenuEvent )
319          if (!m_ui.newInstrumentAction->isEnabled())  {
320                  return;          QMenu menu(this);
321    
322            menu.addAction(m_ui.newInstrumentAction);
323            menu.addSeparator();
324            menu.addAction(m_ui.editInstrumentAction);
325            menu.addAction(m_ui.deleteInstrumentAction);
326            menu.addSeparator();
327            menu.addAction(m_ui.refreshInstrumentsAction);
328    
329          m_ui.contextMenu->exec(          menu.exec(pContextMenuEvent->globalPos());
                 (m_pInstrumentListView->viewport())->mapToGlobal(pos));  
330  }  }
331    
332    

Legend:
Removed from v.2065  
changed lines
  Added in v.2070

  ViewVC Help
Powered by ViewVC