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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2388 - (hide annotations) (download)
Sat Dec 29 19:12:58 2012 UTC (11 years, 3 months ago) by capela
File size: 19850 byte(s)
- Preparations for Qt5 migration. (TESTING)
1 capela 1464 // qsamplerDeviceForm.cpp
2     //
3     /****************************************************************************
4 capela 2387 Copyright (C) 2004-2012, rncbc aka Rui Nuno Capela. All rights reserved.
5 schoenebeck 1667 Copyright (C) 2007, 2008 Christian Schoenebeck
6 capela 1464
7     This program is free software; you can redistribute it and/or
8     modify it under the terms of the GNU General Public License
9     as published by the Free Software Foundation; either version 2
10     of the License, or (at your option) any later version.
11    
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     GNU General Public License for more details.
16    
17     You should have received a copy of the GNU General Public License along
18     with this program; if not, write to the Free Software Foundation, Inc.,
19     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20    
21     *****************************************************************************/
22    
23 schoenebeck 1461 #include "qsamplerDeviceForm.h"
24    
25     #include "qsamplerAbout.h"
26 capela 1473 #include "qsamplerMainForm.h"
27 schoenebeck 1461
28 capela 1499 #include <QHeaderView>
29     #include <QMessageBox>
30    
31    
32 schoenebeck 1461 namespace QSampler {
33    
34 capela 1558 //-------------------------------------------------------------------------
35     // QSampler::DeviceForm -- Device form implementation.
36     //
37    
38 capela 1509 DeviceForm::DeviceForm ( QWidget *pParent, Qt::WindowFlags wflags )
39     : QDialog(pParent, wflags)
40     {
41 capela 1510 m_ui.setupUi(this);
42 schoenebeck 1461
43     // Initialize locals.
44     m_iDirtySetup = 0;
45     m_iDirtyCount = 0;
46     m_bNewDevice = false;
47 capela 1558 m_deviceType = Device::None;
48 schoenebeck 1461 m_pAudioItems = NULL;
49     m_pMidiItems = NULL;
50     // No exclusive mode as default.
51 capela 1558 m_deviceTypeMode = Device::None;
52 schoenebeck 1461
53 capela 1509 m_ui.DeviceListView->header()->hide();
54 schoenebeck 1477
55 capela 1519 int iRowHeight = m_ui.DeviceParamTable->fontMetrics().height() + 4;
56     m_ui.DeviceParamTable->verticalHeader()->setDefaultSectionSize(iRowHeight);
57     m_ui.DevicePortParamTable->verticalHeader()->setDefaultSectionSize(iRowHeight);
58     m_ui.DeviceParamTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
59     m_ui.DevicePortParamTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
60    
61 capela 1509 m_ui.DeviceParamTable->setModel(&m_deviceParamModel);
62     m_ui.DeviceParamTable->setItemDelegate(&m_deviceParamDelegate);
63 capela 2388 #if QT_VERSION >= 0x050000
64     m_ui.DeviceParamTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);
65     #else
66 capela 1509 m_ui.DeviceParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);
67 capela 2387 #endif
68 capela 1509 m_ui.DeviceParamTable->verticalHeader()->hide();
69 schoenebeck 1461
70 capela 1509 m_ui.DevicePortParamTable->setModel(&m_devicePortParamModel);
71     m_ui.DevicePortParamTable->setItemDelegate(&m_devicePortParamDelegate);
72 capela 2388 #if QT_VERSION >= 0x050000
73     m_ui.DevicePortParamTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);
74     #else
75 capela 1509 m_ui.DevicePortParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);
76 capela 2387 #endif
77 capela 1509 m_ui.DevicePortParamTable->verticalHeader()->hide();
78 schoenebeck 1461
79     // Initial contents.
80     refreshDevices();
81     // Try to restore normal window positioning.
82     adjustSize();
83 capela 1466
84 capela 1509 QObject::connect(m_ui.DeviceListView,
85 schoenebeck 1486 SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
86 capela 1466 SLOT(selectDevice()));
87 capela 1509 QObject::connect(m_ui.DeviceListView,
88 schoenebeck 1470 SIGNAL(customContextMenuRequested(const QPoint&)),
89     SLOT(deviceListViewContextMenu(const QPoint&)));
90 capela 1509 QObject::connect(m_ui.RefreshDevicesPushButton,
91 capela 1466 SIGNAL(clicked()),
92     SLOT(refreshDevices()));
93 capela 1509 QObject::connect(m_ui.DriverNameComboBox,
94 schoenebeck 1470 SIGNAL(activated(const QString&)),
95     SLOT(selectDriver(const QString&)));
96 capela 1509 QObject::connect(m_ui.DevicePortComboBox,
97 capela 1466 SIGNAL(activated(int)),
98     SLOT(selectDevicePort(int)));
99 capela 1509 QObject::connect(m_ui.CreateDevicePushButton,
100 capela 1466 SIGNAL(clicked()),
101     SLOT(createDevice()));
102 capela 1509 QObject::connect(m_ui.DeleteDevicePushButton,
103 capela 1466 SIGNAL(clicked()),
104     SLOT(deleteDevice()));
105 capela 1509 QObject::connect(m_ui.ClosePushButton,
106 capela 1466 SIGNAL(clicked()),
107     SLOT(close()));
108 capela 1509 QObject::connect(&m_deviceParamModel,
109 schoenebeck 1486 SIGNAL(modelReset()),
110     SLOT(updateCellRenderers()));
111 capela 1509 QObject::connect(&m_deviceParamModel,
112 schoenebeck 1486 SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
113     SLOT(updateCellRenderers(const QModelIndex&, const QModelIndex&)));
114 capela 1509 QObject::connect(&m_devicePortParamModel,
115 schoenebeck 1486 SIGNAL(modelReset()),
116     SLOT(updatePortCellRenderers()));
117 capela 1509 QObject::connect(&m_devicePortParamModel,
118 schoenebeck 1486 SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
119     SLOT(updatePortCellRenderers(const QModelIndex&, const QModelIndex&)));
120 schoenebeck 1461 }
121    
122 capela 1520
123     DeviceForm::~DeviceForm (void)
124     {
125 schoenebeck 1461 }
126    
127    
128     // Notify our parent that we're emerging.
129     void DeviceForm::showEvent ( QShowEvent *pShowEvent )
130     {
131     MainForm* pMainForm = MainForm::getInstance();
132     if (pMainForm)
133     pMainForm->stabilizeForm();
134    
135 capela 1520 QWidget::showEvent(pShowEvent);
136 schoenebeck 1461
137 capela 1520 refreshDevices();
138 schoenebeck 1461 }
139    
140    
141     // Notify our parent that we're closing.
142     void DeviceForm::hideEvent ( QHideEvent *pHideEvent )
143     {
144     QWidget::hideEvent(pHideEvent);
145    
146     MainForm *pMainForm = MainForm::getInstance();
147     if (pMainForm)
148     pMainForm->stabilizeForm();
149    
150     // Signal special whether we changed the device set.
151     if (m_iDirtyCount > 0) {
152     m_iDirtyCount = 0;
153     emit devicesChanged();
154     }
155     }
156    
157    
158     // Set device type spacial exclusive mode.
159     void DeviceForm::setDeviceTypeMode (
160 capela 1558 Device::DeviceType deviceTypeMode )
161 schoenebeck 1461 {
162     // If it has not changed, do nothing.
163     if (m_deviceTypeMode == deviceTypeMode)
164     return;
165    
166     m_deviceTypeMode = deviceTypeMode;
167    
168     // OK. Do a whole refresh around.
169     refreshDevices();
170     }
171    
172    
173     // Device driver name setup formal initializer.
174     void DeviceForm::setDriverName ( const QString& sDriverName )
175     {
176 capela 1509 if (m_ui.DriverNameComboBox->findText(sDriverName) < 0)
177     m_ui.DriverNameComboBox->insertItem(0, sDriverName);
178     m_ui.DriverNameComboBox->setItemText(
179     m_ui.DriverNameComboBox->currentIndex(),
180 capela 1499 sDriverName);
181 schoenebeck 1461 }
182    
183    
184     // Set current selected device by type and id.
185 capela 1558 void DeviceForm::setDevice ( Device *pDevice )
186 schoenebeck 1461 {
187     // In case no device is given...
188 capela 1558 Device::DeviceType deviceType = m_deviceTypeMode;
189 schoenebeck 1461 if (pDevice)
190     deviceType = pDevice->deviceType();
191    
192     // Get the device view root item...
193 capela 1558 DeviceItem *pRootItem = NULL;
194 schoenebeck 1461 switch (deviceType) {
195 capela 1558 case Device::Audio:
196 schoenebeck 1461 pRootItem = m_pAudioItems;
197     break;
198 capela 1558 case Device::Midi:
199 schoenebeck 1461 pRootItem = m_pMidiItems;
200     break;
201 capela 1558 case Device::None:
202 schoenebeck 1461 break;
203     }
204    
205     // Is the root present?
206     if (pRootItem == NULL)
207     return;
208    
209     // So there's no device huh?
210     if (pDevice == NULL) {
211 capela 1509 m_ui.DeviceListView->setCurrentItem(pRootItem);
212 schoenebeck 1461 return;
213     }
214    
215     // For each child, test for identity...
216     for (int i = 0; i < pRootItem->childCount(); i++) {
217 capela 1558 DeviceItem* pDeviceItem =
218     (DeviceItem*) pRootItem->child(i);
219 schoenebeck 1461
220     // If identities match, select as current device item.
221     if (pDeviceItem->device().deviceID() == pDevice->deviceID()) {
222     pDeviceItem->setSelected(true);
223     break;
224     }
225     }
226     }
227    
228    
229    
230     // Create a new device from current table view.
231     void DeviceForm::createDevice (void)
232     {
233     MainForm *pMainForm = MainForm::getInstance();
234     if (pMainForm == NULL)
235     return;
236    
237 capela 1509 QTreeWidgetItem *pItem = m_ui.DeviceListView->currentItem();
238 schoenebeck 1461 if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
239     return;
240    
241     // About a brand new device instance...
242 capela 1558 Device device(((DeviceItem *) pItem)->device());
243 schoenebeck 1461 if (device.createDevice()) {
244     // Now it depends on the device type...
245 capela 1558 DeviceItem *pRootItem = NULL;
246 schoenebeck 1461 switch (device.deviceType()) {
247 capela 1558 case Device::Audio:
248 schoenebeck 1461 pRootItem = m_pAudioItems;
249     break;
250 capela 1558 case Device::Midi:
251 schoenebeck 1461 pRootItem = m_pMidiItems;
252     break;
253 capela 1558 case Device::None:
254 schoenebeck 1461 break;
255     }
256     // Append the new device item.
257 capela 1558 DeviceItem *pDeviceItem = new DeviceItem(pRootItem,
258 schoenebeck 1461 device.deviceType(), device.deviceID());
259     // Just make it the new selection...
260     pDeviceItem->setSelected(true);
261     // Main session should be marked dirty.
262     pMainForm->sessionDirty();
263     m_iDirtyCount++;
264     }
265     }
266    
267    
268     // Delete current device in table view.
269     void DeviceForm::deleteDevice (void)
270     {
271     MainForm *pMainForm = MainForm::getInstance();
272     if (pMainForm == NULL)
273     return;
274    
275 capela 1509 QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
276 schoenebeck 1461 if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
277     return;
278    
279 capela 1558 Device& device = ((DeviceItem *) pItem)->device();
280 schoenebeck 1461
281     // Prompt user if this is for real...
282 capela 1558 Options *pOptions = pMainForm->options();
283 schoenebeck 1461 if (pOptions && pOptions->bConfirmRemove) {
284     if (QMessageBox::warning(this,
285     QSAMPLER_TITLE ": " + tr("Warning"),
286 capela 1528 tr("About to delete device:\n\n"
287 schoenebeck 1461 "%1\n\n"
288     "Are you sure?")
289     .arg(device.deviceName()),
290 capela 1840 QMessageBox::Ok | QMessageBox::Cancel)
291     == QMessageBox::Cancel)
292 schoenebeck 1461 return;
293     }
294    
295     // Go and destroy...
296     if (device.deleteDevice()) {
297     // Remove it from the device view...
298     delete pItem;
299     // Main session should be marked dirty.
300     pMainForm->sessionDirty();
301     m_iDirtyCount++;
302     }
303     }
304    
305    
306     // Refresh all device list and views.
307     void DeviceForm::refreshDevices (void)
308     {
309     MainForm *pMainForm = MainForm::getInstance();
310     if (pMainForm == NULL)
311     return;
312    
313     // Avoid nested changes.
314     m_iDirtySetup++;
315    
316     //
317     // (Re)Load complete device configuration data ...
318     //
319     m_pAudioItems = NULL;
320     m_pMidiItems = NULL;
321 capela 1509 m_ui.DeviceListView->clear();
322 schoenebeck 1461 if (pMainForm->client()) {
323     int *piDeviceIDs;
324     // Grab and pop Audio devices...
325 capela 1558 if (m_deviceTypeMode == Device::None ||
326     m_deviceTypeMode == Device::Audio) {
327     m_pAudioItems = new DeviceItem(m_ui.DeviceListView,
328     Device::Audio);
329 schoenebeck 1461 }
330     if (m_pAudioItems) {
331 capela 1558 piDeviceIDs = Device::getDevices(pMainForm->client(),
332     Device::Audio);
333 schoenebeck 1461 for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
334 capela 1558 new DeviceItem(m_pAudioItems,
335     Device::Audio, piDeviceIDs[i]);
336 schoenebeck 1461 }
337     m_pAudioItems->setExpanded(true);
338     }
339     // Grab and pop MIDI devices...
340 capela 1558 if (m_deviceTypeMode == Device::None ||
341     m_deviceTypeMode == Device::Midi) {
342     m_pMidiItems = new DeviceItem(m_ui.DeviceListView,
343     Device::Midi);
344 schoenebeck 1461 }
345     if (m_pMidiItems) {
346 capela 1558 piDeviceIDs = Device::getDevices(pMainForm->client(),
347     Device::Midi);
348 schoenebeck 1461 for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
349 capela 1558 new DeviceItem(m_pMidiItems,
350     Device::Midi, piDeviceIDs[i]);
351 schoenebeck 1461 }
352     m_pMidiItems->setExpanded(true);
353     }
354     }
355    
356     // Done.
357     m_iDirtySetup--;
358    
359     // Show something.
360     selectDevice();
361     }
362    
363    
364     // Driver selection slot.
365     void DeviceForm::selectDriver ( const QString& sDriverName )
366     {
367     if (m_iDirtySetup > 0)
368     return;
369    
370     //
371     // Driver name has changed for a new device...
372     //
373    
374 capela 1509 QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
375 schoenebeck 1461 if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
376     return;
377    
378 capela 1558 Device& device = ((DeviceItem *) pItem)->device();
379 schoenebeck 1461
380     // Driver change is only valid for scratch devices...
381     if (m_bNewDevice) {
382     m_iDirtySetup++;
383     device.setDriver(sDriverName);
384 capela 1509 m_deviceParamModel.refresh(&device, m_bNewDevice);
385 schoenebeck 1461 m_iDirtySetup--;
386     // Done.
387     stabilizeForm();
388     }
389     }
390    
391    
392     // Device selection slot.
393 schoenebeck 1477 void DeviceForm::selectDevice ()
394 schoenebeck 1461 {
395     MainForm *pMainForm = MainForm::getInstance();
396     if (pMainForm == NULL)
397     return;
398    
399     if (m_iDirtySetup > 0)
400     return;
401    
402     //
403     // Device selection has changed...
404     //
405    
406 capela 1509 QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
407 schoenebeck 1461 if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) {
408 capela 1558 m_deviceType = Device::None;
409 capela 1509 m_ui.DeviceNameTextLabel->setText(QString::null);
410     m_deviceParamModel.clear();
411     m_ui.DevicePortComboBox->clear();
412     m_devicePortParamModel.clear();
413     m_ui.DevicePortTextLabel->setEnabled(false);
414     m_ui.DevicePortComboBox->setEnabled(false);
415     m_ui.DevicePortParamTable->setEnabled(false);
416 schoenebeck 1461 stabilizeForm();
417     return;
418     }
419    
420 capela 1558 Device& device = ((DeviceItem *) pItem)->device();
421 schoenebeck 1461
422     m_iDirtySetup++;
423     // Flag whether this is a new device.
424     m_bNewDevice = (device.deviceID() < 0);
425    
426     // Fill the device/driver heading...
427 capela 1509 m_ui.DeviceNameTextLabel->setText(device.deviceName());
428 schoenebeck 1461 // The driver combobox is only rebuilt if device type has changed...
429     if (device.deviceType() != m_deviceType) {
430 capela 1509 m_ui.DriverNameComboBox->clear();
431     m_ui.DriverNameComboBox->insertItems(0,
432 capela 1558 Device::getDrivers(pMainForm->client(), device.deviceType()));
433 schoenebeck 1461 m_deviceType = device.deviceType();
434     }
435     // Do we need a driver name?
436     if (m_bNewDevice || device.driverName().isEmpty())
437 capela 1509 device.setDriver(m_ui.DriverNameComboBox->currentText());
438 schoenebeck 1461 setDriverName(device.driverName());
439 capela 1509 m_ui.DriverNameTextLabel->setEnabled(m_bNewDevice);
440     m_ui.DriverNameComboBox->setEnabled(m_bNewDevice);
441 schoenebeck 1461 // Fill the device parameter table...
442 capela 1509 m_deviceParamModel.refresh(&device, m_bNewDevice);
443 schoenebeck 1461 // And now the device port/channel parameter table...
444     switch (device.deviceType()) {
445 capela 1558 case Device::Audio:
446 capela 1509 m_ui.DevicePortTextLabel->setText(tr("Ch&annel:"));
447 schoenebeck 1461 break;
448 capela 1558 case Device::Midi:
449 capela 1509 m_ui.DevicePortTextLabel->setText(tr("P&ort:"));
450 schoenebeck 1461 break;
451 capela 1558 case Device::None:
452 schoenebeck 1461 break;
453     }
454 capela 1509 m_ui.DevicePortComboBox->clear();
455     m_devicePortParamModel.clear();
456 schoenebeck 1461 if (m_bNewDevice) {
457 capela 1509 m_ui.DevicePortTextLabel->setEnabled(false);
458     m_ui.DevicePortComboBox->setEnabled(false);
459     m_ui.DevicePortParamTable->setEnabled(false);
460 schoenebeck 1461 } else {
461     QPixmap pixmap;
462     switch (device.deviceType()) {
463 capela 1558 case Device::Audio:
464 capela 2074 pixmap = QPixmap(":/images/audio2.png");
465 schoenebeck 1461 break;
466 capela 1558 case Device::Midi:
467 capela 2074 pixmap = QPixmap(":/images/midi2.png");
468 schoenebeck 1461 break;
469 capela 1558 case Device::None:
470 schoenebeck 1461 break;
471     }
472 capela 1558 DevicePortList& ports = device.ports();
473     QListIterator<DevicePort *> iter(ports);
474 capela 1499 while (iter.hasNext()) {
475 capela 1558 DevicePort *pPort = iter.next();
476 capela 1509 m_ui.DevicePortComboBox->addItem(pixmap,
477 capela 1499 device.deviceTypeName()
478 schoenebeck 1461 + ' ' + device.driverName()
479     + ' ' + pPort->portName());
480     }
481     bool bEnabled = (ports.count() > 0);
482 capela 1509 m_ui.DevicePortTextLabel->setEnabled(bEnabled);
483     m_ui.DevicePortComboBox->setEnabled(bEnabled);
484     m_ui.DevicePortParamTable->setEnabled(bEnabled);
485 schoenebeck 1461 }
486     // Done.
487     m_iDirtySetup--;
488    
489     // Make the device port/channel selection effective.
490 capela 1509 selectDevicePort(m_ui.DevicePortComboBox->currentIndex());
491 schoenebeck 1461 }
492    
493    
494     // Device port/channel selection slot.
495     void DeviceForm::selectDevicePort ( int iPort )
496     {
497     if (m_iDirtySetup > 0)
498     return;
499    
500     //
501     // Device port/channel selection has changed...
502     //
503    
504 capela 1509 QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
505 schoenebeck 1461 if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
506     return;
507    
508 capela 1558 Device& device = ((DeviceItem *) pItem)->device();
509     DevicePort *pPort = NULL;
510 capela 1504 if (iPort >= 0 && iPort < device.ports().count())
511     pPort = device.ports().at(iPort);
512 schoenebeck 1461 if (pPort) {
513     m_iDirtySetup++;
514 capela 1509 m_devicePortParamModel.refresh(pPort, false);
515 schoenebeck 1461 m_iDirtySetup--;
516     }
517     // Done.
518     stabilizeForm();
519     }
520    
521    
522     // Device parameter value change slot.
523     void DeviceForm::changeDeviceParam ( int iRow, int iCol )
524     {
525     if (m_iDirtySetup > 0)
526     return;
527     if (iRow < 0 || iCol < 0)
528     return;
529    
530     //
531     // Device parameter change...
532     //
533    
534 schoenebeck 1486 /* we do that in the model class now ...
535 capela 1509 QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
536 schoenebeck 1461 if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
537     return;
538    
539 capela 1558 Device& device = ((DeviceItem *) pItem)->device();
540 schoenebeck 1461
541     // Table 1st column has the parameter name;
542 capela 1509 //const QString sParam = m_ui.DeviceParamTable->text(iRow, 0);
543     //const QString sValue = m_ui.DeviceParamTable->text(iRow, iCol);
544     const QString sParam = m_deviceParamModel.data(m_deviceParamModel.index(iRow, 0), Qt::DisplayRole).value<DeviceParameterRow>().name;
545     const QString sValue = m_deviceParamModel.data(m_deviceParamModel.index(iRow, iCol), Qt::DisplayRole).value<DeviceParameterRow>().param.value;
546 schoenebeck 1461 // Set the local device parameter value.
547     if (device.setParam(sParam, sValue)) {
548     selectDevice();
549     } else {
550     stabilizeForm();
551     }
552 schoenebeck 1486 */
553 schoenebeck 1461
554     // Main session should be dirtier...
555     MainForm *pMainForm = MainForm::getInstance();
556     if (pMainForm)
557     pMainForm->sessionDirty();
558     }
559    
560    
561     // Device port/channel parameter value change slot.
562     void DeviceForm::changeDevicePortParam ( int iRow, int iCol )
563     {
564     if (m_iDirtySetup > 0)
565     return;
566     if (iRow < 0 || iCol < 0)
567     return;
568    
569     //
570     // Device port/channel parameter change...
571     //
572    
573 schoenebeck 1486 /* we do that in the model class now ...
574 capela 1509 QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
575 schoenebeck 1461 if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
576     return;
577    
578 capela 1558 Device& device = ((DeviceItem *) pItem)->device();
579 schoenebeck 1461
580 capela 1509 int iPort = m_ui.DevicePortComboBox->currentIndex();
581 capela 1558 DevicePort *pPort = NULL;
582 capela 1504 if (iPort >= 0 && iPort < device.ports().count())
583     pPort = device.ports().at(iPort);
584 schoenebeck 1461 if (pPort == NULL)
585     return;
586    
587     // Table 1st column has the parameter name;
588 capela 1509 //const QString sParam = m_ui.DevicePortParamTable->text(iRow, 0);
589     //const QString sValue = m_ui.DevicePortParamTable->text(iRow, iCol);
590     const QString sParam = m_devicePortParamModel.data(m_devicePortParamModel.index(iRow, 0), Qt::DisplayRole).value<DeviceParameterRow>().name;
591     const QString sValue = m_devicePortParamModel.data(m_devicePortParamModel.index(iRow, iCol), Qt::DisplayRole).value<DeviceParameterRow>().param.value;
592 schoenebeck 1461
593     // Set the local device port/channel parameter value.
594     pPort->setParam(sParam, sValue);
595 schoenebeck 1486 */
596    
597 schoenebeck 1461 // Done.
598     stabilizeForm();
599    
600     // Main session should be dirtier...
601     MainForm* pMainForm = MainForm::getInstance();
602     if (pMainForm)
603     pMainForm->sessionDirty();
604     }
605    
606    
607     // Device list view context menu handler.
608 schoenebeck 1470 void DeviceForm::deviceListViewContextMenu ( const QPoint& pos )
609 schoenebeck 1461 {
610     MainForm *pMainForm = MainForm::getInstance();
611     if (pMainForm == NULL)
612     return;
613    
614 capela 1509 QTreeWidgetItem* pItem = m_ui.DeviceListView->itemAt(pos);
615 schoenebeck 1470 if (pItem == NULL)
616     return;
617    
618 schoenebeck 1461 // Build the device context menu...
619 capela 1499 QMenu menu(this);
620     QAction *pAction;
621 schoenebeck 1461
622     bool bClient = (pMainForm->client() != NULL);
623     bool bEnabled = (pItem != NULL);
624 capela 1499 pAction = menu.addAction(
625 capela 2074 QIcon(":/images/deviceCreate.png"),
626 schoenebeck 1461 tr("&Create device"), this, SLOT(createDevice()));
627 capela 1499 pAction->setEnabled(bEnabled || (bClient && m_bNewDevice));
628     pAction = menu.addAction(
629 capela 2074 QIcon(":/images/deviceDelete.png"),
630 schoenebeck 1461 tr("&Delete device"), this, SLOT(deleteDevice()));
631 capela 1499 pAction->setEnabled(bEnabled && !m_bNewDevice);
632     menu.addSeparator();
633     pAction = menu.addAction(
634 capela 2074 QIcon(":/images/formRefresh.png"),
635 schoenebeck 1461 tr("&Refresh"), this, SLOT(refreshDevices()));
636 capela 1499 pAction->setEnabled(bClient);
637 schoenebeck 1461
638 capela 1499 menu.exec(pos);
639 schoenebeck 1461 }
640    
641    
642     // Stabilize current form state.
643     void DeviceForm::stabilizeForm (void)
644     {
645     MainForm* pMainForm = MainForm::getInstance();
646 capela 1509 QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
647 schoenebeck 1461 bool bClient = (pMainForm && pMainForm->client() != NULL);
648     bool bEnabled = (pItem != NULL);
649 capela 1509 m_ui.DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice);
650     m_ui.DriverNameTextLabel->setEnabled(bEnabled && m_bNewDevice);
651     m_ui.DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice);
652     m_ui.DeviceParamTable->setEnabled(bEnabled);
653     m_ui.RefreshDevicesPushButton->setEnabled(bClient);
654     m_ui.CreateDevicePushButton->setEnabled(bEnabled || (bClient && m_bNewDevice));
655     m_ui.DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice);
656 schoenebeck 1461 }
657    
658 capela 1509
659     void DeviceForm::updateCellRenderers (void)
660     {
661     const int rows = m_deviceParamModel.rowCount();
662     const int cols = m_deviceParamModel.columnCount();
663     updateCellRenderers(
664     m_deviceParamModel.index(0, 0),
665     m_deviceParamModel.index(rows - 1, cols - 1));
666 schoenebeck 1486 }
667    
668 capela 1509
669     void DeviceForm::updateCellRenderers (
670     const QModelIndex& topLeft, const QModelIndex& bottomRight )
671     {
672     for (int r = topLeft.row(); r <= bottomRight.row(); r++) {
673     for (int c = topLeft.column(); c <= bottomRight.column(); c++) {
674     const QModelIndex index = m_deviceParamModel.index(r, c);
675     m_ui.DeviceParamTable->openPersistentEditor(index);
676     }
677     }
678 schoenebeck 1486 }
679    
680 capela 1509
681     void DeviceForm::updatePortCellRenderers (void)
682     {
683     const int rows = m_devicePortParamModel.rowCount();
684     const int cols = m_devicePortParamModel.columnCount();
685     updatePortCellRenderers(
686     m_devicePortParamModel.index(0, 0),
687     m_devicePortParamModel.index(rows - 1, cols - 1));
688 schoenebeck 1486 }
689    
690 capela 1509
691     void DeviceForm::updatePortCellRenderers (
692     const QModelIndex& topLeft, const QModelIndex& bottomRight )
693     {
694     for (int r = topLeft.row(); r <= bottomRight.row(); r++) {
695     for (int c = topLeft.column(); c <= bottomRight.column(); c++) {
696     const QModelIndex index = m_devicePortParamModel.index(r, c);
697     m_ui.DevicePortParamTable->openPersistentEditor(index);
698     }
699     }
700 schoenebeck 1486 }
701    
702 schoenebeck 1461 } // namespace QSampler
703 capela 1464
704    
705     // end of qsamplerDeviceForm.cpp

  ViewVC Help
Powered by ViewVC