--- qsampler/trunk/src/qsamplerInstrumentListForm.cpp 2009/02/19 11:44:57 1840 +++ qsampler/trunk/src/qsamplerInstrumentListForm.cpp 2010/03/13 12:44:15 2065 @@ -1,7 +1,7 @@ // qsamplerInstrumentListForm.cpp // /**************************************************************************** - Copyright (C) 2003-2009, rncbc aka Rui Nuno Capela. All rights reserved. + Copyright (C) 2003-2010, rncbc aka Rui Nuno Capela. All rights reserved. Copyright (C) 2007, Christian Schoenebeck This program is free software; you can redistribute it and/or @@ -23,6 +23,8 @@ #include "qsamplerAbout.h" #include "qsamplerInstrumentListForm.h" +#include "qsamplerInstrumentList.h" + #include "qsamplerInstrumentForm.h" #include "qsamplerOptions.h" @@ -46,56 +48,37 @@ m_ui.setupUi(this); // 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); - - int iRowHeight = m_ui.InstrumentTable->fontMetrics().height() + 4; - m_ui.InstrumentTable->verticalHeader()->setDefaultSectionSize(iRowHeight); - - m_ui.InstrumentTable->setModel(&m_model); - m_ui.InstrumentTable->setItemDelegate(&m_delegate); - m_ui.InstrumentTable->verticalHeader()->hide(); - - QHeaderView *pHeader = m_ui.InstrumentTable->horizontalHeader(); - pHeader->setDefaultAlignment(Qt::AlignLeft); - pHeader->setMovable(false); - pHeader->setStretchLastSection(true); - pHeader->resizeSection(0, 120); // Name - m_ui.InstrumentTable->resizeColumnToContents(1); // Map - m_ui.InstrumentTable->resizeColumnToContents(2); // Bank - m_ui.InstrumentTable->resizeColumnToContents(3); // Prog - m_ui.InstrumentTable->resizeColumnToContents(4); // Engine - pHeader->resizeSection(5, 240); // File - m_ui.InstrumentTable->resizeColumnToContents(6); // Nr - pHeader->resizeSection(7, 60); // Vol + m_ui.instrumentToolbar->addWidget(m_pMapComboBox); - // Enable custom context menu... - m_ui.InstrumentTable->setContextMenuPolicy(Qt::CustomContextMenu); + 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); + m_pInstrumentListView->setContextMenuPolicy(Qt::CustomContextMenu); + QMainWindow::setCentralWidget(m_pInstrumentListView); QObject::connect(m_pMapComboBox, SIGNAL(activated(int)), SLOT(activateMap(int))); QObject::connect( - m_ui.InstrumentTable, + m_pInstrumentListView, SIGNAL(customContextMenuRequested(const QPoint&)), SLOT(contextMenu(const QPoint&))); QObject::connect( - m_ui.InstrumentTable, - SIGNAL(pressed(const QModelIndex&)), + m_pInstrumentListView, + SIGNAL(activated(const QModelIndex&)), SLOT(stabilizeForm())); QObject::connect( - m_ui.InstrumentTable, - SIGNAL(activated(const QModelIndex&)), + m_pInstrumentListView, + SIGNAL(doubleClicked(const QModelIndex&)), SLOT(editInstrument(const QModelIndex&))); QObject::connect( m_ui.newInstrumentAction, @@ -114,13 +97,6 @@ SIGNAL(triggered()), SLOT(refreshInstruments())); - MainForm *pMainForm = MainForm::getInstance(); - if (pMainForm) { - QObject::connect(&m_model, - SIGNAL(instrumentsChanged()), - pMainForm, SLOT(sessionDirty())); - } - // Things must be stable from the start. stabilizeForm(); } @@ -128,6 +104,7 @@ InstrumentListForm::~InstrumentListForm (void) { + delete m_pInstrumentListView; delete m_pMapComboBox; } @@ -211,8 +188,8 @@ if (iMidiMap >= 0) pOptions->iMidiMap = iMidiMap; - m_model.setMidiMap(iMidiMap); - m_model.refresh(); + m_pInstrumentListView->setMidiMap(iMidiMap); + m_pInstrumentListView->refresh(); stabilizeForm(); } @@ -220,45 +197,48 @@ void InstrumentListForm::editInstrument (void) { - editInstrument(m_ui.InstrumentTable->currentIndex()); + editInstrument(m_pInstrumentListView->currentIndex()); } void InstrumentListForm::editInstrument ( const QModelIndex& index ) { - if (!index.isValid() || !index.data(Qt::UserRole).isValid()) + if (!index.isValid()) return; - Instrument* pInstrument - = static_cast ( - index.data(Qt::UserRole).value ()); - + Instrument *pInstrument + = static_cast (index.internalPointer()); if (pInstrument == NULL) return; // Save current key values... - Instrument oldInstrument(*pInstrument); + 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); + form.setup(&instrument); if (form.exec()) { // Commit... - pInstrument->mapInstrument(); + instrument.mapInstrument(); // Check whether we changed instrument key... - if (oldInstrument.map() == pInstrument->map() && - oldInstrument.bank() == pInstrument->bank() && - oldInstrument.prog() == pInstrument->prog()) { + if (instrument.map() == iMap && + instrument.bank() == iBank && + instrument.prog() == iProg) { // Just update tree item... //pItem->update(); } else { // Unmap old instance... - oldInstrument.unmapInstrument(); + Instrument(iMap, iBank, iProg).unmapInstrument(); // correct the position of the instrument in the model - m_model.resort(*pInstrument); + m_pInstrumentListView->updateInstrument(pInstrument); } - // Notify we've changes... - emit m_model.reset(); } + + stabilizeForm(); } @@ -273,25 +253,25 @@ // Commit... instrument.mapInstrument(); + // add new item to the table model - m_model.resort(instrument); - // Notify we've changes... - //emit model.reset(); - //FIXME: call above didnt really refresh, so we use this for now ... - refreshInstruments(); + m_pInstrumentListView->addInstrument( + instrument.map(), + instrument.bank(), + instrument.prog()); + + stabilizeForm(); } void InstrumentListForm::deleteInstrument (void) { - const QModelIndex& index = m_ui.InstrumentTable->currentIndex(); - if (!index.isValid() || !index.data(Qt::UserRole).isValid()) + const QModelIndex& index = m_pInstrumentListView->currentIndex(); + if (!index.isValid()) return; - Instrument *pInstrument = - static_cast ( - index.data(Qt::UserRole).value ()); - + Instrument *pInstrument + = static_cast (index.internalPointer()); if (pInstrument == NULL) return; @@ -314,10 +294,11 @@ } pInstrument->unmapInstrument(); + // let the instrument vanish from the table model - m_model.removeInstrument(*pInstrument); - // Notify we've changes... - emit m_model.reset(); + m_pInstrumentListView->removeInstrument(pInstrument); + + stabilizeForm(); } @@ -328,7 +309,7 @@ bool bEnabled = (pMainForm && pMainForm->client()); m_ui.newInstrumentAction->setEnabled(bEnabled); - const QModelIndex& index = m_ui.InstrumentTable->currentIndex(); + const QModelIndex& index = m_pInstrumentListView->currentIndex(); bEnabled = (bEnabled && index.isValid()); m_ui.editInstrumentAction->setEnabled(bEnabled); m_ui.deleteInstrumentAction->setEnabled(bEnabled); @@ -342,7 +323,7 @@ return; m_ui.contextMenu->exec( - (m_ui.InstrumentTable->viewport())->mapToGlobal(pos)); + (m_pInstrumentListView->viewport())->mapToGlobal(pos)); }