/[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 1492 by schoenebeck, Mon Nov 19 21:08:18 2007 UTC revision 1509 by capela, Thu Nov 22 11:10:44 2007 UTC
# Line 27  Line 27 
27  #include "qsamplerOptions.h"  #include "qsamplerOptions.h"
28  #include "qsamplerInstrument.h"  #include "qsamplerInstrument.h"
29    
 #include <QToolTip>  
30    
31  namespace QSampler {  namespace QSampler {
32    
33  InstrumentListForm::InstrumentListForm ( QWidget* parent, Qt::WindowFlags flags )  InstrumentListForm::InstrumentListForm (
34          : QMainWindow(parent, flags)          QWidget* pParent, Qt::WindowFlags wflags )
35            : QMainWindow(pParent, wflags)
36  {  {
37      ui.setupUi(this);          m_ui.setupUi(this);
38    
39      ui.newInstrumentAction->setText(tr("New &Instrument..."));          // Setup toolbar widgets.
40      ui.newInstrumentAction->setShortcut(Qt::Key_Insert);          m_pMapComboBox = new QComboBox(m_ui.InstrumentToolbar);
41      ui.editInstrumentAction->setText(tr("&Edit..."));          m_pMapComboBox->setMinimumWidth(120);
42      ui.editInstrumentAction->setShortcut(Qt::Key_Enter);          m_pMapComboBox->setEnabled(false);
43      ui.deleteInstrumentAction->setText(tr("&Delete"));          m_pMapComboBox->setToolTip(tr("Instrument Map"));
44      ui.deleteInstrumentAction->setShortcut(Qt::Key_Delete);          m_ui.InstrumentToolbar->addWidget(m_pMapComboBox);
45      ui.refreshInstrumentsAction->setText(tr("&Refresh"));  
46      ui.refreshInstrumentsAction->setShortcut(Qt::Key_F5);          m_ui.InstrumentToolbar->addSeparator();
47            m_ui.InstrumentToolbar->addAction(m_ui.newInstrumentAction);
48      // Setup toolbar widgets.          m_ui.InstrumentToolbar->addAction(m_ui.editInstrumentAction);
49      m_pMapComboBox = new QComboBox(ui.InstrumentToolbar);          m_ui.InstrumentToolbar->addAction(m_ui.deleteInstrumentAction);
50      m_pMapComboBox->setMinimumWidth(120);          m_ui.InstrumentToolbar->addSeparator();
51      m_pMapComboBox->setEnabled(false);          m_ui.InstrumentToolbar->addAction(m_ui.refreshInstrumentsAction);
     QToolTip::add(m_pMapComboBox, tr("Instrument Map"));  
     ui.InstrumentToolbar->addWidget(m_pMapComboBox);  
   
     ui.InstrumentToolbar->addSeparator();  
     ui.newInstrumentAction->addTo(ui.InstrumentToolbar);  
     ui.editInstrumentAction->addTo(ui.InstrumentToolbar);  
     ui.deleteInstrumentAction->addTo(ui.InstrumentToolbar);  
     ui.InstrumentToolbar->addSeparator();  
     ui.refreshInstrumentsAction->addTo(ui.InstrumentToolbar);  
52    
53      ui.InstrumentTable->setModel(&model);          m_ui.InstrumentTable->setModel(&m_model);
54      ui.InstrumentTable->setItemDelegate(&delegate);          m_ui.InstrumentTable->setItemDelegate(&m_delegate);
55    
56          QObject::connect(m_pMapComboBox,          QObject::connect(m_pMapComboBox,
57                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
58                  SLOT(activateMap(int)));                  SLOT(activateMap(int)));
   
59          QObject::connect(          QObject::connect(
60                  ui.refreshInstrumentsAction,                  m_ui.refreshInstrumentsAction,
61                  SIGNAL(triggered()),                  SIGNAL(triggered()),
62                  SLOT(refreshInstruments(void))                  SLOT(refreshInstruments(void)));
63      );          QObject::connect(
64                    m_ui.InstrumentTable,
         connect(  
                 ui.InstrumentTable,  
65                  SIGNAL(activated(const QModelIndex&)),                  SIGNAL(activated(const QModelIndex&)),
66                  SLOT(editInstrument(const QModelIndex&))                  SLOT(editInstrument(const QModelIndex&)));
67          );          QObject::connect(
68          connect(                  m_ui.newInstrumentAction,
                 ui.newInstrumentAction,  
69                  SIGNAL(triggered()),                  SIGNAL(triggered()),
70                  SLOT(newInstrument())                  SLOT(newInstrument()));
71          );          QObject::connect(
72          connect(                  m_ui.deleteInstrumentAction,
                 ui.deleteInstrumentAction,  
73                  SIGNAL(triggered()),                  SIGNAL(triggered()),
74                  SLOT(deleteInstrument())                  SLOT(deleteInstrument()));
75          );          QObject::connect(
76          connect(                  m_ui.editInstrumentAction,
                 ui.editInstrumentAction,  
77                  SIGNAL(triggered()),                  SIGNAL(triggered()),
78                  SLOT(editInstrument())                  SLOT(editInstrument()));
79          );  
80            MainForm *pMainForm = MainForm::getInstance();
81            if (pMainForm) {
82                    QObject::connect(&m_model,
83                            SIGNAL(instrumentsChanged()),
84                            pMainForm, SLOT(sessionDirty()));
85            }
86  }  }
87    
88  InstrumentListForm::~InstrumentListForm() {  
89    InstrumentListForm::~InstrumentListForm (void)
90    {
91          delete m_pMapComboBox;          delete m_pMapComboBox;
92  }  }
93    
# Line 102  InstrumentListForm::~InstrumentListForm( Line 95  InstrumentListForm::~InstrumentListForm(
95  // Notify our parent that we're emerging.  // Notify our parent that we're emerging.
96  void InstrumentListForm::showEvent ( QShowEvent *pShowEvent )  void InstrumentListForm::showEvent ( QShowEvent *pShowEvent )
97  {  {
98          //MainForm* pMainForm = MainForm::getInstance();          MainForm* pMainForm = MainForm::getInstance();
99          //if (pMainForm)          if (pMainForm)
100          //      pMainForm->stabilizeForm();                  pMainForm->stabilizeForm();
101    
102          QWidget::showEvent(pShowEvent);          QWidget::showEvent(pShowEvent);
103  }  }
# Line 115  void InstrumentListForm::hideEvent ( QHi Line 108  void InstrumentListForm::hideEvent ( QHi
108  {  {
109          QWidget::hideEvent(pHideEvent);          QWidget::hideEvent(pHideEvent);
110    
111          //MainForm* pMainForm = MainForm::getInstance();          MainForm* pMainForm = MainForm::getInstance();
112          //if (pMainForm)          if (pMainForm)
113          //      pMainForm->stabilizeForm();                  pMainForm->stabilizeForm();
114    }
115    
116    
117    // Just about to notify main-window that we're closing.
118    void InstrumentListForm::closeEvent ( QCloseEvent * /*pCloseEvent*/ )
119    {
120            QWidget::hide();
121    
122            MainForm *pMainForm = MainForm::getInstance();
123            if (pMainForm)
124                    pMainForm->stabilizeForm();
125  }  }
126    
127    
# Line 133  void InstrumentListForm::refreshInstrume Line 137  void InstrumentListForm::refreshInstrume
137                  return;                  return;
138    
139          // Get/save current map selection...          // Get/save current map selection...
140          int iMap = m_pMapComboBox->currentItem();          int iMap = m_pMapComboBox->currentIndex();
141          if (iMap < 0 || m_pMapComboBox->count() < 2)          if (iMap < 0 || m_pMapComboBox->count() < 2)
142                  iMap = pOptions->iMidiMap + 1;                  iMap = pOptions->iMidiMap + 1;
143    
144          // Populate maps list.          // Populate maps list.
145          m_pMapComboBox->clear();          m_pMapComboBox->clear();
146          m_pMapComboBox->insertItem(tr("(All)"));          m_pMapComboBox->addItem(tr("(All)"));
147          m_pMapComboBox->insertStringList(qsamplerInstrument::getMapNames());          m_pMapComboBox->insertItems(1, qsamplerInstrument::getMapNames());
148    
149          // Adjust to saved selection...          // Adjust to saved selection...
150          if (iMap < 0 || iMap >= m_pMapComboBox->count())          if (iMap < 0 || iMap >= m_pMapComboBox->count())
151                  iMap = 0;                  iMap = 0;
152          m_pMapComboBox->setCurrentItem(iMap);          m_pMapComboBox->setCurrentIndex(iMap);
153          m_pMapComboBox->setEnabled(m_pMapComboBox->count() > 1);          m_pMapComboBox->setEnabled(m_pMapComboBox->count() > 1);
154    
155          activateMap(iMap);          activateMap(iMap);
# Line 167  void InstrumentListForm::activateMap ( i Line 171  void InstrumentListForm::activateMap ( i
171          if (iMidiMap >= 0)          if (iMidiMap >= 0)
172                  pOptions->iMidiMap = iMidiMap;                  pOptions->iMidiMap = iMidiMap;
173    
174          model.setMidiMap(iMidiMap);          m_model.setMidiMap(iMidiMap);
175          model.refresh();          m_model.refresh();
176  }  }
177    
178  void InstrumentListForm::editInstrument() {  
179          const QModelIndex index = ui.InstrumentTable->currentIndex();  void InstrumentListForm::editInstrument (void)
180          editInstrument(index);  {
181            editInstrument(m_ui.InstrumentTable->currentIndex());
182  }  }
183    
184  void InstrumentListForm::editInstrument(const QModelIndex& index) {  
185    void InstrumentListForm::editInstrument ( const QModelIndex& index )
186    {
187          if (!index.isValid() || !index.data(Qt::UserRole).isValid())          if (!index.isValid() || !index.data(Qt::UserRole).isValid())
188                  return;                  return;
189    
190          qsamplerInstrument* pInstrument =          qsamplerInstrument* pInstrument
191                  (qsamplerInstrument*) index.data(Qt::UserRole).value<void*>();                  = static_cast<qsamplerInstrument *> (
192                            index.data(Qt::UserRole).value<void *> ());
193    
194          if (!pInstrument) return;          if (pInstrument == NULL)
195                    return;
196    
197          // Save current key values...          // Save current key values...
198          qsamplerInstrument oldInstrument(*pInstrument);          qsamplerInstrument oldInstrument(*pInstrument);
# Line 203  void InstrumentListForm::editInstrument( Line 212  void InstrumentListForm::editInstrument(
212                          // Unmap old instance...                          // Unmap old instance...
213                          oldInstrument.unmapInstrument();                          oldInstrument.unmapInstrument();
214                          // correct the position of the instrument in the model                          // correct the position of the instrument in the model
215                          model.resort(*pInstrument);                          m_model.resort(*pInstrument);
216                  }                  }
217                  // Notify we've changes...                  // Notify we've changes...
218                  emit model.reset();                  emit m_model.reset();
219          }          }
220  }  }
221    
222  void InstrumentListForm::newInstrument() {  
223    void InstrumentListForm::newInstrument (void)
224    {
225          qsamplerInstrument instrument;          qsamplerInstrument instrument;
226    
227          InstrumentForm form(this);          InstrumentForm form(this);
228          form.setup(&instrument);          form.setup(&instrument);
229          if (!form.exec()) return;          if (!form.exec())
230                    return;
231    
232          // Commit...          // Commit...
233          instrument.mapInstrument();          instrument.mapInstrument();
234          // add new item to the table model          // add new item to the table model
235          model.resort(instrument);          m_model.resort(instrument);
236          // Notify we've changes...          // Notify we've changes...
237          //emit model.reset();          //emit model.reset();
238          //FIXME: call above didnt really refresh, so we use this for now ...          //FIXME: call above didnt really refresh, so we use this for now ...
239          refreshInstruments();          refreshInstruments();
240  }  }
241    
242  void InstrumentListForm::deleteInstrument() {  
243          const QModelIndex index = ui.InstrumentTable->currentIndex();  void InstrumentListForm::deleteInstrument (void)
244          if (!index.isValid() || !index.data(Qt::UserRole).isValid()) return;  {
245            const QModelIndex& index = m_ui.InstrumentTable->currentIndex();
246            if (!index.isValid() || !index.data(Qt::UserRole).isValid())
247                    return;
248    
249          qsamplerInstrument* pInstrument =          qsamplerInstrument* pInstrument =
250                  (qsamplerInstrument*) index.data(Qt::UserRole).value<void*>();                  static_cast<qsamplerInstrument*> (
251                            index.data(Qt::UserRole).value<void *> ());
252    
253          if (!pInstrument) return;          if (pInstrument == NULL)
254                    return;
255    
256          pInstrument->unmapInstrument();          pInstrument->unmapInstrument();
257          // let the instrument vanish from the table model          // let the instrument vanish from the table model
258          model.removeInstrument(*pInstrument);          m_model.removeInstrument(*pInstrument);
259          // Notify we've changes...          // Notify we've changes...
260          emit model.reset();          emit m_model.reset();
261  }  }
262    
263  } // namespace QSampler  } // namespace QSampler

Legend:
Removed from v.1492  
changed lines
  Added in v.1509

  ViewVC Help
Powered by ViewVC