/[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 1504 by capela, Wed Nov 21 11:46:40 2007 UTC revision 1558 by capela, Thu Dec 6 09:35:33 2007 UTC
# Line 20  Line 20 
20    
21  *****************************************************************************/  *****************************************************************************/
22    
23    #include "qsamplerAbout.h"
24  #include "qsamplerInstrumentListForm.h"  #include "qsamplerInstrumentListForm.h"
25    
26  #include "qsamplerInstrumentForm.h"  #include "qsamplerInstrumentForm.h"
27  #include "qsamplerMainForm.h"  
28  #include "qsamplerOptions.h"  #include "qsamplerOptions.h"
29  #include "qsamplerInstrument.h"  #include "qsamplerInstrument.h"
30    #include "qsamplerMainForm.h"
31    
32    #include <QHeaderView>
33    #include <QMessageBox>
34    
35    
36  namespace QSampler {  namespace QSampler {
37    
38    //-------------------------------------------------------------------------
39    // QSampler::InstrumentListForm -- Instrument map list form implementation.
40    //
41    
42  InstrumentListForm::InstrumentListForm (  InstrumentListForm::InstrumentListForm (
43          QWidget* pParent, Qt::WindowFlags wflags )          QWidget* pParent, Qt::WindowFlags wflags )
44          : QMainWindow(pParent, wflags)          : QMainWindow(pParent, wflags)
45  {  {
46      ui.setupUi(this);          m_ui.setupUi(this);
47    
48      // Setup toolbar widgets.          // Setup toolbar widgets.
49      m_pMapComboBox = new QComboBox(ui.InstrumentToolbar);          m_pMapComboBox = new QComboBox(m_ui.InstrumentToolbar);
50      m_pMapComboBox->setMinimumWidth(120);          m_pMapComboBox->setMinimumWidth(120);
51      m_pMapComboBox->setEnabled(false);          m_pMapComboBox->setEnabled(false);
52      m_pMapComboBox->setToolTip(tr("Instrument Map"));          m_pMapComboBox->setToolTip(tr("Instrument Map"));
53      ui.InstrumentToolbar->addWidget(m_pMapComboBox);          m_ui.InstrumentToolbar->addWidget(m_pMapComboBox);
54    
55      ui.InstrumentToolbar->addSeparator();          m_ui.InstrumentToolbar->addSeparator();
56      ui.InstrumentToolbar->addAction(ui.newInstrumentAction);          m_ui.InstrumentToolbar->addAction(m_ui.newInstrumentAction);
57      ui.InstrumentToolbar->addAction(ui.editInstrumentAction);          m_ui.InstrumentToolbar->addAction(m_ui.editInstrumentAction);
58      ui.InstrumentToolbar->addAction(ui.deleteInstrumentAction);          m_ui.InstrumentToolbar->addAction(m_ui.deleteInstrumentAction);
59      ui.InstrumentToolbar->addSeparator();          m_ui.InstrumentToolbar->addSeparator();
60      ui.InstrumentToolbar->addAction(ui.refreshInstrumentsAction);          m_ui.InstrumentToolbar->addAction(m_ui.refreshInstrumentsAction);
61    
62            int iRowHeight = m_ui.InstrumentTable->fontMetrics().height() + 4;
63            m_ui.InstrumentTable->verticalHeader()->setDefaultSectionSize(iRowHeight);
64    
65            m_ui.InstrumentTable->setModel(&m_model);
66            m_ui.InstrumentTable->setItemDelegate(&m_delegate);
67            m_ui.InstrumentTable->verticalHeader()->hide();
68    
69            QHeaderView *pHeader = m_ui.InstrumentTable->horizontalHeader();
70            pHeader->setDefaultAlignment(Qt::AlignLeft);
71            pHeader->setMovable(false);
72            pHeader->setStretchLastSection(true);
73            pHeader->resizeSection(0, 120);                                         // Name
74            m_ui.InstrumentTable->resizeColumnToContents(1);        // Map
75            m_ui.InstrumentTable->resizeColumnToContents(2);        // Bank
76            m_ui.InstrumentTable->resizeColumnToContents(3);        // Prog
77            m_ui.InstrumentTable->resizeColumnToContents(4);        // Engine
78            pHeader->resizeSection(5, 240);                                         // File
79            m_ui.InstrumentTable->resizeColumnToContents(6);        // Nr
80            pHeader->resizeSection(7, 60);                                          // Vol
81    
82      ui.InstrumentTable->setModel(&model);          // Enable custom context menu...
83      ui.InstrumentTable->setItemDelegate(&delegate);          m_ui.InstrumentTable->setContextMenuPolicy(Qt::CustomContextMenu);
84    
85          QObject::connect(m_pMapComboBox,          QObject::connect(m_pMapComboBox,
86                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
87                  SLOT(activateMap(int)));                  SLOT(activateMap(int)));
   
88          QObject::connect(          QObject::connect(
89                  ui.refreshInstrumentsAction,                  m_ui.InstrumentTable,
90                  SIGNAL(triggered()),                  SIGNAL(customContextMenuRequested(const QPoint&)),
91                  SLOT(refreshInstruments(void))                  SLOT(contextMenu(const QPoint&)));
92      );          QObject::connect(
93                    m_ui.InstrumentTable,
94                    SIGNAL(pressed(const QModelIndex&)),
95                    SLOT(stabilizeForm()));
96          QObject::connect(          QObject::connect(
97                  ui.InstrumentTable,                  m_ui.InstrumentTable,
98                  SIGNAL(activated(const QModelIndex&)),                  SIGNAL(activated(const QModelIndex&)),
99                  SLOT(editInstrument(const QModelIndex&))                  SLOT(editInstrument(const QModelIndex&)));
         );  
100          QObject::connect(          QObject::connect(
101                  ui.newInstrumentAction,                  m_ui.newInstrumentAction,
102                  SIGNAL(triggered()),                  SIGNAL(triggered()),
103                  SLOT(newInstrument())                  SLOT(newInstrument()));
         );  
104          QObject::connect(          QObject::connect(
105                  ui.deleteInstrumentAction,                  m_ui.deleteInstrumentAction,
106                  SIGNAL(triggered()),                  SIGNAL(triggered()),
107                  SLOT(deleteInstrument())                  SLOT(deleteInstrument()));
         );  
108          QObject::connect(          QObject::connect(
109                  ui.editInstrumentAction,                  m_ui.editInstrumentAction,
110                  SIGNAL(triggered()),                  SIGNAL(triggered()),
111                  SLOT(editInstrument())                  SLOT(editInstrument()));
112          );          QObject::connect(
113                    m_ui.refreshInstrumentsAction,
114                    SIGNAL(triggered()),
115                    SLOT(refreshInstruments()));
116    
117            MainForm *pMainForm = MainForm::getInstance();
118            if (pMainForm) {
119                    QObject::connect(&m_model,
120                            SIGNAL(instrumentsChanged()),
121                            pMainForm, SLOT(sessionDirty()));
122            }
123    
124            // Things must be stable from the start.
125            stabilizeForm();
126  }  }
127    
128    
# Line 132  void InstrumentListForm::refreshInstrume Line 172  void InstrumentListForm::refreshInstrume
172          if (pMainForm == NULL)          if (pMainForm == NULL)
173                  return;                  return;
174    
175          qsamplerOptions *pOptions = pMainForm->options();          Options *pOptions = pMainForm->options();
176          if (pOptions == NULL)          if (pOptions == NULL)
177                  return;                  return;
178    
# Line 144  void InstrumentListForm::refreshInstrume Line 184  void InstrumentListForm::refreshInstrume
184          // Populate maps list.          // Populate maps list.
185          m_pMapComboBox->clear();          m_pMapComboBox->clear();
186          m_pMapComboBox->addItem(tr("(All)"));          m_pMapComboBox->addItem(tr("(All)"));
187          m_pMapComboBox->insertItems(1, qsamplerInstrument::getMapNames());          m_pMapComboBox->insertItems(1, Instrument::getMapNames());
188    
189          // Adjust to saved selection...          // Adjust to saved selection...
190          if (iMap < 0 || iMap >= m_pMapComboBox->count())          if (iMap < 0 || iMap >= m_pMapComboBox->count())
# Line 163  void InstrumentListForm::activateMap ( i Line 203  void InstrumentListForm::activateMap ( i
203          if (pMainForm == NULL)          if (pMainForm == NULL)
204                  return;                  return;
205    
206          qsamplerOptions *pOptions = pMainForm->options();          Options *pOptions = pMainForm->options();
207          if (pOptions == NULL)          if (pOptions == NULL)
208                  return;                  return;
209    
# Line 171  void InstrumentListForm::activateMap ( i Line 211  void InstrumentListForm::activateMap ( i
211          if (iMidiMap >= 0)          if (iMidiMap >= 0)
212                  pOptions->iMidiMap = iMidiMap;                  pOptions->iMidiMap = iMidiMap;
213    
214          model.setMidiMap(iMidiMap);          m_model.setMidiMap(iMidiMap);
215          model.refresh();          m_model.refresh();
216    
217            stabilizeForm();
218  }  }
219    
220    
221  void InstrumentListForm::editInstrument (void)  void InstrumentListForm::editInstrument (void)
222  {  {
223          editInstrument(ui.InstrumentTable->currentIndex());          editInstrument(m_ui.InstrumentTable->currentIndex());
224  }  }
225    
226    
# Line 187  void InstrumentListForm::editInstrument Line 229  void InstrumentListForm::editInstrument
229          if (!index.isValid() || !index.data(Qt::UserRole).isValid())          if (!index.isValid() || !index.data(Qt::UserRole).isValid())
230                  return;                  return;
231    
232          qsamplerInstrument* pInstrument          Instrument* pInstrument
233                  = static_cast<qsamplerInstrument *> (                  = static_cast<Instrument *> (
234                          index.data(Qt::UserRole).value<void *> ());                          index.data(Qt::UserRole).value<void *> ());
235    
236          if (pInstrument == NULL)          if (pInstrument == NULL)
237                  return;                  return;
238    
239          // Save current key values...          // Save current key values...
240          qsamplerInstrument oldInstrument(*pInstrument);          Instrument oldInstrument(*pInstrument);
241          // Do the edit dance...          // Do the edit dance...
242          InstrumentForm form(this);          InstrumentForm form(this);
243          form.setup(pInstrument);          form.setup(pInstrument);
# Line 206  void InstrumentListForm::editInstrument Line 248  void InstrumentListForm::editInstrument
248                  if (oldInstrument.map()  == pInstrument->map()  &&                  if (oldInstrument.map()  == pInstrument->map()  &&
249                          oldInstrument.bank() == pInstrument->bank() &&                          oldInstrument.bank() == pInstrument->bank() &&
250                          oldInstrument.prog() == pInstrument->prog()) {                          oldInstrument.prog() == pInstrument->prog()) {
251                          // just update tree item...                          // Just update tree item...
252                          //pItem->update();                          //pItem->update();
253                  } else {                  } else {
254                          // Unmap old instance...                          // Unmap old instance...
255                          oldInstrument.unmapInstrument();                          oldInstrument.unmapInstrument();
256                          // correct the position of the instrument in the model                          // correct the position of the instrument in the model
257                          model.resort(*pInstrument);                          m_model.resort(*pInstrument);
258                  }                  }
259                  // Notify we've changes...                  // Notify we've changes...
260                  emit model.reset();                  emit m_model.reset();
261          }          }
262  }  }
263    
264    
265  void InstrumentListForm::newInstrument (void)  void InstrumentListForm::newInstrument (void)
266  {  {
267          qsamplerInstrument instrument;          Instrument instrument;
268    
269          InstrumentForm form(this);          InstrumentForm form(this);
270          form.setup(&instrument);          form.setup(&instrument);
# Line 232  void InstrumentListForm::newInstrument ( Line 274  void InstrumentListForm::newInstrument (
274          // Commit...          // Commit...
275          instrument.mapInstrument();          instrument.mapInstrument();
276          // add new item to the table model          // add new item to the table model
277          model.resort(instrument);          m_model.resort(instrument);
278          // Notify we've changes...          // Notify we've changes...
279          //emit model.reset();          //emit model.reset();
280          //FIXME: call above didnt really refresh, so we use this for now ...          //FIXME: call above didnt really refresh, so we use this for now ...
# Line 242  void InstrumentListForm::newInstrument ( Line 284  void InstrumentListForm::newInstrument (
284    
285  void InstrumentListForm::deleteInstrument (void)  void InstrumentListForm::deleteInstrument (void)
286  {  {
287          const QModelIndex& index = ui.InstrumentTable->currentIndex();          const QModelIndex& index = m_ui.InstrumentTable->currentIndex();
288          if (!index.isValid() || !index.data(Qt::UserRole).isValid())          if (!index.isValid() || !index.data(Qt::UserRole).isValid())
289                  return;                  return;
290    
291          qsamplerInstrument* pInstrument =          Instrument *pInstrument =
292                  static_cast<qsamplerInstrument*> (                  static_cast<Instrument*> (
293                          index.data(Qt::UserRole).value<void *> ());                          index.data(Qt::UserRole).value<void *> ());
294    
295          if (pInstrument == NULL)          if (pInstrument == NULL)
296                  return;                  return;
297    
298            MainForm *pMainForm = MainForm::getInstance();
299            if (pMainForm == NULL)
300                    return;
301    
302            // Prompt user if this is for real...
303            Options *pOptions = pMainForm->options();
304            if (pOptions && pOptions->bConfirmRemove) {
305                    if (QMessageBox::warning(this,
306                            QSAMPLER_TITLE ": " + tr("Warning"),
307                            tr("About to delete instrument map entry:\n\n"
308                            "%1\n\n"
309                            "Are you sure?")
310                            .arg(pInstrument->name()),
311                            tr("OK"), tr("Cancel")) > 0)
312                            return;
313            }
314    
315          pInstrument->unmapInstrument();          pInstrument->unmapInstrument();
316          // let the instrument vanish from the table model          // let the instrument vanish from the table model
317          model.removeInstrument(*pInstrument);          m_model.removeInstrument(*pInstrument);
318          // Notify we've changes...          // Notify we've changes...
319          emit model.reset();          emit m_model.reset();
320  }  }
321    
322    
323    // Update form actions enablement...
324    void InstrumentListForm::stabilizeForm (void)
325    {
326            MainForm *pMainForm = MainForm::getInstance();
327    
328            bool bEnabled = (pMainForm && pMainForm->client());
329            m_ui.newInstrumentAction->setEnabled(bEnabled);
330            const QModelIndex& index = m_ui.InstrumentTable->currentIndex();
331            bEnabled = (bEnabled && index.isValid());
332            m_ui.editInstrumentAction->setEnabled(bEnabled);
333            m_ui.deleteInstrumentAction->setEnabled(bEnabled);
334    }
335    
336    
337    // Handle custom context menu here...
338    void InstrumentListForm::contextMenu ( const QPoint& pos )
339    {
340            if (!m_ui.newInstrumentAction->isEnabled())
341                    return;
342    
343            m_ui.contextMenu->exec(
344                    (m_ui.InstrumentTable->viewport())->mapToGlobal(pos));
345    }
346    
347    
348  } // namespace QSampler  } // namespace QSampler
349    
350    

Legend:
Removed from v.1504  
changed lines
  Added in v.1558

  ViewVC Help
Powered by ViewVC