Resource Browser - smoother gui
When you press down or up while browsing in the resource browser, it plays the sample. FIXED: When you click on the keyboard in the resource browser, and then click on the treeview, it didn't transfer focus.
This commit is contained in:
4
TODO
4
TODO
@@ -52,10 +52,10 @@
|
||||
- add FLAC as export-format?
|
||||
|
||||
Andrew Kelley's todo:
|
||||
* when you press down or up while browsing the resource browser, it should
|
||||
play the sample
|
||||
* load asdlol.mmpz. if you render it without playing it, or if you play it
|
||||
the first time, you hear unwanted artifacts.
|
||||
* VST presets don't work. when you save a project, it doesn't even save
|
||||
what you did.
|
||||
|
||||
|
||||
- automation recording:
|
||||
|
||||
@@ -61,12 +61,15 @@ public:
|
||||
private slots:
|
||||
void showContextMenu( const QPoint & _pos );
|
||||
void startItemPreview( const QModelIndex & _idx );
|
||||
void setFocusAndPreview( const QModelIndex & _idx );
|
||||
void stopItemPreview( const QModelIndex & _idx );
|
||||
void stopPreview();
|
||||
void triggerDefaultAction( const QModelIndex & _idx );
|
||||
void updateFilterStatus();
|
||||
void manageDirectories();
|
||||
|
||||
void currentChanged( const QModelIndex &, const QModelIndex & );
|
||||
|
||||
|
||||
private:
|
||||
void triggerAction( Actions _action, ResourceItem * _item );
|
||||
@@ -76,8 +79,10 @@ private:
|
||||
// the object that will preview individual resources
|
||||
ResourcePreviewer m_previewer;
|
||||
|
||||
QLineEdit * m_filterEdit;
|
||||
// our tree model on-top of a ResourceDB
|
||||
ResourceTreeModel m_treeModel;
|
||||
|
||||
|
||||
// a view for the tree model
|
||||
ResourceTreeView * m_treeView;
|
||||
@@ -88,3 +93,5 @@ private:
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/* vim: set tw=0 noexpandtab: */
|
||||
|
||||
@@ -41,6 +41,10 @@ public slots:
|
||||
void setFilter( const QString & _s );
|
||||
void updateFilter( void );
|
||||
|
||||
void currentChanged( const QModelIndex & current,
|
||||
const QModelIndex & previous );
|
||||
void selectionChanged( const QItemSelection & selected,
|
||||
const QItemSelection & deselected );
|
||||
|
||||
protected:
|
||||
virtual void startDrag( Qt::DropActions supportedActions );
|
||||
@@ -48,14 +52,21 @@ protected:
|
||||
|
||||
private:
|
||||
ResourceTreeModel * m_tm;
|
||||
|
||||
|
||||
QString m_lastFilter;
|
||||
|
||||
|
||||
signals:
|
||||
void dragStarted();
|
||||
|
||||
void treeViewCurrentChanged( const QModelIndex & current,
|
||||
const QModelIndex & previous );
|
||||
void treeViewSelectionChanged( const QItemSelection & selected,
|
||||
const QItemSelection & deselected );
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/* vim: set tw=0 noexpandtab: */
|
||||
|
||||
@@ -163,23 +163,26 @@ void ResourceDB::loadTreeItem( ResourceTreeItem * _i, QDomElement & _de )
|
||||
const QString h = e.attribute( "hash" );
|
||||
if( !h.isEmpty() )
|
||||
{
|
||||
ResourceItem * item = new ResourceItem( m_provider,
|
||||
e.attribute( "name" ),
|
||||
typeFromName( e.attribute( "type" ) ),
|
||||
baseDirFromName( e.attribute( "basedir" ) ),
|
||||
e.attribute( "path" ),
|
||||
h,
|
||||
e.attribute( "author" ),
|
||||
e.attribute( "tags" ),
|
||||
e.attribute( "size" ).toInt(),
|
||||
QDateTime::fromString( e.attribute( "lastmod" ), Qt::ISODate ) );
|
||||
addItem( item );
|
||||
ResourceTreeItem * treeItem = new ResourceTreeItem( _i, item );
|
||||
if( item->type() == ResourceItem::TypeDirectory )
|
||||
{
|
||||
emit directoryItemAdded( item->fullName() );
|
||||
}
|
||||
loadTreeItem( treeItem, e );
|
||||
ResourceItem * item = new ResourceItem(
|
||||
m_provider,
|
||||
e.attribute( "name" ),
|
||||
typeFromName( e.attribute( "type" ) ),
|
||||
baseDirFromName( e.attribute( "basedir" ) ),
|
||||
e.attribute( "path" ),
|
||||
h,
|
||||
e.attribute( "author" ),
|
||||
e.attribute( "tags" ),
|
||||
e.attribute( "size" ).toInt(),
|
||||
QDateTime::fromString( e.attribute( "lastmod" ),
|
||||
Qt::ISODate )
|
||||
);
|
||||
addItem( item );
|
||||
ResourceTreeItem * treeItem = new ResourceTreeItem( _i, item );
|
||||
if( item->type() == ResourceItem::TypeDirectory )
|
||||
{
|
||||
emit directoryItemAdded( item->fullName() );
|
||||
}
|
||||
loadTreeItem( treeItem, e );
|
||||
}
|
||||
}
|
||||
node = node.nextSibling();
|
||||
@@ -328,3 +331,5 @@ void ResourceDB::recursiveRemoveItems( ResourceTreeItem * parent,
|
||||
|
||||
|
||||
#include "moc_ResourceDB.cxx"
|
||||
|
||||
/* vim: set tw=0 noexpandtab: */
|
||||
|
||||
@@ -139,3 +139,4 @@ Piano * ResourcePreviewer::pianoModel()
|
||||
|
||||
#include "moc_ResourcePreviewer.cxx"
|
||||
|
||||
/* vim: set tw=0 noexpandtab: */
|
||||
|
||||
@@ -429,3 +429,4 @@ void ResourceTreeModel::setHidden( ResourceTreeItem * _item,
|
||||
|
||||
#include "moc_ResourceTreeModel.cxx"
|
||||
|
||||
/* vim: set tw=0 noexpandtab: */
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <QtGui/QLineEdit>
|
||||
#include <QtGui/QMenu>
|
||||
#include <QtGui/QPushButton>
|
||||
#include <QKeyEvent>
|
||||
|
||||
#include "ResourceBrowser.h"
|
||||
#include "ResourceFileMapper.h"
|
||||
@@ -77,6 +78,7 @@ ResourceBrowser::ResourceBrowser( QWidget * _parent ) :
|
||||
embed::getIconPixmap( "resource_browser" ),
|
||||
_parent ),
|
||||
m_previewer(),
|
||||
m_filterEdit( NULL ),
|
||||
m_treeModel( engine::resourceProvider()->database() )
|
||||
{
|
||||
// create a model which represents our database as a tree
|
||||
@@ -87,12 +89,12 @@ ResourceBrowser::ResourceBrowser( QWidget * _parent ) :
|
||||
QLabel * filterPixmap = new QLabel;
|
||||
filterPixmap->setPixmap( embed::getIconPixmap( "edit-find" ) );
|
||||
|
||||
QLineEdit * filterEdit = new QLineEdit;
|
||||
m_filterEdit = new QLineEdit;
|
||||
|
||||
m_filterStatusLabel = new QLabel;
|
||||
|
||||
filterLayout->addWidget( filterPixmap );
|
||||
filterLayout->addWidget( filterEdit );
|
||||
filterLayout->addWidget( m_filterEdit );
|
||||
filterLayout->addWidget( m_filterStatusLabel );
|
||||
|
||||
// create an according tree-view for our tree-model
|
||||
@@ -107,10 +109,15 @@ ResourceBrowser::ResourceBrowser( QWidget * _parent ) :
|
||||
// track mouse press and release events
|
||||
connect( m_treeView,
|
||||
SIGNAL( pressed( const QModelIndex & ) ),
|
||||
this, SLOT( startItemPreview( const QModelIndex & ) ) );
|
||||
this, SLOT( setFocusAndPreview( const QModelIndex & ) ) );
|
||||
connect( m_treeView,
|
||||
SIGNAL( clicked( const QModelIndex & ) ),
|
||||
this, SLOT( stopItemPreview( const QModelIndex & ) ) );
|
||||
// play the noise when a new item is selected
|
||||
connect( m_treeView, SIGNAL( treeViewCurrentChanged( const QModelIndex &,
|
||||
const QModelIndex & ) ), this,
|
||||
SLOT( currentChanged( const QModelIndex &, const QModelIndex & ) ) );
|
||||
|
||||
// setup a direct connection so preview is instantly stopped when
|
||||
// drag operation begins
|
||||
connect( m_treeView,
|
||||
@@ -148,13 +155,13 @@ ResourceBrowser::ResourceBrowser( QWidget * _parent ) :
|
||||
addContentWidget( pianoView );
|
||||
|
||||
|
||||
// instantly apply filter when typing into filterEdit
|
||||
connect( filterEdit, SIGNAL( textChanged( const QString & ) ),
|
||||
m_treeView, SLOT( setFilter( const QString & ) ) );
|
||||
connect( filterEdit, SIGNAL( textChanged( const QString & ) ),
|
||||
this, SLOT( updateFilterStatus() ) );
|
||||
// instantly apply filter when typing into m_filterEdit
|
||||
connect( m_filterEdit, SIGNAL( textChanged( const QString & ) ),
|
||||
m_treeView, SLOT( setFilter( const QString & ) ) );
|
||||
connect( m_filterEdit, SIGNAL( textChanged( const QString & ) ),
|
||||
this, SLOT( updateFilterStatus() ) );
|
||||
connect( &m_treeModel, SIGNAL( itemsChanged() ),
|
||||
this, SLOT( updateFilterStatus() ) );
|
||||
this, SLOT( updateFilterStatus() ) );
|
||||
|
||||
// setup actions to be used in context menu
|
||||
for( int i = 0; i < (int) ( sizeof( resourceBrowserActions ) /
|
||||
@@ -179,6 +186,7 @@ ResourceBrowser::ResourceBrowser( QWidget * _parent ) :
|
||||
ResourceBrowser::~ResourceBrowser()
|
||||
{
|
||||
delete m_treeView;
|
||||
delete m_filterEdit;
|
||||
}
|
||||
|
||||
|
||||
@@ -261,6 +269,17 @@ void ResourceBrowser::startItemPreview( const QModelIndex & _idx )
|
||||
}
|
||||
|
||||
|
||||
void ResourceBrowser::setFocusAndPreview( const QModelIndex & _idx )
|
||||
{
|
||||
// transfor focus to the treeview. for some reason you have to
|
||||
// setFocus to the line edit above it first.
|
||||
m_filterEdit->setFocus(Qt::MouseFocusReason);
|
||||
m_treeView->setFocus(Qt::MouseFocusReason);
|
||||
|
||||
startItemPreview( _idx );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ResourceBrowser::stopItemPreview( const QModelIndex & )
|
||||
@@ -271,6 +290,21 @@ void ResourceBrowser::stopItemPreview( const QModelIndex & )
|
||||
|
||||
|
||||
|
||||
void ResourceBrowser::currentChanged( const QModelIndex & current,
|
||||
const QModelIndex & previous )
|
||||
{
|
||||
|
||||
// stop previous previews
|
||||
stopPreview();
|
||||
|
||||
// start previewing the sound we just changed to
|
||||
startItemPreview( current );
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ResourceBrowser::stopPreview()
|
||||
{
|
||||
m_previewer.stopPreview();
|
||||
@@ -358,3 +392,4 @@ void ResourceBrowser::triggerAction( Actions _action, ResourceItem * _item )
|
||||
|
||||
#include "moc_ResourceBrowser.cxx"
|
||||
|
||||
/* vim: set tw=0 noexpandtab: */
|
||||
|
||||
@@ -62,6 +62,18 @@ void ResourceTreeView::setFilter( const QString & _s )
|
||||
}
|
||||
|
||||
|
||||
void ResourceTreeView::currentChanged( const QModelIndex & current,
|
||||
const QModelIndex & previous )
|
||||
{
|
||||
emit treeViewCurrentChanged( current, previous );
|
||||
QTreeView::currentChanged( current, previous );
|
||||
}
|
||||
void ResourceTreeView::selectionChanged( const QItemSelection & selected,
|
||||
const QItemSelection & deselected )
|
||||
{
|
||||
emit treeViewSelectionChanged( selected, deselected );
|
||||
QTreeView::selectionChanged( selected, deselected );
|
||||
}
|
||||
|
||||
|
||||
void ResourceTreeView::updateFilter( void )
|
||||
@@ -82,3 +94,5 @@ void ResourceTreeView::startDrag( Qt::DropActions supportedActions )
|
||||
|
||||
|
||||
#include "moc_ResourceTreeView.cxx"
|
||||
|
||||
/* vim: set tw=0 noexpandtab: */
|
||||
|
||||
Reference in New Issue
Block a user