/[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 2064 by capela, Fri Mar 12 16:02:32 2010 UTC revision 2068 by capela, Sun Mar 14 16:35:48 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          m_ui.InstrumentToolbar->addWidget(m_pMapComboBox);          
60            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);
64          m_ui.InstrumentToolbar->addAction(m_ui.deleteInstrumentAction);          m_ui.instrumentToolbar->addAction(m_ui.deleteInstrumentAction);
65          m_ui.InstrumentToolbar->addSeparator();          m_ui.instrumentToolbar->addSeparator();
66          m_ui.InstrumentToolbar->addAction(m_ui.refreshInstrumentsAction);          m_ui.instrumentToolbar->addAction(m_ui.refreshInstrumentsAction);
   
         m_pInstrumentListView = new InstrumentListView(this);  
   
         QHeaderView *pHeader = m_pInstrumentListView->header();  
         pHeader->setDefaultAlignment(Qt::AlignLeft);  
         pHeader->setMovable(false);  
         pHeader->setStretchLastSection(true);  
         pHeader->resizeSection(0, 120);                                         // Name  
         m_pInstrumentListView->resizeColumnToContents(1);       // Map  
         m_pInstrumentListView->resizeColumnToContents(2);       // Bank  
         m_pInstrumentListView->resizeColumnToContents(3);       // Prog  
         m_pInstrumentListView->resizeColumnToContents(4);       // Engine  
         pHeader->resizeSection(5, 240);                                         // File  
         m_pInstrumentListView->resizeColumnToContents(6);       // Nr  
         pHeader->resizeSection(7, 60);                                          // Vol  
   
         // Enable custom context menu...  
         m_pInstrumentListView->setContextMenuPolicy(Qt::CustomContextMenu);  
   
         QMainWindow::setCentralWidget(m_pInstrumentListView);  
67    
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(pressed(const QModelIndex&)),  
73                  SLOT(stabilizeForm()));                  SLOT(stabilizeForm()));
74          QObject::connect(          QObject::connect(
75                  m_pInstrumentListView,                  m_pInstrumentListView,
# Line 120  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 211  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 227  void InstrumentListForm::editInstrument Line 228  void InstrumentListForm::editInstrument
228          if (pInstrument == NULL)          if (pInstrument == NULL)
229                  return;                  return;
230    
         if (pInstrument == NULL)  
                 return;  
   
231          // Save current key values...          // Save current key values...
232          Instrument oldInstrument(          int iMap  = pInstrument->map();
233                  pInstrument->map(),          int iBank = pInstrument->bank();
234                  pInstrument->bank(),          int iProg = pInstrument->prog();
                 pInstrument->prog());  
   
         // Do the edit dance...  
         InstrumentForm form(this);  
         form.setup(pInstrument);  
         if (form.exec()) {  
                 // Commit...  
                 pInstrument->mapInstrument();  
                 // Check whether we changed instrument key...  
                 if (oldInstrument.map()  == pInstrument->map()  &&  
                         oldInstrument.bank() == pInstrument->bank() &&  
                         oldInstrument.prog() == pInstrument->prog()) {  
                         // Just update tree item...  
                         //pItem->update();  
                 } else {  
                         // Unmap old instance...  
                         oldInstrument.unmapInstrument();  
                         // correct the position of the instrument in the model  
                         m_pInstrumentListView->updateInstrument(pInstrument);  
                 }  
         }  
 }  
235    
236            Instrument instrument(iMap, iBank, iProg);
237    
238  void InstrumentListForm::newInstrument (void)          // Do the edit dance...
 {  
         Instrument instrument;  
   
239          InstrumentForm form(this);          InstrumentForm form(this);
240          form.setup(&instrument);          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                    //pItem->update();
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->updateInstrument(pInstrument);
258            }
259    
260            stabilizeForm();
261  }  }
262    
263    
# Line 311  void InstrumentListForm::deleteInstrumen Line 294  void InstrumentListForm::deleteInstrumen
294    
295          // let the instrument vanish from the table model          // let the instrument vanish from the table model
296          m_pInstrumentListView->removeInstrument(pInstrument);          m_pInstrumentListView->removeInstrument(pInstrument);
297    
298            stabilizeForm();
299  }  }
300    
301    
# Line 328  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.2064  
changed lines
  Added in v.2068

  ViewVC Help
Powered by ViewVC