From 3a97ab888cbeb4ee9cb5dcadf4d68b42bf9a7d89 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 6 May 2009 13:39:48 +0000 Subject: [PATCH] (trunk qt) use the bubble-filter button patch --- qt/mainwin.cc | 73 ++++++++++++++++++++++++++++++++++++++++++--------- qt/mainwin.h | 10 ++++--- 2 files changed, 67 insertions(+), 16 deletions(-) diff --git a/qt/mainwin.cc b/qt/mainwin.cc index cae27bc4c..4500e1cec 100644 --- a/qt/mainwin.cc +++ b/qt/mainwin.cc @@ -23,7 +23,6 @@ #include #include #include -#include #include @@ -62,6 +61,22 @@ TrMainWindow :: getStockIcon( const QString& freedesktop_name, int fallback ) return QtIconLoader::icon( freedesktop_name, fallbackIcon ); } +namespace +{ + QSize calculateTextButtonSizeHint( QPushButton * button ) + { + QStyleOptionButton opt; + opt.initFrom( button ); + QString s( button->text( ) ); + if( s.isEmpty( ) ) + s = QString::fromLatin1( "XXXX" ); + QFontMetrics fm = button->fontMetrics( ); + QSize sz = fm.size( Qt::TextShowMnemonic, s ); + return button->style()->sizeFromContents( QStyle::CT_PushButton, &opt, sz, button ).expandedTo( QApplication::globalStrut( ) ); + } +} + + TrMainWindow :: TrMainWindow( Session& session, Prefs& prefs, TorrentModel& model, bool minimized ): myLastFullUpdateTime( 0 ), mySessionDialog( new SessionDialog( session, prefs, this ) ), @@ -301,9 +316,18 @@ TrMainWindow :: onSetPrefs( bool isChecked ) onSetPrefs( ); } +#define SHOW_KEY "show-mode" + +void +TrMainWindow :: onShowModeClicked( ) +{ + setShowMode( sender()->property(SHOW_KEY).toInt() ); +} + QWidget * TrMainWindow :: createFilterBar( ) { + int i; QMenu * m; QLineEdit * e; QPushButton * p; @@ -313,21 +337,37 @@ TrMainWindow :: createFilterBar( ) const QSize smallIconSize( smallSize, smallSize ); QWidget * top = myFilterBar = new QWidget; - h = new QHBoxLayout( top ); - h->setContentsMargins( HIG::PAD_SMALL, HIG::PAD_SMALL, HIG::PAD_SMALL, 0 ); + h->setContentsMargins( HIG::PAD_SMALL, HIG::PAD_SMALL, HIG::PAD_SMALL, HIG::PAD_SMALL ); h->setSpacing( HIG::PAD_SMALL ); - QTabBar * tabBar = myFilterTabs = new QTabBar( this ); - tabBar->addTab( tr( "A&ll" ) ); - tabBar->addTab( tr( "&Active" ) ); - tabBar->addTab( tr( "&Downloading" ) ); - tabBar->addTab( tr( "&Seeding" ) ); - tabBar->addTab( tr( "&Paused" ) ); - connect( tabBar, SIGNAL(currentChanged(int)), this, SLOT(setShowMode(int))); - h->addWidget( tabBar ); + top->setStyleSheet(" \ + QPushButton{ \ + border-radius: 10px; \ + padding: 0 5px; \ + border: 1px none; \ + } \ + QPushButton:pressed, QPushButton:checked{ \ + border-width: 1px; \ + border-style: solid; \ + border-color: #5f5f5f #979797 #979797; \ + background-color: #979797; \ + color: white; \ + } \ + "); + + QList titles; + titles << tr( "A&ll" ) << tr( "&Active" ) << tr( "&Downloading" ) << tr( "&Seeding" ) << tr( "&Paused" ); + for( i=0; isetProperty( SHOW_KEY, i ); + p->setFlat( true ); + p->setCheckable( true ); + p->setMaximumSize( calculateTextButtonSizeHint( p ) ); + connect( p, SIGNAL(clicked()), this, SLOT(onShowModeClicked())); + h->addWidget( p ); + } - h->addSpacing( HIG::PAD_BIG ); h->addStretch( 1 ); a = new QActionGroup( this ); @@ -773,6 +813,11 @@ TrMainWindow :: reannounceSelected( ) **/ void TrMainWindow :: setShowMode ( int i ) { myPrefs.set( Prefs::FILTER_MODE, FilterMode( i ) ); } +void TrMainWindow :: showAll ( ) { setShowMode( FilterMode :: SHOW_ALL ); } +void TrMainWindow :: showActive ( ) { setShowMode( FilterMode :: SHOW_ACTIVE ); } +void TrMainWindow :: showDownloading ( ) { setShowMode( FilterMode :: SHOW_DOWNLOADING ); } +void TrMainWindow :: showSeeding ( ) { setShowMode( FilterMode :: SHOW_SEEDING ); } +void TrMainWindow :: showPaused ( ) { setShowMode( FilterMode :: SHOW_PAUSED ); } void TrMainWindow :: filterByName ( ) { myFilterModel.setTextMode( TorrentFilter :: FILTER_BY_NAME ); } void TrMainWindow :: filterByTracker ( ) { myFilterModel.setTextMode( TorrentFilter :: FILTER_BY_TRACKER ); } @@ -896,7 +941,9 @@ TrMainWindow :: refreshPref( int key ) break; case Prefs::FILTER_MODE: - myFilterTabs->setCurrentIndex( myPrefs.get(key).mode( ) ); + i = myPrefs.get(key).mode( ); + for( int j=0; jsetChecked( i==j ); break; case Prefs::FILTERBAR: diff --git a/qt/mainwin.h b/qt/mainwin.h index c5bfc51bd..3ae12be40 100644 --- a/qt/mainwin.h +++ b/qt/mainwin.h @@ -44,7 +44,6 @@ class QAction; class QLabel; class QMenu; class QModelIndex; -class QTabBar; class QSortFilterProxyModel; class TrMainWindow: public QMainWindow @@ -79,19 +78,24 @@ class TrMainWindow: public QMainWindow QAction * myUlimitOnAction; QAction * myRatioOffAction; QAction * myRatioOnAction; - QTabBar * myFilterTabs; private: QIcon getStockIcon( const QString&, int fallback=-1 ); private: + void setShowMode( int ); QSet getSelectedTorrents( ) const; void updateNetworkIcon( ); QWidgetList myHidden; private slots: - void setShowMode( int ); void onDetailsDestroyed( ); + void onShowModeClicked( ); + void showAll( ); + void showActive( ); + void showDownloading( ); + void showSeeding( ); + void showPaused( ); void filterByName( ); void filterByFiles( ); void filterByTracker( );