diff --git a/data/themes/default/edit-find.png b/data/themes/default/edit-find.png new file mode 100644 index 000000000..1b7a25280 Binary files /dev/null and b/data/themes/default/edit-find.png differ diff --git a/include/resources_browser.h b/include/resources_browser.h index e63109832..8f8c22e7f 100644 --- a/include/resources_browser.h +++ b/include/resources_browser.h @@ -29,6 +29,7 @@ #include "side_bar_widget.h" class QAction; +class QLabel; class ResourcesItem; class ResourcesTreeModel; class ResourcesTreeView; @@ -58,6 +59,7 @@ public: private slots: void showContextMenu( const QPoint & _pos ); + void updateFilterStatus(); private: @@ -68,6 +70,8 @@ private: ResourcesTreeModel * m_treeModel; ResourcesTreeView * m_treeView; + QLabel * m_filterStatusLabel; + } ; diff --git a/include/resources_item.h b/include/resources_item.h index c92a82f81..88a7abc32 100644 --- a/include/resources_item.h +++ b/include/resources_item.h @@ -159,6 +159,11 @@ public: return m_treeItem; } + const ResourcesTreeItem * treeItem( void ) const + { + return m_treeItem; + } + const QDateTime & lastMod( void ) const { return m_lastMod; diff --git a/include/resources_tree_model.h b/include/resources_tree_model.h index 5ecabff33..74b34d7e6 100644 --- a/include/resources_tree_model.h +++ b/include/resources_tree_model.h @@ -75,6 +75,9 @@ public: return treeItem( _idx )->item(); } + int totalItems() const; + int shownItems() const; + private: bool filterItems( ResourcesTreeItem * _item, diff --git a/src/core/resources_tree_model.cpp b/src/core/resources_tree_model.cpp index 0ac1381e5..8a76c6da1 100644 --- a/src/core/resources_tree_model.cpp +++ b/src/core/resources_tree_model.cpp @@ -195,6 +195,42 @@ void ResourcesTreeModel::setFilter( const QString & _s ) +int ResourcesTreeModel::totalItems() const +{ + const ResourcesDB::ItemList & items = m_db->items(); + int num = 0; + foreach( const ResourcesItem * i, items ) + { + if( i->type() != ResourcesItem::TypeDirectory ) + { + ++num; + } + } + return num; +} + + + + +int ResourcesTreeModel::shownItems() const +{ + const ResourcesDB::ItemList & items = m_db->items(); + int num = 0; + foreach( const ResourcesItem * i, items ) + { + if( i->type() != ResourcesItem::TypeDirectory && + i->treeItem()->isHidden() == false ) + { + ++num; + } + } + return num; +} + + + + + bool ResourcesTreeModel::filterItems( ResourcesTreeItem * _item, const QModelIndex & _parent, const QStringList & _keywords ) diff --git a/src/gui/resources_browser.cpp b/src/gui/resources_browser.cpp index db3b9f7ba..6846aa25d 100644 --- a/src/gui/resources_browser.cpp +++ b/src/gui/resources_browser.cpp @@ -23,6 +23,7 @@ */ #include +#include #include #include @@ -75,25 +76,41 @@ ResourcesBrowser::ResourcesBrowser( QWidget * _parent ) : m_treeModel = new ResourcesTreeModel( engine::getResourcesProvider()->database() ); + // create filter UI + QHBoxLayout * filterLayout = new QHBoxLayout; + + QLabel * filterPixmap = new QLabel; + filterPixmap->setPixmap( embed::getIconPixmap( "edit-find" ) ); + + QLineEdit * filterEdit = new QLineEdit; + + m_filterStatusLabel = new QLabel; + + filterLayout->addWidget( filterPixmap ); + filterLayout->addWidget( filterEdit ); + filterLayout->addWidget( m_filterStatusLabel ); + // create an according tree-view for our tree-model m_treeView = new ResourcesTreeView( m_treeModel, contentParent() ); - QLineEdit * filterEdit = new QLineEdit ( contentParent() ); - // set up context menu handling m_treeView->setContextMenuPolicy( Qt::CustomContextMenu ); connect( m_treeView, SIGNAL( customContextMenuRequested( const QPoint & ) ), this, SLOT( showContextMenu( const QPoint & ) ) ); - // add widgets to us (we're a SideBarWidget) + // add widgets/layouts to us (we're a SideBarWidget) + addContentLayout( filterLayout ); addContentWidget( m_treeView ); - addContentWidget( filterEdit ); // 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() ) ); + connect( m_treeModel, SIGNAL( itemsChanged() ), + this, SLOT( updateFilterStatus() ) ); // setup actions to be used in context menu for( int i = 0;i < (int) ( sizeof( resourcesBrowserActions ) / @@ -189,6 +206,16 @@ void ResourcesBrowser::showContextMenu( const QPoint & _pos ) +void ResourcesBrowser::updateFilterStatus() +{ + m_filterStatusLabel->setText( QString( "%1/%2" ). + arg( m_treeModel->shownItems() ). + arg( m_treeModel->totalItems() ) ); +} + + + + void ResourcesBrowser::triggerAction( Actions _action, ResourcesItem * _item ) { // TODO