1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
|
/*
* FileBrowser.h - include file for FileBrowser
*
* Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of LMMS - https://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#ifndef FILE_BROWSER_H
#define FILE_BROWSER_H
#include <QtCore/QDir>
#include <QtCore/QMutex>
#include <QTreeWidget>
#include "SideBarWidget.h"
class QLineEdit;
class FileItem;
class InstrumentTrack;
class FileBrowserTreeWidget;
class PlayHandle;
class TrackContainer;
class FileBrowser : public SideBarWidget
{
Q_OBJECT
public:
/**
Create a file browser side bar widget
@param directories '*'-separated list of directories to search for.
If a directory of factory files should be in the list it
must be the last one (for the factory files delimiter to work)
@param filter Filter as used in QDir::match
@param recurse *to be documented*
*/
FileBrowser( const QString & directories, const QString & filter,
const QString & title, const QPixmap & pm,
QWidget * parent, bool dirs_as_items = false, bool recurse = false );
virtual ~FileBrowser();
private slots:
void reloadTree( void );
void expandItems( QTreeWidgetItem * item=NULL );
// call with item=NULL to filter the entire tree
bool filterItems( const QString & filter, QTreeWidgetItem * item=NULL );
void giveFocusToFilter();
private:
virtual void keyPressEvent( QKeyEvent * ke );
void addItems( const QString & path );
FileBrowserTreeWidget * m_l;
QLineEdit * m_filterEdit;
QString m_directories; //!< Directories to search, split with '*'
QString m_filter; //!< Filter as used in QDir::match()
bool m_dirsAsItems;
bool m_recurse;
} ;
class FileBrowserTreeWidget : public QTreeWidget
{
Q_OBJECT
public:
FileBrowserTreeWidget( QWidget * parent );
virtual ~FileBrowserTreeWidget();
protected:
virtual void contextMenuEvent( QContextMenuEvent * e );
virtual void mousePressEvent( QMouseEvent * me );
virtual void mouseMoveEvent( QMouseEvent * me );
virtual void mouseReleaseEvent( QMouseEvent * me );
private:
void handleFile( FileItem * fi, InstrumentTrack * it );
void openInNewInstrumentTrack( TrackContainer* tc );
bool m_mousePressed;
QPoint m_pressPos;
PlayHandle* m_previewPlayHandle;
QMutex m_pphMutex;
FileItem * m_contextMenuItem;
private slots:
void activateListItem( QTreeWidgetItem * item, int column );
void openInNewInstrumentTrackBBE( void );
void openInNewInstrumentTrackSE( void );
void sendToActiveInstrumentTrack( void );
void updateDirectory( QTreeWidgetItem * item );
} ;
class Directory : public QTreeWidgetItem
{
public:
Directory( const QString & filename, const QString & path,
const QString & filter );
void update( void );
inline QString fullName( QString path = QString::null )
{
if( path == QString::null )
{
path = m_directories[0];
}
if( path != QString::null )
{
path += QDir::separator();
}
return( QDir::cleanPath( path + text( 0 ) ) +
QDir::separator() );
}
inline void addDirectory( const QString & dir )
{
m_directories.push_back( dir );
}
private:
void initPixmaps( void );
bool addItems( const QString & path );
static QPixmap * s_folderPixmap;
static QPixmap * s_folderOpenedPixmap;
static QPixmap * s_folderLockedPixmap;
//! Directories that lead here
//! Initially, this is just set to the current path of a directory
//! If, however, you have e.g. 'TripleOscillator/xyz' in two of the
//! file browser's search directories 'a' and 'b', this will have two
//! entries 'a/TripleOscillator' and 'b/TripleOscillator'
//! and 'xyz' in the tree widget
QStringList m_directories;
//! Filter as used in QDir::match()
QString m_filter;
int m_dirCount;
} ;
class FileItem : public QTreeWidgetItem
{
public:
enum FileTypes
{
ProjectFile,
PresetFile,
SampleFile,
SoundFontFile,
PatchFile,
MidiFile,
VstPluginFile,
UnknownFile,
NumFileTypes
} ;
enum FileHandling
{
NotSupported,
LoadAsProject,
LoadAsPreset,
LoadByPlugin,
ImportAsProject
} ;
FileItem( QTreeWidget * parent, const QString & name,
const QString & path );
FileItem( const QString & name, const QString & path );
QString fullName() const
{
return QFileInfo(m_path, text(0)).absoluteFilePath();
}
inline FileTypes type( void ) const
{
return( m_type );
}
inline FileHandling handling( void ) const
{
return( m_handling );
}
QString extension( void );
static QString extension( const QString & file );
private:
void initPixmaps( void );
void determineFileType( void );
static QPixmap * s_projectFilePixmap;
static QPixmap * s_presetFilePixmap;
static QPixmap * s_sampleFilePixmap;
static QPixmap * s_soundfontFilePixmap;
static QPixmap * s_vstPluginFilePixmap;
static QPixmap * s_midiFilePixmap;
static QPixmap * s_unknownFilePixmap;
QString m_path;
FileTypes m_type;
FileHandling m_handling;
} ;
#endif
|