/[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 1464 by capela, Thu Nov 1 17:14:21 2007 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-2007, 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 20  Line 20 
20    
21  *****************************************************************************/  *****************************************************************************/
22    
23    #include "qsamplerAbout.h"
24  #include "qsamplerInstrumentListForm.h"  #include "qsamplerInstrumentListForm.h"
25    
26  #include "qsamplerMainForm.h"  #include "qsamplerInstrumentList.h"
27    
28    #include "qsamplerInstrumentForm.h"
29    
30  #include "qsamplerOptions.h"  #include "qsamplerOptions.h"
31  #include "qsamplerInstrument.h"  #include "qsamplerInstrument.h"
32    #include "qsamplerMainForm.h"
33    
34    #include <QHeaderView>
35    #include <QMessageBox>
36    #include <QContextMenuEvent>
37    
38    #include <QCheckBox>
39    
 #include <QToolTip>  
40    
41  namespace QSampler {  namespace QSampler {
42    
43  InstrumentListForm::InstrumentListForm(QWidget* parent, Qt::WindowFlags flags) : QMainWindow(parent, flags) {  //-------------------------------------------------------------------------
44      ui.setupUi(this);  // QSampler::InstrumentListForm -- Instrument map list form implementation.
45    //
46    
47    InstrumentListForm::InstrumentListForm (
48            QWidget* pParent, Qt::WindowFlags wflags )
49            : QMainWindow(pParent, wflags)
50    {
51            m_ui.setupUi(this);
52    
53      ui.newInstrumentAction->setText(tr("New &Instrument..."));          m_pInstrumentListView = new InstrumentListView(this);
54      ui.newInstrumentAction->setShortcut(Qt::Key_Insert);          QMainWindow::setCentralWidget(m_pInstrumentListView);
     ui.editInstrumentAction->setText(tr("&Edit..."));  
     ui.editInstrumentAction->setShortcut(Qt::Key_Enter);  
     ui.deleteInstrumentAction->setText(tr("&Delete"));  
     ui.deleteInstrumentAction->setShortcut(Qt::Key_Delete);  
     ui.refreshInstrumentsAction->setText(tr("&Refresh"));  
     ui.refreshInstrumentsAction->setShortcut(Qt::Key_F5);  
   
     // Setup toolbar widgets.  
     InstrumentToolbar = addToolBar(tr("MIDI Instruments"));  
     m_pMapComboBox = new QComboBox(InstrumentToolbar);  
     m_pMapComboBox->setMinimumWidth(120);  
     m_pMapComboBox->setEnabled(false);  
     QToolTip::add(m_pMapComboBox, tr("Instrument Map"));  
   
     InstrumentToolbar->addSeparator();  
     ui.newInstrumentAction->addTo(InstrumentToolbar);  
     ui.editInstrumentAction->addTo(InstrumentToolbar);  
     ui.deleteInstrumentAction->addTo(InstrumentToolbar);  
     InstrumentToolbar->addSeparator();  
     ui.refreshInstrumentsAction->addTo(InstrumentToolbar);  
55    
56      ui.InstrumentTable->setModel(&model);          // Setup toolbar widgets.
57      //ui.InstrumentTable->setDelegate(delegate);          m_pMapComboBox = new QComboBox(m_ui.instrumentToolbar);
58            m_pMapComboBox->setMinimumWidth(120);
59            m_pMapComboBox->setEnabled(false);
60            m_pMapComboBox->setToolTip(tr("Instrument Map"));
61            
62            m_ui.instrumentToolbar->addWidget(m_pMapComboBox);
63            m_ui.instrumentToolbar->addSeparator();
64            m_ui.instrumentToolbar->addAction(m_ui.newInstrumentAction);
65            m_ui.instrumentToolbar->addAction(m_ui.editInstrumentAction);
66            m_ui.instrumentToolbar->addAction(m_ui.deleteInstrumentAction);
67            m_ui.instrumentToolbar->addSeparator();
68            m_ui.instrumentToolbar->addAction(m_ui.refreshInstrumentsAction);
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(m_pInstrumentListView->selectionModel(),
74                    SIGNAL(currentRowChanged(const QModelIndex&,const QModelIndex&)),
75                    SLOT(stabilizeForm()));
76            QObject::connect(
77                    m_pInstrumentListView,
78                    SIGNAL(activated(const QModelIndex&)),
79                    SLOT(editInstrument(const QModelIndex&)));
80            QObject::connect(
81                    m_ui.newInstrumentAction,
82                    SIGNAL(triggered()),
83                    SLOT(newInstrument()));
84            QObject::connect(
85                    m_ui.deleteInstrumentAction,
86                    SIGNAL(triggered()),
87                    SLOT(deleteInstrument()));
88            QObject::connect(
89                    m_ui.editInstrumentAction,
90                    SIGNAL(triggered()),
91                    SLOT(editInstrument()));
92            QObject::connect(
93                    m_ui.refreshInstrumentsAction,
94                    SIGNAL(triggered()),
95                    SLOT(refreshInstruments()));
96    
97      connect(          // Things must be stable from the start.
98          ui.refreshInstrumentsAction,          stabilizeForm();
         SIGNAL(triggered()), SLOT(refreshInstruments(void))  
     );  
99  }  }
100    
101  InstrumentListForm::~InstrumentListForm() {  
102    InstrumentListForm::~InstrumentListForm (void)
103    {
104          delete m_pMapComboBox;          delete m_pMapComboBox;
105            delete m_pInstrumentListView;
106  }  }
107    
108    
109  // Notify our parent that we're emerging.  // Notify our parent that we're emerging.
110  void InstrumentListForm::showEvent ( QShowEvent *pShowEvent )  void InstrumentListForm::showEvent ( QShowEvent *pShowEvent )
111  {  {
112          //MainForm* pMainForm = MainForm::getInstance();          MainForm* pMainForm = MainForm::getInstance();
113          //if (pMainForm)          if (pMainForm)
114          //      pMainForm->stabilizeForm();                  pMainForm->stabilizeForm();
115    
116          QWidget::showEvent(pShowEvent);          QWidget::showEvent(pShowEvent);
117  }  }
# Line 90  void InstrumentListForm::hideEvent ( QHi Line 122  void InstrumentListForm::hideEvent ( QHi
122  {  {
123          QWidget::hideEvent(pHideEvent);          QWidget::hideEvent(pHideEvent);
124    
125          //MainForm* pMainForm = MainForm::getInstance();          MainForm* pMainForm = MainForm::getInstance();
126          //if (pMainForm)          if (pMainForm)
127          //      pMainForm->stabilizeForm();                  pMainForm->stabilizeForm();
128    }
129    
130    
131    // Just about to notify main-window that we're closing.
132    void InstrumentListForm::closeEvent ( QCloseEvent * /*pCloseEvent*/ )
133    {
134            QWidget::hide();
135    
136            MainForm *pMainForm = MainForm::getInstance();
137            if (pMainForm)
138                    pMainForm->stabilizeForm();
139  }  }
140    
141    
# Line 103  void InstrumentListForm::refreshInstrume Line 146  void InstrumentListForm::refreshInstrume
146          if (pMainForm == NULL)          if (pMainForm == NULL)
147                  return;                  return;
148    
149          qsamplerOptions *pOptions = pMainForm->options();          Options *pOptions = pMainForm->options();
150          if (pOptions == NULL)          if (pOptions == NULL)
151                  return;                  return;
152    
153          // Get/save current map selection...          // Get/save current map selection...
154          int iMap = m_pMapComboBox->currentItem();          int iMap = m_pMapComboBox->currentIndex();
155          if (iMap < 0 || m_pMapComboBox->count() < 2)          if (iMap < 0 || m_pMapComboBox->count() < 2)
156                  iMap = pOptions->iMidiMap + 1;                  iMap = pOptions->iMidiMap + 1;
157    
158          // Populate maps list.          // Populate maps list.
159          m_pMapComboBox->clear();          m_pMapComboBox->clear();
160          m_pMapComboBox->insertItem(tr("(All)"));          m_pMapComboBox->addItem(tr("(All)"));
161          m_pMapComboBox->insertStringList(qsamplerInstrument::getMapNames());          m_pMapComboBox->insertItems(1, Instrument::getMapNames());
162    
163          // Adjust to saved selection...          // Adjust to saved selection...
164          if (iMap < 0 || iMap >= m_pMapComboBox->count())          if (iMap < 0 || iMap >= m_pMapComboBox->count())
165                  iMap = 0;                  iMap = 0;
166          m_pMapComboBox->setCurrentItem(iMap);          m_pMapComboBox->setCurrentIndex(iMap);
167          m_pMapComboBox->setEnabled(m_pMapComboBox->count() > 1);          m_pMapComboBox->setEnabled(m_pMapComboBox->count() > 1);
168    
169          activateMap(iMap);          activateMap(iMap);
# Line 134  void InstrumentListForm::activateMap ( i Line 177  void InstrumentListForm::activateMap ( i
177          if (pMainForm == NULL)          if (pMainForm == NULL)
178                  return;                  return;
179    
180          qsamplerOptions *pOptions = pMainForm->options();          Options *pOptions = pMainForm->options();
181          if (pOptions == NULL)          if (pOptions == NULL)
182                  return;                  return;
183    
# Line 142  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          model.setMidiMap(iMidiMap);          m_pInstrumentListView->setMidiMap(iMidiMap);
189          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();
214    }
215    
216    
217    void InstrumentListForm::editInstrument (void)
218    {
219            editInstrument(m_pInstrumentListView->currentIndex());
220    }
221    
222    
223    void InstrumentListForm::editInstrument ( const QModelIndex& index )
224    {
225            if (!index.isValid())
226                    return;
227    
228            Instrument *pInstrument
229                    = static_cast<Instrument *> (index.internalPointer());
230            if (pInstrument == NULL)
231                    return;
232    
233            // Save current key values...
234            int iMap  = pInstrument->map();
235            int iBank = pInstrument->bank();
236            int iProg = pInstrument->prog();
237    
238            Instrument instrument(iMap, iBank, iProg);
239    
240            // Do the edit dance...
241            InstrumentForm form(this);
242            form.setup(pInstrument);
243            if (!form.exec())
244                    return;
245            
246            // Commit...
247            pInstrument->mapInstrument();
248    
249            // Check whether we changed instrument key...
250            if (pInstrument->map()  == iMap  &&
251                    pInstrument->bank() == iBank &&
252                    pInstrument->prog() == iProg) {
253                    // 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)
267    {
268            const QModelIndex& index = m_pInstrumentListView->currentIndex();
269            if (!index.isValid())
270                    return;
271    
272            Instrument *pInstrument
273                    = static_cast<Instrument *> (index.internalPointer());
274            if (pInstrument == NULL)
275                    return;
276    
277            MainForm *pMainForm = MainForm::getInstance();
278            if (pMainForm == NULL)
279                    return;
280    
281            // Prompt user if this is for real...
282            Options *pOptions = pMainForm->options();
283            if (pOptions && pOptions->bConfirmRemove) {
284                    const QString& sTitle = QSAMPLER_TITLE ": " + tr("Warning");
285                    const QString& sText = tr(
286                            "About to delete instrument map entry:\n\n"
287                            "%1\n\n"
288                            "Are you sure?")
289                            .arg(pInstrument->name());
290             #if 0
291                     if (QMessageBox::warning(this, sTitle, sText,
292                             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();
312    
313            // Let the instrument vanish from the table model...
314            m_pInstrumentListView->removeInstrument(pInstrument);
315    
316            stabilizeForm();
317  }  }
318    
319    
320    // Update form actions enablement...
321    void InstrumentListForm::stabilizeForm (void)
322    {
323            MainForm *pMainForm = MainForm::getInstance();
324    
325            bool bEnabled = (pMainForm && pMainForm->client());
326            m_ui.newInstrumentAction->setEnabled(bEnabled);
327            const QModelIndex& index = m_pInstrumentListView->currentIndex();
328            bEnabled = (bEnabled && index.isValid());
329            m_ui.editInstrumentAction->setEnabled(bEnabled);
330            m_ui.deleteInstrumentAction->setEnabled(bEnabled);
331    }
332    
333    
334    // Context menu request.
335    void InstrumentListForm::contextMenuEvent (
336            QContextMenuEvent *pContextMenuEvent )
337    {
338            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            menu.exec(pContextMenuEvent->globalPos());
348    }
349    
350    
351  } // namespace QSampler  } // namespace QSampler
352    
353    

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

  ViewVC Help
Powered by ViewVC