1 |
// qsamplerDevice.cpp |
// qsamplerDevice.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2006, rncbc aka Rui Nuno Capela. All rights reserved. |
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 |
This program is free software; you can redistribute it and/or |
8 |
modify it under the terms of the GNU General Public License |
modify it under the terms of the GNU General Public License |
29 |
#include <qspinbox.h> |
#include <qspinbox.h> |
30 |
#include <qlineedit.h> |
#include <qlineedit.h> |
31 |
|
|
32 |
|
using namespace QSampler; |
33 |
|
|
34 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
35 |
// qsamplerDeviceParam - MIDI/Audio Device parameter structure. |
// qsamplerDeviceParam - MIDI/Audio Device parameter structure. |
132 |
// Initializer. |
// Initializer. |
133 |
void qsamplerDevice::setDevice ( qsamplerDeviceType deviceType, int iDeviceID ) |
void qsamplerDevice::setDevice ( qsamplerDeviceType deviceType, int iDeviceID ) |
134 |
{ |
{ |
135 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
136 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
137 |
return; |
return; |
138 |
if (pMainForm->client() == NULL) |
if (pMainForm->client() == NULL) |
211 |
// Driver name initializer/settler. |
// Driver name initializer/settler. |
212 |
void qsamplerDevice::setDriver ( const QString& sDriverName ) |
void qsamplerDevice::setDriver ( const QString& sDriverName ) |
213 |
{ |
{ |
214 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
215 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
216 |
return; |
return; |
217 |
if (pMainForm->client() == NULL) |
if (pMainForm->client() == NULL) |
315 |
bool qsamplerDevice::setParam ( const QString& sParam, |
bool qsamplerDevice::setParam ( const QString& sParam, |
316 |
const QString& sValue ) |
const QString& sValue ) |
317 |
{ |
{ |
318 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
319 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
320 |
return false; |
return false; |
321 |
if (pMainForm->client() == NULL) |
if (pMainForm->client() == NULL) |
326 |
|
|
327 |
// If the device already exists, things get immediate... |
// If the device already exists, things get immediate... |
328 |
int iRefresh = 0; |
int iRefresh = 0; |
329 |
if (m_iDeviceID >= 0) { |
if (m_iDeviceID >= 0 && sValue != QString::null) { |
330 |
// Prepare parameter struct. |
// Prepare parameter struct. |
331 |
lscp_param_t param; |
lscp_param_t param; |
332 |
param.key = (char *) sParam.latin1(); |
param.key = (char *) sParam.latin1(); |
385 |
// Create a new device, as a copy of this current one. |
// Create a new device, as a copy of this current one. |
386 |
bool qsamplerDevice::createDevice (void) |
bool qsamplerDevice::createDevice (void) |
387 |
{ |
{ |
388 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
389 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
390 |
return false; |
return false; |
391 |
if (pMainForm->client() == NULL) |
if (pMainForm->client() == NULL) |
396 |
int iParam = 0; |
int iParam = 0; |
397 |
qsamplerDeviceParamMap::ConstIterator iter; |
qsamplerDeviceParamMap::ConstIterator iter; |
398 |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) { |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) { |
399 |
|
if (iter.data().value == QString::null) continue; |
400 |
pParams[iParam].key = (char *) iter.key().latin1(); |
pParams[iParam].key = (char *) iter.key().latin1(); |
401 |
pParams[iParam].value = (char *) iter.data().value.latin1(); |
pParams[iParam].value = (char *) iter.data().value.latin1(); |
402 |
++iParam; |
++iParam; |
441 |
// Destroy existing device. |
// Destroy existing device. |
442 |
bool qsamplerDevice::deleteDevice (void) |
bool qsamplerDevice::deleteDevice (void) |
443 |
{ |
{ |
444 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
445 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
446 |
return false; |
return false; |
447 |
if (pMainForm->client() == NULL) |
if (pMainForm->client() == NULL) |
542 |
// Refresh/set given parameter based on driver supplied dependencies. |
// Refresh/set given parameter based on driver supplied dependencies. |
543 |
int qsamplerDevice::refreshParam ( const QString& sParam ) |
int qsamplerDevice::refreshParam ( const QString& sParam ) |
544 |
{ |
{ |
545 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
546 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
547 |
return 0; |
return 0; |
548 |
if (pMainForm->client() == NULL) |
if (pMainForm->client() == NULL) |
591 |
break; |
break; |
592 |
} |
} |
593 |
if (pParamInfo) { |
if (pParamInfo) { |
594 |
param = qsamplerDeviceParam(pParamInfo, QString(param.value)); |
if (param.value != QString::null) |
595 |
|
param = qsamplerDeviceParam(pParamInfo, param.value); |
596 |
|
else |
597 |
|
param = qsamplerDeviceParam(pParamInfo, NULL); |
598 |
iRefresh++; |
iRefresh++; |
599 |
} |
} |
600 |
|
|
609 |
// Redirected messages output methods. |
// Redirected messages output methods. |
610 |
void qsamplerDevice::appendMessages( const QString& s ) const |
void qsamplerDevice::appendMessages( const QString& s ) const |
611 |
{ |
{ |
612 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
613 |
if (pMainForm) |
if (pMainForm) |
614 |
pMainForm->appendMessages(deviceName() + ' ' + s); |
pMainForm->appendMessages(deviceName() + ' ' + s); |
615 |
} |
} |
617 |
void qsamplerDevice::appendMessagesColor( const QString& s, |
void qsamplerDevice::appendMessagesColor( const QString& s, |
618 |
const QString& c ) const |
const QString& c ) const |
619 |
{ |
{ |
620 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
621 |
if (pMainForm) |
if (pMainForm) |
622 |
pMainForm->appendMessagesColor(deviceName() + ' ' + s, c); |
pMainForm->appendMessagesColor(deviceName() + ' ' + s, c); |
623 |
} |
} |
624 |
|
|
625 |
void qsamplerDevice::appendMessagesText( const QString& s ) const |
void qsamplerDevice::appendMessagesText( const QString& s ) const |
626 |
{ |
{ |
627 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
628 |
if (pMainForm) |
if (pMainForm) |
629 |
pMainForm->appendMessagesText(deviceName() + ' ' + s); |
pMainForm->appendMessagesText(deviceName() + ' ' + s); |
630 |
} |
} |
631 |
|
|
632 |
void qsamplerDevice::appendMessagesError( const QString& s ) const |
void qsamplerDevice::appendMessagesError( const QString& s ) const |
633 |
{ |
{ |
634 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
635 |
if (pMainForm) |
if (pMainForm) |
636 |
pMainForm->appendMessagesError(deviceName() + "\n\n" + s); |
pMainForm->appendMessagesError(deviceName() + "\n\n" + s); |
637 |
} |
} |
638 |
|
|
639 |
void qsamplerDevice::appendMessagesClient( const QString& s ) const |
void qsamplerDevice::appendMessagesClient( const QString& s ) const |
640 |
{ |
{ |
641 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
642 |
if (pMainForm) |
if (pMainForm) |
643 |
pMainForm->appendMessagesClient(deviceName() + ' ' + s); |
pMainForm->appendMessagesClient(deviceName() + ' ' + s); |
644 |
} |
} |
708 |
// Initializer. |
// Initializer. |
709 |
void qsamplerDevicePort::setDevicePort ( int iPortID ) |
void qsamplerDevicePort::setDevicePort ( int iPortID ) |
710 |
{ |
{ |
711 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
712 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
713 |
return; |
return; |
714 |
if (pMainForm->client() == NULL) |
if (pMainForm->client() == NULL) |
797 |
bool qsamplerDevicePort::setParam ( const QString& sParam, |
bool qsamplerDevicePort::setParam ( const QString& sParam, |
798 |
const QString& sValue ) |
const QString& sValue ) |
799 |
{ |
{ |
800 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
801 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
802 |
return false; |
return false; |
803 |
if (pMainForm->client() == NULL) |
if (pMainForm->client() == NULL) |
847 |
|
|
848 |
|
|
849 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
850 |
// qsamplerDeviceItem - QListView device item. |
// qsamplerDeviceItem - QTreeWidget device item. |
851 |
// |
// |
852 |
|
|
853 |
// Constructors. |
// Constructors. |
854 |
qsamplerDeviceItem::qsamplerDeviceItem ( QListView *pListView, |
qsamplerDeviceItem::qsamplerDeviceItem ( QTreeWidget* pTreeWidget, |
855 |
qsamplerDevice::qsamplerDeviceType deviceType ) |
qsamplerDevice::qsamplerDeviceType deviceType ) |
856 |
: QListViewItem(pListView), m_device(deviceType) |
: QTreeWidgetItem(pTreeWidget, QSAMPLER_DEVICE_ITEM), |
857 |
|
m_device(deviceType) |
858 |
{ |
{ |
859 |
switch(m_device.deviceType()) { |
switch(m_device.deviceType()) { |
860 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
861 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio1.png")); |
setIcon(0, QPixmap(":/icons/audio1.png")); |
862 |
QListViewItem::setText(0, QObject::tr("Audio Devices")); |
setText(0, QObject::tr("Audio Devices")); |
863 |
break; |
break; |
864 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
865 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi1.png")); |
setIcon(0, QPixmap(":/icons/midi1.png")); |
866 |
QListViewItem::setText(0, QObject::tr("MIDI Devices")); |
setText(0, QObject::tr("MIDI Devices")); |
867 |
break; |
break; |
868 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
869 |
break; |
break; |
870 |
} |
} |
871 |
} |
} |
872 |
|
|
873 |
qsamplerDeviceItem::qsamplerDeviceItem ( QListViewItem *pItem, |
qsamplerDeviceItem::qsamplerDeviceItem ( QTreeWidgetItem* pItem, |
874 |
qsamplerDevice::qsamplerDeviceType deviceType, |
qsamplerDevice::qsamplerDeviceType deviceType, |
875 |
int iDeviceID ) |
int iDeviceID ) |
876 |
: QListViewItem(pItem), m_device(deviceType, iDeviceID) |
: QTreeWidgetItem(pItem, QSAMPLER_DEVICE_ITEM), |
877 |
|
m_device(deviceType, iDeviceID) |
878 |
{ |
{ |
879 |
switch(m_device.deviceType()) { |
switch(m_device.deviceType()) { |
880 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
881 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio2.png")); |
setIcon(0, QPixmap(":/icons/audio2.png")); |
882 |
break; |
break; |
883 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
884 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi2.png")); |
setIcon(0, QPixmap(":/icons/midi2.png")); |
885 |
break; |
break; |
886 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
887 |
break; |
break; |
888 |
} |
} |
889 |
|
|
890 |
QListViewItem::setText(0, m_device.deviceName()); |
setText(0, m_device.deviceName()); |
891 |
} |
} |
892 |
|
|
893 |
// Default destructor. |
// Default destructor. |
894 |
qsamplerDeviceItem::~qsamplerDeviceItem (void) |
qsamplerDeviceItem::~qsamplerDeviceItem () |
895 |
{ |
{ |
896 |
} |
} |
897 |
|
|
898 |
// Instance accessors. |
// Instance accessors. |
899 |
qsamplerDevice& qsamplerDeviceItem::device (void) |
qsamplerDevice& qsamplerDeviceItem::device () |
900 |
{ |
{ |
901 |
return m_device; |
return m_device; |
902 |
} |
} |
903 |
|
|
|
// To virtually distinguish between list view items. |
|
|
int qsamplerDeviceItem::rtti() const |
|
|
{ |
|
|
return QSAMPLER_DEVICE_ITEM; |
|
|
} |
|
|
|
|
|
|
|
904 |
|
|
905 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
906 |
// qsamplerDeviceParamTable - Device parameter view table. |
// AbstractDeviceParamModel - data model base class for device parameters |
907 |
// |
// |
908 |
|
|
909 |
// Constructor. |
AbstractDeviceParamModel::AbstractDeviceParamModel(QObject* parent) : QAbstractTableModel(parent), bEditable(false) { |
910 |
qsamplerDeviceParamTable::qsamplerDeviceParamTable ( QWidget *pParent, |
params = NULL; |
|
const char *pszName ) |
|
|
: QTable(pParent, pszName) |
|
|
{ |
|
|
// Set fixed number of columns. |
|
|
QTable::setNumCols(3); |
|
|
QTable::setShowGrid(false); |
|
|
QTable::setSorting(false); |
|
|
QTable::setFocusStyle(QTable::FollowStyle); |
|
|
QTable::setSelectionMode(QTable::NoSelection); |
|
|
// No vertical header. |
|
|
QTable::verticalHeader()->hide(); |
|
|
QTable::setLeftMargin(0); |
|
|
// Initialize the fixed table column headings. |
|
|
QHeader *pHeader = QTable::horizontalHeader(); |
|
|
pHeader->setLabel(0, tr("Parameter")); |
|
|
pHeader->setLabel(1, tr("Description")); |
|
|
pHeader->setLabel(2, tr("Value")); |
|
|
// Set read-onlyness of each column |
|
|
QTable::setColumnReadOnly(0, true); |
|
|
QTable::setColumnReadOnly(1, true); |
|
|
// QTable::setColumnReadOnly(2, false); -- of course not. |
|
|
QTable::setColumnStretchable(1, true); |
|
911 |
} |
} |
912 |
|
|
913 |
// Default destructor. |
int AbstractDeviceParamModel::rowCount(const QModelIndex& /*parent*/) const { |
914 |
qsamplerDeviceParamTable::~qsamplerDeviceParamTable (void) |
//std::cout << "model size=" << params.size() << "\n" << std::flush; |
915 |
{ |
return (params) ? params->size() : 0; |
916 |
} |
} |
917 |
|
|
918 |
|
int AbstractDeviceParamModel::columnCount(const QModelIndex& /*parent*/) const { |
919 |
|
return 3; |
920 |
|
} |
921 |
|
|
922 |
// Common parameter table renderer. |
Qt::ItemFlags AbstractDeviceParamModel::flags(const QModelIndex& /*index*/) const { |
923 |
void qsamplerDeviceParamTable::refresh ( const qsamplerDeviceParamMap& params, |
return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled; |
924 |
bool bEditable ) |
} |
|
{ |
|
|
// Always (re)start it empty. |
|
|
QTable::setUpdatesEnabled(false); |
|
|
QTable::setNumRows(0); |
|
925 |
|
|
926 |
// Fill the parameter table... |
QVariant AbstractDeviceParamModel::data(const QModelIndex &index, int role) const { |
927 |
QTable::insertRows(0, params.count()); |
if (!index.isValid()) { |
928 |
int iRow = 0; |
//std::cout << "inavlid device model index\n" << std::flush; |
929 |
qsamplerDeviceParamMap::ConstIterator iter; |
return QVariant(); |
930 |
for (iter = params.begin(); iter != params.end(); ++iter) { |
} |
931 |
const qsamplerDeviceParam& param = iter.data(); |
if (role != Qt::DisplayRole) { |
932 |
bool bEnabled = (bEditable || !param.fix); |
//std::cout << "inavlid display role\n" << std::flush; |
933 |
QTable::setText(iRow, 0, iter.key()); |
return QVariant(); |
934 |
QTable::setText(iRow, 1, param.description); |
} |
935 |
if (param.type == LSCP_TYPE_BOOL) { |
|
936 |
QStringList opts; |
DeviceParameterRow item; |
937 |
opts.append(tr("false")); |
item.name = params->keys()[index.row()]; |
938 |
opts.append(tr("true")); |
item.param = (*params)[item.name]; |
939 |
QComboTableItem *pComboItem = new QComboTableItem(this, opts); |
|
940 |
pComboItem->setCurrentItem(param.value.lower() == "true" ? 1 : 0); |
//std::cout << "item["<<index.row()<<"]=[" << item.name.toLatin1().data() << "]\n" << std::flush; |
941 |
pComboItem->setEnabled(bEnabled); |
|
942 |
QTable::setItem(iRow, 2, pComboItem); |
return QVariant::fromValue(item); |
943 |
} else if (param.possibilities.count() > 0 && bEnabled) { |
} |
944 |
QStringList opts = param.possibilities; |
|
945 |
if (param.multiplicity) |
QVariant AbstractDeviceParamModel::headerData(int section, Qt::Orientation orientation, int role) const { |
946 |
opts.prepend(tr("(none)")); |
if (role != Qt::DisplayRole) return QVariant(); |
947 |
QComboTableItem *pComboItem = new QComboTableItem(this, opts); |
|
948 |
if (param.value.isEmpty()) |
if (orientation == Qt::Horizontal) { |
949 |
pComboItem->setCurrentItem(0); |
switch (section) { |
950 |
else |
case 0: return tr("Parameter"); |
951 |
pComboItem->setCurrentItem(param.value); |
case 1: return tr("Value"); |
952 |
pComboItem->setEnabled(bEnabled); |
case 2: return tr("Description"); |
953 |
QTable::setItem(iRow, 2, pComboItem); |
default: return QVariant(); |
954 |
} else if (param.type == LSCP_TYPE_INT && bEnabled |
} |
955 |
&& !param.range_min.isEmpty() |
} |
|
&& !param.range_max.isEmpty()) { |
|
|
qsamplerDeviceParamTableSpinBox *pSpinItem = |
|
|
new qsamplerDeviceParamTableSpinBox(this, |
|
|
bEnabled ? QTableItem::OnTyping : QTableItem::Never, |
|
|
param.value); |
|
|
pSpinItem->setMinValue(param.range_min.toInt()); |
|
|
pSpinItem->setMaxValue(param.range_max.toInt()); |
|
|
QTable::setItem(iRow, 2, pSpinItem); |
|
|
} else { |
|
|
qsamplerDeviceParamTableEditBox *pEditItem = |
|
|
new qsamplerDeviceParamTableEditBox(this, |
|
|
bEnabled ? QTableItem::OnTyping : QTableItem::Never, |
|
|
param.value); |
|
|
QTable::setItem(iRow, 2, pEditItem); |
|
|
} |
|
|
++iRow; |
|
|
} |
|
956 |
|
|
957 |
// Adjust optimal column widths. |
return QVariant(); |
958 |
QTable::adjustColumn(0); |
} |
959 |
QTable::adjustColumn(2); |
|
960 |
|
void AbstractDeviceParamModel::refresh(const qsamplerDeviceParamMap* params, bool bEditable) { |
961 |
|
this->params = params; |
962 |
|
this->bEditable = bEditable; |
963 |
|
// inform the outer world (QTableView) that our data changed |
964 |
|
QAbstractTableModel::reset(); |
965 |
|
} |
966 |
|
|
967 |
QTable::setUpdatesEnabled(true); |
void AbstractDeviceParamModel::clear() { |
968 |
QTable::updateContents(); |
params = NULL; |
969 |
|
// inform the outer world (QTableView) that our data changed |
970 |
|
QAbstractTableModel::reset(); |
971 |
} |
} |
972 |
|
|
973 |
|
|
974 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
975 |
// qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table. |
// DeviceParamModel - data model for device parameters (used for QTableView) |
976 |
// |
// |
977 |
|
|
978 |
// Constructor. |
DeviceParamModel::DeviceParamModel(QObject* parent) : AbstractDeviceParamModel(parent) { |
979 |
qsamplerDeviceParamTableSpinBox::qsamplerDeviceParamTableSpinBox ( |
device = NULL; |
|
QTable *pTable, EditType editType, const QString& sText ) |
|
|
: QTableItem(pTable, editType, sText) |
|
|
{ |
|
|
m_iValue = sText.toInt(); |
|
|
m_iMinValue = m_iMaxValue = 0; |
|
980 |
} |
} |
981 |
|
|
982 |
// Public accessors. |
bool DeviceParamModel::setData(const QModelIndex& index, const QVariant& value, int /*role*/) { |
983 |
void qsamplerDeviceParamTableSpinBox::setValue ( int iValue ) |
if (!index.isValid()) { |
984 |
{ |
return false; |
985 |
m_iValue = iValue; |
} |
986 |
QTableItem::setText(QString::number(m_iValue)); |
QString key = params->keys()[index.row()]; |
987 |
|
//params[key].value = value.toString(); |
988 |
|
device->setParam(key, value.toString()); |
989 |
|
emit dataChanged(index, index); |
990 |
|
return true; |
991 |
} |
} |
992 |
|
|
993 |
void qsamplerDeviceParamTableSpinBox::setMinValue ( int iMinValue ) |
void DeviceParamModel::refresh(qsamplerDevice* pDevice, bool bEditable) { |
994 |
{ |
device = pDevice; |
995 |
m_iMinValue = iMinValue; |
AbstractDeviceParamModel::refresh(&pDevice->params(), bEditable); |
996 |
} |
} |
997 |
|
|
998 |
void qsamplerDeviceParamTableSpinBox::setMaxValue ( int iMaxValue ) |
void DeviceParamModel::clear() { |
999 |
{ |
AbstractDeviceParamModel::clear(); |
1000 |
m_iMaxValue = iMaxValue; |
device = NULL; |
1001 |
} |
} |
1002 |
|
|
1003 |
// Virtual implemetations. |
|
1004 |
QWidget *qsamplerDeviceParamTableSpinBox::createEditor (void) const |
//------------------------------------------------------------------------- |
1005 |
{ |
// PortParamModel - data model for port parameters (used for QTableView) |
1006 |
QSpinBox *pSpinBox = new QSpinBox(QTableItem::table()->viewport()); |
// |
1007 |
QObject::connect(pSpinBox, SIGNAL(valueChanged(int)), |
|
1008 |
QTableItem::table(), SLOT(doValueChanged())); |
PortParamModel::PortParamModel(QObject* parent) : AbstractDeviceParamModel(parent) { |
1009 |
if (m_iValue >= m_iMinValue && m_iMaxValue >= m_iValue) { |
port = NULL; |
|
pSpinBox->setMinValue(m_iMinValue); |
|
|
pSpinBox->setMaxValue(m_iMaxValue); |
|
|
} |
|
|
pSpinBox->setValue(m_iValue); |
|
|
return pSpinBox; |
|
1010 |
} |
} |
1011 |
|
|
1012 |
void qsamplerDeviceParamTableSpinBox::setContentFromEditor ( QWidget *pWidget ) |
bool PortParamModel::setData(const QModelIndex& index, const QVariant& value, int /*role*/) { |
1013 |
{ |
if (!index.isValid()) { |
1014 |
if (pWidget->inherits("QSpinBox")) |
return false; |
1015 |
QTableItem::setText(QString::number(((QSpinBox *) pWidget)->value())); |
} |
1016 |
else |
QString key = params->keys()[index.row()]; |
1017 |
QTableItem::setContentFromEditor(pWidget); |
//params[key].value = value.toString(); |
1018 |
|
port->setParam(key, value.toString()); |
1019 |
|
emit dataChanged(index, index); |
1020 |
|
return true; |
1021 |
|
} |
1022 |
|
|
1023 |
|
void PortParamModel::refresh(qsamplerDevicePort* pPort, bool bEditable) { |
1024 |
|
port = pPort; |
1025 |
|
AbstractDeviceParamModel::refresh(&pPort->params(), bEditable); |
1026 |
|
} |
1027 |
|
|
1028 |
|
void PortParamModel::clear() { |
1029 |
|
AbstractDeviceParamModel::clear(); |
1030 |
|
port = NULL; |
1031 |
} |
} |
1032 |
|
|
1033 |
|
|
1034 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
1035 |
// qsamplerDeviceParamTableEditBox - Custom edit box for parameter table. |
// DeviceParamDelegate - table cell renderer for device/port parameters |
1036 |
// |
// |
1037 |
|
|
1038 |
// Constructor. |
DeviceParamDelegate::DeviceParamDelegate(QObject *parent) : QItemDelegate(parent) { |
|
qsamplerDeviceParamTableEditBox::qsamplerDeviceParamTableEditBox ( |
|
|
QTable *pTable, EditType editType, const QString& sText ) |
|
|
: QTableItem(pTable, editType, sText) |
|
|
{ |
|
1039 |
} |
} |
1040 |
|
|
1041 |
// Virtual implemetations. |
QWidget* DeviceParamDelegate::createEditor(QWidget *parent, |
1042 |
QWidget *qsamplerDeviceParamTableEditBox::createEditor (void) const |
const QStyleOptionViewItem &/* option */, |
1043 |
{ |
const QModelIndex& index) const |
1044 |
QLineEdit *pEditBox = new QLineEdit(QTableItem::table()->viewport()); |
{ |
1045 |
QObject::connect(pEditBox, SIGNAL(returnPressed()), |
if (!index.isValid()) { |
1046 |
QTableItem::table(), SLOT(doValueChanged())); |
return NULL; |
1047 |
pEditBox->setText(QTableItem::text()); |
} |
1048 |
return pEditBox; |
|
1049 |
|
DeviceParameterRow r = index.model()->data(index, Qt::DisplayRole).value<DeviceParameterRow>(); |
1050 |
|
|
1051 |
|
const bool bEnabled = (/*index.model()->bEditable ||*/ !r.param.fix); |
1052 |
|
|
1053 |
|
switch (index.column()) { |
1054 |
|
case 0: |
1055 |
|
return new QLabel(r.name, parent); |
1056 |
|
case 1: { |
1057 |
|
if (r.param.type == LSCP_TYPE_BOOL) { |
1058 |
|
QCheckBox* pCheckBox = new QCheckBox(parent); |
1059 |
|
pCheckBox->setChecked(r.param.value.lower() == "true"); |
1060 |
|
pCheckBox->setEnabled(bEnabled); |
1061 |
|
return pCheckBox; |
1062 |
|
} else if (r.param.possibilities.count() > 0) { |
1063 |
|
QStringList opts = r.param.possibilities; |
1064 |
|
if (r.param.multiplicity) |
1065 |
|
opts.prepend(tr("(none)")); |
1066 |
|
QComboBox* pComboBox = new QComboBox(parent); |
1067 |
|
pComboBox->addItems(opts); |
1068 |
|
if (r.param.value.isEmpty()) |
1069 |
|
pComboBox->setCurrentIndex(0); |
1070 |
|
else |
1071 |
|
pComboBox->setCurrentIndex(pComboBox->findText(r.param.value)); |
1072 |
|
pComboBox->setEnabled(bEnabled); |
1073 |
|
return pComboBox; |
1074 |
|
} else if (r.param.type == LSCP_TYPE_INT |
1075 |
|
&& !r.param.range_min.isEmpty() |
1076 |
|
&& !r.param.range_max.isEmpty()) { |
1077 |
|
QSpinBox* pSpinBox = new QSpinBox(parent); |
1078 |
|
pSpinBox->setValue(r.param.value.toInt()); |
1079 |
|
pSpinBox->setMinimum(r.param.range_min.toInt()); |
1080 |
|
pSpinBox->setMaximum(r.param.range_max.toInt()); |
1081 |
|
pSpinBox->setEnabled(bEnabled); |
1082 |
|
return pSpinBox; |
1083 |
|
} else { |
1084 |
|
QLineEdit* pLineEdit = new QLineEdit(r.param.value, parent); |
1085 |
|
pLineEdit->setEnabled(bEnabled); |
1086 |
|
return pLineEdit; |
1087 |
|
} |
1088 |
|
} |
1089 |
|
case 2: |
1090 |
|
return new QLabel(r.param.description, parent); |
1091 |
|
default: |
1092 |
|
return NULL; |
1093 |
|
} |
1094 |
|
} |
1095 |
|
|
1096 |
|
void DeviceParamDelegate::setEditorData(QWidget* /*editor*/, const QModelIndex& /*index*/) const { |
1097 |
|
// unused, since we set the editor data already in createEditor() |
1098 |
|
} |
1099 |
|
|
1100 |
|
void DeviceParamDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const { |
1101 |
|
if (index.column() == 1) { |
1102 |
|
DeviceParameterRow r = index.model()->data(index, Qt::DisplayRole).value<DeviceParameterRow>(); |
1103 |
|
if (r.param.type == LSCP_TYPE_BOOL) { |
1104 |
|
QCheckBox* pCheckBox = static_cast<QCheckBox*>(editor); |
1105 |
|
model->setData(index, QVariant(pCheckBox->checkState() == Qt::Checked)); |
1106 |
|
} else if (r.param.possibilities.count() > 0) { |
1107 |
|
QComboBox* pComboBox = static_cast<QComboBox*>(editor); |
1108 |
|
model->setData(index, pComboBox->currentText()); |
1109 |
|
} else if (r.param.type == LSCP_TYPE_INT) { |
1110 |
|
QSpinBox* pSpinBox = static_cast<QSpinBox*>(editor); |
1111 |
|
model->setData(index, pSpinBox->value()); |
1112 |
|
} else { |
1113 |
|
QLineEdit* pLineEdit = static_cast<QLineEdit*>(editor); |
1114 |
|
model->setData(index, pLineEdit->text()); |
1115 |
|
} |
1116 |
|
} |
1117 |
} |
} |
1118 |
|
|
1119 |
void qsamplerDeviceParamTableEditBox::setContentFromEditor ( QWidget *pWidget ) |
void DeviceParamDelegate::updateEditorGeometry(QWidget* editor, |
1120 |
|
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
1121 |
{ |
{ |
1122 |
if (pWidget->inherits("QLineEdit")) |
if (editor) editor->setGeometry(option.rect); |
|
QTableItem::setText(((QLineEdit *) pWidget)->text()); |
|
|
else |
|
|
QTableItem::setContentFromEditor(pWidget); |
|
1123 |
} |
} |
1124 |
|
|
|
|
|
1125 |
// end of qsamplerDevice.cpp |
// end of qsamplerDevice.cpp |
|
|
|