/[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 1528 by capela, Mon Nov 26 18:24:38 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);  
50    
51          ui.DevicePortParamTable->setModel(&devicePortParamModel);          int iRowHeight = m_ui.DeviceParamTable->fontMetrics().height() + 4;
52          ui.DevicePortParamTable->setItemDelegate(&devicePortParamDelegate);          m_ui.DeviceParamTable->verticalHeader()->setDefaultSectionSize(iRowHeight);
53            m_ui.DevicePortParamTable->verticalHeader()->setDefaultSectionSize(iRowHeight);
54          // This an outsider (from designer), but rather important.          m_ui.DeviceParamTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
55          //QObject::connect(DeviceParamTable, SIGNAL(valueChanged(int,int)),          m_ui.DevicePortParamTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
56          //      this, SLOT(changeDeviceParam(int,int)));  
57          //QObject::connect(DevicePortParamTable, SIGNAL(valueChanged(int,int)),          m_ui.DeviceParamTable->setModel(&m_deviceParamModel);
58          //      this, SLOT(changeDevicePortParam(int,int)));          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() {  
111    DeviceForm::~DeviceForm (void)
112    {
113  }  }
114    
115    
# Line 93  void DeviceForm::showEvent ( QShowEvent Line 120  void DeviceForm::showEvent ( QShowEvent
120          if (pMainForm)          if (pMainForm)
121                  pMainForm->stabilizeForm();                  pMainForm->stabilizeForm();
122    
         stabilizeForm();  
   
123          QWidget::showEvent(pShowEvent);          QWidget::showEvent(pShowEvent);
124    
125            refreshDevices();
126  }  }
127    
128    
# Line 118  void DeviceForm::hideEvent ( QHideEvent Line 145  void DeviceForm::hideEvent ( QHideEvent
145    
146  // Set device type spacial exclusive mode.  // Set device type spacial exclusive mode.
147  void DeviceForm::setDeviceTypeMode (  void DeviceForm::setDeviceTypeMode (
148          qsamplerDevice::qsamplerDeviceType deviceTypeMode )          qsamplerDevice::DeviceType deviceTypeMode )
149  {  {
150          // If it has not changed, do nothing.          // If it has not changed, do nothing.
151          if (m_deviceTypeMode == deviceTypeMode)          if (m_deviceTypeMode == deviceTypeMode)
# Line 134  void DeviceForm::setDeviceTypeMode ( Line 161  void DeviceForm::setDeviceTypeMode (
161  // Device driver name setup formal initializer.  // Device driver name setup formal initializer.
162  void DeviceForm::setDriverName ( const QString& sDriverName )  void DeviceForm::setDriverName ( const QString& sDriverName )
163  {  {
164          if (ui.DriverNameComboBox->findText(sDriverName) == 0) {          if (m_ui.DriverNameComboBox->findText(sDriverName) < 0)
165                  ui.DriverNameComboBox->insertItem(sDriverName);                  m_ui.DriverNameComboBox->insertItem(0, sDriverName);
166          }          m_ui.DriverNameComboBox->setItemText(
167          ui.DriverNameComboBox->setCurrentText(sDriverName);                  m_ui.DriverNameComboBox->currentIndex(),
168                    sDriverName);
169  }  }
170    
171    
# Line 145  void DeviceForm::setDriverName ( const Q Line 173  void DeviceForm::setDriverName ( const Q
173  void DeviceForm::setDevice ( qsamplerDevice *pDevice )  void DeviceForm::setDevice ( qsamplerDevice *pDevice )
174  {  {
175          // In case no device is given...          // In case no device is given...
176          qsamplerDevice::qsamplerDeviceType deviceType = m_deviceTypeMode;          qsamplerDevice::DeviceType deviceType = m_deviceTypeMode;
177          if (pDevice)          if (pDevice)
178                  deviceType = pDevice->deviceType();                  deviceType = pDevice->deviceType();
179    
# Line 168  void DeviceForm::setDevice ( qsamplerDev Line 196  void DeviceForm::setDevice ( qsamplerDev
196    
197          // So there's no device huh?          // So there's no device huh?
198          if (pDevice == NULL) {          if (pDevice == NULL) {
199                  ui.DeviceListView->setCurrentItem(pRootItem);                  m_ui.DeviceListView->setCurrentItem(pRootItem);
200                  return;                  return;
201          }          }
202    
# Line 194  void DeviceForm::createDevice (void) Line 222  void DeviceForm::createDevice (void)
222          if (pMainForm == NULL)          if (pMainForm == NULL)
223                  return;                  return;
224    
225          QTreeWidgetItem *pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem *pItem = m_ui.DeviceListView->currentItem();
226          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
227                  return;                  return;
228    
# Line 232  void DeviceForm::deleteDevice (void) Line 260  void DeviceForm::deleteDevice (void)
260          if (pMainForm == NULL)          if (pMainForm == NULL)
261                  return;                  return;
262    
263          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
264          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
265                  return;                  return;
266    
# Line 243  void DeviceForm::deleteDevice (void) Line 271  void DeviceForm::deleteDevice (void)
271          if (pOptions && pOptions->bConfirmRemove) {          if (pOptions && pOptions->bConfirmRemove) {
272                  if (QMessageBox::warning(this,                  if (QMessageBox::warning(this,
273                          QSAMPLER_TITLE ": " + tr("Warning"),                          QSAMPLER_TITLE ": " + tr("Warning"),
274                          tr("Delete device:\n\n"                          tr("About to delete device:\n\n"
275                          "%1\n\n"                          "%1\n\n"
276                          "Are you sure?")                          "Are you sure?")
277                          .arg(device.deviceName()),                          .arg(device.deviceName()),
# Line 277  void DeviceForm::refreshDevices (void) Line 305  void DeviceForm::refreshDevices (void)
305          //          //
306          m_pAudioItems = NULL;          m_pAudioItems = NULL;
307          m_pMidiItems = NULL;          m_pMidiItems = NULL;
308          ui.DeviceListView->clear();          m_ui.DeviceListView->clear();
309          if (pMainForm->client()) {          if (pMainForm->client()) {
310                  int *piDeviceIDs;                  int *piDeviceIDs;
311                  // Grab and pop Audio devices...                  // Grab and pop Audio devices...
312                  if (m_deviceTypeMode == qsamplerDevice::None ||                  if (m_deviceTypeMode == qsamplerDevice::None ||
313                          m_deviceTypeMode == qsamplerDevice::Audio) {                          m_deviceTypeMode == qsamplerDevice::Audio) {
314                          m_pAudioItems = new qsamplerDeviceItem(ui.DeviceListView,                          m_pAudioItems = new qsamplerDeviceItem(m_ui.DeviceListView,
315                                  qsamplerDevice::Audio);                                  qsamplerDevice::Audio);
316                  }                  }
317                  if (m_pAudioItems) {                  if (m_pAudioItems) {
# Line 298  void DeviceForm::refreshDevices (void) Line 326  void DeviceForm::refreshDevices (void)
326                  // Grab and pop MIDI devices...                  // Grab and pop MIDI devices...
327                  if (m_deviceTypeMode == qsamplerDevice::None ||                  if (m_deviceTypeMode == qsamplerDevice::None ||
328                          m_deviceTypeMode == qsamplerDevice::Midi) {                          m_deviceTypeMode == qsamplerDevice::Midi) {
329                          m_pMidiItems = new qsamplerDeviceItem(ui.DeviceListView,                          m_pMidiItems = new qsamplerDeviceItem(m_ui.DeviceListView,
330                                  qsamplerDevice::Midi);                                  qsamplerDevice::Midi);
331                  }                  }
332                  if (m_pMidiItems) {                  if (m_pMidiItems) {
# Line 330  void DeviceForm::selectDriver ( const QS Line 358  void DeviceForm::selectDriver ( const QS
358          //  Driver name has changed for a new device...          //  Driver name has changed for a new device...
359          //          //
360    
361          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
362          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
363                  return;                  return;
364    
# Line 340  void DeviceForm::selectDriver ( const QS Line 368  void DeviceForm::selectDriver ( const QS
368          if (m_bNewDevice) {          if (m_bNewDevice) {
369                  m_iDirtySetup++;                  m_iDirtySetup++;
370                  device.setDriver(sDriverName);                  device.setDriver(sDriverName);
371                  deviceParamModel.refresh(device.params(), m_bNewDevice);                  m_deviceParamModel.refresh(&device, m_bNewDevice);
372                  m_iDirtySetup--;                  m_iDirtySetup--;
373                  // Done.                  // Done.
374                  stabilizeForm();                  stabilizeForm();
# Line 349  void DeviceForm::selectDriver ( const QS Line 377  void DeviceForm::selectDriver ( const QS
377    
378    
379  // Device selection slot.  // Device selection slot.
380  void DeviceForm::selectDevice (void)  void DeviceForm::selectDevice ()
381  {  {
382          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
383          if (pMainForm == NULL)          if (pMainForm == NULL)
# Line 362  void DeviceForm::selectDevice (void) Line 390  void DeviceForm::selectDevice (void)
390          //  Device selection has changed...          //  Device selection has changed...
391          //          //
392    
393          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
394          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) {          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) {
395                  m_deviceType = qsamplerDevice::None;                  m_deviceType = qsamplerDevice::None;
396                  ui.DeviceNameTextLabel->setText(QString::null);                  m_ui.DeviceNameTextLabel->setText(QString::null);
397                  deviceParamModel.clear();                  m_deviceParamModel.clear();
398                  ui.DevicePortComboBox->clear();                  m_ui.DevicePortComboBox->clear();
399                  devicePortParamModel.clear();                  m_devicePortParamModel.clear();
400                  ui.DevicePortTextLabel->setEnabled(false);                  m_ui.DevicePortTextLabel->setEnabled(false);
401                  ui.DevicePortComboBox->setEnabled(false);                  m_ui.DevicePortComboBox->setEnabled(false);
402                  ui.DevicePortParamTable->setEnabled(false);                  m_ui.DevicePortParamTable->setEnabled(false);
403                  stabilizeForm();                  stabilizeForm();
404                  return;                  return;
405          }          }
# Line 383  void DeviceForm::selectDevice (void) Line 411  void DeviceForm::selectDevice (void)
411          m_bNewDevice = (device.deviceID() < 0);          m_bNewDevice = (device.deviceID() < 0);
412    
413          // Fill the device/driver heading...          // Fill the device/driver heading...
414          ui.DeviceNameTextLabel->setText(device.deviceName());          m_ui.DeviceNameTextLabel->setText(device.deviceName());
415          // The driver combobox is only rebuilt if device type has changed...          // The driver combobox is only rebuilt if device type has changed...
416          if (device.deviceType() != m_deviceType) {          if (device.deviceType() != m_deviceType) {
417                  ui.DriverNameComboBox->clear();                  m_ui.DriverNameComboBox->clear();
418                  ui.DriverNameComboBox->insertStringList(                  m_ui.DriverNameComboBox->insertItems(0,
419                          qsamplerDevice::getDrivers(pMainForm->client(), device.deviceType()));                          qsamplerDevice::getDrivers(pMainForm->client(), device.deviceType()));
420                  m_deviceType = device.deviceType();                  m_deviceType = device.deviceType();
421          }          }
422          // Do we need a driver name?          // Do we need a driver name?
423          if (m_bNewDevice || device.driverName().isEmpty())          if (m_bNewDevice || device.driverName().isEmpty())
424                  device.setDriver(ui.DriverNameComboBox->currentText());                  device.setDriver(m_ui.DriverNameComboBox->currentText());
425          setDriverName(device.driverName());          setDriverName(device.driverName());
426          ui.DriverNameTextLabel->setEnabled(m_bNewDevice);          m_ui.DriverNameTextLabel->setEnabled(m_bNewDevice);
427          ui.DriverNameComboBox->setEnabled(m_bNewDevice);          m_ui.DriverNameComboBox->setEnabled(m_bNewDevice);
428          // Fill the device parameter table...          // Fill the device parameter table...
429          deviceParamModel.refresh(device.params(), m_bNewDevice);          m_deviceParamModel.refresh(&device, m_bNewDevice);
430          // And now the device port/channel parameter table...          // And now the device port/channel parameter table...
431          switch (device.deviceType()) {          switch (device.deviceType()) {
432          case qsamplerDevice::Audio:          case qsamplerDevice::Audio:
433                  ui.DevicePortTextLabel->setText(tr("Ch&annel:"));                  m_ui.DevicePortTextLabel->setText(tr("Ch&annel:"));
434                  break;                  break;
435          case qsamplerDevice::Midi:          case qsamplerDevice::Midi:
436                  ui.DevicePortTextLabel->setText(tr("P&ort:"));                  m_ui.DevicePortTextLabel->setText(tr("P&ort:"));
437                  break;                  break;
438          case qsamplerDevice::None:          case qsamplerDevice::None:
439                  break;                  break;
440          }          }
441          ui.DevicePortComboBox->clear();          m_ui.DevicePortComboBox->clear();
442          devicePortParamModel.clear();          m_devicePortParamModel.clear();
443          if (m_bNewDevice) {          if (m_bNewDevice) {
444                  ui.DevicePortTextLabel->setEnabled(false);                  m_ui.DevicePortTextLabel->setEnabled(false);
445                  ui.DevicePortComboBox->setEnabled(false);                  m_ui.DevicePortComboBox->setEnabled(false);
446                  ui.DevicePortParamTable->setEnabled(false);                  m_ui.DevicePortParamTable->setEnabled(false);
447          } else {          } else {
448                  QPixmap pixmap;                  QPixmap pixmap;
449                  switch (device.deviceType()) {                  switch (device.deviceType()) {
450                  case qsamplerDevice::Audio:                  case qsamplerDevice::Audio:
451                          pixmap = QPixmap(":/qsampler/pixmaps/audio2.png");                          pixmap = QPixmap(":/icons/audio2.png");
452                          break;                          break;
453                  case qsamplerDevice::Midi:                  case qsamplerDevice::Midi:
454                          pixmap = QPixmap(":/qsampler/pixmaps/midi2.png");                          pixmap = QPixmap(":/icons/midi2.png");
455                          break;                          break;
456                  case qsamplerDevice::None:                  case qsamplerDevice::None:
457                          break;                          break;
458                  }                  }
459                  qsamplerDevicePortList& ports = device.ports();                  qsamplerDevicePortList& ports = device.ports();
460                  qsamplerDevicePort *pPort;                  QListIterator<qsamplerDevicePort *> iter(ports);
461                  for (pPort = ports.first(); pPort; pPort = ports.next()) {                  while (iter.hasNext()) {
462                          ui.DevicePortComboBox->insertItem(pixmap, device.deviceTypeName()                          qsamplerDevicePort *pPort = iter.next();
463                            m_ui.DevicePortComboBox->addItem(pixmap,
464                                    device.deviceTypeName()
465                                  + ' ' + device.driverName()                                  + ' ' + device.driverName()
466                                  + ' ' + pPort->portName());                                  + ' ' + pPort->portName());
467                  }                  }
468                  bool bEnabled = (ports.count() > 0);                  bool bEnabled = (ports.count() > 0);
469                  ui.DevicePortTextLabel->setEnabled(bEnabled);                  m_ui.DevicePortTextLabel->setEnabled(bEnabled);
470                  ui.DevicePortComboBox->setEnabled(bEnabled);                  m_ui.DevicePortComboBox->setEnabled(bEnabled);
471                  ui.DevicePortParamTable->setEnabled(bEnabled);                  m_ui.DevicePortParamTable->setEnabled(bEnabled);
472          }          }
473          // Done.          // Done.
474          m_iDirtySetup--;          m_iDirtySetup--;
475    
476          // Make the device port/channel selection effective.          // Make the device port/channel selection effective.
477          selectDevicePort(ui.DevicePortComboBox->currentItem());          selectDevicePort(m_ui.DevicePortComboBox->currentIndex());
478  }  }
479    
480    
# Line 458  void DeviceForm::selectDevicePort ( int Line 488  void DeviceForm::selectDevicePort ( int
488          //  Device port/channel selection has changed...          //  Device port/channel selection has changed...
489          //          //
490    
491          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
492          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
493                  return;                  return;
494    
495          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
496          qsamplerDevicePort *pPort = device.ports().at(iPort);          qsamplerDevicePort *pPort = NULL;
497            if (iPort >= 0 && iPort < device.ports().count())
498                    pPort = device.ports().at(iPort);
499          if (pPort) {          if (pPort) {
500                  m_iDirtySetup++;                  m_iDirtySetup++;
501                  devicePortParamModel.refresh(pPort->params(), false);                  m_devicePortParamModel.refresh(pPort, false);
502                  m_iDirtySetup--;                  m_iDirtySetup--;
503          }          }
504          // Done.          // Done.
# Line 486  void DeviceForm::changeDeviceParam ( int Line 518  void DeviceForm::changeDeviceParam ( int
518          //  Device parameter change...          //  Device parameter change...
519          //          //
520    
521          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();  /* we do that in the model class now ...
522            QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
523          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
524                  return;                  return;
525    
526          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
527    
528          // Table 1st column has the parameter name;          // Table 1st column has the parameter name;
529          //const QString sParam = ui.DeviceParamTable->text(iRow, 0);          //const QString sParam = m_ui.DeviceParamTable->text(iRow, 0);
530          //const QString sValue = ui.DeviceParamTable->text(iRow, iCol);          //const QString sValue = m_ui.DeviceParamTable->text(iRow, iCol);
531          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;
532          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;
533          // Set the local device parameter value.          // Set the local device parameter value.
534          if (device.setParam(sParam, sValue)) {          if (device.setParam(sParam, sValue)) {
535                  selectDevice();                  selectDevice();
536          } else {          } else {
537                  stabilizeForm();                  stabilizeForm();
538          }          }
539    */
540    
541          // Main session should be dirtier...          // Main session should be dirtier...
542          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
# Line 523  void DeviceForm::changeDevicePortParam ( Line 557  void DeviceForm::changeDevicePortParam (
557          //  Device port/channel parameter change...          //  Device port/channel parameter change...
558          //          //
559    
560          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();  /* we do that in the model class now ...
561            QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
562          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
563                  return;                  return;
564    
565          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
566    
567          int iPort = ui.DevicePortComboBox->currentItem();          int iPort = m_ui.DevicePortComboBox->currentIndex();
568          qsamplerDevicePort *pPort = device.ports().at(iPort);          qsamplerDevicePort *pPort = NULL;
569            if (iPort >= 0 && iPort < device.ports().count())
570                    pPort = device.ports().at(iPort);
571          if (pPort == NULL)          if (pPort == NULL)
572                  return;                  return;
573    
574          // Table 1st column has the parameter name;          // Table 1st column has the parameter name;
575          //const QString sParam = ui.DevicePortParamTable->text(iRow, 0);          //const QString sParam = m_ui.DevicePortParamTable->text(iRow, 0);
576          //const QString sValue = ui.DevicePortParamTable->text(iRow, iCol);          //const QString sValue = m_ui.DevicePortParamTable->text(iRow, iCol);
577          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;
578          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;
579    
580          // Set the local device port/channel parameter value.          // Set the local device port/channel parameter value.
581          pPort->setParam(sParam, sValue);          pPort->setParam(sParam, sValue);
582    */
583    
584          // Done.          // Done.
585          stabilizeForm();          stabilizeForm();
586    
# Line 559  void DeviceForm::deviceListViewContextMe Line 598  void DeviceForm::deviceListViewContextMe
598          if (pMainForm == NULL)          if (pMainForm == NULL)
599                  return;                  return;
600    
601          QTreeWidgetItem* pItem = ui.DeviceListView->itemAt(pos);          QTreeWidgetItem* pItem = m_ui.DeviceListView->itemAt(pos);
602          if (pItem == NULL)          if (pItem == NULL)
603                  return;                  return;
604    
         int iItemID;  
   
605          // Build the device context menu...          // Build the device context menu...
606          QMenu* pContextMenu = new QMenu(this);          QMenu menu(this);
607            QAction *pAction;
608    
609          bool bClient = (pMainForm->client() != NULL);          bool bClient = (pMainForm->client() != NULL);
610          bool bEnabled = (pItem != NULL);          bool bEnabled = (pItem != NULL);
611          iItemID = pContextMenu->insertItem(          pAction = menu.addAction(
612                  QIconSet(QPixmap(":/qsampler/pixmaps/deviceCreate.png")),                  QIcon(":/qsampler/pixmaps/deviceCreate.png"),
613                  tr("&Create device"), this, SLOT(createDevice()));                  tr("&Create device"), this, SLOT(createDevice()));
614          pContextMenu->setItemEnabled(iItemID, bEnabled || (bClient && m_bNewDevice));          pAction->setEnabled(bEnabled || (bClient && m_bNewDevice));
615          iItemID = pContextMenu->insertItem(          pAction = menu.addAction(
616                  QIconSet(QPixmap(":/qsampler/pixmaps/deviceDelete.png")),                  QIcon(":/qsampler/pixmaps/deviceDelete.png"),
617                  tr("&Delete device"), this, SLOT(deleteDevice()));                  tr("&Delete device"), this, SLOT(deleteDevice()));
618          pContextMenu->setItemEnabled(iItemID, bEnabled && !m_bNewDevice);          pAction->setEnabled(bEnabled && !m_bNewDevice);
619          pContextMenu->insertSeparator();          menu.addSeparator();
620          iItemID = pContextMenu->insertItem(          pAction = menu.addAction(
621                  QIconSet(QPixmap(":/qsampler/pixmaps/formRefresh.png")),                  QIcon(":/qsampler/pixmaps/formRefresh.png"),
622                  tr("&Refresh"), this, SLOT(refreshDevices()));                  tr("&Refresh"), this, SLOT(refreshDevices()));
623          pContextMenu->setItemEnabled(iItemID, bClient);          pAction->setEnabled(bClient);
624    
625          pContextMenu->exec(pos);          menu.exec(pos);
   
         delete pContextMenu;  
626  }  }
627    
628    
# Line 594  void DeviceForm::deviceListViewContextMe Line 630  void DeviceForm::deviceListViewContextMe
630  void DeviceForm::stabilizeForm (void)  void DeviceForm::stabilizeForm (void)
631  {  {
632          MainForm* pMainForm = MainForm::getInstance();          MainForm* pMainForm = MainForm::getInstance();
633          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
634          bool bClient = (pMainForm && pMainForm->client() != NULL);          bool bClient = (pMainForm && pMainForm->client() != NULL);
635          bool bEnabled = (pItem != NULL);          bool bEnabled = (pItem != NULL);
636          ui.DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice);          m_ui.DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice);
637          ui.DriverNameTextLabel->setEnabled(bEnabled &&  m_bNewDevice);          m_ui.DriverNameTextLabel->setEnabled(bEnabled &&  m_bNewDevice);
638          ui.DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice);          m_ui.DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice);
639          ui.DeviceParamTable->setEnabled(bEnabled);          m_ui.DeviceParamTable->setEnabled(bEnabled);
640          ui.RefreshDevicesPushButton->setEnabled(bClient);          m_ui.RefreshDevicesPushButton->setEnabled(bClient);
641          ui.CreateDevicePushButton->setEnabled(bEnabled || (bClient && m_bNewDevice));          m_ui.CreateDevicePushButton->setEnabled(bEnabled || (bClient && m_bNewDevice));
642          ui.DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice);          m_ui.DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice);
643    }
644    
645    
646    void DeviceForm::updateCellRenderers (void)
647    {
648            const int rows = m_deviceParamModel.rowCount();
649            const int cols = m_deviceParamModel.columnCount();
650            updateCellRenderers(
651                    m_deviceParamModel.index(0, 0),
652                    m_deviceParamModel.index(rows - 1, cols - 1));
653    }
654    
655    
656    void DeviceForm::updateCellRenderers (
657            const QModelIndex& topLeft, const QModelIndex& bottomRight )
658    {
659            for (int r = topLeft.row(); r <= bottomRight.row(); r++) {
660                    for (int c = topLeft.column(); c <= bottomRight.column(); c++) {
661                            const QModelIndex index = m_deviceParamModel.index(r, c);
662                            m_ui.DeviceParamTable->openPersistentEditor(index);
663                    }
664            }
665    }
666    
667    
668    void DeviceForm::updatePortCellRenderers (void)
669    {
670            const int rows = m_devicePortParamModel.rowCount();
671            const int cols = m_devicePortParamModel.columnCount();
672            updatePortCellRenderers(
673                    m_devicePortParamModel.index(0, 0),
674                    m_devicePortParamModel.index(rows - 1, cols - 1));
675    }
676    
677    
678    void DeviceForm::updatePortCellRenderers (
679            const QModelIndex& topLeft, const QModelIndex& bottomRight )
680    {
681            for (int r = topLeft.row(); r <= bottomRight.row(); r++) {
682                    for (int c = topLeft.column(); c <= bottomRight.column(); c++) {
683                            const QModelIndex index = m_devicePortParamModel.index(r, c);
684                            m_ui.DevicePortParamTable->openPersistentEditor(index);
685                    }
686            }
687  }  }
688    
689  } // namespace QSampler  } // namespace QSampler

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

  ViewVC Help
Powered by ViewVC