/[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 2064 by capela, Fri Mar 12 16:02:32 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 59  InstrumentListForm::InstrumentListForm ( Line 61  InstrumentListForm::InstrumentListForm (
61          m_ui.InstrumentToolbar->addSeparator();          m_ui.InstrumentToolbar->addSeparator();
62          m_ui.InstrumentToolbar->addAction(m_ui.refreshInstrumentsAction);          m_ui.InstrumentToolbar->addAction(m_ui.refreshInstrumentsAction);
63    
64          int iRowHeight = m_ui.InstrumentTable->fontMetrics().height() + 4;          m_pInstrumentListView = new InstrumentListView(this);
         m_ui.InstrumentTable->verticalHeader()->setDefaultSectionSize(iRowHeight);  
   
         m_ui.InstrumentTable->setModel(&m_model);  
         m_ui.InstrumentTable->setItemDelegate(&m_delegate);  
         m_ui.InstrumentTable->verticalHeader()->hide();  
65    
66          QHeaderView *pHeader = m_ui.InstrumentTable->horizontalHeader();          QHeaderView *pHeader = m_pInstrumentListView->header();
67          pHeader->setDefaultAlignment(Qt::AlignLeft);          pHeader->setDefaultAlignment(Qt::AlignLeft);
68          pHeader->setMovable(false);          pHeader->setMovable(false);
69          pHeader->setStretchLastSection(true);          pHeader->setStretchLastSection(true);
70          pHeader->resizeSection(0, 120);                                         // Name          pHeader->resizeSection(0, 120);                                         // Name
71          m_ui.InstrumentTable->resizeColumnToContents(1);        // Map          m_pInstrumentListView->resizeColumnToContents(1);       // Map
72          m_ui.InstrumentTable->resizeColumnToContents(2);        // Bank          m_pInstrumentListView->resizeColumnToContents(2);       // Bank
73          m_ui.InstrumentTable->resizeColumnToContents(3);        // Prog          m_pInstrumentListView->resizeColumnToContents(3);       // Prog
74          m_ui.InstrumentTable->resizeColumnToContents(4);        // Engine          m_pInstrumentListView->resizeColumnToContents(4);       // Engine
75          pHeader->resizeSection(5, 240);                                         // File          pHeader->resizeSection(5, 240);                                         // File
76          m_ui.InstrumentTable->resizeColumnToContents(6);        // Nr          m_pInstrumentListView->resizeColumnToContents(6);       // Nr
77          pHeader->resizeSection(7, 60);                                          // Vol          pHeader->resizeSection(7, 60);                                          // Vol
78    
79          // Enable custom context menu...          // Enable custom context menu...
80          m_ui.InstrumentTable->setContextMenuPolicy(Qt::CustomContextMenu);          m_pInstrumentListView->setContextMenuPolicy(Qt::CustomContextMenu);
81    
82            QMainWindow::setCentralWidget(m_pInstrumentListView);
83    
84          QObject::connect(m_pMapComboBox,          QObject::connect(m_pMapComboBox,
85                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
86                  SLOT(activateMap(int)));                  SLOT(activateMap(int)));
87          QObject::connect(          QObject::connect(
88                  m_ui.InstrumentTable,                  m_pInstrumentListView,
89                  SIGNAL(customContextMenuRequested(const QPoint&)),                  SIGNAL(customContextMenuRequested(const QPoint&)),
90                  SLOT(contextMenu(const QPoint&)));                  SLOT(contextMenu(const QPoint&)));
91          QObject::connect(          QObject::connect(
92                  m_ui.InstrumentTable,                  m_pInstrumentListView,
93                  SIGNAL(pressed(const QModelIndex&)),                  SIGNAL(pressed(const QModelIndex&)),
94                  SLOT(stabilizeForm()));                  SLOT(stabilizeForm()));
95          QObject::connect(          QObject::connect(
96                  m_ui.InstrumentTable,                  m_pInstrumentListView,
97                  SIGNAL(activated(const QModelIndex&)),                  SIGNAL(activated(const QModelIndex&)),
98                  SLOT(editInstrument(const QModelIndex&)));                  SLOT(editInstrument(const QModelIndex&)));
99          QObject::connect(          QObject::connect(
# Line 114  InstrumentListForm::InstrumentListForm ( Line 113  InstrumentListForm::InstrumentListForm (
113                  SIGNAL(triggered()),                  SIGNAL(triggered()),
114                  SLOT(refreshInstruments()));                  SLOT(refreshInstruments()));
115    
         MainForm *pMainForm = MainForm::getInstance();  
         if (pMainForm) {  
                 QObject::connect(&m_model,  
                         SIGNAL(instrumentsChanged()),  
                         pMainForm, SLOT(sessionDirty()));  
         }  
   
116          // Things must be stable from the start.          // Things must be stable from the start.
117          stabilizeForm();          stabilizeForm();
118  }  }
# Line 128  InstrumentListForm::InstrumentListForm ( Line 120  InstrumentListForm::InstrumentListForm (
120    
121  InstrumentListForm::~InstrumentListForm (void)  InstrumentListForm::~InstrumentListForm (void)
122  {  {
123            delete m_pInstrumentListView;
124          delete m_pMapComboBox;          delete m_pMapComboBox;
125  }  }
126    
# Line 211  void InstrumentListForm::activateMap ( i Line 204  void InstrumentListForm::activateMap ( i
204          if (iMidiMap >= 0)          if (iMidiMap >= 0)
205                  pOptions->iMidiMap = iMidiMap;                  pOptions->iMidiMap = iMidiMap;
206    
207          m_model.setMidiMap(iMidiMap);          m_pInstrumentListView->setMidiMap(iMidiMap);
208          m_model.refresh();          m_pInstrumentListView->refresh();
209    
210          stabilizeForm();          stabilizeForm();
211  }  }
# Line 220  void InstrumentListForm::activateMap ( i Line 213  void InstrumentListForm::activateMap ( i
213    
214  void InstrumentListForm::editInstrument (void)  void InstrumentListForm::editInstrument (void)
215  {  {
216          editInstrument(m_ui.InstrumentTable->currentIndex());          editInstrument(m_pInstrumentListView->currentIndex());
217  }  }
218    
219    
220  void InstrumentListForm::editInstrument ( const QModelIndex& index )  void InstrumentListForm::editInstrument ( const QModelIndex& index )
221  {  {
222          if (!index.isValid() || !index.data(Qt::UserRole).isValid())          if (!index.isValid())
223                  return;                  return;
224    
225          Instrument* pInstrument          Instrument *pInstrument
226                  = static_cast<Instrument *> (                  = static_cast<Instrument *> (index.internalPointer());
227                          index.data(Qt::UserRole).value<void *> ());          if (pInstrument == NULL)
228                    return;
229    
230          if (pInstrument == NULL)          if (pInstrument == NULL)
231                  return;                  return;
232    
233          // Save current key values...          // Save current key values...
234          Instrument oldInstrument(*pInstrument);          Instrument oldInstrument(
235                    pInstrument->map(),
236                    pInstrument->bank(),
237                    pInstrument->prog());
238    
239          // Do the edit dance...          // Do the edit dance...
240          InstrumentForm form(this);          InstrumentForm form(this);
241          form.setup(pInstrument);          form.setup(pInstrument);
# Line 254  void InstrumentListForm::editInstrument Line 252  void InstrumentListForm::editInstrument
252                          // Unmap old instance...                          // Unmap old instance...
253                          oldInstrument.unmapInstrument();                          oldInstrument.unmapInstrument();
254                          // correct the position of the instrument in the model                          // correct the position of the instrument in the model
255                          m_model.resort(*pInstrument);                          m_pInstrumentListView->updateInstrument(pInstrument);
256                  }                  }
                 // Notify we've changes...  
                 emit m_model.reset();  
257          }          }
258  }  }
259    
# Line 273  void InstrumentListForm::newInstrument ( Line 269  void InstrumentListForm::newInstrument (
269    
270          // Commit...          // Commit...
271          instrument.mapInstrument();          instrument.mapInstrument();
272    
273          // add new item to the table model          // add new item to the table model
274          m_model.resort(instrument);          m_pInstrumentListView->addInstrument(
275          // Notify we've changes...                  instrument.map(),
276          //emit model.reset();                  instrument.bank(),
277          //FIXME: call above didnt really refresh, so we use this for now ...                  instrument.prog());
         refreshInstruments();  
278  }  }
279    
280    
281  void InstrumentListForm::deleteInstrument (void)  void InstrumentListForm::deleteInstrument (void)
282  {  {
283          const QModelIndex& index = m_ui.InstrumentTable->currentIndex();          const QModelIndex& index = m_pInstrumentListView->currentIndex();
284          if (!index.isValid() || !index.data(Qt::UserRole).isValid())          if (!index.isValid())
285                  return;                  return;
286    
287          Instrument *pInstrument =          Instrument *pInstrument
288                  static_cast<Instrument*> (                  = static_cast<Instrument *> (index.internalPointer());
                         index.data(Qt::UserRole).value<void *> ());  
   
289          if (pInstrument == NULL)          if (pInstrument == NULL)
290                  return;                  return;
291    
# Line 314  void InstrumentListForm::deleteInstrumen Line 308  void InstrumentListForm::deleteInstrumen
308          }          }
309    
310          pInstrument->unmapInstrument();          pInstrument->unmapInstrument();
311    
312          // let the instrument vanish from the table model          // let the instrument vanish from the table model
313          m_model.removeInstrument(*pInstrument);          m_pInstrumentListView->removeInstrument(pInstrument);
         // Notify we've changes...  
         emit m_model.reset();  
314  }  }
315    
316    
# Line 328  void InstrumentListForm::stabilizeForm ( Line 321  void InstrumentListForm::stabilizeForm (
321    
322          bool bEnabled = (pMainForm && pMainForm->client());          bool bEnabled = (pMainForm && pMainForm->client());
323          m_ui.newInstrumentAction->setEnabled(bEnabled);          m_ui.newInstrumentAction->setEnabled(bEnabled);
324          const QModelIndex& index = m_ui.InstrumentTable->currentIndex();          const QModelIndex& index = m_pInstrumentListView->currentIndex();
325          bEnabled = (bEnabled && index.isValid());          bEnabled = (bEnabled && index.isValid());
326          m_ui.editInstrumentAction->setEnabled(bEnabled);          m_ui.editInstrumentAction->setEnabled(bEnabled);
327          m_ui.deleteInstrumentAction->setEnabled(bEnabled);          m_ui.deleteInstrumentAction->setEnabled(bEnabled);
# Line 342  void InstrumentListForm::contextMenu ( c Line 335  void InstrumentListForm::contextMenu ( c
335                  return;                  return;
336    
337          m_ui.contextMenu->exec(          m_ui.contextMenu->exec(
338                  (m_ui.InstrumentTable->viewport())->mapToGlobal(pos));                  (m_pInstrumentListView->viewport())->mapToGlobal(pos));
339  }  }
340    
341    

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

  ViewVC Help
Powered by ViewVC