void EditChannel::refreshCapabilities() { QPtrListIterator<QLCCapability> it(*m_channel->capabilities()); QLCCapability* cap = NULL; QListViewItem* item = NULL; QString str; m_capabilityList->clear(); /* Fill capabilities */ while ( (cap = it.current()) != 0) { ++it; item = new QListViewItem(m_capabilityList); // Min str.sprintf("%.3d", cap->min()); item->setText(KColumnMin, str); // Max str.sprintf("%.3d", cap->max()); item->setText(KColumnMax, str); // Name item->setText(KColumnName, cap->name()); // Store the capability pointer to the listview as a string str.sprintf("%d", (unsigned long) cap); item->setText(KColumnPointer, str); } slotCapabilityListSelectionChanged(m_capabilityList->currentItem()); }
void QLCCapability_Test::initial() { QLCCapability cap; QVERIFY(cap.min() == 0); QVERIFY(cap.max() == UCHAR_MAX); QVERIFY(cap.name().isEmpty()); }
void QLCFixtureEditor::updateChannelItem(const QLCChannel* channel, QTreeWidgetItem* item) { QString str; Q_ASSERT(channel != NULL); Q_ASSERT(item != NULL); item->setText(CH_COL_NAME, channel->name()); item->setIcon(CH_COL_NAME, channel->getIcon()); item->setText(CH_COL_GRP, QLCChannel::groupToString(channel->group())); item->setData(CH_COL_NAME, PROP_PTR, (qulonglong) channel); /* Destroy the existing list of children */ QList <QTreeWidgetItem*> children(item->takeChildren()); foreach (QTreeWidgetItem* child, children) delete child; /* Put all capabilities as non-selectable sub items */ QListIterator <QLCCapability*> capit(channel->capabilities()); while (capit.hasNext() == true) { QLCCapability* cap = capit.next(); Q_ASSERT(cap != NULL); QTreeWidgetItem* capitem = new QTreeWidgetItem(item); capitem->setText(CH_COL_NAME, QString("[%1-%2]: %3").arg(cap->min()) .arg(cap->max()).arg(cap->name())); capitem->setFlags(0); /* No selection etc. */ } }
void QLCCapability_Test::name() { QLCCapability cap; QVERIFY(cap.name().isEmpty()); cap.setName("Foobar"); QVERIFY(cap.name() == "Foobar"); }
bool QLCChannel::loadXML(const QDomElement& root) { if (root.tagName() != KXMLQLCChannel) { qWarning() << "Channel node not found."; return false; } /* Get channel name */ QString str = root.attribute(KXMLQLCChannelName); if (str.isEmpty() == true) return false; setName(str); /* Subtags */ QDomNode node = root.firstChild(); while (node.isNull() == false) { QDomElement tag = node.toElement(); if (tag.tagName() == KXMLQLCCapability) { /* Create a new capability and attempt to load it */ QLCCapability* cap = new QLCCapability(); if (cap->loadXML(tag) == true) { /* Loading succeeded */ if (addCapability(cap) == false) { /* Value overlaps with existing value */ delete cap; } } else { /* Loading failed */ delete cap; } } else if (tag.tagName() == KXMLQLCChannelGroup) { str = tag.attribute(KXMLQLCChannelGroupByte); setControlByte(ControlByte(str.toInt())); setGroup(stringToGroup(tag.text())); } else if (tag.tagName() == KXMLQLCChannelColour) { setColour(stringToColour(tag.text())); } else { qWarning() << Q_FUNC_INFO << "Unknown Channel tag: " << tag.tagName(); } node = node.nextSibling(); } return true; }
void QLCCapability_Test::max() { QLCCapability cap; QVERIFY(cap.max() == UCHAR_MAX); QFETCH(uchar, value); cap.setMax(value); QCOMPARE(cap.max(), value); }
void QLCCapability_Test::min() { QLCCapability cap; QVERIFY(cap.min() == 0); QFETCH(uchar, value); cap.setMin(value); QCOMPARE(cap.min(), value); }
QLCCapability *QLCCapability::createCopy() { QLCCapability *copy = new QLCCapability(m_min, m_max, m_name); copy->setPreset(preset()); for (int i = 0; i < m_resources.count(); i++) copy->setResource(i, m_resources.at(i)); foreach (AliasInfo alias, m_aliases) copy->addAlias(alias); return copy; }
QLCCapability* QLCChannel::searchCapability(QString name) const { QListIterator <QLCCapability*> it(m_capabilities); while (it.hasNext() == true) { QLCCapability* capability = it.next(); if (capability->name() == name) return capability; } return NULL; }
QLCCapability* QLCChannel::searchCapability(uchar value) const { QListIterator <QLCCapability*> it(m_capabilities); while (it.hasNext() == true) { QLCCapability* capability = it.next(); if (capability->min() <= value && capability->max() >= value) return capability; } return NULL; }
QLCCapability* QLCChannel::searchCapability(const QString& name, bool exactMatch) const { QListIterator <QLCCapability*> it(m_capabilities); while (it.hasNext() == true) { QLCCapability* capability = it.next(); if (exactMatch == true && capability->name() == name) return capability; else if (exactMatch == false && capability->name().contains(name) == true) return capability; } return NULL; }
void QLCCapability_Test::save() { QLCCapability cap; cap.setName("Testing"); cap.setMin(5); cap.setMax(87); QDomDocument doc; QDomElement root = doc.createElement("TestRoot"); QVERIFY(cap.saveXML(&doc, &root) == true); QVERIFY(root.firstChild().toElement().tagName() == "Capability"); QVERIFY(root.firstChild().toElement().text() == "Testing"); QVERIFY(root.firstChild().toElement().attribute("Min") == "5"); QVERIFY(root.firstChild().toElement().attribute("Max") == "87"); }
void FixtureManager::slotAutoFunction() { #if 0 QTreeWidgetItem* item; t_fixture_id fxi_id; Fixture* fxi; item = m_tree->currentItem(); if (item == NULL) return; fxi_id = item->text(KColumnID).toInt(); fxi = _app->doc()->fixture(fxi_id); Q_ASSERT(fxi != NULL); // Loop over all channels for (int i = 0; i < fxi->channels(); i++) { QLCChannel* channel = fxi->channel(i); Q_ASSERT(channel != NULL); QListIterator <QLCCapability*> cap_it(*channel->capabilities()); // Loop over all capabilities while (cap_it.hasNext() == true) { QLCCapability* cap = cap_it.next(); Q_ASSERT(cap != NULL); Scene* sc = static_cast<Scene*> (_app->doc()->newFunction(Function::Scene, fxi_id)); sc->setName(channel->name() + " - " + cap->name()); // Set the unused channels to NoSet and zero. for (int j = 0; j < fxi->channels(); j++) sc->set(j, 0, Scene::NoSet); // Set only the capability sc->set(i, (t_value) ((cap->min() + cap->max()) / 2), Scene::Set); } } #endif }
void QLCCapability_Test::loadNoMax() { QDomDocument doc; QDomElement root = doc.createElement("Capability"); doc.appendChild(root); root.setAttribute("Min", 13); QDomText name = doc.createTextNode("Test1"); root.appendChild(name); QLCCapability cap; QVERIFY(cap.loadXML(root) == false); QVERIFY(cap.name().isEmpty()); QVERIFY(cap.min() == 0); QVERIFY(cap.max() == UCHAR_MAX); }
void QLCCapability_Test::load() { QDomDocument doc; QDomElement root = doc.createElement("Capability"); doc.appendChild(root); root.setAttribute("Min", 13); root.setAttribute("Max", 19); QDomText name = doc.createTextNode("Test1"); root.appendChild(name); QLCCapability cap; QVERIFY(cap.loadXML(root) == true); QVERIFY(cap.name() == "Test1"); QVERIFY(cap.min() == 13); QVERIFY(cap.max() == 19); }
void QLCCapability_Test::middle() { QLCCapability cap; QVERIFY(cap.max() == UCHAR_MAX); QCOMPARE(cap.middle(), uchar(127)); cap.setMin(100); cap.setMax(200); QCOMPARE(cap.middle(), uchar(150)); }
void EditChannel::refreshCapabilities() { QListIterator <QLCCapability*> it(*m_channel->capabilities()); QLCCapability* cap = NULL; QTreeWidgetItem* item = NULL; QString str; m_capabilityList->clear(); /* Fill capabilities */ while (it.hasNext() == true) { cap = it.next(); item = new QTreeWidgetItem(m_capabilityList); // Min str.sprintf("%.3d", cap->min()); item->setText(KColumnMin, str); // Max str.sprintf("%.3d", cap->max()); item->setText(KColumnMax, str); // Name item->setText(KColumnName, cap->name()); // Store the capability pointer to the listview as a string str.sprintf("%lu", (unsigned long) cap); item->setText(KColumnPointer, str); } m_capabilityList->sortItems(KColumnMin, Qt::AscendingOrder); slotCapabilityListSelectionChanged(m_capabilityList->currentItem()); }
void CapabilityWizard::slotCreateCapabilities() { int start = m_startSpin->value(); int gap = m_gapSpin->value(); int amount = m_amountSpin->value(); QString name = m_nameEdit->text(); t_value min = start; t_value max = min + gap; QLCCapability* cap; /* Destroy existing capabilities */ foreach (QLCCapability* cap, m_caps) delete cap; m_caps.clear(); /* Create new capabilities */ for (int i = 0; i < amount; i++) { /* Create a name with the optional hash mark */ QString modname(name); modname.replace("#", QString("%1").arg(i + 1)); /* Create a new capability and add it to our list */ cap = new QLCCapability(min, max, modname); m_caps << cap; /* Bail out when the maximum DMX value has been reached */ if (max == 255) break; /* Increment for the next round */ min = max + 1; max = min + gap; /* Bail out if next round would overflow */ if (max < min) break; } /* Replace capabilities in the list widget */ m_list->clear(); foreach (cap, m_caps) { QListWidgetItem* item; item = new QListWidgetItem(m_list); item->setText(QString("[%1 - %2] %3").arg(cap->min()) .arg(cap->max()).arg(cap->name())); if (m_channel->searchCapability(cap->min()) != NULL || m_channel->searchCapability(cap->max()) != NULL) { /* Disable the item to indicate overlapping */ item->setFlags(0); } }
bool QLCCapability::overlaps(const QLCCapability& cap) { if (m_min >= cap.min() && m_min <= cap.max()) return true; else if (m_max >= cap.min() && m_max <= cap.max()) return true; else if (m_min <= cap.min() && m_max >= cap.min()) return true; else return false; }
bool QLCChannel::addCapability(QLCCapability* cap) { QListIterator <QLCCapability*> it(m_capabilities); QLCCapability* temp = NULL; Q_ASSERT(cap != NULL); /* Check for overlapping values */ while (it.hasNext() == true) { temp = it.next(); if ((temp->min() <= cap->min() && temp->max() > cap->min()) || (temp->min() < cap->max() && temp->max() >= cap->max()) || (temp->min() >= cap->min() && temp->max() <= cap->max())) { return false; } } m_capabilities.append(cap); return true; }
void MainView2D::updateFixtureItem(Fixture *fixture, quint16 headIndex, quint16 linkedIndex, QByteArray &previous) { quint32 itemID = FixtureUtils::fixtureItemID(fixture->id(), headIndex, linkedIndex); QQuickItem *fxItem = m_itemsMap.value(itemID, NULL); bool colorSet = false; bool goboSet = false; bool setPosition = false; int panDegrees = 0; int tiltDegrees = 0; if (fxItem == NULL) return; // in case of a dimmer pack, headIndex is actually the fixture channel // so treat this as a special case and go straight to the point if (fixture->type() == QLCFixtureDef::Dimmer) { qreal value = (qreal)fixture->channelValueAt(headIndex) / 255.0; QMetaObject::invokeMethod(fxItem, "setHeadIntensity", Q_ARG(QVariant, 0), Q_ARG(QVariant, value)); QColor gelColor = m_monProps->fixtureGelColor(fixture->id(), headIndex, linkedIndex); if (gelColor.isValid() == false) gelColor = Qt::white; QMetaObject::invokeMethod(fxItem, "setHeadRGBColor", Q_ARG(QVariant, 0), Q_ARG(QVariant, gelColor)); return; } for (int headIdx = 0; headIdx < fixture->heads(); headIdx++) { quint32 headDimmerIndex = fixture->channelNumber(QLCChannel::Intensity, QLCChannel::MSB, headIdx); //qDebug() << "Head" << headIdx << "dimmer channel:" << mdIndex; qreal intValue = 1.0; if (headDimmerIndex != QLCChannel::invalid()) intValue = (qreal)fixture->channelValueAt(headDimmerIndex) / 255; QMetaObject::invokeMethod(fxItem, "setHeadIntensity", Q_ARG(QVariant, headIdx), Q_ARG(QVariant, intValue)); QMetaObject::invokeMethod(fxItem, "setHeadRGBColor", Q_ARG(QVariant, headIdx), Q_ARG(QVariant, FixtureUtils::headColor(fixture, headIdx))); colorSet = true; } // for heads // now scan all the channels for "common" capabilities for (quint32 i = 0; i < fixture->channels(); i++) { const QLCChannel *ch = fixture->channel(i); if (ch == NULL) continue; uchar value = fixture->channelValueAt(i); switch (ch->group()) { case QLCChannel::Pan: { if (ch->controlByte() == QLCChannel::MSB) panDegrees += (value << 8); else panDegrees += (value); setPosition = true; } break; case QLCChannel::Tilt: { if (ch->controlByte() == QLCChannel::MSB) tiltDegrees += (value << 8); else tiltDegrees += (value); setPosition = true; } break; case QLCChannel::Colour: { if (colorSet && value == 0) break; QLCCapability *cap = ch->searchCapability(value); if (cap == NULL || (cap->presetType() != QLCCapability::SingleColor && cap->presetType() != QLCCapability::DoubleColor)) break; QColor wheelColor1 = cap->resource(0).value<QColor>(); QColor wheelColor2 = cap->resource(1).value<QColor>(); if (wheelColor1.isValid()) { if (wheelColor2.isValid()) { QMetaObject::invokeMethod(fxItem, "setWheelColor", Q_ARG(QVariant, 0), Q_ARG(QVariant, wheelColor1), Q_ARG(QVariant, wheelColor2)); } else { QMetaObject::invokeMethod(fxItem, "setHeadRGBColor", Q_ARG(QVariant, 0), Q_ARG(QVariant, wheelColor1)); } colorSet = true; } } break; case QLCChannel::Gobo: { if (goboSet || (previous.count() && value == previous.at(i))) break; QLCCapability *cap = ch->searchCapability(value); if (cap == NULL) break; if (cap->preset() == QLCCapability::GoboMacro) { QString resName = cap->resource(0).toString(); if (resName.isEmpty() == false && resName.endsWith("open.svg") == false) { QMetaObject::invokeMethod(fxItem, "setGoboPicture", Q_ARG(QVariant, 0), Q_ARG(QVariant, resName)); // here we don't look for any other gobos, so if a // fixture has more than one gobo wheel, the second // one will be skipped if the first one has been set // to a non-open gobo goboSet = true; } } } break; case QLCChannel::Shutter: { if (previous.count() && value == previous.at(i)) break; int high = 200, low = 800; int capPreset = FixtureUtils::shutterTimings(ch, value, high, low); if (capPreset != QLCCapability::Custom) { QMetaObject::invokeMethod(fxItem, "setShutter", Q_ARG(QVariant, capPreset), Q_ARG(QVariant, low), Q_ARG(QVariant, high)); } } break; default: break; } } if (setPosition) { QMetaObject::invokeMethod(fxItem, "setPosition", Q_ARG(QVariant, panDegrees), Q_ARG(QVariant, tiltDegrees)); } }
bool QLCChannel::loadXML(const QDomElement* root) { QDomNode node; QDomElement tag; QString str; Q_ASSERT(root != NULL); if (root->tagName() != KXMLQLCChannel) { qWarning() << "Channel node not found."; return false; } /* Get channel name */ str = root->attribute(KXMLQLCChannelName); if (str == QString::null) return false; else setName(str); /* Subtags */ node = root->firstChild(); while (node.isNull() == false) { tag = node.toElement(); if (tag.tagName() == KXMLQLCCapability) { /* Create a new capability and attempt to load it */ QLCCapability* cap = new QLCCapability(); if (cap->loadXML(&tag) == true) { /* Loading succeeded */ if (addCapability(cap) == false) { /* Value overlaps with existing value */ delete cap; } } else { /* Loading failed */ delete cap; } } else if (tag.tagName() == KXMLQLCChannelGroup) { str = tag.attribute(KXMLQLCChannelGroupByte); setControlByte(str.toInt()); setGroup(tag.text()); } else { qDebug() << "Unknown Channel tag: " << tag.tagName(); } node = node.nextSibling(); } return true; }
void ConsoleChannel::initCapabilityMenu(const QLCChannel* ch) { QLCCapability* cap; QMenu* valueMenu; QAction* action; QString s; QString t; QListIterator <QLCCapability*> it(ch->capabilities()); while (it.hasNext() == true) { cap = it.next(); // Set the value range and name as the menu item's name s = QString("%1: %2 - %3").arg(cap->name()) .arg(cap->min()).arg(cap->max()); if (cap->max() - cap->min() > 0) { // Create submenu for ranges of more than one value valueMenu = new QMenu(m_menu); valueMenu->setTitle(s); /* Add a color icon */ if (ch->group() == QLCChannel::Colour) valueMenu->setIcon(colorIcon(cap->name())); for (int i = cap->min(); i <= cap->max(); i++) { action = valueMenu->addAction( t.sprintf("%.3d", i)); action->setData(i); } m_menu->addMenu(valueMenu); } else { // Just one value in this range, put that into the menu action = m_menu->addAction(s); action->setData(cap->min()); /* Add a color icon */ if (ch->group() == QLCChannel::Colour) action->setIcon(colorIcon(cap->name())); } } // Connect menu item activation signal to this connect(m_menu, SIGNAL(triggered(QAction*)), this, SLOT(slotContextMenuTriggered(QAction*))); // Set the menu also as the preset button's popup menu m_presetButton->setMenu(m_menu); }