[vlc-devel] commit: Qt4: replace Podcast add / remove buttons with plain icons ( Jakob Leben )
git version control
git at videolan.org
Mon Nov 9 20:26:49 CET 2009
vlc | branch: master | Jakob Leben <jleben at videolan.org> | Mon Nov 9 20:24:41 2009 +0100| [e9c40e538e72711e037d021876396a46a6062b82] | committer: Jakob Leben
Qt4: replace Podcast add / remove buttons with plain icons
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e9c40e538e72711e037d021876396a46a6062b82
---
modules/gui/qt4/components/playlist/playlist.cpp | 2 +-
modules/gui/qt4/components/playlist/selector.cpp | 40 ++++++++++++----------
modules/gui/qt4/components/playlist/selector.hpp | 23 +-----------
modules/gui/qt4/util/customwidgets.cpp | 30 ++++++++++++++++
modules/gui/qt4/util/customwidgets.hpp | 19 ++++++++++
5 files changed, 74 insertions(+), 40 deletions(-)
diff --git a/modules/gui/qt4/components/playlist/playlist.cpp b/modules/gui/qt4/components/playlist/playlist.cpp
index b91bbcb..7c79374 100644
--- a/modules/gui/qt4/components/playlist/playlist.cpp
+++ b/modules/gui/qt4/components/playlist/playlist.cpp
@@ -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 );
diff --git a/modules/gui/qt4/components/playlist/selector.cpp b/modules/gui/qt4/components/playlist/selector.cpp
index 946e37d..9a59a9f 100644
--- a/modules/gui/qt4/components/playlist/selector.cpp
+++ b/modules/gui/qt4/components/playlist/selector.cpp
@@ -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;
diff --git a/modules/gui/qt4/components/playlist/selector.hpp b/modules/gui/qt4/components/playlist/selector.hpp
index e7100e3..3682b27 100644
--- a/modules/gui/qt4/components/playlist/selector.hpp
+++ b/modules/gui/qt4/components/playlist/selector.hpp
@@ -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
diff --git a/modules/gui/qt4/util/customwidgets.cpp b/modules/gui/qt4/util/customwidgets.cpp
index 820c8d3..e90f2b0 100644
--- a/modules/gui/qt4/util/customwidgets.cpp
+++ b/modules/gui/qt4/util/customwidgets.cpp
@@ -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
***************************************************************************/
diff --git a/modules/gui/qt4/util/customwidgets.hpp b/modules/gui/qt4/util/customwidgets.hpp
index 3037efa..fce9359 100644
--- a/modules/gui/qt4/util/customwidgets.hpp
+++ b/modules/gui/qt4/util/customwidgets.hpp
@@ -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
*****************************************************************/
More information about the vlc-devel
mailing list