/[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 1528 by capela, Mon Nov 26 18:24:38 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 {
# Line 34  InstrumentListForm::InstrumentListForm ( Line 39  InstrumentListForm::InstrumentListForm (
39          QWidget* pParent, Qt::WindowFlags wflags )          QWidget* pParent, Qt::WindowFlags wflags )
40          : QMainWindow(pParent, wflags)          : QMainWindow(pParent, wflags)
41  {  {
42      ui.setupUi(this);          m_ui.setupUi(this);
43    
44      // Setup toolbar widgets.          // Setup toolbar widgets.
45      m_pMapComboBox = new QComboBox(ui.InstrumentToolbar);          m_pMapComboBox = new QComboBox(m_ui.InstrumentToolbar);
46      m_pMapComboBox->setMinimumWidth(120);          m_pMapComboBox->setMinimumWidth(120);
47      m_pMapComboBox->setEnabled(false);          m_pMapComboBox->setEnabled(false);
48      m_pMapComboBox->setToolTip(tr("Instrument Map"));          m_pMapComboBox->setToolTip(tr("Instrument Map"));
49      ui.InstrumentToolbar->addWidget(m_pMapComboBox);          m_ui.InstrumentToolbar->addWidget(m_pMapComboBox);
50    
51      ui.InstrumentToolbar->addSeparator();          m_ui.InstrumentToolbar->addSeparator();
52      ui.InstrumentToolbar->addAction(ui.newInstrumentAction);          m_ui.InstrumentToolbar->addAction(m_ui.newInstrumentAction);
53      ui.InstrumentToolbar->addAction(ui.editInstrumentAction);          m_ui.InstrumentToolbar->addAction(m_ui.editInstrumentAction);
54      ui.InstrumentToolbar->addAction(ui.deleteInstrumentAction);          m_ui.InstrumentToolbar->addAction(m_ui.deleteInstrumentAction);
55      ui.InstrumentToolbar->addSeparator();          m_ui.InstrumentToolbar->addSeparator();
56      ui.InstrumentToolbar->addAction(ui.refreshInstrumentsAction);          m_ui.InstrumentToolbar->addAction(m_ui.refreshInstrumentsAction);
57    
58            int iRowHeight = m_ui.InstrumentTable->fontMetrics().height() + 4;
59            m_ui.InstrumentTable->verticalHeader()->setDefaultSectionSize(iRowHeight);
60    
61            m_ui.InstrumentTable->setModel(&m_model);
62            m_ui.InstrumentTable->setItemDelegate(&m_delegate);
63            m_ui.InstrumentTable->verticalHeader()->hide();
64    
65            QHeaderView *pHeader = m_ui.InstrumentTable->horizontalHeader();
66            pHeader->setDefaultAlignment(Qt::AlignLeft);
67            pHeader->setMovable(false);
68            pHeader->setStretchLastSection(true);
69            pHeader->resizeSection(0, 120);                                         // Name
70            m_ui.InstrumentTable->resizeColumnToContents(1);        // Map
71            m_ui.InstrumentTable->resizeColumnToContents(2);        // Bank
72            m_ui.InstrumentTable->resizeColumnToContents(3);        // Prog
73            m_ui.InstrumentTable->resizeColumnToContents(4);        // Engine
74            pHeader->resizeSection(5, 240);                                         // File
75            m_ui.InstrumentTable->resizeColumnToContents(6);        // Nr
76            pHeader->resizeSection(7, 60);                                          // Vol
77    
78      ui.InstrumentTable->setModel(&model);          // Enable custom context menu...
79      ui.InstrumentTable->setItemDelegate(&delegate);          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                  ui.refreshInstrumentsAction,                  m_ui.InstrumentTable,
86                  SIGNAL(triggered()),                  SIGNAL(customContextMenuRequested(const QPoint&)),
87                  SLOT(refreshInstruments(void))                  SLOT(contextMenu(const QPoint&)));
     );  
   
88          QObject::connect(          QObject::connect(
89                  ui.InstrumentTable,                  m_ui.InstrumentTable,
90                    SIGNAL(pressed(const QModelIndex&)),
91                    SLOT(stabilizeForm()));
92            QObject::connect(
93                    m_ui.InstrumentTable,
94                  SIGNAL(activated(const QModelIndex&)),                  SIGNAL(activated(const QModelIndex&)),
95                  SLOT(editInstrument(const QModelIndex&))                  SLOT(editInstrument(const QModelIndex&)));
96          );          QObject::connect(
97                    m_ui.newInstrumentAction,
98                    SIGNAL(triggered()),
99                    SLOT(newInstrument()));
100          QObject::connect(          QObject::connect(
101                  ui.newInstrumentAction,                  m_ui.deleteInstrumentAction,
102                  SIGNAL(triggered()),                  SIGNAL(triggered()),
103                  SLOT(newInstrument())                  SLOT(deleteInstrument()));
         );  
104          QObject::connect(          QObject::connect(
105                  ui.deleteInstrumentAction,                  m_ui.editInstrumentAction,
106                  SIGNAL(triggered()),                  SIGNAL(triggered()),
107                  SLOT(deleteInstrument())                  SLOT(editInstrument()));
         );  
108          QObject::connect(          QObject::connect(
109                  ui.editInstrumentAction,                  m_ui.refreshInstrumentsAction,
110                  SIGNAL(triggered()),                  SIGNAL(triggered()),
111                  SLOT(editInstrument())                  SLOT(refreshInstruments()));
112          );  
113            MainForm *pMainForm = MainForm::getInstance();
114            if (pMainForm) {
115                    QObject::connect(&m_model,
116                            SIGNAL(instrumentsChanged()),
117                            pMainForm, SLOT(sessionDirty()));
118            }
119    
120            // Things must be stable from the start.
121            stabilizeForm();
122  }  }
123    
124    
# Line 171  void InstrumentListForm::activateMap ( i Line 207  void InstrumentListForm::activateMap ( i
207          if (iMidiMap >= 0)          if (iMidiMap >= 0)
208                  pOptions->iMidiMap = iMidiMap;                  pOptions->iMidiMap = iMidiMap;
209    
210          model.setMidiMap(iMidiMap);          m_model.setMidiMap(iMidiMap);
211          model.refresh();          m_model.refresh();
212    
213            stabilizeForm();
214  }  }
215    
216    
217  void InstrumentListForm::editInstrument (void)  void InstrumentListForm::editInstrument (void)
218  {  {
219          editInstrument(ui.InstrumentTable->currentIndex());          editInstrument(m_ui.InstrumentTable->currentIndex());
220  }  }
221    
222    
# Line 206  void InstrumentListForm::editInstrument Line 244  void InstrumentListForm::editInstrument
244                  if (oldInstrument.map()  == pInstrument->map()  &&                  if (oldInstrument.map()  == pInstrument->map()  &&
245                          oldInstrument.bank() == pInstrument->bank() &&                          oldInstrument.bank() == pInstrument->bank() &&
246                          oldInstrument.prog() == pInstrument->prog()) {                          oldInstrument.prog() == pInstrument->prog()) {
247                          // just update tree item...                          // Just update tree item...
248                          //pItem->update();                          //pItem->update();
249                  } else {                  } else {
250                          // Unmap old instance...                          // Unmap old instance...
251                          oldInstrument.unmapInstrument();                          oldInstrument.unmapInstrument();
252                          // correct the position of the instrument in the model                          // correct the position of the instrument in the model
253                          model.resort(*pInstrument);                          m_model.resort(*pInstrument);
254                  }                  }
255                  // Notify we've changes...                  // Notify we've changes...
256                  emit model.reset();                  emit m_model.reset();
257          }          }
258  }  }
259    
# Line 232  void InstrumentListForm::newInstrument ( Line 270  void InstrumentListForm::newInstrument (
270          // Commit...          // Commit...
271          instrument.mapInstrument();          instrument.mapInstrument();
272          // add new item to the table model          // add new item to the table model
273          model.resort(instrument);          m_model.resort(instrument);
274          // Notify we've changes...          // Notify we've changes...
275          //emit model.reset();          //emit model.reset();
276          //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 280  void InstrumentListForm::newInstrument (
280    
281  void InstrumentListForm::deleteInstrument (void)  void InstrumentListForm::deleteInstrument (void)
282  {  {
283          const QModelIndex& index = ui.InstrumentTable->currentIndex();          const QModelIndex& index = m_ui.InstrumentTable->currentIndex();
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          model.removeInstrument(*pInstrument);          m_model.removeInstrument(*pInstrument);
314          // Notify we've changes...          // Notify we've changes...
315          emit 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.1504  
changed lines
  Added in v.1528

  ViewVC Help
Powered by ViewVC