Changeset 8332


Ignore:
Timestamp:
May 4, 2009, 5:26:16 PM (12 years ago)
Author:
charles
Message:

(trunk qt) use tabs for the main window's filters

Location:
trunk/qt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/mainwin.cc

    r8327 r8332  
    2424#include <QUrl>
    2525#include <QSignalMapper>
     26#include <QTabBar>
    2627
    2728#include <libtransmission/version.h>
     
    6162    return QtIconLoader::icon( freedesktop_name, fallbackIcon );
    6263}
    63 
    64 namespace
    65 {
    66     QSize calculateTextButtonSizeHint( QPushButton * button )
    67     {
    68         QStyleOptionButton opt;
    69         opt.initFrom( button );
    70         QString s( button->text( ) );
    71         if( s.isEmpty( ) )
    72             s = QString::fromLatin1( "XXXX" );
    73         QFontMetrics fm = button->fontMetrics( );
    74         QSize sz = fm.size( Qt::TextShowMnemonic, s );
    75         return button->style()->sizeFromContents( QStyle::CT_PushButton, &opt, sz, button ).expandedTo( QApplication::globalStrut( ) );
    76     }
    77 }
    78 
    7964
    8065TrMainWindow :: TrMainWindow( Session& session, Prefs& prefs, TorrentModel& model, bool minimized ):
     
    317302}
    318303
    319 #define SHOW_KEY "show-mode"
    320 
    321 void
    322 TrMainWindow :: onShowModeClicked( )
    323 {
    324     setShowMode( sender()->property(SHOW_KEY).toInt() );
    325 }
    326 
    327304QWidget *
    328305TrMainWindow :: createFilterBar( )
    329306{
    330     int i;
    331307    QMenu * m;
    332308    QLineEdit * e;
     
    338314
    339315    QWidget * top = myFilterBar = new QWidget;
     316   
    340317    h = new QHBoxLayout( top );
    341     h->setContentsMargins( HIG::PAD_SMALL, HIG::PAD_SMALL, HIG::PAD_SMALL, HIG::PAD_SMALL );
     318    h->setContentsMargins( HIG::PAD_SMALL, HIG::PAD_SMALL, HIG::PAD_SMALL, 0 );
    342319    h->setSpacing( HIG::PAD_SMALL );
    343320
    344         QList<QString> titles;
    345         titles << tr( "A&ll" ) << tr( "&Active" ) << tr( "&Downloading" ) << tr( "&Seeding" ) << tr( "&Paused" );
    346         for( i=0; i<titles.size(); ++i ) {
    347             p = myFilterButtons[i] = new QPushButton( titles[i] );
    348             p->setProperty( SHOW_KEY, i );
    349             p->setFlat( true );
    350             p->setCheckable( true );
    351             p->setMaximumSize( calculateTextButtonSizeHint( p ) );
    352             connect( p, SIGNAL(clicked()), this, SLOT(onShowModeClicked()));
    353             h->addWidget( p );
    354         }
    355 
     321        QTabBar * tabBar = myFilterTabs = new QTabBar( this );
     322        tabBar->addTab( tr( "A&ll" ) );
     323        tabBar->addTab( tr( "&Active" ) );
     324        tabBar->addTab( tr( "&Downloading" ) );
     325        tabBar->addTab( tr( "&Seeding" ) );
     326        tabBar->addTab( tr( "&Paused" ) );
     327        connect( tabBar, SIGNAL(currentChanged(int)), this, SLOT(setShowMode(int)));
     328        h->addWidget( tabBar );
     329
     330    h->addSpacing( HIG::PAD_BIG );
    356331    h->addStretch( 1 );
    357332
     
    799774
    800775void TrMainWindow :: setShowMode     ( int i ) { myPrefs.set( Prefs::FILTER_MODE, FilterMode( i ) ); }
    801 void TrMainWindow :: showAll         ( ) { setShowMode( FilterMode :: SHOW_ALL ); }
    802 void TrMainWindow :: showActive      ( ) { setShowMode( FilterMode :: SHOW_ACTIVE ); }
    803 void TrMainWindow :: showDownloading ( ) { setShowMode( FilterMode :: SHOW_DOWNLOADING ); }
    804 void TrMainWindow :: showSeeding     ( ) { setShowMode( FilterMode :: SHOW_SEEDING ); }
    805 void TrMainWindow :: showPaused      ( ) { setShowMode( FilterMode :: SHOW_PAUSED ); }
    806776
    807777void TrMainWindow :: filterByName    ( ) { myFilterModel.setTextMode( TorrentFilter :: FILTER_BY_NAME ); }
     
    927897
    928898        case Prefs::FILTER_MODE:
    929             i = myPrefs.get<FilterMode>(key).mode( );
    930             for( int j=0; j<FilterMode::NUM_MODES; ++j )
    931                 myFilterButtons[j]->setChecked( i==j );
     899            myFilterTabs->setCurrentIndex( myPrefs.get<FilterMode>(key).mode( ) );
    932900            break;
    933901
  • trunk/qt/mainwin.h

    r8327 r8332  
    4545class QMenu;
    4646class QModelIndex;
     47class QTabBar;
    4748class QSortFilterProxyModel;
    4849
     
    7980        QAction * myRatioOffAction;
    8081        QAction * myRatioOnAction;
     82        QTabBar * myFilterTabs;
    8183
    8284    private:
     
    8486
    8587    private:
    86         void setShowMode( int );
    8788        QSet<int> getSelectedTorrents( ) const;
    8889        void updateNetworkIcon( );
     
    9091
    9192    private slots:
     93        void setShowMode( int );
    9294        void onDetailsDestroyed( );
    93         void onShowModeClicked( );
    94         void showAll( );
    95         void showActive( );
    96         void showDownloading( );
    97         void showSeeding( );
    98         void showPaused( );
    9995        void filterByName( );
    10096        void filterByFiles( );
Note: See TracChangeset for help on using the changeset viewer.