1 |
// qsamplerDeviceForm.cpp |
2 |
// |
3 |
/**************************************************************************** |
4 |
Copyright (C) 2004-2012, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
Copyright (C) 2007, 2008 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 |
#include "qsamplerDeviceForm.h" |
24 |
|
25 |
#include "qsamplerAbout.h" |
26 |
#include "qsamplerMainForm.h" |
27 |
|
28 |
#include <QHeaderView> |
29 |
#include <QMessageBox> |
30 |
|
31 |
|
32 |
namespace QSampler { |
33 |
|
34 |
//------------------------------------------------------------------------- |
35 |
// QSampler::DeviceForm -- Device form implementation. |
36 |
// |
37 |
|
38 |
DeviceForm::DeviceForm ( QWidget *pParent, Qt::WindowFlags wflags ) |
39 |
: QDialog(pParent, wflags) |
40 |
{ |
41 |
m_ui.setupUi(this); |
42 |
|
43 |
// Initialize locals. |
44 |
m_iDirtySetup = 0; |
45 |
m_iDirtyCount = 0; |
46 |
m_bNewDevice = false; |
47 |
m_deviceType = Device::None; |
48 |
m_pAudioItems = NULL; |
49 |
m_pMidiItems = NULL; |
50 |
// No exclusive mode as default. |
51 |
m_deviceTypeMode = Device::None; |
52 |
|
53 |
m_ui.DeviceListView->header()->hide(); |
54 |
|
55 |
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 |
m_ui.DeviceParamTable->setModel(&m_deviceParamModel); |
62 |
m_ui.DeviceParamTable->setItemDelegate(&m_deviceParamDelegate); |
63 |
#if QT_VERSION < 0x050000 |
64 |
m_ui.DeviceParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch); |
65 |
#endif |
66 |
m_ui.DeviceParamTable->verticalHeader()->hide(); |
67 |
|
68 |
m_ui.DevicePortParamTable->setModel(&m_devicePortParamModel); |
69 |
m_ui.DevicePortParamTable->setItemDelegate(&m_devicePortParamDelegate); |
70 |
#if QT_VERSION < 0x050000 |
71 |
m_ui.DevicePortParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch); |
72 |
#endif |
73 |
m_ui.DevicePortParamTable->verticalHeader()->hide(); |
74 |
|
75 |
// Initial contents. |
76 |
refreshDevices(); |
77 |
// Try to restore normal window positioning. |
78 |
adjustSize(); |
79 |
|
80 |
QObject::connect(m_ui.DeviceListView, |
81 |
SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), |
82 |
SLOT(selectDevice())); |
83 |
QObject::connect(m_ui.DeviceListView, |
84 |
SIGNAL(customContextMenuRequested(const QPoint&)), |
85 |
SLOT(deviceListViewContextMenu(const QPoint&))); |
86 |
QObject::connect(m_ui.RefreshDevicesPushButton, |
87 |
SIGNAL(clicked()), |
88 |
SLOT(refreshDevices())); |
89 |
QObject::connect(m_ui.DriverNameComboBox, |
90 |
SIGNAL(activated(const QString&)), |
91 |
SLOT(selectDriver(const QString&))); |
92 |
QObject::connect(m_ui.DevicePortComboBox, |
93 |
SIGNAL(activated(int)), |
94 |
SLOT(selectDevicePort(int))); |
95 |
QObject::connect(m_ui.CreateDevicePushButton, |
96 |
SIGNAL(clicked()), |
97 |
SLOT(createDevice())); |
98 |
QObject::connect(m_ui.DeleteDevicePushButton, |
99 |
SIGNAL(clicked()), |
100 |
SLOT(deleteDevice())); |
101 |
QObject::connect(m_ui.ClosePushButton, |
102 |
SIGNAL(clicked()), |
103 |
SLOT(close())); |
104 |
QObject::connect(&m_deviceParamModel, |
105 |
SIGNAL(modelReset()), |
106 |
SLOT(updateCellRenderers())); |
107 |
QObject::connect(&m_deviceParamModel, |
108 |
SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), |
109 |
SLOT(updateCellRenderers(const QModelIndex&, const QModelIndex&))); |
110 |
QObject::connect(&m_devicePortParamModel, |
111 |
SIGNAL(modelReset()), |
112 |
SLOT(updatePortCellRenderers())); |
113 |
QObject::connect(&m_devicePortParamModel, |
114 |
SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), |
115 |
SLOT(updatePortCellRenderers(const QModelIndex&, const QModelIndex&))); |
116 |
} |
117 |
|
118 |
|
119 |
DeviceForm::~DeviceForm (void) |
120 |
{ |
121 |
} |
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 |
QWidget::showEvent(pShowEvent); |
132 |
|
133 |
refreshDevices(); |
134 |
} |
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 |
Device::DeviceType deviceTypeMode ) |
157 |
{ |
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 |
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 |
sDriverName); |
177 |
} |
178 |
|
179 |
|
180 |
// Set current selected device by type and id. |
181 |
void DeviceForm::setDevice ( Device *pDevice ) |
182 |
{ |
183 |
// In case no device is given... |
184 |
Device::DeviceType deviceType = m_deviceTypeMode; |
185 |
if (pDevice) |
186 |
deviceType = pDevice->deviceType(); |
187 |
|
188 |
// Get the device view root item... |
189 |
DeviceItem *pRootItem = NULL; |
190 |
switch (deviceType) { |
191 |
case Device::Audio: |
192 |
pRootItem = m_pAudioItems; |
193 |
break; |
194 |
case Device::Midi: |
195 |
pRootItem = m_pMidiItems; |
196 |
break; |
197 |
case Device::None: |
198 |
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 |
m_ui.DeviceListView->setCurrentItem(pRootItem); |
208 |
return; |
209 |
} |
210 |
|
211 |
// For each child, test for identity... |
212 |
for (int i = 0; i < pRootItem->childCount(); i++) { |
213 |
DeviceItem* pDeviceItem = |
214 |
(DeviceItem*) pRootItem->child(i); |
215 |
|
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 |
QTreeWidgetItem *pItem = m_ui.DeviceListView->currentItem(); |
234 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
235 |
return; |
236 |
|
237 |
// About a brand new device instance... |
238 |
Device device(((DeviceItem *) pItem)->device()); |
239 |
if (device.createDevice()) { |
240 |
// Now it depends on the device type... |
241 |
DeviceItem *pRootItem = NULL; |
242 |
switch (device.deviceType()) { |
243 |
case Device::Audio: |
244 |
pRootItem = m_pAudioItems; |
245 |
break; |
246 |
case Device::Midi: |
247 |
pRootItem = m_pMidiItems; |
248 |
break; |
249 |
case Device::None: |
250 |
break; |
251 |
} |
252 |
// Append the new device item. |
253 |
DeviceItem *pDeviceItem = new DeviceItem(pRootItem, |
254 |
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 |
QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem(); |
272 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
273 |
return; |
274 |
|
275 |
Device& device = ((DeviceItem *) pItem)->device(); |
276 |
|
277 |
// Prompt user if this is for real... |
278 |
Options *pOptions = pMainForm->options(); |
279 |
if (pOptions && pOptions->bConfirmRemove) { |
280 |
if (QMessageBox::warning(this, |
281 |
QSAMPLER_TITLE ": " + tr("Warning"), |
282 |
tr("About to delete device:\n\n" |
283 |
"%1\n\n" |
284 |
"Are you sure?") |
285 |
.arg(device.deviceName()), |
286 |
QMessageBox::Ok | QMessageBox::Cancel) |
287 |
== QMessageBox::Cancel) |
288 |
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 |
m_ui.DeviceListView->clear(); |
318 |
if (pMainForm->client()) { |
319 |
int *piDeviceIDs; |
320 |
// Grab and pop Audio devices... |
321 |
if (m_deviceTypeMode == Device::None || |
322 |
m_deviceTypeMode == Device::Audio) { |
323 |
m_pAudioItems = new DeviceItem(m_ui.DeviceListView, |
324 |
Device::Audio); |
325 |
} |
326 |
if (m_pAudioItems) { |
327 |
piDeviceIDs = Device::getDevices(pMainForm->client(), |
328 |
Device::Audio); |
329 |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
330 |
new DeviceItem(m_pAudioItems, |
331 |
Device::Audio, piDeviceIDs[i]); |
332 |
} |
333 |
m_pAudioItems->setExpanded(true); |
334 |
} |
335 |
// Grab and pop MIDI devices... |
336 |
if (m_deviceTypeMode == Device::None || |
337 |
m_deviceTypeMode == Device::Midi) { |
338 |
m_pMidiItems = new DeviceItem(m_ui.DeviceListView, |
339 |
Device::Midi); |
340 |
} |
341 |
if (m_pMidiItems) { |
342 |
piDeviceIDs = Device::getDevices(pMainForm->client(), |
343 |
Device::Midi); |
344 |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
345 |
new DeviceItem(m_pMidiItems, |
346 |
Device::Midi, piDeviceIDs[i]); |
347 |
} |
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 |
QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem(); |
371 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
372 |
return; |
373 |
|
374 |
Device& device = ((DeviceItem *) pItem)->device(); |
375 |
|
376 |
// Driver change is only valid for scratch devices... |
377 |
if (m_bNewDevice) { |
378 |
m_iDirtySetup++; |
379 |
device.setDriver(sDriverName); |
380 |
m_deviceParamModel.refresh(&device, m_bNewDevice); |
381 |
m_iDirtySetup--; |
382 |
// Done. |
383 |
stabilizeForm(); |
384 |
} |
385 |
} |
386 |
|
387 |
|
388 |
// Device selection slot. |
389 |
void DeviceForm::selectDevice () |
390 |
{ |
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 |
QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem(); |
403 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) { |
404 |
m_deviceType = Device::None; |
405 |
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 |
stabilizeForm(); |
413 |
return; |
414 |
} |
415 |
|
416 |
Device& device = ((DeviceItem *) pItem)->device(); |
417 |
|
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 |
m_ui.DeviceNameTextLabel->setText(device.deviceName()); |
424 |
// The driver combobox is only rebuilt if device type has changed... |
425 |
if (device.deviceType() != m_deviceType) { |
426 |
m_ui.DriverNameComboBox->clear(); |
427 |
m_ui.DriverNameComboBox->insertItems(0, |
428 |
Device::getDrivers(pMainForm->client(), device.deviceType())); |
429 |
m_deviceType = device.deviceType(); |
430 |
} |
431 |
// Do we need a driver name? |
432 |
if (m_bNewDevice || device.driverName().isEmpty()) |
433 |
device.setDriver(m_ui.DriverNameComboBox->currentText()); |
434 |
setDriverName(device.driverName()); |
435 |
m_ui.DriverNameTextLabel->setEnabled(m_bNewDevice); |
436 |
m_ui.DriverNameComboBox->setEnabled(m_bNewDevice); |
437 |
// Fill the device parameter table... |
438 |
m_deviceParamModel.refresh(&device, m_bNewDevice); |
439 |
// And now the device port/channel parameter table... |
440 |
switch (device.deviceType()) { |
441 |
case Device::Audio: |
442 |
m_ui.DevicePortTextLabel->setText(tr("Ch&annel:")); |
443 |
break; |
444 |
case Device::Midi: |
445 |
m_ui.DevicePortTextLabel->setText(tr("P&ort:")); |
446 |
break; |
447 |
case Device::None: |
448 |
break; |
449 |
} |
450 |
m_ui.DevicePortComboBox->clear(); |
451 |
m_devicePortParamModel.clear(); |
452 |
if (m_bNewDevice) { |
453 |
m_ui.DevicePortTextLabel->setEnabled(false); |
454 |
m_ui.DevicePortComboBox->setEnabled(false); |
455 |
m_ui.DevicePortParamTable->setEnabled(false); |
456 |
} else { |
457 |
QPixmap pixmap; |
458 |
switch (device.deviceType()) { |
459 |
case Device::Audio: |
460 |
pixmap = QPixmap(":/images/audio2.png"); |
461 |
break; |
462 |
case Device::Midi: |
463 |
pixmap = QPixmap(":/images/midi2.png"); |
464 |
break; |
465 |
case Device::None: |
466 |
break; |
467 |
} |
468 |
DevicePortList& ports = device.ports(); |
469 |
QListIterator<DevicePort *> iter(ports); |
470 |
while (iter.hasNext()) { |
471 |
DevicePort *pPort = iter.next(); |
472 |
m_ui.DevicePortComboBox->addItem(pixmap, |
473 |
device.deviceTypeName() |
474 |
+ ' ' + device.driverName() |
475 |
+ ' ' + pPort->portName()); |
476 |
} |
477 |
bool bEnabled = (ports.count() > 0); |
478 |
m_ui.DevicePortTextLabel->setEnabled(bEnabled); |
479 |
m_ui.DevicePortComboBox->setEnabled(bEnabled); |
480 |
m_ui.DevicePortParamTable->setEnabled(bEnabled); |
481 |
} |
482 |
// Done. |
483 |
m_iDirtySetup--; |
484 |
|
485 |
// Make the device port/channel selection effective. |
486 |
selectDevicePort(m_ui.DevicePortComboBox->currentIndex()); |
487 |
} |
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 |
QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem(); |
501 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
502 |
return; |
503 |
|
504 |
Device& device = ((DeviceItem *) pItem)->device(); |
505 |
DevicePort *pPort = NULL; |
506 |
if (iPort >= 0 && iPort < device.ports().count()) |
507 |
pPort = device.ports().at(iPort); |
508 |
if (pPort) { |
509 |
m_iDirtySetup++; |
510 |
m_devicePortParamModel.refresh(pPort, false); |
511 |
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 |
/* we do that in the model class now ... |
531 |
QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem(); |
532 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
533 |
return; |
534 |
|
535 |
Device& device = ((DeviceItem *) pItem)->device(); |
536 |
|
537 |
// Table 1st column has the parameter name; |
538 |
//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 |
// Set the local device parameter value. |
543 |
if (device.setParam(sParam, sValue)) { |
544 |
selectDevice(); |
545 |
} else { |
546 |
stabilizeForm(); |
547 |
} |
548 |
*/ |
549 |
|
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 |
/* we do that in the model class now ... |
570 |
QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem(); |
571 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
572 |
return; |
573 |
|
574 |
Device& device = ((DeviceItem *) pItem)->device(); |
575 |
|
576 |
int iPort = m_ui.DevicePortComboBox->currentIndex(); |
577 |
DevicePort *pPort = NULL; |
578 |
if (iPort >= 0 && iPort < device.ports().count()) |
579 |
pPort = device.ports().at(iPort); |
580 |
if (pPort == NULL) |
581 |
return; |
582 |
|
583 |
// Table 1st column has the parameter name; |
584 |
//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 |
|
589 |
// Set the local device port/channel parameter value. |
590 |
pPort->setParam(sParam, sValue); |
591 |
*/ |
592 |
|
593 |
// 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 |
void DeviceForm::deviceListViewContextMenu ( const QPoint& pos ) |
605 |
{ |
606 |
MainForm *pMainForm = MainForm::getInstance(); |
607 |
if (pMainForm == NULL) |
608 |
return; |
609 |
|
610 |
QTreeWidgetItem* pItem = m_ui.DeviceListView->itemAt(pos); |
611 |
if (pItem == NULL) |
612 |
return; |
613 |
|
614 |
// Build the device context menu... |
615 |
QMenu menu(this); |
616 |
QAction *pAction; |
617 |
|
618 |
bool bClient = (pMainForm->client() != NULL); |
619 |
bool bEnabled = (pItem != NULL); |
620 |
pAction = menu.addAction( |
621 |
QIcon(":/images/deviceCreate.png"), |
622 |
tr("&Create device"), this, SLOT(createDevice())); |
623 |
pAction->setEnabled(bEnabled || (bClient && m_bNewDevice)); |
624 |
pAction = menu.addAction( |
625 |
QIcon(":/images/deviceDelete.png"), |
626 |
tr("&Delete device"), this, SLOT(deleteDevice())); |
627 |
pAction->setEnabled(bEnabled && !m_bNewDevice); |
628 |
menu.addSeparator(); |
629 |
pAction = menu.addAction( |
630 |
QIcon(":/images/formRefresh.png"), |
631 |
tr("&Refresh"), this, SLOT(refreshDevices())); |
632 |
pAction->setEnabled(bClient); |
633 |
|
634 |
menu.exec(pos); |
635 |
} |
636 |
|
637 |
|
638 |
// Stabilize current form state. |
639 |
void DeviceForm::stabilizeForm (void) |
640 |
{ |
641 |
MainForm* pMainForm = MainForm::getInstance(); |
642 |
QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem(); |
643 |
bool bClient = (pMainForm && pMainForm->client() != NULL); |
644 |
bool bEnabled = (pItem != NULL); |
645 |
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 |
} |
653 |
|
654 |
|
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 |
} |
663 |
|
664 |
|
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 |
} |
675 |
|
676 |
|
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 |
} |
685 |
|
686 |
|
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 |
} |
697 |
|
698 |
} // namespace QSampler |
699 |
|
700 |
|
701 |
// end of qsamplerDeviceForm.cpp |