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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC