Skip to content

Commit

Permalink
PluginBrowser: Tree layout and search bar
Browse files Browse the repository at this point in the history
  • Loading branch information
CYBERDEViLNL authored and CYBERDEViLNL committed Apr 2, 2019
1 parent 4dce466 commit 3ef33db
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 29 deletions.
25 changes: 15 additions & 10 deletions include/PluginBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#include "SideBarWidget.h"
#include "Plugin.h"

class QLineEdit;
class QTreeWidget;
class QTreeWidgetItem;


class PluginBrowser : public SideBarWidget
{
Expand All @@ -39,18 +43,18 @@ class PluginBrowser : public SideBarWidget
PluginBrowser( QWidget * _parent );
virtual ~PluginBrowser() = default;

private:
QWidget * m_view;
};


private slots:
void onFilterChanged( const QString & filter );

private:
void addPlugins();
void updateRootVisibility( int index );
void updateRootVisibilities();

class PluginDescList : public QWidget
{
Q_OBJECT
public:
PluginDescList(QWidget* parent);
QWidget * m_view;
QTreeWidget * m_descTree;
QTreeWidgetItem * m_lmmsRoot;
QTreeWidgetItem * m_lv2Root;
};


Expand All @@ -62,6 +66,7 @@ class PluginDescWidget : public QWidget
public:
typedef Plugin::Descriptor::SubPluginFeatures::Key PluginKey;
PluginDescWidget( const PluginKey & _pk, QWidget * _parent );
QString name() const;


protected:
Expand Down
121 changes: 102 additions & 19 deletions src/gui/PluginBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@

#include "PluginBrowser.h"

#include <QHeaderView>
#include <QLabel>
#include <QPainter>
#include <QLineEdit>
#include <QMouseEvent>
#include <QScrollArea>
#include <QPainter>
#include <QStyleOption>
#include <QTreeWidget>

#include "embed.h"
#include "Engine.h"
Expand Down Expand Up @@ -60,23 +62,91 @@ PluginBrowser::PluginBrowser( QWidget * _parent ) :
m_view );
hint->setWordWrap( true );

QScrollArea* scrollarea = new QScrollArea( m_view );
PluginDescList* descList = new PluginDescList( m_view );
scrollarea->setWidget(descList);
scrollarea->setWidgetResizable(true);
QLineEdit * searchBar = new QLineEdit( m_view );
searchBar->setPlaceholderText( "Search" );
searchBar->setMaxLength( 64 );
searchBar->setClearButtonEnabled( true );

m_descTree = new QTreeWidget( m_view );
m_descTree->setColumnCount( 1 );
m_descTree->header()->setVisible( false );
m_descTree->setIndentation( 10 );
m_descTree->setSelectionMode( QAbstractItemView::NoSelection );

connect( searchBar, SIGNAL( textEdited( const QString & ) ),
this, SLOT( onFilterChanged( const QString & ) ) );

view_layout->addWidget( hint );
view_layout->addWidget( searchBar );
view_layout->addWidget( m_descTree );

// Add LMMS root to the tree
m_lmmsRoot = new QTreeWidgetItem();
m_lmmsRoot->setText( 0, "LMMS" );
m_descTree->insertTopLevelItem( 0, m_lmmsRoot );
m_lmmsRoot->setExpanded( true );

view_layout->addWidget(hint);
view_layout->addWidget(scrollarea);
// Add LV2 root to the tree
m_lv2Root = new QTreeWidgetItem();
m_lv2Root->setText( 0, "LV2" );
m_descTree->insertTopLevelItem( 1, m_lv2Root );

// Add plugins to the tree roots
addPlugins();

// Resize
m_descTree->header()->setSectionResizeMode( QHeaderView::ResizeToContents );

// Hide empty roots
updateRootVisibilities();
}


void PluginBrowser::updateRootVisibility( int rootIndex )
{
QTreeWidgetItem * root = m_descTree->topLevelItem( rootIndex );
root->setHidden( !root->childCount() );
}


PluginDescList::PluginDescList(QWidget *parent) :
QWidget(parent)
void PluginBrowser::updateRootVisibilities()
{
QVBoxLayout* layout = new QVBoxLayout(this);
int rootCount = m_descTree->topLevelItemCount();
for (int rootIndex = 0; rootIndex < rootCount; ++rootIndex)
{
updateRootVisibility( rootIndex );
}
}


void PluginBrowser::onFilterChanged( const QString & filter )
{
int rootCount = m_descTree->topLevelItemCount();
for (int rootIndex = 0; rootIndex < rootCount; ++rootIndex)
{
QTreeWidgetItem * root = m_descTree->topLevelItem( rootIndex );

int itemCount = root->childCount();
for (int itemIndex = 0; itemIndex < itemCount; ++itemIndex)
{
QTreeWidgetItem * item = root->child( itemIndex );
PluginDescWidget * descWidget = static_cast<PluginDescWidget *>
(m_descTree->itemWidget( item, 0));
if (descWidget->name().contains(filter, Qt::CaseInsensitive))
{
item->setHidden( false );
}
else
{
item->setHidden( true );
}
}
}
}


void PluginBrowser::addPlugins()
{
QList<Plugin::Descriptor*> descs = pluginFactory->descriptors(Plugin::Instrument);
std::sort(
descs.begin(),
Expand All @@ -93,7 +163,7 @@ PluginDescList::PluginDescList(QWidget *parent) :

for (const Plugin::Descriptor* desc: descs)
{
if( desc->subPluginFeatures )
if ( desc->subPluginFeatures )
{
desc->subPluginFeatures->listSubPluginKeys(
desc,
Expand All @@ -109,13 +179,18 @@ PluginDescList::PluginDescList(QWidget *parent) :

for (const PluginKey& key : pluginKeys)
{
PluginDescWidget* p = new PluginDescWidget( key, this );
p->show();
layout->addWidget(p);
QTreeWidgetItem * item = new QTreeWidgetItem();
if ( key.desc->name == QStringLiteral("lv2instrument") )
{
m_lv2Root->addChild( item );
}
else
{
m_lmmsRoot->addChild( item );
}
PluginDescWidget* p = new PluginDescWidget( key, m_descTree );
m_descTree->setItemWidget( item, 0, p );
}

setLayout(layout);
layout->addStretch();
}


Expand All @@ -137,6 +212,14 @@ PluginDescWidget::PluginDescWidget(const PluginKey &_pk,



QString PluginDescWidget::name() const
{
return m_pluginKey.displayName();
}




void PluginDescWidget::paintEvent( QPaintEvent * )
{

Expand Down Expand Up @@ -190,7 +273,7 @@ void PluginDescWidget::leaveEvent( QEvent * _e )

void PluginDescWidget::mousePressEvent( QMouseEvent * _me )
{
if( _me->button() == Qt::LeftButton )
if ( _me->button() == Qt::LeftButton )
{
Engine::setDndPluginKey(&m_pluginKey);
new StringPairDrag("instrument",
Expand Down

0 comments on commit 3ef33db

Please sign in to comment.