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