b30b6c
#pragma once
b30b6c
b96f40
#ifndef SCENEBROWSER_INCLUDED
b96f40
#define SCENEBROWSER_INCLUDED
b30b6c
b30b6c
#include <qframe></qframe>
b30b6c
#include <qtreewidget></qtreewidget>
b30b6c
#include <qdatetime></qdatetime>
b30b6c
#include <qitemdelegate></qitemdelegate>
b30b6c
#include <qcheckbox></qcheckbox>
b30b6c
#include <qlist></qlist>
b30b6c
#include <qmodelindex></qmodelindex>
b30b6c
#include "dvitemview.h"
b30b6c
#include "tfilepath.h"
b30b6c
#include "toonzqt/dvdialog.h"
b30b6c
#include "versioncontrol.h"
b96f40
#include "filebrowser.h"
b30b6c
b30b6c
#include "tthread.h"
b30b6c
b30b6c
class QLineEdit;
b30b6c
class QTreeWidgetItem;
b30b6c
class QSplitter;
b30b6c
class DvDirModelNode;
b30b6c
class DvDirTreeView;
b30b6c
class QFileSystemWatcher;
b30b6c
b30b6c
//-----------------------------------------------------------------------------
b30b6c
b96f40
class SceneBrowser final : public QFrame, public DvItemListModel {
b30b6c
  Q_OBJECT
b30b6c
b30b6c
public:
b30b6c
#if QT_VERSION >= 0x050500
b96f40
  SceneBrowser(QWidget *parent, Qt::WindowFlags flags = 0,
b30b6c
              bool noContextMenu = false, bool multiSelectionEnabled = false);
b30b6c
#else
b96f40
  SceneBrowser(QWidget *parent, Qt::WFlags flags = 0, bool noContextMenu = false,
b30b6c
              bool multiSelectionEnabled = false);
b30b6c
#endif
b96f40
  ~SceneBrowser();
b30b6c
b30b6c
  void sortByDataModel(DataType dataType, bool isDiscendent) override;
b30b6c
  void refreshData() override;
b30b6c
b30b6c
  int getItemCount() const override;
b30b6c
  QVariant getItemData(int index, DataType dataType,
b30b6c
                       bool isSelected = false) override;
b30b6c
b30b6c
  bool canRenameItem(int index) const override;
b30b6c
  void renameItem(int index, const QString &newName) override;
b30b6c
b30b6c
  bool isSceneItem(int index) const override;
b30b6c
  void startDragDrop() override;
b30b6c
  QMenu *getContextMenu(QWidget *parent, int index) override;
b30b6c
b30b6c
  /*!
b30b6c
This functions adds to the types to be filtered a new type;
b30b6c
if this function is never  called, the default filter is all image
b30b6c
files and scene files and palette files
b30b6c
*/
b30b6c
  void addFilterType(const QString &type);
b30b6c
b30b6c
  /*!
b30b6c
The setFilterTypes function directly specifies the list of file
b30b6c
types to be displayed in the file browser.
b30b6c
*/
b30b6c
  void setFilterTypes(const QStringList &types);
b30b6c
  const QStringList &getFilterTypes() const { return m_filter; }
b30b6c
  void removeFilterType(const QString &type);
b30b6c
b30b6c
  void setFolder(const TFilePath &fp, bool expandNode = false,
b30b6c
                 bool forceUpdate = false);
b30b6c
  // process when inputting the folder which is not regitered in the folder tree
b30b6c
  // (e.g. UNC path in Windows)
b30b6c
  void setUnregisteredFolder(const TFilePath &fp);
b30b6c
b30b6c
  void setHistoryDay(std::string dayDateString);
b30b6c
b30b6c
  TFilePath getFolder() const { return m_folder; }
b30b6c
  std::string getDayDateString() const { return m_dayDateString; }
b30b6c
b30b6c
  static void refreshFolder(const TFilePath &folder);
b30b6c
b30b6c
  static void updateItemViewerPanel();
b30b6c
b30b6c
  // ritorna true se il file e' stato rinominato. dopo la chiamata fp contiene
b30b6c
  // il nuovo path
b30b6c
  static bool renameFile(TFilePath &fp, QString newName);
b30b6c
b30b6c
  void makeCurrentProjectVisible();
b30b6c
b30b6c
  void enableGlobalSelection(bool enabled);
b30b6c
  void selectNone();
b30b6c
b30b6c
  QSplitter *getMainSplitter() const { return m_mainSplitter; }
b30b6c
b30b6c
  // Enable double-click to open a scene.
b30b6c
  // This is not always desirable (e.g. if a user double-clicks on a file in
b30b6c
  // a "Save As" dialog, they expect the file will be saved to, not opened).
b30b6c
  // So it is disabled by default.
b30b6c
  void enableDoubleClickToOpenScenes();
b30b6c
6081f1
  void enableSingleClickToOpenScenes();
6081f1
b30b6c
protected:
b30b6c
  int findIndexWithPath(TFilePath path);
b30b6c
  void getExpandedFolders(DvDirModelNode *node,
b30b6c
                          QList<dvdirmodelnode *=""> &expandedNodes);</dvdirmodelnode>
b30b6c
b30b6c
  bool dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data,
b30b6c
                    Qt::DropAction action);
b30b6c
b30b6c
  bool acceptDrop(const QMimeData *data) const override;
b30b6c
  bool drop(const QMimeData *data) override;
b30b6c
  void showEvent(QShowEvent *) override;
b30b6c
  void hideEvent(QHideEvent *) override;
b30b6c
b30b6c
  // Fill the QStringList with files selected in the browser, auxiliary files
b30b6c
  // (palette for tlv, hooks, sceneIcons)
b30b6c
  // retrieve also the path, and return also the sceneIconsCount
b30b6c
  void setupVersionControlCommand(QStringList &files, QString &path,
b30b6c
                                  int &sceneIconsCount);
b30b6c
  void setupVersionControlCommand(QString &file, QString &path);
b30b6c
b30b6c
  void refreshHistoryButtons();
b30b6c
b30b6c
public slots:
b30b6c
b30b6c
  void onTreeFolderChanged();
b30b6c
b30b6c
protected slots:
b30b6c
b30b6c
  void refresh();
b30b6c
b30b6c
  void changeFolder(const QModelIndex &index);
b30b6c
  void onDataChanged(const QModelIndex &topLeft,
b30b6c
                     const QModelIndex &bottomRight);
b30b6c
  void loadResources();
b30b6c
  void onClickedItem(int index);
b30b6c
  void onDoubleClickedItem(int index);
b30b6c
  void onSelectedItems(const std::set<int> &indexes);</int>
b30b6c
  void folderUp();
b30b6c
  void newFolder();
b30b6c
b30b6c
  void onBackButtonPushed();
b30b6c
  void onFwdButtonPushed();
b30b6c
  void onFolderEdited();
b30b6c
  void storeFolderHistory();
b30b6c
  void clearHistory();
b30b6c
b30b6c
  void renameAsToonzLevel();
b30b6c
  void updateAndEditVersionControl();
b30b6c
  void editVersionControl();
b30b6c
  void unlockVersionControl();
b30b6c
b30b6c
  void editFrameRangeVersionControl();
b30b6c
  void unlockFrameRangeVersionControl();
b30b6c
b30b6c
  void putFrameRangeVersionControl();
b30b6c
  void revertFrameRangeVersionControl();
b30b6c
b30b6c
  void showLockInformation();
b30b6c
  void showFrameRangeLockInfo();
b30b6c
b30b6c
  void putVersionControl();
b30b6c
  void revertVersionControl();
b30b6c
  void deleteVersionControl();
b30b6c
  void getVersionControl();
b30b6c
  void getRevisionVersionControl();
b30b6c
  void getRevisionHistory();
b30b6c
b30b6c
  void onVersionControlCommandDone(const QStringList &files);
b30b6c
b30b6c
  void onFileSystemChanged(const QString &folderPath);
b30b6c
b30b6c
  // If filePath is a valid scene file, open it. Otherwise do nothing.
b30b6c
  void tryToOpenScene(const TFilePath &filePath);
b30b6c
b30b6c
signals:
b30b6c
b30b6c
  void filePathClicked(const TFilePath &);
b30b6c
  void filePathDoubleClicked(const TFilePath &);
b30b6c
  // reuse the list of TFrameId in order to skip loadInfo() when loading the
b30b6c
  // level with sequencial frames.
b30b6c
  void filePathsSelected(const std::set<tfilepath> &,</tfilepath>
b30b6c
                         const std::list<std::vector<tframeid>> &);</std::vector<tframeid>
b30b6c
  void treeFolderChanged(const TFilePath &);
b30b6c
b30b6c
  // for activating/deactivating the folder history buttons( back button &
b30b6c
  // forward button )
b30b6c
  void historyChanged(bool, bool);
b30b6c
b30b6c
private:
b30b6c
  struct Item {
b30b6c
    QString m_name;
b30b6c
    qlonglong m_fileSize;
b30b6c
    QDateTime m_creationDate;
b30b6c
    QDateTime m_modifiedDate;
b30b6c
    int m_frameCount;
b30b6c
    QString m_fileType;
b30b6c
    TFilePath m_path;
b30b6c
    bool m_validInfo;
b30b6c
b30b6c
    bool m_isFolder;
b30b6c
    bool m_isLink;
b30b6c
    // calling loadInfo to the level with sequencial frames is time consuming.
b30b6c
    // so keep the list of frameIds at the first time and try to reuse it.
b30b6c
    std::vector<tframeid> m_frameIds;</tframeid>
b30b6c
b30b6c
    Item() : m_frameCount(0), m_validInfo(false), m_fileSize(0) {}
b30b6c
    Item(const TFilePath &path, bool folder = false, bool link = false,
b30b6c
         QString name = QString(""))
b30b6c
        : m_path(path)
b30b6c
        , m_frameCount(0)
b30b6c
        , m_validInfo(false)
b30b6c
        , m_fileSize(0)
b30b6c
        , m_isFolder(folder)
b30b6c
        , m_isLink(link)
b30b6c
        , m_name(name) {}
b30b6c
  };
b30b6c
b30b6c
private:
b30b6c
  DvDirTreeView *m_folderTreeView;
b30b6c
  QSplitter *m_mainSplitter;
b30b6c
  QLineEdit *m_folderName;
b30b6c
  DvItemViewer *m_itemViewer;
b30b6c
  FrameCountReader m_frameCountReader;
b30b6c
b30b6c
  // folder history
b30b6c
  QList<qmodelindex> m_indexHistoryList;</qmodelindex>
b30b6c
  int m_currentPosition;
b30b6c
b30b6c
  std::vector<item> m_items;</item>
b30b6c
  TFilePath m_folder;
b30b6c
  std::string m_dayDateString;
b30b6c
  QStringList m_filter;
b30b6c
  std::map<tfilepath, item=""> m_multiFileItemMap;</tfilepath,>
b30b6c
b30b6c
private:
b30b6c
  void readFrameCount(Item &item);
b30b6c
  void readInfo(Item &item);
b30b6c
b30b6c
  void refreshCurrentFolderItems();
b30b6c
b30b6c
  DvItemListModel::Status getItemVersionControlStatus(
b96f40
      const SceneBrowser::Item &item);
b30b6c
};
b30b6c
b30b6c
//-----------------------------------------------------------
b30b6c
b30b6c
#endif