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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1510 - (hide annotations) (download)
Thu Nov 22 14:17:24 2007 UTC (16 years, 5 months ago) by capela
File size: 19515 byte(s)
- Qt4 migration: code cleanup, personal standards beautification :)

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

  ViewVC Help
Powered by ViewVC