/[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 1499 by capela, Tue Nov 20 16:48:04 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    
# Line 39  DeviceForm::DeviceForm(QWidget* parent, Line 44  DeviceForm::DeviceForm(QWidget* parent,
44          // No exclusive mode as default.          // No exclusive mode as default.
45          m_deviceTypeMode = qsamplerDevice::None;          m_deviceTypeMode = qsamplerDevice::None;
46    
47            ui.DeviceListView->header()->hide();
48    
49          ui.DeviceParamTable->setModel(&deviceParamModel);          ui.DeviceParamTable->setModel(&deviceParamModel);
50          ui.DeviceParamTable->setItemDelegate(&deviceParamDelegate);          ui.DeviceParamTable->setItemDelegate(&deviceParamDelegate);
51            ui.DeviceParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);
52    
53          ui.DevicePortParamTable->setModel(&devicePortParamModel);          ui.DevicePortParamTable->setModel(&devicePortParamModel);
54          ui.DevicePortParamTable->setItemDelegate(&devicePortParamDelegate);          ui.DevicePortParamTable->setItemDelegate(&devicePortParamDelegate);
55            ui.DevicePortParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);
         // This an outsider (from designer), but rather important.  
         //QObject::connect(DeviceParamTable, SIGNAL(valueChanged(int,int)),  
         //      this, SLOT(changeDeviceParam(int,int)));  
         //QObject::connect(DevicePortParamTable, SIGNAL(valueChanged(int,int)),  
         //      this, SLOT(changeDevicePortParam(int,int)));  
56    
57          // Initial contents.          // Initial contents.
58          refreshDevices();          refreshDevices();
# Line 57  DeviceForm::DeviceForm(QWidget* parent, Line 60  DeviceForm::DeviceForm(QWidget* parent,
60          adjustSize();          adjustSize();
61    
62          QObject::connect(ui.DeviceListView,          QObject::connect(ui.DeviceListView,
63                  SIGNAL(itemSelectionChanged()),                  SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
64                  SLOT(selectDevice()));                  SLOT(selectDevice()));
65          QObject::connect(ui.DeviceListView,          QObject::connect(ui.DeviceListView,
66                  SIGNAL(customContextMenuRequested(const QPoint&)),                  SIGNAL(customContextMenuRequested(const QPoint&)),
# Line 80  DeviceForm::DeviceForm(QWidget* parent, Line 83  DeviceForm::DeviceForm(QWidget* parent,
83          QObject::connect(ui.ClosePushButton,          QObject::connect(ui.ClosePushButton,
84                  SIGNAL(clicked()),                  SIGNAL(clicked()),
85                  SLOT(close()));                  SLOT(close()));
86            QObject::connect(&deviceParamModel,
87                    SIGNAL(modelReset()),
88                    SLOT(updateCellRenderers()));
89            QObject::connect(&deviceParamModel,
90                    SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
91                    SLOT(updateCellRenderers(const QModelIndex&, const QModelIndex&)));
92            QObject::connect(&devicePortParamModel,
93                    SIGNAL(modelReset()),
94                    SLOT(updatePortCellRenderers()));
95            QObject::connect(&devicePortParamModel,
96                    SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
97                    SLOT(updatePortCellRenderers(const QModelIndex&, const QModelIndex&)));
98  }  }
99    
100  DeviceForm::~DeviceForm() {  DeviceForm::~DeviceForm() {
# Line 134  void DeviceForm::setDeviceTypeMode ( Line 149  void DeviceForm::setDeviceTypeMode (
149  // Device driver name setup formal initializer.  // Device driver name setup formal initializer.
150  void DeviceForm::setDriverName ( const QString& sDriverName )  void DeviceForm::setDriverName ( const QString& sDriverName )
151  {  {
152          if (ui.DriverNameComboBox->findText(sDriverName) == 0) {          if (ui.DriverNameComboBox->findText(sDriverName) < 0)
153                  ui.DriverNameComboBox->insertItem(sDriverName);                  ui.DriverNameComboBox->insertItem(0, sDriverName);
154          }          ui.DriverNameComboBox->setItemText(
155          ui.DriverNameComboBox->setCurrentText(sDriverName);                  ui.DriverNameComboBox->currentIndex(),
156                    sDriverName);
157  }  }
158    
159    
# Line 340  void DeviceForm::selectDriver ( const QS Line 356  void DeviceForm::selectDriver ( const QS
356          if (m_bNewDevice) {          if (m_bNewDevice) {
357                  m_iDirtySetup++;                  m_iDirtySetup++;
358                  device.setDriver(sDriverName);                  device.setDriver(sDriverName);
359                  deviceParamModel.refresh(device.params(), m_bNewDevice);                  deviceParamModel.refresh(&device, m_bNewDevice);
360                  m_iDirtySetup--;                  m_iDirtySetup--;
361                  // Done.                  // Done.
362                  stabilizeForm();                  stabilizeForm();
# Line 349  void DeviceForm::selectDriver ( const QS Line 365  void DeviceForm::selectDriver ( const QS
365    
366    
367  // Device selection slot.  // Device selection slot.
368  void DeviceForm::selectDevice (void)  void DeviceForm::selectDevice ()
369  {  {
370          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
371          if (pMainForm == NULL)          if (pMainForm == NULL)
# Line 387  void DeviceForm::selectDevice (void) Line 403  void DeviceForm::selectDevice (void)
403          // The driver combobox is only rebuilt if device type has changed...          // The driver combobox is only rebuilt if device type has changed...
404          if (device.deviceType() != m_deviceType) {          if (device.deviceType() != m_deviceType) {
405                  ui.DriverNameComboBox->clear();                  ui.DriverNameComboBox->clear();
406                  ui.DriverNameComboBox->insertStringList(                  ui.DriverNameComboBox->insertItems(0,
407                          qsamplerDevice::getDrivers(pMainForm->client(), device.deviceType()));                          qsamplerDevice::getDrivers(pMainForm->client(), device.deviceType()));
408                  m_deviceType = device.deviceType();                  m_deviceType = device.deviceType();
409          }          }
# Line 398  void DeviceForm::selectDevice (void) Line 414  void DeviceForm::selectDevice (void)
414          ui.DriverNameTextLabel->setEnabled(m_bNewDevice);          ui.DriverNameTextLabel->setEnabled(m_bNewDevice);
415          ui.DriverNameComboBox->setEnabled(m_bNewDevice);          ui.DriverNameComboBox->setEnabled(m_bNewDevice);
416          // Fill the device parameter table...          // Fill the device parameter table...
417          deviceParamModel.refresh(device.params(), m_bNewDevice);          deviceParamModel.refresh(&device, m_bNewDevice);
418          // And now the device port/channel parameter table...          // And now the device port/channel parameter table...
419          switch (device.deviceType()) {          switch (device.deviceType()) {
420          case qsamplerDevice::Audio:          case qsamplerDevice::Audio:
# Line 420  void DeviceForm::selectDevice (void) Line 436  void DeviceForm::selectDevice (void)
436                  QPixmap pixmap;                  QPixmap pixmap;
437                  switch (device.deviceType()) {                  switch (device.deviceType()) {
438                  case qsamplerDevice::Audio:                  case qsamplerDevice::Audio:
439                          pixmap = QPixmap(":/qsampler/pixmaps/audio2.png");                          pixmap = QPixmap(":/icons/audio2.png");
440                          break;                          break;
441                  case qsamplerDevice::Midi:                  case qsamplerDevice::Midi:
442                          pixmap = QPixmap(":/qsampler/pixmaps/midi2.png");                          pixmap = QPixmap(":/icons/midi2.png");
443                          break;                          break;
444                  case qsamplerDevice::None:                  case qsamplerDevice::None:
445                          break;                          break;
446                  }                  }
447                  qsamplerDevicePortList& ports = device.ports();                  qsamplerDevicePortList& ports = device.ports();
448                  qsamplerDevicePort *pPort;                  QListIterator<qsamplerDevicePort *> iter(ports);
449                  for (pPort = ports.first(); pPort; pPort = ports.next()) {                  while (iter.hasNext()) {
450                          ui.DevicePortComboBox->insertItem(pixmap, device.deviceTypeName()                          qsamplerDevicePort *pPort = iter.next();
451                            ui.DevicePortComboBox->addItem(pixmap,
452                                    device.deviceTypeName()
453                                  + ' ' + device.driverName()                                  + ' ' + device.driverName()
454                                  + ' ' + pPort->portName());                                  + ' ' + pPort->portName());
455                  }                  }
# Line 444  void DeviceForm::selectDevice (void) Line 462  void DeviceForm::selectDevice (void)
462          m_iDirtySetup--;          m_iDirtySetup--;
463    
464          // Make the device port/channel selection effective.          // Make the device port/channel selection effective.
465          selectDevicePort(ui.DevicePortComboBox->currentItem());          selectDevicePort(ui.DevicePortComboBox->currentIndex());
466  }  }
467    
468    
# Line 466  void DeviceForm::selectDevicePort ( int Line 484  void DeviceForm::selectDevicePort ( int
484          qsamplerDevicePort *pPort = device.ports().at(iPort);          qsamplerDevicePort *pPort = device.ports().at(iPort);
485          if (pPort) {          if (pPort) {
486                  m_iDirtySetup++;                  m_iDirtySetup++;
487                  devicePortParamModel.refresh(pPort->params(), false);                  devicePortParamModel.refresh(pPort, false);
488                  m_iDirtySetup--;                  m_iDirtySetup--;
489          }          }
490          // Done.          // Done.
# Line 486  void DeviceForm::changeDeviceParam ( int Line 504  void DeviceForm::changeDeviceParam ( int
504          //  Device parameter change...          //  Device parameter change...
505          //          //
506    
507    /* we do that in the model class now ...
508          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();
509          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
510                  return;                  return;
# Line 503  void DeviceForm::changeDeviceParam ( int Line 522  void DeviceForm::changeDeviceParam ( int
522          } else {          } else {
523                  stabilizeForm();                  stabilizeForm();
524          }          }
525    */
526    
527          // Main session should be dirtier...          // Main session should be dirtier...
528          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
# Line 523  void DeviceForm::changeDevicePortParam ( Line 543  void DeviceForm::changeDevicePortParam (
543          //  Device port/channel parameter change...          //  Device port/channel parameter change...
544          //          //
545    
546    /* we do that in the model class now ...
547          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();
548          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
549                  return;                  return;
550    
551          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
552    
553          int iPort = ui.DevicePortComboBox->currentItem();          int iPort = ui.DevicePortComboBox->currentIndex();
554          qsamplerDevicePort *pPort = device.ports().at(iPort);          qsamplerDevicePort *pPort = device.ports().at(iPort);
555          if (pPort == NULL)          if (pPort == NULL)
556                  return;                  return;
# Line 542  void DeviceForm::changeDevicePortParam ( Line 563  void DeviceForm::changeDevicePortParam (
563    
564          // Set the local device port/channel parameter value.          // Set the local device port/channel parameter value.
565          pPort->setParam(sParam, sValue);          pPort->setParam(sParam, sValue);
566    */
567    
568          // Done.          // Done.
569          stabilizeForm();          stabilizeForm();
570    
# Line 563  void DeviceForm::deviceListViewContextMe Line 586  void DeviceForm::deviceListViewContextMe
586          if (pItem == NULL)          if (pItem == NULL)
587                  return;                  return;
588    
         int iItemID;  
   
589          // Build the device context menu...          // Build the device context menu...
590          QMenu* pContextMenu = new QMenu(this);          QMenu menu(this);
591            QAction *pAction;
592    
593          bool bClient = (pMainForm->client() != NULL);          bool bClient = (pMainForm->client() != NULL);
594          bool bEnabled = (pItem != NULL);          bool bEnabled = (pItem != NULL);
595          iItemID = pContextMenu->insertItem(          pAction = menu.addAction(
596                  QIconSet(QPixmap(":/qsampler/pixmaps/deviceCreate.png")),                  QIcon(":/qsampler/pixmaps/deviceCreate.png"),
597                  tr("&Create device"), this, SLOT(createDevice()));                  tr("&Create device"), this, SLOT(createDevice()));
598          pContextMenu->setItemEnabled(iItemID, bEnabled || (bClient && m_bNewDevice));          pAction->setEnabled(bEnabled || (bClient && m_bNewDevice));
599          iItemID = pContextMenu->insertItem(          pAction = menu.addAction(
600                  QIconSet(QPixmap(":/qsampler/pixmaps/deviceDelete.png")),                  QIcon(":/qsampler/pixmaps/deviceDelete.png"),
601                  tr("&Delete device"), this, SLOT(deleteDevice()));                  tr("&Delete device"), this, SLOT(deleteDevice()));
602          pContextMenu->setItemEnabled(iItemID, bEnabled && !m_bNewDevice);          pAction->setEnabled(bEnabled && !m_bNewDevice);
603          pContextMenu->insertSeparator();          menu.addSeparator();
604          iItemID = pContextMenu->insertItem(          pAction = menu.addAction(
605                  QIconSet(QPixmap(":/qsampler/pixmaps/formRefresh.png")),                  QIcon(":/qsampler/pixmaps/formRefresh.png"),
606                  tr("&Refresh"), this, SLOT(refreshDevices()));                  tr("&Refresh"), this, SLOT(refreshDevices()));
607          pContextMenu->setItemEnabled(iItemID, bClient);          pAction->setEnabled(bClient);
   
         pContextMenu->exec(pos);  
608    
609          delete pContextMenu;          menu.exec(pos);
610  }  }
611    
612    
# Line 606  void DeviceForm::stabilizeForm (void) Line 626  void DeviceForm::stabilizeForm (void)
626          ui.DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice);          ui.DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice);
627  }  }
628    
629    void DeviceForm::updateCellRenderers() {
630        const int rows = deviceParamModel.rowCount();
631        const int cols = deviceParamModel.columnCount();
632        updateCellRenderers(deviceParamModel.index(0,0),deviceParamModel.index(rows-1,cols-1));
633    }
634    
635    void DeviceForm::updateCellRenderers(const QModelIndex& topLeft, const QModelIndex& bottomRight) {
636        for (int r = topLeft.row(); r <= bottomRight.row(); r++) {
637            for (int c = topLeft.column(); c <= bottomRight.column(); c++) {
638                const QModelIndex index = deviceParamModel.index(r,c);
639                ui.DeviceParamTable->openPersistentEditor(index);
640            }
641        }
642    }
643    
644    void DeviceForm::updatePortCellRenderers() {
645        const int rows = devicePortParamModel.rowCount();
646        const int cols = devicePortParamModel.columnCount();
647        updatePortCellRenderers(devicePortParamModel.index(0,0),devicePortParamModel.index(rows-1,cols-1));
648    }
649    
650    void DeviceForm::updatePortCellRenderers(const QModelIndex& topLeft, const QModelIndex& bottomRight) {
651        for (int r = topLeft.row(); r <= bottomRight.row(); r++) {
652            for (int c = topLeft.column(); c <= bottomRight.column(); c++) {
653                const QModelIndex index = devicePortParamModel.index(r,c);
654                ui.DevicePortParamTable->openPersistentEditor(index);
655            }
656        }
657    }
658    
659  } // namespace QSampler  } // namespace QSampler
660    
661    

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

  ViewVC Help
Powered by ViewVC