void SelectInputChannel::fillTree() { QLCInputChannel* channel; QTreeWidgetItem* uniItem; QTreeWidgetItem* chItem; QLCInputProfile* profile; quint32 uni; InputPatch* patch; /* Add an option to select no input at all */ chItem = new QTreeWidgetItem(m_tree); chItem->setText(KColumnName, KInputNone); chItem->setText(KColumnUniverse, QString("%1") .arg(InputMap::invalidUniverse())); chItem->setText(KColumnChannel, QString("%1") .arg(KInputChannelInvalid)); for (uni = 0; uni < _app->inputMap()->universes(); uni++) { /* Get the patch associated to the current universe */ patch = _app->inputMap()->patch(uni); Q_ASSERT(patch != NULL); /* Make an item for each universe */ uniItem = new QTreeWidgetItem(m_tree); updateUniverseItem(uniItem, uni, patch); if (patch->plugin() != NULL && patch->input() != KInputInvalid) { /* Add a manual option to each patched universe */ chItem = new QTreeWidgetItem(uniItem); updateChannelItem(chItem, uni, NULL, NULL); } /* Add known channels from profile (if any) */ profile = patch->profile(); if (profile != NULL) { QMapIterator <quint32, QLCInputChannel*> it(profile->channels()); while (it.hasNext() == true) { channel = it.next().value(); Q_ASSERT(channel != NULL); chItem = new QTreeWidgetItem(uniItem); updateChannelItem(chItem, uni, channel, profile); } } } /* Listen to item changed signals so that we can catch user's manual input for <...> nodes. Connect AFTER filling the tree so all the initial item->setText()'s won't get caught here. */ connect(m_tree, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(slotItemChanged(QTreeWidgetItem*,int))); }
void QLCFixtureEditor::slotPasteChannel() { QLCChannel* ch = _app->copyChannel(); if (ch != NULL && m_fixtureDef != NULL) { /* Create new mode and an item for it */ QTreeWidgetItem* item; QLCChannel* copy; copy = new QLCChannel(ch); item = new QTreeWidgetItem(m_channelList); int cpIdx = 1; QString copyName; do { copyName = QString("%1 %2").arg(ch->name()).arg(cpIdx); cpIdx++; } while (m_fixtureDef->channel(copyName) != NULL); copy->setName(copyName); m_fixtureDef->addChannel(copy); updateChannelItem(copy, item); m_channelList->setCurrentItem(item); m_channelList->resizeColumnToContents(CH_COL_NAME); setModified(); } }
void InputProfileEditor::slotAddClicked() { QLCInputChannel* channel = new QLCInputChannel(); InputChannelEditor ice(this, m_profile, channel); add: if (ice.exec() == QDialog::Accepted) { channel->setType(ice.type()); channel->setName(ice.name()); if (m_profile->channel(ice.channel()) == NULL) { m_profile->insertChannel(ice.channel(), channel); updateChannelItem(new QTreeWidgetItem(m_tree), channel); } else { QMessageBox::warning(this, tr("Channel already exists"), tr("Channel %1 already exists") .arg(ice.channel() + 1)); goto add; } } else { delete channel; } }
void InputProfileEditor::fillTree() { m_tree->clear(); QMapIterator <quint32,QLCInputChannel*> it(m_profile->channels()); while (it.hasNext() == true) { it.next(); updateChannelItem(new QTreeWidgetItem(m_tree), it.value()); } }
void QLCFixtureEditor::refreshChannelList() { m_channelList->clear(); /* Fill channels list */ QListIterator <QLCChannel*> it(m_fixtureDef->channels()); while (it.hasNext() == true) updateChannelItem(it.next(), new QTreeWidgetItem(m_channelList)); slotChannelListSelectionChanged(m_channelList->currentItem()); m_channelList->resizeColumnToContents(CH_COL_NAME); m_channelList->resizeColumnToContents(CH_COL_GRP); }
void QLCFixtureEditor::slotAddChannel() { EditChannel ec(this); bool ok = false; while (ok == false) { if (ec.exec() == QDialog::Accepted) { if (m_fixtureDef->channel(ec.channel()->name()) != NULL) { QMessageBox::warning(this, tr("Channel already exists"), tr("A channel by the name \"%1\" already exists!") .arg(ec.channel()->name())); ok = false; } else if (ec.channel()->name().length() == 0) { QMessageBox::warning(this, tr("Channel has no name"), tr("You must give the channel a descriptive name!")); ok = false; } else { /* Create a new channel and item for it */ QTreeWidgetItem* item; QLCChannel* ch; ch = new QLCChannel(ec.channel()); item = new QTreeWidgetItem(m_channelList); m_fixtureDef->addChannel(ch); updateChannelItem(ch, item); m_channelList->setCurrentItem(item); m_channelList->resizeColumnToContents(CH_COL_NAME); setModified(); ok = true; } } else { /* Cancel pressed */ ok = true; } } }
void QLCFixtureEditor::slotEditChannel() { QLCChannel* real = NULL; QTreeWidgetItem* item = NULL; // Initialize the dialog with the selected logical channel or // bail out if there is no current selection real = currentChannel(); if (real == NULL) return; EditChannel ec(this, real); if (ec.exec() == QDialog::Accepted) { if (m_fixtureDef->channel(ec.channel()->name()) != NULL && ec.channel()->name() != real->name()) { QMessageBox::warning(this, tr("Channel already exists"), tr("A channel by the name \"%1\" already exists!") .arg(ec.channel()->name())); } else if (ec.channel()->name().length() == 0) { QMessageBox::warning(this, tr("Channel has no name"), tr("You must give the channel a descriptive name!")); } else { // Copy the channel's contents to the real channel *real = *(ec.channel()); item = m_channelList->currentItem(); updateChannelItem(real, item); m_channelList->resizeColumnToContents(CH_COL_NAME); setModified(); } } }
void InputProfileEditor::slotInputValueChanged(quint32 universe, quint32 channel, uchar value, const QString& key) { QTreeWidgetItem* latestItem = NULL; Q_UNUSED(universe); /* Get a list of items that represent the given channel. Basically the list should always contain just one item. */ QList <QTreeWidgetItem*> list; if (channel == UINT_MAX && key.isEmpty() == false) list = m_tree->findItems(key, Qt::MatchExactly, KColumnName); else list = m_tree->findItems(QString("%1").arg(channel + 1), Qt::MatchExactly, KColumnNumber); if (list.size() != 0) latestItem = list.first(); if (list.size() == 0 && m_wizardActive == true) { /* No channel items found. Create a new channel to the profile and display it also in the tree widget */ QLCInputChannel* ch = new QLCInputChannel(); if(key.isEmpty()) ch->setName(tr("Button %1").arg(channel + 1)); else ch->setName(key); ch->setType(QLCInputChannel::Button); m_profile->insertChannel(channel, ch); latestItem = new QTreeWidgetItem(m_tree); updateChannelItem(latestItem, ch); } else if (m_wizardActive == true) { /* Existing channel & item found. Modify their contents. */ latestItem = list.first(); QVariant var = latestItem->data(KColumnValues, Qt::UserRole); QStringList values(var.toStringList()); if (values.size() > 3) { /* No need to collect any more values, since this channel has been judged to be a slider when count == 3 (see below). */ } else if (values.contains(QString("%1").arg(value)) == false) { values << QString("%1").arg(value); values.sort(); latestItem->setData(KColumnValues, Qt::UserRole, values); } /* Change the channel type only the one time when its value count goes over 2. I.e. when a channel can have more than two distinct values, it can no longer be a button. */ if (values.size() == 3) { QLCInputChannel* ch = m_profile->channel(channel); Q_ASSERT(ch != NULL); if (ch->type() == QLCInputChannel::Button) { ch->setType(QLCInputChannel::Slider); if(key.isEmpty()) ch->setName(tr("Slider %1").arg(channel + 1)); else ch->setName(key); updateChannelItem(latestItem, ch); } } } if (latestItem != NULL) { if (m_latestItem != NULL) m_latestItem->setIcon(KColumnNumber, QIcon()); m_latestItem = latestItem; m_latestItem->setIcon(KColumnNumber, QIcon(":/input.png")); m_tree->scrollToItem(m_latestItem); m_timer->start(250); } }
void InputProfileEditor::slotEditClicked() { QLCInputChannel* channel; quint32 chnum; QTreeWidgetItem* item; if (m_tree->selectedItems().count() == 1) { /* Just one item selected. Edit that. */ item = m_tree->currentItem(); if (item == NULL) return; /* Find the channel object associated to the selected item */ chnum = item->text(KColumnNumber).toUInt() - 1; channel = m_profile->channel(chnum); Q_ASSERT(channel != NULL); /* Edit the channel and update its item if necessary */ InputChannelEditor ice(this, m_profile, channel); edit: if (ice.exec() == QDialog::Accepted) { QLCInputChannel* another; another = m_profile->channel(ice.channel()); if (another == NULL || another == channel) { if (ice.channel() != QLCChannel::invalid()) m_profile->remapChannel(channel, ice.channel()); if (ice.name().isEmpty() == false) channel->setName(ice.name()); if (ice.type() != QLCInputChannel::NoType) channel->setType(ice.type()); updateChannelItem(item, channel); } else { QMessageBox::warning(this, tr("Channel already exists"), tr("Channel %1 already exists") .arg(ice.channel() + 1)); goto edit; } } } else if (m_tree->selectedItems().count() > 1) { /* Multiple channels selected. Apply changes to all of them */ InputChannelEditor ice(this, NULL, NULL); if (ice.exec() == QDialog::Accepted) { QListIterator <QTreeWidgetItem*> it(m_tree->selectedItems()); while (it.hasNext() == true) { item = it.next(); Q_ASSERT(item != NULL); chnum = item->text(KColumnNumber).toUInt() - 1; channel = m_profile->channel(chnum); Q_ASSERT(channel != NULL); /* Set only name and type and only if they have been modified. */ if (ice.name().isEmpty() == false) channel->setName(ice.name()); if (ice.type() != QLCInputChannel::NoType) channel->setType(ice.type()); updateChannelItem(item, channel); } } } }