/[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 1464 by capela, Thu Nov 1 17:14:21 2007 UTC revision 1509 by capela, Thu Nov 22 11:10:44 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.          m_ui.DeviceParamTable->setModel(&m_deviceParamModel);
52          //QObject::connect(DeviceParamTable, SIGNAL(valueChanged(int,int)),          m_ui.DeviceParamTable->setItemDelegate(&m_deviceParamDelegate);
53          //      this, SLOT(changeDeviceParam(int,int)));          m_ui.DeviceParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);
54          //QObject::connect(DevicePortParamTable, SIGNAL(valueChanged(int,int)),          m_ui.DeviceParamTable->verticalHeader()->hide();
55          //      this, SLOT(changeDevicePortParam(int,int)));  
56            m_ui.DevicePortParamTable->setModel(&m_devicePortParamModel);
57            m_ui.DevicePortParamTable->setItemDelegate(&m_devicePortParamDelegate);
58            m_ui.DevicePortParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);
59            m_ui.DevicePortParamTable->verticalHeader()->hide();
60    
61          // Initial contents.          // Initial contents.
62          refreshDevices();          refreshDevices();
63          // Try to restore normal window positioning.          // Try to restore normal window positioning.
64          adjustSize();          adjustSize();
65    
66            QObject::connect(m_ui.DeviceListView,
67                    SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
68                    SLOT(selectDevice()));
69            QObject::connect(m_ui.DeviceListView,
70                    SIGNAL(customContextMenuRequested(const QPoint&)),
71                    SLOT(deviceListViewContextMenu(const QPoint&)));
72            QObject::connect(m_ui.RefreshDevicesPushButton,
73                    SIGNAL(clicked()),
74                    SLOT(refreshDevices()));
75            QObject::connect(m_ui.DriverNameComboBox,
76                    SIGNAL(activated(const QString&)),
77                    SLOT(selectDriver(const QString&)));
78            QObject::connect(m_ui.DevicePortComboBox,
79                    SIGNAL(activated(int)),
80                    SLOT(selectDevicePort(int)));
81            QObject::connect(m_ui.CreateDevicePushButton,
82                    SIGNAL(clicked()),
83                    SLOT(createDevice()));
84            QObject::connect(m_ui.DeleteDevicePushButton,
85                    SIGNAL(clicked()),
86                    SLOT(deleteDevice()));
87            QObject::connect(m_ui.ClosePushButton,
88                    SIGNAL(clicked()),
89                    SLOT(close()));
90            QObject::connect(&m_deviceParamModel,
91                    SIGNAL(modelReset()),
92                    SLOT(updateCellRenderers()));
93            QObject::connect(&m_deviceParamModel,
94                    SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
95                    SLOT(updateCellRenderers(const QModelIndex&, const QModelIndex&)));
96            QObject::connect(&m_devicePortParamModel,
97                    SIGNAL(modelReset()),
98                    SLOT(updatePortCellRenderers()));
99            QObject::connect(&m_devicePortParamModel,
100                    SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
101                    SLOT(updatePortCellRenderers(const QModelIndex&, const QModelIndex&)));
102  }  }
103    
104  DeviceForm::~DeviceForm() {  DeviceForm::~DeviceForm() {
# Line 93  void DeviceForm::hideEvent ( QHideEvent Line 137  void DeviceForm::hideEvent ( QHideEvent
137    
138  // Set device type spacial exclusive mode.  // Set device type spacial exclusive mode.
139  void DeviceForm::setDeviceTypeMode (  void DeviceForm::setDeviceTypeMode (
140          qsamplerDevice::qsamplerDeviceType deviceTypeMode )          qsamplerDevice::DeviceType deviceTypeMode )
141  {  {
142          // If it has not changed, do nothing.          // If it has not changed, do nothing.
143          if (m_deviceTypeMode == deviceTypeMode)          if (m_deviceTypeMode == deviceTypeMode)
# Line 109  void DeviceForm::setDeviceTypeMode ( Line 153  void DeviceForm::setDeviceTypeMode (
153  // Device driver name setup formal initializer.  // Device driver name setup formal initializer.
154  void DeviceForm::setDriverName ( const QString& sDriverName )  void DeviceForm::setDriverName ( const QString& sDriverName )
155  {  {
156          if (ui.DriverNameComboBox->findText(sDriverName) == 0) {          if (m_ui.DriverNameComboBox->findText(sDriverName) < 0)
157                  ui.DriverNameComboBox->insertItem(sDriverName);                  m_ui.DriverNameComboBox->insertItem(0, sDriverName);
158          }          m_ui.DriverNameComboBox->setItemText(
159          ui.DriverNameComboBox->setCurrentText(sDriverName);                  m_ui.DriverNameComboBox->currentIndex(),
160                    sDriverName);
161  }  }
162    
163    
# Line 120  void DeviceForm::setDriverName ( const Q Line 165  void DeviceForm::setDriverName ( const Q
165  void DeviceForm::setDevice ( qsamplerDevice *pDevice )  void DeviceForm::setDevice ( qsamplerDevice *pDevice )
166  {  {
167          // In case no device is given...          // In case no device is given...
168          qsamplerDevice::qsamplerDeviceType deviceType = m_deviceTypeMode;          qsamplerDevice::DeviceType deviceType = m_deviceTypeMode;
169          if (pDevice)          if (pDevice)
170                  deviceType = pDevice->deviceType();                  deviceType = pDevice->deviceType();
171    
# Line 143  void DeviceForm::setDevice ( qsamplerDev Line 188  void DeviceForm::setDevice ( qsamplerDev
188    
189          // So there's no device huh?          // So there's no device huh?
190          if (pDevice == NULL) {          if (pDevice == NULL) {
191                  ui.DeviceListView->setCurrentItem(pRootItem);                  m_ui.DeviceListView->setCurrentItem(pRootItem);
192                  return;                  return;
193          }          }
194    
# Line 169  void DeviceForm::createDevice (void) Line 214  void DeviceForm::createDevice (void)
214          if (pMainForm == NULL)          if (pMainForm == NULL)
215                  return;                  return;
216    
217          QTreeWidgetItem *pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem *pItem = m_ui.DeviceListView->currentItem();
218          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
219                  return;                  return;
220    
# Line 207  void DeviceForm::deleteDevice (void) Line 252  void DeviceForm::deleteDevice (void)
252          if (pMainForm == NULL)          if (pMainForm == NULL)
253                  return;                  return;
254    
255          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
256          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
257                  return;                  return;
258    
# Line 252  void DeviceForm::refreshDevices (void) Line 297  void DeviceForm::refreshDevices (void)
297          //          //
298          m_pAudioItems = NULL;          m_pAudioItems = NULL;
299          m_pMidiItems = NULL;          m_pMidiItems = NULL;
300          ui.DeviceListView->clear();          m_ui.DeviceListView->clear();
301          if (pMainForm->client()) {          if (pMainForm->client()) {
302                  int *piDeviceIDs;                  int *piDeviceIDs;
303                  // Grab and pop Audio devices...                  // Grab and pop Audio devices...
304                  if (m_deviceTypeMode == qsamplerDevice::None ||                  if (m_deviceTypeMode == qsamplerDevice::None ||
305                          m_deviceTypeMode == qsamplerDevice::Audio) {                          m_deviceTypeMode == qsamplerDevice::Audio) {
306                          m_pAudioItems = new qsamplerDeviceItem(ui.DeviceListView,                          m_pAudioItems = new qsamplerDeviceItem(m_ui.DeviceListView,
307                                  qsamplerDevice::Audio);                                  qsamplerDevice::Audio);
308                  }                  }
309                  if (m_pAudioItems) {                  if (m_pAudioItems) {
# Line 273  void DeviceForm::refreshDevices (void) Line 318  void DeviceForm::refreshDevices (void)
318                  // Grab and pop MIDI devices...                  // Grab and pop MIDI devices...
319                  if (m_deviceTypeMode == qsamplerDevice::None ||                  if (m_deviceTypeMode == qsamplerDevice::None ||
320                          m_deviceTypeMode == qsamplerDevice::Midi) {                          m_deviceTypeMode == qsamplerDevice::Midi) {
321                          m_pMidiItems = new qsamplerDeviceItem(ui.DeviceListView,                          m_pMidiItems = new qsamplerDeviceItem(m_ui.DeviceListView,
322                                  qsamplerDevice::Midi);                                  qsamplerDevice::Midi);
323                  }                  }
324                  if (m_pMidiItems) {                  if (m_pMidiItems) {
# Line 305  void DeviceForm::selectDriver ( const QS Line 350  void DeviceForm::selectDriver ( const QS
350          //  Driver name has changed for a new device...          //  Driver name has changed for a new device...
351          //          //
352    
353          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
354          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
355                  return;                  return;
356    
# Line 315  void DeviceForm::selectDriver ( const QS Line 360  void DeviceForm::selectDriver ( const QS
360          if (m_bNewDevice) {          if (m_bNewDevice) {
361                  m_iDirtySetup++;                  m_iDirtySetup++;
362                  device.setDriver(sDriverName);                  device.setDriver(sDriverName);
363                  deviceParamModel.refresh(device.params(), m_bNewDevice);                  m_deviceParamModel.refresh(&device, m_bNewDevice);
364                  m_iDirtySetup--;                  m_iDirtySetup--;
365                  // Done.                  // Done.
366                  stabilizeForm();                  stabilizeForm();
# Line 324  void DeviceForm::selectDriver ( const QS Line 369  void DeviceForm::selectDriver ( const QS
369    
370    
371  // Device selection slot.  // Device selection slot.
372  void DeviceForm::selectDevice (void)  void DeviceForm::selectDevice ()
373  {  {
374          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
375          if (pMainForm == NULL)          if (pMainForm == NULL)
# Line 337  void DeviceForm::selectDevice (void) Line 382  void DeviceForm::selectDevice (void)
382          //  Device selection has changed...          //  Device selection has changed...
383          //          //
384    
385          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
386          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) {          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) {
387                  m_deviceType = qsamplerDevice::None;                  m_deviceType = qsamplerDevice::None;
388                  ui.DeviceNameTextLabel->setText(QString::null);                  m_ui.DeviceNameTextLabel->setText(QString::null);
389                  deviceParamModel.clear();                  m_deviceParamModel.clear();
390                  ui.DevicePortComboBox->clear();                  m_ui.DevicePortComboBox->clear();
391                  devicePortParamModel.clear();                  m_devicePortParamModel.clear();
392                  ui.DevicePortTextLabel->setEnabled(false);                  m_ui.DevicePortTextLabel->setEnabled(false);
393                  ui.DevicePortComboBox->setEnabled(false);                  m_ui.DevicePortComboBox->setEnabled(false);
394                  ui.DevicePortParamTable->setEnabled(false);                  m_ui.DevicePortParamTable->setEnabled(false);
395                  stabilizeForm();                  stabilizeForm();
396                  return;                  return;
397          }          }
# Line 358  void DeviceForm::selectDevice (void) Line 403  void DeviceForm::selectDevice (void)
403          m_bNewDevice = (device.deviceID() < 0);          m_bNewDevice = (device.deviceID() < 0);
404    
405          // Fill the device/driver heading...          // Fill the device/driver heading...
406          ui.DeviceNameTextLabel->setText(device.deviceName());          m_ui.DeviceNameTextLabel->setText(device.deviceName());
407          // The driver combobox is only rebuilt if device type has changed...          // The driver combobox is only rebuilt if device type has changed...
408          if (device.deviceType() != m_deviceType) {          if (device.deviceType() != m_deviceType) {
409                  ui.DriverNameComboBox->clear();                  m_ui.DriverNameComboBox->clear();
410                  ui.DriverNameComboBox->insertStringList(                  m_ui.DriverNameComboBox->insertItems(0,
411                          qsamplerDevice::getDrivers(pMainForm->client(), device.deviceType()));                          qsamplerDevice::getDrivers(pMainForm->client(), device.deviceType()));
412                  m_deviceType = device.deviceType();                  m_deviceType = device.deviceType();
413          }          }
414          // Do we need a driver name?          // Do we need a driver name?
415          if (m_bNewDevice || device.driverName().isEmpty())          if (m_bNewDevice || device.driverName().isEmpty())
416                  device.setDriver(ui.DriverNameComboBox->currentText());                  device.setDriver(m_ui.DriverNameComboBox->currentText());
417          setDriverName(device.driverName());          setDriverName(device.driverName());
418          ui.DriverNameTextLabel->setEnabled(m_bNewDevice);          m_ui.DriverNameTextLabel->setEnabled(m_bNewDevice);
419          ui.DriverNameComboBox->setEnabled(m_bNewDevice);          m_ui.DriverNameComboBox->setEnabled(m_bNewDevice);
420          // Fill the device parameter table...          // Fill the device parameter table...
421          deviceParamModel.refresh(device.params(), m_bNewDevice);          m_deviceParamModel.refresh(&device, m_bNewDevice);
422          // And now the device port/channel parameter table...          // And now the device port/channel parameter table...
423          switch (device.deviceType()) {          switch (device.deviceType()) {
424          case qsamplerDevice::Audio:          case qsamplerDevice::Audio:
425                  ui.DevicePortTextLabel->setText(tr("Ch&annel:"));                  m_ui.DevicePortTextLabel->setText(tr("Ch&annel:"));
426                  break;                  break;
427          case qsamplerDevice::Midi:          case qsamplerDevice::Midi:
428                  ui.DevicePortTextLabel->setText(tr("P&ort:"));                  m_ui.DevicePortTextLabel->setText(tr("P&ort:"));
429                  break;                  break;
430          case qsamplerDevice::None:          case qsamplerDevice::None:
431                  break;                  break;
432          }          }
433          ui.DevicePortComboBox->clear();          m_ui.DevicePortComboBox->clear();
434          devicePortParamModel.clear();          m_devicePortParamModel.clear();
435          if (m_bNewDevice) {          if (m_bNewDevice) {
436                  ui.DevicePortTextLabel->setEnabled(false);                  m_ui.DevicePortTextLabel->setEnabled(false);
437                  ui.DevicePortComboBox->setEnabled(false);                  m_ui.DevicePortComboBox->setEnabled(false);
438                  ui.DevicePortParamTable->setEnabled(false);                  m_ui.DevicePortParamTable->setEnabled(false);
439          } else {          } else {
440                  QPixmap pixmap;                  QPixmap pixmap;
441                  switch (device.deviceType()) {                  switch (device.deviceType()) {
442                  case qsamplerDevice::Audio:                  case qsamplerDevice::Audio:
443                          pixmap = QPixmap(":/qsampler/pixmaps/audio2.png");                          pixmap = QPixmap(":/icons/audio2.png");
444                          break;                          break;
445                  case qsamplerDevice::Midi:                  case qsamplerDevice::Midi:
446                          pixmap = QPixmap(":/qsampler/pixmaps/midi2.png");                          pixmap = QPixmap(":/icons/midi2.png");
447                          break;                          break;
448                  case qsamplerDevice::None:                  case qsamplerDevice::None:
449                          break;                          break;
450                  }                  }
451                  qsamplerDevicePortList& ports = device.ports();                  qsamplerDevicePortList& ports = device.ports();
452                  qsamplerDevicePort *pPort;                  QListIterator<qsamplerDevicePort *> iter(ports);
453                  for (pPort = ports.first(); pPort; pPort = ports.next()) {                  while (iter.hasNext()) {
454                          ui.DevicePortComboBox->insertItem(pixmap, device.deviceTypeName()                          qsamplerDevicePort *pPort = iter.next();
455                            m_ui.DevicePortComboBox->addItem(pixmap,
456                                    device.deviceTypeName()
457                                  + ' ' + device.driverName()                                  + ' ' + device.driverName()
458                                  + ' ' + pPort->portName());                                  + ' ' + pPort->portName());
459                  }                  }
460                  bool bEnabled = (ports.count() > 0);                  bool bEnabled = (ports.count() > 0);
461                  ui.DevicePortTextLabel->setEnabled(bEnabled);                  m_ui.DevicePortTextLabel->setEnabled(bEnabled);
462                  ui.DevicePortComboBox->setEnabled(bEnabled);                  m_ui.DevicePortComboBox->setEnabled(bEnabled);
463                  ui.DevicePortParamTable->setEnabled(bEnabled);                  m_ui.DevicePortParamTable->setEnabled(bEnabled);
464          }          }
465          // Done.          // Done.
466          m_iDirtySetup--;          m_iDirtySetup--;
467    
468          // Make the device port/channel selection effective.          // Make the device port/channel selection effective.
469          selectDevicePort(ui.DevicePortComboBox->currentItem());          selectDevicePort(m_ui.DevicePortComboBox->currentIndex());
470  }  }
471    
472    
# Line 433  void DeviceForm::selectDevicePort ( int Line 480  void DeviceForm::selectDevicePort ( int
480          //  Device port/channel selection has changed...          //  Device port/channel selection has changed...
481          //          //
482    
483          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
484          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
485                  return;                  return;
486    
487          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
488          qsamplerDevicePort *pPort = device.ports().at(iPort);          qsamplerDevicePort *pPort = NULL;
489            if (iPort >= 0 && iPort < device.ports().count())
490                    pPort = device.ports().at(iPort);
491          if (pPort) {          if (pPort) {
492                  m_iDirtySetup++;                  m_iDirtySetup++;
493                  devicePortParamModel.refresh(pPort->params(), false);                  m_devicePortParamModel.refresh(pPort, false);
494                  m_iDirtySetup--;                  m_iDirtySetup--;
495          }          }
496          // Done.          // Done.
# Line 461  void DeviceForm::changeDeviceParam ( int Line 510  void DeviceForm::changeDeviceParam ( int
510          //  Device parameter change...          //  Device parameter change...
511          //          //
512    
513          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();  /* we do that in the model class now ...
514            QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
515          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
516                  return;                  return;
517    
518          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
519    
520          // Table 1st column has the parameter name;          // Table 1st column has the parameter name;
521          //const QString sParam = ui.DeviceParamTable->text(iRow, 0);          //const QString sParam = m_ui.DeviceParamTable->text(iRow, 0);
522          //const QString sValue = ui.DeviceParamTable->text(iRow, iCol);          //const QString sValue = m_ui.DeviceParamTable->text(iRow, iCol);
523          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;
524          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;
525          // Set the local device parameter value.          // Set the local device parameter value.
526          if (device.setParam(sParam, sValue)) {          if (device.setParam(sParam, sValue)) {
527                  selectDevice();                  selectDevice();
528          } else {          } else {
529                  stabilizeForm();                  stabilizeForm();
530          }          }
531    */
532    
533          // Main session should be dirtier...          // Main session should be dirtier...
534          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
# Line 498  void DeviceForm::changeDevicePortParam ( Line 549  void DeviceForm::changeDevicePortParam (
549          //  Device port/channel parameter change...          //  Device port/channel parameter change...
550          //          //
551    
552          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();  /* we do that in the model class now ...
553            QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
554          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
555                  return;                  return;
556    
557          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
558    
559          int iPort = ui.DevicePortComboBox->currentItem();          int iPort = m_ui.DevicePortComboBox->currentIndex();
560          qsamplerDevicePort *pPort = device.ports().at(iPort);          qsamplerDevicePort *pPort = NULL;
561            if (iPort >= 0 && iPort < device.ports().count())
562                    pPort = device.ports().at(iPort);
563          if (pPort == NULL)          if (pPort == NULL)
564                  return;                  return;
565    
566          // Table 1st column has the parameter name;          // Table 1st column has the parameter name;
567          //const QString sParam = ui.DevicePortParamTable->text(iRow, 0);          //const QString sParam = m_ui.DevicePortParamTable->text(iRow, 0);
568          //const QString sValue = ui.DevicePortParamTable->text(iRow, iCol);          //const QString sValue = m_ui.DevicePortParamTable->text(iRow, iCol);
569          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;
570          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;
571    
572          // Set the local device port/channel parameter value.          // Set the local device port/channel parameter value.
573          pPort->setParam(sParam, sValue);          pPort->setParam(sParam, sValue);
574    */
575    
576          // Done.          // Done.
577          stabilizeForm();          stabilizeForm();
578    
# Line 528  void DeviceForm::changeDevicePortParam ( Line 584  void DeviceForm::changeDevicePortParam (
584    
585    
586  // Device list view context menu handler.  // Device list view context menu handler.
587  void DeviceForm::contextMenu ( QTreeWidgetItem* pItem, const QPoint& pos, int )  void DeviceForm::deviceListViewContextMenu ( const QPoint& pos )
588  {  {
589          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
590          if (pMainForm == NULL)          if (pMainForm == NULL)
591                  return;                  return;
592    
593          int iItemID;          QTreeWidgetItem* pItem = m_ui.DeviceListView->itemAt(pos);
594            if (pItem == NULL)
595                    return;
596    
597          // Build the device context menu...          // Build the device context menu...
598          QMenu* pContextMenu = new QMenu(this);          QMenu menu(this);
599            QAction *pAction;
600    
601          bool bClient = (pMainForm->client() != NULL);          bool bClient = (pMainForm->client() != NULL);
602          bool bEnabled = (pItem != NULL);          bool bEnabled = (pItem != NULL);
603          iItemID = pContextMenu->insertItem(          pAction = menu.addAction(
604                  QIconSet(QPixmap(":/qsampler/pixmaps/deviceCreate.png")),                  QIcon(":/qsampler/pixmaps/deviceCreate.png"),
605                  tr("&Create device"), this, SLOT(createDevice()));                  tr("&Create device"), this, SLOT(createDevice()));
606          pContextMenu->setItemEnabled(iItemID, bEnabled || (bClient && m_bNewDevice));          pAction->setEnabled(bEnabled || (bClient && m_bNewDevice));
607          iItemID = pContextMenu->insertItem(          pAction = menu.addAction(
608                  QIconSet(QPixmap(":/qsampler/pixmaps/deviceDelete.png")),                  QIcon(":/qsampler/pixmaps/deviceDelete.png"),
609                  tr("&Delete device"), this, SLOT(deleteDevice()));                  tr("&Delete device"), this, SLOT(deleteDevice()));
610          pContextMenu->setItemEnabled(iItemID, bEnabled && !m_bNewDevice);          pAction->setEnabled(bEnabled && !m_bNewDevice);
611          pContextMenu->insertSeparator();          menu.addSeparator();
612          iItemID = pContextMenu->insertItem(          pAction = menu.addAction(
613                  QIconSet(QPixmap(":/qsampler/pixmaps/formRefresh.png")),                  QIcon(":/qsampler/pixmaps/formRefresh.png"),
614                  tr("&Refresh"), this, SLOT(refreshDevices()));                  tr("&Refresh"), this, SLOT(refreshDevices()));
615          pContextMenu->setItemEnabled(iItemID, bClient);          pAction->setEnabled(bClient);
616    
617          pContextMenu->exec(pos);          menu.exec(pos);
   
         delete pContextMenu;  
618  }  }
619    
620    
# Line 565  void DeviceForm::contextMenu ( QTreeWidg Line 622  void DeviceForm::contextMenu ( QTreeWidg
622  void DeviceForm::stabilizeForm (void)  void DeviceForm::stabilizeForm (void)
623  {  {
624          MainForm* pMainForm = MainForm::getInstance();          MainForm* pMainForm = MainForm::getInstance();
625          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
626          bool bClient = (pMainForm && pMainForm->client() != NULL);          bool bClient = (pMainForm && pMainForm->client() != NULL);
627          bool bEnabled = (pItem != NULL);          bool bEnabled = (pItem != NULL);
628          ui.DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice);          m_ui.DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice);
629          ui.DriverNameTextLabel->setEnabled(bEnabled &&  m_bNewDevice);          m_ui.DriverNameTextLabel->setEnabled(bEnabled &&  m_bNewDevice);
630          ui.DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice);          m_ui.DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice);
631          ui.DeviceParamTable->setEnabled(bEnabled);          m_ui.DeviceParamTable->setEnabled(bEnabled);
632          ui.RefreshDevicesPushButton->setEnabled(bClient);          m_ui.RefreshDevicesPushButton->setEnabled(bClient);
633          ui.CreateDevicePushButton->setEnabled(bEnabled || (bClient && m_bNewDevice));          m_ui.CreateDevicePushButton->setEnabled(bEnabled || (bClient && m_bNewDevice));
634          ui.DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice);          m_ui.DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice);
635    }
636    
637    
638    void DeviceForm::updateCellRenderers (void)
639    {
640            const int rows = m_deviceParamModel.rowCount();
641            const int cols = m_deviceParamModel.columnCount();
642            updateCellRenderers(
643                    m_deviceParamModel.index(0, 0),
644                    m_deviceParamModel.index(rows - 1, cols - 1));
645    }
646    
647    
648    void DeviceForm::updateCellRenderers (
649            const QModelIndex& topLeft, const QModelIndex& bottomRight )
650    {
651            for (int r = topLeft.row(); r <= bottomRight.row(); r++) {
652                    for (int c = topLeft.column(); c <= bottomRight.column(); c++) {
653                            const QModelIndex index = m_deviceParamModel.index(r, c);
654                            m_ui.DeviceParamTable->openPersistentEditor(index);
655                    }
656            }
657    }
658    
659    
660    void DeviceForm::updatePortCellRenderers (void)
661    {
662            const int rows = m_devicePortParamModel.rowCount();
663            const int cols = m_devicePortParamModel.columnCount();
664            updatePortCellRenderers(
665                    m_devicePortParamModel.index(0, 0),
666                    m_devicePortParamModel.index(rows - 1, cols - 1));
667    }
668    
669    
670    void DeviceForm::updatePortCellRenderers (
671            const QModelIndex& topLeft, const QModelIndex& bottomRight )
672    {
673            for (int r = topLeft.row(); r <= bottomRight.row(); r++) {
674                    for (int c = topLeft.column(); c <= bottomRight.column(); c++) {
675                            const QModelIndex index = m_devicePortParamModel.index(r, c);
676                            m_ui.DevicePortParamTable->openPersistentEditor(index);
677                    }
678            }
679  }  }
680    
681  } // namespace QSampler  } // namespace QSampler

Legend:
Removed from v.1464  
changed lines
  Added in v.1509

  ViewVC Help
Powered by ViewVC