1/*
2 * This file Copyright (C) Mnemosyne LLC
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2
6 * as published by the Free Software Foundation.
7 *
8 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
9 *
10 * $Id: filterbar.h 11406 2010-11-14 05:03:38Z charles $
11 */
12
13#ifndef QTR_FILTERBAR_H
14#define QTR_FILTERBAR_H
15
16#include <QComboBox>
17#include <QItemDelegate>
18#include <QWidget>
19
20class QLineEdit;
21class QPaintEvent;
22class QStandardItemModel;
23class QTimer;
24
25class Prefs;
26class TorrentFilter;
27class TorrentModel;
28
29class FilterBarComboBoxDelegate: public QItemDelegate
30{
31        Q_OBJECT
32
33    public:
34        FilterBarComboBoxDelegate( QObject * parent, QComboBox * combo );
35
36    public:
37        static bool isSeparator( const QModelIndex &index );
38        static void setSeparator( QAbstractItemModel * model, const QModelIndex& index );
39
40    protected:
41        virtual void paint( QPainter*, const QStyleOptionViewItem&, const QModelIndex& ) const;
42        virtual QSize sizeHint( const QStyleOptionViewItem&, const QModelIndex& ) const;
43
44    private:
45        QComboBox * myCombo;
46
47};
48
49class FilterBarComboBox: public QComboBox
50{
51        Q_OBJECT
52
53    public:
54        FilterBarComboBox( QWidget * parent = 0 );
55
56    protected:
57        virtual void paintEvent( QPaintEvent * e );
58};
59
60
61class FilterBar: public QWidget
62{
63        Q_OBJECT
64
65    public:
66        FilterBar( Prefs& prefs, TorrentModel& torrents, TorrentFilter& filter, QWidget * parent = 0 );
67        ~FilterBar( );
68
69    private:
70        QComboBox * createTrackerCombo( QStandardItemModel *  );
71        QComboBox * createActivityCombo( );
72        void recountSoon( );
73        void refreshTrackers( );
74        QString getCountString( int n ) const;
75
76    private:
77        Prefs& myPrefs;
78        TorrentModel& myTorrents;
79        TorrentFilter& myFilter;
80        QComboBox * myActivityCombo;
81        QComboBox * myTrackerCombo;
82        QStandardItemModel * myTrackerModel;
83        QTimer * myRecountTimer;
84        bool myIsBootstrapping;
85        QLineEdit * myLineEdit;
86
87    private slots:
88        void recount( );
89        void refreshPref( int key );
90        void onActivityIndexChanged( int index );
91        void onTrackerIndexChanged( int index );
92        void onTorrentModelReset( );
93        void onTorrentModelRowsInserted( const QModelIndex&, int, int );
94        void onTorrentModelRowsRemoved( const QModelIndex&, int, int );
95        void onTorrentModelDataChanged( const QModelIndex&, const QModelIndex& );
96        void onTextChanged( const QString& );
97};
98
99#endif
100