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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC