897 |
} |
} |
898 |
|
|
899 |
|
|
|
|
|
900 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
901 |
// qsamplerChannelRoutingTable - Channel routing table. |
// ChannelRoutingModel - data model for audio routing (used for QTableView) |
902 |
// |
// |
|
#if 0 |
|
|
// Constructor. |
|
|
qsamplerChannelRoutingTable::qsamplerChannelRoutingTable ( |
|
|
QWidget *pParent, const char *pszName ) |
|
|
: QTable(pParent, pszName) |
|
|
{ |
|
|
// Set fixed number of columns. |
|
|
QTable::setNumCols(2); |
|
|
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("Sampler Channel")); |
|
|
pHeader->setLabel(1, tr("Device Channel")); |
|
|
// Set read-onlyness of each column |
|
|
QTable::setColumnReadOnly(0, true); |
|
|
// QTable::setColumnReadOnly(1, false); -- of course not. |
|
|
QTable::setColumnStretchable(1, true); |
|
|
} |
|
|
|
|
|
// Default destructor. |
|
|
qsamplerChannelRoutingTable::~qsamplerChannelRoutingTable (void) |
|
|
{ |
|
|
} |
|
|
|
|
|
|
|
|
// Routing map table renderer. |
|
|
void qsamplerChannelRoutingTable::refresh ( qsamplerDevice *pDevice, |
|
|
const qsamplerChannelRoutingMap& routing ) |
|
|
{ |
|
|
if (pDevice == NULL) |
|
|
return; |
|
|
|
|
|
// Always (re)start it empty. |
|
|
QTable::setUpdatesEnabled(false); |
|
|
QTable::setNumRows(0); |
|
|
|
|
|
// The common device port item list. |
|
|
QStringList opts; |
|
|
qsamplerDevicePortList& ports = pDevice->ports(); |
|
|
qsamplerDevicePort *pPort; |
|
|
for (pPort = ports.first(); pPort; pPort = ports.next()) { |
|
|
opts.append(pDevice->deviceTypeName() |
|
|
+ ' ' + pDevice->driverName() |
|
|
+ ' ' + pPort->portName()); |
|
|
} |
|
|
|
|
|
// Those items shall have a proper pixmap... |
|
|
QPixmap pmChannel = QPixmap(":/icons/qsamplerChannel.png"); |
|
|
QPixmap pmDevice; |
|
|
switch (pDevice->deviceType()) { |
|
|
case qsamplerDevice::Audio: |
|
|
pmDevice = QPixmap(":/icons/audio2.png"); |
|
|
break; |
|
|
case qsamplerDevice::Midi: |
|
|
pmDevice = QPixmap(":/icons/midi2.png"); |
|
|
break; |
|
|
case qsamplerDevice::None: |
|
|
break; |
|
|
} |
|
|
|
|
|
// Fill the routing table... |
|
|
QTable::insertRows(0, routing.count()); |
|
|
int iRow = 0; |
|
|
qsamplerChannelRoutingMap::ConstIterator iter; |
|
|
for (iter = routing.begin(); iter != routing.end(); ++iter) { |
|
|
QTable::setPixmap(iRow, 0, pmChannel); |
|
|
QTable::setText(iRow, 0, pDevice->deviceTypeName() |
|
|
+ ' ' + QString::number(iter.key())); |
|
|
qsamplerChannelRoutingComboBox *pComboItem = |
|
|
new qsamplerChannelRoutingComboBox(this, opts, pmDevice); |
|
|
pComboItem->setCurrentItem(iter.data()); |
|
|
QTable::setItem(iRow, 1, pComboItem); |
|
|
++iRow; |
|
|
} |
|
|
|
|
|
// Adjust optimal column widths. |
|
|
QTable::adjustColumn(0); |
|
|
QTable::adjustColumn(1); |
|
|
|
|
|
QTable::setUpdatesEnabled(true); |
|
|
QTable::updateContents(); |
|
|
} |
|
|
|
|
|
|
|
|
// Commit any pending editing. |
|
|
void qsamplerChannelRoutingTable::flush (void) |
|
|
{ |
|
|
if (QTable::isEditing()) |
|
|
QTable::endEdit(QTable::currEditRow(), QTable::currEditCol(), true, true); |
|
|
} |
|
|
#endif |
|
903 |
|
|
904 |
ChannelRoutingModel::ChannelRoutingModel(QObject* parent) : QAbstractTableModel(parent), pDevice(NULL) { |
ChannelRoutingModel::ChannelRoutingModel(QObject* parent) : QAbstractTableModel(parent), pDevice(NULL) { |
905 |
} |
} |
912 |
return 1; |
return 1; |
913 |
} |
} |
914 |
|
|
915 |
|
Qt::ItemFlags ChannelRoutingModel::flags(const QModelIndex& /*index*/) const { |
916 |
|
return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled; |
917 |
|
} |
918 |
|
|
919 |
|
bool ChannelRoutingModel::setData(const QModelIndex& index, const QVariant& value, int /*role*/) { |
920 |
|
if (!index.isValid()) { |
921 |
|
return false; |
922 |
|
} |
923 |
|
|
924 |
|
routing[index.row()] = value.toInt(); |
925 |
|
|
926 |
|
emit dataChanged(index, index); |
927 |
|
return true; |
928 |
|
} |
929 |
|
|
930 |
QVariant ChannelRoutingModel::data(const QModelIndex &index, int role) const { |
QVariant ChannelRoutingModel::data(const QModelIndex &index, int role) const { |
931 |
if (!index.isValid()) |
if (!index.isValid()) |
932 |
return QVariant(); |
return QVariant(); |
933 |
if (role != Qt::DisplayRole) |
if (role != Qt::DisplayRole) |
934 |
return QVariant(); |
return QVariant(); |
935 |
|
if (index.column() != 0) |
936 |
|
return QVariant(); |
937 |
|
|
938 |
ChannelRoutingItem item; |
ChannelRoutingItem item; |
939 |
|
|
948 |
); |
); |
949 |
} |
} |
950 |
|
|
951 |
item.selection = routing[index.column()]; |
item.selection = routing[index.row()]; |
952 |
|
|
953 |
return QVariant::fromValue(item); |
return QVariant::fromValue(item); |
954 |
} |
} |
956 |
QVariant ChannelRoutingModel::headerData(int section, Qt::Orientation orientation, int role) const { |
QVariant ChannelRoutingModel::headerData(int section, Qt::Orientation orientation, int role) const { |
957 |
if (role != Qt::DisplayRole) return QVariant(); |
if (role != Qt::DisplayRole) return QVariant(); |
958 |
|
|
959 |
if (orientation == Qt::Horizontal) |
switch (orientation) { |
960 |
return QObject::tr("Device Channel"); |
case Qt::Horizontal: |
961 |
|
return QObject::tr("-> Device Channel"); |
962 |
if (orientation == Qt::Vertical) |
case Qt::Vertical: |
963 |
return QObject::tr("Sampler Channel Output ") + |
return QObject::tr("Sampler Channel ") + |
964 |
QString(section); |
QString::number(section) + " ->"; |
965 |
|
default: |
966 |
return QVariant(); |
return QVariant(); |
967 |
|
} |
968 |
} |
} |
969 |
|
|
970 |
void ChannelRoutingModel::refresh ( qsamplerDevice *pDevice, |
void ChannelRoutingModel::refresh ( qsamplerDevice *pDevice, |
972 |
{ |
{ |
973 |
this->pDevice = pDevice; |
this->pDevice = pDevice; |
974 |
this->routing = routing; |
this->routing = routing; |
975 |
|
// inform the outer world (QTableView) that our data changed |
976 |
|
QAbstractTableModel::reset(); |
977 |
} |
} |
978 |
|
|
979 |
|
|
980 |
|
//------------------------------------------------------------------------- |
981 |
|
// ChannelRoutingDelegate - table cell renderer for audio routing |
982 |
|
// |
983 |
|
|
984 |
ChannelRoutingDelegate::ChannelRoutingDelegate(QObject *parent) : QItemDelegate(parent) { |
ChannelRoutingDelegate::ChannelRoutingDelegate(QObject *parent) : QItemDelegate(parent) { |
985 |
} |
} |
986 |
|
|
987 |
QWidget* ChannelRoutingDelegate::createEditor(QWidget *parent, |
QWidget* ChannelRoutingDelegate::createEditor(QWidget *parent, |
988 |
const QStyleOptionViewItem &/* option */, |
const QStyleOptionViewItem & option , |
989 |
const QModelIndex& index) const |
const QModelIndex& index) const |
990 |
{ |
{ |
991 |
|
if (!index.isValid()) { |
992 |
|
return NULL; |
993 |
|
} |
994 |
|
|
995 |
|
if (index.column() != 0) { |
996 |
|
return NULL; |
997 |
|
} |
998 |
|
|
999 |
ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>(); |
ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>(); |
1000 |
|
|
1001 |
QComboBox* editor = new QComboBox(parent); |
QComboBox* pComboBox = new QComboBox(parent); |
1002 |
editor->addItems(item.options); |
pComboBox->addItems(item.options); |
1003 |
editor->setCurrentIndex(item.selection); |
pComboBox->setCurrentIndex(item.selection); |
1004 |
editor->installEventFilter(const_cast<ChannelRoutingDelegate*>(this)); |
pComboBox->setEnabled(true); |
1005 |
return editor; |
pComboBox->setGeometry(option.rect); |
1006 |
|
return pComboBox; |
1007 |
} |
} |
1008 |
|
|
1009 |
void ChannelRoutingDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { |
void ChannelRoutingDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { |
1012 |
comboBox->setCurrentIndex(item.selection); |
comboBox->setCurrentIndex(item.selection); |
1013 |
} |
} |
1014 |
|
|
1015 |
void ChannelRoutingDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { |
void ChannelRoutingDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const { |
1016 |
QComboBox* comboBox = static_cast<QComboBox*>(editor); |
QComboBox* comboBox = static_cast<QComboBox*>(editor); |
1017 |
model->setData(index, comboBox->currentIndex()); |
model->setData(index, comboBox->currentIndex()); |
1018 |
} |
} |
1023 |
editor->setGeometry(option.rect); |
editor->setGeometry(option.rect); |
1024 |
} |
} |
1025 |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------- |
|
|
// qsamplerChannelRoutingComboBox - Custom combo box for routing table. |
|
|
// |
|
|
|
|
|
#if 0 |
|
|
// Constructor. |
|
|
qsamplerChannelRoutingComboBox::qsamplerChannelRoutingComboBox ( |
|
|
QTable *pTable, const QStringList& list, const QPixmap& pixmap ) |
|
|
: QTableItem(pTable, QTableItem::WhenCurrent, QString::null, pixmap), |
|
|
m_list(list) |
|
|
{ |
|
|
m_iCurrentItem = 0; |
|
|
} |
|
|
|
|
|
// Public accessors. |
|
|
void qsamplerChannelRoutingComboBox::setCurrentItem ( int iCurrentItem ) |
|
|
{ |
|
|
m_iCurrentItem = iCurrentItem; |
|
|
|
|
|
QTableItem::setText(m_list[iCurrentItem]); |
|
|
} |
|
|
|
|
|
int qsamplerChannelRoutingComboBox::currentItem (void) const |
|
|
{ |
|
|
return m_iCurrentItem; |
|
|
} |
|
|
|
|
|
// Virtual implemetations. |
|
|
QWidget *qsamplerChannelRoutingComboBox::createEditor (void) const |
|
|
{ |
|
|
QComboBox *pComboBox = new QComboBox(QTableItem::table()->viewport()); |
|
|
QObject::connect(pComboBox, SIGNAL(activated(int)), |
|
|
QTableItem::table(), SLOT(doValueChanged())); |
|
|
for (QStringList::ConstIterator iter = m_list.begin(); |
|
|
iter != m_list.end(); iter++) { |
|
|
pComboBox->insertItem(QTableItem::pixmap(), *iter); |
|
|
} |
|
|
pComboBox->setCurrentItem(m_iCurrentItem); |
|
|
return pComboBox; |
|
|
} |
|
|
|
|
|
void qsamplerChannelRoutingComboBox::setContentFromEditor ( QWidget *pWidget ) |
|
|
{ |
|
|
if (pWidget->inherits("QComboBox")) { |
|
|
QComboBox *pComboBox = (QComboBox *) pWidget; |
|
|
m_iCurrentItem = pComboBox->currentItem(); |
|
|
QTableItem::setText(pComboBox->currentText()); |
|
|
} |
|
|
else QTableItem::setContentFromEditor(pWidget); |
|
|
} |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
1026 |
// end of qsamplerChannel.cpp |
// end of qsamplerChannel.cpp |