bool RGBMatrixEditor::createPreviewItems() { m_previewHash.clear(); m_scene->clear(); FixtureGroup* grp = m_doc->fixtureGroup(m_matrix->fixtureGroup()); if (grp == NULL) { QGraphicsTextItem* text = new QGraphicsTextItem(tr("No fixture group to control")); text->setDefaultTextColor(Qt::white); m_scene->addItem(text); return false; } m_previewDirection = m_matrix->direction(); if (m_previewDirection == Function::Forward) { m_matrix->setStepColor(m_matrix->startColor()); } else { if (m_matrix->endColor().isValid()) m_matrix->setStepColor(m_matrix->endColor()); else m_matrix->setStepColor(m_matrix->startColor()); } m_matrix->calculateColorDelta(); m_previewMaps = m_matrix->previewMaps(); if ((m_previewDirection == Function::Forward) || m_previewMaps.isEmpty()) { m_previewStep = 0; } else { m_previewStep = m_previewMaps.size() - 1; } RGBMap map; if (m_previewStep < m_previewMaps.size()) map = m_previewMaps[m_previewStep]; if (map.isEmpty()) return false; for (int x = 0; x < grp->size().width(); x++) { for (int y = 0; y < grp->size().height(); y++) { QLCPoint pt(x, y); if (grp->headHash().contains(pt) == true) { RGBItem* item = new RGBItem; item->setRect(x * RECT_SIZE + RECT_PADDING + ITEM_PADDING, y * RECT_SIZE + RECT_PADDING + ITEM_PADDING, ITEM_SIZE - (2 * ITEM_PADDING), ITEM_SIZE - (2 * ITEM_PADDING)); item->setColor(map[y][x]); item->draw(0); m_scene->addItem(item); m_previewHash[pt] = item; } } } return true; }
void RGBMatrixEditor::slotPreviewTimeout() { if (m_matrix == NULL || m_group == NULL || m_matrix->duration() <= 0) return; RGBMap map; m_previewIterator += MasterTimer::tick(); if (m_previewIterator >= m_matrix->duration()) { int stepsCount = m_matrix->stepsCount(); //qDebug() << "previewTimeout. Step:" << m_previewStep; if (m_matrix->runOrder() == RGBMatrix::PingPong) { if (m_previewDirection == Function::Forward && (m_previewStep + 1) == stepsCount) m_previewDirection = Function::Backward; else if (m_previewDirection == Function::Backward && (m_previewStep - 1) < 0) m_previewDirection = Function::Forward; } if (m_previewDirection == Function::Forward) { m_previewStep++; if (m_previewStep >= stepsCount) { m_previewStep = 0; m_matrix->setStepColor(m_matrix->startColor()); } else m_matrix->updateStepColor(m_previewStep); } else { m_previewStep--; if (m_previewStep < 0) { m_previewStep = stepsCount - 1; if (m_matrix->endColor().isValid()) m_matrix->setStepColor(m_matrix->endColor()); else m_matrix->setStepColor(m_matrix->startColor()); } else m_matrix->updateStepColor(m_previewStep); } map = m_matrix->previewMap(m_previewStep); m_previewIterator = 0; /* for (int y = 0; y < map.size(); y++) { for (int x = 0; x < map[y].size(); x++) { QLCPoint pt(x, y); if (m_group->head(pt).isValid()) { if (shape->color() != QColor(map[y][x]).rgb()) shape->setColor(map[y][x]); if (shape->color() == QColor(Qt::black).rgb()) shape->draw(m_matrix->fadeOutSpeed()); else shape->draw(m_matrix->fadeInSpeed()); } } } */ if (m_previewData.isEmpty() || map.isEmpty()) return; QHashIterator<QLCPoint, GroupHead> it(m_group->headHash()); while(it.hasNext()) { it.next(); QLCPoint pt(it.key()); //GroupHead head(it.value()); int ptIdx = pt.x() + (pt.y() * m_group->size().width()); if (ptIdx < m_previewData.size()) m_previewData[ptIdx] = QVariant(QColor(map[pt.y()][pt.x()])); } //qDebug() << "Preview data changed !"; emit previewDataChanged(m_previewData); } }