Skip to content

Commit

Permalink
qmlui: add channel and capability wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
mcallegari committed Jan 17, 2023
1 parent df0961f commit ff78f16
Show file tree
Hide file tree
Showing 9 changed files with 438 additions and 11 deletions.
42 changes: 41 additions & 1 deletion qmlui/fixtureeditor/channeledit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
limitations under the License.
*/

#include <QQmlEngine>

#include "qlcfixturedef.h"
#include "qlccapability.h"

Expand All @@ -29,6 +31,7 @@ ChannelEdit::ChannelEdit(QLCChannel *channel, QObject *parent)
if (m_channel->capabilities().count() == 0)
{
QLCCapability *cap = new QLCCapability(0, UCHAR_MAX);
QQmlEngine::setObjectOwnership(cap, QQmlEngine::CppOwnership);
cap->setWarning(QLCCapability::EmptyName);
m_channel->addCapability(cap);
}
Expand Down Expand Up @@ -199,7 +202,7 @@ QVariantList ChannelEdit::capabilities() const
return m_capabilities;
}

QLCCapability *ChannelEdit::addCapability()
QLCCapability *ChannelEdit::addNewCapability()
{
int min = 0;
if (m_channel->capabilities().count())
Expand All @@ -208,13 +211,50 @@ QLCCapability *ChannelEdit::addCapability()
min = last->max() + 1;
}
QLCCapability *cap = new QLCCapability(min, UCHAR_MAX);
QQmlEngine::setObjectOwnership(cap, QQmlEngine::CppOwnership);
cap->setWarning(QLCCapability::EmptyName);
if (m_channel->addCapability(cap))
{
updateCapabilities();
}
else
{
delete cap;
return nullptr;
}

return cap;
}

QLCCapability *ChannelEdit::addCapability(int min, int max, QString name)
{
QLCCapability *cap = new QLCCapability(min, max);
QQmlEngine::setObjectOwnership(cap, QQmlEngine::CppOwnership);
cap->setName(name);
if (m_channel->addCapability(cap))
{
updateCapabilities();
}
else
{
delete cap;
return nullptr;
}

return cap;
}

void ChannelEdit::removeCapabilityAtIndex(int index)
{
QList<QLCCapability *> caps = m_channel->capabilities();

if (index < 0 || index >= caps.count())
return;

if (m_channel->removeCapability(caps[index]))
updateCapabilities();
}

int ChannelEdit::getCapabilityPresetAtIndex(int index)
{
QList<QLCCapability *> caps = m_channel->capabilities();
Expand Down
7 changes: 6 additions & 1 deletion qmlui/fixtureeditor/channeledit.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ class ChannelEdit : public QObject
/** Get the list of capabilities for the channel being edited */
QVariantList capabilities() const;

Q_INVOKABLE QLCCapability *addCapability();
/** Methods to add a new capability */
Q_INVOKABLE QLCCapability *addNewCapability();
Q_INVOKABLE QLCCapability *addCapability(int min, int max, QString name);

/** Delete the capability at the given index */
Q_INVOKABLE void removeCapabilityAtIndex(int index);

/** Get/Set a preset for a capability at the given index */
Q_INVOKABLE int getCapabilityPresetAtIndex(int index);
Expand Down
77 changes: 75 additions & 2 deletions qmlui/fixtureeditor/editorview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
limitations under the License.
*/

#include <QQmlEngine>

#include "qlcfixturemode.h"
#include "qlcfixturedef.h"
#include "qlcchannel.h"

#include "channeledit.h"
#include "editorview.h"
Expand Down Expand Up @@ -181,6 +182,7 @@ ChannelEdit *EditorView::requestChannelEditor(QString name)
if (ch == nullptr)
{
ch = new QLCChannel();
QQmlEngine::setObjectOwnership(ch, QQmlEngine::CppOwnership);
ch->setName(tr("New channel %1").arg(m_fixtureDef->channels().count() + 1));
m_fixtureDef->addChannel(ch);
updateChannelList();
Expand All @@ -191,11 +193,82 @@ ChannelEdit *EditorView::requestChannelEditor(QString name)
return m_channelEdit;
}

void EditorView::addPresetChannel(QString name, int group)
{
QLCChannel *channel = new QLCChannel();
channel->setName(name);
if (group > QLCChannel::Nothing)
{
channel->setGroup(QLCChannel::Intensity);
channel->setColour(QLCChannel::PrimaryColour(group));

switch (QLCChannel::PrimaryColour(group))
{
case QLCChannel::Red:
channel->setPreset(QLCChannel::IntensityRed);
break;
case QLCChannel::Green:
channel->setPreset(QLCChannel::IntensityGreen);
break;
case QLCChannel::Blue:
channel->setPreset(QLCChannel::IntensityBlue);
break;
case QLCChannel::White:
channel->setPreset(QLCChannel::IntensityWhite);
break;
case QLCChannel::Amber:
channel->setPreset(QLCChannel::IntensityAmber);
break;
case QLCChannel::UV:
channel->setPreset(QLCChannel::IntensityUV);
break;
default:
break;
}
}
else
{
channel->setGroup(QLCChannel::Group(group));

switch (QLCChannel::Group(group))
{
case QLCChannel::Intensity:
channel->setPreset(QLCChannel::IntensityDimmer);
break;
case QLCChannel::Pan:
channel->setPreset(QLCChannel::PositionPan);
break;
case QLCChannel::Tilt:
channel->setPreset(QLCChannel::PositionTilt);
break;
case QLCChannel::Colour:
channel->setPreset(QLCChannel::ColorMacro);
break;
case QLCChannel::Shutter:
channel->setPreset(QLCChannel::ShutterStrobeSlowFast);
break;
case QLCChannel::Beam:
channel->setPreset(QLCChannel::NoFunction);
break;
case QLCChannel::Effect:
channel->setPreset(QLCChannel::NoFunction);
break;
default:
break;
}
}
channel->addPresetCapability();
m_fixtureDef->addChannel(channel);
updateChannelList();
setModified(true);
}

bool EditorView::deleteChannel(QLCChannel *channel)
{
// TODO: Tardis
bool res = m_fixtureDef->removeChannel(channel);
updateChannelList();
setModified(true);
return res;
}

Expand Down Expand Up @@ -250,7 +323,7 @@ void EditorView::updateModeList()

void EditorView::modeNameChanged()
{
setModified();
setModified(true);
updateModeList();
}

Expand Down
12 changes: 11 additions & 1 deletion qmlui/fixtureeditor/editorview.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
#include <QQuickView>

#include "physicaledit.h"
#include "qlcchannel.h"

class QLCFixtureDef;
class ChannelEdit;
class QLCChannel;
class ListModel;
class ModeEdit;

Expand Down Expand Up @@ -99,13 +99,23 @@ class EditorView : public QObject
* Channels
************************************************************************/
public:
enum CompositeChannelTypes
{
RGBChannel = QLCChannel::Nothing + 100,
RGBWChannel,
RGBAWChannel
};
Q_ENUM(CompositeChannelTypes)

/** Get a list of all the available channels in the definition */
QVariant channels() const;

/** Request a channel editor.
* If $name is empty, a new channel is added */
Q_INVOKABLE ChannelEdit *requestChannelEditor(QString name);

Q_INVOKABLE void addPresetChannel(QString name, int group);

/** Delete the given $channel from the definition */
Q_INVOKABLE bool deleteChannel(QLCChannel *channel);

Expand Down
31 changes: 25 additions & 6 deletions qmlui/qml/fixtureeditor/ChannelEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,25 @@ GridLayout
id: removeCapButton
imgSource: "qrc:/remove.svg"
tooltip: qsTr("Delete the selected capabilities")
onClicked: {
editItem.visible = false
editor.removeCapabilityAtIndex(editItem.indexInList)
}
}

IconButton
{
id: chWizButton
imgSource: "qrc:/wizard.svg"
tooltip: qsTr("Capability wizard")
onClicked: wizardPopup.open()

PopupChannelWizard
{
id: wizardPopup
chEdit: editor
capabilityWizard: true
}
}
}

Expand Down Expand Up @@ -220,7 +239,7 @@ GridLayout
else if (index === capsList.count)
{
// create a new capability
editor.addCapability()
editor.addNewCapability()
}

var item = capsList.itemAtIndex(index)
Expand Down Expand Up @@ -316,7 +335,7 @@ GridLayout
id: minValBox
width: UISettings.bigItemHeight
height: UISettings.listItemHeight
label: cap.min
label: cap ? cap.min : 0
}
Rectangle { width: 1; height: UISettings.listItemHeight; color: UISettings.fgMedium }

Expand All @@ -325,7 +344,7 @@ GridLayout
id: maxValBox
width: UISettings.bigItemHeight
height: UISettings.listItemHeight
label: cap.max
label: cap ? cap.max : 255
}
Rectangle { width: 1; height: UISettings.listItemHeight; color: UISettings.fgMedium }

Expand All @@ -334,18 +353,18 @@ GridLayout
id: capDescription
Layout.fillWidth: true
height: UISettings.listItemHeight
label: cap.name
label: cap ? cap.name : ""
}

IconButton
{
visible: cap.warning
visible: cap ? cap.warning : false
height: UISettings.listItemHeight
width: height
border.width: 0
faSource: FontAwesome.fa_warning
faColor: "yellow"
tooltip: capsList.warningDescription(cap.warning)
tooltip: visible ? capsList.warningDescription(cap.warning) : ""
}
}

Expand Down
14 changes: 14 additions & 0 deletions qmlui/qml/fixtureeditor/EditorView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,20 @@ Rectangle
Layout.fillWidth: true
color: "transparent"
}

IconButton
{
id: chWizButton
imgSource: "qrc:/wizard.svg"
tooltip: qsTr("Channel wizard")
onClicked: wizardPopup.open()

PopupChannelWizard
{
id: wizardPopup
editorView: editorRoot.editorView
}
}
}
} // Rectangle - toolbar

Expand Down
Loading

0 comments on commit ff78f16

Please sign in to comment.