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
|
||||
QT += webkitwidgets widgets
|
||||
HEADERS += src/libremediaserver-audio.h \
|
||||
src/editcuetrackwidget.h \
|
||||
src/cuetracklistwidget.h \
|
||||
src/cuetrackwidget.h \
|
||||
src/showplayer.h \
|
||||
|
@ -26,6 +27,7 @@ HEADERS += src/libremediaserver-audio.h \
|
|||
src/slidergroup.h \
|
||||
src/trackdialog.h
|
||||
SOURCES += src/main.cpp \
|
||||
src/editcuetrackwidget.cpp \
|
||||
src/cuetrackwidget.cpp \
|
||||
src/showplayer.cpp \
|
||||
src/clickabledoublespinbox.cpp \
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
|
||||
#include "cuetrackwidget.h"
|
||||
|
||||
#include <QTableWidget>
|
||||
#include <QTableWidgetItem>
|
||||
|
||||
class CueTrackListWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
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
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "cuetrackwidget.h"
|
||||
#include "editcuetrackwidget.h"
|
||||
#include <QSplitter>
|
||||
|
||||
CueTrackWidget::CueTrackWidget(QWidget *parent) : QWidget(parent) {
|
||||
|
|
|
@ -18,6 +18,7 @@ class CueTrackWidget : public QWidget {
|
|||
|
||||
public:
|
||||
explicit CueTrackWidget(QWidget *parent = nullptr);
|
||||
CueTrack track;
|
||||
CueTrack saveCueTrack() const;
|
||||
void loadCueTrack(const CueTrack &cueTrack);
|
||||
int getVolume() const { return volumeSpin->value() * 2.55f * 255.0f; }
|
||||
|
@ -61,169 +62,164 @@ public:
|
|||
QSpinBox* exitPointSpin;
|
||||
QPushButton* editButton;
|
||||
|
||||
|
||||
private:
|
||||
void setupUi();
|
||||
void setupStatusCombo();
|
||||
|
||||
private slots:
|
||||
void editButtonClicked();
|
||||
};
|
||||
/*
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
||||
// Definición de la clase EditCueTrackWidget
|
||||
#include <QFileDialog>
|
||||
#include "settings.h"
|
||||
|
||||
class EditCueTrackWidget : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit EditCueTrackWidget(QWidget *parent = nullptr);
|
||||
|
||||
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() {
|
||||
filePathEdit = new QLineEdit(this);
|
||||
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);
|
||||
saveButton = new QPushButton("Save", this);
|
||||
cancelButton = new QPushButton("Cancel", this);
|
||||
|
||||
QFormLayout *layout = new QFormLayout(this);
|
||||
layout->addRow("User Number", userNumberSpin);
|
||||
layout->addRow("Name", nameEdit);
|
||||
layout->addRow("File Path", filePathEdit);
|
||||
layout->addRow(browseButton);
|
||||
layout->addRow("Status", statusCombo);
|
||||
layout->addRow("Fade In", fadeInSpin);
|
||||
layout->addRow("Fade Out", fadeOutSpin);
|
||||
layout->addRow("Wait In", waitInSpin);
|
||||
layout->addRow("Wait Out", waitOutSpin);
|
||||
layout->addRow("Stop At End", stopAtEndCheck);
|
||||
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) {
|
||||
filePathEdit->setText(cueTrack.filePath.data());
|
||||
volumeSpin->setValue(cueTrack.volume);
|
||||
panSpin->setValue(cueTrack.pan);
|
||||
pitchSpin->setValue(cueTrack.pitch);
|
||||
bus1Spin->setValue(cueTrack.bus1);
|
||||
bus2Spin->setValue(cueTrack.bus2);
|
||||
fadeInSpin->setValue(cueTrack.fadeIn);
|
||||
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 {
|
||||
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() {
|
||||
connect(saveButton, &QPushButton::clicked, this, &EditCueTrackWidget::accept);
|
||||
connect(cancelButton, &QPushButton::clicked, this, &EditCueTrackWidget::reject);
|
||||
connect(browseButton, &QPushButton::clicked, this, &EditCueTrackWidget::onBrowseButtonClicked);
|
||||
}
|
||||
|
||||
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));
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
#include <QFile>
|
||||
#include <QXmlStreamWriter>
|
||||
|
||||
void saveCueTrackToXml(const CueTrack& cueTrack, const QString& filePath) {
|
||||
QFile file(filePath);
|
||||
if (!file.open(QIODevice::WriteOnly)) {
|
||||
qWarning("No se pudo abrir el archivo para escritura.");
|
||||
return;
|
||||
}
|
||||
|
||||
QXmlStreamWriter xmlWriter(&file);
|
||||
xmlWriter.setAutoFormatting(true); // Para una salida más legible
|
||||
|
||||
xmlWriter.writeStartDocument();
|
||||
xmlWriter.writeStartElement("CueTrack");
|
||||
|
||||
// Escribe los datos del objeto CueTrack como elementos o atributos
|
||||
xmlWriter.writeTextElement("Name", cueTrack.name());
|
||||
xmlWriter.writeTextElement("Volume", QString::number(cueTrack.volume()));
|
||||
xmlWriter.writeTextElement("Pan", QString::number(cueTrack.pan()));
|
||||
xmlWriter.writeTextElement("Pitch", QString::number(cueTrack.pitch()));
|
||||
// Añade más elementos según sea necesario
|
||||
|
||||
xmlWriter.writeEndElement(); // Cierra el elemento CueTrack
|
||||
xmlWriter.writeEndDocument();
|
||||
|
||||
file.close(); // No olvides cerrar el archivo
|
||||
}
|
||||
|
||||
#include <QFile>
|
||||
#include <QXmlStreamReader>
|
||||
|
||||
bool loadCueTrackFromXml(CueTrack& cueTrack, const QString& filePath) {
|
||||
QFile file(filePath);
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
qWarning("No se pudo abrir el archivo para lectura.");
|
||||
return false;
|
||||
}
|
||||
|
||||
QXmlStreamReader xmlReader(&file);
|
||||
|
||||
while (!xmlReader.atEnd() && !xmlReader.hasError()) {
|
||||
// Lee el siguiente elemento
|
||||
QXmlStreamReader::TokenType token = xmlReader.readNext();
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
||||
if (xmlReader.hasError()) {
|
||||
qWarning("Error al leer el archivo XML: %s", xmlReader.errorString().toUtf8().constData());
|
||||
return false;
|
||||
}
|
||||
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
*/
|
||||
#endif // CUETRACKWIDGET_H
|
||||
|
|
Loading…
Add table
Reference in a new issue