Sélectionner une révision Git
MainWindow.hh 2,73 Kio
#pragma once
#ifndef __cplusplus
#error "This is a C++ header"
#endif
#include "../Lib/Utils.hh"
#include "../Lib/AbstractDocument.hh"
#include "../Lib/Document/VivyDocumentStore.hh"
#include "DocumentViews/AudioVisualizer.hh"
#include "VivyDocumentView.hh"
#include "AboutWindow.hh"
#include <QMenu>
#include <QFileDialog>
#include <QMutex>
#include <QMainWindow>
namespace Vivy
{
class MainWindow final : public QMainWindow {
Q_OBJECT
QTabWidget *documents{ nullptr };
QMenu *viewMenu{ nullptr };
QMutex aboutWindowMutex{ QMutex::NonRecursive };
AboutWindow *aboutWindow{ nullptr };
public:
explicit MainWindow() noexcept;
AbstractDocument *getCurrentDocument() const noexcept;
template <class Document> Document *getCurrentDocument() const noexcept
{
if (AbstractDocumentView *currentView = getCurrentDocumentView();
currentView->getType() == Document::type) {
return currentView->getDocument();
} else {
return nullptr;
}
}
private:
void addTab(AbstractDocumentView *);
AbstractDocumentView *getTab(const int) const noexcept;
AbstractDocumentView *getCurrentDocumentView() const;
int findFirstUntouchedDocument() const noexcept;
QString dialogOpenFileName(const QString &title, const QString &folder,
const QString &filter) noexcept;
// Do an action with the selected filename. The 'call' variable must be
// callable like this: call(DocumentView, Document, QString)
template <typename DV, typename D>
void withOpenFileNameDialog(const QString &title, const QString &filter, auto call) noexcept
{
const QString filename = dialogOpenFileName(title, QDir::homePath(), filter);
if (filename.isEmpty()) {
qWarning() << "Found an empty filename, don't open a file";
return;
}
try {
if (AbstractDocumentView *currView = getCurrentDocumentView();
currView->isType(D::type)) {
DV *view = static_cast<VivyDocumentView *>(currView);
D *doc = view->getDocument();
call(view, doc, filename);
}
} catch (const std::runtime_error &e) {
qCritical() << "Operation failed with:" << e.what();
}
}
private slots:
void newDocument() noexcept;
void openDocument() noexcept;
void closeDocument(int index) noexcept;
void openProperties(int index) noexcept;
void loadSubDocumentAss() noexcept;
void loadSubDocumentVideo() noexcept;
void loadSubDocumentAudio() noexcept;
void saveFile() noexcept;
void saveFileAs() noexcept;
void openDialogHelp() noexcept;
void documentViewActionsChanged() noexcept;
};
}