--- qsampler/trunk/src/qsamplerInstrumentListForm.cpp 2010/03/12 16:02:32 2064 +++ qsampler/trunk/src/qsamplerInstrumentListForm.cpp 2010/03/15 18:21:28 2071 @@ -33,6 +33,7 @@ #include #include +#include namespace QSampler { @@ -47,50 +48,28 @@ { m_ui.setupUi(this); + m_pInstrumentListView = new InstrumentListView(this); + QMainWindow::setCentralWidget(m_pInstrumentListView); + // Setup toolbar widgets. - m_pMapComboBox = new QComboBox(m_ui.InstrumentToolbar); + m_pMapComboBox = new QComboBox(m_ui.instrumentToolbar); m_pMapComboBox->setMinimumWidth(120); m_pMapComboBox->setEnabled(false); m_pMapComboBox->setToolTip(tr("Instrument Map")); - m_ui.InstrumentToolbar->addWidget(m_pMapComboBox); - - m_ui.InstrumentToolbar->addSeparator(); - m_ui.InstrumentToolbar->addAction(m_ui.newInstrumentAction); - m_ui.InstrumentToolbar->addAction(m_ui.editInstrumentAction); - m_ui.InstrumentToolbar->addAction(m_ui.deleteInstrumentAction); - m_ui.InstrumentToolbar->addSeparator(); - m_ui.InstrumentToolbar->addAction(m_ui.refreshInstrumentsAction); - - m_pInstrumentListView = new InstrumentListView(this); - - QHeaderView *pHeader = m_pInstrumentListView->header(); - pHeader->setDefaultAlignment(Qt::AlignLeft); - pHeader->setMovable(false); - pHeader->setStretchLastSection(true); - pHeader->resizeSection(0, 120); // Name - m_pInstrumentListView->resizeColumnToContents(1); // Map - m_pInstrumentListView->resizeColumnToContents(2); // Bank - m_pInstrumentListView->resizeColumnToContents(3); // Prog - m_pInstrumentListView->resizeColumnToContents(4); // Engine - pHeader->resizeSection(5, 240); // File - m_pInstrumentListView->resizeColumnToContents(6); // Nr - pHeader->resizeSection(7, 60); // Vol - - // Enable custom context menu... - m_pInstrumentListView->setContextMenuPolicy(Qt::CustomContextMenu); - - QMainWindow::setCentralWidget(m_pInstrumentListView); + + m_ui.instrumentToolbar->addWidget(m_pMapComboBox); + m_ui.instrumentToolbar->addSeparator(); + m_ui.instrumentToolbar->addAction(m_ui.newInstrumentAction); + m_ui.instrumentToolbar->addAction(m_ui.editInstrumentAction); + m_ui.instrumentToolbar->addAction(m_ui.deleteInstrumentAction); + m_ui.instrumentToolbar->addSeparator(); + m_ui.instrumentToolbar->addAction(m_ui.refreshInstrumentsAction); QObject::connect(m_pMapComboBox, SIGNAL(activated(int)), SLOT(activateMap(int))); - QObject::connect( - m_pInstrumentListView, - SIGNAL(customContextMenuRequested(const QPoint&)), - SLOT(contextMenu(const QPoint&))); - QObject::connect( - m_pInstrumentListView, - SIGNAL(pressed(const QModelIndex&)), + QObject::connect(m_pInstrumentListView->selectionModel(), + SIGNAL(currentRowChanged(const QModelIndex&,const QModelIndex&)), SLOT(stabilizeForm())); QObject::connect( m_pInstrumentListView, @@ -120,8 +99,8 @@ InstrumentListForm::~InstrumentListForm (void) { - delete m_pInstrumentListView; delete m_pMapComboBox; + delete m_pInstrumentListView; } @@ -211,6 +190,28 @@ } +void InstrumentListForm::newInstrument (void) +{ + Instrument instrument; + + InstrumentForm form(this); + form.setup(&instrument); + if (!form.exec()) + return; + + // Commit... + instrument.mapInstrument(); + + // add new item to the table model + m_pInstrumentListView->addInstrument( + instrument.map(), + instrument.bank(), + instrument.prog()); + + stabilizeForm(); +} + + void InstrumentListForm::editInstrument (void) { editInstrument(m_pInstrumentListView->currentIndex()); @@ -227,54 +228,36 @@ if (pInstrument == NULL) return; - if (pInstrument == NULL) - return; - // Save current key values... - Instrument oldInstrument( - pInstrument->map(), - pInstrument->bank(), - pInstrument->prog()); + int iMap = pInstrument->map(); + int iBank = pInstrument->bank(); + int iProg = pInstrument->prog(); + + Instrument instrument(iMap, iBank, iProg); // Do the edit dance... InstrumentForm form(this); form.setup(pInstrument); - if (form.exec()) { - // Commit... - pInstrument->mapInstrument(); - // Check whether we changed instrument key... - if (oldInstrument.map() == pInstrument->map() && - oldInstrument.bank() == pInstrument->bank() && - oldInstrument.prog() == pInstrument->prog()) { - // Just update tree item... - //pItem->update(); - } else { - // Unmap old instance... - oldInstrument.unmapInstrument(); - // correct the position of the instrument in the model - m_pInstrumentListView->updateInstrument(pInstrument); - } - } -} - - -void InstrumentListForm::newInstrument (void) -{ - Instrument instrument; - - InstrumentForm form(this); - form.setup(&instrument); if (!form.exec()) return; - + // Commit... - instrument.mapInstrument(); + pInstrument->mapInstrument(); - // add new item to the table model - m_pInstrumentListView->addInstrument( - instrument.map(), - instrument.bank(), - instrument.prog()); + // Check whether we changed instrument key... + if (pInstrument->map() == iMap && + pInstrument->bank() == iBank && + pInstrument->prog() == iProg) { + // Just update tree item... + m_pInstrumentListView->updateInstrument(pInstrument); + } else { + // Unmap old instance... + instrument.unmapInstrument(); + // Correct the position of the instrument in the model + m_pInstrumentListView->resortInstrument(pInstrument); + } + + stabilizeForm(); } @@ -309,8 +292,10 @@ pInstrument->unmapInstrument(); - // let the instrument vanish from the table model + // Let the instrument vanish from the table model... m_pInstrumentListView->removeInstrument(pInstrument); + + stabilizeForm(); } @@ -328,14 +313,20 @@ } -// Handle custom context menu here... -void InstrumentListForm::contextMenu ( const QPoint& pos ) -{ - if (!m_ui.newInstrumentAction->isEnabled()) - return; +// Context menu request. +void InstrumentListForm::contextMenuEvent ( + QContextMenuEvent *pContextMenuEvent ) +{ + QMenu menu(this); + + menu.addAction(m_ui.newInstrumentAction); + menu.addSeparator(); + menu.addAction(m_ui.editInstrumentAction); + menu.addAction(m_ui.deleteInstrumentAction); + menu.addSeparator(); + menu.addAction(m_ui.refreshInstrumentsAction); - m_ui.contextMenu->exec( - (m_pInstrumentListView->viewport())->mapToGlobal(pos)); + menu.exec(pContextMenuEvent->globalPos()); }