1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-13 04:21:51 +02:00

add a collapse button to the dynamic control widget too

This commit is contained in:
Leo Franchi 2010-12-11 15:59:19 -05:00
parent eed7a33578
commit 4460f3ce60
12 changed files with 73 additions and 26 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 650 B

BIN
data/images/list-add.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 564 B

View File

@ -59,6 +59,7 @@
<file>./data/images/view-toggle-pressed-left.png</file>
<file>./data/images/view-toggle-pressed-right.png</file>
<file>./data/images/list-add.png</file>
<file>./data/images/arrow-up-double.png</file>
<file>./data/images/volume-icon-full.png</file>
<file>./data/images/volume-icon-muted.png</file>
<file>./data/images/volume-slider-bkg.png</file>

View File

@ -16,7 +16,8 @@
#include "DynamicControl.h"
Tomahawk::DynamicControl::DynamicControl()
Tomahawk::DynamicControl::DynamicControl( const QStringList& typeSelectors )
: m_typeSelectors( typeSelectors )
{
}
@ -26,9 +27,10 @@ Tomahawk::DynamicControl::~DynamicControl()
}
Tomahawk::DynamicControl::DynamicControl(const QString& selectedType, QObject* parent)
Tomahawk::DynamicControl::DynamicControl(const QString& selectedType, const QStringList& typeSelectors, QObject* parent)
: QObject(parent)
, m_selectedType( selectedType )
, m_typeSelectors( typeSelectors )
{
}

View File

@ -45,8 +45,7 @@ class DynamicControl : public QObject
Q_PROPERTY( QString input READ input WRITE setInput )
public:
// eff this :P
DynamicControl();
DynamicControl( const QStringList& typeSelectors = QStringList() );
virtual ~DynamicControl();
@ -93,7 +92,7 @@ public slots:
protected:
// Private constructor, you can't make one. Get it from your Generator.
explicit DynamicControl( const QString& selectedType, QObject* parent = 0 );
explicit DynamicControl( const QString& selectedType, const QStringList& typeSelectors, QObject* parent = 0 );
QString m_match;
QString m_input;

View File

@ -22,8 +22,8 @@
#include <QLineEdit>
Tomahawk::EchonestControl::EchonestControl( const QString& type, QObject* parent )
: DynamicControl ( type.isEmpty() ? "Artist" : type, parent )
Tomahawk::EchonestControl::EchonestControl( const QString& type, const QStringList& typeSelectors, QObject* parent )
: DynamicControl ( type.isEmpty() ? "Artist" : type, typeSelectors, parent )
{
updateWidgets();
}
@ -70,6 +70,7 @@ Tomahawk::EchonestControl::updateWidgets()
match->addItem( "Similar To", Echonest::DynamicPlaylist::ArtistRadioType );
input->setPlaceholderText( "Artist name" );
input->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Ignored );
connect( match, SIGNAL( currentIndexChanged(int) ), this, SLOT( updateData() ) );
connect( input, SIGNAL( textChanged(QString) ), this, SLOT( updateData() ) );

View File

@ -41,7 +41,7 @@ private slots:
void updateData();
protected:
explicit EchonestControl( const QString& type, QObject* parent = 0 );
explicit EchonestControl( const QString& type, const QStringList& typeSelectors, QObject* parent = 0 );
private:
void updateWidgets();

View File

@ -33,7 +33,7 @@ EchonestFactory::create()
EchonestGenerator::EchonestGenerator ( QObject* parent )
: GeneratorInterface ( parent )
{
m_typeSelectors << "Variety" << "Artist" << "Description" << "Tempo" << "Duration" << "Loudness"
m_typeSelectors << "Artist" << "Variety" << "Description" << "Tempo" << "Duration" << "Loudness"
<< "Danceability" << "Energy" << "Artist Familiarity" << "Artist Hotttnesss" << "Song Familiarity"
<< "Longitude" << "Latitude" << "Mode" << "Key" << "Sorting";
m_type = "echonest";
@ -49,7 +49,7 @@ EchonestGenerator::~EchonestGenerator()
dyncontrol_ptr
EchonestGenerator::createControl( const QString& type ) const
{
return dyncontrol_ptr( new EchonestControl( type ) );
return dyncontrol_ptr( new EchonestControl( type, m_typeSelectors ) );
}
void

View File

@ -79,7 +79,7 @@ void
DynamicControlList::setControls(const QList< dyncontrol_ptr >& controls)
{
foreach( const dyncontrol_ptr& control, controls ) {
m_controls << new DynamicControlWidget( control, false, this );
m_controls << new DynamicControlWidget( control, false, false, this );
}
onShown( this );
}
@ -114,6 +114,7 @@ DynamicControlList::onShown( QWidget* w )
m_layout->addWidget( control );
control->show();
control->setShowPlusButton( control == m_controls.last() );
control->setShowCollapseButton( control == m_controls.last() );
}
}

View File

@ -28,10 +28,12 @@
using namespace Tomahawk;
DynamicControlWidget::DynamicControlWidget( const Tomahawk::dyncontrol_ptr& control, bool showPlus, QWidget* parent )
DynamicControlWidget::DynamicControlWidget( const Tomahawk::dyncontrol_ptr& control, bool showPlus, bool showCollapse, QWidget* parent )
: QWidget(parent)
, m_showPlus( showPlus )
, m_showCollapse( showCollapse )
, m_plusButton( 0 )
, m_collapseButton( 0 )
, m_control( control )
, m_typeSelector( 0 )
, m_layout( 0 )
@ -53,21 +55,35 @@ DynamicControlWidget::DynamicControlWidget( const Tomahawk::dyncontrol_ptr& cont
m_plusButton->setContentsMargins( 0, 0, 0, 0 );
m_plusButton->hide();
m_collapseButton= new QToolButton( this );
m_collapseButton->setIcon( QIcon( RESPATH "images/arrow-up-double.png" ) );
m_collapseButton->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
m_collapseButton->setIconSize( QSize( 16, 16 ) );
m_collapseButton->setToolButtonStyle( Qt::ToolButtonIconOnly );
m_collapseButton->setAutoRaise( true );
m_collapseButton->setContentsMargins( 0, 0, 0, 0 );
m_collapseButton->hide();
connect( m_typeSelector, SIGNAL( currentIndexChanged( QString ) ), SLOT( typeSelectorChanged( QString ) ) );
if( !control.isNull() ) {
foreach( const QString& type, control->typeSelectors() )
m_typeSelector->addItem( type );
m_layout->addWidget( m_typeSelector, 1, Qt::AlignLeft );
m_layout->addWidget( m_control->matchSelector(), 1, Qt::AlignCenter );
m_layout->addWidget( m_control->inputField(), 1, Qt::AlignRight );
m_layout->insertWidget( 0, m_typeSelector, 0, Qt::AlignLeft );
m_layout->insertWidget( 1, m_control->matchSelector(), 0, Qt::AlignCenter );
m_layout->insertWidget( 2, m_control->inputField(), 1, Qt::AlignAbsolute );
}
if( m_showPlus ) {
m_layout->addWidget( m_plusButton, 0, Qt::AlignRight );
if( m_showCollapse ) {
m_layout->insertWidget( 3, m_collapseButton, 0, Qt::AlignRight );
m_plusButton->show();
}
if( m_showPlus ) {
m_layout->insertWidget( 4, m_plusButton, 0, Qt::AlignRight );
m_plusButton->show();
}
setLayout( m_layout );
}
@ -81,15 +97,15 @@ DynamicControlWidget::typeSelectorChanged( QString type )
{
Q_ASSERT( m_layout );
// remove the two widgets, change the control,and re-add the new ones
if( m_layout->count() >= 3 )
if( m_layout->count() >= 4 )
{
m_layout->takeAt( 1 );
m_layout->takeAt( 2 );
m_layout->removeWidget( m_control->matchSelector() );
m_layout->removeWidget( m_control->inputField() );
}
m_control->setSelectedType( type );
m_layout->addWidget( m_control->matchSelector(), 0, Qt::AlignCenter );
m_layout->addWidget( m_control->inputField(), 0, Qt::AlignRight );
m_layout->insertWidget( 1, m_control->matchSelector(), 0, Qt::AlignCenter );
m_layout->insertWidget( 2, m_control->inputField(), 1, Qt::AlignAbsolute );
}
void
@ -98,7 +114,7 @@ DynamicControlWidget::setShowPlusButton(bool show)
if( m_showPlus != show ) {
if( show ) {
m_layout->addWidget( m_plusButton, 0, Qt::AlignRight );
m_layout->insertWidget( m_layout->count() - 1, m_plusButton, 0, Qt::AlignRight );
m_plusButton->show();
} else {
m_layout->removeWidget( m_plusButton );
@ -115,7 +131,25 @@ DynamicControlWidget::showPlusButton() const
return m_showPlus;
}
void DynamicControlWidget::paintEvent(QPaintEvent* e)
void
DynamicControlWidget::setShowCollapseButton(bool show)
{
if( m_showCollapse != show ) {
if( show ) {
m_layout->insertWidget( 3, m_collapseButton, 0, Qt::AlignRight );
m_collapseButton->show();
} else {
m_layout->removeWidget( m_collapseButton );
m_collapseButton->hide();
}
}
m_showCollapse = show;
}
void
DynamicControlWidget::paintEvent(QPaintEvent* e)
{
QPainter p;
p.fillRect( e->rect(), Qt::yellow );

View File

@ -36,19 +36,25 @@ class DynamicControlWidget : public QWidget
{
Q_OBJECT
public:
explicit DynamicControlWidget( const dyncontrol_ptr& control, bool showPlus = false, QWidget* parent = 0);
explicit DynamicControlWidget( const dyncontrol_ptr& control, bool showPlus = false, bool showCollaps = false, QWidget* parent = 0);
virtual ~DynamicControlWidget();
void setShowPlusButton( bool show );
bool showPlusButton() const;
void setShowCollapseButton( bool show );
virtual void paintEvent(QPaintEvent* );
private slots:
void typeSelectorChanged( QString );
private:
bool m_showPlus;
bool m_showCollapse;
QToolButton* m_plusButton;
QToolButton* m_collapseButton;
dyncontrol_ptr m_control;
QComboBox* m_typeSelector;
QHBoxLayout* m_layout;

View File

@ -43,6 +43,8 @@ DynamicWidget::DynamicWidget( const Tomahawk::dynplaylist_ptr& playlist, QWidget
m_splitter = new AnimatedSplitter( this );
m_splitter->setOrientation( Qt::Vertical );
m_splitter->setChildrenCollapsible( false );
layout()->addWidget( m_splitter );
m_controls = new DynamicControlList( m_splitter );
m_model = new PlaylistModel( this );
@ -53,7 +55,8 @@ DynamicWidget::DynamicWidget( const Tomahawk::dynplaylist_ptr& playlist, QWidget
m_splitter->addWidget( m_view );
m_splitter->setGreedyWidget( 1 );
m_splitter->show( 0 );
m_splitter->show( 0, false );
if( !m_playlist.isNull() ) {
m_controls->setControls( m_playlist->generator()->controls() );