--- qsampler/trunk/src/qsamplerDeviceForm.cpp 2007/10/28 23:30:36 1461 +++ qsampler/trunk/src/qsamplerDeviceForm.cpp 2007/11/20 16:48:04 1499 @@ -1,6 +1,33 @@ +// qsamplerDeviceForm.cpp +// +/**************************************************************************** + Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved. + Copyright (C) 2007, Christian Schoenebeck + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +*****************************************************************************/ + #include "qsamplerDeviceForm.h" #include "qsamplerAbout.h" +#include "qsamplerMainForm.h" + +#include +#include + namespace QSampler { @@ -17,22 +44,57 @@ // No exclusive mode as default. m_deviceTypeMode = qsamplerDevice::None; + ui.DeviceListView->header()->hide(); + ui.DeviceParamTable->setModel(&deviceParamModel); ui.DeviceParamTable->setItemDelegate(&deviceParamDelegate); + ui.DeviceParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch); ui.DevicePortParamTable->setModel(&devicePortParamModel); ui.DevicePortParamTable->setItemDelegate(&devicePortParamDelegate); - - // This an outsider (from designer), but rather important. - //QObject::connect(DeviceParamTable, SIGNAL(valueChanged(int,int)), - // this, SLOT(changeDeviceParam(int,int))); - //QObject::connect(DevicePortParamTable, SIGNAL(valueChanged(int,int)), - // this, SLOT(changeDevicePortParam(int,int))); + ui.DevicePortParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch); // Initial contents. refreshDevices(); // Try to restore normal window positioning. adjustSize(); + + QObject::connect(ui.DeviceListView, + SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), + SLOT(selectDevice())); + QObject::connect(ui.DeviceListView, + SIGNAL(customContextMenuRequested(const QPoint&)), + SLOT(deviceListViewContextMenu(const QPoint&))); + QObject::connect(ui.RefreshDevicesPushButton, + SIGNAL(clicked()), + SLOT(refreshDevices())); + QObject::connect(ui.DriverNameComboBox, + SIGNAL(activated(const QString&)), + SLOT(selectDriver(const QString&))); + QObject::connect(ui.DevicePortComboBox, + SIGNAL(activated(int)), + SLOT(selectDevicePort(int))); + QObject::connect(ui.CreateDevicePushButton, + SIGNAL(clicked()), + SLOT(createDevice())); + QObject::connect(ui.DeleteDevicePushButton, + SIGNAL(clicked()), + SLOT(deleteDevice())); + QObject::connect(ui.ClosePushButton, + SIGNAL(clicked()), + SLOT(close())); + QObject::connect(&deviceParamModel, + SIGNAL(modelReset()), + SLOT(updateCellRenderers())); + QObject::connect(&deviceParamModel, + SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), + SLOT(updateCellRenderers(const QModelIndex&, const QModelIndex&))); + QObject::connect(&devicePortParamModel, + SIGNAL(modelReset()), + SLOT(updatePortCellRenderers())); + QObject::connect(&devicePortParamModel, + SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), + SLOT(updatePortCellRenderers(const QModelIndex&, const QModelIndex&))); } DeviceForm::~DeviceForm() { @@ -87,10 +149,11 @@ // Device driver name setup formal initializer. void DeviceForm::setDriverName ( const QString& sDriverName ) { - if (ui.DriverNameComboBox->findText(sDriverName) == 0) { - ui.DriverNameComboBox->insertItem(sDriverName); - } - ui.DriverNameComboBox->setCurrentText(sDriverName); + if (ui.DriverNameComboBox->findText(sDriverName) < 0) + ui.DriverNameComboBox->insertItem(0, sDriverName); + ui.DriverNameComboBox->setItemText( + ui.DriverNameComboBox->currentIndex(), + sDriverName); } @@ -293,7 +356,7 @@ if (m_bNewDevice) { m_iDirtySetup++; device.setDriver(sDriverName); - deviceParamModel.refresh(device.params(), m_bNewDevice); + deviceParamModel.refresh(&device, m_bNewDevice); m_iDirtySetup--; // Done. stabilizeForm(); @@ -302,7 +365,7 @@ // Device selection slot. -void DeviceForm::selectDevice (void) +void DeviceForm::selectDevice () { MainForm *pMainForm = MainForm::getInstance(); if (pMainForm == NULL) @@ -340,7 +403,7 @@ // The driver combobox is only rebuilt if device type has changed... if (device.deviceType() != m_deviceType) { ui.DriverNameComboBox->clear(); - ui.DriverNameComboBox->insertStringList( + ui.DriverNameComboBox->insertItems(0, qsamplerDevice::getDrivers(pMainForm->client(), device.deviceType())); m_deviceType = device.deviceType(); } @@ -351,7 +414,7 @@ ui.DriverNameTextLabel->setEnabled(m_bNewDevice); ui.DriverNameComboBox->setEnabled(m_bNewDevice); // Fill the device parameter table... - deviceParamModel.refresh(device.params(), m_bNewDevice); + deviceParamModel.refresh(&device, m_bNewDevice); // And now the device port/channel parameter table... switch (device.deviceType()) { case qsamplerDevice::Audio: @@ -373,18 +436,20 @@ QPixmap pixmap; switch (device.deviceType()) { case qsamplerDevice::Audio: - pixmap = QPixmap(":/qsampler/pixmaps/audio2.png"); + pixmap = QPixmap(":/icons/audio2.png"); break; case qsamplerDevice::Midi: - pixmap = QPixmap(":/qsampler/pixmaps/midi2.png"); + pixmap = QPixmap(":/icons/midi2.png"); break; case qsamplerDevice::None: break; } qsamplerDevicePortList& ports = device.ports(); - qsamplerDevicePort *pPort; - for (pPort = ports.first(); pPort; pPort = ports.next()) { - ui.DevicePortComboBox->insertItem(pixmap, device.deviceTypeName() + QListIterator iter(ports); + while (iter.hasNext()) { + qsamplerDevicePort *pPort = iter.next(); + ui.DevicePortComboBox->addItem(pixmap, + device.deviceTypeName() + ' ' + device.driverName() + ' ' + pPort->portName()); } @@ -397,7 +462,7 @@ m_iDirtySetup--; // Make the device port/channel selection effective. - selectDevicePort(ui.DevicePortComboBox->currentItem()); + selectDevicePort(ui.DevicePortComboBox->currentIndex()); } @@ -419,7 +484,7 @@ qsamplerDevicePort *pPort = device.ports().at(iPort); if (pPort) { m_iDirtySetup++; - devicePortParamModel.refresh(pPort->params(), false); + devicePortParamModel.refresh(pPort, false); m_iDirtySetup--; } // Done. @@ -439,6 +504,7 @@ // Device parameter change... // +/* we do that in the model class now ... QTreeWidgetItem* pItem = ui.DeviceListView->currentItem(); if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) return; @@ -456,6 +522,7 @@ } else { stabilizeForm(); } +*/ // Main session should be dirtier... MainForm *pMainForm = MainForm::getInstance(); @@ -476,13 +543,14 @@ // Device port/channel parameter change... // +/* we do that in the model class now ... QTreeWidgetItem* pItem = ui.DeviceListView->currentItem(); if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) return; qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); - int iPort = ui.DevicePortComboBox->currentItem(); + int iPort = ui.DevicePortComboBox->currentIndex(); qsamplerDevicePort *pPort = device.ports().at(iPort); if (pPort == NULL) return; @@ -495,6 +563,8 @@ // Set the local device port/channel parameter value. pPort->setParam(sParam, sValue); +*/ + // Done. stabilizeForm(); @@ -506,36 +576,37 @@ // Device list view context menu handler. -void DeviceForm::contextMenu ( QTreeWidgetItem* pItem, const QPoint& pos, int ) +void DeviceForm::deviceListViewContextMenu ( const QPoint& pos ) { MainForm *pMainForm = MainForm::getInstance(); if (pMainForm == NULL) return; - int iItemID; + QTreeWidgetItem* pItem = ui.DeviceListView->itemAt(pos); + if (pItem == NULL) + return; // Build the device context menu... - QMenu* pContextMenu = new QMenu(this); + QMenu menu(this); + QAction *pAction; bool bClient = (pMainForm->client() != NULL); bool bEnabled = (pItem != NULL); - iItemID = pContextMenu->insertItem( - QIconSet(QPixmap(":/qsampler/pixmaps/deviceCreate.png")), + pAction = menu.addAction( + QIcon(":/qsampler/pixmaps/deviceCreate.png"), tr("&Create device"), this, SLOT(createDevice())); - pContextMenu->setItemEnabled(iItemID, bEnabled || (bClient && m_bNewDevice)); - iItemID = pContextMenu->insertItem( - QIconSet(QPixmap(":/qsampler/pixmaps/deviceDelete.png")), + pAction->setEnabled(bEnabled || (bClient && m_bNewDevice)); + pAction = menu.addAction( + QIcon(":/qsampler/pixmaps/deviceDelete.png"), tr("&Delete device"), this, SLOT(deleteDevice())); - pContextMenu->setItemEnabled(iItemID, bEnabled && !m_bNewDevice); - pContextMenu->insertSeparator(); - iItemID = pContextMenu->insertItem( - QIconSet(QPixmap(":/qsampler/pixmaps/formRefresh.png")), + pAction->setEnabled(bEnabled && !m_bNewDevice); + menu.addSeparator(); + pAction = menu.addAction( + QIcon(":/qsampler/pixmaps/formRefresh.png"), tr("&Refresh"), this, SLOT(refreshDevices())); - pContextMenu->setItemEnabled(iItemID, bClient); + pAction->setEnabled(bClient); - pContextMenu->exec(pos); - - delete pContextMenu; + menu.exec(pos); } @@ -555,4 +626,37 @@ ui.DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice); } +void DeviceForm::updateCellRenderers() { + const int rows = deviceParamModel.rowCount(); + const int cols = deviceParamModel.columnCount(); + updateCellRenderers(deviceParamModel.index(0,0),deviceParamModel.index(rows-1,cols-1)); +} + +void DeviceForm::updateCellRenderers(const QModelIndex& topLeft, const QModelIndex& bottomRight) { + for (int r = topLeft.row(); r <= bottomRight.row(); r++) { + for (int c = topLeft.column(); c <= bottomRight.column(); c++) { + const QModelIndex index = deviceParamModel.index(r,c); + ui.DeviceParamTable->openPersistentEditor(index); + } + } +} + +void DeviceForm::updatePortCellRenderers() { + const int rows = devicePortParamModel.rowCount(); + const int cols = devicePortParamModel.columnCount(); + updatePortCellRenderers(devicePortParamModel.index(0,0),devicePortParamModel.index(rows-1,cols-1)); +} + +void DeviceForm::updatePortCellRenderers(const QModelIndex& topLeft, const QModelIndex& bottomRight) { + for (int r = topLeft.row(); r <= bottomRight.row(); r++) { + for (int c = topLeft.column(); c <= bottomRight.column(); c++) { + const QModelIndex index = devicePortParamModel.index(r,c); + ui.DevicePortParamTable->openPersistentEditor(index); + } + } +} + } // namespace QSampler + + +// end of qsamplerDeviceForm.cpp