/[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 1526 by capela, Mon Nov 26 10:58:23 2007 UTC revision 1528 by capela, Mon Nov 26 18:24:38 2007 UTC
# Line 30  Line 30 
30  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
31    
32  #include <QHeaderView>  #include <QHeaderView>
33    #include <QMessageBox>
34    
35    
36  namespace QSampler {  namespace QSampler {
# Line 72  InstrumentListForm::InstrumentListForm ( Line 73  InstrumentListForm::InstrumentListForm (
73          m_ui.InstrumentTable->resizeColumnToContents(4);        // Engine          m_ui.InstrumentTable->resizeColumnToContents(4);        // Engine
74          pHeader->resizeSection(5, 240);                                         // File          pHeader->resizeSection(5, 240);                                         // File
75          m_ui.InstrumentTable->resizeColumnToContents(6);        // Nr          m_ui.InstrumentTable->resizeColumnToContents(6);        // Nr
76          pHeader->resizeSection(7, 60);                                          // vol          pHeader->resizeSection(7, 60);                                          // Vol
77    
78            // Enable custom context menu...
79            m_ui.InstrumentTable->setContextMenuPolicy(Qt::CustomContextMenu);
80    
81          QObject::connect(m_pMapComboBox,          QObject::connect(m_pMapComboBox,
82                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
83                  SLOT(activateMap(int)));                  SLOT(activateMap(int)));
84          QObject::connect(          QObject::connect(
85                  m_ui.refreshInstrumentsAction,                  m_ui.InstrumentTable,
86                  SIGNAL(triggered()),                  SIGNAL(customContextMenuRequested(const QPoint&)),
87                  SLOT(refreshInstruments(void)));                  SLOT(contextMenu(const QPoint&)));
88            QObject::connect(
89                    m_ui.InstrumentTable,
90                    SIGNAL(pressed(const QModelIndex&)),
91                    SLOT(stabilizeForm()));
92          QObject::connect(          QObject::connect(
93                  m_ui.InstrumentTable,                  m_ui.InstrumentTable,
94                  SIGNAL(activated(const QModelIndex&)),                  SIGNAL(activated(const QModelIndex&)),
# Line 97  InstrumentListForm::InstrumentListForm ( Line 105  InstrumentListForm::InstrumentListForm (
105                  m_ui.editInstrumentAction,                  m_ui.editInstrumentAction,
106                  SIGNAL(triggered()),                  SIGNAL(triggered()),
107                  SLOT(editInstrument()));                  SLOT(editInstrument()));
108            QObject::connect(
109                    m_ui.refreshInstrumentsAction,
110                    SIGNAL(triggered()),
111                    SLOT(refreshInstruments()));
112    
113          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
114          if (pMainForm) {          if (pMainForm) {
# Line 104  InstrumentListForm::InstrumentListForm ( Line 116  InstrumentListForm::InstrumentListForm (
116                          SIGNAL(instrumentsChanged()),                          SIGNAL(instrumentsChanged()),
117                          pMainForm, SLOT(sessionDirty()));                          pMainForm, SLOT(sessionDirty()));
118          }          }
119    
120            // Things must be stable from the start.
121            stabilizeForm();
122  }  }
123    
124    
# Line 194  void InstrumentListForm::activateMap ( i Line 209  void InstrumentListForm::activateMap ( i
209    
210          m_model.setMidiMap(iMidiMap);          m_model.setMidiMap(iMidiMap);
211          m_model.refresh();          m_model.refresh();
212    
213            stabilizeForm();
214  }  }
215    
216    
# Line 267  void InstrumentListForm::deleteInstrumen Line 284  void InstrumentListForm::deleteInstrumen
284          if (!index.isValid() || !index.data(Qt::UserRole).isValid())          if (!index.isValid() || !index.data(Qt::UserRole).isValid())
285                  return;                  return;
286    
287          qsamplerInstrument* pInstrument =          qsamplerInstrument *pInstrument =
288                  static_cast<qsamplerInstrument*> (                  static_cast<qsamplerInstrument*> (
289                          index.data(Qt::UserRole).value<void *> ());                          index.data(Qt::UserRole).value<void *> ());
290    
291          if (pInstrument == NULL)          if (pInstrument == NULL)
292                  return;                  return;
293    
294            MainForm *pMainForm = MainForm::getInstance();
295            if (pMainForm == NULL)
296                    return;
297    
298            // Prompt user if this is for real...
299            qsamplerOptions *pOptions = pMainForm->options();
300            if (pOptions && pOptions->bConfirmRemove) {
301                    if (QMessageBox::warning(this,
302                            QSAMPLER_TITLE ": " + tr("Warning"),
303                            tr("About to delete instrument map entry:\n\n"
304                            "%1\n\n"
305                            "Are you sure?")
306                            .arg(pInstrument->name()),
307                            tr("OK"), tr("Cancel")) > 0)
308                            return;
309            }
310    
311          pInstrument->unmapInstrument();          pInstrument->unmapInstrument();
312          // let the instrument vanish from the table model          // let the instrument vanish from the table model
313          m_model.removeInstrument(*pInstrument);          m_model.removeInstrument(*pInstrument);
# Line 281  void InstrumentListForm::deleteInstrumen Line 315  void InstrumentListForm::deleteInstrumen
315          emit m_model.reset();          emit m_model.reset();
316  }  }
317    
318    
319    // Update form actions enablement...
320    void InstrumentListForm::stabilizeForm (void)
321    {
322            MainForm *pMainForm = MainForm::getInstance();
323    
324            bool bEnabled = (pMainForm && pMainForm->client());
325            m_ui.newInstrumentAction->setEnabled(bEnabled);
326            const QModelIndex& index = m_ui.InstrumentTable->currentIndex();
327            bEnabled = (bEnabled && index.isValid());
328            m_ui.editInstrumentAction->setEnabled(bEnabled);
329            m_ui.deleteInstrumentAction->setEnabled(bEnabled);
330    }
331    
332    
333    // Handle custom context menu here...
334    void InstrumentListForm::contextMenu ( const QPoint& pos )
335    {
336            if (!m_ui.newInstrumentAction->isEnabled())
337                    return;
338    
339            m_ui.contextMenu->exec(
340                    (m_ui.InstrumentTable->viewport())->mapToGlobal(pos));
341    }
342    
343    
344  } // namespace QSampler  } // namespace QSampler
345    
346    

Legend:
Removed from v.1526  
changed lines
  Added in v.1528

  ViewVC Help
Powered by ViewVC