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