2 #include <Library/LibraryInterface.hpp>
4 #include <score/application/GUIApplicationContext.hpp>
5 #include <score/tools/std/StringHash.hpp>
6 #include <score/widgets/IconProvider.hpp>
8 #include <QFileIconProvider>
9 #include <QFileSystemModel>
10 #include <QGuiApplication>
14 #include <ossia/detail/hash_map.hpp>
15 #include <ossia/detail/hash_map.hpp>
24 : QFileSystemModel{parent}
26 setIconProvider(&score::IconProvider::instance());
50 auto lst = lib.acceptedFiles();
51 for(
const auto& ext : lib.acceptedFiles())
63 types.insert(t.toUpper());
67 setNameFilters(types.values());
68 setResolveSymlinks(
true);
69 setFilter(QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot);
71 for(
auto& lib : lib_setup)
73 for(
const auto& str : lib.acceptedMimeTypes())
75 m_mimeTypes.push_back(str);
76 m_mimeActions[str] = &lib;
81 #if defined(__clang__)
82 static constexpr
bool supportsDisablingSorting() noexcept
84 return []<
typename T>(T* fsm) constexpr {
85 return requires { fsm->setOption(T::DontSort); };
86 }((QFileSystemModel*)
nullptr);
89 void setSorting(
bool b) noexcept
91 [b]<
typename T>(T&
self) {
92 if constexpr(T::supportsDisablingSorting())
94 static_assert(T::supportsDisablingSorting());
95 self.setOption(T::DontSort, !b);
100 bool isSorting() noexcept
102 return []<
typename T>(T& fsm) {
103 if constexpr(supportsDisablingSorting())
105 static_assert(requires { fsm.setOption(T::DontSort); });
106 return !fsm.testOption(T::DontSort);
115 static constexpr
bool supportsDisablingSorting() noexcept {
return false; }
116 void setSorting(
bool b) noexcept { }
117 bool isSorting() noexcept {
return true; }
120 Qt::ItemFlags flags(
const QModelIndex& index)
const override
122 Qt::ItemFlags f = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled
123 | Qt::ItemIsDropEnabled;
126 f |= Qt::ItemIsEditable;
131 QStringList mimeTypes()
const override {
return m_mimeTypes; }
134 const QMimeData* data, Qt::DropAction action,
int row,
int column,
135 const QModelIndex& parent)
override
137 const QFileInfo f = fileInfo(parent);
138 const QDir d = f.isDir() ? QDir(f.canonicalFilePath()) : f.absoluteDir();
139 for(
const auto& fmt : data->formats())
141 auto it = m_mimeActions.find(fmt);
142 if(it != m_mimeActions.end())
144 if(it->second->onDrop(*data, row, column, d))
152 QVariant data(
const QModelIndex& index,
int role)
const override
154 if(role == Qt::DecorationRole)
157 return score::IconProvider::folderIcon();
161 return QFileSystemModel::data(index, role);
164 QStringList m_mimeTypes;
165 ossia::hash_map<QString, LibraryInterface*> m_mimeActions;
Definition: FileSystemModel.hpp:21
Definition: LibraryInterface.hpp:22
Definition: LibraryInterface.hpp:44
void insert(std::unique_ptr< score::InterfaceBase > e) final override
insert Register a new factory.
Definition: InterfaceList.hpp:98
const T & interfaces() const
Access to a specific interface list.
Definition: ApplicationContext.hpp:67
Specializes ApplicationContext with the QMainWindow.
Definition: GUIApplicationContext.hpp:15