Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
  • c069b6f146dd45e4d9b377eb2578348aded52948
  • master par défaut
  • script
  • new-devel
  • devel
  • timingView-edit
  • fix-mpv
7 résultats

MainWindow.hh

Blame
  • 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;
    };
    
    }