/[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 1558 by capela, Thu Dec 6 09:35:33 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) {  //-------------------------------------------------------------------------
35      ui.setupUi(this);  // QSampler::DeviceForm -- Device form implementation.
36    //
37    
38    DeviceForm::DeviceForm ( QWidget *pParent, Qt::WindowFlags wflags )
39            : QDialog(pParent, wflags)
40    {
41            m_ui.setupUi(this);
42    
43          // Initialize locals.          // Initialize locals.
44          m_iDirtySetup = 0;          m_iDirtySetup = 0;
45          m_iDirtyCount = 0;          m_iDirtyCount = 0;
46          m_bNewDevice  = false;          m_bNewDevice  = false;
47          m_deviceType  = qsamplerDevice::None;          m_deviceType  = Device::None;
48          m_pAudioItems = NULL;          m_pAudioItems = NULL;
49          m_pMidiItems  = NULL;          m_pMidiItems  = NULL;
50          // No exclusive mode as default.          // No exclusive mode as default.
51          m_deviceTypeMode = qsamplerDevice::None;          m_deviceTypeMode = Device::None;
   
         ui.DeviceParamTable->setModel(&deviceParamModel);  
         ui.DeviceParamTable->setItemDelegate(&deviceParamDelegate);  
52    
53          ui.DevicePortParamTable->setModel(&devicePortParamModel);          m_ui.DeviceListView->header()->hide();
         ui.DevicePortParamTable->setItemDelegate(&devicePortParamDelegate);  
54    
55          // This an outsider (from designer), but rather important.          int iRowHeight = m_ui.DeviceParamTable->fontMetrics().height() + 4;
56          //QObject::connect(DeviceParamTable, SIGNAL(valueChanged(int,int)),          m_ui.DeviceParamTable->verticalHeader()->setDefaultSectionSize(iRowHeight);
57          //      this, SLOT(changeDeviceParam(int,int)));          m_ui.DevicePortParamTable->verticalHeader()->setDefaultSectionSize(iRowHeight);
58          //QObject::connect(DevicePortParamTable, SIGNAL(valueChanged(int,int)),          m_ui.DeviceParamTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
59          //      this, SLOT(changeDevicePortParam(int,int)));          m_ui.DevicePortParamTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
60    
61            m_ui.DeviceParamTable->setModel(&m_deviceParamModel);
62            m_ui.DeviceParamTable->setItemDelegate(&m_deviceParamDelegate);
63            m_ui.DeviceParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);
64            m_ui.DeviceParamTable->verticalHeader()->hide();
65    
66            m_ui.DevicePortParamTable->setModel(&m_devicePortParamModel);
67            m_ui.DevicePortParamTable->setItemDelegate(&m_devicePortParamDelegate);
68            m_ui.DevicePortParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);
69            m_ui.DevicePortParamTable->verticalHeader()->hide();
70    
71          // Initial contents.          // Initial contents.
72          refreshDevices();          refreshDevices();
73          // Try to restore normal window positioning.          // Try to restore normal window positioning.
74          adjustSize();          adjustSize();
75    
76            QObject::connect(m_ui.DeviceListView,
77                    SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
78                    SLOT(selectDevice()));
79            QObject::connect(m_ui.DeviceListView,
80                    SIGNAL(customContextMenuRequested(const QPoint&)),
81                    SLOT(deviceListViewContextMenu(const QPoint&)));
82            QObject::connect(m_ui.RefreshDevicesPushButton,
83                    SIGNAL(clicked()),
84                    SLOT(refreshDevices()));
85            QObject::connect(m_ui.DriverNameComboBox,
86                    SIGNAL(activated(const QString&)),
87                    SLOT(selectDriver(const QString&)));
88            QObject::connect(m_ui.DevicePortComboBox,
89                    SIGNAL(activated(int)),
90                    SLOT(selectDevicePort(int)));
91            QObject::connect(m_ui.CreateDevicePushButton,
92                    SIGNAL(clicked()),
93                    SLOT(createDevice()));
94            QObject::connect(m_ui.DeleteDevicePushButton,
95                    SIGNAL(clicked()),
96                    SLOT(deleteDevice()));
97            QObject::connect(m_ui.ClosePushButton,
98                    SIGNAL(clicked()),
99                    SLOT(close()));
100            QObject::connect(&m_deviceParamModel,
101                    SIGNAL(modelReset()),
102                    SLOT(updateCellRenderers()));
103            QObject::connect(&m_deviceParamModel,
104                    SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
105                    SLOT(updateCellRenderers(const QModelIndex&, const QModelIndex&)));
106            QObject::connect(&m_devicePortParamModel,
107                    SIGNAL(modelReset()),
108                    SLOT(updatePortCellRenderers()));
109            QObject::connect(&m_devicePortParamModel,
110                    SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
111                    SLOT(updatePortCellRenderers(const QModelIndex&, const QModelIndex&)));
112  }  }
113    
114  DeviceForm::~DeviceForm() {  
115    DeviceForm::~DeviceForm (void)
116    {
117  }  }
118    
119    
# Line 68  void DeviceForm::showEvent ( QShowEvent Line 124  void DeviceForm::showEvent ( QShowEvent
124          if (pMainForm)          if (pMainForm)
125                  pMainForm->stabilizeForm();                  pMainForm->stabilizeForm();
126    
         stabilizeForm();  
   
127          QWidget::showEvent(pShowEvent);          QWidget::showEvent(pShowEvent);
128    
129            refreshDevices();
130  }  }
131    
132    
# Line 93  void DeviceForm::hideEvent ( QHideEvent Line 149  void DeviceForm::hideEvent ( QHideEvent
149    
150  // Set device type spacial exclusive mode.  // Set device type spacial exclusive mode.
151  void DeviceForm::setDeviceTypeMode (  void DeviceForm::setDeviceTypeMode (
152          qsamplerDevice::qsamplerDeviceType deviceTypeMode )          Device::DeviceType deviceTypeMode )
153  {  {
154          // If it has not changed, do nothing.          // If it has not changed, do nothing.
155          if (m_deviceTypeMode == deviceTypeMode)          if (m_deviceTypeMode == deviceTypeMode)
# Line 109  void DeviceForm::setDeviceTypeMode ( Line 165  void DeviceForm::setDeviceTypeMode (
165  // Device driver name setup formal initializer.  // Device driver name setup formal initializer.
166  void DeviceForm::setDriverName ( const QString& sDriverName )  void DeviceForm::setDriverName ( const QString& sDriverName )
167  {  {
168          if (ui.DriverNameComboBox->findText(sDriverName) == 0) {          if (m_ui.DriverNameComboBox->findText(sDriverName) < 0)
169                  ui.DriverNameComboBox->insertItem(sDriverName);                  m_ui.DriverNameComboBox->insertItem(0, sDriverName);
170          }          m_ui.DriverNameComboBox->setItemText(
171          ui.DriverNameComboBox->setCurrentText(sDriverName);                  m_ui.DriverNameComboBox->currentIndex(),
172                    sDriverName);
173  }  }
174    
175    
176  // Set current selected device by type and id.  // Set current selected device by type and id.
177  void DeviceForm::setDevice ( qsamplerDevice *pDevice )  void DeviceForm::setDevice ( Device *pDevice )
178  {  {
179          // In case no device is given...          // In case no device is given...
180          qsamplerDevice::qsamplerDeviceType deviceType = m_deviceTypeMode;          Device::DeviceType deviceType = m_deviceTypeMode;
181          if (pDevice)          if (pDevice)
182                  deviceType = pDevice->deviceType();                  deviceType = pDevice->deviceType();
183    
184          // Get the device view root item...          // Get the device view root item...
185          qsamplerDeviceItem *pRootItem = NULL;          DeviceItem *pRootItem = NULL;
186          switch (deviceType) {          switch (deviceType) {
187          case qsamplerDevice::Audio:          case Device::Audio:
188                  pRootItem = m_pAudioItems;                  pRootItem = m_pAudioItems;
189                  break;                  break;
190          case qsamplerDevice::Midi:          case Device::Midi:
191                  pRootItem = m_pMidiItems;                  pRootItem = m_pMidiItems;
192                  break;                  break;
193          case qsamplerDevice::None:          case Device::None:
194                  break;                  break;
195          }          }
196    
# Line 143  void DeviceForm::setDevice ( qsamplerDev Line 200  void DeviceForm::setDevice ( qsamplerDev
200    
201          // So there's no device huh?          // So there's no device huh?
202          if (pDevice == NULL) {          if (pDevice == NULL) {
203                  ui.DeviceListView->setCurrentItem(pRootItem);                  m_ui.DeviceListView->setCurrentItem(pRootItem);
204                  return;                  return;
205          }          }
206    
207          // For each child, test for identity...          // For each child, test for identity...
208          for (int i = 0; i < pRootItem->childCount(); i++) {          for (int i = 0; i < pRootItem->childCount(); i++) {
209                  qsamplerDeviceItem* pDeviceItem =                  DeviceItem* pDeviceItem =
210                          (qsamplerDeviceItem*) pRootItem->child(i);                          (DeviceItem*) pRootItem->child(i);
211    
212                  // If identities match, select as current device item.                  // If identities match, select as current device item.
213                  if (pDeviceItem->device().deviceID() == pDevice->deviceID()) {                  if (pDeviceItem->device().deviceID() == pDevice->deviceID()) {
# Line 169  void DeviceForm::createDevice (void) Line 226  void DeviceForm::createDevice (void)
226          if (pMainForm == NULL)          if (pMainForm == NULL)
227                  return;                  return;
228    
229          QTreeWidgetItem *pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem *pItem = m_ui.DeviceListView->currentItem();
230          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
231                  return;                  return;
232    
233          // About a brand new device instance...          // About a brand new device instance...
234          qsamplerDevice device(((qsamplerDeviceItem *) pItem)->device());          Device device(((DeviceItem *) pItem)->device());
235          if (device.createDevice()) {          if (device.createDevice()) {
236                  // Now it depends on the device type...                  // Now it depends on the device type...
237                  qsamplerDeviceItem *pRootItem = NULL;                  DeviceItem *pRootItem = NULL;
238                  switch (device.deviceType()) {                  switch (device.deviceType()) {
239                  case qsamplerDevice::Audio:                  case Device::Audio:
240                          pRootItem = m_pAudioItems;                          pRootItem = m_pAudioItems;
241                          break;                          break;
242                  case qsamplerDevice::Midi:                  case Device::Midi:
243                          pRootItem = m_pMidiItems;                          pRootItem = m_pMidiItems;
244                          break;                          break;
245                  case qsamplerDevice::None:                  case Device::None:
246                          break;                          break;
247                  }                  }
248                  // Append the new device item.                  // Append the new device item.
249                  qsamplerDeviceItem *pDeviceItem = new qsamplerDeviceItem(pRootItem,                  DeviceItem *pDeviceItem = new DeviceItem(pRootItem,
250                          device.deviceType(), device.deviceID());                          device.deviceType(), device.deviceID());
251                  // Just make it the new selection...                  // Just make it the new selection...
252                  pDeviceItem->setSelected(true);                  pDeviceItem->setSelected(true);
# Line 207  void DeviceForm::deleteDevice (void) Line 264  void DeviceForm::deleteDevice (void)
264          if (pMainForm == NULL)          if (pMainForm == NULL)
265                  return;                  return;
266    
267          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
268          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
269                  return;                  return;
270    
271          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          Device& device = ((DeviceItem *) pItem)->device();
272    
273          // Prompt user if this is for real...          // Prompt user if this is for real...
274          qsamplerOptions *pOptions = pMainForm->options();          Options *pOptions = pMainForm->options();
275          if (pOptions && pOptions->bConfirmRemove) {          if (pOptions && pOptions->bConfirmRemove) {
276                  if (QMessageBox::warning(this,                  if (QMessageBox::warning(this,
277                          QSAMPLER_TITLE ": " + tr("Warning"),                          QSAMPLER_TITLE ": " + tr("Warning"),
278                          tr("Delete device:\n\n"                          tr("About to delete device:\n\n"
279                          "%1\n\n"                          "%1\n\n"
280                          "Are you sure?")                          "Are you sure?")
281                          .arg(device.deviceName()),                          .arg(device.deviceName()),
# Line 252  void DeviceForm::refreshDevices (void) Line 309  void DeviceForm::refreshDevices (void)
309          //          //
310          m_pAudioItems = NULL;          m_pAudioItems = NULL;
311          m_pMidiItems = NULL;          m_pMidiItems = NULL;
312          ui.DeviceListView->clear();          m_ui.DeviceListView->clear();
313          if (pMainForm->client()) {          if (pMainForm->client()) {
314                  int *piDeviceIDs;                  int *piDeviceIDs;
315                  // Grab and pop Audio devices...                  // Grab and pop Audio devices...
316                  if (m_deviceTypeMode == qsamplerDevice::None ||                  if (m_deviceTypeMode == Device::None ||
317                          m_deviceTypeMode == qsamplerDevice::Audio) {                          m_deviceTypeMode == Device::Audio) {
318                          m_pAudioItems = new qsamplerDeviceItem(ui.DeviceListView,                          m_pAudioItems = new DeviceItem(m_ui.DeviceListView,
319                                  qsamplerDevice::Audio);                                  Device::Audio);
320                  }                  }
321                  if (m_pAudioItems) {                  if (m_pAudioItems) {
322                          piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(),                          piDeviceIDs = Device::getDevices(pMainForm->client(),
323                                  qsamplerDevice::Audio);                                  Device::Audio);
324                          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {                          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
325                                  new qsamplerDeviceItem(m_pAudioItems,                                  new DeviceItem(m_pAudioItems,
326                                          qsamplerDevice::Audio, piDeviceIDs[i]);                                          Device::Audio, piDeviceIDs[i]);
327                          }                          }
328                          m_pAudioItems->setExpanded(true);                          m_pAudioItems->setExpanded(true);
329                  }                  }
330                  // Grab and pop MIDI devices...                  // Grab and pop MIDI devices...
331                  if (m_deviceTypeMode == qsamplerDevice::None ||                  if (m_deviceTypeMode == Device::None ||
332                          m_deviceTypeMode == qsamplerDevice::Midi) {                          m_deviceTypeMode == Device::Midi) {
333                          m_pMidiItems = new qsamplerDeviceItem(ui.DeviceListView,                          m_pMidiItems = new DeviceItem(m_ui.DeviceListView,
334                                  qsamplerDevice::Midi);                                  Device::Midi);
335                  }                  }
336                  if (m_pMidiItems) {                  if (m_pMidiItems) {
337                          piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(),                          piDeviceIDs = Device::getDevices(pMainForm->client(),
338                                  qsamplerDevice::Midi);                                  Device::Midi);
339                          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {                          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
340                                  new qsamplerDeviceItem(m_pMidiItems,                                  new DeviceItem(m_pMidiItems,
341                                          qsamplerDevice::Midi, piDeviceIDs[i]);                                          Device::Midi, piDeviceIDs[i]);
342                          }                          }
343                          m_pMidiItems->setExpanded(true);                          m_pMidiItems->setExpanded(true);
344                  }                  }
# Line 305  void DeviceForm::selectDriver ( const QS Line 362  void DeviceForm::selectDriver ( const QS
362          //  Driver name has changed for a new device...          //  Driver name has changed for a new device...
363          //          //
364    
365          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
366          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
367                  return;                  return;
368    
369          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          Device& device = ((DeviceItem *) pItem)->device();
370    
371          // Driver change is only valid for scratch devices...          // Driver change is only valid for scratch devices...
372          if (m_bNewDevice) {          if (m_bNewDevice) {
373                  m_iDirtySetup++;                  m_iDirtySetup++;
374                  device.setDriver(sDriverName);                  device.setDriver(sDriverName);
375                  deviceParamModel.refresh(device.params(), m_bNewDevice);                  m_deviceParamModel.refresh(&device, m_bNewDevice);
376                  m_iDirtySetup--;                  m_iDirtySetup--;
377                  // Done.                  // Done.
378                  stabilizeForm();                  stabilizeForm();
# Line 324  void DeviceForm::selectDriver ( const QS Line 381  void DeviceForm::selectDriver ( const QS
381    
382    
383  // Device selection slot.  // Device selection slot.
384  void DeviceForm::selectDevice (void)  void DeviceForm::selectDevice ()
385  {  {
386          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
387          if (pMainForm == NULL)          if (pMainForm == NULL)
# Line 337  void DeviceForm::selectDevice (void) Line 394  void DeviceForm::selectDevice (void)
394          //  Device selection has changed...          //  Device selection has changed...
395          //          //
396    
397          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
398          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) {          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) {
399                  m_deviceType = qsamplerDevice::None;                  m_deviceType = Device::None;
400                  ui.DeviceNameTextLabel->setText(QString::null);                  m_ui.DeviceNameTextLabel->setText(QString::null);
401                  deviceParamModel.clear();                  m_deviceParamModel.clear();
402                  ui.DevicePortComboBox->clear();                  m_ui.DevicePortComboBox->clear();
403                  devicePortParamModel.clear();                  m_devicePortParamModel.clear();
404                  ui.DevicePortTextLabel->setEnabled(false);                  m_ui.DevicePortTextLabel->setEnabled(false);
405                  ui.DevicePortComboBox->setEnabled(false);                  m_ui.DevicePortComboBox->setEnabled(false);
406                  ui.DevicePortParamTable->setEnabled(false);                  m_ui.DevicePortParamTable->setEnabled(false);
407                  stabilizeForm();                  stabilizeForm();
408                  return;                  return;
409          }          }
410    
411          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          Device& device = ((DeviceItem *) pItem)->device();
412    
413          m_iDirtySetup++;          m_iDirtySetup++;
414          // Flag whether this is a new device.          // Flag whether this is a new device.
415          m_bNewDevice = (device.deviceID() < 0);          m_bNewDevice = (device.deviceID() < 0);
416    
417          // Fill the device/driver heading...          // Fill the device/driver heading...
418          ui.DeviceNameTextLabel->setText(device.deviceName());          m_ui.DeviceNameTextLabel->setText(device.deviceName());
419          // The driver combobox is only rebuilt if device type has changed...          // The driver combobox is only rebuilt if device type has changed...
420          if (device.deviceType() != m_deviceType) {          if (device.deviceType() != m_deviceType) {
421                  ui.DriverNameComboBox->clear();                  m_ui.DriverNameComboBox->clear();
422                  ui.DriverNameComboBox->insertStringList(                  m_ui.DriverNameComboBox->insertItems(0,
423                          qsamplerDevice::getDrivers(pMainForm->client(), device.deviceType()));                          Device::getDrivers(pMainForm->client(), device.deviceType()));
424                  m_deviceType = device.deviceType();                  m_deviceType = device.deviceType();
425          }          }
426          // Do we need a driver name?          // Do we need a driver name?
427          if (m_bNewDevice || device.driverName().isEmpty())          if (m_bNewDevice || device.driverName().isEmpty())
428                  device.setDriver(ui.DriverNameComboBox->currentText());                  device.setDriver(m_ui.DriverNameComboBox->currentText());
429          setDriverName(device.driverName());          setDriverName(device.driverName());
430          ui.DriverNameTextLabel->setEnabled(m_bNewDevice);          m_ui.DriverNameTextLabel->setEnabled(m_bNewDevice);
431          ui.DriverNameComboBox->setEnabled(m_bNewDevice);          m_ui.DriverNameComboBox->setEnabled(m_bNewDevice);
432          // Fill the device parameter table...          // Fill the device parameter table...
433          deviceParamModel.refresh(device.params(), m_bNewDevice);          m_deviceParamModel.refresh(&device, m_bNewDevice);
434          // And now the device port/channel parameter table...          // And now the device port/channel parameter table...
435          switch (device.deviceType()) {          switch (device.deviceType()) {
436          case qsamplerDevice::Audio:          case Device::Audio:
437                  ui.DevicePortTextLabel->setText(tr("Ch&annel:"));                  m_ui.DevicePortTextLabel->setText(tr("Ch&annel:"));
438                  break;                  break;
439          case qsamplerDevice::Midi:          case Device::Midi:
440                  ui.DevicePortTextLabel->setText(tr("P&ort:"));                  m_ui.DevicePortTextLabel->setText(tr("P&ort:"));
441                  break;                  break;
442          case qsamplerDevice::None:          case Device::None:
443                  break;                  break;
444          }          }
445          ui.DevicePortComboBox->clear();          m_ui.DevicePortComboBox->clear();
446          devicePortParamModel.clear();          m_devicePortParamModel.clear();
447          if (m_bNewDevice) {          if (m_bNewDevice) {
448                  ui.DevicePortTextLabel->setEnabled(false);                  m_ui.DevicePortTextLabel->setEnabled(false);
449                  ui.DevicePortComboBox->setEnabled(false);                  m_ui.DevicePortComboBox->setEnabled(false);
450                  ui.DevicePortParamTable->setEnabled(false);                  m_ui.DevicePortParamTable->setEnabled(false);
451          } else {          } else {
452                  QPixmap pixmap;                  QPixmap pixmap;
453                  switch (device.deviceType()) {                  switch (device.deviceType()) {
454                  case qsamplerDevice::Audio:                  case Device::Audio:
455                          pixmap = QPixmap(":/qsampler/pixmaps/audio2.png");                          pixmap = QPixmap(":/icons/audio2.png");
456                          break;                          break;
457                  case qsamplerDevice::Midi:                  case Device::Midi:
458                          pixmap = QPixmap(":/qsampler/pixmaps/midi2.png");                          pixmap = QPixmap(":/icons/midi2.png");
459                          break;                          break;
460                  case qsamplerDevice::None:                  case Device::None:
461                          break;                          break;
462                  }                  }
463                  qsamplerDevicePortList& ports = device.ports();                  DevicePortList& ports = device.ports();
464                  qsamplerDevicePort *pPort;                  QListIterator<DevicePort *> iter(ports);
465                  for (pPort = ports.first(); pPort; pPort = ports.next()) {                  while (iter.hasNext()) {
466                          ui.DevicePortComboBox->insertItem(pixmap, device.deviceTypeName()                          DevicePort *pPort = iter.next();
467                            m_ui.DevicePortComboBox->addItem(pixmap,
468                                    device.deviceTypeName()
469                                  + ' ' + device.driverName()                                  + ' ' + device.driverName()
470                                  + ' ' + pPort->portName());                                  + ' ' + pPort->portName());
471                  }                  }
472                  bool bEnabled = (ports.count() > 0);                  bool bEnabled = (ports.count() > 0);
473                  ui.DevicePortTextLabel->setEnabled(bEnabled);                  m_ui.DevicePortTextLabel->setEnabled(bEnabled);
474                  ui.DevicePortComboBox->setEnabled(bEnabled);                  m_ui.DevicePortComboBox->setEnabled(bEnabled);
475                  ui.DevicePortParamTable->setEnabled(bEnabled);                  m_ui.DevicePortParamTable->setEnabled(bEnabled);
476          }          }
477          // Done.          // Done.
478          m_iDirtySetup--;          m_iDirtySetup--;
479    
480          // Make the device port/channel selection effective.          // Make the device port/channel selection effective.
481          selectDevicePort(ui.DevicePortComboBox->currentItem());          selectDevicePort(m_ui.DevicePortComboBox->currentIndex());
482  }  }
483    
484    
# Line 433  void DeviceForm::selectDevicePort ( int Line 492  void DeviceForm::selectDevicePort ( int
492          //  Device port/channel selection has changed...          //  Device port/channel selection has changed...
493          //          //
494    
495          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
496          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
497                  return;                  return;
498    
499          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          Device& device = ((DeviceItem *) pItem)->device();
500          qsamplerDevicePort *pPort = device.ports().at(iPort);          DevicePort *pPort = NULL;
501            if (iPort >= 0 && iPort < device.ports().count())
502                    pPort = device.ports().at(iPort);
503          if (pPort) {          if (pPort) {
504                  m_iDirtySetup++;                  m_iDirtySetup++;
505                  devicePortParamModel.refresh(pPort->params(), false);                  m_devicePortParamModel.refresh(pPort, false);
506                  m_iDirtySetup--;                  m_iDirtySetup--;
507          }          }
508          // Done.          // Done.
# Line 461  void DeviceForm::changeDeviceParam ( int Line 522  void DeviceForm::changeDeviceParam ( int
522          //  Device parameter change...          //  Device parameter change...
523          //          //
524    
525          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();  /* we do that in the model class now ...
526            QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
527          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
528                  return;                  return;
529    
530          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          Device& device = ((DeviceItem *) pItem)->device();
531    
532          // Table 1st column has the parameter name;          // Table 1st column has the parameter name;
533          //const QString sParam = ui.DeviceParamTable->text(iRow, 0);          //const QString sParam = m_ui.DeviceParamTable->text(iRow, 0);
534          //const QString sValue = ui.DeviceParamTable->text(iRow, iCol);          //const QString sValue = m_ui.DeviceParamTable->text(iRow, iCol);
535          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;
536          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;
537          // Set the local device parameter value.          // Set the local device parameter value.
538          if (device.setParam(sParam, sValue)) {          if (device.setParam(sParam, sValue)) {
539                  selectDevice();                  selectDevice();
540          } else {          } else {
541                  stabilizeForm();                  stabilizeForm();
542          }          }
543    */
544    
545          // Main session should be dirtier...          // Main session should be dirtier...
546          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
# Line 498  void DeviceForm::changeDevicePortParam ( Line 561  void DeviceForm::changeDevicePortParam (
561          //  Device port/channel parameter change...          //  Device port/channel parameter change...
562          //          //
563    
564          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();  /* we do that in the model class now ...
565            QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
566          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
567                  return;                  return;
568    
569          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          Device& device = ((DeviceItem *) pItem)->device();
570    
571          int iPort = ui.DevicePortComboBox->currentItem();          int iPort = m_ui.DevicePortComboBox->currentIndex();
572          qsamplerDevicePort *pPort = device.ports().at(iPort);          DevicePort *pPort = NULL;
573            if (iPort >= 0 && iPort < device.ports().count())
574                    pPort = device.ports().at(iPort);
575          if (pPort == NULL)          if (pPort == NULL)
576                  return;                  return;
577    
578          // Table 1st column has the parameter name;          // Table 1st column has the parameter name;
579          //const QString sParam = ui.DevicePortParamTable->text(iRow, 0);          //const QString sParam = m_ui.DevicePortParamTable->text(iRow, 0);
580          //const QString sValue = ui.DevicePortParamTable->text(iRow, iCol);          //const QString sValue = m_ui.DevicePortParamTable->text(iRow, iCol);
581          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;
582          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;
583    
584          // Set the local device port/channel parameter value.          // Set the local device port/channel parameter value.
585          pPort->setParam(sParam, sValue);          pPort->setParam(sParam, sValue);
586    */
587    
588          // Done.          // Done.
589          stabilizeForm();          stabilizeForm();
590    
# Line 528  void DeviceForm::changeDevicePortParam ( Line 596  void DeviceForm::changeDevicePortParam (
596    
597    
598  // Device list view context menu handler.  // Device list view context menu handler.
599  void DeviceForm::contextMenu ( QTreeWidgetItem* pItem, const QPoint& pos, int )  void DeviceForm::deviceListViewContextMenu ( const QPoint& pos )
600  {  {
601          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
602          if (pMainForm == NULL)          if (pMainForm == NULL)
603                  return;                  return;
604    
605          int iItemID;          QTreeWidgetItem* pItem = m_ui.DeviceListView->itemAt(pos);
606            if (pItem == NULL)
607                    return;
608    
609          // Build the device context menu...          // Build the device context menu...
610          QMenu* pContextMenu = new QMenu(this);          QMenu menu(this);
611            QAction *pAction;
612    
613          bool bClient = (pMainForm->client() != NULL);          bool bClient = (pMainForm->client() != NULL);
614          bool bEnabled = (pItem != NULL);          bool bEnabled = (pItem != NULL);
615          iItemID = pContextMenu->insertItem(          pAction = menu.addAction(
616                  QIconSet(QPixmap(":/qsampler/pixmaps/deviceCreate.png")),                  QIcon(":/qsampler/pixmaps/deviceCreate.png"),
617                  tr("&Create device"), this, SLOT(createDevice()));                  tr("&Create device"), this, SLOT(createDevice()));
618          pContextMenu->setItemEnabled(iItemID, bEnabled || (bClient && m_bNewDevice));          pAction->setEnabled(bEnabled || (bClient && m_bNewDevice));
619          iItemID = pContextMenu->insertItem(          pAction = menu.addAction(
620                  QIconSet(QPixmap(":/qsampler/pixmaps/deviceDelete.png")),                  QIcon(":/qsampler/pixmaps/deviceDelete.png"),
621                  tr("&Delete device"), this, SLOT(deleteDevice()));                  tr("&Delete device"), this, SLOT(deleteDevice()));
622          pContextMenu->setItemEnabled(iItemID, bEnabled && !m_bNewDevice);          pAction->setEnabled(bEnabled && !m_bNewDevice);
623          pContextMenu->insertSeparator();          menu.addSeparator();
624          iItemID = pContextMenu->insertItem(          pAction = menu.addAction(
625                  QIconSet(QPixmap(":/qsampler/pixmaps/formRefresh.png")),                  QIcon(":/qsampler/pixmaps/formRefresh.png"),
626                  tr("&Refresh"), this, SLOT(refreshDevices()));                  tr("&Refresh"), this, SLOT(refreshDevices()));
627          pContextMenu->setItemEnabled(iItemID, bClient);          pAction->setEnabled(bClient);
   
         pContextMenu->exec(pos);  
628    
629          delete pContextMenu;          menu.exec(pos);
630  }  }
631    
632    
# Line 565  void DeviceForm::contextMenu ( QTreeWidg Line 634  void DeviceForm::contextMenu ( QTreeWidg
634  void DeviceForm::stabilizeForm (void)  void DeviceForm::stabilizeForm (void)
635  {  {
636          MainForm* pMainForm = MainForm::getInstance();          MainForm* pMainForm = MainForm::getInstance();
637          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
638          bool bClient = (pMainForm && pMainForm->client() != NULL);          bool bClient = (pMainForm && pMainForm->client() != NULL);
639          bool bEnabled = (pItem != NULL);          bool bEnabled = (pItem != NULL);
640          ui.DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice);          m_ui.DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice);
641          ui.DriverNameTextLabel->setEnabled(bEnabled &&  m_bNewDevice);          m_ui.DriverNameTextLabel->setEnabled(bEnabled &&  m_bNewDevice);
642          ui.DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice);          m_ui.DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice);
643          ui.DeviceParamTable->setEnabled(bEnabled);          m_ui.DeviceParamTable->setEnabled(bEnabled);
644          ui.RefreshDevicesPushButton->setEnabled(bClient);          m_ui.RefreshDevicesPushButton->setEnabled(bClient);
645          ui.CreateDevicePushButton->setEnabled(bEnabled || (bClient && m_bNewDevice));          m_ui.CreateDevicePushButton->setEnabled(bEnabled || (bClient && m_bNewDevice));
646          ui.DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice);          m_ui.DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice);
647    }
648    
649    
650    void DeviceForm::updateCellRenderers (void)
651    {
652            const int rows = m_deviceParamModel.rowCount();
653            const int cols = m_deviceParamModel.columnCount();
654            updateCellRenderers(
655                    m_deviceParamModel.index(0, 0),
656                    m_deviceParamModel.index(rows - 1, cols - 1));
657    }
658    
659    
660    void DeviceForm::updateCellRenderers (
661            const QModelIndex& topLeft, const QModelIndex& bottomRight )
662    {
663            for (int r = topLeft.row(); r <= bottomRight.row(); r++) {
664                    for (int c = topLeft.column(); c <= bottomRight.column(); c++) {
665                            const QModelIndex index = m_deviceParamModel.index(r, c);
666                            m_ui.DeviceParamTable->openPersistentEditor(index);
667                    }
668            }
669    }
670    
671    
672    void DeviceForm::updatePortCellRenderers (void)
673    {
674            const int rows = m_devicePortParamModel.rowCount();
675            const int cols = m_devicePortParamModel.columnCount();
676            updatePortCellRenderers(
677                    m_devicePortParamModel.index(0, 0),
678                    m_devicePortParamModel.index(rows - 1, cols - 1));
679    }
680    
681    
682    void DeviceForm::updatePortCellRenderers (
683            const QModelIndex& topLeft, const QModelIndex& bottomRight )
684    {
685            for (int r = topLeft.row(); r <= bottomRight.row(); r++) {
686                    for (int c = topLeft.column(); c <= bottomRight.column(); c++) {
687                            const QModelIndex index = m_devicePortParamModel.index(r, c);
688                            m_ui.DevicePortParamTable->openPersistentEditor(index);
689                    }
690            }
691  }  }
692    
693  } // namespace QSampler  } // namespace QSampler

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

  ViewVC Help
Powered by ViewVC