Skip to content

Commit

Permalink
qmlui: more work on input profile editor
Browse files Browse the repository at this point in the history
  • Loading branch information
mcallegari committed Oct 20, 2023
1 parent 092e0d3 commit a42db9d
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 49 deletions.
75 changes: 49 additions & 26 deletions qmlui/inputoutputmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "outputpatch.h"
#include "inputpatch.h"
#include "universe.h"
#include "qlcfile.h"
#include "tardis.h"
#include "doc.h"

Expand Down Expand Up @@ -560,33 +561,9 @@ int InputOutputManager::outputPatchesCount(int universe) const
* Input Profiles
*********************************************************************/

QVariant InputOutputManager::universeInputProfiles(int universe)
QString InputOutputManager::profileUserFolder()
{
QVariantList profilesList;
QStringList profileNames = m_ioMap->profileNames();
profileNames.sort();
QDir pSysPath = m_ioMap->systemProfileDirectory();

foreach (QString name, profileNames)
{
QLCInputProfile *ip = m_ioMap->profile(name);
if (ip != nullptr)
{
QString type = ip->typeToString(ip->type());
QVariantMap profileMap;
profileMap.insert("universe", universe);
profileMap.insert("name", name);
profileMap.insert("line", name);
profileMap.insert("plugin", type);
if (ip->path().startsWith(pSysPath.absolutePath()))
profileMap.insert("isUser", false);
else
profileMap.insert("isUser", true);
profilesList.append(profileMap);
}
}

return QVariant::fromValue(profilesList);
return m_ioMap->userProfileDirectory().absolutePath();
}

void InputOutputManager::createInputProfile()
Expand Down Expand Up @@ -626,6 +603,23 @@ bool InputOutputManager::editInputProfile(QString name)
return true;
}

bool InputOutputManager::saveInputProfile()
{
if (m_editProfile == nullptr)
return false;

QDir dir(InputOutputMap::userProfileDirectory());
QString absPath = QString("%1/%2-%3%4").arg(dir.absolutePath())
.arg(m_editProfile->manufacturer())
.arg(m_editProfile->model())
.arg(KExtInputProfile);

m_editProfile->saveXML(absPath);
m_profileEditor->setModified(false);

return true;
}

void InputOutputManager::finishInputProfile()
{
if (m_editProfile != nullptr)
Expand All @@ -641,6 +635,35 @@ void InputOutputManager::finishInputProfile()
}
}

QVariant InputOutputManager::universeInputProfiles(int universe)
{
QVariantList profilesList;
QStringList profileNames = m_ioMap->profileNames();
profileNames.sort();
QDir pSysPath = m_ioMap->systemProfileDirectory();

foreach (QString name, profileNames)
{
QLCInputProfile *ip = m_ioMap->profile(name);
if (ip != nullptr)
{
QString type = ip->typeToString(ip->type());
QVariantMap profileMap;
profileMap.insert("universe", universe);
profileMap.insert("name", name);
profileMap.insert("line", name);
profileMap.insert("plugin", type);
if (ip->path().startsWith(pSysPath.absolutePath()))
profileMap.insert("isUser", false);
else
profileMap.insert("isUser", true);
profilesList.append(profileMap);
}
}

return QVariant::fromValue(profilesList);
}

/*********************************************************************
* Beats
*********************************************************************/
Expand Down
7 changes: 6 additions & 1 deletion qmlui/inputoutputmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class InputOutputManager : public PreviewContext
Q_PROPERTY(QString beatType READ beatType WRITE setBeatType NOTIFY beatTypeChanged)
Q_PROPERTY(int bpmNumber READ bpmNumber WRITE setBpmNumber NOTIFY bpmNumberChanged)

Q_PROPERTY(QString profileUserFolder READ profileUserFolder CONSTANT)

public:
InputOutputManager(QQuickView *view, Doc *doc, QObject *parent = 0);

Expand Down Expand Up @@ -147,10 +149,13 @@ protected slots:
* Input Profiles
*********************************************************************/
public:
Q_INVOKABLE QVariant universeInputProfiles(int universe);
QString profileUserFolder();

Q_INVOKABLE void createInputProfile();
Q_INVOKABLE bool editInputProfile(QString name);
Q_INVOKABLE bool saveInputProfile();
Q_INVOKABLE void finishInputProfile();
Q_INVOKABLE QVariant universeInputProfiles(int universe);

private:
InputProfileEditor *m_profileEditor;
Expand Down
6 changes: 3 additions & 3 deletions qmlui/inputprofileeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ QString InputProfileEditor::manufacturer() const

void InputProfileEditor::setManufacturer(const QString &newManufacturer)
{
if (m_profile == nullptr)
if (m_profile == nullptr || m_profile->manufacturer() == newManufacturer)
return;

m_profile->setManufacturer(newManufacturer);
Expand All @@ -75,7 +75,7 @@ QString InputProfileEditor::model() const

void InputProfileEditor::setModel(const QString &newModel)
{
if (m_profile == nullptr)
if (m_profile == nullptr || m_profile->model() == newModel)
return;

m_profile->setModel(newModel);
Expand All @@ -90,7 +90,7 @@ int InputProfileEditor::type()

void InputProfileEditor::setType(const int &newType)
{
if (m_profile == nullptr)
if (m_profile == nullptr || m_profile->type() == newType)
return;

m_profile->setType(QLCInputProfile::Type(newType));
Expand Down
1 change: 1 addition & 0 deletions qmlui/qml/fixtureeditor/qmldir
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ColorToolFull 0.1 ../ColorToolFull.qml
ContextMenuEntry 0.1 ../ContextMenuEntry.qml
CustomCheckBox 0.1 ../CustomCheckBox.qml
CustomComboBox 0.1 ../CustomComboBox.qml
CustomPopupDialog 0.1 ../popup/CustomPopupDialog.qml
CustomScrollBar 0.1 ../CustomScrollBar.qml
CustomSpinBox 0.1 ../CustomSpinBox.qml
CustomTextEdit 0.1 ../CustomTextEdit.qml
Expand Down
43 changes: 43 additions & 0 deletions qmlui/qml/inputoutput/InputProfileEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,49 @@ ColumnLayout
{
id: peContainer

property bool isEditing: false

function showWarning()
{
messagePopup.message = qsTr("You are trying to edit a bundled input profile.<br>" +
"If you modify and save it, a new file will be stored in<br><i>" +
ioManager.profileUserFolder + "</i><br>and will override the bundled file.")
messagePopup.standardButtons = Dialog.Ok
messagePopup.open()
}

function showSaveFirst()
{
messagePopup.message = qsTr("Do you wish to save the current profile first?\nChanges will be lost if you don't save them.")
messagePopup.standardButtons = Dialog.Yes | Dialog.No | Dialog.Cancel
messagePopup.open()
}

CustomPopupDialog
{
id: messagePopup
standardButtons: Dialog.Ok
title: qsTr("!! Warning !!")

onClicked:
{
if (role === Dialog.Yes)
{
// todo save
}
else if (role === Dialog.No)
{
ioManager.finishInputProfile()
isEditing = false
close()
}
else if (role === Dialog.Ok || role === Dialog.Cancel)
{
close()
}
}
}

Rectangle
{
implicitWidth: peContainer.width
Expand Down
48 changes: 29 additions & 19 deletions qmlui/qml/inputoutput/ProfilesList.qml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Rectangle
color: "transparent"

property int universeIndex: 0
property bool isEditing: false

onUniverseIndexChanged:
{
Expand Down Expand Up @@ -72,26 +71,26 @@ Rectangle
{
width: height
height: topBar.height - 2
visible: isEditing
enabled: isEditing && profileEditor.modified
visible: profEditor.isEditing
enabled: profEditor.isEditing && profileEditor.modified
imgSource: "qrc:/filesave.svg"
tooltip: qsTr("Save this profile")

onClicked: { }
onClicked: ioManager.saveInputProfile()
}

IconButton
{
width: height
height: topBar.height - 2
visible: isEditing
visible: profEditor.isEditing
checkable: true
imgSource: "qrc:/wizard.svg"
tooltip: qsTr("Toggle the automatic detection procedure")

onToggled:
{
if (isEditing)
if (profEditor.isEditing)
profileEditor.toggleDetection()
}
}
Expand All @@ -101,18 +100,18 @@ Rectangle
width: height
height: topBar.height - 2
imgSource: "qrc:/add.svg"
tooltip: isEditing ? qsTr("Add a new channel") : qsTr("Create a new input profile")
tooltip: profEditor.isEditing ? qsTr("Add a new channel") : qsTr("Create a new input profile")

onClicked:
{
if (isEditing)
if (profEditor.isEditing)
{

}
else
{
ioManager.createInputProfile()
isEditing = true
profEditor.isEditing = true
}
}
}
Expand All @@ -122,19 +121,21 @@ Rectangle
width: height
height: topBar.height - 2
imgSource: "qrc:/edit.svg"
tooltip: isEditing ? qsTr("Edit the selected channel") : qsTr("Edit the selected input profile")
tooltip: profEditor.isEditing ? qsTr("Edit the selected channel") : qsTr("Edit the selected input profile")
enabled: profListView.selectedIndex >= 0

onClicked:
{
if (isEditing)
if (profEditor.isEditing)
{

}
else
{
ioManager.editInputProfile(profListView.selectedName)
isEditing = true
profEditor.isEditing = true
if (profListView.selectedIsUser == false)
profEditor.showWarning()
}
}
}
Expand All @@ -144,8 +145,8 @@ Rectangle
width: height
height: topBar.height - 2
imgSource: "qrc:/remove.svg"
tooltip: isEditing ? qsTr("Delete the selected channel") : qsTr("Delete the selected input profile(s)")
enabled: profListView.selectedIndex >= 0
tooltip: profEditor.isEditing ? qsTr("Delete the selected channel") : qsTr("Delete the selected input profile(s)")
enabled: profListView.selectedIndex >= 0 && profListView.selectedIsUser

onClicked: { }
}
Expand All @@ -156,15 +157,21 @@ Rectangle
{
width: height
height: topBar.height - 2
visible: isEditing
visible: profEditor.isEditing
border.color: UISettings.bgMedium
useFontawesome: true
label: FontAwesome.fa_times
onClicked:
{
// todo popup for unsaved changes
ioManager.finishInputProfile()
isEditing = false
if (profileEditor.modified)
{
profEditor.showSaveFirst()
}
else
{
ioManager.finishInputProfile()
profEditor.isEditing = false
}
}
}
}
Expand All @@ -177,10 +184,11 @@ Rectangle
Layout.fillHeight: true
z: 1
boundsBehavior: Flickable.StopAtBounds
visible: !isEditing
visible: !profEditor.isEditing

property int selectedIndex: -1
property string selectedName
property bool selectedIsUser: false

delegate:
Item
Expand All @@ -202,6 +210,7 @@ Rectangle
{
profListView.selectedIndex = index
profListView.selectedName = profileItem.lineName
profListView.selectedIsUser = modelData.isUser
}

onReleased:
Expand Down Expand Up @@ -269,6 +278,7 @@ Rectangle

InputProfileEditor
{
id: profEditor
width: profilesContainer.width
Layout.fillHeight: true
visible: isEditing
Expand Down
1 change: 1 addition & 0 deletions qmlui/qml/inputoutput/qmldir
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ singleton FontAwesome 1.0 ../FontAwesomeVariables.qml
ContextMenuEntry 0.1 ../ContextMenuEntry.qml
CustomCheckBox 0.1 ../CustomCheckBox.qml
CustomComboBox 0.1 ../CustomComboBox.qml
CustomPopupDialog 0.1 ../popup/CustomPopupDialog.qml
CustomSpinBox 0.1 ../CustomSpinBox.qml
CustomScrollBar 0.1 ../CustomScrollBar.qml
CustomTextEdit 0.1 ../CustomTextEdit.qml
Expand Down

0 comments on commit a42db9d

Please sign in to comment.