/[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 2722 by capela, Tue Mar 3 17:41:04 2015 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-2015, 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    #include <QCheckBox>
39    
40    
41  namespace QSampler {  namespace QSampler {
# Line 45  InstrumentListForm::InstrumentListForm ( Line 50  InstrumentListForm::InstrumentListForm (
50  {  {
51          m_ui.setupUi(this);          m_ui.setupUi(this);
52    
53            m_pInstrumentListView = new InstrumentListView(this);
54            QMainWindow::setCentralWidget(m_pInstrumentListView);
55    
56          // Setup toolbar widgets.          // Setup toolbar widgets.
57          m_pMapComboBox = new QComboBox(m_ui.InstrumentToolbar);          m_pMapComboBox = new QComboBox(m_ui.instrumentToolbar);
58          m_pMapComboBox->setMinimumWidth(120);          m_pMapComboBox->setMinimumWidth(120);
59          m_pMapComboBox->setEnabled(false);          m_pMapComboBox->setEnabled(false);
60          m_pMapComboBox->setToolTip(tr("Instrument Map"));          m_pMapComboBox->setToolTip(tr("Instrument Map"));
61          m_ui.InstrumentToolbar->addWidget(m_pMapComboBox);          
62            m_ui.instrumentToolbar->addWidget(m_pMapComboBox);
63          m_ui.InstrumentToolbar->addSeparator();          m_ui.instrumentToolbar->addSeparator();
64          m_ui.InstrumentToolbar->addAction(m_ui.newInstrumentAction);          m_ui.instrumentToolbar->addAction(m_ui.newInstrumentAction);
65          m_ui.InstrumentToolbar->addAction(m_ui.editInstrumentAction);          m_ui.instrumentToolbar->addAction(m_ui.editInstrumentAction);
66          m_ui.InstrumentToolbar->addAction(m_ui.deleteInstrumentAction);          m_ui.instrumentToolbar->addAction(m_ui.deleteInstrumentAction);
67          m_ui.InstrumentToolbar->addSeparator();          m_ui.instrumentToolbar->addSeparator();
68          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);  
69    
70          QObject::connect(m_pMapComboBox,          QObject::connect(m_pMapComboBox,
71                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
72                  SLOT(activateMap(int)));                  SLOT(activateMap(int)));
73          QObject::connect(          QObject::connect(m_pInstrumentListView->selectionModel(),
74                  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&)),  
75                  SLOT(stabilizeForm()));                  SLOT(stabilizeForm()));
76          QObject::connect(          QObject::connect(
77                  m_ui.InstrumentTable,                  m_pInstrumentListView,
78                  SIGNAL(activated(const QModelIndex&)),                  SIGNAL(activated(const QModelIndex&)),
79                  SLOT(editInstrument(const QModelIndex&)));                  SLOT(editInstrument(const QModelIndex&)));
80          QObject::connect(          QObject::connect(
# Line 114  InstrumentListForm::InstrumentListForm ( Line 94  InstrumentListForm::InstrumentListForm (
94                  SIGNAL(triggered()),                  SIGNAL(triggered()),
95                  SLOT(refreshInstruments()));                  SLOT(refreshInstruments()));
96    
         MainForm *pMainForm = MainForm::getInstance();  
         if (pMainForm) {  
                 QObject::connect(&m_model,  
                         SIGNAL(instrumentsChanged()),  
                         pMainForm, SLOT(sessionDirty()));  
         }  
   
97          // Things must be stable from the start.          // Things must be stable from the start.
98          stabilizeForm();          stabilizeForm();
99  }  }
# Line 129  InstrumentListForm::InstrumentListForm ( Line 102  InstrumentListForm::InstrumentListForm (
102  InstrumentListForm::~InstrumentListForm (void)  InstrumentListForm::~InstrumentListForm (void)
103  {  {
104          delete m_pMapComboBox;          delete m_pMapComboBox;
105            delete m_pInstrumentListView;
106  }  }
107    
108    
# Line 211  void InstrumentListForm::activateMap ( i Line 185  void InstrumentListForm::activateMap ( i
185          if (iMidiMap >= 0)          if (iMidiMap >= 0)
186                  pOptions->iMidiMap = iMidiMap;                  pOptions->iMidiMap = iMidiMap;
187    
188          m_model.setMidiMap(iMidiMap);          m_pInstrumentListView->setMidiMap(iMidiMap);
189          m_model.refresh();          m_pInstrumentListView->refresh();
190    
191            stabilizeForm();
192    }
193    
194    
195    void InstrumentListForm::newInstrument (void)
196    {
197            Instrument instrument;
198    
199            InstrumentForm form(this);
200            form.setup(&instrument);
201            if (!form.exec())
202                    return;
203    
204            // Commit...
205            instrument.mapInstrument();
206    
207            // add new item to the table model
208            m_pInstrumentListView->addInstrument(
209                    instrument.map(),
210                    instrument.bank(),
211                    instrument.prog());
212    
213          stabilizeForm();          stabilizeForm();
214  }  }
# Line 220  void InstrumentListForm::activateMap ( i Line 216  void InstrumentListForm::activateMap ( i
216    
217  void InstrumentListForm::editInstrument (void)  void InstrumentListForm::editInstrument (void)
218  {  {
219          editInstrument(m_ui.InstrumentTable->currentIndex());          editInstrument(m_pInstrumentListView->currentIndex());
220  }  }
221    
222    
223  void InstrumentListForm::editInstrument ( const QModelIndex& index )  void InstrumentListForm::editInstrument ( const QModelIndex& index )
224  {  {
225          if (!index.isValid() || !index.data(Qt::UserRole).isValid())          if (!index.isValid())
226                  return;                  return;
227    
228          Instrument* pInstrument          Instrument *pInstrument
229                  = static_cast<Instrument *> (                  = static_cast<Instrument *> (index.internalPointer());
                         index.data(Qt::UserRole).value<void *> ());  
   
230          if (pInstrument == NULL)          if (pInstrument == NULL)
231                  return;                  return;
232    
233          // Save current key values...          // Save current key values...
234          Instrument oldInstrument(*pInstrument);          int iMap  = pInstrument->map();
235          // Do the edit dance...          int iBank = pInstrument->bank();
236          InstrumentForm form(this);          int iProg = pInstrument->prog();
         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_model.resort(*pInstrument);  
                 }  
                 // Notify we've changes...  
                 emit m_model.reset();  
         }  
 }  
237    
238            Instrument instrument(iMap, iBank, iProg);
239    
240  void InstrumentListForm::newInstrument (void)          // Do the edit dance...
 {  
         Instrument instrument;  
   
241          InstrumentForm form(this);          InstrumentForm form(this);
242          form.setup(&instrument);          form.setup(pInstrument);
243          if (!form.exec())          if (!form.exec())
244                  return;                  return;
245            
246          // Commit...          // Commit...
247          instrument.mapInstrument();          pInstrument->mapInstrument();
248          // add new item to the table model  
249          m_model.resort(instrument);          // Check whether we changed instrument key...
250          // Notify we've changes...          if (pInstrument->map()  == iMap  &&
251          //emit model.reset();                  pInstrument->bank() == iBank &&
252          //FIXME: call above didnt really refresh, so we use this for now ...                  pInstrument->prog() == iProg) {
253          refreshInstruments();                  // Just update tree item...
254                    m_pInstrumentListView->updateInstrument(pInstrument);
255            } else {
256                    // Unmap old instance...
257                    instrument.unmapInstrument();
258                    // Correct the position of the instrument in the model
259                    m_pInstrumentListView->resortInstrument(pInstrument);
260            }
261    
262            stabilizeForm();
263  }  }
264    
265    
266  void InstrumentListForm::deleteInstrument (void)  void InstrumentListForm::deleteInstrument (void)
267  {  {
268          const QModelIndex& index = m_ui.InstrumentTable->currentIndex();          const QModelIndex& index = m_pInstrumentListView->currentIndex();
269          if (!index.isValid() || !index.data(Qt::UserRole).isValid())          if (!index.isValid())
270                  return;                  return;
271    
272          Instrument *pInstrument =          Instrument *pInstrument
273                  static_cast<Instrument*> (                  = static_cast<Instrument *> (index.internalPointer());
                         index.data(Qt::UserRole).value<void *> ());  
   
274          if (pInstrument == NULL)          if (pInstrument == NULL)
275                  return;                  return;
276    
# Line 302  void InstrumentListForm::deleteInstrumen Line 281  void InstrumentListForm::deleteInstrumen
281          // Prompt user if this is for real...          // Prompt user if this is for real...
282          Options *pOptions = pMainForm->options();          Options *pOptions = pMainForm->options();
283          if (pOptions && pOptions->bConfirmRemove) {          if (pOptions && pOptions->bConfirmRemove) {
284                  if (QMessageBox::warning(this,                  const QString& sTitle = QSAMPLER_TITLE ": " + tr("Warning");
285                          QSAMPLER_TITLE ": " + tr("Warning"),                  const QString& sText = tr(
286                          tr("About to delete instrument map entry:\n\n"                          "About to delete instrument map entry:\n\n"
287                          "%1\n\n"                          "%1\n\n"
288                          "Are you sure?")                          "Are you sure?")
289                          .arg(pInstrument->name()),                          .arg(pInstrument->name());
290                          QMessageBox::Ok | QMessageBox::Cancel)           #if 0
291                          == QMessageBox::Cancel)                   if (QMessageBox::warning(this, sTitle, sText,
292                          return;                           QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Cancel)
293                             return;
294             #else
295                     QMessageBox mbox(this);
296                     mbox.setIcon(QMessageBox::Warning);
297                     mbox.setWindowTitle(sTitle);
298                     mbox.setText(sText);
299                     mbox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
300                     QCheckBox cbox(tr("Don't ask this again"));
301                     cbox.setChecked(false);
302                     cbox.blockSignals(true);
303                     mbox.addButton(&cbox, QMessageBox::ActionRole);
304                     if (mbox.exec() == QMessageBox::Cancel)
305                             return;
306                     if (cbox.isChecked())
307                             pOptions->bConfirmRemove = false;
308             #endif
309          }          }
310    
311          pInstrument->unmapInstrument();          pInstrument->unmapInstrument();
312          // let the instrument vanish from the table model  
313          m_model.removeInstrument(*pInstrument);          // Let the instrument vanish from the table model...
314          // Notify we've changes...          m_pInstrumentListView->removeInstrument(pInstrument);
315          emit m_model.reset();  
316            stabilizeForm();
317  }  }
318    
319    
# Line 328  void InstrumentListForm::stabilizeForm ( Line 324  void InstrumentListForm::stabilizeForm (
324    
325          bool bEnabled = (pMainForm && pMainForm->client());          bool bEnabled = (pMainForm && pMainForm->client());
326          m_ui.newInstrumentAction->setEnabled(bEnabled);          m_ui.newInstrumentAction->setEnabled(bEnabled);
327          const QModelIndex& index = m_ui.InstrumentTable->currentIndex();          const QModelIndex& index = m_pInstrumentListView->currentIndex();
328          bEnabled = (bEnabled && index.isValid());          bEnabled = (bEnabled && index.isValid());
329          m_ui.editInstrumentAction->setEnabled(bEnabled);          m_ui.editInstrumentAction->setEnabled(bEnabled);
330          m_ui.deleteInstrumentAction->setEnabled(bEnabled);          m_ui.deleteInstrumentAction->setEnabled(bEnabled);
331  }  }
332    
333    
334  // Handle custom context menu here...  // Context menu request.
335  void InstrumentListForm::contextMenu ( const QPoint& pos )  void InstrumentListForm::contextMenuEvent (
336  {          QContextMenuEvent *pContextMenuEvent )
337          if (!m_ui.newInstrumentAction->isEnabled())  {
338                  return;          QMenu menu(this);
339    
340            menu.addAction(m_ui.newInstrumentAction);
341            menu.addSeparator();
342            menu.addAction(m_ui.editInstrumentAction);
343            menu.addAction(m_ui.deleteInstrumentAction);
344            menu.addSeparator();
345            menu.addAction(m_ui.refreshInstrumentsAction);
346    
347          m_ui.contextMenu->exec(          menu.exec(pContextMenuEvent->globalPos());
                 (m_ui.InstrumentTable->viewport())->mapToGlobal(pos));  
348  }  }
349    
350    

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

  ViewVC Help
Powered by ViewVC