/[svn]/qsampler/trunk/src/qsamplerChannel.cpp
ViewVC logotype

Diff of /qsampler/trunk/src/qsamplerChannel.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1461 by schoenebeck, Sun Oct 28 23:30:36 2007 UTC revision 1490 by schoenebeck, Mon Nov 19 04:09:30 2007 UTC
# Line 2  Line 2 
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2007, 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
# Line 35  Line 36 
36    
37  #define QSAMPLER_INSTRUMENT_MAX 100  #define QSAMPLER_INSTRUMENT_MAX 100
38    
39    #define UNICODE_RIGHT_ARROW     QChar(char(0x92), char(0x21))
40    
41  using namespace QSampler;  using namespace QSampler;
42    
43  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
# Line 896  QString qsamplerChannel::loadingInstrume Line 899  QString qsamplerChannel::loadingInstrume
899  }  }
900    
901    
   
902  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
903  // qsamplerChannelRoutingTable - Channel routing table.  // ChannelRoutingModel - data model for audio routing (used for QTableView)
904  //  //
 #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::fromMimeSource("qsamplerChannel.png");  
         QPixmap pmDevice;  
         switch (pDevice->deviceType()) {  
         case qsamplerDevice::Audio:  
                 pmDevice = QPixmap::fromMimeSource("audio2.png");  
                 break;  
         case qsamplerDevice::Midi:  
                 pmDevice = QPixmap::fromMimeSource("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  
905    
906  ChannelRoutingModel::ChannelRoutingModel(QObject* parent) : QAbstractTableModel(parent), pDevice(NULL) {  ChannelRoutingModel::ChannelRoutingModel(QObject* parent) : QAbstractTableModel(parent), pDevice(NULL) {
907  }  }
# Line 1009  int ChannelRoutingModel::columnCount(con Line 914  int ChannelRoutingModel::columnCount(con
914      return 1;      return 1;
915  }  }
916    
917    Qt::ItemFlags ChannelRoutingModel::flags(const QModelIndex& /*index*/) const {
918        return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;
919    }
920    
921    bool ChannelRoutingModel::setData(const QModelIndex& index, const QVariant& value, int /*role*/) {
922        if (!index.isValid()) {
923            return false;
924        }
925    
926        routing[index.row()] = value.toInt();
927    
928        emit dataChanged(index, index);
929        return true;
930    }
931    
932  QVariant ChannelRoutingModel::data(const QModelIndex &index, int role) const {  QVariant ChannelRoutingModel::data(const QModelIndex &index, int role) const {
933      if (!index.isValid())      if (!index.isValid())
934          return QVariant();          return QVariant();
935      if (role != Qt::DisplayRole)      if (role != Qt::DisplayRole)
936          return QVariant();          return QVariant();
937        if (index.column() != 0)
938            return QVariant();
939    
940      ChannelRoutingItem item;      ChannelRoutingItem item;
941    
# Line 1028  QVariant ChannelRoutingModel::data(const Line 950  QVariant ChannelRoutingModel::data(const
950          );          );
951      }      }
952    
953      item.selection = routing[index.column()];      item.selection = routing[index.row()];
954    
955      return QVariant::fromValue(item);      return QVariant::fromValue(item);
956  }  }
# Line 1036  QVariant ChannelRoutingModel::data(const Line 958  QVariant ChannelRoutingModel::data(const
958  QVariant ChannelRoutingModel::headerData(int section, Qt::Orientation orientation, int role) const {  QVariant ChannelRoutingModel::headerData(int section, Qt::Orientation orientation, int role) const {
959      if (role != Qt::DisplayRole) return QVariant();      if (role != Qt::DisplayRole) return QVariant();
960    
961      if (orientation == Qt::Horizontal)      switch (orientation) {
962          return QObject::tr("Device Channel");          case Qt::Horizontal:
963                return UNICODE_RIGHT_ARROW + QObject::tr(" Device Channel");
964      if (orientation == Qt::Vertical)          case Qt::Vertical:
965          return QObject::tr("Sampler Channel Output ") +              return QObject::tr("Sampler Channel ") +
966                 QString(section);                     QString::number(section) + " " + UNICODE_RIGHT_ARROW;
967            default:
968      return QVariant();              return QVariant();
969        }
970  }  }
971    
972  void ChannelRoutingModel::refresh ( qsamplerDevice *pDevice,  void ChannelRoutingModel::refresh ( qsamplerDevice *pDevice,
# Line 1051  void ChannelRoutingModel::refresh ( qsam Line 974  void ChannelRoutingModel::refresh ( qsam
974  {  {
975      this->pDevice = pDevice;      this->pDevice = pDevice;
976      this->routing = routing;      this->routing = routing;
977        // inform the outer world (QTableView) that our data changed
978        QAbstractTableModel::reset();
979  }  }
980    
981    
982    //-------------------------------------------------------------------------
983    // ChannelRoutingDelegate - table cell renderer for audio routing
984    //
985    
986  ChannelRoutingDelegate::ChannelRoutingDelegate(QObject *parent) : QItemDelegate(parent) {  ChannelRoutingDelegate::ChannelRoutingDelegate(QObject *parent) : QItemDelegate(parent) {
987  }  }
988    
989  QWidget* ChannelRoutingDelegate::createEditor(QWidget *parent,  QWidget* ChannelRoutingDelegate::createEditor(QWidget *parent,
990          const QStyleOptionViewItem &/* option */,          const QStyleOptionViewItem & option ,
991          const QModelIndex& index) const          const QModelIndex& index) const
992  {  {
993        if (!index.isValid()) {
994            return NULL;
995        }
996    
997        if (index.column() != 0) {
998            return NULL;
999        }
1000    
1001      ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>();      ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>();
1002    
1003      QComboBox* editor = new QComboBox(parent);      QComboBox* pComboBox = new QComboBox(parent);
1004      editor->addItems(item.options);      pComboBox->addItems(item.options);
1005      editor->setCurrentIndex(item.selection);      pComboBox->setCurrentIndex(item.selection);
1006      editor->installEventFilter(const_cast<ChannelRoutingDelegate*>(this));      pComboBox->setEnabled(true);
1007      return editor;      pComboBox->setGeometry(option.rect);
1008        return pComboBox;
1009  }  }
1010    
1011  void ChannelRoutingDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const {  void ChannelRoutingDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const {
# Line 1078  void ChannelRoutingDelegate::setEditorDa Line 1014  void ChannelRoutingDelegate::setEditorDa
1014      comboBox->setCurrentIndex(item.selection);      comboBox->setCurrentIndex(item.selection);
1015  }  }
1016    
1017  void ChannelRoutingDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const {  void ChannelRoutingDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const {
1018      QComboBox* comboBox = static_cast<QComboBox*>(editor);      QComboBox* comboBox = static_cast<QComboBox*>(editor);
1019      model->setData(index, comboBox->currentIndex());      model->setData(index, comboBox->currentIndex());
1020  }  }
# Line 1089  void ChannelRoutingDelegate::updateEdito Line 1025  void ChannelRoutingDelegate::updateEdito
1025      editor->setGeometry(option.rect);      editor->setGeometry(option.rect);
1026  }  }
1027    
1028    // end of qsamplerChannel.cpp
   
 //-------------------------------------------------------------------------  
 // 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  

Legend:
Removed from v.1461  
changed lines
  Added in v.1490

  ViewVC Help
Powered by ViewVC