source: trunk/qt/filterbar.h @ 14392

Last change on this file since 14392 was 14392, checked in by mikedld, 8 years ago

Move filter text clearing button into line edit. Use Qt-provided button on Qt 5.2+.

  • Property svn:keywords set to Date Rev Author Id
File size: 2.6 KB
Line 
1/*
2 * This file Copyright (C) 2010-2014 Mnemosyne LLC
3 *
4 * It may be used under the GNU GPL versions 2 or 3
5 * or any future license endorsed by Mnemosyne LLC.
6 *
7 * $Id: filterbar.h 14392 2014-12-21 15:34:52Z mikedld $
8 */
9
10#ifndef QTR_FILTERBAR_H
11#define QTR_FILTERBAR_H
12
13#include <QComboBox>
14#include <QItemDelegate>
15#include <QLineEdit>
16#include <QWidget>
17
18class QLabel;
19class QLineEdit;
20class QPaintEvent;
21class QStandardItemModel;
22class QTimer;
23
24class Prefs;
25class TorrentFilter;
26class TorrentModel;
27
28class FilterBarComboBoxDelegate: public QItemDelegate
29{
30    Q_OBJECT
31
32  public:
33    FilterBarComboBoxDelegate (QObject * parent, QComboBox * combo);
34
35  public:
36    static bool isSeparator (const QModelIndex &index);
37    static void setSeparator (QAbstractItemModel * model, const QModelIndex& index);
38
39  protected:
40    virtual void paint (QPainter*, const QStyleOptionViewItem&, const QModelIndex&) const;
41    virtual QSize sizeHint (const QStyleOptionViewItem&, const QModelIndex&) const;
42
43  private:
44    QComboBox * myCombo;
45
46};
47
48class FilterBarComboBox: public QComboBox
49{
50    Q_OBJECT
51
52  public:
53    FilterBarComboBox (QWidget * parent = 0);
54    int currentCount () const;
55
56  protected:
57    virtual void paintEvent (QPaintEvent * e);
58};
59
60class FilterBarLineEdit: public QLineEdit
61{
62    Q_OBJECT
63
64  public:
65    FilterBarLineEdit (QWidget * parent = 0);
66
67  protected:
68    virtual void resizeEvent (QResizeEvent * event);
69
70  private slots:
71    void updateClearButtonVisibility ();
72
73  private:
74    QToolButton * myClearButton;
75};
76
77class FilterBar: public QWidget
78{
79    Q_OBJECT
80
81  public:
82    FilterBar (Prefs& prefs, TorrentModel& torrents, TorrentFilter& filter, QWidget * parent = 0);
83    ~FilterBar ();
84
85  private:
86    FilterBarComboBox * createTrackerCombo (QStandardItemModel * );
87    FilterBarComboBox * createActivityCombo ();
88    void recountSoon ();
89    void refreshTrackers ();
90    QString getCountString (int n) const;
91
92  private:
93    Prefs& myPrefs;
94    TorrentModel& myTorrents;
95    TorrentFilter& myFilter;
96    FilterBarComboBox * myActivityCombo;
97    FilterBarComboBox * myTrackerCombo;
98    QLabel * myCountLabel;
99    QStandardItemModel * myTrackerModel;
100    QTimer * myRecountTimer;
101    bool myIsBootstrapping;
102    FilterBarLineEdit * myLineEdit;
103
104  private slots:
105    void recount ();
106    void refreshPref (int key);
107    void refreshCountLabel ();
108    void onActivityIndexChanged (int index);
109    void onTrackerIndexChanged (int index);
110    void onTorrentModelReset ();
111    void onTorrentModelRowsInserted (const QModelIndex&, int, int);
112    void onTorrentModelRowsRemoved (const QModelIndex&, int, int);
113    void onTorrentModelDataChanged (const QModelIndex&, const QModelIndex&);
114    void onTextChanged (const QString&);
115};
116
117#endif
Note: See TracBrowser for help on using the repository browser.