/[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 1840 by capela, Thu Feb 19 11:44:57 2009 UTC revision 2066 by capela, Sat Mar 13 19:15:24 2010 UTC
# Line 1  Line 1 
1  // qsamplerInstrumentListForm.cpp  // qsamplerInstrumentListForm.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2003-2009, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2003-2010, rncbc aka Rui Nuno Capela. All rights reserved.
5     Copyright (C) 2007, Christian Schoenebeck     Copyright (C) 2007, Christian Schoenebeck
6    
7     This program is free software; you can redistribute it and/or     This program is free software; you can redistribute it and/or
# Line 23  Line 23 
23  #include "qsamplerAbout.h"  #include "qsamplerAbout.h"
24  #include "qsamplerInstrumentListForm.h"  #include "qsamplerInstrumentListForm.h"
25    
26    #include "qsamplerInstrumentList.h"
27    
28  #include "qsamplerInstrumentForm.h"  #include "qsamplerInstrumentForm.h"
29    
30  #include "qsamplerOptions.h"  #include "qsamplerOptions.h"
# Line 31  Line 33 
33    
34  #include <QHeaderView>  #include <QHeaderView>
35  #include <QMessageBox>  #include <QMessageBox>
36    #include <QContextMenuEvent>
37    
38    
39  namespace QSampler {  namespace QSampler {
# Line 45  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);
   
         int iRowHeight = m_ui.InstrumentTable->fontMetrics().height() + 4;  
         m_ui.InstrumentTable->verticalHeader()->setDefaultSectionSize(iRowHeight);  
   
         m_ui.InstrumentTable->setModel(&m_model);  
         m_ui.InstrumentTable->setItemDelegate(&m_delegate);  
         m_ui.InstrumentTable->verticalHeader()->hide();  
   
         QHeaderView *pHeader = m_ui.InstrumentTable->horizontalHeader();  
         pHeader->setDefaultAlignment(Qt::AlignLeft);  
         pHeader->setMovable(false);  
         pHeader->setStretchLastSection(true);  
         pHeader->resizeSection(0, 120);                                         // Name  
         m_ui.InstrumentTable->resizeColumnToContents(1);        // Map  
         m_ui.InstrumentTable->resizeColumnToContents(2);        // Bank  
         m_ui.InstrumentTable->resizeColumnToContents(3);        // Prog  
         m_ui.InstrumentTable->resizeColumnToContents(4);        // Engine  
         pHeader->resizeSection(5, 240);                                         // File  
         m_ui.InstrumentTable->resizeColumnToContents(6);        // Nr  
         pHeader->resizeSection(7, 60);                                          // Vol  
   
         // Enable custom context menu...  
         m_ui.InstrumentTable->setContextMenuPolicy(Qt::CustomContextMenu);  
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_ui.InstrumentTable,                  SIGNAL(currentRowChanged(const QModelIndex&,const QModelIndex&)),
                 SIGNAL(customContextMenuRequested(const QPoint&)),  
                 SLOT(contextMenu(const QPoint&)));  
         QObject::connect(  
                 m_ui.InstrumentTable,  
                 SIGNAL(pressed(const QModelIndex&)),  
73                  SLOT(stabilizeForm()));                  SLOT(stabilizeForm()));
74          QObject::connect(          QObject::connect(
75                  m_ui.InstrumentTable,                  m_pInstrumentListView,
76                  SIGNAL(activated(const QModelIndex&)),                  SIGNAL(doubleClicked(const QModelIndex&)),
77                  SLOT(editInstrument(const QModelIndex&)));                  SLOT(editInstrument(const QModelIndex&)));
78          QObject::connect(          QObject::connect(
79                  m_ui.newInstrumentAction,                  m_ui.newInstrumentAction,
# Line 114  InstrumentListForm::InstrumentListForm ( Line 92  InstrumentListForm::InstrumentListForm (
92                  SIGNAL(triggered()),                  SIGNAL(triggered()),
93                  SLOT(refreshInstruments()));                  SLOT(refreshInstruments()));
94    
         MainForm *pMainForm = MainForm::getInstance();  
         if (pMainForm) {  
                 QObject::connect(&m_model,  
                         SIGNAL(instrumentsChanged()),  
                         pMainForm, SLOT(sessionDirty()));  
         }  
   
95          // Things must be stable from the start.          // Things must be stable from the start.
96          stabilizeForm();          stabilizeForm();
97  }  }
# Line 129  InstrumentListForm::InstrumentListForm ( Line 100  InstrumentListForm::InstrumentListForm (
100  InstrumentListForm::~InstrumentListForm (void)  InstrumentListForm::~InstrumentListForm (void)
101  {  {
102          delete m_pMapComboBox;          delete m_pMapComboBox;
103            delete m_pInstrumentListView;
104  }  }
105    
106    
# Line 211  void InstrumentListForm::activateMap ( i Line 183  void InstrumentListForm::activateMap ( i
183          if (iMidiMap >= 0)          if (iMidiMap >= 0)
184                  pOptions->iMidiMap = iMidiMap;                  pOptions->iMidiMap = iMidiMap;
185    
186          m_model.setMidiMap(iMidiMap);          m_pInstrumentListView->setMidiMap(iMidiMap);
187          m_model.refresh();          m_pInstrumentListView->refresh();
188    
189          stabilizeForm();          stabilizeForm();
190  }  }
# Line 220  void InstrumentListForm::activateMap ( i Line 192  void InstrumentListForm::activateMap ( i
192    
193  void InstrumentListForm::editInstrument (void)  void InstrumentListForm::editInstrument (void)
194  {  {
195          editInstrument(m_ui.InstrumentTable->currentIndex());          editInstrument(m_pInstrumentListView->currentIndex());
196  }  }
197    
198    
199  void InstrumentListForm::editInstrument ( const QModelIndex& index )  void InstrumentListForm::editInstrument ( const QModelIndex& index )
200  {  {
201          if (!index.isValid() || !index.data(Qt::UserRole).isValid())          if (!index.isValid())
202                  return;                  return;
203    
204          Instrument* pInstrument          Instrument *pInstrument
205                  = static_cast<Instrument *> (                  = static_cast<Instrument *> (index.internalPointer());
                         index.data(Qt::UserRole).value<void *> ());  
   
206          if (pInstrument == NULL)          if (pInstrument == NULL)
207                  return;                  return;
208    
209          // Save current key values...          // Save current key values...
210          Instrument oldInstrument(*pInstrument);          int iMap  = pInstrument->map();
211            int iBank = pInstrument->bank();
212            int iProg = pInstrument->prog();
213    
214            Instrument instrument(iMap, iBank, iProg);
215    
216          // Do the edit dance...          // Do the edit dance...
217          InstrumentForm form(this);          InstrumentForm form(this);
218          form.setup(pInstrument);          form.setup(&instrument);
219          if (form.exec()) {          if (form.exec()) {
220                  // Commit...                  // Commit...
221                  pInstrument->mapInstrument();                  instrument.mapInstrument();
222                  // Check whether we changed instrument key...                  // Check whether we changed instrument key...
223                  if (oldInstrument.map()  == pInstrument->map()  &&                  if (instrument.map()  == iMap  &&
224                          oldInstrument.bank() == pInstrument->bank() &&                          instrument.bank() == iBank &&
225                          oldInstrument.prog() == pInstrument->prog()) {                          instrument.prog() == iProg) {
226                          // Just update tree item...                          // Just update tree item...
227                          //pItem->update();                          //pItem->update();
228                  } else {                  } else {
229                          // Unmap old instance...                          // Unmap old instance...
230                          oldInstrument.unmapInstrument();                          Instrument(iMap, iBank, iProg).unmapInstrument();
231                          // correct the position of the instrument in the model                          // correct the position of the instrument in the model
232                          m_model.resort(*pInstrument);                          m_pInstrumentListView->updateInstrument(pInstrument);
233                  }                  }
                 // Notify we've changes...  
                 emit m_model.reset();  
234          }          }
235    
236            stabilizeForm();
237  }  }
238    
239    
# Line 273  void InstrumentListForm::newInstrument ( Line 248  void InstrumentListForm::newInstrument (
248    
249          // Commit...          // Commit...
250          instrument.mapInstrument();          instrument.mapInstrument();
251    
252          // add new item to the table model          // add new item to the table model
253          m_model.resort(instrument);          m_pInstrumentListView->addInstrument(
254          // Notify we've changes...                  instrument.map(),
255          //emit model.reset();                  instrument.bank(),
256          //FIXME: call above didnt really refresh, so we use this for now ...                  instrument.prog());
257          refreshInstruments();  
258            stabilizeForm();
259  }  }
260    
261    
262  void InstrumentListForm::deleteInstrument (void)  void InstrumentListForm::deleteInstrument (void)
263  {  {
264          const QModelIndex& index = m_ui.InstrumentTable->currentIndex();          const QModelIndex& index = m_pInstrumentListView->currentIndex();
265          if (!index.isValid() || !index.data(Qt::UserRole).isValid())          if (!index.isValid())
266                  return;                  return;
267    
268          Instrument *pInstrument =          Instrument *pInstrument
269                  static_cast<Instrument*> (                  = static_cast<Instrument *> (index.internalPointer());
                         index.data(Qt::UserRole).value<void *> ());  
   
270          if (pInstrument == NULL)          if (pInstrument == NULL)
271                  return;                  return;
272    
# Line 314  void InstrumentListForm::deleteInstrumen Line 289  void InstrumentListForm::deleteInstrumen
289          }          }
290    
291          pInstrument->unmapInstrument();          pInstrument->unmapInstrument();
292    
293          // let the instrument vanish from the table model          // let the instrument vanish from the table model
294          m_model.removeInstrument(*pInstrument);          m_pInstrumentListView->removeInstrument(pInstrument);
295          // Notify we've changes...  
296          emit m_model.reset();          stabilizeForm();
297  }  }
298    
299    
# Line 328  void InstrumentListForm::stabilizeForm ( Line 304  void InstrumentListForm::stabilizeForm (
304    
305          bool bEnabled = (pMainForm && pMainForm->client());          bool bEnabled = (pMainForm && pMainForm->client());
306          m_ui.newInstrumentAction->setEnabled(bEnabled);          m_ui.newInstrumentAction->setEnabled(bEnabled);
307          const QModelIndex& index = m_ui.InstrumentTable->currentIndex();          const QModelIndex& index = m_pInstrumentListView->currentIndex();
308          bEnabled = (bEnabled && index.isValid());          bEnabled = (bEnabled && index.isValid());
309          m_ui.editInstrumentAction->setEnabled(bEnabled);          m_ui.editInstrumentAction->setEnabled(bEnabled);
310          m_ui.deleteInstrumentAction->setEnabled(bEnabled);          m_ui.deleteInstrumentAction->setEnabled(bEnabled);
311  }  }
312    
313    
314  // Handle custom context menu here...  // Context menu request.
315  void InstrumentListForm::contextMenu ( const QPoint& pos )  void InstrumentListForm::contextMenuEvent (
316            QContextMenuEvent *pContextMenuEvent )
317  {  {
318          if (!m_ui.newInstrumentAction->isEnabled())          if (m_ui.newInstrumentAction->isEnabled())
319                  return;                  m_ui.contextMenu->exec(pContextMenuEvent->globalPos());
   
         m_ui.contextMenu->exec(  
                 (m_ui.InstrumentTable->viewport())->mapToGlobal(pos));  
320  }  }
321    
322    

Legend:
Removed from v.1840  
changed lines
  Added in v.2066

  ViewVC Help
Powered by ViewVC