Keyboard shortcuts to preview/add sounds from sidebar (#5427)

- Extract file item preview start and end into new methods `previewFileItem` and `stopPreview`.
- Add event handlers:
  - `keyPressEvent` to allow auto preview (on up/down arrow navigation), manual preview (space), and send to editors (enter)
  - `keyReleaseEvent` to end previews when preview key is released
  - `hideEvent` to end previews when switching sidebar tab or hiding sidebar
- Functions that operate on a `FileItem` now take it as an argument instead of using a member variable
- `getContextActions` provides menu items for sending clips to the song editor and BB editor with minimal duplicate code
- Some formatting changes in affected code
- Replace many instances of `NULL` with `nullptr`
This commit is contained in:
Spekular
2020-10-03 21:31:13 +02:00
committed by GitHub
parent e5f1007ebb
commit 109a7c4735
2 changed files with 313 additions and 180 deletions

View File

@@ -63,9 +63,9 @@ public:
private slots:
void reloadTree( void );
void expandItems( QTreeWidgetItem * item=NULL, QList<QString> expandedDirs = QList<QString>() );
void expandItems( QTreeWidgetItem * item=nullptr, QList<QString> expandedDirs = QList<QString>() );
// call with item=NULL to filter the entire tree
bool filterItems( const QString & filter, QTreeWidgetItem * item=NULL );
bool filterItems( const QString & filter, QTreeWidgetItem * item=nullptr );
void giveFocusToFilter();
private:
@@ -105,29 +105,38 @@ protected:
void mousePressEvent( QMouseEvent * me ) override;
void mouseMoveEvent( QMouseEvent * me ) override;
void mouseReleaseEvent( QMouseEvent * me ) override;
void keyPressEvent( QKeyEvent * ke ) override;
void keyReleaseEvent( QKeyEvent * ke ) override;
void hideEvent( QHideEvent * he ) override;
private:
//! Start a preview of a file item
void previewFileItem(FileItem* file);
//! If a preview is playing, stop it.
void stopPreview();
void handleFile( FileItem * fi, InstrumentTrack * it );
void openInNewInstrumentTrack( TrackContainer* tc );
void openInNewInstrumentTrack( TrackContainer* tc, FileItem* item );
bool m_mousePressed;
QPoint m_pressPos;
//! This should only be accessed or modified when m_pphMutex is held
PlayHandle* m_previewPlayHandle;
QMutex m_pphMutex;
FileItem * m_contextMenuItem;
QList<QAction*> getContextActions(FileItem* item, bool songEditor);
private slots:
void activateListItem( QTreeWidgetItem * item, int column );
void openInNewInstrumentTrackBBE( void );
void openInNewInstrumentTrackSE( void );
void sendToActiveInstrumentTrack( void );
void openInNewInstrumentTrack( FileItem* item, bool songEditor );
bool openInNewSampleTrack( FileItem* item );
void sendToActiveInstrumentTrack( FileItem* item );
void updateDirectory( QTreeWidgetItem * item );
void openContainingFolder();
void openContainingFolder( FileItem* item );
} ;
@@ -234,6 +243,11 @@ public:
return( m_handling );
}
inline bool isTrack( void ) const
{
return m_handling == LoadAsPreset || m_handling == LoadByPlugin;
}
QString extension( void );
static QString extension( const QString & file );