Commit e9c40e53 authored by jpd's avatar jpd
Browse files

Qt4: replace Podcast add / remove buttons with plain icons

parent 77ed8c31
......@@ -50,7 +50,7 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i ) : p_intf ( _p_i )
/* Source Selector */
selector = new PLSelector( this, p_intf );
QVBoxLayout *selBox = new QVBoxLayout();
selBox->setContentsMargins(0,5,0,0);
selBox->setContentsMargins(5,5,5,0);
selBox->addWidget( selector );
QGroupBox *selGroup = new QGroupBox( qtr( "Media Browser") );
selGroup->setLayout( selBox );
......
......@@ -33,6 +33,7 @@
#include "qt4.hpp"
#include "../../dialogs_provider.hpp"
#include "playlist.hpp"
#include "util/customwidgets.hpp"
#include <QVBoxLayout>
#include <QHeaderView>
......@@ -44,41 +45,49 @@
#include <vlc_services_discovery.h>
PLSelItem::PLSelItem ( QTreeWidgetItem *i, const QString& text )
: qitem(i), btnAction( NULL )
: qitem(i), lblAction( NULL)
{
layout = new QHBoxLayout();
layout->setContentsMargins(0,0,0,0);
layout->addSpacing( 3 );
lbl = new QLabel( text );
lbl->setMargin(3);
layout->addWidget(lbl);
layout->addWidget(lbl, 1);
setLayout( layout );
setMinimumHeight( 22 ); //Action icon height plus 6
}
void PLSelItem::addAction( ItemAction act, const QString& tooltip )
{
if( btnAction ) return;
if( lblAction ) return; //might change later
QIcon icon;
switch( act )
{
case ADD_ACTION:
btnAction = new QPushButton("+"); break;
icon = QIcon( ":/buttons/playlist/playlist_add" ); break;
case RM_ACTION:
btnAction = new QPushButton("-"); break;
icon = QIcon( ":/buttons/playlist/playlist_remove" ); break;
}
if( !tooltip.isEmpty() ) btnAction->setToolTip( tooltip );
btnAction->setMaximumWidth(23);
layout->addWidget( btnAction );
btnAction->hide();
lblAction = new QVLCIconLabel( icon );
if( !tooltip.isEmpty() ) lblAction->setToolTip( tooltip );
layout->addWidget( lblAction, 0 );
lblAction->hide();
layout->addSpacing( 3 );
CONNECT( btnAction, clicked(), this, triggerAction() );
CONNECT( lblAction, clicked(), this, triggerAction() );
}
void PLSelItem::showAction() { if( btnAction ) btnAction->show(); }
void PLSelItem::showAction() { if( lblAction ) lblAction->show(); }
void PLSelItem::hideAction() { if( btnAction ) btnAction->hide(); }
void PLSelItem::hideAction() { if( lblAction ) lblAction->hide(); }
void PLSelItem::setText( const QString& text ) { lbl->setText( text ); }
......@@ -89,18 +98,13 @@ void PLSelItem::leaveEvent( QEvent *ev ){ hideAction(); }
PLSelector::PLSelector( QWidget *p, intf_thread_t *_p_intf )
: QTreeWidget( p ), p_intf(_p_intf)
{
/* custom QItemDelegate just to assure the minimum row height,
which otherwise fails when new child item is inserted */
setFrameStyle( QFrame::NoFrame );
viewport()->setAutoFillBackground( false );
setIconSize( QSize( 24,24 ) );
setIndentation( 10 );
header()->hide();
//setHeaderLabel( qtr( "Medias" ) );
//header()->setMovable( false );
setRootIsDecorated( false );
setAlternatingRowColors( false );
setItemDelegate( new PLSelectorDelegate() );
podcastsParent = NULL;
podcastsParentId = -1;
......
......@@ -42,6 +42,7 @@
#include "qt4.hpp"
class PlaylistWidget;
class QVLCIconLabel;
enum SelectorItemType {
CATEGORY_TYPE,
......@@ -90,31 +91,11 @@ private:
void enterEvent( QEvent* );
void leaveEvent( QEvent* );
QTreeWidgetItem* qitem;
QPushButton* btnAction;
QVLCIconLabel *lblAction;
QLabel *lbl;
QHBoxLayout *layout;
};
class PLSelectorDelegate : public QStyledItemDelegate
{
private:
/*void paint ( QPainter * painter,
const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
if( index.data( TYPE_ROLE ).toInt() == CATEGORY_TYPE )
painter->fillRect( option.rect, QColor( 200,200,200 ) );
QRect r = option.rect;
r.setLeft( r.left() + 5 );
painter->drawText( r, Qt::AlignLeft | Qt::AlignVCenter, index.data().toString() );
}*/
QSize sizeHint ( const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
QSize sz = QStyledItemDelegate::sizeHint( option, index );
if( sz.height() < 23 ) sz.setHeight(23);
return sz;
}
};
Q_DECLARE_METATYPE( playlist_item_t *);
Q_DECLARE_METATYPE( input_item_t *);
class PLSelector: public QTreeWidget
......
......@@ -146,6 +146,36 @@ void SearchLineEdit::updateText( const QString& text )
emit textChanged( text );
}
QVLCIconLabel::QVLCIconLabel( const QIcon& i, QWidget *p )
: QLabel( p ), icon( i )
{
setPixmap( icon.pixmap( pixmapSize( QIcon::Normal ), QIcon::Normal ) );
}
void QVLCIconLabel::setIcon( const QIcon& i )
{ icon = i; }
void QVLCIconLabel::enterEvent( QEvent * )
{
setPixmap( icon.pixmap( pixmapSize( QIcon::Active ), QIcon::Active ) );
}
void QVLCIconLabel::leaveEvent( QEvent * )
{
setPixmap( icon.pixmap( pixmapSize( QIcon::Normal ), QIcon::Normal ) );
}
void QVLCIconLabel::mouseReleaseEvent( QMouseEvent * )
{
emit clicked();
}
QSize QVLCIconLabel::pixmapSize( QIcon::Mode mode, QIcon::State state )
{
QList<QSize> sizes = icon.availableSizes( mode, state );
if( sizes.isEmpty() ) sizes = icon.availableSizes();
return ( !sizes.isEmpty() ? sizes[0] : QSize() );
}
/***************************************************************************
* Hotkeys converters
***************************************************************************/
......
......@@ -28,6 +28,8 @@
#define _CUSTOMWIDGETS_H_
#include <QLineEdit>
#include <QLabel>
#include <QIcon>
/**
This class provides a QLineEdit which contains a greyed-out hinting
......@@ -74,6 +76,23 @@ signals:
void textChanged( const QString& );
};
class QVLCIconLabel : public QLabel
{
Q_OBJECT
public:
QVLCIconLabel( const QIcon&, QWidget *parent = 0 );
void setIcon( const QIcon& );
signals:
void clicked();
protected:
virtual void enterEvent( QEvent * );
virtual void leaveEvent( QEvent * );
virtual void mouseReleaseEvent( QMouseEvent * );
private:
inline QSize pixmapSize( QIcon::Mode = QIcon::Normal, QIcon::State = QIcon::Off );
QIcon icon;
};
/*****************************************************************
* Custom views
*****************************************************************/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment