wip - antes de cambiar a TableWidget
This commit is contained in:
parent
bd9b07f000
commit
3b98be8b14
4 changed files with 174 additions and 143 deletions
|
@ -2,6 +2,7 @@ TEMPLATE = app
|
||||||
TARGET = libremediaserver-audio
|
TARGET = libremediaserver-audio
|
||||||
QT += webkitwidgets widgets
|
QT += webkitwidgets widgets
|
||||||
HEADERS += src/libremediaserver-audio.h \
|
HEADERS += src/libremediaserver-audio.h \
|
||||||
|
src/editcuetrackwidget.h \
|
||||||
src/cuetracklistwidget.h \
|
src/cuetracklistwidget.h \
|
||||||
src/cuetrackwidget.h \
|
src/cuetrackwidget.h \
|
||||||
src/showplayer.h \
|
src/showplayer.h \
|
||||||
|
@ -26,6 +27,7 @@ HEADERS += src/libremediaserver-audio.h \
|
||||||
src/slidergroup.h \
|
src/slidergroup.h \
|
||||||
src/trackdialog.h
|
src/trackdialog.h
|
||||||
SOURCES += src/main.cpp \
|
SOURCES += src/main.cpp \
|
||||||
|
src/editcuetrackwidget.cpp \
|
||||||
src/cuetrackwidget.cpp \
|
src/cuetrackwidget.cpp \
|
||||||
src/showplayer.cpp \
|
src/showplayer.cpp \
|
||||||
src/clickabledoublespinbox.cpp \
|
src/clickabledoublespinbox.cpp \
|
||||||
|
|
|
@ -8,6 +8,9 @@
|
||||||
|
|
||||||
#include "cuetrackwidget.h"
|
#include "cuetrackwidget.h"
|
||||||
|
|
||||||
|
#include <QTableWidget>
|
||||||
|
#include <QTableWidgetItem>
|
||||||
|
|
||||||
class CueTrackListWidget : public QWidget {
|
class CueTrackListWidget : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
@ -92,5 +95,34 @@ private slots:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void displayCueTrackInTable(QTableWidget* tableWidget, const CueTrack& cueTrack) {
|
||||||
|
// Configura las columnas si aún no están configuradas
|
||||||
|
if (tableWidget->columnCount() == 0) {
|
||||||
|
tableWidget->setColumnCount(5); // Ajusta según el número de propiedades a mostrar
|
||||||
|
QStringList headers = {"Nombre", "Volumen", "Pan", "Pitch", "Estado"};
|
||||||
|
tableWidget->setHorizontalHeaderLabels(headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
int currentRow = tableWidget->rowCount();
|
||||||
|
tableWidget->insertRow(currentRow);
|
||||||
|
|
||||||
|
// Nombre
|
||||||
|
tableWidget->setItem(currentRow, 0, new QTableWidgetItem(cueTrack.name));
|
||||||
|
|
||||||
|
// Volumen
|
||||||
|
tableWidget->setItem(currentRow, 1, new QTableWidgetItem(QString::number(cueTrack.volume)));
|
||||||
|
|
||||||
|
// Pan
|
||||||
|
tableWidget->setItem(currentRow, 2, new QTableWidgetItem(QString::number(cueTrack.pan)));
|
||||||
|
|
||||||
|
// Pitch
|
||||||
|
tableWidget->setItem(currentRow, 3, new QTableWidgetItem(QString::number(cueTrack.pitch)));
|
||||||
|
|
||||||
|
// Estado
|
||||||
|
QString statusStr; // Asume que tienes una función para convertir el estado a QString
|
||||||
|
statusStr = statusToString(cueTrack.status); // Implementa esta función según tu lógica
|
||||||
|
tableWidget->setItem(currentRow, 4, new QTableWidgetItem(statusStr));
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "cuetrackwidget.h"
|
#include "cuetrackwidget.h"
|
||||||
|
#include "editcuetrackwidget.h"
|
||||||
#include <QSplitter>
|
#include <QSplitter>
|
||||||
|
|
||||||
CueTrackWidget::CueTrackWidget(QWidget *parent) : QWidget(parent) {
|
CueTrackWidget::CueTrackWidget(QWidget *parent) : QWidget(parent) {
|
||||||
|
|
|
@ -18,6 +18,7 @@ class CueTrackWidget : public QWidget {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CueTrackWidget(QWidget *parent = nullptr);
|
explicit CueTrackWidget(QWidget *parent = nullptr);
|
||||||
|
CueTrack track;
|
||||||
CueTrack saveCueTrack() const;
|
CueTrack saveCueTrack() const;
|
||||||
void loadCueTrack(const CueTrack &cueTrack);
|
void loadCueTrack(const CueTrack &cueTrack);
|
||||||
int getVolume() const { return volumeSpin->value() * 2.55f * 255.0f; }
|
int getVolume() const { return volumeSpin->value() * 2.55f * 255.0f; }
|
||||||
|
@ -61,169 +62,164 @@ public:
|
||||||
QSpinBox* exitPointSpin;
|
QSpinBox* exitPointSpin;
|
||||||
QPushButton* editButton;
|
QPushButton* editButton;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupUi();
|
void setupUi();
|
||||||
void setupStatusCombo();
|
void setupStatusCombo();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void editButtonClicked();
|
void editButtonClicked();
|
||||||
|
/*
|
||||||
|
#include <QFile>
|
||||||
|
#include <QTextStream>
|
||||||
|
|
||||||
|
bool CueTrack::saveToFile(const QString& filePath) const {
|
||||||
|
QFile file(filePath);
|
||||||
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||||
|
return false; // No se pudo abrir el archivo para escritura
|
||||||
|
}
|
||||||
|
|
||||||
|
QTextStream out(&file);
|
||||||
|
|
||||||
|
// Escribir los datos en el archivo
|
||||||
|
out << "Volume: " << getVolume() << "\n";
|
||||||
|
out << "Pan: " << getPan() << "\n";
|
||||||
|
out << "Pitch: " << getPitch() << "\n";
|
||||||
|
out << "Bus1: " << getBus1() << "\n";
|
||||||
|
out << "Bus2: " << getBus2() << "\n";
|
||||||
|
out << "Status: " << static_cast<int>(getStatus()) << "\n";
|
||||||
|
out << "FilePath: " << getFilePath() << "\n";
|
||||||
|
out << "FadeIn: " << getFadeIn() << "\n";
|
||||||
|
out << "FadeOut: " << getFadeOut() << "\n";
|
||||||
|
out << "WaitIn: " << getWaitIn() << "\n";
|
||||||
|
out << "WaitOut: " << getWaitOut() << "\n";
|
||||||
|
out << "StopAtEnd: " << getStopAtEnd() << "\n";
|
||||||
|
out << "Name: " << getName() << "\n";
|
||||||
|
out << "Description: " << getDescription() << "\n";
|
||||||
|
out << "UserNumber: " << getUserNumber() << "\n";
|
||||||
|
out << "EntryPoint: " << getEntryPoint() << "\n";
|
||||||
|
out << "ExitPoint: " << getExitPoint() << "\n";
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#include <QFile>
|
||||||
|
#include <QTextStream>
|
||||||
|
|
||||||
|
bool CueTrack::loadFromFile(const QString& filePath) {
|
||||||
|
QFile file(filePath);
|
||||||
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
return false; // No se pudo abrir el archivo para lectura
|
||||||
|
}
|
||||||
|
|
||||||
|
QTextStream in(&file);
|
||||||
|
|
||||||
|
// Leer los datos del archivo
|
||||||
|
while (!in.atEnd()) {
|
||||||
|
QString line = in.readLine();
|
||||||
|
QStringList parts = line.split(": ");
|
||||||
|
if (parts.size() != 2) continue; // Omitir líneas mal formadas
|
||||||
|
|
||||||
|
QString key = parts[0].trimmed();
|
||||||
|
QString value = parts[1].trimmed();
|
||||||
|
|
||||||
|
if (key == "Volume") setVolume(value.toDouble());
|
||||||
|
else if (key == "Pan") setPan(value.toDouble());
|
||||||
|
else if (key == "Pitch") setPitch(value.toDouble());
|
||||||
|
else if (key == "Bus1") setBus1(value.toInt());
|
||||||
|
else if (key == "Bus2") setBus2(value.toInt());
|
||||||
|
else if (key == "Status") setStatus(static_cast<Status>(value.toInt()));
|
||||||
|
else if (key == "FilePath") setFilePath(value);
|
||||||
|
else if (key == "FadeIn") setFadeIn(value.toDouble());
|
||||||
|
else if (key == "FadeOut") setFadeOut(value.toDouble());
|
||||||
|
else if (key == "WaitIn") setWaitIn(value.toDouble());
|
||||||
|
else if (key == "WaitOut") setWaitOut(value.toDouble());
|
||||||
|
else if (key == "StopAtEnd") setStopAtEnd(value.toInt() != 0);
|
||||||
|
else if (key == "Name") setName(value);
|
||||||
|
else if (key == "Description") setDescription(value);
|
||||||
|
else if (key == "UserNumber") setUserNumber(value.toInt());
|
||||||
|
else if (key == "EntryPoint") setEntryPoint(value.toDouble());
|
||||||
|
else if (key == "ExitPoint") setExitPoint(value.toDouble());
|
||||||
|
// Añadir más campos según sea necesario
|
||||||
|
}
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Definición de la clase EditCueTrackWidget
|
#include <QFile>
|
||||||
#include <QFileDialog>
|
#include <QXmlStreamWriter>
|
||||||
#include "settings.h"
|
|
||||||
|
|
||||||
class EditCueTrackWidget : public QDialog {
|
void saveCueTrackToXml(const CueTrack& cueTrack, const QString& filePath) {
|
||||||
Q_OBJECT
|
QFile file(filePath);
|
||||||
|
if (!file.open(QIODevice::WriteOnly)) {
|
||||||
public:
|
qWarning("No se pudo abrir el archivo para escritura.");
|
||||||
explicit EditCueTrackWidget(QWidget *parent = nullptr);
|
return;
|
||||||
|
|
||||||
void loadCueTrack(const CueTrack &cueTrack);
|
|
||||||
CueTrack saveCueTrack() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void setupUi();
|
|
||||||
void connectSignals();
|
|
||||||
void onBrowseButtonClicked();
|
|
||||||
|
|
||||||
QLineEdit *filePathEdit;
|
|
||||||
QDoubleSpinBox *volumeSpin;
|
|
||||||
QDoubleSpinBox *panSpin;
|
|
||||||
QDoubleSpinBox *pitchSpin;
|
|
||||||
QDoubleSpinBox *bus1Spin;
|
|
||||||
QDoubleSpinBox *bus2Spin;
|
|
||||||
QSpinBox *fadeInSpin;
|
|
||||||
QSpinBox *fadeOutSpin;
|
|
||||||
QSpinBox *waitInSpin;
|
|
||||||
QSpinBox *waitOutSpin;
|
|
||||||
QCheckBox *stopAtEndCheck;
|
|
||||||
QLineEdit *nameEdit;
|
|
||||||
QLineEdit *descriptionEdit;
|
|
||||||
QSpinBox *userNumberSpin;
|
|
||||||
QSpinBox *entryPointSpin;
|
|
||||||
QSpinBox *exitPointSpin;
|
|
||||||
QComboBox *statusCombo;
|
|
||||||
QPushButton *browseButton;
|
|
||||||
QPushButton *saveButton;
|
|
||||||
QPushButton *cancelButton;
|
|
||||||
|
|
||||||
CueTrack currentCueTrack;
|
|
||||||
};
|
|
||||||
|
|
||||||
EditCueTrackWidget::EditCueTrackWidget(QWidget *parent) : QDialog(parent) {
|
|
||||||
setupUi();
|
|
||||||
connectSignals();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditCueTrackWidget::setupUi() {
|
QXmlStreamWriter xmlWriter(&file);
|
||||||
filePathEdit = new QLineEdit(this);
|
xmlWriter.setAutoFormatting(true); // Para una salida más legible
|
||||||
volumeSpin = new QDoubleSpinBox(this);
|
|
||||||
panSpin = new QDoubleSpinBox(this);
|
|
||||||
pitchSpin = new QDoubleSpinBox(this);
|
|
||||||
bus1Spin = new QDoubleSpinBox(this);
|
|
||||||
bus2Spin = new QDoubleSpinBox(this);
|
|
||||||
fadeInSpin = new QSpinBox(this);
|
|
||||||
fadeOutSpin = new QSpinBox(this);
|
|
||||||
waitInSpin = new QSpinBox(this);
|
|
||||||
waitOutSpin = new QSpinBox(this);
|
|
||||||
stopAtEndCheck = new QCheckBox(this);
|
|
||||||
nameEdit = new QLineEdit(this);
|
|
||||||
descriptionEdit = new QLineEdit(this);
|
|
||||||
userNumberSpin = new QSpinBox(this);
|
|
||||||
entryPointSpin = new QSpinBox(this);
|
|
||||||
exitPointSpin = new QSpinBox(this);
|
|
||||||
statusCombo = new QComboBox(this);
|
|
||||||
statusCombo->addItem("Stopped");
|
|
||||||
statusCombo->addItem("Paused");
|
|
||||||
statusCombo->addItem("PlayingOnce");
|
|
||||||
statusCombo->addItem("PlayingLoop");
|
|
||||||
statusCombo->addItem("Iddle");
|
|
||||||
statusCombo->addItem("PlayingFolder");
|
|
||||||
statusCombo->addItem("PlayingFolderLoop");
|
|
||||||
statusCombo->addItem("PlayingFolderRandom");
|
|
||||||
|
|
||||||
browseButton = new QPushButton("Browse...", this);
|
xmlWriter.writeStartDocument();
|
||||||
saveButton = new QPushButton("Save", this);
|
xmlWriter.writeStartElement("CueTrack");
|
||||||
cancelButton = new QPushButton("Cancel", this);
|
|
||||||
|
|
||||||
QFormLayout *layout = new QFormLayout(this);
|
// Escribe los datos del objeto CueTrack como elementos o atributos
|
||||||
layout->addRow("User Number", userNumberSpin);
|
xmlWriter.writeTextElement("Name", cueTrack.name());
|
||||||
layout->addRow("Name", nameEdit);
|
xmlWriter.writeTextElement("Volume", QString::number(cueTrack.volume()));
|
||||||
layout->addRow("File Path", filePathEdit);
|
xmlWriter.writeTextElement("Pan", QString::number(cueTrack.pan()));
|
||||||
layout->addRow(browseButton);
|
xmlWriter.writeTextElement("Pitch", QString::number(cueTrack.pitch()));
|
||||||
layout->addRow("Status", statusCombo);
|
// Añade más elementos según sea necesario
|
||||||
layout->addRow("Fade In", fadeInSpin);
|
|
||||||
layout->addRow("Fade Out", fadeOutSpin);
|
xmlWriter.writeEndElement(); // Cierra el elemento CueTrack
|
||||||
layout->addRow("Wait In", waitInSpin);
|
xmlWriter.writeEndDocument();
|
||||||
layout->addRow("Wait Out", waitOutSpin);
|
|
||||||
layout->addRow("Stop At End", stopAtEndCheck);
|
file.close(); // No olvides cerrar el archivo
|
||||||
layout->addRow("Volume", volumeSpin);
|
|
||||||
layout->addRow("Bus 1", bus1Spin);
|
|
||||||
layout->addRow("Bus 2", bus2Spin);
|
|
||||||
layout->addRow("Pan", panSpin);
|
|
||||||
layout->addRow("Pitch", pitchSpin);
|
|
||||||
layout->addRow("Entry Point", entryPointSpin);
|
|
||||||
layout->addRow("Exit Point", exitPointSpin);
|
|
||||||
layout->addRow("Description", descriptionEdit);
|
|
||||||
layout->addRow(saveButton);
|
|
||||||
layout->addRow(cancelButton);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditCueTrackWidget::loadCueTrack(const CueTrack &cueTrack) {
|
#include <QFile>
|
||||||
filePathEdit->setText(cueTrack.filePath.data());
|
#include <QXmlStreamReader>
|
||||||
volumeSpin->setValue(cueTrack.volume);
|
|
||||||
panSpin->setValue(cueTrack.pan);
|
bool loadCueTrackFromXml(CueTrack& cueTrack, const QString& filePath) {
|
||||||
pitchSpin->setValue(cueTrack.pitch);
|
QFile file(filePath);
|
||||||
bus1Spin->setValue(cueTrack.bus1);
|
if (!file.open(QIODevice::ReadOnly)) {
|
||||||
bus2Spin->setValue(cueTrack.bus2);
|
qWarning("No se pudo abrir el archivo para lectura.");
|
||||||
fadeInSpin->setValue(cueTrack.fadeIn);
|
return false;
|
||||||
fadeOutSpin->setValue(cueTrack.fadeOut);
|
|
||||||
waitInSpin->setValue(cueTrack.waitIn);
|
|
||||||
waitOutSpin->setValue(cueTrack.waitOut);
|
|
||||||
stopAtEndCheck->setChecked(cueTrack.stopAtEnd);
|
|
||||||
nameEdit->setText(cueTrack.name.data());
|
|
||||||
descriptionEdit->setText(cueTrack.description.data());
|
|
||||||
userNumberSpin->setValue(cueTrack.userNumber);
|
|
||||||
entryPointSpin->setValue(cueTrack.entryPoint);
|
|
||||||
exitPointSpin->setValue(cueTrack.exitPoint);
|
|
||||||
statusCombo->setCurrentIndex(statusCombo->findText(statusToString(cueTrack.status)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CueTrack EditCueTrackWidget::saveCueTrack() const {
|
QXmlStreamReader xmlReader(&file);
|
||||||
CueTrack cueTrack;
|
|
||||||
cueTrack.filePath.append(filePathEdit->text().toUtf8().constData());
|
|
||||||
cueTrack.volume = volumeSpin->value();
|
|
||||||
cueTrack.pan = panSpin->value();
|
|
||||||
cueTrack.pitch = pitchSpin->value();
|
|
||||||
cueTrack.name.append(nameEdit->text().toUtf8().constData());
|
|
||||||
cueTrack.description.append(descriptionEdit->text().toUtf8().constData());
|
|
||||||
cueTrack.status = static_cast<Status>(statusCombo->currentIndex());
|
|
||||||
cueTrack.fadeIn = fadeInSpin->value();
|
|
||||||
cueTrack.fadeOut = fadeOutSpin->value();
|
|
||||||
cueTrack.waitIn = waitInSpin->value();
|
|
||||||
cueTrack.waitOut = waitOutSpin->value();
|
|
||||||
cueTrack.stopAtEnd = stopAtEndCheck->isChecked();
|
|
||||||
cueTrack.userNumber = userNumberSpin->value();
|
|
||||||
cueTrack.entryPoint = entryPointSpin->value();
|
|
||||||
cueTrack.exitPoint = exitPointSpin->value();
|
|
||||||
return cueTrack;
|
|
||||||
}
|
|
||||||
|
|
||||||
void EditCueTrackWidget::connectSignals() {
|
while (!xmlReader.atEnd() && !xmlReader.hasError()) {
|
||||||
connect(saveButton, &QPushButton::clicked, this, &EditCueTrackWidget::accept);
|
// Lee el siguiente elemento
|
||||||
connect(cancelButton, &QPushButton::clicked, this, &EditCueTrackWidget::reject);
|
QXmlStreamReader::TokenType token = xmlReader.readNext();
|
||||||
connect(browseButton, &QPushButton::clicked, this, &EditCueTrackWidget::onBrowseButtonClicked);
|
// Si es un elemento de inicio y el nombre del elemento es el esperado
|
||||||
|
if (token == QXmlStreamReader::StartElement) {
|
||||||
|
if (xmlReader.name() == "filePath") {
|
||||||
|
cueTrack.filePath = xmlReader.readElementText().toStdString();
|
||||||
|
} else if (xmlReader.name() == "volume") {
|
||||||
|
cueTrack.volume = xmlReader.readElementText().toInt();
|
||||||
|
} else if (xmlReader.name() == "pan") {
|
||||||
|
cueTrack.pan = xmlReader.readElementText().toInt();
|
||||||
|
} else if (xmlReader.name() == "pitch") {
|
||||||
|
cueTrack.pitch = xmlReader.readElementText().toInt();
|
||||||
|
} else if (xmlReader.name() == "status") {
|
||||||
|
QString statusStr = xmlReader.readElementText();
|
||||||
|
cueTrack.status = stringToStatus(&statusStr); // Asegúrate de que esta función maneje QString correctamente
|
||||||
}
|
}
|
||||||
|
// Añade más campos según sea necesario
|
||||||
void EditCueTrackWidget::onBrowseButtonClicked() {
|
|
||||||
QString filePath = QFileDialog::getOpenFileName(this, tr("Select File"), Settings::getInstance()->getPathMedia(), tr("Audio Files (*.mp3 *.wav *.flac)"));
|
|
||||||
if (!filePath.isEmpty()) {
|
|
||||||
filePathEdit->setText(filePath);
|
|
||||||
QDir dir;
|
|
||||||
Settings::getInstance()->setPathMedia(dir.absoluteFilePath(filePath));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (xmlReader.hasError()) {
|
||||||
|
qWarning("Error al leer el archivo XML: %s", xmlReader.errorString().toUtf8().constData());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
#endif // CUETRACKWIDGET_H
|
#endif // CUETRACKWIDGET_H
|
||||||
|
|
Loading…
Add table
Reference in a new issue