From: Jakob Leben Date: Thu, 4 Feb 2010 08:19:00 +0000 (+0100) Subject: Qt: neat and crispy location bar, new location buttons X-Git-Tag: 1.1.0-ff~435 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=c5b155b60374786cfe8011d294db489bf39342d3;hp=4fe7b1248d1efb1f3d4970c39db646de6bb3e9e6;p=vlc Qt: neat and crispy location bar, new location buttons --- diff --git a/modules/gui/qt4/components/playlist/standardpanel.cpp b/modules/gui/qt4/components/playlist/standardpanel.cpp index 46f5d34bb0..80b0bfdf0a 100644 --- a/modules/gui/qt4/components/playlist/standardpanel.cpp +++ b/modules/gui/qt4/components/playlist/standardpanel.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include @@ -456,33 +457,33 @@ LocationBar::LocationBar( PLModel *m ) model = m; mapper = new QSignalMapper( this ); CONNECT( mapper, mapped( int ), this, invoke( int ) ); + + box = new QHBoxLayout; + box->setSpacing( 0 ); + setLayout( box ); } void LocationBar::setIndex( const QModelIndex &index ) { - clear(); - QAction *prev = NULL; + qDeleteAll( buttons ); + buttons.clear(); QModelIndex i = index; - QFont font; - QFontMetrics metrics( font ); - font.setBold( true ); + bool bold = true; while( true ) { PLItem *item = model->getItem( i ); - QToolButton *btn = new QToolButton; char *fb_name = input_item_GetTitleFbName( item->inputItem() ); QString text = qfu(fb_name); free(fb_name); - text = QString("> ") + metrics.elidedText( text, Qt::ElideRight, 150 ); - btn->setText( text ); - btn->setFont( font ); - prev = insertWidget( prev, btn ); + QToolButton *btn = new LocationButton( text, bold ); + box->insertWidget( 0, btn ); + buttons.append( btn ); mapper->setMapping( btn, item->id() ); CONNECT( btn, clicked( ), mapper, map( ) ); - font = QFont(); + bold = false; if( i.isValid() ) i = i.parent(); else break; @@ -495,3 +496,38 @@ void LocationBar::invoke( int i_id ) setIndex( index ); emit invoked ( index ); } + +LocationButton::LocationButton( const QString &text, bool bold ) +{ + QFont font; + font.setBold( bold ); + setFont( font ); + metrics = new QFontMetrics( font ); + setText( metrics->elidedText( text, Qt::ElideRight, 150 ) ); +} + +void LocationButton::paintEvent ( QPaintEvent * event ) +{ + QStyleOptionButton option; + option.initFrom( this ); + option.rect = rect(); + option.text = text(); + option.features = QStyleOptionButton::Flat; + option.state |= QStyle::State_Enabled; + option.state |= isChecked() ? QStyle::State_On : QStyle::State_Off; + if( isDown() ) option.state |= QStyle::State_Sunken; + QPainter p( this ); + style()->drawControl( QStyle::CE_PushButtonBevel, &option, &p ); + option.rect.setLeft( 18 ); + p.drawText( option.rect, Qt::AlignVCenter, + metrics->elidedText( text(), Qt::ElideRight, option.rect.width() - 5 ) ); + option.rect = QRect( 0, 0, 18, height() ); + style()->drawPrimitive( QStyle::PE_IndicatorArrowRight, &option, &p ); +} + +QSize LocationButton::sizeHint() const +{ + QSize s( metrics->boundingRect( text() ).size() ); + s += QSize( 25, 10 ); + return s; +} diff --git a/modules/gui/qt4/components/playlist/standardpanel.hpp b/modules/gui/qt4/components/playlist/standardpanel.hpp index 7df1cae018..0aedccf6b0 100644 --- a/modules/gui/qt4/components/playlist/standardpanel.hpp +++ b/modules/gui/qt4/components/playlist/standardpanel.hpp @@ -110,7 +110,7 @@ private slots: void browseInto( input_item_t * ); }; -class LocationBar : public QToolBar +class LocationBar : public QWidget { Q_OBJECT; public: @@ -123,6 +123,18 @@ private slots: private: PLModel *model; QSignalMapper *mapper; + QHBoxLayout *box; + QList buttons; +}; + +class LocationButton : public QToolButton +{ + public: + LocationButton( const QString &, bool bold ); + private: + void paintEvent ( QPaintEvent * event ); + QSize sizeHint() const; + QFontMetrics *metrics; }; #endif