/[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 2065 by capela, Sat Mar 13 12:44:15 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 46  InstrumentListForm::InstrumentListForm ( Line 48  InstrumentListForm::InstrumentListForm (
48          m_ui.setupUi(this);          m_ui.setupUi(this);
49    
50          // Setup toolbar widgets.          // Setup toolbar widgets.
51          m_pMapComboBox = new QComboBox(m_ui.InstrumentToolbar);          m_pMapComboBox = new QComboBox(m_ui.instrumentToolbar);
52          m_pMapComboBox->setMinimumWidth(120);          m_pMapComboBox->setMinimumWidth(120);
53          m_pMapComboBox->setEnabled(false);          m_pMapComboBox->setEnabled(false);
54          m_pMapComboBox->setToolTip(tr("Instrument Map"));          m_pMapComboBox->setToolTip(tr("Instrument Map"));
55          m_ui.InstrumentToolbar->addWidget(m_pMapComboBox);          m_ui.instrumentToolbar->addWidget(m_pMapComboBox);
   
         m_ui.InstrumentToolbar->addSeparator();  
         m_ui.InstrumentToolbar->addAction(m_ui.newInstrumentAction);  
         m_ui.InstrumentToolbar->addAction(m_ui.editInstrumentAction);  
         m_ui.InstrumentToolbar->addAction(m_ui.deleteInstrumentAction);  
         m_ui.InstrumentToolbar->addSeparator();  
         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  
56    
57          // Enable custom context menu...          m_ui.instrumentToolbar->addSeparator();
58          m_ui.InstrumentTable->setContextMenuPolicy(Qt::CustomContextMenu);          m_ui.instrumentToolbar->addAction(m_ui.newInstrumentAction);
59            m_ui.instrumentToolbar->addAction(m_ui.editInstrumentAction);
60            m_ui.instrumentToolbar->addAction(m_ui.deleteInstrumentAction);
61            m_ui.instrumentToolbar->addSeparator();
62            m_ui.instrumentToolbar->addAction(m_ui.refreshInstrumentsAction);
63    
64            m_pInstrumentListView = new InstrumentListView(this);
65            m_pInstrumentListView->setContextMenuPolicy(Qt::CustomContextMenu);
66            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(
72                  m_ui.InstrumentTable,                  m_pInstrumentListView,
73                  SIGNAL(customContextMenuRequested(const QPoint&)),                  SIGNAL(customContextMenuRequested(const QPoint&)),
74                  SLOT(contextMenu(const QPoint&)));                  SLOT(contextMenu(const QPoint&)));
75          QObject::connect(          QObject::connect(
76                  m_ui.InstrumentTable,                  m_pInstrumentListView,
77                  SIGNAL(pressed(const QModelIndex&)),                  SIGNAL(activated(const QModelIndex&)),
78                  SLOT(stabilizeForm()));                  SLOT(stabilizeForm()));
79          QObject::connect(          QObject::connect(
80                  m_ui.InstrumentTable,                  m_pInstrumentListView,
81                  SIGNAL(activated(const QModelIndex&)),                  SIGNAL(doubleClicked(const QModelIndex&)),
82                  SLOT(editInstrument(const QModelIndex&)));                  SLOT(editInstrument(const QModelIndex&)));
83          QObject::connect(          QObject::connect(
84                  m_ui.newInstrumentAction,                  m_ui.newInstrumentAction,
# Line 114  InstrumentListForm::InstrumentListForm ( Line 97  InstrumentListForm::InstrumentListForm (
97                  SIGNAL(triggered()),                  SIGNAL(triggered()),
98                  SLOT(refreshInstruments()));                  SLOT(refreshInstruments()));
99    
         MainForm *pMainForm = MainForm::getInstance();  
         if (pMainForm) {  
                 QObject::connect(&m_model,  
                         SIGNAL(instrumentsChanged()),  
                         pMainForm, SLOT(sessionDirty()));  
         }  
   
100          // Things must be stable from the start.          // Things must be stable from the start.
101          stabilizeForm();          stabilizeForm();
102  }  }
# Line 128  InstrumentListForm::InstrumentListForm ( Line 104  InstrumentListForm::InstrumentListForm (
104    
105  InstrumentListForm::~InstrumentListForm (void)  InstrumentListForm::~InstrumentListForm (void)
106  {  {
107            delete m_pInstrumentListView;
108          delete m_pMapComboBox;          delete m_pMapComboBox;
109  }  }
110    
# Line 211  void InstrumentListForm::activateMap ( i Line 188  void InstrumentListForm::activateMap ( i
188          if (iMidiMap >= 0)          if (iMidiMap >= 0)
189                  pOptions->iMidiMap = iMidiMap;                  pOptions->iMidiMap = iMidiMap;
190    
191          m_model.setMidiMap(iMidiMap);          m_pInstrumentListView->setMidiMap(iMidiMap);
192          m_model.refresh();          m_pInstrumentListView->refresh();
193    
194          stabilizeForm();          stabilizeForm();
195  }  }
# Line 220  void InstrumentListForm::activateMap ( i Line 197  void InstrumentListForm::activateMap ( i
197    
198  void InstrumentListForm::editInstrument (void)  void InstrumentListForm::editInstrument (void)
199  {  {
200          editInstrument(m_ui.InstrumentTable->currentIndex());          editInstrument(m_pInstrumentListView->currentIndex());
201  }  }
202    
203    
204  void InstrumentListForm::editInstrument ( const QModelIndex& index )  void InstrumentListForm::editInstrument ( const QModelIndex& index )
205  {  {
206          if (!index.isValid() || !index.data(Qt::UserRole).isValid())          if (!index.isValid())
207                  return;                  return;
208    
209          Instrument* pInstrument          Instrument *pInstrument
210                  = static_cast<Instrument *> (                  = static_cast<Instrument *> (index.internalPointer());
                         index.data(Qt::UserRole).value<void *> ());  
   
211          if (pInstrument == NULL)          if (pInstrument == NULL)
212                  return;                  return;
213    
214          // Save current key values...          // Save current key values...
215          Instrument oldInstrument(*pInstrument);          int iMap  = pInstrument->map();
216            int iBank = pInstrument->bank();
217            int iProg = pInstrument->prog();
218    
219            Instrument instrument(iMap, iBank, iProg);
220    
221          // Do the edit dance...          // Do the edit dance...
222          InstrumentForm form(this);          InstrumentForm form(this);
223          form.setup(pInstrument);          form.setup(&instrument);
224          if (form.exec()) {          if (form.exec()) {
225                  // Commit...                  // Commit...
226                  pInstrument->mapInstrument();                  instrument.mapInstrument();
227                  // Check whether we changed instrument key...                  // Check whether we changed instrument key...
228                  if (oldInstrument.map()  == pInstrument->map()  &&                  if (instrument.map()  == iMap  &&
229                          oldInstrument.bank() == pInstrument->bank() &&                          instrument.bank() == iBank &&
230                          oldInstrument.prog() == pInstrument->prog()) {                          instrument.prog() == iProg) {
231                          // Just update tree item...                          // Just update tree item...
232                          //pItem->update();                          //pItem->update();
233                  } else {                  } else {
234                          // Unmap old instance...                          // Unmap old instance...
235                          oldInstrument.unmapInstrument();                          Instrument(iMap, iBank, iProg).unmapInstrument();
236                          // correct the position of the instrument in the model                          // correct the position of the instrument in the model
237                          m_model.resort(*pInstrument);                          m_pInstrumentListView->updateInstrument(pInstrument);
238                  }                  }
                 // Notify we've changes...  
                 emit m_model.reset();  
239          }          }
240    
241            stabilizeForm();
242  }  }
243    
244    
# Line 273  void InstrumentListForm::newInstrument ( Line 253  void InstrumentListForm::newInstrument (
253    
254          // Commit...          // Commit...
255          instrument.mapInstrument();          instrument.mapInstrument();
256    
257          // add new item to the table model          // add new item to the table model
258          m_model.resort(instrument);          m_pInstrumentListView->addInstrument(
259          // Notify we've changes...                  instrument.map(),
260          //emit model.reset();                  instrument.bank(),
261          //FIXME: call above didnt really refresh, so we use this for now ...                  instrument.prog());
262          refreshInstruments();  
263            stabilizeForm();
264  }  }
265    
266    
267  void InstrumentListForm::deleteInstrument (void)  void InstrumentListForm::deleteInstrument (void)
268  {  {
269          const QModelIndex& index = m_ui.InstrumentTable->currentIndex();          const QModelIndex& index = m_pInstrumentListView->currentIndex();
270          if (!index.isValid() || !index.data(Qt::UserRole).isValid())          if (!index.isValid())
271                  return;                  return;
272    
273          Instrument *pInstrument =          Instrument *pInstrument
274                  static_cast<Instrument*> (                  = static_cast<Instrument *> (index.internalPointer());
                         index.data(Qt::UserRole).value<void *> ());  
   
275          if (pInstrument == NULL)          if (pInstrument == NULL)
276                  return;                  return;
277    
# Line 314  void InstrumentListForm::deleteInstrumen Line 294  void InstrumentListForm::deleteInstrumen
294          }          }
295    
296          pInstrument->unmapInstrument();          pInstrument->unmapInstrument();
297    
298          // let the instrument vanish from the table model          // let the instrument vanish from the table model
299          m_model.removeInstrument(*pInstrument);          m_pInstrumentListView->removeInstrument(pInstrument);
300          // Notify we've changes...  
301          emit m_model.reset();          stabilizeForm();
302  }  }
303    
304    
# Line 328  void InstrumentListForm::stabilizeForm ( Line 309  void InstrumentListForm::stabilizeForm (
309    
310          bool bEnabled = (pMainForm && pMainForm->client());          bool bEnabled = (pMainForm && pMainForm->client());
311          m_ui.newInstrumentAction->setEnabled(bEnabled);          m_ui.newInstrumentAction->setEnabled(bEnabled);
312          const QModelIndex& index = m_ui.InstrumentTable->currentIndex();          const QModelIndex& index = m_pInstrumentListView->currentIndex();
313          bEnabled = (bEnabled && index.isValid());          bEnabled = (bEnabled && index.isValid());
314          m_ui.editInstrumentAction->setEnabled(bEnabled);          m_ui.editInstrumentAction->setEnabled(bEnabled);
315          m_ui.deleteInstrumentAction->setEnabled(bEnabled);          m_ui.deleteInstrumentAction->setEnabled(bEnabled);
# Line 342  void InstrumentListForm::contextMenu ( c Line 323  void InstrumentListForm::contextMenu ( c
323                  return;                  return;
324    
325          m_ui.contextMenu->exec(          m_ui.contextMenu->exec(
326                  (m_ui.InstrumentTable->viewport())->mapToGlobal(pos));                  (m_pInstrumentListView->viewport())->mapToGlobal(pos));
327  }  }
328    
329    

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

  ViewVC Help
Powered by ViewVC