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