Skip to content
Extraits de code Groupes Projets
Vérifiée Valider b1a231e1 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

DOCUMENTS: First quick implementation of documents, document views and the store

parent 67b84755
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!3Add documents
Ce commit fait partie de la requête de fusion !3. Les commentaires créés ici seront créés dans le contexte de cette requête de fusion.
#include "VivyDocument.h"
#include <QString>
bool
VivyDocument::loadSubDocument(const QString &name) noexcept
{
return false;
}
bool
VivyDocument::rename(const QString &name) noexcept
{
return false;
}
QString
VivyDocument::getSubDocument(SubDocument subType) const noexcept
{
if ((documentType & subType) == 0) {
QString ret;
return ret;
}
switch (subType) {
case SubDocument::Audio:
return audioFile;
case SubDocument::Video:
return videoFile;
case SubDocument::ASS:
return assFile;
}
}
VivyDocument *
VivyDocument::fromPath(const QString &path) noexcept
{
return nullptr;
}
VivyDocument *
VivyDocument::newEmpty(const QString &name) noexcept
{
return nullptr;
}
......@@ -5,14 +5,40 @@
#error "This is a C++ header"
#endif
#include <QString>
class VivyDocument {
public:
enum SubDocument : int {
Audio = (1 << 1),
Video = (1 << 2),
ASS = (1 << 3),
};
private:
/* The document name */
const char *name;
QString name;
/* The type to get all fields, has audio, etc... */
int documentType;
/* Links to other files, they're not embeded inside the vivy file */
const char *audioFile;
const char *videoFile;
const char *assFile;
QString audioFile;
QString videoFile;
QString assFile;
/* Create an empty document */
VivyDocument(const QString &name);
public:
static VivyDocument *fromPath(const QString &path) noexcept;
static VivyDocument *newEmpty(const QString &name) noexcept;
bool rename(const QString &) noexcept;
bool loadSubDocument(const QString &) noexcept;
/* Getters */
QString getSubDocument(SubDocument) const noexcept;
};
#endif // VIVY_DOCUMENT_H
#include "VivyDocumentStore.h"
#include "VivyDocument.h"
bool
VivyDocumentStore::loadDocument(const QString &file) noexcept
{
return false;
}
bool
VivyDocumentStore::newDocument(const QString &name) noexcept
{
return false;
}
VivyDocument *
VivyDocumentStore::getDocument(const QString &name) const noexcept
{
if (!documents.contains(name))
return nullptr;
return documents.value(name);
}
VivyDocumentView *
VivyDocumentStore::getDocumentView(const QString &name) const noexcept
{
if (!documents.contains(name))
return nullptr;
return new VivyDocumentView(documents.value(name));
}
#ifndef VIVY_DOCUMENTSTORE_H
#define VIVY_DOCUMENTSTORE_H
#include "VivyDocument.h"
#include "VivyDocumentView.h"
#include <QMap>
#include <QString>
class VivyDocumentStore final {
public:
VivyDocumentStore() noexcept = default;
~VivyDocumentStore() noexcept = default;
/* Don't move this object around */
VivyDocumentStore(const VivyDocumentStore &) = delete; // Copy
VivyDocumentStore(VivyDocumentStore &&) = delete; // Move
VivyDocumentStore &operator=(const VivyDocumentStore &) = delete; // Copy assign
VivyDocumentStore &operator=(VivyDocumentStore &&) = delete; // Move assign
/* Create/load documents */
bool loadDocument(const QString &file) noexcept;
bool newDocument(const QString &name) noexcept;
/* Get stored documents */
VivyDocument *getDocument(const QString &name) const noexcept;
VivyDocumentView *getDocumentView(const QString &name) const noexcept;
private:
QMap<QString, VivyDocument *> documents;
};
#endif // VIVY_DOCUMENTSTORE_H
#include "VivyDocumentView.h"
#include "AudioVisualizer.h"
#include <QVBoxLayout>
#include <cassert>
VivyDocumentView::VivyDocumentView(VivyDocument *doc) noexcept
: document(*doc)
{
QString audioFile = document.getSubDocument(VivyDocument::SubDocument::Audio);
if (!audioFile.isEmpty()) {
visualizer = AudioVisualizer::fromFile(audioFile);
assert(visualizer != nullptr);
}
QVBoxLayout *layout = new QVBoxLayout;
if (visualizer != nullptr)
layout->addWidget(visualizer);
setLayout(layout);
}
......@@ -13,9 +13,12 @@
class VivyDocumentView final : public QWidget {
Q_OBJECT
public:
VivyDocumentView(VivyDocument *) noexcept;
private:
VivyDocument *document;
AudioVisualizer *visualizer;
VivyDocument &document; // A non-null pointer to the document
AudioVisualizer *visualizer = nullptr;
};
#endif // VIVY_DOCUMENTVIEW_H
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter