33 |
|
|
34 |
#include <QHeaderView> |
#include <QHeaderView> |
35 |
#include <QMessageBox> |
#include <QMessageBox> |
36 |
|
#include <QContextMenuEvent> |
37 |
|
|
38 |
|
|
39 |
namespace QSampler { |
namespace QSampler { |
48 |
{ |
{ |
49 |
m_ui.setupUi(this); |
m_ui.setupUi(this); |
50 |
|
|
51 |
|
m_pInstrumentListView = new InstrumentListView(this); |
52 |
|
QMainWindow::setCentralWidget(m_pInstrumentListView); |
53 |
|
|
54 |
// Setup toolbar widgets. |
// Setup toolbar widgets. |
55 |
m_pMapComboBox = new QComboBox(m_ui.InstrumentToolbar); |
m_pMapComboBox = new QComboBox(m_ui.instrumentToolbar); |
56 |
m_pMapComboBox->setMinimumWidth(120); |
m_pMapComboBox->setMinimumWidth(120); |
57 |
m_pMapComboBox->setEnabled(false); |
m_pMapComboBox->setEnabled(false); |
58 |
m_pMapComboBox->setToolTip(tr("Instrument Map")); |
m_pMapComboBox->setToolTip(tr("Instrument Map")); |
59 |
m_ui.InstrumentToolbar->addWidget(m_pMapComboBox); |
|
60 |
|
m_ui.instrumentToolbar->addWidget(m_pMapComboBox); |
61 |
m_ui.InstrumentToolbar->addSeparator(); |
m_ui.instrumentToolbar->addSeparator(); |
62 |
m_ui.InstrumentToolbar->addAction(m_ui.newInstrumentAction); |
m_ui.instrumentToolbar->addAction(m_ui.newInstrumentAction); |
63 |
m_ui.InstrumentToolbar->addAction(m_ui.editInstrumentAction); |
m_ui.instrumentToolbar->addAction(m_ui.editInstrumentAction); |
64 |
m_ui.InstrumentToolbar->addAction(m_ui.deleteInstrumentAction); |
m_ui.instrumentToolbar->addAction(m_ui.deleteInstrumentAction); |
65 |
m_ui.InstrumentToolbar->addSeparator(); |
m_ui.instrumentToolbar->addSeparator(); |
66 |
m_ui.InstrumentToolbar->addAction(m_ui.refreshInstrumentsAction); |
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); |
|
67 |
|
|
68 |
QObject::connect(m_pMapComboBox, |
QObject::connect(m_pMapComboBox, |
69 |
SIGNAL(activated(int)), |
SIGNAL(activated(int)), |
70 |
SLOT(activateMap(int))); |
SLOT(activateMap(int))); |
71 |
QObject::connect( |
QObject::connect(m_pInstrumentListView->selectionModel(), |
72 |
m_pInstrumentListView, |
SIGNAL(currentRowChanged(const QModelIndex&,const QModelIndex&)), |
|
SIGNAL(customContextMenuRequested(const QPoint&)), |
|
|
SLOT(contextMenu(const QPoint&))); |
|
|
QObject::connect( |
|
|
m_pInstrumentListView, |
|
|
SIGNAL(pressed(const QModelIndex&)), |
|
73 |
SLOT(stabilizeForm())); |
SLOT(stabilizeForm())); |
74 |
QObject::connect( |
QObject::connect( |
75 |
m_pInstrumentListView, |
m_pInstrumentListView, |
76 |
SIGNAL(activated(const QModelIndex&)), |
SIGNAL(doubleClicked(const QModelIndex&)), |
77 |
SLOT(editInstrument(const QModelIndex&))); |
SLOT(editInstrument(const QModelIndex&))); |
78 |
QObject::connect( |
QObject::connect( |
79 |
m_ui.newInstrumentAction, |
m_ui.newInstrumentAction, |
99 |
|
|
100 |
InstrumentListForm::~InstrumentListForm (void) |
InstrumentListForm::~InstrumentListForm (void) |
101 |
{ |
{ |
|
delete m_pInstrumentListView; |
|
102 |
delete m_pMapComboBox; |
delete m_pMapComboBox; |
103 |
|
delete m_pInstrumentListView; |
104 |
} |
} |
105 |
|
|
106 |
|
|
206 |
if (pInstrument == NULL) |
if (pInstrument == NULL) |
207 |
return; |
return; |
208 |
|
|
|
if (pInstrument == NULL) |
|
|
return; |
|
|
|
|
209 |
// Save current key values... |
// Save current key values... |
210 |
Instrument oldInstrument( |
int iMap = pInstrument->map(); |
211 |
pInstrument->map(), |
int iBank = pInstrument->bank(); |
212 |
pInstrument->bank(), |
int iProg = pInstrument->prog(); |
213 |
pInstrument->prog()); |
|
214 |
|
Instrument instrument(iMap, iBank, iProg); |
215 |
|
|
216 |
// Do the edit dance... |
// Do the edit dance... |
217 |
InstrumentForm form(this); |
InstrumentForm form(this); |
218 |
form.setup(pInstrument); |
form.setup(&instrument); |
219 |
if (form.exec()) { |
if (form.exec()) { |
220 |
// Commit... |
// Commit... |
221 |
pInstrument->mapInstrument(); |
instrument.mapInstrument(); |
222 |
// Check whether we changed instrument key... |
// Check whether we changed instrument key... |
223 |
if (oldInstrument.map() == pInstrument->map() && |
if (instrument.map() == iMap && |
224 |
oldInstrument.bank() == pInstrument->bank() && |
instrument.bank() == iBank && |
225 |
oldInstrument.prog() == pInstrument->prog()) { |
instrument.prog() == iProg) { |
226 |
// Just update tree item... |
// Just update tree item... |
227 |
//pItem->update(); |
//pItem->update(); |
228 |
} else { |
} else { |
229 |
// Unmap old instance... |
// Unmap old instance... |
230 |
oldInstrument.unmapInstrument(); |
Instrument(iMap, iBank, iProg).unmapInstrument(); |
231 |
// correct the position of the instrument in the model |
// correct the position of the instrument in the model |
232 |
m_pInstrumentListView->updateInstrument(pInstrument); |
m_pInstrumentListView->updateInstrument(pInstrument); |
233 |
} |
} |
234 |
} |
} |
235 |
|
|
236 |
|
stabilizeForm(); |
237 |
} |
} |
238 |
|
|
239 |
|
|
254 |
instrument.map(), |
instrument.map(), |
255 |
instrument.bank(), |
instrument.bank(), |
256 |
instrument.prog()); |
instrument.prog()); |
257 |
|
|
258 |
|
stabilizeForm(); |
259 |
} |
} |
260 |
|
|
261 |
|
|
292 |
|
|
293 |
// let the instrument vanish from the table model |
// let the instrument vanish from the table model |
294 |
m_pInstrumentListView->removeInstrument(pInstrument); |
m_pInstrumentListView->removeInstrument(pInstrument); |
295 |
|
|
296 |
|
stabilizeForm(); |
297 |
} |
} |
298 |
|
|
299 |
|
|
311 |
} |
} |
312 |
|
|
313 |
|
|
314 |
// Handle custom context menu here... |
// Context menu request. |
315 |
void InstrumentListForm::contextMenu ( const QPoint& pos ) |
void InstrumentListForm::contextMenuEvent ( |
316 |
|
QContextMenuEvent *pContextMenuEvent ) |
317 |
{ |
{ |
318 |
if (!m_ui.newInstrumentAction->isEnabled()) |
if (m_ui.newInstrumentAction->isEnabled()) |
319 |
return; |
m_ui.contextMenu->exec(pContextMenuEvent->globalPos()); |
|
|
|
|
m_ui.contextMenu->exec( |
|
|
(m_pInstrumentListView->viewport())->mapToGlobal(pos)); |
|
320 |
} |
} |
321 |
|
|
322 |
|
|