Skip to content

Commit

Permalink
qmlui: more work on fixture editor
Browse files Browse the repository at this point in the history
  • Loading branch information
mcallegari committed Jan 6, 2019
1 parent ecde343 commit 3e141f6
Show file tree
Hide file tree
Showing 9 changed files with 598 additions and 54 deletions.
187 changes: 187 additions & 0 deletions qmlui/fixtureeditor/channeledit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
/*
Q Light Controller Plus
channeledit.cpp
Copyright (c) Massimo Callegari
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

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

#include "channeledit.h"

ChannelEdit::ChannelEdit(QLCChannel *channel, QObject *parent)
: QObject(parent)
, m_channel(channel)
{

}

ChannelEdit::~ChannelEdit()
{

}

QVariantList ChannelEdit::channelPresetList() const
{
QVariantList list;

QVariantMap custom;
custom.insert("mIcon", "qrc:/edit.svg");
custom.insert("mLabel", tr("Custom"));
custom.insert("mValue", 0);
list.append(custom);

for (int i = QLCChannel::Custom + 1; i < QLCChannel::LastPreset; i++)
{
QLCChannel ch;
ch.setPreset(QLCChannel::Preset(i));
QVariantMap chMap;
chMap.insert("mIcon", ch.getIconNameFromGroup(ch.group(), true));
chMap.insert("mLabel", ch.name() + " (" + ch.presetToString(QLCChannel::Preset(i)) + ")");
custom.insert("mValue", i);
list.append(chMap);
}

return list;
}

QVariantList ChannelEdit::channelTypeList() const
{
QVariantList list;

for (QString grp : QLCChannel::groupList())
{
QLCChannel ch;
ch.setGroup(QLCChannel::stringToGroup(grp));

QVariantMap chMap;
chMap.insert("mIcon", ch.getIconNameFromGroup(ch.group(), true));
chMap.insert("mLabel", ch.groupToString(ch.group()));
chMap.insert("mValue", ch.group());
list.append(chMap);

if (ch.group() == QLCChannel::Intensity)
{
for (QString color : QLCChannel::colourList())
{
QLCChannel cc;
cc.setGroup(QLCChannel::Intensity);
cc.setColour(QLCChannel::stringToColour(color));

QVariantMap chMap;
chMap.insert("mIcon", cc.getIconNameFromGroup(ch.group(), true));
chMap.insert("mLabel", cc.colourToString(cc.colour()));
chMap.insert("mValue", cc.colour());
list.append(chMap);
}
}
}

return list;
}

QString ChannelEdit::name() const
{
return m_channel->name();
}

void ChannelEdit::setName(QString name)
{
if (name == m_channel->name())
return;

m_channel->setName(name);
emit nameChanged();
}

int ChannelEdit::preset() const
{
return int(m_channel->preset());
}

void ChannelEdit::setPreset(int index)
{
if (index == int(m_channel->preset()))
return;

m_channel->setPreset(QLCChannel::Preset(index));
emit presetChanged();
if (index)
{
emit groupChanged();
emit controlByteChanged();
}
}

int ChannelEdit::group() const
{
if (m_channel->group() == QLCChannel::Intensity &&
m_channel->colour() != QLCChannel::NoColour)
return m_channel->colour();

return m_channel->group();
}

void ChannelEdit::setGroup(int group)
{
Q_UNUSED(group)
}

int ChannelEdit::controlByte() const
{
return m_channel->controlByte();
}

void ChannelEdit::setControlByte(int byte)
{
if (byte == m_channel->controlByte())
return;

m_channel->setControlByte(QLCChannel::ControlByte(byte));
emit controlByteChanged();
}

int ChannelEdit::defaultValue() const
{
return m_channel->defaultValue();
}

void ChannelEdit::setDefaultValue(int value)
{
if (value == m_channel->defaultValue())
return;

m_channel->setDefaultValue(uchar(value));
emit defaultValueChanged();
}

QVariantList ChannelEdit::capabilities() const
{
QVariantList list;

for (QLCCapability *cap : m_channel->capabilities())
{
QVariantMap capMap;
capMap.insert("iMin", cap->min());
capMap.insert("iMax", cap->max());
capMap.insert("sDesc", cap->name());
list.append(capMap);
}

return list;
}

84 changes: 84 additions & 0 deletions qmlui/fixtureeditor/channeledit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
Q Light Controller Plus
channeledit.h
Copyright (c) Massimo Callegari
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#ifndef CHANNELEDIT_H
#define CHANNELEDIT_H

#include <QQuickView>

class QLCChannel;

class ChannelEdit : public QObject
{
Q_OBJECT

Q_PROPERTY(QVariantList channelPresetList READ channelPresetList CONSTANT)
Q_PROPERTY(QVariantList channelTypeList READ channelTypeList CONSTANT)

Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(int preset READ preset WRITE setPreset NOTIFY presetChanged)
Q_PROPERTY(int group READ group WRITE setGroup NOTIFY groupChanged)

Q_PROPERTY(int controlByte READ controlByte WRITE setControlByte NOTIFY controlByteChanged)
Q_PROPERTY(int defaultValue READ defaultValue WRITE setDefaultValue NOTIFY defaultValueChanged)

Q_PROPERTY(QVariantList capabilities READ capabilities CONSTANT)

public:
ChannelEdit(QLCChannel *channel, QObject *parent = nullptr);
~ChannelEdit();

QVariantList channelPresetList() const;
QVariantList channelTypeList() const;

/** Get/Set the name of the channel being edited */
QString name() const;
void setName(QString name);

/** Get/Set the preset of the channel being edited */
int preset() const;
void setPreset(int index);

/** Get/Set the group of the channel being edited */
int group() const;
void setGroup(int group);

/** Get/Set the byte role of the channel being edited */
int controlByte() const;
void setControlByte(int byte);

/** Get/Set the default value of the channel being edited */
int defaultValue() const;
void setDefaultValue(int value);

QVariantList capabilities() const;

signals:
void nameChanged();
void presetChanged();
void groupChanged();
void controlByteChanged();
void defaultValueChanged();

private:
/** Reference to the channel being edited */
QLCChannel *m_channel;
};

#endif // CHANNELEDIT_H
20 changes: 20 additions & 0 deletions qmlui/fixtureeditor/editorview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
#include "qlcchannel.h"

#include "physicaledit.h"
#include "channeledit.h"
#include "editorview.h"

EditorView::EditorView(QQuickView *view, QLCFixtureDef *fixtureDef, QObject *parent)
: QObject(parent)
, m_view(view)
, m_fixtureDef(fixtureDef)
, m_channelEdit(nullptr)
{
m_globalPhy = new PhysicalEdit(m_fixtureDef->physical(), this);
}
Expand Down Expand Up @@ -102,3 +104,21 @@ QVariantList EditorView::channels() const

return list;
}

ChannelEdit *EditorView::requestChannelEditor(QString chName)
{
if (m_channelEdit != nullptr)
delete m_channelEdit;

QLCChannel *ch = m_fixtureDef->channel(chName);
if (ch == nullptr)
{
ch = new QLCChannel();
ch->setName(tr("New channel"));
m_fixtureDef->addChannel(ch);
emit channelsChanged();
}
m_channelEdit = new ChannelEdit(ch);
return m_channelEdit;
}

12 changes: 10 additions & 2 deletions qmlui/fixtureeditor/editorview.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

class QLCFixtureDef;
class PhysicalEdit;
class ChannelEdit;

class EditorView : public QObject
{
Expand All @@ -37,7 +38,7 @@ class EditorView : public QObject
Q_PROPERTY(QVariantList channels READ channels NOTIFY channelsChanged)

public:
EditorView(QQuickView *view, QLCFixtureDef* fixtureDef, QObject *parent = nullptr);
EditorView(QQuickView *view, QLCFixtureDef *fixtureDef, QObject *parent = nullptr);
~EditorView();

/** Get/Set the fixture manufacturer */
Expand Down Expand Up @@ -74,8 +75,15 @@ class EditorView : public QObject
/** Get a list of all the available channels in the definition */
QVariantList channels() const;

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

private:
ChannelEdit *m_channelEdit;

signals:
void channelsChanged();
};

#endif // FIXTUREEDITOR_H
#endif // EDITORVIEW_H
4 changes: 3 additions & 1 deletion qmlui/fixtureeditor/fixtureeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "fixtureeditor.h"
#include "physicaledit.h"
#include "channeledit.h"
#include "editorview.h"

FixtureEditor::FixtureEditor(QQuickView *view, Doc *doc, QObject *parent)
Expand All @@ -33,8 +34,9 @@ FixtureEditor::FixtureEditor(QQuickView *view, Doc *doc, QObject *parent)
, m_lastId(0)
{
m_view->rootContext()->setContextProperty("fixtureEditor", this);
qmlRegisterUncreatableType<EditorView>("org.qlcplus.classes", 1, 0, "EditorView", "Can't create EditorView!");
qmlRegisterUncreatableType<EditorView>("org.qlcplus.classes", 1, 0, "EditorRef", "Can't create EditorView!");
qmlRegisterUncreatableType<PhysicalEdit>("org.qlcplus.classes", 1, 0, "PhysicalEdit", "Can't create PhysicalEdit!");
qmlRegisterUncreatableType<ChannelEdit>("org.qlcplus.classes", 1, 0, "ChannelEdit", "Can't create ChannelEdit!");
}

FixtureEditor::~FixtureEditor()
Expand Down

0 comments on commit 3e141f6

Please sign in to comment.