/[svn]/qsampler/trunk/src/qsamplerDeviceForm.cpp
ViewVC logotype

Diff of /qsampler/trunk/src/qsamplerDeviceForm.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1470 by schoenebeck, Sun Nov 4 23:37:47 2007 UTC revision 1519 by capela, Sat Nov 24 13:06:19 2007 UTC
# Line 23  Line 23 
23  #include "qsamplerDeviceForm.h"  #include "qsamplerDeviceForm.h"
24    
25  #include "qsamplerAbout.h"  #include "qsamplerAbout.h"
26    #include "qsamplerMainForm.h"
27    
28    #include <QHeaderView>
29    #include <QMessageBox>
30    
31    
32  namespace QSampler {  namespace QSampler {
33    
34  DeviceForm::DeviceForm(QWidget* parent, Qt::WFlags f) : QDialog(parent, f) {  DeviceForm::DeviceForm ( QWidget *pParent, Qt::WindowFlags wflags )
35      ui.setupUi(this);          : QDialog(pParent, wflags)
36    {
37            m_ui.setupUi(this);
38    
39          // Initialize locals.          // Initialize locals.
40          m_iDirtySetup = 0;          m_iDirtySetup = 0;
# Line 39  DeviceForm::DeviceForm(QWidget* parent, Line 46  DeviceForm::DeviceForm(QWidget* parent,
46          // No exclusive mode as default.          // No exclusive mode as default.
47          m_deviceTypeMode = qsamplerDevice::None;          m_deviceTypeMode = qsamplerDevice::None;
48    
49          ui.DeviceParamTable->setModel(&deviceParamModel);          m_ui.DeviceListView->header()->hide();
         ui.DeviceParamTable->setItemDelegate(&deviceParamDelegate);  
   
         ui.DevicePortParamTable->setModel(&devicePortParamModel);  
         ui.DevicePortParamTable->setItemDelegate(&devicePortParamDelegate);  
50    
51          // This an outsider (from designer), but rather important.          int iRowHeight = m_ui.DeviceParamTable->fontMetrics().height() + 4;
52          //QObject::connect(DeviceParamTable, SIGNAL(valueChanged(int,int)),          m_ui.DeviceParamTable->verticalHeader()->setDefaultSectionSize(iRowHeight);
53          //      this, SLOT(changeDeviceParam(int,int)));          m_ui.DevicePortParamTable->verticalHeader()->setDefaultSectionSize(iRowHeight);
54          //QObject::connect(DevicePortParamTable, SIGNAL(valueChanged(int,int)),          m_ui.DeviceParamTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
55          //      this, SLOT(changeDevicePortParam(int,int)));          m_ui.DevicePortParamTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
56    
57            m_ui.DeviceParamTable->setModel(&m_deviceParamModel);
58            m_ui.DeviceParamTable->setItemDelegate(&m_deviceParamDelegate);
59            m_ui.DeviceParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);
60            m_ui.DeviceParamTable->verticalHeader()->hide();
61    
62            m_ui.DevicePortParamTable->setModel(&m_devicePortParamModel);
63            m_ui.DevicePortParamTable->setItemDelegate(&m_devicePortParamDelegate);
64            m_ui.DevicePortParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);
65            m_ui.DevicePortParamTable->verticalHeader()->hide();
66    
67          // Initial contents.          // Initial contents.
68          refreshDevices();          refreshDevices();
69          // Try to restore normal window positioning.          // Try to restore normal window positioning.
70          adjustSize();          adjustSize();
71    
72          QObject::connect(ui.DeviceListView,          QObject::connect(m_ui.DeviceListView,
73                  SIGNAL(itemSelectionChanged()),                  SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
74                  SLOT(selectDevice()));                  SLOT(selectDevice()));
75          QObject::connect(ui.DeviceListView,          QObject::connect(m_ui.DeviceListView,
76                  SIGNAL(customContextMenuRequested(const QPoint&)),                  SIGNAL(customContextMenuRequested(const QPoint&)),
77                  SLOT(deviceListViewContextMenu(const QPoint&)));                  SLOT(deviceListViewContextMenu(const QPoint&)));
78          QObject::connect(ui.RefreshDevicesPushButton,          QObject::connect(m_ui.RefreshDevicesPushButton,
79                  SIGNAL(clicked()),                  SIGNAL(clicked()),
80                  SLOT(refreshDevices()));                  SLOT(refreshDevices()));
81          QObject::connect(ui.DriverNameComboBox,          QObject::connect(m_ui.DriverNameComboBox,
82                  SIGNAL(activated(const QString&)),                  SIGNAL(activated(const QString&)),
83                  SLOT(selectDriver(const QString&)));                  SLOT(selectDriver(const QString&)));
84          QObject::connect(ui.DevicePortComboBox,          QObject::connect(m_ui.DevicePortComboBox,
85                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
86                  SLOT(selectDevicePort(int)));                  SLOT(selectDevicePort(int)));
87          QObject::connect(ui.CreateDevicePushButton,          QObject::connect(m_ui.CreateDevicePushButton,
88                  SIGNAL(clicked()),                  SIGNAL(clicked()),
89                  SLOT(createDevice()));                  SLOT(createDevice()));
90          QObject::connect(ui.DeleteDevicePushButton,          QObject::connect(m_ui.DeleteDevicePushButton,
91                  SIGNAL(clicked()),                  SIGNAL(clicked()),
92                  SLOT(deleteDevice()));                  SLOT(deleteDevice()));
93          QObject::connect(ui.ClosePushButton,          QObject::connect(m_ui.ClosePushButton,
94                  SIGNAL(clicked()),                  SIGNAL(clicked()),
95                  SLOT(close()));                  SLOT(close()));
96            QObject::connect(&m_deviceParamModel,
97                    SIGNAL(modelReset()),
98                    SLOT(updateCellRenderers()));
99            QObject::connect(&m_deviceParamModel,
100                    SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
101                    SLOT(updateCellRenderers(const QModelIndex&, const QModelIndex&)));
102            QObject::connect(&m_devicePortParamModel,
103                    SIGNAL(modelReset()),
104                    SLOT(updatePortCellRenderers()));
105            QObject::connect(&m_devicePortParamModel,
106                    SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
107                    SLOT(updatePortCellRenderers(const QModelIndex&, const QModelIndex&)));
108  }  }
109    
110  DeviceForm::~DeviceForm() {  DeviceForm::~DeviceForm() {
# Line 118  void DeviceForm::hideEvent ( QHideEvent Line 143  void DeviceForm::hideEvent ( QHideEvent
143    
144  // Set device type spacial exclusive mode.  // Set device type spacial exclusive mode.
145  void DeviceForm::setDeviceTypeMode (  void DeviceForm::setDeviceTypeMode (
146          qsamplerDevice::qsamplerDeviceType deviceTypeMode )          qsamplerDevice::DeviceType deviceTypeMode )
147  {  {
148          // If it has not changed, do nothing.          // If it has not changed, do nothing.
149          if (m_deviceTypeMode == deviceTypeMode)          if (m_deviceTypeMode == deviceTypeMode)
# Line 134  void DeviceForm::setDeviceTypeMode ( Line 159  void DeviceForm::setDeviceTypeMode (
159  // Device driver name setup formal initializer.  // Device driver name setup formal initializer.
160  void DeviceForm::setDriverName ( const QString& sDriverName )  void DeviceForm::setDriverName ( const QString& sDriverName )
161  {  {
162          if (ui.DriverNameComboBox->findText(sDriverName) == 0) {          if (m_ui.DriverNameComboBox->findText(sDriverName) < 0)
163                  ui.DriverNameComboBox->insertItem(sDriverName);                  m_ui.DriverNameComboBox->insertItem(0, sDriverName);
164          }          m_ui.DriverNameComboBox->setItemText(
165          ui.DriverNameComboBox->setCurrentText(sDriverName);                  m_ui.DriverNameComboBox->currentIndex(),
166                    sDriverName);
167  }  }
168    
169    
# Line 145  void DeviceForm::setDriverName ( const Q Line 171  void DeviceForm::setDriverName ( const Q
171  void DeviceForm::setDevice ( qsamplerDevice *pDevice )  void DeviceForm::setDevice ( qsamplerDevice *pDevice )
172  {  {
173          // In case no device is given...          // In case no device is given...
174          qsamplerDevice::qsamplerDeviceType deviceType = m_deviceTypeMode;          qsamplerDevice::DeviceType deviceType = m_deviceTypeMode;
175          if (pDevice)          if (pDevice)
176                  deviceType = pDevice->deviceType();                  deviceType = pDevice->deviceType();
177    
# Line 168  void DeviceForm::setDevice ( qsamplerDev Line 194  void DeviceForm::setDevice ( qsamplerDev
194    
195          // So there's no device huh?          // So there's no device huh?
196          if (pDevice == NULL) {          if (pDevice == NULL) {
197                  ui.DeviceListView->setCurrentItem(pRootItem);                  m_ui.DeviceListView->setCurrentItem(pRootItem);
198                  return;                  return;
199          }          }
200    
# Line 194  void DeviceForm::createDevice (void) Line 220  void DeviceForm::createDevice (void)
220          if (pMainForm == NULL)          if (pMainForm == NULL)
221                  return;                  return;
222    
223          QTreeWidgetItem *pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem *pItem = m_ui.DeviceListView->currentItem();
224          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
225                  return;                  return;
226    
# Line 232  void DeviceForm::deleteDevice (void) Line 258  void DeviceForm::deleteDevice (void)
258          if (pMainForm == NULL)          if (pMainForm == NULL)
259                  return;                  return;
260    
261          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
262          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
263                  return;                  return;
264    
# Line 277  void DeviceForm::refreshDevices (void) Line 303  void DeviceForm::refreshDevices (void)
303          //          //
304          m_pAudioItems = NULL;          m_pAudioItems = NULL;
305          m_pMidiItems = NULL;          m_pMidiItems = NULL;
306          ui.DeviceListView->clear();          m_ui.DeviceListView->clear();
307          if (pMainForm->client()) {          if (pMainForm->client()) {
308                  int *piDeviceIDs;                  int *piDeviceIDs;
309                  // Grab and pop Audio devices...                  // Grab and pop Audio devices...
310                  if (m_deviceTypeMode == qsamplerDevice::None ||                  if (m_deviceTypeMode == qsamplerDevice::None ||
311                          m_deviceTypeMode == qsamplerDevice::Audio) {                          m_deviceTypeMode == qsamplerDevice::Audio) {
312                          m_pAudioItems = new qsamplerDeviceItem(ui.DeviceListView,                          m_pAudioItems = new qsamplerDeviceItem(m_ui.DeviceListView,
313                                  qsamplerDevice::Audio);                                  qsamplerDevice::Audio);
314                  }                  }
315                  if (m_pAudioItems) {                  if (m_pAudioItems) {
# Line 298  void DeviceForm::refreshDevices (void) Line 324  void DeviceForm::refreshDevices (void)
324                  // Grab and pop MIDI devices...                  // Grab and pop MIDI devices...
325                  if (m_deviceTypeMode == qsamplerDevice::None ||                  if (m_deviceTypeMode == qsamplerDevice::None ||
326                          m_deviceTypeMode == qsamplerDevice::Midi) {                          m_deviceTypeMode == qsamplerDevice::Midi) {
327                          m_pMidiItems = new qsamplerDeviceItem(ui.DeviceListView,                          m_pMidiItems = new qsamplerDeviceItem(m_ui.DeviceListView,
328                                  qsamplerDevice::Midi);                                  qsamplerDevice::Midi);
329                  }                  }
330                  if (m_pMidiItems) {                  if (m_pMidiItems) {
# Line 330  void DeviceForm::selectDriver ( const QS Line 356  void DeviceForm::selectDriver ( const QS
356          //  Driver name has changed for a new device...          //  Driver name has changed for a new device...
357          //          //
358    
359          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
360          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
361                  return;                  return;
362    
# Line 340  void DeviceForm::selectDriver ( const QS Line 366  void DeviceForm::selectDriver ( const QS
366          if (m_bNewDevice) {          if (m_bNewDevice) {
367                  m_iDirtySetup++;                  m_iDirtySetup++;
368                  device.setDriver(sDriverName);                  device.setDriver(sDriverName);
369                  deviceParamModel.refresh(device.params(), m_bNewDevice);                  m_deviceParamModel.refresh(&device, m_bNewDevice);
370                  m_iDirtySetup--;                  m_iDirtySetup--;
371                  // Done.                  // Done.
372                  stabilizeForm();                  stabilizeForm();
# Line 349  void DeviceForm::selectDriver ( const QS Line 375  void DeviceForm::selectDriver ( const QS
375    
376    
377  // Device selection slot.  // Device selection slot.
378  void DeviceForm::selectDevice (void)  void DeviceForm::selectDevice ()
379  {  {
380          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
381          if (pMainForm == NULL)          if (pMainForm == NULL)
# Line 362  void DeviceForm::selectDevice (void) Line 388  void DeviceForm::selectDevice (void)
388          //  Device selection has changed...          //  Device selection has changed...
389          //          //
390    
391          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
392          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) {          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) {
393                  m_deviceType = qsamplerDevice::None;                  m_deviceType = qsamplerDevice::None;
394                  ui.DeviceNameTextLabel->setText(QString::null);                  m_ui.DeviceNameTextLabel->setText(QString::null);
395                  deviceParamModel.clear();                  m_deviceParamModel.clear();
396                  ui.DevicePortComboBox->clear();                  m_ui.DevicePortComboBox->clear();
397                  devicePortParamModel.clear();                  m_devicePortParamModel.clear();
398                  ui.DevicePortTextLabel->setEnabled(false);                  m_ui.DevicePortTextLabel->setEnabled(false);
399                  ui.DevicePortComboBox->setEnabled(false);                  m_ui.DevicePortComboBox->setEnabled(false);
400                  ui.DevicePortParamTable->setEnabled(false);                  m_ui.DevicePortParamTable->setEnabled(false);
401                  stabilizeForm();                  stabilizeForm();
402                  return;                  return;
403          }          }
# Line 383  void DeviceForm::selectDevice (void) Line 409  void DeviceForm::selectDevice (void)
409          m_bNewDevice = (device.deviceID() < 0);          m_bNewDevice = (device.deviceID() < 0);
410    
411          // Fill the device/driver heading...          // Fill the device/driver heading...
412          ui.DeviceNameTextLabel->setText(device.deviceName());          m_ui.DeviceNameTextLabel->setText(device.deviceName());
413          // The driver combobox is only rebuilt if device type has changed...          // The driver combobox is only rebuilt if device type has changed...
414          if (device.deviceType() != m_deviceType) {          if (device.deviceType() != m_deviceType) {
415                  ui.DriverNameComboBox->clear();                  m_ui.DriverNameComboBox->clear();
416                  ui.DriverNameComboBox->insertStringList(                  m_ui.DriverNameComboBox->insertItems(0,
417                          qsamplerDevice::getDrivers(pMainForm->client(), device.deviceType()));                          qsamplerDevice::getDrivers(pMainForm->client(), device.deviceType()));
418                  m_deviceType = device.deviceType();                  m_deviceType = device.deviceType();
419          }          }
420          // Do we need a driver name?          // Do we need a driver name?
421          if (m_bNewDevice || device.driverName().isEmpty())          if (m_bNewDevice || device.driverName().isEmpty())
422                  device.setDriver(ui.DriverNameComboBox->currentText());                  device.setDriver(m_ui.DriverNameComboBox->currentText());
423          setDriverName(device.driverName());          setDriverName(device.driverName());
424          ui.DriverNameTextLabel->setEnabled(m_bNewDevice);          m_ui.DriverNameTextLabel->setEnabled(m_bNewDevice);
425          ui.DriverNameComboBox->setEnabled(m_bNewDevice);          m_ui.DriverNameComboBox->setEnabled(m_bNewDevice);
426          // Fill the device parameter table...          // Fill the device parameter table...
427          deviceParamModel.refresh(device.params(), m_bNewDevice);          m_deviceParamModel.refresh(&device, m_bNewDevice);
428          // And now the device port/channel parameter table...          // And now the device port/channel parameter table...
429          switch (device.deviceType()) {          switch (device.deviceType()) {
430          case qsamplerDevice::Audio:          case qsamplerDevice::Audio:
431                  ui.DevicePortTextLabel->setText(tr("Ch&annel:"));                  m_ui.DevicePortTextLabel->setText(tr("Ch&annel:"));
432                  break;                  break;
433          case qsamplerDevice::Midi:          case qsamplerDevice::Midi:
434                  ui.DevicePortTextLabel->setText(tr("P&ort:"));                  m_ui.DevicePortTextLabel->setText(tr("P&ort:"));
435                  break;                  break;
436          case qsamplerDevice::None:          case qsamplerDevice::None:
437                  break;                  break;
438          }          }
439          ui.DevicePortComboBox->clear();          m_ui.DevicePortComboBox->clear();
440          devicePortParamModel.clear();          m_devicePortParamModel.clear();
441          if (m_bNewDevice) {          if (m_bNewDevice) {
442                  ui.DevicePortTextLabel->setEnabled(false);                  m_ui.DevicePortTextLabel->setEnabled(false);
443                  ui.DevicePortComboBox->setEnabled(false);                  m_ui.DevicePortComboBox->setEnabled(false);
444                  ui.DevicePortParamTable->setEnabled(false);                  m_ui.DevicePortParamTable->setEnabled(false);
445          } else {          } else {
446                  QPixmap pixmap;                  QPixmap pixmap;
447                  switch (device.deviceType()) {                  switch (device.deviceType()) {
448                  case qsamplerDevice::Audio:                  case qsamplerDevice::Audio:
449                          pixmap = QPixmap(":/qsampler/pixmaps/audio2.png");                          pixmap = QPixmap(":/icons/audio2.png");
450                          break;                          break;
451                  case qsamplerDevice::Midi:                  case qsamplerDevice::Midi:
452                          pixmap = QPixmap(":/qsampler/pixmaps/midi2.png");                          pixmap = QPixmap(":/icons/midi2.png");
453                          break;                          break;
454                  case qsamplerDevice::None:                  case qsamplerDevice::None:
455                          break;                          break;
456                  }                  }
457                  qsamplerDevicePortList& ports = device.ports();                  qsamplerDevicePortList& ports = device.ports();
458                  qsamplerDevicePort *pPort;                  QListIterator<qsamplerDevicePort *> iter(ports);
459                  for (pPort = ports.first(); pPort; pPort = ports.next()) {                  while (iter.hasNext()) {
460                          ui.DevicePortComboBox->insertItem(pixmap, device.deviceTypeName()                          qsamplerDevicePort *pPort = iter.next();
461                            m_ui.DevicePortComboBox->addItem(pixmap,
462                                    device.deviceTypeName()
463                                  + ' ' + device.driverName()                                  + ' ' + device.driverName()
464                                  + ' ' + pPort->portName());                                  + ' ' + pPort->portName());
465                  }                  }
466                  bool bEnabled = (ports.count() > 0);                  bool bEnabled = (ports.count() > 0);
467                  ui.DevicePortTextLabel->setEnabled(bEnabled);                  m_ui.DevicePortTextLabel->setEnabled(bEnabled);
468                  ui.DevicePortComboBox->setEnabled(bEnabled);                  m_ui.DevicePortComboBox->setEnabled(bEnabled);
469                  ui.DevicePortParamTable->setEnabled(bEnabled);                  m_ui.DevicePortParamTable->setEnabled(bEnabled);
470          }          }
471          // Done.          // Done.
472          m_iDirtySetup--;          m_iDirtySetup--;
473    
474          // Make the device port/channel selection effective.          // Make the device port/channel selection effective.
475          selectDevicePort(ui.DevicePortComboBox->currentItem());          selectDevicePort(m_ui.DevicePortComboBox->currentIndex());
476  }  }
477    
478    
# Line 458  void DeviceForm::selectDevicePort ( int Line 486  void DeviceForm::selectDevicePort ( int
486          //  Device port/channel selection has changed...          //  Device port/channel selection has changed...
487          //          //
488    
489          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
490          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
491                  return;                  return;
492    
493          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
494          qsamplerDevicePort *pPort = device.ports().at(iPort);          qsamplerDevicePort *pPort = NULL;
495            if (iPort >= 0 && iPort < device.ports().count())
496                    pPort = device.ports().at(iPort);
497          if (pPort) {          if (pPort) {
498                  m_iDirtySetup++;                  m_iDirtySetup++;
499                  devicePortParamModel.refresh(pPort->params(), false);                  m_devicePortParamModel.refresh(pPort, false);
500                  m_iDirtySetup--;                  m_iDirtySetup--;
501          }          }
502          // Done.          // Done.
# Line 486  void DeviceForm::changeDeviceParam ( int Line 516  void DeviceForm::changeDeviceParam ( int
516          //  Device parameter change...          //  Device parameter change...
517          //          //
518    
519          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();  /* we do that in the model class now ...
520            QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
521          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
522                  return;                  return;
523    
524          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
525    
526          // Table 1st column has the parameter name;          // Table 1st column has the parameter name;
527          //const QString sParam = ui.DeviceParamTable->text(iRow, 0);          //const QString sParam = m_ui.DeviceParamTable->text(iRow, 0);
528          //const QString sValue = ui.DeviceParamTable->text(iRow, iCol);          //const QString sValue = m_ui.DeviceParamTable->text(iRow, iCol);
529          const QString sParam = deviceParamModel.data(deviceParamModel.index(iRow, 0), Qt::DisplayRole).value<DeviceParameterRow>().name;          const QString sParam = m_deviceParamModel.data(m_deviceParamModel.index(iRow, 0), Qt::DisplayRole).value<DeviceParameterRow>().name;
530          const QString sValue = deviceParamModel.data(deviceParamModel.index(iRow, iCol), Qt::DisplayRole).value<DeviceParameterRow>().param.value;          const QString sValue = m_deviceParamModel.data(m_deviceParamModel.index(iRow, iCol), Qt::DisplayRole).value<DeviceParameterRow>().param.value;
531          // Set the local device parameter value.          // Set the local device parameter value.
532          if (device.setParam(sParam, sValue)) {          if (device.setParam(sParam, sValue)) {
533                  selectDevice();                  selectDevice();
534          } else {          } else {
535                  stabilizeForm();                  stabilizeForm();
536          }          }
537    */
538    
539          // Main session should be dirtier...          // Main session should be dirtier...
540          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
# Line 523  void DeviceForm::changeDevicePortParam ( Line 555  void DeviceForm::changeDevicePortParam (
555          //  Device port/channel parameter change...          //  Device port/channel parameter change...
556          //          //
557    
558          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();  /* we do that in the model class now ...
559            QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
560          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
561                  return;                  return;
562    
563          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
564    
565          int iPort = ui.DevicePortComboBox->currentItem();          int iPort = m_ui.DevicePortComboBox->currentIndex();
566          qsamplerDevicePort *pPort = device.ports().at(iPort);          qsamplerDevicePort *pPort = NULL;
567            if (iPort >= 0 && iPort < device.ports().count())
568                    pPort = device.ports().at(iPort);
569          if (pPort == NULL)          if (pPort == NULL)
570                  return;                  return;
571    
572          // Table 1st column has the parameter name;          // Table 1st column has the parameter name;
573          //const QString sParam = ui.DevicePortParamTable->text(iRow, 0);          //const QString sParam = m_ui.DevicePortParamTable->text(iRow, 0);
574          //const QString sValue = ui.DevicePortParamTable->text(iRow, iCol);          //const QString sValue = m_ui.DevicePortParamTable->text(iRow, iCol);
575          const QString sParam = devicePortParamModel.data(devicePortParamModel.index(iRow, 0), Qt::DisplayRole).value<DeviceParameterRow>().name;          const QString sParam = m_devicePortParamModel.data(m_devicePortParamModel.index(iRow, 0), Qt::DisplayRole).value<DeviceParameterRow>().name;
576          const QString sValue = devicePortParamModel.data(devicePortParamModel.index(iRow, iCol), Qt::DisplayRole).value<DeviceParameterRow>().param.value;          const QString sValue = m_devicePortParamModel.data(m_devicePortParamModel.index(iRow, iCol), Qt::DisplayRole).value<DeviceParameterRow>().param.value;
577    
578          // Set the local device port/channel parameter value.          // Set the local device port/channel parameter value.
579          pPort->setParam(sParam, sValue);          pPort->setParam(sParam, sValue);
580    */
581    
582          // Done.          // Done.
583          stabilizeForm();          stabilizeForm();
584    
# Line 559  void DeviceForm::deviceListViewContextMe Line 596  void DeviceForm::deviceListViewContextMe
596          if (pMainForm == NULL)          if (pMainForm == NULL)
597                  return;                  return;
598    
599          QTreeWidgetItem* pItem = ui.DeviceListView->itemAt(pos);          QTreeWidgetItem* pItem = m_ui.DeviceListView->itemAt(pos);
600          if (pItem == NULL)          if (pItem == NULL)
601                  return;                  return;
602    
         int iItemID;  
   
603          // Build the device context menu...          // Build the device context menu...
604          QMenu* pContextMenu = new QMenu(this);          QMenu menu(this);
605            QAction *pAction;
606    
607          bool bClient = (pMainForm->client() != NULL);          bool bClient = (pMainForm->client() != NULL);
608          bool bEnabled = (pItem != NULL);          bool bEnabled = (pItem != NULL);
609          iItemID = pContextMenu->insertItem(          pAction = menu.addAction(
610                  QIconSet(QPixmap(":/qsampler/pixmaps/deviceCreate.png")),                  QIcon(":/qsampler/pixmaps/deviceCreate.png"),
611                  tr("&Create device"), this, SLOT(createDevice()));                  tr("&Create device"), this, SLOT(createDevice()));
612          pContextMenu->setItemEnabled(iItemID, bEnabled || (bClient && m_bNewDevice));          pAction->setEnabled(bEnabled || (bClient && m_bNewDevice));
613          iItemID = pContextMenu->insertItem(          pAction = menu.addAction(
614                  QIconSet(QPixmap(":/qsampler/pixmaps/deviceDelete.png")),                  QIcon(":/qsampler/pixmaps/deviceDelete.png"),
615                  tr("&Delete device"), this, SLOT(deleteDevice()));                  tr("&Delete device"), this, SLOT(deleteDevice()));
616          pContextMenu->setItemEnabled(iItemID, bEnabled && !m_bNewDevice);          pAction->setEnabled(bEnabled && !m_bNewDevice);
617          pContextMenu->insertSeparator();          menu.addSeparator();
618          iItemID = pContextMenu->insertItem(          pAction = menu.addAction(
619                  QIconSet(QPixmap(":/qsampler/pixmaps/formRefresh.png")),                  QIcon(":/qsampler/pixmaps/formRefresh.png"),
620                  tr("&Refresh"), this, SLOT(refreshDevices()));                  tr("&Refresh"), this, SLOT(refreshDevices()));
621          pContextMenu->setItemEnabled(iItemID, bClient);          pAction->setEnabled(bClient);
622    
623          pContextMenu->exec(pos);          menu.exec(pos);
   
         delete pContextMenu;  
624  }  }
625    
626    
# Line 594  void DeviceForm::deviceListViewContextMe Line 628  void DeviceForm::deviceListViewContextMe
628  void DeviceForm::stabilizeForm (void)  void DeviceForm::stabilizeForm (void)
629  {  {
630          MainForm* pMainForm = MainForm::getInstance();          MainForm* pMainForm = MainForm::getInstance();
631          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
632          bool bClient = (pMainForm && pMainForm->client() != NULL);          bool bClient = (pMainForm && pMainForm->client() != NULL);
633          bool bEnabled = (pItem != NULL);          bool bEnabled = (pItem != NULL);
634          ui.DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice);          m_ui.DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice);
635          ui.DriverNameTextLabel->setEnabled(bEnabled &&  m_bNewDevice);          m_ui.DriverNameTextLabel->setEnabled(bEnabled &&  m_bNewDevice);
636          ui.DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice);          m_ui.DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice);
637          ui.DeviceParamTable->setEnabled(bEnabled);          m_ui.DeviceParamTable->setEnabled(bEnabled);
638          ui.RefreshDevicesPushButton->setEnabled(bClient);          m_ui.RefreshDevicesPushButton->setEnabled(bClient);
639          ui.CreateDevicePushButton->setEnabled(bEnabled || (bClient && m_bNewDevice));          m_ui.CreateDevicePushButton->setEnabled(bEnabled || (bClient && m_bNewDevice));
640          ui.DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice);          m_ui.DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice);
641    }
642    
643    
644    void DeviceForm::updateCellRenderers (void)
645    {
646            const int rows = m_deviceParamModel.rowCount();
647            const int cols = m_deviceParamModel.columnCount();
648            updateCellRenderers(
649                    m_deviceParamModel.index(0, 0),
650                    m_deviceParamModel.index(rows - 1, cols - 1));
651    }
652    
653    
654    void DeviceForm::updateCellRenderers (
655            const QModelIndex& topLeft, const QModelIndex& bottomRight )
656    {
657            for (int r = topLeft.row(); r <= bottomRight.row(); r++) {
658                    for (int c = topLeft.column(); c <= bottomRight.column(); c++) {
659                            const QModelIndex index = m_deviceParamModel.index(r, c);
660                            m_ui.DeviceParamTable->openPersistentEditor(index);
661                    }
662            }
663    }
664    
665    
666    void DeviceForm::updatePortCellRenderers (void)
667    {
668            const int rows = m_devicePortParamModel.rowCount();
669            const int cols = m_devicePortParamModel.columnCount();
670            updatePortCellRenderers(
671                    m_devicePortParamModel.index(0, 0),
672                    m_devicePortParamModel.index(rows - 1, cols - 1));
673    }
674    
675    
676    void DeviceForm::updatePortCellRenderers (
677            const QModelIndex& topLeft, const QModelIndex& bottomRight )
678    {
679            for (int r = topLeft.row(); r <= bottomRight.row(); r++) {
680                    for (int c = topLeft.column(); c <= bottomRight.column(); c++) {
681                            const QModelIndex index = m_devicePortParamModel.index(r, c);
682                            m_ui.DevicePortParamTable->openPersistentEditor(index);
683                    }
684            }
685  }  }
686    
687  } // namespace QSampler  } // namespace QSampler

Legend:
Removed from v.1470  
changed lines
  Added in v.1519

  ViewVC Help
Powered by ViewVC