FileBrowser.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. * FileBrowser.h - include file for FileBrowser
  3. *
  4. * Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  5. *
  6. * This file is part of LMMS - https://lmms.io
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program (see COPYING); if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA.
  22. *
  23. */
  24. #ifndef FILE_BROWSER_H
  25. #define FILE_BROWSER_H
  26. #include <QtCore/QDir>
  27. #include <QtCore/QMutex>
  28. #include <QTreeWidget>
  29. #include "SideBarWidget.h"
  30. class QLineEdit;
  31. class FileItem;
  32. class InstrumentTrack;
  33. class FileBrowserTreeWidget;
  34. class PlayHandle;
  35. class TrackContainer;
  36. class FileBrowser : public SideBarWidget
  37. {
  38. Q_OBJECT
  39. public:
  40. FileBrowser( const QString & directories, const QString & filter,
  41. const QString & title, const QPixmap & pm,
  42. QWidget * parent, bool dirs_as_items = false, bool recurse = false );
  43. virtual ~FileBrowser() = default;
  44. private slots:
  45. void reloadTree( void );
  46. void expandItems( QTreeWidgetItem * item=NULL, QList<QString> expandedDirs = QList<QString>() );
  47. // call with item=NULL to filter the entire tree
  48. bool filterItems( const QString & filter, QTreeWidgetItem * item=NULL );
  49. void giveFocusToFilter();
  50. private:
  51. void keyPressEvent( QKeyEvent * ke ) override;
  52. void addItems( const QString & path );
  53. FileBrowserTreeWidget * m_fileBrowserTreeWidget;
  54. QLineEdit * m_filterEdit;
  55. QString m_directories;
  56. QString m_filter;
  57. bool m_dirsAsItems;
  58. bool m_recurse;
  59. } ;
  60. class FileBrowserTreeWidget : public QTreeWidget
  61. {
  62. Q_OBJECT
  63. public:
  64. FileBrowserTreeWidget( QWidget * parent );
  65. virtual ~FileBrowserTreeWidget() = default;
  66. //! This method returns a QList with paths (QString's) of all directories
  67. //! that are expanded in the tree.
  68. QList<QString> expandedDirs( QTreeWidgetItem * item = nullptr ) const;
  69. protected:
  70. void contextMenuEvent( QContextMenuEvent * e ) override;
  71. void mousePressEvent( QMouseEvent * me ) override;
  72. void mouseMoveEvent( QMouseEvent * me ) override;
  73. void mouseReleaseEvent( QMouseEvent * me ) override;
  74. private:
  75. void handleFile( FileItem * fi, InstrumentTrack * it );
  76. void openInNewInstrumentTrack( TrackContainer* tc );
  77. bool m_mousePressed;
  78. QPoint m_pressPos;
  79. PlayHandle* m_previewPlayHandle;
  80. QMutex m_pphMutex;
  81. FileItem * m_contextMenuItem;
  82. private slots:
  83. void activateListItem( QTreeWidgetItem * item, int column );
  84. void openInNewInstrumentTrackBBE( void );
  85. void openInNewInstrumentTrackSE( void );
  86. void sendToActiveInstrumentTrack( void );
  87. void updateDirectory( QTreeWidgetItem * item );
  88. } ;
  89. class Directory : public QTreeWidgetItem
  90. {
  91. public:
  92. Directory( const QString & filename, const QString & path,
  93. const QString & filter );
  94. void update( void );
  95. inline QString fullName( QString path = QString() )
  96. {
  97. if( path.isEmpty() )
  98. {
  99. path = m_directories[0];
  100. }
  101. if( ! path.isEmpty() )
  102. {
  103. path += QDir::separator();
  104. }
  105. return( QDir::cleanPath( path + text( 0 ) ) +
  106. QDir::separator() );
  107. }
  108. inline void addDirectory( const QString & dir )
  109. {
  110. m_directories.push_back( dir );
  111. }
  112. private:
  113. void initPixmaps( void );
  114. bool addItems( const QString & path );
  115. static QPixmap * s_folderPixmap;
  116. static QPixmap * s_folderOpenedPixmap;
  117. static QPixmap * s_folderLockedPixmap;
  118. QStringList m_directories;
  119. QString m_filter;
  120. int m_dirCount;
  121. } ;
  122. class FileItem : public QTreeWidgetItem
  123. {
  124. public:
  125. enum FileTypes
  126. {
  127. ProjectFile,
  128. PresetFile,
  129. SampleFile,
  130. SoundFontFile,
  131. PatchFile,
  132. MidiFile,
  133. VstPluginFile,
  134. UnknownFile,
  135. NumFileTypes
  136. } ;
  137. enum FileHandling
  138. {
  139. NotSupported,
  140. LoadAsProject,
  141. LoadAsPreset,
  142. LoadByPlugin,
  143. ImportAsProject
  144. } ;
  145. FileItem( QTreeWidget * parent, const QString & name,
  146. const QString & path );
  147. FileItem( const QString & name, const QString & path );
  148. QString fullName() const
  149. {
  150. return QFileInfo(m_path, text(0)).absoluteFilePath();
  151. }
  152. inline FileTypes type( void ) const
  153. {
  154. return( m_type );
  155. }
  156. inline FileHandling handling( void ) const
  157. {
  158. return( m_handling );
  159. }
  160. QString extension( void );
  161. static QString extension( const QString & file );
  162. private:
  163. void initPixmaps( void );
  164. void determineFileType( void );
  165. static QPixmap * s_projectFilePixmap;
  166. static QPixmap * s_presetFilePixmap;
  167. static QPixmap * s_sampleFilePixmap;
  168. static QPixmap * s_soundfontFilePixmap;
  169. static QPixmap * s_vstPluginFilePixmap;
  170. static QPixmap * s_midiFilePixmap;
  171. static QPixmap * s_unknownFilePixmap;
  172. QString m_path;
  173. FileTypes m_type;
  174. FileHandling m_handling;
  175. } ;
  176. #endif